rtl8367b.c 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602
  1. /*
  2. * Platform driver for the Realtek RTL8367R-VB ethernet switches
  3. *
  4. * Copyright (C) 2012 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 RTL8367B_RESET_DELAY 1000 /* msecs*/
  21. #define RTL8367B_PHY_ADDR_MAX 8
  22. #define RTL8367B_PHY_REG_MAX 31
  23. #define RTL8367B_VID_MASK 0x3fff
  24. #define RTL8367B_FID_MASK 0xf
  25. #define RTL8367B_UNTAG_MASK 0xff
  26. #define RTL8367B_MEMBER_MASK 0xff
  27. #define RTL8367B_PORT_MISC_CFG_REG(_p) (0x000e + 0x20 * (_p))
  28. #define RTL8367B_PORT_MISC_CFG_EGRESS_MODE_SHIFT 4
  29. #define RTL8367B_PORT_MISC_CFG_EGRESS_MODE_MASK 0x3
  30. #define RTL8367B_PORT_MISC_CFG_EGRESS_MODE_ORIGINAL 0
  31. #define RTL8367B_PORT_MISC_CFG_EGRESS_MODE_KEEP 1
  32. #define RTL8367B_PORT_MISC_CFG_EGRESS_MODE_PRI 2
  33. #define RTL8367B_PORT_MISC_CFG_EGRESS_MODE_REAL 3
  34. #define RTL8367B_BYPASS_LINE_RATE_REG 0x03f7
  35. #define RTL8367B_TA_CTRL_REG 0x0500 /*GOOD*/
  36. #define RTL8367B_TA_CTRL_SPA_SHIFT 8
  37. #define RTL8367B_TA_CTRL_SPA_MASK 0x7
  38. #define RTL8367B_TA_CTRL_METHOD BIT(4)/*GOOD*/
  39. #define RTL8367B_TA_CTRL_CMD_SHIFT 3
  40. #define RTL8367B_TA_CTRL_CMD_READ 0
  41. #define RTL8367B_TA_CTRL_CMD_WRITE 1
  42. #define RTL8367B_TA_CTRL_TABLE_SHIFT 0 /*GOOD*/
  43. #define RTL8367B_TA_CTRL_TABLE_ACLRULE 1
  44. #define RTL8367B_TA_CTRL_TABLE_ACLACT 2
  45. #define RTL8367B_TA_CTRL_TABLE_CVLAN 3
  46. #define RTL8367B_TA_CTRL_TABLE_L2 4
  47. #define RTL8367B_TA_CTRL_CVLAN_READ \
  48. ((RTL8367B_TA_CTRL_CMD_READ << RTL8367B_TA_CTRL_CMD_SHIFT) | \
  49. RTL8367B_TA_CTRL_TABLE_CVLAN)
  50. #define RTL8367B_TA_CTRL_CVLAN_WRITE \
  51. ((RTL8367B_TA_CTRL_CMD_WRITE << RTL8367B_TA_CTRL_CMD_SHIFT) | \
  52. RTL8367B_TA_CTRL_TABLE_CVLAN)
  53. #define RTL8367B_TA_ADDR_REG 0x0501/*GOOD*/
  54. #define RTL8367B_TA_ADDR_MASK 0x3fff/*GOOD*/
  55. #define RTL8367B_TA_LUT_REG 0x0502/*GOOD*/
  56. #define RTL8367B_TA_WRDATA_REG(_x) (0x0510 + (_x))/*GOOD*/
  57. #define RTL8367B_TA_VLAN_NUM_WORDS 2
  58. #define RTL8367B_TA_VLAN_VID_MASK RTL8367B_VID_MASK
  59. #define RTL8367B_TA_VLAN0_MEMBER_SHIFT 0
  60. #define RTL8367B_TA_VLAN0_MEMBER_MASK RTL8367B_MEMBER_MASK
  61. #define RTL8367B_TA_VLAN0_UNTAG_SHIFT 8
  62. #define RTL8367B_TA_VLAN0_UNTAG_MASK RTL8367B_MEMBER_MASK
  63. #define RTL8367B_TA_VLAN1_FID_SHIFT 0
  64. #define RTL8367B_TA_VLAN1_FID_MASK RTL8367B_FID_MASK
  65. #define RTL8367B_TA_RDDATA_REG(_x) (0x0520 + (_x))/*GOOD*/
  66. #define RTL8367B_VLAN_PVID_CTRL_REG(_p) (0x0700 + (_p) / 2) /*GOOD*/
  67. #define RTL8367B_VLAN_PVID_CTRL_MASK 0x1f /*GOOD*/
  68. #define RTL8367B_VLAN_PVID_CTRL_SHIFT(_p) (8 * ((_p) % 2)) /*GOOD*/
  69. #define RTL8367B_VLAN_MC_BASE(_x) (0x0728 + (_x) * 4) /*GOOD*/
  70. #define RTL8367B_VLAN_MC_NUM_WORDS 4 /*GOOD*/
  71. #define RTL8367B_VLAN_MC0_MEMBER_SHIFT 0/*GOOD*/
  72. #define RTL8367B_VLAN_MC0_MEMBER_MASK RTL8367B_MEMBER_MASK/*GOOD*/
  73. #define RTL8367B_VLAN_MC1_FID_SHIFT 0/*GOOD*/
  74. #define RTL8367B_VLAN_MC1_FID_MASK RTL8367B_FID_MASK/*GOOD*/
  75. #define RTL8367B_VLAN_MC3_EVID_SHIFT 0/*GOOD*/
  76. #define RTL8367B_VLAN_MC3_EVID_MASK RTL8367B_VID_MASK/*GOOD*/
  77. #define RTL8367B_VLAN_CTRL_REG 0x07a8 /*GOOD*/
  78. #define RTL8367B_VLAN_CTRL_ENABLE BIT(0)
  79. #define RTL8367B_VLAN_INGRESS_REG 0x07a9 /*GOOD*/
  80. #define RTL8367B_PORT_ISOLATION_REG(_p) (0x08a2 + (_p)) /*GOOD*/
  81. #define RTL8367B_MIB_COUNTER_REG(_x) (0x1000 + (_x)) /*GOOD*/
  82. #define RTL8367B_MIB_COUNTER_PORT_OFFSET 0x007c /*GOOD*/
  83. #define RTL8367B_MIB_ADDRESS_REG 0x1004 /*GOOD*/
  84. #define RTL8367B_MIB_CTRL0_REG(_x) (0x1005 + (_x)) /*GOOD*/
  85. #define RTL8367B_MIB_CTRL0_GLOBAL_RESET_MASK BIT(11) /*GOOD*/
  86. #define RTL8367B_MIB_CTRL0_QM_RESET_MASK BIT(10) /*GOOD*/
  87. #define RTL8367B_MIB_CTRL0_PORT_RESET_MASK(_p) BIT(2 + (_p)) /*GOOD*/
  88. #define RTL8367B_MIB_CTRL0_RESET_MASK BIT(1) /*GOOD*/
  89. #define RTL8367B_MIB_CTRL0_BUSY_MASK BIT(0) /*GOOD*/
  90. #define RTL8367B_SWC0_REG 0x1200/*GOOD*/
  91. #define RTL8367B_SWC0_MAX_LENGTH_SHIFT 13/*GOOD*/
  92. #define RTL8367B_SWC0_MAX_LENGTH(_x) ((_x) << 13) /*GOOD*/
  93. #define RTL8367B_SWC0_MAX_LENGTH_MASK RTL8367B_SWC0_MAX_LENGTH(0x3)
  94. #define RTL8367B_SWC0_MAX_LENGTH_1522 RTL8367B_SWC0_MAX_LENGTH(0)
  95. #define RTL8367B_SWC0_MAX_LENGTH_1536 RTL8367B_SWC0_MAX_LENGTH(1)
  96. #define RTL8367B_SWC0_MAX_LENGTH_1552 RTL8367B_SWC0_MAX_LENGTH(2)
  97. #define RTL8367B_SWC0_MAX_LENGTH_16000 RTL8367B_SWC0_MAX_LENGTH(3)
  98. #define RTL8367B_CHIP_NUMBER_REG 0x1300/*GOOD*/
  99. #define RTL8367B_CHIP_VER_REG 0x1301/*GOOD*/
  100. #define RTL8367B_CHIP_VER_RLVID_SHIFT 12/*GOOD*/
  101. #define RTL8367B_CHIP_VER_RLVID_MASK 0xf/*GOOD*/
  102. #define RTL8367B_CHIP_VER_MCID_SHIFT 8/*GOOD*/
  103. #define RTL8367B_CHIP_VER_MCID_MASK 0xf/*GOOD*/
  104. #define RTL8367B_CHIP_VER_BOID_SHIFT 4/*GOOD*/
  105. #define RTL8367B_CHIP_VER_BOID_MASK 0xf/*GOOD*/
  106. #define RTL8367B_CHIP_VER_AFE_SHIFT 0/*GOOD*/
  107. #define RTL8367B_CHIP_VER_AFE_MASK 0x1/*GOOD*/
  108. #define RTL8367B_CHIP_MODE_REG 0x1302
  109. #define RTL8367B_CHIP_MODE_MASK 0x7
  110. #define RTL8367B_CHIP_DEBUG0_REG 0x1303
  111. #define RTL8367B_CHIP_DEBUG0_DUMMY0(_x) BIT(8 + (_x))
  112. #define RTL8367B_CHIP_DEBUG1_REG 0x1304
  113. #define RTL8367B_DIS_REG 0x1305
  114. #define RTL8367B_DIS_SKIP_MII_RXER(_x) BIT(12 + (_x))
  115. #define RTL8367B_DIS_RGMII_SHIFT(_x) (4 * (_x))
  116. #define RTL8367B_DIS_RGMII_MASK 0x7
  117. #define RTL8367B_EXT_RGMXF_REG(_x) (0x1306 + (_x))
  118. #define RTL8367B_EXT_RGMXF_DUMMY0_SHIFT 5
  119. #define RTL8367B_EXT_RGMXF_DUMMY0_MASK 0x7ff
  120. #define RTL8367B_EXT_RGMXF_TXDELAY_SHIFT 3
  121. #define RTL8367B_EXT_RGMXF_TXDELAY_MASK 1
  122. #define RTL8367B_EXT_RGMXF_RXDELAY_MASK 0x7
  123. #define RTL8367B_DI_FORCE_REG(_x) (0x1310 + (_x))
  124. #define RTL8367B_DI_FORCE_MODE BIT(12)
  125. #define RTL8367B_DI_FORCE_NWAY BIT(7)
  126. #define RTL8367B_DI_FORCE_TXPAUSE BIT(6)
  127. #define RTL8367B_DI_FORCE_RXPAUSE BIT(5)
  128. #define RTL8367B_DI_FORCE_LINK BIT(4)
  129. #define RTL8367B_DI_FORCE_DUPLEX BIT(2)
  130. #define RTL8367B_DI_FORCE_SPEED_MASK 3
  131. #define RTL8367B_DI_FORCE_SPEED_10 0
  132. #define RTL8367B_DI_FORCE_SPEED_100 1
  133. #define RTL8367B_DI_FORCE_SPEED_1000 2
  134. #define RTL8367B_MAC_FORCE_REG(_x) (0x1312 + (_x))
  135. #define RTL8367B_CHIP_RESET_REG 0x1322 /*GOOD*/
  136. #define RTL8367B_CHIP_RESET_SW BIT(1) /*GOOD*/
  137. #define RTL8367B_CHIP_RESET_HW BIT(0) /*GOOD*/
  138. #define RTL8367B_PORT_STATUS_REG(_p) (0x1352 + (_p)) /*GOOD*/
  139. #define RTL8367B_PORT_STATUS_EN_1000_SPI BIT(11) /*GOOD*/
  140. #define RTL8367B_PORT_STATUS_EN_100_SPI BIT(10)/*GOOD*/
  141. #define RTL8367B_PORT_STATUS_NWAY_FAULT BIT(9)/*GOOD*/
  142. #define RTL8367B_PORT_STATUS_LINK_MASTER BIT(8)/*GOOD*/
  143. #define RTL8367B_PORT_STATUS_NWAY BIT(7)/*GOOD*/
  144. #define RTL8367B_PORT_STATUS_TXPAUSE BIT(6)/*GOOD*/
  145. #define RTL8367B_PORT_STATUS_RXPAUSE BIT(5)/*GOOD*/
  146. #define RTL8367B_PORT_STATUS_LINK BIT(4)/*GOOD*/
  147. #define RTL8367B_PORT_STATUS_DUPLEX BIT(2)/*GOOD*/
  148. #define RTL8367B_PORT_STATUS_SPEED_MASK 0x0003/*GOOD*/
  149. #define RTL8367B_PORT_STATUS_SPEED_10 0/*GOOD*/
  150. #define RTL8367B_PORT_STATUS_SPEED_100 1/*GOOD*/
  151. #define RTL8367B_PORT_STATUS_SPEED_1000 2/*GOOD*/
  152. #define RTL8367B_RTL_MAGIC_ID_REG 0x13c2
  153. #define RTL8367B_RTL_MAGIC_ID_VAL 0x0249
  154. #define RTL8367B_IA_CTRL_REG 0x1f00
  155. #define RTL8367B_IA_CTRL_RW(_x) ((_x) << 1)
  156. #define RTL8367B_IA_CTRL_RW_READ RTL8367B_IA_CTRL_RW(0)
  157. #define RTL8367B_IA_CTRL_RW_WRITE RTL8367B_IA_CTRL_RW(1)
  158. #define RTL8367B_IA_CTRL_CMD_MASK BIT(0)
  159. #define RTL8367B_IA_STATUS_REG 0x1f01
  160. #define RTL8367B_IA_STATUS_PHY_BUSY BIT(2)
  161. #define RTL8367B_IA_STATUS_SDS_BUSY BIT(1)
  162. #define RTL8367B_IA_STATUS_MDX_BUSY BIT(0)
  163. #define RTL8367B_IA_ADDRESS_REG 0x1f02
  164. #define RTL8367B_IA_WRITE_DATA_REG 0x1f03
  165. #define RTL8367B_IA_READ_DATA_REG 0x1f04
  166. #define RTL8367B_INTERNAL_PHY_REG(_a, _r) (0x2000 + 32 * (_a) + (_r))
  167. #define RTL8367B_NUM_MIB_COUNTERS 58
  168. #define RTL8367B_CPU_PORT_NUM 5
  169. #define RTL8367B_NUM_PORTS 8
  170. #define RTL8367B_NUM_VLANS 32
  171. #define RTL8367B_NUM_VIDS 4096
  172. #define RTL8367B_PRIORITYMAX 7
  173. #define RTL8367B_FIDMAX 7
  174. #define RTL8367B_PORT_0 BIT(0)
  175. #define RTL8367B_PORT_1 BIT(1)
  176. #define RTL8367B_PORT_2 BIT(2)
  177. #define RTL8367B_PORT_3 BIT(3)
  178. #define RTL8367B_PORT_4 BIT(4)
  179. #define RTL8367B_PORT_E0 BIT(5) /* External port 0 */
  180. #define RTL8367B_PORT_E1 BIT(6) /* External port 1 */
  181. #define RTL8367B_PORT_E2 BIT(7) /* External port 2 */
  182. #define RTL8367B_PORTS_ALL \
  183. (RTL8367B_PORT_0 | RTL8367B_PORT_1 | RTL8367B_PORT_2 | \
  184. RTL8367B_PORT_3 | RTL8367B_PORT_4 | RTL8367B_PORT_E0 | \
  185. RTL8367B_PORT_E1 | RTL8367B_PORT_E2)
  186. #define RTL8367B_PORTS_ALL_BUT_CPU \
  187. (RTL8367B_PORT_0 | RTL8367B_PORT_1 | RTL8367B_PORT_2 | \
  188. RTL8367B_PORT_3 | RTL8367B_PORT_4 | RTL8367B_PORT_E1 | \
  189. RTL8367B_PORT_E2)
  190. struct rtl8367b_initval {
  191. u16 reg;
  192. u16 val;
  193. };
  194. static struct rtl8366_mib_counter
  195. rtl8367b_mib_counters[RTL8367B_NUM_MIB_COUNTERS] = {
  196. {0, 0, 4, "ifInOctets" },
  197. {0, 4, 2, "dot3StatsFCSErrors" },
  198. {0, 6, 2, "dot3StatsSymbolErrors" },
  199. {0, 8, 2, "dot3InPauseFrames" },
  200. {0, 10, 2, "dot3ControlInUnknownOpcodes" },
  201. {0, 12, 2, "etherStatsFragments" },
  202. {0, 14, 2, "etherStatsJabbers" },
  203. {0, 16, 2, "ifInUcastPkts" },
  204. {0, 18, 2, "etherStatsDropEvents" },
  205. {0, 20, 2, "ifInMulticastPkts" },
  206. {0, 22, 2, "ifInBroadcastPkts" },
  207. {0, 24, 2, "inMldChecksumError" },
  208. {0, 26, 2, "inIgmpChecksumError" },
  209. {0, 28, 2, "inMldSpecificQuery" },
  210. {0, 30, 2, "inMldGeneralQuery" },
  211. {0, 32, 2, "inIgmpSpecificQuery" },
  212. {0, 34, 2, "inIgmpGeneralQuery" },
  213. {0, 36, 2, "inMldLeaves" },
  214. {0, 38, 2, "inIgmpLeaves" },
  215. {0, 40, 4, "etherStatsOctets" },
  216. {0, 44, 2, "etherStatsUnderSizePkts" },
  217. {0, 46, 2, "etherOversizeStats" },
  218. {0, 48, 2, "etherStatsPkts64Octets" },
  219. {0, 50, 2, "etherStatsPkts65to127Octets" },
  220. {0, 52, 2, "etherStatsPkts128to255Octets" },
  221. {0, 54, 2, "etherStatsPkts256to511Octets" },
  222. {0, 56, 2, "etherStatsPkts512to1023Octets" },
  223. {0, 58, 2, "etherStatsPkts1024to1518Octets" },
  224. {0, 60, 4, "ifOutOctets" },
  225. {0, 64, 2, "dot3StatsSingleCollisionFrames" },
  226. {0, 66, 2, "dot3StatMultipleCollisionFrames" },
  227. {0, 68, 2, "dot3sDeferredTransmissions" },
  228. {0, 70, 2, "dot3StatsLateCollisions" },
  229. {0, 72, 2, "etherStatsCollisions" },
  230. {0, 74, 2, "dot3StatsExcessiveCollisions" },
  231. {0, 76, 2, "dot3OutPauseFrames" },
  232. {0, 78, 2, "ifOutDiscards" },
  233. {0, 80, 2, "dot1dTpPortInDiscards" },
  234. {0, 82, 2, "ifOutUcastPkts" },
  235. {0, 84, 2, "ifOutMulticastPkts" },
  236. {0, 86, 2, "ifOutBroadcastPkts" },
  237. {0, 88, 2, "outOampduPkts" },
  238. {0, 90, 2, "inOampduPkts" },
  239. {0, 92, 2, "inIgmpJoinsSuccess" },
  240. {0, 94, 2, "inIgmpJoinsFail" },
  241. {0, 96, 2, "inMldJoinsSuccess" },
  242. {0, 98, 2, "inMldJoinsFail" },
  243. {0, 100, 2, "inReportSuppressionDrop" },
  244. {0, 102, 2, "inLeaveSuppressionDrop" },
  245. {0, 104, 2, "outIgmpReports" },
  246. {0, 106, 2, "outIgmpLeaves" },
  247. {0, 108, 2, "outIgmpGeneralQuery" },
  248. {0, 110, 2, "outIgmpSpecificQuery" },
  249. {0, 112, 2, "outMldReports" },
  250. {0, 114, 2, "outMldLeaves" },
  251. {0, 116, 2, "outMldGeneralQuery" },
  252. {0, 118, 2, "outMldSpecificQuery" },
  253. {0, 120, 2, "inKnownMulticastPkts" },
  254. };
  255. #define REG_RD(_smi, _reg, _val) \
  256. do { \
  257. err = rtl8366_smi_read_reg(_smi, _reg, _val); \
  258. if (err) \
  259. return err; \
  260. } while (0)
  261. #define REG_WR(_smi, _reg, _val) \
  262. do { \
  263. err = rtl8366_smi_write_reg(_smi, _reg, _val); \
  264. if (err) \
  265. return err; \
  266. } while (0)
  267. #define REG_RMW(_smi, _reg, _mask, _val) \
  268. do { \
  269. err = rtl8366_smi_rmwr(_smi, _reg, _mask, _val); \
  270. if (err) \
  271. return err; \
  272. } while (0)
  273. static const struct rtl8367b_initval rtl8367r_vb_initvals_0[] = {
  274. {0x1B03, 0x0876}, {0x1200, 0x7FC4}, {0x0301, 0x0026}, {0x1722, 0x0E14},
  275. {0x205F, 0x0002}, {0x2059, 0x1A00}, {0x205F, 0x0000}, {0x207F, 0x0002},
  276. {0x2077, 0x0000}, {0x2078, 0x0000}, {0x2079, 0x0000}, {0x207A, 0x0000},
  277. {0x207B, 0x0000}, {0x207F, 0x0000}, {0x205F, 0x0002}, {0x2053, 0x0000},
  278. {0x2054, 0x0000}, {0x2055, 0x0000}, {0x2056, 0x0000}, {0x2057, 0x0000},
  279. {0x205F, 0x0000}, {0x12A4, 0x110A}, {0x12A6, 0x150A}, {0x13F1, 0x0013},
  280. {0x13F4, 0x0010}, {0x13F5, 0x0000}, {0x0018, 0x0F00}, {0x0038, 0x0F00},
  281. {0x0058, 0x0F00}, {0x0078, 0x0F00}, {0x0098, 0x0F00}, {0x12B6, 0x0C02},
  282. {0x12B7, 0x030F}, {0x12B8, 0x11FF}, {0x12BC, 0x0004}, {0x1362, 0x0115},
  283. {0x1363, 0x0002}, {0x1363, 0x0000}, {0x133F, 0x0030}, {0x133E, 0x000E},
  284. {0x221F, 0x0007}, {0x221E, 0x002D}, {0x2218, 0xF030}, {0x221F, 0x0007},
  285. {0x221E, 0x0023}, {0x2216, 0x0005}, {0x2215, 0x00B9}, {0x2219, 0x0044},
  286. {0x2215, 0x00BA}, {0x2219, 0x0020}, {0x2215, 0x00BB}, {0x2219, 0x00C1},
  287. {0x2215, 0x0148}, {0x2219, 0x0096}, {0x2215, 0x016E}, {0x2219, 0x0026},
  288. {0x2216, 0x0000}, {0x2216, 0x0000}, {0x221E, 0x002D}, {0x2218, 0xF010},
  289. {0x221F, 0x0007}, {0x221E, 0x0020}, {0x2215, 0x0D00}, {0x221F, 0x0000},
  290. {0x221F, 0x0000}, {0x2217, 0x2160}, {0x221F, 0x0001}, {0x2210, 0xF25E},
  291. {0x221F, 0x0007}, {0x221E, 0x0042}, {0x2215, 0x0F00}, {0x2215, 0x0F00},
  292. {0x2216, 0x7408}, {0x2215, 0x0E00}, {0x2215, 0x0F00}, {0x2215, 0x0F01},
  293. {0x2216, 0x4000}, {0x2215, 0x0E01}, {0x2215, 0x0F01}, {0x2215, 0x0F02},
  294. {0x2216, 0x9400}, {0x2215, 0x0E02}, {0x2215, 0x0F02}, {0x2215, 0x0F03},
  295. {0x2216, 0x7408}, {0x2215, 0x0E03}, {0x2215, 0x0F03}, {0x2215, 0x0F04},
  296. {0x2216, 0x4008}, {0x2215, 0x0E04}, {0x2215, 0x0F04}, {0x2215, 0x0F05},
  297. {0x2216, 0x9400}, {0x2215, 0x0E05}, {0x2215, 0x0F05}, {0x2215, 0x0F06},
  298. {0x2216, 0x0803}, {0x2215, 0x0E06}, {0x2215, 0x0F06}, {0x2215, 0x0D00},
  299. {0x2215, 0x0100}, {0x221F, 0x0001}, {0x2210, 0xF05E}, {0x221F, 0x0000},
  300. {0x2217, 0x2100}, {0x221F, 0x0000}, {0x220D, 0x0003}, {0x220E, 0x0015},
  301. {0x220D, 0x4003}, {0x220E, 0x0006}, {0x221F, 0x0000}, {0x2200, 0x1340},
  302. {0x133F, 0x0010}, {0x12A0, 0x0058}, {0x12A1, 0x0058}, {0x133E, 0x000E},
  303. {0x133F, 0x0030}, {0x221F, 0x0000}, {0x2210, 0x0166}, {0x221F, 0x0000},
  304. {0x133E, 0x000E}, {0x133F, 0x0010}, {0x133F, 0x0030}, {0x133E, 0x000E},
  305. {0x221F, 0x0005}, {0x2205, 0xFFF6}, {0x2206, 0x0080}, {0x2205, 0x8B6E},
  306. {0x2206, 0x0000}, {0x220F, 0x0100}, {0x2205, 0x8000}, {0x2206, 0x0280},
  307. {0x2206, 0x28F7}, {0x2206, 0x00E0}, {0x2206, 0xFFF7}, {0x2206, 0xA080},
  308. {0x2206, 0x02AE}, {0x2206, 0xF602}, {0x2206, 0x0153}, {0x2206, 0x0201},
  309. {0x2206, 0x6602}, {0x2206, 0x80B9}, {0x2206, 0xE08B}, {0x2206, 0x8CE1},
  310. {0x2206, 0x8B8D}, {0x2206, 0x1E01}, {0x2206, 0xE18B}, {0x2206, 0x8E1E},
  311. {0x2206, 0x01A0}, {0x2206, 0x00E7}, {0x2206, 0xAEDB}, {0x2206, 0xEEE0},
  312. {0x2206, 0x120E}, {0x2206, 0xEEE0}, {0x2206, 0x1300}, {0x2206, 0xEEE0},
  313. {0x2206, 0x2001}, {0x2206, 0xEEE0}, {0x2206, 0x2166}, {0x2206, 0xEEE0},
  314. {0x2206, 0xC463}, {0x2206, 0xEEE0}, {0x2206, 0xC5E8}, {0x2206, 0xEEE0},
  315. {0x2206, 0xC699}, {0x2206, 0xEEE0}, {0x2206, 0xC7C2}, {0x2206, 0xEEE0},
  316. {0x2206, 0xC801}, {0x2206, 0xEEE0}, {0x2206, 0xC913}, {0x2206, 0xEEE0},
  317. {0x2206, 0xCA30}, {0x2206, 0xEEE0}, {0x2206, 0xCB3E}, {0x2206, 0xEEE0},
  318. {0x2206, 0xDCE1}, {0x2206, 0xEEE0}, {0x2206, 0xDD00}, {0x2206, 0xEEE2},
  319. {0x2206, 0x0001}, {0x2206, 0xEEE2}, {0x2206, 0x0100}, {0x2206, 0xEEE4},
  320. {0x2206, 0x8860}, {0x2206, 0xEEE4}, {0x2206, 0x8902}, {0x2206, 0xEEE4},
  321. {0x2206, 0x8C00}, {0x2206, 0xEEE4}, {0x2206, 0x8D30}, {0x2206, 0xEEEA},
  322. {0x2206, 0x1480}, {0x2206, 0xEEEA}, {0x2206, 0x1503}, {0x2206, 0xEEEA},
  323. {0x2206, 0xC600}, {0x2206, 0xEEEA}, {0x2206, 0xC706}, {0x2206, 0xEE85},
  324. {0x2206, 0xEE00}, {0x2206, 0xEE85}, {0x2206, 0xEF00}, {0x2206, 0xEE8B},
  325. {0x2206, 0x6750}, {0x2206, 0xEE8B}, {0x2206, 0x6632}, {0x2206, 0xEE8A},
  326. {0x2206, 0xD448}, {0x2206, 0xEE8A}, {0x2206, 0xD548}, {0x2206, 0xEE8A},
  327. {0x2206, 0xD649}, {0x2206, 0xEE8A}, {0x2206, 0xD7F8}, {0x2206, 0xEE8B},
  328. {0x2206, 0x85E2}, {0x2206, 0xEE8B}, {0x2206, 0x8700}, {0x2206, 0xEEFF},
  329. {0x2206, 0xF600}, {0x2206, 0xEEFF}, {0x2206, 0xF7FC}, {0x2206, 0x04F8},
  330. {0x2206, 0xE08B}, {0x2206, 0x8EAD}, {0x2206, 0x2023}, {0x2206, 0xF620},
  331. {0x2206, 0xE48B}, {0x2206, 0x8E02}, {0x2206, 0x2877}, {0x2206, 0x0225},
  332. {0x2206, 0xC702}, {0x2206, 0x26A1}, {0x2206, 0x0281}, {0x2206, 0xB302},
  333. {0x2206, 0x8496}, {0x2206, 0x0202}, {0x2206, 0xA102}, {0x2206, 0x27F1},
  334. {0x2206, 0x0228}, {0x2206, 0xF902}, {0x2206, 0x2AA0}, {0x2206, 0x0282},
  335. {0x2206, 0xB8E0}, {0x2206, 0x8B8E}, {0x2206, 0xAD21}, {0x2206, 0x08F6},
  336. {0x2206, 0x21E4}, {0x2206, 0x8B8E}, {0x2206, 0x0202}, {0x2206, 0x80E0},
  337. {0x2206, 0x8B8E}, {0x2206, 0xAD22}, {0x2206, 0x05F6}, {0x2206, 0x22E4},
  338. {0x2206, 0x8B8E}, {0x2206, 0xE08B}, {0x2206, 0x8EAD}, {0x2206, 0x2305},
  339. {0x2206, 0xF623}, {0x2206, 0xE48B}, {0x2206, 0x8EE0}, {0x2206, 0x8B8E},
  340. {0x2206, 0xAD24}, {0x2206, 0x08F6}, {0x2206, 0x24E4}, {0x2206, 0x8B8E},
  341. {0x2206, 0x0227}, {0x2206, 0x6AE0}, {0x2206, 0x8B8E}, {0x2206, 0xAD25},
  342. {0x2206, 0x05F6}, {0x2206, 0x25E4}, {0x2206, 0x8B8E}, {0x2206, 0xE08B},
  343. {0x2206, 0x8EAD}, {0x2206, 0x260B}, {0x2206, 0xF626}, {0x2206, 0xE48B},
  344. {0x2206, 0x8E02}, {0x2206, 0x830D}, {0x2206, 0x021D}, {0x2206, 0x6BE0},
  345. {0x2206, 0x8B8E}, {0x2206, 0xAD27}, {0x2206, 0x05F6}, {0x2206, 0x27E4},
  346. {0x2206, 0x8B8E}, {0x2206, 0x0281}, {0x2206, 0x4402}, {0x2206, 0x045C},
  347. {0x2206, 0xFC04}, {0x2206, 0xF8E0}, {0x2206, 0x8B83}, {0x2206, 0xAD23},
  348. {0x2206, 0x30E0}, {0x2206, 0xE022}, {0x2206, 0xE1E0}, {0x2206, 0x2359},
  349. {0x2206, 0x02E0}, {0x2206, 0x85EF}, {0x2206, 0xE585}, {0x2206, 0xEFAC},
  350. {0x2206, 0x2907}, {0x2206, 0x1F01}, {0x2206, 0x9E51}, {0x2206, 0xAD29},
  351. {0x2206, 0x20E0}, {0x2206, 0x8B83}, {0x2206, 0xAD21}, {0x2206, 0x06E1},
  352. {0x2206, 0x8B84}, {0x2206, 0xAD28}, {0x2206, 0x42E0}, {0x2206, 0x8B85},
  353. {0x2206, 0xAD21}, {0x2206, 0x06E1}, {0x2206, 0x8B84}, {0x2206, 0xAD29},
  354. {0x2206, 0x36BF}, {0x2206, 0x34BF}, {0x2206, 0x022C}, {0x2206, 0x31AE},
  355. {0x2206, 0x2EE0}, {0x2206, 0x8B83}, {0x2206, 0xAD21}, {0x2206, 0x10E0},
  356. {0x2206, 0x8B84}, {0x2206, 0xF620}, {0x2206, 0xE48B}, {0x2206, 0x84EE},
  357. {0x2206, 0x8ADA}, {0x2206, 0x00EE}, {0x2206, 0x8ADB}, {0x2206, 0x00E0},
  358. {0x2206, 0x8B85}, {0x2206, 0xAD21}, {0x2206, 0x0CE0}, {0x2206, 0x8B84},
  359. {0x2206, 0xF621}, {0x2206, 0xE48B}, {0x2206, 0x84EE}, {0x2206, 0x8B72},
  360. {0x2206, 0xFFBF}, {0x2206, 0x34C2}, {0x2206, 0x022C}, {0x2206, 0x31FC},
  361. {0x2206, 0x04F8}, {0x2206, 0xFAEF}, {0x2206, 0x69E0}, {0x2206, 0x8B85},
  362. {0x2206, 0xAD21}, {0x2206, 0x42E0}, {0x2206, 0xE022}, {0x2206, 0xE1E0},
  363. {0x2206, 0x2358}, {0x2206, 0xC059}, {0x2206, 0x021E}, {0x2206, 0x01E1},
  364. {0x2206, 0x8B72}, {0x2206, 0x1F10}, {0x2206, 0x9E2F}, {0x2206, 0xE48B},
  365. {0x2206, 0x72AD}, {0x2206, 0x2123}, {0x2206, 0xE18B}, {0x2206, 0x84F7},
  366. {0x2206, 0x29E5}, {0x2206, 0x8B84}, {0x2206, 0xAC27}, {0x2206, 0x10AC},
  367. {0x2206, 0x2605}, {0x2206, 0x0205}, {0x2206, 0x23AE}, {0x2206, 0x1602},
  368. {0x2206, 0x0535}, {0x2206, 0x0282}, {0x2206, 0x30AE}, {0x2206, 0x0E02},
  369. {0x2206, 0x056A}, {0x2206, 0x0282}, {0x2206, 0x75AE}, {0x2206, 0x0602},
  370. {0x2206, 0x04DC}, {0x2206, 0x0282}, {0x2206, 0x04EF}, {0x2206, 0x96FE},
  371. {0x2206, 0xFC04}, {0x2206, 0xF8F9}, {0x2206, 0xE08B}, {0x2206, 0x87AD},
  372. {0x2206, 0x2321}, {0x2206, 0xE0EA}, {0x2206, 0x14E1}, {0x2206, 0xEA15},
  373. {0x2206, 0xAD26}, {0x2206, 0x18F6}, {0x2206, 0x27E4}, {0x2206, 0xEA14},
  374. {0x2206, 0xE5EA}, {0x2206, 0x15F6}, {0x2206, 0x26E4}, {0x2206, 0xEA14},
  375. {0x2206, 0xE5EA}, {0x2206, 0x15F7}, {0x2206, 0x27E4}, {0x2206, 0xEA14},
  376. {0x2206, 0xE5EA}, {0x2206, 0x15FD}, {0x2206, 0xFC04}, {0x2206, 0xF8F9},
  377. {0x2206, 0xE08B}, {0x2206, 0x87AD}, {0x2206, 0x233A}, {0x2206, 0xAD22},
  378. {0x2206, 0x37E0}, {0x2206, 0xE020}, {0x2206, 0xE1E0}, {0x2206, 0x21AC},
  379. {0x2206, 0x212E}, {0x2206, 0xE0EA}, {0x2206, 0x14E1}, {0x2206, 0xEA15},
  380. {0x2206, 0xF627}, {0x2206, 0xE4EA}, {0x2206, 0x14E5}, {0x2206, 0xEA15},
  381. {0x2206, 0xE2EA}, {0x2206, 0x12E3}, {0x2206, 0xEA13}, {0x2206, 0x5A8F},
  382. {0x2206, 0x6A20}, {0x2206, 0xE6EA}, {0x2206, 0x12E7}, {0x2206, 0xEA13},
  383. {0x2206, 0xF726}, {0x2206, 0xE4EA}, {0x2206, 0x14E5}, {0x2206, 0xEA15},
  384. {0x2206, 0xF727}, {0x2206, 0xE4EA}, {0x2206, 0x14E5}, {0x2206, 0xEA15},
  385. {0x2206, 0xFDFC}, {0x2206, 0x04F8}, {0x2206, 0xF9E0}, {0x2206, 0x8B87},
  386. {0x2206, 0xAD23}, {0x2206, 0x38AD}, {0x2206, 0x2135}, {0x2206, 0xE0E0},
  387. {0x2206, 0x20E1}, {0x2206, 0xE021}, {0x2206, 0xAC21}, {0x2206, 0x2CE0},
  388. {0x2206, 0xEA14}, {0x2206, 0xE1EA}, {0x2206, 0x15F6}, {0x2206, 0x27E4},
  389. {0x2206, 0xEA14}, {0x2206, 0xE5EA}, {0x2206, 0x15E2}, {0x2206, 0xEA12},
  390. {0x2206, 0xE3EA}, {0x2206, 0x135A}, {0x2206, 0x8FE6}, {0x2206, 0xEA12},
  391. {0x2206, 0xE7EA}, {0x2206, 0x13F7}, {0x2206, 0x26E4}, {0x2206, 0xEA14},
  392. {0x2206, 0xE5EA}, {0x2206, 0x15F7}, {0x2206, 0x27E4}, {0x2206, 0xEA14},
  393. {0x2206, 0xE5EA}, {0x2206, 0x15FD}, {0x2206, 0xFC04}, {0x2206, 0xF8FA},
  394. {0x2206, 0xEF69}, {0x2206, 0xE08B}, {0x2206, 0x86AD}, {0x2206, 0x2146},
  395. {0x2206, 0xE0E0}, {0x2206, 0x22E1}, {0x2206, 0xE023}, {0x2206, 0x58C0},
  396. {0x2206, 0x5902}, {0x2206, 0x1E01}, {0x2206, 0xE18B}, {0x2206, 0x651F},
  397. {0x2206, 0x109E}, {0x2206, 0x33E4}, {0x2206, 0x8B65}, {0x2206, 0xAD21},
  398. {0x2206, 0x22AD}, {0x2206, 0x272A}, {0x2206, 0xD400}, {0x2206, 0x01BF},
  399. {0x2206, 0x34F2}, {0x2206, 0x022C}, {0x2206, 0xA2BF}, {0x2206, 0x34F5},
  400. {0x2206, 0x022C}, {0x2206, 0xE0E0}, {0x2206, 0x8B67}, {0x2206, 0x1B10},
  401. {0x2206, 0xAA14}, {0x2206, 0xE18B}, {0x2206, 0x660D}, {0x2206, 0x1459},
  402. {0x2206, 0x0FAE}, {0x2206, 0x05E1}, {0x2206, 0x8B66}, {0x2206, 0x590F},
  403. {0x2206, 0xBF85}, {0x2206, 0x6102}, {0x2206, 0x2CA2}, {0x2206, 0xEF96},
  404. {0x2206, 0xFEFC}, {0x2206, 0x04F8}, {0x2206, 0xF9FA}, {0x2206, 0xFBEF},
  405. {0x2206, 0x79E2}, {0x2206, 0x8AD2}, {0x2206, 0xAC19}, {0x2206, 0x2DE0},
  406. {0x2206, 0xE036}, {0x2206, 0xE1E0}, {0x2206, 0x37EF}, {0x2206, 0x311F},
  407. {0x2206, 0x325B}, {0x2206, 0x019E}, {0x2206, 0x1F7A}, {0x2206, 0x0159},
  408. {0x2206, 0x019F}, {0x2206, 0x0ABF}, {0x2206, 0x348E}, {0x2206, 0x022C},
  409. {0x2206, 0x31F6}, {0x2206, 0x06AE}, {0x2206, 0x0FF6}, {0x2206, 0x0302},
  410. {0x2206, 0x0470}, {0x2206, 0xF703}, {0x2206, 0xF706}, {0x2206, 0xBF34},
  411. {0x2206, 0x9302}, {0x2206, 0x2C31}, {0x2206, 0xAC1A}, {0x2206, 0x25E0},
  412. {0x2206, 0xE022}, {0x2206, 0xE1E0}, {0x2206, 0x23EF}, {0x2206, 0x300D},
  413. {0x2206, 0x311F}, {0x2206, 0x325B}, {0x2206, 0x029E}, {0x2206, 0x157A},
  414. {0x2206, 0x0258}, {0x2206, 0xC4A0}, {0x2206, 0x0408}, {0x2206, 0xBF34},
  415. {0x2206, 0x9E02}, {0x2206, 0x2C31}, {0x2206, 0xAE06}, {0x2206, 0xBF34},
  416. {0x2206, 0x9C02}, {0x2206, 0x2C31}, {0x2206, 0xAC1B}, {0x2206, 0x4AE0},
  417. {0x2206, 0xE012}, {0x2206, 0xE1E0}, {0x2206, 0x13EF}, {0x2206, 0x300D},
  418. {0x2206, 0x331F}, {0x2206, 0x325B}, {0x2206, 0x1C9E}, {0x2206, 0x3AEF},
  419. {0x2206, 0x325B}, {0x2206, 0x1C9F}, {0x2206, 0x09BF}, {0x2206, 0x3498},
  420. {0x2206, 0x022C}, {0x2206, 0x3102}, {0x2206, 0x83C5}, {0x2206, 0x5A03},
  421. {0x2206, 0x0D03}, {0x2206, 0x581C}, {0x2206, 0x1E20}, {0x2206, 0x0207},
  422. {0x2206, 0xA0A0}, {0x2206, 0x000E}, {0x2206, 0x0284}, {0x2206, 0x17AD},
  423. {0x2206, 0x1817}, {0x2206, 0xBF34}, {0x2206, 0x9A02}, {0x2206, 0x2C31},
  424. {0x2206, 0xAE0F}, {0x2206, 0xBF34}, {0x2206, 0xC802}, {0x2206, 0x2C31},
  425. {0x2206, 0xBF34}, {0x2206, 0xC502}, {0x2206, 0x2C31}, {0x2206, 0x0284},
  426. {0x2206, 0x52E6}, {0x2206, 0x8AD2}, {0x2206, 0xEF97}, {0x2206, 0xFFFE},
  427. {0x2206, 0xFDFC}, {0x2206, 0x04F8}, {0x2206, 0xBF34}, {0x2206, 0xDA02},
  428. {0x2206, 0x2CE0}, {0x2206, 0xE58A}, {0x2206, 0xD3BF}, {0x2206, 0x34D4},
  429. {0x2206, 0x022C}, {0x2206, 0xE00C}, {0x2206, 0x1159}, {0x2206, 0x02E0},
  430. {0x2206, 0x8AD3}, {0x2206, 0x1E01}, {0x2206, 0xE48A}, {0x2206, 0xD3D1},
  431. {0x2206, 0x00BF}, {0x2206, 0x34DA}, {0x2206, 0x022C}, {0x2206, 0xA2D1},
  432. {0x2206, 0x01BF}, {0x2206, 0x34D4}, {0x2206, 0x022C}, {0x2206, 0xA2BF},
  433. {0x2206, 0x34CB}, {0x2206, 0x022C}, {0x2206, 0xE0E5}, {0x2206, 0x8ACE},
  434. {0x2206, 0xBF85}, {0x2206, 0x6702}, {0x2206, 0x2CE0}, {0x2206, 0xE58A},
  435. {0x2206, 0xCFBF}, {0x2206, 0x8564}, {0x2206, 0x022C}, {0x2206, 0xE0E5},
  436. {0x2206, 0x8AD0}, {0x2206, 0xBF85}, {0x2206, 0x6A02}, {0x2206, 0x2CE0},
  437. {0x2206, 0xE58A}, {0x2206, 0xD1FC}, {0x2206, 0x04F8}, {0x2206, 0xE18A},
  438. {0x2206, 0xD1BF}, {0x2206, 0x856A}, {0x2206, 0x022C}, {0x2206, 0xA2E1},
  439. {0x2206, 0x8AD0}, {0x2206, 0xBF85}, {0x2206, 0x6402}, {0x2206, 0x2CA2},
  440. {0x2206, 0xE18A}, {0x2206, 0xCFBF}, {0x2206, 0x8567}, {0x2206, 0x022C},
  441. {0x2206, 0xA2E1}, {0x2206, 0x8ACE}, {0x2206, 0xBF34}, {0x2206, 0xCB02},
  442. {0x2206, 0x2CA2}, {0x2206, 0xE18A}, {0x2206, 0xD3BF}, {0x2206, 0x34DA},
  443. {0x2206, 0x022C}, {0x2206, 0xA2E1}, {0x2206, 0x8AD3}, {0x2206, 0x0D11},
  444. {0x2206, 0xBF34}, {0x2206, 0xD402}, {0x2206, 0x2CA2}, {0x2206, 0xFC04},
  445. {0x2206, 0xF9A0}, {0x2206, 0x0405}, {0x2206, 0xE38A}, {0x2206, 0xD4AE},
  446. {0x2206, 0x13A0}, {0x2206, 0x0805}, {0x2206, 0xE38A}, {0x2206, 0xD5AE},
  447. {0x2206, 0x0BA0}, {0x2206, 0x0C05}, {0x2206, 0xE38A}, {0x2206, 0xD6AE},
  448. {0x2206, 0x03E3}, {0x2206, 0x8AD7}, {0x2206, 0xEF13}, {0x2206, 0xBF34},
  449. {0x2206, 0xCB02}, {0x2206, 0x2CA2}, {0x2206, 0xEF13}, {0x2206, 0x0D11},
  450. {0x2206, 0xBF85}, {0x2206, 0x6702}, {0x2206, 0x2CA2}, {0x2206, 0xEF13},
  451. {0x2206, 0x0D14}, {0x2206, 0xBF85}, {0x2206, 0x6402}, {0x2206, 0x2CA2},
  452. {0x2206, 0xEF13}, {0x2206, 0x0D17}, {0x2206, 0xBF85}, {0x2206, 0x6A02},
  453. {0x2206, 0x2CA2}, {0x2206, 0xFD04}, {0x2206, 0xF8E0}, {0x2206, 0x8B85},
  454. {0x2206, 0xAD27}, {0x2206, 0x2DE0}, {0x2206, 0xE036}, {0x2206, 0xE1E0},
  455. {0x2206, 0x37E1}, {0x2206, 0x8B73}, {0x2206, 0x1F10}, {0x2206, 0x9E20},
  456. {0x2206, 0xE48B}, {0x2206, 0x73AC}, {0x2206, 0x200B}, {0x2206, 0xAC21},
  457. {0x2206, 0x0DAC}, {0x2206, 0x250F}, {0x2206, 0xAC27}, {0x2206, 0x0EAE},
  458. {0x2206, 0x0F02}, {0x2206, 0x84CC}, {0x2206, 0xAE0A}, {0x2206, 0x0284},
  459. {0x2206, 0xD1AE}, {0x2206, 0x05AE}, {0x2206, 0x0302}, {0x2206, 0x84D8},
  460. {0x2206, 0xFC04}, {0x2206, 0xEE8B}, {0x2206, 0x6800}, {0x2206, 0x0402},
  461. {0x2206, 0x84E5}, {0x2206, 0x0285}, {0x2206, 0x2804}, {0x2206, 0x0285},
  462. {0x2206, 0x4904}, {0x2206, 0xEE8B}, {0x2206, 0x6800}, {0x2206, 0xEE8B},
  463. {0x2206, 0x6902}, {0x2206, 0x04F8}, {0x2206, 0xF9E0}, {0x2206, 0x8B85},
  464. {0x2206, 0xAD26}, {0x2206, 0x38D0}, {0x2206, 0x0B02}, {0x2206, 0x2B4D},
  465. {0x2206, 0x5882}, {0x2206, 0x7882}, {0x2206, 0x9F2D}, {0x2206, 0xE08B},
  466. {0x2206, 0x68E1}, {0x2206, 0x8B69}, {0x2206, 0x1F10}, {0x2206, 0x9EC8},
  467. {0x2206, 0x10E4}, {0x2206, 0x8B68}, {0x2206, 0xE0E0}, {0x2206, 0x00E1},
  468. {0x2206, 0xE001}, {0x2206, 0xF727}, {0x2206, 0xE4E0}, {0x2206, 0x00E5},
  469. {0x2206, 0xE001}, {0x2206, 0xE2E0}, {0x2206, 0x20E3}, {0x2206, 0xE021},
  470. {0x2206, 0xAD30}, {0x2206, 0xF7F6}, {0x2206, 0x27E4}, {0x2206, 0xE000},
  471. {0x2206, 0xE5E0}, {0x2206, 0x01FD}, {0x2206, 0xFC04}, {0x2206, 0xF8FA},
  472. {0x2206, 0xEF69}, {0x2206, 0xE08B}, {0x2206, 0x86AD}, {0x2206, 0x2212},
  473. {0x2206, 0xE0E0}, {0x2206, 0x14E1}, {0x2206, 0xE015}, {0x2206, 0xAD26},
  474. {0x2206, 0x9CE1}, {0x2206, 0x85E0}, {0x2206, 0xBF85}, {0x2206, 0x6D02},
  475. {0x2206, 0x2CA2}, {0x2206, 0xEF96}, {0x2206, 0xFEFC}, {0x2206, 0x04F8},
  476. {0x2206, 0xFAEF}, {0x2206, 0x69E0}, {0x2206, 0x8B86}, {0x2206, 0xAD22},
  477. {0x2206, 0x09E1}, {0x2206, 0x85E1}, {0x2206, 0xBF85}, {0x2206, 0x6D02},
  478. {0x2206, 0x2CA2}, {0x2206, 0xEF96}, {0x2206, 0xFEFC}, {0x2206, 0x0464},
  479. {0x2206, 0xE48C}, {0x2206, 0xFDE4}, {0x2206, 0x80CA}, {0x2206, 0xE480},
  480. {0x2206, 0x66E0}, {0x2206, 0x8E70}, {0x2206, 0xE076}, {0x2205, 0xE142},
  481. {0x2206, 0x0701}, {0x2205, 0xE140}, {0x2206, 0x0405}, {0x220F, 0x0000},
  482. {0x221F, 0x0000}, {0x2200, 0x1340}, {0x133E, 0x000E}, {0x133F, 0x0010},
  483. {0x13EB, 0x11BB}
  484. };
  485. static const struct rtl8367b_initval rtl8367r_vb_initvals_1[] = {
  486. {0x1B03, 0x0876}, {0x1200, 0x7FC4}, {0x1305, 0xC000}, {0x121E, 0x03CA},
  487. {0x1233, 0x0352}, {0x1234, 0x0064}, {0x1237, 0x0096}, {0x1238, 0x0078},
  488. {0x1239, 0x0084}, {0x123A, 0x0030}, {0x205F, 0x0002}, {0x2059, 0x1A00},
  489. {0x205F, 0x0000}, {0x207F, 0x0002}, {0x2077, 0x0000}, {0x2078, 0x0000},
  490. {0x2079, 0x0000}, {0x207A, 0x0000}, {0x207B, 0x0000}, {0x207F, 0x0000},
  491. {0x205F, 0x0002}, {0x2053, 0x0000}, {0x2054, 0x0000}, {0x2055, 0x0000},
  492. {0x2056, 0x0000}, {0x2057, 0x0000}, {0x205F, 0x0000}, {0x133F, 0x0030},
  493. {0x133E, 0x000E}, {0x221F, 0x0005}, {0x2205, 0x8B86}, {0x2206, 0x800E},
  494. {0x221F, 0x0000}, {0x133F, 0x0010}, {0x12A3, 0x2200}, {0x6107, 0xE58B},
  495. {0x6103, 0xA970}, {0x0018, 0x0F00}, {0x0038, 0x0F00}, {0x0058, 0x0F00},
  496. {0x0078, 0x0F00}, {0x0098, 0x0F00}, {0x133F, 0x0030}, {0x133E, 0x000E},
  497. {0x221F, 0x0005}, {0x2205, 0x8B6E}, {0x2206, 0x0000}, {0x220F, 0x0100},
  498. {0x2205, 0xFFF6}, {0x2206, 0x0080}, {0x2205, 0x8000}, {0x2206, 0x0280},
  499. {0x2206, 0x2BF7}, {0x2206, 0x00E0}, {0x2206, 0xFFF7}, {0x2206, 0xA080},
  500. {0x2206, 0x02AE}, {0x2206, 0xF602}, {0x2206, 0x0153}, {0x2206, 0x0201},
  501. {0x2206, 0x6602}, {0x2206, 0x8044}, {0x2206, 0x0201}, {0x2206, 0x7CE0},
  502. {0x2206, 0x8B8C}, {0x2206, 0xE18B}, {0x2206, 0x8D1E}, {0x2206, 0x01E1},
  503. {0x2206, 0x8B8E}, {0x2206, 0x1E01}, {0x2206, 0xA000}, {0x2206, 0xE4AE},
  504. {0x2206, 0xD8EE}, {0x2206, 0x85C0}, {0x2206, 0x00EE}, {0x2206, 0x85C1},
  505. {0x2206, 0x00EE}, {0x2206, 0x8AFC}, {0x2206, 0x07EE}, {0x2206, 0x8AFD},
  506. {0x2206, 0x73EE}, {0x2206, 0xFFF6}, {0x2206, 0x00EE}, {0x2206, 0xFFF7},
  507. {0x2206, 0xFC04}, {0x2206, 0xF8E0}, {0x2206, 0x8B8E}, {0x2206, 0xAD20},
  508. {0x2206, 0x0302}, {0x2206, 0x8050}, {0x2206, 0xFC04}, {0x2206, 0xF8F9},
  509. {0x2206, 0xE08B}, {0x2206, 0x85AD}, {0x2206, 0x2548}, {0x2206, 0xE08A},
  510. {0x2206, 0xE4E1}, {0x2206, 0x8AE5}, {0x2206, 0x7C00}, {0x2206, 0x009E},
  511. {0x2206, 0x35EE}, {0x2206, 0x8AE4}, {0x2206, 0x00EE}, {0x2206, 0x8AE5},
  512. {0x2206, 0x00E0}, {0x2206, 0x8AFC}, {0x2206, 0xE18A}, {0x2206, 0xFDE2},
  513. {0x2206, 0x85C0}, {0x2206, 0xE385}, {0x2206, 0xC102}, {0x2206, 0x2DAC},
  514. {0x2206, 0xAD20}, {0x2206, 0x12EE}, {0x2206, 0x8AE4}, {0x2206, 0x03EE},
  515. {0x2206, 0x8AE5}, {0x2206, 0xB7EE}, {0x2206, 0x85C0}, {0x2206, 0x00EE},
  516. {0x2206, 0x85C1}, {0x2206, 0x00AE}, {0x2206, 0x1115}, {0x2206, 0xE685},
  517. {0x2206, 0xC0E7}, {0x2206, 0x85C1}, {0x2206, 0xAE08}, {0x2206, 0xEE85},
  518. {0x2206, 0xC000}, {0x2206, 0xEE85}, {0x2206, 0xC100}, {0x2206, 0xFDFC},
  519. {0x2206, 0x0400}, {0x2205, 0xE142}, {0x2206, 0x0701}, {0x2205, 0xE140},
  520. {0x2206, 0x0405}, {0x220F, 0x0000}, {0x221F, 0x0000}, {0x133E, 0x000E},
  521. {0x133F, 0x0010}, {0x13EB, 0x11BB}, {0x207F, 0x0002}, {0x2073, 0x1D22},
  522. {0x207F, 0x0000}, {0x133F, 0x0030}, {0x133E, 0x000E}, {0x2200, 0x1340},
  523. {0x133E, 0x000E}, {0x133F, 0x0010},
  524. };
  525. static int rtl8367b_write_initvals(struct rtl8366_smi *smi,
  526. const struct rtl8367b_initval *initvals,
  527. int count)
  528. {
  529. int err;
  530. int i;
  531. for (i = 0; i < count; i++)
  532. REG_WR(smi, initvals[i].reg, initvals[i].val);
  533. return 0;
  534. }
  535. static int rtl8367b_read_phy_reg(struct rtl8366_smi *smi,
  536. u32 phy_addr, u32 phy_reg, u32 *val)
  537. {
  538. int timeout;
  539. u32 data;
  540. int err;
  541. if (phy_addr > RTL8367B_PHY_ADDR_MAX)
  542. return -EINVAL;
  543. if (phy_reg > RTL8367B_PHY_REG_MAX)
  544. return -EINVAL;
  545. REG_RD(smi, RTL8367B_IA_STATUS_REG, &data);
  546. if (data & RTL8367B_IA_STATUS_PHY_BUSY)
  547. return -ETIMEDOUT;
  548. /* prepare address */
  549. REG_WR(smi, RTL8367B_IA_ADDRESS_REG,
  550. RTL8367B_INTERNAL_PHY_REG(phy_addr, phy_reg));
  551. /* send read command */
  552. REG_WR(smi, RTL8367B_IA_CTRL_REG,
  553. RTL8367B_IA_CTRL_CMD_MASK | RTL8367B_IA_CTRL_RW_READ);
  554. timeout = 5;
  555. do {
  556. REG_RD(smi, RTL8367B_IA_STATUS_REG, &data);
  557. if ((data & RTL8367B_IA_STATUS_PHY_BUSY) == 0)
  558. break;
  559. if (timeout--) {
  560. dev_err(smi->parent, "phy read timed out\n");
  561. return -ETIMEDOUT;
  562. }
  563. udelay(1);
  564. } while (1);
  565. /* read data */
  566. REG_RD(smi, RTL8367B_IA_READ_DATA_REG, val);
  567. dev_dbg(smi->parent, "phy_read: addr:%02x, reg:%02x, val:%04x\n",
  568. phy_addr, phy_reg, *val);
  569. return 0;
  570. }
  571. static int rtl8367b_write_phy_reg(struct rtl8366_smi *smi,
  572. u32 phy_addr, u32 phy_reg, u32 val)
  573. {
  574. int timeout;
  575. u32 data;
  576. int err;
  577. dev_dbg(smi->parent, "phy_write: addr:%02x, reg:%02x, val:%04x\n",
  578. phy_addr, phy_reg, val);
  579. if (phy_addr > RTL8367B_PHY_ADDR_MAX)
  580. return -EINVAL;
  581. if (phy_reg > RTL8367B_PHY_REG_MAX)
  582. return -EINVAL;
  583. REG_RD(smi, RTL8367B_IA_STATUS_REG, &data);
  584. if (data & RTL8367B_IA_STATUS_PHY_BUSY)
  585. return -ETIMEDOUT;
  586. /* preapre data */
  587. REG_WR(smi, RTL8367B_IA_WRITE_DATA_REG, val);
  588. /* prepare address */
  589. REG_WR(smi, RTL8367B_IA_ADDRESS_REG,
  590. RTL8367B_INTERNAL_PHY_REG(phy_addr, phy_reg));
  591. /* send write command */
  592. REG_WR(smi, RTL8367B_IA_CTRL_REG,
  593. RTL8367B_IA_CTRL_CMD_MASK | RTL8367B_IA_CTRL_RW_WRITE);
  594. timeout = 5;
  595. do {
  596. REG_RD(smi, RTL8367B_IA_STATUS_REG, &data);
  597. if ((data & RTL8367B_IA_STATUS_PHY_BUSY) == 0)
  598. break;
  599. if (timeout--) {
  600. dev_err(smi->parent, "phy write timed out\n");
  601. return -ETIMEDOUT;
  602. }
  603. udelay(1);
  604. } while (1);
  605. return 0;
  606. }
  607. static int rtl8367b_init_regs(struct rtl8366_smi *smi)
  608. {
  609. const struct rtl8367b_initval *initvals;
  610. u32 chip_ver;
  611. u32 rlvid;
  612. int count;
  613. int err;
  614. REG_WR(smi, RTL8367B_RTL_MAGIC_ID_REG, RTL8367B_RTL_MAGIC_ID_VAL);
  615. REG_RD(smi, RTL8367B_CHIP_VER_REG, &chip_ver);
  616. rlvid = (chip_ver >> RTL8367B_CHIP_VER_RLVID_SHIFT) &
  617. RTL8367B_CHIP_VER_RLVID_MASK;
  618. switch (rlvid) {
  619. case 0:
  620. initvals = rtl8367r_vb_initvals_0;
  621. count = ARRAY_SIZE(rtl8367r_vb_initvals_0);
  622. break;
  623. case 1:
  624. initvals = rtl8367r_vb_initvals_1;
  625. count = ARRAY_SIZE(rtl8367r_vb_initvals_1);
  626. break;
  627. default:
  628. dev_err(smi->parent, "unknow rlvid %u\n", rlvid);
  629. return -ENODEV;
  630. }
  631. /* TODO: disable RLTP */
  632. return rtl8367b_write_initvals(smi, initvals, count);
  633. }
  634. static int rtl8367b_reset_chip(struct rtl8366_smi *smi)
  635. {
  636. int timeout = 10;
  637. int err;
  638. u32 data;
  639. REG_WR(smi, RTL8367B_CHIP_RESET_REG, RTL8367B_CHIP_RESET_HW);
  640. msleep(RTL8367B_RESET_DELAY);
  641. do {
  642. REG_RD(smi, RTL8367B_CHIP_RESET_REG, &data);
  643. if (!(data & RTL8367B_CHIP_RESET_HW))
  644. break;
  645. msleep(1);
  646. } while (--timeout);
  647. if (!timeout) {
  648. dev_err(smi->parent, "chip reset timed out\n");
  649. return -ETIMEDOUT;
  650. }
  651. return 0;
  652. }
  653. static int rtl8367b_extif_set_mode(struct rtl8366_smi *smi, int id,
  654. enum rtl8367_extif_mode mode)
  655. {
  656. int err;
  657. /* set port mode */
  658. switch (mode) {
  659. case RTL8367_EXTIF_MODE_RGMII:
  660. case RTL8367_EXTIF_MODE_RGMII_33V:
  661. REG_WR(smi, RTL8367B_CHIP_DEBUG0_REG, 0x0367);
  662. REG_WR(smi, RTL8367B_CHIP_DEBUG1_REG, 0x7777);
  663. break;
  664. case RTL8367_EXTIF_MODE_TMII_MAC:
  665. case RTL8367_EXTIF_MODE_TMII_PHY:
  666. REG_RMW(smi, RTL8367B_BYPASS_LINE_RATE_REG,
  667. BIT((id + 1) % 2), BIT((id + 1) % 2));
  668. break;
  669. case RTL8367_EXTIF_MODE_GMII:
  670. REG_RMW(smi, RTL8367B_CHIP_DEBUG0_REG,
  671. RTL8367B_CHIP_DEBUG0_DUMMY0(id),
  672. RTL8367B_CHIP_DEBUG0_DUMMY0(id));
  673. REG_RMW(smi, RTL8367B_EXT_RGMXF_REG(id), BIT(6), BIT(6));
  674. break;
  675. case RTL8367_EXTIF_MODE_MII_MAC:
  676. case RTL8367_EXTIF_MODE_MII_PHY:
  677. case RTL8367_EXTIF_MODE_DISABLED:
  678. REG_RMW(smi, RTL8367B_BYPASS_LINE_RATE_REG,
  679. BIT((id + 1) % 2), 0);
  680. REG_RMW(smi, RTL8367B_EXT_RGMXF_REG(id), BIT(6), 0);
  681. break;
  682. default:
  683. dev_err(smi->parent,
  684. "invalid mode for external interface %d\n", id);
  685. return -EINVAL;
  686. }
  687. REG_RMW(smi, RTL8367B_DIS_REG,
  688. RTL8367B_DIS_RGMII_MASK << RTL8367B_DIS_RGMII_SHIFT(id),
  689. mode << RTL8367B_DIS_RGMII_SHIFT(id));
  690. return 0;
  691. }
  692. static int rtl8367b_extif_set_force(struct rtl8366_smi *smi, int id,
  693. struct rtl8367_port_ability *pa)
  694. {
  695. u32 mask;
  696. u32 val;
  697. int err;
  698. mask = (RTL8367B_DI_FORCE_MODE |
  699. RTL8367B_DI_FORCE_NWAY |
  700. RTL8367B_DI_FORCE_TXPAUSE |
  701. RTL8367B_DI_FORCE_RXPAUSE |
  702. RTL8367B_DI_FORCE_LINK |
  703. RTL8367B_DI_FORCE_DUPLEX |
  704. RTL8367B_DI_FORCE_SPEED_MASK);
  705. val = pa->speed;
  706. val |= pa->force_mode ? RTL8367B_DI_FORCE_MODE : 0;
  707. val |= pa->nway ? RTL8367B_DI_FORCE_NWAY : 0;
  708. val |= pa->txpause ? RTL8367B_DI_FORCE_TXPAUSE : 0;
  709. val |= pa->rxpause ? RTL8367B_DI_FORCE_RXPAUSE : 0;
  710. val |= pa->link ? RTL8367B_DI_FORCE_LINK : 0;
  711. val |= pa->duplex ? RTL8367B_DI_FORCE_DUPLEX : 0;
  712. REG_RMW(smi, RTL8367B_DI_FORCE_REG(id), mask, val);
  713. return 0;
  714. }
  715. static int rtl8367b_extif_set_rgmii_delay(struct rtl8366_smi *smi, int id,
  716. unsigned txdelay, unsigned rxdelay)
  717. {
  718. u32 mask;
  719. u32 val;
  720. int err;
  721. mask = (RTL8367B_EXT_RGMXF_RXDELAY_MASK |
  722. (RTL8367B_EXT_RGMXF_TXDELAY_MASK <<
  723. RTL8367B_EXT_RGMXF_TXDELAY_SHIFT));
  724. val = rxdelay;
  725. val |= txdelay << RTL8367B_EXT_RGMXF_TXDELAY_SHIFT;
  726. REG_RMW(smi, RTL8367B_EXT_RGMXF_REG(id), mask, val);
  727. return 0;
  728. }
  729. static int rtl8367b_extif_init(struct rtl8366_smi *smi, int id,
  730. struct rtl8367_extif_config *cfg)
  731. {
  732. enum rtl8367_extif_mode mode;
  733. int err;
  734. mode = (cfg) ? cfg->mode : RTL8367_EXTIF_MODE_DISABLED;
  735. err = rtl8367b_extif_set_mode(smi, id, mode);
  736. if (err)
  737. return err;
  738. if (mode != RTL8367_EXTIF_MODE_DISABLED) {
  739. err = rtl8367b_extif_set_force(smi, id, &cfg->ability);
  740. if (err)
  741. return err;
  742. err = rtl8367b_extif_set_rgmii_delay(smi, id, cfg->txdelay,
  743. cfg->rxdelay);
  744. if (err)
  745. return err;
  746. }
  747. return 0;
  748. }
  749. #ifdef CONFIG_OF
  750. static int rtl8367b_extif_init_of(struct rtl8366_smi *smi, int id,
  751. const char *name)
  752. {
  753. struct rtl8367_extif_config *cfg;
  754. const __be32 *prop;
  755. int size;
  756. int err;
  757. prop = of_get_property(smi->parent->of_node, name, &size);
  758. if (!prop)
  759. return rtl8367b_extif_init(smi, id, NULL);
  760. if (size != (9 * sizeof(*prop))) {
  761. dev_err(smi->parent, "%s property is invalid\n", name);
  762. return -EINVAL;
  763. }
  764. cfg = kzalloc(sizeof(struct rtl8367_extif_config), GFP_KERNEL);
  765. if (!cfg)
  766. return -ENOMEM;
  767. cfg->txdelay = be32_to_cpup(prop++);
  768. cfg->rxdelay = be32_to_cpup(prop++);
  769. cfg->mode = be32_to_cpup(prop++);
  770. cfg->ability.force_mode = be32_to_cpup(prop++);
  771. cfg->ability.txpause = be32_to_cpup(prop++);
  772. cfg->ability.rxpause = be32_to_cpup(prop++);
  773. cfg->ability.link = be32_to_cpup(prop++);
  774. cfg->ability.duplex = be32_to_cpup(prop++);
  775. cfg->ability.speed = be32_to_cpup(prop++);
  776. err = rtl8367b_extif_init(smi, id, cfg);
  777. kfree(cfg);
  778. return err;
  779. }
  780. #else
  781. static int rtl8367b_extif_init_of(struct rtl8366_smi *smi, int id,
  782. const char *name)
  783. {
  784. return -EINVAL;
  785. }
  786. #endif
  787. static int rtl8367b_setup(struct rtl8366_smi *smi)
  788. {
  789. struct rtl8367_platform_data *pdata;
  790. int err;
  791. int i;
  792. pdata = smi->parent->platform_data;
  793. err = rtl8367b_init_regs(smi);
  794. if (err)
  795. return err;
  796. /* initialize external interfaces */
  797. if (smi->parent->of_node) {
  798. err = rtl8367b_extif_init_of(smi, 0, "realtek,extif0");
  799. if (err)
  800. return err;
  801. err = rtl8367b_extif_init_of(smi, 1, "realtek,extif1");
  802. if (err)
  803. return err;
  804. } else {
  805. err = rtl8367b_extif_init(smi, 0, pdata->extif0_cfg);
  806. if (err)
  807. return err;
  808. err = rtl8367b_extif_init(smi, 1, pdata->extif1_cfg);
  809. if (err)
  810. return err;
  811. }
  812. /* set maximum packet length to 1536 bytes */
  813. REG_RMW(smi, RTL8367B_SWC0_REG, RTL8367B_SWC0_MAX_LENGTH_MASK,
  814. RTL8367B_SWC0_MAX_LENGTH_1536);
  815. /*
  816. * discard VLAN tagged packets if the port is not a member of
  817. * the VLAN with which the packets is associated.
  818. */
  819. REG_WR(smi, RTL8367B_VLAN_INGRESS_REG, RTL8367B_PORTS_ALL);
  820. /*
  821. * Setup egress tag mode for each port.
  822. */
  823. for (i = 0; i < RTL8367B_NUM_PORTS; i++)
  824. REG_RMW(smi,
  825. RTL8367B_PORT_MISC_CFG_REG(i),
  826. RTL8367B_PORT_MISC_CFG_EGRESS_MODE_MASK <<
  827. RTL8367B_PORT_MISC_CFG_EGRESS_MODE_SHIFT,
  828. RTL8367B_PORT_MISC_CFG_EGRESS_MODE_ORIGINAL <<
  829. RTL8367B_PORT_MISC_CFG_EGRESS_MODE_SHIFT);
  830. return 0;
  831. }
  832. static int rtl8367b_get_mib_counter(struct rtl8366_smi *smi, int counter,
  833. int port, unsigned long long *val)
  834. {
  835. struct rtl8366_mib_counter *mib;
  836. int offset;
  837. int i;
  838. int err;
  839. u32 addr, data;
  840. u64 mibvalue;
  841. if (port > RTL8367B_NUM_PORTS ||
  842. counter >= RTL8367B_NUM_MIB_COUNTERS)
  843. return -EINVAL;
  844. mib = &rtl8367b_mib_counters[counter];
  845. addr = RTL8367B_MIB_COUNTER_PORT_OFFSET * port + mib->offset;
  846. /*
  847. * Writing access counter address first
  848. * then ASIC will prepare 64bits counter wait for being retrived
  849. */
  850. REG_WR(smi, RTL8367B_MIB_ADDRESS_REG, addr >> 2);
  851. /* read MIB control register */
  852. REG_RD(smi, RTL8367B_MIB_CTRL0_REG(0), &data);
  853. if (data & RTL8367B_MIB_CTRL0_BUSY_MASK)
  854. return -EBUSY;
  855. if (data & RTL8367B_MIB_CTRL0_RESET_MASK)
  856. return -EIO;
  857. if (mib->length == 4)
  858. offset = 3;
  859. else
  860. offset = (mib->offset + 1) % 4;
  861. mibvalue = 0;
  862. for (i = 0; i < mib->length; i++) {
  863. REG_RD(smi, RTL8367B_MIB_COUNTER_REG(offset - i), &data);
  864. mibvalue = (mibvalue << 16) | (data & 0xFFFF);
  865. }
  866. *val = mibvalue;
  867. return 0;
  868. }
  869. static int rtl8367b_get_vlan_4k(struct rtl8366_smi *smi, u32 vid,
  870. struct rtl8366_vlan_4k *vlan4k)
  871. {
  872. u32 data[RTL8367B_TA_VLAN_NUM_WORDS];
  873. int err;
  874. int i;
  875. memset(vlan4k, '\0', sizeof(struct rtl8366_vlan_4k));
  876. if (vid >= RTL8367B_NUM_VIDS)
  877. return -EINVAL;
  878. /* write VID */
  879. REG_WR(smi, RTL8367B_TA_ADDR_REG, vid);
  880. /* write table access control word */
  881. REG_WR(smi, RTL8367B_TA_CTRL_REG, RTL8367B_TA_CTRL_CVLAN_READ);
  882. for (i = 0; i < ARRAY_SIZE(data); i++)
  883. REG_RD(smi, RTL8367B_TA_RDDATA_REG(i), &data[i]);
  884. vlan4k->vid = vid;
  885. vlan4k->member = (data[0] >> RTL8367B_TA_VLAN0_MEMBER_SHIFT) &
  886. RTL8367B_TA_VLAN0_MEMBER_MASK;
  887. vlan4k->untag = (data[0] >> RTL8367B_TA_VLAN0_UNTAG_SHIFT) &
  888. RTL8367B_TA_VLAN0_UNTAG_MASK;
  889. vlan4k->fid = (data[1] >> RTL8367B_TA_VLAN1_FID_SHIFT) &
  890. RTL8367B_TA_VLAN1_FID_MASK;
  891. return 0;
  892. }
  893. static int rtl8367b_set_vlan_4k(struct rtl8366_smi *smi,
  894. const struct rtl8366_vlan_4k *vlan4k)
  895. {
  896. u32 data[RTL8367B_TA_VLAN_NUM_WORDS];
  897. int err;
  898. int i;
  899. if (vlan4k->vid >= RTL8367B_NUM_VIDS ||
  900. vlan4k->member > RTL8367B_TA_VLAN0_MEMBER_MASK ||
  901. vlan4k->untag > RTL8367B_UNTAG_MASK ||
  902. vlan4k->fid > RTL8367B_FIDMAX)
  903. return -EINVAL;
  904. memset(data, 0, sizeof(data));
  905. data[0] = (vlan4k->member & RTL8367B_TA_VLAN0_MEMBER_MASK) <<
  906. RTL8367B_TA_VLAN0_MEMBER_SHIFT;
  907. data[0] |= (vlan4k->untag & RTL8367B_TA_VLAN0_UNTAG_MASK) <<
  908. RTL8367B_TA_VLAN0_UNTAG_SHIFT;
  909. data[1] = (vlan4k->fid & RTL8367B_TA_VLAN1_FID_MASK) <<
  910. RTL8367B_TA_VLAN1_FID_SHIFT;
  911. for (i = 0; i < ARRAY_SIZE(data); i++)
  912. REG_WR(smi, RTL8367B_TA_WRDATA_REG(i), data[i]);
  913. /* write VID */
  914. REG_WR(smi, RTL8367B_TA_ADDR_REG,
  915. vlan4k->vid & RTL8367B_TA_VLAN_VID_MASK);
  916. /* write table access control word */
  917. REG_WR(smi, RTL8367B_TA_CTRL_REG, RTL8367B_TA_CTRL_CVLAN_WRITE);
  918. return 0;
  919. }
  920. static int rtl8367b_get_vlan_mc(struct rtl8366_smi *smi, u32 index,
  921. struct rtl8366_vlan_mc *vlanmc)
  922. {
  923. u32 data[RTL8367B_VLAN_MC_NUM_WORDS];
  924. int err;
  925. int i;
  926. memset(vlanmc, '\0', sizeof(struct rtl8366_vlan_mc));
  927. if (index >= RTL8367B_NUM_VLANS)
  928. return -EINVAL;
  929. for (i = 0; i < ARRAY_SIZE(data); i++)
  930. REG_RD(smi, RTL8367B_VLAN_MC_BASE(index) + i, &data[i]);
  931. vlanmc->member = (data[0] >> RTL8367B_VLAN_MC0_MEMBER_SHIFT) &
  932. RTL8367B_VLAN_MC0_MEMBER_MASK;
  933. vlanmc->fid = (data[1] >> RTL8367B_VLAN_MC1_FID_SHIFT) &
  934. RTL8367B_VLAN_MC1_FID_MASK;
  935. vlanmc->vid = (data[3] >> RTL8367B_VLAN_MC3_EVID_SHIFT) &
  936. RTL8367B_VLAN_MC3_EVID_MASK;
  937. return 0;
  938. }
  939. static int rtl8367b_set_vlan_mc(struct rtl8366_smi *smi, u32 index,
  940. const struct rtl8366_vlan_mc *vlanmc)
  941. {
  942. u32 data[RTL8367B_VLAN_MC_NUM_WORDS];
  943. int err;
  944. int i;
  945. if (index >= RTL8367B_NUM_VLANS ||
  946. vlanmc->vid >= RTL8367B_NUM_VIDS ||
  947. vlanmc->priority > RTL8367B_PRIORITYMAX ||
  948. vlanmc->member > RTL8367B_VLAN_MC0_MEMBER_MASK ||
  949. vlanmc->untag > RTL8367B_UNTAG_MASK ||
  950. vlanmc->fid > RTL8367B_FIDMAX)
  951. return -EINVAL;
  952. data[0] = (vlanmc->member & RTL8367B_VLAN_MC0_MEMBER_MASK) <<
  953. RTL8367B_VLAN_MC0_MEMBER_SHIFT;
  954. data[1] = (vlanmc->fid & RTL8367B_VLAN_MC1_FID_MASK) <<
  955. RTL8367B_VLAN_MC1_FID_SHIFT;
  956. data[2] = 0;
  957. data[3] = (vlanmc->vid & RTL8367B_VLAN_MC3_EVID_MASK) <<
  958. RTL8367B_VLAN_MC3_EVID_SHIFT;
  959. for (i = 0; i < ARRAY_SIZE(data); i++)
  960. REG_WR(smi, RTL8367B_VLAN_MC_BASE(index) + i, data[i]);
  961. return 0;
  962. }
  963. static int rtl8367b_get_mc_index(struct rtl8366_smi *smi, int port, int *val)
  964. {
  965. u32 data;
  966. int err;
  967. if (port >= RTL8367B_NUM_PORTS)
  968. return -EINVAL;
  969. REG_RD(smi, RTL8367B_VLAN_PVID_CTRL_REG(port), &data);
  970. *val = (data >> RTL8367B_VLAN_PVID_CTRL_SHIFT(port)) &
  971. RTL8367B_VLAN_PVID_CTRL_MASK;
  972. return 0;
  973. }
  974. static int rtl8367b_set_mc_index(struct rtl8366_smi *smi, int port, int index)
  975. {
  976. if (port >= RTL8367B_NUM_PORTS || index >= RTL8367B_NUM_VLANS)
  977. return -EINVAL;
  978. return rtl8366_smi_rmwr(smi, RTL8367B_VLAN_PVID_CTRL_REG(port),
  979. RTL8367B_VLAN_PVID_CTRL_MASK <<
  980. RTL8367B_VLAN_PVID_CTRL_SHIFT(port),
  981. (index & RTL8367B_VLAN_PVID_CTRL_MASK) <<
  982. RTL8367B_VLAN_PVID_CTRL_SHIFT(port));
  983. }
  984. static int rtl8367b_enable_vlan(struct rtl8366_smi *smi, int enable)
  985. {
  986. return rtl8366_smi_rmwr(smi, RTL8367B_VLAN_CTRL_REG,
  987. RTL8367B_VLAN_CTRL_ENABLE,
  988. (enable) ? RTL8367B_VLAN_CTRL_ENABLE : 0);
  989. }
  990. static int rtl8367b_enable_vlan4k(struct rtl8366_smi *smi, int enable)
  991. {
  992. return 0;
  993. }
  994. static int rtl8367b_is_vlan_valid(struct rtl8366_smi *smi, unsigned vlan)
  995. {
  996. unsigned max = RTL8367B_NUM_VLANS;
  997. if (smi->vlan4k_enabled)
  998. max = RTL8367B_NUM_VIDS - 1;
  999. if (vlan == 0 || vlan >= max)
  1000. return 0;
  1001. return 1;
  1002. }
  1003. static int rtl8367b_enable_port(struct rtl8366_smi *smi, int port, int enable)
  1004. {
  1005. int err;
  1006. REG_WR(smi, RTL8367B_PORT_ISOLATION_REG(port),
  1007. (enable) ? RTL8367B_PORTS_ALL : 0);
  1008. return 0;
  1009. }
  1010. static int rtl8367b_sw_reset_mibs(struct switch_dev *dev,
  1011. const struct switch_attr *attr,
  1012. struct switch_val *val)
  1013. {
  1014. struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
  1015. return rtl8366_smi_rmwr(smi, RTL8367B_MIB_CTRL0_REG(0), 0,
  1016. RTL8367B_MIB_CTRL0_GLOBAL_RESET_MASK);
  1017. }
  1018. static int rtl8367b_sw_get_port_link(struct switch_dev *dev,
  1019. int port,
  1020. struct switch_port_link *link)
  1021. {
  1022. struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
  1023. u32 data = 0;
  1024. u32 speed;
  1025. if (port >= RTL8367B_NUM_PORTS)
  1026. return -EINVAL;
  1027. rtl8366_smi_read_reg(smi, RTL8367B_PORT_STATUS_REG(port), &data);
  1028. link->link = !!(data & RTL8367B_PORT_STATUS_LINK);
  1029. if (!link->link)
  1030. return 0;
  1031. link->duplex = !!(data & RTL8367B_PORT_STATUS_DUPLEX);
  1032. link->rx_flow = !!(data & RTL8367B_PORT_STATUS_RXPAUSE);
  1033. link->tx_flow = !!(data & RTL8367B_PORT_STATUS_TXPAUSE);
  1034. link->aneg = !!(data & RTL8367B_PORT_STATUS_NWAY);
  1035. speed = (data & RTL8367B_PORT_STATUS_SPEED_MASK);
  1036. switch (speed) {
  1037. case 0:
  1038. link->speed = SWITCH_PORT_SPEED_10;
  1039. break;
  1040. case 1:
  1041. link->speed = SWITCH_PORT_SPEED_100;
  1042. break;
  1043. case 2:
  1044. link->speed = SWITCH_PORT_SPEED_1000;
  1045. break;
  1046. default:
  1047. link->speed = SWITCH_PORT_SPEED_UNKNOWN;
  1048. break;
  1049. }
  1050. return 0;
  1051. }
  1052. static int rtl8367b_sw_get_max_length(struct switch_dev *dev,
  1053. const struct switch_attr *attr,
  1054. struct switch_val *val)
  1055. {
  1056. struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
  1057. u32 data;
  1058. rtl8366_smi_read_reg(smi, RTL8367B_SWC0_REG, &data);
  1059. val->value.i = (data & RTL8367B_SWC0_MAX_LENGTH_MASK) >>
  1060. RTL8367B_SWC0_MAX_LENGTH_SHIFT;
  1061. return 0;
  1062. }
  1063. static int rtl8367b_sw_set_max_length(struct switch_dev *dev,
  1064. const struct switch_attr *attr,
  1065. struct switch_val *val)
  1066. {
  1067. struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
  1068. u32 max_len;
  1069. switch (val->value.i) {
  1070. case 0:
  1071. max_len = RTL8367B_SWC0_MAX_LENGTH_1522;
  1072. break;
  1073. case 1:
  1074. max_len = RTL8367B_SWC0_MAX_LENGTH_1536;
  1075. break;
  1076. case 2:
  1077. max_len = RTL8367B_SWC0_MAX_LENGTH_1552;
  1078. break;
  1079. case 3:
  1080. max_len = RTL8367B_SWC0_MAX_LENGTH_16000;
  1081. break;
  1082. default:
  1083. return -EINVAL;
  1084. }
  1085. return rtl8366_smi_rmwr(smi, RTL8367B_SWC0_REG,
  1086. RTL8367B_SWC0_MAX_LENGTH_MASK, max_len);
  1087. }
  1088. static int rtl8367b_sw_reset_port_mibs(struct switch_dev *dev,
  1089. const struct switch_attr *attr,
  1090. struct switch_val *val)
  1091. {
  1092. struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
  1093. int port;
  1094. port = val->port_vlan;
  1095. if (port >= RTL8367B_NUM_PORTS)
  1096. return -EINVAL;
  1097. return rtl8366_smi_rmwr(smi, RTL8367B_MIB_CTRL0_REG(port / 8), 0,
  1098. RTL8367B_MIB_CTRL0_PORT_RESET_MASK(port % 8));
  1099. }
  1100. static struct switch_attr rtl8367b_globals[] = {
  1101. {
  1102. .type = SWITCH_TYPE_INT,
  1103. .name = "enable_vlan",
  1104. .description = "Enable VLAN mode",
  1105. .set = rtl8366_sw_set_vlan_enable,
  1106. .get = rtl8366_sw_get_vlan_enable,
  1107. .max = 1,
  1108. .ofs = 1
  1109. }, {
  1110. .type = SWITCH_TYPE_INT,
  1111. .name = "enable_vlan4k",
  1112. .description = "Enable VLAN 4K mode",
  1113. .set = rtl8366_sw_set_vlan_enable,
  1114. .get = rtl8366_sw_get_vlan_enable,
  1115. .max = 1,
  1116. .ofs = 2
  1117. }, {
  1118. .type = SWITCH_TYPE_NOVAL,
  1119. .name = "reset_mibs",
  1120. .description = "Reset all MIB counters",
  1121. .set = rtl8367b_sw_reset_mibs,
  1122. }, {
  1123. .type = SWITCH_TYPE_INT,
  1124. .name = "max_length",
  1125. .description = "Get/Set the maximum length of valid packets"
  1126. "(0:1522, 1:1536, 2:1552, 3:16000)",
  1127. .set = rtl8367b_sw_set_max_length,
  1128. .get = rtl8367b_sw_get_max_length,
  1129. .max = 3,
  1130. }
  1131. };
  1132. static struct switch_attr rtl8367b_port[] = {
  1133. {
  1134. .type = SWITCH_TYPE_NOVAL,
  1135. .name = "reset_mib",
  1136. .description = "Reset single port MIB counters",
  1137. .set = rtl8367b_sw_reset_port_mibs,
  1138. }, {
  1139. .type = SWITCH_TYPE_STRING,
  1140. .name = "mib",
  1141. .description = "Get MIB counters for port",
  1142. .max = 33,
  1143. .set = NULL,
  1144. .get = rtl8366_sw_get_port_mib,
  1145. },
  1146. };
  1147. static struct switch_attr rtl8367b_vlan[] = {
  1148. {
  1149. .type = SWITCH_TYPE_STRING,
  1150. .name = "info",
  1151. .description = "Get vlan information",
  1152. .max = 1,
  1153. .set = NULL,
  1154. .get = rtl8366_sw_get_vlan_info,
  1155. },
  1156. };
  1157. static const struct switch_dev_ops rtl8367b_sw_ops = {
  1158. .attr_global = {
  1159. .attr = rtl8367b_globals,
  1160. .n_attr = ARRAY_SIZE(rtl8367b_globals),
  1161. },
  1162. .attr_port = {
  1163. .attr = rtl8367b_port,
  1164. .n_attr = ARRAY_SIZE(rtl8367b_port),
  1165. },
  1166. .attr_vlan = {
  1167. .attr = rtl8367b_vlan,
  1168. .n_attr = ARRAY_SIZE(rtl8367b_vlan),
  1169. },
  1170. .get_vlan_ports = rtl8366_sw_get_vlan_ports,
  1171. .set_vlan_ports = rtl8366_sw_set_vlan_ports,
  1172. .get_port_pvid = rtl8366_sw_get_port_pvid,
  1173. .set_port_pvid = rtl8366_sw_set_port_pvid,
  1174. .reset_switch = rtl8366_sw_reset_switch,
  1175. .get_port_link = rtl8367b_sw_get_port_link,
  1176. };
  1177. static int rtl8367b_switch_init(struct rtl8366_smi *smi)
  1178. {
  1179. struct switch_dev *dev = &smi->sw_dev;
  1180. int err;
  1181. dev->name = "RTL8367B";
  1182. dev->cpu_port = RTL8367B_CPU_PORT_NUM;
  1183. dev->ports = RTL8367B_NUM_PORTS;
  1184. dev->vlans = RTL8367B_NUM_VIDS;
  1185. dev->ops = &rtl8367b_sw_ops;
  1186. dev->alias = dev_name(smi->parent);
  1187. err = register_switch(dev, NULL);
  1188. if (err)
  1189. dev_err(smi->parent, "switch registration failed\n");
  1190. return err;
  1191. }
  1192. static void rtl8367b_switch_cleanup(struct rtl8366_smi *smi)
  1193. {
  1194. unregister_switch(&smi->sw_dev);
  1195. }
  1196. static int rtl8367b_mii_read(struct mii_bus *bus, int addr, int reg)
  1197. {
  1198. struct rtl8366_smi *smi = bus->priv;
  1199. u32 val = 0;
  1200. int err;
  1201. err = rtl8367b_read_phy_reg(smi, addr, reg, &val);
  1202. if (err)
  1203. return 0xffff;
  1204. return val;
  1205. }
  1206. static int rtl8367b_mii_write(struct mii_bus *bus, int addr, int reg, u16 val)
  1207. {
  1208. struct rtl8366_smi *smi = bus->priv;
  1209. u32 t;
  1210. int err;
  1211. err = rtl8367b_write_phy_reg(smi, addr, reg, val);
  1212. if (err)
  1213. return err;
  1214. /* flush write */
  1215. (void) rtl8367b_read_phy_reg(smi, addr, reg, &t);
  1216. return err;
  1217. }
  1218. static int rtl8367b_detect(struct rtl8366_smi *smi)
  1219. {
  1220. const char *chip_name;
  1221. u32 chip_num;
  1222. u32 chip_ver;
  1223. u32 chip_mode;
  1224. int ret;
  1225. /* TODO: improve chip detection */
  1226. rtl8366_smi_write_reg(smi, RTL8367B_RTL_MAGIC_ID_REG,
  1227. RTL8367B_RTL_MAGIC_ID_VAL);
  1228. ret = rtl8366_smi_read_reg(smi, RTL8367B_CHIP_NUMBER_REG, &chip_num);
  1229. if (ret) {
  1230. dev_err(smi->parent, "unable to read %s register\n",
  1231. "chip number");
  1232. return ret;
  1233. }
  1234. ret = rtl8366_smi_read_reg(smi, RTL8367B_CHIP_VER_REG, &chip_ver);
  1235. if (ret) {
  1236. dev_err(smi->parent, "unable to read %s register\n",
  1237. "chip version");
  1238. return ret;
  1239. }
  1240. ret = rtl8366_smi_read_reg(smi, RTL8367B_CHIP_MODE_REG, &chip_mode);
  1241. if (ret) {
  1242. dev_err(smi->parent, "unable to read %s register\n",
  1243. "chip mode");
  1244. return ret;
  1245. }
  1246. switch (chip_ver) {
  1247. case 0x1000:
  1248. chip_name = "8367RB";
  1249. break;
  1250. case 0x1010:
  1251. chip_name = "8367R-VB";
  1252. break;
  1253. default:
  1254. dev_err(smi->parent,
  1255. "unknown chip num:%04x ver:%04x, mode:%04x\n",
  1256. chip_num, chip_ver, chip_mode);
  1257. return -ENODEV;
  1258. }
  1259. dev_info(smi->parent, "RTL%s chip found\n", chip_name);
  1260. return 0;
  1261. }
  1262. static struct rtl8366_smi_ops rtl8367b_smi_ops = {
  1263. .detect = rtl8367b_detect,
  1264. .reset_chip = rtl8367b_reset_chip,
  1265. .setup = rtl8367b_setup,
  1266. .mii_read = rtl8367b_mii_read,
  1267. .mii_write = rtl8367b_mii_write,
  1268. .get_vlan_mc = rtl8367b_get_vlan_mc,
  1269. .set_vlan_mc = rtl8367b_set_vlan_mc,
  1270. .get_vlan_4k = rtl8367b_get_vlan_4k,
  1271. .set_vlan_4k = rtl8367b_set_vlan_4k,
  1272. .get_mc_index = rtl8367b_get_mc_index,
  1273. .set_mc_index = rtl8367b_set_mc_index,
  1274. .get_mib_counter = rtl8367b_get_mib_counter,
  1275. .is_vlan_valid = rtl8367b_is_vlan_valid,
  1276. .enable_vlan = rtl8367b_enable_vlan,
  1277. .enable_vlan4k = rtl8367b_enable_vlan4k,
  1278. .enable_port = rtl8367b_enable_port,
  1279. };
  1280. static int rtl8367b_probe(struct platform_device *pdev)
  1281. {
  1282. struct rtl8366_smi *smi;
  1283. int err;
  1284. smi = rtl8366_smi_probe(pdev);
  1285. if (!smi)
  1286. return -ENODEV;
  1287. smi->clk_delay = 1500;
  1288. smi->cmd_read = 0xb9;
  1289. smi->cmd_write = 0xb8;
  1290. smi->ops = &rtl8367b_smi_ops;
  1291. smi->cpu_port = RTL8367B_CPU_PORT_NUM;
  1292. smi->num_ports = RTL8367B_NUM_PORTS;
  1293. smi->num_vlan_mc = RTL8367B_NUM_VLANS;
  1294. smi->mib_counters = rtl8367b_mib_counters;
  1295. smi->num_mib_counters = ARRAY_SIZE(rtl8367b_mib_counters);
  1296. err = rtl8366_smi_init(smi);
  1297. if (err)
  1298. goto err_free_smi;
  1299. platform_set_drvdata(pdev, smi);
  1300. err = rtl8367b_switch_init(smi);
  1301. if (err)
  1302. goto err_clear_drvdata;
  1303. return 0;
  1304. err_clear_drvdata:
  1305. platform_set_drvdata(pdev, NULL);
  1306. rtl8366_smi_cleanup(smi);
  1307. err_free_smi:
  1308. kfree(smi);
  1309. return err;
  1310. }
  1311. static int rtl8367b_remove(struct platform_device *pdev)
  1312. {
  1313. struct rtl8366_smi *smi = platform_get_drvdata(pdev);
  1314. if (smi) {
  1315. rtl8367b_switch_cleanup(smi);
  1316. platform_set_drvdata(pdev, NULL);
  1317. rtl8366_smi_cleanup(smi);
  1318. kfree(smi);
  1319. }
  1320. return 0;
  1321. }
  1322. static void rtl8367b_shutdown(struct platform_device *pdev)
  1323. {
  1324. struct rtl8366_smi *smi = platform_get_drvdata(pdev);
  1325. if (smi)
  1326. rtl8367b_reset_chip(smi);
  1327. }
  1328. #ifdef CONFIG_OF
  1329. static const struct of_device_id rtl8367b_match[] = {
  1330. { .compatible = "realtek,rtl8367b" },
  1331. { .compatible = "rtl8367b" },
  1332. {},
  1333. };
  1334. MODULE_DEVICE_TABLE(of, rtl8367b_match);
  1335. #endif
  1336. static struct platform_driver rtl8367b_driver = {
  1337. .driver = {
  1338. .name = RTL8367B_DRIVER_NAME,
  1339. .owner = THIS_MODULE,
  1340. #ifdef CONFIG_OF
  1341. .of_match_table = of_match_ptr(rtl8367b_match),
  1342. #endif
  1343. },
  1344. .probe = rtl8367b_probe,
  1345. .remove = rtl8367b_remove,
  1346. .shutdown = rtl8367b_shutdown,
  1347. };
  1348. module_platform_driver(rtl8367b_driver);
  1349. MODULE_DESCRIPTION(RTL8367B_DRIVER_DESC);
  1350. MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  1351. MODULE_LICENSE("GPL v2");
  1352. MODULE_ALIAS("platform:" RTL8367B_DRIVER_NAME);