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

Add SDCA class driver

Merge series from Charles Keepax <ckeepax@opensource.cirrus.com>:

This series adds an initial SDCA class driver, this consists of a
primary driver attached to the SoundWire device, and auxiliary drivers
representing each of the functions of the SDCA device. These drivers all
use the APIs added over the past series's to provide the class
functionality, as such these final drivers themselves are quite thin.

Also a few fix ups at the start of the series that have gathered up
whilst the last SDCA series was in review.

+1139 -130
+2
include/linux/soundwire/sdw_registers.h
··· 355 355 /* Check the reserved and fixed bits in address */ 356 356 #define SDW_SDCA_VALID_CTL(reg) (((reg) & (GENMASK(31, 25) | BIT(18) | BIT(13))) == BIT(30)) 357 357 358 + #define SDW_SDCA_MAX_REGISTER 0x47FFFFFF 359 + 358 360 #endif /* __SDW_REGISTERS_H */
+14
include/sound/sdca.h
··· 13 13 #include <linux/kconfig.h> 14 14 15 15 struct acpi_table_swft; 16 + struct fwnode_handle; 16 17 struct sdw_slave; 18 + struct sdca_dev; 17 19 18 20 #define SDCA_MAX_FUNCTION_COUNT 8 19 21 20 22 /** 21 23 * struct sdca_function_desc - short descriptor for an SDCA Function 22 24 * @node: firmware node for the Function. 25 + * @func_dev: pointer to SDCA function device. 23 26 * @name: Human-readable string. 24 27 * @type: Function topology type. 25 28 * @adr: ACPI address (used for SDCA register access). 26 29 */ 27 30 struct sdca_function_desc { 28 31 struct fwnode_handle *node; 32 + struct sdca_dev *func_dev; 29 33 const char *name; 30 34 u32 type; 31 35 u8 adr; ··· 62 58 void sdca_lookup_swft(struct sdw_slave *slave); 63 59 void sdca_lookup_interface_revision(struct sdw_slave *slave); 64 60 bool sdca_device_quirk_match(struct sdw_slave *slave, enum sdca_quirk quirk); 61 + int sdca_dev_register_functions(struct sdw_slave *slave); 62 + void sdca_dev_unregister_functions(struct sdw_slave *slave); 65 63 66 64 #else 67 65 ··· 74 68 { 75 69 return false; 76 70 } 71 + 72 + static inline int sdca_dev_register_functions(struct sdw_slave *slave) 73 + { 74 + return 0; 75 + } 76 + 77 + static inline void sdca_dev_unregister_functions(struct sdw_slave *slave) {} 78 + 77 79 #endif 78 80 79 81 #endif
+2
include/sound/sdca_regmap.h
··· 27 27 28 28 int sdca_regmap_write_defaults(struct device *dev, struct regmap *regmap, 29 29 struct sdca_function_data *function); 30 + int sdca_regmap_write_init(struct device *dev, struct regmap *regmap, 31 + struct sdca_function_data *function); 30 32 31 33 #endif // __SDCA_REGMAP_H__
+18
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). ··· 36 35 37 36 config SND_SOC_SDCA_OPTIONAL 38 37 def_tristate SND_SOC_SDCA || !SND_SOC_SDCA 38 + 39 + config SND_SOC_SDCA_CLASS 40 + tristate "SDCA Class Driver" 41 + depends on SND_SOC_SDCA 42 + select SND_SOC_SDCA_CLASS_FUNCTION 43 + select SND_SOC_SDCA_FDL 44 + select SND_SOC_SDCA_HID 45 + select SND_SOC_SDCA_IRQ 46 + help 47 + This option enables support for the SDCA Class driver which should 48 + support any class compliant SDCA part. 49 + 50 + config SND_SOC_SDCA_CLASS_FUNCTION 51 + tristate 52 + help 53 + This option enables support for the SDCA Class Function drivers, 54 + these implement the individual functions of the SDCA Class driver. 39 55 40 56 endmenu
+8 -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 8 8 9 + snd-soc-sdca-class-y := sdca_class.o 10 + snd-soc-sdca-class-function-y := sdca_class_function.o 11 + 9 12 obj-$(CONFIG_SND_SOC_SDCA) += snd-soc-sdca.o 13 + 14 + obj-$(CONFIG_SND_SOC_SDCA_CLASS) += snd-soc-sdca-class.o 15 + obj-$(CONFIG_SND_SOC_SDCA_CLASS_FUNCTION) += snd-soc-sdca-class-function.o
+304
sound/soc/sdca/sdca_class.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + // Copyright (C) 2025 Cirrus Logic, Inc. and 3 + // Cirrus Logic International Semiconductor Ltd. 4 + 5 + /* 6 + * The MIPI SDCA specification is available for public downloads at 7 + * https://www.mipi.org/mipi-sdca-v1-0-download 8 + */ 9 + 10 + #include <linux/device.h> 11 + #include <linux/err.h> 12 + #include <linux/mod_devicetable.h> 13 + #include <linux/module.h> 14 + #include <linux/pm.h> 15 + #include <linux/pm_runtime.h> 16 + #include <linux/regmap.h> 17 + #include <linux/soundwire/sdw.h> 18 + #include <linux/soundwire/sdw_registers.h> 19 + #include <linux/soundwire/sdw_type.h> 20 + #include <sound/sdca.h> 21 + #include <sound/sdca_function.h> 22 + #include <sound/sdca_interrupts.h> 23 + #include <sound/sdca_regmap.h> 24 + #include "sdca_class.h" 25 + 26 + #define CLASS_SDW_ATTACH_TIMEOUT_MS 5000 27 + 28 + static int class_read_prop(struct sdw_slave *sdw) 29 + { 30 + struct sdw_slave_prop *prop = &sdw->prop; 31 + 32 + sdw_slave_read_prop(sdw); 33 + 34 + prop->use_domain_irq = true; 35 + prop->scp_int1_mask = SDW_SCP_INT1_BUS_CLASH | SDW_SCP_INT1_PARITY | 36 + SDW_SCP_INT1_IMPL_DEF; 37 + 38 + return 0; 39 + } 40 + 41 + static int class_sdw_update_status(struct sdw_slave *sdw, enum sdw_slave_status status) 42 + { 43 + struct sdca_class_drv *drv = dev_get_drvdata(&sdw->dev); 44 + 45 + switch (status) { 46 + case SDW_SLAVE_ATTACHED: 47 + dev_dbg(drv->dev, "device attach\n"); 48 + 49 + drv->attached = true; 50 + 51 + complete(&drv->device_attach); 52 + break; 53 + case SDW_SLAVE_UNATTACHED: 54 + dev_dbg(drv->dev, "device detach\n"); 55 + 56 + drv->attached = false; 57 + 58 + reinit_completion(&drv->device_attach); 59 + break; 60 + default: 61 + break; 62 + } 63 + 64 + return 0; 65 + } 66 + 67 + static const struct sdw_slave_ops class_sdw_ops = { 68 + .read_prop = class_read_prop, 69 + .update_status = class_sdw_update_status, 70 + }; 71 + 72 + static void class_regmap_lock(void *data) 73 + { 74 + struct mutex *lock = data; 75 + 76 + mutex_lock(lock); 77 + } 78 + 79 + static void class_regmap_unlock(void *data) 80 + { 81 + struct mutex *lock = data; 82 + 83 + mutex_unlock(lock); 84 + } 85 + 86 + static int class_wait_for_attach(struct sdca_class_drv *drv) 87 + { 88 + if (!drv->attached) { 89 + unsigned long timeout = msecs_to_jiffies(CLASS_SDW_ATTACH_TIMEOUT_MS); 90 + unsigned long time; 91 + 92 + time = wait_for_completion_timeout(&drv->device_attach, timeout); 93 + if (!time) { 94 + dev_err(drv->dev, "timed out waiting for device re-attach\n"); 95 + return -ETIMEDOUT; 96 + } 97 + } 98 + 99 + regcache_cache_only(drv->dev_regmap, false); 100 + 101 + return 0; 102 + } 103 + 104 + static bool class_dev_regmap_volatile(struct device *dev, unsigned int reg) 105 + { 106 + switch (reg) { 107 + case SDW_SCP_SDCA_INTMASK1 ... SDW_SCP_SDCA_INTMASK4: 108 + return false; 109 + default: 110 + return true; 111 + } 112 + } 113 + 114 + static bool class_dev_regmap_precious(struct device *dev, unsigned int reg) 115 + { 116 + switch (reg) { 117 + case SDW_SCP_SDCA_INT1 ... SDW_SCP_SDCA_INT4: 118 + case SDW_SCP_SDCA_INTMASK1 ... SDW_SCP_SDCA_INTMASK4: 119 + return false; 120 + default: 121 + return true; 122 + } 123 + } 124 + 125 + static const struct regmap_config class_dev_regmap_config = { 126 + .name = "sdca-device", 127 + .reg_bits = 32, 128 + .val_bits = 8, 129 + 130 + .max_register = SDW_SDCA_MAX_REGISTER, 131 + .volatile_reg = class_dev_regmap_volatile, 132 + .precious_reg = class_dev_regmap_precious, 133 + 134 + .cache_type = REGCACHE_MAPLE, 135 + 136 + .lock = class_regmap_lock, 137 + .unlock = class_regmap_unlock, 138 + }; 139 + 140 + static void class_boot_work(struct work_struct *work) 141 + { 142 + struct sdca_class_drv *drv = container_of(work, 143 + struct sdca_class_drv, 144 + boot_work); 145 + int ret; 146 + 147 + ret = class_wait_for_attach(drv); 148 + if (ret) 149 + goto err; 150 + 151 + drv->irq_info = sdca_irq_allocate(drv->dev, drv->dev_regmap, 152 + drv->sdw->irq); 153 + if (IS_ERR(drv->irq_info)) 154 + goto err; 155 + 156 + ret = sdca_dev_register_functions(drv->sdw); 157 + if (ret) 158 + goto err; 159 + 160 + dev_dbg(drv->dev, "boot work complete\n"); 161 + 162 + pm_runtime_mark_last_busy(drv->dev); 163 + pm_runtime_put_autosuspend(drv->dev); 164 + 165 + return; 166 + 167 + err: 168 + pm_runtime_put_sync(drv->dev); 169 + } 170 + 171 + static void class_dev_remove(void *data) 172 + { 173 + struct sdca_class_drv *drv = data; 174 + 175 + cancel_work_sync(&drv->boot_work); 176 + 177 + sdca_dev_unregister_functions(drv->sdw); 178 + } 179 + 180 + static int class_sdw_probe(struct sdw_slave *sdw, const struct sdw_device_id *id) 181 + { 182 + struct device *dev = &sdw->dev; 183 + struct sdca_device_data *data = &sdw->sdca_data; 184 + struct regmap_config *dev_config; 185 + struct sdca_class_drv *drv; 186 + int ret; 187 + 188 + sdca_lookup_swft(sdw); 189 + 190 + drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL); 191 + if (!drv) 192 + return -ENOMEM; 193 + 194 + dev_config = devm_kmemdup(dev, &class_dev_regmap_config, 195 + sizeof(*dev_config), GFP_KERNEL); 196 + if (!dev_config) 197 + return -ENOMEM; 198 + 199 + drv->functions = devm_kcalloc(dev, data->num_functions, 200 + sizeof(*drv->functions), 201 + GFP_KERNEL); 202 + if (!drv->functions) 203 + return -ENOMEM; 204 + 205 + drv->dev = dev; 206 + drv->sdw = sdw; 207 + mutex_init(&drv->regmap_lock); 208 + 209 + dev_set_drvdata(drv->dev, drv); 210 + 211 + INIT_WORK(&drv->boot_work, class_boot_work); 212 + init_completion(&drv->device_attach); 213 + 214 + dev_config->lock_arg = &drv->regmap_lock; 215 + 216 + drv->dev_regmap = devm_regmap_init_sdw(sdw, dev_config); 217 + if (IS_ERR(drv->dev_regmap)) 218 + return dev_err_probe(drv->dev, PTR_ERR(drv->dev_regmap), 219 + "failed to create device regmap\n"); 220 + 221 + regcache_cache_only(drv->dev_regmap, true); 222 + 223 + pm_runtime_set_autosuspend_delay(dev, 250); 224 + pm_runtime_use_autosuspend(dev); 225 + pm_runtime_set_active(dev); 226 + pm_runtime_get_noresume(dev); 227 + 228 + ret = devm_pm_runtime_enable(dev); 229 + if (ret) 230 + return ret; 231 + 232 + ret = devm_add_action_or_reset(dev, class_dev_remove, drv); 233 + if (ret) 234 + return ret; 235 + 236 + queue_work(system_long_wq, &drv->boot_work); 237 + 238 + return 0; 239 + } 240 + 241 + static int class_runtime_suspend(struct device *dev) 242 + { 243 + struct sdca_class_drv *drv = dev_get_drvdata(dev); 244 + 245 + /* 246 + * Whilst the driver doesn't power the chip down here, going into runtime 247 + * suspend lets the SoundWire bus power down, which means the driver 248 + * can't communicate with the device any more. 249 + */ 250 + regcache_cache_only(drv->dev_regmap, true); 251 + 252 + return 0; 253 + } 254 + 255 + static int class_runtime_resume(struct device *dev) 256 + { 257 + struct sdca_class_drv *drv = dev_get_drvdata(dev); 258 + int ret; 259 + 260 + ret = class_wait_for_attach(drv); 261 + if (ret) 262 + goto err; 263 + 264 + regcache_mark_dirty(drv->dev_regmap); 265 + 266 + ret = regcache_sync(drv->dev_regmap); 267 + if (ret) { 268 + dev_err(drv->dev, "failed to restore cache: %d\n", ret); 269 + goto err; 270 + } 271 + 272 + return 0; 273 + 274 + err: 275 + regcache_cache_only(drv->dev_regmap, true); 276 + 277 + return ret; 278 + } 279 + 280 + static const struct dev_pm_ops class_pm_ops = { 281 + RUNTIME_PM_OPS(class_runtime_suspend, class_runtime_resume, NULL) 282 + }; 283 + 284 + static const struct sdw_device_id class_sdw_id[] = { 285 + SDW_SLAVE_ENTRY(0x01FA, 0x4245, 0), 286 + {} 287 + }; 288 + MODULE_DEVICE_TABLE(sdw, class_sdw_id); 289 + 290 + static struct sdw_driver class_sdw_driver = { 291 + .driver = { 292 + .name = "sdca_class", 293 + .pm = pm_ptr(&class_pm_ops), 294 + }, 295 + 296 + .probe = class_sdw_probe, 297 + .id_table = class_sdw_id, 298 + .ops = &class_sdw_ops, 299 + }; 300 + module_sdw_driver(class_sdw_driver); 301 + 302 + MODULE_LICENSE("GPL"); 303 + MODULE_DESCRIPTION("SDCA Class Driver"); 304 + MODULE_IMPORT_NS("SND_SOC_SDCA");
+37
sound/soc/sdca/sdca_class.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 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) 2025 Cirrus Logic, Inc. and 7 + * Cirrus Logic International Semiconductor Ltd. 8 + */ 9 + 10 + #ifndef __SDCA_CLASS_H__ 11 + #define __SDCA_CLASS_H__ 12 + 13 + #include <linux/completion.h> 14 + #include <linux/mutex.h> 15 + #include <linux/workqueue.h> 16 + 17 + struct device; 18 + struct regmap; 19 + struct sdw_slave; 20 + struct sdca_function_data; 21 + 22 + struct sdca_class_drv { 23 + struct device *dev; 24 + struct regmap *dev_regmap; 25 + struct sdw_slave *sdw; 26 + 27 + struct sdca_function_data *functions; 28 + struct sdca_interrupt_info *irq_info; 29 + 30 + struct mutex regmap_lock; 31 + struct work_struct boot_work; 32 + struct completion device_attach; 33 + 34 + bool attached; 35 + }; 36 + 37 + #endif /* __SDCA_CLASS_H__ */
+460
sound/soc/sdca/sdca_class_function.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + // Copyright (C) 2025 Cirrus Logic, Inc. and 3 + // Cirrus Logic International Semiconductor Ltd. 4 + 5 + /* 6 + * The MIPI SDCA specification is available for public downloads at 7 + * https://www.mipi.org/mipi-sdca-v1-0-download 8 + */ 9 + 10 + #include <linux/auxiliary_bus.h> 11 + #include <linux/minmax.h> 12 + #include <linux/module.h> 13 + #include <linux/pm.h> 14 + #include <linux/pm_runtime.h> 15 + #include <linux/soundwire/sdw.h> 16 + #include <linux/soundwire/sdw_registers.h> 17 + #include <sound/pcm.h> 18 + #include <sound/sdca_asoc.h> 19 + #include <sound/sdca_fdl.h> 20 + #include <sound/sdca_function.h> 21 + #include <sound/sdca_interrupts.h> 22 + #include <sound/sdca_regmap.h> 23 + #include <sound/sdw.h> 24 + #include <sound/soc-component.h> 25 + #include <sound/soc-dai.h> 26 + #include <sound/soc.h> 27 + #include "sdca_class.h" 28 + 29 + struct class_function_drv { 30 + struct device *dev; 31 + struct regmap *regmap; 32 + struct sdca_class_drv *core; 33 + 34 + struct sdca_function_data *function; 35 + }; 36 + 37 + static void class_function_regmap_lock(void *data) 38 + { 39 + struct mutex *lock = data; 40 + 41 + mutex_lock(lock); 42 + } 43 + 44 + static void class_function_regmap_unlock(void *data) 45 + { 46 + struct mutex *lock = data; 47 + 48 + mutex_unlock(lock); 49 + } 50 + 51 + static bool class_function_regmap_writeable(struct device *dev, unsigned int reg) 52 + { 53 + struct auxiliary_device *auxdev = to_auxiliary_dev(dev); 54 + struct class_function_drv *drv = auxiliary_get_drvdata(auxdev); 55 + 56 + return sdca_regmap_writeable(drv->function, reg); 57 + } 58 + 59 + static bool class_function_regmap_readable(struct device *dev, unsigned int reg) 60 + { 61 + struct auxiliary_device *auxdev = to_auxiliary_dev(dev); 62 + struct class_function_drv *drv = auxiliary_get_drvdata(auxdev); 63 + 64 + return sdca_regmap_readable(drv->function, reg); 65 + } 66 + 67 + static bool class_function_regmap_volatile(struct device *dev, unsigned int reg) 68 + { 69 + struct auxiliary_device *auxdev = to_auxiliary_dev(dev); 70 + struct class_function_drv *drv = auxiliary_get_drvdata(auxdev); 71 + 72 + return sdca_regmap_volatile(drv->function, reg); 73 + } 74 + 75 + static const struct regmap_config class_function_regmap_config = { 76 + .name = "sdca", 77 + .reg_bits = 32, 78 + .val_bits = 32, 79 + .reg_format_endian = REGMAP_ENDIAN_LITTLE, 80 + .val_format_endian = REGMAP_ENDIAN_LITTLE, 81 + 82 + .max_register = SDW_SDCA_MAX_REGISTER, 83 + .readable_reg = class_function_regmap_readable, 84 + .writeable_reg = class_function_regmap_writeable, 85 + .volatile_reg = class_function_regmap_volatile, 86 + 87 + .cache_type = REGCACHE_MAPLE, 88 + 89 + .lock = class_function_regmap_lock, 90 + .unlock = class_function_regmap_unlock, 91 + }; 92 + 93 + static int class_function_regmap_mbq_size(struct device *dev, unsigned int reg) 94 + { 95 + struct auxiliary_device *auxdev = to_auxiliary_dev(dev); 96 + struct class_function_drv *drv = auxiliary_get_drvdata(auxdev); 97 + 98 + return sdca_regmap_mbq_size(drv->function, reg); 99 + } 100 + 101 + static bool class_function_regmap_deferrable(struct device *dev, unsigned int reg) 102 + { 103 + struct auxiliary_device *auxdev = to_auxiliary_dev(dev); 104 + struct class_function_drv *drv = auxiliary_get_drvdata(auxdev); 105 + 106 + return sdca_regmap_deferrable(drv->function, reg); 107 + } 108 + 109 + static const struct regmap_sdw_mbq_cfg class_function_mbq_config = { 110 + .mbq_size = class_function_regmap_mbq_size, 111 + .deferrable = class_function_regmap_deferrable, 112 + .retry_us = 1000, 113 + .timeout_us = 10000, 114 + }; 115 + 116 + static int class_function_startup(struct snd_pcm_substream *substream, 117 + struct snd_soc_dai *dai) 118 + { 119 + struct class_function_drv *drv = snd_soc_component_get_drvdata(dai->component); 120 + 121 + return sdca_asoc_set_constraints(drv->dev, drv->regmap, drv->function, 122 + substream, dai); 123 + } 124 + 125 + static int class_function_sdw_add_peripheral(struct snd_pcm_substream *substream, 126 + struct snd_pcm_hw_params *params, 127 + struct snd_soc_dai *dai) 128 + { 129 + struct class_function_drv *drv = snd_soc_component_get_drvdata(dai->component); 130 + struct sdw_stream_runtime *sdw_stream = snd_soc_dai_get_dma_data(dai, substream); 131 + struct sdw_slave *sdw = dev_to_sdw_dev(drv->dev->parent); 132 + struct sdw_stream_config sconfig = {0}; 133 + struct sdw_port_config pconfig = {0}; 134 + int ret; 135 + 136 + if (!sdw_stream) 137 + return -EINVAL; 138 + 139 + snd_sdw_params_to_config(substream, params, &sconfig, &pconfig); 140 + 141 + /* 142 + * FIXME: As also noted in sdca_asoc_get_port(), currently only 143 + * a single unshared port is supported for each DAI. 144 + */ 145 + ret = sdca_asoc_get_port(drv->dev, drv->regmap, drv->function, dai); 146 + if (ret < 0) 147 + return ret; 148 + 149 + pconfig.num = ret; 150 + 151 + ret = sdw_stream_add_slave(sdw, &sconfig, &pconfig, 1, sdw_stream); 152 + if (ret) { 153 + dev_err(drv->dev, "failed to add sdw stream: %d\n", ret); 154 + return ret; 155 + } 156 + 157 + return sdca_asoc_hw_params(drv->dev, drv->regmap, drv->function, 158 + substream, params, dai); 159 + } 160 + 161 + static int class_function_sdw_remove_peripheral(struct snd_pcm_substream *substream, 162 + struct snd_soc_dai *dai) 163 + { 164 + struct class_function_drv *drv = snd_soc_component_get_drvdata(dai->component); 165 + struct sdw_stream_runtime *sdw_stream = snd_soc_dai_get_dma_data(dai, substream); 166 + struct sdw_slave *sdw = dev_to_sdw_dev(drv->dev->parent); 167 + 168 + if (!sdw_stream) 169 + return -EINVAL; 170 + 171 + return sdw_stream_remove_slave(sdw, sdw_stream); 172 + } 173 + 174 + static int class_function_sdw_set_stream(struct snd_soc_dai *dai, void *sdw_stream, 175 + int direction) 176 + { 177 + snd_soc_dai_dma_data_set(dai, direction, sdw_stream); 178 + 179 + return 0; 180 + } 181 + 182 + static const struct snd_soc_dai_ops class_function_sdw_ops = { 183 + .startup = class_function_startup, 184 + .shutdown = sdca_asoc_free_constraints, 185 + .set_stream = class_function_sdw_set_stream, 186 + .hw_params = class_function_sdw_add_peripheral, 187 + .hw_free = class_function_sdw_remove_peripheral, 188 + }; 189 + 190 + static int class_function_component_probe(struct snd_soc_component *component) 191 + { 192 + struct class_function_drv *drv = snd_soc_component_get_drvdata(component); 193 + struct sdca_class_drv *core = drv->core; 194 + 195 + return sdca_irq_populate(drv->function, component, core->irq_info); 196 + } 197 + 198 + static const struct snd_soc_component_driver class_function_component_drv = { 199 + .probe = class_function_component_probe, 200 + .endianness = 1, 201 + }; 202 + 203 + static int class_function_boot(struct class_function_drv *drv) 204 + { 205 + unsigned int reg = SDW_SDCA_CTL(drv->function->desc->adr, 206 + SDCA_ENTITY_TYPE_ENTITY_0, 207 + SDCA_CTL_ENTITY_0_FUNCTION_STATUS, 0); 208 + unsigned int val; 209 + int ret; 210 + 211 + ret = regmap_read(drv->regmap, reg, &val); 212 + if (ret < 0) { 213 + dev_err(drv->dev, "failed to read function status: %d\n", ret); 214 + return ret; 215 + } 216 + 217 + if (!(val & SDCA_CTL_ENTITY_0_FUNCTION_HAS_BEEN_RESET)) { 218 + dev_dbg(drv->dev, "reset function device\n"); 219 + 220 + ret = sdca_reset_function(drv->dev, drv->function, drv->regmap); 221 + if (ret) 222 + return ret; 223 + } 224 + 225 + if (val & SDCA_CTL_ENTITY_0_FUNCTION_NEEDS_INITIALIZATION) { 226 + dev_dbg(drv->dev, "write initialisation\n"); 227 + 228 + ret = sdca_regmap_write_init(drv->dev, drv->core->dev_regmap, 229 + drv->function); 230 + if (ret) 231 + return ret; 232 + 233 + ret = regmap_write(drv->regmap, reg, 234 + SDCA_CTL_ENTITY_0_FUNCTION_NEEDS_INITIALIZATION); 235 + if (ret < 0) { 236 + dev_err(drv->dev, 237 + "failed to clear function init status: %d\n", 238 + ret); 239 + return ret; 240 + } 241 + } 242 + 243 + /* Start FDL process */ 244 + ret = sdca_irq_populate_early(drv->dev, drv->regmap, drv->function, 245 + drv->core->irq_info); 246 + if (ret) 247 + return ret; 248 + 249 + ret = sdca_fdl_sync(drv->dev, drv->function, drv->core->irq_info); 250 + if (ret) 251 + return ret; 252 + 253 + ret = sdca_regmap_write_defaults(drv->dev, drv->regmap, drv->function); 254 + if (ret) 255 + return ret; 256 + 257 + ret = regmap_write(drv->regmap, reg, 0xFF); 258 + if (ret < 0) { 259 + dev_err(drv->dev, "failed to clear function status: %d\n", ret); 260 + return ret; 261 + } 262 + 263 + return 0; 264 + } 265 + 266 + static int class_function_probe(struct auxiliary_device *auxdev, 267 + const struct auxiliary_device_id *aux_dev_id) 268 + { 269 + struct device *dev = &auxdev->dev; 270 + struct sdca_class_drv *core = dev_get_drvdata(dev->parent); 271 + struct sdca_device_data *data = &core->sdw->sdca_data; 272 + struct sdca_function_desc *desc; 273 + struct snd_soc_component_driver *cmp_drv; 274 + struct snd_soc_dai_driver *dais; 275 + struct class_function_drv *drv; 276 + struct regmap_sdw_mbq_cfg *mbq_config; 277 + struct regmap_config *config; 278 + struct reg_default *defaults; 279 + int ndefaults; 280 + int num_dais; 281 + int ret; 282 + int i; 283 + 284 + drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL); 285 + if (!drv) 286 + return -ENOMEM; 287 + 288 + cmp_drv = devm_kmemdup(dev, &class_function_component_drv, sizeof(*cmp_drv), 289 + GFP_KERNEL); 290 + if (!cmp_drv) 291 + return -ENOMEM; 292 + 293 + config = devm_kmemdup(dev, &class_function_regmap_config, sizeof(*config), 294 + GFP_KERNEL); 295 + if (!config) 296 + return -ENOMEM; 297 + 298 + mbq_config = devm_kmemdup(dev, &class_function_mbq_config, sizeof(*mbq_config), 299 + GFP_KERNEL); 300 + if (!mbq_config) 301 + return -ENOMEM; 302 + 303 + drv->dev = dev; 304 + drv->core = core; 305 + 306 + for (i = 0; i < data->num_functions; i++) { 307 + desc = &data->function[i]; 308 + 309 + if (desc->type == aux_dev_id->driver_data) 310 + break; 311 + } 312 + if (i == core->sdw->sdca_data.num_functions) { 313 + dev_err(dev, "failed to locate function\n"); 314 + return -EINVAL; 315 + } 316 + 317 + drv->function = &core->functions[i]; 318 + 319 + ret = sdca_parse_function(dev, core->sdw, desc, drv->function); 320 + if (ret) 321 + return ret; 322 + 323 + ndefaults = sdca_regmap_count_constants(dev, drv->function); 324 + if (ndefaults < 0) 325 + return ndefaults; 326 + 327 + defaults = devm_kcalloc(dev, ndefaults, sizeof(*defaults), GFP_KERNEL); 328 + if (!defaults) 329 + return -ENOMEM; 330 + 331 + ret = sdca_regmap_populate_constants(dev, drv->function, defaults); 332 + if (ret < 0) 333 + return ret; 334 + 335 + regcache_sort_defaults(defaults, ndefaults); 336 + 337 + auxiliary_set_drvdata(auxdev, drv); 338 + 339 + config->reg_defaults = defaults; 340 + config->num_reg_defaults = ndefaults; 341 + config->lock_arg = &core->regmap_lock; 342 + 343 + if (drv->function->busy_max_delay) { 344 + mbq_config->timeout_us = drv->function->busy_max_delay; 345 + mbq_config->retry_us = umax(drv->function->busy_max_delay / 10, 346 + mbq_config->retry_us); 347 + } 348 + 349 + drv->regmap = devm_regmap_init_sdw_mbq_cfg(dev, core->sdw, config, mbq_config); 350 + if (IS_ERR(drv->regmap)) 351 + return dev_err_probe(dev, PTR_ERR(drv->regmap), 352 + "failed to create regmap"); 353 + 354 + ret = sdca_asoc_populate_component(dev, drv->function, cmp_drv, 355 + &dais, &num_dais, 356 + &class_function_sdw_ops); 357 + if (ret) 358 + return ret; 359 + 360 + pm_runtime_set_autosuspend_delay(dev, 200); 361 + pm_runtime_use_autosuspend(dev); 362 + pm_runtime_set_active(dev); 363 + pm_runtime_get_noresume(dev); 364 + 365 + ret = devm_pm_runtime_enable(dev); 366 + if (ret) 367 + return ret; 368 + 369 + ret = class_function_boot(drv); 370 + if (ret) 371 + return ret; 372 + 373 + ret = devm_snd_soc_register_component(dev, cmp_drv, dais, num_dais); 374 + if (ret) 375 + return dev_err_probe(dev, ret, "failed to register component\n"); 376 + 377 + pm_runtime_mark_last_busy(dev); 378 + pm_runtime_put_autosuspend(dev); 379 + 380 + return 0; 381 + } 382 + 383 + static int class_function_runtime_suspend(struct device *dev) 384 + { 385 + struct auxiliary_device *auxdev = to_auxiliary_dev(dev); 386 + struct class_function_drv *drv = auxiliary_get_drvdata(auxdev); 387 + 388 + /* 389 + * Whilst the driver doesn't power the chip down here, going into 390 + * runtime suspend means the driver can't be sure the bus won't 391 + * power down which would prevent communication with the device. 392 + */ 393 + regcache_cache_only(drv->regmap, true); 394 + 395 + return 0; 396 + } 397 + 398 + static int class_function_runtime_resume(struct device *dev) 399 + { 400 + struct auxiliary_device *auxdev = to_auxiliary_dev(dev); 401 + struct class_function_drv *drv = auxiliary_get_drvdata(auxdev); 402 + int ret; 403 + 404 + regcache_mark_dirty(drv->regmap); 405 + regcache_cache_only(drv->regmap, false); 406 + 407 + ret = regcache_sync(drv->regmap); 408 + if (ret) { 409 + dev_err(drv->dev, "failed to restore register cache: %d\n", ret); 410 + goto err; 411 + } 412 + 413 + return 0; 414 + 415 + err: 416 + regcache_cache_only(drv->regmap, true); 417 + 418 + return ret; 419 + } 420 + 421 + static const struct dev_pm_ops class_function_pm_ops = { 422 + RUNTIME_PM_OPS(class_function_runtime_suspend, 423 + class_function_runtime_resume, NULL) 424 + }; 425 + 426 + static const struct auxiliary_device_id class_function_id_table[] = { 427 + { 428 + .name = "snd_soc_sdca." SDCA_FUNCTION_TYPE_SMART_AMP_NAME, 429 + .driver_data = SDCA_FUNCTION_TYPE_SMART_AMP, 430 + }, 431 + { 432 + .name = "snd_soc_sdca." SDCA_FUNCTION_TYPE_SMART_MIC_NAME, 433 + .driver_data = SDCA_FUNCTION_TYPE_SMART_MIC, 434 + }, 435 + { 436 + .name = "snd_soc_sdca." SDCA_FUNCTION_TYPE_UAJ_NAME, 437 + .driver_data = SDCA_FUNCTION_TYPE_UAJ, 438 + }, 439 + { 440 + .name = "snd_soc_sdca." SDCA_FUNCTION_TYPE_HID_NAME, 441 + .driver_data = SDCA_FUNCTION_TYPE_HID, 442 + }, 443 + {}, 444 + }; 445 + MODULE_DEVICE_TABLE(auxiliary, class_function_id_table); 446 + 447 + static struct auxiliary_driver class_function_drv = { 448 + .driver = { 449 + .name = "sdca_function", 450 + .pm = pm_ptr(&class_function_pm_ops), 451 + }, 452 + 453 + .probe = class_function_probe, 454 + .id_table = class_function_id_table 455 + }; 456 + module_auxiliary_driver(class_function_drv); 457 + 458 + MODULE_LICENSE("GPL"); 459 + MODULE_DESCRIPTION("SDCA Class Function Driver"); 460 + MODULE_IMPORT_NS("SND_SOC_SDCA");
+55 -50
sound/soc/sdca/sdca_fdl.c
··· 51 51 return -EINVAL; 52 52 } 53 53 54 + /* 55 + * Poll up to 16 times but no more than once per ms, these are just 56 + * arbitrarily selected values, so may be fine tuned in future. 57 + */ 54 58 poll_us = umin(function->reset_max_delay >> 4, 1000); 55 59 56 60 ret = regmap_read_poll_timeout(regmap, reg, val, !val, poll_us, ··· 406 402 unsigned int reg, status; 407 403 int response, ret; 408 404 409 - guard(mutex)(&fdl_state->lock); 410 - 411 405 ret = sdca_ump_get_owner_host(dev, interrupt->function_regmap, 412 406 interrupt->function, interrupt->entity, 413 407 interrupt->control); ··· 414 412 415 413 sdca_ump_cancel_timeout(&fdl_state->timeout); 416 414 417 - reg = SDW_SDCA_CTL(interrupt->function->desc->adr, interrupt->entity->id, 418 - SDCA_CTL_XU_FDL_STATUS, 0); 419 - ret = regmap_read(interrupt->function_regmap, reg, &status); 420 - if (ret < 0) { 421 - dev_err(dev, "failed to read FDL status: %d\n", ret); 422 - return ret; 423 - } 424 - 425 - dev_dbg(dev, "FDL status: %#x\n", status); 426 - 427 - ret = fdl_status_process(interrupt, status); 428 - if (ret < 0) 429 - goto reset_function; 430 - 431 - response = ret; 432 - 433 - dev_dbg(dev, "FDL response: %#x\n", response); 434 - 435 - ret = regmap_write(interrupt->function_regmap, reg, 436 - response | (status & ~SDCA_CTL_XU_FDLH_MASK)); 437 - if (ret < 0) { 438 - dev_err(dev, "failed to set FDL status signal: %d\n", ret); 439 - return ret; 440 - } 441 - 442 - ret = sdca_ump_set_owner_device(dev, interrupt->function_regmap, 443 - interrupt->function, interrupt->entity, 444 - interrupt->control); 445 - if (ret) 446 - return ret; 447 - 448 - switch (response) { 449 - case SDCA_CTL_XU_FDLH_RESET_ACK: 450 - dev_dbg(dev, "FDL request reset\n"); 451 - 452 - switch (xu->reset_mechanism) { 453 - default: 454 - dev_warn(dev, "Requested reset mechanism not implemented\n"); 455 - fallthrough; 456 - case SDCA_XU_RESET_FUNCTION: 457 - goto reset_function; 415 + scoped_guard(mutex, &fdl_state->lock) { 416 + reg = SDW_SDCA_CTL(interrupt->function->desc->adr, 417 + interrupt->entity->id, SDCA_CTL_XU_FDL_STATUS, 0); 418 + ret = regmap_read(interrupt->function_regmap, reg, &status); 419 + if (ret < 0) { 420 + dev_err(dev, "failed to read FDL status: %d\n", ret); 421 + return ret; 458 422 } 459 - case SDCA_CTL_XU_FDLH_COMPLETE: 460 - if (status & SDCA_CTL_XU_FDLD_REQ_ABORT || 461 - status == SDCA_CTL_XU_FDLD_COMPLETE) 423 + 424 + dev_dbg(dev, "FDL status: %#x\n", status); 425 + 426 + ret = fdl_status_process(interrupt, status); 427 + if (ret < 0) 428 + goto reset_function; 429 + 430 + response = ret; 431 + 432 + dev_dbg(dev, "FDL response: %#x\n", response); 433 + 434 + ret = regmap_write(interrupt->function_regmap, reg, 435 + response | (status & ~SDCA_CTL_XU_FDLH_MASK)); 436 + if (ret < 0) { 437 + dev_err(dev, "failed to set FDL status signal: %d\n", ret); 438 + return ret; 439 + } 440 + 441 + ret = sdca_ump_set_owner_device(dev, interrupt->function_regmap, 442 + interrupt->function, 443 + interrupt->entity, 444 + interrupt->control); 445 + if (ret) 446 + return ret; 447 + 448 + switch (response) { 449 + case SDCA_CTL_XU_FDLH_RESET_ACK: 450 + dev_dbg(dev, "FDL request reset\n"); 451 + 452 + switch (xu->reset_mechanism) { 453 + default: 454 + dev_warn(dev, "Requested reset mechanism not implemented\n"); 455 + fallthrough; 456 + case SDCA_XU_RESET_FUNCTION: 457 + goto reset_function; 458 + } 459 + case SDCA_CTL_XU_FDLH_COMPLETE: 460 + if (status & SDCA_CTL_XU_FDLD_REQ_ABORT || 461 + status == SDCA_CTL_XU_FDLD_COMPLETE) 462 + return 0; 463 + fallthrough; 464 + default: 465 + sdca_ump_schedule_timeout(&fdl_state->timeout, xu->max_delay); 462 466 return 0; 463 - fallthrough; 464 - default: 465 - sdca_ump_schedule_timeout(&fdl_state->timeout, xu->max_delay); 466 - return 0; 467 + } 467 468 } 468 469 469 470 reset_function:
+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
+25 -27
sound/soc/sdca/sdca_functions.c
··· 6 6 * https://www.mipi.org/mipi-sdca-v1-0-download 7 7 */ 8 8 9 - #define dev_fmt(fmt) "%s: " fmt, __func__ 10 - 11 9 #include <linux/acpi.h> 12 10 #include <linux/byteorder/generic.h> 13 11 #include <linux/cleanup.h> ··· 1011 1013 control->type = find_sdca_control_datatype(entity, control); 1012 1014 control->nbits = find_sdca_control_bits(entity, control); 1013 1015 1014 - dev_info(dev, "%s: %s: control %#x mode %#x layers %#x cn %#llx int %d %s\n", 1015 - entity->label, control->label, control->sel, 1016 - control->mode, control->layers, control->cn_list, 1017 - control->interrupt_position, control->deferrable ? "deferrable" : ""); 1016 + dev_dbg(dev, "%s: %s: control %#x mode %#x layers %#x cn %#llx int %d %s\n", 1017 + entity->label, control->label, control->sel, 1018 + control->mode, control->layers, control->cn_list, 1019 + control->interrupt_position, control->deferrable ? "deferrable" : ""); 1018 1020 1019 1021 return 0; 1020 1022 } ··· 1135 1137 if (!ret) 1136 1138 terminal->num_transducer = tmp; 1137 1139 1138 - dev_info(dev, "%s: terminal type %#x ref %#x conn %#x count %d\n", 1139 - entity->label, terminal->type, terminal->reference, 1140 - terminal->connector, terminal->num_transducer); 1140 + dev_dbg(dev, "%s: terminal type %#x ref %#x conn %#x count %d\n", 1141 + entity->label, terminal->type, terminal->reference, 1142 + terminal->connector, terminal->num_transducer); 1141 1143 1142 1144 return 0; 1143 1145 } ··· 1163 1165 if (!ret) 1164 1166 clock->max_delay = tmp; 1165 1167 1166 - dev_info(dev, "%s: clock type %#x delay %d\n", entity->label, 1167 - clock->type, clock->max_delay); 1168 + dev_dbg(dev, "%s: clock type %#x delay %d\n", entity->label, 1169 + clock->type, clock->max_delay); 1168 1170 1169 1171 return 0; 1170 1172 } ··· 1215 1217 delays[i].to_ps = delay_list[j++]; 1216 1218 delays[i].us = delay_list[j++]; 1217 1219 1218 - dev_info(dev, "%s: from %#x to %#x delay %dus\n", entity->label, 1219 - delays[i].from_ps, delays[i].to_ps, delays[i].us); 1220 + dev_dbg(dev, "%s: from %#x to %#x delay %dus\n", entity->label, 1221 + delays[i].from_ps, delays[i].to_ps, delays[i].us); 1220 1222 } 1221 1223 1222 1224 power->num_max_delay = num_delays; ··· 1322 1324 unsigned char *report_desc = NULL; 1323 1325 1324 1326 ret = fwnode_property_read_u32(entity_node, 1325 - "mipi-sdca-RxUMP-ownership-transition-maxdelay", &delay); 1327 + "mipi-sdca-RxUMP-ownership-transition-max-delay", &delay); 1326 1328 if (!ret) 1327 1329 hide->max_delay = delay; 1328 1330 ··· 1445 1447 1446 1448 entity->type = tmp; 1447 1449 1448 - dev_info(dev, "%s: entity %#x type %#x\n", 1449 - entity->label, entity->id, entity->type); 1450 + dev_dbg(dev, "%s: entity %#x type %#x\n", 1451 + entity->label, entity->id, entity->type); 1450 1452 1451 1453 switch (entity->type) { 1452 1454 case SDCA_ENTITY_TYPE_IT: ··· 1621 1623 1622 1624 terminal->clock = clock_entity; 1623 1625 1624 - dev_info(dev, "%s -> %s\n", clock_entity->label, entity->label); 1626 + dev_dbg(dev, "%s -> %s\n", clock_entity->label, entity->label); 1625 1627 1626 1628 fwnode_handle_put(clock_node); 1627 1629 return 0; ··· 1671 1673 return -EINVAL; 1672 1674 } 1673 1675 1674 - dev_info(dev, "%s -> %s\n", managed[i]->label, entity->label); 1676 + dev_dbg(dev, "%s -> %s\n", managed[i]->label, entity->label); 1675 1677 } 1676 1678 1677 1679 power->num_managed = num_managed; ··· 1806 1808 1807 1809 pins[i] = connected_entity; 1808 1810 1809 - dev_info(dev, "%s -> %s\n", connected_entity->label, entity->label); 1811 + dev_dbg(dev, "%s -> %s\n", connected_entity->label, entity->label); 1810 1812 1811 1813 i++; 1812 1814 fwnode_handle_put(connected_node); ··· 1891 1893 1892 1894 channel->relationship = tmp; 1893 1895 1894 - dev_info(dev, "cluster %#x: channel id %#x purpose %#x relationship %#x\n", 1895 - cluster->id, channel->id, channel->purpose, channel->relationship); 1896 + dev_dbg(dev, "cluster %#x: channel id %#x purpose %#x relationship %#x\n", 1897 + cluster->id, channel->id, channel->purpose, channel->relationship); 1896 1898 1897 1899 return 0; 1898 1900 } ··· 2063 2065 return -EINVAL; 2064 2066 } 2065 2067 2066 - dev_info(dev, "fileset: %#x\n", filesets_list[i]); 2068 + dev_dbg(dev, "fileset: %#x\n", filesets_list[i]); 2067 2069 2068 2070 files = devm_kcalloc(dev, num_entries / mult_fileset, 2069 2071 sizeof(struct sdca_fdl_file), GFP_KERNEL); ··· 2084 2086 file->file_id = fileset_entries[j++]; 2085 2087 file->fdl_offset = fileset_entries[j++]; 2086 2088 2087 - dev_info(dev, "file: %#x, vendor: %#x, offset: %#x\n", 2088 - file->file_id, file->vendor_id, file->fdl_offset); 2089 + dev_dbg(dev, "file: %#x, vendor: %#x, offset: %#x\n", 2090 + file->file_id, file->vendor_id, file->fdl_offset); 2089 2091 } 2090 2092 2091 2093 set->id = filesets_list[i]; ··· 2128 2130 if (!ret) 2129 2131 function->reset_max_delay = tmp; 2130 2132 2131 - dev_info(dev, "%pfwP: name %s busy delay %dus reset delay %dus\n", 2132 - function->desc->node, function->desc->name, 2133 - function->busy_max_delay, function->reset_max_delay); 2133 + dev_dbg(dev, "%pfwP: name %s busy delay %dus reset delay %dus\n", 2134 + function->desc->node, function->desc->name, 2135 + function->busy_max_delay, function->reset_max_delay); 2134 2136 2135 2137 ret = find_sdca_init_table(dev, function_desc->node, function); 2136 2138 if (ret)
-3
sound/soc/sdca/sdca_hid.c
··· 166 166 return 0; 167 167 } 168 168 EXPORT_SYMBOL_NS(sdca_hid_process_report, "SND_SOC_SDCA"); 169 - 170 - MODULE_LICENSE("Dual BSD/GPL"); 171 - MODULE_DESCRIPTION("SDCA HID library");
+14 -25
sound/soc/sdca/sdca_interrupts.c
··· 456 456 else if (!interrupt) 457 457 continue; 458 458 459 - switch (entity->type) { 460 - case SDCA_ENTITY_TYPE_XU: 461 - if (control->sel != SDCA_CTL_XU_FDL_CURRENTOWNER) 462 - break; 463 - 459 + switch (SDCA_CTL_TYPE(entity->type, control->sel)) { 460 + case SDCA_CTL_TYPE_S(XU, FDL_CURRENTOWNER): 464 461 ret = sdca_irq_data_populate(dev, regmap, NULL, 465 462 function, entity, 466 463 control, interrupt); ··· 531 534 532 535 handler = base_handler; 533 536 534 - switch (entity->type) { 535 - case SDCA_ENTITY_TYPE_ENTITY_0: 536 - if (control->sel == SDCA_CTL_ENTITY_0_FUNCTION_STATUS) 537 - handler = function_status_handler; 537 + switch (SDCA_CTL_TYPE(entity->type, control->sel)) { 538 + case SDCA_CTL_TYPE_S(ENTITY_0, FUNCTION_STATUS): 539 + handler = function_status_handler; 538 540 break; 539 - case SDCA_ENTITY_TYPE_GE: 540 - if (control->sel == SDCA_CTL_GE_DETECTED_MODE) 541 - handler = detected_mode_handler; 541 + case SDCA_CTL_TYPE_S(GE, DETECTED_MODE): 542 + handler = detected_mode_handler; 542 543 break; 543 - case SDCA_ENTITY_TYPE_XU: 544 - if (control->sel == SDCA_CTL_XU_FDL_CURRENTOWNER) { 545 - ret = sdca_fdl_alloc_state(interrupt); 546 - if (ret) 547 - return ret; 544 + case SDCA_CTL_TYPE_S(XU, FDL_CURRENTOWNER): 545 + ret = sdca_fdl_alloc_state(interrupt); 546 + if (ret) 547 + return ret; 548 548 549 - handler = fdl_owner_handler; 550 - } 549 + handler = fdl_owner_handler; 551 550 break; 552 - case SDCA_ENTITY_TYPE_HIDE: 553 - if (control->sel == SDCA_CTL_HIDE_HIDTX_CURRENTOWNER) 554 - handler = hid_handler; 551 + case SDCA_CTL_TYPE_S(HIDE, HIDTX_CURRENTOWNER): 552 + handler = hid_handler; 555 553 break; 556 554 default: 557 555 break; ··· 610 618 return info; 611 619 } 612 620 EXPORT_SYMBOL_NS_GPL(sdca_irq_allocate, "SND_SOC_SDCA"); 613 - 614 - MODULE_LICENSE("GPL"); 615 - MODULE_DESCRIPTION("SDCA IRQ library");
+68 -23
sound/soc/sdca/sdca_regmap.c
··· 275 275 } 276 276 EXPORT_SYMBOL_NS(sdca_regmap_populate_constants, "SND_SOC_SDCA"); 277 277 278 + static int populate_control_defaults(struct device *dev, struct regmap *regmap, 279 + struct sdca_function_data *function, 280 + struct sdca_entity *entity, 281 + struct sdca_control *control) 282 + { 283 + int i, ret; 284 + int cn; 285 + 286 + if (control->mode == SDCA_ACCESS_MODE_DC) 287 + return 0; 288 + 289 + if (control->layers & SDCA_ACCESS_LAYER_DEVICE) 290 + return 0; 291 + 292 + i = 0; 293 + for_each_set_bit(cn, (unsigned long *)&control->cn_list, 294 + BITS_PER_TYPE(control->cn_list)) { 295 + unsigned int reg, val; 296 + 297 + reg = SDW_SDCA_CTL(function->desc->adr, entity->id, control->sel, cn); 298 + 299 + if (control->has_default || control->has_fixed) { 300 + ret = regmap_write(regmap, reg, control->values[i]); 301 + if (ret) { 302 + dev_err(dev, "Failed to write default %#x: %d\n", 303 + reg, ret); 304 + return ret; 305 + } 306 + 307 + i++; 308 + } else if (!control->is_volatile) { 309 + ret = regmap_read(regmap, reg, &val); 310 + if (ret) { 311 + dev_err(dev, "Failed to read initial %#x: %d\n", 312 + reg, ret); 313 + return ret; 314 + } 315 + } 316 + } 317 + 318 + return 0; 319 + } 320 + 278 321 /** 279 322 * sdca_regmap_write_defaults - write out DisCo defaults to device 280 323 * @dev: Pointer to the device. ··· 326 283 * 327 284 * This function will write out to the hardware all the DisCo default and 328 285 * fixed value controls. This will cause them to be populated into the cache, 329 - * and subsequent handling can be done through a cache sync. 286 + * and subsequent handling can be done through a cache sync. It will also 287 + * read any non-volatile registers that don't have defaults/fixed values to 288 + * populate those into the cache, this ensures they are available for reads 289 + * even when the device is runtime suspended. 330 290 * 331 291 * Return: Returns zero on success, and a negative error code on failure. 332 292 */ 333 293 int sdca_regmap_write_defaults(struct device *dev, struct regmap *regmap, 334 294 struct sdca_function_data *function) 335 295 { 336 - int i, j, k; 296 + int i, j; 337 297 int ret; 338 298 339 299 for (i = 0; i < function->num_entities; i++) { ··· 344 298 345 299 for (j = 0; j < entity->num_controls; j++) { 346 300 struct sdca_control *control = &entity->controls[j]; 347 - int cn; 348 301 349 - if (control->mode == SDCA_ACCESS_MODE_DC) 350 - continue; 351 - 352 - if (!control->has_default && !control->has_fixed) 353 - continue; 354 - 355 - k = 0; 356 - for_each_set_bit(cn, (unsigned long *)&control->cn_list, 357 - BITS_PER_TYPE(control->cn_list)) { 358 - unsigned int reg; 359 - 360 - reg = SDW_SDCA_CTL(function->desc->adr, entity->id, 361 - control->sel, cn); 362 - 363 - ret = regmap_write(regmap, reg, control->values[k]); 364 - if (ret) 365 - return ret; 366 - 367 - k++; 368 - } 302 + ret = populate_control_defaults(dev, regmap, function, 303 + entity, control); 304 + if (ret) 305 + return ret; 369 306 } 370 307 } 371 308 372 309 return 0; 373 310 } 374 311 EXPORT_SYMBOL_NS(sdca_regmap_write_defaults, "SND_SOC_SDCA"); 312 + 313 + int sdca_regmap_write_init(struct device *dev, struct regmap *regmap, 314 + struct sdca_function_data *function) 315 + { 316 + struct sdca_init_write *init = function->init_table; 317 + int ret, i; 318 + 319 + for (i = 0; i < function->num_init_table; i++) { 320 + ret = regmap_write(regmap, init[i].addr, init[i].val); 321 + if (ret) 322 + return ret; 323 + } 324 + 325 + return 0; 326 + } 327 + EXPORT_SYMBOL_NS(sdca_regmap_write_init, "SND_SOC_SDCA");