reset-berlin.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (C) 2014 Marvell Technology Group Ltd.
  3. *
  4. * Marvell Berlin reset driver
  5. *
  6. * Antoine Tenart <antoine.tenart@free-electrons.com>
  7. * Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
  8. *
  9. * This file is licensed under the terms of the GNU General Public
  10. * License version 2. This program is licensed "as is" without any
  11. * warranty of any kind, whether express or implied.
  12. */
  13. #include <linux/delay.h>
  14. #include <linux/io.h>
  15. #include <linux/mfd/syscon.h>
  16. #include <linux/init.h>
  17. #include <linux/of.h>
  18. #include <linux/of_address.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/regmap.h>
  21. #include <linux/reset-controller.h>
  22. #include <linux/slab.h>
  23. #include <linux/types.h>
  24. #define BERLIN_MAX_RESETS 32
  25. #define to_berlin_reset_priv(p) \
  26. container_of((p), struct berlin_reset_priv, rcdev)
  27. struct berlin_reset_priv {
  28. struct regmap *regmap;
  29. struct reset_controller_dev rcdev;
  30. };
  31. static int berlin_reset_reset(struct reset_controller_dev *rcdev,
  32. unsigned long id)
  33. {
  34. struct berlin_reset_priv *priv = to_berlin_reset_priv(rcdev);
  35. int offset = id >> 8;
  36. int mask = BIT(id & 0x1f);
  37. regmap_write(priv->regmap, offset, mask);
  38. /* let the reset be effective */
  39. udelay(10);
  40. return 0;
  41. }
  42. static const struct reset_control_ops berlin_reset_ops = {
  43. .reset = berlin_reset_reset,
  44. };
  45. static int berlin_reset_xlate(struct reset_controller_dev *rcdev,
  46. const struct of_phandle_args *reset_spec)
  47. {
  48. unsigned offset, bit;
  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. return reset_controller_register(&priv->rcdev);
  72. }
  73. static const struct of_device_id berlin_reset_dt_match[] = {
  74. { .compatible = "marvell,berlin2-reset" },
  75. { },
  76. };
  77. static struct platform_driver berlin_reset_driver = {
  78. .probe = berlin2_reset_probe,
  79. .driver = {
  80. .name = "berlin2-reset",
  81. .of_match_table = berlin_reset_dt_match,
  82. },
  83. };
  84. builtin_platform_driver(berlin_reset_driver);