aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/clk/clk-gpio.c
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2017-09-24 12:19:18 -0400
committerStephen Boyd <sboyd@codeaurora.org>2017-11-02 04:20:38 -0400
commit908a543ac7cdf3aa8a283ec42cab3c16e2fc45a2 (patch)
tree1e3ddd5fec1f52481399503d590c32915d219bad /drivers/clk/clk-gpio.c
parent2bd6bf03f4c1c59381d62c61d03f6cc3fe71f66e (diff)
clk: clk-gpio: Make GPIO clock provider use descriptors only
After som grep:ing it turns out nothing in the kernel is really calling clk_[hw_]_register_gpio_[gate|mux](). All existing instances are just created directly from the device tree probe functions at the bottom of the clk-gpio.c clock provider file. This means we can change the signature of the function without any consequences! Everyone should be using GPIO descriptors now, so let's just go in and enforce that. This saves a bit of code since GPIO descriptors know inherently if they are active low so no need for the code keeping track of that. We leave it to the caller to come up with the GPIO descriptor. It is nowadays possible to do that even without a corresponding device, so no excuse not to pass them around. The one in-kernel user lifecycles it using devm_gpiod_get() in gpio_clk_driver_probe(). Cc: Sergej Sawazki <ce3a@gmx.de> Cc: Jyri Sarha <jsarha@ti.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
Diffstat (limited to 'drivers/clk/clk-gpio.c')
-rw-r--r--drivers/clk/clk-gpio.c90
1 files changed, 35 insertions, 55 deletions
diff --git a/drivers/clk/clk-gpio.c b/drivers/clk/clk-gpio.c
index 86b245746a6b..9d057073e110 100644
--- a/drivers/clk/clk-gpio.c
+++ b/drivers/clk/clk-gpio.c
@@ -15,9 +15,7 @@
15#include <linux/clk-provider.h> 15#include <linux/clk-provider.h>
16#include <linux/export.h> 16#include <linux/export.h>
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/gpio.h>
19#include <linux/gpio/consumer.h> 18#include <linux/gpio/consumer.h>
20#include <linux/of_gpio.h>
21#include <linux/err.h> 19#include <linux/err.h>
22#include <linux/device.h> 20#include <linux/device.h>
23#include <linux/platform_device.h> 21#include <linux/platform_device.h>
@@ -95,14 +93,12 @@ const struct clk_ops clk_gpio_mux_ops = {
95EXPORT_SYMBOL_GPL(clk_gpio_mux_ops); 93EXPORT_SYMBOL_GPL(clk_gpio_mux_ops);
96 94
97static struct clk_hw *clk_register_gpio(struct device *dev, const char *name, 95static struct clk_hw *clk_register_gpio(struct device *dev, const char *name,
98 const char * const *parent_names, u8 num_parents, unsigned gpio, 96 const char * const *parent_names, u8 num_parents, struct gpio_desc *gpiod,
99 bool active_low, unsigned long flags, 97 unsigned long flags, const struct clk_ops *clk_gpio_ops)
100 const struct clk_ops *clk_gpio_ops)
101{ 98{
102 struct clk_gpio *clk_gpio; 99 struct clk_gpio *clk_gpio;
103 struct clk_hw *hw; 100 struct clk_hw *hw;
104 struct clk_init_data init = {}; 101 struct clk_init_data init = {};
105 unsigned long gpio_flags;
106 int err; 102 int err;
107 103
108 if (dev) 104 if (dev)
@@ -113,24 +109,13 @@ static struct clk_hw *clk_register_gpio(struct device *dev, const char *name,
113 if (!clk_gpio) 109 if (!clk_gpio)
114 return ERR_PTR(-ENOMEM); 110 return ERR_PTR(-ENOMEM);
115 111
116 if (active_low) 112 /*
117 gpio_flags = GPIOF_ACTIVE_LOW | GPIOF_OUT_INIT_HIGH; 113 * Set to disabled no matter what: NOTE if the GPIO line is active low
118 else 114 * the GPIO descriptor knows this and will set it high to deassert the
119 gpio_flags = GPIOF_OUT_INIT_LOW; 115 * line. This assumes the GPIO descriptor has been requested using
120 116 * GPIOD_ASIS by the callers so we need to initialize it as disabled here.
121 if (dev) 117 */
122 err = devm_gpio_request_one(dev, gpio, gpio_flags, name); 118 gpiod_set_value(gpiod, 0);
123 else
124 err = gpio_request_one(gpio, gpio_flags, name);
125 if (err) {
126 if (err != -EPROBE_DEFER)
127 pr_err("%s: %s: Error requesting clock control gpio %u\n",
128 __func__, name, gpio);
129 if (!dev)
130 kfree(clk_gpio);
131
132 return ERR_PTR(err);
133 }
134 119
135 init.name = name; 120 init.name = name;
136 init.ops = clk_gpio_ops; 121 init.ops = clk_gpio_ops;
@@ -138,7 +123,7 @@ static struct clk_hw *clk_register_gpio(struct device *dev, const char *name,
138 init.parent_names = parent_names; 123 init.parent_names = parent_names;
139 init.num_parents = num_parents; 124 init.num_parents = num_parents;
140 125
141 clk_gpio->gpiod = gpio_to_desc(gpio); 126 clk_gpio->gpiod = gpiod;
142 clk_gpio->hw.init = &init; 127 clk_gpio->hw.init = &init;
143 128
144 hw = &clk_gpio->hw; 129 hw = &clk_gpio->hw;
@@ -151,7 +136,6 @@ static struct clk_hw *clk_register_gpio(struct device *dev, const char *name,
151 return hw; 136 return hw;
152 137
153 if (!dev) { 138 if (!dev) {
154 gpiod_put(clk_gpio->gpiod);
155 kfree(clk_gpio); 139 kfree(clk_gpio);
156 } 140 }
157 141
@@ -164,29 +148,27 @@ static struct clk_hw *clk_register_gpio(struct device *dev, const char *name,
164 * @dev: device that is registering this clock 148 * @dev: device that is registering this clock
165 * @name: name of this clock 149 * @name: name of this clock
166 * @parent_name: name of this clock's parent 150 * @parent_name: name of this clock's parent
167 * @gpio: gpio number to gate this clock 151 * @gpiod: gpio descriptor to gate this clock
168 * @active_low: true if gpio should be set to 0 to enable clock
169 * @flags: clock flags 152 * @flags: clock flags
170 */ 153 */
171struct clk_hw *clk_hw_register_gpio_gate(struct device *dev, const char *name, 154struct clk_hw *clk_hw_register_gpio_gate(struct device *dev, const char *name,
172 const char *parent_name, unsigned gpio, bool active_low, 155 const char *parent_name, struct gpio_desc *gpiod,
173 unsigned long flags) 156 unsigned long flags)
174{ 157{
175 return clk_register_gpio(dev, name, 158 return clk_register_gpio(dev, name,
176 (parent_name ? &parent_name : NULL), 159 (parent_name ? &parent_name : NULL),
177 (parent_name ? 1 : 0), gpio, active_low, flags, 160 (parent_name ? 1 : 0), gpiod, flags,
178 &clk_gpio_gate_ops); 161 &clk_gpio_gate_ops);
179} 162}
180EXPORT_SYMBOL_GPL(clk_hw_register_gpio_gate); 163EXPORT_SYMBOL_GPL(clk_hw_register_gpio_gate);
181 164
182struct clk *clk_register_gpio_gate(struct device *dev, const char *name, 165struct clk *clk_register_gpio_gate(struct device *dev, const char *name,
183 const char *parent_name, unsigned gpio, bool active_low, 166 const char *parent_name, struct gpio_desc *gpiod,
184 unsigned long flags) 167 unsigned long flags)
185{ 168{
186 struct clk_hw *hw; 169 struct clk_hw *hw;
187 170
188 hw = clk_hw_register_gpio_gate(dev, name, parent_name, gpio, active_low, 171 hw = clk_hw_register_gpio_gate(dev, name, parent_name, gpiod, flags);
189 flags);
190 if (IS_ERR(hw)) 172 if (IS_ERR(hw))
191 return ERR_CAST(hw); 173 return ERR_CAST(hw);
192 return hw->clk; 174 return hw->clk;
@@ -199,13 +181,12 @@ EXPORT_SYMBOL_GPL(clk_register_gpio_gate);
199 * @name: name of this clock 181 * @name: name of this clock
200 * @parent_names: names of this clock's parents 182 * @parent_names: names of this clock's parents
201 * @num_parents: number of parents listed in @parent_names 183 * @num_parents: number of parents listed in @parent_names
202 * @gpio: gpio number to gate this clock 184 * @gpiod: gpio descriptor to gate this clock
203 * @active_low: true if gpio should be set to 0 to enable clock
204 * @flags: clock flags 185 * @flags: clock flags
205 */ 186 */
206struct clk_hw *clk_hw_register_gpio_mux(struct device *dev, const char *name, 187struct clk_hw *clk_hw_register_gpio_mux(struct device *dev, const char *name,
207 const char * const *parent_names, u8 num_parents, unsigned gpio, 188 const char * const *parent_names, u8 num_parents, struct gpio_desc *gpiod,
208 bool active_low, unsigned long flags) 189 unsigned long flags)
209{ 190{
210 if (num_parents != 2) { 191 if (num_parents != 2) {
211 pr_err("mux-clock %s must have 2 parents\n", name); 192 pr_err("mux-clock %s must have 2 parents\n", name);
@@ -213,18 +194,18 @@ struct clk_hw *clk_hw_register_gpio_mux(struct device *dev, const char *name,
213 } 194 }
214 195
215 return clk_register_gpio(dev, name, parent_names, num_parents, 196 return clk_register_gpio(dev, name, parent_names, num_parents,
216 gpio, active_low, flags, &clk_gpio_mux_ops); 197 gpiod, flags, &clk_gpio_mux_ops);
217} 198}
218EXPORT_SYMBOL_GPL(clk_hw_register_gpio_mux); 199EXPORT_SYMBOL_GPL(clk_hw_register_gpio_mux);
219 200
220struct clk *clk_register_gpio_mux(struct device *dev, const char *name, 201struct clk *clk_register_gpio_mux(struct device *dev, const char *name,
221 const char * const *parent_names, u8 num_parents, unsigned gpio, 202 const char * const *parent_names, u8 num_parents, struct gpio_desc *gpiod,
222 bool active_low, unsigned long flags) 203 unsigned long flags)
223{ 204{
224 struct clk_hw *hw; 205 struct clk_hw *hw;
225 206
226 hw = clk_hw_register_gpio_mux(dev, name, parent_names, num_parents, 207 hw = clk_hw_register_gpio_mux(dev, name, parent_names, num_parents,
227 gpio, active_low, flags); 208 gpiod, flags);
228 if (IS_ERR(hw)) 209 if (IS_ERR(hw))
229 return ERR_CAST(hw); 210 return ERR_CAST(hw);
230 return hw->clk; 211 return hw->clk;
@@ -236,10 +217,10 @@ static int gpio_clk_driver_probe(struct platform_device *pdev)
236 struct device_node *node = pdev->dev.of_node; 217 struct device_node *node = pdev->dev.of_node;
237 const char **parent_names, *gpio_name; 218 const char **parent_names, *gpio_name;
238 unsigned int num_parents; 219 unsigned int num_parents;
239 int gpio; 220 struct gpio_desc *gpiod;
240 enum of_gpio_flags of_flags;
241 struct clk *clk; 221 struct clk *clk;
242 bool active_low, is_mux; 222 bool is_mux;
223 int ret;
243 224
244 num_parents = of_clk_get_parent_count(node); 225 num_parents = of_clk_get_parent_count(node);
245 if (num_parents) { 226 if (num_parents) {
@@ -255,28 +236,27 @@ static int gpio_clk_driver_probe(struct platform_device *pdev)
255 236
256 is_mux = of_device_is_compatible(node, "gpio-mux-clock"); 237 is_mux = of_device_is_compatible(node, "gpio-mux-clock");
257 238
258 gpio_name = is_mux ? "select-gpios" : "enable-gpios"; 239 gpio_name = is_mux ? "select" : "enable";
259 gpio = of_get_named_gpio_flags(node, gpio_name, 0, &of_flags); 240 gpiod = devm_gpiod_get(&pdev->dev, gpio_name, GPIOD_ASIS);
260 if (gpio < 0) { 241 if (IS_ERR(gpiod)) {
261 if (gpio == -EPROBE_DEFER) 242 ret = PTR_ERR(gpiod);
243 if (ret == -EPROBE_DEFER)
262 pr_debug("%s: %s: GPIOs not yet available, retry later\n", 244 pr_debug("%s: %s: GPIOs not yet available, retry later\n",
263 node->name, __func__); 245 node->name, __func__);
264 else 246 else
265 pr_err("%s: %s: Can't get '%s' DT property\n", 247 pr_err("%s: %s: Can't get '%s' named GPIO property\n",
266 node->name, __func__, 248 node->name, __func__,
267 gpio_name); 249 gpio_name);
268 return gpio; 250 return ret;
269 } 251 }
270 252
271 active_low = of_flags & OF_GPIO_ACTIVE_LOW;
272
273 if (is_mux) 253 if (is_mux)
274 clk = clk_register_gpio_mux(&pdev->dev, node->name, 254 clk = clk_register_gpio_mux(&pdev->dev, node->name,
275 parent_names, num_parents, gpio, active_low, 0); 255 parent_names, num_parents, gpiod, 0);
276 else 256 else
277 clk = clk_register_gpio_gate(&pdev->dev, node->name, 257 clk = clk_register_gpio_gate(&pdev->dev, node->name,
278 parent_names ? parent_names[0] : NULL, gpio, 258 parent_names ? parent_names[0] : NULL, gpiod,
279 active_low, 0); 259 0);
280 if (IS_ERR(clk)) 260 if (IS_ERR(clk))
281 return PTR_ERR(clk); 261 return PTR_ERR(clk);
282 262