blob: 7d1ac4274f89ed2edea5390334da8420792cd3a4 [file] [log] [blame]
Anil Kumar33b0f152020-10-12 11:39:15 -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>
Anil Kumar33b0f152020-10-12 11:39:15 -07007#include <device/soundwire.h>
Julius Werner5ff18082021-08-24 16:03:57 -07008#include <mipi/ids.h>
Anil Kumar33b0f152020-10-12 11:39:15 -07009#include <stdio.h>
10
11#include "chip.h"
12
13static struct soundwire_address alc711_address = {
14 .version = SOUNDWIRE_VERSION_1_1,
15 .manufacturer_id = MIPI_MFG_ID_REALTEK,
16 .part_id = MIPI_DEV_ID_REALTEK_ALC711,
17 .class = MIPI_CLASS_NONE
18};
19
20static struct soundwire_slave alc711_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(2),
31 .sink_port_list = SOUNDWIRE_PORT(1),
32};
33
34static struct soundwire_audio_mode alc711_audio_mode = {
35 /* Bus frequency must be 1/2/4/8 divider of supported input frequencies. */
36 .bus_frequency_configs_count = 12,
37 .bus_frequency_configs = {
38 9600 * KHz,
39 4800 * KHz,
40 2400 * KHz,
41 1200 * KHz,
42 12000 * KHz,
43 6000 * KHz,
44 3000 * KHz,
45 1500 * KHz,
46 12288 * KHz,
47 6144 * KHz,
48 3072 * KHz,
49 1536 * KHz
50 },
51 /* Support 16 KHz to 192 KHz sampling frequency */
52 .sampling_frequency_configs_count = 9,
53 .sampling_frequency_configs = {
54 16 * KHz,
55 22.05 * KHz,
56 24 * KHz,
57 32 * KHz,
58 44.1 * KHz,
59 48 * KHz,
60 88.2 * KHz,
61 96 * KHz,
62 192 * KHz
63 },
64 .prepare_channel_behavior = CHANNEL_PREPARE_ANY_FREQUENCY
65};
66
67static struct soundwire_dpn alc711_dp = {
68 .port_wordlength_configs_count = 1,
69 .port_wordlength_configs = { 32 },
70 .data_port_type = FULL_DATA_PORT,
71 .max_grouping_supported = BLOCK_GROUP_COUNT_1,
72 .simplified_channelprepare_sm = false,
73 .imp_def_dpn_interrupts_supported = 0,
74 .min_channel_number = 1,
75 .max_channel_number = 2,
76 .modes_supported = MODE_ISOCHRONOUS | MODE_TX_CONTROLLED |
77 MODE_RX_CONTROLLED | MODE_FULL_ASYNCHRONOUS,
78 .block_packing_mode = true,
79 .port_audio_mode_count = 1,
80 .port_audio_mode_list = { 0 }
81};
82
83static const struct soundwire_codec alc711_codec = {
84 .slave = &alc711_slave,
85 .audio_mode = { &alc711_audio_mode },
86 .dpn = {
87 {
88 /* Data Input for Speaker Path */
89 .port = 1,
90 .sink = &alc711_dp
91 },
92 {
93 /* Data Output for DSP Path */
94 .port = 2,
95 .source = &alc711_dp
96 }
97 }
98
99};
100
101static void soundwire_alc711_fill_ssdt(const struct device *dev)
102{
103 struct drivers_soundwire_alc711_config *config = dev->chip_info;
104 const char *scope = acpi_device_scope(dev);
105 struct acpi_dp *dsd;
106
Karthikeyan Ramasubramaniand1c0f952020-11-02 16:26:52 -0700107 if (!scope)
Anil Kumar33b0f152020-10-12 11:39:15 -0700108 return;
109
110 acpigen_write_scope(scope);
111 acpigen_write_device(acpi_device_name(dev));
112
113 /* Set codec address IDs. */
114 alc711_address.link_id = dev->path.generic.id;
115 alc711_address.unique_id = dev->path.generic.subid;
116
117 acpigen_write_ADR_soundwire_device(&alc711_address);
118 acpigen_write_name_string("_DDN", config->desc ? : dev->chip_ops->name);
119 acpigen_write_STA(acpi_device_status(dev));
120
121 dsd = acpi_dp_new_table("_DSD");
122 soundwire_gen_codec(dsd, &alc711_codec, NULL);
123 acpi_dp_write(dsd);
124
125 acpigen_pop_len(); /* Device */
126 acpigen_pop_len(); /* Scope */
127}
128
129static const char *soundwire_alc711_acpi_name(const struct device *dev)
130{
131 struct drivers_soundwire_alc711_config *config = dev->chip_info;
132 static char name[5];
133
134 if (config->name)
135 return config->name;
136 snprintf(name, sizeof(name), "SW%1X%1X", dev->path.generic.id, dev->path.generic.subid);
137 return name;
138}
139
140static struct device_operations soundwire_alc711_ops = {
141 .read_resources = noop_read_resources,
142 .set_resources = noop_set_resources,
143 .acpi_name = soundwire_alc711_acpi_name,
144 .acpi_fill_ssdt = soundwire_alc711_fill_ssdt,
145};
146
147static void soundwire_alc711_enable(struct device *dev)
148{
149 dev->ops = &soundwire_alc711_ops;
150}
151
152struct chip_operations drivers_soundwire_alc711_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +0900153 .name = "Realtek ALC711 SoundWire Codec",
Anil Kumar33b0f152020-10-12 11:39:15 -0700154 .enable_dev = soundwire_alc711_enable
155};