pegasos_eth.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * arch/ppc/platforms/chrp_pegasos_eth.c
  3. *
  4. * Copyright (C) 2005 Sven Luther <sl@bplan-gmbh.de>
  5. * Thanks to :
  6. * Dale Farnsworth <dale@farnsworth.org>
  7. * Mark A. Greer <mgreer@mvista.com>
  8. * Nicolas DET <nd@bplan-gmbh.de>
  9. * Benjamin Herrenschmidt <benh@kernel.crashing.org>
  10. * And anyone else who helped me on this.
  11. */
  12. #include <linux/types.h>
  13. #include <linux/init.h>
  14. #include <linux/ioport.h>
  15. #include <linux/device.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/mv643xx.h>
  18. #include <linux/pci.h>
  19. #define PEGASOS2_MARVELL_REGBASE (0xf1000000)
  20. #define PEGASOS2_MARVELL_REGSIZE (0x00004000)
  21. #define PEGASOS2_SRAM_BASE (0xf2000000)
  22. #define PEGASOS2_SRAM_SIZE (256*1024)
  23. #define PEGASOS2_SRAM_BASE_ETH0 (PEGASOS2_SRAM_BASE)
  24. #define PEGASOS2_SRAM_BASE_ETH1 (PEGASOS2_SRAM_BASE_ETH0 + (PEGASOS2_SRAM_SIZE / 2) )
  25. #define PEGASOS2_SRAM_RXRING_SIZE (PEGASOS2_SRAM_SIZE/4)
  26. #define PEGASOS2_SRAM_TXRING_SIZE (PEGASOS2_SRAM_SIZE/4)
  27. #undef BE_VERBOSE
  28. static struct resource mv643xx_eth_shared_resources[] = {
  29. [0] = {
  30. .name = "ethernet shared base",
  31. .start = 0xf1000000 + MV643XX_ETH_SHARED_REGS,
  32. .end = 0xf1000000 + MV643XX_ETH_SHARED_REGS +
  33. MV643XX_ETH_SHARED_REGS_SIZE - 1,
  34. .flags = IORESOURCE_MEM,
  35. },
  36. };
  37. static struct platform_device mv643xx_eth_shared_device = {
  38. .name = MV643XX_ETH_SHARED_NAME,
  39. .id = 0,
  40. .num_resources = ARRAY_SIZE(mv643xx_eth_shared_resources),
  41. .resource = mv643xx_eth_shared_resources,
  42. };
  43. static struct resource mv643xx_eth0_resources[] = {
  44. [0] = {
  45. .name = "eth0 irq",
  46. .start = 9,
  47. .end = 9,
  48. .flags = IORESOURCE_IRQ,
  49. },
  50. };
  51. static struct mv643xx_eth_platform_data eth0_pd = {
  52. .tx_sram_addr = PEGASOS2_SRAM_BASE_ETH0,
  53. .tx_sram_size = PEGASOS2_SRAM_TXRING_SIZE,
  54. .tx_queue_size = PEGASOS2_SRAM_TXRING_SIZE/16,
  55. .rx_sram_addr = PEGASOS2_SRAM_BASE_ETH0 + PEGASOS2_SRAM_TXRING_SIZE,
  56. .rx_sram_size = PEGASOS2_SRAM_RXRING_SIZE,
  57. .rx_queue_size = PEGASOS2_SRAM_RXRING_SIZE/16,
  58. };
  59. static struct platform_device eth0_device = {
  60. .name = MV643XX_ETH_NAME,
  61. .id = 0,
  62. .num_resources = ARRAY_SIZE(mv643xx_eth0_resources),
  63. .resource = mv643xx_eth0_resources,
  64. .dev = {
  65. .platform_data = &eth0_pd,
  66. },
  67. };
  68. static struct resource mv643xx_eth1_resources[] = {
  69. [0] = {
  70. .name = "eth1 irq",
  71. .start = 9,
  72. .end = 9,
  73. .flags = IORESOURCE_IRQ,
  74. },
  75. };
  76. static struct mv643xx_eth_platform_data eth1_pd = {
  77. .tx_sram_addr = PEGASOS2_SRAM_BASE_ETH1,
  78. .tx_sram_size = PEGASOS2_SRAM_TXRING_SIZE,
  79. .tx_queue_size = PEGASOS2_SRAM_TXRING_SIZE/16,
  80. .rx_sram_addr = PEGASOS2_SRAM_BASE_ETH1 + PEGASOS2_SRAM_TXRING_SIZE,
  81. .rx_sram_size = PEGASOS2_SRAM_RXRING_SIZE,
  82. .rx_queue_size = PEGASOS2_SRAM_RXRING_SIZE/16,
  83. };
  84. static struct platform_device eth1_device = {
  85. .name = MV643XX_ETH_NAME,
  86. .id = 1,
  87. .num_resources = ARRAY_SIZE(mv643xx_eth1_resources),
  88. .resource = mv643xx_eth1_resources,
  89. .dev = {
  90. .platform_data = &eth1_pd,
  91. },
  92. };
  93. static struct platform_device *mv643xx_eth_pd_devs[] __initdata = {
  94. &mv643xx_eth_shared_device,
  95. &eth0_device,
  96. &eth1_device,
  97. };
  98. /***********/
  99. /***********/
  100. #define MV_READ(offset,val) { val = readl(mv643xx_reg_base + offset); }
  101. #define MV_WRITE(offset,data) writel(data, mv643xx_reg_base + offset)
  102. static void __iomem *mv643xx_reg_base;
  103. static int Enable_SRAM(void)
  104. {
  105. u32 ALong;
  106. if (mv643xx_reg_base == NULL)
  107. mv643xx_reg_base = ioremap(PEGASOS2_MARVELL_REGBASE,
  108. PEGASOS2_MARVELL_REGSIZE);
  109. if (mv643xx_reg_base == NULL)
  110. return -ENOMEM;
  111. #ifdef BE_VERBOSE
  112. printk("Pegasos II/Marvell MV64361: register remapped from %p to %p\n",
  113. (void *)PEGASOS2_MARVELL_REGBASE, (void *)mv643xx_reg_base);
  114. #endif
  115. MV_WRITE(MV64340_SRAM_CONFIG, 0);
  116. MV_WRITE(MV64340_INTEGRATED_SRAM_BASE_ADDR, PEGASOS2_SRAM_BASE >> 16);
  117. MV_READ(MV64340_BASE_ADDR_ENABLE, ALong);
  118. ALong &= ~(1 << 19);
  119. MV_WRITE(MV64340_BASE_ADDR_ENABLE, ALong);
  120. ALong = 0x02;
  121. ALong |= PEGASOS2_SRAM_BASE & 0xffff0000;
  122. MV_WRITE(MV643XX_ETH_BAR_4, ALong);
  123. MV_WRITE(MV643XX_ETH_SIZE_REG_4, (PEGASOS2_SRAM_SIZE-1) & 0xffff0000);
  124. MV_READ(MV643XX_ETH_BASE_ADDR_ENABLE_REG, ALong);
  125. ALong &= ~(1 << 4);
  126. MV_WRITE(MV643XX_ETH_BASE_ADDR_ENABLE_REG, ALong);
  127. #ifdef BE_VERBOSE
  128. printk("Pegasos II/Marvell MV64361: register unmapped\n");
  129. printk("Pegasos II/Marvell MV64361: SRAM at %p, size=%x\n", (void*) PEGASOS2_SRAM_BASE, PEGASOS2_SRAM_SIZE);
  130. #endif
  131. iounmap(mv643xx_reg_base);
  132. mv643xx_reg_base = NULL;
  133. return 1;
  134. }
  135. /***********/
  136. /***********/
  137. int mv643xx_eth_add_pds(void)
  138. {
  139. int ret = 0;
  140. static struct pci_device_id pci_marvell_mv64360[] = {
  141. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, PCI_DEVICE_ID_MARVELL_MV64360) },
  142. { }
  143. };
  144. #ifdef BE_VERBOSE
  145. printk("Pegasos II/Marvell MV64361: init\n");
  146. #endif
  147. if (pci_dev_present(pci_marvell_mv64360)) {
  148. ret = platform_add_devices(mv643xx_eth_pd_devs,
  149. ARRAY_SIZE(mv643xx_eth_pd_devs));
  150. if ( Enable_SRAM() < 0)
  151. {
  152. eth0_pd.tx_sram_addr = 0;
  153. eth0_pd.tx_sram_size = 0;
  154. eth0_pd.rx_sram_addr = 0;
  155. eth0_pd.rx_sram_size = 0;
  156. eth1_pd.tx_sram_addr = 0;
  157. eth1_pd.tx_sram_size = 0;
  158. eth1_pd.rx_sram_addr = 0;
  159. eth1_pd.rx_sram_size = 0;
  160. #ifdef BE_VERBOSE
  161. printk("Pegasos II/Marvell MV64361: Can't enable the "
  162. "SRAM\n");
  163. #endif
  164. }
  165. }
  166. #ifdef BE_VERBOSE
  167. printk("Pegasos II/Marvell MV64361: init is over\n");
  168. #endif
  169. return ret;
  170. }
  171. device_initcall(mv643xx_eth_add_pds);