From 675398674c4edc2058a1dd632abd5d748b4653c3 Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Sun, 14 Jun 2020 23:12:21 +0900 Subject: ALSA: firewire-motu: wait for notification when changing clock configuration for protocol v3 It costs expensive to change clock configuration for models of protocol version 3. In current implementation, speculative strategy is used to finish the operation; just waiting for 4 seconds. As long as I investigate, when accepting and changing clock status actually, the device sends notification with mask. This commit uses wise way to wait for the notification after changing sampling clock rate during 4 seconds. Signed-off-by: Takashi Sakamoto Link: https://lore.kernel.org/r/20200614141221.53527-1-o-takashi@sakamocchi.jp Signed-off-by: Takashi Iwai --- sound/firewire/motu/motu-protocol-v3.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/sound/firewire/motu/motu-protocol-v3.c b/sound/firewire/motu/motu-protocol-v3.c index 01a47ac7bb2d..4e6b0e449ee4 100644 --- a/sound/firewire/motu/motu-protocol-v3.c +++ b/sound/firewire/motu/motu-protocol-v3.c @@ -24,6 +24,9 @@ #define V3_NO_ADAT_OPT_OUT_IFACE_A 0x00040000 #define V3_NO_ADAT_OPT_OUT_IFACE_B 0x00400000 +#define V3_MSG_FLAG_CLK_CHANGED 0x00000002 +#define V3_CLK_WAIT_MSEC 4000 + int snd_motu_protocol_v3_get_clock_rate(struct snd_motu *motu, unsigned int *rate) { @@ -79,9 +82,16 @@ int snd_motu_protocol_v3_set_clock_rate(struct snd_motu *motu, return err; if (need_to_wait) { - /* Cost expensive. */ - if (msleep_interruptible(4000) > 0) - return -EINTR; + int result; + + motu->msg = 0; + result = wait_event_interruptible_timeout(motu->hwdep_wait, + motu->msg & V3_MSG_FLAG_CLK_CHANGED, + msecs_to_jiffies(V3_CLK_WAIT_MSEC)); + if (result < 0) + return result; + if (result == 0) + return -ETIMEDOUT; } return 0; -- cgit v1.2.3 From 3aad07b87ac3fa1c67a75403f7f9c576da8df71d Mon Sep 17 00:00:00 2001 From: Tzung-Bi Shih Date: Fri, 5 Jun 2020 11:49:30 +0800 Subject: ASoC: max98357a: add compatible string for MAX98360A Maxim MAX98360A audio amplifier is functionally identical to MAX98357A. Adds compatible string "maxim,max98360a" for driver reuse. Signed-off-by: Tzung-Bi Shih Link: https://lore.kernel.org/r/20200605034931.107713-2-tzungbi@google.com Signed-off-by: Mark Brown --- sound/soc/codecs/max98357a.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sound/soc/codecs/max98357a.c b/sound/soc/codecs/max98357a.c index a8bd793a7867..4f431133d0bb 100644 --- a/sound/soc/codecs/max98357a.c +++ b/sound/soc/codecs/max98357a.c @@ -125,6 +125,7 @@ static int max98357a_platform_probe(struct platform_device *pdev) #ifdef CONFIG_OF static const struct of_device_id max98357a_device_id[] = { { .compatible = "maxim,max98357a" }, + { .compatible = "maxim,max98360a" }, {} }; MODULE_DEVICE_TABLE(of, max98357a_device_id); -- cgit v1.2.3 From 3e3b803f9e76b2ec386c0f3f0618fb7d0bca4ffc Mon Sep 17 00:00:00 2001 From: Tzung-Bi Shih Date: Fri, 5 Jun 2020 11:49:31 +0800 Subject: ASoC: dt-bindings: add compatible string for MAX98360A Maxim MAX98360A audio amplifier is functionally identical to MAX98357A. Adds compatible string "maxim,max98360a" for driver reuse. Signed-off-by: Tzung-Bi Shih Link: https://lore.kernel.org/r/20200605034931.107713-3-tzungbi@google.com Signed-off-by: Mark Brown --- Documentation/devicetree/bindings/sound/max98357a.txt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/sound/max98357a.txt b/Documentation/devicetree/bindings/sound/max98357a.txt index 4bce14ce806f..75db84d06240 100644 --- a/Documentation/devicetree/bindings/sound/max98357a.txt +++ b/Documentation/devicetree/bindings/sound/max98357a.txt @@ -1,9 +1,10 @@ -Maxim MAX98357A audio DAC +Maxim MAX98357A/MAX98360A audio DAC -This node models the Maxim MAX98357A DAC. +This node models the Maxim MAX98357A/MAX98360A DAC. Required properties: -- compatible : "maxim,max98357a" +- compatible : "maxim,max98357a" for MAX98357A. + "maxim,max98360a" for MAX98360A. Optional properties: - sdmode-gpios : GPIO specifier for the chip's SD_MODE pin. @@ -20,3 +21,8 @@ max98357a { compatible = "maxim,max98357a"; sdmode-gpios = <&qcom_pinmux 25 0>; }; + +max98360a { + compatible = "maxim,max98360a"; + sdmode-gpios = <&qcom_pinmux 25 0>; +}; -- cgit v1.2.3 From d955dab33af4ebff0f6c486da216ebbf590eb7e4 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 15 Jun 2020 18:00:42 +0200 Subject: ALSA: pcm: Use dma_mmap_coherent() on x86, too We avoided the explicit use of dma_mmap_coherent() on x86 because of a spurious warning in x86 APT code in the past. However, this blindly assumes that the pages allocated via dma_alloc_coherent() on x86 are the ones convertible via virt_to_page() (that is used in the default mmap handler), and it's no longer true; with the indirect DMA ops, this can be handled differently. The only certain way for doing mmap such pages is the dma_mmap_coherent(), and the warning seems already gone in the recent code, so let's use it consistently. Link: https://lore.kernel.org/r/20200615160045.2703-2-tiwai@suse.de Signed-off-by: Takashi Iwai --- sound/core/pcm_native.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 9630d2523948..1e51c849d3d4 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -3713,7 +3713,6 @@ int snd_pcm_lib_default_mmap(struct snd_pcm_substream *substream, area->vm_end - area->vm_start, area->vm_page_prot); } #endif /* CONFIG_GENERIC_ALLOCATOR */ -#ifndef CONFIG_X86 /* for avoiding warnings arch/x86/mm/pat.c */ if (IS_ENABLED(CONFIG_HAS_DMA) && !substream->ops->page && (substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV || substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV_UC)) @@ -3722,7 +3721,6 @@ int snd_pcm_lib_default_mmap(struct snd_pcm_substream *substream, substream->runtime->dma_area, substream->runtime->dma_addr, substream->runtime->dma_bytes); -#endif /* CONFIG_X86 */ /* mmap with fault handler */ area->vm_ops = &snd_pcm_vm_ops_data_fault; return 0; -- cgit v1.2.3 From 28e60dbb83f76b18acade913dfdb029cd908c9b0 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 15 Jun 2020 18:00:43 +0200 Subject: ALSA: memalloc: Initialize all fields of snd_dma_buffer properly Some fields in snd_dma_buffer aren't touched in snd_dma_alloc_pages() and might be left uninitialized. Let's clear all fields properly, so that we can use a NULL check (e.g. dmab->private_data) as conditional in a later patch. Link: https://lore.kernel.org/r/20200615160045.2703-3-tiwai@suse.de Signed-off-by: Takashi Iwai --- sound/core/memalloc.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c index bea46ed157a6..d8f28d030985 100644 --- a/sound/core/memalloc.c +++ b/sound/core/memalloc.c @@ -135,16 +135,17 @@ int snd_dma_alloc_pages(int type, struct device *device, size_t size, dmab->dev.type = type; dmab->dev.dev = device; dmab->bytes = 0; + dmab->area = NULL; + dmab->addr = 0; + dmab->private_data = NULL; switch (type) { case SNDRV_DMA_TYPE_CONTINUOUS: gfp = snd_mem_get_gfp_flags(device, GFP_KERNEL); dmab->area = alloc_pages_exact(size, gfp); - dmab->addr = 0; break; case SNDRV_DMA_TYPE_VMALLOC: gfp = snd_mem_get_gfp_flags(device, GFP_KERNEL | __GFP_HIGHMEM); dmab->area = __vmalloc(size, gfp); - dmab->addr = 0; break; #ifdef CONFIG_HAS_DMA #ifdef CONFIG_GENERIC_ALLOCATOR @@ -171,8 +172,6 @@ int snd_dma_alloc_pages(int type, struct device *device, size_t size, #endif default: pr_err("snd-malloc: invalid device type %d\n", type); - dmab->area = NULL; - dmab->addr = 0; return -ENXIO; } if (! dmab->area) -- cgit v1.2.3 From 2a1f3368bff609504cdc984cdb7cef467bb0b2b0 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 15 Jun 2020 18:00:44 +0200 Subject: ALSA: memalloc: Make SG-buffer helper usable for continuous buffer, too We have a few helper functions for making the access to the buffer address easier on SG-buffer. Those are specific to the buffer that is allocated with SG-buffer type, and it makes hard to use both SG and non-SG buffers in the same code. This patch adds a few simple checks and lets the helpers to deal with both SG- and continuous buffers gracefully. It's a preliminary step for the upcoming patch that mimics the buffer type on the fly. Link: https://lore.kernel.org/r/20200615160045.2703-4-tiwai@suse.de Signed-off-by: Takashi Iwai --- include/sound/memalloc.h | 9 ++++++++- sound/core/sgbuf.c | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/sound/memalloc.h b/include/sound/memalloc.h index 3b47832b1c1f..5daa937684a4 100644 --- a/include/sound/memalloc.h +++ b/include/sound/memalloc.h @@ -94,7 +94,11 @@ static inline dma_addr_t snd_sgbuf_get_addr(struct snd_dma_buffer *dmab, size_t offset) { struct snd_sg_buf *sgbuf = dmab->private_data; - dma_addr_t addr = sgbuf->table[offset >> PAGE_SHIFT].addr; + dma_addr_t addr; + + if (!sgbuf) + return dmab->addr + offset; + addr = sgbuf->table[offset >> PAGE_SHIFT].addr; addr &= ~((dma_addr_t)PAGE_SIZE - 1); return addr + offset % PAGE_SIZE; } @@ -106,6 +110,9 @@ static inline void *snd_sgbuf_get_ptr(struct snd_dma_buffer *dmab, size_t offset) { struct snd_sg_buf *sgbuf = dmab->private_data; + + if (!sgbuf) + return dmab->area + offset; return sgbuf->table[offset >> PAGE_SHIFT].buf + offset % PAGE_SIZE; } diff --git a/sound/core/sgbuf.c b/sound/core/sgbuf.c index c42217e2dd19..29ddb76187e5 100644 --- a/sound/core/sgbuf.c +++ b/sound/core/sgbuf.c @@ -142,6 +142,9 @@ unsigned int snd_sgbuf_get_chunk_size(struct snd_dma_buffer *dmab, struct snd_sg_buf *sg = dmab->private_data; unsigned int start, end, pg; + if (!sg) + return size; + start = ofs >> PAGE_SHIFT; end = (ofs + size - 1) >> PAGE_SHIFT; /* check page continuity */ -- cgit v1.2.3 From 3ad796cbc36a7bc8bfd4de191d791b9490bc112b Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 15 Jun 2020 18:00:45 +0200 Subject: ALSA: pcm: Use SG-buffer only when direct DMA is available The DMA-coherent SG-buffer is tricky to use, as it does need the mapping. It used to work stably on x86 over years (and that's why we had enabled SG-buffer on solely x86) with the default mmap handler and vmap(), but our luck seems no forever success. The chance of breakage is high when the special DMA handling is introduced in the arch side. In this patch, we change the buffer allocation to use the SG-buffer only when the device in question is with the direct DMA. It's a bit hackish, but it's currently the only condition that may work (more or less) reliably with the default mmap and vmap() for mapping the pages that are deduced via virt_to_page(). In theory, we can apply the similar hack in the sound/core memory allocation helper, too; but it's used by SOF for allocating SG pages without re-mapping via vmap() or mmap, and it's fine to use it in that way, so let's keep it and adds the workaround in PCM side. Link: https://lore.kernel.org/r/20200615160045.2703-5-tiwai@suse.de Signed-off-by: Takashi Iwai --- sound/core/pcm_memory.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sound/core/pcm_memory.c b/sound/core/pcm_memory.c index 860935e3aea4..8326d16d3596 100644 --- a/sound/core/pcm_memory.c +++ b/sound/core/pcm_memory.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -39,6 +40,18 @@ static int do_alloc_pages(struct snd_card *card, int type, struct device *dev, if (max_alloc_per_card && card->total_pcm_alloc_bytes + size > max_alloc_per_card) return -ENOMEM; + + if (IS_ENABLED(CONFIG_SND_DMA_SGBUF) && + (type == SNDRV_DMA_TYPE_DEV_SG || type == SNDRV_DMA_TYPE_DEV_UC_SG) && + !dma_is_direct(get_dma_ops(dev))) { + /* mutate to continuous page allocation */ + dev_dbg(dev, "Use continuous page allocator\n"); + if (type == SNDRV_DMA_TYPE_DEV_SG) + type = SNDRV_DMA_TYPE_DEV; + else + type = SNDRV_DMA_TYPE_DEV_UC; + } + err = snd_dma_alloc_pages(type, dev, size, dmab); if (!err) { mutex_lock(&card->memory_mutex); -- cgit v1.2.3 From 1328948fea693679ab81601aa72a9ed6025f81ea Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Fri, 12 Jun 2020 15:40:48 -0500 Subject: ASoC: soc-core: reduce verbosity of BE override message With dynamic debug not enabled, we still see this sort of messages: [ 47.656671] sof_sdw sof_sdw: info: override BE DAI link SDW0-Playback [ 47.656677] sof_sdw sof_sdw: info: override BE DAI link SDW0-Capture [ 47.656682] sof_sdw sof_sdw: info: override BE DAI link SDW1-Playback [ 47.656686] sof_sdw sof_sdw: info: override BE DAI link SDW3-Capture [ 47.656691] sof_sdw sof_sdw: info: override BE DAI link iDisp1 [ 47.656695] sof_sdw sof_sdw: info: override BE DAI link iDisp2 [ 47.656699] sof_sdw sof_sdw: info: override BE DAI link iDisp3 This is not really helpful for most users, move to dev_dbg. Signed-off-by: Pierre-Louis Bossart Reviewed-by: Bard Liao Reviewed-by: Kai Vehmanen Link: https://lore.kernel.org/r/20200612204050.25901-2-pierre-louis.bossart@linux.intel.com Signed-off-by: Mark Brown --- sound/soc/soc-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 0f30f5aabaa8..e607a4927933 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1638,8 +1638,8 @@ match: continue; } - dev_info(card->dev, "info: override BE DAI link %s\n", - card->dai_link[i].name); + dev_dbg(card->dev, "info: override BE DAI link %s\n", + card->dai_link[i].name); /* override platform component */ if (!dai_link->platforms) { -- cgit v1.2.3 From 799827a42045e77a34bd4a90ba8bde372ed8058d Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Fri, 12 Jun 2020 15:40:49 -0500 Subject: ASoC: soc-pcm: improve error messages in soc_pcm_new() Provide an explicit dmesg trace with the PCM 'new_name', dailink name and error code to help with debug. Signed-off-by: Pierre-Louis Bossart Reviewed-by: Bard Liao Reviewed-by: Kai Vehmanen Link: https://lore.kernel.org/r/20200612204050.25901-3-pierre-louis.bossart@linux.intel.com Signed-off-by: Mark Brown --- sound/soc/soc-pcm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index c517064f5391..00aba7fa8d78 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -2891,8 +2891,8 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) capture, &pcm); } if (ret < 0) { - dev_err(rtd->card->dev, "ASoC: can't create pcm for %s\n", - rtd->dai_link->name); + dev_err(rtd->card->dev, "ASoC: can't create pcm %s for dailink %s: %d\n", + new_name, rtd->dai_link->name, ret); return ret; } dev_dbg(rtd->card->dev, "ASoC: registered pcm #%d %s\n",num, new_name); @@ -2957,7 +2957,8 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) ret = snd_soc_pcm_component_new(rtd); if (ret < 0) { - dev_err(rtd->dev, "ASoC: pcm constructor failed: %d\n", ret); + dev_err(rtd->dev, "ASoC: pcm %s constructor failed for dailink %s: %d\n", + new_name, rtd->dai_link->name, ret); return ret; } -- cgit v1.2.3 From 1d5cd5254f67bc65622f4cac04c25d6e082f21b0 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Fri, 12 Jun 2020 15:40:50 -0500 Subject: ASoC: soc-pcm/compress: reduce verbosity on mapping ok messages With dynamic debug not enabled, we still get these messages: [ 48.133586] sof_sdw sof_sdw: rt711-aif1 <-> SDW0 Pin2 mapping ok [ 48.133595] sof_sdw sof_sdw: rt711-aif1 <-> SDW0 Pin3 mapping ok [ 48.133650] sof_sdw sof_sdw: sdw:1:25d:1308:0 <-> SDW1 Pin2 mapping ok [ 48.133658] sof_sdw sof_sdw: rt715-aif2 <-> SDW3 Pin2 mapping ok [ 48.133666] sof_sdw sof_sdw: intel-hdmi-hifi1 <-> iDisp1 Pin mapping ok [ 48.133672] sof_sdw sof_sdw: intel-hdmi-hifi2 <-> iDisp2 Pin mapping ok [ 48.133677] sof_sdw sof_sdw: intel-hdmi-hifi3 <-> iDisp3 Pin mapping ok [ 48.133712] sof_sdw sof_sdw: snd-soc-dummy-dai <-> Headphone 0 mapping ok [ 48.133733] sof_sdw sof_sdw: snd-soc-dummy-dai <-> Headset mic 1 mapping ok [ 48.133746] sof_sdw sof_sdw: snd-soc-dummy-dai <-> SDW1-speakers 2 mapping ok [ 48.133762] sof_sdw sof_sdw: snd-soc-dummy-dai <-> Microphones 4 mapping ok [ 48.133774] sof_sdw sof_sdw: snd-soc-dummy-dai <-> HDMI1 5 mapping ok [ 48.133798] sof_sdw sof_sdw: snd-soc-dummy-dai <-> HDMI2 6 mapping ok [ 48.133809] sof_sdw sof_sdw: snd-soc-dummy-dai <-> HDMI3 7 mapping ok This is not really useful for most users, demote to dev_dbg() Signed-off-by: Pierre-Louis Bossart Reviewed-by: Bard Liao Reviewed-by: Kai Vehmanen Link: https://lore.kernel.org/r/20200612204050.25901-4-pierre-louis.bossart@linux.intel.com Signed-off-by: Mark Brown --- sound/soc/soc-compress.c | 4 ++-- sound/soc/soc-pcm.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index 4984b6a2c370..415510909a82 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -867,8 +867,8 @@ int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) rtd->compr = compr; compr->private_data = rtd; - dev_info(rtd->card->dev, "Compress ASoC: %s <-> %s mapping ok\n", - codec_dai->name, cpu_dai->name); + dev_dbg(rtd->card->dev, "Compress ASoC: %s <-> %s mapping ok\n", + codec_dai->name, cpu_dai->name); return 0; } diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 00aba7fa8d78..0cd83d38ff1a 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -2964,9 +2964,9 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) pcm->no_device_suspend = true; out: - dev_info(rtd->card->dev, "%s <-> %s mapping ok\n", - (rtd->num_codecs > 1) ? "multicodec" : asoc_rtd_to_codec(rtd, 0)->name, - (rtd->num_cpus > 1) ? "multicpu" : asoc_rtd_to_cpu(rtd, 0)->name); + dev_dbg(rtd->card->dev, "%s <-> %s mapping ok\n", + (rtd->num_codecs > 1) ? "multicodec" : asoc_rtd_to_codec(rtd, 0)->name, + (rtd->num_cpus > 1) ? "multicpu" : asoc_rtd_to_cpu(rtd, 0)->name); return ret; } -- cgit v1.2.3 From 4ca8701ee3106943c84d011c86a7ae41aff72e17 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Thu, 4 Jun 2020 17:06:11 +0900 Subject: ASoC: soc-component: add soc_component_pin() and share code soc-component has too many snd_soc_component_xxx_pin_xxx() functions. The difference between these functions are used function name and enable/disable. This patch adds common soc_component_pin() and share code. Signed-off-by: Kuninori Morimoto Reviewed-by: Ranjani Sridharan Link: https://lore.kernel.org/r/87tuzrw8zw.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- sound/soc/soc-component.c | 152 ++++++---------------------------------------- 1 file changed, 20 insertions(+), 132 deletions(-) diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index 785a0385cc7f..76f4b953563c 100644 --- a/sound/soc/soc-component.c +++ b/sound/soc/soc-component.c @@ -77,8 +77,10 @@ int snd_soc_component_set_bias_level(struct snd_soc_component *component, return 0; } -int snd_soc_component_enable_pin(struct snd_soc_component *component, - const char *pin) +static int soc_component_pin(struct snd_soc_component *component, + const char *pin, + int (*pin_func)(struct snd_soc_dapm_context *dapm, + const char *pin)) { struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); @@ -86,170 +88,71 @@ int snd_soc_component_enable_pin(struct snd_soc_component *component, int ret; if (!component->name_prefix) - return snd_soc_dapm_enable_pin(dapm, pin); + return pin_func(dapm, pin); full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin); if (!full_name) return -ENOMEM; - ret = snd_soc_dapm_enable_pin(dapm, full_name); + ret = pin_func(dapm, full_name); kfree(full_name); return ret; } + +int snd_soc_component_enable_pin(struct snd_soc_component *component, + const char *pin) +{ + return soc_component_pin(component, pin, snd_soc_dapm_enable_pin); +} EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin); int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component, const char *pin) { - struct snd_soc_dapm_context *dapm = - snd_soc_component_get_dapm(component); - char *full_name; - int ret; - - if (!component->name_prefix) - return snd_soc_dapm_enable_pin_unlocked(dapm, pin); - - full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin); - if (!full_name) - return -ENOMEM; - - ret = snd_soc_dapm_enable_pin_unlocked(dapm, full_name); - kfree(full_name); - - return ret; + return soc_component_pin(component, pin, snd_soc_dapm_enable_pin_unlocked); } EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin_unlocked); int snd_soc_component_disable_pin(struct snd_soc_component *component, const char *pin) { - struct snd_soc_dapm_context *dapm = - snd_soc_component_get_dapm(component); - char *full_name; - int ret; - - if (!component->name_prefix) - return snd_soc_dapm_disable_pin(dapm, pin); - - full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin); - if (!full_name) - return -ENOMEM; - - ret = snd_soc_dapm_disable_pin(dapm, full_name); - kfree(full_name); - - return ret; + return soc_component_pin(component, pin, snd_soc_dapm_disable_pin); } EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin); int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component, const char *pin) { - struct snd_soc_dapm_context *dapm = - snd_soc_component_get_dapm(component); - char *full_name; - int ret; - - if (!component->name_prefix) - return snd_soc_dapm_disable_pin_unlocked(dapm, pin); - - full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin); - if (!full_name) - return -ENOMEM; - - ret = snd_soc_dapm_disable_pin_unlocked(dapm, full_name); - kfree(full_name); - - return ret; + return soc_component_pin(component, pin, snd_soc_dapm_disable_pin_unlocked); } EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin_unlocked); int snd_soc_component_nc_pin(struct snd_soc_component *component, const char *pin) { - struct snd_soc_dapm_context *dapm = - snd_soc_component_get_dapm(component); - char *full_name; - int ret; - - if (!component->name_prefix) - return snd_soc_dapm_nc_pin(dapm, pin); - - full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin); - if (!full_name) - return -ENOMEM; - - ret = snd_soc_dapm_nc_pin(dapm, full_name); - kfree(full_name); - - return ret; + return soc_component_pin(component, pin, snd_soc_dapm_nc_pin); } EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin); int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component, const char *pin) { - struct snd_soc_dapm_context *dapm = - snd_soc_component_get_dapm(component); - char *full_name; - int ret; - - if (!component->name_prefix) - return snd_soc_dapm_nc_pin_unlocked(dapm, pin); - - full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin); - if (!full_name) - return -ENOMEM; - - ret = snd_soc_dapm_nc_pin_unlocked(dapm, full_name); - kfree(full_name); - - return ret; + return soc_component_pin(component, pin, snd_soc_dapm_nc_pin_unlocked); } EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin_unlocked); int snd_soc_component_get_pin_status(struct snd_soc_component *component, const char *pin) { - struct snd_soc_dapm_context *dapm = - snd_soc_component_get_dapm(component); - char *full_name; - int ret; - - if (!component->name_prefix) - return snd_soc_dapm_get_pin_status(dapm, pin); - - full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin); - if (!full_name) - return -ENOMEM; - - ret = snd_soc_dapm_get_pin_status(dapm, full_name); - kfree(full_name); - - return ret; + return soc_component_pin(component, pin, snd_soc_dapm_get_pin_status); } EXPORT_SYMBOL_GPL(snd_soc_component_get_pin_status); int snd_soc_component_force_enable_pin(struct snd_soc_component *component, const char *pin) { - struct snd_soc_dapm_context *dapm = - snd_soc_component_get_dapm(component); - char *full_name; - int ret; - - if (!component->name_prefix) - return snd_soc_dapm_force_enable_pin(dapm, pin); - - full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin); - if (!full_name) - return -ENOMEM; - - ret = snd_soc_dapm_force_enable_pin(dapm, full_name); - kfree(full_name); - - return ret; + return soc_component_pin(component, pin, snd_soc_dapm_force_enable_pin); } EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin); @@ -257,22 +160,7 @@ int snd_soc_component_force_enable_pin_unlocked( struct snd_soc_component *component, const char *pin) { - struct snd_soc_dapm_context *dapm = - snd_soc_component_get_dapm(component); - char *full_name; - int ret; - - if (!component->name_prefix) - return snd_soc_dapm_force_enable_pin_unlocked(dapm, pin); - - full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin); - if (!full_name) - return -ENOMEM; - - ret = snd_soc_dapm_force_enable_pin_unlocked(dapm, full_name); - kfree(full_name); - - return ret; + return soc_component_pin(component, pin, snd_soc_dapm_force_enable_pin_unlocked); } EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin_unlocked); -- cgit v1.2.3 From c7d75b5938e38a48e5fdac44f88fc5882f1f7bed Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Thu, 4 Jun 2020 17:06:22 +0900 Subject: ASoC: soc-component: move snd_soc_component_xxx_regmap() to soc-component soc-component is handling snd_soc_component_xxx(). Move snd_soc_component_xxx_regmap() to it. Signed-off-by: Kuninori Morimoto Reviewed-by: Ranjani Sridharan Link: https://lore.kernel.org/r/87sgfbw8zl.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- include/sound/soc-component.h | 1 + sound/soc/soc-component.c | 50 +++++++++++++++++++++++++++++++++++++++++++ sound/soc/soc-core.c | 50 ------------------------------------------- 3 files changed, 51 insertions(+), 50 deletions(-) diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h index 5663891148e3..481132141dc2 100644 --- a/include/sound/soc-component.h +++ b/include/sound/soc-component.h @@ -359,6 +359,7 @@ int snd_soc_component_stream_event(struct snd_soc_component *component, int snd_soc_component_set_bias_level(struct snd_soc_component *component, enum snd_soc_bias_level level); +void snd_soc_component_setup_regmap(struct snd_soc_component *component); #ifdef CONFIG_REGMAP void snd_soc_component_init_regmap(struct snd_soc_component *component, struct regmap *regmap); diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index 76f4b953563c..3c96a1adaa8b 100644 --- a/sound/soc/soc-component.c +++ b/sound/soc/soc-component.c @@ -302,6 +302,56 @@ int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component, return -ENOTSUPP; } +void snd_soc_component_setup_regmap(struct snd_soc_component *component) +{ + int val_bytes = regmap_get_val_bytes(component->regmap); + + /* Errors are legitimate for non-integer byte multiples */ + if (val_bytes > 0) + component->val_bytes = val_bytes; +} + +#ifdef CONFIG_REGMAP + +/** + * snd_soc_component_init_regmap() - Initialize regmap instance for the + * component + * @component: The component for which to initialize the regmap instance + * @regmap: The regmap instance that should be used by the component + * + * This function allows deferred assignment of the regmap instance that is + * associated with the component. Only use this if the regmap instance is not + * yet ready when the component is registered. The function must also be called + * before the first IO attempt of the component. + */ +void snd_soc_component_init_regmap(struct snd_soc_component *component, + struct regmap *regmap) +{ + component->regmap = regmap; + snd_soc_component_setup_regmap(component); +} +EXPORT_SYMBOL_GPL(snd_soc_component_init_regmap); + +/** + * snd_soc_component_exit_regmap() - De-initialize regmap instance for the + * component + * @component: The component for which to de-initialize the regmap instance + * + * Calls regmap_exit() on the regmap instance associated to the component and + * removes the regmap instance from the component. + * + * This function should only be used if snd_soc_component_init_regmap() was used + * to initialize the regmap instance. + */ +void snd_soc_component_exit_regmap(struct snd_soc_component *component) +{ + regmap_exit(component->regmap); + component->regmap = NULL; +} +EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap); + +#endif + int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream) { struct snd_soc_pcm_runtime *rtd = substream->private_data; diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 0f30f5aabaa8..13a59736b2fc 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -2398,56 +2398,6 @@ static int snd_soc_component_initialize(struct snd_soc_component *component, return 0; } -static void snd_soc_component_setup_regmap(struct snd_soc_component *component) -{ - int val_bytes = regmap_get_val_bytes(component->regmap); - - /* Errors are legitimate for non-integer byte multiples */ - if (val_bytes > 0) - component->val_bytes = val_bytes; -} - -#ifdef CONFIG_REGMAP - -/** - * snd_soc_component_init_regmap() - Initialize regmap instance for the - * component - * @component: The component for which to initialize the regmap instance - * @regmap: The regmap instance that should be used by the component - * - * This function allows deferred assignment of the regmap instance that is - * associated with the component. Only use this if the regmap instance is not - * yet ready when the component is registered. The function must also be called - * before the first IO attempt of the component. - */ -void snd_soc_component_init_regmap(struct snd_soc_component *component, - struct regmap *regmap) -{ - component->regmap = regmap; - snd_soc_component_setup_regmap(component); -} -EXPORT_SYMBOL_GPL(snd_soc_component_init_regmap); - -/** - * snd_soc_component_exit_regmap() - De-initialize regmap instance for the - * component - * @component: The component for which to de-initialize the regmap instance - * - * Calls regmap_exit() on the regmap instance associated to the component and - * removes the regmap instance from the component. - * - * This function should only be used if snd_soc_component_init_regmap() was used - * to initialize the regmap instance. - */ -void snd_soc_component_exit_regmap(struct snd_soc_component *component) -{ - regmap_exit(component->regmap); - component->regmap = NULL; -} -EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap); - -#endif - #define ENDIANNESS_MAP(name) \ (SNDRV_PCM_FMTBIT_##name##LE | SNDRV_PCM_FMTBIT_##name##BE) static u64 endianness_format_map[] = { -- cgit v1.2.3 From 536aba1dd4939bf647f5d182d4f101ae548e6505 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Thu, 4 Jun 2020 17:06:32 +0900 Subject: ASoC: soc-component: move snd_soc_component_initialize() to soc-component.c snd_soc_component_xxx() should be implemented at soc-component.c Signed-off-by: Kuninori Morimoto Reviewed-by: Ranjani Sridharan Link: https://lore.kernel.org/r/87r1uvw8zb.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- include/sound/soc-component.h | 4 ++++ sound/soc/soc-component.c | 16 ++++++++++++++++ sound/soc/soc-core.c | 29 ++++++++--------------------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h index 481132141dc2..cb0d34fa77c6 100644 --- a/include/sound/soc-component.h +++ b/include/sound/soc-component.h @@ -324,6 +324,10 @@ static inline int snd_soc_component_cache_sync( return regcache_sync(component->regmap); } +int snd_soc_component_initialize(struct snd_soc_component *component, + const struct snd_soc_component_driver *driver, + struct device *dev, const char *name); + /* component IO */ int snd_soc_component_read(struct snd_soc_component *component, unsigned int reg, unsigned int *val); diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index 3c96a1adaa8b..5bf2e71d3d83 100644 --- a/sound/soc/soc-component.c +++ b/sound/soc/soc-component.c @@ -8,6 +8,22 @@ #include #include +int snd_soc_component_initialize(struct snd_soc_component *component, + const struct snd_soc_component_driver *driver, + struct device *dev, const char *name) +{ + INIT_LIST_HEAD(&component->dai_list); + INIT_LIST_HEAD(&component->dobj_list); + INIT_LIST_HEAD(&component->card_list); + mutex_init(&component->io_mutex); + + component->name = name; + component->dev = dev; + component->driver = driver; + + return 0; +} + /** * snd_soc_component_set_sysclk - configure COMPONENT system or master clock. * @component: COMPONENT diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 13a59736b2fc..e596e5a765da 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -2378,26 +2378,6 @@ err: return ret; } -static int snd_soc_component_initialize(struct snd_soc_component *component, - const struct snd_soc_component_driver *driver, struct device *dev) -{ - INIT_LIST_HEAD(&component->dai_list); - INIT_LIST_HEAD(&component->dobj_list); - INIT_LIST_HEAD(&component->card_list); - mutex_init(&component->io_mutex); - - component->name = fmt_single_name(dev, &component->id); - if (!component->name) { - dev_err(dev, "ASoC: Failed to allocate name\n"); - return -ENOMEM; - } - - component->dev = dev; - component->driver = driver; - - return 0; -} - #define ENDIANNESS_MAP(name) \ (SNDRV_PCM_FMTBIT_##name##LE | SNDRV_PCM_FMTBIT_##name##BE) static u64 endianness_format_map[] = { @@ -2460,12 +2440,19 @@ int snd_soc_add_component(struct device *dev, struct snd_soc_dai_driver *dai_drv, int num_dai) { + const char *name = fmt_single_name(dev, &component->id); int ret; int i; + if (!name) { + dev_err(dev, "ASoC: Failed to allocate name\n"); + return -ENOMEM; + } + mutex_lock(&client_mutex); - ret = snd_soc_component_initialize(component, component_driver, dev); + ret = snd_soc_component_initialize(component, component_driver, + dev, name); if (ret) goto err_free; -- cgit v1.2.3 From e2329eeba45fdad5eeb2bec5c61f8cefbee69cb8 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Thu, 4 Jun 2020 17:06:41 +0900 Subject: ASoC: soc-component: add soc_component_err() At soc-component.c, it is good idea to indicate error function and its component name if there was error. This patch adds soc_component_err() for it. Signed-off-by: Kuninori Morimoto Reviewed-by: Ranjani Sridharan Link: https://lore.kernel.org/r/87pnafw8z2.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- sound/soc/soc-component.c | 162 +++++++++++++++++++++++++++++++++------------- 1 file changed, 116 insertions(+), 46 deletions(-) diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index 5bf2e71d3d83..6d29c2de3b24 100644 --- a/sound/soc/soc-component.c +++ b/sound/soc/soc-component.c @@ -8,6 +8,28 @@ #include #include +#define soc_component_ret(dai, ret) _soc_component_ret(dai, __func__, ret) +static inline int _soc_component_ret(struct snd_soc_component *component, + const char *func, int ret) +{ + /* Positive/Zero values are not errors */ + if (ret >= 0) + return ret; + + /* Negative values might be errors */ + switch (ret) { + case -EPROBE_DEFER: + case -ENOTSUPP: + break; + default: + dev_err(component->dev, + "ASoC: error at %s on %s: %d\n", + func, component->name, ret); + } + + return ret; +} + int snd_soc_component_initialize(struct snd_soc_component *component, const struct snd_soc_component_driver *driver, struct device *dev, const char *name) @@ -38,11 +60,13 @@ int snd_soc_component_set_sysclk(struct snd_soc_component *component, int clk_id, int source, unsigned int freq, int dir) { + int ret = -ENOTSUPP; + if (component->driver->set_sysclk) - return component->driver->set_sysclk(component, clk_id, source, + ret = component->driver->set_sysclk(component, clk_id, source, freq, dir); - return -ENOTSUPP; + return soc_component_ret(component, ret); } EXPORT_SYMBOL_GPL(snd_soc_component_set_sysclk); @@ -60,11 +84,13 @@ int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id, int source, unsigned int freq_in, unsigned int freq_out) { + int ret = -EINVAL; + if (component->driver->set_pll) - return component->driver->set_pll(component, pll_id, source, + ret = component->driver->set_pll(component, pll_id, source, freq_in, freq_out); - return -EINVAL; + return soc_component_ret(component, ret); } EXPORT_SYMBOL_GPL(snd_soc_component_set_pll); @@ -78,19 +104,23 @@ void snd_soc_component_seq_notifier(struct snd_soc_component *component, int snd_soc_component_stream_event(struct snd_soc_component *component, int event) { + int ret = 0; + if (component->driver->stream_event) - return component->driver->stream_event(component, event); + ret = component->driver->stream_event(component, event); - return 0; + return soc_component_ret(component, ret); } int snd_soc_component_set_bias_level(struct snd_soc_component *component, enum snd_soc_bias_level level) { + int ret = 0; + if (component->driver->set_bias_level) - return component->driver->set_bias_level(component, level); + ret = component->driver->set_bias_level(component, level); - return 0; + return soc_component_ret(component, ret); } static int soc_component_pin(struct snd_soc_component *component, @@ -103,17 +133,21 @@ static int soc_component_pin(struct snd_soc_component *component, char *full_name; int ret; - if (!component->name_prefix) - return pin_func(dapm, pin); + if (!component->name_prefix) { + ret = pin_func(dapm, pin); + goto end; + } full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin); - if (!full_name) - return -ENOMEM; + if (!full_name) { + ret = -ENOMEM; + goto end; + } ret = pin_func(dapm, full_name); kfree(full_name); - - return ret; +end: + return soc_component_ret(component, ret); } int snd_soc_component_enable_pin(struct snd_soc_component *component, @@ -191,21 +225,25 @@ EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin_unlocked); int snd_soc_component_set_jack(struct snd_soc_component *component, struct snd_soc_jack *jack, void *data) { + int ret = -ENOTSUPP; + if (component->driver->set_jack) - return component->driver->set_jack(component, jack, data); + ret = component->driver->set_jack(component, jack, data); - return -ENOTSUPP; + return soc_component_ret(component, ret); } EXPORT_SYMBOL_GPL(snd_soc_component_set_jack); int snd_soc_component_module_get(struct snd_soc_component *component, int upon_open) { + int ret = 0; + if (component->driver->module_get_upon_open == !!upon_open && !try_module_get(component->dev->driver->owner)) - return -ENODEV; + ret = -ENODEV; - return 0; + return soc_component_ret(component, ret); } void snd_soc_component_module_put(struct snd_soc_component *component, @@ -218,52 +256,70 @@ void snd_soc_component_module_put(struct snd_soc_component *component, int snd_soc_component_open(struct snd_soc_component *component, struct snd_pcm_substream *substream) { + int ret = 0; + if (component->driver->open) - return component->driver->open(component, substream); - return 0; + ret = component->driver->open(component, substream); + + return soc_component_ret(component, ret); } int snd_soc_component_close(struct snd_soc_component *component, struct snd_pcm_substream *substream) { + int ret = 0; + if (component->driver->close) - return component->driver->close(component, substream); - return 0; + ret = component->driver->close(component, substream); + + return soc_component_ret(component, ret); } int snd_soc_component_prepare(struct snd_soc_component *component, struct snd_pcm_substream *substream) { + int ret = 0; + if (component->driver->prepare) - return component->driver->prepare(component, substream); - return 0; + ret = component->driver->prepare(component, substream); + + return soc_component_ret(component, ret); } int snd_soc_component_hw_params(struct snd_soc_component *component, struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { + int ret = 0; + if (component->driver->hw_params) - return component->driver->hw_params(component, - substream, params); - return 0; + ret = component->driver->hw_params(component, + substream, params); + + return soc_component_ret(component, ret); } int snd_soc_component_hw_free(struct snd_soc_component *component, struct snd_pcm_substream *substream) { + int ret = 0; + if (component->driver->hw_free) - return component->driver->hw_free(component, substream); - return 0; + ret = component->driver->hw_free(component, substream); + + return soc_component_ret(component, ret); } int snd_soc_component_trigger(struct snd_soc_component *component, struct snd_pcm_substream *substream, int cmd) { + int ret = 0; + if (component->driver->trigger) - return component->driver->trigger(component, substream, cmd); - return 0; + ret = component->driver->trigger(component, substream, cmd); + + return soc_component_ret(component, ret); } void snd_soc_component_suspend(struct snd_soc_component *component) @@ -287,10 +343,12 @@ int snd_soc_component_is_suspended(struct snd_soc_component *component) int snd_soc_component_probe(struct snd_soc_component *component) { + int ret = 0; + if (component->driver->probe) - return component->driver->probe(component); + ret = component->driver->probe(component); - return 0; + return soc_component_ret(component, ret); } void snd_soc_component_remove(struct snd_soc_component *component) @@ -302,20 +360,25 @@ void snd_soc_component_remove(struct snd_soc_component *component) int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component, struct device_node *ep) { + int ret = -ENOTSUPP; + if (component->driver->of_xlate_dai_id) - return component->driver->of_xlate_dai_id(component, ep); + ret = component->driver->of_xlate_dai_id(component, ep); - return -ENOTSUPP; + return soc_component_ret(component, ret); } int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component, struct of_phandle_args *args, const char **dai_name) { + int ret = -ENOTSUPP; + if (component->driver->of_xlate_dai_name) - return component->driver->of_xlate_dai_name(component, - args, dai_name); - return -ENOTSUPP; + ret = component->driver->of_xlate_dai_name(component, + args, dai_name); + + return soc_component_ret(component, ret); } void snd_soc_component_setup_regmap(struct snd_soc_component *component) @@ -392,8 +455,10 @@ int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream, /* FIXME: use 1st ioctl */ for_each_rtd_components(rtd, i, component) if (component->driver->ioctl) - return component->driver->ioctl(component, substream, - cmd, arg); + return soc_component_ret( + component, + component->driver->ioctl(component, + substream, cmd, arg)); return snd_pcm_lib_ioctl(substream, cmd, arg); } @@ -409,7 +474,7 @@ int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream) ret = component->driver->sync_stop(component, substream); if (ret < 0) - return ret; + soc_component_ret(component, ret); } } @@ -427,8 +492,11 @@ int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream, /* FIXME. it returns 1st copy now */ for_each_rtd_components(rtd, i, component) if (component->driver->copy_user) - return component->driver->copy_user( - component, substream, channel, pos, buf, bytes); + return soc_component_ret( + component, + component->driver->copy_user( + component, substream, channel, + pos, buf, bytes)); return -EINVAL; } @@ -464,8 +532,10 @@ int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream, /* FIXME. it returns 1st mmap now */ for_each_rtd_components(rtd, i, component) if (component->driver->mmap) - return component->driver->mmap(component, - substream, vma); + soc_component_ret( + component, + component->driver->mmap(component, + substream, vma)); return -EINVAL; } @@ -480,7 +550,7 @@ int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd) if (component->driver->pcm_construct) { ret = component->driver->pcm_construct(component, rtd); if (ret < 0) - return ret; + soc_component_ret(component, ret); } } -- cgit v1.2.3 From 4f39514f36980a4b20a754a5d51486a5999c8380 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Thu, 4 Jun 2020 17:06:58 +0900 Subject: ASoC: soc-component: add snd_soc_pcm_component_prepare() We have 2 type of component functions snd_soc_component_xxx() is focusing to component itself, snd_soc_pcm_component_xxx() is focusing to rtd related component. Now we can update snd_soc_component_prepare() to snd_soc_pcm_component_prepare(). This patch do it. Signed-off-by: Kuninori Morimoto Reviewed-by: Ranjani Sridharan Link: https://lore.kernel.org/r/87o8pzw8yl.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- include/sound/soc-component.h | 3 +-- sound/soc/soc-component.c | 28 +++++++++++++++++----------- sound/soc/soc-pcm.c | 12 +++--------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h index cb0d34fa77c6..fc287e910240 100644 --- a/include/sound/soc-component.h +++ b/include/sound/soc-component.h @@ -426,8 +426,6 @@ int snd_soc_component_open(struct snd_soc_component *component, struct snd_pcm_substream *substream); int snd_soc_component_close(struct snd_soc_component *component, struct snd_pcm_substream *substream); -int snd_soc_component_prepare(struct snd_soc_component *component, - struct snd_pcm_substream *substream); int snd_soc_component_hw_params(struct snd_soc_component *component, struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params); @@ -460,5 +458,6 @@ int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream, struct vm_area_struct *vma); int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd); void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd); +int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream); #endif /* __SOC_COMPONENT_H */ diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index 6d29c2de3b24..1bc155bc8e5e 100644 --- a/sound/soc/soc-component.c +++ b/sound/soc/soc-component.c @@ -275,17 +275,6 @@ int snd_soc_component_close(struct snd_soc_component *component, return soc_component_ret(component, ret); } -int snd_soc_component_prepare(struct snd_soc_component *component, - struct snd_pcm_substream *substream) -{ - int ret = 0; - - if (component->driver->prepare) - ret = component->driver->prepare(component, substream); - - return soc_component_ret(component, ret); -} - int snd_soc_component_hw_params(struct snd_soc_component *component, struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) @@ -569,3 +558,20 @@ void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd) if (component->driver->pcm_destruct) component->driver->pcm_destruct(component, rtd->pcm); } + +int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream) +{ + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_component *component; + int i, ret; + + for_each_rtd_components(rtd, i, component) { + if (component->driver->prepare) { + ret = component->driver->prepare(component, substream); + if (ret < 0) + return soc_component_ret(component, ret); + } + } + + return 0; +} diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index c517064f5391..8ba0f14a2f2f 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -850,7 +850,6 @@ static void codec2codec_close_delayed_work(struct snd_soc_pcm_runtime *rtd) static int soc_pcm_prepare(struct snd_pcm_substream *substream) { struct snd_soc_pcm_runtime *rtd = substream->private_data; - struct snd_soc_component *component; struct snd_soc_dai *dai; int i, ret = 0; @@ -860,14 +859,9 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream) if (ret < 0) goto out; - for_each_rtd_components(rtd, i, component) { - ret = snd_soc_component_prepare(component, substream); - if (ret < 0) { - dev_err(component->dev, - "ASoC: platform prepare error: %d\n", ret); - goto out; - } - } + ret = snd_soc_pcm_component_prepare(substream); + if (ret < 0) + goto out; ret = snd_soc_pcm_dai_prepare(substream); if (ret < 0) { -- cgit v1.2.3 From e1bafa828e3a0622ac24d238e00937f3059ed585 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Thu, 4 Jun 2020 17:07:11 +0900 Subject: ASoC: soc-component: add snd_soc_pcm_component_hw_params() We have 2 type of component functions snd_soc_component_xxx() is focusing to component itself, snd_soc_pcm_component_xxx() is focusing to rtd related component. Now we can update snd_soc_component_hw_params() to snd_soc_pcm_component_hw_params(). This patch do it. Signed-off-by: Kuninori Morimoto Reviewed-by: Ranjani Sridharan Link: https://lore.kernel.org/r/87mu5jw8y8.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- include/sound/soc-component.h | 6 +++--- sound/soc/soc-component.c | 36 +++++++++++++++++++++++------------- sound/soc/soc-pcm.c | 13 +++---------- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h index fc287e910240..a2898bdd0a3c 100644 --- a/include/sound/soc-component.h +++ b/include/sound/soc-component.h @@ -426,9 +426,6 @@ int snd_soc_component_open(struct snd_soc_component *component, struct snd_pcm_substream *substream); int snd_soc_component_close(struct snd_soc_component *component, struct snd_pcm_substream *substream); -int snd_soc_component_hw_params(struct snd_soc_component *component, - struct snd_pcm_substream *substream, - struct snd_pcm_hw_params *params); int snd_soc_component_hw_free(struct snd_soc_component *component, struct snd_pcm_substream *substream); int snd_soc_component_trigger(struct snd_soc_component *component, @@ -459,5 +456,8 @@ int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream, int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd); void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd); int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream); +int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_component **last); #endif /* __SOC_COMPONENT_H */ diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index 1bc155bc8e5e..56341968fe6d 100644 --- a/sound/soc/soc-component.c +++ b/sound/soc/soc-component.c @@ -275,19 +275,6 @@ int snd_soc_component_close(struct snd_soc_component *component, return soc_component_ret(component, ret); } -int snd_soc_component_hw_params(struct snd_soc_component *component, - struct snd_pcm_substream *substream, - struct snd_pcm_hw_params *params) -{ - int ret = 0; - - if (component->driver->hw_params) - ret = component->driver->hw_params(component, - substream, params); - - return soc_component_ret(component, ret); -} - int snd_soc_component_hw_free(struct snd_soc_component *component, struct snd_pcm_substream *substream) { @@ -575,3 +562,26 @@ int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream) return 0; } + +int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_component **last) +{ + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_component *component; + int i, ret; + + for_each_rtd_components(rtd, i, component) { + if (component->driver->hw_params) { + ret = component->driver->hw_params(component, + substream, params); + if (ret < 0) { + *last = component; + return soc_component_ret(component, ret); + } + } + } + + *last = NULL; + return 0; +} diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 8ba0f14a2f2f..e5eef48af167 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -1009,16 +1009,9 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream, snd_soc_dapm_update_dai(substream, params, cpu_dai); } - for_each_rtd_components(rtd, i, component) { - ret = snd_soc_component_hw_params(component, substream, params); - if (ret < 0) { - dev_err(component->dev, - "ASoC: %s hw params failed: %d\n", - component->name, ret); - goto component_err; - } - } - component = NULL; + ret = snd_soc_pcm_component_hw_params(substream, params, &component); + if (ret < 0) + goto component_err; out: mutex_unlock(&rtd->card->pcm_mutex); -- cgit v1.2.3 From 047511198639649bdaacb1a34d9691429ccc5698 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Thu, 4 Jun 2020 17:07:24 +0900 Subject: ASoC: soc-component: add snd_soc_pcm_component_hw_free() We have 2 type of component functions snd_soc_component_xxx() is focusing to component itself, snd_soc_pcm_component_xxx() is focusing to rtd related component. Now we can update snd_soc_component_hw_free() to snd_soc_pcm_component_hw_free(). This patch do it. Signed-off-by: Kuninori Morimoto Reviewed-by: Ranjani Sridharan Link: https://lore.kernel.org/r/87lfl3w8xv.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- include/sound/soc-component.h | 4 ++-- sound/soc/soc-component.c | 30 +++++++++++++++++++----------- sound/soc/soc-pcm.c | 23 ++--------------------- 3 files changed, 23 insertions(+), 34 deletions(-) diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h index a2898bdd0a3c..d2f62d529559 100644 --- a/include/sound/soc-component.h +++ b/include/sound/soc-component.h @@ -426,8 +426,6 @@ int snd_soc_component_open(struct snd_soc_component *component, struct snd_pcm_substream *substream); int snd_soc_component_close(struct snd_soc_component *component, struct snd_pcm_substream *substream); -int snd_soc_component_hw_free(struct snd_soc_component *component, - struct snd_pcm_substream *substream); int snd_soc_component_trigger(struct snd_soc_component *component, struct snd_pcm_substream *substream, int cmd); @@ -459,5 +457,7 @@ int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream); int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_component **last); +void snd_soc_pcm_component_hw_free(struct snd_pcm_substream *substream, + struct snd_soc_component *last); #endif /* __SOC_COMPONENT_H */ diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index 56341968fe6d..380f6459b5cb 100644 --- a/sound/soc/soc-component.c +++ b/sound/soc/soc-component.c @@ -275,17 +275,6 @@ int snd_soc_component_close(struct snd_soc_component *component, return soc_component_ret(component, ret); } -int snd_soc_component_hw_free(struct snd_soc_component *component, - struct snd_pcm_substream *substream) -{ - int ret = 0; - - if (component->driver->hw_free) - ret = component->driver->hw_free(component, substream); - - return soc_component_ret(component, ret); -} - int snd_soc_component_trigger(struct snd_soc_component *component, struct snd_pcm_substream *substream, int cmd) @@ -585,3 +574,22 @@ int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream, *last = NULL; return 0; } + +void snd_soc_pcm_component_hw_free(struct snd_pcm_substream *substream, + struct snd_soc_component *last) +{ + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_component *component; + int i, ret; + + for_each_rtd_components(rtd, i, component) { + if (component == last) + break; + + if (component->driver->hw_free) { + ret = component->driver->hw_free(component, substream); + if (ret < 0) + soc_component_ret(component, ret); + } + } +} diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index e5eef48af167..cbce15c5721e 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -898,25 +898,6 @@ static void soc_pcm_codec_params_fixup(struct snd_pcm_hw_params *params, interval->max = channels; } -static int soc_pcm_components_hw_free(struct snd_pcm_substream *substream, - struct snd_soc_component *last) -{ - struct snd_soc_pcm_runtime *rtd = substream->private_data; - struct snd_soc_component *component; - int i, r, ret = 0; - - for_each_rtd_components(rtd, i, component) { - if (component == last) - break; - - r = snd_soc_component_hw_free(component, substream); - if (r < 0) - ret = r; /* use last ret */ - } - - return ret; -} - /* * Called by ALSA when the hardware params are set by application. This * function can also be called multiple times and can allocate buffers @@ -1018,7 +999,7 @@ out: return ret; component_err: - soc_pcm_components_hw_free(substream, component); + snd_soc_pcm_component_hw_free(substream, component); i = rtd->num_cpus; @@ -1077,7 +1058,7 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream) snd_soc_link_hw_free(substream); /* free any component resources */ - soc_pcm_components_hw_free(substream, NULL); + snd_soc_pcm_component_hw_free(substream, NULL); /* now free hw params for the DAIs */ for_each_rtd_dais(rtd, i, dai) { -- cgit v1.2.3 From 32fd120475c1b8a83d28bfedc2b95ec981fbb809 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Thu, 4 Jun 2020 17:07:40 +0900 Subject: ASoC: soc-component: add snd_soc_pcm_component_trigger() We have 2 type of component functions snd_soc_component_xxx() is focusing to component itself, snd_soc_pcm_component_xxx() is focusing to rtd related component. Now we can update snd_soc_component_trigger() to snd_soc_pcm_component_trigger(). This patch do it. Signed-off-by: Kuninori Morimoto Reviewed-by: Ranjani Sridharan Link: https://lore.kernel.org/r/87k10nw8xf.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- include/sound/soc-component.h | 5 ++--- sound/soc/soc-component.c | 30 ++++++++++++++++++------------ sound/soc/soc-pcm.c | 24 ++++++++---------------- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h index d2f62d529559..bb26d55a9289 100644 --- a/include/sound/soc-component.h +++ b/include/sound/soc-component.h @@ -426,9 +426,6 @@ int snd_soc_component_open(struct snd_soc_component *component, struct snd_pcm_substream *substream); int snd_soc_component_close(struct snd_soc_component *component, struct snd_pcm_substream *substream); -int snd_soc_component_trigger(struct snd_soc_component *component, - struct snd_pcm_substream *substream, - int cmd); void snd_soc_component_suspend(struct snd_soc_component *component); void snd_soc_component_resume(struct snd_soc_component *component); int snd_soc_component_is_suspended(struct snd_soc_component *component); @@ -459,5 +456,7 @@ int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream, struct snd_soc_component **last); void snd_soc_pcm_component_hw_free(struct snd_pcm_substream *substream, struct snd_soc_component *last); +int snd_soc_pcm_component_trigger(struct snd_pcm_substream *substream, + int cmd); #endif /* __SOC_COMPONENT_H */ diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index 380f6459b5cb..150b02be0219 100644 --- a/sound/soc/soc-component.c +++ b/sound/soc/soc-component.c @@ -275,18 +275,6 @@ int snd_soc_component_close(struct snd_soc_component *component, return soc_component_ret(component, ret); } -int snd_soc_component_trigger(struct snd_soc_component *component, - struct snd_pcm_substream *substream, - int cmd) -{ - int ret = 0; - - if (component->driver->trigger) - ret = component->driver->trigger(component, substream, cmd); - - return soc_component_ret(component, ret); -} - void snd_soc_component_suspend(struct snd_soc_component *component) { if (component->driver->suspend) @@ -593,3 +581,21 @@ void snd_soc_pcm_component_hw_free(struct snd_pcm_substream *substream, } } } + +int snd_soc_pcm_component_trigger(struct snd_pcm_substream *substream, + int cmd) +{ + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_component *component; + int i, ret; + + for_each_rtd_components(rtd, i, component) { + if (component->driver->trigger) { + ret = component->driver->trigger(component, substream, cmd); + if (ret < 0) + return soc_component_ret(component, ret); + } + } + + return 0; +} diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index cbce15c5721e..be5c83f1ab0c 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -1074,38 +1074,30 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream) static int soc_pcm_trigger_start(struct snd_pcm_substream *substream, int cmd) { - struct snd_soc_pcm_runtime *rtd = substream->private_data; - struct snd_soc_component *component; - int i, ret; + int ret; ret = snd_soc_link_trigger(substream, cmd); if (ret < 0) return ret; - for_each_rtd_components(rtd, i, component) { - ret = snd_soc_component_trigger(component, substream, cmd); - if (ret < 0) - return ret; - } + ret = snd_soc_pcm_component_trigger(substream, cmd); + if (ret < 0) + return ret; return snd_soc_pcm_dai_trigger(substream, cmd); } static int soc_pcm_trigger_stop(struct snd_pcm_substream *substream, int cmd) { - struct snd_soc_pcm_runtime *rtd = substream->private_data; - struct snd_soc_component *component; - int i, ret; + int ret; ret = snd_soc_pcm_dai_trigger(substream, cmd); if (ret < 0) return ret; - for_each_rtd_components(rtd, i, component) { - ret = snd_soc_component_trigger(component, substream, cmd); - if (ret < 0) - retu