mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-12-29 09:16:33 +00:00
reset: gpio: Add GPIO-based reset controller
Add a simple driver to control GPIO-based resets using the reset controller API for the cases when the GPIOs are shared and reset should be coordinated. The driver is expected to be used by reset core framework for ad-hoc reset controllers. Cc: Bartosz Golaszewski <brgl@bgdev.pl> Cc: Chris Packham <chris.packham@alliedtelesis.co.nz> Cc: Sean Anderson <sean.anderson@seco.com> Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Link: https://lore.kernel.org/r/20240129115216.96479-4-krzysztof.kozlowski@linaro.org Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
This commit is contained in:
parent
0f28982835
commit
cee544a40e
@ -8911,6 +8911,11 @@ F: Documentation/i2c/muxes/i2c-mux-gpio.rst
|
||||
F: drivers/i2c/muxes/i2c-mux-gpio.c
|
||||
F: include/linux/platform_data/i2c-mux-gpio.h
|
||||
|
||||
GENERIC GPIO RESET DRIVER
|
||||
M: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
|
||||
S: Maintained
|
||||
F: drivers/reset/reset-gpio.c
|
||||
|
||||
GENERIC HDLC (WAN) DRIVERS
|
||||
M: Krzysztof Halasa <khc@pm.waw.pl>
|
||||
S: Maintained
|
||||
|
@ -66,6 +66,15 @@ config RESET_BRCMSTB_RESCAL
|
||||
This enables the RESCAL reset controller for SATA, PCIe0, or PCIe1 on
|
||||
BCM7216.
|
||||
|
||||
config RESET_GPIO
|
||||
tristate "GPIO reset controller"
|
||||
help
|
||||
This enables a generic reset controller for resets attached via
|
||||
GPIOs. Typically for OF platforms this driver expects "reset-gpios"
|
||||
property.
|
||||
|
||||
If compiled as module, it will be called reset-gpio.
|
||||
|
||||
config RESET_HSDK
|
||||
bool "Synopsys HSDK Reset Driver"
|
||||
depends on HAS_IOMEM
|
||||
|
@ -11,6 +11,7 @@ obj-$(CONFIG_RESET_BCM6345) += reset-bcm6345.o
|
||||
obj-$(CONFIG_RESET_BERLIN) += reset-berlin.o
|
||||
obj-$(CONFIG_RESET_BRCMSTB) += reset-brcmstb.o
|
||||
obj-$(CONFIG_RESET_BRCMSTB_RESCAL) += reset-brcmstb-rescal.o
|
||||
obj-$(CONFIG_RESET_GPIO) += reset-gpio.o
|
||||
obj-$(CONFIG_RESET_HSDK) += reset-hsdk.o
|
||||
obj-$(CONFIG_RESET_IMX7) += reset-imx7.o
|
||||
obj-$(CONFIG_RESET_INTEL_GW) += reset-intel-gw.o
|
||||
|
119
drivers/reset/reset-gpio.c
Normal file
119
drivers/reset/reset-gpio.c
Normal file
@ -0,0 +1,119 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
#include <linux/gpio/consumer.h>
|
||||
#include <linux/mod_devicetable.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/reset-controller.h>
|
||||
|
||||
struct reset_gpio_priv {
|
||||
struct reset_controller_dev rc;
|
||||
struct gpio_desc *reset;
|
||||
};
|
||||
|
||||
static inline struct reset_gpio_priv
|
||||
*rc_to_reset_gpio(struct reset_controller_dev *rc)
|
||||
{
|
||||
return container_of(rc, struct reset_gpio_priv, rc);
|
||||
}
|
||||
|
||||
static int reset_gpio_assert(struct reset_controller_dev *rc, unsigned long id)
|
||||
{
|
||||
struct reset_gpio_priv *priv = rc_to_reset_gpio(rc);
|
||||
|
||||
gpiod_set_value_cansleep(priv->reset, 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int reset_gpio_deassert(struct reset_controller_dev *rc,
|
||||
unsigned long id)
|
||||
{
|
||||
struct reset_gpio_priv *priv = rc_to_reset_gpio(rc);
|
||||
|
||||
gpiod_set_value_cansleep(priv->reset, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int reset_gpio_status(struct reset_controller_dev *rc, unsigned long id)
|
||||
{
|
||||
struct reset_gpio_priv *priv = rc_to_reset_gpio(rc);
|
||||
|
||||
return gpiod_get_value_cansleep(priv->reset);
|
||||
}
|
||||
|
||||
static const struct reset_control_ops reset_gpio_ops = {
|
||||
.assert = reset_gpio_assert,
|
||||
.deassert = reset_gpio_deassert,
|
||||
.status = reset_gpio_status,
|
||||
};
|
||||
|
||||
static int reset_gpio_of_xlate(struct reset_controller_dev *rcdev,
|
||||
const struct of_phandle_args *reset_spec)
|
||||
{
|
||||
return reset_spec->args[0];
|
||||
}
|
||||
|
||||
static void reset_gpio_of_node_put(void *data)
|
||||
{
|
||||
of_node_put(data);
|
||||
}
|
||||
|
||||
static int reset_gpio_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct device *dev = &pdev->dev;
|
||||
struct of_phandle_args *platdata = dev_get_platdata(dev);
|
||||
struct reset_gpio_priv *priv;
|
||||
int ret;
|
||||
|
||||
if (!platdata)
|
||||
return -EINVAL;
|
||||
|
||||
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
|
||||
if (!priv)
|
||||
return -ENOMEM;
|
||||
|
||||
platform_set_drvdata(pdev, &priv->rc);
|
||||
|
||||
priv->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
|
||||
if (IS_ERR(priv->reset))
|
||||
return dev_err_probe(dev, PTR_ERR(priv->reset),
|
||||
"Could not get reset gpios\n");
|
||||
|
||||
priv->rc.ops = &reset_gpio_ops;
|
||||
priv->rc.owner = THIS_MODULE;
|
||||
priv->rc.dev = dev;
|
||||
priv->rc.of_args = platdata;
|
||||
ret = devm_add_action_or_reset(dev, reset_gpio_of_node_put,
|
||||
priv->rc.of_node);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
/* Cells to match GPIO specifier, but it's not really used */
|
||||
priv->rc.of_reset_n_cells = 2;
|
||||
priv->rc.of_xlate = reset_gpio_of_xlate;
|
||||
priv->rc.nr_resets = 1;
|
||||
|
||||
return devm_reset_controller_register(dev, &priv->rc);
|
||||
}
|
||||
|
||||
static const struct platform_device_id reset_gpio_ids[] = {
|
||||
{ .name = "reset-gpio", },
|
||||
{}
|
||||
};
|
||||
MODULE_DEVICE_TABLE(platform, reset_gpio_ids);
|
||||
|
||||
static struct platform_driver reset_gpio_driver = {
|
||||
.probe = reset_gpio_probe,
|
||||
.id_table = reset_gpio_ids,
|
||||
.driver = {
|
||||
.name = "reset-gpio",
|
||||
},
|
||||
};
|
||||
module_platform_driver(reset_gpio_driver);
|
||||
|
||||
MODULE_AUTHOR("Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>");
|
||||
MODULE_DESCRIPTION("Generic GPIO reset driver");
|
||||
MODULE_LICENSE("GPL");
|
Loading…
Reference in New Issue
Block a user