rstc.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. /*
  30. * Writing 1 to this bit resets corresponding block.
  31. * Writing 0 to this bit de-asserts reset signal of the
  32. * corresponding block. datasheet doesn't require explicit
  33. * delay between the set and clear of reset bit. it could
  34. * be shorter if tests pass.
  35. */
  36. writel(readl(sirfsoc_rstc_base +
  37. (reset_bit / 32) * 4) | (1 << reset_bit),
  38. sirfsoc_rstc_base + (reset_bit / 32) * 4);
  39. msleep(20);
  40. writel(readl(sirfsoc_rstc_base +
  41. (reset_bit / 32) * 4) & ~(1 << reset_bit),
  42. sirfsoc_rstc_base + (reset_bit / 32) * 4);
  43. mutex_unlock(&rstc_lock);
  44. return 0;
  45. }
  46. static struct reset_control_ops sirfsoc_rstc_ops = {
  47. .reset = sirfsoc_reset_module,
  48. };
  49. static struct reset_controller_dev sirfsoc_reset_controller = {
  50. .ops = &sirfsoc_rstc_ops,
  51. .nr_resets = SIRFSOC_RSTBIT_NUM,
  52. };
  53. #define SIRFSOC_SYS_RST_BIT BIT(31)
  54. static void sirfsoc_restart(enum reboot_mode mode, const char *cmd)
  55. {
  56. writel(SIRFSOC_SYS_RST_BIT, sirfsoc_rstc_base);
  57. }
  58. static int sirfsoc_rstc_probe(struct platform_device *pdev)
  59. {
  60. struct device_node *np = pdev->dev.of_node;
  61. sirfsoc_rstc_base = of_iomap(np, 0);
  62. if (!sirfsoc_rstc_base) {
  63. dev_err(&pdev->dev, "unable to map rstc cpu registers\n");
  64. return -ENOMEM;
  65. }
  66. sirfsoc_reset_controller.of_node = np;
  67. arm_pm_restart = sirfsoc_restart;
  68. if (IS_ENABLED(CONFIG_RESET_CONTROLLER))
  69. reset_controller_register(&sirfsoc_reset_controller);
  70. return 0;
  71. }
  72. static const struct of_device_id rstc_ids[] = {
  73. { .compatible = "sirf,prima2-rstc" },
  74. {},
  75. };
  76. static struct platform_driver sirfsoc_rstc_driver = {
  77. .probe = sirfsoc_rstc_probe,
  78. .driver = {
  79. .name = "sirfsoc_rstc",
  80. .of_match_table = rstc_ids,
  81. },
  82. };
  83. static int __init sirfsoc_rstc_init(void)
  84. {
  85. return platform_driver_register(&sirfsoc_rstc_driver);
  86. }
  87. subsys_initcall(sirfsoc_rstc_init);