blob: 7b90d7834b00cd321c76cb79cd3e3444b75c1ab9 [file] [log] [blame]
Kapil Porwal1fe5fcf2023-02-25 22:19:48 +05301/* 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/path.h>
8#include <device/soundwire.h>
9#include <mipi/ids.h>
10#include <stdio.h>
11
12#include "chip.h"
13
14static struct soundwire_address max98363_address = {
15 .version = SOUNDWIRE_VERSION_1_2,
16 .manufacturer_id = MIPI_MFG_ID_MAXIM,
17 .part_id = MIPI_DEV_ID_MAXIM_MAX98363,
18 .class = MIPI_CLASS_NONE
19};
20
21static struct soundwire_slave max98363_slave = {
22 .wake_up_unavailable = false,
23 .test_mode_supported = false,
24 .clock_stop_mode1_supported = true,
25 .simplified_clockstopprepare_sm_supported = true,
26 .clockstopprepare_hard_reset_behavior = false,
27 .highPHY_capable = false,
28 .paging_supported = false,
29 .bank_delay_supported = false,
30 .port15_read_behavior = false,
31 .source_port_list = 0,
32 .sink_port_list = SOUNDWIRE_PORT(1),
33};
34
35static struct soundwire_audio_mode max98363_audio_mode = {
36 /* Bus frequency must be 2/4/8/16 divider of supported input frequencies. */
37 .bus_frequency_configs_count = 19,
38 .bus_frequency_configs = {
39 9600 * KHz, 4800 * KHz, 2400 * KHz, 1200 * KHz, /* 19.2 MHz */
40 11289600, 5644800, 2822400, 1411200, /* 22.5792 MHz */
41 12000 * KHz, 6000 * KHz, 3000 * KHz, 1500 * KHz, /* 24 MHz */
42 12288 * KHz, 6144 * KHz, 3072 * KHz, 1536 * KHz, /* 24.576 MHz */
43 8000 * KHz, 4000 * KHz, 2000 * KHz, /* 32 MHz (no /2) */
44 },
45 /* Support 16 KHz to 96 KHz sampling frequency */
46 .sampling_frequency_configs_count = 8,
47 .sampling_frequency_configs = {
48 16 * KHz,
49 22.05 * KHz,
50 24 * KHz,
51 32 * KHz,
52 44.1 * KHz,
53 48 * KHz,
54 88.2 * KHz,
55 96 * KHz,
56 },
57 .prepare_channel_behavior = CHANNEL_PREPARE_ANY_FREQUENCY
58};
59
60static struct soundwire_dpn max98363_dp1 = {
61 .port_wordlength_configs_count = 1,
62 .port_wordlength_configs = { 32 },
63 .data_port_type = FULL_DATA_PORT,
64 .max_grouping_supported = BLOCK_GROUP_COUNT_1,
65 .simplified_channelprepare_sm = false,
66 .imp_def_dpn_interrupts_supported = 0,
67 .min_channel_number = 1,
68 .max_channel_number = 1,
69 .modes_supported = MODE_ISOCHRONOUS | MODE_TX_CONTROLLED |
70 MODE_RX_CONTROLLED | MODE_FULL_ASYNCHRONOUS,
71 .block_packing_mode = true,
72 .port_audio_mode_count = 1,
73 .port_audio_mode_list = { 0 }
74};
75
76static const struct soundwire_codec max98363_codec = {
77 .slave = &max98363_slave,
78 .audio_mode = { &max98363_audio_mode },
79 .dpn = {
80 {
81 /* Data Input for Speaker Path */
82 .port = 1,
83 .sink = &max98363_dp1
84 }
85 }
86};
87
88static void soundwire_max98363_fill_ssdt(const struct device *dev)
89{
90 struct drivers_soundwire_max98363_config *config = dev->chip_info;
91 const char *scope = acpi_device_scope(dev);
92 struct acpi_dp *dsd;
93
94 if (!scope)
95 return;
96
97 acpigen_write_scope(scope);
98 acpigen_write_device(acpi_device_name(dev));
99
100 /* Set codec address IDs. */
101 max98363_address.link_id = dev->path.generic.id;
102 max98363_address.unique_id = dev->path.generic.subid;
103
104 acpigen_write_ADR_soundwire_device(&max98363_address);
105 acpigen_write_name_string("_DDN", config->desc ? : dev->chip_ops->name);
106 acpigen_write_STA(acpi_device_status(dev));
107
108 dsd = acpi_dp_new_table("_DSD");
109 soundwire_gen_codec(dsd, &max98363_codec, NULL);
110 acpi_dp_write(dsd);
111
112 acpigen_pop_len(); /* Device */
113 acpigen_pop_len(); /* Scope */
114}
115
116static const char *soundwire_max98363_acpi_name(const struct device *dev)
117{
118 struct drivers_soundwire_max98363_config *config = dev->chip_info;
119 if (config->acpi_name[0] != 0)
120 return config->acpi_name;
121 snprintf(config->acpi_name, sizeof(config->acpi_name), "SW%1X%1X",
122 dev->path.generic.id, dev->path.generic.subid);
123 return config->acpi_name;
124}
125
126static struct device_operations soundwire_max98363_ops = {
127 .read_resources = noop_read_resources,
128 .set_resources = noop_set_resources,
129 .acpi_name = soundwire_max98363_acpi_name,
130 .acpi_fill_ssdt = soundwire_max98363_fill_ssdt,
131};
132
133static void soundwire_max98363_enable(struct device *dev)
134{
135 dev->ops = &soundwire_max98363_ops;
136}
137
138struct chip_operations drivers_soundwire_max98363_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +0900139 .name = "Maxim MAX98363 SoundWire Codec",
Kapil Porwal1fe5fcf2023-02-25 22:19:48 +0530140 .enable_dev = soundwire_max98363_enable
141};