blob: 67ce61c6248f24e78817ad943bdc631a24a28f2a [file] [log] [blame]
Duncan Laurie73ce9fb2020-04-29 14:25:54 -07001/* 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>
Duncan Laurie73ce9fb2020-04-29 14:25:54 -07007#include <device/soundwire.h>
Julius Werner5ff18082021-08-24 16:03:57 -07008#include <mipi/ids.h>
Duncan Laurie73ce9fb2020-04-29 14:25:54 -07009#include <stdio.h>
10
11#include "chip.h"
12
13static 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
20static 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
36static struct soundwire_bra_mode alc5682_dp0_bra_mode = {
37 .bus_frequency_configs_count = 7,
38 .bus_frequency_configs = {
39 1000 * KHz, /* 1 MHz */
40 2400 * KHz, /* 2.4 MHz */
41 3000 * KHz, /* 3 MHz */
42 4000 * KHz, /* 4 MHz */
43 4800 * KHz, /* 4.8 MHz */
44 9600 * KHz, /* 9.6 MHz */
45 12000 * KHz, /* 12 MHz */
46 },
47 .max_data_per_frame = 470,
48 .min_us_between_transactions = 0
49};
50
51static 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
62static struct soundwire_audio_mode alc5682_audio_mode = {
63 .bus_frequency_configs_count = 7,
64 .bus_frequency_configs = {
65 1000 * KHz, /* 1 MHz */
66 2400 * KHz, /* 2.4 MHz */
67 3000 * KHz, /* 3 MHz */
68 4000 * KHz, /* 4 MHz */
69 4800 * KHz, /* 4.8 MHz */
70 9600 * KHz, /* 9.6 MHz */
71 12000 * KHz, /* 12 MHz */
72 },
73 /* Support 8 KHz to 192 KHz sampling frequency */
74 .max_sampling_frequency = 192 * KHz,
75 .min_sampling_frequency = 8 * KHz,
76 .prepare_channel_behavior = CHANNEL_PREPARE_ANY_FREQUENCY
77};
78
79static 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
95static 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
124static 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
Karthikeyan Ramasubramaniand1c0f952020-11-02 16:26:52 -0700130 if (!scope)
Duncan Laurie73ce9fb2020-04-29 14:25:54 -0700131 return;
132
133 acpigen_write_scope(scope);
134 acpigen_write_device(acpi_device_name(dev));
135
136 /* Set codec address IDs. */
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(); /* Device */
149 acpigen_pop_len(); /* Scope */
150}
151
152static 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
163static 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
170static void soundwire_alc5682_enable(struct device *dev)
171{
172 dev->ops = &soundwire_alc5682_ops;
173}
174
175struct chip_operations drivers_soundwire_alc5682_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +0900176 .name = "Realtek ALC5682 SoundWire Codec",
Duncan Laurie73ce9fb2020-04-29 14:25:54 -0700177 .enable_dev = soundwire_alc5682_enable
178};