blob: 4a755135bcd388433696ee4c651a5bbb03302f5b [file] [log] [blame]
Peter Ujfalusif9f8c042012-09-14 17:30:27 +03001/*
2* TWL6040 clock module driver for OMAP4 McPDM functional clock
3*
4* Copyright (C) 2012 Texas Instruments Inc.
5* Peter Ujfalusi <peter.ujfalusi@ti.com>
6*
7* This program is free software; you can redistribute it and/or
8* modify it under the terms of the GNU General Public License
9* version 2 as published by the Free Software Foundation.
10*
11* This program is distributed in the hope that it will be useful, but
12* WITHOUT ANY WARRANTY; without even the implied warranty of
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14* General Public License for more details.
15*
16* You should have received a copy of the GNU General Public License
17* along with this program; if not, write to the Free Software
18* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19* 02110-1301 USA
20*
21*/
22
23#include <linux/clk.h>
24#include <linux/module.h>
25#include <linux/slab.h>
26#include <linux/platform_device.h>
27#include <linux/mfd/twl6040.h>
28#include <linux/clk-provider.h>
29
30struct twl6040_clk {
31 struct twl6040 *twl6040;
32 struct device *dev;
33 struct clk_hw mcpdm_fclk;
34 struct clk *clk;
35 int enabled;
36};
37
38static int twl6040_bitclk_is_enabled(struct clk_hw *hw)
39{
40 struct twl6040_clk *twl6040_clk = container_of(hw, struct twl6040_clk,
41 mcpdm_fclk);
42 return twl6040_clk->enabled;
43}
44
45static int twl6040_bitclk_prepare(struct clk_hw *hw)
46{
47 struct twl6040_clk *twl6040_clk = container_of(hw, struct twl6040_clk,
48 mcpdm_fclk);
49 int ret;
50
51 ret = twl6040_power(twl6040_clk->twl6040, 1);
52 if (!ret)
53 twl6040_clk->enabled = 1;
54
55 return ret;
56}
57
58static void twl6040_bitclk_unprepare(struct clk_hw *hw)
59{
60 struct twl6040_clk *twl6040_clk = container_of(hw, struct twl6040_clk,
61 mcpdm_fclk);
62 int ret;
63
64 ret = twl6040_power(twl6040_clk->twl6040, 0);
65 if (!ret)
66 twl6040_clk->enabled = 0;
67}
68
69static const struct clk_ops twl6040_mcpdm_ops = {
70 .is_enabled = twl6040_bitclk_is_enabled,
71 .prepare = twl6040_bitclk_prepare,
72 .unprepare = twl6040_bitclk_unprepare,
73};
74
75static struct clk_init_data wm831x_clkout_init = {
76 .name = "mcpdm_fclk",
77 .ops = &twl6040_mcpdm_ops,
78 .flags = CLK_IS_ROOT,
79};
80
Greg Kroah-Hartman0fe763c2012-12-21 15:14:44 -080081static int twl6040_clk_probe(struct platform_device *pdev)
Peter Ujfalusif9f8c042012-09-14 17:30:27 +030082{
83 struct twl6040 *twl6040 = dev_get_drvdata(pdev->dev.parent);
84 struct twl6040_clk *clkdata;
85
86 clkdata = devm_kzalloc(&pdev->dev, sizeof(*clkdata), GFP_KERNEL);
87 if (!clkdata)
88 return -ENOMEM;
89
90 clkdata->dev = &pdev->dev;
91 clkdata->twl6040 = twl6040;
92
93 clkdata->mcpdm_fclk.init = &wm831x_clkout_init;
94 clkdata->clk = clk_register(&pdev->dev, &clkdata->mcpdm_fclk);
Wei Yongjunddc07ef2012-11-01 13:33:55 +080095 if (IS_ERR(clkdata->clk))
96 return PTR_ERR(clkdata->clk);
Peter Ujfalusif9f8c042012-09-14 17:30:27 +030097
Jingoo Hanc0431032013-05-24 10:11:46 +090098 platform_set_drvdata(pdev, clkdata);
Peter Ujfalusif9f8c042012-09-14 17:30:27 +030099
100 return 0;
101}
102
Greg Kroah-Hartman0fe763c2012-12-21 15:14:44 -0800103static int twl6040_clk_remove(struct platform_device *pdev)
Peter Ujfalusif9f8c042012-09-14 17:30:27 +0300104{
Jingoo Hanc0431032013-05-24 10:11:46 +0900105 struct twl6040_clk *clkdata = platform_get_drvdata(pdev);
Peter Ujfalusif9f8c042012-09-14 17:30:27 +0300106
107 clk_unregister(clkdata->clk);
108
109 return 0;
110}
111
112static struct platform_driver twl6040_clk_driver = {
113 .driver = {
114 .name = "twl6040-clk",
Peter Ujfalusif9f8c042012-09-14 17:30:27 +0300115 },
116 .probe = twl6040_clk_probe,
Greg Kroah-Hartman0fe763c2012-12-21 15:14:44 -0800117 .remove = twl6040_clk_remove,
Peter Ujfalusif9f8c042012-09-14 17:30:27 +0300118};
119
120module_platform_driver(twl6040_clk_driver);
121
122MODULE_DESCRIPTION("TWL6040 clock driver for McPDM functional clock");
123MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@ti.com>");
124MODULE_ALIAS("platform:twl6040-clk");
125MODULE_LICENSE("GPL");