diff options
Diffstat (limited to 'drivers/clk/clk-gpio.c')
-rw-r--r-- | drivers/clk/clk-gpio.c | 65 |
1 files changed, 28 insertions, 37 deletions
diff --git a/drivers/clk/clk-gpio.c b/drivers/clk/clk-gpio.c index 352c85dfe2..940a20523e 100644 --- a/drivers/clk/clk-gpio.c +++ b/drivers/clk/clk-gpio.c @@ -1,19 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * clk-gpio.c - clock that can be enabled and disabled via GPIO output * Based on Linux clk support * * Copyright (c) 2018 Nikita Yushchenko <nikita.yoush@cogentembedded.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * */ #include <common.h> #include <malloc.h> @@ -24,30 +14,30 @@ #include <init.h> struct clk_gpio { - struct clk clk; + struct clk_hw hw; const char *parent; int gpio; }; -#define to_clk_gpio(_clk) container_of(_clk, struct clk_gpio, clk) +#define to_clk_gpio(_hw) container_of(_hw, struct clk_gpio, hw) -static int clk_gpio_enable(struct clk *clk) +static int clk_gpio_enable(struct clk_hw *hw) { - struct clk_gpio *clk_gpio = to_clk_gpio(clk); + struct clk_gpio *clk_gpio = to_clk_gpio(hw); gpio_set_active(clk_gpio->gpio, true); return 0; } -static void clk_gpio_disable(struct clk *clk) +static void clk_gpio_disable(struct clk_hw *hw) { - struct clk_gpio *clk_gpio = to_clk_gpio(clk); + struct clk_gpio *clk_gpio = to_clk_gpio(hw); gpio_set_active(clk_gpio->gpio, false); } -static int clk_gpio_is_enabled(struct clk *clk) +static int clk_gpio_is_enabled(struct clk_hw *hw) { - struct clk_gpio *clk_gpio = to_clk_gpio(clk); + struct clk_gpio *clk_gpio = to_clk_gpio(hw); return gpio_is_active(clk_gpio->gpio); } @@ -60,8 +50,9 @@ static struct clk_ops clk_gpio_ops = { .is_enabled = clk_gpio_is_enabled, }; -static int of_gpio_clk_setup(struct device_node *node) +static int of_gpio_clk_probe(struct device *dev) { + struct device_node *node = dev->device_node; struct clk_gpio *clk_gpio; enum of_gpio_flags of_flags; unsigned long flags; @@ -77,13 +68,13 @@ static int of_gpio_clk_setup(struct device_node *node) goto no_parent; } - clk_gpio->clk.ops = &clk_gpio_ops; - clk_gpio->clk.parent_names = &clk_gpio->parent; - clk_gpio->clk.num_parents = 1; + clk_gpio->hw.clk.ops = &clk_gpio_ops; + clk_gpio->hw.clk.parent_names = &clk_gpio->parent; + clk_gpio->hw.clk.num_parents = 1; - clk_gpio->clk.name = node->name; + clk_gpio->hw.clk.name = node->name; of_property_read_string(node, "clock-output-names", - &clk_gpio->clk.name); + &clk_gpio->hw.clk.name); ret = of_get_named_gpio_flags(node, "enable-gpios", 0, &of_flags); @@ -96,15 +87,15 @@ static int of_gpio_clk_setup(struct device_node *node) flags = GPIOF_OUT_INIT_ACTIVE; if (of_flags & OF_GPIO_ACTIVE_LOW) flags |= GPIOF_ACTIVE_LOW; - ret = gpio_request_one(clk_gpio->gpio, flags, clk_gpio->clk.name); + ret = gpio_request_one(clk_gpio->gpio, flags, clk_gpio->hw.clk.name); if (ret) goto no_request; - ret = clk_register(&clk_gpio->clk); + ret = bclk_register(&clk_gpio->hw.clk); if (ret) goto no_register; - return of_clk_add_provider(node, of_clk_src_simple_get, &clk_gpio->clk); + return of_clk_add_provider(node, of_clk_src_simple_get, &clk_gpio->hw.clk); no_register: gpio_free(clk_gpio->gpio); @@ -115,16 +106,16 @@ no_parent: return ret; } -/* Can't use OF_CLK_DECLARE due to need to run after GPIOcontrollers have - * registrered */ - static const struct of_device_id clk_gpio_device_id[] = { - { .compatible = "gpio-gate-clock", .data = of_gpio_clk_setup, }, + { .compatible = "gpio-gate-clock", }, {} }; +MODULE_DEVICE_TABLE(of, clk_gpio_device_id); -static int clk_gpio_init(void) -{ - return of_clk_init(NULL, clk_gpio_device_id); -} -coredevice_initcall(clk_gpio_init); +static struct driver gpio_gate_clock_driver = { + .probe = of_gpio_clk_probe, + .name = "gpio-gate-clock", + .of_compatible = DRV_OF_COMPAT(clk_gpio_device_id), +}; + +core_platform_driver(gpio_gate_clock_driver); |