rstc.c 2.3 KB

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