mirror of https://gitee.com/openkylin/linux.git
clk: clk-gpio: add support for sleeping GPIOs in gpio-gate-clk
The current implementation of gpio-gate-clk enables/disables the clock using the GPIO in the ->enable() and ->disable() clock callbacks. This requires the GPIO to be configurable in atomic contexts. While it is the case for most memory-mapped GPIO controllers, it is not the case for GPIO expanders on I2C or SPI. This commit extends the gpio-gate-clk to check whether the GPIO calls require sleeping or not. If sleeping is not required, the current implementation based on ->enable()/->disable() is kept. However, if sleeping is needed, we instead implement the logic in the ->prepare() and ->unprepare() hooks. Thanks to this, a gate clock connected to a GPIO on a GPIO expander can be controlled with the existing driver. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> [sboyd@kernel.org: Mark clk ops static] Signed-off-by: Stephen Boyd <sboyd@kernel.org>
This commit is contained in:
parent
bfeffd1552
commit
c0189feead
|
@ -58,6 +58,35 @@ const struct clk_ops clk_gpio_gate_ops = {
|
||||||
};
|
};
|
||||||
EXPORT_SYMBOL_GPL(clk_gpio_gate_ops);
|
EXPORT_SYMBOL_GPL(clk_gpio_gate_ops);
|
||||||
|
|
||||||
|
static int clk_sleeping_gpio_gate_prepare(struct clk_hw *hw)
|
||||||
|
{
|
||||||
|
struct clk_gpio *clk = to_clk_gpio(hw);
|
||||||
|
|
||||||
|
gpiod_set_value_cansleep(clk->gpiod, 1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void clk_sleeping_gpio_gate_unprepare(struct clk_hw *hw)
|
||||||
|
{
|
||||||
|
struct clk_gpio *clk = to_clk_gpio(hw);
|
||||||
|
|
||||||
|
gpiod_set_value_cansleep(clk->gpiod, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int clk_sleeping_gpio_gate_is_prepared(struct clk_hw *hw)
|
||||||
|
{
|
||||||
|
struct clk_gpio *clk = to_clk_gpio(hw);
|
||||||
|
|
||||||
|
return gpiod_get_value_cansleep(clk->gpiod);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct clk_ops clk_sleeping_gpio_gate_ops = {
|
||||||
|
.prepare = clk_sleeping_gpio_gate_prepare,
|
||||||
|
.unprepare = clk_sleeping_gpio_gate_unprepare,
|
||||||
|
.is_prepared = clk_sleeping_gpio_gate_is_prepared,
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DOC: basic clock multiplexer which can be controlled with a gpio output
|
* DOC: basic clock multiplexer which can be controlled with a gpio output
|
||||||
* Traits of this clock:
|
* Traits of this clock:
|
||||||
|
@ -144,10 +173,16 @@ struct clk_hw *clk_hw_register_gpio_gate(struct device *dev, const char *name,
|
||||||
const char *parent_name, struct gpio_desc *gpiod,
|
const char *parent_name, struct gpio_desc *gpiod,
|
||||||
unsigned long flags)
|
unsigned long flags)
|
||||||
{
|
{
|
||||||
|
const struct clk_ops *ops;
|
||||||
|
|
||||||
|
if (gpiod_cansleep(gpiod))
|
||||||
|
ops = &clk_sleeping_gpio_gate_ops;
|
||||||
|
else
|
||||||
|
ops = &clk_gpio_gate_ops;
|
||||||
|
|
||||||
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), gpiod, flags,
|
(parent_name ? 1 : 0), gpiod, flags, ops);
|
||||||
&clk_gpio_gate_ops);
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(clk_hw_register_gpio_gate);
|
EXPORT_SYMBOL_GPL(clk_hw_register_gpio_gate);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue