| 1 |
|
| 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/soundwire.h> |
| 8 |
#include <mipi/ids.h> |
| 9 |
#include <stdio.h> |
| 10 |
|
| 11 |
#include "chip.h" |
| 12 |
|
| 13 |
static struct soundwire_multilane alc711_multilane = { |
| 14 |
}; |
| 15 |
|
| 16 |
static struct soundwire_slave alc711_slave = { |
| 17 |
.wake_up_unavailable = false, |
| 18 |
.test_mode_supported = false, |
| 19 |
.clock_stop_mode1_supported = true, |
| 20 |
.simplified_clockstopprepare_sm_supported = true, |
| 21 |
.clockstopprepare_hard_reset_behavior = false, |
| 22 |
.highPHY_capable = false, |
| 23 |
.paging_supported = false, |
| 24 |
.bank_delay_supported = false, |
| 25 |
.port15_read_behavior = false, |
| 26 |
.source_port_list = SOUNDWIRE_PORT(2), |
| 27 |
.sink_port_list = SOUNDWIRE_PORT(1), |
| 28 |
}; |
| 29 |
|
| 30 |
static struct soundwire_audio_mode alc711_audio_mode = { |
| 31 |
|
| 32 |
.bus_frequency_configs_count = 12, |
| 33 |
.bus_frequency_configs = { |
| 34 |
9600 * KHz, |
| 35 |
4800 * KHz, |
| 36 |
2400 * KHz, |
| 37 |
1200 * KHz, |
| 38 |
12000 * KHz, |
| 39 |
6000 * KHz, |
| 40 |
3000 * KHz, |
| 41 |
1500 * KHz, |
| 42 |
12288 * KHz, |
| 43 |
6144 * KHz, |
| 44 |
3072 * KHz, |
| 45 |
1536 * KHz |
| 46 |
}, |
| 47 |
|
| 48 |
.sampling_frequency_configs_count = 9, |
| 49 |
.sampling_frequency_configs = { |
| 50 |
16 * KHz, |
| 51 |
22.05 * KHz, |
| 52 |
24 * KHz, |
| 53 |
32 * KHz, |
| 54 |
44.1 * KHz, |
| 55 |
48 * KHz, |
| 56 |
88.2 * KHz, |
| 57 |
96 * KHz, |
| 58 |
192 * KHz |
| 59 |
}, |
| 60 |
.prepare_channel_behavior = CHANNEL_PREPARE_ANY_FREQUENCY |
| 61 |
}; |
| 62 |
|
| 63 |
static struct soundwire_dpn alc711_dp = { |
| 64 |
.port_wordlength_configs_count = 1, |
| 65 |
.port_wordlength_configs = { 32 }, |
| 66 |
.data_port_type = FULL_DATA_PORT, |
| 67 |
.max_grouping_supported = BLOCK_GROUP_COUNT_1, |
| 68 |
.simplified_channelprepare_sm = false, |
| 69 |
.imp_def_dpn_interrupts_supported = 0, |
| 70 |
.min_channel_number = 1, |
| 71 |
.max_channel_number = 2, |
| 72 |
.modes_supported = MODE_ISOCHRONOUS | MODE_TX_CONTROLLED | |
| 73 |
MODE_RX_CONTROLLED | MODE_FULL_ASYNCHRONOUS, |
| 74 |
.block_packing_mode = true, |
| 75 |
.port_audio_mode_count = 1, |
| 76 |
.port_audio_mode_list = { 0 } |
| 77 |
}; |
| 78 |
|
| 79 |
static const struct soundwire_codec alc711_codec = { |
| 80 |
.slave = &alc711_slave, |
| 81 |
.audio_mode = { &alc711_audio_mode }, |
| 82 |
.dpn = { |
| 83 |
{ |
| 84 |
|
| 85 |
.port = 1, |
| 86 |
.sink = &alc711_dp |
| 87 |
}, |
| 88 |
{ |
| 89 |
|
| 90 |
.port = 2, |
| 91 |
.source = &alc711_dp |
| 92 |
} |
| 93 |
}, |
| 94 |
.multilane = &alc711_multilane |
| 95 |
|
| 96 |
}; |
| 97 |
|
| 98 |
static void soundwire_alc711_fill_ssdt(const struct device *dev) |
| 99 |
{ |
| 100 |
struct drivers_soundwire_alc711_config *config = dev->chip_info; |
| 101 |
const char *scope = acpi_device_scope(dev); |
| 102 |
struct acpi_dp *dsd; |
| 103 |
size_t lane_mapping_count, audio_mode_count; |
| 104 |
|
| 105 |
if (!scope) |
| 106 |
return; |
| 107 |
|
| 108 |
acpigen_write_scope(scope); |
| 109 |
acpigen_write_device(acpi_device_name(dev)); |
| 110 |
|
| 111 |
|
| 112 |
config->alc711_address.link_id = dev->path.generic.id; |
| 113 |
config->alc711_address.unique_id = dev->path.generic.subid; |
| 114 |
config->alc711_address.manufacturer_id = MIPI_MFG_ID_REALTEK; |
| 115 |
|
| 116 |
acpigen_write_ADR_soundwire_device(&config->alc711_address); |
| 117 |
acpigen_write_name_string("_DDN", config->desc ? : dev->chip_ops->name); |
| 118 |
acpigen_write_STA(acpi_device_status(dev)); |
| 119 |
|
| 120 |
|
| 121 |
lane_mapping_count = MIN(ARRAY_SIZE(config->multilane.lane_mapping), SOUNDWIRE_MAX_LANE); |
| 122 |
if (lane_mapping_count > 0) { |
| 123 |
alc711_multilane.lane_mapping_count = lane_mapping_count; |
| 124 |
memcpy(&alc711_multilane.lane_mapping, &config->multilane.lane_mapping, |
| 125 |
sizeof(struct soundwire_multilane_map) * lane_mapping_count); |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
audio_mode_count = MIN(ARRAY_SIZE(config->audio_mode), SOUNDWIRE_MAX_MODE); |
| 130 |
if (audio_mode_count > 0) |
| 131 |
|
| 132 |
memcpy(&alc711_audio_mode, &config->audio_mode, sizeof(struct soundwire_audio_mode)); |
| 133 |
|
| 134 |
|
| 135 |
if (config->disable_clkstop_sm_support) |
| 136 |
alc711_slave.simplified_clockstopprepare_sm_supported = false; |
| 137 |
|
| 138 |
dsd = acpi_dp_new_table("_DSD"); |
| 139 |
soundwire_gen_codec(dsd, &alc711_codec, NULL); |
| 140 |
acpi_dp_write(dsd); |
| 141 |
|
| 142 |
acpigen_pop_len(); |
| 143 |
acpigen_pop_len(); |
| 144 |
} |
| 145 |
|
| 146 |
static const char *soundwire_alc711_acpi_name(const struct device *dev) |
| 147 |
{ |
| 148 |
struct drivers_soundwire_alc711_config *config = dev->chip_info; |
| 149 |
static char name[5]; |
| 150 |
|
| 151 |
if (config->name) |
| 152 |
return config->name; |
| 153 |
snprintf(name, sizeof(name), "SW%1X%1X", dev->path.generic.id, dev->path.generic.subid); |
| 154 |
return name; |
| 155 |
} |
| 156 |
|
| 157 |
static struct device_operations soundwire_alc711_ops = { |
| 158 |
.read_resources = noop_read_resources, |
| 159 |
.set_resources = noop_set_resources, |
| 160 |
.acpi_name = soundwire_alc711_acpi_name, |
| 161 |
.acpi_fill_ssdt = soundwire_alc711_fill_ssdt, |
| 162 |
}; |
| 163 |
|
| 164 |
static void soundwire_alc711_enable(struct device *dev) |
| 165 |
{ |
| 166 |
dev->ops = &soundwire_alc711_ops; |
| 167 |
} |
| 168 |
|
| 169 |
struct chip_operations drivers_soundwire_alc711_ops = { |
| 170 |
#if CONFIG(DRIVERS_SOUNDWIRE_ALC_BASE_7XX) |
| 171 |
.name = "Realtek ALC 7 Series SoundWire Codec", |
| 172 |
#else |
| 173 |
.name = "Unknown", |
| 174 |
#endif |
| 175 |
.enable_dev = soundwire_alc711_enable |
| 176 |
}; |