Loading drivers/clk/clk-gpio.c +28 −56 Original line number Original line Diff line number Diff line Loading @@ -15,9 +15,7 @@ #include <linux/clk-provider.h> #include <linux/clk-provider.h> #include <linux/export.h> #include <linux/export.h> #include <linux/slab.h> #include <linux/slab.h> #include <linux/gpio.h> #include <linux/gpio/consumer.h> #include <linux/gpio/consumer.h> #include <linux/of_gpio.h> #include <linux/err.h> #include <linux/err.h> #include <linux/device.h> #include <linux/device.h> #include <linux/platform_device.h> #include <linux/platform_device.h> Loading Loading @@ -95,14 +93,12 @@ const struct clk_ops clk_gpio_mux_ops = { EXPORT_SYMBOL_GPL(clk_gpio_mux_ops); EXPORT_SYMBOL_GPL(clk_gpio_mux_ops); static struct clk_hw *clk_register_gpio(struct device *dev, const char *name, static struct clk_hw *clk_register_gpio(struct device *dev, const char *name, const char * const *parent_names, u8 num_parents, unsigned gpio, const char * const *parent_names, u8 num_parents, struct gpio_desc *gpiod, bool active_low, unsigned long flags, unsigned long flags, const struct clk_ops *clk_gpio_ops) const struct clk_ops *clk_gpio_ops) { { struct clk_gpio *clk_gpio; struct clk_gpio *clk_gpio; struct clk_hw *hw; struct clk_hw *hw; struct clk_init_data init = {}; struct clk_init_data init = {}; unsigned long gpio_flags; int err; int err; if (dev) if (dev) Loading @@ -113,32 +109,13 @@ static struct clk_hw *clk_register_gpio(struct device *dev, const char *name, if (!clk_gpio) if (!clk_gpio) return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM); if (active_low) gpio_flags = GPIOF_ACTIVE_LOW | GPIOF_OUT_INIT_HIGH; else gpio_flags = GPIOF_OUT_INIT_LOW; if (dev) err = devm_gpio_request_one(dev, gpio, gpio_flags, name); else err = gpio_request_one(gpio, gpio_flags, name); if (err) { if (err != -EPROBE_DEFER) pr_err("%s: %s: Error requesting clock control gpio %u\n", __func__, name, gpio); if (!dev) kfree(clk_gpio); return ERR_PTR(err); } init.name = name; init.name = name; init.ops = clk_gpio_ops; init.ops = clk_gpio_ops; init.flags = flags | CLK_IS_BASIC; init.flags = flags | CLK_IS_BASIC; init.parent_names = parent_names; init.parent_names = parent_names; init.num_parents = num_parents; init.num_parents = num_parents; clk_gpio->gpiod = gpio_to_desc(gpio); clk_gpio->gpiod = gpiod; clk_gpio->hw.init = &init; clk_gpio->hw.init = &init; hw = &clk_gpio->hw; hw = &clk_gpio->hw; Loading @@ -151,7 +128,6 @@ static struct clk_hw *clk_register_gpio(struct device *dev, const char *name, return hw; return hw; if (!dev) { if (!dev) { gpiod_put(clk_gpio->gpiod); kfree(clk_gpio); kfree(clk_gpio); } } Loading @@ -164,29 +140,27 @@ static struct clk_hw *clk_register_gpio(struct device *dev, const char *name, * @dev: device that is registering this clock * @dev: device that is registering this clock * @name: name of this clock * @name: name of this clock * @parent_name: name of this clock's parent * @parent_name: name of this clock's parent * @gpio: gpio number to gate this clock * @gpiod: gpio descriptor to gate this clock * @active_low: true if gpio should be set to 0 to enable clock * @flags: clock flags * @flags: clock flags */ */ struct clk_hw *clk_hw_register_gpio_gate(struct device *dev, const char *name, struct clk_hw *clk_hw_register_gpio_gate(struct device *dev, const char *name, const char *parent_name, unsigned gpio, bool active_low, const char *parent_name, struct gpio_desc *gpiod, unsigned long flags) unsigned long flags) { { return clk_register_gpio(dev, name, return clk_register_gpio(dev, name, (parent_name ? &parent_name : NULL), (parent_name ? &parent_name : NULL), (parent_name ? 1 : 0), gpio, active_low, flags, (parent_name ? 1 : 0), gpiod, flags, &clk_gpio_gate_ops); &clk_gpio_gate_ops); } } EXPORT_SYMBOL_GPL(clk_hw_register_gpio_gate); EXPORT_SYMBOL_GPL(clk_hw_register_gpio_gate); struct clk *clk_register_gpio_gate(struct device *dev, const char *name, struct clk *clk_register_gpio_gate(struct device *dev, const char *name, const char *parent_name, unsigned gpio, bool active_low, const char *parent_name, struct gpio_desc *gpiod, unsigned long flags) unsigned long flags) { { struct clk_hw *hw; struct clk_hw *hw; hw = clk_hw_register_gpio_gate(dev, name, parent_name, gpio, active_low, hw = clk_hw_register_gpio_gate(dev, name, parent_name, gpiod, flags); flags); if (IS_ERR(hw)) if (IS_ERR(hw)) return ERR_CAST(hw); return ERR_CAST(hw); return hw->clk; return hw->clk; Loading @@ -199,13 +173,12 @@ EXPORT_SYMBOL_GPL(clk_register_gpio_gate); * @name: name of this clock * @name: name of this clock * @parent_names: names of this clock's parents * @parent_names: names of this clock's parents * @num_parents: number of parents listed in @parent_names * @num_parents: number of parents listed in @parent_names * @gpio: gpio number to gate this clock * @gpiod: gpio descriptor to gate this clock * @active_low: true if gpio should be set to 0 to enable clock * @flags: clock flags * @flags: clock flags */ */ struct clk_hw *clk_hw_register_gpio_mux(struct device *dev, const char *name, struct clk_hw *clk_hw_register_gpio_mux(struct device *dev, const char *name, const char * const *parent_names, u8 num_parents, unsigned gpio, const char * const *parent_names, u8 num_parents, struct gpio_desc *gpiod, bool active_low, unsigned long flags) unsigned long flags) { { if (num_parents != 2) { if (num_parents != 2) { pr_err("mux-clock %s must have 2 parents\n", name); pr_err("mux-clock %s must have 2 parents\n", name); Loading @@ -213,18 +186,18 @@ struct clk_hw *clk_hw_register_gpio_mux(struct device *dev, const char *name, } } return clk_register_gpio(dev, name, parent_names, num_parents, return clk_register_gpio(dev, name, parent_names, num_parents, gpio, active_low, flags, &clk_gpio_mux_ops); gpiod, flags, &clk_gpio_mux_ops); } } EXPORT_SYMBOL_GPL(clk_hw_register_gpio_mux); EXPORT_SYMBOL_GPL(clk_hw_register_gpio_mux); struct clk *clk_register_gpio_mux(struct device *dev, const char *name, struct clk *clk_register_gpio_mux(struct device *dev, const char *name, const char * const *parent_names, u8 num_parents, unsigned gpio, const char * const *parent_names, u8 num_parents, struct gpio_desc *gpiod, bool active_low, unsigned long flags) unsigned long flags) { { struct clk_hw *hw; struct clk_hw *hw; hw = clk_hw_register_gpio_mux(dev, name, parent_names, num_parents, hw = clk_hw_register_gpio_mux(dev, name, parent_names, num_parents, gpio, active_low, flags); gpiod, flags); if (IS_ERR(hw)) if (IS_ERR(hw)) return ERR_CAST(hw); return ERR_CAST(hw); return hw->clk; return hw->clk; Loading @@ -236,10 +209,10 @@ static int gpio_clk_driver_probe(struct platform_device *pdev) struct device_node *node = pdev->dev.of_node; struct device_node *node = pdev->dev.of_node; const char **parent_names, *gpio_name; const char **parent_names, *gpio_name; unsigned int num_parents; unsigned int num_parents; int gpio; struct gpio_desc *gpiod; enum of_gpio_flags of_flags; struct clk *clk; struct clk *clk; bool active_low, is_mux; bool is_mux; int ret; num_parents = of_clk_get_parent_count(node); num_parents = of_clk_get_parent_count(node); if (num_parents) { if (num_parents) { Loading @@ -255,28 +228,27 @@ static int gpio_clk_driver_probe(struct platform_device *pdev) is_mux = of_device_is_compatible(node, "gpio-mux-clock"); is_mux = of_device_is_compatible(node, "gpio-mux-clock"); gpio_name = is_mux ? "select-gpios" : "enable-gpios"; gpio_name = is_mux ? "select" : "enable"; gpio = of_get_named_gpio_flags(node, gpio_name, 0, &of_flags); gpiod = devm_gpiod_get(&pdev->dev, gpio_name, GPIOD_OUT_LOW); if (gpio < 0) { if (IS_ERR(gpiod)) { if (gpio == -EPROBE_DEFER) ret = PTR_ERR(gpiod); if (ret == -EPROBE_DEFER) pr_debug("%s: %s: GPIOs not yet available, retry later\n", pr_debug("%s: %s: GPIOs not yet available, retry later\n", node->name, __func__); node->name, __func__); else else pr_err("%s: %s: Can't get '%s' DT property\n", pr_err("%s: %s: Can't get '%s' named GPIO property\n", node->name, __func__, node->name, __func__, gpio_name); gpio_name); return gpio; return ret; } } active_low = of_flags & OF_GPIO_ACTIVE_LOW; if (is_mux) if (is_mux) clk = clk_register_gpio_mux(&pdev->dev, node->name, clk = clk_register_gpio_mux(&pdev->dev, node->name, parent_names, num_parents, gpio, active_low, 0); parent_names, num_parents, gpiod, 0); else else clk = clk_register_gpio_gate(&pdev->dev, node->name, clk = clk_register_gpio_gate(&pdev->dev, node->name, parent_names ? parent_names[0] : NULL, gpio, parent_names ? parent_names[0] : NULL, gpiod, active_low, 0); 0); if (IS_ERR(clk)) if (IS_ERR(clk)) return PTR_ERR(clk); return PTR_ERR(clk); Loading include/linux/clk-provider.h +6 −6 Original line number Original line Diff line number Diff line Loading @@ -682,10 +682,10 @@ struct clk_gpio { extern const struct clk_ops clk_gpio_gate_ops; extern const struct clk_ops clk_gpio_gate_ops; struct clk *clk_register_gpio_gate(struct device *dev, const char *name, struct clk *clk_register_gpio_gate(struct device *dev, const char *name, const char *parent_name, unsigned gpio, bool active_low, const char *parent_name, struct gpio_desc *gpiod, unsigned long flags); unsigned long flags); struct clk_hw *clk_hw_register_gpio_gate(struct device *dev, const char *name, struct clk_hw *clk_hw_register_gpio_gate(struct device *dev, const char *name, const char *parent_name, unsigned gpio, bool active_low, const char *parent_name, struct gpio_desc *gpiod, unsigned long flags); unsigned long flags); void clk_hw_unregister_gpio_gate(struct clk_hw *hw); void clk_hw_unregister_gpio_gate(struct clk_hw *hw); Loading @@ -701,11 +701,11 @@ void clk_hw_unregister_gpio_gate(struct clk_hw *hw); extern const struct clk_ops clk_gpio_mux_ops; extern const struct clk_ops clk_gpio_mux_ops; struct clk *clk_register_gpio_mux(struct device *dev, const char *name, struct clk *clk_register_gpio_mux(struct device *dev, const char *name, const char * const *parent_names, u8 num_parents, unsigned gpio, const char * const *parent_names, u8 num_parents, struct gpio_desc *gpiod, bool active_low, unsigned long flags); unsigned long flags); struct clk_hw *clk_hw_register_gpio_mux(struct device *dev, const char *name, struct clk_hw *clk_hw_register_gpio_mux(struct device *dev, const char *name, const char * const *parent_names, u8 num_parents, unsigned gpio, const char * const *parent_names, u8 num_parents, struct gpio_desc *gpiod, bool active_low, unsigned long flags); unsigned long flags); void clk_hw_unregister_gpio_mux(struct clk_hw *hw); void clk_hw_unregister_gpio_mux(struct clk_hw *hw); /** /** Loading Loading
drivers/clk/clk-gpio.c +28 −56 Original line number Original line Diff line number Diff line Loading @@ -15,9 +15,7 @@ #include <linux/clk-provider.h> #include <linux/clk-provider.h> #include <linux/export.h> #include <linux/export.h> #include <linux/slab.h> #include <linux/slab.h> #include <linux/gpio.h> #include <linux/gpio/consumer.h> #include <linux/gpio/consumer.h> #include <linux/of_gpio.h> #include <linux/err.h> #include <linux/err.h> #include <linux/device.h> #include <linux/device.h> #include <linux/platform_device.h> #include <linux/platform_device.h> Loading Loading @@ -95,14 +93,12 @@ const struct clk_ops clk_gpio_mux_ops = { EXPORT_SYMBOL_GPL(clk_gpio_mux_ops); EXPORT_SYMBOL_GPL(clk_gpio_mux_ops); static struct clk_hw *clk_register_gpio(struct device *dev, const char *name, static struct clk_hw *clk_register_gpio(struct device *dev, const char *name, const char * const *parent_names, u8 num_parents, unsigned gpio, const char * const *parent_names, u8 num_parents, struct gpio_desc *gpiod, bool active_low, unsigned long flags, unsigned long flags, const struct clk_ops *clk_gpio_ops) const struct clk_ops *clk_gpio_ops) { { struct clk_gpio *clk_gpio; struct clk_gpio *clk_gpio; struct clk_hw *hw; struct clk_hw *hw; struct clk_init_data init = {}; struct clk_init_data init = {}; unsigned long gpio_flags; int err; int err; if (dev) if (dev) Loading @@ -113,32 +109,13 @@ static struct clk_hw *clk_register_gpio(struct device *dev, const char *name, if (!clk_gpio) if (!clk_gpio) return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM); if (active_low) gpio_flags = GPIOF_ACTIVE_LOW | GPIOF_OUT_INIT_HIGH; else gpio_flags = GPIOF_OUT_INIT_LOW; if (dev) err = devm_gpio_request_one(dev, gpio, gpio_flags, name); else err = gpio_request_one(gpio, gpio_flags, name); if (err) { if (err != -EPROBE_DEFER) pr_err("%s: %s: Error requesting clock control gpio %u\n", __func__, name, gpio); if (!dev) kfree(clk_gpio); return ERR_PTR(err); } init.name = name; init.name = name; init.ops = clk_gpio_ops; init.ops = clk_gpio_ops; init.flags = flags | CLK_IS_BASIC; init.flags = flags | CLK_IS_BASIC; init.parent_names = parent_names; init.parent_names = parent_names; init.num_parents = num_parents; init.num_parents = num_parents; clk_gpio->gpiod = gpio_to_desc(gpio); clk_gpio->gpiod = gpiod; clk_gpio->hw.init = &init; clk_gpio->hw.init = &init; hw = &clk_gpio->hw; hw = &clk_gpio->hw; Loading @@ -151,7 +128,6 @@ static struct clk_hw *clk_register_gpio(struct device *dev, const char *name, return hw; return hw; if (!dev) { if (!dev) { gpiod_put(clk_gpio->gpiod); kfree(clk_gpio); kfree(clk_gpio); } } Loading @@ -164,29 +140,27 @@ static struct clk_hw *clk_register_gpio(struct device *dev, const char *name, * @dev: device that is registering this clock * @dev: device that is registering this clock * @name: name of this clock * @name: name of this clock * @parent_name: name of this clock's parent * @parent_name: name of this clock's parent * @gpio: gpio number to gate this clock * @gpiod: gpio descriptor to gate this clock * @active_low: true if gpio should be set to 0 to enable clock * @flags: clock flags * @flags: clock flags */ */ struct clk_hw *clk_hw_register_gpio_gate(struct device *dev, const char *name, struct clk_hw *clk_hw_register_gpio_gate(struct device *dev, const char *name, const char *parent_name, unsigned gpio, bool active_low, const char *parent_name, struct gpio_desc *gpiod, unsigned long flags) unsigned long flags) { { return clk_register_gpio(dev, name, return clk_register_gpio(dev, name, (parent_name ? &parent_name : NULL), (parent_name ? &parent_name : NULL), (parent_name ? 1 : 0), gpio, active_low, flags, (parent_name ? 1 : 0), gpiod, flags, &clk_gpio_gate_ops); &clk_gpio_gate_ops); } } EXPORT_SYMBOL_GPL(clk_hw_register_gpio_gate); EXPORT_SYMBOL_GPL(clk_hw_register_gpio_gate); struct clk *clk_register_gpio_gate(struct device *dev, const char *name, struct clk *clk_register_gpio_gate(struct device *dev, const char *name, const char *parent_name, unsigned gpio, bool active_low, const char *parent_name, struct gpio_desc *gpiod, unsigned long flags) unsigned long flags) { { struct clk_hw *hw; struct clk_hw *hw; hw = clk_hw_register_gpio_gate(dev, name, parent_name, gpio, active_low, hw = clk_hw_register_gpio_gate(dev, name, parent_name, gpiod, flags); flags); if (IS_ERR(hw)) if (IS_ERR(hw)) return ERR_CAST(hw); return ERR_CAST(hw); return hw->clk; return hw->clk; Loading @@ -199,13 +173,12 @@ EXPORT_SYMBOL_GPL(clk_register_gpio_gate); * @name: name of this clock * @name: name of this clock * @parent_names: names of this clock's parents * @parent_names: names of this clock's parents * @num_parents: number of parents listed in @parent_names * @num_parents: number of parents listed in @parent_names * @gpio: gpio number to gate this clock * @gpiod: gpio descriptor to gate this clock * @active_low: true if gpio should be set to 0 to enable clock * @flags: clock flags * @flags: clock flags */ */ struct clk_hw *clk_hw_register_gpio_mux(struct device *dev, const char *name, struct clk_hw *clk_hw_register_gpio_mux(struct device *dev, const char *name, const char * const *parent_names, u8 num_parents, unsigned gpio, const char * const *parent_names, u8 num_parents, struct gpio_desc *gpiod, bool active_low, unsigned long flags) unsigned long flags) { { if (num_parents != 2) { if (num_parents != 2) { pr_err("mux-clock %s must have 2 parents\n", name); pr_err("mux-clock %s must have 2 parents\n", name); Loading @@ -213,18 +186,18 @@ struct clk_hw *clk_hw_register_gpio_mux(struct device *dev, const char *name, } } return clk_register_gpio(dev, name, parent_names, num_parents, return clk_register_gpio(dev, name, parent_names, num_parents, gpio, active_low, flags, &clk_gpio_mux_ops); gpiod, flags, &clk_gpio_mux_ops); } } EXPORT_SYMBOL_GPL(clk_hw_register_gpio_mux); EXPORT_SYMBOL_GPL(clk_hw_register_gpio_mux); struct clk *clk_register_gpio_mux(struct device *dev, const char *name, struct clk *clk_register_gpio_mux(struct device *dev, const char *name, const char * const *parent_names, u8 num_parents, unsigned gpio, const char * const *parent_names, u8 num_parents, struct gpio_desc *gpiod, bool active_low, unsigned long flags) unsigned long flags) { { struct clk_hw *hw; struct clk_hw *hw; hw = clk_hw_register_gpio_mux(dev, name, parent_names, num_parents, hw = clk_hw_register_gpio_mux(dev, name, parent_names, num_parents, gpio, active_low, flags); gpiod, flags); if (IS_ERR(hw)) if (IS_ERR(hw)) return ERR_CAST(hw); return ERR_CAST(hw); return hw->clk; return hw->clk; Loading @@ -236,10 +209,10 @@ static int gpio_clk_driver_probe(struct platform_device *pdev) struct device_node *node = pdev->dev.of_node; struct device_node *node = pdev->dev.of_node; const char **parent_names, *gpio_name; const char **parent_names, *gpio_name; unsigned int num_parents; unsigned int num_parents; int gpio; struct gpio_desc *gpiod; enum of_gpio_flags of_flags; struct clk *clk; struct clk *clk; bool active_low, is_mux; bool is_mux; int ret; num_parents = of_clk_get_parent_count(node); num_parents = of_clk_get_parent_count(node); if (num_parents) { if (num_parents) { Loading @@ -255,28 +228,27 @@ static int gpio_clk_driver_probe(struct platform_device *pdev) is_mux = of_device_is_compatible(node, "gpio-mux-clock"); is_mux = of_device_is_compatible(node, "gpio-mux-clock"); gpio_name = is_mux ? "select-gpios" : "enable-gpios"; gpio_name = is_mux ? "select" : "enable"; gpio = of_get_named_gpio_flags(node, gpio_name, 0, &of_flags); gpiod = devm_gpiod_get(&pdev->dev, gpio_name, GPIOD_OUT_LOW); if (gpio < 0) { if (IS_ERR(gpiod)) { if (gpio == -EPROBE_DEFER) ret = PTR_ERR(gpiod); if (ret == -EPROBE_DEFER) pr_debug("%s: %s: GPIOs not yet available, retry later\n", pr_debug("%s: %s: GPIOs not yet available, retry later\n", node->name, __func__); node->name, __func__); else else pr_err("%s: %s: Can't get '%s' DT property\n", pr_err("%s: %s: Can't get '%s' named GPIO property\n", node->name, __func__, node->name, __func__, gpio_name); gpio_name); return gpio; return ret; } } active_low = of_flags & OF_GPIO_ACTIVE_LOW; if (is_mux) if (is_mux) clk = clk_register_gpio_mux(&pdev->dev, node->name, clk = clk_register_gpio_mux(&pdev->dev, node->name, parent_names, num_parents, gpio, active_low, 0); parent_names, num_parents, gpiod, 0); else else clk = clk_register_gpio_gate(&pdev->dev, node->name, clk = clk_register_gpio_gate(&pdev->dev, node->name, parent_names ? parent_names[0] : NULL, gpio, parent_names ? parent_names[0] : NULL, gpiod, active_low, 0); 0); if (IS_ERR(clk)) if (IS_ERR(clk)) return PTR_ERR(clk); return PTR_ERR(clk); Loading
include/linux/clk-provider.h +6 −6 Original line number Original line Diff line number Diff line Loading @@ -682,10 +682,10 @@ struct clk_gpio { extern const struct clk_ops clk_gpio_gate_ops; extern const struct clk_ops clk_gpio_gate_ops; struct clk *clk_register_gpio_gate(struct device *dev, const char *name, struct clk *clk_register_gpio_gate(struct device *dev, const char *name, const char *parent_name, unsigned gpio, bool active_low, const char *parent_name, struct gpio_desc *gpiod, unsigned long flags); unsigned long flags); struct clk_hw *clk_hw_register_gpio_gate(struct device *dev, const char *name, struct clk_hw *clk_hw_register_gpio_gate(struct device *dev, const char *name, const char *parent_name, unsigned gpio, bool active_low, const char *parent_name, struct gpio_desc *gpiod, unsigned long flags); unsigned long flags); void clk_hw_unregister_gpio_gate(struct clk_hw *hw); void clk_hw_unregister_gpio_gate(struct clk_hw *hw); Loading @@ -701,11 +701,11 @@ void clk_hw_unregister_gpio_gate(struct clk_hw *hw); extern const struct clk_ops clk_gpio_mux_ops; extern const struct clk_ops clk_gpio_mux_ops; struct clk *clk_register_gpio_mux(struct device *dev, const char *name, struct clk *clk_register_gpio_mux(struct device *dev, const char *name, const char * const *parent_names, u8 num_parents, unsigned gpio, const char * const *parent_names, u8 num_parents, struct gpio_desc *gpiod, bool active_low, unsigned long flags); unsigned long flags); struct clk_hw *clk_hw_register_gpio_mux(struct device *dev, const char *name, struct clk_hw *clk_hw_register_gpio_mux(struct device *dev, const char *name, const char * const *parent_names, u8 num_parents, unsigned gpio, const char * const *parent_names, u8 num_parents, struct gpio_desc *gpiod, bool active_low, unsigned long flags); unsigned long flags); void clk_hw_unregister_gpio_mux(struct clk_hw *hw); void clk_hw_unregister_gpio_mux(struct clk_hw *hw); /** /** Loading