Vitaly Rodionov | 4113645 | 2021-04-15 22:51:48 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Vitaly Rodionov | 4113645 | 2021-04-15 22:51:48 +0100 | [diff] [blame] | 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 <device/path.h> |
| 9 | |
| 10 | #include "chip.h" |
| 11 | |
| 12 | #define CS42L42_ACPI_NAME "CRUS" |
| 13 | #define CS42L42_ACPI_HID "10134242" |
| 14 | |
| 15 | static void cs42l42_fill_ssdt(const struct device *dev) |
| 16 | { |
| 17 | struct drivers_i2c_cs42l42_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", CS42L42_ACPI_HID); |
| 36 | acpigen_write_name_integer("_UID", 0); |
| 37 | acpigen_write_name_string("_DDN", dev->chip_ops->name); |
| 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 | /* Use either Interrupt() or GpioInt() */ |
| 45 | if (config->irq_gpio.pin_count) |
| 46 | acpi_device_write_gpio(&config->irq_gpio); |
| 47 | else |
| 48 | acpi_device_write_interrupt(&config->irq); |
| 49 | |
| 50 | /* for cs42l42reset gpio */ |
| 51 | if (config->reset_gpio.pin_count) |
| 52 | acpi_device_write_gpio(&config->reset_gpio); |
| 53 | |
| 54 | acpigen_write_resourcetemplate_footer(); |
| 55 | |
| 56 | /* AAD Child Device Properties */ |
| 57 | dsd = acpi_dp_new_table("_DSD"); |
| 58 | if (config->irq_gpio.pin_count) |
| 59 | acpi_dp_add_gpio(dsd, "irq-gpios", path, |
| 60 | gpio_index++, /* Index = 0 */ |
| 61 | 0, /* Pin = 0 (There is a single pin in the GPIO resource). */ |
| 62 | config->irq_gpio.active_low); |
| 63 | if (config->reset_gpio.pin_count) |
| 64 | acpi_dp_add_gpio(dsd, "reset-gpios", path, |
| 65 | gpio_index++, /* Index = 0 or 1 (if irq gpio is written). */ |
| 66 | 0, /* Pin = 0 (There is a single pin in the GPIO resource). */ |
| 67 | config->reset_gpio.active_low); |
| 68 | acpi_dp_add_integer(dsd, "cirrus,ts-inv", config->ts_inv ? 1 : 0); |
| 69 | acpi_dp_add_integer(dsd, "cirrus,ts-dbnc-rise", config->ts_dbnc_rise); |
| 70 | acpi_dp_add_integer(dsd, "cirrus,ts-dbnc-fall", config->ts_dbnc_fall); |
| 71 | acpi_dp_add_integer(dsd, "cirrus,btn-det-init-dbnce", config->btn_det_init_dbnce); |
| 72 | |
| 73 | if (config->btn_det_init_dbnce > 200) { |
| 74 | printk(BIOS_ERR, "%s: Incorrect btn_det_init_dbnce(%d). Using default of 100ms\n", |
| 75 | __func__, config->btn_det_init_dbnce); |
| 76 | config->btn_det_init_dbnce = 100; |
| 77 | } |
| 78 | |
| 79 | acpi_dp_add_integer(dsd, "cirrus,btn-det-event-dbnce", config->btn_det_event_dbnce); |
| 80 | |
| 81 | if (config->btn_det_event_dbnce > 100) { |
| 82 | printk(BIOS_ERR, "%s: Incorrect btn_det_event_dbnce(%d). Using default of 10ms\n", |
| 83 | __func__, config->btn_det_event_dbnce); |
| 84 | config->btn_det_event_dbnce = 10; |
| 85 | } |
| 86 | |
| 87 | acpi_dp_add_integer_array(dsd, "cirrus,bias-lvls", config->bias_lvls, 4); |
| 88 | acpi_dp_add_integer(dsd, "cirrus,hs-bias-ramp-rate", config->hs_bias_ramp_rate); |
Vitaly Rodionov | 2be6da1 | 2021-05-06 19:50:36 +0100 | [diff] [blame] | 89 | if (config->hs_bias_sense_disable) |
| 90 | acpi_dp_add_integer(dsd, "cirrus,hs-bias-sense-disable", 1); |
Vitaly Rodionov | 4113645 | 2021-04-15 22:51:48 +0100 | [diff] [blame] | 91 | |
| 92 | /* Write Device Property Hierarchy */ |
| 93 | acpi_dp_write(dsd); |
| 94 | |
| 95 | acpigen_pop_len(); /* Device */ |
| 96 | acpigen_pop_len(); /* Scope */ |
| 97 | |
| 98 | printk(BIOS_INFO, "%s: %s address 0%xh irq %d\n", |
| 99 | acpi_device_path(dev), dev->chip_ops->name, |
| 100 | dev->path.i2c.device, config->irq.pin); |
| 101 | } |
| 102 | |
| 103 | static const char *cs42l42_acpi_name(const struct device *dev) |
| 104 | { |
| 105 | return CS42L42_ACPI_NAME; |
| 106 | } |
| 107 | |
| 108 | static struct device_operations cs42l42_ops = { |
| 109 | .read_resources = noop_read_resources, |
| 110 | .set_resources = noop_set_resources, |
| 111 | .acpi_name = cs42l42_acpi_name, |
| 112 | .acpi_fill_ssdt = cs42l42_fill_ssdt, |
| 113 | }; |
| 114 | |
| 115 | static void cs42l42_enable(struct device *dev) |
| 116 | { |
| 117 | dev->ops = &cs42l42_ops; |
| 118 | } |
| 119 | |
| 120 | struct chip_operations drivers_i2c_cs42l42_ops = { |
Nicholas Sudsgaard | bfb11be | 2024-01-30 09:53:46 +0900 | [diff] [blame^] | 121 | .name = "Cirrus Logic CS42l42 Audio Codec", |
Vitaly Rodionov | 4113645 | 2021-04-15 22:51:48 +0100 | [diff] [blame] | 122 | .enable_dev = cs42l42_enable |
| 123 | }; |