diff options
| author | Stephen Boyd <sboyd@codeaurora.org> | 2017-11-14 13:07:45 -0500 |
|---|---|---|
| committer | Stephen Boyd <sboyd@codeaurora.org> | 2017-11-14 13:07:45 -0500 |
| commit | e8d07fd258a4ab8be7e85de44ffa2e362b49a743 (patch) | |
| tree | 46e32c10d1bbbb7aa247ead5bcf0f9d6f663e894 | |
| parent | 4c4fe1697162a211ded0ccdde4c78acbbe64b5e8 (diff) | |
| parent | 1b5d1a58a51324b1b6c851abec3bf40bd539cbb2 (diff) | |
Merge branch 'clk-gpio' into clk-next
* clk-gpio:
clk: clk-gpio: Request GPIO descriptor as LOW
clk: clk-gpio: Make GPIO clock provider use descriptors only
| -rw-r--r-- | drivers/clk/clk-gpio.c | 84 | ||||
| -rw-r--r-- | include/linux/clk-provider.h | 12 |
2 files changed, 34 insertions, 62 deletions
diff --git a/drivers/clk/clk-gpio.c b/drivers/clk/clk-gpio.c index 86b245746a6b..151513c655c3 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 = { | |||
| 95 | EXPORT_SYMBOL_GPL(clk_gpio_mux_ops); | 93 | EXPORT_SYMBOL_GPL(clk_gpio_mux_ops); |
| 96 | 94 | ||
| 97 | static struct clk_hw *clk_register_gpio(struct device *dev, const char *name, | 95 | static 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,32 +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) | ||
| 117 | gpio_flags = GPIOF_ACTIVE_LOW | GPIOF_OUT_INIT_HIGH; | ||
| 118 | else | ||
| 119 | gpio_flags = GPIOF_OUT_INIT_LOW; | ||
| 120 | |||
| 121 | if (dev) | ||
| 122 | err = devm_gpio_request_one(dev, gpio, gpio_flags, name); | ||
| 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 | |||
| 135 | init.name = name; | 112 | init.name = name; |
| 136 | init.ops = clk_gpio_ops; | 113 | init.ops = clk_gpio_ops; |
| 137 | init.flags = flags | CLK_IS_BASIC; | 114 | init.flags = flags | CLK_IS_BASIC; |
| 138 | init.parent_names = parent_names; | 115 | init.parent_names = parent_names; |
| 139 | init.num_parents = num_parents; | 116 | init.num_parents = num_parents; |
| 140 | 117 | ||
| 141 | clk_gpio->gpiod = gpio_to_desc(gpio); | 118 | clk_gpio->gpiod = gpiod; |
| 142 | clk_gpio->hw.init = &init; | 119 | clk_gpio->hw.init = &init; |
| 143 | 120 | ||
| 144 | hw = &clk_gpio->hw; | 121 | hw = &clk_gpio->hw; |
| @@ -151,7 +128,6 @@ static struct clk_hw *clk_register_gpio(struct device *dev, const char *name, | |||
| 151 | return hw; | 128 | return hw; |
| 152 | 129 | ||
| 153 | if (!dev) { | 130 | if (!dev) { |
| 154 | gpiod_put(clk_gpio->gpiod); | ||
| 155 | kfree(clk_gpio); | 131 | kfree(clk_gpio); |
| 156 | } | 132 | } |
| 157 | 133 | ||
| @@ -164,29 +140,27 @@ static struct clk_hw *clk_register_gpio(struct device *dev, const char *name, | |||
| 164 | * @dev: device that is registering this clock | 140 | * @dev: device that is registering this clock |
| 165 | * @name: name of this clock | 141 | * @name: name of this clock |
| 166 | * @parent_name: name of this clock's parent | 142 | * @parent_name: name of this clock's parent |
| 167 | * @gpio: gpio number to gate this clock | 143 | * @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 | 144 | * @flags: clock flags |
| 170 | */ | 145 | */ |
| 171 | struct clk_hw *clk_hw_register_gpio_gate(struct device *dev, const char *name, | 146 | struct clk_hw *clk_hw_register_gpio_gate(struct device *dev, const char *name, |
| 172 | const char *parent_name, unsigned gpio, bool active_low, | 147 | const char *parent_name, struct gpio_desc *gpiod, |
| 173 | unsigned long flags) | 148 | unsigned long flags) |
| 174 | { | 149 | { |
| 175 | return clk_register_gpio(dev, name, | 150 | return clk_register_gpio(dev, name, |
| 176 | (parent_name ? &parent_name : NULL), | 151 | (parent_name ? &parent_name : NULL), |
| 177 | (parent_name ? 1 : 0), gpio, active_low, flags, | 152 | (parent_name ? 1 : 0), gpiod, flags, |
| 178 | &clk_gpio_gate_ops); | 153 | &clk_gpio_gate_ops); |
| 179 | } | 154 | } |
| 180 | EXPORT_SYMBOL_GPL(clk_hw_register_gpio_gate); | 155 | EXPORT_SYMBOL_GPL(clk_hw_register_gpio_gate); |
| 181 | 156 | ||
| 182 | struct clk *clk_register_gpio_gate(struct device *dev, const char *name, | 157 | struct clk *clk_register_gpio_gate(struct device *dev, const char *name, |
| 183 | const char *parent_name, unsigned gpio, bool active_low, | 158 | const char *parent_name, struct gpio_desc *gpiod, |
| 184 | unsigned long flags) | 159 | unsigned long flags) |
| 185 | { | 160 | { |
| 186 | struct clk_hw *hw; | 161 | struct clk_hw *hw; |
| 187 | 162 | ||
| 188 | hw = clk_hw_register_gpio_gate(dev, name, parent_name, gpio, active_low, | 163 | hw = clk_hw_register_gpio_gate(dev, name, parent_name, gpiod, flags); |
| 189 | flags); | ||
| 190 | if (IS_ERR(hw)) | 164 | if (IS_ERR(hw)) |
| 191 | return ERR_CAST(hw); | 165 | return ERR_CAST(hw); |
| 192 | return hw->clk; | 166 | return hw->clk; |
| @@ -199,13 +173,12 @@ EXPORT_SYMBOL_GPL(clk_register_gpio_gate); | |||
| 199 | * @name: name of this clock | 173 | * @name: name of this clock |
| 200 | * @parent_names: names of this clock's parents | 174 | * @parent_names: names of this clock's parents |
| 201 | * @num_parents: number of parents listed in @parent_names | 175 | * @num_parents: number of parents listed in @parent_names |
| 202 | * @gpio: gpio number to gate this clock | 176 | * @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 | 177 | * @flags: clock flags |
| 205 | */ | 178 | */ |
| 206 | struct clk_hw *clk_hw_register_gpio_mux(struct device *dev, const char *name, | 179 | struct clk_hw *clk_hw_register_gpio_mux(struct device *dev, const char *name, |
| 207 | const char * const *parent_names, u8 num_parents, unsigned gpio, | 180 | const char * const *parent_names, u8 num_parents, struct gpio_desc *gpiod, |
| 208 | bool active_low, unsigned long flags) | 181 | unsigned long flags) |
| 209 | { | 182 | { |
| 210 | if (num_parents != 2) { | 183 | if (num_parents != 2) { |
| 211 | pr_err("mux-clock %s must have 2 parents\n", name); | 184 | pr_err("mux-clock %s must have 2 parents\n", name); |
| @@ -213,18 +186,18 @@ struct clk_hw *clk_hw_register_gpio_mux(struct device *dev, const char *name, | |||
| 213 | } | 186 | } |
| 214 | 187 | ||
| 215 | return clk_register_gpio(dev, name, parent_names, num_parents, | 188 | return clk_register_gpio(dev, name, parent_names, num_parents, |
| 216 | gpio, active_low, flags, &clk_gpio_mux_ops); | 189 | gpiod, flags, &clk_gpio_mux_ops); |
| 217 | } | 190 | } |
| 218 | EXPORT_SYMBOL_GPL(clk_hw_register_gpio_mux); | 191 | EXPORT_SYMBOL_GPL(clk_hw_register_gpio_mux); |
| 219 | 192 | ||
| 220 | struct clk *clk_register_gpio_mux(struct device *dev, const char *name, | 193 | struct clk *clk_register_gpio_mux(struct device *dev, const char *name, |
| 221 | const char * const *parent_names, u8 num_parents, unsigned gpio, | 194 | const char * const *parent_names, u8 num_parents, struct gpio_desc *gpiod, |
| 222 | bool active_low, unsigned long flags) | 195 | unsigned long flags) |
| 223 | { | 196 | { |
| 224 | struct clk_hw *hw; | 197 | struct clk_hw *hw; |
| 225 | 198 | ||
| 226 | hw = clk_hw_register_gpio_mux(dev, name, parent_names, num_parents, | 199 | hw = clk_hw_register_gpio_mux(dev, name, parent_names, num_parents, |
| 227 | gpio, active_low, flags); | 200 | gpiod, flags); |
| 228 | if (IS_ERR(hw)) | 201 | if (IS_ERR(hw)) |
| 229 | return ERR_CAST(hw); | 202 | return ERR_CAST(hw); |
| 230 | return hw->clk; | 203 | return hw->clk; |
| @@ -236,10 +209,10 @@ static int gpio_clk_driver_probe(struct platform_device *pdev) | |||
| 236 | struct device_node *node = pdev->dev.of_node; | 209 | struct device_node *node = pdev->dev.of_node; |
| 237 | const char **parent_names, *gpio_name; | 210 | const char **parent_names, *gpio_name; |
| 238 | unsigned int num_parents; | 211 | unsigned int num_parents; |
| 239 | int gpio; | 212 | struct gpio_desc *gpiod; |
| 240 | enum of_gpio_flags of_flags; | ||
| 241 | struct clk *clk; | 213 | struct clk *clk; |
| 242 | bool active_low, is_mux; | 214 | bool is_mux; |
| 215 | int ret; | ||
| 243 | 216 | ||
| 244 | num_parents = of_clk_get_parent_count(node); | 217 | num_parents = of_clk_get_parent_count(node); |
| 245 | if (num_parents) { | 218 | if (num_parents) { |
| @@ -255,28 +228,27 @@ static int gpio_clk_driver_probe(struct platform_device *pdev) | |||
| 255 | 228 | ||
| 256 | is_mux = of_device_is_compatible(node, "gpio-mux-clock"); | 229 | is_mux = of_device_is_compatible(node, "gpio-mux-clock"); |
| 257 | 230 | ||
| 258 | gpio_name = is_mux ? "select-gpios" : "enable-gpios"; | 231 | gpio_name = is_mux ? "select" : "enable"; |
| 259 | gpio = of_get_named_gpio_flags(node, gpio_name, 0, &of_flags); | 232 | gpiod = devm_gpiod_get(&pdev->dev, gpio_name, GPIOD_OUT_LOW); |
