Anil Kumar | d7c31d1 | 2020-09-18 15:30:56 -0700 | [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> |
Anil Kumar | d7c31d1 | 2020-09-18 15:30:56 -0700 | [diff] [blame] | 8 | #include <device/soundwire.h> |
Julius Werner | 5ff1808 | 2021-08-24 16:03:57 -0700 | [diff] [blame] | 9 | #include <mipi/ids.h> |
Anil Kumar | d7c31d1 | 2020-09-18 15:30:56 -0700 | [diff] [blame] | 10 | #include <stdio.h> |
| 11 | |
| 12 | #include "chip.h" |
| 13 | |
| 14 | static struct soundwire_address alc1308_address = { |
| 15 | .version = SOUNDWIRE_VERSION_1_1, |
| 16 | .manufacturer_id = MIPI_MFG_ID_REALTEK, |
| 17 | .part_id = MIPI_DEV_ID_REALTEK_ALC1308, |
| 18 | .class = MIPI_CLASS_NONE |
| 19 | }; |
| 20 | |
| 21 | static struct soundwire_slave alc1308_slave = { |
| 22 | .wake_up_unavailable = false, |
| 23 | .test_mode_supported = false, |
| 24 | .clock_stop_mode1_supported = true, |
| 25 | .simplified_clockstopprepare_sm_supported = true, |
| 26 | .clockstopprepare_hard_reset_behavior = false, |
| 27 | .highPHY_capable = false, |
| 28 | .paging_supported = false, |
| 29 | .bank_delay_supported = false, |
| 30 | .port15_read_behavior = false, |
| 31 | .source_port_list = SOUNDWIRE_PORT(2) | SOUNDWIRE_PORT(4), |
| 32 | .sink_port_list = SOUNDWIRE_PORT(1) |
| 33 | }; |
| 34 | |
| 35 | static struct soundwire_audio_mode alc1308_audio_mode = { |
| 36 | /* Bus frequency must be 1/2/4/8 divider of supported input frequencies. */ |
| 37 | .bus_frequency_configs_count = 12, |
| 38 | .bus_frequency_configs = { |
| 39 | 9600 * KHz, 4800 * KHz, 2400 * KHz, 1200 * KHz, /* 9.6 MHz */ |
| 40 | 12000 * KHz, 6000 * KHz, 3000 * KHz, 1500 * KHz, /* 12 MHz */ |
| 41 | 12288 * KHz, 6144 * KHz, 3072 * KHz, 1536 * KHz /* 12.288 MHz */ |
| 42 | }, |
| 43 | /* Support 16 KHz to 96 KHz sampling frequency */ |
| 44 | .sampling_frequency_configs_count = 8, |
| 45 | .sampling_frequency_configs = { |
| 46 | 16 * KHz, |
| 47 | 22.05 * KHz, |
| 48 | 24 * KHz, |
| 49 | 32 * KHz, |
| 50 | 44.1 * KHz, |
| 51 | 48 * KHz, |
| 52 | 88.2 * KHz, |
| 53 | 96 * KHz, |
| 54 | }, |
| 55 | .prepare_channel_behavior = CHANNEL_PREPARE_ANY_FREQUENCY |
| 56 | }; |
| 57 | |
| 58 | static struct soundwire_dpn alc1308_dp1 = { |
| 59 | .port_wordlength_configs_count = 1, |
| 60 | .port_wordlength_configs = { 32 }, |
| 61 | .data_port_type = FULL_DATA_PORT, |
| 62 | .max_grouping_supported = BLOCK_GROUP_COUNT_1, |
| 63 | .simplified_channelprepare_sm = false, |
| 64 | .imp_def_dpn_interrupts_supported = 0, |
| 65 | .min_channel_number = 1, |
| 66 | .max_channel_number = 2, |
| 67 | .modes_supported = MODE_ISOCHRONOUS | MODE_TX_CONTROLLED | |
| 68 | MODE_RX_CONTROLLED | MODE_FULL_ASYNCHRONOUS, |
| 69 | .block_packing_mode = true, |
| 70 | .port_audio_mode_count = 1, |
| 71 | .port_audio_mode_list = { 0 } |
| 72 | }; |
| 73 | |
| 74 | static const struct soundwire_codec alc1308_codec = { |
| 75 | .slave = &alc1308_slave, |
| 76 | .audio_mode = { &alc1308_audio_mode }, |
| 77 | .dpn = { |
| 78 | { |
| 79 | /* Data Input for Speaker Path */ |
| 80 | .port = 1, |
| 81 | .sink = &alc1308_dp1 |
| 82 | }, |
| 83 | { |
| 84 | /* Data out for I.V sensing */ |
| 85 | .port = 2, |
| 86 | .source = &alc1308_dp1 |
| 87 | }, |
| 88 | { |
| 89 | /* Data out for I.V sensing */ |
| 90 | .port = 4, |
| 91 | .source = &alc1308_dp1 |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | }; |
| 96 | |
| 97 | static void soundwire_alc1308_fill_ssdt(const struct device *dev) |
| 98 | { |
| 99 | struct drivers_soundwire_alc1308_config *config = dev->chip_info; |
| 100 | const char *scope = acpi_device_scope(dev); |
| 101 | struct acpi_dp *dsd; |
| 102 | |
| 103 | if (!dev->enabled || !scope) |
| 104 | return; |
| 105 | |
| 106 | acpigen_write_scope(scope); |
| 107 | acpigen_write_device(acpi_device_name(dev)); |
| 108 | |
| 109 | /* Set codec address IDs. */ |
| 110 | alc1308_address.link_id = dev->path.generic.id; |
| 111 | alc1308_address.unique_id = dev->path.generic.subid; |
| 112 | |
| 113 | acpigen_write_ADR_soundwire_device(&alc1308_address); |
| 114 | acpigen_write_name_string("_DDN", config->desc ? : dev->chip_ops->name); |
| 115 | acpigen_write_STA(acpi_device_status(dev)); |
| 116 | |
| 117 | dsd = acpi_dp_new_table("_DSD"); |
| 118 | soundwire_gen_codec(dsd, &alc1308_codec, NULL); |
| 119 | acpi_dp_write(dsd); |
| 120 | |
| 121 | acpigen_pop_len(); /* Device */ |
| 122 | acpigen_pop_len(); /* Scope */ |
| 123 | } |
| 124 | |
| 125 | static const char *soundwire_alc1308_acpi_name(const struct device *dev) |
| 126 | { |
| 127 | struct drivers_soundwire_alc1308_config *config = dev->chip_info; |
| 128 | static char name[5]; |
| 129 | |
| 130 | if (config->name) |
| 131 | return config->name; |
| 132 | snprintf(name, sizeof(name), "SW%1X%1X", dev->path.generic.id, dev->path.generic.subid); |
| 133 | return name; |
| 134 | } |
| 135 | |
| 136 | static struct device_operations soundwire_alc1308_ops = { |
| 137 | .read_resources = noop_read_resources, |
| 138 | .set_resources = noop_set_resources, |
| 139 | .acpi_name = soundwire_alc1308_acpi_name, |
| 140 | .acpi_fill_ssdt = soundwire_alc1308_fill_ssdt, |
| 141 | }; |
| 142 | |
| 143 | static void soundwire_alc1308_enable(struct device *dev) |
| 144 | { |
| 145 | dev->ops = &soundwire_alc1308_ops; |
| 146 | } |
| 147 | |
| 148 | struct chip_operations drivers_soundwire_alc1308_ops = { |
| 149 | CHIP_NAME("Realtek ALC1308 SoundWire Codec") |
| 150 | .enable_dev = soundwire_alc1308_enable |
| 151 | }; |