sound: Add hikey960 i2s audio driver
PATCH 1/3 sound: Add hikey960 i2s audio driver
From: Youlin Wang <[email protected]>
Add i2s driver for hisi3660 soc found on the hikey960 board. Add conpile line in make file.
Technical support by Guangke Ji.
--- sound/soc/hisilicon/Kconfig | 8 +- sound/soc/hisilicon/Makefile | 1 + sound/soc/hisilicon/hi3660-i2s.c | 448 +++++++++++++++++++++++++++++++++++++++ sound/soc/hisilicon/hi3660-i2s.h | 99 +++++++++ 4 files changed, 555 insertions(+), 1 deletion(-) create mode 100644 sound/soc/hisilicon/hi3660-i2s.c create mode 100644 sound/soc/hisilicon/hi3660-i2s.h
sound/soc/hisilicon/Kconfig +7 -1
@@ -1,5 +1,11 @@ config SND_I2S_HI6210_I2S - tristate "Hisilicon I2S controller" + tristate "Hisilicon Hi6210 I2S controller" + select SND_SOC_GENERIC_DMAENGINE_PCM + help + Hisilicon I2S + +config SND_I2S_HI3660_I2S + tristate "Hisilicon 960 I2S controller" select SND_SOC_GENERIC_DMAENGINE_PCM help Hisilicon I2S
sound/soc/hisilicon/Makefile +1 -0
@@ -1 +1,2 @@ obj-$(CONFIG_SND_I2S_HI6210_I2S) += hi6210-i2s.o +obj-$(CONFIG_SND_I2S_HI3660_I2S) += hi3660-i2s.o
sound/soc/hisilicon/hi3660-i2s.c new file +448 -0
448 lines not on this page · raw message
sound/soc/hisilicon/hi3660-i2s.h new file +99 -0
99 lines not on this page · raw message
Signature · 1 line
2.8.0
Mark Brown
maintainerQuoted 1 line · Pengcheng Li
From: Youlin Wang <[email protected]>
Please use subject lines matching the style for the subsystem. This makes it easier for people to identify relevant patches.
Please don't ignore review comments, people are generally making them for a reason and are likely to have the same concerns if issues remain unaddressed. Having to repeat the same comments can get repetitive and make people question the value of time spent reviewing. If you disagree with the review comments that's fine but you need to reply and discuss your concerns so that the reviewer can understand your decisions.
sound/soc/hisilicon/Kconfig line 6
Quoted 7 lines
config
SND_I2S_HI6210_I2Ssound/soc/hisilicon/Kconfig +5
-1- tristate "Hisilicon I2S controller" + tristate "Hisilicon Hi6210 I2S controller" + select SND_SOC_GENERIC_DMAENGINE_PCM + help + Hisilicon I2S +
This should really be a separate patch as it's an update to the existing driver.
sound/soc/hisilicon/hi3660-i2s.c line 4
Quoted 7 lines
sound/soc/hisilicon/hi3660-i2s.c new file +4
-0@@ -0,0 +1,448 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* linux/sound/soc/hisilicon/hi3660-i2s.c +*
Please make the entire comment a C++ one so it looks intentional.
sound/soc/hisilicon/hi3660-i2s.c line 8
Quoted 4 lines
sound/soc/hisilicon/hi3660-i2s.c new file +4
-0+* I2S IP driver for hi3660. +* +* Copyright (c) 2001-2021, Huawei Tech. Co., Ltd. +*/
Given that it's currently 2019 I'm not sure that the years copyright is claimed for here are accurate...
sound/soc/hisilicon/hi3660-i2s.c line 61
Quoted 6 lines
sound/soc/hisilicon/hi3660-i2s.c new file +6
-0+static void update_bits (struct hi3660_i2s *i2s,u32 ofs,u32 reset,u32 set) +{ +u32 val =readl (i2s->base + ofs) & ~reset; + +writel (val | set, i2s->base + ofs); +}
It'd be better to namespace the functions in the driver to avoid collisons with anything that gets added to headers. Look at how other drivers name their functions for examples.
It's also a bit confusing to have an _update_bits() with the set/reset pattern given that we've got _update_bits() functions with the mask/values pattern at both the ASoC and regmap levels in Linux.
sound/soc/hisilicon/hi3660-i2s.c line 137
Quoted 8 lines
sound/soc/hisilicon/hi3660-i2s.c new file +8
-0+static void shutdown (struct snd_pcm_substream *substream, +struct snd_soc_dai *cpu_dai) +{ +struct hi3660_i2s *i2s =dev_get_drvdata (cpu_dai->dev); + +if (!IS_ERR_OR_NULL (i2s->asp_subsys_clk)) +clk_disable_unprepare (i2s->asp_subsys_clk); +}
Can the driver actually function usefully without this clock?
sound/soc/hisilicon/hi3660-i2s.c line 187
Quoted 5 lines
sound/soc/hisilicon/hi3660-i2s.c new file +5
-0+static int set_sysclk (struct snd_soc_dai *cpu_dai, +int clk_id,unsigned int freq,int dir) +{ +return 0 ; +}
Don't implement empty operations; if it's safe to not have an operation (like this one) then the framework will handle it being missing.
sound/soc/hisilicon/hi3660-i2s.c line 198
Quoted 10 lines
sound/soc/hisilicon/hi3660-i2s.c new file +10
-0+static int set_format (struct snd_soc_dai *cpu_dai,unsigned int fmt) +{ +struct hi3660_i2s *i2s =dev_get_drvdata (cpu_dai->dev); + + i2s->format = fmt; + i2s->master = (i2s->format &SND_SOC_DAIFMT_MASTER_MASK ) == +SND_SOC_DAIFMT_CBS_CFS ; + +return 0 ; +}
There should be some validation in this function to make sure that the format is valid.
sound/soc/hisilicon/hi3660-i2s.c line 231
Quoted 5 lines
sound/soc/hisilicon/hi3660-i2s.c new file +5
-0+case SNDRV_PCM_FORMAT_U24_LE : +case SNDRV_PCM_FORMAT_S24_LE : + i2s->bits =32 ; + dma_data->addr_width =4 ; +break ;
Does the hardware not support 32 bit samples?
sound/soc/hisilicon/hi3660-i2s.c line 374
Quoted 11 lines
sound/soc/hisilicon/hi3660-i2s.c new file +11
-0+ res =platform_get_resource (pdev,IORESOURCE_MEM ,1 ); +if (!res) { + ret = -ENODEV ; +return ret; + } + i2s->base_syscon =devm_ioremap (dev, res->start,resource_size (res)); +if (IS_ERR (i2s->base_syscon)) { +dev_err (&pdev->dev,"ioremap failed\n" ); + ret =PTR_ERR (i2s->base_syscon); +return ret; + }
If there's a system controller involved shouldn't we be using the standard system controller support in drivers/mfd/syscon.c? Other HiSilicon devices seem to use it.
sound/soc/hisilicon/hi3660-i2s.c line 382
Quoted 6 lines
sound/soc/hisilicon/hi3660-i2s.c new file +6
-0+ i2s->pctrl =devm_pinctrl_get (dev); +if (IS_ERR (i2s->pctrl)) { +dev_err (dev,"could not get pinctrl\n" ); + ret = -EIO ; +return ret; + }
This is discarding the error code returned by the API which is going to make debuggging harder and will break deferred probe - you should use PTR_ERR() to get the error and both print it and return it as the error code.
sound/soc/hisilicon/hi3660-i2s.c line 422
Quoted 8 lines
sound/soc/hisilicon/hi3660-i2s.c new file +8
-0+static int hi3660_i2s_remove (struct platform_device *pdev) +{ +struct hi3660_i2s *i2s =dev_get_drvdata (&pdev->dev); + +snd_soc_unregister_component (&pdev->dev); +dev_set_drvdata (&pdev->dev,NULL ); + +pinctrl_put (i2s->pctrl);
The driver used devm_ functions on probe so no need to explicitly undo things, the devm_ code will handle that for you.
Hello Pengcheng,
Make sure you run ./scripts/checkpatch.pl --strict yourpatchfile.patch
Quoted 6 lines · Pengcheng Li
From: Youlin Wang <[email protected]>
Add i2s driver for hisi3660 soc found on the hikey960 board. Add conpile line in make file.
Technical support by Guangke Ji.
Care to add here some documentation pointers to I2S IP on the SOC?
sound/soc/hisilicon/Kconfig line 5
Quoted 11 lines
sound/soc/hisilicon/Kconfig +4
-1@@ -1,5 +1,11 @@ config SND_I2S_HI6210_I2S - tristate "Hisilicon I2S controller" + tristate "Hisilicon Hi6210 I2S controller" + select SND_SOC_GENERIC_DMAENGINE_PCM + help + Hisilicon I2S
Can you enahance the help text? Something like "I2S controller driver for hisi3600 SoC"
<snip>
sound/soc/hisilicon/Kconfig line 6
Quoted 1 line
sound/soc/hisilicon/Kconfig +1
-0+ * Copyright (c) 2001-2021, Huawei Tech. Co., Ltd.
2021? :) IANAL but this looks strange :).
Quoted 5 lines
sound/soc/hisilicon/Kconfig +5
-0+struct hi3660_i2s { + struct device *dev; + struct reset_control *rc; + int clocks; + struct regulator *regu_asp;
sound/soc/hisilicon/Kconfig
Quoted 10 lines
sound/soc/hisilicon/Kconfig +10
-0+ struct pinctrl *pctrl; + struct pinctrl_state *pin_default; + struct pinctrl_state *pin_idle; + struct clk *asp_subsys_clk; + struct snd_soc_dai_driver dai; + void __iomem *base; + void __iomem *base_syscon; + phys_addr_t base_phys; + struct snd_dmaengine_dai_dma_data dma_data[2]; + spinlock_t lock;
What is this lock used for? Please add some docs.
Quoted 12 lines
sound/soc/hisilicon/Kconfig +12
-0+ int rate; + int format; + int bits; + int channels; + u32 master; + u32 status; +}; + +static void update_bits(struct hi3660_i2s *i2s, u32 ofs, u32 reset, u32 set) +{ + u32 val = readl(i2s->base + ofs) & ~reset; +
sound/soc/hisilicon/Kconfig
Quoted 10 lines
sound/soc/hisilicon/Kconfig +10
-0+ writel(val | set, i2s->base + ofs); +} + +static void update_bits_syscon(struct hi3660_i2s *i2s, + u32 ofs, u32 reset, u32 set) +{ + u32 val = readl(i2s->base_syscon + ofs) & ~reset; + + writel(val | set, i2s->base_syscon + ofs); +}
Look at the snd_soc_component_update_bits. You can make these two functions following the same
pattern for parameters.