From 57f7feff2912d6996b5f3fcac084308ce195127c Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Tue, 19 Sep 2017 22:50:00 +0100 Subject: ASoC: rl6231: make arrays div and pd static const, reduces object code size Don't populate the read-only arrays div and pd on the stack, instead make them static const. Makes the object code smaller by 210 bytes: Before: text data bss dec hex filename 2869 720 0 3589 e05 sound/soc/codecs/rl6231.o After: text data bss dec hex filename 2495 880 0 3375 d2f sound/soc/codecs/rl6231.o Signed-off-by: Colin Ian King Signed-off-by: Mark Brown --- sound/soc/codecs/rl6231.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'sound') diff --git a/sound/soc/codecs/rl6231.c b/sound/soc/codecs/rl6231.c index 7b447d0b173a..974a9040651d 100644 --- a/sound/soc/codecs/rl6231.c +++ b/sound/soc/codecs/rl6231.c @@ -71,7 +71,7 @@ EXPORT_SYMBOL_GPL(rl6231_get_pre_div); */ int rl6231_calc_dmic_clk(int rate) { - int div[] = {2, 3, 4, 6, 8, 12}; + static const int div[] = {2, 3, 4, 6, 8, 12}; int i; if (rate < 1000000 * div[0]) { @@ -189,7 +189,8 @@ EXPORT_SYMBOL_GPL(rl6231_pll_calc); int rl6231_get_clk_info(int sclk, int rate) { - int i, pd[] = {1, 2, 3, 4, 6, 8, 12, 16}; + int i; + static const int pd[] = {1, 2, 3, 4, 6, 8, 12, 16}; if (sclk <= 0 || rate <= 0) return -EINVAL; -- cgit v1.2.3 From 28aef24d726f8d503fde24ccf8a14b214355cfb5 Mon Sep 17 00:00:00 2001 From: "oder_chiou@realtek.com" Date: Thu, 2 Nov 2017 19:21:16 +0800 Subject: ASoC: rt5514: The ACPI also should use the function rt5514_parse_dp() The patch fixed that the ACPI cannot access the device property from the function rt5514_parse_dp(). Signed-off-by: Oder Chiou Signed-off-by: Mark Brown --- sound/soc/codecs/rt5514.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'sound') diff --git a/sound/soc/codecs/rt5514.c b/sound/soc/codecs/rt5514.c index d7956ababd11..2a5b5d74e697 100644 --- a/sound/soc/codecs/rt5514.c +++ b/sound/soc/codecs/rt5514.c @@ -1143,7 +1143,7 @@ static const struct acpi_device_id rt5514_acpi_match[] = { MODULE_DEVICE_TABLE(acpi, rt5514_acpi_match); #endif -static int rt5514_parse_dt(struct rt5514_priv *rt5514, struct device *dev) +static int rt5514_parse_dp(struct rt5514_priv *rt5514, struct device *dev) { device_property_read_u32(dev, "realtek,dmic-init-delay-ms", &rt5514->pdata.dmic_init_delay); @@ -1183,8 +1183,8 @@ static int rt5514_i2c_probe(struct i2c_client *i2c, if (pdata) rt5514->pdata = *pdata; - else if (i2c->dev.of_node) - rt5514_parse_dt(rt5514, &i2c->dev); + else + rt5514_parse_dp(rt5514, &i2c->dev); rt5514->i2c_regmap = devm_regmap_init_i2c(i2c, &rt5514_i2c_regmap); if (IS_ERR(rt5514->i2c_regmap)) { -- cgit v1.2.3 From c4a71ff78e668a75a4a3cfd9ebbfbd5cbe8da5fb Mon Sep 17 00:00:00 2001 From: Oder Chiou Date: Wed, 8 Nov 2017 19:21:47 +0800 Subject: ASoC: rt5514-spi: Let the buf_size to align with period_bytes The patch lets the buf_size to align with period_bytes to prevent the buffer reading over the real size of the DSP buffer and also avoid to calculate the wrong size of remaining data. Signed-off-by: Oder Chiou Signed-off-by: Mark Brown --- sound/soc/codecs/rt5514-spi.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'sound') diff --git a/sound/soc/codecs/rt5514-spi.c b/sound/soc/codecs/rt5514-spi.c index 12f2ecf3a4fe..0896817ffc3f 100644 --- a/sound/soc/codecs/rt5514-spi.c +++ b/sound/soc/codecs/rt5514-spi.c @@ -147,8 +147,13 @@ done: static void rt5514_schedule_copy(struct rt5514_dsp *rt5514_dsp) { + size_t period_bytes; u8 buf[8]; + if (!rt5514_dsp->substream) + return; + + period_bytes = snd_pcm_lib_period_bytes(rt5514_dsp->substream); rt5514_dsp->get_size = 0; /** @@ -176,6 +181,10 @@ static void rt5514_schedule_copy(struct rt5514_dsp *rt5514_dsp) rt5514_dsp->buf_size = rt5514_dsp->buf_limit - rt5514_dsp->buf_base; + if (rt5514_dsp->buf_size % period_bytes) + rt5514_dsp->buf_size = (rt5514_dsp->buf_size / period_bytes) * + period_bytes; + if (rt5514_dsp->buf_base && rt5514_dsp->buf_limit && rt5514_dsp->buf_rp && rt5514_dsp->buf_size) schedule_delayed_work(&rt5514_dsp->copy_work, 0); -- cgit v1.2.3 From 58f1c07d23cddbc4c8aa99a214934eb7d33e8523 Mon Sep 17 00:00:00 2001 From: "oder_chiou@realtek.com" Date: Wed, 8 Nov 2017 15:04:21 +0800 Subject: ASoC: rt5514: Voice wakeup support. If the rt5514 Wake on Voice device is opened while suspended, it will be able to wake up the system when a voice command is detected. This patch also supports user-space policy to override wakeup behavior by /sys/bus/spi/drivers/rt5514/spi2.0/power/wakeup. Signed-off-by: Chinyue Chen Signed-off-by: Oder Chiou Signed-off-by: Mark Brown --- sound/soc/codecs/rt5514-spi.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'sound') diff --git a/sound/soc/codecs/rt5514-spi.c b/sound/soc/codecs/rt5514-spi.c index 0896817ffc3f..d03756913dd9 100644 --- a/sound/soc/codecs/rt5514-spi.c +++ b/sound/soc/codecs/rt5514-spi.c @@ -456,9 +456,35 @@ static int rt5514_spi_probe(struct spi_device *spi) return ret; } + device_init_wakeup(&spi->dev, true); + + return 0; +} + +static int rt5514_suspend(struct device *dev) +{ + int irq = to_spi_device(dev)->irq; + + if (device_may_wakeup(dev)) + enable_irq_wake(irq); + return 0; } +static int rt5514_resume(struct device *dev) +{ + int irq = to_spi_device(dev)->irq; + + if (device_may_wakeup(dev)) + disable_irq_wake(irq); + + return 0; +} + +static const struct dev_pm_ops rt5514_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(rt5514_suspend, rt5514_resume) +}; + static const struct of_device_id rt5514_of_match[] = { { .compatible = "realtek,rt5514", }, {}, @@ -468,6 +494,7 @@ MODULE_DEVICE_TABLE(of, rt5514_of_match); static struct spi_driver rt5514_spi_driver = { .driver = { .name = "rt5514", + .pm = &rt5514_pm_ops, .of_match_table = of_match_ptr(rt5514_of_match), }, .probe = rt5514_spi_probe, -- cgit v1.2.3 From e9c50aa6bd3996924b5fd87ab59289888cd5704a Mon Sep 17 00:00:00 2001 From: "oder_chiou@realtek.com" Date: Wed, 8 Nov 2017 15:04:22 +0800 Subject: ASoC: rt5514-spi: check irq status to schedule data copy in resume function For wake on voice use case, we need to copy data from DSP buffer to PCM stream when system wakes up by voice. However the edge triggered IRQ could be missed when system wakes up, in that case the irq function will not be called. If the substream was constructed beforce suspend, we will schedule data copy in resume function. Signed-off-by: Oder Chiou Signed-off-by: Mark Brown --- sound/soc/codecs/rt5514-spi.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'sound') diff --git a/sound/soc/codecs/rt5514-spi.c b/sound/soc/codecs/rt5514-spi.c index d03756913dd9..36e0a58ffc87 100644 --- a/sound/soc/codecs/rt5514-spi.c +++ b/sound/soc/codecs/rt5514-spi.c @@ -473,11 +473,21 @@ static int rt5514_suspend(struct device *dev) static int rt5514_resume(struct device *dev) { + struct snd_soc_platform *platform = snd_soc_lookup_platform(dev); + struct rt5514_dsp *rt5514_dsp = + snd_soc_platform_get_drvdata(platform); int irq = to_spi_device(dev)->irq; + u8 buf[8]; if (device_may_wakeup(dev)) disable_irq_wake(irq); + if (rt5514_dsp->substream) { + rt5514_spi_burst_read(RT5514_IRQ_CTRL, (u8 *)&buf, sizeof(buf)); + if (buf[0] & RT5514_IRQ_STATUS_BIT) + rt5514_schedule_copy(rt5514_dsp); + } + return 0; } -- cgit v1.2.3 From 7e6358ec3b6f69815a42af6203219584a80d4e22 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Fri, 10 Nov 2017 15:54:42 +0100 Subject: ASoC: rt5514: mark PM functions as __maybe_unused The new functions are only used when CONFIG_PM is enabled, leading to a harmless warning: sound/soc/codecs/rt5514-spi.c:474:12: error: 'rt5514_resume' defined but not used [-Werror=unused-function] sound/soc/codecs/rt5514-spi.c:464:12: error: 'rt5514_suspend' defined but not used [-Werror=unused-function] This marks them as __maybe_unused to make the build silent again. Fixes: 58f1c07d23cd ("ASoC: rt5514: Voice wakeup support.") Signed-off-by: Arnd Bergmann Signed-off-by: Mark Brown --- sound/soc/codecs/rt5514-spi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sound') diff --git a/sound/soc/codecs/rt5514-spi.c b/sound/soc/codecs/rt5514-spi.c index 36e0a58ffc87..2df91db765ac 100644 --- a/sound/soc/codecs/rt5514-spi.c +++ b/sound/soc/codecs/rt5514-spi.c @@ -461,7 +461,7 @@ static int rt5514_spi_probe(struct spi_device *spi) return 0; } -static int rt5514_suspend(struct device *dev) +static int __maybe_unused rt5514_suspend(struct device *dev) { int irq = to_spi_device(dev)->irq; @@ -471,7 +471,7 @@ static int rt5514_suspend(struct device *dev) return 0; } -static int rt5514_resume(struct device *dev) +static int __maybe_unused rt5514_resume(struct device *dev) { struct snd_soc_platform *platform = snd_soc_lookup_platform(dev); struct rt5514_dsp *rt5514_dsp = -- cgit v1.2.3 From c56308775b5b81683789f9ee03f009493b51e6ab Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Fri, 10 Nov 2017 15:54:43 +0100 Subject: ASoC: rt5514: work around link error The main rt5514 driver optionally calls into the SPI back-end to load the firmware. This causes a link error when one driver selects rt5514 as built-in and another driver selects rt5514-spi as a loadable module: sound/soc/codecs/rt5514.o: In function `rt5514_dsp_voice_wake_up_put': rt5514.c:(.text+0xac8): undefined reference to `rt5514_spi_burst_write' As a workaround, this adds another silent symbol, to force rt5514-spi to be built-in for that configuration. I'm not overly happy with that solution, but couldn't come up with anything better. Using 'IS_REACHABLE()' would break the case that relies on the loadable module, and all other ideas would result in more complexity. Signed-off-by: Arnd Bergmann Signed-off-by: Mark Brown --- sound/soc/codecs/Kconfig | 4 ++++ sound/soc/codecs/Makefile | 1 + 2 files changed, 5 insertions(+) (limited to 'sound') diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index c367d11079bc..01f436cc14c6 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig @@ -749,6 +749,10 @@ config SND_SOC_RT5514 config SND_SOC_RT5514_SPI tristate +config SND_SOC_RT5514_SPI_BUILTIN + bool # force RT5514_SPI to be built-in to avoid link errors + default SND_SOC_RT5514=y && SND_SOC_RT5514_SPI=m + config SND_SOC_RT5616 tristate "Realtek RT5616 CODEC" depends on I2C diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index 77c18189c9ad..2dc42b296973 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile @@ -359,6 +359,7 @@ obj-$(CONFIG_SND_SOC_RT286) += snd-soc-rt286.o obj-$(CONFIG_SND_SOC_RT298) += snd-soc-rt298.o obj-$(CONFIG_SND_SOC_RT5514) += snd-soc-rt5514.o obj-$(CONFIG_SND_SOC_RT5514_SPI) += snd-soc-rt5514-spi.o +obj-$(CONFIG_SND_SOC_RT5514_SPI_BUILTIN) += snd-soc-rt5514-spi.o obj-$(CONFIG_SND_SOC_RT5616) += snd-soc-rt5616.o obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o -- cgit v1.2.3