rtl8367.c 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835
  1. /*
  2. * Platform driver for the Realtek RTL8367R/M ethernet switches
  3. *
  4. * Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/device.h>
  14. #include <linux/of.h>
  15. #include <linux/of_platform.h>
  16. #include <linux/delay.h>
  17. #include <linux/skbuff.h>
  18. #include <linux/rtl8367.h>
  19. #include "rtl8366_smi.h"
  20. #define RTL8367_RESET_DELAY 1000 /* msecs*/
  21. #define RTL8367_PHY_ADDR_MAX 8
  22. #define RTL8367_PHY_REG_MAX 31
  23. #define RTL8367_VID_MASK 0xffff
  24. #define RTL8367_FID_MASK 0xfff
  25. #define RTL8367_UNTAG_MASK 0xffff
  26. #define RTL8367_MEMBER_MASK 0xffff
  27. #define RTL8367_PORT_CFG_REG(_p) (0x000e + 0x20 * (_p))
  28. #define RTL8367_PORT_CFG_EGRESS_MODE_SHIFT 4
  29. #define RTL8367_PORT_CFG_EGRESS_MODE_MASK 0x3
  30. #define RTL8367_PORT_CFG_EGRESS_MODE_ORIGINAL 0
  31. #define RTL8367_PORT_CFG_EGRESS_MODE_KEEP 1
  32. #define RTL8367_PORT_CFG_EGRESS_MODE_PRI 2
  33. #define RTL8367_PORT_CFG_EGRESS_MODE_REAL 3
  34. #define RTL8367_BYPASS_LINE_RATE_REG 0x03f7
  35. #define RTL8367_TA_CTRL_REG 0x0500
  36. #define RTL8367_TA_CTRL_STATUS BIT(12)
  37. #define RTL8367_TA_CTRL_METHOD BIT(5)
  38. #define RTL8367_TA_CTRL_CMD_SHIFT 4
  39. #define RTL8367_TA_CTRL_CMD_READ 0
  40. #define RTL8367_TA_CTRL_CMD_WRITE 1
  41. #define RTL8367_TA_CTRL_TABLE_SHIFT 0
  42. #define RTL8367_TA_CTRL_TABLE_ACLRULE 1
  43. #define RTL8367_TA_CTRL_TABLE_ACLACT 2
  44. #define RTL8367_TA_CTRL_TABLE_CVLAN 3
  45. #define RTL8367_TA_CTRL_TABLE_L2 4
  46. #define RTL8367_TA_CTRL_CVLAN_READ \
  47. ((RTL8367_TA_CTRL_CMD_READ << RTL8367_TA_CTRL_CMD_SHIFT) | \
  48. RTL8367_TA_CTRL_TABLE_CVLAN)
  49. #define RTL8367_TA_CTRL_CVLAN_WRITE \
  50. ((RTL8367_TA_CTRL_CMD_WRITE << RTL8367_TA_CTRL_CMD_SHIFT) | \
  51. RTL8367_TA_CTRL_TABLE_CVLAN)
  52. #define RTL8367_TA_ADDR_REG 0x0501
  53. #define RTL8367_TA_ADDR_MASK 0x3fff
  54. #define RTL8367_TA_DATA_REG(_x) (0x0503 + (_x))
  55. #define RTL8367_TA_VLAN_DATA_SIZE 4
  56. #define RTL8367_TA_VLAN_VID_MASK RTL8367_VID_MASK
  57. #define RTL8367_TA_VLAN_MEMBER_SHIFT 0
  58. #define RTL8367_TA_VLAN_MEMBER_MASK RTL8367_MEMBER_MASK
  59. #define RTL8367_TA_VLAN_FID_SHIFT 0
  60. #define RTL8367_TA_VLAN_FID_MASK RTL8367_FID_MASK
  61. #define RTL8367_TA_VLAN_UNTAG1_SHIFT 14
  62. #define RTL8367_TA_VLAN_UNTAG1_MASK 0x3
  63. #define RTL8367_TA_VLAN_UNTAG2_SHIFT 0
  64. #define RTL8367_TA_VLAN_UNTAG2_MASK 0x3fff
  65. #define RTL8367_VLAN_PVID_CTRL_REG(_p) (0x0700 + (_p) / 2)
  66. #define RTL8367_VLAN_PVID_CTRL_MASK 0x1f
  67. #define RTL8367_VLAN_PVID_CTRL_SHIFT(_p) (8 * ((_p) % 2))
  68. #define RTL8367_VLAN_MC_BASE(_x) (0x0728 + (_x) * 4)
  69. #define RTL8367_VLAN_MC_DATA_SIZE 4
  70. #define RTL8367_VLAN_MC_MEMBER_SHIFT 0
  71. #define RTL8367_VLAN_MC_MEMBER_MASK RTL8367_MEMBER_MASK
  72. #define RTL8367_VLAN_MC_FID_SHIFT 0
  73. #define RTL8367_VLAN_MC_FID_MASK RTL8367_FID_MASK
  74. #define RTL8367_VLAN_MC_EVID_SHIFT 0
  75. #define RTL8367_VLAN_MC_EVID_MASK RTL8367_VID_MASK
  76. #define RTL8367_VLAN_CTRL_REG 0x07a8
  77. #define RTL8367_VLAN_CTRL_ENABLE BIT(0)
  78. #define RTL8367_VLAN_INGRESS_REG 0x07a9
  79. #define RTL8367_PORT_ISOLATION_REG(_p) (0x08a2 + (_p))
  80. #define RTL8367_MIB_COUNTER_REG(_x) (0x1000 + (_x))
  81. #define RTL8367_MIB_ADDRESS_REG 0x1004
  82. #define RTL8367_MIB_CTRL_REG(_x) (0x1005 + (_x))
  83. #define RTL8367_MIB_CTRL_GLOBAL_RESET_MASK BIT(11)
  84. #define RTL8367_MIB_CTRL_QM_RESET_MASK BIT(10)
  85. #define RTL8367_MIB_CTRL_PORT_RESET_MASK(_p) BIT(2 + (_p))
  86. #define RTL8367_MIB_CTRL_RESET_MASK BIT(1)
  87. #define RTL8367_MIB_CTRL_BUSY_MASK BIT(0)
  88. #define RTL8367_MIB_COUNT 36
  89. #define RTL8367_MIB_COUNTER_PORT_OFFSET 0x0050
  90. #define RTL8367_SWC0_REG 0x1200
  91. #define RTL8367_SWC0_MAX_LENGTH_SHIFT 13
  92. #define RTL8367_SWC0_MAX_LENGTH(_x) ((_x) << 13)
  93. #define RTL8367_SWC0_MAX_LENGTH_MASK RTL8367_SWC0_MAX_LENGTH(0x3)
  94. #define RTL8367_SWC0_MAX_LENGTH_1522 RTL8367_SWC0_MAX_LENGTH(0)
  95. #define RTL8367_SWC0_MAX_LENGTH_1536 RTL8367_SWC0_MAX_LENGTH(1)
  96. #define RTL8367_SWC0_MAX_LENGTH_1552 RTL8367_SWC0_MAX_LENGTH(2)
  97. #define RTL8367_SWC0_MAX_LENGTH_16000 RTL8367_SWC0_MAX_LENGTH(3)
  98. #define RTL8367_CHIP_NUMBER_REG 0x1300
  99. #define RTL8367_CHIP_VER_REG 0x1301
  100. #define RTL8367_CHIP_VER_RLVID_SHIFT 12
  101. #define RTL8367_CHIP_VER_RLVID_MASK 0xf
  102. #define RTL8367_CHIP_VER_MCID_SHIFT 8
  103. #define RTL8367_CHIP_VER_MCID_MASK 0xf
  104. #define RTL8367_CHIP_VER_BOID_SHIFT 4
  105. #define RTL8367_CHIP_VER_BOID_MASK 0xf
  106. #define RTL8367_CHIP_MODE_REG 0x1302
  107. #define RTL8367_CHIP_MODE_MASK 0x7
  108. #define RTL8367_CHIP_DEBUG0_REG 0x1303
  109. #define RTL8367_CHIP_DEBUG0_DUMMY0(_x) BIT(8 + (_x))
  110. #define RTL8367_CHIP_DEBUG1_REG 0x1304
  111. #define RTL8367_DIS_REG 0x1305
  112. #define RTL8367_DIS_SKIP_MII_RXER(_x) BIT(12 + (_x))
  113. #define RTL8367_DIS_RGMII_SHIFT(_x) (4 * (_x))
  114. #define RTL8367_DIS_RGMII_MASK 0x7
  115. #define RTL8367_EXT_RGMXF_REG(_x) (0x1306 + (_x))
  116. #define RTL8367_EXT_RGMXF_DUMMY0_SHIFT 5
  117. #define RTL8367_EXT_RGMXF_DUMMY0_MASK 0x7ff
  118. #define RTL8367_EXT_RGMXF_TXDELAY_SHIFT 3
  119. #define RTL8367_EXT_RGMXF_TXDELAY_MASK 1
  120. #define RTL8367_EXT_RGMXF_RXDELAY_MASK 0x7
  121. #define RTL8367_DI_FORCE_REG(_x) (0x1310 + (_x))
  122. #define RTL8367_DI_FORCE_MODE BIT(12)
  123. #define RTL8367_DI_FORCE_NWAY BIT(7)
  124. #define RTL8367_DI_FORCE_TXPAUSE BIT(6)
  125. #define RTL8367_DI_FORCE_RXPAUSE BIT(5)
  126. #define RTL8367_DI_FORCE_LINK BIT(4)
  127. #define RTL8367_DI_FORCE_DUPLEX BIT(2)
  128. #define RTL8367_DI_FORCE_SPEED_MASK 3
  129. #define RTL8367_DI_FORCE_SPEED_10 0
  130. #define RTL8367_DI_FORCE_SPEED_100 1
  131. #define RTL8367_DI_FORCE_SPEED_1000 2
  132. #define RTL8367_MAC_FORCE_REG(_x) (0x1312 + (_x))
  133. #define RTL8367_CHIP_RESET_REG 0x1322
  134. #define RTL8367_CHIP_RESET_SW BIT(1)
  135. #define RTL8367_CHIP_RESET_HW BIT(0)
  136. #define RTL8367_PORT_STATUS_REG(_p) (0x1352 + (_p))
  137. #define RTL8367_PORT_STATUS_NWAY BIT(7)
  138. #define RTL8367_PORT_STATUS_TXPAUSE BIT(6)
  139. #define RTL8367_PORT_STATUS_RXPAUSE BIT(5)
  140. #define RTL8367_PORT_STATUS_LINK BIT(4)
  141. #define RTL8367_PORT_STATUS_DUPLEX BIT(2)
  142. #define RTL8367_PORT_STATUS_SPEED_MASK 0x0003
  143. #define RTL8367_PORT_STATUS_SPEED_10 0
  144. #define RTL8367_PORT_STATUS_SPEED_100 1
  145. #define RTL8367_PORT_STATUS_SPEED_1000 2
  146. #define RTL8367_RTL_NO_REG 0x13c0
  147. #define RTL8367_RTL_NO_8367R 0x3670
  148. #define RTL8367_RTL_NO_8367M 0x3671
  149. #define RTL8367_RTL_VER_REG 0x13c1
  150. #define RTL8367_RTL_VER_MASK 0xf
  151. #define RTL8367_RTL_MAGIC_ID_REG 0x13c2
  152. #define RTL8367_RTL_MAGIC_ID_VAL 0x0249
  153. #define RTL8367_LED_SYS_CONFIG_REG 0x1b00
  154. #define RTL8367_LED_MODE_REG 0x1b02
  155. #define RTL8367_LED_MODE_RATE_M 0x7
  156. #define RTL8367_LED_MODE_RATE_S 1
  157. #define RTL8367_LED_CONFIG_REG 0x1b03
  158. #define RTL8367_LED_CONFIG_DATA_S 12
  159. #define RTL8367_LED_CONFIG_DATA_M 0x3
  160. #define RTL8367_LED_CONFIG_SEL BIT(14)
  161. #define RTL8367_LED_CONFIG_LED_CFG_M 0xf
  162. #define RTL8367_PARA_LED_IO_EN1_REG 0x1b24
  163. #define RTL8367_PARA_LED_IO_EN2_REG 0x1b25
  164. #define RTL8367_PARA_LED_IO_EN_PMASK 0xff
  165. #define RTL8367_IA_CTRL_REG 0x1f00
  166. #define RTL8367_IA_CTRL_RW(_x) ((_x) << 1)
  167. #define RTL8367_IA_CTRL_RW_READ RTL8367_IA_CTRL_RW(0)
  168. #define RTL8367_IA_CTRL_RW_WRITE RTL8367_IA_CTRL_RW(1)
  169. #define RTL8367_IA_CTRL_CMD_MASK BIT(0)
  170. #define RTL8367_IA_STATUS_REG 0x1f01
  171. #define RTL8367_IA_STATUS_PHY_BUSY BIT(2)
  172. #define RTL8367_IA_STATUS_SDS_BUSY BIT(1)
  173. #define RTL8367_IA_STATUS_MDX_BUSY BIT(0)
  174. #define RTL8367_IA_ADDRESS_REG 0x1f02
  175. #define RTL8367_IA_WRITE_DATA_REG 0x1f03
  176. #define RTL8367_IA_READ_DATA_REG 0x1f04
  177. #define RTL8367_INTERNAL_PHY_REG(_a, _r) (0x2000 + 32 * (_a) + (_r))
  178. #define RTL8367_CPU_PORT_NUM 9
  179. #define RTL8367_NUM_PORTS 10
  180. #define RTL8367_NUM_VLANS 32
  181. #define RTL8367_NUM_LEDGROUPS 4
  182. #define RTL8367_NUM_VIDS 4096
  183. #define RTL8367_PRIORITYMAX 7
  184. #define RTL8367_FIDMAX 7
  185. #define RTL8367_PORT_0 BIT(0)
  186. #define RTL8367_PORT_1 BIT(1)
  187. #define RTL8367_PORT_2 BIT(2)
  188. #define RTL8367_PORT_3 BIT(3)
  189. #define RTL8367_PORT_4 BIT(4)
  190. #define RTL8367_PORT_5 BIT(5)
  191. #define RTL8367_PORT_6 BIT(6)
  192. #define RTL8367_PORT_7 BIT(7)
  193. #define RTL8367_PORT_E1 BIT(8) /* external port 1 */
  194. #define RTL8367_PORT_E0 BIT(9) /* external port 0 */
  195. #define RTL8367_PORTS_ALL \
  196. (RTL8367_PORT_0 | RTL8367_PORT_1 | RTL8367_PORT_2 | \
  197. RTL8367_PORT_3 | RTL8367_PORT_4 | RTL8367_PORT_5 | \
  198. RTL8367_PORT_6 | RTL8367_PORT_7 | RTL8367_PORT_E1 | \
  199. RTL8367_PORT_E0)
  200. #define RTL8367_PORTS_ALL_BUT_CPU \
  201. (RTL8367_PORT_0 | RTL8367_PORT_1 | RTL8367_PORT_2 | \
  202. RTL8367_PORT_3 | RTL8367_PORT_4 | RTL8367_PORT_5 | \
  203. RTL8367_PORT_6 | RTL8367_PORT_7 | RTL8367_PORT_E1)
  204. struct rtl8367_initval {
  205. u16 reg;
  206. u16 val;
  207. };
  208. static struct rtl8366_mib_counter rtl8367_mib_counters[] = {
  209. { 0, 0, 4, "IfInOctets" },
  210. { 0, 4, 2, "Dot3StatsFCSErrors" },
  211. { 0, 6, 2, "Dot3StatsSymbolErrors" },
  212. { 0, 8, 2, "Dot3InPauseFrames" },
  213. { 0, 10, 2, "Dot3ControlInUnknownOpcodes" },
  214. { 0, 12, 2, "EtherStatsFragments" },
  215. { 0, 14, 2, "EtherStatsJabbers" },
  216. { 0, 16, 2, "IfInUcastPkts" },
  217. { 0, 18, 2, "EtherStatsDropEvents" },
  218. { 0, 20, 4, "EtherStatsOctets" },
  219. { 0, 24, 2, "EtherStatsUnderSizePkts" },
  220. { 0, 26, 2, "EtherOversizeStats" },
  221. { 0, 28, 2, "EtherStatsPkts64Octets" },
  222. { 0, 30, 2, "EtherStatsPkts65to127Octets" },
  223. { 0, 32, 2, "EtherStatsPkts128to255Octets" },
  224. { 0, 34, 2, "EtherStatsPkts256to511Octets" },
  225. { 0, 36, 2, "EtherStatsPkts512to1023Octets" },
  226. { 0, 38, 2, "EtherStatsPkts1024to1518Octets" },
  227. { 0, 40, 2, "EtherStatsMulticastPkts" },
  228. { 0, 42, 2, "EtherStatsBroadcastPkts" },
  229. { 0, 44, 4, "IfOutOctets" },
  230. { 0, 48, 2, "Dot3StatsSingleCollisionFrames" },
  231. { 0, 50, 2, "Dot3StatMultipleCollisionFrames" },
  232. { 0, 52, 2, "Dot3sDeferredTransmissions" },
  233. { 0, 54, 2, "Dot3StatsLateCollisions" },
  234. { 0, 56, 2, "EtherStatsCollisions" },
  235. { 0, 58, 2, "Dot3StatsExcessiveCollisions" },
  236. { 0, 60, 2, "Dot3OutPauseFrames" },
  237. { 0, 62, 2, "Dot1dBasePortDelayExceededDiscards" },
  238. { 0, 64, 2, "Dot1dTpPortInDiscards" },
  239. { 0, 66, 2, "IfOutUcastPkts" },
  240. { 0, 68, 2, "IfOutMulticastPkts" },
  241. { 0, 70, 2, "IfOutBroadcastPkts" },
  242. { 0, 72, 2, "OutOampduPkts" },
  243. { 0, 74, 2, "InOampduPkts" },
  244. { 0, 76, 2, "PktgenPkts" },
  245. };
  246. #define REG_RD(_smi, _reg, _val) \
  247. do { \
  248. err = rtl8366_smi_read_reg(_smi, _reg, _val); \
  249. if (err) \
  250. return err; \
  251. } while (0)
  252. #define REG_WR(_smi, _reg, _val) \
  253. do { \
  254. err = rtl8366_smi_write_reg(_smi, _reg, _val); \
  255. if (err) \
  256. return err; \
  257. } while (0)
  258. #define REG_RMW(_smi, _reg, _mask, _val) \
  259. do { \
  260. err = rtl8366_smi_rmwr(_smi, _reg, _mask, _val); \
  261. if (err) \
  262. return err; \
  263. } while (0)
  264. static const struct rtl8367_initval rtl8367_initvals_0_0[] = {
  265. {0x133f, 0x0030}, {0x133e, 0x000e}, {0x221f, 0x0000}, {0x2215, 0x1006},
  266. {0x221f, 0x0005}, {0x2200, 0x00c6}, {0x221f, 0x0007}, {0x221e, 0x0048},
  267. {0x2215, 0x6412}, {0x2216, 0x6412}, {0x2217, 0x6412}, {0x2218, 0x6412},
  268. {0x2219, 0x6412}, {0x221A, 0x6412}, {0x221f, 0x0001}, {0x220c, 0xdbf0},
  269. {0x2209, 0x2576}, {0x2207, 0x287E}, {0x220A, 0x68E5}, {0x221D, 0x3DA4},
  270. {0x221C, 0xE7F7}, {0x2214, 0x7F52}, {0x2218, 0x7FCE}, {0x2208, 0x04B7},
  271. {0x2206, 0x4072}, {0x2210, 0xF05E}, {0x221B, 0xB414}, {0x221F, 0x0003},
  272. {0x221A, 0x06A6}, {0x2210, 0xF05E}, {0x2213, 0x06EB}, {0x2212, 0xF4D2},
  273. {0x220E, 0xE120}, {0x2200, 0x7C00}, {0x2202, 0x5FD0}, {0x220D, 0x0207},
  274. {0x221f, 0x0002}, {0x2205, 0x0978}, {0x2202, 0x8C01}, {0x2207, 0x3620},
  275. {0x221C, 0x0001}, {0x2203, 0x0420}, {0x2204, 0x80C8}, {0x133e, 0x0ede},
  276. {0x221f, 0x0002}, {0x220c, 0x0073}, {0x220d, 0xEB65}, {0x220e, 0x51d1},
  277. {0x220f, 0x5dcb}, {0x2210, 0x3044}, {0x2211, 0x1800}, {0x2212, 0x7E00},
  278. {0x2213, 0x0000}, {0x133f, 0x0010}, {0x133e, 0x0ffe}, {0x207f, 0x0002},
  279. {0x2074, 0x3D22}, {0x2075, 0x2000}, {0x2076, 0x6040}, {0x2077, 0x0000},
  280. {0x2078, 0x0f0a}, {0x2079, 0x50AB}, {0x207a, 0x0000}, {0x207b, 0x0f0f},
  281. {0x205f, 0x0002}, {0x2054, 0xFF00}, {0x2055, 0x000A}, {0x2056, 0x000A},
  282. {0x2057, 0x0005}, {0x2058, 0x0005}, {0x2059, 0x0000}, {0x205A, 0x0005},
  283. {0x205B, 0x0005}, {0x205C, 0x0005}, {0x209f, 0x0002}, {0x2094, 0x00AA},
  284. {0x2095, 0x00AA}, {0x2096, 0x00AA}, {0x2097, 0x00AA}, {0x2098, 0x0055},
  285. {0x2099, 0x00AA}, {0x209A, 0x00AA}, {0x209B, 0x00AA}, {0x1363, 0x8354},
  286. {0x1270, 0x3333}, {0x1271, 0x3333}, {0x1272, 0x3333}, {0x1330, 0x00DB},
  287. {0x1203, 0xff00}, {0x1200, 0x7fc4}, {0x121d, 0x1006}, {0x121e, 0x03e8},
  288. {0x121f, 0x02b3}, {0x1220, 0x028f}, {0x1221, 0x029b}, {0x1222, 0x0277},
  289. {0x1223, 0x02b3}, {0x1224, 0x028f}, {0x1225, 0x029b}, {0x1226, 0x0277},
  290. {0x1227, 0x00c0}, {0x1228, 0x00b4}, {0x122f, 0x00c0}, {0x1230, 0x00b4},
  291. {0x1229, 0x0020}, {0x122a, 0x000c}, {0x1231, 0x0030}, {0x1232, 0x0024},
  292. {0x0219, 0x0032}, {0x0200, 0x03e8}, {0x0201, 0x03e8}, {0x0202, 0x03e8},
  293. {0x0203, 0x03e8}, {0x0204, 0x03e8}, {0x0205, 0x03e8}, {0x0206, 0x03e8},
  294. {0x0207, 0x03e8}, {0x0218, 0x0032}, {0x0208, 0x029b}, {0x0209, 0x029b},
  295. {0x020a, 0x029b}, {0x020b, 0x029b}, {0x020c, 0x029b}, {0x020d, 0x029b},
  296. {0x020e, 0x029b}, {0x020f, 0x029b}, {0x0210, 0x029b}, {0x0211, 0x029b},
  297. {0x0212, 0x029b}, {0x0213, 0x029b}, {0x0214, 0x029b}, {0x0215, 0x029b},
  298. {0x0216, 0x029b}, {0x0217, 0x029b}, {0x0900, 0x0000}, {0x0901, 0x0000},
  299. {0x0902, 0x0000}, {0x0903, 0x0000}, {0x0865, 0x3210}, {0x087b, 0x0000},
  300. {0x087c, 0xff00}, {0x087d, 0x0000}, {0x087e, 0x0000}, {0x0801, 0x0100},
  301. {0x0802, 0x0100}, {0x1700, 0x014C}, {0x0301, 0x00FF}, {0x12AA, 0x0096},
  302. {0x133f, 0x0030}, {0x133e, 0x000e}, {0x221f, 0x0005}, {0x2200, 0x00C4},
  303. {0x221f, 0x0000}, {0x2210, 0x05EF}, {0x2204, 0x05E1}, {0x2200, 0x1340},
  304. {0x133f, 0x0010}, {0x20A0, 0x1940}, {0x20C0, 0x1940}, {0x20E0, 0x1940},
  305. };
  306. static const struct rtl8367_initval rtl8367_initvals_0_1[] = {
  307. {0x133f, 0x0030}, {0x133e, 0x000e}, {0x221f, 0x0000}, {0x2215, 0x1006},
  308. {0x221f, 0x0005}, {0x2200, 0x00c6}, {0x221f, 0x0007}, {0x221e, 0x0048},
  309. {0x2215, 0x6412}, {0x2216, 0x6412}, {0x2217, 0x6412}, {0x2218, 0x6412},
  310. {0x2219, 0x6412}, {0x221A, 0x6412}, {0x221f, 0x0001}, {0x220c, 0xdbf0},
  311. {0x2209, 0x2576}, {0x2207, 0x287E}, {0x220A, 0x68E5}, {0x221D, 0x3DA4},
  312. {0x221C, 0xE7F7}, {0x2214, 0x7F52}, {0x2218, 0x7FCE}, {0x2208, 0x04B7},
  313. {0x2206, 0x4072}, {0x2210, 0xF05E}, {0x221B, 0xB414}, {0x221F, 0x0003},
  314. {0x221A, 0x06A6}, {0x2210, 0xF05E}, {0x2213, 0x06EB}, {0x2212, 0xF4D2},
  315. {0x220E, 0xE120}, {0x2200, 0x7C00}, {0x2202, 0x5FD0}, {0x220D, 0x0207},
  316. {0x221f, 0x0002}, {0x2205, 0x0978}, {0x2202, 0x8C01}, {0x2207, 0x3620},
  317. {0x221C, 0x0001}, {0x2203, 0x0420}, {0x2204, 0x80C8}, {0x133e, 0x0ede},
  318. {0x221f, 0x0002}, {0x220c, 0x0073}, {0x220d, 0xEB65}, {0x220e, 0x51d1},
  319. {0x220f, 0x5dcb}, {0x2210, 0x3044}, {0x2211, 0x1800}, {0x2212, 0x7E00},
  320. {0x2213, 0x0000}, {0x133f, 0x0010}, {0x133e, 0x0ffe}, {0x207f, 0x0002},
  321. {0x2074, 0x3D22}, {0x2075, 0x2000}, {0x2076, 0x6040}, {0x2077, 0x0000},
  322. {0x2078, 0x0f0a}, {0x2079, 0x50AB}, {0x207a, 0x0000}, {0x207b, 0x0f0f},
  323. {0x205f, 0x0002}, {0x2054, 0xFF00}, {0x2055, 0x000A}, {0x2056, 0x000A},
  324. {0x2057, 0x0005}, {0x2058, 0x0005}, {0x2059, 0x0000}, {0x205A, 0x0005},
  325. {0x205B, 0x0005}, {0x205C, 0x0005}, {0x209f, 0x0002}, {0x2094, 0x00AA},
  326. {0x2095, 0x00AA}, {0x2096, 0x00AA}, {0x2097, 0x00AA}, {0x2098, 0x0055},
  327. {0x2099, 0x00AA}, {0x209A, 0x00AA}, {0x209B, 0x00AA}, {0x1363, 0x8354},
  328. {0x1270, 0x3333}, {0x1271, 0x3333}, {0x1272, 0x3333}, {0x1330, 0x00DB},
  329. {0x1203, 0xff00}, {0x1200, 0x7fc4}, {0x121d, 0x1b06}, {0x121e, 0x07f0},
  330. {0x121f, 0x0438}, {0x1220, 0x040f}, {0x1221, 0x040f}, {0x1222, 0x03eb},
  331. {0x1223, 0x0438}, {0x1224, 0x040f}, {0x1225, 0x040f}, {0x1226, 0x03eb},
  332. {0x1227, 0x0144}, {0x1228, 0x0138}, {0x122f, 0x0144}, {0x1230, 0x0138},
  333. {0x1229, 0x0020}, {0x122a, 0x000c}, {0x1231, 0x0030}, {0x1232, 0x0024},
  334. {0x0219, 0x0032}, {0x0200, 0x07d0}, {0x0201, 0x07d0}, {0x0202, 0x07d0},
  335. {0x0203, 0x07d0}, {0x0204, 0x07d0}, {0x0205, 0x07d0}, {0x0206, 0x07d0},
  336. {0x0207, 0x07d0}, {0x0218, 0x0032}, {0x0208, 0x0190}, {0x0209, 0x0190},
  337. {0x020a, 0x0190}, {0x020b, 0x0190}, {0x020c, 0x0190}, {0x020d, 0x0190},
  338. {0x020e, 0x0190}, {0x020f, 0x0190}, {0x0210, 0x0190}, {0x0211, 0x0190},
  339. {0x0212, 0x0190}, {0x0213, 0x0190}, {0x0214, 0x0190}, {0x0215, 0x0190},
  340. {0x0216, 0x0190}, {0x0217, 0x0190}, {0x0900, 0x0000}, {0x0901, 0x0000},
  341. {0x0902, 0x0000}, {0x0903, 0x0000}, {0x0865, 0x3210}, {0x087b, 0x0000},
  342. {0x087c, 0xff00}, {0x087d, 0x0000}, {0x087e, 0x0000}, {0x0801, 0x0100},
  343. {0x0802, 0x0100}, {0x1700, 0x0125}, {0x0301, 0x00FF}, {0x12AA, 0x0096},
  344. {0x133f, 0x0030}, {0x133e, 0x000e}, {0x221f, 0x0005}, {0x2200, 0x00C4},
  345. {0x221f, 0x0000}, {0x2210, 0x05EF}, {0x2204, 0x05E1}, {0x2200, 0x1340},
  346. {0x133f, 0x0010},
  347. };
  348. static const struct rtl8367_initval rtl8367_initvals_1_0[] = {
  349. {0x1B24, 0x0000}, {0x1B25, 0x0000}, {0x1B26, 0x0000}, {0x1B27, 0x0000},
  350. {0x207F, 0x0002}, {0x2079, 0x0200}, {0x207F, 0x0000}, {0x133F, 0x0030},
  351. {0x133E, 0x000E}, {0x221F, 0x0005}, {0x2201, 0x0700}, {0x2205, 0x8B82},
  352. {0x2206, 0x05CB}, {0x221F, 0x0002}, {0x2204, 0x80C2}, {0x2205, 0x0938},
  353. {0x221F, 0x0003}, {0x2212, 0xC4D2}, {0x220D, 0x0207}, {0x221F, 0x0001},
  354. {0x2207, 0x267E}, {0x221C, 0xE5F7}, {0x221B, 0x0424}, {0x221F, 0x0007},
  355. {0x221E, 0x0040}, {0x2218, 0x0000}, {0x221F, 0x0007}, {0x221E, 0x002C},
  356. {0x2218, 0x008B}, {0x221F, 0x0005}, {0x2205, 0xFFF6}, {0x2206, 0x0080},
  357. {0x2205, 0x8000}, {0x2206, 0xF8E0}, {0x2206, 0xE000}, {0x2206, 0xE1E0},
  358. {0x2206, 0x01AC}, {0x2206, 0x2408}, {0x2206, 0xE08B}, {0x2206, 0x84F7},
  359. {0x2206, 0x20E4}, {0x2206, 0x8B84}, {0x2206, 0xFC05}, {0x2206, 0xF8FA},
  360. {0x2206, 0xEF69}, {0x2206, 0xE08B}, {0x2206, 0x86AC}, {0x2206, 0x201A},
  361. {0x2206, 0xBF80}, {0x2206, 0x59D0}, {0x2206, 0x2402}, {0x2206, 0x803D},
  362. {0x2206, 0xE0E0}, {0x2206, 0xE4E1}, {0x2206, 0xE0E5}, {0x2206, 0x5806},
  363. {0x2206, 0x68C0}, {0x2206, 0xD1D2}, {0x2206, 0xE4E0}, {0x2206, 0xE4E5},
  364. {0x2206, 0xE0E5}, {0x2206, 0xEF96}, {0x2206, 0xFEFC}, {0x2206, 0x05FB},
  365. {0x2206, 0x0BFB}, {0x2206, 0x58FF}, {0x2206, 0x9E11}, {0x2206, 0x06F0},
  366. {0x2206, 0x0C81}, {0x2206, 0x8AE0}, {0x2206, 0x0019}, {0x2206, 0x1B89},
  367. {0x2206, 0xCFEB}, {0x2206, 0x19EB}, {0x2206, 0x19B0}, {0x2206, 0xEFFF},
  368. {0x2206, 0x0BFF}, {0x2206, 0x0425}, {0x2206, 0x0807}, {0x2206, 0x2640},
  369. {0x2206, 0x7227}, {0x2206, 0x267E}, {0x2206, 0x2804}, {0x2206, 0xB729},
  370. {0x2206, 0x2576}, {0x2206, 0x2A68}, {0x2206, 0xE52B}, {0x2206, 0xAD00},
  371. {0x2206, 0x2CDB}, {0x2206, 0xF02D}, {0x2206, 0x67BB}, {0x2206, 0x2E7B},
  372. {0x2206, 0x0F2F}, {0x2206, 0x7365}, {0x2206, 0x31AC}, {0x2206, 0xCC32},
  373. {0x2206, 0x2300}, {0x2206, 0x332D}, {0x2206, 0x1734}, {0x2206, 0x7F52},
  374. {0x2206, 0x3510}, {0x2206, 0x0036}, {0x2206, 0x0600}, {0x2206, 0x370C},
  375. {0x2206, 0xC038}, {0x2206, 0x7FCE}, {0x2206, 0x3CE5}, {0x2206, 0xF73D},
  376. {0x2206, 0x3DA4}, {0x2206, 0x6530}, {0x2206, 0x3E67}, {0x2206, 0x0053},
  377. {0x2206, 0x69D2}, {0x2206, 0x0F6A}, {0x2206, 0x012C}, {0x2206, 0x6C2B},
  378. {0x2206, 0x136E}, {0x2206, 0xE100}, {0x2206, 0x6F12}, {0x2206, 0xF771},
  379. {0x2206, 0x006B}, {0x2206, 0x7306}, {0x2206, 0xEB74}, {0x2206, 0x94C7},
  380. {0x2206, 0x7698}, {0x2206, 0x0A77}, {0x2206, 0x5000}, {0x2206, 0x788A},
  381. {0x2206, 0x1579}, {0x2206, 0x7F6F}, {0x2206, 0x7A06}, {0x2206, 0xA600},
  382. {0x2205, 0x8B90}, {0x2206, 0x8000}, {0x2205, 0x8B92}, {0x2206, 0x8000},
  383. {0x2205, 0x8B94}, {0x2206, 0x8014}, {0x2208, 0xFFFA}, {0x2202, 0x3C65},
  384. {0x2205, 0xFFF6}, {0x2206, 0x00F7}, {0x221F, 0x0000}, {0x221F, 0x0007},
  385. {0x221E, 0x0042}, {0x2218, 0x0000}, {0x221E, 0x002D}, {0x2218, 0xF010},
  386. {0x221E, 0x0020}, {0x2215, 0x0000}, {0x221E, 0x0023}, {0x2216, 0x8000},
  387. {0x221F, 0x0000}, {0x133F, 0x0010}, {0x133E, 0x0FFE}, {0x1362, 0x0115},
  388. {0x1363, 0x0002}, {0x1363, 0x0000}, {0x1306, 0x000C}, {0x1307, 0x000C},
  389. {0x1303, 0x0067}, {0x1304, 0x4444}, {0x1203, 0xFF00}, {0x1200, 0x7FC4},
  390. {0x121D, 0x7D16}, {0x121E, 0x03E8}, {0x121F, 0x024E}, {0x1220, 0x0230},
  391. {0x1221, 0x0244}, {0x1222, 0x0226}, {0x1223, 0x024E}, {0x1224, 0x0230},
  392. {0x1225, 0x0244}, {0x1226, 0x0226}, {0x1227, 0x00C0}, {0x1228, 0x00B4},
  393. {0x122F, 0x00C0}, {0x1230, 0x00B4}, {0x0208, 0x03E8}, {0x0209, 0x03E8},
  394. {0x020A, 0x03E8}, {0x020B, 0x03E8}, {0x020C, 0x03E8}, {0x020D, 0x03E8},
  395. {0x020E, 0x03E8}, {0x020F, 0x03E8}, {0x0210, 0x03E8}, {0x0211, 0x03E8},
  396. {0x0212, 0x03E8}, {0x0213, 0x03E8}, {0x0214, 0x03E8}, {0x0215, 0x03E8},
  397. {0x0216, 0x03E8}, {0x0217, 0x03E8}, {0x0900, 0x0000}, {0x0901, 0x0000},
  398. {0x0902, 0x0000}, {0x0903, 0x0000}, {0x0865, 0x3210}, {0x087B, 0x0000},
  399. {0x087C, 0xFF00}, {0x087D, 0x0000}, {0x087E, 0x0000}, {0x0801, 0x0100},
  400. {0x0802, 0x0100}, {0x0A20, 0x2040}, {0x0A21, 0x2040}, {0x0A22, 0x2040},
  401. {0x0A23, 0x2040}, {0x0A24, 0x2040}, {0x0A28, 0x2040}, {0x0A29, 0x2040},
  402. {0x133F, 0x0030}, {0x133E, 0x000E}, {0x221F, 0x0000}, {0x2200, 0x1340},
  403. {0x221F, 0x0000}, {0x133F, 0x0010}, {0x133E, 0x0FFE}, {0x20A0, 0x1940},
  404. {0x20C0, 0x1940}, {0x20E0, 0x1940}, {0x130c, 0x0050},
  405. };
  406. static const struct rtl8367_initval rtl8367_initvals_1_1[] = {
  407. {0x1B24, 0x0000}, {0x1B25, 0x0000}, {0x1B26, 0x0000}, {0x1B27, 0x0000},
  408. {0x207F, 0x0002}, {0x2079, 0x0200}, {0x207F, 0x0000}, {0x133F, 0x0030},
  409. {0x133E, 0x000E}, {0x221F, 0x0005}, {0x2201, 0x0700}, {0x2205, 0x8B82},
  410. {0x2206, 0x05CB}, {0x221F, 0x0002}, {0x2204, 0x80C2}, {0x2205, 0x0938},
  411. {0x221F, 0x0003}, {0x2212, 0xC4D2}, {0x220D, 0x0207}, {0x221F, 0x0001},
  412. {0x2207, 0x267E}, {0x221C, 0xE5F7}, {0x221B, 0x0424}, {0x221F, 0x0007},
  413. {0x221E, 0x0040}, {0x2218, 0x0000}, {0x221F, 0x0007}, {0x221E, 0x002C},
  414. {0x2218, 0x008B}, {0x221F, 0x0005}, {0x2205, 0xFFF6}, {0x2206, 0x0080},
  415. {0x2205, 0x8000}, {0x2206, 0xF8E0}, {0x2206, 0xE000}, {0x2206, 0xE1E0},
  416. {0x2206, 0x01AC}, {0x2206, 0x2408}, {0x2206, 0xE08B}, {0x2206, 0x84F7},
  417. {0x2206, 0x20E4}, {0x2206, 0x8B84}, {0x2206, 0xFC05}, {0x2206, 0xF8FA},
  418. {0x2206, 0xEF69}, {0x2206, 0xE08B}, {0x2206, 0x86AC}, {0x2206, 0x201A},
  419. {0x2206, 0xBF80}, {0x2206, 0x59D0}, {0x2206, 0x2402}, {0x2206, 0x803D},
  420. {0x2206, 0xE0E0}, {0x2206, 0xE4E1}, {0x2206, 0xE0E5}, {0x2206, 0x5806},
  421. {0x2206, 0x68C0}, {0x2206, 0xD1D2}, {0x2206, 0xE4E0}, {0x2206, 0xE4E5},
  422. {0x2206, 0xE0E5}, {0x2206, 0xEF96}, {0x2206, 0xFEFC}, {0x2206, 0x05FB},
  423. {0x2206, 0x0BFB}, {0x2206, 0x58FF}, {0x2206, 0x9E11}, {0x2206, 0x06F0},
  424. {0x2206, 0x0C81}, {0x2206, 0x8AE0}, {0x2206, 0x0019}, {0x2206, 0x1B89},
  425. {0x2206, 0xCFEB}, {0x2206, 0x19EB}, {0x2206, 0x19B0}, {0x2206, 0xEFFF},
  426. {0x2206, 0x0BFF}, {0x2206, 0x0425}, {0x2206, 0x0807}, {0x2206, 0x2640},
  427. {0x2206, 0x7227}, {0x2206, 0x267E}, {0x2206, 0x2804}, {0x2206, 0xB729},
  428. {0x2206, 0x2576}, {0x2206, 0x2A68}, {0x2206, 0xE52B}, {0x2206, 0xAD00},
  429. {0x2206, 0x2CDB}, {0x2206, 0xF02D}, {0x2206, 0x67BB}, {0x2206, 0x2E7B},
  430. {0x2206, 0x0F2F}, {0x2206, 0x7365}, {0x2206, 0x31AC}, {0x2206, 0xCC32},
  431. {0x2206, 0x2300}, {0x2206, 0x332D}, {0x2206, 0x1734}, {0x2206, 0x7F52},
  432. {0x2206, 0x3510}, {0x2206, 0x0036}, {0x2206, 0x0600}, {0x2206, 0x370C},
  433. {0x2206, 0xC038}, {0x2206, 0x7FCE}, {0x2206, 0x3CE5}, {0x2206, 0xF73D},
  434. {0x2206, 0x3DA4}, {0x2206, 0x6530}, {0x2206, 0x3E67}, {0x2206, 0x0053},
  435. {0x2206, 0x69D2}, {0x2206, 0x0F6A}, {0x2206, 0x012C}, {0x2206, 0x6C2B},
  436. {0x2206, 0x136E}, {0x2206, 0xE100}, {0x2206, 0x6F12}, {0x2206, 0xF771},
  437. {0x2206, 0x006B}, {0x2206, 0x7306}, {0x2206, 0xEB74}, {0x2206, 0x94C7},
  438. {0x2206, 0x7698}, {0x2206, 0x0A77}, {0x2206, 0x5000}, {0x2206, 0x788A},
  439. {0x2206, 0x1579}, {0x2206, 0x7F6F}, {0x2206, 0x7A06}, {0x2206, 0xA600},
  440. {0x2205, 0x8B90}, {0x2206, 0x8000}, {0x2205, 0x8B92}, {0x2206, 0x8000},
  441. {0x2205, 0x8B94}, {0x2206, 0x8014}, {0x2208, 0xFFFA}, {0x2202, 0x3C65},
  442. {0x2205, 0xFFF6}, {0x2206, 0x00F7}, {0x221F, 0x0000}, {0x221F, 0x0007},
  443. {0x221E, 0x0042}, {0x2218, 0x0000}, {0x221E, 0x002D}, {0x2218, 0xF010},
  444. {0x221E, 0x0020}, {0x2215, 0x0000}, {0x221E, 0x0023}, {0x2216, 0x8000},
  445. {0x221F, 0x0000}, {0x133F, 0x0010}, {0x133E, 0x0FFE}, {0x1362, 0x0115},
  446. {0x1363, 0x0002}, {0x1363, 0x0000}, {0x1306, 0x000C}, {0x1307, 0x000C},
  447. {0x1303, 0x0067}, {0x1304, 0x4444}, {0x1203, 0xFF00}, {0x1200, 0x7FC4},
  448. {0x0900, 0x0000}, {0x0901, 0x0000}, {0x0902, 0x0000}, {0x0903, 0x0000},
  449. {0x0865, 0x3210}, {0x087B, 0x0000}, {0x087C, 0xFF00}, {0x087D, 0x0000},
  450. {0x087E, 0x0000}, {0x0801, 0x0100}, {0x0802, 0x0100}, {0x0A20, 0x2040},
  451. {0x0A21, 0x2040}, {0x0A22, 0x2040}, {0x0A23, 0x2040}, {0x0A24, 0x2040},
  452. {0x0A25, 0x2040}, {0x0A26, 0x2040}, {0x0A27, 0x2040}, {0x0A28, 0x2040},
  453. {0x0A29, 0x2040}, {0x133F, 0x0030}, {0x133E, 0x000E}, {0x221F, 0x0000},
  454. {0x2200, 0x1340}, {0x221F, 0x0000}, {0x133F, 0x0010}, {0x133E, 0x0FFE},
  455. {0x1B03, 0x0876},
  456. };
  457. static const struct rtl8367_initval rtl8367_initvals_2_0[] = {
  458. {0x1b24, 0x0000}, {0x1b25, 0x0000}, {0x1b26, 0x0000}, {0x1b27, 0x0000},
  459. {0x133f, 0x0030}, {0x133e, 0x000e}, {0x221f, 0x0007}, {0x221e, 0x0048},
  460. {0x2219, 0x4012}, {0x221f, 0x0003}, {0x2201, 0x3554}, {0x2202, 0x63e8},
  461. {0x2203, 0x99c2}, {0x2204, 0x0113}, {0x2205, 0x303e}, {0x220d, 0x0207},
  462. {0x220e, 0xe100}, {0x221f, 0x0007}, {0x221e, 0x0040}, {0x2218, 0x0000},
  463. {0x221f, 0x0007}, {0x221e, 0x002c}, {0x2218, 0x008b}, {0x221f, 0x0005},
  464. {0x2205, 0xfff6}, {0x2206, 0x0080}, {0x221f, 0x0005}, {0x2205, 0x8000},
  465. {0x2206, 0x0280}, {0x2206, 0x2bf7}, {0x2206, 0x00e0}, {0x2206, 0xfff7},
  466. {0x2206, 0xa080}, {0x2206, 0x02ae}, {0x2206, 0xf602}, {0x2206, 0x804e},
  467. {0x2206, 0x0201}, {0x2206, 0x5002}, {0x2206, 0x0163}, {0x2206, 0x0201},
  468. {0x2206, 0x79e0}, {0x2206, 0x8b8c}, {0x2206, 0xe18b}, {0x2206, 0x8d1e},
  469. {0x2206, 0x01e1}, {0x2206, 0x8b8e}, {0x2206, 0x1e01}, {0x2206, 0xa000},
  470. {0x2206, 0xe4ae}, {0x2206, 0xd8bf}, {0x2206, 0x8b88}, {0x2206, 0xec00},
  471. {0x2206, 0x19a9}, {0x2206, 0x8b90}, {0x2206, 0xf9ee}, {0x2206, 0xfff6},
  472. {0x2206, 0x00ee}, {0x2206, 0xfff7}, {0x2206, 0xfce0}, {0x2206, 0xe140},
  473. {0x2206, 0xe1e1}, {0x2206, 0x41f7}, {0x2206, 0x2ff6}, {0x2206, 0x28e4},
  474. {0x2206, 0xe140}, {0x2206, 0xe5e1}, {0x2206, 0x4104}, {0x2206, 0xf8fa},
  475. {0x2206, 0xef69}, {0x2206, 0xe08b}, {0x2206, 0x86ac}, {0x2206, 0x201a},
  476. {0x2206, 0xbf80}, {0x2206, 0x77d0}, {0x2206, 0x6c02}, {0x2206, 0x2978},
  477. {0x2206, 0xe0e0}, {0x2206, 0xe4e1}, {0x2206, 0xe0e5}, {0x2206, 0x5806},
  478. {0x2206, 0x68c0}, {0x2206, 0xd1d2}, {0x2206, 0xe4e0}, {0x2206, 0xe4e5},
  479. {0x2206, 0xe0e5}, {0x2206, 0xef96}, {0x2206, 0xfefc}, {0x2206, 0x0425},
  480. {0x2206, 0x0807}, {0x2206, 0x2640}, {0x2206, 0x7227}, {0x2206, 0x267e},
  481. {0x2206, 0x2804}, {0x2206, 0xb729}, {0x2206, 0x2576}, {0x2206, 0x2a68},
  482. {0x2206, 0xe52b}, {0x2206, 0xad00}, {0x2206, 0x2cdb}, {0x2206, 0xf02d},
  483. {0x2206, 0x67bb}, {0x2206, 0x2e7b}, {0x2206, 0x0f2f}, {0x2206, 0x7365},
  484. {0x2206, 0x31ac}, {0x2206, 0xcc32}, {0x2206, 0x2300}, {0x2206, 0x332d},
  485. {0x2206, 0x1734}, {0x2206, 0x7f52}, {0x2206, 0x3510}, {0x2206, 0x0036},
  486. {0x2206, 0x0600}, {0x2206, 0x370c}, {0x2206, 0xc038}, {0x2206, 0x7fce},
  487. {0x2206, 0x3ce5}, {0x2206, 0xf73d}, {0x2206, 0x3da4}, {0x2206, 0x6530},
  488. {0x2206, 0x3e67}, {0x2206, 0x0053}, {0x2206, 0x69d2}, {0x2206, 0x0f6a},
  489. {0x2206, 0x012c}, {0x2206, 0x6c2b}, {0x2206, 0x136e}, {0x2206, 0xe100},
  490. {0x2206, 0x6f12}, {0x2206, 0xf771}, {0x2206, 0x006b}, {0x2206, 0x7306},
  491. {0x2206, 0xeb74}, {0x2206, 0x94c7}, {0x2206, 0x7698}, {0x2206, 0x0a77},
  492. {0x2206, 0x5000}, {0x2206, 0x788a}, {0x2206, 0x1579}, {0x2206, 0x7f6f},
  493. {0x2206, 0x7a06}, {0x2206, 0xa600}, {0x2201, 0x0701}, {0x2200, 0x0405},
  494. {0x221f, 0x0000}, {0x2200, 0x1340}, {0x221f, 0x0000}, {0x133f, 0x0010},
  495. {0x133e, 0x0ffe}, {0x1203, 0xff00}, {0x1200, 0x7fc4}, {0x121d, 0x7D16},
  496. {0x121e, 0x03e8}, {0x121f, 0x024e}, {0x1220, 0x0230}, {0x1221, 0x0244},
  497. {0x1222, 0x0226}, {0x1223, 0x024e}, {0x1224, 0x0230}, {0x1225, 0x0244},
  498. {0x1226, 0x0226}, {0x1227, 0x00c0}, {0x1228, 0x00b4}, {0x122f, 0x00c0},
  499. {0x1230, 0x00b4}, {0x0208, 0x03e8}, {0x0209, 0x03e8}, {0x020a, 0x03e8},
  500. {0x020b, 0x03e8}, {0x020c, 0x03e8}, {0x020d, 0x03e8}, {0x020e, 0x03e8},
  501. {0x020f, 0x03e8}, {0x0210, 0x03e8}, {0x0211, 0x03e8}, {0x0212, 0x03e8},
  502. {0x0213, 0x03e8}, {0x0214, 0x03e8}, {0x0215, 0x03e8}, {0x0216, 0x03e8},
  503. {0x0217, 0x03e8}, {0x0900, 0x0000}, {0x0901, 0x0000}, {0x0902, 0x0000},
  504. {0x0903, 0x0000}, {0x0865, 0x3210}, {0x087b, 0x0000}, {0x087c, 0xff00},
  505. {0x087d, 0x0000}, {0x087e, 0x0000}, {0x0801, 0x0100}, {0x0802, 0x0100},
  506. {0x0A20, 0x2040}, {0x0A21, 0x2040}, {0x0A22, 0x2040}, {0x0A23, 0x2040},
  507. {0x0A24, 0x2040}, {0x0A28, 0x2040}, {0x0A29, 0x2040}, {0x20A0, 0x1940},
  508. {0x20C0, 0x1940}, {0x20E0, 0x1940}, {0x130c, 0x0050},
  509. };
  510. static const struct rtl8367_initval rtl8367_initvals_2_1[] = {
  511. {0x1b24, 0x0000}, {0x1b25, 0x0000}, {0x1b26, 0x0000}, {0x1b27, 0x0000},
  512. {0x133f, 0x0030}, {0x133e, 0x000e}, {0x221f, 0x0007}, {0x221e, 0x0048},
  513. {0x2219, 0x4012}, {0x221f, 0x0003}, {0x2201, 0x3554}, {0x2202, 0x63e8},
  514. {0x2203, 0x99c2}, {0x2204, 0x0113}, {0x2205, 0x303e}, {0x220d, 0x0207},
  515. {0x220e, 0xe100}, {0x221f, 0x0007}, {0x221e, 0x0040}, {0x2218, 0x0000},
  516. {0x221f, 0x0007}, {0x221e, 0x002c}, {0x2218, 0x008b}, {0x221f, 0x0005},
  517. {0x2205, 0xfff6}, {0x2206, 0x0080}, {0x221f, 0x0005}, {0x2205, 0x8000},
  518. {0x2206, 0x0280}, {0x2206, 0x2bf7}, {0x2206, 0x00e0}, {0x2206, 0xfff7},
  519. {0x2206, 0xa080}, {0x2206, 0x02ae}, {0x2206, 0xf602}, {0x2206, 0x804e},
  520. {0x2206, 0x0201}, {0x2206, 0x5002}, {0x2206, 0x0163}, {0x2206, 0x0201},
  521. {0x2206, 0x79e0}, {0x2206, 0x8b8c}, {0x2206, 0xe18b}, {0x2206, 0x8d1e},
  522. {0x2206, 0x01e1}, {0x2206, 0x8b8e}, {0x2206, 0x1e01}, {0x2206, 0xa000},
  523. {0x2206, 0xe4ae}, {0x2206, 0xd8bf}, {0x2206, 0x8b88}, {0x2206, 0xec00},
  524. {0x2206, 0x19a9}, {0x2206, 0x8b90}, {0x2206, 0xf9ee}, {0x2206, 0xfff6},
  525. {0x2206, 0x00ee}, {0x2206, 0xfff7}, {0x2206, 0xfce0}, {0x2206, 0xe140},
  526. {0x2206, 0xe1e1}, {0x2206, 0x41f7}, {0x2206, 0x2ff6}, {0x2206, 0x28e4},
  527. {0x2206, 0xe140}, {0x2206, 0xe5e1}, {0x2206, 0x4104}, {0x2206, 0xf8fa},
  528. {0x2206, 0xef69}, {0x2206, 0xe08b}, {0x2206, 0x86ac}, {0x2206, 0x201a},
  529. {0x2206, 0xbf80}, {0x2206, 0x77d0}, {0x2206, 0x6c02}, {0x2206, 0x2978},
  530. {0x2206, 0xe0e0}, {0x2206, 0xe4e1}, {0x2206, 0xe0e5}, {0x2206, 0x5806},
  531. {0x2206, 0x68c0}, {0x2206, 0xd1d2}, {0x2206, 0xe4e0}, {0x2206, 0xe4e5},
  532. {0x2206, 0xe0e5}, {0x2206, 0xef96}, {0x2206, 0xfefc}, {0x2206, 0x0425},
  533. {0x2206, 0x0807}, {0x2206, 0x2640}, {0x2206, 0x7227}, {0x2206, 0x267e},
  534. {0x2206, 0x2804}, {0x2206, 0xb729}, {0x2206, 0x2576}, {0x2206, 0x2a68},
  535. {0x2206, 0xe52b}, {0x2206, 0xad00}, {0x2206, 0x2cdb}, {0x2206, 0xf02d},
  536. {0x2206, 0x67bb}, {0x2206, 0x2e7b}, {0x2206, 0x0f2f}, {0x2206, 0x7365},
  537. {0x2206, 0x31ac}, {0x2206, 0xcc32}, {0x2206, 0x2300}, {0x2206, 0x332d},
  538. {0x2206, 0x1734}, {0x2206, 0x7f52}, {0x2206, 0x3510}, {0x2206, 0x0036},
  539. {0x2206, 0x0600}, {0x2206, 0x370c}, {0x2206, 0xc038}, {0x2206, 0x7fce},
  540. {0x2206, 0x3ce5}, {0x2206, 0xf73d}, {0x2206, 0x3da4}, {0x2206, 0x6530},
  541. {0x2206, 0x3e67}, {0x2206, 0x0053}, {0x2206, 0x69d2}, {0x2206, 0x0f6a},
  542. {0x2206, 0x012c}, {0x2206, 0x6c2b}, {0x2206, 0x136e}, {0x2206, 0xe100},
  543. {0x2206, 0x6f12}, {0x2206, 0xf771}, {0x2206, 0x006b}, {0x2206, 0x7306},
  544. {0x2206, 0xeb74}, {0x2206, 0x94c7}, {0x2206, 0x7698}, {0x2206, 0x0a77},
  545. {0x2206, 0x5000}, {0x2206, 0x788a}, {0x2206, 0x1579}, {0x2206, 0x7f6f},
  546. {0x2206, 0x7a06}, {0x2206, 0xa600}, {0x2201, 0x0701}, {0x2200, 0x0405},
  547. {0x221f, 0x0000}, {0x2200, 0x1340}, {0x221f, 0x0000}, {0x133f, 0x0010},
  548. {0x133e, 0x0ffe}, {0x1203, 0xff00}, {0x1200, 0x7fc4}, {0x0900, 0x0000},
  549. {0x0901, 0x0000}, {0x0902, 0x0000}, {0x0903, 0x0000}, {0x0865, 0x3210},
  550. {0x087b, 0x0000}, {0x087c, 0xff00}, {0x087d, 0x0000}, {0x087e, 0x0000},
  551. {0x0801, 0x0100}, {0x0802, 0x0100}, {0x0A20, 0x2040}, {0x0A21, 0x2040},
  552. {0x0A22, 0x2040}, {0x0A23, 0x2040}, {0x0A24, 0x2040}, {0x0A25, 0x2040},
  553. {0x0A26, 0x2040}, {0x0A27, 0x2040}, {0x0A28, 0x2040}, {0x0A29, 0x2040},
  554. {0x130c, 0x0050},
  555. };
  556. static int rtl8367_write_initvals(struct rtl8366_smi *smi,
  557. const struct rtl8367_initval *initvals,
  558. int count)
  559. {
  560. int err;
  561. int i;
  562. for (i = 0; i < count; i++)
  563. REG_WR(smi, initvals[i].reg, initvals[i].val);
  564. return 0;
  565. }
  566. static int rtl8367_read_phy_reg(struct rtl8366_smi *smi,
  567. u32 phy_addr, u32 phy_reg, u32 *val)
  568. {
  569. int timeout;
  570. u32 data;
  571. int err;
  572. if (phy_addr > RTL8367_PHY_ADDR_MAX)
  573. return -EINVAL;
  574. if (phy_reg > RTL8367_PHY_REG_MAX)
  575. return -EINVAL;
  576. REG_RD(smi, RTL8367_IA_STATUS_REG, &data);
  577. if (data & RTL8367_IA_STATUS_PHY_BUSY)
  578. return -ETIMEDOUT;
  579. /* prepare address */
  580. REG_WR(smi, RTL8367_IA_ADDRESS_REG,
  581. RTL8367_INTERNAL_PHY_REG(phy_addr, phy_reg));
  582. /* send read command */
  583. REG_WR(smi, RTL8367_IA_CTRL_REG,
  584. RTL8367_IA_CTRL_CMD_MASK | RTL8367_IA_CTRL_RW_READ);
  585. timeout = 5;
  586. do {
  587. REG_RD(smi, RTL8367_IA_STATUS_REG, &data);
  588. if ((data & RTL8367_IA_STATUS_PHY_BUSY) == 0)
  589. break;
  590. if (timeout--) {
  591. dev_err(smi->parent, "phy read timed out\n");
  592. return -ETIMEDOUT;
  593. }
  594. udelay(1);
  595. } while (1);
  596. /* read data */
  597. REG_RD(smi, RTL8367_IA_READ_DATA_REG, val);
  598. dev_dbg(smi->parent, "phy_read: addr:%02x, reg:%02x, val:%04x\n",
  599. phy_addr, phy_reg, *val);
  600. return 0;
  601. }
  602. static int rtl8367_write_phy_reg(struct rtl8366_smi *smi,
  603. u32 phy_addr, u32 phy_reg, u32 val)
  604. {
  605. int timeout;
  606. u32 data;
  607. int err;
  608. dev_dbg(smi->parent, "phy_write: addr:%02x, reg:%02x, val:%04x\n",
  609. phy_addr, phy_reg, val);
  610. if (phy_addr > RTL8367_PHY_ADDR_MAX)
  611. return -EINVAL;
  612. if (phy_reg > RTL8367_PHY_REG_MAX)
  613. return -EINVAL;
  614. REG_RD(smi, RTL8367_IA_STATUS_REG, &data);
  615. if (data & RTL8367_IA_STATUS_PHY_BUSY)
  616. return -ETIMEDOUT;
  617. /* preapre data */
  618. REG_WR(smi, RTL8367_IA_WRITE_DATA_REG, val);
  619. /* prepare address */
  620. REG_WR(smi, RTL8367_IA_ADDRESS_REG,
  621. RTL8367_INTERNAL_PHY_REG(phy_addr, phy_reg));
  622. /* send write command */
  623. REG_WR(smi, RTL8367_IA_CTRL_REG,
  624. RTL8367_IA_CTRL_CMD_MASK | RTL8367_IA_CTRL_RW_WRITE);
  625. timeout = 5;
  626. do {
  627. REG_RD(smi, RTL8367_IA_STATUS_REG, &data);
  628. if ((data & RTL8367_IA_STATUS_PHY_BUSY) == 0)
  629. break;
  630. if (timeout--) {
  631. dev_err(smi->parent, "phy write timed out\n");
  632. return -ETIMEDOUT;
  633. }
  634. udelay(1);
  635. } while (1);
  636. return 0;
  637. }
  638. static int rtl8367_init_regs0(struct rtl8366_smi *smi, unsigned mode)
  639. {
  640. const struct rtl8367_initval *initvals;
  641. int count;
  642. int err;
  643. switch (mode) {
  644. case 0:
  645. initvals = rtl8367_initvals_0_0;
  646. count = ARRAY_SIZE(rtl8367_initvals_0_0);
  647. break;
  648. case 1:
  649. case 2:
  650. initvals = rtl8367_initvals_0_1;
  651. count = ARRAY_SIZE(rtl8367_initvals_0_1);
  652. break;
  653. default:
  654. dev_err(smi->parent, "%s: unknow mode %u\n", __func__, mode);
  655. return -ENODEV;
  656. }
  657. err = rtl8367_write_initvals(smi, initvals, count);
  658. if (err)
  659. return err;
  660. /* TODO: complete this */
  661. return 0;
  662. }
  663. static int rtl8367_init_regs1(struct rtl8366_smi *smi, unsigned mode)
  664. {
  665. const struct rtl8367_initval *initvals;
  666. int count;
  667. switch (mode) {
  668. case 0:
  669. initvals = rtl8367_initvals_1_0;
  670. count = ARRAY_SIZE(rtl8367_initvals_1_0);
  671. break;
  672. case 1:
  673. case 2:
  674. initvals = rtl8367_initvals_1_1;
  675. count = ARRAY_SIZE(rtl8367_initvals_1_1);
  676. break;
  677. default:
  678. dev_err(smi->parent, "%s: unknow mode %u\n", __func__, mode);
  679. return -ENODEV;
  680. }
  681. return rtl8367_write_initvals(smi, initvals, count);
  682. }
  683. static int rtl8367_init_regs2(struct rtl8366_smi *smi, unsigned mode)
  684. {
  685. const struct rtl8367_initval *initvals;
  686. int count;
  687. switch (mode) {
  688. case 0:
  689. initvals = rtl8367_initvals_2_0;
  690. count = ARRAY_SIZE(rtl8367_initvals_2_0);
  691. break;
  692. case 1:
  693. case 2:
  694. initvals = rtl8367_initvals_2_1;
  695. count = ARRAY_SIZE(rtl8367_initvals_2_1);
  696. break;
  697. default:
  698. dev_err(smi->parent, "%s: unknow mode %u\n", __func__, mode);
  699. return -ENODEV;
  700. }
  701. return rtl8367_write_initvals(smi, initvals, count);
  702. }
  703. static int rtl8367_init_regs(struct rtl8366_smi *smi)
  704. {
  705. u32 data;
  706. u32 rlvid;
  707. u32 mode;
  708. int err;
  709. REG_WR(smi, RTL8367_RTL_MAGIC_ID_REG, RTL8367_RTL_MAGIC_ID_VAL);
  710. REG_RD(smi, RTL8367_CHIP_VER_REG, &data);
  711. rlvid = (data >> RTL8367_CHIP_VER_RLVID_SHIFT) &
  712. RTL8367_CHIP_VER_RLVID_MASK;
  713. REG_RD(smi, RTL8367_CHIP_MODE_REG, &data);
  714. mode = data & RTL8367_CHIP_MODE_MASK;
  715. switch (rlvid) {
  716. case 0:
  717. err = rtl8367_init_regs0(smi, mode);
  718. break;
  719. case 1:
  720. err = rtl8367_write_phy_reg(smi, 0, 31, 5);
  721. if (err)
  722. break;
  723. err = rtl8367_write_phy_reg(smi, 0, 5, 0x3ffe);
  724. if (err)
  725. break;
  726. err = rtl8367_read_phy_reg(smi, 0, 6, &data);
  727. if (err)
  728. break;
  729. if (data == 0x94eb) {
  730. err = rtl8367_init_regs1(smi, mode);
  731. } else if (data == 0x2104) {
  732. err = rtl8367_init_regs2(smi, mode);
  733. } else {
  734. dev_err(smi->parent, "unknow phy data %04x\n", data);
  735. return -ENODEV;
  736. }
  737. break;
  738. default:
  739. dev_err(smi->parent, "unknow rlvid %u\n", rlvid);
  740. err = -ENODEV;
  741. break;
  742. }
  743. return err;
  744. }
  745. static int rtl8367_reset_chip(struct rtl8366_smi *smi)
  746. {
  747. int timeout = 10;
  748. int err;
  749. u32 data;
  750. REG_WR(smi, RTL8367_CHIP_RESET_REG, RTL8367_CHIP_RESET_HW);
  751. msleep(RTL8367_RESET_DELAY);
  752. do {
  753. REG_RD(smi, RTL8367_CHIP_RESET_REG, &data);
  754. if (!(data & RTL8367_CHIP_RESET_HW))
  755. break;
  756. msleep(1);
  757. } while (--timeout);
  758. if (!timeout) {
  759. dev_err(smi->parent, "chip reset timed out\n");
  760. return -ETIMEDOUT;
  761. }
  762. return 0;
  763. }
  764. static int rtl8367_extif_set_mode(struct rtl8366_smi *smi, int id,
  765. enum rtl8367_extif_mode mode)
  766. {
  767. int err;
  768. /* set port mode */
  769. switch (mode) {
  770. case RTL8367_EXTIF_MODE_RGMII:
  771. case RTL8367_EXTIF_MODE_RGMII_33V:
  772. REG_WR(smi, RTL8367_CHIP_DEBUG0_REG, 0x0367);
  773. REG_WR(smi, RTL8367_CHIP_DEBUG1_REG, 0x7777);
  774. break;
  775. case RTL8367_EXTIF_MODE_TMII_MAC:
  776. case RTL8367_EXTIF_MODE_TMII_PHY:
  777. REG_RMW(smi, RTL8367_BYPASS_LINE_RATE_REG,
  778. BIT((id + 1) % 2), BIT((id + 1) % 2));
  779. break;
  780. case RTL8367_EXTIF_MODE_GMII:
  781. REG_RMW(smi, RTL8367_CHIP_DEBUG0_REG,
  782. RTL8367_CHIP_DEBUG0_DUMMY0(id),
  783. RTL8367_CHIP_DEBUG0_DUMMY0(id));
  784. REG_RMW(smi, RTL8367_EXT_RGMXF_REG(id), BIT(6), BIT(6));
  785. break;
  786. case RTL8367_EXTIF_MODE_MII_MAC:
  787. case RTL8367_EXTIF_MODE_MII_PHY:
  788. case RTL8367_EXTIF_MODE_DISABLED:
  789. REG_RMW(smi, RTL8367_BYPASS_LINE_RATE_REG,
  790. BIT((id + 1) % 2), 0);
  791. REG_RMW(smi, RTL8367_EXT_RGMXF_REG(id), BIT(6), 0);
  792. break;
  793. default:
  794. dev_err(smi->parent,
  795. "invalid mode for external interface %d\n", id);
  796. return -EINVAL;
  797. }
  798. REG_RMW(smi, RTL8367_DIS_REG,
  799. RTL8367_DIS_RGMII_MASK << RTL8367_DIS_RGMII_SHIFT(id),
  800. mode << RTL8367_DIS_RGMII_SHIFT(id));
  801. return 0;
  802. }
  803. static int rtl8367_extif_set_force(struct rtl8366_smi *smi, int id,
  804. struct rtl8367_port_ability *pa)
  805. {
  806. u32 mask;
  807. u32 val;
  808. int err;
  809. mask = (RTL8367_DI_FORCE_MODE |
  810. RTL8367_DI_FORCE_NWAY |
  811. RTL8367_DI_FORCE_TXPAUSE |
  812. RTL8367_DI_FORCE_RXPAUSE |
  813. RTL8367_DI_FORCE_LINK |
  814. RTL8367_DI_FORCE_DUPLEX |
  815. RTL8367_DI_FORCE_SPEED_MASK);
  816. val = pa->speed;
  817. val |= pa->force_mode ? RTL8367_DI_FORCE_MODE : 0;
  818. val |= pa->nway ? RTL8367_DI_FORCE_NWAY : 0;
  819. val |= pa->txpause ? RTL8367_DI_FORCE_TXPAUSE : 0;
  820. val |= pa->rxpause ? RTL8367_DI_FORCE_RXPAUSE : 0;
  821. val |= pa->link ? RTL8367_DI_FORCE_LINK : 0;
  822. val |= pa->duplex ? RTL8367_DI_FORCE_DUPLEX : 0;
  823. REG_RMW(smi, RTL8367_DI_FORCE_REG(id), mask, val);
  824. return 0;
  825. }
  826. static int rtl8367_extif_set_rgmii_delay(struct rtl8366_smi *smi, int id,
  827. unsigned txdelay, unsigned rxdelay)
  828. {
  829. u32 mask;
  830. u32 val;
  831. int err;
  832. mask = (RTL8367_EXT_RGMXF_RXDELAY_MASK |
  833. (RTL8367_EXT_RGMXF_TXDELAY_MASK <<
  834. RTL8367_EXT_RGMXF_TXDELAY_SHIFT));
  835. val = rxdelay;
  836. val |= txdelay << RTL8367_EXT_RGMXF_TXDELAY_SHIFT;
  837. REG_RMW(smi, RTL8367_EXT_RGMXF_REG(id), mask, val);
  838. return 0;
  839. }
  840. static int rtl8367_extif_init(struct rtl8366_smi *smi, int id,
  841. struct rtl8367_extif_config *cfg)
  842. {
  843. enum rtl8367_extif_mode mode;
  844. int err;
  845. mode = (cfg) ? cfg->mode : RTL8367_EXTIF_MODE_DISABLED;
  846. err = rtl8367_extif_set_mode(smi, id, mode);
  847. if (err)
  848. return err;
  849. if (mode != RTL8367_EXTIF_MODE_DISABLED) {
  850. err = rtl8367_extif_set_force(smi, id, &cfg->ability);
  851. if (err)
  852. return err;
  853. err = rtl8367_extif_set_rgmii_delay(smi, id, cfg->txdelay,
  854. cfg->rxdelay);
  855. if (err)
  856. return err;
  857. }
  858. return 0;
  859. }
  860. static int rtl8367_led_group_set_ports(struct rtl8366_smi *smi,
  861. unsigned int group, u16 port_mask)
  862. {
  863. u32 reg;
  864. u32 s;
  865. int err;
  866. port_mask &= RTL8367_PARA_LED_IO_EN_PMASK;
  867. s = (group % 2) * 8;
  868. reg = RTL8367_PARA_LED_IO_EN1_REG + (group / 2);
  869. REG_RMW(smi, reg, (RTL8367_PARA_LED_IO_EN_PMASK << s), port_mask << s);
  870. return 0;
  871. }
  872. static int rtl8367_led_group_set_mode(struct rtl8366_smi *smi,
  873. unsigned int mode)
  874. {
  875. u16 mask;
  876. u16 set;
  877. int err;
  878. mode &= RTL8367_LED_CONFIG_DATA_M;
  879. mask = (RTL8367_LED_CONFIG_DATA_M << RTL8367_LED_CONFIG_DATA_S) |
  880. RTL8367_LED_CONFIG_SEL;
  881. set = (mode << RTL8367_LED_CONFIG_DATA_S) | RTL8367_LED_CONFIG_SEL;
  882. REG_RMW(smi, RTL8367_LED_CONFIG_REG, mask, set);
  883. return 0;
  884. }
  885. static int rtl8367_led_group_set_config(struct rtl8366_smi *smi,
  886. unsigned int led, unsigned int cfg)
  887. {
  888. u16 mask;
  889. u16 set;
  890. int err;
  891. mask = (RTL8367_LED_CONFIG_LED_CFG_M << (led * 4)) |
  892. RTL8367_LED_CONFIG_SEL;
  893. set = (cfg & RTL8367_LED_CONFIG_LED_CFG_M) << (led * 4);
  894. REG_RMW(smi, RTL8367_LED_CONFIG_REG, mask, set);
  895. return 0;
  896. }
  897. static int rtl8367_led_op_select_parallel(struct rtl8366_smi *smi)
  898. {
  899. int err;
  900. REG_WR(smi, RTL8367_LED_SYS_CONFIG_REG, 0x1472);
  901. return 0;
  902. }
  903. static int rtl8367_led_blinkrate_set(struct rtl8366_smi *smi, unsigned int rate)
  904. {
  905. u16 mask;
  906. u16 set;
  907. int err;
  908. mask = RTL8367_LED_MODE_RATE_M << RTL8367_LED_MODE_RATE_S;
  909. set = (rate & RTL8367_LED_MODE_RATE_M) << RTL8367_LED_MODE_RATE_S;
  910. REG_RMW(smi, RTL8367_LED_MODE_REG, mask, set);
  911. return 0;
  912. }
  913. #ifdef CONFIG_OF
  914. static int rtl8367_extif_init_of(struct rtl8366_smi *smi, int id,
  915. const char *name)
  916. {
  917. struct rtl8367_extif_config *cfg;
  918. const __be32 *prop;
  919. int size;
  920. int err;
  921. prop = of_get_property(smi->parent->of_node, name, &size);
  922. if (!prop)
  923. return rtl8367_extif_init(smi, id, NULL);
  924. if (size != (9 * sizeof(*prop))) {
  925. dev_err(smi->parent, "%s property is invalid\n", name);
  926. return -EINVAL;
  927. }
  928. cfg = kzalloc(sizeof(struct rtl8367_extif_config), GFP_KERNEL);
  929. if (!cfg)
  930. return -ENOMEM;
  931. cfg->txdelay = be32_to_cpup(prop++);
  932. cfg->rxdelay = be32_to_cpup(prop++);
  933. cfg->mode = be32_to_cpup(prop++);
  934. cfg->ability.force_mode = be32_to_cpup(prop++);
  935. cfg->ability.txpause = be32_to_cpup(prop++);
  936. cfg->ability.rxpause = be32_to_cpup(prop++);
  937. cfg->ability.link = be32_to_cpup(prop++);
  938. cfg->ability.duplex = be32_to_cpup(prop++);
  939. cfg->ability.speed = be32_to_cpup(prop++);
  940. err = rtl8367_extif_init(smi, id, cfg);
  941. kfree(cfg);
  942. return err;
  943. }
  944. #else
  945. static int rtl8367_extif_init_of(struct rtl8366_smi *smi, int id,
  946. const char *name)
  947. {
  948. return -EINVAL;
  949. }
  950. #endif
  951. static int rtl8367_setup(struct rtl8366_smi *smi)
  952. {
  953. struct rtl8367_platform_data *pdata;
  954. int err;
  955. int i;
  956. pdata = smi->parent->platform_data;
  957. err = rtl8367_init_regs(smi);
  958. if (err)
  959. return err;
  960. /* initialize external interfaces */
  961. if (smi->parent->of_node) {
  962. err = rtl8367_extif_init_of(smi, 0, "realtek,extif0");
  963. if (err)
  964. return err;
  965. err = rtl8367_extif_init_of(smi, 1, "realtek,extif1");
  966. if (err)
  967. return err;
  968. } else {
  969. err = rtl8367_extif_init(smi, 0, pdata->extif0_cfg);
  970. if (err)
  971. return err;
  972. err = rtl8367_extif_init(smi, 1, pdata->extif1_cfg);
  973. if (err)
  974. return err;
  975. }
  976. /* set maximum packet length to 1536 bytes */
  977. REG_RMW(smi, RTL8367_SWC0_REG, RTL8367_SWC0_MAX_LENGTH_MASK,
  978. RTL8367_SWC0_MAX_LENGTH_1536);
  979. /*
  980. * discard VLAN tagged packets if the port is not a member of
  981. * the VLAN with which the packets is associated.
  982. */
  983. REG_WR(smi, RTL8367_VLAN_INGRESS_REG, RTL8367_PORTS_ALL);
  984. /*
  985. * Setup egress tag mode for each port.
  986. */
  987. for (i = 0; i < RTL8367_NUM_PORTS; i++)
  988. REG_RMW(smi,
  989. RTL8367_PORT_CFG_REG(i),
  990. RTL8367_PORT_CFG_EGRESS_MODE_MASK <<
  991. RTL8367_PORT_CFG_EGRESS_MODE_SHIFT,
  992. RTL8367_PORT_CFG_EGRESS_MODE_ORIGINAL <<
  993. RTL8367_PORT_CFG_EGRESS_MODE_SHIFT);
  994. /* setup LEDs */
  995. err = rtl8367_led_group_set_ports(smi, 0, RTL8367_PORTS_ALL);
  996. if (err)
  997. return err;
  998. err = rtl8367_led_group_set_mode(smi, 0);
  999. if (err)
  1000. return err;
  1001. err = rtl8367_led_op_select_parallel(smi);
  1002. if (err)
  1003. return err;
  1004. err = rtl8367_led_blinkrate_set(smi, 1);
  1005. if (err)
  1006. return err;
  1007. err = rtl8367_led_group_set_config(smi, 0, 2);
  1008. if (err)
  1009. return err;
  1010. return 0;
  1011. }
  1012. static int rtl8367_get_mib_counter(struct rtl8366_smi *smi, int counter,
  1013. int port, unsigned long long *val)
  1014. {
  1015. struct rtl8366_mib_counter *mib;
  1016. int offset;
  1017. int i;
  1018. int err;
  1019. u32 addr, data;
  1020. u64 mibvalue;
  1021. if (port > RTL8367_NUM_PORTS || counter >= RTL8367_MIB_COUNT)
  1022. return -EINVAL;
  1023. mib = &rtl8367_mib_counters[counter];
  1024. addr = RTL8367_MIB_COUNTER_PORT_OFFSET * port + mib->offset;
  1025. /*
  1026. * Writing access counter address first
  1027. * then ASIC will prepare 64bits counter wait for being retrived
  1028. */
  1029. REG_WR(smi, RTL8367_MIB_ADDRESS_REG, addr >> 2);
  1030. /* read MIB control register */
  1031. REG_RD(smi, RTL8367_MIB_CTRL_REG(0), &data);
  1032. if (data & RTL8367_MIB_CTRL_BUSY_MASK)
  1033. return -EBUSY;
  1034. if (data & RTL8367_MIB_CTRL_RESET_MASK)
  1035. return -EIO;
  1036. if (mib->length == 4)
  1037. offset = 3;
  1038. else
  1039. offset = (mib->offset + 1) % 4;
  1040. mibvalue = 0;
  1041. for (i = 0; i < mib->length; i++) {
  1042. REG_RD(smi, RTL8367_MIB_COUNTER_REG(offset - i), &data);
  1043. mibvalue = (mibvalue << 16) | (data & 0xFFFF);
  1044. }
  1045. *val = mibvalue;
  1046. return 0;
  1047. }
  1048. static int rtl8367_get_vlan_4k(struct rtl8366_smi *smi, u32 vid,
  1049. struct rtl8366_vlan_4k *vlan4k)
  1050. {
  1051. u32 data[RTL8367_TA_VLAN_DATA_SIZE];
  1052. int err;
  1053. int i;
  1054. memset(vlan4k, '\0', sizeof(struct rtl8366_vlan_4k));
  1055. if (vid >= RTL8367_NUM_VIDS)
  1056. return -EINVAL;
  1057. /* write VID */
  1058. REG_WR(smi, RTL8367_TA_ADDR_REG, vid);
  1059. /* write table access control word */
  1060. REG_WR(smi, RTL8367_TA_CTRL_REG, RTL8367_TA_CTRL_CVLAN_READ);
  1061. for (i = 0; i < ARRAY_SIZE(data); i++)
  1062. REG_RD(smi, RTL8367_TA_DATA_REG(i), &data[i]);
  1063. vlan4k->vid = vid;
  1064. vlan4k->member = (data[0] >> RTL8367_TA_VLAN_MEMBER_SHIFT) &
  1065. RTL8367_TA_VLAN_MEMBER_MASK;
  1066. vlan4k->fid = (data[1] >> RTL8367_TA_VLAN_FID_SHIFT) &
  1067. RTL8367_TA_VLAN_FID_MASK;
  1068. vlan4k->untag = (data[2] >> RTL8367_TA_VLAN_UNTAG1_SHIFT) &
  1069. RTL8367_TA_VLAN_UNTAG1_MASK;
  1070. vlan4k->untag |= ((data[3] >> RTL8367_TA_VLAN_UNTAG2_SHIFT) &
  1071. RTL8367_TA_VLAN_UNTAG2_MASK) << 2;
  1072. return 0;
  1073. }
  1074. static int rtl8367_set_vlan_4k(struct rtl8366_smi *smi,
  1075. const struct rtl8366_vlan_4k *vlan4k)
  1076. {
  1077. u32 data[RTL8367_TA_VLAN_DATA_SIZE];
  1078. int err;
  1079. int i;
  1080. if (vlan4k->vid >= RTL8367_NUM_VIDS ||
  1081. vlan4k->member > RTL8367_TA_VLAN_MEMBER_MASK ||
  1082. vlan4k->untag > RTL8367_UNTAG_MASK ||
  1083. vlan4k->fid > RTL8367_FIDMAX)
  1084. return -EINVAL;
  1085. data[0] = (vlan4k->member & RTL8367_TA_VLAN_MEMBER_MASK) <<
  1086. RTL8367_TA_VLAN_MEMBER_SHIFT;
  1087. data[1] = (vlan4k->fid & RTL8367_TA_VLAN_FID_MASK) <<
  1088. RTL8367_TA_VLAN_FID_SHIFT;
  1089. data[2] = (vlan4k->untag & RTL8367_TA_VLAN_UNTAG1_MASK) <<
  1090. RTL8367_TA_VLAN_UNTAG1_SHIFT;
  1091. data[3] = ((vlan4k->untag >> 2) & RTL8367_TA_VLAN_UNTAG2_MASK) <<
  1092. RTL8367_TA_VLAN_UNTAG2_SHIFT;
  1093. for (i = 0; i < ARRAY_SIZE(data); i++)
  1094. REG_WR(smi, RTL8367_TA_DATA_REG(i), data[i]);
  1095. /* write VID */
  1096. REG_WR(smi, RTL8367_TA_ADDR_REG,
  1097. vlan4k->vid & RTL8367_TA_VLAN_VID_MASK);
  1098. /* write table access control word */
  1099. REG_WR(smi, RTL8367_TA_CTRL_REG, RTL8367_TA_CTRL_CVLAN_WRITE);
  1100. return 0;
  1101. }
  1102. static int rtl8367_get_vlan_mc(struct rtl8366_smi *smi, u32 index,
  1103. struct rtl8366_vlan_mc *vlanmc)
  1104. {
  1105. u32 data[RTL8367_VLAN_MC_DATA_SIZE];
  1106. int err;
  1107. int i;
  1108. memset(vlanmc, '\0', sizeof(struct rtl8366_vlan_mc));
  1109. if (index >= RTL8367_NUM_VLANS)
  1110. return -EINVAL;
  1111. for (i = 0; i < ARRAY_SIZE(data); i++)
  1112. REG_RD(smi, RTL8367_VLAN_MC_BASE(index) + i, &data[i]);
  1113. vlanmc->member = (data[0] >> RTL8367_VLAN_MC_MEMBER_SHIFT) &
  1114. RTL8367_VLAN_MC_MEMBER_MASK;
  1115. vlanmc->fid = (data[1] >> RTL8367_VLAN_MC_FID_SHIFT) &
  1116. RTL8367_VLAN_MC_FID_MASK;
  1117. vlanmc->vid = (data[3] >> RTL8367_VLAN_MC_EVID_SHIFT) &
  1118. RTL8367_VLAN_MC_EVID_MASK;
  1119. return 0;
  1120. }
  1121. static int rtl8367_set_vlan_mc(struct rtl8366_smi *smi, u32 index,
  1122. const struct rtl8366_vlan_mc *vlanmc)
  1123. {
  1124. u32 data[RTL8367_VLAN_MC_DATA_SIZE];
  1125. int err;
  1126. int i;
  1127. if (index >= RTL8367_NUM_VLANS ||
  1128. vlanmc->vid >= RTL8367_NUM_VIDS ||
  1129. vlanmc->priority > RTL8367_PRIORITYMAX ||
  1130. vlanmc->member > RTL8367_VLAN_MC_MEMBER_MASK ||
  1131. vlanmc->untag > RTL8367_UNTAG_MASK ||
  1132. vlanmc->fid > RTL8367_FIDMAX)
  1133. return -EINVAL;
  1134. data[0] = (vlanmc->member & RTL8367_VLAN_MC_MEMBER_MASK) <<
  1135. RTL8367_VLAN_MC_MEMBER_SHIFT;
  1136. data[1] = (vlanmc->fid & RTL8367_VLAN_MC_FID_MASK) <<
  1137. RTL8367_VLAN_MC_FID_SHIFT;
  1138. data[2] = 0;
  1139. data[3] = (vlanmc->vid & RTL8367_VLAN_MC_EVID_MASK) <<
  1140. RTL8367_VLAN_MC_EVID_SHIFT;
  1141. for (i = 0; i < ARRAY_SIZE(data); i++)
  1142. REG_WR(smi, RTL8367_VLAN_MC_BASE(index) + i, data[i]);
  1143. return 0;
  1144. }
  1145. static int rtl8367_get_mc_index(struct rtl8366_smi *smi, int port, int *val)
  1146. {
  1147. u32 data;
  1148. int err;
  1149. if (port >= RTL8367_NUM_PORTS)
  1150. return -EINVAL;
  1151. REG_RD(smi, RTL8367_VLAN_PVID_CTRL_REG(port), &data);
  1152. *val = (data >> RTL8367_VLAN_PVID_CTRL_SHIFT(port)) &
  1153. RTL8367_VLAN_PVID_CTRL_MASK;
  1154. return 0;
  1155. }
  1156. static int rtl8367_set_mc_index(struct rtl8366_smi *smi, int port, int index)
  1157. {
  1158. if (port >= RTL8367_NUM_PORTS || index >= RTL8367_NUM_VLANS)
  1159. return -EINVAL;
  1160. return rtl8366_smi_rmwr(smi, RTL8367_VLAN_PVID_CTRL_REG(port),
  1161. RTL8367_VLAN_PVID_CTRL_MASK <<
  1162. RTL8367_VLAN_PVID_CTRL_SHIFT(port),
  1163. (index & RTL8367_VLAN_PVID_CTRL_MASK) <<
  1164. RTL8367_VLAN_PVID_CTRL_SHIFT(port));
  1165. }
  1166. static int rtl8367_enable_vlan(struct rtl8366_smi *smi, int enable)
  1167. {
  1168. return rtl8366_smi_rmwr(smi, RTL8367_VLAN_CTRL_REG,
  1169. RTL8367_VLAN_CTRL_ENABLE,
  1170. (enable) ? RTL8367_VLAN_CTRL_ENABLE : 0);
  1171. }
  1172. static int rtl8367_enable_vlan4k(struct rtl8366_smi *smi, int enable)
  1173. {
  1174. return 0;
  1175. }
  1176. static int rtl8367_is_vlan_valid(struct rtl8366_smi *smi, unsigned vlan)
  1177. {
  1178. unsigned max = RTL8367_NUM_VLANS;
  1179. if (smi->vlan4k_enabled)
  1180. max = RTL8367_NUM_VIDS - 1;
  1181. if (vlan == 0 || vlan >= max)
  1182. return 0;
  1183. return 1;
  1184. }
  1185. static int rtl8367_enable_port(struct rtl8366_smi *smi, int port, int enable)
  1186. {
  1187. int err;
  1188. REG_WR(smi, RTL8367_PORT_ISOLATION_REG(port),
  1189. (enable) ? RTL8367_PORTS_ALL : 0);
  1190. return 0;
  1191. }
  1192. static int rtl8367_sw_reset_mibs(struct switch_dev *dev,
  1193. const struct switch_attr *attr,
  1194. struct switch_val *val)
  1195. {
  1196. struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
  1197. return rtl8366_smi_rmwr(smi, RTL8367_MIB_CTRL_REG(0), 0,
  1198. RTL8367_MIB_CTRL_GLOBAL_RESET_MASK);
  1199. }
  1200. static int rtl8367_sw_get_port_link(struct switch_dev *dev,
  1201. int port,
  1202. struct switch_port_link *link)
  1203. {
  1204. struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
  1205. u32 data = 0;
  1206. u32 speed;
  1207. if (port >= RTL8367_NUM_PORTS)
  1208. return -EINVAL;
  1209. rtl8366_smi_read_reg(smi, RTL8367_PORT_STATUS_REG(port), &data);
  1210. link->link = !!(data & RTL8367_PORT_STATUS_LINK);
  1211. if (!link->link)
  1212. return 0;
  1213. link->duplex = !!(data & RTL8367_PORT_STATUS_DUPLEX);
  1214. link->rx_flow = !!(data & RTL8367_PORT_STATUS_RXPAUSE);
  1215. link->tx_flow = !!(data & RTL8367_PORT_STATUS_TXPAUSE);
  1216. link->aneg = !!(data & RTL8367_PORT_STATUS_NWAY);
  1217. speed = (data & RTL8367_PORT_STATUS_SPEED_MASK);
  1218. switch (speed) {
  1219. case 0:
  1220. link->speed = SWITCH_PORT_SPEED_10;
  1221. break;
  1222. case 1:
  1223. link->speed = SWITCH_PORT_SPEED_100;
  1224. break;
  1225. case 2:
  1226. link->speed = SWITCH_PORT_SPEED_1000;
  1227. break;
  1228. default:
  1229. link->speed = SWITCH_PORT_SPEED_UNKNOWN;
  1230. break;
  1231. }
  1232. return 0;
  1233. }
  1234. static int rtl8367_sw_get_max_length(struct switch_dev *dev,
  1235. const struct switch_attr *attr,
  1236. struct switch_val *val)
  1237. {
  1238. struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
  1239. u32 data;
  1240. rtl8366_smi_read_reg(smi, RTL8367_SWC0_REG, &data);
  1241. val->value.i = (data & RTL8367_SWC0_MAX_LENGTH_MASK) >>
  1242. RTL8367_SWC0_MAX_LENGTH_SHIFT;
  1243. return 0;
  1244. }
  1245. static int rtl8367_sw_set_max_length(struct switch_dev *dev,
  1246. const struct switch_attr *attr,
  1247. struct switch_val *val)
  1248. {
  1249. struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
  1250. u32 max_len;
  1251. switch (val->value.i) {
  1252. case 0:
  1253. max_len = RTL8367_SWC0_MAX_LENGTH_1522;
  1254. break;
  1255. case 1:
  1256. max_len = RTL8367_SWC0_MAX_LENGTH_1536;
  1257. break;
  1258. case 2:
  1259. max_len = RTL8367_SWC0_MAX_LENGTH_1552;
  1260. break;
  1261. case 3:
  1262. max_len = RTL8367_SWC0_MAX_LENGTH_16000;
  1263. break;
  1264. default:
  1265. return -EINVAL;
  1266. }
  1267. return rtl8366_smi_rmwr(smi, RTL8367_SWC0_REG,
  1268. RTL8367_SWC0_MAX_LENGTH_MASK, max_len);
  1269. }
  1270. static int rtl8367_sw_reset_port_mibs(struct switch_dev *dev,
  1271. const struct switch_attr *attr,
  1272. struct switch_val *val)
  1273. {
  1274. struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
  1275. int port;
  1276. port = val->port_vlan;
  1277. if (port >= RTL8367_NUM_PORTS)
  1278. return -EINVAL;
  1279. return rtl8366_smi_rmwr(smi, RTL8367_MIB_CTRL_REG(port / 8), 0,
  1280. RTL8367_MIB_CTRL_PORT_RESET_MASK(port % 8));
  1281. }
  1282. static struct switch_attr rtl8367_globals[] = {
  1283. {
  1284. .type = SWITCH_TYPE_INT,
  1285. .name = "enable_vlan",
  1286. .description = "Enable VLAN mode",
  1287. .set = rtl8366_sw_set_vlan_enable,
  1288. .get = rtl8366_sw_get_vlan_enable,
  1289. .max = 1,
  1290. .ofs = 1
  1291. }, {
  1292. .type = SWITCH_TYPE_INT,
  1293. .name = "enable_vlan4k",
  1294. .description = "Enable VLAN 4K mode",
  1295. .set = rtl8366_sw_set_vlan_enable,
  1296. .get = rtl8366_sw_get_vlan_enable,
  1297. .max = 1,
  1298. .ofs = 2
  1299. }, {
  1300. .type = SWITCH_TYPE_NOVAL,
  1301. .name = "reset_mibs",
  1302. .description = "Reset all MIB counters",
  1303. .set = rtl8367_sw_reset_mibs,
  1304. }, {
  1305. .type = SWITCH_TYPE_INT,
  1306. .name = "max_length",
  1307. .description = "Get/Set the maximum length of valid packets"
  1308. "(0:1522, 1:1536, 2:1552, 3:16000)",
  1309. .set = rtl8367_sw_set_max_length,
  1310. .get = rtl8367_sw_get_max_length,
  1311. .max = 3,
  1312. }
  1313. };
  1314. static struct switch_attr rtl8367_port[] = {
  1315. {
  1316. .type = SWITCH_TYPE_NOVAL,
  1317. .name = "reset_mib",
  1318. .description = "Reset single port MIB counters",
  1319. .set = rtl8367_sw_reset_port_mibs,
  1320. }, {
  1321. .type = SWITCH_TYPE_STRING,
  1322. .name = "mib",
  1323. .description = "Get MIB counters for port",
  1324. .max = 33,
  1325. .set = NULL,
  1326. .get = rtl8366_sw_get_port_mib,
  1327. },
  1328. };
  1329. static struct switch_attr rtl8367_vlan[] = {
  1330. {
  1331. .type = SWITCH_TYPE_STRING,
  1332. .name = "info",
  1333. .description = "Get vlan information",
  1334. .max = 1,
  1335. .set = NULL,
  1336. .get = rtl8366_sw_get_vlan_info,
  1337. }, {
  1338. .type = SWITCH_TYPE_INT,
  1339. .name = "fid",
  1340. .description = "Get/Set vlan FID",
  1341. .max = RTL8367_FIDMAX,
  1342. .set = rtl8366_sw_set_vlan_fid,
  1343. .get = rtl8366_sw_get_vlan_fid,
  1344. },
  1345. };
  1346. static const struct switch_dev_ops rtl8367_sw_ops = {
  1347. .attr_global = {
  1348. .attr = rtl8367_globals,
  1349. .n_attr = ARRAY_SIZE(rtl8367_globals),
  1350. },
  1351. .attr_port = {
  1352. .attr = rtl8367_port,
  1353. .n_attr = ARRAY_SIZE(rtl8367_port),
  1354. },
  1355. .attr_vlan = {
  1356. .attr = rtl8367_vlan,
  1357. .n_attr = ARRAY_SIZE(rtl8367_vlan),
  1358. },
  1359. .get_vlan_ports = rtl8366_sw_get_vlan_ports,
  1360. .set_vlan_ports = rtl8366_sw_set_vlan_ports,
  1361. .get_port_pvid = rtl8366_sw_get_port_pvid,
  1362. .set_port_pvid = rtl8366_sw_set_port_pvid,
  1363. .reset_switch = rtl8366_sw_reset_switch,
  1364. .get_port_link = rtl8367_sw_get_port_link,
  1365. };
  1366. static int rtl8367_switch_init(struct rtl8366_smi *smi)
  1367. {
  1368. struct switch_dev *dev = &smi->sw_dev;
  1369. int err;
  1370. dev->name = "RTL8367";
  1371. dev->cpu_port = RTL8367_CPU_PORT_NUM;
  1372. dev->ports = RTL8367_NUM_PORTS;
  1373. dev->vlans = RTL8367_NUM_VIDS;
  1374. dev->ops = &rtl8367_sw_ops;
  1375. dev->alias = dev_name(smi->parent);
  1376. err = register_switch(dev, NULL);
  1377. if (err)
  1378. dev_err(smi->parent, "switch registration failed\n");
  1379. return err;
  1380. }
  1381. static void rtl8367_switch_cleanup(struct rtl8366_smi *smi)
  1382. {
  1383. unregister_switch(&smi->sw_dev);
  1384. }
  1385. static int rtl8367_mii_read(struct mii_bus *bus, int addr, int reg)
  1386. {
  1387. struct rtl8366_smi *smi = bus->priv;
  1388. u32 val = 0;
  1389. int err;
  1390. err = rtl8367_read_phy_reg(smi, addr, reg, &val);
  1391. if (err)
  1392. return 0xffff;
  1393. return val;
  1394. }
  1395. static int rtl8367_mii_write(struct mii_bus *bus, int addr, int reg, u16 val)
  1396. {
  1397. struct rtl8366_smi *smi = bus->priv;
  1398. u32 t;
  1399. int err;
  1400. err = rtl8367_write_phy_reg(smi, addr, reg, val);
  1401. if (err)
  1402. return err;
  1403. /* flush write */
  1404. (void) rtl8367_read_phy_reg(smi, addr, reg, &t);
  1405. return err;
  1406. }
  1407. static int rtl8367_detect(struct rtl8366_smi *smi)
  1408. {
  1409. u32 rtl_no = 0;
  1410. u32 rtl_ver = 0;
  1411. char *chip_name;
  1412. int ret;
  1413. ret = rtl8366_smi_read_reg(smi, RTL8367_RTL_NO_REG, &rtl_no);
  1414. if (ret) {
  1415. dev_err(smi->parent, "unable to read chip number\n");
  1416. return ret;
  1417. }
  1418. switch (rtl_no) {
  1419. case RTL8367_RTL_NO_8367R:
  1420. chip_name = "8367R";
  1421. break;
  1422. case RTL8367_RTL_NO_8367M:
  1423. chip_name = "8367M";
  1424. break;
  1425. default:
  1426. dev_err(smi->parent, "unknown chip number (%04x)\n", rtl_no);
  1427. return -ENODEV;
  1428. }
  1429. ret = rtl8366_smi_read_reg(smi, RTL8367_RTL_VER_REG, &rtl_ver);
  1430. if (ret) {
  1431. dev_err(smi->parent, "unable to read chip version\n");
  1432. return ret;
  1433. }
  1434. dev_info(smi->parent, "RTL%s ver. %u chip found\n",
  1435. chip_name, rtl_ver & RTL8367_RTL_VER_MASK);
  1436. return 0;
  1437. }
  1438. static struct rtl8366_smi_ops rtl8367_smi_ops = {
  1439. .detect = rtl8367_detect,
  1440. .reset_chip = rtl8367_reset_chip,
  1441. .setup = rtl8367_setup,
  1442. .mii_read = rtl8367_mii_read,
  1443. .mii_write = rtl8367_mii_write,
  1444. .get_vlan_mc = rtl8367_get_vlan_mc,
  1445. .set_vlan_mc = rtl8367_set_vlan_mc,
  1446. .get_vlan_4k = rtl8367_get_vlan_4k,
  1447. .set_vlan_4k = rtl8367_set_vlan_4k,
  1448. .get_mc_index = rtl8367_get_mc_index,
  1449. .set_mc_index = rtl8367_set_mc_index,
  1450. .get_mib_counter = rtl8367_get_mib_counter,
  1451. .is_vlan_valid = rtl8367_is_vlan_valid,
  1452. .enable_vlan = rtl8367_enable_vlan,
  1453. .enable_vlan4k = rtl8367_enable_vlan4k,
  1454. .enable_port = rtl8367_enable_port,
  1455. };
  1456. static int rtl8367_probe(struct platform_device *pdev)
  1457. {
  1458. struct rtl8366_smi *smi;
  1459. int err;
  1460. smi = rtl8366_smi_probe(pdev);
  1461. if (!smi)
  1462. return -ENODEV;
  1463. smi->clk_delay = 1500;
  1464. smi->cmd_read = 0xb9;
  1465. smi->cmd_write = 0xb8;
  1466. smi->ops = &rtl8367_smi_ops;
  1467. smi->cpu_port = RTL8367_CPU_PORT_NUM;
  1468. smi->num_ports = RTL8367_NUM_PORTS;
  1469. smi->num_vlan_mc = RTL8367_NUM_VLANS;
  1470. smi->mib_counters = rtl8367_mib_counters;
  1471. smi->num_mib_counters = ARRAY_SIZE(rtl8367_mib_counters);
  1472. err = rtl8366_smi_init(smi);
  1473. if (err)
  1474. goto err_free_smi;
  1475. platform_set_drvdata(pdev, smi);
  1476. err = rtl8367_switch_init(smi);
  1477. if (err)
  1478. goto err_clear_drvdata;
  1479. return 0;
  1480. err_clear_drvdata:
  1481. platform_set_drvdata(pdev, NULL);
  1482. rtl8366_smi_cleanup(smi);
  1483. err_free_smi:
  1484. kfree(smi);
  1485. return err;
  1486. }
  1487. static int rtl8367_remove(struct platform_device *pdev)
  1488. {
  1489. struct rtl8366_smi *smi = platform_get_drvdata(pdev);
  1490. if (smi) {
  1491. rtl8367_switch_cleanup(smi);
  1492. platform_set_drvdata(pdev, NULL);
  1493. rtl8366_smi_cleanup(smi);
  1494. kfree(smi);
  1495. }
  1496. return 0;
  1497. }
  1498. static void rtl8367_shutdown(struct platform_device *pdev)
  1499. {
  1500. struct rtl8366_smi *smi = platform_get_drvdata(pdev);
  1501. if (smi)
  1502. rtl8367_reset_chip(smi);
  1503. }
  1504. #ifdef CONFIG_OF
  1505. static const struct of_device_id rtl8367_match[] = {
  1506. { .compatible = "realtek,rtl8367" },
  1507. {},
  1508. };
  1509. MODULE_DEVICE_TABLE(of, rtl8367_match);
  1510. #endif
  1511. static struct platform_driver rtl8367_driver = {
  1512. .driver = {
  1513. .name = RTL8367_DRIVER_NAME,
  1514. .owner = THIS_MODULE,
  1515. #ifdef CONFIG_OF
  1516. .of_match_table = of_match_ptr(rtl8367_match),
  1517. #endif
  1518. },
  1519. .probe = rtl8367_probe,
  1520. .remove = rtl8367_remove,
  1521. .shutdown = rtl8367_shutdown,
  1522. };
  1523. static int __init rtl8367_module_init(void)
  1524. {
  1525. return platform_driver_register(&rtl8367_driver);
  1526. }
  1527. module_init(rtl8367_module_init);
  1528. static void __exit rtl8367_module_exit(void)
  1529. {
  1530. platform_driver_unregister(&rtl8367_driver);
  1531. }
  1532. module_exit(rtl8367_module_exit);
  1533. MODULE_DESCRIPTION("Realtek RTL8367 ethernet switch driver");
  1534. MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  1535. MODULE_LICENSE("GPL v2");
  1536. MODULE_ALIAS("platform:" RTL8367_DRIVER_NAME);