reset-berlin.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (C) 2014 Marvell Technology Group Ltd.
  3. *
  4. * Antoine Tenart <antoine.tenart@free-electrons.com>
  5. * Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
  6. *
  7. * This file is licensed under the terms of the GNU General Public
  8. * License version 2. This program is licensed "as is" without any
  9. * warranty of any kind, whether express or implied.
  10. */
  11. #include <linux/delay.h>
  12. #include <linux/io.h>
  13. #include <linux/mfd/syscon.h>
  14. #include <linux/module.h>
  15. #include <linux/of.h>
  16. #include <linux/of_address.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/regmap.h>
  19. #include <linux/reset-controller.h>
  20. #include <linux/slab.h>
  21. #include <linux/types.h>
  22. #define BERLIN_MAX_RESETS 32
  23. #define to_berlin_reset_priv(p) \
  24. container_of((p), struct berlin_reset_priv, rcdev)
  25. struct berlin_reset_priv {
  26. struct regmap *regmap;
  27. struct reset_controller_dev rcdev;
  28. };
  29. static int berlin_reset_reset(struct reset_controller_dev *rcdev,
  30. unsigned long id)
  31. {
  32. struct berlin_reset_priv *priv = to_berlin_reset_priv(rcdev);
  33. int offset = id >> 8;
  34. int mask = BIT(id & 0x1f);
  35. regmap_write(priv->regmap, offset, mask);
  36. /* let the reset be effective */
  37. udelay(10);
  38. return 0;
  39. }
  40. static struct reset_control_ops berlin_reset_ops = {
  41. .reset = berlin_reset_reset,
  42. };
  43. static int berlin_reset_xlate(struct reset_controller_dev *rcdev,
  44. const struct of_phandle_args *reset_spec)
  45. {
  46. unsigned offset, bit;
  47. if (WARN_ON(reset_spec->args_count != rcdev->of_reset_n_cells))
  48. return -EINVAL;
  49. offset = reset_spec->args[0];
  50. bit = reset_spec->args[1];
  51. if (bit >= BERLIN_MAX_RESETS)
  52. return -EINVAL;
  53. return (offset << 8) | bit;
  54. }
  55. static int berlin2_reset_probe(struct platform_device *pdev)
  56. {
  57. struct device_node *parent_np = of_get_parent(pdev->dev.of_node);
  58. struct berlin_reset_priv *priv;
  59. priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
  60. if (!priv)
  61. return -ENOMEM;
  62. priv->regmap = syscon_node_to_regmap(parent_np);
  63. of_node_put(parent_np);
  64. if (IS_ERR(priv->regmap))
  65. return PTR_ERR(priv->regmap);
  66. priv->rcdev.owner = THIS_MODULE;
  67. priv->rcdev.ops = &berlin_reset_ops;
  68. priv->rcdev.of_node = pdev->dev.of_node;
  69. priv->rcdev.of_reset_n_cells = 2;
  70. priv->rcdev.of_xlate = berlin_reset_xlate;
  71. reset_controller_register(&priv->rcdev);
  72. return 0;
  73. }
  74. static const struct of_device_id berlin_reset_dt_match[] = {
  75. { .compatible = "marvell,berlin2-reset" },
  76. { },
  77. };
  78. MODULE_DEVICE_TABLE(of, berlin_reset_dt_match);
  79. static struct platform_driver berlin_reset_driver = {
  80. .probe = berlin2_reset_probe,
  81. .driver = {
  82. .name = "berlin2-reset",
  83. .of_match_table = berlin_reset_dt_match,
  84. },
  85. };
  86. module_platform_driver(berlin_reset_driver);
  87. MODULE_AUTHOR("Antoine Tenart <antoine.tenart@free-electrons.com>");
  88. MODULE_AUTHOR("Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>");
  89. MODULE_DESCRIPTION("Marvell Berlin reset driver");
  90. MODULE_LICENSE("GPL");