board-ingenic.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Support for Ingenic SoCs
  4. *
  5. * Copyright (C) 2009-2010, Lars-Peter Clausen <[email protected]>
  6. * Copyright (C) 2011, Maarten ter Huurne <[email protected]>
  7. * Copyright (C) 2020 Paul Cercueil <[email protected]>
  8. */
  9. #include <linux/clk.h>
  10. #include <linux/of.h>
  11. #include <linux/of_address.h>
  12. #include <linux/of_fdt.h>
  13. #include <linux/pm.h>
  14. #include <linux/sizes.h>
  15. #include <linux/suspend.h>
  16. #include <linux/types.h>
  17. #include <asm/bootinfo.h>
  18. #include <asm/machine.h>
  19. #include <asm/reboot.h>
  20. static __init char *ingenic_get_system_type(unsigned long machtype)
  21. {
  22. switch (machtype) {
  23. case MACH_INGENIC_X2100:
  24. return "X2100";
  25. case MACH_INGENIC_X2000H:
  26. return "X2000H";
  27. case MACH_INGENIC_X2000E:
  28. return "X2000E";
  29. case MACH_INGENIC_X2000:
  30. return "X2000";
  31. case MACH_INGENIC_X1830:
  32. return "X1830";
  33. case MACH_INGENIC_X1000E:
  34. return "X1000E";
  35. case MACH_INGENIC_X1000:
  36. return "X1000";
  37. case MACH_INGENIC_JZ4780:
  38. return "JZ4780";
  39. case MACH_INGENIC_JZ4775:
  40. return "JZ4775";
  41. case MACH_INGENIC_JZ4770:
  42. return "JZ4770";
  43. case MACH_INGENIC_JZ4760B:
  44. return "JZ4760B";
  45. case MACH_INGENIC_JZ4760:
  46. return "JZ4760";
  47. case MACH_INGENIC_JZ4755:
  48. return "JZ4755";
  49. case MACH_INGENIC_JZ4750:
  50. return "JZ4750";
  51. case MACH_INGENIC_JZ4725B:
  52. return "JZ4725B";
  53. case MACH_INGENIC_JZ4730:
  54. return "JZ4730";
  55. default:
  56. return "JZ4740";
  57. }
  58. }
  59. static __init const void *ingenic_fixup_fdt(const void *fdt, const void *match_data)
  60. {
  61. /*
  62. * Old devicetree files for the qi,lb60 board did not have a /memory
  63. * node. Hardcode the memory info here.
  64. */
  65. if (!fdt_node_check_compatible(fdt, 0, "qi,lb60") &&
  66. fdt_path_offset(fdt, "/memory") < 0)
  67. early_init_dt_add_memory_arch(0, SZ_32M);
  68. mips_machtype = (unsigned long)match_data;
  69. system_type = ingenic_get_system_type(mips_machtype);
  70. return fdt;
  71. }
  72. static const struct of_device_id ingenic_of_match[] __initconst = {
  73. { .compatible = "ingenic,jz4730", .data = (void *)MACH_INGENIC_JZ4730 },
  74. { .compatible = "ingenic,jz4740", .data = (void *)MACH_INGENIC_JZ4740 },
  75. { .compatible = "ingenic,jz4725b", .data = (void *)MACH_INGENIC_JZ4725B },
  76. { .compatible = "ingenic,jz4750", .data = (void *)MACH_INGENIC_JZ4750 },
  77. { .compatible = "ingenic,jz4755", .data = (void *)MACH_INGENIC_JZ4755 },
  78. { .compatible = "ingenic,jz4760", .data = (void *)MACH_INGENIC_JZ4760 },
  79. { .compatible = "ingenic,jz4760b", .data = (void *)MACH_INGENIC_JZ4760B },
  80. { .compatible = "ingenic,jz4770", .data = (void *)MACH_INGENIC_JZ4770 },
  81. { .compatible = "ingenic,jz4775", .data = (void *)MACH_INGENIC_JZ4775 },
  82. { .compatible = "ingenic,jz4780", .data = (void *)MACH_INGENIC_JZ4780 },
  83. { .compatible = "ingenic,x1000", .data = (void *)MACH_INGENIC_X1000 },
  84. { .compatible = "ingenic,x1000e", .data = (void *)MACH_INGENIC_X1000E },
  85. { .compatible = "ingenic,x1830", .data = (void *)MACH_INGENIC_X1830 },
  86. { .compatible = "ingenic,x2000", .data = (void *)MACH_INGENIC_X2000 },
  87. { .compatible = "ingenic,x2000e", .data = (void *)MACH_INGENIC_X2000E },
  88. { .compatible = "ingenic,x2000h", .data = (void *)MACH_INGENIC_X2000H },
  89. { .compatible = "ingenic,x2100", .data = (void *)MACH_INGENIC_X2100 },
  90. {}
  91. };
  92. MIPS_MACHINE(ingenic) = {
  93. .matches = ingenic_of_match,
  94. .fixup_fdt = ingenic_fixup_fdt,
  95. };
  96. static void ingenic_wait_instr(void)
  97. {
  98. __asm__(".set push;\n"
  99. ".set mips3;\n"
  100. "wait;\n"
  101. ".set pop;\n"
  102. );
  103. }
  104. static void ingenic_halt(void)
  105. {
  106. for (;;)
  107. ingenic_wait_instr();
  108. }
  109. static int __maybe_unused ingenic_pm_enter(suspend_state_t state)
  110. {
  111. ingenic_wait_instr();
  112. return 0;
  113. }
  114. static const struct platform_suspend_ops ingenic_pm_ops __maybe_unused = {
  115. .valid = suspend_valid_only_mem,
  116. .enter = ingenic_pm_enter,
  117. };
  118. static int __init ingenic_pm_init(void)
  119. {
  120. if (boot_cpu_type() == CPU_XBURST) {
  121. if (IS_ENABLED(CONFIG_PM_SLEEP))
  122. suspend_set_ops(&ingenic_pm_ops);
  123. _machine_halt = ingenic_halt;
  124. }
  125. return 0;
  126. }
  127. late_initcall(ingenic_pm_init);