acpi: Add IORT helper functions
[coreboot2.git] / src / drivers / i2c / max98396 / max98396.c
blobf71873a26d3fa9e261ae7afebabc09ca1232bd95
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <acpi/acpi_device.h>
4 #include <acpi/acpigen.h>
5 #include <console/console.h>
6 #include <device/i2c_simple.h>
7 #include <device/device.h>
8 #include <stdio.h>
10 #include "chip.h"
12 #define MAX98396_ACPI_HID "ADS8396"
14 static void max98396_fill_ssdt(const struct device *dev)
16 struct drivers_i2c_max98396_config *config = dev->chip_info;
17 const char *scope = acpi_device_scope(dev);
18 struct acpi_i2c i2c = {
19 .address = dev->path.i2c.device,
20 .mode_10bit = dev->path.i2c.mode_10bit,
21 .speed = config->bus_speed ? : I2C_SPEED_FAST,
22 .resource = scope,
24 struct acpi_dp *dp;
25 const char *path = acpi_device_path(dev);
27 if (!scope) {
28 printk(BIOS_ERR, "%s: dev not enabled\n", __func__);
29 return;
32 /* Device */
33 acpigen_write_scope(scope);
34 acpigen_write_device(acpi_device_name(dev));
35 acpigen_write_name_string("_HID", MAX98396_ACPI_HID);
36 acpigen_write_name_integer("_UID", config->uid);
37 if (config->desc)
38 acpigen_write_name_string("_DDN", config->desc);
39 acpigen_write_STA(acpi_device_status(dev));
41 /* Resources */
42 acpigen_write_name("_CRS");
43 acpigen_write_resourcetemplate_header();
44 acpi_device_write_i2c(&i2c);
45 if (config->reset_gpio.pin_count)
46 acpi_device_write_gpio(&config->reset_gpio);
47 acpigen_write_resourcetemplate_footer();
49 /* Device Properties */
50 dp = acpi_dp_new_table("_DSD");
52 acpi_dp_add_integer(dp, "adi,vmon-slot-no", config->vmon_slot_no);
53 acpi_dp_add_integer(dp, "adi,imon-slot-no", config->imon_slot_no);
54 acpi_dp_add_integer(dp, "adi,spkfb-slot-no", config->spkfb_slot_no);
55 if (config->reset_gpio.pin_count)
56 acpi_dp_add_gpio(dp, "reset-gpios", path,
57 0, /* Index = 0 */
58 0, /* Pin = 0 */
59 config->reset_gpio.active_low);
60 acpi_dp_write(dp);
62 acpigen_write_device_end();
63 acpigen_write_scope_end();
65 printk(BIOS_INFO, "%s: %s address 0%xh\n", acpi_device_path(dev),
66 dev->chip_ops->name, dev->path.i2c.device);
69 static const char *max98396_acpi_name(const struct device *dev)
71 struct drivers_i2c_max98396_config *config = dev->chip_info;
72 static char name[ACPI_NAME_BUFFER_SIZE];
74 if (config->name && strlen(config->name) == 4)
75 return config->name;
77 snprintf(name, sizeof(name), "D%03.3X", dev->path.i2c.device);
78 return name;
81 static struct device_operations max98396_ops = {
82 .read_resources = noop_read_resources,
83 .set_resources = noop_set_resources,
84 .acpi_name = max98396_acpi_name,
85 .acpi_fill_ssdt = max98396_fill_ssdt,
88 static void max98396_enable(struct device *dev)
90 struct drivers_i2c_max98396_config *config = dev->chip_info;
92 dev->ops = &max98396_ops;
94 if (config->desc)
95 dev->name = config->desc;
98 struct chip_operations drivers_i2c_max98396_ops = {
99 .name = "Maxim MAX98396 Codec",
100 .enable_dev = max98396_enable