coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
alc5682.c
Go to the documentation of this file.
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/path.h>
8 #include <device/soundwire.h>
9 #include <mipi/ids.h>
10 #include <stdio.h>
11 
12 #include "chip.h"
13 
14 static struct soundwire_address alc5682_address = {
16  .manufacturer_id = MIPI_MFG_ID_REALTEK,
17  .part_id = MIPI_DEV_ID_REALTEK_ALC5682,
18  .class = MIPI_CLASS_NONE
19 };
20 
21 static struct soundwire_slave alc5682_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 = SOUNDWIRE_PORT(1) | SOUNDWIRE_PORT(2) |
33  .sink_port_list = SOUNDWIRE_PORT(1) | SOUNDWIRE_PORT(2) |
35 };
36 
39  .bus_frequency_configs = {
40  1000 * KHz, /* 1 MHz */
41  2400 * KHz, /* 2.4 MHz */
42  3000 * KHz, /* 3 MHz */
43  4000 * KHz, /* 4 MHz */
44  4800 * KHz, /* 4.8 MHz */
45  9600 * KHz, /* 9.6 MHz */
46  12000 * KHz, /* 12 MHz */
47  },
48  .max_data_per_frame = 470,
49  .min_us_between_transactions = 0
50 };
51 
52 static struct soundwire_dp0 alc5682_dp0 = {
53  .port_max_wordlength = 64,
54  .port_min_wordlength = 1,
55  .bra_imp_def_response_supported = false,
56  .simplified_channel_prepare_sm = true,
57  .imp_def_dp0_interrupts_supported = 0,
58  .imp_def_bpt_supported = true,
59  .bra_mode_count = 1,
60  .bra_mode_list = { 0 }
61 };
62 
65  .bus_frequency_configs = {
66  1000 * KHz, /* 1 MHz */
67  2400 * KHz, /* 2.4 MHz */
68  3000 * KHz, /* 3 MHz */
69  4000 * KHz, /* 4 MHz */
70  4800 * KHz, /* 4.8 MHz */
71  9600 * KHz, /* 9.6 MHz */
72  12000 * KHz, /* 12 MHz */
73  },
74  /* Support 8 KHz to 192 KHz sampling frequency */
75  .max_sampling_frequency = 192 * KHz,
76  .min_sampling_frequency = 8 * KHz,
77  .prepare_channel_behavior = CHANNEL_PREPARE_ANY_FREQUENCY
78 };
79 
80 static struct soundwire_dpn alc5682_dpn = {
82  .port_wordlength_configs = { 16, 20, 24 },
83  .data_port_type = FULL_DATA_PORT,
84  .max_grouping_supported = BLOCK_GROUP_COUNT_1,
85  .simplified_channelprepare_sm = false,
86  .imp_def_dpn_interrupts_supported = 0,
87  .min_channel_number = 1,
88  .max_channel_number = 2,
89  .modes_supported = MODE_ISOCHRONOUS | MODE_TX_CONTROLLED |
91  .block_packing_mode = true,
92  .port_audio_mode_count = 1,
93  .port_audio_mode_list = { 0 }
94 };
95 
96 static const struct soundwire_codec alc5682_codec = {
97  .slave = &alc5682_slave,
98  .dp0_bra_mode = { &alc5682_dp0_bra_mode },
99  .dp0 = &alc5682_dp0,
100  .audio_mode = { &alc5682_audio_mode },
101  .dpn = {
102  {
103  .port = 1,
104  .source = &alc5682_dpn,
105  .sink = &alc5682_dpn,
106  },
107  {
108  .port = 2,
109  .source = &alc5682_dpn,
110  .sink = &alc5682_dpn,
111  },
112  {
113  .port = 3,
114  .source = &alc5682_dpn,
115  .sink = &alc5682_dpn,
116  },
117  {
118  .port = 4,
119  .source = &alc5682_dpn,
120  .sink = &alc5682_dpn,
121  }
122  }
123 };
124 
125 static void soundwire_alc5682_fill_ssdt(const struct device *dev)
126 {
128  const char *scope = acpi_device_scope(dev);
129  struct acpi_dp *dsd;
130 
131  if (!scope)
132  return;
133 
134  acpigen_write_scope(scope);
136 
137  /* Set codec address IDs. */
140 
142  acpigen_write_name_string("_DDN", config->desc ? : dev->chip_ops->name);
144 
145  dsd = acpi_dp_new_table("_DSD");
147  acpi_dp_write(dsd);
148 
149  acpigen_pop_len(); /* Device */
150  acpigen_pop_len(); /* Scope */
151 }
152 
153 static const char *soundwire_alc5682_acpi_name(const struct device *dev)
154 {
156  static char name[5];
157 
158  if (config->name)
159  return config->name;
160  snprintf(name, sizeof(name), "SW%1X%1X", dev->path.generic.id, dev->path.generic.subid);
161  return name;
162 }
163 
166  .set_resources = noop_set_resources,
167  .acpi_name = soundwire_alc5682_acpi_name,
168  .acpi_fill_ssdt = soundwire_alc5682_fill_ssdt,
169 };
170 
171 static void soundwire_alc5682_enable(struct device *dev)
172 {
173  dev->ops = &soundwire_alc5682_ops;
174 }
175 
177  CHIP_NAME("Realtek ALC5682 SoundWire Codec")
178  .enable_dev = soundwire_alc5682_enable
179 };
void acpi_dp_write(struct acpi_dp *table)
Definition: device.c:898
int acpi_device_status(const struct device *dev)
Definition: device.c:193
const char * acpi_device_name(const struct device *dev)
Definition: device.c:49
struct acpi_dp * acpi_dp_new_table(const char *name)
Definition: device.c:930
const char * acpi_device_scope(const struct device *dev)
Definition: device.c:158
void soundwire_gen_codec(struct acpi_dp *dsd, const struct soundwire_codec *codec, soundwire_dp_prop_cb dp_prop_cb)
soundwire_gen_codec() - Generate SoundWire properties for codec device.
Definition: soundwire.c:338
void acpigen_pop_len(void)
Definition: acpigen.c:37
void acpigen_write_scope(const char *name)
Definition: acpigen.c:326
void acpigen_write_STA(uint8_t status)
Definition: acpigen.c:783
void acpigen_write_ADR_soundwire_device(const struct soundwire_address *address)
acpigen_write_ADR_soundwire_device() - SoundWire ACPI Device Address Encoding.
Definition: acpigen.c:2144
void acpigen_write_device(const char *name)
Definition: acpigen.c:769
void acpigen_write_name_string(const char *name, const char *string)
Definition: acpigen.c:176
static struct soundwire_bra_mode alc5682_dp0_bra_mode
Definition: alc5682.c:37
struct chip_operations drivers_soundwire_alc5682_ops
Definition: alc5682.c:176
static struct soundwire_slave alc5682_slave
Definition: alc5682.c:21
static void soundwire_alc5682_fill_ssdt(const struct device *dev)
Definition: alc5682.c:125
static const struct soundwire_codec alc5682_codec
Definition: alc5682.c:96
static struct soundwire_audio_mode alc5682_audio_mode
Definition: alc5682.c:63
static const char * soundwire_alc5682_acpi_name(const struct device *dev)
Definition: alc5682.c:153
static struct soundwire_address alc5682_address
Definition: alc5682.c:14
static struct soundwire_dp0 alc5682_dp0
Definition: alc5682.c:52
static struct device_operations soundwire_alc5682_ops
Definition: alc5682.c:164
static struct soundwire_dpn alc5682_dpn
Definition: alc5682.c:80
static void soundwire_alc5682_enable(struct device *dev)
Definition: alc5682.c:171
const char * name
Definition: mmu.c:92
#define KHz
Definition: helpers.h:79
#define MIPI_MFG_ID_REALTEK
Definition: ids.h:21
#define MIPI_DEV_ID_REALTEK_ALC5682
Definition: ids.h:22
#define CHIP_NAME(X)
Definition: device.h:32
static void noop_read_resources(struct device *dev)
Standard device operations function pointers shims.
Definition: device.h:73
static void noop_set_resources(struct device *dev)
Definition: device.h:74
#define SOUNDWIRE_PORT(port)
Definition: soundwire.h:133
@ BLOCK_GROUP_COUNT_1
Definition: soundwire.h:265
@ MIPI_CLASS_NONE
Definition: soundwire.h:70
@ CHANNEL_PREPARE_ANY_FREQUENCY
Definition: soundwire.h:222
@ MODE_ISOCHRONOUS
Definition: soundwire.h:273
@ MODE_RX_CONTROLLED
Definition: soundwire.h:275
@ MODE_TX_CONTROLLED
Definition: soundwire.h:274
@ MODE_FULL_ASYNCHRONOUS
Definition: soundwire.h:276
@ FULL_DATA_PORT
Definition: soundwire.h:258
@ SOUNDWIRE_VERSION_1_1
Definition: soundwire.h:57
enum board_config config
Definition: memory.c:448
#define NULL
Definition: stddef.h:19
const char * name
Definition: device.h:29
void(* read_resources)(struct device *dev)
Definition: device.h:39
struct generic_path generic
Definition: path.h:125
Definition: device.h:107
struct chip_operations * chip_ops
Definition: device.h:144
struct device_path path
Definition: device.h:115
struct device_operations * ops
Definition: device.h:143
DEVTREE_CONST void * chip_info
Definition: device.h:164
unsigned int subid
Definition: path.h:97
unsigned int id
Definition: path.h:96
uint8_t link_id
Definition: soundwire.h:85
enum soundwire_version version
Definition: soundwire.h:84
uint8_t unique_id
Definition: soundwire.h:86
struct soundwire_audio_mode - Properties for each supported Audio Mode.
Definition: soundwire.h:243
size_t bus_frequency_configs_count
Definition: soundwire.h:246
struct soundwire_bra_mode - Bulk Register Access mode properties.
Definition: soundwire.h:354
size_t bus_frequency_configs_count
Definition: soundwire.h:357
struct soundwire_codec - Contains all configuration for a SoundWire codec slave device.
Definition: soundwire.h:419
struct soundwire_slave * slave
Definition: soundwire.h:420
struct soundwire_dp0 - Configuration properties for SoundWire DP0 Data Port.
Definition: soundwire.h:383
unsigned int port_max_wordlength
Definition: soundwire.h:384
struct soundwire_dpn - Configuration properties for SoundWire DPn Data Ports.
Definition: soundwire.h:318
size_t port_wordlength_configs_count
Definition: soundwire.h:321
struct soundwire_slave - SoundWire slave device properties.
Definition: soundwire.h:156
bool wake_up_unavailable
Definition: soundwire.h:157
int snprintf(char *buf, size_t size, const char *fmt,...)
Note: This file is only for POSIX compatibility, and is meant to be chain-included via string....
Definition: vsprintf.c:35