| 1 | |
| 2 |
|
| 3 | #include <linux/auxiliary_bus.h>
|
| 4 | #include <linux/gpio/consumer.h>
|
| 5 | #include <linux/module.h>
|
| 6 | #include <linux/property.h>
|
| 7 | #include <linux/reset-controller.h>
|
| 8 |
|
| 9 | struct reset_gpio_priv {
|
| 10 | struct reset_controller_dev rc;
|
| 11 | struct gpio_desc *reset;
|
| 12 | };
|
| 13 |
|
| 14 | static inline struct reset_gpio_priv
|
| 15 | *rc_to_reset_gpio(struct reset_controller_dev *rc)
|
| 16 | {
|
| 17 | return container_of(rc, struct reset_gpio_priv, rc);
|
| 18 | }
|
| 19 |
|
| 20 | static int reset_gpio_assert(struct reset_controller_dev *rc, unsigned long id)
|
| 21 | {
|
| 22 | struct reset_gpio_priv *priv = rc_to_reset_gpio(rc);
|
| 23 |
|
| 24 | return gpiod_set_value_cansleep(priv->reset, 1);
|
| 25 | }
|
| 26 |
|
| 27 | static int reset_gpio_deassert(struct reset_controller_dev *rc,
|
| 28 | unsigned long id)
|
| 29 | {
|
| 30 | struct reset_gpio_priv *priv = rc_to_reset_gpio(rc);
|
| 31 |
|
| 32 | return gpiod_set_value_cansleep(priv->reset, 0);
|
| 33 | }
|
| 34 |
|
| 35 | static int reset_gpio_status(struct reset_controller_dev *rc, unsigned long id)
|
| 36 | {
|
| 37 | struct reset_gpio_priv *priv = rc_to_reset_gpio(rc);
|
| 38 |
|
| 39 | return gpiod_get_value_cansleep(priv->reset);
|
| 40 | }
|
| 41 |
|
| 42 | static const struct reset_control_ops reset_gpio_ops = {
|
| 43 | .assert = reset_gpio_assert,
|
| 44 | .deassert = reset_gpio_deassert,
|
| 45 | .status = reset_gpio_status,
|
| 46 | };
|
| 47 |
|
| 48 | static int reset_gpio_fwnode_xlate(struct reset_controller_dev *rcdev,
|
| 49 | const struct fwnode_reference_args *reset_spec)
|
| 50 | {
|
| 51 | return reset_spec->args[0];
|
| 52 | }
|
| 53 |
|
| 54 | static int reset_gpio_probe(struct auxiliary_device *adev,
|
| 55 | const struct auxiliary_device_id *id)
|
| 56 | {
|
| 57 | struct device *dev = &adev->dev;
|
| 58 | struct reset_gpio_priv *priv;
|
| 59 |
|
| 60 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
|
| 61 | if (!priv)
|
| 62 | return -ENOMEM;
|
| 63 |
|
| 64 | priv->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
|
| 65 | if (IS_ERR(priv->reset))
|
| 66 | return dev_err_probe(dev, PTR_ERR(priv->reset),
|
| 67 | "Could not get reset gpios\n");
|
| 68 |
|
| 69 | priv->rc.ops = &reset_gpio_ops;
|
| 70 | priv->rc.owner = THIS_MODULE;
|
| 71 | priv->rc.dev = dev;
|
| 72 |
|
| 73 |
|
| 74 | priv->rc.fwnode_reset_n_cells = 2;
|
| 75 | priv->rc.fwnode_xlate = reset_gpio_fwnode_xlate;
|
| 76 | priv->rc.nr_resets = 1;
|
| 77 |
|
| 78 | return devm_reset_controller_register(dev, &priv->rc);
|
| 79 | }
|
| 80 |
|
| 81 | static const struct auxiliary_device_id reset_gpio_ids[] = {
|
| 82 | { .name = "reset.gpio" },
|
| 83 | {}
|
| 84 | };
|
| 85 | MODULE_DEVICE_TABLE(auxiliary, reset_gpio_ids);
|
| 86 |
|
| 87 | static struct auxiliary_driver reset_gpio_driver = {
|
| 88 | .probe = reset_gpio_probe,
|
| 89 | .id_table = reset_gpio_ids,
|
| 90 | .driver = {
|
| 91 | .name = "reset-gpio",
|
| 92 | .suppress_bind_attrs = true,
|
| 93 | },
|
| 94 | };
|
| 95 | module_auxiliary_driver(reset_gpio_driver);
|
| 96 |
|
| 97 | MODULE_AUTHOR("Krzysztof Kozlowski <[email protected]>");
|
| 98 | MODULE_DESCRIPTION("Generic GPIO reset driver");
|
| 99 | MODULE_LICENSE("GPL");
|