Stefan Binding | 7cd5058 | 2021-12-22 14:30:08 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <acpi/acpi.h> |
| 4 | #include <acpi/acpi_device.h> |
| 5 | #include <acpi/acpigen.h> |
| 6 | #include <console/console.h> |
| 7 | #include <device/i2c_simple.h> |
| 8 | #include <device/device.h> |
Stefan Binding | 7cd5058 | 2021-12-22 14:30:08 +0000 | [diff] [blame] | 9 | |
| 10 | #include "chip.h" |
| 11 | |
| 12 | #define CS35L53_ACPI_HID "CSC3541" |
| 13 | |
| 14 | static void cs35l53_fill_ssdt(const struct device *dev) |
| 15 | { |
| 16 | struct drivers_i2c_cs35l53_config *config = dev->chip_info; |
| 17 | const char *scope = acpi_device_scope(dev); |
| 18 | const char *path = acpi_device_path(dev); |
| 19 | struct acpi_i2c i2c = { |
| 20 | .address = dev->path.i2c.device, |
| 21 | .mode_10bit = dev->path.i2c.mode_10bit, |
| 22 | .speed = config->bus_speed ? : I2C_SPEED_FAST, |
| 23 | .resource = scope, |
| 24 | }; |
| 25 | struct acpi_dp *dsd; |
| 26 | int gpio_index = 0; |
| 27 | |
| 28 | if (!scope) |
| 29 | return; |
| 30 | |
| 31 | /* Device */ |
| 32 | acpigen_write_scope(scope); |
| 33 | acpigen_write_device(acpi_device_name(dev)); |
| 34 | acpigen_write_name_string("_HID", CS35L53_ACPI_HID); |
Vitaly Rodionov | 74782cb | 2022-05-24 14:58:01 +0100 | [diff] [blame] | 35 | acpigen_write_name_integer("_UID", config->uid); |
| 36 | if (config->desc == NULL) |
| 37 | acpigen_write_name_string("_DDN", dev->chip_ops->name); |
| 38 | else |
| 39 | acpigen_write_name_string("_DDN", config->desc); |
Stefan Binding | 7cd5058 | 2021-12-22 14:30:08 +0000 | [diff] [blame] | 40 | acpigen_write_name_string("_SUB", config->sub); |
| 41 | acpigen_write_STA(acpi_device_status(dev)); |
| 42 | |
| 43 | /* Resources */ |
| 44 | acpigen_write_name("_CRS"); |
| 45 | acpigen_write_resourcetemplate_header(); |
| 46 | acpi_device_write_i2c(&i2c); |
| 47 | /* Use either Interrupt() or GpioInt() */ |
| 48 | if (config->irq_gpio.pin_count) |
| 49 | acpi_device_write_gpio(&config->irq_gpio); |
| 50 | else |
| 51 | acpi_device_write_interrupt(&config->irq); |
| 52 | |
| 53 | /* for cs35l53 reset gpio */ |
| 54 | if (config->reset_gpio.pin_count) |
| 55 | acpi_device_write_gpio(&config->reset_gpio); |
| 56 | |
| 57 | acpigen_write_resourcetemplate_footer(); |
| 58 | |
| 59 | /* Add Child Device Properties */ |
| 60 | dsd = acpi_dp_new_table("_DSD"); |
| 61 | if (config->irq_gpio.pin_count) |
| 62 | acpi_dp_add_gpio(dsd, "irq-gpios", path, |
| 63 | gpio_index++, /* Index = 0 */ |
| 64 | 0, /* Pin = 0 (There is a single pin in the GPIO resource). */ |
| 65 | config->irq_gpio.active_low); |
| 66 | if (config->reset_gpio.pin_count) |
| 67 | acpi_dp_add_gpio(dsd, "reset-gpios", path, |
| 68 | gpio_index++, /* Index = 0 or 1 (if irq gpio is written). */ |
| 69 | 0, /* Pin = 0 (There is a single pin in the GPIO resource). */ |
| 70 | config->reset_gpio.active_low); |
| 71 | |
| 72 | acpi_dp_add_integer(dsd, "cirrus,boost-type", config->boost_type); |
| 73 | |
| 74 | switch (config->boost_type) { |
| 75 | case INTERNAL_BOOST: |
| 76 | if ((config->boost_peak_milliamp > 4500) || |
| 77 | (config->boost_peak_milliamp < 1600) || |
| 78 | (config->boost_peak_milliamp % 50)) { |
| 79 | printk(BIOS_ERR, |
| 80 | "%s: Incorrect boost_peak_milliamp(%d). Using default of 4500 mA\n", |
| 81 | __func__, config->boost_peak_milliamp); |
| 82 | config->boost_peak_milliamp = 4500; |
| 83 | } |
| 84 | acpi_dp_add_integer(dsd, "cirrus,boost-peak-milliamp", |
| 85 | config->boost_peak_milliamp); |
| 86 | acpi_dp_add_integer(dsd, "cirrus,boost-ind-nanohenry", |
| 87 | config->boost_ind_nanohenry); |
| 88 | acpi_dp_add_integer(dsd, "cirrus,boost-cap-microfarad", |
| 89 | config->boost_cap_microfarad); |
| 90 | break; |
| 91 | case EXTERNAL_BOOST: |
| 92 | config->gpio1_output_enable = true; |
| 93 | config->gpio1_src_select = GPIO1_SRC_GPIO; |
| 94 | break; |
| 95 | default: |
| 96 | break; |
| 97 | } |
| 98 | |
| 99 | acpi_dp_add_integer(dsd, "cirrus,asp-sdout-hiz", config->asp_sdout_hiz); |
| 100 | acpi_dp_add_integer(dsd, "cirrus,gpio1-polarity-invert", |
| 101 | config->gpio1_polarity_invert); |
| 102 | acpi_dp_add_integer(dsd, "cirrus,gpio1-output-enable", |
| 103 | config->gpio1_output_enable); |
| 104 | acpi_dp_add_integer(dsd, "cirrus,gpio1-src-select", config->gpio1_src_select); |
| 105 | acpi_dp_add_integer(dsd, "cirrus,gpio2-polarity-invert", |
| 106 | config->gpio2_polarity_invert); |
| 107 | acpi_dp_add_integer(dsd, "cirrus,gpio2-output-enable", |
| 108 | config->gpio2_output_enable); |
| 109 | acpi_dp_add_integer(dsd, "cirrus,gpio2-src-select", config->gpio2_src_select); |
| 110 | |
| 111 | /* Write Device Property Hierarchy */ |
| 112 | acpi_dp_write(dsd); |
| 113 | |
| 114 | acpigen_pop_len(); /* Device */ |
| 115 | acpigen_pop_len(); /* Scope */ |
| 116 | |
| 117 | printk(BIOS_INFO, "%s: %s address 0%xh irq %d\n", |
| 118 | acpi_device_path(dev), dev->chip_ops->name, |
| 119 | dev->path.i2c.device, config->irq.pin); |
| 120 | } |
| 121 | |
| 122 | static const char *cs35l53_acpi_name(const struct device *dev) |
| 123 | { |
| 124 | struct drivers_i2c_cs35l53_config *config = dev->chip_info; |
| 125 | static char name[ACPI_NAME_BUFFER_SIZE]; |
| 126 | |
| 127 | if (config->name) |
| 128 | return config->name; |
| 129 | |
| 130 | snprintf(name, sizeof(name), "D%03.3X", dev->path.i2c.device); |
| 131 | return name; |
| 132 | } |
| 133 | |
| 134 | static struct device_operations cs35l53_ops = { |
| 135 | .read_resources = noop_read_resources, |
| 136 | .set_resources = noop_set_resources, |
| 137 | .acpi_name = cs35l53_acpi_name, |
| 138 | .acpi_fill_ssdt = cs35l53_fill_ssdt, |
| 139 | }; |
| 140 | |
| 141 | static void cs35l53_enable(struct device *dev) |
| 142 | { |
| 143 | dev->ops = &cs35l53_ops; |
| 144 | } |
| 145 | |
| 146 | struct chip_operations drivers_i2c_cs35l53_ops = { |
Nicholas Sudsgaard | bfb11be | 2024-01-30 09:53:46 +0900 | [diff] [blame] | 147 | .name = "Cirrus Logic CS35L53 Audio Codec", |
Stefan Binding | 7cd5058 | 2021-12-22 14:30:08 +0000 | [diff] [blame] | 148 | .enable_dev = cs35l53_enable |
| 149 | }; |