All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heiner Kallweit <hkallweit1@gmail.com>
To: Marek Vasut <marex@denx.de>, netdev@vger.kernel.org
Cc: Andrew Lunn <andrew@lunn.ch>, Florian Fainelli <f.fainelli@gmail.com>
Subject: Re: [PATCH V3] net: phy: tja11xx: Add TJA11xx PHY driver
Date: Sun, 23 Dec 2018 10:41:03 +0100	[thread overview]
Message-ID: <6f19cf67-aef8-9b9c-1993-bf986bb8d41f@gmail.com> (raw)
In-Reply-To: <9ae94569-2bef-acea-6b48-18d679060901@denx.de>

On 23.12.2018 10:16, Marek Vasut wrote:
> On 12/22/18 6:39 PM, Heiner Kallweit wrote:
>> On 22.12.2018 00:35, Marek Vasut wrote:
>>> Add driver for the NXP TJA1100 and TJA1101 PHYs. These PHYs are special
>>> BroadRReach 100BaseT1 PHYs used in automotive.
>>>
>>> Signed-off-by: Marek Vasut <marex@denx.de>
>>> Cc: Andrew Lunn <andrew@lunn.ch>
>>> Cc: Florian Fainelli <f.fainelli@gmail.com>
>>> Cc: Heiner Kallweit <hkallweit1@gmail.com>
>>> ---
>>> 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
>>>
>> [...]
>>> +
>>> +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
> 
>>> +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
> 
>>> +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) ?
> 
> 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.

>> And if devm_kstrdup fails, then most likely you have an out-of-memory
>> error, so why not return -ENOMEM as usual?
> 
> Fixed
> 
>>> +
>>> +	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.
> 
> 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.

  reply	other threads:[~2018-12-23  9:41 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-21 23:35 [PATCH V3] net: phy: tja11xx: Add TJA11xx PHY driver Marek Vasut
2018-12-22 17:39 ` Heiner Kallweit
2018-12-23  9:16   ` Marek Vasut
2018-12-23  9:41     ` Heiner Kallweit [this message]
2018-12-23  9:59       ` Andrew Lunn
2018-12-23 10:21       ` Marek Vasut
2018-12-23 10:35         ` Andrew Lunn
2018-12-23 10:48           ` Marek Vasut
2019-01-03  2:09     ` Marek Vasut
2019-01-03  6:23       ` Heiner Kallweit
2019-01-04  2:19         ` Marek Vasut
2019-01-04  2:53           ` Marek Vasut
2019-01-04  2:57             ` Florian Fainelli
2019-01-04  5:40               ` Marek Vasut
2018-12-22 20:51 ` Heiner Kallweit
2018-12-23  9:13   ` Marek Vasut
2018-12-23 10:06   ` Andrew Lunn
2018-12-23 10:49     ` Marek Vasut
2018-12-23 10:58       ` Andrew Lunn
2018-12-23 11:00         ` Marek Vasut

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6f19cf67-aef8-9b9c-1993-bf986bb8d41f@gmail.com \
    --to=hkallweit1@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=f.fainelli@gmail.com \
    --cc=marex@denx.de \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.