at803x.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * drivers/net/phy/at803x.c
  4. *
  5. * Driver for Qualcomm Atheros AR803x PHY
  6. *
  7. * Author: Matus Ujhelyi <[email protected]>
  8. */
  9. #include <linux/phy.h>
  10. #include <linux/module.h>
  11. #include <linux/string.h>
  12. #include <linux/netdevice.h>
  13. #include <linux/etherdevice.h>
  14. #include <linux/ethtool_netlink.h>
  15. #include <linux/of_gpio.h>
  16. #include <linux/bitfield.h>
  17. #include <linux/gpio/consumer.h>
  18. #include <linux/regulator/of_regulator.h>
  19. #include <linux/regulator/driver.h>
  20. #include <linux/regulator/consumer.h>
  21. #include <linux/phylink.h>
  22. #include <linux/sfp.h>
  23. #include <dt-bindings/net/qca-ar803x.h>
  24. #define AT803X_SPECIFIC_FUNCTION_CONTROL 0x10
  25. #define AT803X_SFC_ASSERT_CRS BIT(11)
  26. #define AT803X_SFC_FORCE_LINK BIT(10)
  27. #define AT803X_SFC_MDI_CROSSOVER_MODE_M GENMASK(6, 5)
  28. #define AT803X_SFC_AUTOMATIC_CROSSOVER 0x3
  29. #define AT803X_SFC_MANUAL_MDIX 0x1
  30. #define AT803X_SFC_MANUAL_MDI 0x0
  31. #define AT803X_SFC_SQE_TEST BIT(2)
  32. #define AT803X_SFC_POLARITY_REVERSAL BIT(1)
  33. #define AT803X_SFC_DISABLE_JABBER BIT(0)
  34. #define AT803X_SPECIFIC_STATUS 0x11
  35. #define AT803X_SS_SPEED_MASK GENMASK(15, 14)
  36. #define AT803X_SS_SPEED_1000 2
  37. #define AT803X_SS_SPEED_100 1
  38. #define AT803X_SS_SPEED_10 0
  39. #define AT803X_SS_DUPLEX BIT(13)
  40. #define AT803X_SS_SPEED_DUPLEX_RESOLVED BIT(11)
  41. #define AT803X_SS_MDIX BIT(6)
  42. #define QCA808X_SS_SPEED_MASK GENMASK(9, 7)
  43. #define QCA808X_SS_SPEED_2500 4
  44. #define AT803X_INTR_ENABLE 0x12
  45. #define AT803X_INTR_ENABLE_AUTONEG_ERR BIT(15)
  46. #define AT803X_INTR_ENABLE_SPEED_CHANGED BIT(14)
  47. #define AT803X_INTR_ENABLE_DUPLEX_CHANGED BIT(13)
  48. #define AT803X_INTR_ENABLE_PAGE_RECEIVED BIT(12)
  49. #define AT803X_INTR_ENABLE_LINK_FAIL BIT(11)
  50. #define AT803X_INTR_ENABLE_LINK_SUCCESS BIT(10)
  51. #define AT803X_INTR_ENABLE_LINK_FAIL_BX BIT(8)
  52. #define AT803X_INTR_ENABLE_LINK_SUCCESS_BX BIT(7)
  53. #define AT803X_INTR_ENABLE_WIRESPEED_DOWNGRADE BIT(5)
  54. #define AT803X_INTR_ENABLE_POLARITY_CHANGED BIT(1)
  55. #define AT803X_INTR_ENABLE_WOL BIT(0)
  56. #define AT803X_INTR_STATUS 0x13
  57. #define AT803X_SMART_SPEED 0x14
  58. #define AT803X_SMART_SPEED_ENABLE BIT(5)
  59. #define AT803X_SMART_SPEED_RETRY_LIMIT_MASK GENMASK(4, 2)
  60. #define AT803X_SMART_SPEED_BYPASS_TIMER BIT(1)
  61. #define AT803X_CDT 0x16
  62. #define AT803X_CDT_MDI_PAIR_MASK GENMASK(9, 8)
  63. #define AT803X_CDT_ENABLE_TEST BIT(0)
  64. #define AT803X_CDT_STATUS 0x1c
  65. #define AT803X_CDT_STATUS_STAT_NORMAL 0
  66. #define AT803X_CDT_STATUS_STAT_SHORT 1
  67. #define AT803X_CDT_STATUS_STAT_OPEN 2
  68. #define AT803X_CDT_STATUS_STAT_FAIL 3
  69. #define AT803X_CDT_STATUS_STAT_MASK GENMASK(9, 8)
  70. #define AT803X_CDT_STATUS_DELTA_TIME_MASK GENMASK(7, 0)
  71. #define AT803X_LED_CONTROL 0x18
  72. #define AT803X_PHY_MMD3_WOL_CTRL 0x8012
  73. #define AT803X_WOL_EN BIT(5)
  74. #define AT803X_LOC_MAC_ADDR_0_15_OFFSET 0x804C
  75. #define AT803X_LOC_MAC_ADDR_16_31_OFFSET 0x804B
  76. #define AT803X_LOC_MAC_ADDR_32_47_OFFSET 0x804A
  77. #define AT803X_REG_CHIP_CONFIG 0x1f
  78. #define AT803X_BT_BX_REG_SEL 0x8000
  79. #define AT803X_DEBUG_ADDR 0x1D
  80. #define AT803X_DEBUG_DATA 0x1E
  81. #define AT803X_MODE_CFG_MASK 0x0F
  82. #define AT803X_MODE_CFG_BASET_RGMII 0x00
  83. #define AT803X_MODE_CFG_BASET_SGMII 0x01
  84. #define AT803X_MODE_CFG_BX1000_RGMII_50OHM 0x02
  85. #define AT803X_MODE_CFG_BX1000_RGMII_75OHM 0x03
  86. #define AT803X_MODE_CFG_BX1000_CONV_50OHM 0x04
  87. #define AT803X_MODE_CFG_BX1000_CONV_75OHM 0x05
  88. #define AT803X_MODE_CFG_FX100_RGMII_50OHM 0x06
  89. #define AT803X_MODE_CFG_FX100_CONV_50OHM 0x07
  90. #define AT803X_MODE_CFG_RGMII_AUTO_MDET 0x0B
  91. #define AT803X_MODE_CFG_FX100_RGMII_75OHM 0x0E
  92. #define AT803X_MODE_CFG_FX100_CONV_75OHM 0x0F
  93. #define AT803X_PSSR 0x11 /*PHY-Specific Status Register*/
  94. #define AT803X_PSSR_MR_AN_COMPLETE 0x0200
  95. #define AT803X_DEBUG_ANALOG_TEST_CTRL 0x00
  96. #define QCA8327_DEBUG_MANU_CTRL_EN BIT(2)
  97. #define QCA8337_DEBUG_MANU_CTRL_EN GENMASK(3, 2)
  98. #define AT803X_DEBUG_RX_CLK_DLY_EN BIT(15)
  99. #define AT803X_DEBUG_SYSTEM_CTRL_MODE 0x05
  100. #define AT803X_DEBUG_TX_CLK_DLY_EN BIT(8)
  101. #define AT803X_DEBUG_REG_HIB_CTRL 0x0b
  102. #define AT803X_DEBUG_HIB_CTRL_SEL_RST_80U BIT(10)
  103. #define AT803X_DEBUG_HIB_CTRL_EN_ANY_CHANGE BIT(13)
  104. #define AT803X_DEBUG_HIB_CTRL_PS_HIB_EN BIT(15)
  105. #define AT803X_DEBUG_REG_3C 0x3C
  106. #define AT803X_DEBUG_REG_GREEN 0x3D
  107. #define AT803X_DEBUG_GATE_CLK_IN1000 BIT(6)
  108. #define AT803X_DEBUG_REG_1F 0x1F
  109. #define AT803X_DEBUG_PLL_ON BIT(2)
  110. #define AT803X_DEBUG_RGMII_1V8 BIT(3)
  111. #define MDIO_AZ_DEBUG 0x800D
  112. /* AT803x supports either the XTAL input pad, an internal PLL or the
  113. * DSP as clock reference for the clock output pad. The XTAL reference
  114. * is only used for 25 MHz output, all other frequencies need the PLL.
  115. * The DSP as a clock reference is used in synchronous ethernet
  116. * applications.
  117. *
  118. * By default the PLL is only enabled if there is a link. Otherwise
  119. * the PHY will go into low power state and disabled the PLL. You can
  120. * set the PLL_ON bit (see debug register 0x1f) to keep the PLL always
  121. * enabled.
  122. */
  123. #define AT803X_MMD7_CLK25M 0x8016
  124. #define AT803X_CLK_OUT_MASK GENMASK(4, 2)
  125. #define AT803X_CLK_OUT_25MHZ_XTAL 0
  126. #define AT803X_CLK_OUT_25MHZ_DSP 1
  127. #define AT803X_CLK_OUT_50MHZ_PLL 2
  128. #define AT803X_CLK_OUT_50MHZ_DSP 3
  129. #define AT803X_CLK_OUT_62_5MHZ_PLL 4
  130. #define AT803X_CLK_OUT_62_5MHZ_DSP 5
  131. #define AT803X_CLK_OUT_125MHZ_PLL 6
  132. #define AT803X_CLK_OUT_125MHZ_DSP 7
  133. /* The AR8035 has another mask which is compatible with the AR8031/AR8033 mask
  134. * but doesn't support choosing between XTAL/PLL and DSP.
  135. */
  136. #define AT8035_CLK_OUT_MASK GENMASK(4, 3)
  137. #define AT803X_CLK_OUT_STRENGTH_MASK GENMASK(8, 7)
  138. #define AT803X_CLK_OUT_STRENGTH_FULL 0
  139. #define AT803X_CLK_OUT_STRENGTH_HALF 1
  140. #define AT803X_CLK_OUT_STRENGTH_QUARTER 2
  141. #define AT803X_DEFAULT_DOWNSHIFT 5
  142. #define AT803X_MIN_DOWNSHIFT 2
  143. #define AT803X_MAX_DOWNSHIFT 9
  144. #define AT803X_MMD3_SMARTEEE_CTL1 0x805b
  145. #define AT803X_MMD3_SMARTEEE_CTL2 0x805c
  146. #define AT803X_MMD3_SMARTEEE_CTL3 0x805d
  147. #define AT803X_MMD3_SMARTEEE_CTL3_LPI_EN BIT(8)
  148. #define ATH9331_PHY_ID 0x004dd041
  149. #define ATH8030_PHY_ID 0x004dd076
  150. #define ATH8031_PHY_ID 0x004dd074
  151. #define ATH8032_PHY_ID 0x004dd023
  152. #define ATH8035_PHY_ID 0x004dd072
  153. #define AT8030_PHY_ID_MASK 0xffffffef
  154. #define QCA8081_PHY_ID 0x004dd101
  155. #define QCA8327_A_PHY_ID 0x004dd033
  156. #define QCA8327_B_PHY_ID 0x004dd034
  157. #define QCA8337_PHY_ID 0x004dd036
  158. #define QCA9561_PHY_ID 0x004dd042
  159. #define QCA8K_PHY_ID_MASK 0xffffffff
  160. #define QCA8K_DEVFLAGS_REVISION_MASK GENMASK(2, 0)
  161. #define AT803X_PAGE_FIBER 0
  162. #define AT803X_PAGE_COPPER 1
  163. /* don't turn off internal PLL */
  164. #define AT803X_KEEP_PLL_ENABLED BIT(0)
  165. #define AT803X_DISABLE_SMARTEEE BIT(1)
  166. /* disable hibernation mode */
  167. #define AT803X_DISABLE_HIBERNATION_MODE BIT(2)
  168. /* ADC threshold */
  169. #define QCA808X_PHY_DEBUG_ADC_THRESHOLD 0x2c80
  170. #define QCA808X_ADC_THRESHOLD_MASK GENMASK(7, 0)
  171. #define QCA808X_ADC_THRESHOLD_80MV 0
  172. #define QCA808X_ADC_THRESHOLD_100MV 0xf0
  173. #define QCA808X_ADC_THRESHOLD_200MV 0x0f
  174. #define QCA808X_ADC_THRESHOLD_300MV 0xff
  175. /* CLD control */
  176. #define QCA808X_PHY_MMD3_ADDR_CLD_CTRL7 0x8007
  177. #define QCA808X_8023AZ_AFE_CTRL_MASK GENMASK(8, 4)
  178. #define QCA808X_8023AZ_AFE_EN 0x90
  179. /* AZ control */
  180. #define QCA808X_PHY_MMD3_AZ_TRAINING_CTRL 0x8008
  181. #define QCA808X_MMD3_AZ_TRAINING_VAL 0x1c32
  182. #define QCA808X_PHY_MMD1_MSE_THRESHOLD_20DB 0x8014
  183. #define QCA808X_MSE_THRESHOLD_20DB_VALUE 0x529
  184. #define QCA808X_PHY_MMD1_MSE_THRESHOLD_17DB 0x800E
  185. #define QCA808X_MSE_THRESHOLD_17DB_VALUE 0x341
  186. #define QCA808X_PHY_MMD1_MSE_THRESHOLD_27DB 0x801E
  187. #define QCA808X_MSE_THRESHOLD_27DB_VALUE 0x419
  188. #define QCA808X_PHY_MMD1_MSE_THRESHOLD_28DB 0x8020
  189. #define QCA808X_MSE_THRESHOLD_28DB_VALUE 0x341
  190. #define QCA808X_PHY_MMD7_TOP_OPTION1 0x901c
  191. #define QCA808X_TOP_OPTION1_DATA 0x0
  192. #define QCA808X_PHY_MMD3_DEBUG_1 0xa100
  193. #define QCA808X_MMD3_DEBUG_1_VALUE 0x9203
  194. #define QCA808X_PHY_MMD3_DEBUG_2 0xa101
  195. #define QCA808X_MMD3_DEBUG_2_VALUE 0x48ad
  196. #define QCA808X_PHY_MMD3_DEBUG_3 0xa103
  197. #define QCA808X_MMD3_DEBUG_3_VALUE 0x1698
  198. #define QCA808X_PHY_MMD3_DEBUG_4 0xa105
  199. #define QCA808X_MMD3_DEBUG_4_VALUE 0x8001
  200. #define QCA808X_PHY_MMD3_DEBUG_5 0xa106
  201. #define QCA808X_MMD3_DEBUG_5_VALUE 0x1111
  202. #define QCA808X_PHY_MMD3_DEBUG_6 0xa011
  203. #define QCA808X_MMD3_DEBUG_6_VALUE 0x5f85
  204. /* master/slave seed config */
  205. #define QCA808X_PHY_DEBUG_LOCAL_SEED 9
  206. #define QCA808X_MASTER_SLAVE_SEED_ENABLE BIT(1)
  207. #define QCA808X_MASTER_SLAVE_SEED_CFG GENMASK(12, 2)
  208. #define QCA808X_MASTER_SLAVE_SEED_RANGE 0x32
  209. /* Hibernation yields lower power consumpiton in contrast with normal operation mode.
  210. * when the copper cable is unplugged, the PHY enters into hibernation mode in about 10s.
  211. */
  212. #define QCA808X_DBG_AN_TEST 0xb
  213. #define QCA808X_HIBERNATION_EN BIT(15)
  214. #define QCA808X_CDT_ENABLE_TEST BIT(15)
  215. #define QCA808X_CDT_INTER_CHECK_DIS BIT(13)
  216. #define QCA808X_CDT_LENGTH_UNIT BIT(10)
  217. #define QCA808X_MMD3_CDT_STATUS 0x8064
  218. #define QCA808X_MMD3_CDT_DIAG_PAIR_A 0x8065
  219. #define QCA808X_MMD3_CDT_DIAG_PAIR_B 0x8066
  220. #define QCA808X_MMD3_CDT_DIAG_PAIR_C 0x8067
  221. #define QCA808X_MMD3_CDT_DIAG_PAIR_D 0x8068
  222. #define QCA808X_CDT_DIAG_LENGTH GENMASK(7, 0)
  223. #define QCA808X_CDT_CODE_PAIR_A GENMASK(15, 12)
  224. #define QCA808X_CDT_CODE_PAIR_B GENMASK(11, 8)
  225. #define QCA808X_CDT_CODE_PAIR_C GENMASK(7, 4)
  226. #define QCA808X_CDT_CODE_PAIR_D GENMASK(3, 0)
  227. #define QCA808X_CDT_STATUS_STAT_FAIL 0
  228. #define QCA808X_CDT_STATUS_STAT_NORMAL 1
  229. #define QCA808X_CDT_STATUS_STAT_OPEN 2
  230. #define QCA808X_CDT_STATUS_STAT_SHORT 3
  231. MODULE_DESCRIPTION("Qualcomm Atheros AR803x and QCA808X PHY driver");
  232. MODULE_AUTHOR("Matus Ujhelyi");
  233. MODULE_LICENSE("GPL");
  234. enum stat_access_type {
  235. PHY,
  236. MMD
  237. };
  238. struct at803x_hw_stat {
  239. const char *string;
  240. u8 reg;
  241. u32 mask;
  242. enum stat_access_type access_type;
  243. };
  244. static struct at803x_hw_stat at803x_hw_stats[] = {
  245. { "phy_idle_errors", 0xa, GENMASK(7, 0), PHY},
  246. { "phy_receive_errors", 0x15, GENMASK(15, 0), PHY},
  247. { "eee_wake_errors", 0x16, GENMASK(15, 0), MMD},
  248. };
  249. struct at803x_priv {
  250. int flags;
  251. u16 clk_25m_reg;
  252. u16 clk_25m_mask;
  253. u8 smarteee_lpi_tw_1g;
  254. u8 smarteee_lpi_tw_100m;
  255. bool is_fiber;
  256. bool is_1000basex;
  257. struct regulator_dev *vddio_rdev;
  258. struct regulator_dev *vddh_rdev;
  259. u64 stats[ARRAY_SIZE(at803x_hw_stats)];
  260. };
  261. struct at803x_context {
  262. u16 bmcr;
  263. u16 advertise;
  264. u16 control1000;
  265. u16 int_enable;
  266. u16 smart_speed;
  267. u16 led_control;
  268. };
  269. static int at803x_debug_reg_write(struct phy_device *phydev, u16 reg, u16 data)
  270. {
  271. int ret;
  272. ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg);
  273. if (ret < 0)
  274. return ret;
  275. return phy_write(phydev, AT803X_DEBUG_DATA, data);
  276. }
  277. static int at803x_debug_reg_read(struct phy_device *phydev, u16 reg)
  278. {
  279. int ret;
  280. ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg);
  281. if (ret < 0)
  282. return ret;
  283. return phy_read(phydev, AT803X_DEBUG_DATA);
  284. }
  285. static int at803x_debug_reg_mask(struct phy_device *phydev, u16 reg,
  286. u16 clear, u16 set)
  287. {
  288. u16 val;
  289. int ret;
  290. ret = at803x_debug_reg_read(phydev, reg);
  291. if (ret < 0)
  292. return ret;
  293. val = ret & 0xffff;
  294. val &= ~clear;
  295. val |= set;
  296. return phy_write(phydev, AT803X_DEBUG_DATA, val);
  297. }
  298. static int at803x_write_page(struct phy_device *phydev, int page)
  299. {
  300. int mask;
  301. int set;
  302. if (page == AT803X_PAGE_COPPER) {
  303. set = AT803X_BT_BX_REG_SEL;
  304. mask = 0;
  305. } else {
  306. set = 0;
  307. mask = AT803X_BT_BX_REG_SEL;
  308. }
  309. return __phy_modify(phydev, AT803X_REG_CHIP_CONFIG, mask, set);
  310. }
  311. static int at803x_read_page(struct phy_device *phydev)
  312. {
  313. int ccr = __phy_read(phydev, AT803X_REG_CHIP_CONFIG);
  314. if (ccr < 0)
  315. return ccr;
  316. if (ccr & AT803X_BT_BX_REG_SEL)
  317. return AT803X_PAGE_COPPER;
  318. return AT803X_PAGE_FIBER;
  319. }
  320. static int at803x_enable_rx_delay(struct phy_device *phydev)
  321. {
  322. return at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, 0,
  323. AT803X_DEBUG_RX_CLK_DLY_EN);
  324. }
  325. static int at803x_enable_tx_delay(struct phy_device *phydev)
  326. {
  327. return at803x_debug_reg_mask(phydev, AT803X_DEBUG_SYSTEM_CTRL_MODE, 0,
  328. AT803X_DEBUG_TX_CLK_DLY_EN);
  329. }
  330. static int at803x_disable_rx_delay(struct phy_device *phydev)
  331. {
  332. return at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL,
  333. AT803X_DEBUG_RX_CLK_DLY_EN, 0);
  334. }
  335. static int at803x_disable_tx_delay(struct phy_device *phydev)
  336. {
  337. return at803x_debug_reg_mask(phydev, AT803X_DEBUG_SYSTEM_CTRL_MODE,
  338. AT803X_DEBUG_TX_CLK_DLY_EN, 0);
  339. }
  340. /* save relevant PHY registers to private copy */
  341. static void at803x_context_save(struct phy_device *phydev,
  342. struct at803x_context *context)
  343. {
  344. context->bmcr = phy_read(phydev, MII_BMCR);
  345. context->advertise = phy_read(phydev, MII_ADVERTISE);
  346. context->control1000 = phy_read(phydev, MII_CTRL1000);
  347. context->int_enable = phy_read(phydev, AT803X_INTR_ENABLE);
  348. context->smart_speed = phy_read(phydev, AT803X_SMART_SPEED);
  349. context->led_control = phy_read(phydev, AT803X_LED_CONTROL);
  350. }
  351. /* restore relevant PHY registers from private copy */
  352. static void at803x_context_restore(struct phy_device *phydev,
  353. const struct at803x_context *context)
  354. {
  355. phy_write(phydev, MII_BMCR, context->bmcr);
  356. phy_write(phydev, MII_ADVERTISE, context->advertise);
  357. phy_write(phydev, MII_CTRL1000, context->control1000);
  358. phy_write(phydev, AT803X_INTR_ENABLE, context->int_enable);
  359. phy_write(phydev, AT803X_SMART_SPEED, context->smart_speed);
  360. phy_write(phydev, AT803X_LED_CONTROL, context->led_control);
  361. }
  362. static int at803x_set_wol(struct phy_device *phydev,
  363. struct ethtool_wolinfo *wol)
  364. {
  365. int ret, irq_enabled;
  366. if (wol->wolopts & WAKE_MAGIC) {
  367. struct net_device *ndev = phydev->attached_dev;
  368. const u8 *mac;
  369. unsigned int i;
  370. static const unsigned int offsets[] = {
  371. AT803X_LOC_MAC_ADDR_32_47_OFFSET,
  372. AT803X_LOC_MAC_ADDR_16_31_OFFSET,
  373. AT803X_LOC_MAC_ADDR_0_15_OFFSET,
  374. };
  375. if (!ndev)
  376. return -ENODEV;
  377. mac = (const u8 *) ndev->dev_addr;
  378. if (!is_valid_ether_addr(mac))
  379. return -EINVAL;
  380. for (i = 0; i < 3; i++)
  381. phy_write_mmd(phydev, MDIO_MMD_PCS, offsets[i],
  382. mac[(i * 2) + 1] | (mac[(i * 2)] << 8));
  383. /* Enable WOL function for 1588 */
  384. if (phydev->drv->phy_id == ATH8031_PHY_ID) {
  385. ret = phy_modify_mmd(phydev, MDIO_MMD_PCS,
  386. AT803X_PHY_MMD3_WOL_CTRL,
  387. 0, AT803X_WOL_EN);
  388. if (ret)
  389. return ret;
  390. }
  391. /* Enable WOL interrupt */
  392. ret = phy_modify(phydev, AT803X_INTR_ENABLE, 0, AT803X_INTR_ENABLE_WOL);
  393. if (ret)
  394. return ret;
  395. } else {
  396. /* Disable WoL function for 1588 */
  397. if (phydev->drv->phy_id == ATH8031_PHY_ID) {
  398. ret = phy_modify_mmd(phydev, MDIO_MMD_PCS,
  399. AT803X_PHY_MMD3_WOL_CTRL,
  400. AT803X_WOL_EN, 0);
  401. if (ret)
  402. return ret;
  403. }
  404. /* Disable WOL interrupt */
  405. ret = phy_modify(phydev, AT803X_INTR_ENABLE, AT803X_INTR_ENABLE_WOL, 0);
  406. if (ret)
  407. return ret;
  408. }
  409. /* Clear WOL status */
  410. ret = phy_read(phydev, AT803X_INTR_STATUS);
  411. if (ret < 0)
  412. return ret;
  413. /* Check if there are other interrupts except for WOL triggered when PHY is
  414. * in interrupt mode, only the interrupts enabled by AT803X_INTR_ENABLE can
  415. * be passed up to the interrupt PIN.
  416. */
  417. irq_enabled = phy_read(phydev, AT803X_INTR_ENABLE);
  418. if (irq_enabled < 0)
  419. return irq_enabled;
  420. irq_enabled &= ~AT803X_INTR_ENABLE_WOL;
  421. if (ret & irq_enabled && !phy_polling_mode(phydev))
  422. phy_trigger_machine(phydev);
  423. return 0;
  424. }
  425. static void at803x_get_wol(struct phy_device *phydev,
  426. struct ethtool_wolinfo *wol)
  427. {
  428. int value;
  429. wol->supported = WAKE_MAGIC;
  430. wol->wolopts = 0;
  431. value = phy_read(phydev, AT803X_INTR_ENABLE);
  432. if (value < 0)
  433. return;
  434. if (value & AT803X_INTR_ENABLE_WOL)
  435. wol->wolopts |= WAKE_MAGIC;
  436. }
  437. static int at803x_get_sset_count(struct phy_device *phydev)
  438. {
  439. return ARRAY_SIZE(at803x_hw_stats);
  440. }
  441. static void at803x_get_strings(struct phy_device *phydev, u8 *data)
  442. {
  443. int i;
  444. for (i = 0; i < ARRAY_SIZE(at803x_hw_stats); i++) {
  445. strscpy(data + i * ETH_GSTRING_LEN,
  446. at803x_hw_stats[i].string, ETH_GSTRING_LEN);
  447. }
  448. }
  449. static u64 at803x_get_stat(struct phy_device *phydev, int i)
  450. {
  451. struct at803x_hw_stat stat = at803x_hw_stats[i];
  452. struct at803x_priv *priv = phydev->priv;
  453. int val;
  454. u64 ret;
  455. if (stat.access_type == MMD)
  456. val = phy_read_mmd(phydev, MDIO_MMD_PCS, stat.reg);
  457. else
  458. val = phy_read(phydev, stat.reg);
  459. if (val < 0) {
  460. ret = U64_MAX;
  461. } else {
  462. val = val & stat.mask;
  463. priv->stats[i] += val;
  464. ret = priv->stats[i];
  465. }
  466. return ret;
  467. }
  468. static void at803x_get_stats(struct phy_device *phydev,
  469. struct ethtool_stats *stats, u64 *data)
  470. {
  471. int i;
  472. for (i = 0; i < ARRAY_SIZE(at803x_hw_stats); i++)
  473. data[i] = at803x_get_stat(phydev, i);
  474. }
  475. static int at803x_suspend(struct phy_device *phydev)
  476. {
  477. int value;
  478. int wol_enabled;
  479. value = phy_read(phydev, AT803X_INTR_ENABLE);
  480. wol_enabled = value & AT803X_INTR_ENABLE_WOL;
  481. if (wol_enabled)
  482. value = BMCR_ISOLATE;
  483. else
  484. value = BMCR_PDOWN;
  485. phy_modify(phydev, MII_BMCR, 0, value);
  486. return 0;
  487. }
  488. static int at803x_resume(struct phy_device *phydev)
  489. {
  490. return phy_modify(phydev, MII_BMCR, BMCR_PDOWN | BMCR_ISOLATE, 0);
  491. }
  492. static int at803x_rgmii_reg_set_voltage_sel(struct regulator_dev *rdev,
  493. unsigned int selector)
  494. {
  495. struct phy_device *phydev = rdev_get_drvdata(rdev);
  496. if (selector)
  497. return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
  498. 0, AT803X_DEBUG_RGMII_1V8);
  499. else
  500. return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
  501. AT803X_DEBUG_RGMII_1V8, 0);
  502. }
  503. static int at803x_rgmii_reg_get_voltage_sel(struct regulator_dev *rdev)
  504. {
  505. struct phy_device *phydev = rdev_get_drvdata(rdev);
  506. int val;
  507. val = at803x_debug_reg_read(phydev, AT803X_DEBUG_REG_1F);
  508. if (val < 0)
  509. return val;
  510. return (val & AT803X_DEBUG_RGMII_1V8) ? 1 : 0;
  511. }
  512. static const struct regulator_ops vddio_regulator_ops = {
  513. .list_voltage = regulator_list_voltage_table,
  514. .set_voltage_sel = at803x_rgmii_reg_set_voltage_sel,
  515. .get_voltage_sel = at803x_rgmii_reg_get_voltage_sel,
  516. };
  517. static const unsigned int vddio_voltage_table[] = {
  518. 1500000,
  519. 1800000,
  520. };
  521. static const struct regulator_desc vddio_desc = {
  522. .name = "vddio",
  523. .of_match = of_match_ptr("vddio-regulator"),
  524. .n_voltages = ARRAY_SIZE(vddio_voltage_table),
  525. .volt_table = vddio_voltage_table,
  526. .ops = &vddio_regulator_ops,
  527. .type = REGULATOR_VOLTAGE,
  528. .owner = THIS_MODULE,
  529. };
  530. static const struct regulator_ops vddh_regulator_ops = {
  531. };
  532. static const struct regulator_desc vddh_desc = {
  533. .name = "vddh",
  534. .of_match = of_match_ptr("vddh-regulator"),
  535. .n_voltages = 1,
  536. .fixed_uV = 2500000,
  537. .ops = &vddh_regulator_ops,
  538. .type = REGULATOR_VOLTAGE,
  539. .owner = THIS_MODULE,
  540. };
  541. static int at8031_register_regulators(struct phy_device *phydev)
  542. {
  543. struct at803x_priv *priv = phydev->priv;
  544. struct device *dev = &phydev->mdio.dev;
  545. struct regulator_config config = { };
  546. config.dev = dev;
  547. config.driver_data = phydev;
  548. priv->vddio_rdev = devm_regulator_register(dev, &vddio_desc, &config);
  549. if (IS_ERR(priv->vddio_rdev)) {
  550. phydev_err(phydev, "failed to register VDDIO regulator\n");
  551. return PTR_ERR(priv->vddio_rdev);
  552. }
  553. priv->vddh_rdev = devm_regulator_register(dev, &vddh_desc, &config);
  554. if (IS_ERR(priv->vddh_rdev)) {
  555. phydev_err(phydev, "failed to register VDDH regulator\n");
  556. return PTR_ERR(priv->vddh_rdev);
  557. }
  558. return 0;
  559. }
  560. static int at803x_sfp_insert(void *upstream, const struct sfp_eeprom_id *id)
  561. {
  562. struct phy_device *phydev = upstream;
  563. __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_support);
  564. __ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support);
  565. DECLARE_PHY_INTERFACE_MASK(interfaces);
  566. phy_interface_t iface;
  567. linkmode_zero(phy_support);
  568. phylink_set(phy_support, 1000baseX_Full);
  569. phylink_set(phy_support, 1000baseT_Full);
  570. phylink_set(phy_support, Autoneg);
  571. phylink_set(phy_support, Pause);
  572. phylink_set(phy_support, Asym_Pause);
  573. linkmode_zero(sfp_support);
  574. sfp_parse_support(phydev->sfp_bus, id, sfp_support, interfaces);
  575. /* Some modules support 10G modes as well as others we support.
  576. * Mask out non-supported modes so the correct interface is picked.
  577. */
  578. linkmode_and(sfp_support, phy_support, sfp_support);
  579. if (linkmode_empty(sfp_support)) {
  580. dev_err(&phydev->mdio.dev, "incompatible SFP module inserted\n");
  581. return -EINVAL;
  582. }
  583. iface = sfp_select_interface(phydev->sfp_bus, sfp_support);
  584. /* Only 1000Base-X is supported by AR8031/8033 as the downstream SerDes
  585. * interface for use with SFP modules.
  586. * However, some copper modules detected as having a preferred SGMII
  587. * interface do default to and function in 1000Base-X mode, so just
  588. * print a warning and allow such modules, as they may have some chance
  589. * of working.
  590. */
  591. if (iface == PHY_INTERFACE_MODE_SGMII)
  592. dev_warn(&phydev->mdio.dev, "module may not function if 1000Base-X not supported\n");
  593. else if (iface != PHY_INTERFACE_MODE_1000BASEX)
  594. return -EINVAL;
  595. return 0;
  596. }
  597. static const struct sfp_upstream_ops at803x_sfp_ops = {
  598. .attach = phy_sfp_attach,
  599. .detach = phy_sfp_detach,
  600. .module_insert = at803x_sfp_insert,
  601. };
  602. static int at803x_parse_dt(struct phy_device *phydev)
  603. {
  604. struct device_node *node = phydev->mdio.dev.of_node;
  605. struct at803x_priv *priv = phydev->priv;
  606. u32 freq, strength, tw;
  607. unsigned int sel;
  608. int ret;
  609. if (!IS_ENABLED(CONFIG_OF_MDIO))
  610. return 0;
  611. if (of_property_read_bool(node, "qca,disable-smarteee"))
  612. priv->flags |= AT803X_DISABLE_SMARTEEE;
  613. if (of_property_read_bool(node, "qca,disable-hibernation-mode"))
  614. priv->flags |= AT803X_DISABLE_HIBERNATION_MODE;
  615. if (!of_property_read_u32(node, "qca,smarteee-tw-us-1g", &tw)) {
  616. if (!tw || tw > 255) {
  617. phydev_err(phydev, "invalid qca,smarteee-tw-us-1g\n");
  618. return -EINVAL;
  619. }
  620. priv->smarteee_lpi_tw_1g = tw;
  621. }
  622. if (!of_property_read_u32(node, "qca,smarteee-tw-us-100m", &tw)) {
  623. if (!tw || tw > 255) {
  624. phydev_err(phydev, "invalid qca,smarteee-tw-us-100m\n");
  625. return -EINVAL;
  626. }
  627. priv->smarteee_lpi_tw_100m = tw;
  628. }
  629. ret = of_property_read_u32(node, "qca,clk-out-frequency", &freq);
  630. if (!ret) {
  631. switch (freq) {
  632. case 25000000:
  633. sel = AT803X_CLK_OUT_25MHZ_XTAL;
  634. break;
  635. case 50000000:
  636. sel = AT803X_CLK_OUT_50MHZ_PLL;
  637. break;
  638. case 62500000:
  639. sel = AT803X_CLK_OUT_62_5MHZ_PLL;
  640. break;
  641. case 125000000:
  642. sel = AT803X_CLK_OUT_125MHZ_PLL;
  643. break;
  644. default:
  645. phydev_err(phydev, "invalid qca,clk-out-frequency\n");
  646. return -EINVAL;
  647. }
  648. priv->clk_25m_reg |= FIELD_PREP(AT803X_CLK_OUT_MASK, sel);
  649. priv->clk_25m_mask |= AT803X_CLK_OUT_MASK;
  650. /* Fixup for the AR8030/AR8035. This chip has another mask and
  651. * doesn't support the DSP reference. Eg. the lowest bit of the
  652. * mask. The upper two bits select the same frequencies. Mask
  653. * the lowest bit here.
  654. *
  655. * Warning:
  656. * There was no datasheet for the AR8030 available so this is
  657. * just a guess. But the AR8035 is listed as pin compatible
  658. * to the AR8030 so there might be a good chance it works on
  659. * the AR8030 too.
  660. */
  661. if (phydev->drv->phy_id == ATH8030_PHY_ID ||
  662. phydev->drv->phy_id == ATH8035_PHY_ID) {
  663. priv->clk_25m_reg &= AT8035_CLK_OUT_MASK;
  664. priv->clk_25m_mask &= AT8035_CLK_OUT_MASK;
  665. }
  666. }
  667. ret = of_property_read_u32(node, "qca,clk-out-strength", &strength);
  668. if (!ret) {
  669. priv->clk_25m_mask |= AT803X_CLK_OUT_STRENGTH_MASK;
  670. switch (strength) {
  671. case AR803X_STRENGTH_FULL:
  672. priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_FULL;
  673. break;
  674. case AR803X_STRENGTH_HALF:
  675. priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_HALF;
  676. break;
  677. case AR803X_STRENGTH_QUARTER:
  678. priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_QUARTER;
  679. break;
  680. default:
  681. phydev_err(phydev, "invalid qca,clk-out-strength\n");
  682. return -EINVAL;
  683. }
  684. }
  685. /* Only supported on AR8031/AR8033, the AR8030/AR8035 use strapping
  686. * options.
  687. */
  688. if (phydev->drv->phy_id == ATH8031_PHY_ID) {
  689. if (of_property_read_bool(node, "qca,keep-pll-enabled"))
  690. priv->flags |= AT803X_KEEP_PLL_ENABLED;
  691. ret = at8031_register_regulators(phydev);
  692. if (ret < 0)
  693. return ret;
  694. ret = devm_regulator_get_enable_optional(&phydev->mdio.dev,
  695. "vddio");
  696. if (ret) {
  697. phydev_err(phydev, "failed to get VDDIO regulator\n");
  698. return ret;
  699. }
  700. /* Only AR8031/8033 support 1000Base-X for SFP modules */
  701. ret = phy_sfp_probe(phydev, &at803x_sfp_ops);
  702. if (ret < 0)
  703. return ret;
  704. }
  705. return 0;
  706. }
  707. static int at803x_probe(struct phy_device *phydev)
  708. {
  709. struct device *dev = &phydev->mdio.dev;
  710. struct at803x_priv *priv;
  711. int ret;
  712. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  713. if (!priv)
  714. return -ENOMEM;
  715. phydev->priv = priv;
  716. ret = at803x_parse_dt(phydev);
  717. if (ret)
  718. return ret;
  719. if (phydev->drv->phy_id == ATH8031_PHY_ID) {
  720. int ccr = phy_read(phydev, AT803X_REG_CHIP_CONFIG);
  721. int mode_cfg;
  722. if (ccr < 0)
  723. return ccr;
  724. mode_cfg = ccr & AT803X_MODE_CFG_MASK;
  725. switch (mode_cfg) {
  726. case AT803X_MODE_CFG_BX1000_RGMII_50OHM:
  727. case AT803X_MODE_CFG_BX1000_RGMII_75OHM:
  728. priv->is_1000basex = true;
  729. fallthrough;
  730. case AT803X_MODE_CFG_FX100_RGMII_50OHM:
  731. case AT803X_MODE_CFG_FX100_RGMII_75OHM:
  732. priv->is_fiber = true;
  733. break;
  734. }
  735. /* Disable WoL in 1588 register which is enabled
  736. * by default
  737. */
  738. ret = phy_modify_mmd(phydev, MDIO_MMD_PCS,
  739. AT803X_PHY_MMD3_WOL_CTRL,
  740. AT803X_WOL_EN, 0);
  741. if (ret)
  742. return ret;
  743. }
  744. return 0;
  745. }
  746. static int at803x_get_features(struct phy_device *phydev)
  747. {
  748. struct at803x_priv *priv = phydev->priv;
  749. int err;
  750. err = genphy_read_abilities(phydev);
  751. if (err)
  752. return err;
  753. if (phydev->drv->phy_id == QCA8081_PHY_ID) {
  754. err = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PMA_NG_EXTABLE);
  755. if (err < 0)
  756. return err;
  757. linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->supported,
  758. err & MDIO_PMA_NG_EXTABLE_2_5GBT);
  759. }
  760. if (phydev->drv->phy_id != ATH8031_PHY_ID)
  761. return 0;
  762. /* AR8031/AR8033 have different status registers
  763. * for copper and fiber operation. However, the
  764. * extended status register is the same for both
  765. * operation modes.
  766. *
  767. * As a result of that, ESTATUS_1000_XFULL is set
  768. * to 1 even when operating in copper TP mode.
  769. *
  770. * Remove this mode from the supported link modes
  771. * when not operating in 1000BaseX mode.
  772. */
  773. if (!priv->is_1000basex)
  774. linkmode_clear_bit(ETHTOOL_LINK_MODE_1000baseX_Full_BIT,
  775. phydev->supported);
  776. return 0;
  777. }
  778. static int at803x_smarteee_config(struct phy_device *phydev)
  779. {
  780. struct at803x_priv *priv = phydev->priv;
  781. u16 mask = 0, val = 0;
  782. int ret;
  783. if (priv->flags & AT803X_DISABLE_SMARTEEE)
  784. return phy_modify_mmd(phydev, MDIO_MMD_PCS,
  785. AT803X_MMD3_SMARTEEE_CTL3,
  786. AT803X_MMD3_SMARTEEE_CTL3_LPI_EN, 0);
  787. if (priv->smarteee_lpi_tw_1g) {
  788. mask |= 0xff00;
  789. val |= priv->smarteee_lpi_tw_1g << 8;
  790. }
  791. if (priv->smarteee_lpi_tw_100m) {
  792. mask |= 0x00ff;
  793. val |= priv->smarteee_lpi_tw_100m;
  794. }
  795. if (!mask)
  796. return 0;
  797. ret = phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_MMD3_SMARTEEE_CTL1,
  798. mask, val);
  799. if (ret)
  800. return ret;
  801. return phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_MMD3_SMARTEEE_CTL3,
  802. AT803X_MMD3_SMARTEEE_CTL3_LPI_EN,
  803. AT803X_MMD3_SMARTEEE_CTL3_LPI_EN);
  804. }
  805. static int at803x_clk_out_config(struct phy_device *phydev)
  806. {
  807. struct at803x_priv *priv = phydev->priv;
  808. if (!priv->clk_25m_mask)
  809. return 0;
  810. return phy_modify_mmd(phydev, MDIO_MMD_AN, AT803X_MMD7_CLK25M,
  811. priv->clk_25m_mask, priv->clk_25m_reg);
  812. }
  813. static int at8031_pll_config(struct phy_device *phydev)
  814. {
  815. struct at803x_priv *priv = phydev->priv;
  816. /* The default after hardware reset is PLL OFF. After a soft reset, the
  817. * values are retained.
  818. */
  819. if (priv->flags & AT803X_KEEP_PLL_ENABLED)
  820. return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
  821. 0, AT803X_DEBUG_PLL_ON);
  822. else
  823. return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
  824. AT803X_DEBUG_PLL_ON, 0);
  825. }
  826. static int at803x_hibernation_mode_config(struct phy_device *phydev)
  827. {
  828. struct at803x_priv *priv = phydev->priv;
  829. /* The default after hardware reset is hibernation mode enabled. After
  830. * software reset, the value is retained.
  831. */
  832. if (!(priv->flags & AT803X_DISABLE_HIBERNATION_MODE))
  833. return 0;
  834. return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_HIB_CTRL,
  835. AT803X_DEBUG_HIB_CTRL_PS_HIB_EN, 0);
  836. }
  837. static int at803x_config_init(struct phy_device *phydev)
  838. {
  839. struct at803x_priv *priv = phydev->priv;
  840. int ret;
  841. if (phydev->drv->phy_id == ATH8031_PHY_ID) {
  842. /* Some bootloaders leave the fiber page selected.
  843. * Switch to the appropriate page (fiber or copper), as otherwise we
  844. * read the PHY capabilities from the wrong page.
  845. */
  846. phy_lock_mdio_bus(phydev);
  847. ret = at803x_write_page(phydev,
  848. priv->is_fiber ? AT803X_PAGE_FIBER :
  849. AT803X_PAGE_COPPER);
  850. phy_unlock_mdio_bus(phydev);
  851. if (ret)
  852. return ret;
  853. ret = at8031_pll_config(phydev);
  854. if (ret < 0)
  855. return ret;
  856. }
  857. /* The RX and TX delay default is:
  858. * after HW reset: RX delay enabled and TX delay disabled
  859. * after SW reset: RX delay enabled, while TX delay retains the
  860. * value before reset.
  861. */
  862. if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
  863. phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
  864. ret = at803x_enable_rx_delay(phydev);
  865. else
  866. ret = at803x_disable_rx_delay(phydev);
  867. if (ret < 0)
  868. return ret;
  869. if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
  870. phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
  871. ret = at803x_enable_tx_delay(phydev);
  872. else
  873. ret = at803x_disable_tx_delay(phydev);
  874. if (ret < 0)
  875. return ret;
  876. ret = at803x_smarteee_config(phydev);
  877. if (ret < 0)
  878. return ret;
  879. ret = at803x_clk_out_config(phydev);
  880. if (ret < 0)
  881. return ret;
  882. ret = at803x_hibernation_mode_config(phydev);
  883. if (ret < 0)
  884. return ret;
  885. /* Ar803x extended next page bit is enabled by default. Cisco
  886. * multigig switches read this bit and attempt to negotiate 10Gbps
  887. * rates even if the next page bit is disabled. This is incorrect
  888. * behaviour but we still need to accommodate it. XNP is only needed
  889. * for 10Gbps support, so disable XNP.
  890. */
  891. return phy_modify(phydev, MII_ADVERTISE, MDIO_AN_CTRL1_XNP, 0);
  892. }
  893. static int at803x_ack_interrupt(struct phy_device *phydev)
  894. {
  895. int err;
  896. err = phy_read(phydev, AT803X_INTR_STATUS);
  897. return (err < 0) ? err : 0;
  898. }
  899. static int at803x_config_intr(struct phy_device *phydev)
  900. {
  901. struct at803x_priv *priv = phydev->priv;
  902. int err;
  903. int value;
  904. value = phy_read(phydev, AT803X_INTR_ENABLE);
  905. if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
  906. /* Clear any pending interrupts */
  907. err = at803x_ack_interrupt(phydev);
  908. if (err)
  909. return err;
  910. value |= AT803X_INTR_ENABLE_AUTONEG_ERR;
  911. value |= AT803X_INTR_ENABLE_SPEED_CHANGED;
  912. value |= AT803X_INTR_ENABLE_DUPLEX_CHANGED;
  913. value |= AT803X_INTR_ENABLE_LINK_FAIL;
  914. value |= AT803X_INTR_ENABLE_LINK_SUCCESS;
  915. if (priv->is_fiber) {
  916. value |= AT803X_INTR_ENABLE_LINK_FAIL_BX;
  917. value |= AT803X_INTR_ENABLE_LINK_SUCCESS_BX;
  918. }
  919. err = phy_write(phydev, AT803X_INTR_ENABLE, value);
  920. } else {
  921. err = phy_write(phydev, AT803X_INTR_ENABLE, 0);
  922. if (err)
  923. return err;
  924. /* Clear any pending interrupts */
  925. err = at803x_ack_interrupt(phydev);
  926. }
  927. return err;
  928. }
  929. static irqreturn_t at803x_handle_interrupt(struct phy_device *phydev)
  930. {
  931. int irq_status, int_enabled;
  932. irq_status = phy_read(phydev, AT803X_INTR_STATUS);
  933. if (irq_status < 0) {
  934. phy_error(phydev);
  935. return IRQ_NONE;
  936. }
  937. /* Read the current enabled interrupts */
  938. int_enabled = phy_read(phydev, AT803X_INTR_ENABLE);
  939. if (int_enabled < 0) {
  940. phy_error(phydev);
  941. return IRQ_NONE;
  942. }
  943. /* See if this was one of our enabled interrupts */
  944. if (!(irq_status & int_enabled))
  945. return IRQ_NONE;
  946. phy_trigger_machine(phydev);
  947. return IRQ_HANDLED;
  948. }
  949. static void at803x_link_change_notify(struct phy_device *phydev)
  950. {
  951. /*
  952. * Conduct a hardware reset for AT8030 every time a link loss is
  953. * signalled. This is necessary to circumvent a hardware bug that
  954. * occurs when the cable is unplugged while TX packets are pending
  955. * in the FIFO. In such cases, the FIFO enters an error mode it
  956. * cannot recover from by software.
  957. */
  958. if (phydev->state == PHY_NOLINK && phydev->mdio.reset_gpio) {
  959. struct at803x_context context;
  960. at803x_context_save(phydev, &context);
  961. phy_device_reset(phydev, 1);
  962. msleep(1);
  963. phy_device_reset(phydev, 0);
  964. msleep(1);
  965. at803x_context_restore(phydev, &context);
  966. phydev_dbg(phydev, "%s(): phy was reset\n", __func__);
  967. }
  968. }
  969. static int at803x_read_specific_status(struct phy_device *phydev)
  970. {
  971. int ss;
  972. /* Read the AT8035 PHY-Specific Status register, which indicates the
  973. * speed and duplex that the PHY is actually using, irrespective of
  974. * whether we are in autoneg mode or not.
  975. */
  976. ss = phy_read(phydev, AT803X_SPECIFIC_STATUS);
  977. if (ss < 0)
  978. return ss;
  979. if (ss & AT803X_SS_SPEED_DUPLEX_RESOLVED) {
  980. int sfc, speed;
  981. sfc = phy_read(phydev, AT803X_SPECIFIC_FUNCTION_CONTROL);
  982. if (sfc < 0)
  983. return sfc;
  984. /* qca8081 takes the different bits for speed value from at803x */
  985. if (phydev->drv->phy_id == QCA8081_PHY_ID)
  986. speed = FIELD_GET(QCA808X_SS_SPEED_MASK, ss);
  987. else
  988. speed = FIELD_GET(AT803X_SS_SPEED_MASK, ss);
  989. switch (speed) {
  990. case AT803X_SS_SPEED_10:
  991. phydev->speed = SPEED_10;
  992. break;
  993. case AT803X_SS_SPEED_100:
  994. phydev->speed = SPEED_100;
  995. break;
  996. case AT803X_SS_SPEED_1000:
  997. phydev->speed = SPEED_1000;
  998. break;
  999. case QCA808X_SS_SPEED_2500:
  1000. phydev->speed = SPEED_2500;
  1001. break;
  1002. }
  1003. if (ss & AT803X_SS_DUPLEX)
  1004. phydev->duplex = DUPLEX_FULL;
  1005. else
  1006. phydev->duplex = DUPLEX_HALF;
  1007. if (ss & AT803X_SS_MDIX)
  1008. phydev->mdix = ETH_TP_MDI_X;
  1009. else
  1010. phydev->mdix = ETH_TP_MDI;
  1011. switch (FIELD_GET(AT803X_SFC_MDI_CROSSOVER_MODE_M, sfc)) {
  1012. case AT803X_SFC_MANUAL_MDI:
  1013. phydev->mdix_ctrl = ETH_TP_MDI;
  1014. break;
  1015. case AT803X_SFC_MANUAL_MDIX:
  1016. phydev->mdix_ctrl = ETH_TP_MDI_X;
  1017. break;
  1018. case AT803X_SFC_AUTOMATIC_CROSSOVER:
  1019. phydev->mdix_ctrl = ETH_TP_MDI_AUTO;
  1020. break;
  1021. }
  1022. }
  1023. return 0;
  1024. }
  1025. static int at803x_read_status(struct phy_device *phydev)
  1026. {
  1027. struct at803x_priv *priv = phydev->priv;
  1028. int err, old_link = phydev->link;
  1029. if (priv->is_1000basex)
  1030. return genphy_c37_read_status(phydev);
  1031. /* Update the link, but return if there was an error */
  1032. err = genphy_update_link(phydev);
  1033. if (err)
  1034. return err;
  1035. /* why bother the PHY if nothing can have changed */
  1036. if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link)
  1037. return 0;
  1038. phydev->speed = SPEED_UNKNOWN;
  1039. phydev->duplex = DUPLEX_UNKNOWN;
  1040. phydev->pause = 0;
  1041. phydev->asym_pause = 0;
  1042. err = genphy_read_lpa(phydev);
  1043. if (err < 0)
  1044. return err;
  1045. err = at803x_read_specific_status(phydev);
  1046. if (err < 0)
  1047. return err;
  1048. if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete)
  1049. phy_resolve_aneg_pause(phydev);
  1050. return 0;
  1051. }
  1052. static int at803x_config_mdix(struct phy_device *phydev, u8 ctrl)
  1053. {
  1054. u16 val;
  1055. switch (ctrl) {
  1056. case ETH_TP_MDI:
  1057. val = AT803X_SFC_MANUAL_MDI;
  1058. break;
  1059. case ETH_TP_MDI_X:
  1060. val = AT803X_SFC_MANUAL_MDIX;
  1061. break;
  1062. case ETH_TP_MDI_AUTO:
  1063. val = AT803X_SFC_AUTOMATIC_CROSSOVER;
  1064. break;
  1065. default:
  1066. return 0;
  1067. }
  1068. return phy_modify_changed(phydev, AT803X_SPECIFIC_FUNCTION_CONTROL,
  1069. AT803X_SFC_MDI_CROSSOVER_MODE_M,
  1070. FIELD_PREP(AT803X_SFC_MDI_CROSSOVER_MODE_M, val));
  1071. }
  1072. static int at803x_config_aneg(struct phy_device *phydev)
  1073. {
  1074. struct at803x_priv *priv = phydev->priv;
  1075. int ret;
  1076. ret = at803x_config_mdix(phydev, phydev->mdix_ctrl);
  1077. if (ret < 0)
  1078. return ret;
  1079. /* Changes of the midx bits are disruptive to the normal operation;
  1080. * therefore any changes to these registers must be followed by a
  1081. * software reset to take effect.
  1082. */
  1083. if (ret == 1) {
  1084. ret = genphy_soft_reset(phydev);
  1085. if (ret < 0)
  1086. return ret;
  1087. }
  1088. if (priv->is_1000basex)
  1089. return genphy_c37_config_aneg(phydev);
  1090. /* Do not restart auto-negotiation by setting ret to 0 defautly,
  1091. * when calling __genphy_config_aneg later.
  1092. */
  1093. ret = 0;
  1094. if (phydev->drv->phy_id == QCA8081_PHY_ID) {
  1095. int phy_ctrl = 0;
  1096. /* The reg MII_BMCR also needs to be configured for force mode, the
  1097. * genphy_config_aneg is also needed.
  1098. */
  1099. if (phydev->autoneg == AUTONEG_DISABLE)
  1100. genphy_c45_pma_setup_forced(phydev);
  1101. if (linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->advertising))
  1102. phy_ctrl = MDIO_AN_10GBT_CTRL_ADV2_5G;
  1103. ret = phy_modify_mmd_changed(phydev, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL,
  1104. MDIO_AN_10GBT_CTRL_ADV2_5G, phy_ctrl);
  1105. if (ret < 0)
  1106. return ret;
  1107. }
  1108. return __genphy_config_aneg(phydev, ret);
  1109. }
  1110. static int at803x_get_downshift(struct phy_device *phydev, u8 *d)
  1111. {
  1112. int val;
  1113. val = phy_read(phydev, AT803X_SMART_SPEED);
  1114. if (val < 0)
  1115. return val;
  1116. if (val & AT803X_SMART_SPEED_ENABLE)
  1117. *d = FIELD_GET(AT803X_SMART_SPEED_RETRY_LIMIT_MASK, val) + 2;
  1118. else
  1119. *d = DOWNSHIFT_DEV_DISABLE;
  1120. return 0;
  1121. }
  1122. static int at803x_set_downshift(struct phy_device *phydev, u8 cnt)
  1123. {
  1124. u16 mask, set;
  1125. int ret;
  1126. switch (cnt) {
  1127. case DOWNSHIFT_DEV_DEFAULT_COUNT:
  1128. cnt = AT803X_DEFAULT_DOWNSHIFT;
  1129. fallthrough;
  1130. case AT803X_MIN_DOWNSHIFT ... AT803X_MAX_DOWNSHIFT:
  1131. set = AT803X_SMART_SPEED_ENABLE |
  1132. AT803X_SMART_SPEED_BYPASS_TIMER |
  1133. FIELD_PREP(AT803X_SMART_SPEED_RETRY_LIMIT_MASK, cnt - 2);
  1134. mask = AT803X_SMART_SPEED_RETRY_LIMIT_MASK;
  1135. break;
  1136. case DOWNSHIFT_DEV_DISABLE:
  1137. set = 0;
  1138. mask = AT803X_SMART_SPEED_ENABLE |
  1139. AT803X_SMART_SPEED_BYPASS_TIMER;
  1140. break;
  1141. default:
  1142. return -EINVAL;
  1143. }
  1144. ret = phy_modify_changed(phydev, AT803X_SMART_SPEED, mask, set);
  1145. /* After changing the smart speed settings, we need to perform a
  1146. * software reset, use phy_init_hw() to make sure we set the
  1147. * reapply any values which might got lost during software reset.
  1148. */
  1149. if (ret == 1)
  1150. ret = phy_init_hw(phydev);
  1151. return ret;
  1152. }
  1153. static int at803x_get_tunable(struct phy_device *phydev,
  1154. struct ethtool_tunable *tuna, void *data)
  1155. {
  1156. switch (tuna->id) {
  1157. case ETHTOOL_PHY_DOWNSHIFT:
  1158. return at803x_get_downshift(phydev, data);
  1159. default:
  1160. return -EOPNOTSUPP;
  1161. }
  1162. }
  1163. static int at803x_set_tunable(struct phy_device *phydev,
  1164. struct ethtool_tunable *tuna, const void *data)
  1165. {
  1166. switch (tuna->id) {
  1167. case ETHTOOL_PHY_DOWNSHIFT:
  1168. return at803x_set_downshift(phydev, *(const u8 *)data);
  1169. default:
  1170. return -EOPNOTSUPP;
  1171. }
  1172. }
  1173. static int at803x_cable_test_result_trans(u16 status)
  1174. {
  1175. switch (FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status)) {
  1176. case AT803X_CDT_STATUS_STAT_NORMAL:
  1177. return ETHTOOL_A_CABLE_RESULT_CODE_OK;
  1178. case AT803X_CDT_STATUS_STAT_SHORT:
  1179. return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT;
  1180. case AT803X_CDT_STATUS_STAT_OPEN:
  1181. return ETHTOOL_A_CABLE_RESULT_CODE_OPEN;
  1182. case AT803X_CDT_STATUS_STAT_FAIL:
  1183. default:
  1184. return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC;
  1185. }
  1186. }
  1187. static bool at803x_cdt_test_failed(u16 status)
  1188. {
  1189. return FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status) ==
  1190. AT803X_CDT_STATUS_STAT_FAIL;
  1191. }
  1192. static bool at803x_cdt_fault_length_valid(u16 status)
  1193. {
  1194. switch (FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status)) {
  1195. case AT803X_CDT_STATUS_STAT_OPEN:
  1196. case AT803X_CDT_STATUS_STAT_SHORT:
  1197. return true;
  1198. }
  1199. return false;
  1200. }
  1201. static int at803x_cdt_fault_length(u16 status)
  1202. {
  1203. int dt;
  1204. /* According to the datasheet the distance to the fault is
  1205. * DELTA_TIME * 0.824 meters.
  1206. *
  1207. * The author suspect the correct formula is:
  1208. *
  1209. * fault_distance = DELTA_TIME * (c * VF) / 125MHz / 2
  1210. *
  1211. * where c is the speed of light, VF is the velocity factor of
  1212. * the twisted pair cable, 125MHz the counter frequency and
  1213. * we need to divide by 2 because the hardware will measure the
  1214. * round trip time to the fault and back to the PHY.
  1215. *
  1216. * With a VF of 0.69 we get the factor 0.824 mentioned in the
  1217. * datasheet.
  1218. */
  1219. dt = FIELD_GET(AT803X_CDT_STATUS_DELTA_TIME_MASK, status);
  1220. return (dt * 824) / 10;
  1221. }
  1222. static int at803x_cdt_start(struct phy_device *phydev, int pair)
  1223. {
  1224. u16 cdt;
  1225. /* qca8081 takes the different bit 15 to enable CDT test */
  1226. if (phydev->drv->phy_id == QCA8081_PHY_ID)
  1227. cdt = QCA808X_CDT_ENABLE_TEST |
  1228. QCA808X_CDT_LENGTH_UNIT |
  1229. QCA808X_CDT_INTER_CHECK_DIS;
  1230. else
  1231. cdt = FIELD_PREP(AT803X_CDT_MDI_PAIR_MASK, pair) |
  1232. AT803X_CDT_ENABLE_TEST;
  1233. return phy_write(phydev, AT803X_CDT, cdt);
  1234. }
  1235. static int at803x_cdt_wait_for_completion(struct phy_device *phydev)
  1236. {
  1237. int val, ret;
  1238. u16 cdt_en;
  1239. if (phydev->drv->phy_id == QCA8081_PHY_ID)
  1240. cdt_en = QCA808X_CDT_ENABLE_TEST;
  1241. else
  1242. cdt_en = AT803X_CDT_ENABLE_TEST;
  1243. /* One test run takes about 25ms */
  1244. ret = phy_read_poll_timeout(phydev, AT803X_CDT, val,
  1245. !(val & cdt_en),
  1246. 30000, 100000, true);
  1247. return ret < 0 ? ret : 0;
  1248. }
  1249. static int at803x_cable_test_one_pair(struct phy_device *phydev, int pair)
  1250. {
  1251. static const int ethtool_pair[] = {
  1252. ETHTOOL_A_CABLE_PAIR_A,
  1253. ETHTOOL_A_CABLE_PAIR_B,
  1254. ETHTOOL_A_CABLE_PAIR_C,
  1255. ETHTOOL_A_CABLE_PAIR_D,
  1256. };
  1257. int ret, val;
  1258. ret = at803x_cdt_start(phydev, pair);
  1259. if (ret)
  1260. return ret;
  1261. ret = at803x_cdt_wait_for_completion(phydev);
  1262. if (ret)
  1263. return ret;
  1264. val = phy_read(phydev, AT803X_CDT_STATUS);
  1265. if (val < 0)
  1266. return val;
  1267. if (at803x_cdt_test_failed(val))
  1268. return 0;
  1269. ethnl_cable_test_result(phydev, ethtool_pair[pair],
  1270. at803x_cable_test_result_trans(val));
  1271. if (at803x_cdt_fault_length_valid(val))
  1272. ethnl_cable_test_fault_length(phydev, ethtool_pair[pair],
  1273. at803x_cdt_fault_length(val));
  1274. return 1;
  1275. }
  1276. static int at803x_cable_test_get_status(struct phy_device *phydev,
  1277. bool *finished)
  1278. {
  1279. unsigned long pair_mask;
  1280. int retries = 20;
  1281. int pair, ret;
  1282. if (phydev->phy_id == ATH9331_PHY_ID ||
  1283. phydev->phy_id == ATH8032_PHY_ID ||
  1284. phydev->phy_id == QCA9561_PHY_ID)
  1285. pair_mask = 0x3;
  1286. else
  1287. pair_mask = 0xf;
  1288. *finished = false;
  1289. /* According to the datasheet the CDT can be performed when
  1290. * there is no link partner or when the link partner is
  1291. * auto-negotiating. Starting the test will restart the AN
  1292. * automatically. It seems that doing this repeatedly we will
  1293. * get a slot where our link partner won't disturb our
  1294. * measurement.
  1295. */
  1296. while (pair_mask && retries--) {
  1297. for_each_set_bit(pair, &pair_mask, 4) {
  1298. ret = at803x_cable_test_one_pair(phydev, pair);
  1299. if (ret < 0)
  1300. return ret;
  1301. if (ret)
  1302. clear_bit(pair, &pair_mask);
  1303. }
  1304. if (pair_mask)
  1305. msleep(250);
  1306. }
  1307. *finished = true;
  1308. return 0;
  1309. }
  1310. static int at803x_cable_test_start(struct phy_device *phydev)
  1311. {
  1312. /* Enable auto-negotiation, but advertise no capabilities, no link
  1313. * will be established. A restart of the auto-negotiation is not
  1314. * required, because the cable test will automatically break the link.
  1315. */
  1316. phy_write(phydev, MII_BMCR, BMCR_ANENABLE);
  1317. phy_write(phydev, MII_ADVERTISE, ADVERTISE_CSMA);
  1318. if (phydev->phy_id != ATH9331_PHY_ID &&
  1319. phydev->phy_id != ATH8032_PHY_ID &&
  1320. phydev->phy_id != QCA9561_PHY_ID)
  1321. phy_write(phydev, MII_CTRL1000, 0);
  1322. /* we do all the (time consuming) work later */
  1323. return 0;
  1324. }
  1325. static int qca83xx_config_init(struct phy_device *phydev)
  1326. {
  1327. u8 switch_revision;
  1328. switch_revision = phydev->dev_flags & QCA8K_DEVFLAGS_REVISION_MASK;
  1329. switch (switch_revision) {
  1330. case 1:
  1331. /* For 100M waveform */
  1332. at803x_debug_reg_write(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, 0x02ea);
  1333. /* Turn on Gigabit clock */
  1334. at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_GREEN, 0x68a0);
  1335. break;
  1336. case 2:
  1337. phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0x0);
  1338. fallthrough;
  1339. case 4:
  1340. phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_AZ_DEBUG, 0x803f);
  1341. at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_GREEN, 0x6860);
  1342. at803x_debug_reg_write(phydev, AT803X_DEBUG_SYSTEM_CTRL_MODE, 0x2c46);
  1343. at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_3C, 0x6000);
  1344. break;
  1345. }
  1346. /* QCA8327 require DAC amplitude adjustment for 100m set to +6%.
  1347. * Disable on init and enable only with 100m speed following
  1348. * qca original source code.
  1349. */
  1350. if (phydev->drv->phy_id == QCA8327_A_PHY_ID ||
  1351. phydev->drv->phy_id == QCA8327_B_PHY_ID)
  1352. at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL,
  1353. QCA8327_DEBUG_MANU_CTRL_EN, 0);
  1354. /* Following original QCA sourcecode set port to prefer master */
  1355. phy_set_bits(phydev, MII_CTRL1000, CTL1000_PREFER_MASTER);
  1356. return 0;
  1357. }
  1358. static void qca83xx_link_change_notify(struct phy_device *phydev)
  1359. {
  1360. /* QCA8337 doesn't require DAC Amplitude adjustement */
  1361. if (phydev->drv->phy_id == QCA8337_PHY_ID)
  1362. return;
  1363. /* Set DAC Amplitude adjustment to +6% for 100m on link running */
  1364. if (phydev->state == PHY_RUNNING) {
  1365. if (phydev->speed == SPEED_100)
  1366. at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL,
  1367. QCA8327_DEBUG_MANU_CTRL_EN,
  1368. QCA8327_DEBUG_MANU_CTRL_EN);
  1369. } else {
  1370. /* Reset DAC Amplitude adjustment */
  1371. at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL,
  1372. QCA8327_DEBUG_MANU_CTRL_EN, 0);
  1373. }
  1374. }
  1375. static int qca83xx_resume(struct phy_device *phydev)
  1376. {
  1377. int ret, val;
  1378. /* Skip reset if not suspended */
  1379. if (!phydev->suspended)
  1380. return 0;
  1381. /* Reinit the port, reset values set by suspend */
  1382. qca83xx_config_init(phydev);
  1383. /* Reset the port on port resume */
  1384. phy_set_bits(phydev, MII_BMCR, BMCR_RESET | BMCR_ANENABLE);
  1385. /* On resume from suspend the switch execute a reset and
  1386. * restart auto-negotiation. Wait for reset to complete.
  1387. */
  1388. ret = phy_read_poll_timeout(phydev, MII_BMCR, val, !(val & BMCR_RESET),
  1389. 50000, 600000, true);
  1390. if (ret)
  1391. return ret;
  1392. msleep(1);
  1393. return 0;
  1394. }
  1395. static int qca83xx_suspend(struct phy_device *phydev)
  1396. {
  1397. u16 mask = 0;
  1398. /* Only QCA8337 support actual suspend.
  1399. * QCA8327 cause port unreliability when phy suspend
  1400. * is set.
  1401. */
  1402. if (phydev->drv->phy_id == QCA8337_PHY_ID) {
  1403. genphy_suspend(phydev);
  1404. } else {
  1405. mask |= ~(BMCR_SPEED1000 | BMCR_FULLDPLX);
  1406. phy_modify(phydev, MII_BMCR, mask, 0);
  1407. }
  1408. at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_GREEN,
  1409. AT803X_DEBUG_GATE_CLK_IN1000, 0);
  1410. at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_HIB_CTRL,
  1411. AT803X_DEBUG_HIB_CTRL_EN_ANY_CHANGE |
  1412. AT803X_DEBUG_HIB_CTRL_SEL_RST_80U, 0);
  1413. return 0;
  1414. }
  1415. static int qca808x_phy_fast_retrain_config(struct phy_device *phydev)
  1416. {
  1417. int ret;
  1418. /* Enable fast retrain */
  1419. ret = genphy_c45_fast_retrain(phydev, true);
  1420. if (ret)
  1421. return ret;
  1422. phy_write_mmd(phydev, MDIO_MMD_AN, QCA808X_PHY_MMD7_TOP_OPTION1,
  1423. QCA808X_TOP_OPTION1_DATA);
  1424. phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_20DB,
  1425. QCA808X_MSE_THRESHOLD_20DB_VALUE);
  1426. phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_17DB,
  1427. QCA808X_MSE_THRESHOLD_17DB_VALUE);
  1428. phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_27DB,
  1429. QCA808X_MSE_THRESHOLD_27DB_VALUE);
  1430. phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_28DB,
  1431. QCA808X_MSE_THRESHOLD_28DB_VALUE);
  1432. phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_1,
  1433. QCA808X_MMD3_DEBUG_1_VALUE);
  1434. phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_4,
  1435. QCA808X_MMD3_DEBUG_4_VALUE);
  1436. phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_5,
  1437. QCA808X_MMD3_DEBUG_5_VALUE);
  1438. phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_3,
  1439. QCA808X_MMD3_DEBUG_3_VALUE);
  1440. phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_6,
  1441. QCA808X_MMD3_DEBUG_6_VALUE);
  1442. phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_2,
  1443. QCA808X_MMD3_DEBUG_2_VALUE);
  1444. return 0;
  1445. }
  1446. static int qca808x_phy_ms_random_seed_set(struct phy_device *phydev)
  1447. {
  1448. u16 seed_value = prandom_u32_max(QCA808X_MASTER_SLAVE_SEED_RANGE);
  1449. return at803x_debug_reg_mask(phydev, QCA808X_PHY_DEBUG_LOCAL_SEED,
  1450. QCA808X_MASTER_SLAVE_SEED_CFG,
  1451. FIELD_PREP(QCA808X_MASTER_SLAVE_SEED_CFG, seed_value));
  1452. }
  1453. static int qca808x_phy_ms_seed_enable(struct phy_device *phydev, bool enable)
  1454. {
  1455. u16 seed_enable = 0;
  1456. if (enable)
  1457. seed_enable = QCA808X_MASTER_SLAVE_SEED_ENABLE;
  1458. return at803x_debug_reg_mask(phydev, QCA808X_PHY_DEBUG_LOCAL_SEED,
  1459. QCA808X_MASTER_SLAVE_SEED_ENABLE, seed_enable);
  1460. }
  1461. static int qca808x_config_init(struct phy_device *phydev)
  1462. {
  1463. int ret;
  1464. /* Active adc&vga on 802.3az for the link 1000M and 100M */
  1465. ret = phy_modify_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_ADDR_CLD_CTRL7,
  1466. QCA808X_8023AZ_AFE_CTRL_MASK, QCA808X_8023AZ_AFE_EN);
  1467. if (ret)
  1468. return ret;
  1469. /* Adjust the threshold on 802.3az for the link 1000M */
  1470. ret = phy_write_mmd(phydev, MDIO_MMD_PCS,
  1471. QCA808X_PHY_MMD3_AZ_TRAINING_CTRL, QCA808X_MMD3_AZ_TRAINING_VAL);
  1472. if (ret)
  1473. return ret;
  1474. /* Config the fast retrain for the link 2500M */
  1475. ret = qca808x_phy_fast_retrain_config(phydev);
  1476. if (ret)
  1477. return ret;
  1478. /* Configure lower ramdom seed to make phy linked as slave mode */
  1479. ret = qca808x_phy_ms_random_seed_set(phydev);
  1480. if (ret)
  1481. return ret;
  1482. /* Enable seed */
  1483. ret = qca808x_phy_ms_seed_enable(phydev, true);
  1484. if (ret)
  1485. return ret;
  1486. /* Configure adc threshold as 100mv for the link 10M */
  1487. return at803x_debug_reg_mask(phydev, QCA808X_PHY_DEBUG_ADC_THRESHOLD,
  1488. QCA808X_ADC_THRESHOLD_MASK, QCA808X_ADC_THRESHOLD_100MV);
  1489. }
  1490. static int qca808x_read_status(struct phy_device *phydev)
  1491. {
  1492. int ret;
  1493. ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_10GBT_STAT);
  1494. if (ret < 0)
  1495. return ret;
  1496. linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->lp_advertising,
  1497. ret & MDIO_AN_10GBT_STAT_LP2_5G);
  1498. ret = genphy_read_status(phydev);
  1499. if (ret)
  1500. return ret;
  1501. ret = at803x_read_specific_status(phydev);
  1502. if (ret < 0)
  1503. return ret;
  1504. if (phydev->link) {
  1505. if (phydev->speed == SPEED_2500)
  1506. phydev->interface = PHY_INTERFACE_MODE_2500BASEX;
  1507. else
  1508. phydev->interface = PHY_INTERFACE_MODE_SGMII;
  1509. } else {
  1510. /* generate seed as a lower random value to make PHY linked as SLAVE easily,
  1511. * except for master/slave configuration fault detected.
  1512. * the reason for not putting this code into the function link_change_notify is
  1513. * the corner case where the link partner is also the qca8081 PHY and the seed
  1514. * value is configured as the same value, the link can't be up and no link change
  1515. * occurs.
  1516. */
  1517. if (phydev->master_slave_state == MASTER_SLAVE_STATE_ERR) {
  1518. qca808x_phy_ms_seed_enable(phydev, false);
  1519. } else {
  1520. qca808x_phy_ms_random_seed_set(phydev);
  1521. qca808x_phy_ms_seed_enable(phydev, true);
  1522. }
  1523. }
  1524. return 0;
  1525. }
  1526. static int qca808x_soft_reset(struct phy_device *phydev)
  1527. {
  1528. int ret;
  1529. ret = genphy_soft_reset(phydev);
  1530. if (ret < 0)
  1531. return ret;
  1532. return qca808x_phy_ms_seed_enable(phydev, true);
  1533. }
  1534. static bool qca808x_cdt_fault_length_valid(int cdt_code)
  1535. {
  1536. switch (cdt_code) {
  1537. case QCA808X_CDT_STATUS_STAT_SHORT:
  1538. case QCA808X_CDT_STATUS_STAT_OPEN:
  1539. return true;
  1540. default:
  1541. return false;
  1542. }
  1543. }
  1544. static int qca808x_cable_test_result_trans(int cdt_code)
  1545. {
  1546. switch (cdt_code) {
  1547. case QCA808X_CDT_STATUS_STAT_NORMAL:
  1548. return ETHTOOL_A_CABLE_RESULT_CODE_OK;
  1549. case QCA808X_CDT_STATUS_STAT_SHORT:
  1550. return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT;
  1551. case QCA808X_CDT_STATUS_STAT_OPEN:
  1552. return ETHTOOL_A_CABLE_RESULT_CODE_OPEN;
  1553. case QCA808X_CDT_STATUS_STAT_FAIL:
  1554. default:
  1555. return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC;
  1556. }
  1557. }
  1558. static int qca808x_cdt_fault_length(struct phy_device *phydev, int pair)
  1559. {
  1560. int val;
  1561. u32 cdt_length_reg = 0;
  1562. switch (pair) {
  1563. case ETHTOOL_A_CABLE_PAIR_A:
  1564. cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_A;
  1565. break;
  1566. case ETHTOOL_A_CABLE_PAIR_B:
  1567. cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_B;
  1568. break;
  1569. case ETHTOOL_A_CABLE_PAIR_C:
  1570. cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_C;
  1571. break;
  1572. case ETHTOOL_A_CABLE_PAIR_D:
  1573. cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_D;
  1574. break;
  1575. default:
  1576. return -EINVAL;
  1577. }
  1578. val = phy_read_mmd(phydev, MDIO_MMD_PCS, cdt_length_reg);
  1579. if (val < 0)
  1580. return val;
  1581. return (FIELD_GET(QCA808X_CDT_DIAG_LENGTH, val) * 824) / 10;
  1582. }
  1583. static int qca808x_cable_test_start(struct phy_device *phydev)
  1584. {
  1585. int ret;
  1586. /* perform CDT with the following configs:
  1587. * 1. disable hibernation.
  1588. * 2. force PHY working in MDI mode.
  1589. * 3. for PHY working in 1000BaseT.
  1590. * 4. configure the threshold.
  1591. */
  1592. ret = at803x_debug_reg_mask(phydev, QCA808X_DBG_AN_TEST, QCA808X_HIBERNATION_EN, 0);
  1593. if (ret < 0)
  1594. return ret;
  1595. ret = at803x_config_mdix(phydev, ETH_TP_MDI);
  1596. if (ret < 0)
  1597. return ret;
  1598. /* Force 1000base-T needs to configure PMA/PMD and MII_BMCR */
  1599. phydev->duplex = DUPLEX_FULL;
  1600. phydev->speed = SPEED_1000;
  1601. ret = genphy_c45_pma_setup_forced(phydev);
  1602. if (ret < 0)
  1603. return ret;
  1604. ret = genphy_setup_forced(phydev);
  1605. if (ret < 0)
  1606. return ret;
  1607. /* configure the thresholds for open, short, pair ok test */
  1608. phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8074, 0xc040);
  1609. phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8076, 0xc040);
  1610. phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8077, 0xa060);
  1611. phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8078, 0xc050);
  1612. phy_write_mmd(phydev, MDIO_MMD_PCS, 0x807a, 0xc060);
  1613. phy_write_mmd(phydev, MDIO_MMD_PCS, 0x807e, 0xb060);
  1614. return 0;
  1615. }
  1616. static int qca808x_cable_test_get_status(struct phy_device *phydev, bool *finished)
  1617. {
  1618. int ret, val;
  1619. int pair_a, pair_b, pair_c, pair_d;
  1620. *finished = false;
  1621. ret = at803x_cdt_start(phydev, 0);
  1622. if (ret)
  1623. return ret;
  1624. ret = at803x_cdt_wait_for_completion(phydev);
  1625. if (ret)
  1626. return ret;
  1627. val = phy_read_mmd(phydev, MDIO_MMD_PCS, QCA808X_MMD3_CDT_STATUS);
  1628. if (val < 0)
  1629. return val;
  1630. pair_a = FIELD_GET(QCA808X_CDT_CODE_PAIR_A, val);
  1631. pair_b = FIELD_GET(QCA808X_CDT_CODE_PAIR_B, val);
  1632. pair_c = FIELD_GET(QCA808X_CDT_CODE_PAIR_C, val);
  1633. pair_d = FIELD_GET(QCA808X_CDT_CODE_PAIR_D, val);
  1634. ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_A,
  1635. qca808x_cable_test_result_trans(pair_a));
  1636. ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_B,
  1637. qca808x_cable_test_result_trans(pair_b));
  1638. ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_C,
  1639. qca808x_cable_test_result_trans(pair_c));
  1640. ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_D,
  1641. qca808x_cable_test_result_trans(pair_d));
  1642. if (qca808x_cdt_fault_length_valid(pair_a))
  1643. ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_A,
  1644. qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_A));
  1645. if (qca808x_cdt_fault_length_valid(pair_b))
  1646. ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_B,
  1647. qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_B));
  1648. if (qca808x_cdt_fault_length_valid(pair_c))
  1649. ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_C,
  1650. qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_C));
  1651. if (qca808x_cdt_fault_length_valid(pair_d))
  1652. ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_D,
  1653. qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_D));
  1654. *finished = true;
  1655. return 0;
  1656. }
  1657. static struct phy_driver at803x_driver[] = {
  1658. {
  1659. /* Qualcomm Atheros AR8035 */
  1660. PHY_ID_MATCH_EXACT(ATH8035_PHY_ID),
  1661. .name = "Qualcomm Atheros AR8035",
  1662. .flags = PHY_POLL_CABLE_TEST,
  1663. .probe = at803x_probe,
  1664. .config_aneg = at803x_config_aneg,
  1665. .config_init = at803x_config_init,
  1666. .soft_reset = genphy_soft_reset,
  1667. .set_wol = at803x_set_wol,
  1668. .get_wol = at803x_get_wol,
  1669. .suspend = at803x_suspend,
  1670. .resume = at803x_resume,
  1671. /* PHY_GBIT_FEATURES */
  1672. .read_status = at803x_read_status,
  1673. .config_intr = at803x_config_intr,
  1674. .handle_interrupt = at803x_handle_interrupt,
  1675. .get_tunable = at803x_get_tunable,
  1676. .set_tunable = at803x_set_tunable,
  1677. .cable_test_start = at803x_cable_test_start,
  1678. .cable_test_get_status = at803x_cable_test_get_status,
  1679. }, {
  1680. /* Qualcomm Atheros AR8030 */
  1681. .phy_id = ATH8030_PHY_ID,
  1682. .name = "Qualcomm Atheros AR8030",
  1683. .phy_id_mask = AT8030_PHY_ID_MASK,
  1684. .probe = at803x_probe,
  1685. .config_init = at803x_config_init,
  1686. .link_change_notify = at803x_link_change_notify,
  1687. .set_wol = at803x_set_wol,
  1688. .get_wol = at803x_get_wol,
  1689. .suspend = at803x_suspend,
  1690. .resume = at803x_resume,
  1691. /* PHY_BASIC_FEATURES */
  1692. .config_intr = at803x_config_intr,
  1693. .handle_interrupt = at803x_handle_interrupt,
  1694. }, {
  1695. /* Qualcomm Atheros AR8031/AR8033 */
  1696. PHY_ID_MATCH_EXACT(ATH8031_PHY_ID),
  1697. .name = "Qualcomm Atheros AR8031/AR8033",
  1698. .flags = PHY_POLL_CABLE_TEST,
  1699. .probe = at803x_probe,
  1700. .config_init = at803x_config_init,
  1701. .config_aneg = at803x_config_aneg,
  1702. .soft_reset = genphy_soft_reset,
  1703. .set_wol = at803x_set_wol,
  1704. .get_wol = at803x_get_wol,
  1705. .suspend = at803x_suspend,
  1706. .resume = at803x_resume,
  1707. .read_page = at803x_read_page,
  1708. .write_page = at803x_write_page,
  1709. .get_features = at803x_get_features,
  1710. .read_status = at803x_read_status,
  1711. .config_intr = &at803x_config_intr,
  1712. .handle_interrupt = at803x_handle_interrupt,
  1713. .get_tunable = at803x_get_tunable,
  1714. .set_tunable = at803x_set_tunable,
  1715. .cable_test_start = at803x_cable_test_start,
  1716. .cable_test_get_status = at803x_cable_test_get_status,
  1717. }, {
  1718. /* Qualcomm Atheros AR8032 */
  1719. PHY_ID_MATCH_EXACT(ATH8032_PHY_ID),
  1720. .name = "Qualcomm Atheros AR8032",
  1721. .probe = at803x_probe,
  1722. .flags = PHY_POLL_CABLE_TEST,
  1723. .config_init = at803x_config_init,
  1724. .link_change_notify = at803x_link_change_notify,
  1725. .suspend = at803x_suspend,
  1726. .resume = at803x_resume,
  1727. /* PHY_BASIC_FEATURES */
  1728. .config_intr = at803x_config_intr,
  1729. .handle_interrupt = at803x_handle_interrupt,
  1730. .cable_test_start = at803x_cable_test_start,
  1731. .cable_test_get_status = at803x_cable_test_get_status,
  1732. }, {
  1733. /* ATHEROS AR9331 */
  1734. PHY_ID_MATCH_EXACT(ATH9331_PHY_ID),
  1735. .name = "Qualcomm Atheros AR9331 built-in PHY",
  1736. .probe = at803x_probe,
  1737. .suspend = at803x_suspend,
  1738. .resume = at803x_resume,
  1739. .flags = PHY_POLL_CABLE_TEST,
  1740. /* PHY_BASIC_FEATURES */
  1741. .config_intr = &at803x_config_intr,
  1742. .handle_interrupt = at803x_handle_interrupt,
  1743. .cable_test_start = at803x_cable_test_start,
  1744. .cable_test_get_status = at803x_cable_test_get_status,
  1745. .read_status = at803x_read_status,
  1746. .soft_reset = genphy_soft_reset,
  1747. .config_aneg = at803x_config_aneg,
  1748. }, {
  1749. /* Qualcomm Atheros QCA9561 */
  1750. PHY_ID_MATCH_EXACT(QCA9561_PHY_ID),
  1751. .name = "Qualcomm Atheros QCA9561 built-in PHY",
  1752. .probe = at803x_probe,
  1753. .suspend = at803x_suspend,
  1754. .resume = at803x_resume,
  1755. .flags = PHY_POLL_CABLE_TEST,
  1756. /* PHY_BASIC_FEATURES */
  1757. .config_intr = &at803x_config_intr,
  1758. .handle_interrupt = at803x_handle_interrupt,
  1759. .cable_test_start = at803x_cable_test_start,
  1760. .cable_test_get_status = at803x_cable_test_get_status,
  1761. .read_status = at803x_read_status,
  1762. .soft_reset = genphy_soft_reset,
  1763. .config_aneg = at803x_config_aneg,
  1764. }, {
  1765. /* QCA8337 */
  1766. .phy_id = QCA8337_PHY_ID,
  1767. .phy_id_mask = QCA8K_PHY_ID_MASK,
  1768. .name = "Qualcomm Atheros 8337 internal PHY",
  1769. /* PHY_GBIT_FEATURES */
  1770. .link_change_notify = qca83xx_link_change_notify,
  1771. .probe = at803x_probe,
  1772. .flags = PHY_IS_INTERNAL,
  1773. .config_init = qca83xx_config_init,
  1774. .soft_reset = genphy_soft_reset,
  1775. .get_sset_count = at803x_get_sset_count,
  1776. .get_strings = at803x_get_strings,
  1777. .get_stats = at803x_get_stats,
  1778. .suspend = qca83xx_suspend,
  1779. .resume = qca83xx_resume,
  1780. }, {
  1781. /* QCA8327-A from switch QCA8327-AL1A */
  1782. .phy_id = QCA8327_A_PHY_ID,
  1783. .phy_id_mask = QCA8K_PHY_ID_MASK,
  1784. .name = "Qualcomm Atheros 8327-A internal PHY",
  1785. /* PHY_GBIT_FEATURES */
  1786. .link_change_notify = qca83xx_link_change_notify,
  1787. .probe = at803x_probe,
  1788. .flags = PHY_IS_INTERNAL,
  1789. .config_init = qca83xx_config_init,
  1790. .soft_reset = genphy_soft_reset,
  1791. .get_sset_count = at803x_get_sset_count,
  1792. .get_strings = at803x_get_strings,
  1793. .get_stats = at803x_get_stats,
  1794. .suspend = qca83xx_suspend,
  1795. .resume = qca83xx_resume,
  1796. }, {
  1797. /* QCA8327-B from switch QCA8327-BL1A */
  1798. .phy_id = QCA8327_B_PHY_ID,
  1799. .phy_id_mask = QCA8K_PHY_ID_MASK,
  1800. .name = "Qualcomm Atheros 8327-B internal PHY",
  1801. /* PHY_GBIT_FEATURES */
  1802. .link_change_notify = qca83xx_link_change_notify,
  1803. .probe = at803x_probe,
  1804. .flags = PHY_IS_INTERNAL,
  1805. .config_init = qca83xx_config_init,
  1806. .soft_reset = genphy_soft_reset,
  1807. .get_sset_count = at803x_get_sset_count,
  1808. .get_strings = at803x_get_strings,
  1809. .get_stats = at803x_get_stats,
  1810. .suspend = qca83xx_suspend,
  1811. .resume = qca83xx_resume,
  1812. }, {
  1813. /* Qualcomm QCA8081 */
  1814. PHY_ID_MATCH_EXACT(QCA8081_PHY_ID),
  1815. .name = "Qualcomm QCA8081",
  1816. .flags = PHY_POLL_CABLE_TEST,
  1817. .probe = at803x_probe,
  1818. .config_intr = at803x_config_intr,
  1819. .handle_interrupt = at803x_handle_interrupt,
  1820. .get_tunable = at803x_get_tunable,
  1821. .set_tunable = at803x_set_tunable,
  1822. .set_wol = at803x_set_wol,
  1823. .get_wol = at803x_get_wol,
  1824. .get_features = at803x_get_features,
  1825. .config_aneg = at803x_config_aneg,
  1826. .suspend = genphy_suspend,
  1827. .resume = genphy_resume,
  1828. .read_status = qca808x_read_status,
  1829. .config_init = qca808x_config_init,
  1830. .soft_reset = qca808x_soft_reset,
  1831. .cable_test_start = qca808x_cable_test_start,
  1832. .cable_test_get_status = qca808x_cable_test_get_status,
  1833. }, };
  1834. module_phy_driver(at803x_driver);
  1835. static struct mdio_device_id __maybe_unused atheros_tbl[] = {
  1836. { ATH8030_PHY_ID, AT8030_PHY_ID_MASK },
  1837. { PHY_ID_MATCH_EXACT(ATH8031_PHY_ID) },
  1838. { PHY_ID_MATCH_EXACT(ATH8032_PHY_ID) },
  1839. { PHY_ID_MATCH_EXACT(ATH8035_PHY_ID) },
  1840. { PHY_ID_MATCH_EXACT(ATH9331_PHY_ID) },
  1841. { PHY_ID_MATCH_EXACT(QCA8337_PHY_ID) },
  1842. { PHY_ID_MATCH_EXACT(QCA8327_A_PHY_ID) },
  1843. { PHY_ID_MATCH_EXACT(QCA8327_B_PHY_ID) },
  1844. { PHY_ID_MATCH_EXACT(QCA9561_PHY_ID) },
  1845. { PHY_ID_MATCH_EXACT(QCA8081_PHY_ID) },
  1846. { }
  1847. };
  1848. MODULE_DEVICE_TABLE(mdio, atheros_tbl);