netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: phy: microchip_t1: add lan87xx_phy_init to initialize the lan87xx phy.
@ 2020-03-17 19:08 Yuiko Oshino
  2020-03-22  3:12 ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Yuiko Oshino @ 2020-03-17 19:08 UTC (permalink / raw)
  To: davem; +Cc: UNGLinuxDriver, netdev

lan87xx_phy_init() initializes the lan87xx phy.

fixes: 3e50d2da5850 ("Add driver for Microchip LAN87XX T1 PHYs")
Signed-off-by: Yuiko Oshino <yuiko.oshino@microchip.com>
---
 drivers/net/phy/microchip_t1.c | 119 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 119 insertions(+)

diff --git a/drivers/net/phy/microchip_t1.c b/drivers/net/phy/microchip_t1.c
index 001def4..4646b7be 100644
--- a/drivers/net/phy/microchip_t1.c
+++ b/drivers/net/phy/microchip_t1.c
@@ -3,9 +3,21 @@
 
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/delay.h>
 #include <linux/mii.h>
 #include <linux/phy.h>
 
+/* External Register Control Register */
+#define LAN87XX_EXT_REG_CTL                     (0x14)
+#define LAN87XX_EXT_REG_CTL_RD_CTL              (0x1000)
+#define LAN87XX_EXT_REG_CTL_WR_CTL              (0x0800)
+
+/* External Register Read Data Register */
+#define LAN87XX_EXT_REG_RD_DATA                 (0x15)
+
+/* External Register Write Data Register */
+#define LAN87XX_EXT_REG_WR_DATA                 (0x16)
+
 /* Interrupt Source Register */
 #define LAN87XX_INTERRUPT_SOURCE                (0x18)
 
@@ -14,9 +26,108 @@
 #define LAN87XX_MASK_LINK_UP                    (0x0004)
 #define LAN87XX_MASK_LINK_DOWN                  (0x0002)
 
+/* phyaccess nested types */
+#define	PHYACC_ATTR_MODE_READ		0
+#define	PHYACC_ATTR_MODE_WRITE		1
+
+#define	PHYACC_ATTR_BANK_SMI		0
+#define	PHYACC_ATTR_BANK_MISC		1
+#define	PHYACC_ATTR_BANK_PCS		2
+#define	PHYACC_ATTR_BANK_AFE		3
+
 #define DRIVER_AUTHOR	"Nisar Sayed <nisar.sayed@microchip.com>"
 #define DRIVER_DESC	"Microchip LAN87XX T1 PHY driver"
 
+struct access_ereg_val {
+	u8  mode;
+	u8  bank;
+	u8  offset;
+	u16 val;
+};
+
+static int access_ereg(struct phy_device *phydev, u8 mode, u8 bank,
+		       u8 offset, u16 val)
+{
+	u16 ereg = 0;
+	int rc = 0;
+
+	if (mode > 1 || bank > 7)
+		return -EINVAL;
+
+	if (mode == PHYACC_ATTR_MODE_WRITE) {
+		ereg |= LAN87XX_EXT_REG_CTL_WR_CTL;
+		rc = phy_write(phydev, LAN87XX_EXT_REG_WR_DATA, val);
+		if (rc < 0)
+			return rc;
+	} else {
+		ereg |= LAN87XX_EXT_REG_CTL_RD_CTL;
+	}
+
+	ereg |= (bank << 8) | offset;
+
+	rc = phy_write(phydev, LAN87XX_EXT_REG_CTL, ereg);
+	if (rc < 0)
+		return rc;
+
+	if (mode == PHYACC_ATTR_MODE_READ)
+		rc = phy_read(phydev, LAN87XX_EXT_REG_RD_DATA);
+
+	return rc;
+}
+
+static int lan87xx_phy_init(struct phy_device *phydev)
+{
+	static const struct access_ereg_val init[] = {
+		{PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_AFE, 0x0B, 0x000A},
+		{PHYACC_ATTR_MODE_READ, PHYACC_ATTR_BANK_MISC, 0x8, 0},
+		{PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_MISC, 0x8, 0},
+		{PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_MISC, 0x10, 0x0009},
+		{PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_SMI, 0x17, 0},
+		/* TC10 Config */
+		{PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_MISC, 0x20, 0x0023},
+		{PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_PCS, 0x20, 0x3C3C},
+		{PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_MISC, 0x21, 0x274F},
+		{PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_MISC, 0x20, 0x80A7},
+		{PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_MISC, 0x24, 0x9110},
+		{PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_MISC, 0x20, 0x0087},
+		/* HW Init */
+		{PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_SMI, 0x1A, 0x0300},
+	};
+	int rc, i;
+
+	/* Enter Managed Mode */
+	rc = access_ereg(phydev, PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_SMI,
+			 0x1a, 0x0300);
+	if (rc < 0)
+		return rc;
+
+	/* Reset the SMI block */
+	rc = access_ereg(phydev, PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_SMI,
+			 0x00, 0xA100);
+	if (rc < 0)
+		return rc;
+
+	/* Wait for the self-clearing bit to be cleared */
+	usleep_range(1000, 2000);
+	rc = access_ereg(phydev, PHYACC_ATTR_MODE_READ,
+			 PHYACC_ATTR_BANK_SMI, 0x00, 0);
+	if (rc < 0)
+		return rc;
+	if ((rc & 0x8000) != 0)
+		return -ETIMEDOUT;
+
+	/* PHY Initialization */
+	for (i = 0; i < ARRAY_SIZE(init); i++) {
+		rc = access_ereg(phydev, init[i].mode, init[i].bank,
+				 init[i].offset, init[i].val);
+
+		if (rc < 0)
+			return rc;
+	}
+
+	return 0;
+}
+
 static int lan87xx_phy_config_intr(struct phy_device *phydev)
 {
 	int rc, val = 0;
@@ -40,6 +151,13 @@ static int lan87xx_phy_ack_interrupt(struct phy_device *phydev)
 	return rc < 0 ? rc : 0;
 }
 
+static int lan87xx_config_init(struct phy_device *phydev)
+{
+	int rc = lan87xx_phy_init(phydev);
+
+	return rc < 0 ? rc : 0;
+}
+
 static struct phy_driver microchip_t1_phy_driver[] = {
 	{
 		.phy_id         = 0x0007c150,
@@ -48,6 +166,7 @@ static struct phy_driver microchip_t1_phy_driver[] = {
 
 		.features       = PHY_BASIC_T1_FEATURES,
 
+		.config_init	= lan87xx_config_init,
 		.config_aneg    = genphy_config_aneg,
 
 		.ack_interrupt  = lan87xx_phy_ack_interrupt,
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: phy: microchip_t1: add lan87xx_phy_init to initialize the lan87xx phy.
  2020-03-17 19:08 [PATCH net] net: phy: microchip_t1: add lan87xx_phy_init to initialize the lan87xx phy Yuiko Oshino
@ 2020-03-22  3:12 ` David Miller
  2020-03-30 13:55   ` Yuiko.Oshino
  0 siblings, 1 reply; 3+ messages in thread
From: David Miller @ 2020-03-22  3:12 UTC (permalink / raw)
  To: yuiko.oshino; +Cc: davem, UNGLinuxDriver, netdev

From: Yuiko Oshino <yuiko.oshino@microchip.com>
Date: Tue, 17 Mar 2020 15:08:38 -0400

> lan87xx_phy_init() initializes the lan87xx phy.
> 
> fixes: 3e50d2da5850 ("Add driver for Microchip LAN87XX T1 PHYs")
> Signed-off-by: Yuiko Oshino <yuiko.oshino@microchip.com>

"Fixes: " should be capitalized.

You commit message is way too terse.

> +	static const struct access_ereg_val init[] = {
> +		{PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_AFE, 0x0B, 0x000A},
> +		{PHYACC_ATTR_MODE_READ, PHYACC_ATTR_BANK_MISC, 0x8, 0},
> +		{PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_MISC, 0x8, 0},
> +		{PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_MISC, 0x10, 0x0009},
> +		{PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_SMI, 0x17, 0},
> +		/* TC10 Config */
> +		{PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_MISC, 0x20, 0x0023},
> +		{PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_PCS, 0x20, 0x3C3C},
> +		{PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_MISC, 0x21, 0x274F},
> +		{PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_MISC, 0x20, 0x80A7},
> +		{PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_MISC, 0x24, 0x9110},
> +		{PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_MISC, 0x20, 0x0087},
> +		/* HW Init */
> +		{PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_SMI, 0x1A, 0x0300},
> +	};

What do these registers do, and what do the values programmed into them
do?

If you don't know, how can you know if this code is correct?

You must document this as much as possible.

Thank you.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [PATCH net] net: phy: microchip_t1: add lan87xx_phy_init to initialize the lan87xx phy.
  2020-03-22  3:12 ` David Miller
@ 2020-03-30 13:55   ` Yuiko.Oshino
  0 siblings, 0 replies; 3+ messages in thread
From: Yuiko.Oshino @ 2020-03-30 13:55 UTC (permalink / raw)
  To: davem; +Cc: davem, UNGLinuxDriver, netdev

>From: David Miller <davem@davemloft.net>
>Sent: Saturday, March 21, 2020 11:12 PM

>
>From: Yuiko Oshino <yuiko.oshino@microchip.com>
>Date: Tue, 17 Mar 2020 15:08:38 -0400
>
>> lan87xx_phy_init() initializes the lan87xx phy.
>>
>> fixes: 3e50d2da5850 ("Add driver for Microchip LAN87XX T1 PHYs")
>> Signed-off-by: Yuiko Oshino <yuiko.oshino@microchip.com>
>
>"Fixes: " should be capitalized.
>
>You commit message is way too terse.
>
>> +     static const struct access_ereg_val init[] = {
>> +             {PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_AFE, 0x0B,
>0x000A},
>> +             {PHYACC_ATTR_MODE_READ, PHYACC_ATTR_BANK_MISC, 0x8, 0},
>> +             {PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_MISC, 0x8, 0},
>> +             {PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_MISC, 0x10,
>0x0009},
>> +             {PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_SMI, 0x17, 0},
>> +             /* TC10 Config */
>> +             {PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_MISC, 0x20,
>0x0023},
>> +             {PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_PCS, 0x20,
>0x3C3C},
>> +             {PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_MISC, 0x21,
>0x274F},
>> +             {PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_MISC, 0x20,
>0x80A7},
>> +             {PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_MISC, 0x24,
>0x9110},
>> +             {PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_MISC, 0x20,
>0x0087},
>> +             /* HW Init */
>> +             {PHYACC_ATTR_MODE_WRITE, PHYACC_ATTR_BANK_SMI, 0x1A,
>0x0300},
>> +     };
>
>What do these registers do, and what do the values programmed into them do?
>
>If you don't know, how can you know if this code is correct?
>
>You must document this as much as possible.
>
>Thank you.

Hi David,
Thank you for your comments.
I will improve and submit v1.
The initialization scripts also will be changed as our hardware engineers updated them.

Thank you.
Yuiko


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-03-30 13:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-17 19:08 [PATCH net] net: phy: microchip_t1: add lan87xx_phy_init to initialize the lan87xx phy Yuiko Oshino
2020-03-22  3:12 ` David Miller
2020-03-30 13:55   ` Yuiko.Oshino

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).