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>
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
,
25 const char *path
= acpi_device_path(dev
);
28 printk(BIOS_ERR
, "%s: dev not enabled\n", __func__
);
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
);
38 acpigen_write_name_string("_DDN", config
->desc
);
39 acpigen_write_STA(acpi_device_status(dev
));
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
,
59 config
->reset_gpio
.active_low
);
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)
77 snprintf(name
, sizeof(name
), "D%03.3X", dev
->path
.i2c
.device
);
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
;
95 dev
->name
= config
->desc
;
98 struct chip_operations drivers_i2c_max98396_ops
= {
99 .name
= "Maxim MAX98396 Codec",
100 .enable_dev
= max98396_enable