reset-pistachio.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Pistachio SoC Reset Controller driver
  3. *
  4. * Copyright (C) 2015 Imagination Technologies Ltd.
  5. *
  6. * Author: Damien Horsley <Damien.Horsley@imgtec.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms and conditions of the GNU General Public License,
  10. * version 2, as published by the Free Software Foundation.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/of.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/regmap.h>
  16. #include <linux/reset-controller.h>
  17. #include <linux/slab.h>
  18. #include <linux/mfd/syscon.h>
  19. #include <dt-bindings/reset/pistachio-resets.h>
  20. #define PISTACHIO_SOFT_RESET 0
  21. struct pistachio_reset_data {
  22. struct reset_controller_dev rcdev;
  23. struct regmap *periph_regs;
  24. };
  25. static inline int pistachio_reset_shift(unsigned long id)
  26. {
  27. switch (id) {
  28. case PISTACHIO_RESET_I2C0:
  29. case PISTACHIO_RESET_I2C1:
  30. case PISTACHIO_RESET_I2C2:
  31. case PISTACHIO_RESET_I2C3:
  32. case PISTACHIO_RESET_I2S_IN:
  33. case PISTACHIO_RESET_PRL_OUT:
  34. case PISTACHIO_RESET_SPDIF_OUT:
  35. case PISTACHIO_RESET_SPI:
  36. case PISTACHIO_RESET_PWM_PDM:
  37. case PISTACHIO_RESET_UART0:
  38. case PISTACHIO_RESET_UART1:
  39. case PISTACHIO_RESET_QSPI:
  40. case PISTACHIO_RESET_MDC:
  41. case PISTACHIO_RESET_SDHOST:
  42. case PISTACHIO_RESET_ETHERNET:
  43. case PISTACHIO_RESET_IR:
  44. case PISTACHIO_RESET_HASH:
  45. case PISTACHIO_RESET_TIMER:
  46. return id;
  47. case PISTACHIO_RESET_I2S_OUT:
  48. case PISTACHIO_RESET_SPDIF_IN:
  49. case PISTACHIO_RESET_EVT:
  50. return id + 6;
  51. case PISTACHIO_RESET_USB_H:
  52. case PISTACHIO_RESET_USB_PR:
  53. case PISTACHIO_RESET_USB_PHY_PR:
  54. case PISTACHIO_RESET_USB_PHY_PON:
  55. return id + 7;
  56. default:
  57. return -EINVAL;
  58. }
  59. }
  60. static int pistachio_reset_assert(struct reset_controller_dev *rcdev,
  61. unsigned long id)
  62. {
  63. struct pistachio_reset_data *rd;
  64. u32 mask;
  65. int shift;
  66. rd = container_of(rcdev, struct pistachio_reset_data, rcdev);
  67. shift = pistachio_reset_shift(id);
  68. if (shift < 0)
  69. return shift;
  70. mask = BIT(shift);
  71. return regmap_update_bits(rd->periph_regs, PISTACHIO_SOFT_RESET,
  72. mask, mask);
  73. }
  74. static int pistachio_reset_deassert(struct reset_controller_dev *rcdev,
  75. unsigned long id)
  76. {
  77. struct pistachio_reset_data *rd;
  78. u32 mask;
  79. int shift;
  80. rd = container_of(rcdev, struct pistachio_reset_data, rcdev);
  81. shift = pistachio_reset_shift(id);
  82. if (shift < 0)
  83. return shift;
  84. mask = BIT(shift);
  85. return regmap_update_bits(rd->periph_regs, PISTACHIO_SOFT_RESET,
  86. mask, 0);
  87. }
  88. static const struct reset_control_ops pistachio_reset_ops = {
  89. .assert = pistachio_reset_assert,
  90. .deassert = pistachio_reset_deassert,
  91. };
  92. static int pistachio_reset_probe(struct platform_device *pdev)
  93. {
  94. struct pistachio_reset_data *rd;
  95. struct device *dev = &pdev->dev;
  96. struct device_node *np = pdev->dev.of_node;
  97. rd = devm_kzalloc(dev, sizeof(*rd), GFP_KERNEL);
  98. if (!rd)
  99. return -ENOMEM;
  100. rd->periph_regs = syscon_node_to_regmap(np->parent);
  101. if (IS_ERR(rd->periph_regs))
  102. return PTR_ERR(rd->periph_regs);
  103. rd->rcdev.owner = THIS_MODULE;
  104. rd->rcdev.nr_resets = PISTACHIO_RESET_MAX + 1;
  105. rd->rcdev.ops = &pistachio_reset_ops;
  106. rd->rcdev.of_node = np;
  107. return devm_reset_controller_register(dev, &rd->rcdev);
  108. }
  109. static const struct of_device_id pistachio_reset_dt_ids[] = {
  110. { .compatible = "img,pistachio-reset", },
  111. { /* sentinel */ },
  112. };
  113. static struct platform_driver pistachio_reset_driver = {
  114. .probe = pistachio_reset_probe,
  115. .driver = {
  116. .name = "pistachio-reset",
  117. .of_match_table = pistachio_reset_dt_ids,
  118. },
  119. };
  120. builtin_platform_driver(pistachio_reset_driver);