Bluetooth: Remove unneeded initializer for management command table
[linux/fpc-iii.git] / drivers / clk / clk-rk808.c
blob83902b9cd49ef0a5772e807806999a1d16786195
1 /*
2 * Clkout driver for Rockchip RK808
4 * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
6 * Author:Chris Zhong <zyw@rock-chips.com>
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.
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.
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>
26 #define RK808_NR_OUTPUT 2
28 struct 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;
35 static unsigned long rk808_clkout_recalc_rate(struct clk_hw *hw,
36 unsigned long parent_rate)
38 return 32768;
41 static int rk808_clkout2_enable(struct clk_hw *hw, bool enable)
43 struct rk808_clkout *rk808_clkout = container_of(hw,
44 struct rk808_clkout,
45 clkout2_hw);
46 struct rk808 *rk808 = rk808_clkout->rk808;
48 return regmap_update_bits(rk808->regmap, RK808_CLK32OUT_REG,
49 CLK32KOUT2_EN, enable ? CLK32KOUT2_EN : 0);
52 static int rk808_clkout2_prepare(struct clk_hw *hw)
54 return rk808_clkout2_enable(hw, true);
57 static void rk808_clkout2_unprepare(struct clk_hw *hw)
59 rk808_clkout2_enable(hw, false);
62 static int rk808_clkout2_is_prepared(struct clk_hw *hw)
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;
70 int ret = regmap_read(rk808->regmap, RK808_CLK32OUT_REG, &val);
72 if (ret < 0)
73 return ret;
75 return (val & CLK32KOUT2_EN) ? 1 : 0;
78 static const struct clk_ops rk808_clkout1_ops = {
79 .recalc_rate = rk808_clkout_recalc_rate,
82 static 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,
89 static int rk808_clkout_probe(struct platform_device *pdev)
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;
98 rk808_clkout = devm_kzalloc(&client->dev,
99 sizeof(*rk808_clkout), GFP_KERNEL);
100 if (!rk808_clkout)
101 return -ENOMEM;
103 rk808_clkout->rk808 = rk808;
105 clk_table = devm_kcalloc(&client->dev, RK808_NR_OUTPUT,
106 sizeof(struct clk *), GFP_KERNEL);
107 if (!clk_table)
108 return -ENOMEM;
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;
117 /* optional override of the clockname */
118 of_property_read_string_index(node, "clock-output-names",
119 0, &init.name);
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]);
126 init.name = "rk808-clkout2";
127 init.ops = &rk808_clkout2_ops;
128 rk808_clkout->clkout2_hw.init = &init;
130 /* optional override of the clockname */
131 of_property_read_string_index(node, "clock-output-names",
132 1, &init.name);
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]);
139 rk808_clkout->clk_data.clks = clk_table;
140 rk808_clkout->clk_data.clk_num = RK808_NR_OUTPUT;
142 return of_clk_add_provider(node, of_clk_src_onecell_get,
143 &rk808_clkout->clk_data);
146 static int rk808_clkout_remove(struct platform_device *pdev)
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;
152 of_clk_del_provider(node);
154 return 0;
157 static struct platform_driver rk808_clkout_driver = {
158 .probe = rk808_clkout_probe,
159 .remove = rk808_clkout_remove,
160 .driver = {
161 .name = "rk808-clkout",
165 module_platform_driver(rk808_clkout_driver);
167 MODULE_DESCRIPTION("Clkout driver for the rk808 series PMICs");
168 MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>");
169 MODULE_LICENSE("GPL");
170 MODULE_ALIAS("platform:rk808-clkout");