linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] CLK: clk-twl6040: Initial clock driver for OMAP4+ McPDM fclk clock
@ 2012-09-14 14:30 Peter Ujfalusi
  2012-10-29 17:30 ` Mike Turquette
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Ujfalusi @ 2012-09-14 14:30 UTC (permalink / raw)
  To: linux-arm-kernel

On OMAP4+ platforms the functional clock for the McPDM IP is suplied by
the twl6040 codec (bit clock on the PDM bus).
This common clock driver for twl6040 will register the mcpdm_fclk clock to
be used by the McPDM driver to make sure that the needed clocks are
available when needed.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---

Hello Mike,

This driver is going to be used by the OMAP McPDM driver when we moved to common
clock framework.
To avoid merge conflicts I'm going to send the patch needed for the twl6040 MFD
core driver to register the platform device for the clk driver.

Some background: OMAP McPDM's functional clock is coming from external source,
which is the bitclock of the McPDM interface generated by external codec
(twl6040). This clock is needed to access McPDM registers as well and when I'm
going to implement the power states of twl6040 we need to make sure that the
clock is running from twl6040 to McPDM in order to avoid surprises.

Regards,
Peter

 drivers/clk/Kconfig       |   8 +++
 drivers/clk/Makefile      |   1 +
 drivers/clk/clk-twl6040.c | 126 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 135 insertions(+)
 create mode 100644 drivers/clk/clk-twl6040.c

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index bace9e9..3d0b784 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -53,4 +53,12 @@ config COMMON_CLK_MAX77686
 	---help---
 	  This driver supports Maxim 77686 crystal oscillator clock. 
 
+config CLK_TWL6040
+	tristate "External McPDM functional clock from twl6040"
+	depends on TWL6040_CORE
+	---help---
+	  Enable the external functional clock support on OMAP4+ platforms for
+	  McPDM. McPDM module is using the external bit clock on the McPDM bus
+	  as functional clock.
+
 endmenu
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 6327536..c55d840 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -20,3 +20,4 @@ obj-$(CONFIG_ARCH_U8500)	+= ux500/
 # Chip specific
 obj-$(CONFIG_COMMON_CLK_WM831X) += clk-wm831x.o
 obj-$(CONFIG_COMMON_CLK_MAX77686) += clk-max77686.o
+obj-$(CONFIG_CLK_TWL6040)	+= clk-twl6040.o
diff --git a/drivers/clk/clk-twl6040.c b/drivers/clk/clk-twl6040.c
new file mode 100644
index 0000000..f4a3389
--- /dev/null
+++ b/drivers/clk/clk-twl6040.c
@@ -0,0 +1,126 @@
+/*
+* TWL6040 clock module driver for OMAP4 McPDM functional clock
+*
+* Copyright (C) 2012 Texas Instruments Inc.
+* Peter Ujfalusi <peter.ujfalusi@ti.com>
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* version 2 as published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful, but
+* WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA
+*
+*/
+
+#include <linux/clk.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/platform_device.h>
+#include <linux/mfd/twl6040.h>
+#include <linux/clk-provider.h>
+
+struct twl6040_clk {
+	struct twl6040 *twl6040;
+	struct device *dev;
+	struct clk_hw mcpdm_fclk;
+	struct clk *clk;
+	int enabled;
+};
+
+static int twl6040_bitclk_is_enabled(struct clk_hw *hw)
+{
+	struct twl6040_clk *twl6040_clk = container_of(hw, struct twl6040_clk,
+						       mcpdm_fclk);
+	return twl6040_clk->enabled;
+}
+
+static int twl6040_bitclk_prepare(struct clk_hw *hw)
+{
+	struct twl6040_clk *twl6040_clk = container_of(hw, struct twl6040_clk,
+						       mcpdm_fclk);
+	int ret;
+
+	ret = twl6040_power(twl6040_clk->twl6040, 1);
+	if (!ret)
+		twl6040_clk->enabled = 1;
+
+	return ret;
+}
+
+static void twl6040_bitclk_unprepare(struct clk_hw *hw)
+{
+	struct twl6040_clk *twl6040_clk = container_of(hw, struct twl6040_clk,
+						       mcpdm_fclk);
+	int ret;
+
+	ret = twl6040_power(twl6040_clk->twl6040, 0);
+	if (!ret)
+		twl6040_clk->enabled = 0;
+}
+
+static const struct clk_ops twl6040_mcpdm_ops = {
+	.is_enabled = twl6040_bitclk_is_enabled,
+	.prepare = twl6040_bitclk_prepare,
+	.unprepare = twl6040_bitclk_unprepare,
+};
+
+static struct clk_init_data wm831x_clkout_init = {
+	.name = "mcpdm_fclk",
+	.ops = &twl6040_mcpdm_ops,
+	.flags = CLK_IS_ROOT,
+};
+
+static int __devinit twl6040_clk_probe(struct platform_device *pdev)
+{
+	struct twl6040 *twl6040 = dev_get_drvdata(pdev->dev.parent);
+	struct twl6040_clk *clkdata;
+
+	clkdata = devm_kzalloc(&pdev->dev, sizeof(*clkdata), GFP_KERNEL);
+	if (!clkdata)
+		return -ENOMEM;
+
+	clkdata->dev = &pdev->dev;
+	clkdata->twl6040 = twl6040;
+
+	clkdata->mcpdm_fclk.init = &wm831x_clkout_init;
+	clkdata->clk = clk_register(&pdev->dev, &clkdata->mcpdm_fclk);
+	if (!clkdata->clk)
+		return -EINVAL;
+
+	dev_set_drvdata(&pdev->dev, clkdata);
+
+	return 0;
+}
+
+static int __devexit twl6040_clk_remove(struct platform_device *pdev)
+{
+	struct twl6040_clk *clkdata = dev_get_drvdata(&pdev->dev);
+
+	clk_unregister(clkdata->clk);
+
+	return 0;
+}
+
+static struct platform_driver twl6040_clk_driver = {
+	.driver = {
+		.name = "twl6040-clk",
+		.owner = THIS_MODULE,
+	},
+	.probe = twl6040_clk_probe,
+	.remove = __devexit_p(twl6040_clk_remove),
+};
+
+module_platform_driver(twl6040_clk_driver);
+
+MODULE_DESCRIPTION("TWL6040 clock driver for McPDM functional clock");
+MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@ti.com>");
+MODULE_ALIAS("platform:twl6040-clk");
+MODULE_LICENSE("GPL");
-- 
1.7.12

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] CLK: clk-twl6040: Initial clock driver for OMAP4+ McPDM fclk clock
  2012-09-14 14:30 [PATCH] CLK: clk-twl6040: Initial clock driver for OMAP4+ McPDM fclk clock Peter Ujfalusi
@ 2012-10-29 17:30 ` Mike Turquette
  2012-10-30  7:39   ` Péter Ujfalusi
  0 siblings, 1 reply; 4+ messages in thread
From: Mike Turquette @ 2012-10-29 17:30 UTC (permalink / raw)
  To: linux-arm-kernel

Quoting Peter Ujfalusi (2012-09-14 07:30:27)
> On OMAP4+ platforms the functional clock for the McPDM IP is suplied by
> the twl6040 codec (bit clock on the PDM bus).
> This common clock driver for twl6040 will register the mcpdm_fclk clock to
> be used by the McPDM driver to make sure that the needed clocks are
> available when needed.
> 
> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
> ---
> 
> Hello Mike,
> 
> This driver is going to be used by the OMAP McPDM driver when we moved to common
> clock framework.
> To avoid merge conflicts I'm going to send the patch needed for the twl6040 MFD
> core driver to register the platform device for the clk driver.
> 

Peter,

The patch looks good to me.  To be clear, you wan this to go through
clk-next or the mfd tree for avoiding conflicts?

Thanks,
Mike

> Some background: OMAP McPDM's functional clock is coming from external source,
> which is the bitclock of the McPDM interface generated by external codec
> (twl6040). This clock is needed to access McPDM registers as well and when I'm
> going to implement the power states of twl6040 we need to make sure that the
> clock is running from twl6040 to McPDM in order to avoid surprises.
> 
> Regards,
> Peter
> 
>  drivers/clk/Kconfig       |   8 +++
>  drivers/clk/Makefile      |   1 +
>  drivers/clk/clk-twl6040.c | 126 ++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 135 insertions(+)
>  create mode 100644 drivers/clk/clk-twl6040.c
> 
> diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
> index bace9e9..3d0b784 100644
> --- a/drivers/clk/Kconfig
> +++ b/drivers/clk/Kconfig
> @@ -53,4 +53,12 @@ config COMMON_CLK_MAX77686
>         ---help---
>           This driver supports Maxim 77686 crystal oscillator clock. 
>  
> +config CLK_TWL6040
> +       tristate "External McPDM functional clock from twl6040"
> +       depends on TWL6040_CORE
> +       ---help---
> +         Enable the external functional clock support on OMAP4+ platforms for
> +         McPDM. McPDM module is using the external bit clock on the McPDM bus
> +         as functional clock.
> +
>  endmenu
> diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
> index 6327536..c55d840 100644
> --- a/drivers/clk/Makefile
> +++ b/drivers/clk/Makefile
> @@ -20,3 +20,4 @@ obj-$(CONFIG_ARCH_U8500)      += ux500/
>  # Chip specific
>  obj-$(CONFIG_COMMON_CLK_WM831X) += clk-wm831x.o
>  obj-$(CONFIG_COMMON_CLK_MAX77686) += clk-max77686.o
> +obj-$(CONFIG_CLK_TWL6040)      += clk-twl6040.o
> diff --git a/drivers/clk/clk-twl6040.c b/drivers/clk/clk-twl6040.c
> new file mode 100644
> index 0000000..f4a3389
> --- /dev/null
> +++ b/drivers/clk/clk-twl6040.c
> @@ -0,0 +1,126 @@
> +/*
> +* TWL6040 clock module driver for OMAP4 McPDM functional clock
> +*
> +* Copyright (C) 2012 Texas Instruments Inc.
> +* Peter Ujfalusi <peter.ujfalusi@ti.com>
> +*
> +* This program is free software; you can redistribute it and/or
> +* modify it under the terms of the GNU General Public License
> +* version 2 as published by the Free Software Foundation.
> +*
> +* This program is distributed in the hope that it will be useful, but
> +* WITHOUT ANY WARRANTY; without even the implied warranty of
> +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> +* General Public License for more details.
> +*
> +* You should have received a copy of the GNU General Public License
> +* along with this program; if not, write to the Free Software
> +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
> +* 02110-1301 USA
> +*
> +*/
> +
> +#include <linux/clk.h>
> +#include <linux/module.h>
> +#include <linux/slab.h>
> +#include <linux/platform_device.h>
> +#include <linux/mfd/twl6040.h>
> +#include <linux/clk-provider.h>
> +
> +struct twl6040_clk {
> +       struct twl6040 *twl6040;
> +       struct device *dev;
> +       struct clk_hw mcpdm_fclk;
> +       struct clk *clk;
> +       int enabled;
> +};
> +
> +static int twl6040_bitclk_is_enabled(struct clk_hw *hw)
> +{
> +       struct twl6040_clk *twl6040_clk = container_of(hw, struct twl6040_clk,
> +                                                      mcpdm_fclk);
> +       return twl6040_clk->enabled;
> +}
> +
> +static int twl6040_bitclk_prepare(struct clk_hw *hw)
> +{
> +       struct twl6040_clk *twl6040_clk = container_of(hw, struct twl6040_clk,
> +                                                      mcpdm_fclk);
> +       int ret;
> +
> +       ret = twl6040_power(twl6040_clk->twl6040, 1);
> +       if (!ret)
> +               twl6040_clk->enabled = 1;
> +
> +       return ret;
> +}
> +
> +static void twl6040_bitclk_unprepare(struct clk_hw *hw)
> +{
> +       struct twl6040_clk *twl6040_clk = container_of(hw, struct twl6040_clk,
> +                                                      mcpdm_fclk);
> +       int ret;
> +
> +       ret = twl6040_power(twl6040_clk->twl6040, 0);
> +       if (!ret)
> +               twl6040_clk->enabled = 0;
> +}
> +
> +static const struct clk_ops twl6040_mcpdm_ops = {
> +       .is_enabled = twl6040_bitclk_is_enabled,
> +       .prepare = twl6040_bitclk_prepare,
> +       .unprepare = twl6040_bitclk_unprepare,
> +};
> +
> +static struct clk_init_data wm831x_clkout_init = {
> +       .name = "mcpdm_fclk",
> +       .ops = &twl6040_mcpdm_ops,
> +       .flags = CLK_IS_ROOT,
> +};
> +
> +static int __devinit twl6040_clk_probe(struct platform_device *pdev)
> +{
> +       struct twl6040 *twl6040 = dev_get_drvdata(pdev->dev.parent);
> +       struct twl6040_clk *clkdata;
> +
> +       clkdata = devm_kzalloc(&pdev->dev, sizeof(*clkdata), GFP_KERNEL);
> +       if (!clkdata)
> +               return -ENOMEM;
> +
> +       clkdata->dev = &pdev->dev;
> +       clkdata->twl6040 = twl6040;
> +
> +       clkdata->mcpdm_fclk.init = &wm831x_clkout_init;
> +       clkdata->clk = clk_register(&pdev->dev, &clkdata->mcpdm_fclk);
> +       if (!clkdata->clk)
> +               return -EINVAL;
> +
> +       dev_set_drvdata(&pdev->dev, clkdata);
> +
> +       return 0;
> +}
> +
> +static int __devexit twl6040_clk_remove(struct platform_device *pdev)
> +{
> +       struct twl6040_clk *clkdata = dev_get_drvdata(&pdev->dev);
> +
> +       clk_unregister(clkdata->clk);
> +
> +       return 0;
> +}
> +
> +static struct platform_driver twl6040_clk_driver = {
> +       .driver = {
> +               .name = "twl6040-clk",
> +               .owner = THIS_MODULE,
> +       },
> +       .probe = twl6040_clk_probe,
> +       .remove = __devexit_p(twl6040_clk_remove),
> +};
> +
> +module_platform_driver(twl6040_clk_driver);
> +
> +MODULE_DESCRIPTION("TWL6040 clock driver for McPDM functional clock");
> +MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@ti.com>");
> +MODULE_ALIAS("platform:twl6040-clk");
> +MODULE_LICENSE("GPL");
> -- 
> 1.7.12

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] CLK: clk-twl6040: Initial clock driver for OMAP4+ McPDM fclk clock
  2012-10-29 17:30 ` Mike Turquette
@ 2012-10-30  7:39   ` Péter Ujfalusi
  2012-10-30 10:05     ` Mike Turquette
  0 siblings, 1 reply; 4+ messages in thread
From: Péter Ujfalusi @ 2012-10-30  7:39 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Mike,

On 10/29/2012 06:30 PM, Mike Turquette wrote:
> Peter,
> 
> The patch looks good to me.  To be clear, you wan this to go through
> clk-next or the mfd tree for avoiding conflicts?

clk-next is the best place for it I think. The MFD part to register the device
can still wait till we have ccf support on OMAP4.

Thank you,
P?ter

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] CLK: clk-twl6040: Initial clock driver for OMAP4+ McPDM fclk clock
  2012-10-30  7:39   ` Péter Ujfalusi
@ 2012-10-30 10:05     ` Mike Turquette
  0 siblings, 0 replies; 4+ messages in thread
From: Mike Turquette @ 2012-10-30 10:05 UTC (permalink / raw)
  To: linux-arm-kernel

Quoting P?ter Ujfalusi (2012-10-30 00:39:25)
> Hi Mike,
> 
> On 10/29/2012 06:30 PM, Mike Turquette wrote:
> > Peter,
> > 
> > The patch looks good to me.  To be clear, you wan this to go through
> > clk-next or the mfd tree for avoiding conflicts?
> 
> clk-next is the best place for it I think. The MFD part to register the device
> can still wait till we have ccf support on OMAP4.
>

Cool.  I've taken this into clk-next.

Regards,
Mike
 
> Thank you,
> P?ter

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-10-30 10:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-14 14:30 [PATCH] CLK: clk-twl6040: Initial clock driver for OMAP4+ McPDM fclk clock Peter Ujfalusi
2012-10-29 17:30 ` Mike Turquette
2012-10-30  7:39   ` Péter Ujfalusi
2012-10-30 10:05     ` Mike Turquette

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).