Message ID | fd3989d15546502b47f580e6a2c3a59cb628ce93.1727056789.git.zhoubinbin@loongson.cn (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | ASoC: Some issues about loongson i2s | expand |
On Tue, Sep 24, 2024 at 03:00:48PM +0800, Binbin Zhou wrote: > config SND_SOC_LOONGSON_I2S_PCI > tristate "Loongson I2S-PCI Device Driver" > - select REGMAP_MMIO > depends on PCI > + select REGMAP_MMIO > + select SND_SOC_LOONGSON_CARD > help > Say Y or M if you want to add support for I2S driver for > Loongson I2S controller. You shouldn't select the card from the DAI drivers, some system might use the driver with a different card for some reason. If anything a select from the card to the DAI driver is more appropriate, cards are the main user thing. > +++ b/sound/soc/loongson/loongson_i2s_plat.c > @@ -0,0 +1,186 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Loongson I2S controller master mode dirver(platform device) Please use C++ style for the whole comment block so things look more intentional.
Hi Binbin,
kernel test robot noticed the following build warnings:
[auto build test WARNING on broonie-sound/for-next]
[also build test WARNING on linus/master next-20240924]
[cannot apply to robh/for-next v6.11]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Binbin-Zhou/ASoC-dt-bindings-Add-Everest-ES8323-Codec/20240924-150942
base: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
patch link: https://lore.kernel.org/r/fd3989d15546502b47f580e6a2c3a59cb628ce93.1727056789.git.zhoubinbin%40loongson.cn
patch subject: [PATCH v2 7/9] ASoC: loongson: Add I2S controller driver as platform device
config: alpha-kismet-CONFIG_SND_SOC_LOONGSON_CARD-CONFIG_SND_SOC_LOONGSON_I2S_PCI-0-0 (https://download.01.org/0day-ci/archive/20240925/202409250533.AEodmhZc-lkp@intel.com/config)
reproduce: (https://download.01.org/0day-ci/archive/20240925/202409250533.AEodmhZc-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202409250533.AEodmhZc-lkp@intel.com/
kismet warnings: (new ones prefixed by >>)
>> kismet: WARNING: unmet direct dependencies detected for SND_SOC_LOONGSON_CARD when selected by SND_SOC_LOONGSON_I2S_PCI
WARNING: unmet direct dependencies detected for SND_SOC_LOONGSON_CARD
Depends on [n]: SOUND [=y] && SND [=y] && SND_SOC [=y] && (LOONGARCH || COMPILE_TEST [=n])
Selected by [y]:
- SND_SOC_LOONGSON_I2S_PCI [=y] && SOUND [=y] && SND [=y] && SND_SOC [=y] && PCI [=y]
Hi Binbin,
kernel test robot noticed the following build warnings:
[auto build test WARNING on broonie-sound/for-next]
[also build test WARNING on linus/master next-20240924]
[cannot apply to robh/for-next v6.11]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Binbin-Zhou/ASoC-dt-bindings-Add-Everest-ES8323-Codec/20240924-150942
base: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
patch link: https://lore.kernel.org/r/fd3989d15546502b47f580e6a2c3a59cb628ce93.1727056789.git.zhoubinbin%40loongson.cn
patch subject: [PATCH v2 7/9] ASoC: loongson: Add I2S controller driver as platform device
config: alpha-kismet-CONFIG_SND_SOC_LOONGSON_CARD-CONFIG_SND_SOC_LOONGSON_I2S_PLATFORM-0-0 (https://download.01.org/0day-ci/archive/20240925/202409251242.gyf8pdxt-lkp@intel.com/config)
reproduce: (https://download.01.org/0day-ci/archive/20240925/202409251242.gyf8pdxt-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202409251242.gyf8pdxt-lkp@intel.com/
kismet warnings: (new ones prefixed by >>)
>> kismet: WARNING: unmet direct dependencies detected for SND_SOC_LOONGSON_CARD when selected by SND_SOC_LOONGSON_I2S_PLATFORM
WARNING: unmet direct dependencies detected for SND_SOC_LOONGSON_CARD
Depends on [n]: SOUND [=y] && SND [=y] && SND_SOC [=y] && (LOONGARCH || COMPILE_TEST [=n])
Selected by [y]:
- SND_SOC_LOONGSON_I2S_PLATFORM [=y] && SOUND [=y] && SND [=y] && SND_SOC [=y] && OF [=y]
Hi Mark: Thanks for your reply. On Tue, Sep 24, 2024 at 3:14 PM Mark Brown <broonie@kernel.org> wrote: > > On Tue, Sep 24, 2024 at 03:00:48PM +0800, Binbin Zhou wrote: > > > config SND_SOC_LOONGSON_I2S_PCI > > tristate "Loongson I2S-PCI Device Driver" > > - select REGMAP_MMIO > > depends on PCI > > + select REGMAP_MMIO > > + select SND_SOC_LOONGSON_CARD > > help > > Say Y or M if you want to add support for I2S driver for > > Loongson I2S controller. > > You shouldn't select the card from the DAI drivers, some system might > use the driver with a different card for some reason. If anything a > select from the card to the DAI driver is more appropriate, cards are > the main user thing. I will rewrite the dependency between the card and the DAI driver, as follows: config SND_SOC_LOONGSON_CARD tristate "Loongson Sound Card Driver" depends on LOONGARCH || COMPILE_TEST select SND_SOC_LOONGSON_I2S_PCI if PCI select SND_SOC_LOONGSON_I2S_PLATFORM if OF config SND_SOC_LOONGSON_I2S_PCI tristate "Loongson I2S-PCI Device Driver" select REGMAP_MMIO config SND_SOC_LOONGSON_I2S_PLATFORM tristate "Loongson I2S controller as platform device" select REGMAP_MMIO select SND_SOC_GENERIC_DMAENGINE_PCM Thanks. Binbin > > > +++ b/sound/soc/loongson/loongson_i2s_plat.c > > @@ -0,0 +1,186 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* > > + * Loongson I2S controller master mode dirver(platform device) > > Please use C++ style for the whole comment block so things look more > intentional.
On Thu, Sep 26, 2024 at 08:03:55AM +0600, Binbin Zhou wrote: > I will rewrite the dependency between the card and the DAI driver, as follows: > config SND_SOC_LOONGSON_CARD > tristate "Loongson Sound Card Driver" > depends on LOONGARCH || COMPILE_TEST > select SND_SOC_LOONGSON_I2S_PCI if PCI > select SND_SOC_LOONGSON_I2S_PLATFORM if OF > config SND_SOC_LOONGSON_I2S_PCI > tristate "Loongson I2S-PCI Device Driver" > select REGMAP_MMIO > config SND_SOC_LOONGSON_I2S_PLATFORM > tristate "Loongson I2S controller as platform device" > select REGMAP_MMIO > select SND_SOC_GENERIC_DMAENGINE_PCM That looks good apart from the PCI and platform drivers should probably also have a depends on LOONGARCH || COMPILE_TEST so they're not shown on architectures where they can't be used unless doing testing.
Hi Mark: On Thu, Sep 26, 2024 at 1:45 PM Mark Brown <broonie@kernel.org> wrote: > > On Thu, Sep 26, 2024 at 08:03:55AM +0600, Binbin Zhou wrote: > > > I will rewrite the dependency between the card and the DAI driver, as follows: > > > config SND_SOC_LOONGSON_CARD > > tristate "Loongson Sound Card Driver" > > depends on LOONGARCH || COMPILE_TEST > > select SND_SOC_LOONGSON_I2S_PCI if PCI > > select SND_SOC_LOONGSON_I2S_PLATFORM if OF > > > config SND_SOC_LOONGSON_I2S_PCI > > tristate "Loongson I2S-PCI Device Driver" > > select REGMAP_MMIO > > > config SND_SOC_LOONGSON_I2S_PLATFORM > > tristate "Loongson I2S controller as platform device" > > select REGMAP_MMIO > > select SND_SOC_GENERIC_DMAENGINE_PCM > > That looks good apart from the PCI and platform drivers should probably > also have a > > depends on LOONGARCH || COMPILE_TEST > > so they're not shown on architectures where they can't be used unless > doing testing. OK, I will add it in the V3 patchset. Thanks. Binbin
diff --git a/sound/soc/loongson/Kconfig b/sound/soc/loongson/Kconfig index b8d7e2bade24..715ddc91a834 100644 --- a/sound/soc/loongson/Kconfig +++ b/sound/soc/loongson/Kconfig @@ -1,11 +1,21 @@ # SPDX-License-Identifier: GPL-2.0 menu "SoC Audio for Loongson CPUs" + +config SND_SOC_LOONGSON_CARD + tristate "Loongson Sound Card Driver" depends on LOONGARCH || COMPILE_TEST + help + Say Y or M if you want to add support for SoC audio using + loongson I2S controller. + + The driver add support for ALSA SoC Audio support using + loongson I2S controller. config SND_SOC_LOONGSON_I2S_PCI tristate "Loongson I2S-PCI Device Driver" - select REGMAP_MMIO depends on PCI + select REGMAP_MMIO + select SND_SOC_LOONGSON_CARD help Say Y or M if you want to add support for I2S driver for Loongson I2S controller. @@ -13,15 +23,16 @@ config SND_SOC_LOONGSON_I2S_PCI The controller is found in loongson bridge chips or SoCs, and work as a PCI device. -config SND_SOC_LOONGSON_CARD - tristate "Loongson Sound Card Driver" - select SND_SOC_LOONGSON_I2S_PCI - depends on PCI +config SND_SOC_LOONGSON_I2S_PLATFORM + tristate "Loongson I2S controller as platform device" + depends on OF + select REGMAP_MMIO + select SND_SOC_LOONGSON_CARD + select SND_SOC_GENERIC_DMAENGINE_PCM help - Say Y or M if you want to add support for SoC audio using - loongson I2S controller. - - The driver add support for ALSA SoC Audio support using - loongson I2S controller. + Say Y or M if you want to add support for I2S driver for + Loongson I2S controller. + The controller work as a platform device, found in Loongson-2K1000 + SoCs. endmenu diff --git a/sound/soc/loongson/Makefile b/sound/soc/loongson/Makefile index 578030ad6563..f396259244a3 100644 --- a/sound/soc/loongson/Makefile +++ b/sound/soc/loongson/Makefile @@ -3,6 +3,9 @@ snd-soc-loongson-i2s-pci-y := loongson_i2s_pci.o loongson_i2s.o loongson_dma.o obj-$(CONFIG_SND_SOC_LOONGSON_I2S_PCI) += snd-soc-loongson-i2s-pci.o +snd-soc-loongson-i2s-plat-y := loongson_i2s_plat.o loongson_i2s.o +obj-$(CONFIG_SND_SOC_LOONGSON_I2S_PLATFORM) += snd-soc-loongson-i2s-plat.o + #Machine Support snd-soc-loongson-card-y := loongson_card.o obj-$(CONFIG_SND_SOC_LOONGSON_CARD) += snd-soc-loongson-card.o diff --git a/sound/soc/loongson/loongson_i2s_plat.c b/sound/soc/loongson/loongson_i2s_plat.c new file mode 100644 index 000000000000..668067753b1c --- /dev/null +++ b/sound/soc/loongson/loongson_i2s_plat.c @@ -0,0 +1,186 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Loongson I2S controller master mode dirver(platform device) + * + * Copyright (C) 2023-2024 Loongson Technology Corporation Limited + * + * Author: Yingkun Meng <mengyingkun@loongson.cn> + * Binbin Zhou <zhoubinbin@loongson.cn> + */ + +#include <linux/clk.h> +#include <linux/dma-mapping.h> +#include <linux/module.h> +#include <linux/of_dma.h> +#include <linux/platform_device.h> +#include <linux/pm_runtime.h> +#include <sound/dmaengine_pcm.h> +#include <sound/pcm.h> +#include <sound/pcm_params.h> +#include <sound/soc.h> + +#include "loongson_i2s.h" + +#define LOONGSON_I2S_RX_DMA_OFFSET 21 +#define LOONGSON_I2S_TX_DMA_OFFSET 18 + +#define LOONGSON_DMA0_CONF 0x0 +#define LOONGSON_DMA1_CONF 0x1 +#define LOONGSON_DMA2_CONF 0x2 +#define LOONGSON_DMA3_CONF 0x3 +#define LOONGSON_DMA4_CONF 0x4 + +/* periods_max = PAGE_SIZE / sizeof(struct ls_dma_chan_reg) */ +static const struct snd_pcm_hardware loongson_pcm_hardware = { + .info = SNDRV_PCM_INFO_MMAP | + SNDRV_PCM_INFO_INTERLEAVED | + SNDRV_PCM_INFO_MMAP_VALID | + SNDRV_PCM_INFO_RESUME | + SNDRV_PCM_INFO_PAUSE, + .formats = SNDRV_PCM_FMTBIT_S16_LE | + SNDRV_PCM_FMTBIT_S20_3LE | + SNDRV_PCM_FMTBIT_S24_LE, + .period_bytes_min = 128, + .period_bytes_max = 128 * 1024, + .periods_min = 1, + .periods_max = 64, + .buffer_bytes_max = 1024 * 1024, +}; + +static const struct snd_dmaengine_pcm_config loongson_dmaengine_pcm_config = { + .pcm_hardware = &loongson_pcm_hardware, + .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config, + .prealloc_buffer_size = 128 * 1024, +}; + +static int loongson_pcm_open(struct snd_soc_component *component, + struct snd_pcm_substream *substream) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + + if (substream->pcm->device & 1) { + runtime->hw.info &= ~SNDRV_PCM_INFO_INTERLEAVED; + runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED; + } + + if (substream->pcm->device & 2) + runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP | + SNDRV_PCM_INFO_MMAP_VALID); + /* + * For mysterious reasons (and despite what the manual says) + * playback samples are lost if the DMA count is not a multiple + * of the DMA burst size. Let's add a rule to enforce that. + */ + snd_pcm_hw_constraint_step(runtime, 0, + SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 128); + snd_pcm_hw_constraint_step(runtime, 0, + SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 128); + snd_pcm_hw_constraint_integer(substream->runtime, + SNDRV_PCM_HW_PARAM_PERIODS); + + return 0; +} + +static const struct snd_soc_component_driver loongson_i2s_component_driver = { + .name = LS_I2S_DRVNAME, + .open = loongson_pcm_open, +}; + +static const struct regmap_config loongson_i2s_regmap_config = { + .reg_bits = 32, + .reg_stride = 4, + .val_bits = 32, + .max_register = 0x14, + .cache_type = REGCACHE_FLAT, +}; + +static int loongson_i2s_apbdma_config(struct platform_device *pdev) +{ + int val; + void __iomem *regs; + + regs = devm_platform_ioremap_resource(pdev, 1); + if (IS_ERR(regs)) + return PTR_ERR(regs); + + val = readl(regs); + val |= LOONGSON_DMA2_CONF << LOONGSON_I2S_TX_DMA_OFFSET; + val |= LOONGSON_DMA3_CONF << LOONGSON_I2S_RX_DMA_OFFSET; + writel(val, regs); + + return 0; +} + +static int loongson_i2s_plat_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct loongson_i2s *i2s; + struct resource *res; + struct clk *i2s_clk; + int ret; + + i2s = devm_kzalloc(dev, sizeof(*i2s), GFP_KERNEL); + if (!i2s) + return -ENOMEM; + + ret = loongson_i2s_apbdma_config(pdev); + if (ret) + return ret; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + i2s->reg_base = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(i2s->reg_base)) + return dev_err_probe(dev, PTR_ERR(i2s->reg_base), + "devm_ioremap_resource failed\n"); + + i2s->regmap = devm_regmap_init_mmio(dev, i2s->reg_base, + &loongson_i2s_regmap_config); + if (IS_ERR(i2s->regmap)) + return dev_err_probe(dev, PTR_ERR(i2s->regmap), + "devm_regmap_init_mmio failed\n"); + + i2s->playback_dma_data.addr = res->start + LS_I2S_TX_DATA; + i2s->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; + i2s->playback_dma_data.maxburst = 4; + + i2s->capture_dma_data.addr = res->start + LS_I2S_RX_DATA; + i2s->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; + i2s->capture_dma_data.maxburst = 4; + + i2s_clk = devm_clk_get_enabled(dev, NULL); + if (IS_ERR(i2s_clk)) + return dev_err_probe(dev, PTR_ERR(i2s_clk), "clock property invalid\n"); + i2s->clk_rate = clk_get_rate(i2s_clk); + + dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); + dev_set_name(dev, LS_I2S_DRVNAME); + dev_set_drvdata(dev, i2s); + + ret = devm_snd_soc_register_component(dev, &loongson_i2s_component_driver, + &loongson_i2s_dai, 1); + if (ret) + return dev_err_probe(dev, ret, "failed to register DAI\n"); + + return devm_snd_dmaengine_pcm_register(dev, &loongson_dmaengine_pcm_config, + SND_DMAENGINE_PCM_FLAG_COMPAT); +} + +static const struct of_device_id loongson_i2s_ids[] = { + { .compatible = "loongson,ls2k1000-i2s" }, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(of, loongson_i2s_ids); + +static struct platform_driver loongson_i2s_driver = { + .probe = loongson_i2s_plat_probe, + .driver = { + .name = "loongson-i2s-plat", + .pm = pm_sleep_ptr(&loongson_i2s_pm), + .of_match_table = loongson_i2s_ids, + }, +}; +module_platform_driver(loongson_i2s_driver); + +MODULE_DESCRIPTION("Loongson I2S Master Mode ASoC Driver"); +MODULE_AUTHOR("Loongson Technology Corporation Limited"); +MODULE_LICENSE("GPL");
The Loongson I2S controller exists not only in PCI form (LS7A bridge chip), but also in platform device form (Loongson-2K1000 SoC). This patch adds support for platform device I2S controller. Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn> --- sound/soc/loongson/Kconfig | 31 +++-- sound/soc/loongson/Makefile | 3 + sound/soc/loongson/loongson_i2s_plat.c | 186 +++++++++++++++++++++++++ 3 files changed, 210 insertions(+), 10 deletions(-) create mode 100644 sound/soc/loongson/loongson_i2s_plat.c