platform.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2006, 07 Ralf Baechle (ralf@linux-mips.org)
  7. * Copyright (C) 2007 Dale Farnsworth (dale@farnsworth.org)
  8. */
  9. #include <linux/delay.h>
  10. #include <linux/if_ether.h>
  11. #include <linux/init.h>
  12. #include <linux/ioport.h>
  13. #include <linux/module.h>
  14. #include <linux/mv643xx.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/serial_8250.h>
  17. #include "ocelot_3_fpga.h"
  18. #if defined(CONFIG_MV643XX_ETH) || defined(CONFIG_MV643XX_ETH_MODULE)
  19. static struct resource mv643xx_eth_shared_resources[] = {
  20. [0] = {
  21. .name = "ethernet shared base",
  22. .start = 0xf1000000 + MV643XX_ETH_SHARED_REGS,
  23. .end = 0xf1000000 + MV643XX_ETH_SHARED_REGS +
  24. MV643XX_ETH_SHARED_REGS_SIZE - 1,
  25. .flags = IORESOURCE_MEM,
  26. },
  27. };
  28. static struct platform_device mv643xx_eth_shared_device = {
  29. .name = MV643XX_ETH_SHARED_NAME,
  30. .id = 0,
  31. .num_resources = ARRAY_SIZE(mv643xx_eth_shared_resources),
  32. .resource = mv643xx_eth_shared_resources,
  33. };
  34. #define MV_SRAM_BASE 0xfe000000UL
  35. #define MV_SRAM_SIZE (256 * 1024)
  36. #define MV_SRAM_RXRING_SIZE (MV_SRAM_SIZE / 4)
  37. #define MV_SRAM_TXRING_SIZE (MV_SRAM_SIZE / 4)
  38. #define MV_SRAM_BASE_ETH0 MV_SRAM_BASE
  39. #define MV_SRAM_BASE_ETH1 (MV_SRAM_BASE + (MV_SRAM_SIZE / 2))
  40. #define MV64x60_IRQ_ETH_0 48
  41. #define MV64x60_IRQ_ETH_1 49
  42. #define MV64x60_IRQ_ETH_2 50
  43. static struct resource mv64x60_eth0_resources[] = {
  44. [0] = {
  45. .name = "eth0 irq",
  46. .start = MV64x60_IRQ_ETH_0,
  47. .end = MV64x60_IRQ_ETH_0,
  48. .flags = IORESOURCE_IRQ,
  49. },
  50. };
  51. static struct mv643xx_eth_platform_data eth0_pd = {
  52. .port_number = 0,
  53. .tx_sram_addr = MV_SRAM_BASE_ETH0,
  54. .tx_sram_size = MV_SRAM_TXRING_SIZE,
  55. .tx_queue_size = MV_SRAM_TXRING_SIZE / 16,
  56. .rx_sram_addr = MV_SRAM_BASE_ETH0 + MV_SRAM_TXRING_SIZE,
  57. .rx_sram_size = MV_SRAM_RXRING_SIZE,
  58. .rx_queue_size = MV_SRAM_RXRING_SIZE / 16,
  59. };
  60. static struct platform_device eth0_device = {
  61. .name = MV643XX_ETH_NAME,
  62. .id = 0,
  63. .num_resources = ARRAY_SIZE(mv64x60_eth0_resources),
  64. .resource = mv64x60_eth0_resources,
  65. .dev = {
  66. .platform_data = &eth0_pd,
  67. },
  68. };
  69. static struct resource mv64x60_eth1_resources[] = {
  70. [0] = {
  71. .name = "eth1 irq",
  72. .start = MV64x60_IRQ_ETH_1,
  73. .end = MV64x60_IRQ_ETH_1,
  74. .flags = IORESOURCE_IRQ,
  75. },
  76. };
  77. static struct mv643xx_eth_platform_data eth1_pd = {
  78. .port_number = 1,
  79. .tx_sram_addr = MV_SRAM_BASE_ETH1,
  80. .tx_sram_size = MV_SRAM_TXRING_SIZE,
  81. .tx_queue_size = MV_SRAM_TXRING_SIZE / 16,
  82. .rx_sram_addr = MV_SRAM_BASE_ETH1 + MV_SRAM_TXRING_SIZE,
  83. .rx_sram_size = MV_SRAM_RXRING_SIZE,
  84. .rx_queue_size = MV_SRAM_RXRING_SIZE / 16,
  85. };
  86. static struct platform_device eth1_device = {
  87. .name = MV643XX_ETH_NAME,
  88. .id = 1,
  89. .num_resources = ARRAY_SIZE(mv64x60_eth1_resources),
  90. .resource = mv64x60_eth1_resources,
  91. .dev = {
  92. .platform_data = &eth1_pd,
  93. },
  94. };
  95. static struct resource mv64x60_eth2_resources[] = {
  96. [0] = {
  97. .name = "eth2 irq",
  98. .start = MV64x60_IRQ_ETH_2,
  99. .end = MV64x60_IRQ_ETH_2,
  100. .flags = IORESOURCE_IRQ,
  101. },
  102. };
  103. static struct mv643xx_eth_platform_data eth2_pd = {
  104. .port_number = 2,
  105. };
  106. static struct platform_device eth2_device = {
  107. .name = MV643XX_ETH_NAME,
  108. .id = 2,
  109. .num_resources = ARRAY_SIZE(mv64x60_eth2_resources),
  110. .resource = mv64x60_eth2_resources,
  111. .dev = {
  112. .platform_data = &eth2_pd,
  113. },
  114. };
  115. static struct platform_device *mv643xx_eth_pd_devs[] __initdata = {
  116. &mv643xx_eth_shared_device,
  117. &eth0_device,
  118. &eth1_device,
  119. &eth2_device,
  120. };
  121. static u8 __init exchange_bit(u8 val, u8 cs)
  122. {
  123. /* place the data */
  124. OCELOT_FPGA_WRITE((val << 2) | cs, EEPROM_MODE);
  125. udelay(1);
  126. /* turn the clock on */
  127. OCELOT_FPGA_WRITE((val << 2) | cs | 0x2, EEPROM_MODE);
  128. udelay(1);
  129. /* turn the clock off and read-strobe */
  130. OCELOT_FPGA_WRITE((val << 2) | cs | 0x10, EEPROM_MODE);
  131. /* return the data */
  132. return (OCELOT_FPGA_READ(EEPROM_MODE) >> 3) & 0x1;
  133. }
  134. static void __init get_mac(char dest[6])
  135. {
  136. u8 read_opcode[12] = {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  137. int i,j;
  138. for (i = 0; i < 12; i++)
  139. exchange_bit(read_opcode[i], 1);
  140. for (j = 0; j < 6; j++) {
  141. dest[j] = 0;
  142. for (i = 0; i < 8; i++) {
  143. dest[j] <<= 1;
  144. dest[j] |= exchange_bit(0, 1);
  145. }
  146. }
  147. /* turn off CS */
  148. exchange_bit(0,0);
  149. }
  150. /*
  151. * Copy and increment ethernet MAC address by a small value.
  152. *
  153. * This is useful for systems where the only one MAC address is stored in
  154. * non-volatile memory for multiple ports.
  155. */
  156. static inline void eth_mac_add(unsigned char *dst, unsigned char *src,
  157. unsigned int add)
  158. {
  159. int i;
  160. BUG_ON(add >= 256);
  161. for (i = ETH_ALEN; i >= 0; i--) {
  162. dst[i] = src[i] + add;
  163. add = dst[i] < src[i]; /* compute carry */
  164. }
  165. WARN_ON(add);
  166. }
  167. static int __init mv643xx_eth_add_pds(void)
  168. {
  169. unsigned char mac[ETH_ALEN];
  170. int ret;
  171. get_mac(mac);
  172. eth_mac_add(eth0_pd.mac_addr, mac, 0);
  173. eth_mac_add(eth1_pd.mac_addr, mac, 1);
  174. eth_mac_add(eth2_pd.mac_addr, mac, 2);
  175. ret = platform_add_devices(mv643xx_eth_pd_devs,
  176. ARRAY_SIZE(mv643xx_eth_pd_devs));
  177. return ret;
  178. }
  179. device_initcall(mv643xx_eth_add_pds);
  180. #endif /* defined(CONFIG_MV643XX_ETH) || defined(CONFIG_MV643XX_ETH_MODULE) */
  181. #define OCELOT3_UART_FLAGS (UPF_BOOT_AUTOCONF | UPF_SKIP_TEST)
  182. static struct plat_serial8250_port uart8250_data[] = {
  183. {
  184. .membase = (signed long) 0xfd000020,
  185. .irq = 6,
  186. .uartclk = 20000000,
  187. .iotype = UPIO_MEM,
  188. .flags = OCELOT3_UART_FLAGS,
  189. .regshift = 2,
  190. },
  191. { },
  192. };
  193. static struct platform_device uart8250_device = {
  194. .name = "serial8250",
  195. .id = PLAT8250_DEV_PLATFORM,
  196. .dev = {
  197. .platform_data = uart8250_data,
  198. },
  199. };
  200. static int __init uart8250_init(void)
  201. {
  202. return platform_device_register(&uart8250_device);
  203. }
  204. module_init(uart8250_init);
  205. MODULE_AUTHOR("Ralf Baechle <ralf@linux-mips.org>");
  206. MODULE_LICENSE("GPL");
  207. MODULE_DESCRIPTION("8250 UART probe driver for the Ocelot 3");