Eric Lai | 201928b | 2022-07-28 10:17:54 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 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> |
Eric Lai | 201928b | 2022-07-28 10:17:54 +0800 | [diff] [blame] | 8 | |
| 9 | #include "chip.h" |
| 10 | |
| 11 | #define MAX98396_ACPI_HID "ADS8396" |
| 12 | |
| 13 | static void max98396_fill_ssdt(const struct device *dev) |
| 14 | { |
| 15 | struct drivers_i2c_max98396_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, |
| 22 | }; |
| 23 | struct acpi_dp *dp; |
| 24 | const char *path = acpi_device_path(dev); |
| 25 | |
| 26 | if (!scope) { |
| 27 | printk(BIOS_ERR, "%s: dev not enabled\n", __func__); |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | /* Device */ |
| 32 | acpigen_write_scope(scope); |
| 33 | acpigen_write_device(acpi_device_name(dev)); |
| 34 | acpigen_write_name_string("_HID", MAX98396_ACPI_HID); |
| 35 | acpigen_write_name_integer("_UID", config->uid); |
| 36 | if (config->desc) |
| 37 | acpigen_write_name_string("_DDN", config->desc); |
| 38 | acpigen_write_STA(acpi_device_status(dev)); |
| 39 | |
| 40 | /* Resources */ |
| 41 | acpigen_write_name("_CRS"); |
| 42 | acpigen_write_resourcetemplate_header(); |
| 43 | acpi_device_write_i2c(&i2c); |
| 44 | if (config->reset_gpio.pin_count) |
| 45 | acpi_device_write_gpio(&config->reset_gpio); |
| 46 | acpigen_write_resourcetemplate_footer(); |
| 47 | |
| 48 | /* Device Properties */ |
| 49 | dp = acpi_dp_new_table("_DSD"); |
| 50 | |
| 51 | acpi_dp_add_integer(dp, "adi,vmon-slot-no", config->vmon_slot_no); |
| 52 | acpi_dp_add_integer(dp, "adi,imon-slot-no", config->imon_slot_no); |
| 53 | acpi_dp_add_integer(dp, "adi,spkfb-slot-no", config->spkfb_slot_no); |
| 54 | if (config->reset_gpio.pin_count) |
| 55 | acpi_dp_add_gpio(dp, "reset-gpios", path, |
| 56 | 0, /* Index = 0 */ |
| 57 | 0, /* Pin = 0 */ |
| 58 | config->reset_gpio.active_low); |
| 59 | acpi_dp_write(dp); |
| 60 | |
| 61 | acpigen_write_device_end(); |
| 62 | acpigen_write_scope_end(); |
| 63 | |
| 64 | printk(BIOS_INFO, "%s: %s address 0%xh\n", acpi_device_path(dev), |
| 65 | dev->chip_ops->name, dev->path.i2c.device); |
| 66 | } |
| 67 | |
| 68 | static const char *max98396_acpi_name(const struct device *dev) |
| 69 | { |
| 70 | struct drivers_i2c_max98396_config *config = dev->chip_info; |
| 71 | static char name[ACPI_NAME_BUFFER_SIZE]; |
| 72 | |
| 73 | if (config->name && strlen(config->name) == 4) |
| 74 | return config->name; |
| 75 | |
| 76 | snprintf(name, sizeof(name), "D%03.3X", dev->path.i2c.device); |
| 77 | return name; |
| 78 | } |
| 79 | |
| 80 | static struct device_operations max98396_ops = { |
| 81 | .read_resources = noop_read_resources, |
| 82 | .set_resources = noop_set_resources, |
| 83 | .acpi_name = max98396_acpi_name, |
| 84 | .acpi_fill_ssdt = max98396_fill_ssdt, |
| 85 | }; |
| 86 | |
| 87 | static void max98396_enable(struct device *dev) |
| 88 | { |
| 89 | struct drivers_i2c_max98396_config *config = dev->chip_info; |
| 90 | |
| 91 | dev->ops = &max98396_ops; |
| 92 | |
| 93 | if (config->desc) |
| 94 | dev->name = config->desc; |
| 95 | } |
| 96 | |
| 97 | struct chip_operations drivers_i2c_max98396_ops = { |
Nicholas Sudsgaard | bfb11be | 2024-01-30 09:53:46 +0900 | [diff] [blame] | 98 | .name = "Maxim MAX98396 Codec", |
Eric Lai | 201928b | 2022-07-28 10:17:54 +0800 | [diff] [blame] | 99 | .enable_dev = max98396_enable |
| 100 | }; |