Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: SDCA: add function devices

Use the auxiliary bus to register/unregister subdevices for each
function. Each function will be handled with a separate driver,
matched using a name.

If a vendor wants to override a specific function driver, they could
use a custom name to match with a custom function driver.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Tested-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Reviewed-by: Maciej Strozek <mstrozek@opensource.cirrus.com>
Reviewed-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Tested-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Link: https://patch.msgid.link/20251120153023.2105663-12-ckeepax@opensource.cirrus.com
Reviewed-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Pierre-Louis Bossart and committed by
Mark Brown
4496d1c6 5acf17b6

+148 -2
+13
include/sound/sdca.h
··· 15 15 struct acpi_table_swft; 16 16 struct fwnode_handle; 17 17 struct sdw_slave; 18 + struct sdca_dev; 18 19 19 20 #define SDCA_MAX_FUNCTION_COUNT 8 20 21 21 22 /** 22 23 * struct sdca_function_desc - short descriptor for an SDCA Function 23 24 * @node: firmware node for the Function. 25 + * @func_dev: pointer to SDCA function device. 24 26 * @name: Human-readable string. 25 27 * @type: Function topology type. 26 28 * @adr: ACPI address (used for SDCA register access). 27 29 */ 28 30 struct sdca_function_desc { 29 31 struct fwnode_handle *node; 32 + struct sdca_dev *func_dev; 30 33 const char *name; 31 34 u32 type; 32 35 u8 adr; ··· 62 59 void sdca_lookup_swft(struct sdw_slave *slave); 63 60 void sdca_lookup_interface_revision(struct sdw_slave *slave); 64 61 bool sdca_device_quirk_match(struct sdw_slave *slave, enum sdca_quirk quirk); 62 + int sdca_dev_register_functions(struct sdw_slave *slave); 63 + void sdca_dev_unregister_functions(struct sdw_slave *slave); 65 64 66 65 #else 67 66 ··· 74 69 { 75 70 return false; 76 71 } 72 + 73 + static inline int sdca_dev_register_functions(struct sdw_slave *slave) 74 + { 75 + return 0; 76 + } 77 + 78 + static inline void sdca_dev_unregister_functions(struct sdw_slave *slave) {} 79 + 77 80 #endif 78 81 79 82 #endif
+1
sound/soc/sdca/Kconfig
··· 4 4 config SND_SOC_SDCA 5 5 tristate 6 6 depends on ACPI 7 + select AUXILIARY_BUS 7 8 help 8 9 This option enables support for the MIPI SoundWire Device 9 10 Class for Audio (SDCA).
+2 -2
sound/soc/sdca/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 2 3 - snd-soc-sdca-y := sdca_functions.o sdca_device.o sdca_regmap.o sdca_asoc.o \ 4 - sdca_ump.o 3 + snd-soc-sdca-y := sdca_functions.o sdca_device.o sdca_function_device.o \ 4 + sdca_regmap.o sdca_asoc.o sdca_ump.o 5 5 snd-soc-sdca-$(CONFIG_SND_SOC_SDCA_HID) += sdca_hid.o 6 6 snd-soc-sdca-$(CONFIG_SND_SOC_SDCA_IRQ) += sdca_interrupts.o 7 7 snd-soc-sdca-$(CONFIG_SND_SOC_SDCA_FDL) += sdca_fdl.o
+117
sound/soc/sdca/sdca_function_device.c
··· 1 + // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) 2 + // Copyright(c) 2024 Intel Corporation. 3 + 4 + /* 5 + * SDCA Function Device management 6 + */ 7 + 8 + #include <linux/acpi.h> 9 + #include <linux/module.h> 10 + #include <linux/auxiliary_bus.h> 11 + #include <linux/soundwire/sdw.h> 12 + #include <sound/sdca.h> 13 + #include <sound/sdca_function.h> 14 + #include "sdca_function_device.h" 15 + 16 + /* 17 + * A SoundWire device can have multiple SDCA functions identified by 18 + * their type and ADR. there can be multiple SoundWire devices per 19 + * link, or multiple devices spread across multiple links. An IDA is 20 + * required to identify each instance. 21 + */ 22 + static DEFINE_IDA(sdca_function_ida); 23 + 24 + static void sdca_dev_release(struct device *dev) 25 + { 26 + struct auxiliary_device *auxdev = to_auxiliary_dev(dev); 27 + struct sdca_dev *sdev = auxiliary_dev_to_sdca_dev(auxdev); 28 + 29 + ida_free(&sdca_function_ida, auxdev->id); 30 + kfree(sdev); 31 + } 32 + 33 + /* alloc, init and add link devices */ 34 + static struct sdca_dev *sdca_dev_register(struct device *parent, 35 + struct sdca_function_desc *function_desc) 36 + { 37 + struct sdca_dev *sdev; 38 + struct auxiliary_device *auxdev; 39 + int ret; 40 + int rc; 41 + 42 + sdev = kzalloc(sizeof(*sdev), GFP_KERNEL); 43 + if (!sdev) 44 + return ERR_PTR(-ENOMEM); 45 + 46 + auxdev = &sdev->auxdev; 47 + auxdev->name = function_desc->name; 48 + auxdev->dev.parent = parent; 49 + auxdev->dev.fwnode = function_desc->node; 50 + auxdev->dev.release = sdca_dev_release; 51 + 52 + sdev->function.desc = function_desc; 53 + 54 + rc = ida_alloc(&sdca_function_ida, GFP_KERNEL); 55 + if (rc < 0) { 56 + kfree(sdev); 57 + return ERR_PTR(rc); 58 + } 59 + auxdev->id = rc; 60 + 61 + /* now follow the two-step init/add sequence */ 62 + ret = auxiliary_device_init(auxdev); 63 + if (ret < 0) { 64 + dev_err(parent, "failed to initialize SDCA function dev %s\n", 65 + function_desc->name); 66 + ida_free(&sdca_function_ida, auxdev->id); 67 + kfree(sdev); 68 + return ERR_PTR(ret); 69 + } 70 + 71 + ret = auxiliary_device_add(auxdev); 72 + if (ret < 0) { 73 + dev_err(parent, "failed to add SDCA function dev %s\n", 74 + sdev->auxdev.name); 75 + /* sdev will be freed with the put_device() and .release sequence */ 76 + auxiliary_device_uninit(&sdev->auxdev); 77 + return ERR_PTR(ret); 78 + } 79 + 80 + return sdev; 81 + } 82 + 83 + static void sdca_dev_unregister(struct sdca_dev *sdev) 84 + { 85 + auxiliary_device_delete(&sdev->auxdev); 86 + auxiliary_device_uninit(&sdev->auxdev); 87 + } 88 + 89 + int sdca_dev_register_functions(struct sdw_slave *slave) 90 + { 91 + struct sdca_device_data *sdca_data = &slave->sdca_data; 92 + int i; 93 + 94 + for (i = 0; i < sdca_data->num_functions; i++) { 95 + struct sdca_dev *func_dev; 96 + 97 + func_dev = sdca_dev_register(&slave->dev, 98 + &sdca_data->function[i]); 99 + if (!func_dev) 100 + return -ENODEV; 101 + 102 + sdca_data->function[i].func_dev = func_dev; 103 + } 104 + 105 + return 0; 106 + } 107 + EXPORT_SYMBOL_NS(sdca_dev_register_functions, "SND_SOC_SDCA"); 108 + 109 + void sdca_dev_unregister_functions(struct sdw_slave *slave) 110 + { 111 + struct sdca_device_data *sdca_data = &slave->sdca_data; 112 + int i; 113 + 114 + for (i = 0; i < sdca_data->num_functions; i++) 115 + sdca_dev_unregister(sdca_data->function[i].func_dev); 116 + } 117 + EXPORT_SYMBOL_NS(sdca_dev_unregister_functions, "SND_SOC_SDCA");
+15
sound/soc/sdca/sdca_function_device.h
··· 1 + /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */ 2 + /* Copyright(c) 2024 Intel Corporation. */ 3 + 4 + #ifndef __SDCA_FUNCTION_DEVICE_H 5 + #define __SDCA_FUNCTION_DEVICE_H 6 + 7 + struct sdca_dev { 8 + struct auxiliary_device auxdev; 9 + struct sdca_function_data function; 10 + }; 11 + 12 + #define auxiliary_dev_to_sdca_dev(auxiliary_dev) \ 13 + container_of(auxiliary_dev, struct sdca_dev, auxdev) 14 + 15 + #endif