summaryrefslogtreecommitdiffstats
path: root/drivers/clk
diff options
context:
space:
mode:
authorDaniel Lezcano <daniel.lezcano@linaro.org>2017-04-17 13:19:25 -0400
committerStephen Boyd <sboyd@codeaurora.org>2017-04-21 22:18:53 -0400
commitb68adc23bc3d0c81a08b69cf1ba0bf0405c9d868 (patch)
tree3dd120d9513de93aec3bdd4b054d727118e699f6 /drivers/clk
parentfc04f27dfc4280ef35540ab40fa14c24ff8cc799 (diff)
clk: hi6220: Add the hi655x's pmic clock
The hi655x multi function device is a PMIC providing regulators. The PMIC also provides a clock for the WiFi and the Bluetooth, let's implement this clock in order to add it in the hi655x MFD and allow proper wireless initialization. Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> [sboyd@codeaurora.org: Remove clkdev usage] Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
Diffstat (limited to 'drivers/clk')
-rw-r--r--drivers/clk/Kconfig8
-rw-r--r--drivers/clk/Makefile1
-rw-r--r--drivers/clk/clk-hi655x.c126
3 files changed, 135 insertions, 0 deletions
diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 9356ab4b7d76..36cfea38135f 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -47,6 +47,14 @@ config COMMON_CLK_RK808
47 clocked at 32KHz each. Clkout1 is always on, Clkout2 can off 47 clocked at 32KHz each. Clkout1 is always on, Clkout2 can off
48 by control register. 48 by control register.
49 49
50config COMMON_CLK_HI655X
51 tristate "Clock driver for Hi655x"
52 depends on MFD_HI655X_PMIC || COMPILE_TEST
53 ---help---
54 This driver supports the hi655x PMIC clock. This
55 multi-function device has one fixed-rate oscillator, clocked
56 at 32KHz.
57
50config COMMON_CLK_SCPI 58config COMMON_CLK_SCPI
51 tristate "Clock driver controlled via SCPI interface" 59 tristate "Clock driver controlled via SCPI interface"
52 depends on ARM_SCPI_PROTOCOL || COMPILE_TEST 60 depends on ARM_SCPI_PROTOCOL || COMPILE_TEST
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 92c12b86c2e8..c19983afcb81 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -36,6 +36,7 @@ obj-$(CONFIG_COMMON_CLK_PALMAS) += clk-palmas.o
36obj-$(CONFIG_COMMON_CLK_PWM) += clk-pwm.o 36obj-$(CONFIG_COMMON_CLK_PWM) += clk-pwm.o
37obj-$(CONFIG_CLK_QORIQ) += clk-qoriq.o 37obj-$(CONFIG_CLK_QORIQ) += clk-qoriq.o
38obj-$(CONFIG_COMMON_CLK_RK808) += clk-rk808.o 38obj-$(CONFIG_COMMON_CLK_RK808) += clk-rk808.o
39obj-$(CONFIG_COMMON_CLK_HI655X) += clk-hi655x.o
39obj-$(CONFIG_COMMON_CLK_S2MPS11) += clk-s2mps11.o 40obj-$(CONFIG_COMMON_CLK_S2MPS11) += clk-s2mps11.o
40obj-$(CONFIG_COMMON_CLK_SCPI) += clk-scpi.o 41obj-$(CONFIG_COMMON_CLK_SCPI) += clk-scpi.o
41obj-$(CONFIG_COMMON_CLK_SI5351) += clk-si5351.o 42obj-$(CONFIG_COMMON_CLK_SI5351) += clk-si5351.o
diff --git a/drivers/clk/clk-hi655x.c b/drivers/clk/clk-hi655x.c
new file mode 100644
index 000000000000..403a0188634a
--- /dev/null
+++ b/drivers/clk/clk-hi655x.c
@@ -0,0 +1,126 @@
1/*
2 * Clock driver for Hi655x
3 *
4 * Copyright (c) 2017, Linaro Ltd.
5 *
6 * Author: Daniel Lezcano <daniel.lezcano@linaro.org>
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#include <linux/clk-provider.h>
18#include <linux/module.h>
19#include <linux/platform_device.h>
20#include <linux/regmap.h>
21#include <linux/slab.h>
22#include <linux/mfd/core.h>
23#include <linux/mfd/hi655x-pmic.h>
24
25#define HI655X_CLK_BASE HI655X_BUS_ADDR(0x1c)
26#define HI655X_CLK_SET BIT(6)
27
28struct hi655x_clk {
29 struct hi655x_pmic *hi655x;
30 struct clk_hw clk_hw;
31};
32
33static unsigned long hi655x_clk_recalc_rate(struct clk_hw *hw,
34 unsigned long parent_rate)
35{
36 return 32768;
37}
38
39static int hi655x_clk_enable(struct clk_hw *hw, bool enable)
40{
41 struct hi655x_clk *hi655x_clk =
42 container_of(hw, struct hi655x_clk, clk_hw);
43
44 struct hi655x_pmic *hi655x = hi655x_clk->hi655x;
45
46 return regmap_update_bits(hi655x->regmap, HI655X_CLK_BASE,
47 HI655X_CLK_SET, enable ? HI655X_CLK_SET : 0);
48}
49
50static int hi655x_clk_prepare(struct clk_hw *hw)
51{
52 return hi655x_clk_enable(hw, true);
53}
54
55static void hi655x_clk_unprepare(struct clk_hw *hw)
56{
57 hi655x_clk_enable(hw, false);
58}
59
60static int hi655x_clk_is_prepared(struct clk_hw *hw)
61{
62 struct hi655x_clk *hi655x_clk =
63 container_of(hw, struct hi655x_clk, clk_hw);
64 struct hi655x_pmic *hi655x = hi655x_clk->hi655x;
65 int ret;
66 uint32_t val;
67
68 ret = regmap_read(hi655x->regmap, HI655X_CLK_BASE, &val);
69 if (ret < 0)
70 return ret;
71
72 return val & HI655X_CLK_BASE;
73}
74
75static const struct clk_ops hi655x_clk_ops = {
76 .prepare = hi655x_clk_prepare,
77 .unprepare = hi655x_clk_unprepare,
78 .is_prepared = hi655x_clk_is_prepared,
79 .recalc_rate = hi655x_clk_recalc_rate,
80};
81
82static int hi655x_clk_probe(struct platform_device *pdev)
83{
84 struct device *parent = pdev->dev.parent;
85 struct hi655x_pmic *hi655x = dev_get_drvdata(parent);
86 struct hi655x_clk *hi655x_clk;
87 const char *clk_name = "hi655x-clk";
88 struct clk_init_data init = {
89 .name = clk_name,
90 .ops = &hi655x_clk_ops
91 };
92 int ret;
93
94 hi655x_clk = devm_kzalloc(&pdev->dev, sizeof(*hi655x_clk), GFP_KERNEL);
95 if (!hi655x_clk)
96 return -ENOMEM;
97
98 of_property_read_string_index(parent->of_node, "clock-output-names",
99 0, &clk_name);
100
101 hi655x_clk->clk_hw.init = &init;
102 hi655x_clk->hi655x = hi655x;
103
104 platform_set_drvdata(pdev, hi655x_clk);
105
106 ret = devm_clk_hw_register(&pdev->dev, &hi655x_clk->clk_hw);
107 if (ret)
108 return ret;
109
110 return of_clk_add_hw_provider(parent->of_node, of_clk_hw_simple_get,
111 &hi655x_clk->clk_hw);
112}
113
114static struct platform_driver hi655x_clk_driver = {
115 .probe = hi655x_clk_probe,
116 .driver = {
117 .name = "hi655x-clk",
118 },
119};
120
121module_platform_driver(hi655x_clk_driver);
122
123MODULE_DESCRIPTION("Clk driver for the hi655x series PMICs");
124MODULE_AUTHOR("Daniel Lezcano <daniel.lezcano@linaro.org>");
125MODULE_LICENSE("GPL");
126MODULE_ALIAS("platform:hi655x-clk");