xref: /aosp_15_r20/external/coreboot/src/drivers/soundwire/alc1308/alc1308.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* 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>
7 #include <device/soundwire.h>
8 #include <mipi/ids.h>
9 #include <stdio.h>
10 
11 #include "chip.h"
12 
13 static struct soundwire_address alc1308_address = {
14 	.version = SOUNDWIRE_VERSION_1_1,
15 	.manufacturer_id = MIPI_MFG_ID_REALTEK,
16 	.part_id = MIPI_DEV_ID_REALTEK_ALC1308,
17 	.class = MIPI_CLASS_NONE
18 };
19 
20 static struct soundwire_slave alc1308_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) | SOUNDWIRE_PORT(4),
31 	.sink_port_list = SOUNDWIRE_PORT(1)
32 };
33 
34 static struct soundwire_audio_mode alc1308_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,  4800 * KHz, 2400 * KHz, 1200 * KHz, /* 9.6 MHz */
39 		12000 * KHz, 6000 * KHz, 3000 * KHz, 1500 * KHz,  /* 12 MHz */
40 		12288 * KHz, 6144 * KHz, 3072 * KHz, 1536 * KHz  /* 12.288 MHz */
41 	},
42 	/* Support 16 KHz to 96 KHz sampling frequency */
43 	.sampling_frequency_configs_count = 8,
44 	.sampling_frequency_configs = {
45 		16 * KHz,
46 		22.05 * KHz,
47 		24 * KHz,
48 		32 * KHz,
49 		44.1 * KHz,
50 		48 * KHz,
51 		88.2 * KHz,
52 		96 * KHz,
53 	},
54 	.prepare_channel_behavior = CHANNEL_PREPARE_ANY_FREQUENCY
55 };
56 
57 static struct soundwire_dpn alc1308_dp1 = {
58 	.port_wordlength_configs_count = 1,
59 	.port_wordlength_configs = { 32 },
60 	.data_port_type = FULL_DATA_PORT,
61 	.max_grouping_supported = BLOCK_GROUP_COUNT_1,
62 	.simplified_channelprepare_sm = false,
63 	.imp_def_dpn_interrupts_supported = 0,
64 	.min_channel_number = 1,
65 	.max_channel_number = 2,
66 	.modes_supported = MODE_ISOCHRONOUS | MODE_TX_CONTROLLED |
67 			   MODE_RX_CONTROLLED | MODE_FULL_ASYNCHRONOUS,
68 	.block_packing_mode = true,
69 	.port_audio_mode_count = 1,
70 	.port_audio_mode_list = { 0 }
71 };
72 
73 static const struct soundwire_codec alc1308_codec = {
74 	.slave = &alc1308_slave,
75 	.audio_mode = { &alc1308_audio_mode },
76 	.dpn = {
77 		{
78 			/* Data Input for Speaker Path */
79 			.port = 1,
80 			.sink = &alc1308_dp1
81 		},
82 		{
83 			/* Data out for I.V sensing */
84 			.port = 2,
85 			.source = &alc1308_dp1
86 		},
87 		{
88 			/* Data out for I.V sensing */
89 			.port = 4,
90 			.source = &alc1308_dp1
91 		}
92 	}
93 
94 };
95 
soundwire_alc1308_fill_ssdt(const struct device * dev)96 static void soundwire_alc1308_fill_ssdt(const struct device *dev)
97 {
98 	struct drivers_soundwire_alc1308_config *config = dev->chip_info;
99 	const char *scope = acpi_device_scope(dev);
100 	struct acpi_dp *dsd;
101 
102 	if (!dev->enabled || !scope)
103 		return;
104 
105 	acpigen_write_scope(scope);
106 	acpigen_write_device(acpi_device_name(dev));
107 
108 	/* Set codec address IDs. */
109 	alc1308_address.link_id = dev->path.generic.id;
110 	alc1308_address.unique_id = dev->path.generic.subid;
111 
112 	acpigen_write_ADR_soundwire_device(&alc1308_address);
113 	acpigen_write_name_string("_DDN", config->desc ? : dev->chip_ops->name);
114 	acpigen_write_STA(acpi_device_status(dev));
115 
116 	dsd = acpi_dp_new_table("_DSD");
117 	soundwire_gen_codec(dsd, &alc1308_codec, NULL);
118 	acpi_dp_write(dsd);
119 
120 	acpigen_pop_len(); /* Device */
121 	acpigen_pop_len(); /* Scope */
122 }
123 
soundwire_alc1308_acpi_name(const struct device * dev)124 static const char *soundwire_alc1308_acpi_name(const struct device *dev)
125 {
126 	struct drivers_soundwire_alc1308_config *config = dev->chip_info;
127 	static char name[5];
128 
129 	if (config->name)
130 		return config->name;
131 	snprintf(name, sizeof(name), "SW%1X%1X", dev->path.generic.id, dev->path.generic.subid);
132 	return name;
133 }
134 
135 static struct device_operations soundwire_alc1308_ops = {
136 	.read_resources		= noop_read_resources,
137 	.set_resources		= noop_set_resources,
138 	.acpi_name		= soundwire_alc1308_acpi_name,
139 	.acpi_fill_ssdt		= soundwire_alc1308_fill_ssdt,
140 };
141 
soundwire_alc1308_enable(struct device * dev)142 static void soundwire_alc1308_enable(struct device *dev)
143 {
144 	dev->ops = &soundwire_alc1308_ops;
145 }
146 
147 struct chip_operations drivers_soundwire_alc1308_ops = {
148 	.name = "Realtek ALC1308 SoundWire Codec",
149 	.enable_dev = soundwire_alc1308_enable
150 };
151