Lines Matching +full:gated +full:- +full:fixed +full:- +full:clock

1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2013 - 2014 Texas Instruments Incorporated - https://www.ti.com
9 * Gpio controlled clock implementation
12 #include <linux/clk-provider.h>
23 * DOC: basic gpio gated clock which can be enabled and disabled
25 * Traits of this clock:
26 * prepare - clk_(un)prepare are functional and control a gpio that can sleep
27 * enable - clk_enable and clk_disable are functional & control
28 * non-sleeping gpio
29 * rate - inherits rate from parent. No clk_set_rate support
30 * parent - fixed parent. No clk_set_parent support
34 * struct clk_gpio - gpio gated clock
36 * @hw: handle between common and hardware-specific interfaces
39 * Clock with a gpio control for enabling and disabling the parent clock
57 gpiod_set_value(clk->gpiod, 1); in clk_gpio_gate_enable()
66 gpiod_set_value(clk->gpiod, 0); in clk_gpio_gate_disable()
73 return gpiod_get_value(clk->gpiod); in clk_gpio_gate_is_enabled()
86 gpiod_set_value_cansleep(clk->gpiod, 1); in clk_sleeping_gpio_gate_prepare()
95 gpiod_set_value_cansleep(clk->gpiod, 0); in clk_sleeping_gpio_gate_unprepare()
102 return gpiod_get_value_cansleep(clk->gpiod); in clk_sleeping_gpio_gate_is_prepared()
112 * DOC: basic clock multiplexer which can be controlled with a gpio output
113 * Traits of this clock:
114 * prepare - clk_prepare only ensures that parents are prepared
115 * rate - rate is only affected by parent switching. No clk_set_rate support
116 * parent - parent is adjustable through clk_set_parent
123 return gpiod_get_value_cansleep(clk->gpiod); in clk_gpio_mux_get_parent()
130 gpiod_set_value_cansleep(clk->gpiod, index); in clk_gpio_mux_set_parent()
156 return ERR_PTR(-ENOMEM); in clk_register_gpio()
158 init.name = dev->of_node->name; in clk_register_gpio()
164 clk_gpio->gpiod = gpiod; in clk_register_gpio()
165 clk_gpio->hw.init = &init; in clk_register_gpio()
167 hw = &clk_gpio->hw; in clk_register_gpio()
197 struct device *dev = &pdev->dev; in gpio_clk_driver_probe()
198 struct device_node *node = dev->of_node; in gpio_clk_driver_probe()
205 is_mux = of_device_is_compatible(node, "gpio-mux-clock"); in gpio_clk_driver_probe()
209 dev_err(dev, "mux-clock must have 2 parents\n"); in gpio_clk_driver_probe()
210 return -EINVAL; in gpio_clk_driver_probe()
230 { .compatible = "gpio-mux-clock" },
231 { .compatible = "gpio-gate-clock" },
238 .name = "gpio-clk",
245 * DOC: gated fixed clock, controlled with a gpio output and a regulator
246 * Traits of this clock:
247 * prepare - clk_prepare and clk_unprepare are function & control regulator
249 * enable - clk_enable and clk_disable are functional & control gpio
250 * rate - rate is fixed and set on clock registration
251 * parent - fixed clock is a root clock and has no parent
255 * struct clk_gated_fixed - Gateable fixed rate clock
256 * @clk_gpio: instance of clk_gpio for gate-gpio
258 * @rate: fixed rate
271 return to_clk_gated_fixed(to_clk_gpio(hw))->rate; in clk_gated_fixed_recalc_rate()
278 if (!clk->supply) in clk_gated_fixed_prepare()
281 return regulator_enable(clk->supply); in clk_gated_fixed_prepare()
288 if (!clk->supply) in clk_gated_fixed_unprepare()
291 regulator_disable(clk->supply); in clk_gated_fixed_unprepare()
298 if (!clk->supply) in clk_gated_fixed_is_prepared()
301 return regulator_is_enabled(clk->supply); in clk_gated_fixed_is_prepared()
305 * Fixed gated clock with non-sleeping gpio.
308 * and the enable operation switches the enable-gpio.
342 * Fixed gated clock with non-sleeping gpio.
344 * Enabling the supply regulator and switching the enable-gpio happens
358 struct device *dev = &pdev->dev; in clk_gated_fixed_probe()
367 return -ENOMEM; in clk_gated_fixed_probe()
369 ret = device_property_read_u32(dev, "clock-frequency", &rate); in clk_gated_fixed_probe()
371 return dev_err_probe(dev, ret, "Failed to get clock-frequency\n"); in clk_gated_fixed_probe()
372 clk->rate = rate; in clk_gated_fixed_probe()
374 ret = device_property_read_string(dev, "clock-output-names", &clk_name); in clk_gated_fixed_probe()
376 clk_name = fwnode_get_name(dev->fwnode); in clk_gated_fixed_probe()
378 clk->supply = devm_regulator_get_optional(dev, "vdd"); in clk_gated_fixed_probe()
379 if (IS_ERR(clk->supply)) { in clk_gated_fixed_probe()
380 if (PTR_ERR(clk->supply) != -ENODEV) in clk_gated_fixed_probe()
381 return dev_err_probe(dev, PTR_ERR(clk->supply), in clk_gated_fixed_probe()
383 clk->supply = NULL; in clk_gated_fixed_probe()
386 clk->clk_gpio.gpiod = devm_gpiod_get_optional(dev, "enable", in clk_gated_fixed_probe()
388 if (IS_ERR(clk->clk_gpio.gpiod)) in clk_gated_fixed_probe()
389 return dev_err_probe(dev, PTR_ERR(clk->clk_gpio.gpiod), in clk_gated_fixed_probe()
392 if (gpiod_cansleep(clk->clk_gpio.gpiod)) in clk_gated_fixed_probe()
397 clk->clk_gpio.hw.init = CLK_HW_INIT_NO_PARENT(clk_name, ops, 0); in clk_gated_fixed_probe()
399 /* register the clock */ in clk_gated_fixed_probe()
400 ret = devm_clk_hw_register(dev, &clk->clk_gpio.hw); in clk_gated_fixed_probe()
403 "Failed to register clock\n"); in clk_gated_fixed_probe()
406 &clk->clk_gpio.hw); in clk_gated_fixed_probe()
409 "Failed to register clock provider\n"); in clk_gated_fixed_probe()
415 { .compatible = "gated-fixed-clock" },
422 .name = "gated-fixed-clk",