mb/google/brya: Create rull variant
[coreboot2.git] / src / drivers / soundwire / alc711 / alc711.c
blob1a31f0d4e08ce7a68ae32d64c9db14d7fef8e0b5
1 /* SPDX-License-Identifier: GPL-2.0-only */
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>
11 #include "chip.h"
13 static struct soundwire_address alc711_address = {
14 #if CONFIG(DRIVERS_SOUNDWIRE_ALC722)
15 .version = SOUNDWIRE_VERSION_1_2,
16 .part_id = MIPI_DEV_ID_REALTEK_ALC722,
17 .class = MIPI_CLASS_SDCA,
18 #elif CONFIG(DRIVERS_SOUNDWIRE_ALC721)
19 .version = SOUNDWIRE_VERSION_1_2,
20 .part_id = MIPI_DEV_ID_REALTEK_ALC721,
21 .class = MIPI_CLASS_SDCA,
22 #elif CONFIG(DRIVERS_SOUNDWIRE_ALC711)
23 .version = SOUNDWIRE_VERSION_1_1,
24 .part_id = MIPI_DEV_ID_REALTEK_ALC711,
25 .class = MIPI_CLASS_NONE,
26 #else
27 #error "No Realtek SoundWire codec selected"
28 #endif
29 .manufacturer_id = MIPI_MFG_ID_REALTEK,
32 static struct soundwire_slave alc711_slave = {
33 .wake_up_unavailable = false,
34 .test_mode_supported = false,
35 .clock_stop_mode1_supported = true,
36 .simplified_clockstopprepare_sm_supported = true,
37 .clockstopprepare_hard_reset_behavior = false,
38 .highPHY_capable = false,
39 .paging_supported = false,
40 .bank_delay_supported = false,
41 .port15_read_behavior = false,
42 .source_port_list = SOUNDWIRE_PORT(2),
43 .sink_port_list = SOUNDWIRE_PORT(1),
46 static struct soundwire_audio_mode alc711_audio_mode = {
47 /* Bus frequency must be 1/2/4/8 divider of supported input frequencies. */
48 .bus_frequency_configs_count = 12,
49 .bus_frequency_configs = {
50 9600 * KHz,
51 4800 * KHz,
52 2400 * KHz,
53 1200 * KHz,
54 12000 * KHz,
55 6000 * KHz,
56 3000 * KHz,
57 1500 * KHz,
58 12288 * KHz,
59 6144 * KHz,
60 3072 * KHz,
61 1536 * KHz
63 /* Support 16 KHz to 192 KHz sampling frequency */
64 .sampling_frequency_configs_count = 9,
65 .sampling_frequency_configs = {
66 16 * KHz,
67 22.05 * KHz,
68 24 * KHz,
69 32 * KHz,
70 44.1 * KHz,
71 48 * KHz,
72 88.2 * KHz,
73 96 * KHz,
74 192 * KHz
76 .prepare_channel_behavior = CHANNEL_PREPARE_ANY_FREQUENCY
79 static struct soundwire_dpn alc711_dp = {
80 .port_wordlength_configs_count = 1,
81 .port_wordlength_configs = { 32 },
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 }
95 static const struct soundwire_codec alc711_codec = {
96 .slave = &alc711_slave,
97 .audio_mode = { &alc711_audio_mode },
98 .dpn = {
100 /* Data Input for Speaker Path */
101 .port = 1,
102 .sink = &alc711_dp
105 /* Data Output for DSP Path */
106 .port = 2,
107 .source = &alc711_dp
113 static void soundwire_alc711_fill_ssdt(const struct device *dev)
115 struct drivers_soundwire_alc711_config *config = dev->chip_info;
116 const char *scope = acpi_device_scope(dev);
117 struct acpi_dp *dsd;
119 if (!scope)
120 return;
122 acpigen_write_scope(scope);
123 acpigen_write_device(acpi_device_name(dev));
125 /* Set codec address IDs. */
126 alc711_address.link_id = dev->path.generic.id;
127 alc711_address.unique_id = dev->path.generic.subid;
129 acpigen_write_ADR_soundwire_device(&alc711_address);
130 acpigen_write_name_string("_DDN", config->desc ? : dev->chip_ops->name);
131 acpigen_write_STA(acpi_device_status(dev));
133 dsd = acpi_dp_new_table("_DSD");
134 soundwire_gen_codec(dsd, &alc711_codec, NULL);
135 acpi_dp_write(dsd);
137 acpigen_pop_len(); /* Device */
138 acpigen_pop_len(); /* Scope */
141 static const char *soundwire_alc711_acpi_name(const struct device *dev)
143 struct drivers_soundwire_alc711_config *config = dev->chip_info;
144 static char name[5];
146 if (config->name)
147 return config->name;
148 snprintf(name, sizeof(name), "SW%1X%1X", dev->path.generic.id, dev->path.generic.subid);
149 return name;
152 static struct device_operations soundwire_alc711_ops = {
153 .read_resources = noop_read_resources,
154 .set_resources = noop_set_resources,
155 .acpi_name = soundwire_alc711_acpi_name,
156 .acpi_fill_ssdt = soundwire_alc711_fill_ssdt,
159 static void soundwire_alc711_enable(struct device *dev)
161 dev->ops = &soundwire_alc711_ops;
164 struct chip_operations drivers_soundwire_alc711_ops = {
165 #if CONFIG(DRIVERS_SOUNDWIRE_ALC_BASE_7XX)
166 .name = "Realtek ALC 7 Series SoundWire Codec",
167 #else
168 .name = "Unknown",
169 #endif
170 .enable_dev = soundwire_alc711_enable