Alsa-devel
Threads by month
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
June 2024
- 96 participants
- 202 discussions
10 Jun '24
This driver was ported from an old version in linux 2.6.27 and adjusted
for the new ASoC framework and DMA API.
Signed-off-by: Piotr Wojtaszczyk <piotr.wojtaszczyk(a)timesys.com>
---
.../bindings/sound/nxp,lpc3220-i2s.yaml | 50 +++
arch/arm/boot/dts/lpc32xx.dtsi | 4 +
arch/arm/mach-lpc32xx/phy3250.c | 60 +++
sound/soc/fsl/Kconfig | 7 +
sound/soc/fsl/Makefile | 2 +
sound/soc/fsl/lpc3xxx-i2s.c | 411 ++++++++++++++++++
sound/soc/fsl/lpc3xxx-i2s.h | 94 ++++
sound/soc/fsl/lpc3xxx-pcm.c | 75 ++++
8 files changed, 703 insertions(+)
create mode 100644 Documentation/devicetree/bindings/sound/nxp,lpc3220-i2s.yaml
create mode 100644 sound/soc/fsl/lpc3xxx-i2s.c
create mode 100644 sound/soc/fsl/lpc3xxx-i2s.h
create mode 100644 sound/soc/fsl/lpc3xxx-pcm.c
diff --git a/Documentation/devicetree/bindings/sound/nxp,lpc3220-i2s.yaml b/Documentation/devicetree/bindings/sound/nxp,lpc3220-i2s.yaml
new file mode 100644
index 000000000000..e41330b6775c
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/nxp,lpc3220-i2s.yaml
@@ -0,0 +1,50 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/nxp,lpc3220-i2s.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: NXP LPC32XX I2S Controller
+
+description:
+ The block adds I2S and PCM drivers for LPC32XX
+
+properties:
+ compatible:
+ enum:
+ - nxp,lpc3220-i2s
+
+ reg:
+ maxItems: 1
+
+ clocks:
+ items:
+ - description: input clock of the peripheral.
+
+ clock-names:
+ items:
+ - const: i2s_clk
+
+ interrupts:
+ maxItems: 1
+
+required:
+ - compatible
+ - reg
+ - clocks
+ - clock-names
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/clock/lpc32xx-clock.h>
+
+ i2s0: i2s@20094000 {
+ compatible = "nxp,lpc3220-i2s";
+ reg = <0x20094000 0x1000>;
+ clocks = <&clk LPC32XX_CLK_I2S0>;
+ clock-names = "i2s_clk";
+ };
+
+...
diff --git a/arch/arm/boot/dts/lpc32xx.dtsi b/arch/arm/boot/dts/lpc32xx.dtsi
index c87066d6c995..dc5738f2b42d 100644
--- a/arch/arm/boot/dts/lpc32xx.dtsi
+++ b/arch/arm/boot/dts/lpc32xx.dtsi
@@ -221,6 +221,8 @@ spi2: spi@20090000 {
i2s0: i2s@20094000 {
compatible = "nxp,lpc3220-i2s";
reg = <0x20094000 0x1000>;
+ clocks = <&clk LPC32XX_CLK_I2S0>;
+ clock-names = "i2s_clk";
status = "disabled";
};
@@ -237,6 +239,8 @@ sd: sd@20098000 {
i2s1: i2s@2009c000 {
compatible = "nxp,lpc3220-i2s";
reg = <0x2009c000 0x1000>;
+ clocks = <&clk LPC32XX_CLK_I2S1>;
+ clock-names = "i2s_clk";
status = "disabled";
};
diff --git a/arch/arm/mach-lpc32xx/phy3250.c b/arch/arm/mach-lpc32xx/phy3250.c
index 66701bf43248..b866b9a75558 100644
--- a/arch/arm/mach-lpc32xx/phy3250.c
+++ b/arch/arm/mach-lpc32xx/phy3250.c
@@ -9,6 +9,7 @@
*/
#include <linux/amba/pl08x.h>
+#include <linux/amba/pl022.h>
#include <linux/mtd/lpc32xx_mlc.h>
#include <linux/mtd/lpc32xx_slc.h>
#include <linux/of_platform.h>
@@ -29,6 +30,46 @@ static struct pl08x_channel_data pl08x_slave_channels[] = {
.max_signal = 12,
.periph_buses = PL08X_AHB1,
},
+ {
+ .bus_id = "i2s-tx",
+ .min_signal = 13,
+ .max_signal = 13,
+ .periph_buses = PL08X_AHB1,
+ },
+ {
+ .bus_id = "i2s-rx",
+ .min_signal = 0,
+ .max_signal = 0,
+ .periph_buses = PL08X_AHB1,
+ },
+ {
+ .bus_id = "ssp0-tx",
+ .min_signal = 15,
+ .max_signal = 15,
+ .muxval = 1,
+ .periph_buses = PL08X_AHB1,
+ },
+ {
+ .bus_id = "ssp0-rx",
+ .min_signal = 14,
+ .max_signal = 14,
+ .muxval = 1,
+ .periph_buses = PL08X_AHB1,
+ },
+ {
+ .bus_id = "ssp1-tx",
+ .min_signal = 11,
+ .max_signal = 11,
+ .muxval = 1,
+ .periph_buses = PL08X_AHB1,
+ },
+ {
+ .bus_id = "ssp1-rx",
+ .min_signal = 3,
+ .max_signal = 3,
+ .muxval = 1,
+ .periph_buses = PL08X_AHB1,
+ },
};
static int pl08x_get_signal(const struct pl08x_channel_data *cd)
@@ -60,12 +101,31 @@ static struct lpc32xx_mlc_platform_data lpc32xx_mlc_data = {
.dma_filter = pl08x_filter_id,
};
+static struct pl022_ssp_controller lpc32xx_ssp_data[] = {
+ {
+ .bus_id = 0,
+ .enable_dma = 0,
+ .dma_filter = pl08x_filter_id,
+ .dma_tx_param = "ssp0-tx",
+ .dma_rx_param = "ssp0-rx",
+ },
+ {
+ .bus_id = 1,
+ .enable_dma = 0,
+ .dma_filter = pl08x_filter_id,
+ .dma_tx_param = "ssp1-tx",
+ .dma_rx_param = "ssp1-rx",
+ }
+};
+
static const struct of_dev_auxdata lpc32xx_auxdata_lookup[] __initconst = {
OF_DEV_AUXDATA("arm,pl080", 0x31000000, "pl08xdmac", &pl08x_pd),
OF_DEV_AUXDATA("nxp,lpc3220-slc", 0x20020000, "20020000.flash",
&lpc32xx_slc_data),
OF_DEV_AUXDATA("nxp,lpc3220-mlc", 0x200a8000, "200a8000.flash",
&lpc32xx_mlc_data),
+ OF_DEV_AUXDATA("arm,pl022", 0x20084000, NULL, &lpc32xx_ssp_data[0]),
+ OF_DEV_AUXDATA("arm,pl022", 0x2008c000, NULL, &lpc32xx_ssp_data[1]),
{ }
};
diff --git a/sound/soc/fsl/Kconfig b/sound/soc/fsl/Kconfig
index 258306d8ce51..5f25aa7d632c 100644
--- a/sound/soc/fsl/Kconfig
+++ b/sound/soc/fsl/Kconfig
@@ -132,6 +132,13 @@ config SND_SOC_FSL_RPMSG
This option is only useful for out-of-tree drivers since
in-tree drivers select it automatically.
+config SND_SOC_FSL_LPC3XXX
+ tristate "SoC Audio for NXP LPC32XX CPUs"
+ depends on ARCH_LPC32XX && SND_SOC
+ select SND_SOC_GENERIC_DMAENGINE_PCM
+ help
+ Say Y or M if you want to add support for the LPC3XXX I2S interface.
+
config SND_SOC_IMX_PCM_DMA
tristate
select SND_SOC_GENERIC_DMAENGINE_PCM
diff --git a/sound/soc/fsl/Makefile b/sound/soc/fsl/Makefile
index 9f743fcc0e02..988dc98cdfc6 100644
--- a/sound/soc/fsl/Makefile
+++ b/sound/soc/fsl/Makefile
@@ -29,6 +29,7 @@ snd-soc-fsl-easrc-objs := fsl_easrc.o
snd-soc-fsl-xcvr-objs := fsl_xcvr.o
snd-soc-fsl-aud2htx-objs := fsl_aud2htx.o
snd-soc-fsl-rpmsg-objs := fsl_rpmsg.o
+snd-soc-fsl-lpc3xxx-objs := lpc3xxx-pcm.o lpc3xxx-i2s.o
obj-$(CONFIG_SND_SOC_FSL_AUDMIX) += snd-soc-fsl-audmix.o
obj-$(CONFIG_SND_SOC_FSL_ASOC_CARD) += snd-soc-fsl-asoc-card.o
@@ -45,6 +46,7 @@ obj-$(CONFIG_SND_SOC_POWERPC_DMA) += snd-soc-fsl-dma.o
obj-$(CONFIG_SND_SOC_FSL_XCVR) += snd-soc-fsl-xcvr.o
obj-$(CONFIG_SND_SOC_FSL_AUD2HTX) += snd-soc-fsl-aud2htx.o
obj-$(CONFIG_SND_SOC_FSL_RPMSG) += snd-soc-fsl-rpmsg.o
+obj-$(CONFIG_SND_SOC_FSL_LPC3XXX) += snd-soc-fsl-lpc3xxx.o
# MPC5200 Platform Support
obj-$(CONFIG_SND_MPC52xx_DMA) += mpc5200_dma.o
diff --git a/sound/soc/fsl/lpc3xxx-i2s.c b/sound/soc/fsl/lpc3xxx-i2s.c
new file mode 100644
index 000000000000..853284eb14f1
--- /dev/null
+++ b/sound/soc/fsl/lpc3xxx-i2s.c
@@ -0,0 +1,411 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Author: Kevin Wells <kevin.wells(a)nxp.com>
+ *
+ * Copyright (C) 2008 NXP Semiconductors
+ * Copyright 2023 Timesys Corporation <piotr.wojtaszczyk(a)timesys.com>
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/device.h>
+#include <linux/delay.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/dmaengine_pcm.h>
+#include <sound/initval.h>
+#include <sound/soc.h>
+
+#include "lpc3xxx-i2s.h"
+
+#define I2S_PLAYBACK_FLAG 0x1
+#define I2S_CAPTURE_FLAG 0x2
+
+#define LPC3XXX_I2S_RATES ( \
+ SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \
+ SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
+ SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000)
+
+#define LPC3XXX_I2S_FORMATS ( \
+ SNDRV_PCM_FMTBIT_S8 | \
+ SNDRV_PCM_FMTBIT_S16_LE | \
+ SNDRV_PCM_FMTBIT_S32_LE)
+
+static u32 absd32(u32 v1, u32 v2)
+{
+ if (v1 > v2) {
+ return v1 - v2;
+ }
+ return v2 - v1;
+}
+
+static void __lpc3xxx_find_clkdiv(u32 *clkx, u32 *clky, int freq,
+ int xbytes, u32 clkrate)
+{
+ u32 i2srate;
+ u32 idxx, idyy;
+ u32 savedbitclkrate, diff, trate, baseclk;
+
+ /* Adjust rate for sample size (bits) and 2 channels and offset for
+ * divider in clock output
+ */
+ i2srate = (freq / 100) * 2 * (8 * xbytes);
+ i2srate = i2srate << 1;
+ clkrate = clkrate / 100;
+ baseclk = clkrate;
+ *clkx = 1;
+ *clky = 1;
+
+ /* Find the best divider */
+ *clkx = *clky = 0;
+ savedbitclkrate = 0;
+ diff = ~0;
+ for (idxx = 1; idxx < 0xFF; idxx++) {
+ for (idyy = 1; idyy < 0xFF; idyy++) {
+ trate = (baseclk * idxx) / idyy;
+ if (absd32(trate, i2srate) < diff) {
+ diff = absd32(trate, i2srate);
+ savedbitclkrate = trate;
+ *clkx = idxx;
+ *clky = idyy;
+ }
+ }
+ }
+}
+
+static int lpc3xxx_i2s_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai)
+{
+ struct lpc3xxx_i2s_info *i2s_info_p = snd_soc_dai_get_drvdata(cpu_dai);
+ struct device *dev = i2s_info_p->dev;
+ u32 flag;
+ int ret = 0;
+
+ mutex_lock(&i2s_info_p->lock);
+
+ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+ flag = I2S_PLAYBACK_FLAG;
+ } else {
+ flag = I2S_CAPTURE_FLAG;
+ }
+
+ if (flag & i2s_info_p->streams_in_use) {
+ dev_warn(dev, "I2S channel is busy\n");
+ ret = -EBUSY;
+ goto lpc32xx_unlock;
+ }
+
+ if (i2s_info_p->streams_in_use == 0) {
+ ret = clk_prepare_enable(i2s_info_p->clk);
+ if (ret) {
+ dev_err(dev, "Can't enable clock, err=%d\n", ret);
+ goto lpc32xx_unlock;
+ }
+ }
+
+ i2s_info_p->streams_in_use |= flag;
+
+lpc32xx_unlock:
+ mutex_unlock(&i2s_info_p->lock);
+ return ret;
+}
+
+static void lpc3xxx_i2s_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai)
+{
+ struct lpc3xxx_i2s_info *i2s_info_p = snd_soc_dai_get_drvdata(cpu_dai);
+ struct regmap *regs = i2s_info_p->regs;
+ const u32 stop_bits = (I2S_RESET | I2S_STOP);
+ u32 flag;
+
+ mutex_lock(&i2s_info_p->lock);
+
+ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+ flag = I2S_PLAYBACK_FLAG;
+ regmap_write(regs, I2S_TX_RATE, 0);
+ regmap_update_bits(regs, I2S_DAO, stop_bits, stop_bits);
+ } else {
+ flag = I2S_CAPTURE_FLAG;
+ regmap_write(regs, I2S_RX_RATE, 0);
+ regmap_update_bits(regs, I2S_DAI, stop_bits, stop_bits);
+ }
+ i2s_info_p->streams_in_use &= ~flag;
+
+ if (i2s_info_p->streams_in_use == 0) {
+ clk_disable_unprepare(i2s_info_p->clk);
+ }
+
+ mutex_unlock(&i2s_info_p->lock);
+}
+
+static int lpc3xxx_i2s_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
+ int clk_id, unsigned int freq, int dir)
+{
+ struct lpc3xxx_i2s_info *i2s_info_p = snd_soc_dai_get_drvdata(cpu_dai);
+
+ /* Will use in HW params later */
+ i2s_info_p->freq = freq;
+
+ return 0;
+}
+
+static int lpc3xxx_i2s_set_dai_fmt(struct snd_soc_dai *cpu_dai,
+ unsigned int fmt)
+{
+ struct lpc3xxx_i2s_info *i2s_info_p = snd_soc_dai_get_drvdata(cpu_dai);
+ struct device *dev = i2s_info_p->dev;
+
+ if ((fmt & SND_SOC_DAIFMT_FORMAT_MASK) != SND_SOC_DAIFMT_I2S) {
+ dev_warn(dev, "unsupported bus format %d\n", fmt);
+ return -EINVAL;
+ }
+ return 0;
+}
+
+static int lpc3xxx_i2s_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params, struct snd_soc_dai *cpu_dai)
+{
+ struct lpc3xxx_i2s_info *i2s_info_p = snd_soc_dai_get_drvdata(cpu_dai);
+ struct device *dev = i2s_info_p->dev;
+ struct regmap *regs = i2s_info_p->regs;
+ int xfersize;
+ u32 tmp, clkx, clky;
+
+ tmp = I2S_RESET | I2S_STOP;
+ switch (params_format(params)) {
+ case SNDRV_PCM_FORMAT_S8:
+ tmp |= I2S_WW8 | I2S_WS_HP(I2S_WW8_HP);
+ xfersize = 1;
+ break;
+
+ case SNDRV_PCM_FORMAT_S16_LE:
+ tmp |= I2S_WW16 | I2S_WS_HP(I2S_WW16_HP);
+ xfersize = 2;
+ break;
+
+ case SNDRV_PCM_FORMAT_S32_LE:
+ tmp |= I2S_WW32 | I2S_WS_HP(I2S_WW32_HP);
+ xfersize = 4;
+ break;
+
+ default:
+ dev_warn(dev, "Unsupported audio data format %d\n",
+ params_format(params));
+ return -EINVAL;
+ }
+
+ if (params_channels(params) == 1) {
+ tmp |= I2S_MONO;
+ }
+
+ __lpc3xxx_find_clkdiv(&clkx, &clky, i2s_info_p->freq, xfersize, i2s_info_p->clkrate);
+
+ dev_dbg(dev, "Stream : %s\n",
+ substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? "playback" : "capture");
+ dev_dbg(dev, "Desired clock rate : %d\n", i2s_info_p->freq);
+ dev_dbg(dev, "Base clock rate : %d\n", i2s_info_p->clkrate);
+ dev_dbg(dev, "Transfer size (bytes) : %d\n", xfersize);
+ dev_dbg(dev, "Clock divider (x) : %d\n", clkx);
+ dev_dbg(dev, "Clock divider (y) : %d\n", clky);
+ dev_dbg(dev, "Channels : %d\n", params_channels(params));
+ dev_dbg(dev, "Data format : %s\n", "I2S");
+
+ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+ regmap_write(regs, I2S_DMA1, I2S_DMA1_TX_EN | I2S_DMA0_TX_DEPTH(4));
+ regmap_write(regs, I2S_TX_RATE, (clkx << 8) | clky);
+ regmap_write(regs, I2S_DAO, tmp);
+ } else {
+ regmap_write(regs, I2S_DMA0, I2S_DMA0_RX_EN | I2S_DMA1_RX_DEPTH(4));
+ regmap_write(regs, I2S_RX_RATE, (clkx << 8) | clky);
+ regmap_write(regs, I2S_DAI, tmp);
+ }
+
+ return 0;
+}
+
+static int lpc3xxx_i2s_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai)
+{
+ return 0;
+}
+
+static int lpc3xxx_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
+ struct snd_soc_dai *cpu_dai)
+{
+ struct lpc3xxx_i2s_info *i2s_info_p = snd_soc_dai_get_drvdata(cpu_dai);
+ struct regmap *regs = i2s_info_p->regs;
+ int ret = 0;
+
+ switch (cmd) {
+ case SNDRV_PCM_TRIGGER_STOP:
+ case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+ case SNDRV_PCM_TRIGGER_SUSPEND:
+ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+ regmap_update_bits(regs, I2S_DAO, I2S_STOP, I2S_STOP);
+ } else {
+ regmap_update_bits(regs, I2S_DAI, I2S_STOP, I2S_STOP);
+ }
+ break;
+
+ case SNDRV_PCM_TRIGGER_START:
+ case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+ case SNDRV_PCM_TRIGGER_RESUME:
+ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+ regmap_update_bits(regs, I2S_DAO, (I2S_RESET | I2S_STOP), 0);
+ } else {
+ regmap_update_bits(regs, I2S_DAI, (I2S_RESET | I2S_STOP), 0);
+ }
+ break;
+ default:
+ ret = -EINVAL;
+ }
+
+ return ret;
+}
+
+const struct snd_soc_dai_ops lpc3xxx_i2s_dai_ops = {
+ .startup = lpc3xxx_i2s_startup,
+ .shutdown = lpc3xxx_i2s_shutdown,
+ .prepare = lpc3xxx_i2s_prepare,
+ .trigger = lpc3xxx_i2s_trigger,
+ .hw_params = lpc3xxx_i2s_hw_params,
+ .set_sysclk = lpc3xxx_i2s_set_dai_sysclk,
+ .set_fmt = lpc3xxx_i2s_set_dai_fmt,
+};
+
+static int lpc3xxx_i2s_dai_probe(struct snd_soc_dai *dai)
+{
+ struct lpc3xxx_i2s_info *i2s_info_p = snd_soc_dai_get_drvdata(dai);
+
+ snd_soc_dai_init_dma_data(dai, &i2s_info_p->playback_dma_config,
+ &i2s_info_p->capture_dma_config);
+ return 0;
+}
+
+struct snd_soc_dai_driver lpc3xxx_i2s_dai_driver = {
+ .probe = lpc3xxx_i2s_dai_probe,
+ .playback = {
+ .channels_min = 1,
+ .channels_max = 2,
+ .rates = LPC3XXX_I2S_RATES,
+ .formats = LPC3XXX_I2S_FORMATS,
+ },
+ .capture = {
+ .channels_min = 1,
+ .channels_max = 2,
+ .rates = LPC3XXX_I2S_RATES,
+ .formats = LPC3XXX_I2S_FORMATS,
+ },
+ .ops = &lpc3xxx_i2s_dai_ops,
+ .symmetric_rate = 1,
+ .symmetric_channels = 1,
+ .symmetric_sample_bits = 1,
+};
+
+static const struct snd_soc_component_driver lpc32xx_i2s_component = {
+ .name = "lpc32xx-i2s",
+};
+
+static const struct regmap_config lpc32xx_i2s_regconfig = {
+ .reg_bits = 32,
+ .reg_stride = 4,
+ .val_bits = 32,
+ .max_register = I2S_RX_RATE,
+};
+
+static int lpc32xx_i2s_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct lpc3xxx_i2s_info *i2s_info_p;
+ struct resource *res;
+ void __iomem *iomem;
+ int ret;
+
+ i2s_info_p = devm_kzalloc(dev, sizeof(*i2s_info_p), GFP_KERNEL);
+ if (!i2s_info_p)
+ return -ENOMEM;
+
+ platform_set_drvdata(pdev, i2s_info_p);
+ i2s_info_p->dev = dev;
+
+ iomem = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
+ if (IS_ERR(iomem)) {
+ dev_err(dev, "Can't map registers\n");
+ return PTR_ERR(iomem);
+ }
+
+ i2s_info_p->regs = devm_regmap_init_mmio(dev, iomem, &lpc32xx_i2s_regconfig);
+ if (IS_ERR(i2s_info_p->regs)) {
+ ret = PTR_ERR(i2s_info_p->regs);
+ dev_err(dev, "failed to init register map: %d\n", ret);
+ return ret;
+ }
+
+ i2s_info_p->clk = devm_clk_get(dev, "i2s_clk");
+ if (IS_ERR(i2s_info_p->clk)) {
+ dev_err(dev, "Can't get clock\n");
+ return PTR_ERR(i2s_info_p->clk);
+ }
+
+ i2s_info_p->clkrate = clk_get_rate(i2s_info_p->clk);
+ if (i2s_info_p->clkrate == 0) {
+ dev_err(dev, "Invalid returned clock rate\n");
+ goto err_clk_disable;
+ }
+
+ mutex_init(&i2s_info_p->lock);
+
+ ret = devm_snd_soc_register_component(dev, &lpc32xx_i2s_component,
+ &lpc3xxx_i2s_dai_driver, 1);
+ if (ret) {
+ dev_err(dev, "Can't register cpu_dai component\n");
+ goto err_clk_disable;
+ }
+
+ i2s_info_p->playback_dma_config.addr = (dma_addr_t)(res->start + I2S_TX_FIFO);
+ i2s_info_p->playback_dma_config.maxburst = 4;
+ i2s_info_p->playback_dma_config.filter_data = "i2s-tx";
+ i2s_info_p->capture_dma_config.addr = (dma_addr_t)(res->start + I2S_RX_FIFO);
+ i2s_info_p->capture_dma_config.maxburst = 4;
+ i2s_info_p->capture_dma_config.filter_data = "i2s-rx";
+
+ ret = lpc3xxx_pcm_register(pdev);
+ if (ret) {
+ dev_err(dev, "Can't register pcm component\n");
+ goto err_clk_disable;
+ }
+
+ return 0;
+
+err_clk_disable:
+ return ret;
+}
+
+static int lpc32xx_i2s_remove(struct platform_device *pdev)
+{
+ return 0;
+}
+
+static const struct of_device_id lpc32xx_i2s_match[] = {
+ { .compatible = "nxp,lpc3220-i2s" },
+ {},
+};
+MODULE_DEVICE_TABLE(of, lpc32xx_i2s_match);
+
+static struct platform_driver lpc32xx_i2s_driver = {
+ .probe = lpc32xx_i2s_probe,
+ .remove = lpc32xx_i2s_remove,
+ .driver = {
+ .name = "lpc3xxx-i2s",
+ .of_match_table = of_match_ptr(lpc32xx_i2s_match),
+ },
+};
+
+module_platform_driver(lpc32xx_i2s_driver);
+
+MODULE_AUTHOR("Kevin Wells <kevin.wells(a)nxp.com>");
+MODULE_AUTHOR("Piotr Wojtaszczyk <piotr.wojtaszczyk(a)timesys.com>");
+MODULE_DESCRIPTION("ASoC LPC3XXX I2S interface");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/fsl/lpc3xxx-i2s.h b/sound/soc/fsl/lpc3xxx-i2s.h
new file mode 100644
index 000000000000..f88ab74cfe41
--- /dev/null
+++ b/sound/soc/fsl/lpc3xxx-i2s.h
@@ -0,0 +1,94 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Author: Kevin Wells <kevin.wells(a)nxp.com>
+ *
+ * Copyright (C) 2008 NXP Semiconductors
+ * Copyright 2023 Timesys Corporation <piotr.wojtaszczyk(a)timesys.com>
+ */
+
+#ifndef __SOUND_SOC_LPC3XXX_I2S_H
+#define __SOUND_SOC_LPC3XXX_I2S_H
+
+#include <linux/types.h>
+#include <linux/regmap.h>
+
+struct lpc3xxx_i2s_info {
+ struct device *dev;
+ struct clk *clk;
+ struct mutex lock;
+ struct regmap *regs;
+ u32 streams_in_use;
+ u32 clkrate;
+ int freq;
+ struct snd_dmaengine_dai_dma_data playback_dma_config;
+ struct snd_dmaengine_dai_dma_data capture_dma_config;
+};
+
+int lpc3xxx_pcm_register(struct platform_device *pdev);
+
+#define _SBF(f, v) ((v) << (f))
+#define _BIT(n) _SBF(n, 1)
+
+/* I2S controller register offsets */
+#define I2S_DAO 0x00
+#define I2S_DAI 0x04
+#define I2S_TX_FIFO 0x08
+#define I2S_RX_FIFO 0x0C
+#define I2S_STAT 0x10
+#define I2S_DMA0 0x14
+#define I2S_DMA1 0x18
+#define I2S_IRQ 0x1C
+#define I2S_TX_RATE 0x20
+#define I2S_RX_RATE 0x24
+
+/* i2s_daO i2s_dai register definitions */
+#define I2S_WW8 _SBF(0, 0) /* Word width is 8bit*/
+#define I2S_WW16 _SBF(0, 1) /* Word width is 16bit*/
+#define I2S_WW32 _SBF(0, 3) /* Word width is 32bit*/
+#define I2S_MONO _BIT(2) /* Mono */
+#define I2S_STOP _BIT(3) /* Stop, diables the access to FIFO, mutes the channel */
+#define I2S_RESET _BIT(4) /* Reset the channel */
+#define I2S_WS_SEL _BIT(5) /* Channel Master(0) or slave(1) mode select*/
+#define I2S_WS_HP(s) _SBF(6, s) /* Word select half period - 1 */
+
+#define I2S_MUTE _BIT(15) /* Mute the channel, Transmit channel only */
+
+#define I2S_WW32_HP 0x1f /* Word select half period for 32bit word width */
+#define I2S_WW16_HP 0x0f /* Word select half period for 16bit word width */
+#define I2S_WW8_HP 0x7 /* Word select half period for 8bit word width */
+
+#define WSMASK_HP 0X7FC /* Mask for WS half period bits */
+
+/* i2s_tx_fifo register definitions */
+#define I2S_FIFO_TX_WRITE(d) (d)
+
+/* i2s_rx_fifo register definitions */
+#define I2S_FIFO_RX_WRITE(d) (d)
+
+/* i2s_stat register definitions */
+#define I2S_IRQ_STAT _BIT(0)
+#define I2S_DMA0_REQ _BIT(1)
+#define I2S_DMA1_REQ _BIT(2)
+
+#define I2S_RX_STATE_MASK 0x0000ff00
+#define I2S_TX_STATE_MASK 0x00ff0000
+
+/* i2s_dma0 Configuration register definitions */
+#define I2S_DMA0_RX_EN _BIT(0) /* Enable RX DMA1*/
+#define I2S_DMA0_TX_EN _BIT(1) /* Enable TX DMA1*/
+#define I2S_DMA0_RX_DEPTH(s) _SBF(8, s) /* Set the level for DMA1 RX Request */
+#define I2S_DMA0_TX_DEPTH(s) _SBF(16, s) /* Set the level for DMA1 TX Request */
+
+/* i2s_dma1 Configuration register definitions */
+#define I2S_DMA1_RX_EN _BIT(0) /* Enable RX DMA1*/
+#define I2S_DMA1_TX_EN _BIT(1) /* Enable TX DMA1*/
+#define I2S_DMA1_RX_DEPTH(s) _SBF(8, s) /* Set the level for DMA1 RX Request */
+#define I2S_DMA1_TX_DEPTH(s) _SBF(16, s) /* Set the level for DMA1 TX Request */
+
+/* i2s_irq register definitions */
+#define I2S_RX_IRQ_EN _BIT(0) /* Enable RX IRQ*/
+#define I2S_TX_IRQ_EN _BIT(1) /* Enable TX IRQ*/
+#define I2S_IRQ_RX_DEPTH(s) _SBF(8, s) /* valid values ar 0 to 7 */
+#define I2S_IRQ_TX_DEPTH(s) _SBF(16, s) /* valid values ar 0 to 7 */
+
+#endif
diff --git a/sound/soc/fsl/lpc3xxx-pcm.c b/sound/soc/fsl/lpc3xxx-pcm.c
new file mode 100644
index 000000000000..2dbc60d06452
--- /dev/null
+++ b/sound/soc/fsl/lpc3xxx-pcm.c
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Author: Kevin Wells <kevin.wells(a)nxp.com>
+ *
+ * Copyright (C) 2008 NXP Semiconductors
+ * Copyright 2023 Timesys Corporation <piotr.wojtaszczyk(a)timesys.com>
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/dma-mapping.h>
+#include <linux/amba/pl08x.h>
+
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/dmaengine_pcm.h>
+#include <sound/soc.h>
+
+#include "lpc3xxx-i2s.h"
+
+#define STUB_FORMATS (SNDRV_PCM_FMTBIT_S8 | \
+ SNDRV_PCM_FMTBIT_U8 | \
+ SNDRV_PCM_FMTBIT_S16_LE | \
+ SNDRV_PCM_FMTBIT_U16_LE | \
+ SNDRV_PCM_FMTBIT_S24_LE | \
+ SNDRV_PCM_FMTBIT_U24_LE | \
+ SNDRV_PCM_FMTBIT_S32_LE | \
+ SNDRV_PCM_FMTBIT_U32_LE | \
+ SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE)
+
+
+static const struct snd_pcm_hardware lpc3xxx_pcm_hardware = {
+ .info = (SNDRV_PCM_INFO_MMAP |
+ SNDRV_PCM_INFO_MMAP_VALID |
+ SNDRV_PCM_INFO_INTERLEAVED |
+ SNDRV_PCM_INFO_BLOCK_TRANSFER |
+ SNDRV_PCM_INFO_PAUSE |
+ SNDRV_PCM_INFO_RESUME),
+ .formats = STUB_FORMATS,
+ .period_bytes_min = 128,
+ .period_bytes_max = 2048,
+ .periods_min = 2,
+ .periods_max = 1024,
+ .buffer_bytes_max = 128 * 1024
+};
+
+static const struct snd_dmaengine_pcm_config lpc3xxx_dmaengine_pcm_config = {
+ .pcm_hardware = &lpc3xxx_pcm_hardware,
+ .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
+ .compat_filter_fn = pl08x_filter_id,
+ .prealloc_buffer_size = 128 * 1024,
+};
+
+const struct snd_soc_component_driver lpc3xxx_soc_platform_driver = {
+ .name = "lpc32xx-pcm",
+};
+
+int lpc3xxx_pcm_register(struct platform_device *pdev)
+{
+ int ret;
+
+ ret = devm_snd_dmaengine_pcm_register(&pdev->dev, &lpc3xxx_dmaengine_pcm_config,
+ SND_DMAENGINE_PCM_FLAG_NO_DT | SND_DMAENGINE_PCM_FLAG_COMPAT);
+ if (ret) {
+ dev_err(&pdev->dev, "failed to register dmaengine: %d\n", ret);
+ return ret;
+ }
+
+ return devm_snd_soc_register_component(&pdev->dev, &lpc3xxx_soc_platform_driver,
+ NULL, 0);
+}
+EXPORT_SYMBOL(lpc3xxx_pcm_register);
--
2.25.1
1
0
[PATCH v1 1/1] treewide: Align match_string() with sysfs_match_string()
by Andy Shevchenko 10 Jun '24
by Andy Shevchenko 10 Jun '24
10 Jun '24
Make two APIs look similar. Hence convert match_string() to be
a 2-argument macro. In order to avoid unneeded churn, convert
all users as well. There is no functional change intended.
Signed-off-by: Andy Shevchenko <andriy.shevchenko(a)linux.intel.com>
---
Compile tested with `make allyesconfig` and `make allmodconfig`
on x86_64, arm, aarch64, powerpc64 (8 builds total).
I guess the best is to apply it to Linus' tree directly.
And now it seems a good timing as there are no new users
of this API either in v6.10-rcX, or in Linux Next.
But if you think differently, tell me.
arch/powerpc/xmon/xmon.c | 5 ++--
arch/x86/kernel/cpu/mtrr/if.c | 4 +--
crypto/asymmetric_keys/pkcs7_verify.c | 4 +--
drivers/acpi/scan.c | 4 +--
drivers/ata/pata_hpt366.c | 2 +-
drivers/ata/pata_hpt37x.c | 2 +-
drivers/base/property.c | 6 ++--
drivers/char/ipmi/ipmi_msghandler.c | 2 +-
drivers/char/ipmi/ipmi_si_hardcode.c | 2 +-
drivers/clk/bcm/clk-bcm2835.c | 4 +--
drivers/clk/rockchip/clk.c | 4 +--
drivers/clk/tegra/clk-tegra124-emc.c | 7 ++---
drivers/cpufreq/amd-pstate.c | 4 +--
drivers/cpufreq/intel_pstate.c | 2 +-
.../intel/qat/qat_common/adf_cfg_services.c | 5 ++--
.../gpu/drm/drm_panel_orientation_quirks.c | 2 +-
drivers/gpu/drm/i915/display/intel_pipe_crc.c | 2 +-
drivers/gpu/drm/nouveau/dispnv04/tvnv17.c | 4 +--
drivers/gpu/drm/nouveau/dispnv50/crc.c | 2 +-
drivers/hwmon/ltc4282.c | 14 ++++-----
drivers/hwmon/nct6775-platform.c | 6 ++--
drivers/hwtracing/intel_th/msu.c | 2 +-
drivers/i2c/busses/i2c-i801.c | 4 +--
drivers/leds/leds-sun50i-a100.c | 2 +-
drivers/mfd/omap-usb-host.c | 2 +-
drivers/mmc/host/sdhci-xenon-phy.c | 13 ++++-----
drivers/mtd/nand/raw/nand_macronix.c | 10 ++-----
.../net/ethernet/chelsio/cxgb4/cudbg_lib.c | 6 ++--
.../net/wireless/intel/iwlwifi/mvm/debugfs.c | 2 +-
drivers/pci/pcie/aer.c | 2 +-
drivers/phy/mediatek/phy-mtk-tphy.c | 8 ++---
drivers/phy/tegra/xusb.c | 4 +--
drivers/pinctrl/mvebu/pinctrl-armada-37xx.c | 6 ++--
drivers/pinctrl/pinmux.c | 6 ++--
drivers/platform/x86/hp/hp-wmi.c | 29 +++++++------------
drivers/platform/x86/msi-ec.c | 4 +--
drivers/power/supply/ab8500_btemp.c | 2 +-
drivers/power/supply/ab8500_chargalg.c | 2 +-
drivers/power/supply/ab8500_charger.c | 2 +-
drivers/power/supply/ab8500_fg.c | 2 +-
drivers/staging/gdm724x/gdm_tty.c | 5 ++--
.../int340x_thermal/processor_thermal_rfim.c | 4 +--
.../processor_thermal_wt_req.c | 2 +-
drivers/usb/common/common.c | 8 ++---
drivers/usb/dwc3/dwc3-rtk.c | 2 +-
drivers/usb/typec/class.c | 14 ++++-----
drivers/usb/typec/tipd/core.c | 3 +-
drivers/video/fbdev/pxafb.c | 4 +--
fs/bcachefs/compress.c | 2 +-
fs/bcachefs/opts.c | 4 +--
fs/bcachefs/util.c | 4 +--
fs/ubifs/auth.c | 8 ++---
include/linux/string.h | 12 +++++++-
kernel/cgroup/rdma.c | 2 +-
kernel/sched/debug.c | 2 +-
kernel/trace/trace.c | 4 +--
kernel/trace/trace_osnoise.c | 4 +--
lib/dynamic_debug.c | 5 ++--
lib/string_helpers.c | 6 ++--
mm/mempolicy.c | 4 +--
mm/vmpressure.c | 4 +--
security/apparmor/lsm.c | 9 +++---
security/integrity/ima/ima_main.c | 2 +-
security/integrity/ima/ima_policy.c | 2 +-
sound/firewire/oxfw/oxfw.c | 2 +-
sound/pci/oxygen/oxygen_mixer.c | 2 +-
sound/soc/codecs/max98088.c | 2 +-
sound/soc/codecs/max98095.c | 2 +-
sound/soc/soc-dapm.c | 5 ++--
69 files changed, 150 insertions(+), 174 deletions(-)
diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index bd4813bad317..f479cc62674a 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -3478,8 +3478,7 @@ skipbl(void)
return c;
}
-#define N_PTREGS 44
-static const char *regnames[N_PTREGS] = {
+static const char *regnames[] = {
"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
"r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
@@ -3514,7 +3513,7 @@ scanhex(unsigned long *vp)
regname[i] = c;
}
regname[i] = 0;
- i = match_string(regnames, N_PTREGS, regname);
+ i = match_string(regnames, regname);
if (i < 0) {
printf("invalid register name '%%%s'\n", regname);
return 0;
diff --git a/arch/x86/kernel/cpu/mtrr/if.c b/arch/x86/kernel/cpu/mtrr/if.c
index a5c506f6da7f..9b749b848123 100644
--- a/arch/x86/kernel/cpu/mtrr/if.c
+++ b/arch/x86/kernel/cpu/mtrr/if.c
@@ -4,8 +4,8 @@
#include <linux/uaccess.h>
#include <linux/proc_fs.h>
#include <linux/ctype.h>
-#include <linux/string.h>
#include <linux/slab.h>
+#include <linux/string_helpers.h>
#include <linux/init.h>
#define LINE_SIZE 80
@@ -139,7 +139,7 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
return -EINVAL;
ptr = skip_spaces(ptr + 5);
- i = match_string(mtrr_strings, MTRR_NUM_TYPES, ptr);
+ i = match_string(mtrr_strings, ptr);
if (i < 0)
return i;
diff --git a/crypto/asymmetric_keys/pkcs7_verify.c b/crypto/asymmetric_keys/pkcs7_verify.c
index f0d4ff3c20a8..1139d9d1c89a 100644
--- a/crypto/asymmetric_keys/pkcs7_verify.c
+++ b/crypto/asymmetric_keys/pkcs7_verify.c
@@ -141,8 +141,8 @@ int pkcs7_get_digest(struct pkcs7_message *pkcs7, const u8 **buf, u32 *len,
*buf = sinfo->sig->digest;
*len = sinfo->sig->digest_size;
- i = match_string(hash_algo_name, HASH_ALGO__LAST,
- sinfo->sig->hash_algo);
+ i = __match_string(hash_algo_name, HASH_ALGO__LAST,
+ sinfo->sig->hash_algo);
if (i >= 0)
*hash_algo = i;
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 503773707e01..9cb350de30f0 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -798,7 +798,7 @@ static bool acpi_info_matches_ids(struct acpi_device_info *info,
if (!(info->valid & ACPI_VALID_HID))
return false;
- index = match_string(ids, -1, info->hardware_id.string);
+ index = __match_string(ids, -1, info->hardware_id.string);
if (index >= 0)
return true;
@@ -809,7 +809,7 @@ static bool acpi_info_matches_ids(struct acpi_device_info *info,
return false;
for (i = 0; i < cid_list->count; i++) {
- index = match_string(ids, -1, cid_list->ids[i].string);
+ index = __match_string(ids, -1, cid_list->ids[i].string);
if (index >= 0)
return true;
}
diff --git a/drivers/ata/pata_hpt366.c b/drivers/ata/pata_hpt366.c
index bdccd1ba1524..8134f9290791 100644
--- a/drivers/ata/pata_hpt366.c
+++ b/drivers/ata/pata_hpt366.c
@@ -178,7 +178,7 @@ static int hpt_dma_blacklisted(const struct ata_device *dev, char *modestr,
ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num));
- i = match_string(list, -1, model_num);
+ i = __match_string(list, -1, model_num);
if (i >= 0) {
ata_dev_warn(dev, "%s is not supported for %s\n", modestr, list[i]);
return 1;
diff --git a/drivers/ata/pata_hpt37x.c b/drivers/ata/pata_hpt37x.c
index c0329cf01135..2d0b659bbd65 100644
--- a/drivers/ata/pata_hpt37x.c
+++ b/drivers/ata/pata_hpt37x.c
@@ -226,7 +226,7 @@ static int hpt_dma_blacklisted(const struct ata_device *dev, char *modestr,
ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num));
- i = match_string(list, -1, model_num);
+ i = __match_string(list, -1, model_num);
if (i >= 0) {
ata_dev_warn(dev, "%s is not supported for %s\n",
modestr, list[i]);
diff --git a/drivers/base/property.c b/drivers/base/property.c
index 837d77e3af2b..075c9dbd7aa5 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -15,7 +15,7 @@
#include <linux/property.h>
#include <linux/phy.h>
#include <linux/slab.h>
-#include <linux/string.h>
+#include <linux/string_helpers.h>
#include <linux/types.h>
struct fwnode_handle *__dev_fwnode(struct device *dev)
@@ -489,7 +489,7 @@ int fwnode_property_match_string(const struct fwnode_handle *fwnode,
if (ret < 0)
goto out_free;
- ret = match_string(values, nval, string);
+ ret = __match_string(values, nval, string);
if (ret < 0)
ret = -ENODATA;
@@ -526,7 +526,7 @@ int fwnode_property_match_property_string(const struct fwnode_handle *fwnode,
if (ret)
return ret;
- ret = match_string(array, n, string);
+ ret = __match_string(array, n, string);
if (ret < 0)
ret = -ENOENT;
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index e12b531f5c2f..c7526eb1e963 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -78,7 +78,7 @@ static int panic_op_write_handler(const char *val,
int e;
strscpy(valcp, val, sizeof(valcp));
- e = match_string(ipmi_panic_event_str, -1, strstrip(valcp));
+ e = __match_string(ipmi_panic_event_str, -1, strstrip(valcp));
if (e < 0)
return e;
diff --git a/drivers/char/ipmi/ipmi_si_hardcode.c b/drivers/char/ipmi/ipmi_si_hardcode.c
index 0c92fa3eee88..4d3275374a53 100644
--- a/drivers/char/ipmi/ipmi_si_hardcode.c
+++ b/drivers/char/ipmi/ipmi_si_hardcode.c
@@ -70,7 +70,7 @@ static void __init ipmi_hardcode_init_one(const char *si_type_str,
if (!si_type_str || !*si_type_str) {
p.type = SI_KCS;
} else {
- t = match_string(si_to_str, -1, si_type_str);
+ t = __match_string(si_to_str, -1, si_type_str);
if (t < 0) {
pr_warn("Interface type specified for interface %d, was invalid: %s\n",
i, si_type_str);
diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c
index fb04734afc80..9446422d5fa8 100644
--- a/drivers/clk/bcm/clk-bcm2835.c
+++ b/drivers/clk/bcm/clk-bcm2835.c
@@ -1447,9 +1447,7 @@ static struct clk_hw *bcm2835_register_clock(struct bcm2835_cprman *cprman,
for (i = 0; i < clock_data->num_mux_parents; i++) {
parents[i] = clock_data->parents[i];
- ret = match_string(cprman_parent_names,
- ARRAY_SIZE(cprman_parent_names),
- parents[i]);
+ ret = match_string(cprman_parent_names, parents[i]);
if (ret >= 0)
parents[i] = cprman->real_parent_names[ret];
}
diff --git a/drivers/clk/rockchip/clk.c b/drivers/clk/rockchip/clk.c
index 73d2cbdc716b..30414d081f46 100644
--- a/drivers/clk/rockchip/clk.c
+++ b/drivers/clk/rockchip/clk.c
@@ -266,8 +266,8 @@ static struct clk *rockchip_clk_register_frac_branch(
struct clk *mux_clk;
int ret;
- frac->mux_frac_idx = match_string(child->parent_names,
- child->num_parents, name);
+ frac->mux_frac_idx = __match_string(child->parent_names,
+ child->num_parents, name);
frac->mux_ops = &clk_mux_ops;
frac->clk_nb.notifier_call = rockchip_clk_frac_notifier_cb;
diff --git a/drivers/clk/tegra/clk-tegra124-emc.c b/drivers/clk/tegra/clk-tegra124-emc.c
index 2a6db0434281..a2709ed60ee7 100644
--- a/drivers/clk/tegra/clk-tegra124-emc.c
+++ b/drivers/clk/tegra/clk-tegra124-emc.c
@@ -20,7 +20,7 @@
#include <linux/of_platform.h>
#include <linux/platform_device.h>
#include <linux/sort.h>
-#include <linux/string.h>
+#include <linux/string_helpers.h>
#include <soc/tegra/fuse.h>
@@ -413,13 +413,12 @@ static int load_one_timing_from_dt(struct tegra_clk_emc *tegra,
}
timing->parent_index = 0xff;
- i = match_string(emc_parent_clk_names, ARRAY_SIZE(emc_parent_clk_names),
- __clk_get_name(timing->parent));
+ i = match_string(emc_parent_clk_names, __clk_get_name(timing->parent));
if (i < 0) {
pr_err("timing %pOF: %s is not a valid parent\n",
node, __clk_get_name(timing->parent));
clk_put(timing->parent);
- return -EINVAL;
+ return i;
}
timing->parent_index = i;
diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 1b7e82a0ad2e..b6f52f44625f 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -1117,9 +1117,9 @@ static ssize_t store_energy_performance_preference(
if (ret != 1)
return -EINVAL;
- ret = match_string(energy_perf_strings, -1, str_preference);
+ ret = __match_string(energy_perf_strings, -1, str_preference);
if (ret < 0)
- return -EINVAL;
+ return ret;
mutex_lock(&amd_pstate_limits_lock);
ret = amd_pstate_set_energy_pref_index(cpudata, ret);
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 4b986c044741..1c2ee10415a2 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -832,7 +832,7 @@ static ssize_t store_energy_performance_preference(
if (ret != 1)
return -EINVAL;
- ret = match_string(energy_perf_strings, -1, str_preference);
+ ret = __match_string(energy_perf_strings, -1, str_preference);
if (ret < 0) {
if (!boot_cpu_has(X86_FEATURE_HWP_EPP))
return ret;
diff --git a/drivers/crypto/intel/qat/qat_common/adf_cfg_services.c b/drivers/crypto/intel/qat/qat_common/adf_cfg_services.c
index 268052294468..4b8c45e8b164 100644
--- a/drivers/crypto/intel/qat/qat_common/adf_cfg_services.c
+++ b/drivers/crypto/intel/qat/qat_common/adf_cfg_services.c
@@ -3,7 +3,7 @@
#include <linux/export.h>
#include <linux/pci.h>
-#include <linux/string.h>
+#include <linux/string_helpers.h>
#include "adf_cfg.h"
#include "adf_cfg_services.h"
#include "adf_cfg_strings.h"
@@ -35,8 +35,7 @@ int adf_get_service_enabled(struct adf_accel_dev *accel_dev)
return ret;
}
- ret = match_string(adf_cfg_services, ARRAY_SIZE(adf_cfg_services),
- services);
+ ret = match_string(adf_cfg_services, services);
if (ret < 0)
dev_err(&GET_DEV(accel_dev),
"Invalid value of " ADF_SERVICES_ENABLED " param: %s\n",
diff --git a/drivers/gpu/drm/drm_panel_orientation_quirks.c b/drivers/gpu/drm/drm_panel_orientation_quirks.c
index aa93129c3397..624743caac4c 100644
--- a/drivers/gpu/drm/drm_panel_orientation_quirks.c
+++ b/drivers/gpu/drm/drm_panel_orientation_quirks.c
@@ -481,7 +481,7 @@ int drm_get_panel_orientation_quirk(int width, int height)
if (!bios_date)
continue;
- i = match_string(data->bios_dates, -1, bios_date);
+ i = __match_string(data->bios_dates, -1, bios_date);
if (i >= 0)
return data->orientation;
}
diff --git a/drivers/gpu/drm/i915/display/intel_pipe_crc.c b/drivers/gpu/drm/i915/display/intel_pipe_crc.c
index 5a468ed6e26c..f9e7c66fd538 100644
--- a/drivers/gpu/drm/i915/display/intel_pipe_crc.c
+++ b/drivers/gpu/drm/i915/display/intel_pipe_crc.c
@@ -426,7 +426,7 @@ display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
return 0;
}
- i = match_string(pipe_crc_sources, ARRAY_SIZE(pipe_crc_sources), buf);
+ i = match_string(pipe_crc_sources, buf);
if (i < 0)
return i;
diff --git a/drivers/gpu/drm/nouveau/dispnv04/tvnv17.c b/drivers/gpu/drm/nouveau/dispnv04/tvnv17.c
index 670c9739e5e1..7fb9f5345654 100644
--- a/drivers/gpu/drm/nouveau/dispnv04/tvnv17.c
+++ b/drivers/gpu/drm/nouveau/dispnv04/tvnv17.c
@@ -645,8 +645,8 @@ static int nv17_tv_create_resources(struct drm_encoder *encoder,
int i;
if (nouveau_tv_norm) {
- i = match_string(nv17_tv_norm_names, num_tv_norms,
- nouveau_tv_norm);
+ i = __match_string(nv17_tv_norm_names, num_tv_norms,
+ nouveau_tv_norm);
if (i < 0)
NV_WARN(drm, "Invalid TV norm setting \"%s\"\n",
nouveau_tv_norm);
diff --git a/drivers/gpu/drm/nouveau/dispnv50/crc.c b/drivers/gpu/drm/nouveau/dispnv50/crc.c
index 5936b6b3b15d..ea35d283b2d2 100644
--- a/drivers/gpu/drm/nouveau/dispnv50/crc.c
+++ b/drivers/gpu/drm/nouveau/dispnv50/crc.c
@@ -38,7 +38,7 @@ static int nv50_crc_parse_source(const char *buf, enum nv50_crc_source *s)
return 0;
}
- i = match_string(nv50_crc_sources, ARRAY_SIZE(nv50_crc_sources), buf);
+ i = match_string(nv50_crc_sources, buf);
if (i < 0)
return i;
diff --git a/drivers/hwmon/ltc4282.c b/drivers/hwmon/ltc4282.c
index 4f608a3790fb..3546f5a7e7bd 100644
--- a/drivers/hwmon/ltc4282.c
+++ b/drivers/hwmon/ltc4282.c
@@ -21,7 +21,7 @@
#include <linux/mutex.h>
#include <linux/regmap.h>
#include <linux/property.h>
-#include <linux/string.h>
+#include <linux/string_helpers.h>
#include <linux/units.h>
#include <linux/util_macros.h>
@@ -1282,8 +1282,7 @@ static int ltc4282_gpio_setup(struct ltc4282_state *st, struct device *dev)
ret = device_property_read_string(dev, "adi,gpio1-mode", &func);
if (!ret) {
- ret = match_string(ltc4282_gpio1_modes,
- ARRAY_SIZE(ltc4282_gpio1_modes), func);
+ ret = match_string(ltc4282_gpio1_modes, func);
if (ret < 0)
return dev_err_probe(dev, ret,
"Invalid func(%s) for gpio1\n",
@@ -1298,8 +1297,7 @@ static int ltc4282_gpio_setup(struct ltc4282_state *st, struct device *dev)
ret = device_property_read_string(dev, "adi,gpio2-mode", &func);
if (!ret) {
- ret = match_string(ltc4282_gpio2_modes,
- ARRAY_SIZE(ltc4282_gpio2_modes), func);
+ ret = match_string(ltc4282_gpio2_modes, func);
if (ret < 0)
return dev_err_probe(dev, ret,
"Invalid func(%s) for gpio2\n",
@@ -1463,8 +1461,7 @@ static int ltc4282_setup(struct ltc4282_state *st, struct device *dev)
ret = device_property_read_string(dev, "adi,overvoltage-dividers",
÷r);
if (!ret) {
- int div = match_string(ltc4282_dividers,
- ARRAY_SIZE(ltc4282_dividers), divider);
+ int div = match_string(ltc4282_dividers, divider);
if (div < 0)
return dev_err_probe(dev, -EINVAL,
"Invalid val(%s) for adi,overvoltage-divider\n",
@@ -1478,8 +1475,7 @@ static int ltc4282_setup(struct ltc4282_state *st, struct device *dev)
ret = device_property_read_string(dev, "adi,undervoltage-dividers",
÷r);
if (!ret) {
- int div = match_string(ltc4282_dividers,
- ARRAY_SIZE(ltc4282_dividers), divider);
+ int div = match_string(ltc4282_dividers, divider);
if (div < 0)
return dev_err_probe(dev, -EINVAL,
"Invalid val(%s) for adi,undervoltage-divider\n",
diff --git a/drivers/hwmon/nct6775-platform.c b/drivers/hwmon/nct6775-platform.c
index 9aa4dcf4a6f3..eb7eef9d2a76 100644
--- a/drivers/hwmon/nct6775-platform.c
+++ b/drivers/hwmon/nct6775-platform.c
@@ -1514,13 +1514,11 @@ static int __init sensors_nct6775_platform_init(void)
if (board_name && board_vendor &&
!strcmp(board_vendor, "ASUSTeK COMPUTER INC.")) {
- err = match_string(asus_wmi_boards, ARRAY_SIZE(asus_wmi_boards),
- board_name);
+ err = match_string(asus_wmi_boards, board_name);
if (err >= 0)
access = nct6775_determine_access(ASUSWMI_DEVICE_UID);
- err = match_string(asus_msi_boards, ARRAY_SIZE(asus_msi_boards),
- board_name);
+ err = match_string(asus_msi_boards, board_name);
if (err >= 0)
access = nct6775_determine_access(ASUSMSI_DEVICE_UID);
}
diff --git a/drivers/hwtracing/intel_th/msu.c b/drivers/hwtracing/intel_th/msu.c
index be63d5b8f193..b083f1360111 100644
--- a/drivers/hwtracing/intel_th/msu.c
+++ b/drivers/hwtracing/intel_th/msu.c
@@ -1901,7 +1901,7 @@ mode_store(struct device *dev, struct device_attribute *attr, const char *buf,
if (!mode)
return -ENOMEM;
- i = match_string(msc_mode, ARRAY_SIZE(msc_mode), mode);
+ i = match_string(msc_mode, mode);
if (i >= 0) {
kfree(mode);
goto found;
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index d2d2a6dbe29f..0eccb636b2fe 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -111,7 +111,7 @@
#include <linux/io.h>
#include <linux/dmi.h>
#include <linux/slab.h>
-#include <linux/string.h>
+#include <linux/string_helpers.h>
#include <linux/completion.h>
#include <linux/err.h>
#include <linux/platform_device.h>
@@ -1186,7 +1186,7 @@ static acpi_status check_acpi_smo88xx_device(acpi_handle obj_handle,
if (!hid)
goto smo88xx_not_found;
- i = match_string(acpi_smo8800_ids, ARRAY_SIZE(acpi_smo8800_ids), hid);
+ i = match_string(acpi_smo8800_ids, hid);
if (i < 0)
goto smo88xx_not_found;
diff --git a/drivers/leds/leds-sun50i-a100.c b/drivers/leds/leds-sun50i-a100.c
index 119eff9471f0..4220f1f8a503 100644
--- a/drivers/leds/leds-sun50i-a100.c
+++ b/drivers/leds/leds-sun50i-a100.c
@@ -256,7 +256,7 @@ static int sun50i_a100_ledc_parse_format(struct device *dev,
device_property_read_string(dev, "allwinner,pixel-format", &format);
- i = match_string(sun50i_a100_ledc_formats, ARRAY_SIZE(sun50i_a100_ledc_formats), format);
+ i = match_string(sun50i_a100_ledc_formats, format);
if (i < 0)
return dev_err_probe(dev, i, "Bad pixel format '%s'\n", format);
diff --git a/drivers/mfd/omap-usb-host.c b/drivers/mfd/omap-usb-host.c
index 949feb03d4f8..06c208d8a992 100644
--- a/drivers/mfd/omap-usb-host.c
+++ b/drivers/mfd/omap-usb-host.c
@@ -498,7 +498,7 @@ static int usbhs_omap_get_dt_pdata(struct device *dev,
continue;
/* get 'enum usbhs_omap_port_mode' from port mode string */
- ret = match_string(port_modes, ARRAY_SIZE(port_modes), mode);
+ ret = match_string(port_modes, mode);
if (ret < 0) {
dev_warn(dev, "Invalid port%d-mode \"%s\" in device tree\n",
i, mode);
diff --git a/drivers/mmc/host/sdhci-xenon-phy.c b/drivers/mmc/host/sdhci-xenon-phy.c
index cc9d28b75eb9..1865e26ae736 100644
--- a/drivers/mmc/host/sdhci-xenon-phy.c
+++ b/drivers/mmc/host/sdhci-xenon-phy.c
@@ -135,15 +135,14 @@ struct xenon_emmc_phy_regs {
u32 logic_timing_val;
};
-static const char * const phy_types[] = {
- "emmc 5.0 phy",
- "emmc 5.1 phy"
-};
-
enum xenon_phy_type_enum {
EMMC_5_0_PHY,
EMMC_5_1_PHY,
- NR_PHY_TYPES
+};
+
+static const char * const phy_types[] = {
+ [EMMC_5_0_PHY] = "emmc 5.0 phy",
+ [EMMC_5_1_PHY] = "emmc 5.1 phy",
};
enum soc_pad_ctrl_type {
@@ -852,7 +851,7 @@ static int xenon_add_phy(struct device *dev, struct sdhci_host *host,
struct xenon_priv *priv = sdhci_pltfm_priv(pltfm_host);
int ret;
- priv->phy_type = match_string(phy_types, NR_PHY_TYPES, phy_name);
+ priv->phy_type = match_string(phy_types, phy_name);
if (priv->phy_type < 0) {
dev_err(mmc_dev(host->mmc),
"Unable to determine PHY name %s. Use default eMMC 5.1 PHY\n",
diff --git a/drivers/mtd/nand/raw/nand_macronix.c b/drivers/mtd/nand/raw/nand_macronix.c
index e229de32ff50..8b3fb2c72bd6 100644
--- a/drivers/mtd/nand/raw/nand_macronix.c
+++ b/drivers/mtd/nand/raw/nand_macronix.c
@@ -178,8 +178,7 @@ static void macronix_nand_fix_broken_get_timings(struct nand_chip *chip)
if (!chip->parameters.supports_set_get_features)
return;
- i = match_string(broken_get_timings, ARRAY_SIZE(broken_get_timings),
- chip->parameters.model);
+ i = match_string(broken_get_timings, chip->parameters.model);
if (i < 0)
return;
@@ -317,8 +316,7 @@ static void macronix_nand_deep_power_down_support(struct nand_chip *chip)
"MX30UF4G28AD",
};
- i = match_string(deep_power_down_dev, ARRAY_SIZE(deep_power_down_dev),
- chip->parameters.model);
+ i = match_string(deep_power_down_dev, chip->parameters.model);
if (i < 0)
return;
@@ -461,9 +459,7 @@ static void macronix_nand_setup_otp(struct nand_chip *chip)
};
struct mtd_info *mtd;
- if (match_string(supported_otp_models,
- ARRAY_SIZE(supported_otp_models),
- chip->parameters.model) < 0)
+ if (match_string(supported_otp_models, chip->parameters.model) < 0)
return;
if (!chip->parameters.supports_set_get_features)
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c b/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c
index 557c591a6ce3..cff23dc56641 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c
@@ -4,7 +4,7 @@
*/
#include <linux/sort.h>
-#include <linux/string.h>
+#include <linux/string_helpers.h>
#include "t4_regs.h"
#include "cxgb4.h"
@@ -1191,9 +1191,9 @@ static int cudbg_get_mem_region(struct adapter *padap,
if (rc)
return rc;
- i = match_string(cudbg_region, ARRAY_SIZE(cudbg_region), region_name);
+ i = match_string(cudbg_region, region_name);
if (i < 0)
- return -EINVAL;
+ return i;
idx = i;
for (i = 0; i < meminfo->mem_c; i++) {
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
index 79f4ac8cbc72..58388ca9ecfa 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
@@ -724,7 +724,7 @@ iwl_dbgfs_bt_force_ant_write(struct iwl_mvm *mvm, char *buf,
};
int ret, bt_force_ant_mode;
- ret = match_string(modes_str, ARRAY_SIZE(modes_str), buf);
+ ret = match_string(modes_str, buf);
if (ret < 0)
return ret;
diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c
index ac6293c24976..2d317c7e1cea 100644
--- a/drivers/pci/pcie/aer.c
+++ b/drivers/pci/pcie/aer.c
@@ -210,7 +210,7 @@ void pcie_ecrc_get_policy(char *str)
{
int i;
- i = match_string(ecrc_policy_str, ARRAY_SIZE(ecrc_policy_str), str);
+ i = match_string(ecrc_policy_str, str);
if (i < 0)
return;
diff --git a/drivers/phy/mediatek/phy-mtk-tphy.c b/drivers/phy/mediatek/phy-mtk-tphy.c
index 25b86bbb9cec..762674acb7fc 100644
--- a/drivers/phy/mediatek/phy-mtk-tphy.c
+++ b/drivers/phy/mediatek/phy-mtk-tphy.c
@@ -389,7 +389,7 @@ static int u2_phy_params_show(struct seq_file *sf, void *unused)
u32 val = 0;
int ret;
- ret = match_string(u2_phy_files, ARRAY_SIZE(u2_phy_files), fname);
+ ret = match_string(u2_phy_files, fname);
if (ret < 0)
return ret;
@@ -464,7 +464,7 @@ static ssize_t u2_phy_params_write(struct file *file, const char __user *ubuf,
if (rc)
return rc;
- ret = match_string(u2_phy_files, ARRAY_SIZE(u2_phy_files), fname);
+ ret = match_string(u2_phy_files, fname);
if (ret < 0)
return (ssize_t)ret;
@@ -530,7 +530,7 @@ static int u3_phy_params_show(struct seq_file *sf, void *unused)
u32 tmp;
int ret;
- ret = match_string(u3_phy_files, ARRAY_SIZE(u3_phy_files), fname);
+ ret = match_string(u3_phy_files, fname);
if (ret < 0)
return ret;
@@ -590,7 +590,7 @@ static ssize_t u3_phy_params_write(struct file *file, const char __user *ubuf,
if (rc)
return rc;
- ret = match_string(u3_phy_files, ARRAY_SIZE(u3_phy_files), fname);
+ ret = match_string(u3_phy_files, fname);
if (ret < 0)
return (ssize_t)ret;
diff --git a/drivers/phy/tegra/xusb.c b/drivers/phy/tegra/xusb.c
index cfdb54b6070a..5fb8656aa31d 100644
--- a/drivers/phy/tegra/xusb.c
+++ b/drivers/phy/tegra/xusb.c
@@ -123,7 +123,7 @@ int tegra_xusb_lane_parse_dt(struct tegra_xusb_lane *lane,
if (err < 0)
return err;
- err = match_string(lane->soc->funcs, lane->soc->num_funcs, function);
+ err = __match_string(lane->soc->funcs, lane->soc->num_funcs, function);
if (err < 0) {
dev_err(dev, "invalid function \"%s\" for lane \"%pOFn\"\n",
function, np);
@@ -748,7 +748,7 @@ static int tegra_xusb_usb2_port_parse_dt(struct tegra_xusb_usb2_port *usb2)
usb2->internal = of_property_read_bool(np, "nvidia,internal");
if (!of_property_read_string(np, "mode", &mode)) {
- int err = match_string(modes, ARRAY_SIZE(modes), mode);
+ int err = match_string(modes, mode);
if (err < 0) {
dev_err(&port->dev, "invalid value %s for \"mode\"\n",
mode);
diff --git a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
index 4c4ada06423d..55b5464595b5 100644
--- a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
+++ b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
@@ -352,7 +352,7 @@ static int armada_37xx_pmx_set_by_name(struct pinctrl_dev *pctldev,
dev_dbg(dev, "enable function %s group %s\n", name, grp->name);
- func = match_string(grp->funcs, NB_FUNCS, name);
+ func = match_string(grp->funcs, name);
if (func < 0)
return -ENOTSUPP;
@@ -885,7 +885,7 @@ static int armada_37xx_fill_group(struct armada_37xx_pinctrl *info)
for (j = 0; j < grp->extra_npins; j++)
grp->pins[i+j] = grp->extra_pin + j;
- for (f = 0; (f < NB_FUNCS) && grp->funcs[f]; f++) {
+ for (f = 0; (f < ARRAY_SIZE(grp->funcs)) && grp->funcs[f]; f++) {
int ret;
/* check for unique functions and count groups */
ret = armada_37xx_add_function(info->funcs, &funcsize,
@@ -937,7 +937,7 @@ static int armada_37xx_fill_func(struct armada_37xx_pinctrl *info)
struct armada_37xx_pin_group *gp = &info->groups[g];
int f;
- f = match_string(gp->funcs, NB_FUNCS, name);
+ f = match_string(gp->funcs, name);
if (f < 0)
continue;
diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c
index addba55334d9..af2334b16b94 100644
--- a/drivers/pinctrl/pinmux.c
+++ b/drivers/pinctrl/pinmux.c
@@ -23,7 +23,7 @@
#include <linux/radix-tree.h>
#include <linux/seq_file.h>
#include <linux/slab.h>
-#include <linux/string.h>
+#include <linux/string_helpers.h>
#include <linux/pinctrl/machine.h>
#include <linux/pinctrl/pinctrl.h>
@@ -376,7 +376,7 @@ int pinmux_map_to_setting(const struct pinctrl_map *map,
}
if (map->data.mux.group) {
group = map->data.mux.group;
- ret = match_string(groups, num_groups, group);
+ ret = __match_string(groups, num_groups, group);
if (ret < 0) {
dev_err(pctldev->dev,
"invalid group \"%s\" for function \"%s\"\n",
@@ -730,7 +730,7 @@ static ssize_t pinmux_select_write(struct file *file, const char __user *user_bu
goto exit_free_buf;
}
- ret = match_string(groups, num_groups, gname);
+ ret = __match_string(groups, num_groups, gname);
if (ret < 0) {
dev_err(pctldev->dev, "invalid group %s", gname);
goto exit_free_buf;
diff --git a/drivers/platform/x86/hp/hp-wmi.c b/drivers/platform/x86/hp/hp-wmi.c
index 5fa553023842..ad7a9063c5d2 100644
--- a/drivers/platform/x86/hp/hp-wmi.c
+++ b/drivers/platform/x86/hp/hp-wmi.c
@@ -25,7 +25,7 @@
#include <linux/hwmon.h>
#include <linux/acpi.h>
#include <linux/rfkill.h>
-#include <linux/string.h>
+#include <linux/string_helpers.h>
#include <linux/dmi.h>
MODULE_AUTHOR("Matthew Garrett <mjg59(a)srcf.ucam.org>");
@@ -443,18 +443,15 @@ static int hp_wmi_get_tablet_mode(void)
{
char system_device_mode[4] = { 0 };
const char *chassis_type;
- bool tablet_found;
int ret;
chassis_type = dmi_get_system_info(DMI_CHASSIS_TYPE);
if (!chassis_type)
return -ENODEV;
- tablet_found = match_string(tablet_chassis_types,
- ARRAY_SIZE(tablet_chassis_types),
- chassis_type) >= 0;
- if (!tablet_found)
- return -ENODEV;
+ ret = match_string(tablet_chassis_types, chassis_type);
+ if (ret < 0)
+ return ret;
ret = hp_wmi_perform_query(HPWMI_SYSTEM_DEVICE_MODE, HPWMI_READ,
system_device_mode, zero_if_sup(system_device_mode),
@@ -490,9 +487,7 @@ static bool is_omen_thermal_profile(void)
if (!board_name)
return false;
- return match_string(omen_thermal_profile_boards,
- ARRAY_SIZE(omen_thermal_profile_boards),
- board_name) >= 0;
+ return match_string(omen_thermal_profile_boards, board_name) >= 0;
}
static int omen_get_thermal_policy_version(void)
@@ -503,9 +498,9 @@ static int omen_get_thermal_policy_version(void)
const char *board_name = dmi_get_system_info(DMI_BOARD_NAME);
if (board_name) {
- int matches = match_string(omen_thermal_profile_force_v0_boards,
- ARRAY_SIZE(omen_thermal_profile_force_v0_boards),
- board_name);
+ int matches;
+
+ matches = match_string(omen_thermal_profile_force_v0_boards, board_name);
if (matches >= 0)
return 0;
}
@@ -1230,9 +1225,7 @@ static bool has_omen_thermal_profile_ec_timer(void)
if (!board_name)
return false;
- return match_string(omen_timed_thermal_profile_boards,
- ARRAY_SIZE(omen_timed_thermal_profile_boards),
- board_name) >= 0;
+ return match_string(omen_timed_thermal_profile_boards, board_name) >= 0;
}
inline int omen_thermal_profile_ec_flags_set(enum hp_thermal_profile_omen_flags flags)
@@ -1376,9 +1369,7 @@ static bool is_victus_thermal_profile(void)
if (!board_name)
return false;
- return match_string(victus_thermal_profile_boards,
- ARRAY_SIZE(victus_thermal_profile_boards),
- board_name) >= 0;
+ return match_string(victus_thermal_profile_boards, board_name) >= 0;
}
static int platform_profile_victus_get(struct platform_profile_handler *pprof,
diff --git a/drivers/platform/x86/msi-ec.c b/drivers/platform/x86/msi-ec.c
index f19504dbf164..a1b2dbb1a10f 100644
--- a/drivers/platform/x86/msi-ec.c
+++ b/drivers/platform/x86/msi-ec.c
@@ -25,7 +25,7 @@
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/seq_file.h>
-#include <linux/string.h>
+#include <linux/string_helpers.h>
#define SM_ECO_NAME "eco"
#define SM_COMFORT_NAME "comfort"
@@ -1316,7 +1316,7 @@ static int __init load_configuration(void)
/* load the suitable configuration, if exists */
for (int i = 0; CONFIGS[i]; i++) {
- if (match_string(CONFIGS[i]->allowed_fw, -1, fw_version) != -EINVAL) {
+ if (__match_string(CONFIGS[i]->allowed_fw, -1, fw_version) >= 0) {
conf = *CONFIGS[i];
conf.allowed_fw = NULL;
return 0;
diff --git a/drivers/power/supply/ab8500_btemp.c b/drivers/power/supply/ab8500_btemp.c
index 56f136b2d071..824c71965150 100644
--- a/drivers/power/supply/ab8500_btemp.c
+++ b/drivers/power/supply/ab8500_btemp.c
@@ -556,7 +556,7 @@ static int ab8500_btemp_get_ext_psy_data(struct device *dev, void *data)
* For all psy where the name of your driver
* appears in any supplied_to
*/
- j = match_string(supplicants, ext->num_supplicants, psy->desc->name);
+ j = __match_string(supplicants, ext->num_supplicants, psy->desc->name);
if (j < 0)
return 0;
diff --git a/drivers/power/supply/ab8500_chargalg.c b/drivers/power/supply/ab8500_chargalg.c
index 55ab7a28056e..230a4efee210 100644
--- a/drivers/power/supply/ab8500_chargalg.c
+++ b/drivers/power/supply/ab8500_chargalg.c
@@ -857,7 +857,7 @@ static int ab8500_chargalg_get_ext_psy_data(struct device *dev, void *data)
psy = (struct power_supply *)data;
di = power_supply_get_drvdata(psy);
/* For all psy where the driver name appears in any supplied_to */
- j = match_string(supplicants, ext->num_supplicants, psy->desc->name);
+ j = __match_string(supplicants, ext->num_supplicants, psy->desc->name);
if (j < 0)
return 0;
diff --git a/drivers/power/supply/ab8500_charger.c b/drivers/power/supply/ab8500_charger.c
index 9b34d1a60f66..5eae14ca92fe 100644
--- a/drivers/power/supply/ab8500_charger.c
+++ b/drivers/power/supply/ab8500_charger.c
@@ -1902,7 +1902,7 @@ static int ab8500_charger_get_ext_psy_data(struct device *dev, void *data)
* in practice what we will find will always be "ab8500_fg" as
* the fuel gauge is responsible of keeping track of VBAT.
*/
- j = match_string(supplicants, ext->num_supplicants, psy->desc->name);
+ j = __match_string(supplicants, ext->num_supplicants, psy->desc->name);
if (j < 0)
return 0;
diff --git a/drivers/power/supply/ab8500_fg.c b/drivers/power/supply/ab8500_fg.c
index 2ccaf6116c09..c3bc2833fc7e 100644
--- a/drivers/power/supply/ab8500_fg.c
+++ b/drivers/power/supply/ab8500_fg.c
@@ -2197,7 +2197,7 @@ static int ab8500_fg_get_ext_psy_data(struct device *dev, void *data)
* For all psy where the name of your driver
* appears in any supplied_to
*/
- j = match_string(supplicants, ext->num_supplicants, psy->desc->name);
+ j = __match_string(supplicants, ext->num_supplicants, psy->desc->name);
if (j < 0)
return 0;
diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
index 15c246d3b1a3..e87987a93860 100644
--- a/drivers/staging/gdm724x/gdm_tty.c
+++ b/drivers/staging/gdm724x/gdm_tty.c
@@ -53,10 +53,9 @@ static int gdm_tty_install(struct tty_driver *driver, struct tty_struct *tty)
struct gdm *gdm = NULL;
int ret;
- ret = match_string(DRIVER_STRING, TTY_MAX_COUNT,
- tty->driver->driver_name);
+ ret = match_string(DRIVER_STRING, tty->driver->driver_name);
if (ret < 0)
- return -ENODEV;
+ return ret;
mutex_lock(&gdm_table_lock);
gdm = gdm_table[ret][tty->index];
diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_rfim.c b/drivers/thermal/intel/int340x_thermal/processor_thermal_rfim.c
index e56db75a94fb..dbd176b0fb1f 100644
--- a/drivers/thermal/intel/int340x_thermal/processor_thermal_rfim.c
+++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_rfim.c
@@ -111,7 +111,7 @@ static ssize_t suffix##_show(struct device *dev,\
match_strs = (const char **)fivr_strings;\
mmio_regs = tgl_fivr_mmio_regs;\
} \
- ret = match_string(match_strs, -1, attr->attr.name);\
+ ret = __match_string(match_strs, -1, attr->attr.name);\
if (ret < 0)\
return ret;\
reg_val = readl((void __iomem *) (proc_priv->mmio_base + mmio_regs[ret].offset));\
@@ -145,7 +145,7 @@ static ssize_t suffix##_store(struct device *dev,\
mmio_regs = tgl_fivr_mmio_regs;\
} \
\
- ret = match_string(match_strs, -1, attr->attr.name);\
+ ret = __match_string(match_strs, -1, attr->attr.name);\
if (ret < 0)\
return ret;\
if (mmio_regs[ret].read_only)\
diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_wt_req.c b/drivers/thermal/intel/int340x_thermal/processor_thermal_wt_req.c
index f298e7442662..57f456befb34 100644
--- a/drivers/thermal/intel/int340x_thermal/processor_thermal_wt_req.c
+++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_wt_req.c
@@ -50,7 +50,7 @@ static ssize_t workload_type_store(struct device *dev,
if (ret != 1)
return -EINVAL;
- ret = match_string(workload_types, -1, str_preference);
+ ret = __match_string(workload_types, -1, str_preference);
if (ret < 0)
return ret;
diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
index b84efae26e15..657be0162dd9 100644
--- a/drivers/usb/common/common.c
+++ b/drivers/usb/common/common.c
@@ -114,11 +114,11 @@ enum usb_device_speed usb_get_maximum_speed(struct device *dev)
if (ret < 0)
return USB_SPEED_UNKNOWN;
- ret = match_string(ssp_rate, ARRAY_SIZE(ssp_rate), maximum_speed);
+ ret = match_string(ssp_rate, maximum_speed);
if (ret > 0)
return USB_SPEED_SUPER_PLUS;
- ret = match_string(speed_names, ARRAY_SIZE(speed_names), maximum_speed);
+ ret = match_string(speed_names, maximum_speed);
return (ret < 0) ? USB_SPEED_UNKNOWN : ret;
}
EXPORT_SYMBOL_GPL(usb_get_maximum_speed);
@@ -141,7 +141,7 @@ enum usb_ssp_rate usb_get_maximum_ssp_rate(struct device *dev)
if (ret < 0)
return USB_SSP_GEN_UNKNOWN;
- ret = match_string(ssp_rate, ARRAY_SIZE(ssp_rate), maximum_speed);
+ ret = match_string(ssp_rate, maximum_speed);
return (ret < 0) ? USB_SSP_GEN_UNKNOWN : ret;
}
EXPORT_SYMBOL_GPL(usb_get_maximum_ssp_rate);
@@ -184,7 +184,7 @@ static enum usb_dr_mode usb_get_dr_mode_from_string(const char *str)
{
int ret;
- ret = match_string(usb_dr_modes, ARRAY_SIZE(usb_dr_modes), str);
+ ret = match_string(usb_dr_modes, str);
return (ret < 0) ? USB_DR_MODE_UNKNOWN : ret;
}
diff --git a/drivers/usb/dwc3/dwc3-rtk.c b/drivers/usb/dwc3/dwc3-rtk.c
index 3cd6b184551c..90cee91f4ff9 100644
--- a/drivers/usb/dwc3/dwc3-rtk.c
+++ b/drivers/usb/dwc3/dwc3-rtk.c
@@ -185,7 +185,7 @@ static enum usb_device_speed __get_dwc3_maximum_speed(struct device_node *np)
if (ret < 0)
goto out;
- ret = match_string(speed_names, ARRAY_SIZE(speed_names), maximum_speed);
+ ret = match_string(speed_names, maximum_speed);
out:
of_node_put(dwc3_np);
diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index 9610e647a8d4..7bc4695f8d0b 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -1986,8 +1986,7 @@ EXPORT_SYMBOL_GPL(typec_set_pwr_opmode);
*/
int typec_find_pwr_opmode(const char *name)
{
- return match_string(typec_pwr_opmodes,
- ARRAY_SIZE(typec_pwr_opmodes), name);
+ return match_string(typec_pwr_opmodes, name);
}
EXPORT_SYMBOL_GPL(typec_find_pwr_opmode);
@@ -2001,8 +2000,7 @@ EXPORT_SYMBOL_GPL(typec_find_pwr_opmode);
*/
int typec_find_orientation(const char *name)
{
- return match_string(typec_orientations, ARRAY_SIZE(typec_orientations),
- name);
+ return match_string(typec_orientations, name);
}
EXPORT_SYMBOL_GPL(typec_find_orientation);
@@ -2016,8 +2014,7 @@ EXPORT_SYMBOL_GPL(typec_find_orientation);
*/
int typec_find_port_power_role(const char *name)
{
- return match_string(typec_port_power_roles,
- ARRAY_SIZE(typec_port_power_roles), name);
+ return match_string(typec_port_power_roles, name);
}
EXPORT_SYMBOL_GPL(typec_find_port_power_role);
@@ -2031,7 +2028,7 @@ EXPORT_SYMBOL_GPL(typec_find_port_power_role);
*/
int typec_find_power_role(const char *name)
{
- return match_string(typec_roles, ARRAY_SIZE(typec_roles), name);
+ return match_string(typec_roles, name);
}
EXPORT_SYMBOL_GPL(typec_find_power_role);
@@ -2045,8 +2042,7 @@ EXPORT_SYMBOL_GPL(typec_find_power_role);
*/
int typec_find_port_data_role(const char *name)
{
- return match_string(typec_port_data_roles,
- ARRAY_SIZE(typec_port_data_roles), name);
+ return match_string(typec_port_data_roles, name);
}
EXPORT_SYMBOL_GPL(typec_find_port_data_role);
diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
index ad76dbd20e65..2ce2d355a039 100644
--- a/drivers/usb/typec/tipd/core.c
+++ b/drivers/usb/typec/tipd/core.c
@@ -722,8 +722,7 @@ static int tps6598x_check_mode(struct tps6598x *tps)
if (ret)
return ret;
- ret = match_string(modes, ARRAY_SIZE(modes), mode);
-
+ ret = match_string(modes, mode);
switch (ret) {
case TPS_MODE_APP:
case TPS_MODE_PTCH:
diff --git a/drivers/video/fbdev/pxafb.c b/drivers/video/fbdev/pxafb.c
index 2ef56fa28aff..f1b562b94744 100644
--- a/drivers/video/fbdev/pxafb.c
+++ b/drivers/video/fbdev/pxafb.c
@@ -37,9 +37,9 @@
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/errno.h>
-#include <linux/string.h>
#include <linux/interrupt.h>
#include <linux/slab.h>
+#include <linux/string_helpers.h>
#include <linux/mm.h>
#include <linux/fb.h>
#include <linux/delay.h>
@@ -2107,7 +2107,7 @@ static int of_get_pxafb_display(struct device *dev, struct device_node *disp,
if (ret)
s = "color-tft";
- i = match_string(lcd_types, -1, s);
+ i = __match_string(lcd_types, -1, s);
if (i < 0) {
dev_err(dev, "lcd-type %s is unknown\n", s);
return i;
diff --git a/fs/bcachefs/compress.c b/fs/bcachefs/compress.c
index 1410365a8891..a62c5dd5b470 100644
--- a/fs/bcachefs/compress.c
+++ b/fs/bcachefs/compress.c
@@ -667,7 +667,7 @@ int bch2_opt_compression_parse(struct bch_fs *c, const char *_val, u64 *res,
type_str = strsep(&p, ":");
level_str = p;
- ret = match_string(bch2_compression_opts, -1, type_str);
+ ret = __match_string(bch2_compression_opts, -1, type_str);
if (ret < 0 && err)
prt_str(err, "invalid compression type");
if (ret < 0)
diff --git a/fs/bcachefs/opts.c b/fs/bcachefs/opts.c
index bb068fd72465..cbe4e820419f 100644
--- a/fs/bcachefs/opts.c
+++ b/fs/bcachefs/opts.c
@@ -122,7 +122,7 @@ static int bch2_opt_fix_errors_parse(struct bch_fs *c, const char *val, u64 *res
if (!val) {
*res = FSCK_FIX_yes;
} else {
- int ret = match_string(bch2_fsck_fix_opts, -1, val);
+ int ret = __match_string(bch2_fsck_fix_opts, -1, val);
if (ret < 0 && err)
prt_str(err, "fix_errors: invalid selection");
@@ -366,7 +366,7 @@ int bch2_opt_parse(struct bch_fs *c,
return -EINVAL;
}
- ret = match_string(opt->choices, -1, val);
+ ret = __match_string(opt->choices, -1, val);
if (ret < 0) {
if (err)
prt_printf(err, "%s: invalid selection",
diff --git a/fs/bcachefs/util.c b/fs/bcachefs/util.c
index de331dec2a99..8cef641a38fb 100644
--- a/fs/bcachefs/util.c
+++ b/fs/bcachefs/util.c
@@ -19,7 +19,7 @@
#include <linux/preempt.h>
#include <linux/random.h>
#include <linux/seq_file.h>
-#include <linux/string.h>
+#include <linux/string_helpers.h>
#include <linux/types.h>
#include <linux/sched/clock.h>
@@ -215,7 +215,7 @@ u64 bch2_read_flag_list(char *opt, const char * const list[])
s = strim(d);
while ((p = strsep(&s, ","))) {
- int flag = match_string(list, -1, p);
+ int flag = __match_string(list, -1, p);
if (flag < 0) {
ret = -1;
diff --git a/fs/ubifs/auth.c b/fs/ubifs/auth.c
index a4a0158f712d..fc0da18bfa65 100644
--- a/fs/ubifs/auth.c
+++ b/fs/ubifs/auth.c
@@ -264,13 +264,13 @@ int ubifs_init_authentication(struct ubifs_info *c)
return -EINVAL;
}
- c->auth_hash_algo = match_string(hash_algo_name, HASH_ALGO__LAST,
- c->auth_hash_name);
- if ((int)c->auth_hash_algo < 0) {
+ err = __match_string(hash_algo_name, HASH_ALGO__LAST, c->auth_hash_name);
+ if (err < 0) {
ubifs_err(c, "Unknown hash algo %s specified",
c->auth_hash_name);
- return -EINVAL;
+ return err;
}
+ c->auth_hash_algo = err;
snprintf(hmac_name, CRYPTO_MAX_ALG_NAME, "hmac(%s)",
c->auth_hash_name);
diff --git a/include/linux/string.h b/include/linux/string.h
index 60168aa2af07..92fc7631f6a4 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -303,8 +303,18 @@ extern unsigned long long memparse(const char *ptr, char **retptr);
extern bool parse_option_str(const char *str, const char *option);
extern char *next_arg(char *args, char **param, char **val);
+int __match_string(const char * const *array, size_t n, const char *string);
+
+/**
+ * match_string - matches given string in an array
+ * @_a: array of strings
+ * @_s: string to match with
+ *
+ * Helper for __match_string(). Calculates the size of @a automatically.
+ */
+#define match_string(_a, _s) __match_string(_a, ARRAY_SIZE(_a), _s)
+
extern bool sysfs_streq(const char *s1, const char *s2);
-int match_string(const char * const *array, size_t n, const char *string);
int __sysfs_match_string(const char * const *array, size_t n, const char *s);
/**
diff --git a/kernel/cgroup/rdma.c b/kernel/cgroup/rdma.c
index ef5878fb2005..10105cfc5981 100644
--- a/kernel/cgroup/rdma.c
+++ b/kernel/cgroup/rdma.c
@@ -366,7 +366,7 @@ static int parse_resource(char *c, int *intval)
if (!name || !value)
return -EINVAL;
- i = match_string(rdmacg_resource_names, RDMACG_RESOURCE_MAX, name);
+ i = match_string(rdmacg_resource_names, name);
if (i < 0)
return i;
diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index c1eb9a1afd13..b6238341e3c0 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -105,7 +105,7 @@ static int sched_feat_set(char *cmp)
cmp += 3;
}
- i = match_string(sched_feat_names, __SCHED_FEAT_NR, cmp);
+ i = __match_string(sched_feat_names, __SCHED_FEAT_NR, cmp);
if (i < 0)
return i;
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 578a49ff5c32..13c0a1fa30cd 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -32,7 +32,6 @@
#include <linux/percpu.h>
#include <linux/splice.h>
#include <linux/kdebug.h>
-#include <linux/string.h>
#include <linux/mount.h>
#include <linux/rwsem.h>
#include <linux/slab.h>
@@ -45,6 +44,7 @@
#include <linux/trace.h>
#include <linux/sched/clock.h>
#include <linux/sched/rt.h>
+#include <linux/string_helpers.h>
#include <linux/fsnotify.h>
#include <linux/irq_work.h>
#include <linux/workqueue.h>
@@ -5309,7 +5309,7 @@ int trace_set_options(struct trace_array *tr, char *option)
mutex_lock(&event_mutex);
mutex_lock(&trace_types_lock);
- ret = match_string(trace_options, -1, cmp);
+ ret = __match_string(trace_options, -1, cmp);
/* If no option could be set, test the specific tracer options */
if (ret < 0)
ret = set_tracer_option(tr, cmp, neg);
diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c
index a8e28f9b9271..7bed499effd3 100644
--- a/kernel/trace/trace_osnoise.c
+++ b/kernel/trace/trace_osnoise.c
@@ -2230,9 +2230,9 @@ static ssize_t osnoise_options_write(struct file *filp, const char __user *ubuf,
enable = false;
}
- option = match_string(osnoise_options_str, OSN_MAX, option_str);
+ option = match_string(osnoise_options_str, option_str);
if (option < 0)
- return -EINVAL;
+ return option;
/*
* trace_types_lock is taken to avoid concurrency on start/stop.
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index f2c5e7910bb1..cd4fbcea38ba 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -24,7 +24,6 @@
#include <linux/list.h>
#include <linux/sysctl.h>
#include <linux/ctype.h>
-#include <linux/string.h>
#include <linux/parser.h>
#include <linux/string_helpers.h>
#include <linux/uaccess.h>
@@ -154,7 +153,7 @@ static struct ddebug_class_map *ddebug_find_valid_class(struct ddebug_table cons
int idx;
list_for_each_entry(map, &dt->maps, link) {
- idx = match_string(map->class_names, map->length, class_string);
+ idx = __match_string(map->class_names, map->length, class_string);
if (idx >= 0) {
*class_id = idx + map->base;
return map;
@@ -665,7 +664,7 @@ static int param_set_dyndbg_classnames(const char *instr, const struct kernel_pa
if (*cl_str == '+')
cl_str++;
}
- cls_id = match_string(map->class_names, map->length, cl_str);
+ cls_id = __match_string(map->class_names, map->length, cl_str);
if (cls_id < 0) {
pr_err("%s unknown to %s\n", cl_str, KP_NAME(kp));
continue;
diff --git a/lib/string_helpers.c b/lib/string_helpers.c
index 69ba49b853c7..d3d0d2154146 100644
--- a/lib/string_helpers.c
+++ b/lib/string_helpers.c
@@ -898,7 +898,7 @@ bool sysfs_streq(const char *s1, const char *s2)
EXPORT_SYMBOL(sysfs_streq);
/**
- * match_string - matches given string in an array
+ * __match_string - matches given string in an array
* @array: array of strings
* @n: number of strings in the array or -1 for NULL terminated arrays
* @string: string to match with
@@ -914,7 +914,7 @@ EXPORT_SYMBOL(sysfs_streq);
* Return:
* index of a @string in the @array if matches, or %-EINVAL otherwise.
*/
-int match_string(const char * const *array, size_t n, const char *string)
+int __match_string(const char * const *array, size_t n, const char *string)
{
int index;
const char *item;
@@ -929,7 +929,7 @@ int match_string(const char * const *array, size_t n, const char *string)
return -EINVAL;
}
-EXPORT_SYMBOL(match_string);
+EXPORT_SYMBOL(__match_string);
/**
* __sysfs_match_string - matches given string in an array
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index aec756ae5637..89c132170431 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -89,7 +89,6 @@
#include <linux/nodemask.h>
#include <linux/cpuset.h>
#include <linux/slab.h>
-#include <linux/string.h>
#include <linux/export.h>
#include <linux/nsproxy.h>
#include <linux/interrupt.h>
@@ -103,6 +102,7 @@
#include <linux/ksm.h>
#include <linux/rmap.h>
#include <linux/security.h>
+#include <linux/string_helpers.h>
#include <linux/syscalls.h>
#include <linux/ctype.h>
#include <linux/mm_inline.h>
@@ -3183,7 +3183,7 @@ int mpol_parse_str(char *str, struct mempolicy **mpol)
} else
nodes_clear(nodes);
- mode = match_string(policy_modes, MPOL_MAX, str);
+ mode = match_string(policy_modes, str);
if (mode < 0)
goto out;
diff --git a/mm/vmpressure.c b/mm/vmpressure.c
index bd5183dfd879..eaaa133ce12b 100644
--- a/mm/vmpressure.c
+++ b/mm/vmpressure.c
@@ -388,7 +388,7 @@ int vmpressure_register_event(struct mem_cgroup *memcg,
/* Find required level */
token = strsep(&spec, ",");
- ret = match_string(vmpressure_str_levels, VMPRESSURE_NUM_LEVELS, token);
+ ret = match_string(vmpressure_str_levels, token);
if (ret < 0)
goto out;
level = ret;
@@ -396,7 +396,7 @@ int vmpressure_register_event(struct mem_cgroup *memcg,
/* Find optional mode */
token = strsep(&spec, ",");
if (token) {
- ret = match_string(vmpressure_str_modes, VMPRESSURE_NUM_MODES, token);
+ ret = match_string(vmpressure_str_modes, token);
if (ret < 0)
goto out;
mode = ret;
diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
index 6239777090c4..e3fc94b4c7e5 100644
--- a/security/apparmor/lsm.c
+++ b/security/apparmor/lsm.c
@@ -1820,9 +1820,9 @@ static int param_set_audit(const char *val, const struct kernel_param *kp)
if (apparmor_initialized && !aa_current_policy_admin_capable(NULL))
return -EPERM;
- i = match_string(audit_mode_names, AUDIT_MAX_INDEX, val);
+ i = __match_string(audit_mode_names, AUDIT_MAX_INDEX, val);
if (i < 0)
- return -EINVAL;
+ return i;
aa_g_audit = i;
return 0;
@@ -1849,10 +1849,9 @@ static int param_set_mode(const char *val, const struct kernel_param *kp)
if (apparmor_initialized && !aa_current_policy_admin_capable(NULL))
return -EPERM;
- i = match_string(aa_profile_mode_names, APPARMOR_MODE_NAMES_MAX_INDEX,
- val);
+ i = __match_string(aa_profile_mode_names, APPARMOR_MODE_NAMES_MAX_INDEX, val);
if (i < 0)
- return -EINVAL;
+ return i;
aa_g_profile_mode = i;
return 0;
diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c
index f04f43af651c..49d6e9cc3387 100644
--- a/security/integrity/ima/ima_main.c
+++ b/security/integrity/ima/ima_main.c
@@ -64,7 +64,7 @@ static int __init hash_setup(char *str)
goto out;
}
- i = match_string(hash_algo_name, HASH_ALGO__LAST, str);
+ i = __match_string(hash_algo_name, HASH_ALGO__LAST, str);
if (i < 0) {
pr_err("invalid hash algorithm \"%s\"", str);
return 1;
diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c
index c0556907c2e6..fa67c5794071 100644
--- a/security/integrity/ima/ima_policy.c
+++ b/security/integrity/ima/ima_policy.c
@@ -1380,7 +1380,7 @@ static unsigned int ima_parse_appraise_algos(char *arg)
char *token;
while ((token = strsep(&arg, ",")) != NULL) {
- idx = match_string(hash_algo_name, HASH_ALGO__LAST, token);
+ idx = __match_string(hash_algo_name, HASH_ALGO__LAST, token);
if (idx < 0) {
pr_err("unknown hash algorithm \"%s\"",
diff --git a/sound/firewire/oxfw/oxfw.c b/sound/firewire/oxfw/oxfw.c
index 98ae0e8cba87..5b38069daa0a 100644
--- a/sound/firewire/oxfw/oxfw.c
+++ b/sound/firewire/oxfw/oxfw.c
@@ -59,7 +59,7 @@ static bool detect_loud_models(struct fw_unit *unit)
if (err < 0)
return false;
- return match_string(models, ARRAY_SIZE(models), model) >= 0;
+ return match_string(models, model) >= 0;
}
static int name_card(struct snd_oxfw *oxfw, const struct ieee1394_device_id *entry)
diff --git a/sound/pci/oxygen/oxygen_mixer.c b/sound/pci/oxygen/oxygen_mixer.c
index eb3aca16359c..73e15d5d6be9 100644
--- a/sound/pci/oxygen/oxygen_mixer.c
+++ b/sound/pci/oxygen/oxygen_mixer.c
@@ -1074,7 +1074,7 @@ static int add_controls(struct oxygen *chip,
err = snd_ctl_add(chip->card, ctl);
if (err < 0)
return err;
- j = match_string(known_ctl_names, CONTROL_COUNT, ctl->id.name);
+ j = match_string(known_ctl_names, ctl->id.name);
if (j >= 0) {
chip->controls[j] = ctl;
ctl->private_free = oxygen_any_ctl_free;
diff --git a/sound/soc/codecs/max98088.c b/sound/soc/codecs/max98088.c
index 8b56ee550c09..4736a4ba0e1f 100644
--- a/sound/soc/codecs/max98088.c
+++ b/sound/soc/codecs/max98088.c
@@ -1414,7 +1414,7 @@ static int max98088_get_channel(struct snd_soc_component *component, const char
{
int ret;
- ret = match_string(eq_mode_name, ARRAY_SIZE(eq_mode_name), name);
+ ret = match_string(eq_mode_name, name);
if (ret < 0)
dev_err(component->dev, "Bad EQ channel name '%s'\n", name);
return ret;
diff --git a/sound/soc/codecs/max98095.c b/sound/soc/codecs/max98095.c
index 7e525d49328d..430bce3333a9 100644
--- a/sound/soc/codecs/max98095.c
+++ b/sound/soc/codecs/max98095.c
@@ -1627,7 +1627,7 @@ static int max98095_get_bq_channel(struct snd_soc_component *component,
{
int ret;
- ret = match_string(bq_mode_name, ARRAY_SIZE(bq_mode_name), name);
+ ret = match_string(bq_mode_name, name);
if (ret < 0)
dev_err(component->dev, "Bad biquad channel name '%s'\n", name);
return ret;
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 16dad4a45443..7064f4cae549 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -769,14 +769,13 @@ static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
item = 0;
}
- i = match_string(e->texts, e->items, control_name);
+ i = __match_string(e->texts, e->items, control_name);
if (i < 0)
- return -ENODEV;
+ return i;
path->name = e->texts[i];
path->connect = (i == item);
return 0;
-
}
/* set up initial codec paths */
--
2.43.0.rc1.1336.g36b5255a03ac
18
17
Onboard Speaker does not work and Internal Mic (DMIC) isn't detected on Dell Latitude 7350 Detachable
by GitHub issues - edited 10 Jun '24
by GitHub issues - edited 10 Jun '24
10 Jun '24
alsa-project/alsa-ucm-conf issue #424 was edited from DeepHarsora-Dell:
Installed Fedora Rawhide on Dell Latitude 7350 Detachable resulting in no-audio output from onboard speaker and in-built mic (DMIC) can't be detected. (SKU - 0x0C64)
Updated the SUT with the following
1. Topology built rightly.
2. Noticed proper SOF Machine driver in upstream as on v.6.10-rc1, able to load the topology.
3. Updated the UCM2 config files as per [[ALSA_UCM_README]](https://github.com/alsa-project/alsa-ucm-conf/blob/master…
Below is the error found while alsaucm reload
[linuxengg@fedora ~]$ sudo alsaucm reload
ALSA lib ucm_subs.c:807:(uc_mgr_get_substituted_value) variable '${var:__RegEx}' is not defined in this context!
ALSA lib parser.c:2024:(parse_verb_file) error: /sof-soundwire/HiFi.conf failed to parse device ALSA lib main.c:1554:(snd_use_case_mgr_open) error: failed to import hw:0 use case configuration -22
alsaucm: error failed to open sound card hw:0: Invalid argument
Issue URL : https://github.com/alsa-project/alsa-ucm-conf/issues/424
Repository URL: https://github.com/alsa-project/alsa-ucm-conf
1
0
alsa-project/alsa-lib issue #400 was opened from sylware:
To have the less "technical distance" with modern audio hardware (for instance usb audio 2), is it better to have interleaved audio frames each with a pitch, or brutally planar with a pitch per plane?
Issue URL : https://github.com/alsa-project/alsa-lib/issues/400
Repository URL: https://github.com/alsa-project/alsa-lib
1
0
Hello Shengjiu Wang,
Commit 039652a5b965 ("ASoC: fsl-asoc-card: Add MQS support") from Jun
17, 2020 (linux-next), leads to the following Smatch static checker
warning:
sound/soc/fsl/fsl-asoc-card.c:796 fsl_asoc_card_probe()
error: uninitialized symbol 'codec_dev_name'.
sound/soc/fsl/fsl-asoc-card.c
542 static int fsl_asoc_card_probe(struct platform_device *pdev)
543 {
544 struct device_node *cpu_np, *codec_np, *asrc_np;
545 struct device_node *np = pdev->dev.of_node;
546 struct platform_device *asrc_pdev = NULL;
547 struct device_node *bitclkprovider = NULL;
548 struct device_node *frameprovider = NULL;
549 struct platform_device *cpu_pdev;
550 struct fsl_asoc_card_priv *priv;
551 struct device *codec_dev = NULL;
552 const char *codec_dai_name;
553 const char *codec_dev_name;
554 u32 asrc_fmt = 0;
555 u32 width;
556 int ret;
557
558 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
559 if (!priv)
560 return -ENOMEM;
561
562 cpu_np = of_parse_phandle(np, "audio-cpu", 0);
563 /* Give a chance to old DT binding */
564 if (!cpu_np)
565 cpu_np = of_parse_phandle(np, "ssi-controller", 0);
566 if (!cpu_np) {
567 dev_err(&pdev->dev, "CPU phandle missing or invalid\n");
568 ret = -EINVAL;
569 goto fail;
570 }
571
572 cpu_pdev = of_find_device_by_node(cpu_np);
573 if (!cpu_pdev) {
574 dev_err(&pdev->dev, "failed to find CPU DAI device\n");
575 ret = -EINVAL;
576 goto fail;
577 }
578
579 codec_np = of_parse_phandle(np, "audio-codec", 0);
580 if (codec_np) {
581 struct platform_device *codec_pdev;
582 struct i2c_client *codec_i2c;
583
584 codec_i2c = of_find_i2c_device_by_node(codec_np);
585 if (codec_i2c) {
586 codec_dev = &codec_i2c->dev;
587 codec_dev_name = codec_i2c->name;
588 }
589 if (!codec_dev) {
590 codec_pdev = of_find_device_by_node(codec_np);
591 if (codec_pdev) {
592 codec_dev = &codec_pdev->dev;
593 codec_dev_name = codec_pdev->name;
594 }
595 }
There are a bunch of ways that codec_dev_name can end up uninitialized.
596 }
597
598 asrc_np = of_parse_phandle(np, "audio-asrc", 0);
599 if (asrc_np)
600 asrc_pdev = of_find_device_by_node(asrc_np);
601
602 /* Get the MCLK rate only, and leave it controlled by CODEC drivers */
603 if (codec_dev) {
604 struct clk *codec_clk = clk_get(codec_dev, NULL);
605
[ Snip ]
789 /* Initialize sound card */
790 priv->pdev = pdev;
791 priv->card.dev = &pdev->dev;
792 priv->card.owner = THIS_MODULE;
793 ret = snd_soc_of_parse_card_name(&priv->card, "model");
794 if (ret) {
795 snprintf(priv->name, sizeof(priv->name), "%s-audio",
--> 796 fsl_asoc_card_is_ac97(priv) ? "ac97" : codec_dev_name);
Used in error handling only.
797 priv->card.name = priv->name;
798 }
799 priv->card.dai_link = priv->dai_link;
800 priv->card.late_probe = fsl_asoc_card_late_probe;
regards,
dan carpenter
1
0
08 Jun '24
From: Srinivas Kandagatla <srinivas.kandagatla(a)linaro.org>
This patchset adds support for.
1. parse Display Port module tokens from ASoC topology
2. add support to DP/HDMI Jack events.
3. fixes a typo in function name in sm8250
Verified these patches on X13s along with changes to tplg in
https://git.codelinaro.org/linaro/qcomlt/audioreach-topology/-/tree/topic/x…
and ucm changes from https://github.com/Srinivas-Kandagatla/alsa-ucm-conf/tree/topic/x13s-dp
Thanks,
Srini
Changes since v1:
- Fixed unused variable warning.
- fixed warning 'break;' to avoid fall-through
Srinivas Kandagatla (4):
ASoC: qcom: q6dsp: parse Display port tokens
ASoC: qcom: common: add Display port Jack function
ASoC: qcom: sc8280xp: add Display port Jack
ASoC: qcom: sm8250: fix a typo in function name
sound/soc/qcom/common.c | 29 +++++++++++++++++++++++++++++
sound/soc/qcom/common.h | 3 +++
sound/soc/qcom/qdsp6/topology.c | 26 ++++++++++++++++++++++++++
sound/soc/qcom/sc8280xp.c | 14 ++++++++++++++
sound/soc/qcom/sm8250.c | 4 ++--
5 files changed, 74 insertions(+), 2 deletions(-)
--
2.25.1
5
24
Set driver name to DRV_NAME. This simplifies the code and gets rid of
the following error messages:
ASoC: driver name too long 'HDMI 58040000.encoder' -> 'HDMI_58040000_e'
Signed-off-by: Primoz Fiser <primoz.fiser(a)norik.com>
---
sound/soc/ti/omap-hdmi.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/sound/soc/ti/omap-hdmi.c b/sound/soc/ti/omap-hdmi.c
index 639bc83f4263..3f35eedeea41 100644
--- a/sound/soc/ti/omap-hdmi.c
+++ b/sound/soc/ti/omap-hdmi.c
@@ -354,11 +354,7 @@ static int omap_hdmi_audio_probe(struct platform_device *pdev)
if (!card)
return -ENOMEM;
- card->name = devm_kasprintf(dev, GFP_KERNEL,
- "HDMI %s", dev_name(ad->dssdev));
- if (!card->name)
- return -ENOMEM;
-
+ card->name = DRV_NAME;
card->owner = THIS_MODULE;
card->dai_link =
devm_kzalloc(dev, sizeof(*(card->dai_link)), GFP_KERNEL);
--
2.25.1
3
4
Replace or drop the legacy header that is subject to remove.
Not all of them were compile-tested, the series might have
hidden compilation errors.
In v3:
- moved aw88399 from the "Remove ..." patch to the "Replace ..." (LKP)
In v2:
- added tags (Kuninori, Charles)
- ripped out TAS2781 (it's a mess from GPIO handling perspective)
Andy Shevchenko (6):
ASoC: codecs: Remove unused of_gpio.h
ASoC: fsl: Remove unused of_gpio.h
ASoC: rockchip: Remove unused of_gpio.h
ASoC: codecs: Replace of_gpio.h by proper one
ASoC: generic: Replace of_gpio.h by proper one
ASoC: samsung: Replace of_gpio.h by proper one
sound/soc/codecs/ak4118.c | 1 -
sound/soc/codecs/ak4458.c | 1 -
sound/soc/codecs/aw88395/aw88395.c | 2 +-
sound/soc/codecs/aw88399.c | 2 +-
sound/soc/codecs/cs53l30.c | 1 -
sound/soc/codecs/max98390.c | 1 -
sound/soc/codecs/pcm3168a.c | 1 -
sound/soc/codecs/rk817_codec.c | 1 -
sound/soc/codecs/tas2552.c | 1 -
sound/soc/codecs/tas2764.c | 1 -
sound/soc/codecs/tas2770.c | 1 -
sound/soc/codecs/tas2780.c | 1 -
sound/soc/codecs/tlv320adc3xxx.c | 1 -
sound/soc/codecs/tlv320adcx140.c | 1 -
sound/soc/codecs/tlv320aic31xx.c | 1 -
sound/soc/codecs/ts3a227e.c | 1 -
sound/soc/codecs/wsa883x.c | 1 -
sound/soc/fsl/imx-es8328.c | 1 -
sound/soc/fsl/imx-rpmsg.c | 2 --
sound/soc/generic/audio-graph-card2-custom-sample.c | 3 ++-
sound/soc/rockchip/rockchip_i2s.c | 1 -
sound/soc/rockchip/rockchip_spdif.c | 1 -
sound/soc/samsung/aries_wm8994.c | 2 +-
23 files changed, 5 insertions(+), 24 deletions(-)
--
2.43.0.rc1.1336.g36b5255a03ac
2
7
07 Jun '24
In some cases, depending on system design, the MICBIAS pins on the
chip are not needed as such, but a couple of extra GPIO pins would be
useful. This patch allows the MICBIAS pins to be configured in the
device tree as general purpose output pins, controlled via the GPIO
framework.
Owing to their originally intended purpose there are some limitations:
when the MICBIAS pins are deactivated, they will float, so will likely
need a pulldown in many applications. When activated, they will
assume the voltage specified by the micbias1-vg and micbias2-vg
properties, respectively, meaning that the resulting output voltage
will be 2.0 V, 2.5 V or AVDD .
Signed-off-by: Ricard Wanderlof <ricard.wanderlof(a)axis.com>
---
Changes in v2:
- Corrected typo in yaml document for ti,micbias2-vg property reference
- Added dependecies to yaml document for ti,micbias1-gio and ti,micbias2-gpo
- Link to v1: https://lore.kernel.org/r/20240529-tlv320adc3xxx-micbias-gpo-v1-0-300d39cec…
---
Ricard Wanderlof (2):
ASoC: dt-bindings: tlv320adc3xxx: Add MICBIAS-as-GPO properties
tlv320adc3xxx: Add support for using MICBIAS pins as GPO
.../bindings/sound/ti,tlv320adc3xxx.yaml | 24 +++++
sound/soc/codecs/tlv320adc3xxx.c | 105 ++++++++++++++++-----
2 files changed, 108 insertions(+), 21 deletions(-)
---
base-commit: 47d09270d7776e46858a161f94b735640b2fb056
change-id: 20240528-tlv320adc3xxx-micbias-gpo-b8b4d1c846d3
Best regards,
--
--
Ricard Wolf Wanderlof ricardw(at)axis.com
Axis Communications AB, Lund, Sweden www.axis.com
Phone +46 46 272 2016 Fax +46 46 13 61 30
2
3
This series fixes two patches:
1. Fix the dmaengine API usage by calling dmaengine_synchronize() after
dmaengine_terminate_async() when xrun events occur in application
2. Use the McASP AFIFO property from DT to refine the period size,
instead of hardcoding minimum to 64 samples
Signed-off-by: Jai Luthra <j-luthra(a)ti.com>
---
Jai Luthra (2):
ALSA: dmaengine: Synchronize dma channel in prepare()
ASoC: ti: davinci-mcasp: Set min period size using FIFO config
include/sound/dmaengine_pcm.h | 1 +
sound/core/pcm_dmaengine.c | 10 ++++++++++
sound/soc/soc-generic-dmaengine-pcm.c | 8 ++++++++
sound/soc/ti/davinci-mcasp.c | 9 +++++++--
4 files changed, 26 insertions(+), 2 deletions(-)
---
base-commit: d97496ca23a2d4ee80b7302849404859d9058bcd
change-id: 20240604-asoc_next-c063fcc190c6
Best regards,
--
Jai Luthra <j-luthra(a)ti.com>
2
3