blob: a394154002626ad538bfdfe1eea156e17e26f0d5 [file] [log] [blame]
Duncan Lauriee0563cc2020-04-29 14:01:04 -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 Lauriee0563cc2020-04-29 14:01:04 -07007#include <device/soundwire.h>
Julius Werner5ff18082021-08-24 16:03:57 -07008#include <mipi/ids.h>
Duncan Lauriee0563cc2020-04-29 14:01:04 -07009#include <stdio.h>
10
11#include "chip.h"
12
13static struct soundwire_address max98373_address = {
14 .version = SOUNDWIRE_VERSION_1_1,
15 .manufacturer_id = MIPI_MFG_ID_MAXIM,
16 .part_id = MIPI_DEV_ID_MAXIM_MAX98373,
17 .class = MIPI_CLASS_NONE
18};
19
20static struct soundwire_slave max98373_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(3),
31 .sink_port_list = SOUNDWIRE_PORT(1),
32};
33
34static struct soundwire_audio_mode max98373_audio_mode = {
35 /* Bus frequency must be 1/2/4/8 divider of supported input frequencies. */
36 .bus_frequency_configs_count = 27,
37 .bus_frequency_configs = {
38 7680 * KHz, 3840 * KHz, 1920 * KHz, 960 * KHz, /* 7.68 MHz */
39 8400 * KHz, 4200 * KHz, 2100 * KHz, 1050 * KHz, /* 8.4 MHz */
40 9600 * KHz, 4800 * KHz, 2400 * KHz, 1200 * KHz, /* 9.6 MHz */
41 11289600, 5644800, 2822400, 1411200, /* 11.2896 MHz */
42 12000 * KHz, 6000 * KHz, 3000 * KHz, 1500 * KHz, /* 12 MHz */
43 12288 * KHz, 6144 * KHz, 3072 * KHz, 1536 * KHz, /* 12.288 MHz */
44 13000 * KHz, 6500 * KHz, 3250 * KHz /* 13 MHz (no /8) */
45 },
46 /* Support 16 KHz to 96 KHz sampling frequency */
47 .sampling_frequency_configs_count = 8,
48 .sampling_frequency_configs = {
49 16 * KHz,
50 22.05 * KHz,
51 24 * KHz,
52 32 * KHz,
53 44.1 * KHz,
54 48 * KHz,
55 88.2 * KHz,
56 96 * KHz,
57 },
58 .prepare_channel_behavior = CHANNEL_PREPARE_ANY_FREQUENCY
59};
60
61static struct soundwire_dpn max98373_dp1 = {
62 .port_wordlength_configs_count = 1,
63 .port_wordlength_configs = { 32 },
64 .data_port_type = FULL_DATA_PORT,
65 .max_grouping_supported = BLOCK_GROUP_COUNT_1,
66 .simplified_channelprepare_sm = false,
67 .imp_def_dpn_interrupts_supported = 0,
68 .min_channel_number = 1,
69 .max_channel_number = 2,
70 .modes_supported = MODE_ISOCHRONOUS | MODE_TX_CONTROLLED |
71 MODE_RX_CONTROLLED | MODE_FULL_ASYNCHRONOUS,
72 .block_packing_mode = true,
73 .port_audio_mode_count = 1,
74 .port_audio_mode_list = { 0 }
75};
76
77static struct soundwire_dpn max98373_dp3 = {
78 .port_wordlength_configs_count = 1,
79 .port_wordlength_configs = { 16 },
80 .data_port_type = FULL_DATA_PORT,
81 .max_grouping_supported = BLOCK_GROUP_COUNT_1,
82 .simplified_channelprepare_sm = false,
83 .imp_def_dpn_interrupts_supported = 0,
84 .min_channel_number = 1,
85 .max_channel_number = 2,
86 .modes_supported = MODE_ISOCHRONOUS | MODE_TX_CONTROLLED |
87 MODE_RX_CONTROLLED | MODE_FULL_ASYNCHRONOUS,
88 .block_packing_mode = true,
89 .port_audio_mode_count = 1,
90 .port_audio_mode_list = { 0 }
91};
92
93static const struct soundwire_codec max98373_codec = {
94 .slave = &max98373_slave,
95 .audio_mode = { &max98373_audio_mode },
96 .dpn = {
97 {
98 /* Data Input for Speaker Path */
99 .port = 1,
100 .sink = &max98373_dp1
101 },
102 {
103 /* Data Output for I/V Sense ADC Path */
104 .port = 3,
105 .source = &max98373_dp3,
106 }
107 }
108};
109
110static void soundwire_max98373_fill_ssdt(const struct device *dev)
111{
112 struct drivers_soundwire_max98373_config *config = dev->chip_info;
113 const char *scope = acpi_device_scope(dev);
114 struct acpi_dp *dsd;
115
Karthikeyan Ramasubramaniand1c0f952020-11-02 16:26:52 -0700116 if (!scope)
Duncan Lauriee0563cc2020-04-29 14:01:04 -0700117 return;
118
119 acpigen_write_scope(scope);
120 acpigen_write_device(acpi_device_name(dev));
121
122 /* Set codec address IDs. */
123 max98373_address.link_id = dev->path.generic.id;
124 max98373_address.unique_id = dev->path.generic.subid;
125
126 acpigen_write_ADR_soundwire_device(&max98373_address);
127 acpigen_write_name_string("_DDN", config->desc ? : dev->chip_ops->name);
128 acpigen_write_STA(acpi_device_status(dev));
129
130 dsd = acpi_dp_new_table("_DSD");
131 soundwire_gen_codec(dsd, &max98373_codec, NULL);
132 acpi_dp_write(dsd);
133
134 acpigen_pop_len(); /* Device */
135 acpigen_pop_len(); /* Scope */
136}
137
138static const char *soundwire_max98373_acpi_name(const struct device *dev)
139{
140 struct drivers_soundwire_max98373_config *config = dev->chip_info;
141 static char name[5];
142
143 if (config->name)
144 return config->name;
145 snprintf(name, sizeof(name), "SW%1X%1X", dev->path.generic.id, dev->path.generic.subid);
146 return name;
147}
148
149static struct device_operations soundwire_max98373_ops = {
150 .read_resources = noop_read_resources,
151 .set_resources = noop_set_resources,
152 .acpi_name = soundwire_max98373_acpi_name,
153 .acpi_fill_ssdt = soundwire_max98373_fill_ssdt,
154};
155
156static void soundwire_max98373_enable(struct device *dev)
157{
158 dev->ops = &soundwire_max98373_ops;
159}
160
161struct chip_operations drivers_soundwire_max98373_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +0900162 .name = "Maxim MAX98373 SoundWire Codec",
Duncan Lauriee0563cc2020-04-29 14:01:04 -0700163 .enable_dev = soundwire_max98373_enable
164};