setup.c 6.7 KB

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