2
0

713-v6.9-03-net-phy-qcom-deatch-qca83xx-PHY-driver-from-at803x.patch 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. From 2e45d404d99d43bb7127b74b5dea8818df64996c Mon Sep 17 00:00:00 2001
  2. From: Christian Marangi <[email protected]>
  3. Date: Mon, 29 Jan 2024 15:15:21 +0100
  4. Subject: [PATCH 3/5] net: phy: qcom: deatch qca83xx PHY driver from at803x
  5. Deatch qca83xx PHY driver from at803x.
  6. The QCA83xx PHYs implement specific function and doesn't use generic
  7. at803x so it can be detached from the driver and moved to a dedicated
  8. one.
  9. Probe function and priv struct is reimplemented to allocate and use
  10. only the qca83xx specific data. Unused data from at803x PHY driver
  11. are dropped from at803x priv struct.
  12. This is to make slimmer PHY drivers instead of including lots of bloat
  13. that would never be used in specific SoC.
  14. A new Kconfig flag QCA83XX_PHY is introduced to compile the new
  15. introduced PHY driver.
  16. As the Kconfig name starts with Qualcomm the same order is kept.
  17. Signed-off-by: Christian Marangi <[email protected]>
  18. Reviewed-by: Andrew Lunn <[email protected]>
  19. Link: https://lore.kernel.org/r/[email protected]
  20. Signed-off-by: Jakub Kicinski <[email protected]>
  21. ---
  22. drivers/net/phy/qcom/Kconfig | 11 +-
  23. drivers/net/phy/qcom/Makefile | 1 +
  24. drivers/net/phy/qcom/at803x.c | 235 ----------------------------
  25. drivers/net/phy/qcom/qca83xx.c | 275 +++++++++++++++++++++++++++++++++
  26. 4 files changed, 284 insertions(+), 238 deletions(-)
  27. create mode 100644 drivers/net/phy/qcom/qca83xx.c
  28. --- a/drivers/net/phy/qcom/Kconfig
  29. +++ b/drivers/net/phy/qcom/Kconfig
  30. @@ -3,9 +3,14 @@ config QCOM_NET_PHYLIB
  31. tristate
  32. config AT803X_PHY
  33. - tristate "Qualcomm Atheros AR803X PHYs and QCA833x PHYs"
  34. + tristate "Qualcomm Atheros AR803X PHYs"
  35. select QCOM_NET_PHYLIB
  36. depends on REGULATOR
  37. help
  38. - Currently supports the AR8030, AR8031, AR8033, AR8035 and internal
  39. - QCA8337(Internal qca8k PHY) model
  40. + Currently supports the AR8030, AR8031, AR8033, AR8035 model
  41. +
  42. +config QCA83XX_PHY
  43. + tristate "Qualcomm Atheros QCA833x PHYs"
  44. + select QCOM_NET_PHYLIB
  45. + help
  46. + Currently supports the internal QCA8337(Internal qca8k PHY) model
  47. --- a/drivers/net/phy/qcom/Makefile
  48. +++ b/drivers/net/phy/qcom/Makefile
  49. @@ -1,3 +1,4 @@
  50. # SPDX-License-Identifier: GPL-2.0
  51. obj-$(CONFIG_QCOM_NET_PHYLIB) += qcom-phy-lib.o
  52. obj-$(CONFIG_AT803X_PHY) += at803x.o
  53. +obj-$(CONFIG_QCA83XX_PHY) += qca83xx.o
  54. --- a/drivers/net/phy/qcom/at803x.c
  55. +++ b/drivers/net/phy/qcom/at803x.c
  56. @@ -102,17 +102,10 @@
  57. #define AT803X_PSSR 0x11 /*PHY-Specific Status Register*/
  58. #define AT803X_PSSR_MR_AN_COMPLETE 0x0200
  59. -#define AT803X_DEBUG_REG_3C 0x3C
  60. -
  61. -#define AT803X_DEBUG_REG_GREEN 0x3D
  62. -#define AT803X_DEBUG_GATE_CLK_IN1000 BIT(6)
  63. -
  64. #define AT803X_DEBUG_REG_1F 0x1F
  65. #define AT803X_DEBUG_PLL_ON BIT(2)
  66. #define AT803X_DEBUG_RGMII_1V8 BIT(3)
  67. -#define MDIO_AZ_DEBUG 0x800D
  68. -
  69. /* AT803x supports either the XTAL input pad, an internal PLL or the
  70. * DSP as clock reference for the clock output pad. The XTAL reference
  71. * is only used for 25 MHz output, all other frequencies need the PLL.
  72. @@ -163,13 +156,7 @@
  73. #define QCA8081_PHY_ID 0x004dd101
  74. -#define QCA8327_A_PHY_ID 0x004dd033
  75. -#define QCA8327_B_PHY_ID 0x004dd034
  76. -#define QCA8337_PHY_ID 0x004dd036
  77. #define QCA9561_PHY_ID 0x004dd042
  78. -#define QCA8K_PHY_ID_MASK 0xffffffff
  79. -
  80. -#define QCA8K_DEVFLAGS_REVISION_MASK GENMASK(2, 0)
  81. #define AT803X_PAGE_FIBER 0
  82. #define AT803X_PAGE_COPPER 1
  83. @@ -379,12 +366,6 @@ MODULE_DESCRIPTION("Qualcomm Atheros AR8
  84. MODULE_AUTHOR("Matus Ujhelyi");
  85. MODULE_LICENSE("GPL");
  86. -static struct at803x_hw_stat qca83xx_hw_stats[] = {
  87. - { "phy_idle_errors", 0xa, GENMASK(7, 0), PHY},
  88. - { "phy_receive_errors", 0x15, GENMASK(15, 0), PHY},
  89. - { "eee_wake_errors", 0x16, GENMASK(15, 0), MMD},
  90. -};
  91. -
  92. struct at803x_ss_mask {
  93. u16 speed_mask;
  94. u8 speed_shift;
  95. @@ -400,7 +381,6 @@ struct at803x_priv {
  96. bool is_1000basex;
  97. struct regulator_dev *vddio_rdev;
  98. struct regulator_dev *vddh_rdev;
  99. - u64 stats[ARRAY_SIZE(qca83xx_hw_stats)];
  100. int led_polarity_mode;
  101. };
  102. @@ -564,53 +544,6 @@ static void at803x_get_wol(struct phy_de
  103. wol->wolopts |= WAKE_MAGIC;
  104. }
  105. -static int qca83xx_get_sset_count(struct phy_device *phydev)
  106. -{
  107. - return ARRAY_SIZE(qca83xx_hw_stats);
  108. -}
  109. -
  110. -static void qca83xx_get_strings(struct phy_device *phydev, u8 *data)
  111. -{
  112. - int i;
  113. -
  114. - for (i = 0; i < ARRAY_SIZE(qca83xx_hw_stats); i++) {
  115. - strscpy(data + i * ETH_GSTRING_LEN,
  116. - qca83xx_hw_stats[i].string, ETH_GSTRING_LEN);
  117. - }
  118. -}
  119. -
  120. -static u64 qca83xx_get_stat(struct phy_device *phydev, int i)
  121. -{
  122. - struct at803x_hw_stat stat = qca83xx_hw_stats[i];
  123. - struct at803x_priv *priv = phydev->priv;
  124. - int val;
  125. - u64 ret;
  126. -
  127. - if (stat.access_type == MMD)
  128. - val = phy_read_mmd(phydev, MDIO_MMD_PCS, stat.reg);
  129. - else
  130. - val = phy_read(phydev, stat.reg);
  131. -
  132. - if (val < 0) {
  133. - ret = U64_MAX;
  134. - } else {
  135. - val = val & stat.mask;
  136. - priv->stats[i] += val;
  137. - ret = priv->stats[i];
  138. - }
  139. -
  140. - return ret;
  141. -}
  142. -
  143. -static void qca83xx_get_stats(struct phy_device *phydev,
  144. - struct ethtool_stats *stats, u64 *data)
  145. -{
  146. - int i;
  147. -
  148. - for (i = 0; i < ARRAY_SIZE(qca83xx_hw_stats); i++)
  149. - data[i] = qca83xx_get_stat(phydev, i);
  150. -}
  151. -
  152. static int at803x_suspend(struct phy_device *phydev)
  153. {
  154. int value;
  155. @@ -1707,124 +1640,6 @@ static int at8035_probe(struct phy_devic
  156. return at8035_parse_dt(phydev);
  157. }
  158. -static int qca83xx_config_init(struct phy_device *phydev)
  159. -{
  160. - u8 switch_revision;
  161. -
  162. - switch_revision = phydev->dev_flags & QCA8K_DEVFLAGS_REVISION_MASK;
  163. -
  164. - switch (switch_revision) {
  165. - case 1:
  166. - /* For 100M waveform */
  167. - at803x_debug_reg_write(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, 0x02ea);
  168. - /* Turn on Gigabit clock */
  169. - at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_GREEN, 0x68a0);
  170. - break;
  171. -
  172. - case 2:
  173. - phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0x0);
  174. - fallthrough;
  175. - case 4:
  176. - phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_AZ_DEBUG, 0x803f);
  177. - at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_GREEN, 0x6860);
  178. - at803x_debug_reg_write(phydev, AT803X_DEBUG_SYSTEM_CTRL_MODE, 0x2c46);
  179. - at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_3C, 0x6000);
  180. - break;
  181. - }
  182. -
  183. - /* Following original QCA sourcecode set port to prefer master */
  184. - phy_set_bits(phydev, MII_CTRL1000, CTL1000_PREFER_MASTER);
  185. -
  186. - return 0;
  187. -}
  188. -
  189. -static int qca8327_config_init(struct phy_device *phydev)
  190. -{
  191. - /* QCA8327 require DAC amplitude adjustment for 100m set to +6%.
  192. - * Disable on init and enable only with 100m speed following
  193. - * qca original source code.
  194. - */
  195. - at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL,
  196. - QCA8327_DEBUG_MANU_CTRL_EN, 0);
  197. -
  198. - return qca83xx_config_init(phydev);
  199. -}
  200. -
  201. -static void qca83xx_link_change_notify(struct phy_device *phydev)
  202. -{
  203. - /* Set DAC Amplitude adjustment to +6% for 100m on link running */
  204. - if (phydev->state == PHY_RUNNING) {
  205. - if (phydev->speed == SPEED_100)
  206. - at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL,
  207. - QCA8327_DEBUG_MANU_CTRL_EN,
  208. - QCA8327_DEBUG_MANU_CTRL_EN);
  209. - } else {
  210. - /* Reset DAC Amplitude adjustment */
  211. - at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL,
  212. - QCA8327_DEBUG_MANU_CTRL_EN, 0);
  213. - }
  214. -}
  215. -
  216. -static int qca83xx_resume(struct phy_device *phydev)
  217. -{
  218. - int ret, val;
  219. -
  220. - /* Skip reset if not suspended */
  221. - if (!phydev->suspended)
  222. - return 0;
  223. -
  224. - /* Reinit the port, reset values set by suspend */
  225. - qca83xx_config_init(phydev);
  226. -
  227. - /* Reset the port on port resume */
  228. - phy_set_bits(phydev, MII_BMCR, BMCR_RESET | BMCR_ANENABLE);
  229. -
  230. - /* On resume from suspend the switch execute a reset and
  231. - * restart auto-negotiation. Wait for reset to complete.
  232. - */
  233. - ret = phy_read_poll_timeout(phydev, MII_BMCR, val, !(val & BMCR_RESET),
  234. - 50000, 600000, true);
  235. - if (ret)
  236. - return ret;
  237. -
  238. - usleep_range(1000, 2000);
  239. -
  240. - return 0;
  241. -}
  242. -
  243. -static int qca83xx_suspend(struct phy_device *phydev)
  244. -{
  245. - at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_GREEN,
  246. - AT803X_DEBUG_GATE_CLK_IN1000, 0);
  247. -
  248. - at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_HIB_CTRL,
  249. - AT803X_DEBUG_HIB_CTRL_EN_ANY_CHANGE |
  250. - AT803X_DEBUG_HIB_CTRL_SEL_RST_80U, 0);
  251. -
  252. - return 0;
  253. -}
  254. -
  255. -static int qca8337_suspend(struct phy_device *phydev)
  256. -{
  257. - /* Only QCA8337 support actual suspend. */
  258. - genphy_suspend(phydev);
  259. -
  260. - return qca83xx_suspend(phydev);
  261. -}
  262. -
  263. -static int qca8327_suspend(struct phy_device *phydev)
  264. -{
  265. - u16 mask = 0;
  266. -
  267. - /* QCA8327 cause port unreliability when phy suspend
  268. - * is set.
  269. - */
  270. - mask |= ~(BMCR_SPEED1000 | BMCR_FULLDPLX);
  271. - phy_modify(phydev, MII_BMCR, mask, 0);
  272. -
  273. - return qca83xx_suspend(phydev);
  274. -}
  275. -
  276. static int qca808x_phy_fast_retrain_config(struct phy_device *phydev)
  277. {
  278. int ret;
  279. @@ -2599,53 +2414,6 @@ static struct phy_driver at803x_driver[]
  280. .soft_reset = genphy_soft_reset,
  281. .config_aneg = at803x_config_aneg,
  282. }, {
  283. - /* QCA8337 */
  284. - .phy_id = QCA8337_PHY_ID,
  285. - .phy_id_mask = QCA8K_PHY_ID_MASK,
  286. - .name = "Qualcomm Atheros 8337 internal PHY",
  287. - /* PHY_GBIT_FEATURES */
  288. - .probe = at803x_probe,
  289. - .flags = PHY_IS_INTERNAL,
  290. - .config_init = qca83xx_config_init,
  291. - .soft_reset = genphy_soft_reset,
  292. - .get_sset_count = qca83xx_get_sset_count,
  293. - .get_strings = qca83xx_get_strings,
  294. - .get_stats = qca83xx_get_stats,
  295. - .suspend = qca8337_suspend,
  296. - .resume = qca83xx_resume,
  297. -}, {
  298. - /* QCA8327-A from switch QCA8327-AL1A */
  299. - .phy_id = QCA8327_A_PHY_ID,
  300. - .phy_id_mask = QCA8K_PHY_ID_MASK,
  301. - .name = "Qualcomm Atheros 8327-A internal PHY",
  302. - /* PHY_GBIT_FEATURES */
  303. - .link_change_notify = qca83xx_link_change_notify,
  304. - .probe = at803x_probe,
  305. - .flags = PHY_IS_INTERNAL,
  306. - .config_init = qca8327_config_init,
  307. - .soft_reset = genphy_soft_reset,
  308. - .get_sset_count = qca83xx_get_sset_count,
  309. - .get_strings = qca83xx_get_strings,
  310. - .get_stats = qca83xx_get_stats,
  311. - .suspend = qca8327_suspend,
  312. - .resume = qca83xx_resume,
  313. -}, {
  314. - /* QCA8327-B from switch QCA8327-BL1A */
  315. - .phy_id = QCA8327_B_PHY_ID,
  316. - .phy_id_mask = QCA8K_PHY_ID_MASK,
  317. - .name = "Qualcomm Atheros 8327-B internal PHY",
  318. - /* PHY_GBIT_FEATURES */
  319. - .link_change_notify = qca83xx_link_change_notify,
  320. - .probe = at803x_probe,
  321. - .flags = PHY_IS_INTERNAL,
  322. - .config_init = qca8327_config_init,
  323. - .soft_reset = genphy_soft_reset,
  324. - .get_sset_count = qca83xx_get_sset_count,
  325. - .get_strings = qca83xx_get_strings,
  326. - .get_stats = qca83xx_get_stats,
  327. - .suspend = qca8327_suspend,
  328. - .resume = qca83xx_resume,
  329. -}, {
  330. /* Qualcomm QCA8081 */
  331. PHY_ID_MATCH_EXACT(QCA8081_PHY_ID),
  332. .name = "Qualcomm QCA8081",
  333. @@ -2683,9 +2451,6 @@ static struct mdio_device_id __maybe_unu
  334. { PHY_ID_MATCH_EXACT(ATH8032_PHY_ID) },
  335. { PHY_ID_MATCH_EXACT(ATH8035_PHY_ID) },
  336. { PHY_ID_MATCH_EXACT(ATH9331_PHY_ID) },
  337. - { PHY_ID_MATCH_EXACT(QCA8337_PHY_ID) },
  338. - { PHY_ID_MATCH_EXACT(QCA8327_A_PHY_ID) },
  339. - { PHY_ID_MATCH_EXACT(QCA8327_B_PHY_ID) },
  340. { PHY_ID_MATCH_EXACT(QCA9561_PHY_ID) },
  341. { PHY_ID_MATCH_EXACT(QCA8081_PHY_ID) },
  342. { }
  343. --- /dev/null
  344. +++ b/drivers/net/phy/qcom/qca83xx.c
  345. @@ -0,0 +1,275 @@
  346. +// SPDX-License-Identifier: GPL-2.0+
  347. +
  348. +#include <linux/phy.h>
  349. +#include <linux/module.h>
  350. +
  351. +#include "qcom.h"
  352. +
  353. +#define AT803X_DEBUG_REG_3C 0x3C
  354. +
  355. +#define AT803X_DEBUG_REG_GREEN 0x3D
  356. +#define AT803X_DEBUG_GATE_CLK_IN1000 BIT(6)
  357. +
  358. +#define MDIO_AZ_DEBUG 0x800D
  359. +
  360. +#define QCA8327_A_PHY_ID 0x004dd033
  361. +#define QCA8327_B_PHY_ID 0x004dd034
  362. +#define QCA8337_PHY_ID 0x004dd036
  363. +#define QCA8K_PHY_ID_MASK 0xffffffff
  364. +
  365. +#define QCA8K_DEVFLAGS_REVISION_MASK GENMASK(2, 0)
  366. +
  367. +static struct at803x_hw_stat qca83xx_hw_stats[] = {
  368. + { "phy_idle_errors", 0xa, GENMASK(7, 0), PHY},
  369. + { "phy_receive_errors", 0x15, GENMASK(15, 0), PHY},
  370. + { "eee_wake_errors", 0x16, GENMASK(15, 0), MMD},
  371. +};
  372. +
  373. +struct qca83xx_priv {
  374. + u64 stats[ARRAY_SIZE(qca83xx_hw_stats)];
  375. +};
  376. +
  377. +MODULE_DESCRIPTION("Qualcomm Atheros QCA83XX PHY driver");
  378. +MODULE_AUTHOR("Matus Ujhelyi");
  379. +MODULE_AUTHOR("Christian Marangi <[email protected]>");
  380. +MODULE_LICENSE("GPL");
  381. +
  382. +static int qca83xx_get_sset_count(struct phy_device *phydev)
  383. +{
  384. + return ARRAY_SIZE(qca83xx_hw_stats);
  385. +}
  386. +
  387. +static void qca83xx_get_strings(struct phy_device *phydev, u8 *data)
  388. +{
  389. + int i;
  390. +
  391. + for (i = 0; i < ARRAY_SIZE(qca83xx_hw_stats); i++) {
  392. + strscpy(data + i * ETH_GSTRING_LEN,
  393. + qca83xx_hw_stats[i].string, ETH_GSTRING_LEN);
  394. + }
  395. +}
  396. +
  397. +static u64 qca83xx_get_stat(struct phy_device *phydev, int i)
  398. +{
  399. + struct at803x_hw_stat stat = qca83xx_hw_stats[i];
  400. + struct qca83xx_priv *priv = phydev->priv;
  401. + int val;
  402. + u64 ret;
  403. +
  404. + if (stat.access_type == MMD)
  405. + val = phy_read_mmd(phydev, MDIO_MMD_PCS, stat.reg);
  406. + else
  407. + val = phy_read(phydev, stat.reg);
  408. +
  409. + if (val < 0) {
  410. + ret = U64_MAX;
  411. + } else {
  412. + val = val & stat.mask;
  413. + priv->stats[i] += val;
  414. + ret = priv->stats[i];
  415. + }
  416. +
  417. + return ret;
  418. +}
  419. +
  420. +static void qca83xx_get_stats(struct phy_device *phydev,
  421. + struct ethtool_stats *stats, u64 *data)
  422. +{
  423. + int i;
  424. +
  425. + for (i = 0; i < ARRAY_SIZE(qca83xx_hw_stats); i++)
  426. + data[i] = qca83xx_get_stat(phydev, i);
  427. +}
  428. +
  429. +static int qca83xx_probe(struct phy_device *phydev)
  430. +{
  431. + struct device *dev = &phydev->mdio.dev;
  432. + struct qca83xx_priv *priv;
  433. +
  434. + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  435. + if (!priv)
  436. + return -ENOMEM;
  437. +
  438. + phydev->priv = priv;
  439. +
  440. + return 0;
  441. +}
  442. +
  443. +static int qca83xx_config_init(struct phy_device *phydev)
  444. +{
  445. + u8 switch_revision;
  446. +
  447. + switch_revision = phydev->dev_flags & QCA8K_DEVFLAGS_REVISION_MASK;
  448. +
  449. + switch (switch_revision) {
  450. + case 1:
  451. + /* For 100M waveform */
  452. + at803x_debug_reg_write(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, 0x02ea);
  453. + /* Turn on Gigabit clock */
  454. + at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_GREEN, 0x68a0);
  455. + break;
  456. +
  457. + case 2:
  458. + phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0x0);
  459. + fallthrough;
  460. + case 4:
  461. + phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_AZ_DEBUG, 0x803f);
  462. + at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_GREEN, 0x6860);
  463. + at803x_debug_reg_write(phydev, AT803X_DEBUG_SYSTEM_CTRL_MODE, 0x2c46);
  464. + at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_3C, 0x6000);
  465. + break;
  466. + }
  467. +
  468. + /* Following original QCA sourcecode set port to prefer master */
  469. + phy_set_bits(phydev, MII_CTRL1000, CTL1000_PREFER_MASTER);
  470. +
  471. + return 0;
  472. +}
  473. +
  474. +static int qca8327_config_init(struct phy_device *phydev)
  475. +{
  476. + /* QCA8327 require DAC amplitude adjustment for 100m set to +6%.
  477. + * Disable on init and enable only with 100m speed following
  478. + * qca original source code.
  479. + */
  480. + at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL,
  481. + QCA8327_DEBUG_MANU_CTRL_EN, 0);
  482. +
  483. + return qca83xx_config_init(phydev);
  484. +}
  485. +
  486. +static void qca83xx_link_change_notify(struct phy_device *phydev)
  487. +{
  488. + /* Set DAC Amplitude adjustment to +6% for 100m on link running */
  489. + if (phydev->state == PHY_RUNNING) {
  490. + if (phydev->speed == SPEED_100)
  491. + at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL,
  492. + QCA8327_DEBUG_MANU_CTRL_EN,
  493. + QCA8327_DEBUG_MANU_CTRL_EN);
  494. + } else {
  495. + /* Reset DAC Amplitude adjustment */
  496. + at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL,
  497. + QCA8327_DEBUG_MANU_CTRL_EN, 0);
  498. + }
  499. +}
  500. +
  501. +static int qca83xx_resume(struct phy_device *phydev)
  502. +{
  503. + int ret, val;
  504. +
  505. + /* Skip reset if not suspended */
  506. + if (!phydev->suspended)
  507. + return 0;
  508. +
  509. + /* Reinit the port, reset values set by suspend */
  510. + qca83xx_config_init(phydev);
  511. +
  512. + /* Reset the port on port resume */
  513. + phy_set_bits(phydev, MII_BMCR, BMCR_RESET | BMCR_ANENABLE);
  514. +
  515. + /* On resume from suspend the switch execute a reset and
  516. + * restart auto-negotiation. Wait for reset to complete.
  517. + */
  518. + ret = phy_read_poll_timeout(phydev, MII_BMCR, val, !(val & BMCR_RESET),
  519. + 50000, 600000, true);
  520. + if (ret)
  521. + return ret;
  522. +
  523. + usleep_range(1000, 2000);
  524. +
  525. + return 0;
  526. +}
  527. +
  528. +static int qca83xx_suspend(struct phy_device *phydev)
  529. +{
  530. + at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_GREEN,
  531. + AT803X_DEBUG_GATE_CLK_IN1000, 0);
  532. +
  533. + at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_HIB_CTRL,
  534. + AT803X_DEBUG_HIB_CTRL_EN_ANY_CHANGE |
  535. + AT803X_DEBUG_HIB_CTRL_SEL_RST_80U, 0);
  536. +
  537. + return 0;
  538. +}
  539. +
  540. +static int qca8337_suspend(struct phy_device *phydev)
  541. +{
  542. + /* Only QCA8337 support actual suspend. */
  543. + genphy_suspend(phydev);
  544. +
  545. + return qca83xx_suspend(phydev);
  546. +}
  547. +
  548. +static int qca8327_suspend(struct phy_device *phydev)
  549. +{
  550. + u16 mask = 0;
  551. +
  552. + /* QCA8327 cause port unreliability when phy suspend
  553. + * is set.
  554. + */
  555. + mask |= ~(BMCR_SPEED1000 | BMCR_FULLDPLX);
  556. + phy_modify(phydev, MII_BMCR, mask, 0);
  557. +
  558. + return qca83xx_suspend(phydev);
  559. +}
  560. +
  561. +static struct phy_driver qca83xx_driver[] = {
  562. +{
  563. + /* QCA8337 */
  564. + .phy_id = QCA8337_PHY_ID,
  565. + .phy_id_mask = QCA8K_PHY_ID_MASK,
  566. + .name = "Qualcomm Atheros 8337 internal PHY",
  567. + /* PHY_GBIT_FEATURES */
  568. + .probe = qca83xx_probe,
  569. + .flags = PHY_IS_INTERNAL,
  570. + .config_init = qca83xx_config_init,
  571. + .soft_reset = genphy_soft_reset,
  572. + .get_sset_count = qca83xx_get_sset_count,
  573. + .get_strings = qca83xx_get_strings,
  574. + .get_stats = qca83xx_get_stats,
  575. + .suspend = qca8337_suspend,
  576. + .resume = qca83xx_resume,
  577. +}, {
  578. + /* QCA8327-A from switch QCA8327-AL1A */
  579. + .phy_id = QCA8327_A_PHY_ID,
  580. + .phy_id_mask = QCA8K_PHY_ID_MASK,
  581. + .name = "Qualcomm Atheros 8327-A internal PHY",
  582. + /* PHY_GBIT_FEATURES */
  583. + .link_change_notify = qca83xx_link_change_notify,
  584. + .probe = qca83xx_probe,
  585. + .flags = PHY_IS_INTERNAL,
  586. + .config_init = qca8327_config_init,
  587. + .soft_reset = genphy_soft_reset,
  588. + .get_sset_count = qca83xx_get_sset_count,
  589. + .get_strings = qca83xx_get_strings,
  590. + .get_stats = qca83xx_get_stats,
  591. + .suspend = qca8327_suspend,
  592. + .resume = qca83xx_resume,
  593. +}, {
  594. + /* QCA8327-B from switch QCA8327-BL1A */
  595. + .phy_id = QCA8327_B_PHY_ID,
  596. + .phy_id_mask = QCA8K_PHY_ID_MASK,
  597. + .name = "Qualcomm Atheros 8327-B internal PHY",
  598. + /* PHY_GBIT_FEATURES */
  599. + .link_change_notify = qca83xx_link_change_notify,
  600. + .probe = qca83xx_probe,
  601. + .flags = PHY_IS_INTERNAL,
  602. + .config_init = qca8327_config_init,
  603. + .soft_reset = genphy_soft_reset,
  604. + .get_sset_count = qca83xx_get_sset_count,
  605. + .get_strings = qca83xx_get_strings,
  606. + .get_stats = qca83xx_get_stats,
  607. + .suspend = qca8327_suspend,
  608. + .resume = qca83xx_resume,
  609. +}, };
  610. +
  611. +module_phy_driver(qca83xx_driver);
  612. +
  613. +static struct mdio_device_id __maybe_unused qca83xx_tbl[] = {
  614. + { PHY_ID_MATCH_EXACT(QCA8337_PHY_ID) },
  615. + { PHY_ID_MATCH_EXACT(QCA8327_A_PHY_ID) },
  616. + { PHY_ID_MATCH_EXACT(QCA8327_B_PHY_ID) },
  617. + { }
  618. +};
  619. +
  620. +MODULE_DEVICE_TABLE(mdio, qca83xx_tbl);