chrp_pegasos_eth.c 5.1 KB

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