rstc.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. {},
  20. };
  21. static int __init sirfsoc_of_rstc_init(void)
  22. {
  23. struct device_node *np;
  24. np = of_find_matching_node(NULL, rstc_ids);
  25. if (!np)
  26. panic("unable to find compatible rstc node in dtb\n");
  27. sirfsoc_rstc_base = of_iomap(np, 0);
  28. if (!sirfsoc_rstc_base)
  29. panic("unable to map rstc cpu registers\n");
  30. of_node_put(np);
  31. return 0;
  32. }
  33. early_initcall(sirfsoc_of_rstc_init);
  34. int sirfsoc_reset_device(struct device *dev)
  35. {
  36. const unsigned int *prop = of_get_property(dev->of_node, "reset-bit", NULL);
  37. unsigned int reset_bit;
  38. if (!prop)
  39. return -ENODEV;
  40. reset_bit = be32_to_cpup(prop);
  41. mutex_lock(&rstc_lock);
  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. mutex_unlock(&rstc_lock);
  54. return 0;
  55. }
  56. #define SIRFSOC_SYS_RST_BIT BIT(31)
  57. void sirfsoc_restart(char mode, const char *cmd)
  58. {
  59. writel(SIRFSOC_SYS_RST_BIT, sirfsoc_rstc_base);
  60. }