pegasos_eth.c 4.5 KB

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