Skip to contentSkip to conversation

net: phy: tja11xx: Add TJA11xx PHY driver

PATCH Superseded Marek Vasut 4 participants 20 messages Dec 21, 2018 – Jan 4, 2019

Subsystems (3)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 net: phy: tja11xx: Add TJA11xx PHY driver

Add driver for the NXP TJA1100 and TJA1101 PHYs. These PHYs are special BroadRReach 100BaseT1 PHYs used in automotive.

Cc Andrew Lunn <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Heiner Kallweit <[email protected]>

---
V2: - Use phy_modify(), phy_{set,clear}_bits()
- Drop enable argument of tja11xx_enable_link_control()
- Use PHY_BASIC_T1_FEATURES and dont modify supported/advertised features in config_init callback
- Use genphy_soft_reset() instead of opencoding the reset sequence.
- Drop the aneg parts, since the PHY datasheet claims it does not support aneg
V3: - Replace clr with mask
- Add hwmon support
- Check commstat in tja11xx_read_status() only if link is up
- Use PHY_ID_MATCH_MODEL()

---
 drivers/net/phy/Kconfig       |   6 +
 drivers/net/phy/Makefile      |   1 +
 drivers/net/phy/nxp-tja11xx.c | 424 ++++++++++++++++++++++++++++++++++
 3 files changed, 431 insertions(+)
 create mode 100644 drivers/net/phy/nxp-tja11xx.c
drivers/net/phy/Kconfig +6 -0
index 3d187cd50eb0..88b462ef1274 100644
@@ -389,6 +389,12 @@ config NATIONAL_PHY
 	---help---
 	  Currently supports the DP83865 PHY.
 
+config NXP_TJA11XX_PHY
+	tristate "NXP TJA11xx PHYs support"
+	depends on HWMON
+	---help---
+	  Currently supports the NXP TJA1100 and TJA1101 PHY.
+
 config QSEMI_PHY
 	tristate "Quality Semiconductor PHYs"
 	---help---
drivers/net/phy/Makefile +1 -0
index 5805c0b7d60e..023e5db8c7cc 100644
@@ -76,6 +76,7 @@ obj-$(CONFIG_MICROCHIP_PHY)	+= microchip.o
 obj-$(CONFIG_MICROCHIP_T1_PHY)	+= microchip_t1.o
 obj-$(CONFIG_MICROSEMI_PHY)	+= mscc.o
 obj-$(CONFIG_NATIONAL_PHY)	+= national.o
+obj-$(CONFIG_NXP_TJA11XX_PHY)	+= nxp-tja11xx.o
 obj-$(CONFIG_QSEMI_PHY)		+= qsemi.o
 obj-$(CONFIG_REALTEK_PHY)	+= realtek.o
 obj-$(CONFIG_RENESAS_PHY)	+= uPD60620.o
drivers/net/phy/nxp-tja11xx.c new file +424 -0

424 lines not on this page · raw message

Signature · 1 line
2.19.2
maintainer
#1 lore raw
Quoted 26 lines · Marek Vasut

Add driver for the NXP TJA1100 and TJA1101 PHYs. These PHYs are special BroadRReach 100BaseT1 PHYs used in automotive.

Cc Andrew Lunn <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Heiner Kallweit <[email protected]>

---
V2: - Use phy_modify(), phy_{set,clear}_bits()
- Drop enable argument of tja11xx_enable_link_control()
- Use PHY_BASIC_T1_FEATURES and dont modify supported/advertised features in config_init callback
- Use genphy_soft_reset() instead of opencoding the reset sequence.
- Drop the aneg parts, since the PHY datasheet claims it does not support aneg
V3: - Replace clr with mask
- Add hwmon support
- Check commstat in tja11xx_read_status() only if link is up
- Use PHY_ID_MATCH_MODEL()

---
 drivers/net/phy/Kconfig       |   6 +
 drivers/net/phy/Makefile      |   1 +
 drivers/net/phy/nxp-tja11xx.c | 424 ++++++++++++++++++++++++++++++++++
 3 files changed, 431 insertions(+)
 create mode 100644 drivers/net/phy/nxp-tja11xx.c

[...]

drivers/net/phy/nxp-tja11xx.c line 62

Quoted 8 lines
drivers/net/phy/nxp-tja11xx.c new file +8 -0
+
+struct tja11xx_phy_stats {
+	const char	*string;
+	u8		reg;
+	u8		off;
+	u16		mask;
+};
+

As written in my other mail, you could think of using FIELD_GET() again. Things like
... n, BIT(n),
... m, BIT(m),
are simply redundant.

drivers/net/phy/nxp-tja11xx.c line 69

Quoted 7 lines
drivers/net/phy/nxp-tja11xx.c new file +7 -0
+static struct tja11xx_phy_stats tja11xx_hw_stats[] = {
+	{ "phy_symbol_error_count", 20, 0, 0xffff },
+	{ "phy_polarity_detect", 25, 6, BIT(6) },
+	{ "phy_open_detect", 25, 7, BIT(7) },
+	{ "phy_short_detect", 25, 8, BIT(8) },
+	{ "phy_rem_rcvr_count", 26, 0, 0xff },
+	{ "phy_loc_rcvr_count", 26, 8, 0xff },

Shouldn't mask in the last line be 0xff00 ? In the relevant code you do: val = (reg & mask) >> off

drivers/net/phy/nxp-tja11xx.c line 363

Quoted 13 lines
drivers/net/phy/nxp-tja11xx.c new file +13 -0
+static int tja11xx_probe(struct phy_device *phydev)
+{
+	struct device *dev = &phydev->mdio.dev;
+	struct tja11xx_priv *priv;
+	int i;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->hwmon_name = devm_kstrdup(dev, dev_name(dev), GFP_KERNEL);
+	if (!priv->hwmon_name)
+		return -ENODEV;

Do you really need to make a copy of the device name?
Why not simply priv->hwmon_name = dev_name(dev) ?
And if devm_kstrdup fails, then most likely you have an out-of-memory error, so why not return -ENOMEM as usual?

drivers/net/phy/nxp-tja11xx.c line 374

Quoted 11 lines
drivers/net/phy/nxp-tja11xx.c new file +11 -0
+
+	for (i = 0; priv->hwmon_name[i]; i++)
+		if (hwmon_is_bad_char(priv->hwmon_name[i]))
+			priv->hwmon_name[i] = '_';
+
+	priv->hwmon_dev =
+		devm_hwmon_device_register_with_info(dev, priv->hwmon_name,
+						     phydev,
+						     &tja11xx_hwmon_chip_info,
+						     NULL);
+

Prerequisite for this call is that HWMON is configured in the kernel and it's reachable. Something like "IS_REACHABLE(CONFIG_HWMON)" would be needed. You can see driver rtc-ds1307 for an example.

#2 lore raw
Quoted 28 lines · Heiner Kallweit
Quoted 26 lines · Marek Vasut

Add driver for the NXP TJA1100 and TJA1101 PHYs. These PHYs are special BroadRReach 100BaseT1 PHYs used in automotive.

Cc Andrew Lunn <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Heiner Kallweit <[email protected]>

---
V2: - Use phy_modify(), phy_{set,clear}_bits()
- Drop enable argument of tja11xx_enable_link_control()
- Use PHY_BASIC_T1_FEATURES and dont modify supported/advertised features in config_init callback
- Use genphy_soft_reset() instead of opencoding the reset sequence.
- Drop the aneg parts, since the PHY datasheet claims it does not support aneg
V3: - Replace clr with mask
- Add hwmon support
- Check commstat in tja11xx_read_status() only if link is up
- Use PHY_ID_MATCH_MODEL()

---
 drivers/net/phy/Kconfig       |   6 +
 drivers/net/phy/Makefile      |   1 +
 drivers/net/phy/nxp-tja11xx.c | 424 ++++++++++++++++++++++++++++++++++
 3 files changed, 431 insertions(+)
 create mode 100644 drivers/net/phy/nxp-tja11xx.c

[...]

Quoted 13 lines

drivers/net/phy/nxp-tja11xx.c line 62

Quoted 8 lines
drivers/net/phy/nxp-tja11xx.c new file +8 -0
+
+struct tja11xx_phy_stats {
+	const char	*string;
+	u8		reg;
+	u8		off;
+	u16		mask;
+};
+

As written in my other mail, you could think of using FIELD_GET() again. Things like
... n, BIT(n),
... m, BIT(m),
are simply redundant.

Done

Quoted 10 lines

drivers/net/phy/nxp-tja11xx.c line 69

Quoted 7 lines
drivers/net/phy/nxp-tja11xx.c new file +7 -0
+static struct tja11xx_phy_stats tja11xx_hw_stats[] = {
+	{ "phy_symbol_error_count", 20, 0, 0xffff },
+	{ "phy_polarity_detect", 25, 6, BIT(6) },
+	{ "phy_open_detect", 25, 7, BIT(7) },
+	{ "phy_short_detect", 25, 8, BIT(8) },
+	{ "phy_rem_rcvr_count", 26, 0, 0xff },
+	{ "phy_loc_rcvr_count", 26, 8, 0xff },

Shouldn't mask in the last line be 0xff00 ? In the relevant code you do: val = (reg & mask) >> off

Yes, fixed, thanks

Quoted 8 lines
Quoted 8 lines
drivers/net/phy/nxp-tja11xx.c new file +8 -0
+static int tja11xx_probe(struct phy_device *phydev)
+{
+	struct device *dev = &phydev->mdio.dev;
+	struct tja11xx_priv *priv;
+	int i;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
Quoted 8 lines

drivers/net/phy/nxp-tja11xx.c line 363

Quoted 5 lines
drivers/net/phy/nxp-tja11xx.c new file +5 -0
+		return -ENOMEM;
+
+	priv->hwmon_name = devm_kstrdup(dev, dev_name(dev), GFP_KERNEL);
+	if (!priv->hwmon_name)
+		return -ENODEV;

Do you really need to make a copy of the device name? Why not simply priv->hwmon_name = dev_name(dev) ?

Fine by me, but then maybe I don't quite understand why the other drivers duplicate the name, eg. the sfp.c one.

Quoted 2 lines

And if devm_kstrdup fails, then most likely you have an out-of-memory error, so why not return -ENOMEM as usual?

Fixed

Quoted 6 lines
Quoted 6 lines
drivers/net/phy/nxp-tja11xx.c new file +6 -0
+
+	for (i = 0; priv->hwmon_name[i]; i++)
+		if (hwmon_is_bad_char(priv->hwmon_name[i]))
+			priv->hwmon_name[i] = '_';
+
+	priv->hwmon_dev =
Quoted 8 lines

drivers/net/phy/nxp-tja11xx.c line 374

Quoted 5 lines
drivers/net/phy/nxp-tja11xx.c new file +5 -0
+		devm_hwmon_device_register_with_info(dev, priv->hwmon_name,
+						     phydev,
+						     &tja11xx_hwmon_chip_info,
+						     NULL);
+

Prerequisite for this call is that HWMON is configured in the kernel and it's reachable. Something like "IS_REACHABLE(CONFIG_HWMON)" would be needed. You can see driver rtc-ds1307 for an example.

The driver depends on HWMON, so that should be sufficient ?

Signature · 2 lines
Best regards,
Marek Vasut
maintainer
#3 lore raw
Quoted 75 lines · Marek Vasut
Quoted 28 lines · Heiner Kallweit
Quoted 26 lines · Marek Vasut

Add driver for the NXP TJA1100 and TJA1101 PHYs. These PHYs are special BroadRReach 100BaseT1 PHYs used in automotive.

Cc Andrew Lunn <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Heiner Kallweit <[email protected]>

---
V2: - Use phy_modify(), phy_{set,clear}_bits()
- Drop enable argument of tja11xx_enable_link_control()
- Use PHY_BASIC_T1_FEATURES and dont modify supported/advertised features in config_init callback
- Use genphy_soft_reset() instead of opencoding the reset sequence.
- Drop the aneg parts, since the PHY datasheet claims it does not support aneg
V3: - Replace clr with mask
- Add hwmon support
- Check commstat in tja11xx_read_status() only if link is up
- Use PHY_ID_MATCH_MODEL()

---
 drivers/net/phy/Kconfig       |   6 +
 drivers/net/phy/Makefile      |   1 +
 drivers/net/phy/nxp-tja11xx.c | 424 ++++++++++++++++++++++++++++++++++
 3 files changed, 431 insertions(+)
 create mode 100644 drivers/net/phy/nxp-tja11xx.c

[...]

Quoted 13 lines

drivers/net/phy/nxp-tja11xx.c line 62

Quoted 8 lines
drivers/net/phy/nxp-tja11xx.c new file +8 -0
+
+struct tja11xx_phy_stats {
+	const char	*string;
+	u8		reg;
+	u8		off;
+	u16		mask;
+};
+

As written in my other mail, you could think of using FIELD_GET() again. Things like
... n, BIT(n),
... m, BIT(m),
are simply redundant.

Done

Quoted 10 lines

drivers/net/phy/nxp-tja11xx.c line 69

Quoted 7 lines
drivers/net/phy/nxp-tja11xx.c new file +7 -0
+static struct tja11xx_phy_stats tja11xx_hw_stats[] = {
+	{ "phy_symbol_error_count", 20, 0, 0xffff },
+	{ "phy_polarity_detect", 25, 6, BIT(6) },
+	{ "phy_open_detect", 25, 7, BIT(7) },
+	{ "phy_short_detect", 25, 8, BIT(8) },
+	{ "phy_rem_rcvr_count", 26, 0, 0xff },
+	{ "phy_loc_rcvr_count", 26, 8, 0xff },

Shouldn't mask in the last line be 0xff00 ? In the relevant code you do: val = (reg & mask) >> off

Yes, fixed, thanks

Quoted 8 lines
Quoted 8 lines
drivers/net/phy/nxp-tja11xx.c new file +8 -0
+static int tja11xx_probe(struct phy_device *phydev)
+{
+	struct device *dev = &phydev->mdio.dev;
+	struct tja11xx_priv *priv;
+	int i;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
Quoted 8 lines

drivers/net/phy/nxp-tja11xx.c line 363

Quoted 5 lines
drivers/net/phy/nxp-tja11xx.c new file +5 -0
+		return -ENOMEM;
+
+	priv->hwmon_name = devm_kstrdup(dev, dev_name(dev), GFP_KERNEL);
+	if (!priv->hwmon_name)
+		return -ENODEV;

Do you really need to make a copy of the device name? Why not simply priv->hwmon_name = dev_name(dev) ?

Quoted 3 lines

Fine by me, but then maybe I don't quite understand why the other drivers duplicate the name, eg. the sfp.c one.

It's a question of object lifetime. If the original object can go away before your object, then you need to make a copy of the name. However in our case I don't think priv can live longer than dev.

Quoted 20 lines
Quoted 2 lines

And if devm_kstrdup fails, then most likely you have an out-of-memory error, so why not return -ENOMEM as usual?

Fixed

Quoted 6 lines
Quoted 6 lines
drivers/net/phy/nxp-tja11xx.c new file +6 -0
+
+	for (i = 0; priv->hwmon_name[i]; i++)
+		if (hwmon_is_bad_char(priv->hwmon_name[i]))
+			priv->hwmon_name[i] = '_';
+
+	priv->hwmon_dev =
Quoted 8 lines

drivers/net/phy/nxp-tja11xx.c line 374

Quoted 5 lines
drivers/net/phy/nxp-tja11xx.c new file +5 -0
+		devm_hwmon_device_register_with_info(dev, priv->hwmon_name,
+						     phydev,
+						     &tja11xx_hwmon_chip_info,
+						     NULL);
+

Prerequisite for this call is that HWMON is configured in the kernel and it's reachable. Something like "IS_REACHABLE(CONFIG_HWMON)" would be needed. You can see driver rtc-ds1307 for an example.

Quoted 2 lines

The driver depends on HWMON, so that should be sufficient ?

Missed that, that's sufficient. Just something to think about:
Often HWMON is seen as an optional add-on feature. The driver itself would work perfectly fine also w/o HWMON. In this case you don't want the hard dependency. So it's up to you whether you want to allow that the driver is used on systems w/o HWMON support.

maintainer
#4 lore raw
Quoted 21 lines
Quoted 11 lines
Quoted 10 lines

drivers/net/phy/nxp-tja11xx.c line 363

Quoted 7 lines
drivers/net/phy/nxp-tja11xx.c new file +7 -0
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->hwmon_name = devm_kstrdup(dev, dev_name(dev), GFP_KERNEL);
+	if (!priv->hwmon_name)
+		return -ENODEV;

Do you really need to make a copy of the device name? Why not simply priv->hwmon_name = dev_name(dev) ?

Quoted 3 lines

Fine by me, but then maybe I don't quite understand why the other drivers duplicate the name, eg. the sfp.c one.

It's a question of object lifetime. If the original object can go away before your object, then you need to make a copy of the name. However in our case I don't think priv can live longer than dev.

Quoted 3 lines
Quoted 2 lines

And if devm_kstrdup fails, then most likely you have an out-of-memory error, so why not return -ENOMEM as usual?

Quoted 6 lines
Quoted 6 lines

Fixed

Quoted 4 lines

drivers/net/phy/nxp-tja11xx.c line 367

Quoted 4 lines
drivers/net/phy/nxp-tja11xx.c new file +4 -0
+
+	for (i = 0; priv->hwmon_name[i]; i++)
+		if (hwmon_is_bad_char(priv->hwmon_name[i]))
+			priv->hwmon_name[i] = '_';

This is one reason to make a copy. You don't want to apply that to main name of the device.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/net/phy/nxp-tja11xx.c line 374

Quoted 7 lines
drivers/net/phy/nxp-tja11xx.c new file +7 -0
+
+	priv->hwmon_dev =
+		devm_hwmon_device_register_with_info(dev, priv->hwmon_name,
+						     phydev,
+						     &tja11xx_hwmon_chip_info,
+						     NULL);
+

The second reason is priv is released before dev, but what about hwmon, especially if somebody has one of the files open? Is the unregister synchronous?

Andrew

#5 lore raw
In reply to Heiner Kallweit
Quoted 103 lines · Heiner Kallweit
Quoted 75 lines · Marek Vasut
Quoted 28 lines · Heiner Kallweit
Quoted 26 lines · Marek Vasut

Add driver for the NXP TJA1100 and TJA1101 PHYs. These PHYs are special BroadRReach 100BaseT1 PHYs used in automotive.

Cc Andrew Lunn <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Heiner Kallweit <[email protected]>

---
V2: - Use phy_modify(), phy_{set,clear}_bits()
- Drop enable argument of tja11xx_enable_link_control()
- Use PHY_BASIC_T1_FEATURES and dont modify supported/advertised features in config_init callback
- Use genphy_soft_reset() instead of opencoding the reset sequence.
- Drop the aneg parts, since the PHY datasheet claims it does not support aneg
V3: - Replace clr with mask
- Add hwmon support
- Check commstat in tja11xx_read_status() only if link is up
- Use PHY_ID_MATCH_MODEL()

---
 drivers/net/phy/Kconfig       |   6 +
 drivers/net/phy/Makefile      |   1 +
 drivers/net/phy/nxp-tja11xx.c | 424 ++++++++++++++++++++++++++++++++++
 3 files changed, 431 insertions(+)
 create mode 100644 drivers/net/phy/nxp-tja11xx.c

[...]

Quoted 13 lines

drivers/net/phy/nxp-tja11xx.c line 62

Quoted 8 lines
drivers/net/phy/nxp-tja11xx.c new file +8 -0
+
+struct tja11xx_phy_stats {
+	const char	*string;
+	u8		reg;
+	u8		off;
+	u16		mask;
+};
+

As written in my other mail, you could think of using FIELD_GET() again. Things like
... n, BIT(n),
... m, BIT(m),
are simply redundant.

Done

Quoted 10 lines

drivers/net/phy/nxp-tja11xx.c line 69

Quoted 7 lines
drivers/net/phy/nxp-tja11xx.c new file +7 -0
+static struct tja11xx_phy_stats tja11xx_hw_stats[] = {
+	{ "phy_symbol_error_count", 20, 0, 0xffff },
+	{ "phy_polarity_detect", 25, 6, BIT(6) },
+	{ "phy_open_detect", 25, 7, BIT(7) },
+	{ "phy_short_detect", 25, 8, BIT(8) },
+	{ "phy_rem_rcvr_count", 26, 0, 0xff },
+	{ "phy_loc_rcvr_count", 26, 8, 0xff },

Shouldn't mask in the last line be 0xff00 ? In the relevant code you do: val = (reg & mask) >> off

Yes, fixed, thanks

Quoted 8 lines
Quoted 8 lines
drivers/net/phy/nxp-tja11xx.c new file +8 -0
+static int tja11xx_probe(struct phy_device *phydev)
+{
+	struct device *dev = &phydev->mdio.dev;
+	struct tja11xx_priv *priv;
+	int i;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
Quoted 8 lines

drivers/net/phy/nxp-tja11xx.c line 363

Quoted 5 lines
drivers/net/phy/nxp-tja11xx.c new file +5 -0
+		return -ENOMEM;
+
+	priv->hwmon_name = devm_kstrdup(dev, dev_name(dev), GFP_KERNEL);
+	if (!priv->hwmon_name)
+		return -ENODEV;

Do you really need to make a copy of the device name? Why not simply priv->hwmon_name = dev_name(dev) ?

Quoted 3 lines

Fine by me, but then maybe I don't quite understand why the other drivers duplicate the name, eg. the sfp.c one.

It's a question of object lifetime. If the original object can go away before your object, then you need to make a copy of the name. However in our case I don't think priv can live longer than dev.

Quoted 20 lines
Quoted 2 lines

And if devm_kstrdup fails, then most likely you have an out-of-memory error, so why not return -ENOMEM as usual?

Fixed

Quoted 14 lines

drivers/net/phy/nxp-tja11xx.c line 374

Quoted 11 lines
drivers/net/phy/nxp-tja11xx.c new file +11 -0
+
+	for (i = 0; priv->hwmon_name[i]; i++)
+		if (hwmon_is_bad_char(priv->hwmon_name[i]))
+			priv->hwmon_name[i] = '_';
+
+	priv->hwmon_dev =
+		devm_hwmon_device_register_with_info(dev, priv->hwmon_name,
+						     phydev,
+						     &tja11xx_hwmon_chip_info,
+						     NULL);
+

Prerequisite for this call is that HWMON is configured in the kernel and it's reachable. Something like "IS_REACHABLE(CONFIG_HWMON)" would be needed. You can see driver rtc-ds1307 for an example.

Quoted 7 lines
Quoted 2 lines

The driver depends on HWMON, so that should be sufficient ?

Missed that, that's sufficient. Just something to think about:
Often HWMON is seen as an optional add-on feature. The driver itself would work perfectly fine also w/o HWMON. In this case you don't want the hard dependency. So it's up to you whether you want to allow that the driver is used on systems w/o HWMON support.

Given that the HWMON indicates that the automotive device either overheated or suffered undervolt, I presume it'd be safer not to make it optional ?

Signature · 2 lines
Best regards,
Marek Vasut
maintainer
#6 lore raw
Quoted 3 lines

Given that the HWMON indicates that the automotive device either overheated or suffered undervolt, I presume it'd be safer not to make it optional ?

Hi Marek

It is a niche device, where i expect a custom kernel configuration. Do any of these devices exist on standard PCIe cards? Maybe a test PC using a standard Linux Distribution? But then again, such distributions turn on HWMON anyway.

Andrew

#7 lore raw
Quoted 10 lines · Andrew Lunn
Quoted 3 lines

Given that the HWMON indicates that the automotive device either overheated or suffered undervolt, I presume it'd be safer not to make it optional ?

Hi Marek

It is a niche device, where i expect a custom kernel configuration. Do any of these devices exist on standard PCIe cards? Maybe a test PC using a standard Linux Distribution? But then again, such distributions turn on HWMON anyway.

Not to my knowledge. I have two on various embedded systems and one on SMSC95xx USB-ethernet device (although, the SMSC95xx driver needs to be fixed to support that, cfr. the other thread).

Signature · 2 lines
Best regards,
Marek Vasut
#8 lore raw
In reply to Marek Vasut
Quoted 43 lines · Marek Vasut
Quoted 28 lines · Heiner Kallweit
Quoted 26 lines · Marek Vasut

Add driver for the NXP TJA1100 and TJA1101 PHYs. These PHYs are special BroadRReach 100BaseT1 PHYs used in automotive.

Cc Andrew Lunn <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Heiner Kallweit <[email protected]>

---
V2: - Use phy_modify(), phy_{set,clear}_bits()
- Drop enable argument of tja11xx_enable_link_control()
- Use PHY_BASIC_T1_FEATURES and dont modify supported/advertised features in config_init callback
- Use genphy_soft_reset() instead of opencoding the reset sequence.
- Drop the aneg parts, since the PHY datasheet claims it does not support aneg
V3: - Replace clr with mask
- Add hwmon support
- Check commstat in tja11xx_read_status() only if link is up
- Use PHY_ID_MATCH_MODEL()

---
 drivers/net/phy/Kconfig       |   6 +
 drivers/net/phy/Makefile      |   1 +
 drivers/net/phy/nxp-tja11xx.c | 424 ++++++++++++++++++++++++++++++++++
 3 files changed, 431 insertions(+)
 create mode 100644 drivers/net/phy/nxp-tja11xx.c

[...]

Quoted 13 lines

drivers/net/phy/nxp-tja11xx.c line 62

Quoted 8 lines
drivers/net/phy/nxp-tja11xx.c new file +8 -0
+
+struct tja11xx_phy_stats {
+	const char	*string;
+	u8		reg;
+	u8		off;
+	u16		mask;
+};
+

As written in my other mail, you could think of using FIELD_GET() again. Things like
... n, BIT(n),
... m, BIT(m),
are simply redundant.

Quoted 1 line

Done

And undone, FIELD_GET() requires a mask that is compile-time constant. That's not the case here.

Replicating what FIELD_GET() does at runtime is inefficient, so we can as well encode the field and offset back into the table. Or is there a better suggestion ?

Signature · 2 lines
Best regards,
Marek Vasut
maintainer
#9 lore raw
Quoted 44 lines · Marek Vasut
Quoted 43 lines · Marek Vasut
Quoted 41 lines · Heiner Kallweit
Quoted 26 lines · Marek Vasut

Add driver for the NXP TJA1100 and TJA1101 PHYs. These PHYs are special BroadRReach 100BaseT1 PHYs used in automotive.

Cc Andrew Lunn <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Heiner Kallweit <[email protected]>

---
V2: - Use phy_modify(), phy_{set,clear}_bits()
- Drop enable argument of tja11xx_enable_link_control()
- Use PHY_BASIC_T1_FEATURES and dont modify supported/advertised features in config_init callback
- Use genphy_soft_reset() instead of opencoding the reset sequence.
- Drop the aneg parts, since the PHY datasheet claims it does not support aneg
V3: - Replace clr with mask
- Add hwmon support
- Check commstat in tja11xx_read_status() only if link is up
- Use PHY_ID_MATCH_MODEL()

---
 drivers/net/phy/Kconfig       |   6 +
 drivers/net/phy/Makefile      |   1 +
 drivers/net/phy/nxp-tja11xx.c | 424 ++++++++++++++++++++++++++++++++++
 3 files changed, 431 insertions(+)
 create mode 100644 drivers/net/phy/nxp-tja11xx.c

[...]

drivers/net/phy/nxp-tja11xx.c line 62

Quoted 8 lines
drivers/net/phy/nxp-tja11xx.c new file +8 -0
+
+struct tja11xx_phy_stats {
+	const char	*string;
+	u8		reg;
+	u8		off;
+	u16		mask;
+};
+

As written in my other mail, you could think of using FIELD_GET() again. Things like
... n, BIT(n),
... m, BIT(m),
are simply redundant.

Quoted 9 lines
Quoted 1 line

Done

And undone, FIELD_GET() requires a mask that is compile-time constant. That's not the case here.

Replicating what FIELD_GET() does at runtime is inefficient, so we can as well encode the field and offset back into the table. Or is there a better suggestion ?

You're right, FIELD_GET() requires a constant as mask. Then for the case here I'm not aware of a better solution than having also the mask in the table.

#10 lore raw
Quoted 50 lines · Heiner Kallweit
Quoted 49 lines · Marek Vasut
Quoted 43 lines · Marek Vasut
Quoted 28 lines · Heiner Kallweit
Quoted 26 lines · Marek Vasut

Add driver for the NXP TJA1100 and TJA1101 PHYs. These PHYs are special BroadRReach 100BaseT1 PHYs used in automotive.

Cc Andrew Lunn <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Heiner Kallweit <[email protected]>

---
V2: - Use phy_modify(), phy_{set,clear}_bits()
- Drop enable argument of tja11xx_enable_link_control()
- Use PHY_BASIC_T1_FEATURES and dont modify supported/advertised features in config_init callback
- Use genphy_soft_reset() instead of opencoding the reset sequence.
- Drop the aneg parts, since the PHY datasheet claims it does not support aneg
V3: - Replace clr with mask
- Add hwmon support
- Check commstat in tja11xx_read_status() only if link is up
- Use PHY_ID_MATCH_MODEL()

---
 drivers/net/phy/Kconfig       |   6 +
 drivers/net/phy/Makefile      |   1 +
 drivers/net/phy/nxp-tja11xx.c | 424 ++++++++++++++++++++++++++++++++++
 3 files changed, 431 insertions(+)
 create mode 100644 drivers/net/phy/nxp-tja11xx.c

[...]

Quoted 13 lines

drivers/net/phy/nxp-tja11xx.c line 62

Quoted 8 lines
drivers/net/phy/nxp-tja11xx.c new file +8 -0
+
+struct tja11xx_phy_stats {
+	const char	*string;
+	u8		reg;
+	u8		off;
+	u16		mask;
+};
+

As written in my other mail, you could think of using FIELD_GET() again. Things like
... n, BIT(n),
... m, BIT(m),
are simply redundant.

Quoted 1 line

Done

And undone, FIELD_GET() requires a mask that is compile-time constant. That's not the case here.

Quoted 7 lines
Quoted 4 lines

Replicating what FIELD_GET() does at runtime is inefficient, so we can as well encode the field and offset back into the table. Or is there a better suggestion ?

You're right, FIELD_GET() requires a constant as mask. Then for the case here I'm not aware of a better solution than having also the mask in the table.

V4 is out then.

Signature · 2 lines
Best regards,
Marek Vasut
#11 lore raw

On 1/4/19 3:19 AM, Marek Vasut wrote:

[...]

On a separate note, I was pondering about the master/slave mode of the TJA11xx PHY. Right now, the driver only operates in Automatic mode, however the PHY can be force-configured as either master or slave. Would using .set_tunable with a new tunable type be a good way to expose this to userspace ? The ethtool can then configure the PHY mode.

Signature · 2 lines
Best regards,
Marek Vasut
#12 lore raw
Quoted 9 lines · Marek Vasut

On 1/4/19 3:19 AM, Marek Vasut wrote:

[...]

On a separate note, I was pondering about the master/slave mode of the TJA11xx PHY. Right now, the driver only operates in Automatic mode, however the PHY can be force-configured as either master or slave. Would using .set_tunable with a new tunable type be a good way to expose this to userspace ? The ethtool can then configure the PHY mode.

Using an ethtool u8 tunable would be fine, with something like:

0 -> automatic
1 -> force master
2 -> force slave

Signature · 1 line
Florian
#13 lore raw
Quoted 13 lines · Florian Fainelli
Quoted 9 lines · Marek Vasut

On 1/4/19 3:19 AM, Marek Vasut wrote:

[...]

On a separate note, I was pondering about the master/slave mode of the TJA11xx PHY. Right now, the driver only operates in Automatic mode, however the PHY can be force-configured as either master or slave. Would using .set_tunable with a new tunable type be a good way to expose this to userspace ? The ethtool can then configure the PHY mode.

Quoted 5 lines

Using an ethtool u8 tunable would be fine, with something like:

0 -> automatic
1 -> force master
2 -> force slave

Fine, however I'll send it as a separate patch later. How does this name/macro sound for the tunable ?

[ETHTOOL_PHY_BRR_MODE] = "phy-broadrreach-mode",

Signature · 2 lines
Best regards,
Marek Vasut
maintainer
#14 lore raw
In reply to Marek Vasut
Quoted 25 lines · Marek Vasut

Add driver for the NXP TJA1100 and TJA1101 PHYs. These PHYs are special BroadRReach 100BaseT1 PHYs used in automotive.

Cc Andrew Lunn <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Heiner Kallweit <[email protected]>

---
V2: - Use phy_modify(), phy_{set,clear}_bits()
- Drop enable argument of tja11xx_enable_link_control()
- Use PHY_BASIC_T1_FEATURES and dont modify supported/advertised features in config_init callback
- Use genphy_soft_reset() instead of opencoding the reset sequence.
- Drop the aneg parts, since the PHY datasheet claims it does not support aneg
V3: - Replace clr with mask
- Add hwmon support
- Check commstat in tja11xx_read_status() only if link is up
- Use PHY_ID_MATCH_MODEL()

---
 drivers/net/phy/Kconfig       |   6 +
 drivers/net/phy/Makefile      |   1 +
 drivers/net/phy/nxp-tja11xx.c | 424 ++++++++++++++++++++++++++++++++++
 3 files changed, 431 insertions(+)
 create mode 100644 drivers/net/phy/nxp-tja11xx.c

[...]

Quoted 16 lines
drivers/net/phy/nxp-tja11xx.c new file +16 -0
+static int tja11xx_hwmon_read(struct device *dev,
+			      enum hwmon_sensor_types type,
+			      u32 attr, int channel, long *value)
+{
+	struct phy_device *phydev = dev_get_drvdata(dev);
+	int ret;
+
+	switch (attr) {
+	case hwmon_in_lcrit_alarm:
+		ret = phy_read(phydev, MII_INTSRC);
+		if (ret < 0)
+			return ret;
+
+		*value = !!(ret & MII_INTSRC_TEMP_ERR);
+		return 0;
+	case hwmon_temp_crit_alarm:

drivers/net/phy/nxp-tja11xx.c line 300

Quoted 10 lines
drivers/net/phy/nxp-tja11xx.c new file +10 -0
+		ret = phy_read(phydev, MII_INTSRC);
+		if (ret < 0)
+			return ret;
+
+		*value = !!(ret & MII_INTSRC_TEMP_ERR);
+		return 0;
+	default:
+		return -EOPNOTSUPP;
+	}
+}

This looks like a copy & paste error, in both cases you're doing the same.

#15 lore raw
Quoted 46 lines · Heiner Kallweit
Quoted 25 lines · Marek Vasut

Add driver for the NXP TJA1100 and TJA1101 PHYs. These PHYs are special BroadRReach 100BaseT1 PHYs used in automotive.

Cc Andrew Lunn <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Heiner Kallweit <[email protected]>

---
V2: - Use phy_modify(), phy_{set,clear}_bits()
- Drop enable argument of tja11xx_enable_link_control()
- Use PHY_BASIC_T1_FEATURES and dont modify supported/advertised features in config_init callback
- Use genphy_soft_reset() instead of opencoding the reset sequence.
- Drop the aneg parts, since the PHY datasheet claims it does not support aneg
V3: - Replace clr with mask
- Add hwmon support
- Check commstat in tja11xx_read_status() only if link is up
- Use PHY_ID_MATCH_MODEL()

---
 drivers/net/phy/Kconfig       |   6 +
 drivers/net/phy/Makefile      |   1 +
 drivers/net/phy/nxp-tja11xx.c | 424 ++++++++++++++++++++++++++++++++++
 3 files changed, 431 insertions(+)
 create mode 100644 drivers/net/phy/nxp-tja11xx.c

[...]

Quoted 19 lines
drivers/net/phy/nxp-tja11xx.c new file +19 -0
+static int tja11xx_hwmon_read(struct device *dev,
+			      enum hwmon_sensor_types type,
+			      u32 attr, int channel, long *value)
+{
+	struct phy_device *phydev = dev_get_drvdata(dev);
+	int ret;
+
+	switch (attr) {
+	case hwmon_in_lcrit_alarm:
+		ret = phy_read(phydev, MII_INTSRC);
+		if (ret < 0)
+			return ret;
+
+		*value = !!(ret & MII_INTSRC_TEMP_ERR);
+		return 0;
+	case hwmon_temp_crit_alarm:
+		ret = phy_read(phydev, MII_INTSRC);
+		if (ret < 0)
+			return ret;
Quoted 8 lines

drivers/net/phy/nxp-tja11xx.c line 300

Quoted 7 lines
drivers/net/phy/nxp-tja11xx.c new file +7 -0
+
+		*value = !!(ret & MII_INTSRC_TEMP_ERR);
+		return 0;
+	default:
+		return -EOPNOTSUPP;
+	}
+}

This looks like a copy & paste error, in both cases you're doing the same.

Fixed, thanks. I'll send V4 once I can actually test this stuff.

Signature · 2 lines
Best regards,
Marek Vasut
maintainer
#16 lore raw
In reply to Heiner Kallweit
Quoted 12 lines
Quoted 12 lines
drivers/net/phy/nxp-tja11xx.c new file +12 -0
+	switch (attr) {
+	case hwmon_in_lcrit_alarm:
+		ret = phy_read(phydev, MII_INTSRC);
+		if (ret < 0)
+			return ret;
+
+		*value = !!(ret & MII_INTSRC_TEMP_ERR);
+		return 0;
+	case hwmon_temp_crit_alarm:
+		ret = phy_read(phydev, MII_INTSRC);
+		if (ret < 0)
+			return ret;
Quoted 8 lines

drivers/net/phy/nxp-tja11xx.c line 300

Quoted 7 lines
drivers/net/phy/nxp-tja11xx.c new file +7 -0
+
+		*value = !!(ret & MII_INTSRC_TEMP_ERR);
+		return 0;
+	default:
+		return -EOPNOTSUPP;
+	}
+}

This looks like a copy & paste error, in both cases you're doing the same.

You also should not do it like this. hwmon_temp_crit_alarm is in a different set of enum's as hwmon_in_lcrit_alarm. hwmon_in_lcrit_alarm = 14. hwmon_temp_max_alarm also is 14. You should have two different switch statements to take account of this.

Andrew

#17 lore raw
Quoted 21 lines · Andrew Lunn
Quoted 12 lines
Quoted 12 lines
drivers/net/phy/nxp-tja11xx.c new file +12 -0
+	switch (attr) {
+	case hwmon_in_lcrit_alarm:
+		ret = phy_read(phydev, MII_INTSRC);
+		if (ret < 0)
+			return ret;
+
+		*value = !!(ret & MII_INTSRC_TEMP_ERR);
+		return 0;
+	case hwmon_temp_crit_alarm:
+		ret = phy_read(phydev, MII_INTSRC);
+		if (ret < 0)
+			return ret;
Quoted 8 lines

drivers/net/phy/nxp-tja11xx.c line 300

Quoted 7 lines
drivers/net/phy/nxp-tja11xx.c new file +7 -0
+
+		*value = !!(ret & MII_INTSRC_TEMP_ERR);
+		return 0;
+	default:
+		return -EOPNOTSUPP;
+	}
+}

This looks like a copy & paste error, in both cases you're doing the same.

Quoted 4 lines

You also should not do it like this. hwmon_temp_crit_alarm is in a different set of enum's as hwmon_in_lcrit_alarm. hwmon_in_lcrit_alarm = 14. hwmon_temp_max_alarm also is 14. You should have two different switch statements to take account of this.

I can also use a simple conditional, since I don't expect the number of HWMON properties to grow, eg.

if (type == hwmon_in && attr == hwmon_in_lcrit_alarm) {...} if (type == hwmon_temp && attr == hwmon_temp_crit_alarm) {...}

I think that's a bit more readable.

Signature · 2 lines
Best regards,
Marek Vasut
maintainer
#18 lore raw
Quoted 5 lines

I can also use a simple conditional, since I don't expect the number of HWMON properties to grow, eg.

if (type == hwmon_in && attr == hwmon_in_lcrit_alarm) {...} if (type == hwmon_temp && attr == hwmon_temp_crit_alarm) {...}

Yes, that is fine.

Please make sure you Cc: the HWMON maintainer on this patch.

Andrew

#19 lore raw
Quoted 9 lines · Andrew Lunn
Quoted 5 lines

I can also use a simple conditional, since I don't expect the number of HWMON properties to grow, eg.

if (type == hwmon_in && attr == hwmon_in_lcrit_alarm) {...} if (type == hwmon_temp && attr == hwmon_temp_crit_alarm) {...}

Yes, that is fine.

Please make sure you Cc: the HWMON maintainer on this patch.

Fine

Signature · 2 lines
Best regards,
Marek Vasut