Skip to content

Commit de2c2c4

Browse files
plbossartbardliao
authored andcommitted
ASoC: SDCA: add initial module
Add new module for SDCA (SoundWire Device Class for Audio) support. For now just add a parser to identify the SDCA revision and the function mask. Note that the SDCA definitions and related MIPI DisCo properties are defined only for ACPI platforms and extracted with _DSD helpers. There is currently no support for Device Tree in the specification, the 'depends on ACPI' reflects this design limitation. This might change in a future revision of the specification but for SDCA 1.0 ACPI is the only supported type of platform firmware. The SDCA library is defined with static inline fallbacks, which will allow for unconditional addition of SDCA support in common parts of the code. The design follows a four-step process: 1) Basic information related to Functions is extracted from MIPI DisCo tables and stored in the 'struct sdw_slave'. Devm_ based memory allocation is not allowed at this point prior to a driver probe, so we only store the function node, address and type. 2) When a codec driver probes, it will register subdevices for each Function identified in phase 1) 3) a driver will probe for each subdevice and addition parsing/memory allocation takes place at this level. devm_ based allocation is highly encouraged to make error handling manageable. 4) Before the peripheral device becomes physically attached, register access is not permitted and the regmaps are cache-only. When peripheral device is enumerated, the bus level uses the 'update_status' notification; after optional device-level initialization, the codec driver will notify each of the subdevices so that they can start interacting with the hardware. Note that the context extracted in 1) should be arguably be handled completely in the codec driver probe. That would however make it difficult to use the ACPI information for machine quirks, and e.g. select different machine driver and topologies as done for the RT712_VB handling later in the series. To make the implementation of quirks simpler, this patchset extracts a minimal amount of context (interface revision and number/type of Functions) before the codec driver probe, and stores this context in the scope of the 'struct sdw_slave'. The SDCA library can also be used in a vendor-specific driver without creating subdevices, e.g. to retrieve the 'initialization-table' values to write platform-specific values as needed. For more technical details, the SDCA specification is available for public downloads at https://www.mipi.org/mipi-sdca-v1-0-download Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
1 parent ca2a06c commit de2c2c4

9 files changed

Lines changed: 327 additions & 0 deletions

File tree

include/linux/soundwire/sdw.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/irqdomain.h>
1111
#include <linux/mod_devicetable.h>
1212
#include <linux/bitfield.h>
13+
#include <sound/sdca.h>
1314

1415
struct sdw_bus;
1516
struct sdw_slave;
@@ -647,6 +648,7 @@ struct sdw_slave_ops {
647648
* @is_mockup_device: status flag used to squelch errors in the command/control
648649
* protocol for SoundWire mockup devices
649650
* @sdw_dev_lock: mutex used to protect callbacks/remove races
651+
* @sdca_data: structure containing all device data for SDCA helpers
650652
*/
651653
struct sdw_slave {
652654
struct sdw_slave_id id;
@@ -670,6 +672,7 @@ struct sdw_slave {
670672
bool first_interrupt_done;
671673
bool is_mockup_device;
672674
struct mutex sdw_dev_lock; /* protect callbacks/remove races */
675+
struct sdca_device_data sdca_data;
673676
};
674677

675678
#define dev_to_sdw_dev(_dev) container_of(_dev, struct sdw_slave, dev)

include/sound/sdca.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
2+
/*
3+
* The MIPI SDCA specification is available for public downloads at
4+
* https://www.mipi.org/mipi-sdca-v1-0-download
5+
*
6+
* Copyright(c) 2024 Intel Corporation
7+
*/
8+
9+
#ifndef __SDCA_H__
10+
#define __SDCA_H__
11+
12+
struct sdw_slave;
13+
14+
#define SDCA_MAX_FUNCTION_COUNT 8
15+
16+
/**
17+
* sdca_device_desc - short descriptor for an SDCA Function
18+
* @adr: ACPI address (used for SDCA register access)
19+
* @type: Function topology type
20+
* @name: human-readable string
21+
*/
22+
struct sdca_function_desc {
23+
u64 adr;
24+
u32 type;
25+
const char *name;
26+
};
27+
28+
/**
29+
* sdca_device_data - structure containing all SDCA related information
30+
* @sdca_interface_revision: value read from _DSD property, mainly to check
31+
* for changes between silicon versions
32+
* @num_functions: total number of supported SDCA functions. Invalid/unsupported
33+
* functions will be skipped.
34+
* @sdca_func: array of function descriptors
35+
*/
36+
struct sdca_device_data {
37+
u32 interface_revision;
38+
int num_functions;
39+
struct sdca_function_desc sdca_func[SDCA_MAX_FUNCTION_COUNT];
40+
};
41+
42+
#if IS_ENABLED(CONFIG_ACPI) && IS_ENABLED(CONFIG_SND_SOC_SDCA)
43+
44+
void sdca_lookup_functions(struct sdw_slave *slave);
45+
void sdca_lookup_interface_revision(struct sdw_slave *slave);
46+
47+
#else
48+
49+
static inline void sdca_lookup_functions(struct sdw_slave *slave) {}
50+
static inline void sdca_lookup_interface_revision(struct sdw_slave *slave) {}
51+
52+
#endif
53+
54+
#endif

include/sound/sdca_function.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
2+
/*
3+
* The MIPI SDCA specification is available for public downloads at
4+
* https://www.mipi.org/mipi-sdca-v1-0-download
5+
*
6+
* Copyright(c) 2024 Intel Corporation
7+
*/
8+
9+
#ifndef __SDCA_FUNCTION_H__
10+
#define __SDCA_FUNCTION_H__
11+
12+
/*
13+
* SDCA Function Types from SDCA specification v1.0a Section 5.1.2
14+
* all Function types not described are reserved
15+
* Note that SIMPLE_AMP, SIMPLE_MIC and SIMPLE_JACK Function Types
16+
* are NOT defined in SDCA 1.0a, but they were defined in earlier
17+
* drafts and are planned for 1.1.
18+
*/
19+
20+
enum sdca_function_type {
21+
SDCA_FUNCTION_TYPE_SMART_AMP = 0x01, /* Amplifier with protection features */
22+
SDCA_FUNCTION_TYPE_SIMPLE_AMP = 0x02, /* subset of SmartAmp */
23+
SDCA_FUNCTION_TYPE_SMART_MIC = 0x03, /* Smart microphone with acoustic triggers */
24+
SDCA_FUNCTION_TYPE_SIMPLE_MIC = 0x04, /* subset of SmartMic */
25+
SDCA_FUNCTION_TYPE_SPEAKER_MIC = 0x05, /* Combination of SmartMic and SmartAmp */
26+
SDCA_FUNCTION_TYPE_UAJ = 0x06, /* 3.5mm Universal Audio jack */
27+
SDCA_FUNCTION_TYPE_RJ = 0x07, /* Retaskable jack */
28+
SDCA_FUNCTION_TYPE_SIMPLE_JACK = 0x08, /* Subset of UAJ */
29+
SDCA_FUNCTION_TYPE_HID = 0x0A, /* Human Interface Device, for e.g. buttons */
30+
SDCA_FUNCTION_TYPE_IMP_DEF = 0x1F, /* Implementation-defined function */
31+
};
32+
33+
/* Human-readable names used for kernel logs and Function device registration/bind */
34+
#define SDCA_FUNCTION_TYPE_SMART_AMP_NAME "SmartAmp"
35+
#define SDCA_FUNCTION_TYPE_SIMPLE_AMP_NAME "SimpleAmp"
36+
#define SDCA_FUNCTION_TYPE_SMART_MIC_NAME "SmartMic"
37+
#define SDCA_FUNCTION_TYPE_SIMPLE_MIC_NAME "SimpleMic"
38+
#define SDCA_FUNCTION_TYPE_SPEAKER_MIC_NAME "SpeakerMic"
39+
#define SDCA_FUNCTION_TYPE_UAJ_NAME "UAJ"
40+
#define SDCA_FUNCTION_TYPE_RJ_NAME "RJ"
41+
#define SDCA_FUNCTION_TYPE_SIMPLE_NAME "SimpleJack"
42+
#define SDCA_FUNCTION_TYPE_HID_NAME "HID"
43+
44+
enum sdca_entity0_controls {
45+
SDCA_CONTROL_ENTITY_0_COMMIT_GROUP_MASK = 0x01,
46+
SDCA_CONTROL_ENTITY_0_INTSTAT_CLEAR = 0x02,
47+
SDCA_CONTROL_ENTITY_0_INT_ENABLE = 0x03,
48+
SDCA_CONTROL_ENTITY_0_FUNCTION_SDCA_VERSION = 0x04,
49+
SDCA_CONTROL_ENTITY_0_FUNCTION_TOPOLOGY = 0x05,
50+
SDCA_CONTROL_ENTITY_0_FUNCTION_MANUFACTURER_ID = 0x06,
51+
SDCA_CONTROL_ENTITY_0_FUNCTION_ID = 0x07,
52+
SDCA_CONTROL_ENTITY_0_FUNCTION_VERSION = 0x08
53+
};
54+
55+
#endif

sound/soc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ source "sound/soc/pxa/Kconfig"
108108
source "sound/soc/qcom/Kconfig"
109109
source "sound/soc/rockchip/Kconfig"
110110
source "sound/soc/samsung/Kconfig"
111+
source "sound/soc/sdca/Kconfig"
111112
source "sound/soc/sh/Kconfig"
112113
source "sound/soc/sof/Kconfig"
113114
source "sound/soc/spear/Kconfig"

sound/soc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ obj-$(CONFIG_SND_SOC) += pxa/
6161
obj-$(CONFIG_SND_SOC) += qcom/
6262
obj-$(CONFIG_SND_SOC) += rockchip/
6363
obj-$(CONFIG_SND_SOC) += samsung/
64+
obj-$(CONFIG_SND_SOC) += sdca/
6465
obj-$(CONFIG_SND_SOC) += sh/
6566
obj-$(CONFIG_SND_SOC) += sof/
6667
obj-$(CONFIG_SND_SOC) += spear/

sound/soc/sdca/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
3+
config SND_SOC_SDCA
4+
tristate "ASoC SDCA library"
5+
depends on ACPI
6+
help
7+
This option enables support for the MIPI SoundWire Device
8+
Class for Audio (SDCA).
9+
10+
config SND_SOC_SDCA_OPTIONAL
11+
def_tristate SND_SOC_SDCA || !SND_SOC_SDCA

sound/soc/sdca/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
3+
snd-soc-sdca-objs := sdca_functions.o sdca_device.o
4+
5+
obj-$(CONFIG_SND_SOC_SDCA) += snd-soc-sdca.o

sound/soc/sdca/sdca_device.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
2+
// Copyright(c) 2024 Intel Corporation
3+
4+
/*
5+
* The MIPI SDCA specification is available for public downloads at
6+
* https://www.mipi.org/mipi-sdca-v1-0-download
7+
*/
8+
9+
#include <linux/acpi.h>
10+
#include <linux/soundwire/sdw.h>
11+
#include <sound/sdca.h>
12+
13+
void sdca_lookup_interface_revision(struct sdw_slave *slave)
14+
{
15+
struct fwnode_handle *fwnode = slave->dev.fwnode;
16+
17+
/*
18+
* if this property is not present, then the sdca_interface_revision will
19+
* remain zero, which will be considered as 'not defined' or 'invalid'.
20+
*/
21+
fwnode_property_read_u32(fwnode, "mipi-sdw-sdca-interface-revision",
22+
&slave->sdca_data.interface_revision);
23+
}
24+
EXPORT_SYMBOL_NS(sdca_lookup_interface_revision, SND_SOC_SDCA);

sound/soc/sdca/sdca_functions.c

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
2+
// Copyright(c) 2024 Intel Corporation
3+
4+
/*
5+
* The MIPI SDCA specification is available for public downloads at
6+
* https://www.mipi.org/mipi-sdca-v1-0-download
7+
*/
8+
9+
#include <linux/acpi.h>
10+
#include <linux/soundwire/sdw.h>
11+
#include <sound/sdca.h>
12+
#include <sound/sdca_function.h>
13+
14+
static int patch_sdca_function_type(struct device *dev,
15+
u32 interface_revision,
16+
u32 *function_type,
17+
const char **function_name)
18+
{
19+
unsigned long function_type_patch = 0;
20+
21+
/*
22+
* Unfortunately early SDCA specifications used different indices for Functions,
23+
* for backwards compatibility we have to reorder the values found
24+
*/
25+
if (interface_revision >= 0x0801)
26+
goto skip_early_draft_order;
27+
28+
switch (*function_type) {
29+
case 1:
30+
function_type_patch = SDCA_FUNCTION_TYPE_SMART_AMP;
31+
break;
32+
case 2:
33+
function_type_patch = SDCA_FUNCTION_TYPE_SMART_MIC;
34+
break;
35+
case 3:
36+
function_type_patch = SDCA_FUNCTION_TYPE_SPEAKER_MIC;
37+
break;
38+
case 4:
39+
function_type_patch = SDCA_FUNCTION_TYPE_UAJ;
40+
break;
41+
case 5:
42+
function_type_patch = SDCA_FUNCTION_TYPE_RJ;
43+
break;
44+
case 6:
45+
function_type_patch = SDCA_FUNCTION_TYPE_HID;
46+
break;
47+
default:
48+
dev_warn(dev, "%s: SDCA version %#x unsupported function type %d, skipped\n",
49+
__func__, interface_revision, *function_type);
50+
return -EINVAL;
51+
}
52+
53+
skip_early_draft_order:
54+
if (function_type_patch)
55+
*function_type = function_type_patch;
56+
57+
/* now double-check the values */
58+
switch (*function_type) {
59+
case SDCA_FUNCTION_TYPE_SMART_AMP:
60+
*function_name = SDCA_FUNCTION_TYPE_SMART_AMP_NAME;
61+
break;
62+
case SDCA_FUNCTION_TYPE_SMART_MIC:
63+
*function_name = SDCA_FUNCTION_TYPE_SMART_MIC_NAME;
64+
break;
65+
case SDCA_FUNCTION_TYPE_UAJ:
66+
*function_name = SDCA_FUNCTION_TYPE_UAJ_NAME;
67+
break;
68+
case SDCA_FUNCTION_TYPE_HID:
69+
*function_name = SDCA_FUNCTION_TYPE_HID_NAME;
70+
break;
71+
case SDCA_FUNCTION_TYPE_SIMPLE_AMP:
72+
case SDCA_FUNCTION_TYPE_SIMPLE_MIC:
73+
case SDCA_FUNCTION_TYPE_SPEAKER_MIC:
74+
case SDCA_FUNCTION_TYPE_RJ:
75+
case SDCA_FUNCTION_TYPE_IMP_DEF:
76+
dev_warn(dev, "%s: found unsupported SDCA function type %d, skipped\n",
77+
__func__, *function_type);
78+
return -EINVAL;
79+
default:
80+
dev_err(dev, "%s: found invalid SDCA function type %d, skipped\n",
81+
__func__, *function_type);
82+
return -EINVAL;
83+
}
84+
85+
dev_info(dev, "%s: found SDCA function %s (type %d)\n",
86+
__func__, *function_name, *function_type);
87+
88+
return 0;
89+
}
90+
91+
static int find_sdca_function(struct acpi_device *adev, void *data)
92+
{
93+
struct fwnode_handle *function_node = acpi_fwnode_handle(adev);
94+
struct sdca_device_data *sdca_data = data;
95+
struct device *dev = &adev->dev;
96+
struct fwnode_handle *control5; /* used to identify function type */
97+
const char *function_name;
98+
u32 function_type;
99+
int func_index;
100+
u64 addr;
101+
int ret;
102+
103+
if (sdca_data->num_functions >= SDCA_MAX_FUNCTION_COUNT) {
104+
dev_err(dev, "%s: maximum number of functions exceeded\n", __func__);
105+
return -EINVAL;
106+
}
107+
108+
/*
109+
* The number of functions cannot exceed 8, we could use
110+
* acpi_get_local_address() but the value is stored as u64 so
111+
* we might as well avoid casts and intermediate levels
112+
*/
113+
ret = acpi_get_local_u64_address(adev->handle, &addr);
114+
if (ret < 0)
115+
return ret;
116+
117+
if (!addr) {
118+
dev_err(dev, "%s: no addr\n", __func__);
119+
return -ENODEV;
120+
}
121+
122+
/*
123+
* Extracting the topology type for an SDCA function is a
124+
* convoluted process.
125+
* The Function type is only visible as a result of a read
126+
* from a control. In theory this would mean reading from the hardware,
127+
* but the SDCA/DisCo specs defined the notion of "DC value" - a constant
128+
* represented with a DSD subproperty.
129+
* Drivers have to query the properties for the control
130+
* SDCA_CONTROL_ENTITY_0_FUNCTION_TOPOLOGY (0x05)
131+
*/
132+
control5 = fwnode_get_named_child_node(function_node,
133+
"mipi-sdca-control-0x5-subproperties");
134+
if (!control5)
135+
return -ENODEV;
136+
137+
ret = fwnode_property_read_u32(control5, "mipi-sdca-control-dc-value",
138+
&function_type);
139+
140+
fwnode_handle_put(control5);
141+
142+
if (ret < 0) {
143+
dev_err(dev, "%s: the function type can only be determined from ACPI information\n",
144+
__func__);
145+
return ret;
146+
}
147+
148+
ret = patch_sdca_function_type(dev, sdca_data->interface_revision,
149+
&function_type, &function_name);
150+
if (ret < 0)
151+
return ret;
152+
153+
/* store results */
154+
func_index = sdca_data->num_functions;
155+
sdca_data->sdca_func[func_index].adr = addr;
156+
sdca_data->sdca_func[func_index].type = function_type;
157+
sdca_data->sdca_func[func_index].name = function_name;
158+
sdca_data->num_functions++;
159+
160+
return 0;
161+
}
162+
163+
void sdca_lookup_functions(struct sdw_slave *slave)
164+
{
165+
struct device *dev = &slave->dev;
166+
struct acpi_device *adev = to_acpi_device_node(dev->fwnode);
167+
168+
acpi_dev_for_each_child(adev, find_sdca_function, &slave->sdca_data);
169+
}
170+
EXPORT_SYMBOL_NS(sdca_lookup_functions, SND_SOC_SDCA);
171+
172+
MODULE_LICENSE("Dual BSD/GPL");
173+
MODULE_DESCRIPTION("SDCA library");

0 commit comments

Comments
 (0)