setup.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. *
  4. * arch/xtensa/platform/xtavnet/setup.c
  5. *
  6. * ...
  7. *
  8. * Authors: Chris Zankel <[email protected]>
  9. * Joe Taylor <[email protected]>
  10. *
  11. * Copyright 2001 - 2006 Tensilica Inc.
  12. */
  13. #include <linux/stddef.h>
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/io.h>
  17. #include <linux/errno.h>
  18. #include <linux/reboot.h>
  19. #include <linux/kdev_t.h>
  20. #include <linux/types.h>
  21. #include <linux/major.h>
  22. #include <linux/console.h>
  23. #include <linux/delay.h>
  24. #include <linux/of.h>
  25. #include <linux/clk-provider.h>
  26. #include <linux/of_address.h>
  27. #include <linux/slab.h>
  28. #include <asm/timex.h>
  29. #include <asm/processor.h>
  30. #include <asm/platform.h>
  31. #include <asm/bootparam.h>
  32. #include <platform/lcd.h>
  33. #include <platform/hardware.h>
  34. void platform_halt(void)
  35. {
  36. lcd_disp_at_pos(" HALT ", 0);
  37. local_irq_disable();
  38. while (1)
  39. cpu_relax();
  40. }
  41. void platform_power_off(void)
  42. {
  43. lcd_disp_at_pos("POWEROFF", 0);
  44. local_irq_disable();
  45. while (1)
  46. cpu_relax();
  47. }
  48. void platform_restart(void)
  49. {
  50. /* Try software reset first. */
  51. WRITE_ONCE(*(u32 *)XTFPGA_SWRST_VADDR, 0xdead);
  52. /* If software reset did not work, flush and reset the mmu,
  53. * simulate a processor reset, and jump to the reset vector.
  54. */
  55. cpu_reset();
  56. /* control never gets here */
  57. }
  58. #ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT
  59. void __init platform_calibrate_ccount(void)
  60. {
  61. ccount_freq = *(long *)XTFPGA_CLKFRQ_VADDR;
  62. }
  63. #endif
  64. #ifdef CONFIG_USE_OF
  65. static void __init xtfpga_clk_setup(struct device_node *np)
  66. {
  67. void __iomem *base = of_iomap(np, 0);
  68. struct clk *clk;
  69. u32 freq;
  70. if (!base) {
  71. pr_err("%pOFn: invalid address\n", np);
  72. return;
  73. }
  74. freq = __raw_readl(base);
  75. iounmap(base);
  76. clk = clk_register_fixed_rate(NULL, np->name, NULL, 0, freq);
  77. if (IS_ERR(clk)) {
  78. pr_err("%pOFn: clk registration failed\n", np);
  79. return;
  80. }
  81. if (of_clk_add_provider(np, of_clk_src_simple_get, clk)) {
  82. pr_err("%pOFn: clk provider registration failed\n", np);
  83. return;
  84. }
  85. }
  86. CLK_OF_DECLARE(xtfpga_clk, "cdns,xtfpga-clock", xtfpga_clk_setup);
  87. #define MAC_LEN 6
  88. static void __init update_local_mac(struct device_node *node)
  89. {
  90. struct property *newmac;
  91. const u8* macaddr;
  92. int prop_len;
  93. macaddr = of_get_property(node, "local-mac-address", &prop_len);
  94. if (macaddr == NULL || prop_len != MAC_LEN)
  95. return;
  96. newmac = kzalloc(sizeof(*newmac) + MAC_LEN, GFP_KERNEL);
  97. if (newmac == NULL)
  98. return;
  99. newmac->value = newmac + 1;
  100. newmac->length = MAC_LEN;
  101. newmac->name = kstrdup("local-mac-address", GFP_KERNEL);
  102. if (newmac->name == NULL) {
  103. kfree(newmac);
  104. return;
  105. }
  106. memcpy(newmac->value, macaddr, MAC_LEN);
  107. ((u8*)newmac->value)[5] = (*(u32*)DIP_SWITCHES_VADDR) & 0x3f;
  108. of_update_property(node, newmac);
  109. }
  110. static int __init machine_setup(void)
  111. {
  112. struct device_node *eth = NULL;
  113. if ((eth = of_find_compatible_node(eth, NULL, "opencores,ethoc")))
  114. update_local_mac(eth);
  115. of_node_put(eth);
  116. return 0;
  117. }
  118. arch_initcall(machine_setup);
  119. #else
  120. #include <linux/serial_8250.h>
  121. #include <linux/if.h>
  122. #include <net/ethoc.h>
  123. #include <linux/usb/c67x00.h>
  124. /*----------------------------------------------------------------------------
  125. * Ethernet -- OpenCores Ethernet MAC (ethoc driver)
  126. */
  127. static struct resource ethoc_res[] = {
  128. [0] = { /* register space */
  129. .start = OETH_REGS_PADDR,
  130. .end = OETH_REGS_PADDR + OETH_REGS_SIZE - 1,
  131. .flags = IORESOURCE_MEM,
  132. },
  133. [1] = { /* buffer space */
  134. .start = OETH_SRAMBUFF_PADDR,
  135. .end = OETH_SRAMBUFF_PADDR + OETH_SRAMBUFF_SIZE - 1,
  136. .flags = IORESOURCE_MEM,
  137. },
  138. [2] = { /* IRQ number */
  139. .start = XTENSA_PIC_LINUX_IRQ(OETH_IRQ),
  140. .end = XTENSA_PIC_LINUX_IRQ(OETH_IRQ),
  141. .flags = IORESOURCE_IRQ,
  142. },
  143. };
  144. static struct ethoc_platform_data ethoc_pdata = {
  145. /*
  146. * The MAC address for these boards is 00:50:c2:13:6f:xx.
  147. * The last byte (here as zero) is read from the DIP switches on the
  148. * board.
  149. */
  150. .hwaddr = { 0x00, 0x50, 0xc2, 0x13, 0x6f, 0 },
  151. .phy_id = -1,
  152. .big_endian = XCHAL_HAVE_BE,
  153. };
  154. static struct platform_device ethoc_device = {
  155. .name = "ethoc",
  156. .id = -1,
  157. .num_resources = ARRAY_SIZE(ethoc_res),
  158. .resource = ethoc_res,
  159. .dev = {
  160. .platform_data = &ethoc_pdata,
  161. },
  162. };
  163. /*----------------------------------------------------------------------------
  164. * USB Host/Device -- Cypress CY7C67300
  165. */
  166. static struct resource c67x00_res[] = {
  167. [0] = { /* register space */
  168. .start = C67X00_PADDR,
  169. .end = C67X00_PADDR + C67X00_SIZE - 1,
  170. .flags = IORESOURCE_MEM,
  171. },
  172. [1] = { /* IRQ number */
  173. .start = XTENSA_PIC_LINUX_IRQ(C67X00_IRQ),
  174. .end = XTENSA_PIC_LINUX_IRQ(C67X00_IRQ),
  175. .flags = IORESOURCE_IRQ,
  176. },
  177. };
  178. static struct c67x00_platform_data c67x00_pdata = {
  179. .sie_config = C67X00_SIE1_HOST | C67X00_SIE2_UNUSED,
  180. .hpi_regstep = 4,
  181. };
  182. static struct platform_device c67x00_device = {
  183. .name = "c67x00",
  184. .id = -1,
  185. .num_resources = ARRAY_SIZE(c67x00_res),
  186. .resource = c67x00_res,
  187. .dev = {
  188. .platform_data = &c67x00_pdata,
  189. },
  190. };
  191. /*----------------------------------------------------------------------------
  192. * UART
  193. */
  194. static struct resource serial_resource = {
  195. .start = DUART16552_PADDR,
  196. .end = DUART16552_PADDR + 0x1f,
  197. .flags = IORESOURCE_MEM,
  198. };
  199. static struct plat_serial8250_port serial_platform_data[] = {
  200. [0] = {
  201. .mapbase = DUART16552_PADDR,
  202. .irq = XTENSA_PIC_LINUX_IRQ(DUART16552_INTNUM),
  203. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST |
  204. UPF_IOREMAP,
  205. .iotype = XCHAL_HAVE_BE ? UPIO_MEM32BE : UPIO_MEM32,
  206. .regshift = 2,
  207. .uartclk = 0, /* set in xtavnet_init() */
  208. },
  209. { },
  210. };
  211. static struct platform_device xtavnet_uart = {
  212. .name = "serial8250",
  213. .id = PLAT8250_DEV_PLATFORM,
  214. .dev = {
  215. .platform_data = serial_platform_data,
  216. },
  217. .num_resources = 1,
  218. .resource = &serial_resource,
  219. };
  220. /* platform devices */
  221. static struct platform_device *platform_devices[] __initdata = {
  222. &ethoc_device,
  223. &c67x00_device,
  224. &xtavnet_uart,
  225. };
  226. static int __init xtavnet_init(void)
  227. {
  228. /* Ethernet MAC address. */
  229. ethoc_pdata.hwaddr[5] = *(u32 *)DIP_SWITCHES_VADDR;
  230. /* Clock rate varies among FPGA bitstreams; board specific FPGA register
  231. * reports the actual clock rate.
  232. */
  233. serial_platform_data[0].uartclk = *(long *)XTFPGA_CLKFRQ_VADDR;
  234. /* register platform devices */
  235. platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
  236. /* ETHOC driver is a bit quiet; at least display Ethernet MAC, so user
  237. * knows whether they set it correctly on the DIP switches.
  238. */
  239. pr_info("XTFPGA: Ethernet MAC %pM\n", ethoc_pdata.hwaddr);
  240. ethoc_pdata.eth_clkfreq = *(long *)XTFPGA_CLKFRQ_VADDR;
  241. return 0;
  242. }
  243. /*
  244. * Register to be done during do_initcalls().
  245. */
  246. arch_initcall(xtavnet_init);
  247. #endif /* CONFIG_USE_OF */