aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandru Ardelean <alexandru.ardelean@analog.com>2019-08-16 09:10:08 -0400
committerDavid S. Miller <davem@davemloft.net>2019-08-16 14:56:26 -0400
commitfa5bd9c5f1cdb0fa90530113056f45d699009ede (patch)
treeb6ce7344ce39b5f813d56d9947824d250bb8e69d
parentc6aa697c41fd3bbd0d8697a7462109ffe605a867 (diff)
net: phy: adin: implement PHY subsystem software reset
The ADIN PHYs supports 4 types of reset: 1. The standard PHY reset via BMCR_RESET bit in MII_BMCR reg 2. Reset via GPIO 3. Reset via reg GeSftRst (0xff0c) & reload previous pin configs 4. Reset via reg GeSftRst (0xff0c) & request new pin configs Resets 2, 3 & 4 are almost identical, with the exception that the crystal oscillator is available during reset for 2. This change implements subsystem software reset via the GeSftRst and reloading the previous pin configuration (so reset number 3). This will also reset the PHY core regs (similar to reset 1). Since writing bit 1 to reg GeSftRst is self-clearing, the only thing that can be done, is to write to that register, wait a specific amount of time (10 milliseconds should be enough) and try to read back and check if there are no errors on read. A busy-wait-read won't work well, and may sometimes work or not work. In case phylib is configured to also do a reset via GPIO, the ADIN PHY may be reset twice when the PHY device registers, but that isn't a problem, since it's being done on boot (or PHY device register). Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/phy/adin.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/drivers/net/phy/adin.c b/drivers/net/phy/adin.c
index 131b7f85ae32..5622a393e7cf 100644
--- a/drivers/net/phy/adin.c
+++ b/drivers/net/phy/adin.c
@@ -6,6 +6,7 @@
6 */ 6 */
7#include <linux/kernel.h> 7#include <linux/kernel.h>
8#include <linux/bitfield.h> 8#include <linux/bitfield.h>
9#include <linux/delay.h>
9#include <linux/errno.h> 10#include <linux/errno.h>
10#include <linux/init.h> 11#include <linux/init.h>
11#include <linux/module.h> 12#include <linux/module.h>
@@ -50,6 +51,9 @@
50#define ADIN1300_CLOCK_STOP_REG 0x9400 51#define ADIN1300_CLOCK_STOP_REG 0x9400
51#define ADIN1300_LPI_WAKE_ERR_CNT_REG 0xa000 52#define ADIN1300_LPI_WAKE_ERR_CNT_REG 0xa000
52 53
54#define ADIN1300_GE_SOFT_RESET_REG 0xff0c
55#define ADIN1300_GE_SOFT_RESET BIT(0)
56
53#define ADIN1300_GE_RGMII_CFG_REG 0xff23 57#define ADIN1300_GE_RGMII_CFG_REG 0xff23
54#define ADIN1300_GE_RGMII_RX_MSK GENMASK(8, 6) 58#define ADIN1300_GE_RGMII_RX_MSK GENMASK(8, 6)
55#define ADIN1300_GE_RGMII_RX_SEL(x) \ 59#define ADIN1300_GE_RGMII_RX_SEL(x) \
@@ -442,11 +446,32 @@ static int adin_read_status(struct phy_device *phydev)
442 return genphy_read_status(phydev); 446 return genphy_read_status(phydev);
443} 447}
444 448
449static int adin_soft_reset(struct phy_device *phydev)
450{
451 int rc;
452
453 /* The reset bit is self-clearing, set it and wait */
454 rc = phy_set_bits_mmd(phydev, MDIO_MMD_VEND1,
455 ADIN1300_GE_SOFT_RESET_REG,
456 ADIN1300_GE_SOFT_RESET);
457 if (rc < 0)
458 return rc;
459
460 msleep(10);
461
462 /* If we get a read error something may be wrong */
463 rc = phy_read_mmd(phydev, MDIO_MMD_VEND1,
464 ADIN1300_GE_SOFT_RESET_REG);
465
466 return rc < 0 ? rc : 0;
467}
468
445static struct phy_driver adin_driver[] = { 469static struct phy_driver adin_driver[] = {
446 { 470 {
447 PHY_ID_MATCH_MODEL(PHY_ID_ADIN1200), 471 PHY_ID_MATCH_MODEL(PHY_ID_ADIN1200),
448 .name = "ADIN1200", 472 .name = "ADIN1200",
449 .config_init = adin_config_init, 473 .config_init = adin_config_init,
474 .soft_reset = adin_soft_reset,
450 .config_aneg = adin_config_aneg, 475 .config_aneg = adin_config_aneg,
451 .read_status = adin_read_status, 476 .read_status = adin_read_status,
452 .ack_interrupt = adin_phy_ack_intr, 477 .ack_interrupt = adin_phy_ack_intr,
@@ -460,6 +485,7 @@ static struct phy_driver adin_driver[] = {
460 PHY_ID_MATCH_MODEL(PHY_ID_ADIN1300), 485 PHY_ID_MATCH_MODEL(PHY_ID_ADIN1300),
461 .name = "ADIN1300", 486 .name = "ADIN1300",
462 .config_init = adin_config_init, 487 .config_init = adin_config_init,
488 .soft_reset = adin_soft_reset,
463 .config_aneg = adin_config_aneg, 489 .config_aneg = adin_config_aneg,
464 .read_status = adin_read_status, 490 .read_status = adin_read_status,
465 .ack_interrupt = adin_phy_ack_intr, 491 .ack_interrupt = adin_phy_ack_intr,