reset.c 2.1 KB

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