rtl8367.c 58 KB

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