aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/clk
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/clk')
-rw-r--r--drivers/clk/Kconfig9
-rw-r--r--drivers/clk/Makefile1
-rw-r--r--drivers/clk/at91/Makefile1
-rw-r--r--drivers/clk/at91/clk-h32mx.c123
-rw-r--r--drivers/clk/at91/clk-system.c8
-rw-r--r--drivers/clk/at91/pmc.c6
-rw-r--r--drivers/clk/at91/pmc.h5
-rw-r--r--drivers/clk/clk-rk808.c170
-rw-r--r--drivers/clk/shmobile/Makefile3
9 files changed, 317 insertions, 9 deletions
diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 1d4d3fc182dd..455fd17d938e 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -49,6 +49,15 @@ config COMMON_CLK_MAX77802
49 ---help--- 49 ---help---
50 This driver supports Maxim 77802 crystal oscillator clock. 50 This driver supports Maxim 77802 crystal oscillator clock.
51 51
52config COMMON_CLK_RK808
53 tristate "Clock driver for RK808"
54 depends on MFD_RK808
55 ---help---
56 This driver supports RK808 crystal oscillator clock. These
57 multi-function devices have two fixed-rate oscillators,
58 clocked at 32KHz each. Clkout1 is always on, Clkout2 can off
59 by control register.
60
52config COMMON_CLK_SI5351 61config COMMON_CLK_SI5351
53 tristate "Clock driver for SiLabs 5351A/B/C" 62 tristate "Clock driver for SiLabs 5351A/B/C"
54 depends on I2C 63 depends on I2C
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 5eaf1b547f19..d5fba5bc6e1b 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -31,6 +31,7 @@ obj-$(CONFIG_ARCH_NOMADIK) += clk-nomadik.o
31obj-$(CONFIG_ARCH_NSPIRE) += clk-nspire.o 31obj-$(CONFIG_ARCH_NSPIRE) += clk-nspire.o
32obj-$(CONFIG_COMMON_CLK_PALMAS) += clk-palmas.o 32obj-$(CONFIG_COMMON_CLK_PALMAS) += clk-palmas.o
33obj-$(CONFIG_CLK_PPC_CORENET) += clk-ppc-corenet.o 33obj-$(CONFIG_CLK_PPC_CORENET) += clk-ppc-corenet.o
34obj-$(CONFIG_COMMON_CLK_RK808) += clk-rk808.o
34obj-$(CONFIG_COMMON_CLK_S2MPS11) += clk-s2mps11.o 35obj-$(CONFIG_COMMON_CLK_S2MPS11) += clk-s2mps11.o
35obj-$(CONFIG_COMMON_CLK_SI5351) += clk-si5351.o 36obj-$(CONFIG_COMMON_CLK_SI5351) += clk-si5351.o
36obj-$(CONFIG_COMMON_CLK_SI570) += clk-si570.o 37obj-$(CONFIG_COMMON_CLK_SI570) += clk-si570.o
diff --git a/drivers/clk/at91/Makefile b/drivers/clk/at91/Makefile
index 4998aee59267..89a48a7bd5df 100644
--- a/drivers/clk/at91/Makefile
+++ b/drivers/clk/at91/Makefile
@@ -9,3 +9,4 @@ obj-y += clk-system.o clk-peripheral.o clk-programmable.o
9obj-$(CONFIG_HAVE_AT91_UTMI) += clk-utmi.o 9obj-$(CONFIG_HAVE_AT91_UTMI) += clk-utmi.o
10obj-$(CONFIG_HAVE_AT91_USB_CLK) += clk-usb.o 10obj-$(CONFIG_HAVE_AT91_USB_CLK) += clk-usb.o
11obj-$(CONFIG_HAVE_AT91_SMD) += clk-smd.o 11obj-$(CONFIG_HAVE_AT91_SMD) += clk-smd.o
12obj-$(CONFIG_HAVE_AT91_H32MX) += clk-h32mx.o
diff --git a/drivers/clk/at91/clk-h32mx.c b/drivers/clk/at91/clk-h32mx.c
new file mode 100644
index 000000000000..152dcb3f7b5f
--- /dev/null
+++ b/drivers/clk/at91/clk-h32mx.c
@@ -0,0 +1,123 @@
1/*
2 * clk-h32mx.c
3 *
4 * Copyright (C) 2014 Atmel
5 *
6 * Alexandre Belloni <alexandre.belloni@free-electrons.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 */
14
15#include <linux/clk-provider.h>
16#include <linux/clkdev.h>
17#include <linux/clk/at91_pmc.h>
18#include <linux/delay.h>
19#include <linux/of.h>
20#include <linux/of_address.h>
21#include <linux/of_irq.h>
22#include <linux/io.h>
23#include <linux/interrupt.h>
24#include <linux/irq.h>
25#include <linux/sched.h>
26#include <linux/wait.h>
27
28#include "pmc.h"
29
30#define H32MX_MAX_FREQ 90000000
31
32struct clk_sama5d4_h32mx {
33 struct clk_hw hw;
34 struct at91_pmc *pmc;
35};
36
37#define to_clk_sama5d4_h32mx(hw) container_of(hw, struct clk_sama5d4_h32mx, hw)
38
39static unsigned long clk_sama5d4_h32mx_recalc_rate(struct clk_hw *hw,
40 unsigned long parent_rate)
41{
42 struct clk_sama5d4_h32mx *h32mxclk = to_clk_sama5d4_h32mx(hw);
43
44 if (pmc_read(h32mxclk->pmc, AT91_PMC_MCKR) & AT91_PMC_H32MXDIV)
45 return parent_rate / 2;
46
47 if (parent_rate > H32MX_MAX_FREQ)
48 pr_warn("H32MX clock is too fast\n");
49 return parent_rate;
50}
51
52static long clk_sama5d4_h32mx_round_rate(struct clk_hw *hw, unsigned long rate,
53 unsigned long *parent_rate)
54{
55 unsigned long div;
56
57 if (rate > *parent_rate)
58 return *parent_rate;
59 div = *parent_rate / 2;
60 if (rate < div)
61 return div;
62
63 if (rate - div < *parent_rate - rate)
64 return div;
65
66 return *parent_rate;
67}
68
69static int clk_sama5d4_h32mx_set_rate(struct clk_hw *hw, unsigned long rate,
70 unsigned long parent_rate)
71{
72 struct clk_sama5d4_h32mx *h32mxclk = to_clk_sama5d4_h32mx(hw);
73 struct at91_pmc *pmc = h32mxclk->pmc;
74 u32 tmp;
75
76 if (parent_rate != rate && (parent_rate / 2) != rate)
77 return -EINVAL;
78
79 pmc_lock(pmc);
80 tmp = pmc_read(pmc, AT91_PMC_MCKR) & ~AT91_PMC_H32MXDIV;
81 if ((parent_rate / 2) == rate)
82 tmp |= AT91_PMC_H32MXDIV;
83 pmc_write(pmc, AT91_PMC_MCKR, tmp);
84 pmc_unlock(pmc);
85
86 return 0;
87}
88
89static const struct clk_ops h32mx_ops = {
90 .recalc_rate = clk_sama5d4_h32mx_recalc_rate,
91 .round_rate = clk_sama5d4_h32mx_round_rate,
92 .set_rate = clk_sama5d4_h32mx_set_rate,
93};
94
95void __init of_sama5d4_clk_h32mx_setup(struct device_node *np,
96 struct at91_pmc *pmc)
97{
98 struct clk_sama5d4_h32mx *h32mxclk;
99 struct clk_init_data init;
100 const char *parent_name;
101 struct clk *clk;
102
103 h32mxclk = kzalloc(sizeof(*h32mxclk), GFP_KERNEL);
104 if (!h32mxclk)
105 return;
106
107 parent_name = of_clk_get_parent_name(np, 0);
108
109 init.name = np->name;
110 init.ops = &h32mx_ops;
111 init.parent_names = parent_name ? &parent_name : NULL;
112 init.num_parents = parent_name ? 1 : 0;
113 init.flags = CLK_SET_RATE_GATE;
114
115 h32mxclk->hw.init = &init;
116 h32mxclk->pmc = pmc;
117
118 clk = clk_register(NULL, &h32mxclk->hw);
119 if (!clk)
120 return;
121
122 of_clk_add_provider(np, of_clk_src_simple_get, clk);
123}
diff --git a/drivers/clk/at91/clk-system.c b/drivers/clk/at91/clk-system.c
index 8c96307d7363..a76d03fd577b 100644
--- a/drivers/clk/at91/clk-system.c
+++ b/drivers/clk/at91/clk-system.c
@@ -119,13 +119,7 @@ at91_clk_register_system(struct at91_pmc *pmc, const char *name,
119 init.ops = &system_ops; 119 init.ops = &system_ops;
120 init.parent_names = &parent_name; 120 init.parent_names = &parent_name;
121 init.num_parents = 1; 121 init.num_parents = 1;
122 /* 122 init.flags = CLK_SET_RATE_PARENT;
123 * CLK_IGNORE_UNUSED is used to avoid ddrck switch off.
124 * TODO : we should implement a driver supporting at91 ddr controller
125 * (see drivers/memory) which would request and enable the ddrck clock.
126 * When this is done we will be able to remove CLK_IGNORE_UNUSED flag.
127 */
128 init.flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED;
129 123
130 sys->id = id; 124 sys->id = id;
131 sys->hw.init = &init; 125 sys->hw.init = &init;
diff --git a/drivers/clk/at91/pmc.c b/drivers/clk/at91/pmc.c
index 524196bb35a5..386999b4f8eb 100644
--- a/drivers/clk/at91/pmc.c
+++ b/drivers/clk/at91/pmc.c
@@ -337,6 +337,12 @@ static const struct of_device_id pmc_clk_ids[] __initconst = {
337 .data = of_at91sam9x5_clk_smd_setup, 337 .data = of_at91sam9x5_clk_smd_setup,
338 }, 338 },
339#endif 339#endif
340#if defined(CONFIG_HAVE_AT91_H32MX)
341 {
342 .compatible = "atmel,sama5d4-clk-h32mx",
343 .data = of_sama5d4_clk_h32mx_setup,
344 },
345#endif
340 { /*sentinel*/ } 346 { /*sentinel*/ }
341}; 347};
342 348
diff --git a/drivers/clk/at91/pmc.h b/drivers/clk/at91/pmc.h
index 6c7625976113..52d2041fa3f6 100644
--- a/drivers/clk/at91/pmc.h
+++ b/drivers/clk/at91/pmc.h
@@ -120,4 +120,9 @@ extern void __init of_at91sam9x5_clk_smd_setup(struct device_node *np,
120 struct at91_pmc *pmc); 120 struct at91_pmc *pmc);
121#endif 121#endif
122 122
123#if defined(CONFIG_HAVE_AT91_SMD)
124extern void __init of_sama5d4_clk_h32mx_setup(struct device_node *np,
125 struct at91_pmc *pmc);
126#endif
127
123#endif /* __PMC_H_ */ 128#endif /* __PMC_H_ */
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");
diff --git a/drivers/clk/shmobile/Makefile b/drivers/clk/shmobile/Makefile
index e0029237827a..960bf22d42ae 100644
--- a/drivers/clk/shmobile/Makefile
+++ b/drivers/clk/shmobile/Makefile
@@ -4,7 +4,6 @@ obj-$(CONFIG_ARCH_R8A7740) += clk-r8a7740.o
4obj-$(CONFIG_ARCH_R8A7779) += clk-r8a7779.o 4obj-$(CONFIG_ARCH_R8A7779) += clk-r8a7779.o
5obj-$(CONFIG_ARCH_R8A7790) += clk-rcar-gen2.o 5obj-$(CONFIG_ARCH_R8A7790) += clk-rcar-gen2.o
6obj-$(CONFIG_ARCH_R8A7791) += clk-rcar-gen2.o 6obj-$(CONFIG_ARCH_R8A7791) += clk-rcar-gen2.o
7obj-$(CONFIG_ARCH_R8A7794) += clk-rcar-gen2.o
7obj-$(CONFIG_ARCH_SHMOBILE_MULTI) += clk-div6.o 8obj-$(CONFIG_ARCH_SHMOBILE_MULTI) += clk-div6.o
8obj-$(CONFIG_ARCH_SHMOBILE_MULTI) += clk-mstp.o 9obj-$(CONFIG_ARCH_SHMOBILE_MULTI) += clk-mstp.o
9# for emply built-in.o
10obj-n := dummy