[alsa-devel] [PATCH 00/14] clk/mfd/ASoC/ARM: OMAP4/5: McPDM/twl6040 pdmclk support
Hi,
this is something I wanted to do for a long time...
First of all: sorry for the cross domain series. I did tested alone all the domain patches and they are not causing any regression. When they come together we will have ability to control the pdmclk needed by McPDM.
CLK patches: The driver was w/o DT support and needed some cleanup so we can use the driver. I have also renamed it to twl6040-pdmclk from twl6040-clk to be precise.
MFD patches: The regmap_sync() was not working since the twl6040 does not support bulk access and now we are going to create the needed child for the pdmclk.
ARM patches: Updatding the board DTS files and add the needed lines for the pdmclk.
ASoC patches: The machine driver needs to select the twl6040-clk driver as it will be used by the omap-mcpdm. I needed to do some cleanup and add also suspend/resume support before adding the code for pdmclk handling since I don't want to keep the twl6040 powered on when the board is suspended. At the moment it is not possible to do true dynamic twl6040 power up/down due to pop noises, but I will be looking at that later. The driver in the future will fail if it is not able to get the pdmclk to avoid kernel crash (McPDM registers are not accessible when pdmclk is not available).
I have tested the patches by domain and also in all (I hope) permutation they could be. I have not experienced any regression.
Regards, Peter --- Peter Ujfalusi (14): clk: twl6040: Correct clk_ops clk: twl6040: Register the clock as of_clk_provider clk: twl6040: Rename the driver and use consistent names in the code mfd: twl6040: The chip does not support bulk access mfd: twl6040: Register child device for twl6040-pdmclk ARM: dts: omap5-board-common: Add pdmclk binding for audio ARM: dts: omap4-panda-common: Add pdmclk binding for audio ARM: dts: omap4-sdp: Add pdmclk binding for audio ARM: dts: omap4-var-som-om44: Add pdmclk binding for audio ARM: dts: omap4-duovero: Add pdmclk binding for audio ASoC: omap: Kconfig: SND_OMAP_SOC_OMAP_ABE_TWL6040 to select CLK_TWL6040 ASoC: omap-mcpdm: Move the WD enable write inside omap_mcpdm_open_streams() ASoC: omap-mcpdm: Support for suspend resume ASoC: omap-mcpdm: Add support for pdmclk clock handling
Documentation/devicetree/bindings/mfd/twl6040.txt | 1 + .../devicetree/bindings/sound/omap-mcpdm.txt | 10 +++ arch/arm/boot/dts/omap4-duovero.dtsi | 5 ++ arch/arm/boot/dts/omap4-panda-common.dtsi | 5 ++ arch/arm/boot/dts/omap4-sdp.dts | 5 ++ arch/arm/boot/dts/omap4-var-som-om44.dtsi | 5 ++ arch/arm/boot/dts/omap5-board-common.dtsi | 5 ++ drivers/clk/clk-twl6040.c | 80 +++++++++++++--------- drivers/mfd/twl6040.c | 6 ++ include/linux/mfd/twl6040.h | 2 +- sound/soc/omap/Kconfig | 1 + sound/soc/omap/omap-mcpdm.c | 74 ++++++++++++++++++-- 12 files changed, 160 insertions(+), 39 deletions(-)
Since the drover only supports prepare callbacks, the use of is_enabled is not correct, it should be handling is_prepared.
Signed-off-by: Peter Ujfalusi peter.ujfalusi@ti.com --- drivers/clk/clk-twl6040.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/clk/clk-twl6040.c b/drivers/clk/clk-twl6040.c index 697c66757400..e167e0bbaff5 100644 --- a/drivers/clk/clk-twl6040.c +++ b/drivers/clk/clk-twl6040.c @@ -34,7 +34,7 @@ struct twl6040_clk { int enabled; };
-static int twl6040_bitclk_is_enabled(struct clk_hw *hw) +static int twl6040_bitclk_is_prepared(struct clk_hw *hw) { struct twl6040_clk *twl6040_clk = container_of(hw, struct twl6040_clk, mcpdm_fclk); @@ -66,7 +66,7 @@ static void twl6040_bitclk_unprepare(struct clk_hw *hw) }
static const struct clk_ops twl6040_mcpdm_ops = { - .is_enabled = twl6040_bitclk_is_enabled, + .is_prepared = twl6040_bitclk_is_prepared, .prepare = twl6040_bitclk_prepare, .unprepare = twl6040_bitclk_unprepare, };
In order ot be able to use the pdmclk clock via DT it need to be registered as of_clk_provide. Since the twl6040 clock driver does not have it's own DT node, use the parent's node for registering.
Signed-off-by: Peter Ujfalusi peter.ujfalusi@ti.com --- drivers/clk/clk-twl6040.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/clk/clk-twl6040.c b/drivers/clk/clk-twl6040.c index e167e0bbaff5..6a2dbe6a1627 100644 --- a/drivers/clk/clk-twl6040.c +++ b/drivers/clk/clk-twl6040.c @@ -95,7 +95,8 @@ static int twl6040_clk_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, clkdata);
- return 0; + return of_clk_add_provider(pdev->dev.parent->of_node, + of_clk_src_simple_get, clkdata->clk); }
static struct platform_driver twl6040_clk_driver = {
The driver is to provide the functional clock to OMAP4/5 McPDM. The clock is named as pdmclk in the documentations so change the function names, structure names and variables to align with this. At the same time rename the driver from "twl6040-clk" to "twl6040-pdmclk". This can be done w/o regression since the clock driver is not in use at the moment, the MFD core driver is not even registering the device for it.
Signed-off-by: Peter Ujfalusi peter.ujfalusi@ti.com --- drivers/clk/clk-twl6040.c | 77 +++++++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 32 deletions(-)
diff --git a/drivers/clk/clk-twl6040.c b/drivers/clk/clk-twl6040.c index 6a2dbe6a1627..c98b1ec76f54 100644 --- a/drivers/clk/clk-twl6040.c +++ b/drivers/clk/clk-twl6040.c @@ -26,60 +26,73 @@ #include <linux/mfd/twl6040.h> #include <linux/clk-provider.h>
-struct twl6040_clk { +struct twl6040_pdmclk { struct twl6040 *twl6040; struct device *dev; - struct clk_hw mcpdm_fclk; + struct clk_hw pdmclk_hw; struct clk *clk; int enabled; };
-static int twl6040_bitclk_is_prepared(struct clk_hw *hw) +static int twl6040_pdmclk_is_prepared(struct clk_hw *hw) { - struct twl6040_clk *twl6040_clk = container_of(hw, struct twl6040_clk, - mcpdm_fclk); - return twl6040_clk->enabled; + struct twl6040_pdmclk *pdmclk = container_of(hw, struct twl6040_pdmclk, + pdmclk_hw); + + return pdmclk->enabled; }
-static int twl6040_bitclk_prepare(struct clk_hw *hw) +static int twl6040_pdmclk_prepare(struct clk_hw *hw) { - struct twl6040_clk *twl6040_clk = container_of(hw, struct twl6040_clk, - mcpdm_fclk); + struct twl6040_pdmclk *pdmclk = container_of(hw, struct twl6040_pdmclk, + pdmclk_hw); int ret;
- ret = twl6040_power(twl6040_clk->twl6040, 1); + ret = twl6040_power(pdmclk->twl6040, 1); if (!ret) - twl6040_clk->enabled = 1; + pdmclk->enabled = 1;
return ret; }
-static void twl6040_bitclk_unprepare(struct clk_hw *hw) +static void twl6040_pdmclk_unprepare(struct clk_hw *hw) { - struct twl6040_clk *twl6040_clk = container_of(hw, struct twl6040_clk, - mcpdm_fclk); + struct twl6040_pdmclk *pdmclk = container_of(hw, struct twl6040_pdmclk, + pdmclk_hw); int ret;
- ret = twl6040_power(twl6040_clk->twl6040, 0); + ret = twl6040_power(pdmclk->twl6040, 0); if (!ret) - twl6040_clk->enabled = 0; + pdmclk->enabled = 0; + +} + +static unsigned long twl6040_pdmclk_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct twl6040_pdmclk *pdmclk = container_of(hw, struct twl6040_pdmclk, + pdmclk_hw); + + return twl6040_get_sysclk(pdmclk->twl6040); }
-static const struct clk_ops twl6040_mcpdm_ops = { - .is_prepared = twl6040_bitclk_is_prepared, - .prepare = twl6040_bitclk_prepare, - .unprepare = twl6040_bitclk_unprepare, +static const struct clk_ops twl6040_pdmclk_ops = { + .is_prepared = twl6040_pdmclk_is_prepared, + .prepare = twl6040_pdmclk_prepare, + .unprepare = twl6040_pdmclk_unprepare, + .recalc_rate = twl6040_pdmclk_recalc_rate, };
-static struct clk_init_data wm831x_clkout_init = { - .name = "mcpdm_fclk", - .ops = &twl6040_mcpdm_ops, +static struct clk_init_data twl6040_pdmclk_init = { + .name = "pdmclk", + .ops = &twl6040_pdmclk_ops, + .flags = CLK_GET_RATE_NOCACHE, };
-static int twl6040_clk_probe(struct platform_device *pdev) +static int twl6040_pdmclk_probe(struct platform_device *pdev) { struct twl6040 *twl6040 = dev_get_drvdata(pdev->dev.parent); - struct twl6040_clk *clkdata; + struct twl6040_pdmclk *clkdata;
clkdata = devm_kzalloc(&pdev->dev, sizeof(*clkdata), GFP_KERNEL); if (!clkdata) @@ -88,8 +101,8 @@ static int twl6040_clk_probe(struct platform_device *pdev) clkdata->dev = &pdev->dev; clkdata->twl6040 = twl6040;
- clkdata->mcpdm_fclk.init = &wm831x_clkout_init; - clkdata->clk = devm_clk_register(&pdev->dev, &clkdata->mcpdm_fclk); + clkdata->pdmclk_hw.init = &twl6040_pdmclk_init; + clkdata->clk = devm_clk_register(&pdev->dev, &clkdata->pdmclk_hw); if (IS_ERR(clkdata->clk)) return PTR_ERR(clkdata->clk);
@@ -99,16 +112,16 @@ static int twl6040_clk_probe(struct platform_device *pdev) of_clk_src_simple_get, clkdata->clk); }
-static struct platform_driver twl6040_clk_driver = { +static struct platform_driver twl6040_pdmclk_driver = { .driver = { - .name = "twl6040-clk", + .name = "twl6040-pdmclk", }, - .probe = twl6040_clk_probe, + .probe = twl6040_pdmclk_probe, };
-module_platform_driver(twl6040_clk_driver); +module_platform_driver(twl6040_pdmclk_driver);
MODULE_DESCRIPTION("TWL6040 clock driver for McPDM functional clock"); MODULE_AUTHOR("Peter Ujfalusi peter.ujfalusi@ti.com"); -MODULE_ALIAS("platform:twl6040-clk"); +MODULE_ALIAS("platform:twl6040-pdmclk"); MODULE_LICENSE("GPL");
Bulk access is not working with twl6040, we need to use single register access. Bulk access would happen when we try to sync the regcache after power on.
Signed-off-by: Peter Ujfalusi peter.ujfalusi@ti.com --- drivers/mfd/twl6040.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/drivers/mfd/twl6040.c b/drivers/mfd/twl6040.c index f3dcf3a85e84..2596546553aa 100644 --- a/drivers/mfd/twl6040.c +++ b/drivers/mfd/twl6040.c @@ -608,6 +608,7 @@ static const struct regmap_config twl6040_regmap_config = { .writeable_reg = twl6040_writeable_reg,
.cache_type = REGCACHE_RBTREE, + .use_single_rw = true, };
static const struct regmap_irq twl6040_irqs[] = {
The McPDM in OMAP4/5 is using the pdmclk from twl6040 as functional clock. The twl6040-pdmclk driver provides a clock which can be used to make sure that the pdmclk is active when the McPDM is in use.
Signed-off-by: Peter Ujfalusi peter.ujfalusi@ti.com --- Documentation/devicetree/bindings/mfd/twl6040.txt | 1 + drivers/mfd/twl6040.c | 5 +++++ include/linux/mfd/twl6040.h | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/Documentation/devicetree/bindings/mfd/twl6040.txt b/Documentation/devicetree/bindings/mfd/twl6040.txt index e6afdfa3543d..9a98ee7c323d 100644 --- a/Documentation/devicetree/bindings/mfd/twl6040.txt +++ b/Documentation/devicetree/bindings/mfd/twl6040.txt @@ -12,6 +12,7 @@ Required properties: - interrupt-parent: The parent interrupt controller - gpio-controller: - #gpio-cells = <1>: twl6040 provides GPO lines. +- #clock-cells = <0>; twl6040 is a provider of pdmclk which is used by McPDM - twl6040,audpwron-gpio: Power on GPIO line for the twl6040
- vio-supply: Regulator for the twl6040 VIO supply diff --git a/drivers/mfd/twl6040.c b/drivers/mfd/twl6040.c index 2596546553aa..873628a1bd79 100644 --- a/drivers/mfd/twl6040.c +++ b/drivers/mfd/twl6040.c @@ -782,6 +782,11 @@ static int twl6040_probe(struct i2c_client *client, cell->name = "twl6040-gpo"; children++;
+ /* PDM clock support */ + cell = &twl6040->cells[children]; + cell->name = "twl6040-pdmclk"; + children++; + /* The chip is powered down so mark regmap to cache only and dirty */ regcache_cache_only(twl6040->regmap, true); regcache_mark_dirty(twl6040->regmap); diff --git a/include/linux/mfd/twl6040.h b/include/linux/mfd/twl6040.h index 8015db974157..ef0bb07c3f3d 100644 --- a/include/linux/mfd/twl6040.h +++ b/include/linux/mfd/twl6040.h @@ -168,7 +168,7 @@ #define TWL6040_VIBROCDET 0x20 #define TWL6040_TSHUTDET 0x40
-#define TWL6040_CELLS 3 +#define TWL6040_CELLS 4
#define TWL6040_REV_ES1_0 0x00 #define TWL6040_REV_ES1_1 0x01 /* Rev ES1.1 and ES1.2 */
On Wed, May 18, 2016 at 04:46:27PM +0300, Peter Ujfalusi wrote:
The McPDM in OMAP4/5 is using the pdmclk from twl6040 as functional clock. The twl6040-pdmclk driver provides a clock which can be used to make sure that the pdmclk is active when the McPDM is in use.
Signed-off-by: Peter Ujfalusi peter.ujfalusi@ti.com
Documentation/devicetree/bindings/mfd/twl6040.txt | 1 + drivers/mfd/twl6040.c | 5 +++++ include/linux/mfd/twl6040.h | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-)
Acked-by: Rob Herring robh@kernel.org
The twl6040 codec is generating the pdmclk, which is used by the McPDM as functional clock.
Signed-off-by: Peter Ujfalusi peter.ujfalusi@ti.com --- arch/arm/boot/dts/omap5-board-common.dtsi | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/arch/arm/boot/dts/omap5-board-common.dtsi b/arch/arm/boot/dts/omap5-board-common.dtsi index 19efaa079797..63d0352d068d 100644 --- a/arch/arm/boot/dts/omap5-board-common.dtsi +++ b/arch/arm/boot/dts/omap5-board-common.dtsi @@ -637,6 +637,7 @@
twl6040: twl@4b { compatible = "ti,twl6040"; + #clock-cells = <0>; reg = <0x4b>;
pinctrl-names = "default"; @@ -658,6 +659,10 @@ &mcpdm { pinctrl-names = "default"; pinctrl-0 = <&mcpdm_pins>; + + clocks = <&twl6040>; + clock-names = "pdmclk"; + status = "okay"; };
The twl6040 codec is generating the pdmclk, which is used by the McPDM as functional clock.
Signed-off-by: Peter Ujfalusi peter.ujfalusi@ti.com --- arch/arm/boot/dts/omap4-panda-common.dtsi | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/arch/arm/boot/dts/omap4-panda-common.dtsi b/arch/arm/boot/dts/omap4-panda-common.dtsi index df2e356ec089..e1d606f64cb7 100644 --- a/arch/arm/boot/dts/omap4-panda-common.dtsi +++ b/arch/arm/boot/dts/omap4-panda-common.dtsi @@ -376,6 +376,7 @@
twl6040: twl@4b { compatible = "ti,twl6040"; + #clock-cells = <0>; reg = <0x4b>;
pinctrl-names = "default"; @@ -479,6 +480,10 @@ &mcpdm { pinctrl-names = "default"; pinctrl-0 = <&mcpdm_pins>; + + clocks = <&twl6040>; + clock-names = "pdmclk"; + status = "okay"; };
The twl6040 codec is generating the pdmclk, which is used by the McPDM as functional clock.
Signed-off-by: Peter Ujfalusi peter.ujfalusi@ti.com --- arch/arm/boot/dts/omap4-sdp.dts | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/arch/arm/boot/dts/omap4-sdp.dts b/arch/arm/boot/dts/omap4-sdp.dts index aae513265dc2..7e6cd2d8ed5d 100644 --- a/arch/arm/boot/dts/omap4-sdp.dts +++ b/arch/arm/boot/dts/omap4-sdp.dts @@ -367,6 +367,7 @@
twl6040: twl@4b { compatible = "ti,twl6040"; + #clock-cells = <0>; reg = <0x4b>;
pinctrl-names = "default"; @@ -620,6 +621,10 @@ &mcpdm { pinctrl-names = "default"; pinctrl-0 = <&mcpdm_pins>; + + clocks = <&twl6040>; + clock-names = "pdmclk"; + status = "okay"; };
The twl6040 codec is generating the pdmclk, which is used by the McPDM as functional clock.
Signed-off-by: Peter Ujfalusi peter.ujfalusi@ti.com --- arch/arm/boot/dts/omap4-var-som-om44.dtsi | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/arch/arm/boot/dts/omap4-var-som-om44.dtsi b/arch/arm/boot/dts/omap4-var-som-om44.dtsi index a17997f4e9aa..873cfc87260c 100644 --- a/arch/arm/boot/dts/omap4-var-som-om44.dtsi +++ b/arch/arm/boot/dts/omap4-var-som-om44.dtsi @@ -189,6 +189,7 @@
twl6040: twl@4b { compatible = "ti,twl6040"; + #clock-cells = <0>; reg = <0x4b>;
pinctrl-names = "default"; @@ -252,6 +253,10 @@ &mcpdm { pinctrl-names = "default"; pinctrl-0 = <&mcpdm_pins>; + + clocks = <&twl6040>; + clock-names = "pdmclk"; + status = "okay"; };
The twl6040 codec is generating the pdmclk, which is used by the McPDM as functional clock.
Signed-off-by: Peter Ujfalusi peter.ujfalusi@ti.com --- arch/arm/boot/dts/omap4-duovero.dtsi | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/arch/arm/boot/dts/omap4-duovero.dtsi b/arch/arm/boot/dts/omap4-duovero.dtsi index f2a94fa62552..a90b582e4c3f 100644 --- a/arch/arm/boot/dts/omap4-duovero.dtsi +++ b/arch/arm/boot/dts/omap4-duovero.dtsi @@ -177,6 +177,7 @@
twl6040: twl@4b { compatible = "ti,twl6040"; + #clock-cells = <0>; reg = <0x4b>; interrupts = <GIC_SPI 119 IRQ_TYPE_LEVEL_HIGH>; /* IRQ_SYS_2N cascaded to gic */ ti,audpwron-gpio = <&gpio6 0 GPIO_ACTIVE_HIGH>; /* gpio_160 */ @@ -207,6 +208,10 @@ &mcpdm { pinctrl-names = "default"; pinctrl-0 = <&mcpdm_pins>; + + clocks = <&twl6040>; + clock-names = "pdmclk"; + status = "okay"; };
The pdmclk is needed for McPDM. It is generated by twl6040.
Signed-off-by: Peter Ujfalusi peter.ujfalusi@ti.com --- sound/soc/omap/Kconfig | 1 + 1 file changed, 1 insertion(+)
diff --git a/sound/soc/omap/Kconfig b/sound/soc/omap/Kconfig index 5520273724ae..347705c04db1 100644 --- a/sound/soc/omap/Kconfig +++ b/sound/soc/omap/Kconfig @@ -119,6 +119,7 @@ config SND_OMAP_SOC_OMAP_ABE_TWL6040 select SND_SOC_TWL6040 select SND_SOC_DMIC select COMMON_CLK_PALMAS if (SOC_OMAP5 && MFD_PALMAS) + select CLK_TWL6040 help Say Y if you want to add support for SoC audio on OMAP boards using ABE and twl6040 codec. This driver currently supports:
The DS4_WD_EN bit is only touched before calling omap_mcpdm_open_streams(). Move it inside of that function for simplicity.
Signed-off-by: Peter Ujfalusi peter.ujfalusi@ti.com --- sound/soc/omap/omap-mcpdm.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/sound/soc/omap/omap-mcpdm.c b/sound/soc/omap/omap-mcpdm.c index b837265ac3e9..11bd07cdce22 100644 --- a/sound/soc/omap/omap-mcpdm.c +++ b/sound/soc/omap/omap-mcpdm.c @@ -173,6 +173,10 @@ static inline int omap_mcpdm_active(struct omap_mcpdm *mcpdm) */ static void omap_mcpdm_open_streams(struct omap_mcpdm *mcpdm) { + u32 ctrl = omap_mcpdm_read(mcpdm, MCPDM_REG_CTRL); + + omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL, ctrl | MCPDM_WD_EN); + omap_mcpdm_write(mcpdm, MCPDM_REG_IRQENABLE_SET, MCPDM_DN_IRQ_EMPTY | MCPDM_DN_IRQ_FULL | MCPDM_UP_IRQ_EMPTY | MCPDM_UP_IRQ_FULL); @@ -258,12 +262,9 @@ static int omap_mcpdm_dai_startup(struct snd_pcm_substream *substream,
mutex_lock(&mcpdm->mutex);
- if (!dai->active) { - u32 ctrl = omap_mcpdm_read(mcpdm, MCPDM_REG_CTRL); - - omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL, ctrl | MCPDM_WD_EN); + if (!dai->active) omap_mcpdm_open_streams(mcpdm); - } + mutex_unlock(&mcpdm->mutex);
return 0;
Implement ASoC's suspend and resume callbacks. Since McPDM does not use pcm_trigger for start and stop of the stream due to strict sequencing needs with the twl6040, the callbacks will stop and restart the McPDM in case the board suspended during audio activity.
Signed-off-by: Peter Ujfalusi peter.ujfalusi@ti.com --- sound/soc/omap/omap-mcpdm.c | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
diff --git a/sound/soc/omap/omap-mcpdm.c b/sound/soc/omap/omap-mcpdm.c index 11bd07cdce22..74d6e6fdcfd0 100644 --- a/sound/soc/omap/omap-mcpdm.c +++ b/sound/soc/omap/omap-mcpdm.c @@ -66,6 +66,9 @@ struct omap_mcpdm { /* McPDM needs to be restarted due to runtime reconfiguration */ bool restart;
+ /* pm state for suspend/resume handling */ + int pm_active_count; + struct snd_dmaengine_dai_dma_data dma_data[2]; };
@@ -422,12 +425,55 @@ static int omap_mcpdm_remove(struct snd_soc_dai *dai) return 0; }
+#ifdef CONFIG_PM_SLEEP +static int omap_mcpdm_suspend(struct snd_soc_dai *dai) +{ + struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai); + + if (dai->active) { + omap_mcpdm_stop(mcpdm); + omap_mcpdm_close_streams(mcpdm); + } + + mcpdm->pm_active_count = 0; + while (pm_runtime_active(mcpdm->dev)) { + pm_runtime_put_sync(mcpdm->dev); + mcpdm->pm_active_count++; + } + + return 0; +} + +static int omap_mcpdm_resume(struct snd_soc_dai *dai) +{ + struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai); + + if (mcpdm->pm_active_count) { + while (mcpdm->pm_active_count--) + pm_runtime_get_sync(mcpdm->dev); + + if (dai->active) { + omap_mcpdm_open_streams(mcpdm); + omap_mcpdm_start(mcpdm); + } + } + + + return 0; +} +#else +#define omap_mcpdm_suspend NULL +#define omap_mcpdm_resume NULL +#endif + #define OMAP_MCPDM_RATES (SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000) #define OMAP_MCPDM_FORMATS SNDRV_PCM_FMTBIT_S32_LE
static struct snd_soc_dai_driver omap_mcpdm_dai = { .probe = omap_mcpdm_probe, .remove = omap_mcpdm_remove, + .suspend = omap_mcpdm_suspend, + .resume = omap_mcpdm_resume, .probe_order = SND_SOC_COMP_ORDER_LATE, .remove_order = SND_SOC_COMP_ORDER_EARLY, .playback = {
McPDM module receives it's functional clock from external source. This clock is the pdmclk provided by the twl6040 audio IC. If the clock is not available all register accesses to McPDM fails and the module is not operational.
Signed-off-by: Peter Ujfalusi peter.ujfalusi@ti.com --- Documentation/devicetree/bindings/sound/omap-mcpdm.txt | 10 ++++++++++ sound/soc/omap/omap-mcpdm.c | 17 +++++++++++++++++ 2 files changed, 27 insertions(+)
diff --git a/Documentation/devicetree/bindings/sound/omap-mcpdm.txt b/Documentation/devicetree/bindings/sound/omap-mcpdm.txt index 0741dff048dd..6f6c2f8e908d 100644 --- a/Documentation/devicetree/bindings/sound/omap-mcpdm.txt +++ b/Documentation/devicetree/bindings/sound/omap-mcpdm.txt @@ -8,6 +8,8 @@ Required properties: - interrupts: Interrupt number for McPDM - interrupt-parent: The parent interrupt controller - ti,hwmods: Name of the hwmod associated to the McPDM +- clocks: phandle for the pdmclk provider, likely <&twl6040> +- clock-names: Must be "pdmclk"
Example:
@@ -19,3 +21,11 @@ mcpdm: mcpdm@40132000 { interrupt-parent = <&gic>; ti,hwmods = "mcpdm"; }; + +In board DTS file the pdmclk needs to be added: + +&mcpdm { + clocks = <&twl6040>; + clock-names = "pdmclk"; + status = "okay"; +}; diff --git a/sound/soc/omap/omap-mcpdm.c b/sound/soc/omap/omap-mcpdm.c index 74d6e6fdcfd0..e7cdc51fd806 100644 --- a/sound/soc/omap/omap-mcpdm.c +++ b/sound/soc/omap/omap-mcpdm.c @@ -31,6 +31,7 @@ #include <linux/err.h> #include <linux/io.h> #include <linux/irq.h> +#include <linux/clk.h> #include <linux/slab.h> #include <linux/pm_runtime.h> #include <linux/of_device.h> @@ -54,6 +55,7 @@ struct omap_mcpdm { unsigned long phys_base; void __iomem *io_base; int irq; + struct clk *pdmclk;
struct mutex mutex;
@@ -388,6 +390,7 @@ static int omap_mcpdm_probe(struct snd_soc_dai *dai) struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai); int ret;
+ clk_prepare_enable(mcpdm->pdmclk); pm_runtime_enable(mcpdm->dev);
/* Disable lines while request is ongoing */ @@ -422,6 +425,7 @@ static int omap_mcpdm_remove(struct snd_soc_dai *dai)
pm_runtime_disable(mcpdm->dev);
+ clk_disable_unprepare(mcpdm->pdmclk); return 0; }
@@ -441,6 +445,8 @@ static int omap_mcpdm_suspend(struct snd_soc_dai *dai) mcpdm->pm_active_count++; }
+ clk_disable_unprepare(mcpdm->pdmclk); + return 0; }
@@ -448,6 +454,8 @@ static int omap_mcpdm_resume(struct snd_soc_dai *dai) { struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai);
+ clk_prepare_enable(mcpdm->pdmclk); + if (mcpdm->pm_active_count) { while (mcpdm->pm_active_count--) pm_runtime_get_sync(mcpdm->dev); @@ -541,6 +549,15 @@ static int asoc_mcpdm_probe(struct platform_device *pdev)
mcpdm->dev = &pdev->dev;
+ mcpdm->pdmclk = devm_clk_get(&pdev->dev, "pdmclk"); + if (IS_ERR(mcpdm->pdmclk)) { + if (PTR_ERR(mcpdm->pdmclk) == -EPROBE_DEFER) + return -EPROBE_DEFER; + dev_warn(&pdev->dev, "Error getting pdmclk (%ld)!\n", + PTR_ERR(mcpdm->pdmclk)); + mcpdm->pdmclk = NULL; + } + ret = devm_snd_soc_register_component(&pdev->dev, &omap_mcpdm_component, &omap_mcpdm_dai, 1);
On Wed, May 18, 2016 at 04:46:36PM +0300, Peter Ujfalusi wrote:
McPDM module receives it's functional clock from external source. This clock is the pdmclk provided by the twl6040 audio IC. If the clock is not available all register accesses to McPDM fails and the module is not operational.
Signed-off-by: Peter Ujfalusi peter.ujfalusi@ti.com
Documentation/devicetree/bindings/sound/omap-mcpdm.txt | 10 ++++++++++ sound/soc/omap/omap-mcpdm.c | 17 +++++++++++++++++ 2 files changed, 27 insertions(+)
Acked-by: Rob Herring robh@kernel.org
participants (3)
-
Mark Brown
-
Peter Ujfalusi
-
Rob Herring