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