Marek Vasut | 59ee41c | 2023-08-14 01:51:27 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2023 Marek Vasut <marek.vasut+renesas@mailbox.org> |
| 4 | */ |
| 5 | |
| 6 | #include <asm/gpio.h> |
| 7 | #include <common.h> |
| 8 | #include <clk-uclass.h> |
| 9 | #include <dm.h> |
| 10 | |
| 11 | struct clk_gpio_priv { |
| 12 | struct gpio_desc enable; |
| 13 | }; |
| 14 | |
| 15 | static int clk_gpio_enable(struct clk *clk) |
| 16 | { |
| 17 | struct clk_gpio_priv *priv = dev_get_priv(clk->dev); |
| 18 | |
| 19 | dm_gpio_set_value(&priv->enable, 1); |
| 20 | |
| 21 | return 0; |
| 22 | } |
| 23 | |
| 24 | static int clk_gpio_disable(struct clk *clk) |
| 25 | { |
| 26 | struct clk_gpio_priv *priv = dev_get_priv(clk->dev); |
| 27 | |
| 28 | dm_gpio_set_value(&priv->enable, 0); |
| 29 | |
| 30 | return 0; |
| 31 | } |
| 32 | |
| 33 | const struct clk_ops clk_gpio_ops = { |
| 34 | .enable = clk_gpio_enable, |
| 35 | .disable = clk_gpio_disable, |
| 36 | }; |
| 37 | |
| 38 | static int clk_gpio_probe(struct udevice *dev) |
| 39 | { |
| 40 | struct clk_gpio_priv *priv = dev_get_priv(dev); |
| 41 | |
| 42 | return gpio_request_by_name(dev, "enable-gpios", 0, |
| 43 | &priv->enable, GPIOD_IS_OUT); |
| 44 | } |
| 45 | |
| 46 | /* |
| 47 | * When implementing clk-mux-clock, use gpio_request_list_by_name |
| 48 | * and implement get_rate/set_rate/set_parent ops. This should be |
| 49 | * in a separate driver and with separate Kconfig option to enable |
| 50 | * that driver, since unlike Linux implementation, the U-Boot DM |
| 51 | * integration would be orthogonal to this driver. |
| 52 | */ |
| 53 | static const struct udevice_id clk_gpio_match[] = { |
| 54 | { .compatible = "gpio-gate-clock" }, |
| 55 | { /* sentinel */ } |
| 56 | }; |
| 57 | |
| 58 | U_BOOT_DRIVER(gpio_gate_clock) = { |
| 59 | .name = "gpio_clock", |
| 60 | .id = UCLASS_CLK, |
| 61 | .of_match = clk_gpio_match, |
| 62 | .probe = clk_gpio_probe, |
| 63 | .priv_auto = sizeof(struct clk_gpio_priv), |
| 64 | .ops = &clk_gpio_ops, |
| 65 | .flags = DM_FLAG_PRE_RELOC, |
| 66 | }; |