pegasos_eth.c 5.2 KB

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