rstc.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * reset controller for CSR SiRFprimaII
  3. *
  4. * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
  5. *
  6. * Licensed under GPLv2 or later.
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/mutex.h>
  10. #include <linux/io.h>
  11. #include <linux/delay.h>
  12. #include <linux/device.h>
  13. #include <linux/of.h>
  14. #include <linux/of_address.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/reboot.h>
  17. #include <linux/reset-controller.h>
  18. #include <asm/system_misc.h>
  19. #define SIRFSOC_RSTBIT_NUM 64
  20. static void __iomem *sirfsoc_rstc_base;
  21. static DEFINE_MUTEX(rstc_lock);
  22. static int sirfsoc_reset_module(struct reset_controller_dev *rcdev,
  23. unsigned long sw_reset_idx)
  24. {
  25. u32 reset_bit = sw_reset_idx;
  26. if (reset_bit >= SIRFSOC_RSTBIT_NUM)
  27. return -EINVAL;
  28. mutex_lock(&rstc_lock);
  29. if (of_device_is_compatible(rcdev->of_node, "sirf,prima2-rstc")) {
  30. /*
  31. * Writing 1 to this bit resets corresponding block.
  32. * Writing 0 to this bit de-asserts reset signal of the
  33. * corresponding block. datasheet doesn't require explicit
  34. * delay between the set and clear of reset bit. it could
  35. * be shorter if tests pass.
  36. */
  37. writel(readl(sirfsoc_rstc_base +
  38. (reset_bit / 32) * 4) | (1 << reset_bit),
  39. sirfsoc_rstc_base + (reset_bit / 32) * 4);
  40. msleep(20);
  41. writel(readl(sirfsoc_rstc_base +
  42. (reset_bit / 32) * 4) & ~(1 << reset_bit),
  43. sirfsoc_rstc_base + (reset_bit / 32) * 4);
  44. } else {
  45. /*
  46. * For MARCO and POLO
  47. * Writing 1 to SET register resets corresponding block.
  48. * Writing 1 to CLEAR register de-asserts reset signal of the
  49. * corresponding block.
  50. * datasheet doesn't require explicit delay between the set and
  51. * clear of reset bit. it could be shorter if tests pass.
  52. */
  53. writel(1 << reset_bit,
  54. sirfsoc_rstc_base + (reset_bit / 32) * 8);
  55. msleep(20);
  56. writel(1 << reset_bit,
  57. sirfsoc_rstc_base + (reset_bit / 32) * 8 + 4);
  58. }
  59. mutex_unlock(&rstc_lock);
  60. return 0;
  61. }
  62. static struct reset_control_ops sirfsoc_rstc_ops = {
  63. .reset = sirfsoc_reset_module,
  64. };
  65. static struct reset_controller_dev sirfsoc_reset_controller = {
  66. .ops = &sirfsoc_rstc_ops,
  67. .nr_resets = SIRFSOC_RSTBIT_NUM,
  68. };
  69. #define SIRFSOC_SYS_RST_BIT BIT(31)
  70. static void sirfsoc_restart(enum reboot_mode mode, const char *cmd)
  71. {
  72. writel(SIRFSOC_SYS_RST_BIT, sirfsoc_rstc_base);
  73. }
  74. static int sirfsoc_rstc_probe(struct platform_device *pdev)
  75. {
  76. struct device_node *np = pdev->dev.of_node;
  77. sirfsoc_rstc_base = of_iomap(np, 0);
  78. if (!sirfsoc_rstc_base) {
  79. dev_err(&pdev->dev, "unable to map rstc cpu registers\n");
  80. return -ENOMEM;
  81. }
  82. sirfsoc_reset_controller.of_node = np;
  83. arm_pm_restart = sirfsoc_restart;
  84. if (IS_ENABLED(CONFIG_RESET_CONTROLLER))
  85. reset_controller_register(&sirfsoc_reset_controller);
  86. return 0;
  87. }
  88. static const struct of_device_id rstc_ids[] = {
  89. { .compatible = "sirf,prima2-rstc" },
  90. { .compatible = "sirf,marco-rstc" },
  91. {},
  92. };
  93. static struct platform_driver sirfsoc_rstc_driver = {
  94. .probe = sirfsoc_rstc_probe,
  95. .driver = {
  96. .name = "sirfsoc_rstc",
  97. .owner = THIS_MODULE,
  98. .of_match_table = rstc_ids,
  99. },
  100. };
  101. static int __init sirfsoc_rstc_init(void)
  102. {
  103. return platform_driver_register(&sirfsoc_rstc_driver);
  104. }
  105. subsys_initcall(sirfsoc_rstc_init);