[PATCH v1 0/2] Read _SUB from ACPI to be able to identify firmware
CS35L41 has a DSP which is able to run firmware, as well as a tuning file. Different systems may want to use different firmwares and tuning files, and some firmwares/tunings may not be compatible with other systems. To allow a system to select the correct fimware/tuning, we can read an _SUB from the ACPI. This _SUB can then be used to uniquely identify the system in the firmware/tuning file name.
Add a helper function which reads the _SUB, so this can be used by other parts in the future. Add support inside the CS35L41 ASoC driver to read this _SUB, and save it appropriately.
Stefan Binding (2): ACPI: utils: Add api to read _SUB from ACPI ASoC: cs35l41: Read System Name from ACPI _SUB to identify firmware
drivers/acpi/utils.c | 26 ++++++++++++++++++++++++++ include/linux/acpi.h | 8 ++++++++ sound/soc/codecs/cs35l41.c | 27 +++++++++++++++++++++++++++ 3 files changed, 61 insertions(+)
Add a wrapper function to read the _SUB string from ACPI.
Signed-off-by: Stefan Binding sbinding@opensource.cirrus.com --- drivers/acpi/utils.c | 26 ++++++++++++++++++++++++++ include/linux/acpi.h | 8 ++++++++ 2 files changed, 34 insertions(+)
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c index 3a9773a09e19..5d1bdb79e372 100644 --- a/drivers/acpi/utils.c +++ b/drivers/acpi/utils.c @@ -291,6 +291,32 @@ int acpi_get_local_address(acpi_handle handle, u32 *addr) } EXPORT_SYMBOL(acpi_get_local_address);
+int acpi_get_sub(acpi_handle handle, char *sub, size_t size) +{ + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; + union acpi_object *obj; + acpi_status status; + int ret; + + status = acpi_evaluate_object(handle, METHOD_NAME__SUB, NULL, &buffer); + if (!ACPI_SUCCESS(status)) { + acpi_handle_debug(handle, "Reading ACPI _SUB failed: %#x\n", status); + return -ENOENT; + } + + obj = buffer.pointer; + if (obj->type == ACPI_TYPE_STRING) { + ret = strscpy(sub, obj->string.pointer, size); + } else { + acpi_handle_warn(handle, "Warning ACPI _SUB did not return a string\n"); + ret = -EINVAL; + } + acpi_os_free(buffer.pointer); + + return ret; +} +EXPORT_SYMBOL_GPL(acpi_get_sub); + acpi_status acpi_evaluate_reference(acpi_handle handle, acpi_string pathname, diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 4f82a5bc6d98..9bf18adf5920 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -21,6 +21,8 @@ #endif #include <acpi/acpi.h>
+#define ACPI_MAX_SUB_BUF_SIZE 9 + #ifdef CONFIG_ACPI
#include <linux/list.h> @@ -762,6 +764,7 @@ static inline u64 acpi_arch_get_root_pointer(void) #endif
int acpi_get_local_address(acpi_handle handle, u32 *addr); +int acpi_get_sub(acpi_handle handle, char *sub, size_t size);
#else /* !CONFIG_ACPI */
@@ -1023,6 +1026,11 @@ static inline int acpi_get_local_address(acpi_handle handle, u32 *addr) return -ENODEV; }
+static int acpi_get_sub(acpi_handle handle, char *sub, size_t size) +{ + return -ENODEV; +} + static inline int acpi_register_wakeup_handler(int wake_irq, bool (*wakeup)(void *context), void *context) {
On Wed, Jun 22, 2022 at 3:08 PM Stefan Binding sbinding@opensource.cirrus.com wrote:
Add a wrapper function to read the _SUB string from ACPI.
Signed-off-by: Stefan Binding sbinding@opensource.cirrus.com
drivers/acpi/utils.c | 26 ++++++++++++++++++++++++++ include/linux/acpi.h | 8 ++++++++ 2 files changed, 34 insertions(+)
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c index 3a9773a09e19..5d1bdb79e372 100644 --- a/drivers/acpi/utils.c +++ b/drivers/acpi/utils.c @@ -291,6 +291,32 @@ int acpi_get_local_address(acpi_handle handle, u32 *addr) } EXPORT_SYMBOL(acpi_get_local_address);
+int acpi_get_sub(acpi_handle handle, char *sub, size_t size)
I'd call it acpi_get_subsystem_id().
+{
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
union acpi_object *obj;
acpi_status status;
int ret;
status = acpi_evaluate_object(handle, METHOD_NAME__SUB, NULL, &buffer);
if (!ACPI_SUCCESS(status)) {
Typically, ACPI_FAILURE() is used in checks like this.
acpi_handle_debug(handle, "Reading ACPI _SUB failed: %#x\n", status);
It would be enough to say "_SUB evaluation failed".
return -ENOENT;
Why not use -ENODATA here?
}
obj = buffer.pointer;
if (obj->type == ACPI_TYPE_STRING) {
ret = strscpy(sub, obj->string.pointer, size);
It may be simpler to allocate the memory here so that callers don't have to worry about it.
Also, this is expected to be a proper device ID, not just a string, so maybe some validation checks could be made here?
} else {
acpi_handle_warn(handle, "Warning ACPI _SUB did not return a string\n");
ret = -EINVAL;
}
acpi_os_free(buffer.pointer);
return ret;
+} +EXPORT_SYMBOL_GPL(acpi_get_sub);
acpi_status acpi_evaluate_reference(acpi_handle handle, acpi_string pathname, diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 4f82a5bc6d98..9bf18adf5920 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -21,6 +21,8 @@ #endif #include <acpi/acpi.h>
+#define ACPI_MAX_SUB_BUF_SIZE 9
#ifdef CONFIG_ACPI
#include <linux/list.h> @@ -762,6 +764,7 @@ static inline u64 acpi_arch_get_root_pointer(void) #endif
int acpi_get_local_address(acpi_handle handle, u32 *addr); +int acpi_get_sub(acpi_handle handle, char *sub, size_t size);
#else /* !CONFIG_ACPI */
@@ -1023,6 +1026,11 @@ static inline int acpi_get_local_address(acpi_handle handle, u32 *addr) return -ENODEV; }
+static int acpi_get_sub(acpi_handle handle, char *sub, size_t size) +{
return -ENODEV;
+}
static inline int acpi_register_wakeup_handler(int wake_irq, bool (*wakeup)(void *context), void *context) { --
Hi Stefan,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on rafael-pm/linux-next] [also build test ERROR on broonie-sound/for-next linus/master v5.19-rc3 next-20220622] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/Stefan-Binding/Read-_SUB-from... base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next config: powerpc-buildonly-randconfig-r002-20220622 (https://download.01.org/0day-ci/archive/20220623/202206230433.0LyjOI85-lkp@i...) compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 8b8d126598ce7bd5243da7f94f69fa1104288bee) reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # install powerpc cross compiling tool for clang build # apt-get install binutils-powerpc-linux-gnu # https://github.com/intel-lab-lkp/linux/commit/97b928a895ce3105296f0036393bb9... git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Stefan-Binding/Read-_SUB-from-ACPI-to-be-able-to-identify-firmware/20220622-211004 git checkout 97b928a895ce3105296f0036393bb9ee04f11ae4 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=powerpc SHELL=/bin/bash arch/powerpc/
If you fix the issue, kindly add following tag where applicable Reported-by: kernel test robot lkp@intel.com
All errors (new ones prefixed by >>):
In file included from arch/powerpc/kernel/traps.c:32: In file included from include/linux/backlight.h:13: In file included from include/linux/fb.h:7: In file included from include/uapi/linux/fb.h:6: In file included from include/linux/i2c.h:13:
include/linux/acpi.h:1029:12: error: unused function 'acpi_get_sub' [-Werror,-Wunused-function]
static int acpi_get_sub(acpi_handle handle, char *sub, size_t size) ^ 1 error generated.
vim +/acpi_get_sub +1029 include/linux/acpi.h
1028
1029 static int acpi_get_sub(acpi_handle handle, char *sub, size_t size)
1030 { 1031 return -ENODEV; 1032 } 1033
Hi Stefan,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on rafael-pm/linux-next] [also build test ERROR on broonie-sound/for-next linus/master v5.19-rc3 next-20220622] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/Stefan-Binding/Read-_SUB-from... base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next config: powerpc-pasemi_defconfig (https://download.01.org/0day-ci/archive/20220623/202206230402.9xK6YlsY-lkp@i...) compiler: powerpc-linux-gcc (GCC) 11.3.0 reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/intel-lab-lkp/linux/commit/97b928a895ce3105296f0036393bb9... git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Stefan-Binding/Read-_SUB-from-ACPI-to-be-able-to-identify-firmware/20220622-211004 git checkout 97b928a895ce3105296f0036393bb9ee04f11ae4 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=powerpc SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable Reported-by: kernel test robot lkp@intel.com
All errors (new ones prefixed by >>):
In file included from include/linux/i2c.h:13, from include/uapi/linux/fb.h:6, from include/linux/fb.h:7, from include/linux/backlight.h:13, from arch/powerpc/kernel/traps.c:32:
include/linux/acpi.h:1029:12: error: 'acpi_get_sub' defined but not used [-Werror=unused-function]
1029 | static int acpi_get_sub(acpi_handle handle, char *sub, size_t size) | ^~~~~~~~~~~~ cc1: all warnings being treated as errors
vim +/acpi_get_sub +1029 include/linux/acpi.h
1028
1029 static int acpi_get_sub(acpi_handle handle, char *sub, size_t size)
1030 { 1031 return -ENODEV; 1032 } 1033
When loading firmware, wm_adsp uses a number of parameters to determine the path of the firmware and tuning files to load. One of these parameters is system_name. Add support in cs35l41 to read this system name from the ACPI _SUB ID in order to uniquely identify the firmware and tuning mapped to a particular system.
Signed-off-by: Stefan Binding sbinding@opensource.cirrus.com --- sound/soc/codecs/cs35l41.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
diff --git a/sound/soc/codecs/cs35l41.c b/sound/soc/codecs/cs35l41.c index 8766e19d85f1..5df04a2ab5a3 100644 --- a/sound/soc/codecs/cs35l41.c +++ b/sound/soc/codecs/cs35l41.c @@ -6,6 +6,7 @@ // // Author: David Rhodes david.rhodes@cirrus.com
+#include <linux/acpi.h> #include <linux/delay.h> #include <linux/err.h> #include <linux/init.h> @@ -1142,6 +1143,28 @@ static int cs35l41_dsp_init(struct cs35l41_private *cs35l41) return ret; }
+static int cs35l41_probe_acpi(struct cs35l41_private *cs35l41) +{ + struct acpi_device *adev; + int ret; + char sub[ACPI_MAX_SUB_BUF_SIZE]; + + adev = ACPI_COMPANION(cs35l41->dev); + /* If there is no ACPI_COMPANION, there is no ACPI for this system, return 0 */ + if (!adev) + return 0; + + ret = acpi_get_sub(adev->handle, sub, sizeof(sub)); + if (ret < 0) + return ret; + + cs35l41->dsp.system_name = devm_kstrdup(cs35l41->dev, sub, GFP_KERNEL); + if (!cs35l41->dsp.system_name) + return -ENOMEM; + + return 0; +} + int cs35l41_probe(struct cs35l41_private *cs35l41, const struct cs35l41_hw_cfg *hw_cfg) { u32 regid, reg_revid, i, mtl_revid, int_status, chipid_match; @@ -1270,6 +1293,10 @@ int cs35l41_probe(struct cs35l41_private *cs35l41, const struct cs35l41_hw_cfg * goto err; }
+ ret = cs35l41_probe_acpi(cs35l41); + if (ret < 0) + goto err; + ret = cs35l41_dsp_init(cs35l41); if (ret < 0) goto err;
Hi Stefan,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on rafael-pm/linux-next] [also build test ERROR on broonie-sound/for-next linus/master v5.19-rc3 next-20220622] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/Stefan-Binding/Read-_SUB-from... base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next config: sparc64-randconfig-r002-20220622 (https://download.01.org/0day-ci/archive/20220623/202206231108.xPflWTbR-lkp@i...) compiler: sparc64-linux-gcc (GCC) 11.3.0 reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/intel-lab-lkp/linux/commit/338eadc59e88d60759ea445011a653... git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Stefan-Binding/Read-_SUB-from-ACPI-to-be-able-to-identify-firmware/20220622-211004 git checkout 338eadc59e88d60759ea445011a6537222b233e3 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=sparc64 SHELL=/bin/bash sound/soc/codecs/
If you fix the issue, kindly add following tag where applicable Reported-by: kernel test robot lkp@intel.com
All errors (new ones prefixed by >>):
sound/soc/codecs/cs35l41.c: In function 'cs35l41_probe_acpi':
sound/soc/codecs/cs35l41.c:1157:32: error: invalid use of undefined type 'struct acpi_device'
1157 | ret = acpi_get_sub(adev->handle, sub, sizeof(sub)); | ^~
vim +1157 sound/soc/codecs/cs35l41.c
1145 1146 static int cs35l41_probe_acpi(struct cs35l41_private *cs35l41) 1147 { 1148 struct acpi_device *adev; 1149 int ret; 1150 char sub[ACPI_MAX_SUB_BUF_SIZE]; 1151 1152 adev = ACPI_COMPANION(cs35l41->dev); 1153 /* If there is no ACPI_COMPANION, there is no ACPI for this system, return 0 */ 1154 if (!adev) 1155 return 0; 1156
1157 ret = acpi_get_sub(adev->handle, sub, sizeof(sub));
1158 if (ret < 0) 1159 return ret; 1160 1161 cs35l41->dsp.system_name = devm_kstrdup(cs35l41->dev, sub, GFP_KERNEL); 1162 if (!cs35l41->dsp.system_name) 1163 return -ENOMEM; 1164 1165 return 0; 1166 } 1167
participants (3)
-
kernel test robot
-
Rafael J. Wysocki
-
Stefan Binding