acpi: Add IORT helper functions
[coreboot2.git] / src / drivers / i2c / max98373 / max98373.c
blob1035a7c5d9950149641bd012af678bb80cd81198
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 "chip.h"
10 #define MAX98373_ACPI_NAME "MAXI"
11 #define MAX98373_ACPI_HID "MX98373"
13 static void max98373_fill_ssdt(const struct device *dev)
15 struct drivers_i2c_max98373_config *config = dev->chip_info;
16 const char *scope = acpi_device_scope(dev);
17 struct acpi_i2c i2c = {
18 .address = dev->path.i2c.device,
19 .mode_10bit = dev->path.i2c.mode_10bit,
20 .speed = config->bus_speed ? : I2C_SPEED_FAST,
21 .resource = scope,
23 struct acpi_dp *dp;
25 if (!scope) {
26 printk(BIOS_ERR, "%s: dev not enabled\n", __func__);
27 return;
30 /* Device */
31 acpigen_write_scope(scope);
32 acpigen_write_device(acpi_device_name(dev));
33 acpigen_write_name_string("_HID", MAX98373_ACPI_HID);
34 acpigen_write_name_integer("_UID", config->uid);
35 if (config->desc)
36 acpigen_write_name_string("_DDN", config->desc);
37 acpigen_write_STA(acpi_device_status(dev));
39 /* Resources */
40 acpigen_write_name("_CRS");
41 acpigen_write_resourcetemplate_header();
42 acpi_device_write_i2c(&i2c);
43 acpigen_write_resourcetemplate_footer();
45 /* Device Properties */
46 dp = acpi_dp_new_table("_DSD");
48 if (config->interleave_mode)
49 acpi_dp_add_integer(dp, "maxim,interleave_mode",
50 config->interleave_mode);
51 acpi_dp_add_integer(dp, "maxim,vmon-slot-no", config->vmon_slot_no);
52 acpi_dp_add_integer(dp, "maxim,imon-slot-no", config->imon_slot_no);
54 acpi_dp_write(dp);
56 acpigen_pop_len(); /* Device */
57 acpigen_pop_len(); /* Scope */
59 printk(BIOS_INFO, "%s: %s address 0%xh\n", acpi_device_path(dev),
60 dev->chip_ops->name, dev->path.i2c.device);
63 static const char *max98373_acpi_name(const struct device *dev)
65 struct drivers_i2c_max98373_config *config = dev->chip_info;
67 if (config->name)
68 return config->name;
70 return MAX98373_ACPI_NAME;
73 static struct device_operations max98373_ops = {
74 .read_resources = noop_read_resources,
75 .set_resources = noop_set_resources,
76 .acpi_name = max98373_acpi_name,
77 .acpi_fill_ssdt = max98373_fill_ssdt,
80 static void max98373_enable(struct device *dev)
82 struct drivers_i2c_max98373_config *config = dev->chip_info;
84 dev->ops = &max98373_ops;
86 if (config && config->desc) {
87 dev->name = config->desc;
91 struct chip_operations drivers_i2c_max98373_ops = {
92 .name = "Maxim MAX98373 Codec",
93 .enable_dev = max98373_enable