blob: 697c66757400ccc2e502b9bf24b79bdf94d7fa6d [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
Peter Ujfalusif9f8c042012-09-14 17:30:27 +030023#include <linux/module.h>
24#include <linux/slab.h>
25#include <linux/platform_device.h>
26#include <linux/mfd/twl6040.h>
27#include <linux/clk-provider.h>
28
29struct twl6040_clk {
30 struct twl6040 *twl6040;
31 struct device *dev;
32 struct clk_hw mcpdm_fclk;
33 struct clk *clk;
34 int enabled;
35};
36
37static int twl6040_bitclk_is_enabled(struct clk_hw *hw)
38{
39 struct twl6040_clk *twl6040_clk = container_of(hw, struct twl6040_clk,
40 mcpdm_fclk);
41 return twl6040_clk->enabled;
42}
43
44static int twl6040_bitclk_prepare(struct clk_hw *hw)
45{
46 struct twl6040_clk *twl6040_clk = container_of(hw, struct twl6040_clk,
47 mcpdm_fclk);
48 int ret;
49
50 ret = twl6040_power(twl6040_clk->twl6040, 1);
51 if (!ret)
52 twl6040_clk->enabled = 1;
53
54 return ret;
55}
56
57static void twl6040_bitclk_unprepare(struct clk_hw *hw)
58{
59 struct twl6040_clk *twl6040_clk = container_of(hw, struct twl6040_clk,
60 mcpdm_fclk);
61 int ret;
62
63 ret = twl6040_power(twl6040_clk->twl6040, 0);
64 if (!ret)
65 twl6040_clk->enabled = 0;
66}
67
68static const struct clk_ops twl6040_mcpdm_ops = {
69 .is_enabled = twl6040_bitclk_is_enabled,
70 .prepare = twl6040_bitclk_prepare,
71 .unprepare = twl6040_bitclk_unprepare,
72};
73
74static struct clk_init_data wm831x_clkout_init = {
75 .name = "mcpdm_fclk",
76 .ops = &twl6040_mcpdm_ops,
Peter Ujfalusif9f8c042012-09-14 17:30:27 +030077};
78
Greg Kroah-Hartman0fe763c2012-12-21 15:14:44 -080079static int twl6040_clk_probe(struct platform_device *pdev)
Peter Ujfalusif9f8c042012-09-14 17:30:27 +030080{
81 struct twl6040 *twl6040 = dev_get_drvdata(pdev->dev.parent);
82 struct twl6040_clk *clkdata;
83
84 clkdata = devm_kzalloc(&pdev->dev, sizeof(*clkdata), GFP_KERNEL);
85 if (!clkdata)
86 return -ENOMEM;
87
88 clkdata->dev = &pdev->dev;
89 clkdata->twl6040 = twl6040;
90
91 clkdata->mcpdm_fclk.init = &wm831x_clkout_init;
Axel Lin5c757452015-07-16 22:15:53 +080092 clkdata->clk = devm_clk_register(&pdev->dev, &clkdata->mcpdm_fclk);
Wei Yongjunddc07ef2012-11-01 13:33:55 +080093 if (IS_ERR(clkdata->clk))
94 return PTR_ERR(clkdata->clk);
Peter Ujfalusif9f8c042012-09-14 17:30:27 +030095
Jingoo Hanc0431032013-05-24 10:11:46 +090096 platform_set_drvdata(pdev, clkdata);
Peter Ujfalusif9f8c042012-09-14 17:30:27 +030097
98 return 0;
99}
100
Peter Ujfalusif9f8c042012-09-14 17:30:27 +0300101static struct platform_driver twl6040_clk_driver = {
102 .driver = {
103 .name = "twl6040-clk",
Peter Ujfalusif9f8c042012-09-14 17:30:27 +0300104 },
105 .probe = twl6040_clk_probe,
Peter Ujfalusif9f8c042012-09-14 17:30:27 +0300106};
107
108module_platform_driver(twl6040_clk_driver);
109
110MODULE_DESCRIPTION("TWL6040 clock driver for McPDM functional clock");
111MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@ti.com>");
112MODULE_ALIAS("platform:twl6040-clk");
113MODULE_LICENSE("GPL");