board-sead3.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * Copyright (C) 2016 Imagination Technologies
  3. * Author: Paul Burton <paul.burton@mips.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. */
  10. #define pr_fmt(fmt) "sead3: " fmt
  11. #include <linux/errno.h>
  12. #include <linux/libfdt.h>
  13. #include <linux/printk.h>
  14. #include <linux/sizes.h>
  15. #include <asm/fw/fw.h>
  16. #include <asm/io.h>
  17. #include <asm/machine.h>
  18. #include <asm/yamon-dt.h>
  19. #define SEAD_CONFIG CKSEG1ADDR(0x1b100110)
  20. #define SEAD_CONFIG_GIC_PRESENT BIT(1)
  21. #define MIPS_REVISION CKSEG1ADDR(0x1fc00010)
  22. #define MIPS_REVISION_MACHINE (0xf << 4)
  23. #define MIPS_REVISION_MACHINE_SEAD3 (0x4 << 4)
  24. /*
  25. * Maximum 384MB RAM at physical address 0, preceding any I/O.
  26. */
  27. static struct yamon_mem_region mem_regions[] __initdata = {
  28. /* start size */
  29. { 0, SZ_256M + SZ_128M },
  30. {}
  31. };
  32. static __init bool sead3_detect(void)
  33. {
  34. uint32_t rev;
  35. rev = __raw_readl((void *)MIPS_REVISION);
  36. return (rev & MIPS_REVISION_MACHINE) == MIPS_REVISION_MACHINE_SEAD3;
  37. }
  38. static __init int append_memory(void *fdt)
  39. {
  40. return yamon_dt_append_memory(fdt, mem_regions);
  41. }
  42. static __init int remove_gic(void *fdt)
  43. {
  44. const unsigned int cpu_ehci_int = 2;
  45. const unsigned int cpu_uart_int = 4;
  46. const unsigned int cpu_eth_int = 6;
  47. int gic_off, cpu_off, uart_off, eth_off, ehci_off, err;
  48. uint32_t cfg, cpu_phandle;
  49. /* leave the GIC node intact if a GIC is present */
  50. cfg = __raw_readl((uint32_t *)SEAD_CONFIG);
  51. if (cfg & SEAD_CONFIG_GIC_PRESENT)
  52. return 0;
  53. gic_off = fdt_node_offset_by_compatible(fdt, -1, "mti,gic");
  54. if (gic_off < 0) {
  55. pr_err("unable to find DT GIC node: %d\n", gic_off);
  56. return gic_off;
  57. }
  58. err = fdt_nop_node(fdt, gic_off);
  59. if (err) {
  60. pr_err("unable to nop GIC node\n");
  61. return err;
  62. }
  63. cpu_off = fdt_node_offset_by_compatible(fdt, -1,
  64. "mti,cpu-interrupt-controller");
  65. if (cpu_off < 0) {
  66. pr_err("unable to find CPU intc node: %d\n", cpu_off);
  67. return cpu_off;
  68. }
  69. cpu_phandle = fdt_get_phandle(fdt, cpu_off);
  70. if (!cpu_phandle) {
  71. pr_err("unable to get CPU intc phandle\n");
  72. return -EINVAL;
  73. }
  74. uart_off = fdt_node_offset_by_compatible(fdt, -1, "ns16550a");
  75. while (uart_off >= 0) {
  76. err = fdt_setprop_u32(fdt, uart_off, "interrupt-parent",
  77. cpu_phandle);
  78. if (err) {
  79. pr_warn("unable to set UART interrupt-parent: %d\n",
  80. err);
  81. return err;
  82. }
  83. err = fdt_setprop_u32(fdt, uart_off, "interrupts",
  84. cpu_uart_int);
  85. if (err) {
  86. pr_err("unable to set UART interrupts property: %d\n",
  87. err);
  88. return err;
  89. }
  90. uart_off = fdt_node_offset_by_compatible(fdt, uart_off,
  91. "ns16550a");
  92. }
  93. if (uart_off != -FDT_ERR_NOTFOUND) {
  94. pr_err("error searching for UART DT node: %d\n", uart_off);
  95. return uart_off;
  96. }
  97. eth_off = fdt_node_offset_by_compatible(fdt, -1, "smsc,lan9115");
  98. if (eth_off < 0) {
  99. pr_err("unable to find ethernet DT node: %d\n", eth_off);
  100. return eth_off;
  101. }
  102. err = fdt_setprop_u32(fdt, eth_off, "interrupt-parent", cpu_phandle);
  103. if (err) {
  104. pr_err("unable to set ethernet interrupt-parent: %d\n", err);
  105. return err;
  106. }
  107. err = fdt_setprop_u32(fdt, eth_off, "interrupts", cpu_eth_int);
  108. if (err) {
  109. pr_err("unable to set ethernet interrupts property: %d\n", err);
  110. return err;
  111. }
  112. ehci_off = fdt_node_offset_by_compatible(fdt, -1, "generic-ehci");
  113. if (ehci_off < 0) {
  114. pr_err("unable to find EHCI DT node: %d\n", ehci_off);
  115. return ehci_off;
  116. }
  117. err = fdt_setprop_u32(fdt, ehci_off, "interrupt-parent", cpu_phandle);
  118. if (err) {
  119. pr_err("unable to set EHCI interrupt-parent: %d\n", err);
  120. return err;
  121. }
  122. err = fdt_setprop_u32(fdt, ehci_off, "interrupts", cpu_ehci_int);
  123. if (err) {
  124. pr_err("unable to set EHCI interrupts property: %d\n", err);
  125. return err;
  126. }
  127. return 0;
  128. }
  129. static const struct mips_fdt_fixup sead3_fdt_fixups[] __initconst = {
  130. { yamon_dt_append_cmdline, "append command line" },
  131. { append_memory, "append memory" },
  132. { remove_gic, "remove GIC when not present" },
  133. { yamon_dt_serial_config, "append serial configuration" },
  134. { },
  135. };
  136. static __init const void *sead3_fixup_fdt(const void *fdt,
  137. const void *match_data)
  138. {
  139. static unsigned char fdt_buf[16 << 10] __initdata;
  140. int err;
  141. if (fdt_check_header(fdt))
  142. panic("Corrupt DT");
  143. /* if this isn't SEAD3, something went wrong */
  144. BUG_ON(fdt_node_check_compatible(fdt, 0, "mti,sead-3"));
  145. fw_init_cmdline();
  146. err = apply_mips_fdt_fixups(fdt_buf, sizeof(fdt_buf),
  147. fdt, sead3_fdt_fixups);
  148. if (err)
  149. panic("Unable to fixup FDT: %d", err);
  150. return fdt_buf;
  151. }
  152. static __init unsigned int sead3_measure_hpt_freq(void)
  153. {
  154. void __iomem *status_reg = (void __iomem *)0xbf000410;
  155. unsigned int freq, orig, tick = 0;
  156. unsigned long flags;
  157. local_irq_save(flags);
  158. orig = readl(status_reg) & 0x2; /* get original sample */
  159. /* wait for transition */
  160. while ((readl(status_reg) & 0x2) == orig)
  161. ;
  162. orig = orig ^ 0x2; /* flip the bit */
  163. write_c0_count(0);
  164. /* wait 1 second (the sampling clock transitions every 10ms) */
  165. while (tick < 100) {
  166. /* wait for transition */
  167. while ((readl(status_reg) & 0x2) == orig)
  168. ;
  169. orig = orig ^ 0x2; /* flip the bit */
  170. tick++;
  171. }
  172. freq = read_c0_count();
  173. local_irq_restore(flags);
  174. return freq;
  175. }
  176. extern char __dtb_sead3_begin[];
  177. MIPS_MACHINE(sead3) = {
  178. .fdt = __dtb_sead3_begin,
  179. .detect = sead3_detect,
  180. .fixup_fdt = sead3_fixup_fdt,
  181. .measure_hpt_freq = sead3_measure_hpt_freq,
  182. };