Kapil Porwal | 93b7fd1 | 2023-02-25 22:23:01 +0530 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <acpi/acpigen.h> |
| 4 | #include <acpi/acpi_device.h> |
| 5 | #include <acpi/acpi_soundwire.h> |
| 6 | #include <device/device.h> |
| 7 | #include <device/path.h> |
| 8 | #include <device/soundwire.h> |
| 9 | #include <mipi/ids.h> |
| 10 | #include <stdio.h> |
| 11 | |
| 12 | #include "chip.h" |
| 13 | |
| 14 | static struct soundwire_address cs42l42_address = { |
| 15 | .version = SOUNDWIRE_VERSION_1_0, |
| 16 | .manufacturer_id = MIPI_MFG_ID_CIRRUS, |
| 17 | .part_id = MIPI_DEV_ID_CIRRUS_CS42L42, |
| 18 | .class = MIPI_CLASS_NONE |
| 19 | }; |
| 20 | |
| 21 | static struct soundwire_slave cs42l42_slave = { |
| 22 | .wake_up_unavailable = false, |
| 23 | .test_mode_supported = false, |
| 24 | .clock_stop_mode1_supported = true, |
| 25 | .simplified_clockstopprepare_sm_supported = false, |
| 26 | .clockstopprepare_hard_reset_behavior = true, |
| 27 | .highPHY_capable = false, |
| 28 | .paging_supported = true, |
| 29 | .bank_delay_supported = true, |
| 30 | .port15_read_behavior = false, |
| 31 | .source_port_list = SOUNDWIRE_PORT(1), |
| 32 | .sink_port_list = SOUNDWIRE_PORT(2) | SOUNDWIRE_PORT(3) |
| 33 | }; |
| 34 | |
| 35 | static struct soundwire_bra_mode cs42l42_dp0_bra_mode = { |
| 36 | .bus_frequency_configs_count = 6, |
| 37 | .bus_frequency_configs = { |
| 38 | 11289600, /* 11.2896 MHz */ |
| 39 | 12000 * KHz, /* 12 MHz */ |
| 40 | 12288 * KHz, /* 12.288 MHz */ |
| 41 | 22579200, /* 22.5792 MHz */ |
| 42 | 24000 * KHz, /* 24 MHz */ |
| 43 | 24576 * KHz, /* 24.576 MHz */ |
| 44 | }, |
| 45 | .max_data_per_frame = 4096, /* MaxRow*MaxCol = 256*16 = 4096 */ |
| 46 | .min_us_between_transactions = 0 |
| 47 | }; |
| 48 | |
| 49 | static struct soundwire_dp0 cs42l42_dp0 = { |
| 50 | .port_max_wordlength = 64, |
| 51 | .port_min_wordlength = 1, |
| 52 | .bra_imp_def_response_supported = false, |
| 53 | .simplified_channel_prepare_sm = true, |
| 54 | .imp_def_dp0_interrupts_supported = 0, |
| 55 | .imp_def_bpt_supported = true, |
| 56 | .bra_mode_count = 1, |
| 57 | .bra_mode_list = { 0 } |
| 58 | }; |
| 59 | |
| 60 | static struct soundwire_audio_mode cs42l42_audio_mode = { |
| 61 | .bus_frequency_configs_count = 6, |
| 62 | .bus_frequency_configs = { |
| 63 | 11289600, /* 11.2896 MHz */ |
| 64 | 12000 * KHz, /* 12 MHz */ |
| 65 | 12288 * KHz, /* 12.288 MHz */ |
| 66 | 22579200, /* 22.5792 MHz */ |
| 67 | 24000 * KHz, /* 24 MHz */ |
| 68 | 24576 * KHz, /* 24.576 MHz */ |
| 69 | }, |
| 70 | /* Support 8 KHz to 192 KHz sampling frequency */ |
| 71 | .max_sampling_frequency = 192 * KHz, |
| 72 | .min_sampling_frequency = 8 * KHz, |
| 73 | .prepare_channel_behavior = CHANNEL_PREPARE_ANY_FREQUENCY |
| 74 | }; |
| 75 | |
| 76 | static struct soundwire_dpn cs42l42_dp1 = { |
| 77 | .port_max_wordlength = 64, |
| 78 | .port_min_wordlength = 1, |
| 79 | .data_port_type = FULL_DATA_PORT, |
| 80 | .max_grouping_supported = BLOCK_GROUP_COUNT_1, |
| 81 | .simplified_channelprepare_sm = false, |
| 82 | .imp_def_dpn_interrupts_supported = 0, |
| 83 | .min_channel_number = 1, |
| 84 | .max_channel_number = 1, |
| 85 | .modes_supported = MODE_ISOCHRONOUS | MODE_TX_CONTROLLED | |
| 86 | MODE_RX_CONTROLLED | MODE_FULL_ASYNCHRONOUS, |
| 87 | .block_packing_mode = true, |
| 88 | .port_audio_mode_count = 1, |
| 89 | .port_audio_mode_list = { 0 } |
| 90 | }; |
| 91 | |
| 92 | static struct soundwire_dpn cs42l42_dpn = { |
| 93 | .port_max_wordlength = 64, |
| 94 | .port_min_wordlength = 1, |
| 95 | .data_port_type = FULL_DATA_PORT, |
| 96 | .max_grouping_supported = BLOCK_GROUP_COUNT_1, |
| 97 | .simplified_channelprepare_sm = false, |
| 98 | .imp_def_dpn_interrupts_supported = 0, |
| 99 | .min_channel_number = 1, |
| 100 | .max_channel_number = 2, |
| 101 | .modes_supported = MODE_ISOCHRONOUS | MODE_TX_CONTROLLED | |
| 102 | MODE_RX_CONTROLLED | MODE_FULL_ASYNCHRONOUS, |
| 103 | .block_packing_mode = true, |
| 104 | .port_audio_mode_count = 1, |
| 105 | .port_audio_mode_list = { 0 } |
| 106 | }; |
| 107 | |
| 108 | static const struct soundwire_codec cs42l42_codec = { |
| 109 | .slave = &cs42l42_slave, |
| 110 | .dp0_bra_mode = { &cs42l42_dp0_bra_mode }, |
| 111 | .dp0 = &cs42l42_dp0, |
| 112 | .audio_mode = { &cs42l42_audio_mode }, |
| 113 | .dpn = { |
| 114 | { |
| 115 | .port = 1, |
| 116 | .source = &cs42l42_dp1, |
| 117 | }, |
| 118 | { |
| 119 | .port = 2, |
| 120 | .sink = &cs42l42_dpn, |
| 121 | }, |
| 122 | { |
| 123 | .port = 3, |
| 124 | .sink = &cs42l42_dpn, |
| 125 | } |
| 126 | } |
| 127 | }; |
| 128 | |
| 129 | static void soundwire_cs42l42_fill_ssdt(const struct device *dev) |
| 130 | { |
| 131 | struct drivers_soundwire_cs42l42_config *config = dev->chip_info; |
| 132 | const char *scope = acpi_device_scope(dev); |
| 133 | const char *path = acpi_device_path(dev); |
| 134 | struct acpi_dp *dsd; |
| 135 | int gpio_index = 0; |
| 136 | |
| 137 | if (!scope) |
| 138 | return; |
| 139 | |
| 140 | acpigen_write_scope(scope); |
| 141 | acpigen_write_device(acpi_device_name(dev)); |
| 142 | |
| 143 | /* Set codec address IDs. */ |
| 144 | cs42l42_address.link_id = dev->path.generic.id; |
| 145 | cs42l42_address.unique_id = dev->path.generic.subid; |
| 146 | |
| 147 | acpigen_write_ADR_soundwire_device(&cs42l42_address); |
| 148 | acpigen_write_name_string("_DDN", config->desc ? : dev->chip_ops->name); |
| 149 | acpigen_write_STA(acpi_device_status(dev)); |
| 150 | |
| 151 | /* Resources */ |
| 152 | acpigen_write_name("_CRS"); |
| 153 | acpigen_write_resourcetemplate_header(); |
| 154 | |
| 155 | /* Use either Interrupt() or GpioInt() */ |
| 156 | if (config->irq_gpio.pin_count) |
| 157 | acpi_device_write_gpio(&config->irq_gpio); |
| 158 | else |
| 159 | acpi_device_write_interrupt(&config->irq); |
| 160 | |
| 161 | /* for cs42l42 reset gpio */ |
| 162 | if (config->reset_gpio.pin_count) |
| 163 | acpi_device_write_gpio(&config->reset_gpio); |
| 164 | |
| 165 | acpigen_write_resourcetemplate_footer(); |
| 166 | |
| 167 | dsd = acpi_dp_new_table("_DSD"); |
| 168 | |
| 169 | if (config->irq_gpio.pin_count) |
| 170 | acpi_dp_add_gpio(dsd, "irq-gpios", path, |
| 171 | gpio_index++, /* Index = 0 */ |
| 172 | 0, /* Pin = 0 (There is a single pin in the GPIO resource). */ |
| 173 | config->irq_gpio.active_low); |
| 174 | if (config->reset_gpio.pin_count) |
| 175 | acpi_dp_add_gpio(dsd, "reset-gpios", path, |
| 176 | gpio_index++, /* Index = 0 or 1 (if irq gpio is written). */ |
| 177 | 0, /* Pin = 0 (There is a single pin in the GPIO resource). */ |
| 178 | config->reset_gpio.active_low); |
| 179 | acpi_dp_add_integer(dsd, "cirrus,ts-inv", config->ts_inv ? 1 : 0); |
| 180 | acpi_dp_add_integer(dsd, "cirrus,ts-dbnc-rise", config->ts_dbnc_rise); |
| 181 | acpi_dp_add_integer(dsd, "cirrus,ts-dbnc-fall", config->ts_dbnc_fall); |
| 182 | acpi_dp_add_integer(dsd, "cirrus,btn-det-init-dbnce", config->btn_det_init_dbnce); |
| 183 | if (config->btn_det_init_dbnce > 200) { |
| 184 | printk(BIOS_ERR, "%s: Incorrect btn_det_init_dbnce(%d). Using default of 100ms\n", |
| 185 | __func__, config->btn_det_init_dbnce); |
| 186 | config->btn_det_init_dbnce = 100; |
| 187 | } |
| 188 | acpi_dp_add_integer(dsd, "cirrus,btn-det-event-dbnce", config->btn_det_event_dbnce); |
| 189 | if (config->btn_det_event_dbnce > 100) { |
| 190 | printk(BIOS_ERR, "%s: Incorrect btn_det_event_dbnce(%d). Using default of 10ms\n", |
| 191 | __func__, config->btn_det_event_dbnce); |
| 192 | config->btn_det_event_dbnce = 10; |
| 193 | } |
| 194 | acpi_dp_add_integer_array(dsd, "cirrus,bias-lvls", config->bias_lvls, 4); |
| 195 | acpi_dp_add_integer(dsd, "cirrus,hs-bias-ramp-rate", config->hs_bias_ramp_rate); |
| 196 | if (config->hs_bias_sense_disable) |
| 197 | acpi_dp_add_integer(dsd, "cirrus,hs-bias-sense-disable", 1); |
| 198 | |
| 199 | soundwire_gen_codec(dsd, &cs42l42_codec, NULL); |
| 200 | acpi_dp_write(dsd); |
| 201 | |
| 202 | acpigen_pop_len(); /* Device */ |
| 203 | acpigen_pop_len(); /* Scope */ |
| 204 | } |
| 205 | |
| 206 | static const char *soundwire_cs42l42_acpi_name(const struct device *dev) |
| 207 | { |
| 208 | struct drivers_soundwire_cs42l42_config *config = dev->chip_info; |
| 209 | if (config->acpi_name[0] != 0) |
| 210 | return config->acpi_name; |
| 211 | snprintf(config->acpi_name, sizeof(config->acpi_name), "SW%1X%1X", |
| 212 | dev->path.generic.id, dev->path.generic.subid); |
| 213 | return config->acpi_name; |
| 214 | } |
| 215 | |
| 216 | static struct device_operations soundwire_cs42l42_ops = { |
| 217 | .read_resources = noop_read_resources, |
| 218 | .set_resources = noop_set_resources, |
| 219 | .acpi_name = soundwire_cs42l42_acpi_name, |
| 220 | .acpi_fill_ssdt = soundwire_cs42l42_fill_ssdt, |
| 221 | }; |
| 222 | |
| 223 | static void soundwire_cs42l42_enable(struct device *dev) |
| 224 | { |
| 225 | dev->ops = &soundwire_cs42l42_ops; |
| 226 | } |
| 227 | |
| 228 | struct chip_operations drivers_soundwire_cs42l42_ops = { |
| 229 | CHIP_NAME("Cirrus Logic CS42L42 SoundWire Codec") |
| 230 | .enable_dev = soundwire_cs42l42_enable |
| 231 | }; |