coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
i2s_machine_dev.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include <acpi/acpi_device.h>
4 #include <acpi/acpigen.h>
5 #include <device/device.h>
6 #include <string.h>
7 #include "chip.h"
8 #include <console/console.h>
9 
10 #define AMD_I2S_ACPI_DESC "I2S machine driver"
11 
12 static void i2s_machine_dev_fill_crs_dsd(const char *path,
13  const struct acpi_gpio *dmic_select_gpio)
14 {
15  struct acpi_dp *dsd;
16 
17  /* Resources */
18  acpigen_write_name("_CRS");
20  acpi_device_write_gpio(dmic_select_gpio);
22 
23  dsd = acpi_dp_new_table("_DSD");
24  /*
25  * This GPIO is used to select DMIC0 or DMIC1 by the kernel driver. It does not
26  * really have a polarity since low and high control the selection of DMIC and
27  * hence does not have an active polarity.
28  * Kernel driver does not use the polarity field and instead treats the GPIO
29  * selection as follows:
30  * Set low (0) = Select DMIC0
31  * Set high (1) = Select DMIC1
32  */
33  acpi_dp_add_gpio(dsd, "dmic-gpios", path,
34  0, /* Index = 0 (There is a single GPIO entry in _CRS). */
35  0, /* Pin = 0 (There is a single pin in the GPIO resource). */
36  0); /* Active low = 0 (Kernel driver does not use active polarity). */
37  acpi_dp_write(dsd);
38 }
39 
40 static void i2s_machine_dev_fill_ssdt(const struct device *dev)
41 {
42  const char *scope = acpi_device_scope(dev);
43  const struct acpi_gpio *dmic_select_gpio;
44  const struct drivers_amd_i2s_machine_dev_config *cfg;
45  const char *path = acpi_device_path(dev);
46 
47  cfg = config_of(dev);
48 
50 
51  if (scope == NULL) {
52  printk(BIOS_ERR, "%s: ERROR: ACPI I2S scope not found\n", dev_path(dev));
53  return;
54  }
55 
56  if (cfg->hid == NULL) {
57  printk(BIOS_ERR, "%s: ERROR: HID required\n", dev_path(dev));
58  return;
59  }
60 
61  acpigen_write_scope(scope); /* Scope */
62  acpigen_write_device(acpi_device_name(dev)); /* Device */
63  acpigen_write_name_string("_HID", cfg->hid);
64  acpigen_write_name_integer("_UID", cfg->uid);
66 
68 
71 
72  acpigen_pop_len(); /* Device */
73  acpigen_pop_len(); /* Scope */
74 
75  printk(BIOS_INFO, "%s: %s at %s\n", path, AMD_I2S_ACPI_DESC, dev_path(dev));
76 }
77 
78 static const char *i2s_machine_dev_acpi_name(const struct device *dev)
79 {
80  static char name[5];
81  snprintf(name, sizeof(name), "I2S%X", dev->path.generic.id);
82  return name;
83 }
84 
85 static struct device_operations i2s_machine_dev_ops = {
87  .set_resources = noop_set_resources,
88  .acpi_name = i2s_machine_dev_acpi_name,
89  .acpi_fill_ssdt = i2s_machine_dev_fill_ssdt,
90 };
91 
92 static void i2s_machine_dev_enable(struct device *dev)
93 {
94  dev->ops = &i2s_machine_dev_ops;
95 }
96 
98  CHIP_NAME("AMD I2S Machine Device")
99  .enable_dev = i2s_machine_dev_enable
100 };
void acpi_device_write_gpio(const struct acpi_gpio *gpio)
Definition: device.c:258
const char * acpi_device_path(const struct device *dev)
Definition: device.c:144
void acpi_dp_write(struct acpi_dp *table)
Definition: device.c:898
struct acpi_dp * acpi_dp_add_gpio(struct acpi_dp *dp, const char *name, const char *ref, int index, int pin, int active_low)
Definition: device.c:1142
int acpi_device_status(const struct device *dev)
Definition: device.c:193
const char * acpi_device_name(const struct device *dev)
Definition: device.c:49
struct acpi_dp * acpi_dp_new_table(const char *name)
Definition: device.c:930
const char * acpi_device_scope(const struct device *dev)
Definition: device.c:158
void acpigen_pop_len(void)
Definition: acpigen.c:37
void acpigen_write_scope(const char *name)
Definition: acpigen.c:326
void acpigen_write_resourcetemplate_footer(void)
Definition: acpigen.c:1165
void acpigen_write_name_integer(const char *name, uint64_t val)
Definition: acpigen.c:170
void acpigen_write_STA(uint8_t status)
Definition: acpigen.c:783
void acpigen_write_resourcetemplate_header(void)
Definition: acpigen.c:1147
void acpigen_write_device(const char *name)
Definition: acpigen.c:769
void acpigen_write_name(const char *name)
Definition: acpigen.c:320
void acpigen_write_name_string(const char *name, const char *string)
Definition: acpigen.c:176
const char * name
Definition: mmu.c:92
#define printk(level,...)
Definition: stdlib.h:16
const char * dev_path(const struct device *dev)
Definition: device_util.c:149
static void i2s_machine_dev_enable(struct device *dev)
static const char * i2s_machine_dev_acpi_name(const struct device *dev)
struct chip_operations drivers_amd_i2s_machine_dev_ops
static void i2s_machine_dev_fill_ssdt(const struct device *dev)
#define AMD_I2S_ACPI_DESC
static struct device_operations i2s_machine_dev_ops
static void i2s_machine_dev_fill_crs_dsd(const char *path, const struct acpi_gpio *dmic_select_gpio)
#define CHIP_NAME(X)
Definition: device.h:32
static void noop_read_resources(struct device *dev)
Standard device operations function pointers shims.
Definition: device.h:73
static void noop_set_resources(struct device *dev)
Definition: device.h:74
static DEVTREE_CONST void * config_of(const struct device *dev)
Definition: device.h:382
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
#define NULL
Definition: stddef.h:19
int pin_count
Definition: acpi_device.h:165
void(* read_resources)(struct device *dev)
Definition: device.h:39
struct generic_path generic
Definition: path.h:125
Definition: device.h:107
struct device_path path
Definition: device.h:115
struct device_operations * ops
Definition: device.h:143
struct acpi_gpio dmic_select_gpio
Definition: chip.h:19
unsigned int id
Definition: path.h:96
int snprintf(char *buf, size_t size, const char *fmt,...)
Note: This file is only for POSIX compatibility, and is meant to be chain-included via string....
Definition: vsprintf.c:35