Skip to contentSkip to conversation

net: ethernet: mediatek: get the chip id by ETHDMASYS registers

PATCH Nelson Chang 2 participants 2 messages Oct 4, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi John,

Thanks for your review!
I will modify that as below. Would you think it is okay?

static int mtk_get_chip_id(struct mtk_eth *eth, u32 *chip_id)

{
	u32 val[2], id[4];

	regmap_read(eth->ethsys, ETHSYS_CHIPID0_3, &val[0]);
	regmap_read(eth->ethsys, ETHSYS_CHIPID4_7, &val[1]);

	id[3] = ((val[0] >> 16) & 0xff) - '0';
	id[2] = ((val[0] >> 24) & 0xff) - '0';
	id[1] = (val[1] & 0xff) - '0';
	id[0] = ((val[1] >> 8) & 0xff) - '0';

	*chip_id = (id[3] * 1000) + (id[2] * 100) +
		   (id[1] * 10) + id[0];

	if (!(*chip_id)) {
		dev_err(eth->dev, "failed to get chip id\n");
		return -ENODEV;
	}

	dev_info(eth->dev, "chip id = %d\n", *chip_id);

	return 0;
}
...
static int mtk_probe(struct platform_device *pdev)
{
	...
	err = mtk_get_chip_id(eth, &eth->chip_id);
	if (err)
		return err;
	...
}

Nelson

-----Original Message-----
From: John Crispin [mailto:[email protected]]
Sent: Tuesday, October 04, 2016 3:17 AM
To: Nelson Chang (張家祥); [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net-next 1/3] net: ethernet: mediatek: get the chip id by ETHDMASYS registers

Hi Nelson,

comments inline

Quoted 25 lines · Nelson Chang

The driver gets the chip id by ETHSYS_CHIPID0_3/ETHSYS_CHIPID4_7 registers in mtk_probe().

---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 27 
+++++++++++++++++++++++++++  
drivers/net/ethernet/mediatek/mtk_eth_soc.h |  5 +++++
 2 files changed, 32 insertions(+)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +6 -0
index ad4ab97..a3e4ae6 100644
@@ -2323,6 +2323,27 @@ free_netdev:
 	return err;
 }
 
+static u32 mtk_get_chip_id(struct mtk_eth *eth) {
+	u32 val[2], id[4];
+	u32 chip_id;
+
+	regmap_read(eth->ethsys, ETHSYS_CHIPID0_3, &val[0]);
+	regmap_read(eth->ethsys, ETHSYS_CHIPID4_7, &val[1]);

drivers/net/ethernet/mediatek/mtk_eth_soc.c free_netdev: · line 2341

Quoted 10 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +10 -0
+
+	id[3] = ((val[0] >> 16) & 0xff) - '0';
+	id[2] = ((val[0] >> 24) & 0xff) - '0';
+	id[1] = (val[1] & 0xff) - '0';
+	id[0] = ((val[1] >> 8) & 0xff) - '0';
+
+	chip_id = (id[3] * 1000) + (id[2] * 100) +
+		  (id[1] * 10) + id[0];
+
+	dev_info(eth->dev, "chip id = %d\n", chip_id);

the chip id is printed here

Quoted 6 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +3 -0
+	return chip_id;
+}
+
 static int mtk_probe(struct platform_device *pdev)  {
 	struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 

0); @@ -2388,6 +2409,12 @@ static int mtk_probe(struct platform_device

*pdev)

drivers/net/ethernet/mediatek/mtk_eth_soc.c

Quoted 9 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +6 -0
 	if (err)
 		return err;
 
+	eth->chip_id = mtk_get_chip_id(eth);
+	if (!eth->chip_id) {
+		dev_err(&pdev->dev, "failed to get chip id\n");
+		return -ENODEV;
+	}
+

and the error check happens here. maybe you could move the dev_err to the above function.

John

Quoted 28 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +0 -0
 	for_each_child_of_node(pdev->dev.of_node, mac_np) {
 		if (!of_device_is_compatible(mac_np,
 					     "mediatek,eth-mac"))
drivers/net/ethernet/mediatek/mtk_eth_soc.h +5 -0
index 3003195..a5b422b 100644
@@ -342,6 +342,10 @@
 #define GPIO_BIAS_CTRL		0xed0
 #define GPIO_DRV_SEL10		0xf00
 
+/* ethernet subsystem chip id register */
+#define ETHSYS_CHIPID0_3	0x0
+#define ETHSYS_CHIPID4_7	0x4
+
 /* ethernet subsystem config register */
 #define ETHSYS_SYSCFG0		0x14
 #define SYSCFG0_GE_MASK		0x3
@@ -534,6 +538,7 @@ struct mtk_eth {
 	unsigned long			sysclk;
 	struct regmap			*ethsys;
 	struct regmap			*pctl;
+	u32				chip_id;
 	bool				hwlro;
 	atomic_t			dma_refcnt;
 	struct mtk_tx_ring		tx_ring;
#1 lore raw
Quoted 40 lines · Nelson Chang

Hi John,

Thanks for your review!
I will modify that as below. Would you think it is okay?

static int mtk_get_chip_id(struct mtk_eth *eth, u32 *chip_id)

{
	u32 val[2], id[4];

	regmap_read(eth->ethsys, ETHSYS_CHIPID0_3, &val[0]);
	regmap_read(eth->ethsys, ETHSYS_CHIPID4_7, &val[1]);

	id[3] = ((val[0] >> 16) & 0xff) - '0';
	id[2] = ((val[0] >> 24) & 0xff) - '0';
	id[1] = (val[1] & 0xff) - '0';
	id[0] = ((val[1] >> 8) & 0xff) - '0';

	*chip_id = (id[3] * 1000) + (id[2] * 100) +
		   (id[1] * 10) + id[0];

	if (!(*chip_id)) {
		dev_err(eth->dev, "failed to get chip id\n");
		return -ENODEV;
	}

	dev_info(eth->dev, "chip id = %d\n", *chip_id);

	return 0;
}
...
static int mtk_probe(struct platform_device *pdev)
{
	...
	err = mtk_get_chip_id(eth, &eth->chip_id);
	if (err)
		return err;
	...
}
Quoted 1 line

Nelson

Hi Nelson,

I think that looks nicer, thanks !

John

Quoted 105 lines

-----Original Message-----
From: John Crispin [mailto:[email protected]]
Sent: Tuesday, October 04, 2016 3:17 AM
To: Nelson Chang (張家祥); [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net-next 1/3] net: ethernet: mediatek: get the chip id by ETHDMASYS registers

Hi Nelson,

comments inline

Quoted 25 lines · Nelson Chang

The driver gets the chip id by ETHSYS_CHIPID0_3/ETHSYS_CHIPID4_7 registers in mtk_probe().

---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 27 
+++++++++++++++++++++++++++  
drivers/net/ethernet/mediatek/mtk_eth_soc.h |  5 +++++
 2 files changed, 32 insertions(+)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +6 -0
index ad4ab97..a3e4ae6 100644
@@ -2323,6 +2323,27 @@ free_netdev:
 	return err;
 }
 
+static u32 mtk_get_chip_id(struct mtk_eth *eth) {
+	u32 val[2], id[4];
+	u32 chip_id;
+
+	regmap_read(eth->ethsys, ETHSYS_CHIPID0_3, &val[0]);
+	regmap_read(eth->ethsys, ETHSYS_CHIPID4_7, &val[1]);

drivers/net/ethernet/mediatek/mtk_eth_soc.c free_netdev: · line 2341

Quoted 10 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +10 -0
+
+	id[3] = ((val[0] >> 16) & 0xff) - '0';
+	id[2] = ((val[0] >> 24) & 0xff) - '0';
+	id[1] = (val[1] & 0xff) - '0';
+	id[0] = ((val[1] >> 8) & 0xff) - '0';
+
+	chip_id = (id[3] * 1000) + (id[2] * 100) +
+		  (id[1] * 10) + id[0];
+
+	dev_info(eth->dev, "chip id = %d\n", chip_id);

the chip id is printed here

Quoted 6 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +3 -0
+	return chip_id;
+}
+
 static int mtk_probe(struct platform_device *pdev)  {
 	struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 

0); @@ -2388,6 +2409,12 @@ static int mtk_probe(struct platform_device

*pdev)

drivers/net/ethernet/mediatek/mtk_eth_soc.c

Quoted 9 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +6 -0
 	if (err)
 		return err;
 
+	eth->chip_id = mtk_get_chip_id(eth);
+	if (!eth->chip_id) {
+		dev_err(&pdev->dev, "failed to get chip id\n");
+		return -ENODEV;
+	}
+

and the error check happens here. maybe you could move the dev_err to the above function.

John

Quoted 28 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +0 -0
 	for_each_child_of_node(pdev->dev.of_node, mac_np) {
 		if (!of_device_is_compatible(mac_np,
 					     "mediatek,eth-mac"))
drivers/net/ethernet/mediatek/mtk_eth_soc.h +5 -0
index 3003195..a5b422b 100644
@@ -342,6 +342,10 @@
 #define GPIO_BIAS_CTRL		0xed0
 #define GPIO_DRV_SEL10		0xf00
 
+/* ethernet subsystem chip id register */
+#define ETHSYS_CHIPID0_3	0x0
+#define ETHSYS_CHIPID4_7	0x4
+
 /* ethernet subsystem config register */
 #define ETHSYS_SYSCFG0		0x14
 #define SYSCFG0_GE_MASK		0x3
@@ -534,6 +538,7 @@ struct mtk_eth {
 	unsigned long			sysclk;
 	struct regmap			*ethsys;
 	struct regmap			*pctl;
+	u32				chip_id;
 	bool				hwlro;
 	atomic_t			dma_refcnt;
 	struct mtk_tx_ring		tx_ring;