2
0

adm6996.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * ADM6996 switch driver
  3. *
  4. * Copyright (c) 2008 Felix Fietkau <[email protected]>
  5. * Copyright (c) 2010,2011 Peter Lebbing <[email protected]>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License v2 as published by the
  9. * Free Software Foundation
  10. */
  11. #ifndef __ADM6996_H
  12. #define __ADM6996_H
  13. /*
  14. * ADM_PHY_PORTS: Number of ports with a PHY.
  15. * We only control ports 0 to 3, because if 4 is connected, it is most likely
  16. * not connected to the switch but to a separate MII and MAC for the WAN port.
  17. */
  18. #define ADM_PHY_PORTS 4
  19. #define ADM_NUM_PORTS 6
  20. #define ADM_CPU_PORT 5
  21. #define ADM_NUM_VLANS 16
  22. #define ADM_VLAN_MAX_ID 4094
  23. enum admreg {
  24. ADM_EEPROM_BASE = 0x0,
  25. ADM_P0_CFG = ADM_EEPROM_BASE + 1,
  26. ADM_P1_CFG = ADM_EEPROM_BASE + 3,
  27. ADM_P2_CFG = ADM_EEPROM_BASE + 5,
  28. ADM_P3_CFG = ADM_EEPROM_BASE + 7,
  29. ADM_P4_CFG = ADM_EEPROM_BASE + 8,
  30. ADM_P5_CFG = ADM_EEPROM_BASE + 9,
  31. ADM_SYSC0 = ADM_EEPROM_BASE + 0xa,
  32. ADM_VLAN_PRIOMAP = ADM_EEPROM_BASE + 0xe,
  33. ADM_SYSC3 = ADM_EEPROM_BASE + 0x11,
  34. /* Input Force No Tag Enable */
  35. ADM_IFNTE = ADM_EEPROM_BASE + 0x20,
  36. ADM_VID_CHECK = ADM_EEPROM_BASE + 0x26,
  37. ADM_P0_PVID = ADM_EEPROM_BASE + 0x28,
  38. ADM_P1_PVID = ADM_EEPROM_BASE + 0x29,
  39. /* Output Tag Bypass Enable and P2 PVID */
  40. ADM_OTBE_P2_PVID = ADM_EEPROM_BASE + 0x2a,
  41. ADM_P3_P4_PVID = ADM_EEPROM_BASE + 0x2b,
  42. ADM_P5_PVID = ADM_EEPROM_BASE + 0x2c,
  43. ADM_EEPROM_EXT_BASE = 0x40,
  44. #define ADM_VLAN_FILT_L(n) (ADM_EEPROM_EXT_BASE + 2 * (n))
  45. #define ADM_VLAN_FILT_H(n) (ADM_EEPROM_EXT_BASE + 1 + 2 * (n))
  46. ADM_COUNTER_BASE = 0xa0,
  47. ADM_SIG0 = ADM_COUNTER_BASE + 0,
  48. ADM_SIG1 = ADM_COUNTER_BASE + 1,
  49. ADM_PHY_BASE = 0x200,
  50. #define ADM_PHY_PORT(n) (ADM_PHY_BASE + (0x20 * n))
  51. };
  52. /* Chip identification patterns */
  53. #define ADM_SIG0_MASK 0xffff
  54. #define ADM_SIG0_VAL 0x1023
  55. #define ADM_SIG1_MASK 0xffff
  56. #define ADM_SIG1_VAL 0x0007
  57. enum {
  58. ADM_PHYCFG_COLTST = (1 << 7), /* Enable collision test */
  59. ADM_PHYCFG_DPLX = (1 << 8), /* Enable full duplex */
  60. ADM_PHYCFG_ANEN_RST = (1 << 9), /* Restart auto negotiation (self clear) */
  61. ADM_PHYCFG_ISO = (1 << 10), /* Isolate PHY */
  62. ADM_PHYCFG_PDN = (1 << 11), /* Power down PHY */
  63. ADM_PHYCFG_ANEN = (1 << 12), /* Enable auto negotiation */
  64. ADM_PHYCFG_SPEED_100 = (1 << 13), /* Enable 100 Mbit/s */
  65. ADM_PHYCFG_LPBK = (1 << 14), /* Enable loopback operation */
  66. ADM_PHYCFG_RST = (1 << 15), /* Reset the port (self clear) */
  67. ADM_PHYCFG_INIT = (
  68. ADM_PHYCFG_RST |
  69. ADM_PHYCFG_SPEED_100 |
  70. ADM_PHYCFG_ANEN |
  71. ADM_PHYCFG_ANEN_RST
  72. )
  73. };
  74. enum {
  75. ADM_PORTCFG_FC = (1 << 0), /* Enable 802.x flow control */
  76. ADM_PORTCFG_AN = (1 << 1), /* Enable auto-negotiation */
  77. ADM_PORTCFG_SPEED_100 = (1 << 2), /* Enable 100 Mbit/s */
  78. ADM_PORTCFG_DPLX = (1 << 3), /* Enable full duplex */
  79. ADM_PORTCFG_OT = (1 << 4), /* Output tagged packets */
  80. ADM_PORTCFG_PD = (1 << 5), /* Port disable */
  81. ADM_PORTCFG_TV_PRIO = (1 << 6), /* 0 = VLAN based priority
  82. * 1 = TOS based priority */
  83. ADM_PORTCFG_PPE = (1 << 7), /* Port based priority enable */
  84. ADM_PORTCFG_PP_S = (1 << 8), /* Port based priority, 2 bits */
  85. ADM_PORTCFG_PVID_BASE = (1 << 10), /* Primary VLAN id, 4 bits */
  86. ADM_PORTCFG_FSE = (1 << 14), /* Fx select enable */
  87. ADM_PORTCFG_CAM = (1 << 15), /* Crossover Auto MDIX */
  88. ADM_PORTCFG_INIT = (
  89. ADM_PORTCFG_FC |
  90. ADM_PORTCFG_AN |
  91. ADM_PORTCFG_SPEED_100 |
  92. ADM_PORTCFG_DPLX |
  93. ADM_PORTCFG_CAM
  94. ),
  95. ADM_PORTCFG_CPU = (
  96. ADM_PORTCFG_FC |
  97. ADM_PORTCFG_SPEED_100 |
  98. ADM_PORTCFG_OT |
  99. ADM_PORTCFG_DPLX
  100. ),
  101. };
  102. #define ADM_PORTCFG_PPID(n) ((n & 0x3) << 8)
  103. #define ADM_PORTCFG_PVID(n) ((n & 0xf) << 10)
  104. #define ADM_PORTCFG_PVID_MASK (0xf << 10)
  105. #define ADM_IFNTE_MASK (0x3f << 9)
  106. #define ADM_VID_CHECK_MASK (0x3f << 6)
  107. #define ADM_P0_PVID_VAL(n) ((((n) & 0xff0) >> 4) << 0)
  108. #define ADM_P1_PVID_VAL(n) ((((n) & 0xff0) >> 4) << 0)
  109. #define ADM_P2_PVID_VAL(n) ((((n) & 0xff0) >> 4) << 0)
  110. #define ADM_P3_PVID_VAL(n) ((((n) & 0xff0) >> 4) << 0)
  111. #define ADM_P4_PVID_VAL(n) ((((n) & 0xff0) >> 4) << 8)
  112. #define ADM_P5_PVID_VAL(n) ((((n) & 0xff0) >> 4) << 0)
  113. #define ADM_P2_PVID_MASK 0xff
  114. #define ADM_OTBE(n) (((n) & 0x3f) << 8)
  115. #define ADM_OTBE_MASK (0x3f << 8)
  116. /* ADM_SYSC0 */
  117. enum {
  118. ADM_NTTE = (1 << 2), /* New Tag Transmit Enable */
  119. ADM_RVID1 = (1 << 8) /* Replace VLAN ID 1 */
  120. };
  121. /* Tag Based VLAN in ADM_SYSC3 */
  122. #define ADM_TBV (1 << 5)
  123. static const u8 adm_portcfg[] = {
  124. [0] = ADM_P0_CFG,
  125. [1] = ADM_P1_CFG,
  126. [2] = ADM_P2_CFG,
  127. [3] = ADM_P3_CFG,
  128. [4] = ADM_P4_CFG,
  129. [5] = ADM_P5_CFG,
  130. };
  131. /* Fields in ADM_VLAN_FILT_L(x) */
  132. #define ADM_VLAN_FILT_FID(n) (((n) & 0xf) << 12)
  133. #define ADM_VLAN_FILT_TAGGED(n) (((n) & 0x3f) << 6)
  134. #define ADM_VLAN_FILT_MEMBER(n) (((n) & 0x3f) << 0)
  135. #define ADM_VLAN_FILT_MEMBER_MASK 0x3f
  136. /* Fields in ADM_VLAN_FILT_H(x) */
  137. #define ADM_VLAN_FILT_VALID (1 << 15)
  138. #define ADM_VLAN_FILT_VID(n) (((n) & 0xfff) << 0)
  139. /*
  140. * Split the register address in phy id and register
  141. * it will get combined again by the mdio bus op
  142. */
  143. #define PHYADDR(_reg) ((_reg >> 5) & 0xff), (_reg & 0x1f)
  144. #endif