drivers/uart: Replace 'unsigned long int' by 'unsigned long'
[coreboot2.git] / src / drivers / soundwire / alc5682 / alc5682.c
blob67ce61c6248f24e78817ad943bdc631a24a28f2a
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 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
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)
36 static 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 */
47 .max_data_per_frame = 470,
48 .min_us_between_transactions = 0
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 }
62 static 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 */
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
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 }
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 = {
102 .port = 1,
103 .source = &alc5682_dpn,
104 .sink = &alc5682_dpn,
107 .port = 2,
108 .source = &alc5682_dpn,
109 .sink = &alc5682_dpn,
112 .port = 3,
113 .source = &alc5682_dpn,
114 .sink = &alc5682_dpn,
117 .port = 4,
118 .source = &alc5682_dpn,
119 .sink = &alc5682_dpn,
124 static void soundwire_alc5682_fill_ssdt(const struct device *dev)
126 struct drivers_soundwire_alc5682_config *config = dev->chip_info;
127 const char *scope = acpi_device_scope(dev);
128 struct acpi_dp *dsd;
130 if (!scope)
131 return;
133 acpigen_write_scope(scope);
134 acpigen_write_device(acpi_device_name(dev));
136 /* Set codec address IDs. */
137 alc5682_address.link_id = dev->path.generic.id;
138 alc5682_address.unique_id = dev->path.generic.subid;
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));
144 dsd = acpi_dp_new_table("_DSD");
145 soundwire_gen_codec(dsd, &alc5682_codec, NULL);
146 acpi_dp_write(dsd);
148 acpigen_pop_len(); /* Device */
149 acpigen_pop_len(); /* Scope */
152 static const char *soundwire_alc5682_acpi_name(const struct device *dev)
154 struct drivers_soundwire_alc5682_config *config = dev->chip_info;
155 static char name[5];
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;
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,
170 static void soundwire_alc5682_enable(struct device *dev)
172 dev->ops = &soundwire_alc5682_ops;
175 struct chip_operations drivers_soundwire_alc5682_ops = {
176 .name = "Realtek ALC5682 SoundWire Codec",
177 .enable_dev = soundwire_alc5682_enable