| 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_slave alc1320_slave = { |
| 14 |
.wake_up_unavailable = false, |
| 15 |
.test_mode_supported = false, |
| 16 |
.clock_stop_mode1_supported = true, |
| 17 |
.simplified_clockstopprepare_sm_supported = true, |
| 18 |
.clockstopprepare_hard_reset_behavior = false, |
| 19 |
.highPHY_capable = false, |
| 20 |
.paging_supported = false, |
| 21 |
.bank_delay_supported = false, |
| 22 |
.port15_read_behavior = false, |
| 23 |
.source_port_list = SOUNDWIRE_PORT(2) | SOUNDWIRE_PORT(4), |
| 24 |
.sink_port_list = SOUNDWIRE_PORT(1) |
| 25 |
}; |
| 26 |
|
| 27 |
static struct soundwire_audio_mode alc1320_audio_mode = { |
| 28 |
|
| 29 |
.bus_frequency_configs_count = 20, |
| 30 |
.bus_frequency_configs = { |
| 31 |
9600 * KHz, 4800 * KHz, 2400 * KHz, 1200 * KHz, |
| 32 |
11289600, 5644800, 2822400, 1411200, |
| 33 |
12000 * KHz, 6000 * KHz, 3000 * KHz, 1500 * KHz, |
| 34 |
12288 * KHz, 6144 * KHz, 3072 * KHz, 1536 * KHz, |
| 35 |
16000 * KHz, 8000 * KHz, 4000 * KHz, 2000 * KHz, |
| 36 |
}, |
| 37 |
|
| 38 |
.sampling_frequency_configs_count = 6, |
| 39 |
.sampling_frequency_configs = { |
| 40 |
16 * KHz, |
| 41 |
32 * KHz, |
| 42 |
44.1 * KHz, |
| 43 |
48 * KHz, |
| 44 |
96 * KHz, |
| 45 |
192 * KHz, |
| 46 |
}, |
| 47 |
.prepare_channel_behavior = CHANNEL_PREPARE_ANY_FREQUENCY |
| 48 |
}; |
| 49 |
|
| 50 |
static struct soundwire_dpn alc1320_dp1 = { |
| 51 |
.port_wordlength_configs_count = 1, |
| 52 |
.port_wordlength_configs = { 32 }, |
| 53 |
.data_port_type = FULL_DATA_PORT, |
| 54 |
.max_grouping_supported = BLOCK_GROUP_COUNT_1, |
| 55 |
.simplified_channelprepare_sm = false, |
| 56 |
.imp_def_dpn_interrupts_supported = 0, |
| 57 |
.min_channel_number = 1, |
| 58 |
.max_channel_number = 2, |
| 59 |
.modes_supported = MODE_ISOCHRONOUS | MODE_TX_CONTROLLED | |
| 60 |
MODE_RX_CONTROLLED | MODE_FULL_ASYNCHRONOUS, |
| 61 |
.block_packing_mode = true, |
| 62 |
.port_audio_mode_count = 1, |
| 63 |
.port_audio_mode_list = { 0 } |
| 64 |
}; |
| 65 |
|
| 66 |
static const struct soundwire_codec alc1320_codec = { |
| 67 |
.slave = &alc1320_slave, |
| 68 |
.audio_mode = { &alc1320_audio_mode }, |
| 69 |
.dpn = { |
| 70 |
{ |
| 71 |
|
| 72 |
.port = 1, |
| 73 |
.sink = &alc1320_dp1 |
| 74 |
}, |
| 75 |
{ |
| 76 |
|
| 77 |
.port = 2, |
| 78 |
.source = &alc1320_dp1 |
| 79 |
}, |
| 80 |
{ |
| 81 |
|
| 82 |
.port = 4, |
| 83 |
.source = &alc1320_dp1 |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
}; |
| 88 |
|
| 89 |
static void soundwire_alc1320_fill_ssdt(const struct device *dev) |
| 90 |
{ |
| 91 |
struct drivers_soundwire_alc1320_config *config = dev->chip_info; |
| 92 |
const char *scope = acpi_device_scope(dev); |
| 93 |
struct acpi_dp *dsd; |
| 94 |
|
| 95 |
if (!dev->enabled || !scope) |
| 96 |
return; |
| 97 |
|
| 98 |
acpigen_write_scope(scope); |
| 99 |
acpigen_write_device(acpi_device_name(dev)); |
| 100 |
|
| 101 |
|
| 102 |
config->alc1320_address.link_id = dev->path.generic.id; |
| 103 |
config->alc1320_address.unique_id = dev->path.generic.subid; |
| 104 |
config->alc1320_address.manufacturer_id = MIPI_MFG_ID_REALTEK; |
| 105 |
|
| 106 |
acpigen_write_ADR_soundwire_device(&config->alc1320_address); |
| 107 |
acpigen_write_name_string("_DDN", config->desc ? : dev->chip_ops->name); |
| 108 |
acpigen_write_STA(acpi_device_status(dev)); |
| 109 |
|
| 110 |
dsd = acpi_dp_new_table("_DSD"); |
| 111 |
soundwire_gen_codec(dsd, &alc1320_codec, NULL); |
| 112 |
acpi_dp_write(dsd); |
| 113 |
|
| 114 |
acpigen_pop_len(); |
| 115 |
acpigen_pop_len(); |
| 116 |
} |
| 117 |
|
| 118 |
static const char *soundwire_alc1320_acpi_name(const struct device *dev) |
| 119 |
{ |
| 120 |
struct drivers_soundwire_alc1320_config *config = dev->chip_info; |
| 121 |
static char name[5]; |
| 122 |
|
| 123 |
if (config->name) |
| 124 |
return config->name; |
| 125 |
snprintf(name, sizeof(name), "SW%1X%1X", dev->path.generic.id, dev->path.generic.subid); |
| 126 |
return name; |
| 127 |
} |
| 128 |
|
| 129 |
static struct device_operations soundwire_alc1320_ops = { |
| 130 |
.read_resources = noop_read_resources, |
| 131 |
.set_resources = noop_set_resources, |
| 132 |
.acpi_name = soundwire_alc1320_acpi_name, |
| 133 |
.acpi_fill_ssdt = soundwire_alc1320_fill_ssdt, |
| 134 |
}; |
| 135 |
|
| 136 |
static void soundwire_alc1320_enable(struct device *dev) |
| 137 |
{ |
| 138 |
dev->ops = &soundwire_alc1320_ops; |
| 139 |
} |
| 140 |
|
| 141 |
struct chip_operations drivers_soundwire_alc1320_ops = { |
| 142 |
.name = "Realtek ALC1320 SoundWire Codec", |
| 143 |
.enable_dev = soundwire_alc1320_enable |
| 144 |
}; |