aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/clk/Kconfig9
-rw-r--r--drivers/clk/Makefile1
-rw-r--r--drivers/clk/clk-rk808.c170
3 files changed, 180 insertions, 0 deletions
diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index cfd3af7b2cbd..84e0590e31dc 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -38,6 +38,15 @@ config COMMON_CLK_MAX77686
38 ---help--- 38 ---help---
39 This driver supports Maxim 77686 crystal oscillator clock. 39 This driver supports Maxim 77686 crystal oscillator clock.
40 40
41config COMMON_CLK_RK808
42 tristate "Clock driver for RK808"
43 depends on MFD_RK808
44 ---help---
45 This driver supports RK808 crystal oscillator clock. These
46 multi-function devices have two fixed-rate oscillators,
47 clocked at 32KHz each. Clkout1 is always on, Clkout2 can off
48 by control register.
49
41config COMMON_CLK_SI5351 50config COMMON_CLK_SI5351
42 tristate "Clock driver for SiLabs 5351A/B/C" 51 tristate "Clock driver for SiLabs 5351A/B/C"
43 depends on I2C 52 depends on I2C
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index f537a0b1f798..99f53d5f8766 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_ARCH_NOMADIK) += clk-nomadik.o
28obj-$(CONFIG_ARCH_NSPIRE) += clk-nspire.o 28obj-$(CONFIG_ARCH_NSPIRE) += clk-nspire.o
29obj-$(CONFIG_COMMON_CLK_PALMAS) += clk-palmas.o 29obj-$(CONFIG_COMMON_CLK_PALMAS) += clk-palmas.o
30obj-$(CONFIG_CLK_PPC_CORENET) += clk-ppc-corenet.o 30obj-$(CONFIG_CLK_PPC_CORENET) += clk-ppc-corenet.o
31obj-$(CONFIG_COMMON_CLK_RK808) += clk-rk808.o
31obj-$(CONFIG_COMMON_CLK_S2MPS11) += clk-s2mps11.o 32obj-$(CONFIG_COMMON_CLK_S2MPS11) += clk-s2mps11.o
32obj-$(CONFIG_COMMON_CLK_SI5351) += clk-si5351.o 33obj-$(CONFIG_COMMON_CLK_SI5351) += clk-si5351.o
33obj-$(CONFIG_COMMON_CLK_SI570) += clk-si570.o 34obj-$(CONFIG_COMMON_CLK_SI570) += clk-si570.o
diff --git a/drivers/clk/clk-rk808.c b/drivers/clk/clk-rk808.c
new file mode 100644
index 000000000000..83902b9cd49e
--- /dev/null
+++ b/drivers/clk/clk-rk808.c
@@ -0,0 +1,170 @@
1/*
2 * Clkout driver for Rockchip RK808
3 *
4 * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
5 *
6 * Author:Chris Zhong <zyw@rock-chips.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 */
17
18#include <linux/clk.h>
19#include <linux/clk-provider.h>
20#include <linux/module.h>
21#include <linux/slab.h>
22#include <linux/platform_device.h>
23#include <linux/mfd/rk808.h>
24#include <linux/i2c.h>
25
26#define RK808_NR_OUTPUT 2
27
28struct rk808_clkout {
29 struct rk808 *rk808;
30 struct clk_onecell_data clk_data;
31 struct clk_hw clkout1_hw;
32 struct clk_hw clkout2_hw;
33};
34
35static unsigned long rk808_clkout_recalc_rate(struct clk_hw *hw,
36 unsigned long parent_rate)
37{
38 return 32768;
39}
40
41static int rk808_clkout2_enable(struct clk_hw *hw, bool enable)
42{
43 struct rk808_clkout *rk808_clkout = container_of(hw,
44 struct rk808_clkout,
45 clkout2_hw);
46 struct rk808 *rk808 = rk808_clkout->rk808;
47
48 return regmap_update_bits(rk808->regmap, RK808_CLK32OUT_REG,
49 CLK32KOUT2_EN, enable ? CLK32KOUT2_EN : 0);
50}
51
52static int rk808_clkout2_prepare(struct clk_hw *hw)
53{
54 return rk808_clkout2_enable(hw, true);
55}
56
57static void rk808_clkout2_unprepare(struct clk_hw *hw)
58{
59 rk808_clkout2_enable(hw, false);
60}
61
62static int rk808_clkout2_is_prepared(struct clk_hw *hw)
63{
64 struct rk808_clkout *rk808_clkout = container_of(hw,
65 struct rk808_clkout,
66 clkout2_hw);
67 struct rk808 *rk808 = rk808_clkout->rk808;
68 uint32_t val;
69
70 int ret = regmap_read(rk808->regmap, RK808_CLK32OUT_REG, &val);
71
72 if (ret < 0)
73 return ret;
74
75 return (val & CLK32KOUT2_EN) ? 1 : 0;
76}
77
78static const struct clk_ops rk808_clkout1_ops = {
79 .recalc_rate = rk808_clkout_recalc_rate,
80};
81
82static const struct clk_ops rk808_clkout2_ops = {
83 .prepare = rk808_clkout2_prepare,
84 .unprepare = rk808_clkout2_unprepare,
85 .is_prepared = rk808_clkout2_is_prepared,
86 .recalc_rate = rk808_clkout_recalc_rate,
87};
88
89static int rk808_clkout_probe(struct platform_device *pdev)
90{
91 struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
92 struct i2c_client *client = rk808->i2c;
93 struct device_node *node = client->dev.of_node;
94 struct clk_init_data init = {};
95 struct clk **clk_table;
96 struct rk808_clkout *rk808_clkout;
97
98 rk808_clkout = devm_kzalloc(&client->dev,
99 sizeof(*rk808_clkout), GFP_KERNEL);
100 if (!rk808_clkout)
101 return -ENOMEM;
102
103 rk808_clkout->rk808 = rk808;
104
105 clk_table = devm_kcalloc(&client->dev, RK808_NR_OUTPUT,
106 sizeof(struct clk *), GFP_KERNEL);
107 if (!clk_table)
108 return -ENOMEM;
109
110 init.flags = CLK_IS_ROOT;
111 init.parent_names = NULL;
112 init.num_parents = 0;
113 init.name = "rk808-clkout1";
114 init.ops = &rk808_clkout1_ops;
115 rk808_clkout->clkout1_hw.init = &init;
116
117 /* optional override of the clockname */
118 of_property_read_string_index(node, "clock-output-names",
119 0, &init.name);
120
121 clk_table[0] = devm_clk_register(&client->dev,
122 &rk808_clkout->clkout1_hw);
123 if (IS_ERR(clk_table[0]))
124 return PTR_ERR(clk_table[0]);
125
126 init.name = "rk808-clkout2";
127 init.ops = &rk808_clkout2_ops;
128 rk808_clkout->clkout2_hw.init = &init;
129
130 /* optional override of the clockname */
131 of_property_read_string_index(node, "clock-output-names",
132 1, &init.name);
133
134 clk_table[1] = devm_clk_register(&client->dev,
135 &rk808_clkout->clkout2_hw);
136 if (IS_ERR(clk_table[1]))
137 return PTR_ERR(clk_table[1]);
138
139 rk808_clkout->clk_data.clks = clk_table;
140 rk808_clkout->clk_data.clk_num = RK808_NR_OUTPUT;
141
142 return of_clk_add_provider(node, of_clk_src_onecell_get,
143 &rk808_clkout->clk_data);
144}
145
146static int rk808_clkout_remove(struct platform_device *pdev)
147{
148 struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
149 struct i2c_client *client = rk808->i2c;
150 struct device_node *node = client->dev.of_node;
151
152 of_clk_del_provider(node);
153
154 return 0;
155}
156
157static struct platform_driver rk808_clkout_driver = {
158 .probe = rk808_clkout_probe,
159 .remove = rk808_clkout_remove,
160 .driver = {
161 .name = "rk808-clkout",
162 },
163};
164
165module_platform_driver(rk808_clkout_driver);
166
167MODULE_DESCRIPTION("Clkout driver for the rk808 series PMICs");
168MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>");
169MODULE_LICENSE("GPL");
170MODULE_ALIAS("platform:rk808-clkout");