| 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_address alc5682_address = { |
| 14 |
.version = SOUNDWIRE_VERSION_1_1, |
| 15 |
.manufacturer_id = MIPI_MFG_ID_REALTEK, |
| 16 |
.part_id = MIPI_DEV_ID_REALTEK_ALC5682, |
| 17 |
.class = MIPI_CLASS_NONE |
| 18 |
}; |
| 19 |
|
| 20 |
static struct soundwire_slave alc5682_slave = { |
| 21 |
.wake_up_unavailable = false, |
| 22 |
.test_mode_supported = false, |
| 23 |
.clock_stop_mode1_supported = true, |
| 24 |
.simplified_clockstopprepare_sm_supported = true, |
| 25 |
.clockstopprepare_hard_reset_behavior = false, |
| 26 |
.highPHY_capable = false, |
| 27 |
.paging_supported = false, |
| 28 |
.bank_delay_supported = false, |
| 29 |
.port15_read_behavior = false, |
| 30 |
.source_port_list = SOUNDWIRE_PORT(1) | SOUNDWIRE_PORT(2) | |
| 31 |
SOUNDWIRE_PORT(3) | SOUNDWIRE_PORT(4), |
| 32 |
.sink_port_list = SOUNDWIRE_PORT(1) | SOUNDWIRE_PORT(2) | |
| 33 |
SOUNDWIRE_PORT(3) | SOUNDWIRE_PORT(4) |
| 34 |
}; |
| 35 |
|
| 36 |
static struct soundwire_bra_mode alc5682_dp0_bra_mode = { |
| 37 |
.bus_frequency_configs_count = 7, |
| 38 |
.bus_frequency_configs = { |
| 39 |
1000 * KHz, |
| 40 |
2400 * KHz, |
| 41 |
3000 * KHz, |
| 42 |
4000 * KHz, |
| 43 |
4800 * KHz, |
| 44 |
9600 * KHz, |
| 45 |
12000 * KHz, |
| 46 |
}, |
| 47 |
.max_data_per_frame = 470, |
| 48 |
.min_us_between_transactions = 0 |
| 49 |
}; |
| 50 |
|
| 51 |
static struct soundwire_dp0 alc5682_dp0 = { |
| 52 |
.port_max_wordlength = 64, |
| 53 |
.port_min_wordlength = 1, |
| 54 |
.bra_imp_def_response_supported = false, |
| 55 |
.simplified_channel_prepare_sm = true, |
| 56 |
.imp_def_dp0_interrupts_supported = 0, |
| 57 |
.imp_def_bpt_supported = true, |
| 58 |
.bra_mode_count = 1, |
| 59 |
.bra_mode_list = { 0 } |
| 60 |
}; |
| 61 |
|
| 62 |
static struct soundwire_audio_mode alc5682_audio_mode = { |
| 63 |
.bus_frequency_configs_count = 7, |
| 64 |
.bus_frequency_configs = { |
| 65 |
1000 * KHz, |
| 66 |
2400 * KHz, |
| 67 |
3000 * KHz, |
| 68 |
4000 * KHz, |
| 69 |
4800 * KHz, |
| 70 |
9600 * KHz, |
| 71 |
12000 * KHz, |
| 72 |
}, |
| 73 |
|
| 74 |
.max_sampling_frequency = 192 * KHz, |
| 75 |
.min_sampling_frequency = 8 * KHz, |
| 76 |
.prepare_channel_behavior = CHANNEL_PREPARE_ANY_FREQUENCY |
| 77 |
}; |
| 78 |
|
| 79 |
static struct soundwire_dpn alc5682_dpn = { |
| 80 |
.port_wordlength_configs_count = 3, |
| 81 |
.port_wordlength_configs = { 16, 20, 24 }, |
| 82 |
.data_port_type = FULL_DATA_PORT, |
| 83 |
.max_grouping_supported = BLOCK_GROUP_COUNT_1, |
| 84 |
.simplified_channelprepare_sm = false, |
| 85 |
.imp_def_dpn_interrupts_supported = 0, |
| 86 |
.min_channel_number = 1, |
| 87 |
.max_channel_number = 2, |
| 88 |
.modes_supported = MODE_ISOCHRONOUS | MODE_TX_CONTROLLED | |
| 89 |
MODE_RX_CONTROLLED | MODE_FULL_ASYNCHRONOUS, |
| 90 |
.block_packing_mode = true, |
| 91 |
.port_audio_mode_count = 1, |
| 92 |
.port_audio_mode_list = { 0 } |
| 93 |
}; |
| 94 |
|
| 95 |
static const struct soundwire_codec alc5682_codec = { |
| 96 |
.slave = &alc5682_slave, |
| 97 |
.dp0_bra_mode = { &alc5682_dp0_bra_mode }, |
| 98 |
.dp0 = &alc5682_dp0, |
| 99 |
.audio_mode = { &alc5682_audio_mode }, |
| 100 |
.dpn = { |
| 101 |
{ |
| 102 |
.port = 1, |
| 103 |
.source = &alc5682_dpn, |
| 104 |
.sink = &alc5682_dpn, |
| 105 |
}, |
| 106 |
{ |
| 107 |
.port = 2, |
| 108 |
.source = &alc5682_dpn, |
| 109 |
.sink = &alc5682_dpn, |
| 110 |
}, |
| 111 |
{ |
| 112 |
.port = 3, |
| 113 |
.source = &alc5682_dpn, |
| 114 |
.sink = &alc5682_dpn, |
| 115 |
}, |
| 116 |
{ |
| 117 |
.port = 4, |
| 118 |
.source = &alc5682_dpn, |
| 119 |
.sink = &alc5682_dpn, |
| 120 |
} |
| 121 |
} |
| 122 |
}; |
| 123 |
|
| 124 |
static void soundwire_alc5682_fill_ssdt(const struct device *dev) |
| 125 |
{ |
| 126 |
struct drivers_soundwire_alc5682_config *config = dev->chip_info; |
| 127 |
const char *scope = acpi_device_scope(dev); |
| 128 |
struct acpi_dp *dsd; |
| 129 |
|
| 130 |
if (!scope) |
| 131 |
return; |
| 132 |
|
| 133 |
acpigen_write_scope(scope); |
| 134 |
acpigen_write_device(acpi_device_name(dev)); |
| 135 |
|
| 136 |
|
| 137 |
alc5682_address.link_id = dev->path.generic.id; |
| 138 |
alc5682_address.unique_id = dev->path.generic.subid; |
| 139 |
|
| 140 |
acpigen_write_ADR_soundwire_device(&alc5682_address); |
| 141 |
acpigen_write_name_string("_DDN", config->desc ? : dev->chip_ops->name); |
| 142 |
acpigen_write_STA(acpi_device_status(dev)); |
| 143 |
|
| 144 |
dsd = acpi_dp_new_table("_DSD"); |
| 145 |
soundwire_gen_codec(dsd, &alc5682_codec, NULL); |
| 146 |
acpi_dp_write(dsd); |
| 147 |
|
| 148 |
acpigen_pop_len(); |
| 149 |
acpigen_pop_len(); |
| 150 |
} |
| 151 |
|
| 152 |
static const char *soundwire_alc5682_acpi_name(const struct device *dev) |
| 153 |
{ |
| 154 |
struct drivers_soundwire_alc5682_config *config = dev->chip_info; |
| 155 |
static char name[5]; |
| 156 |
|
| 157 |
if (config->name) |
| 158 |
return config->name; |
| 159 |
snprintf(name, sizeof(name), "SW%1X%1X", dev->path.generic.id, dev->path.generic.subid); |
| 160 |
return name; |
| 161 |
} |
| 162 |
|
| 163 |
static struct device_operations soundwire_alc5682_ops = { |
| 164 |
.read_resources = noop_read_resources, |
| 165 |
.set_resources = noop_set_resources, |
| 166 |
.acpi_name = soundwire_alc5682_acpi_name, |
| 167 |
.acpi_fill_ssdt = soundwire_alc5682_fill_ssdt, |
| 168 |
}; |
| 169 |
|
| 170 |
static void soundwire_alc5682_enable(struct device *dev) |
| 171 |
{ |
| 172 |
dev->ops = &soundwire_alc5682_ops; |
| 173 |
} |
| 174 |
|
| 175 |
struct chip_operations drivers_soundwire_alc5682_ops = { |
| 176 |
.name = "Realtek ALC5682 SoundWire Codec", |
| 177 |
.enable_dev = soundwire_alc5682_enable |
| 178 |
}; |