pegasos_eth.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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_ETH_PORT0 (PEGASOS2_SRAM_BASE)
  22. #define PEGASOS2_SRAM_BASE_ETH_PORT1 (PEGASOS2_SRAM_BASE_ETH_PORT0 + (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. /*
  42. * The orion mdio driver only covers shared + 0x4 up to shared + 0x84 - 1
  43. */
  44. static struct resource mv643xx_eth_mvmdio_resources[] = {
  45. [0] = {
  46. .name = "ethernet mdio base",
  47. .start = 0xf1000000 + MV643XX_ETH_SHARED_REGS + 0x4,
  48. .end = 0xf1000000 + MV643XX_ETH_SHARED_REGS + 0x83,
  49. .flags = IORESOURCE_MEM,
  50. },
  51. };
  52. static struct platform_device mv643xx_eth_mvmdio_device = {
  53. .name = "orion-mdio",
  54. .id = -1,
  55. .num_resources = ARRAY_SIZE(mv643xx_eth_mvmdio_resources),
  56. .resource = mv643xx_eth_shared_resources,
  57. };
  58. static struct resource mv643xx_eth_port1_resources[] = {
  59. [0] = {
  60. .name = "eth port1 irq",
  61. .start = 9,
  62. .end = 9,
  63. .flags = IORESOURCE_IRQ,
  64. },
  65. };
  66. static struct mv643xx_eth_platform_data eth_port1_pd = {
  67. .shared = &mv643xx_eth_shared_device,
  68. .port_number = 1,
  69. .phy_addr = MV643XX_ETH_PHY_ADDR(7),
  70. .tx_sram_addr = PEGASOS2_SRAM_BASE_ETH_PORT1,
  71. .tx_sram_size = PEGASOS2_SRAM_TXRING_SIZE,
  72. .tx_queue_size = PEGASOS2_SRAM_TXRING_SIZE/16,
  73. .rx_sram_addr = PEGASOS2_SRAM_BASE_ETH_PORT1 + PEGASOS2_SRAM_TXRING_SIZE,
  74. .rx_sram_size = PEGASOS2_SRAM_RXRING_SIZE,
  75. .rx_queue_size = PEGASOS2_SRAM_RXRING_SIZE/16,
  76. };
  77. static struct platform_device eth_port1_device = {
  78. .name = MV643XX_ETH_NAME,
  79. .id = 1,
  80. .num_resources = ARRAY_SIZE(mv643xx_eth_port1_resources),
  81. .resource = mv643xx_eth_port1_resources,
  82. .dev = {
  83. .platform_data = &eth_port1_pd,
  84. },
  85. };
  86. static struct platform_device *mv643xx_eth_pd_devs[] __initdata = {
  87. &mv643xx_eth_shared_device,
  88. &mv643xx_eth_mvmdio_device,
  89. &eth_port1_device,
  90. };
  91. /***********/
  92. /***********/
  93. #define MV_READ(offset,val) { val = readl(mv643xx_reg_base + offset); }
  94. #define MV_WRITE(offset,data) writel(data, mv643xx_reg_base + offset)
  95. static void __iomem *mv643xx_reg_base;
  96. static int Enable_SRAM(void)
  97. {
  98. u32 ALong;
  99. if (mv643xx_reg_base == NULL)
  100. mv643xx_reg_base = ioremap(PEGASOS2_MARVELL_REGBASE,
  101. PEGASOS2_MARVELL_REGSIZE);
  102. if (mv643xx_reg_base == NULL)
  103. return -ENOMEM;
  104. #ifdef BE_VERBOSE
  105. printk("Pegasos II/Marvell MV64361: register remapped from %p to %p\n",
  106. (void *)PEGASOS2_MARVELL_REGBASE, (void *)mv643xx_reg_base);
  107. #endif
  108. MV_WRITE(MV64340_SRAM_CONFIG, 0);
  109. MV_WRITE(MV64340_INTEGRATED_SRAM_BASE_ADDR, PEGASOS2_SRAM_BASE >> 16);
  110. MV_READ(MV64340_BASE_ADDR_ENABLE, ALong);
  111. ALong &= ~(1 << 19);
  112. MV_WRITE(MV64340_BASE_ADDR_ENABLE, ALong);
  113. ALong = 0x02;
  114. ALong |= PEGASOS2_SRAM_BASE & 0xffff0000;
  115. MV_WRITE(MV643XX_ETH_BAR_4, ALong);
  116. MV_WRITE(MV643XX_ETH_SIZE_REG_4, (PEGASOS2_SRAM_SIZE-1) & 0xffff0000);
  117. MV_READ(MV643XX_ETH_BASE_ADDR_ENABLE_REG, ALong);
  118. ALong &= ~(1 << 4);
  119. MV_WRITE(MV643XX_ETH_BASE_ADDR_ENABLE_REG, ALong);
  120. #ifdef BE_VERBOSE
  121. printk("Pegasos II/Marvell MV64361: register unmapped\n");
  122. printk("Pegasos II/Marvell MV64361: SRAM at %p, size=%x\n", (void*) PEGASOS2_SRAM_BASE, PEGASOS2_SRAM_SIZE);
  123. #endif
  124. iounmap(mv643xx_reg_base);
  125. mv643xx_reg_base = NULL;
  126. return 1;
  127. }
  128. /***********/
  129. /***********/
  130. static int __init mv643xx_eth_add_pds(void)
  131. {
  132. int ret = 0;
  133. static struct pci_device_id pci_marvell_mv64360[] = {
  134. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, PCI_DEVICE_ID_MARVELL_MV64360) },
  135. { }
  136. };
  137. #ifdef BE_VERBOSE
  138. printk("Pegasos II/Marvell MV64361: init\n");
  139. #endif
  140. if (pci_dev_present(pci_marvell_mv64360)) {
  141. ret = platform_add_devices(mv643xx_eth_pd_devs,
  142. ARRAY_SIZE(mv643xx_eth_pd_devs));
  143. if ( Enable_SRAM() < 0)
  144. {
  145. eth_port1_pd.tx_sram_addr = 0;
  146. eth_port1_pd.tx_sram_size = 0;
  147. eth_port1_pd.rx_sram_addr = 0;
  148. eth_port1_pd.rx_sram_size = 0;
  149. #ifdef BE_VERBOSE
  150. printk("Pegasos II/Marvell MV64361: Can't enable the "
  151. "SRAM\n");
  152. #endif
  153. }
  154. }
  155. #ifdef BE_VERBOSE
  156. printk("Pegasos II/Marvell MV64361: init is over\n");
  157. #endif
  158. return ret;
  159. }
  160. device_initcall(mv643xx_eth_add_pds);