rstc.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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/reboot.h>
  16. void __iomem *sirfsoc_rstc_base;
  17. static DEFINE_MUTEX(rstc_lock);
  18. static struct of_device_id rstc_ids[] = {
  19. { .compatible = "sirf,prima2-rstc" },
  20. { .compatible = "sirf,marco-rstc" },
  21. {},
  22. };
  23. static int __init sirfsoc_of_rstc_init(void)
  24. {
  25. struct device_node *np;
  26. np = of_find_matching_node(NULL, rstc_ids);
  27. if (!np) {
  28. pr_err("unable to find compatible sirf rstc node in dtb\n");
  29. return -ENOENT;
  30. }
  31. sirfsoc_rstc_base = of_iomap(np, 0);
  32. if (!sirfsoc_rstc_base)
  33. panic("unable to map rstc cpu registers\n");
  34. of_node_put(np);
  35. return 0;
  36. }
  37. early_initcall(sirfsoc_of_rstc_init);
  38. int sirfsoc_reset_device(struct device *dev)
  39. {
  40. u32 reset_bit;
  41. if (of_property_read_u32(dev->of_node, "reset-bit", &reset_bit))
  42. return -EINVAL;
  43. mutex_lock(&rstc_lock);
  44. if (of_device_is_compatible(dev->of_node, "sirf,prima2-rstc")) {
  45. /*
  46. * Writing 1 to this bit resets corresponding block. Writing 0 to this
  47. * bit de-asserts reset signal of the corresponding block.
  48. * datasheet doesn't require explicit delay between the set and clear
  49. * of reset bit. it could be shorter if tests pass.
  50. */
  51. writel(readl(sirfsoc_rstc_base + (reset_bit / 32) * 4) | reset_bit,
  52. sirfsoc_rstc_base + (reset_bit / 32) * 4);
  53. msleep(10);
  54. writel(readl(sirfsoc_rstc_base + (reset_bit / 32) * 4) & ~reset_bit,
  55. sirfsoc_rstc_base + (reset_bit / 32) * 4);
  56. } else {
  57. /*
  58. * For MARCO and POLO
  59. * Writing 1 to SET register resets corresponding block. Writing 1 to CLEAR
  60. * register de-asserts reset signal of the corresponding block.
  61. * datasheet doesn't require explicit delay between the set and clear
  62. * of reset bit. it could be shorter if tests pass.
  63. */
  64. writel(reset_bit, sirfsoc_rstc_base + (reset_bit / 32) * 8);
  65. msleep(10);
  66. writel(reset_bit, sirfsoc_rstc_base + (reset_bit / 32) * 8 + 4);
  67. }
  68. mutex_unlock(&rstc_lock);
  69. return 0;
  70. }
  71. #define SIRFSOC_SYS_RST_BIT BIT(31)
  72. void sirfsoc_restart(enum reboot_mode mode, const char *cmd)
  73. {
  74. writel(SIRFSOC_SYS_RST_BIT, sirfsoc_rstc_base);
  75. }