reset.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * This program is free software; you can redistribute it and/or modify it
  3. * under the terms of the GNU General Public License version 2 as published
  4. * by the Free Software Foundation.
  5. *
  6. * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  7. * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  8. * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
  9. */
  10. #include <linux/pm.h>
  11. #include <linux/io.h>
  12. #include <linux/of.h>
  13. #include <linux/delay.h>
  14. #include <linux/reset-controller.h>
  15. #include <asm/reboot.h>
  16. #include <asm/mach-ralink/ralink_regs.h>
  17. /* Reset Control */
  18. #define SYSC_REG_RESET_CTRL 0x034
  19. #define RSTCTL_RESET_PCI BIT(26)
  20. #define RSTCTL_RESET_SYSTEM BIT(0)
  21. static int ralink_assert_device(struct reset_controller_dev *rcdev,
  22. unsigned long id)
  23. {
  24. u32 val;
  25. if (id < 8)
  26. return -1;
  27. val = rt_sysc_r32(SYSC_REG_RESET_CTRL);
  28. val |= BIT(id);
  29. rt_sysc_w32(val, SYSC_REG_RESET_CTRL);
  30. return 0;
  31. }
  32. static int ralink_deassert_device(struct reset_controller_dev *rcdev,
  33. unsigned long id)
  34. {
  35. u32 val;
  36. if (id < 8)
  37. return -1;
  38. val = rt_sysc_r32(SYSC_REG_RESET_CTRL);
  39. val &= ~BIT(id);
  40. rt_sysc_w32(val, SYSC_REG_RESET_CTRL);
  41. return 0;
  42. }
  43. static int ralink_reset_device(struct reset_controller_dev *rcdev,
  44. unsigned long id)
  45. {
  46. ralink_assert_device(rcdev, id);
  47. return ralink_deassert_device(rcdev, id);
  48. }
  49. static struct reset_control_ops reset_ops = {
  50. .reset = ralink_reset_device,
  51. .assert = ralink_assert_device,
  52. .deassert = ralink_deassert_device,
  53. };
  54. static struct reset_controller_dev reset_dev = {
  55. .ops = &reset_ops,
  56. .owner = THIS_MODULE,
  57. .nr_resets = 32,
  58. .of_reset_n_cells = 1,
  59. };
  60. void ralink_rst_init(void)
  61. {
  62. reset_dev.of_node = of_find_compatible_node(NULL, NULL,
  63. "ralink,rt2880-reset");
  64. if (!reset_dev.of_node)
  65. pr_err("Failed to find reset controller node");
  66. else
  67. reset_controller_register(&reset_dev);
  68. }
  69. static void ralink_restart(char *command)
  70. {
  71. if (IS_ENABLED(CONFIG_PCI)) {
  72. rt_sysc_m32(0, RSTCTL_RESET_PCI, SYSC_REG_RESET_CTRL);
  73. mdelay(50);
  74. }
  75. local_irq_disable();
  76. rt_sysc_w32(RSTCTL_RESET_SYSTEM, SYSC_REG_RESET_CTRL);
  77. unreachable();
  78. }
  79. static int __init mips_reboot_setup(void)
  80. {
  81. _machine_restart = ralink_restart;
  82. return 0;
  83. }
  84. arch_initcall(mips_reboot_setup);