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

ALSA: hda: move Intel SoundWire ACPI scan to dedicated module

The ACPI scan capabilities is called from the intel-dspconfig as well
as the SOF/HDaudio drivers. This creates dependencies and randconfig issues
when HDaudio and SOF/SoundWire are not all configured as modules.

To simplify Kconfig dependencies between HDAudio, SoundWire, SOF and
intel-dspconfig, move the ACPI scan helpers to a dedicated
module. This follows the same idea as NHLT helpers which are already
handled as a dedicated module.

The only functional change is that the kernel parameter to filter
links is now handled by a different module, but that was only provided
for developers needing work-arounds for early BIOS releases.

Reported-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Reviewed-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Reviewed-by: Bard Liao <bard.liao@intel.com>
Acked-by: Mark Brown <broonie@kernel.org>
Acked-by: Vinod Koul <vkoul@kernel.org>
Link: https://lore.kernel.org/r/20210302003125.1178419-7-pierre-louis.bossart@linux.intel.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>

authored by

Pierre-Louis Bossart and committed by
Takashi Iwai
08c2a4bc cf5807f5

+186 -161
-2
drivers/soundwire/intel.h
··· 48 48 #endif 49 49 }; 50 50 51 - #define SDW_INTEL_QUIRK_MASK_BUS_DISABLE BIT(1) 52 - 53 51 int intel_master_startup(struct platform_device *pdev); 54 52 int intel_master_process_wakeen_event(struct platform_device *pdev); 55 53
-158
drivers/soundwire/intel_init.c
··· 18 18 #include "cadence_master.h" 19 19 #include "intel.h" 20 20 21 - #define SDW_LINK_TYPE 4 /* from Intel ACPI documentation */ 22 - #define SDW_MAX_LINKS 4 23 21 #define SDW_SHIM_LCAP 0x0 24 22 #define SDW_SHIM_BASE 0x2C000 25 23 #define SDW_ALH_BASE 0x2C800 26 24 #define SDW_LINK_BASE 0x30000 27 25 #define SDW_LINK_SIZE 0x10000 28 - 29 - static int ctrl_link_mask; 30 - module_param_named(sdw_link_mask, ctrl_link_mask, int, 0444); 31 - MODULE_PARM_DESC(sdw_link_mask, "Intel link mask (one bit per link)"); 32 - 33 - static bool is_link_enabled(struct fwnode_handle *fw_node, int i) 34 - { 35 - struct fwnode_handle *link; 36 - char name[32]; 37 - u32 quirk_mask = 0; 38 - 39 - /* Find master handle */ 40 - snprintf(name, sizeof(name), 41 - "mipi-sdw-link-%d-subproperties", i); 42 - 43 - link = fwnode_get_named_child_node(fw_node, name); 44 - if (!link) 45 - return false; 46 - 47 - fwnode_property_read_u32(link, 48 - "intel-quirk-mask", 49 - &quirk_mask); 50 - 51 - if (quirk_mask & SDW_INTEL_QUIRK_MASK_BUS_DISABLE) 52 - return false; 53 - 54 - return true; 55 - } 56 26 57 27 static int sdw_intel_cleanup(struct sdw_intel_ctx *ctx) 58 28 { ··· 46 76 47 77 if (!link->clock_stop_quirks) 48 78 pm_runtime_put_noidle(link->dev); 49 - } 50 - 51 - return 0; 52 - } 53 - 54 - static int 55 - sdw_intel_scan_controller(struct sdw_intel_acpi_info *info) 56 - { 57 - struct acpi_device *adev; 58 - int ret, i; 59 - u8 count; 60 - 61 - if (acpi_bus_get_device(info->handle, &adev)) 62 - return -EINVAL; 63 - 64 - /* Found controller, find links supported */ 65 - count = 0; 66 - ret = fwnode_property_read_u8_array(acpi_fwnode_handle(adev), 67 - "mipi-sdw-master-count", &count, 1); 68 - 69 - /* 70 - * In theory we could check the number of links supported in 71 - * hardware, but in that step we cannot assume SoundWire IP is 72 - * powered. 73 - * 74 - * In addition, if the BIOS doesn't even provide this 75 - * 'master-count' property then all the inits based on link 76 - * masks will fail as well. 77 - * 78 - * We will check the hardware capabilities in the startup() step 79 - */ 80 - 81 - if (ret) { 82 - dev_err(&adev->dev, 83 - "Failed to read mipi-sdw-master-count: %d\n", ret); 84 - return -EINVAL; 85 - } 86 - 87 - /* Check count is within bounds */ 88 - if (count > SDW_MAX_LINKS) { 89 - dev_err(&adev->dev, "Link count %d exceeds max %d\n", 90 - count, SDW_MAX_LINKS); 91 - return -EINVAL; 92 - } 93 - 94 - if (!count) { 95 - dev_warn(&adev->dev, "No SoundWire links detected\n"); 96 - return -EINVAL; 97 - } 98 - dev_dbg(&adev->dev, "ACPI reports %d SDW Link devices\n", count); 99 - 100 - info->count = count; 101 - info->link_mask = 0; 102 - 103 - for (i = 0; i < count; i++) { 104 - if (ctrl_link_mask && !(ctrl_link_mask & BIT(i))) { 105 - dev_dbg(&adev->dev, 106 - "Link %d masked, will not be enabled\n", i); 107 - continue; 108 - } 109 - 110 - if (!is_link_enabled(acpi_fwnode_handle(adev), i)) { 111 - dev_dbg(&adev->dev, 112 - "Link %d not selected in firmware\n", i); 113 - continue; 114 - } 115 - 116 - info->link_mask |= BIT(i); 117 79 } 118 80 119 81 return 0; ··· 258 356 259 357 return 0; 260 358 } 261 - 262 - static acpi_status sdw_intel_acpi_cb(acpi_handle handle, u32 level, 263 - void *cdata, void **return_value) 264 - { 265 - struct sdw_intel_acpi_info *info = cdata; 266 - struct acpi_device *adev; 267 - acpi_status status; 268 - u64 adr; 269 - 270 - status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, &adr); 271 - if (ACPI_FAILURE(status)) 272 - return AE_OK; /* keep going */ 273 - 274 - if (acpi_bus_get_device(handle, &adev)) { 275 - pr_err("%s: Couldn't find ACPI handle\n", __func__); 276 - return AE_NOT_FOUND; 277 - } 278 - 279 - info->handle = handle; 280 - 281 - /* 282 - * On some Intel platforms, multiple children of the HDAS 283 - * device can be found, but only one of them is the SoundWire 284 - * controller. The SNDW device is always exposed with 285 - * Name(_ADR, 0x40000000), with bits 31..28 representing the 286 - * SoundWire link so filter accordingly 287 - */ 288 - if (FIELD_GET(GENMASK(31, 28), adr) != SDW_LINK_TYPE) 289 - return AE_OK; /* keep going */ 290 - 291 - /* device found, stop namespace walk */ 292 - return AE_CTRL_TERMINATE; 293 - } 294 - 295 - /** 296 - * sdw_intel_acpi_scan() - SoundWire Intel init routine 297 - * @parent_handle: ACPI parent handle 298 - * @info: description of what firmware/DSDT tables expose 299 - * 300 - * This scans the namespace and queries firmware to figure out which 301 - * links to enable. A follow-up use of sdw_intel_probe() and 302 - * sdw_intel_startup() is required for creation of devices and bus 303 - * startup 304 - */ 305 - int sdw_intel_acpi_scan(acpi_handle *parent_handle, 306 - struct sdw_intel_acpi_info *info) 307 - { 308 - acpi_status status; 309 - 310 - info->handle = NULL; 311 - status = acpi_walk_namespace(ACPI_TYPE_DEVICE, 312 - parent_handle, 1, 313 - sdw_intel_acpi_cb, 314 - NULL, info, NULL); 315 - if (ACPI_FAILURE(status) || info->handle == NULL) 316 - return -ENODEV; 317 - 318 - return sdw_intel_scan_controller(info); 319 - } 320 - EXPORT_SYMBOL_NS(sdw_intel_acpi_scan, SOUNDWIRE_INTEL_INIT); 321 359 322 360 /** 323 361 * sdw_intel_probe() - SoundWire Intel probe routine
+2
include/linux/soundwire/sdw_intel.h
··· 187 187 188 188 irqreturn_t sdw_intel_thread(int irq, void *dev_id); 189 189 190 + #define SDW_INTEL_QUIRK_MASK_BUS_DISABLE BIT(1) 191 + 190 192 #endif
+4
sound/hda/Kconfig
··· 44 44 config SND_INTEL_DSP_CONFIG 45 45 tristate 46 46 select SND_INTEL_NHLT if ACPI 47 + select SND_INTEL_SOUNDWIRE_ACPI if ACPI 47 48 # this config should be selected only for Intel DSP platforms. 48 49 # A fallback is provided so that the code compiles in all cases. 50 + 51 + config SND_INTEL_SOUNDWIRE_ACPI 52 + tristate 49 53 50 54 config SND_INTEL_BYT_PREFER_SOF 51 55 bool "Prefer SOF driver over SST on BY/CHT platforms"
+3
sound/hda/Makefile
··· 17 17 snd-intel-dspcfg-objs := intel-dsp-config.o 18 18 snd-intel-dspcfg-$(CONFIG_SND_INTEL_NHLT) += intel-nhlt.o 19 19 obj-$(CONFIG_SND_INTEL_DSP_CONFIG) += snd-intel-dspcfg.o 20 + 21 + snd-intel-sdw-acpi-objs := intel-sdw-acpi.o 22 + obj-$(CONFIG_SND_INTEL_SOUNDWIRE_ACPI) += snd-intel-sdw-acpi.o
+1 -1
sound/hda/intel-dsp-config.c
··· 557 557 558 558 MODULE_LICENSE("GPL v2"); 559 559 MODULE_DESCRIPTION("Intel DSP config driver"); 560 - MODULE_IMPORT_NS(SOUNDWIRE_INTEL_INIT); 560 + MODULE_IMPORT_NS(SND_INTEL_SOUNDWIRE_ACPI);
+174
sound/hda/intel-sdw-acpi.c
··· 1 + // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) 2 + // Copyright(c) 2015-2021 Intel Corporation. 3 + 4 + /* 5 + * SDW Intel ACPI scan helpers 6 + */ 7 + 8 + #include <linux/acpi.h> 9 + #include <linux/export.h> 10 + #include <linux/module.h> 11 + #include <linux/soundwire/sdw_intel.h> 12 + #include <linux/string.h> 13 + 14 + #define SDW_LINK_TYPE 4 /* from Intel ACPI documentation */ 15 + #define SDW_MAX_LINKS 4 16 + 17 + static int ctrl_link_mask; 18 + module_param_named(sdw_link_mask, ctrl_link_mask, int, 0444); 19 + MODULE_PARM_DESC(sdw_link_mask, "Intel link mask (one bit per link)"); 20 + 21 + static bool is_link_enabled(struct fwnode_handle *fw_node, int i) 22 + { 23 + struct fwnode_handle *link; 24 + char name[32]; 25 + u32 quirk_mask = 0; 26 + 27 + /* Find master handle */ 28 + snprintf(name, sizeof(name), 29 + "mipi-sdw-link-%d-subproperties", i); 30 + 31 + link = fwnode_get_named_child_node(fw_node, name); 32 + if (!link) 33 + return false; 34 + 35 + fwnode_property_read_u32(link, 36 + "intel-quirk-mask", 37 + &quirk_mask); 38 + 39 + if (quirk_mask & SDW_INTEL_QUIRK_MASK_BUS_DISABLE) 40 + return false; 41 + 42 + return true; 43 + } 44 + 45 + static int 46 + sdw_intel_scan_controller(struct sdw_intel_acpi_info *info) 47 + { 48 + struct acpi_device *adev; 49 + int ret, i; 50 + u8 count; 51 + 52 + if (acpi_bus_get_device(info->handle, &adev)) 53 + return -EINVAL; 54 + 55 + /* Found controller, find links supported */ 56 + count = 0; 57 + ret = fwnode_property_read_u8_array(acpi_fwnode_handle(adev), 58 + "mipi-sdw-master-count", &count, 1); 59 + 60 + /* 61 + * In theory we could check the number of links supported in 62 + * hardware, but in that step we cannot assume SoundWire IP is 63 + * powered. 64 + * 65 + * In addition, if the BIOS doesn't even provide this 66 + * 'master-count' property then all the inits based on link 67 + * masks will fail as well. 68 + * 69 + * We will check the hardware capabilities in the startup() step 70 + */ 71 + 72 + if (ret) { 73 + dev_err(&adev->dev, 74 + "Failed to read mipi-sdw-master-count: %d\n", ret); 75 + return -EINVAL; 76 + } 77 + 78 + /* Check count is within bounds */ 79 + if (count > SDW_MAX_LINKS) { 80 + dev_err(&adev->dev, "Link count %d exceeds max %d\n", 81 + count, SDW_MAX_LINKS); 82 + return -EINVAL; 83 + } 84 + 85 + if (!count) { 86 + dev_warn(&adev->dev, "No SoundWire links detected\n"); 87 + return -EINVAL; 88 + } 89 + dev_dbg(&adev->dev, "ACPI reports %d SDW Link devices\n", count); 90 + 91 + info->count = count; 92 + info->link_mask = 0; 93 + 94 + for (i = 0; i < count; i++) { 95 + if (ctrl_link_mask && !(ctrl_link_mask & BIT(i))) { 96 + dev_dbg(&adev->dev, 97 + "Link %d masked, will not be enabled\n", i); 98 + continue; 99 + } 100 + 101 + if (!is_link_enabled(acpi_fwnode_handle(adev), i)) { 102 + dev_dbg(&adev->dev, 103 + "Link %d not selected in firmware\n", i); 104 + continue; 105 + } 106 + 107 + info->link_mask |= BIT(i); 108 + } 109 + 110 + return 0; 111 + } 112 + 113 + static acpi_status sdw_intel_acpi_cb(acpi_handle handle, u32 level, 114 + void *cdata, void **return_value) 115 + { 116 + struct sdw_intel_acpi_info *info = cdata; 117 + struct acpi_device *adev; 118 + acpi_status status; 119 + u64 adr; 120 + 121 + status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, &adr); 122 + if (ACPI_FAILURE(status)) 123 + return AE_OK; /* keep going */ 124 + 125 + if (acpi_bus_get_device(handle, &adev)) { 126 + pr_err("%s: Couldn't find ACPI handle\n", __func__); 127 + return AE_NOT_FOUND; 128 + } 129 + 130 + info->handle = handle; 131 + 132 + /* 133 + * On some Intel platforms, multiple children of the HDAS 134 + * device can be found, but only one of them is the SoundWire 135 + * controller. The SNDW device is always exposed with 136 + * Name(_ADR, 0x40000000), with bits 31..28 representing the 137 + * SoundWire link so filter accordingly 138 + */ 139 + if (FIELD_GET(GENMASK(31, 28), adr) != SDW_LINK_TYPE) 140 + return AE_OK; /* keep going */ 141 + 142 + /* device found, stop namespace walk */ 143 + return AE_CTRL_TERMINATE; 144 + } 145 + 146 + /** 147 + * sdw_intel_acpi_scan() - SoundWire Intel init routine 148 + * @parent_handle: ACPI parent handle 149 + * @info: description of what firmware/DSDT tables expose 150 + * 151 + * This scans the namespace and queries firmware to figure out which 152 + * links to enable. A follow-up use of sdw_intel_probe() and 153 + * sdw_intel_startup() is required for creation of devices and bus 154 + * startup 155 + */ 156 + int sdw_intel_acpi_scan(acpi_handle *parent_handle, 157 + struct sdw_intel_acpi_info *info) 158 + { 159 + acpi_status status; 160 + 161 + info->handle = NULL; 162 + status = acpi_walk_namespace(ACPI_TYPE_DEVICE, 163 + parent_handle, 1, 164 + sdw_intel_acpi_cb, 165 + NULL, info, NULL); 166 + if (ACPI_FAILURE(status) || info->handle == NULL) 167 + return -ENODEV; 168 + 169 + return sdw_intel_scan_controller(info); 170 + } 171 + EXPORT_SYMBOL_NS(sdw_intel_acpi_scan, SND_INTEL_SOUNDWIRE_ACPI); 172 + 173 + MODULE_LICENSE("Dual BSD/GPL"); 174 + MODULE_DESCRIPTION("Intel Soundwire ACPI helpers");
+1
sound/soc/sof/intel/Kconfig
··· 286 286 depends on ACPI && SOUNDWIRE 287 287 depends on !(SOUNDWIRE=m && SND_SOC_SOF_INTEL_SOUNDWIRE_LINK_BASELINE=y) 288 288 select SOUNDWIRE_INTEL 289 + select SND_INTEL_SOUNDWIRE_ACPI 289 290 help 290 291 This adds support for SoundWire with Sound Open Firmware 291 292 for Intel(R) platforms.
+1
sound/soc/sof/intel/hda.c
··· 1279 1279 MODULE_IMPORT_NS(SND_SOC_SOF_HDA_AUDIO_CODEC); 1280 1280 MODULE_IMPORT_NS(SND_SOC_SOF_HDA_AUDIO_CODEC_I915); 1281 1281 MODULE_IMPORT_NS(SND_SOC_SOF_XTENSA); 1282 + MODULE_IMPORT_NS(SND_INTEL_SOUNDWIRE_ACPI); 1282 1283 MODULE_IMPORT_NS(SOUNDWIRE_INTEL_INIT);