netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* RFC: Custom PHY device detection functions
@ 2008-06-04 20:55 Felix Fietkau
  2008-06-05 18:52 ` Trent Piepho
  0 siblings, 1 reply; 3+ messages in thread
From: Felix Fietkau @ 2008-06-04 20:55 UTC (permalink / raw)
  To: netdev

Hi,

I'm working on Linux on small consumer grade wireless routers. Many of 
these have switches that connect directly to the Ethernet controller 
through MII/MDIO. These typically support 6-8 ports, one of which connects 
to the CPU. I am working on supporting some of these with PHY drivers, 
which I will submit for review when they're ready.
Most of these devices can be detected with the regular PHY ID and mask, but 
unfortunately there are some that lay out their registers a bit differently 
and thus need custom detection.
I worked around this with the following patch, that allows drivers to do 
their own detection, but I'm not sure if this is suitable for inclusion in 
the PHY layer or if there is a different way to solve this.
Any ideas?

- Felix

--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -132,6 +132,9 @@
  	struct phy_device *phydev = to_phy_device(dev);
  	struct phy_driver *phydrv = to_phy_driver(drv);

+	if (phydrv->detect)
+		return (phydrv->detect(phydev->bus, phydev->addr));
+
  	return ((phydrv->phy_id & phydrv->phy_id_mask) ==
  		(phydev->phy_id & phydrv->phy_id_mask));
  }
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -325,6 +325,11 @@
  	u32 features;
  	u32 flags;

+	/* Called during discovery to test if the
+	 * device can attach to the bus, even if
+	 * phy id and mask do not match */
+	bool (*detect)(struct mii_bus *bus, int addr);
+
  	/* Called to initialize the PHY,
  	 * including after a reset */
  	int (*config_init)(struct phy_device *phydev);


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

* Re: RFC: Custom PHY device detection functions
  2008-06-04 20:55 RFC: Custom PHY device detection functions Felix Fietkau
@ 2008-06-05 18:52 ` Trent Piepho
  2008-06-05 20:19   ` Felix Fietkau
  0 siblings, 1 reply; 3+ messages in thread
From: Trent Piepho @ 2008-06-05 18:52 UTC (permalink / raw)
  To: Felix Fietkau; +Cc: netdev

On Wed, 4 Jun 2008, Felix Fietkau wrote:
> I'm working on Linux on small consumer grade wireless routers. Many of these 
> have switches that connect directly to the Ethernet controller through 
> MII/MDIO. These typically support 6-8 ports, one of which connects to the 
> CPU. I am working on supporting some of these with PHY drivers, which I will 
> submit for review when they're ready.
> Most of these devices can be detected with the regular PHY ID and mask, but 
> unfortunately there are some that lay out their registers a bit differently 
> and thus need custom detection.
> I worked around this with the following patch, that allows drivers to do 
> their own detection, but I'm not sure if this is suitable for inclusion in 
> the PHY layer or if there is a different way to solve this.
> Any ideas?

If the phy uses non-standard registers, isn't it too late after the phy
layer has already read the phy_id?

If not, could you use the existing probe function?  Set phy_id_mask to 0 and
have the probe function return ENODEV if it's the wrong device.  I think the
driver layer will go through all matching drivers, calling each one's probe
function, until one of them claims the device.

>
> - Felix
>
> --- a/drivers/net/phy/mdio_bus.c
> +++ b/drivers/net/phy/mdio_bus.c
> @@ -132,6 +132,9 @@
> 	 struct phy_device *phydev = to_phy_device(dev);
> 	 struct phy_driver *phydrv = to_phy_driver(drv);
>
> +	if (phydrv->detect)
> +		return (phydrv->detect(phydev->bus, phydev->addr));
> +
> 	 return ((phydrv->phy_id & phydrv->phy_id_mask) ==
>  		(phydev->phy_id & phydrv->phy_id_mask));
> }
> --- a/include/linux/phy.h
> +++ b/include/linux/phy.h
> @@ -325,6 +325,11 @@
> 	 u32 features;
> 	 u32 flags;
>
> +	/* Called during discovery to test if the
> +	 * device can attach to the bus, even if
> +	 * phy id and mask do not match */
> +	bool (*detect)(struct mii_bus *bus, int addr);
> +
> 	 /* Called to initialize the PHY,
> 	 * including after a reset */
> 	 int (*config_init)(struct phy_device *phydev);
>
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
>

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

* Re: RFC: Custom PHY device detection functions
  2008-06-05 18:52 ` Trent Piepho
@ 2008-06-05 20:19   ` Felix Fietkau
  0 siblings, 0 replies; 3+ messages in thread
From: Felix Fietkau @ 2008-06-05 20:19 UTC (permalink / raw)
  To: Trent Piepho; +Cc: netdev

Trent Piepho wrote:
> On Wed, 4 Jun 2008, Felix Fietkau wrote:
>> I'm working on Linux on small consumer grade wireless routers. Many of these 
>> have switches that connect directly to the Ethernet controller through 
>> MII/MDIO. These typically support 6-8 ports, one of which connects to the 
>> CPU. I am working on supporting some of these with PHY drivers, which I will 
>> submit for review when they're ready.
>> Most of these devices can be detected with the regular PHY ID and mask, but 
>> unfortunately there are some that lay out their registers a bit differently 
>> and thus need custom detection.
>> I worked around this with the following patch, that allows drivers to do 
>> their own detection, but I'm not sure if this is suitable for inclusion in 
>> the PHY layer or if there is a different way to solve this.
>> Any ideas?
> 
> If the phy uses non-standard registers, isn't it too late after the phy
> layer has already read the phy_id?
Reading phy_id does not cause any problems, it just doesn't give us 
anything base detection on.

> If not, could you use the existing probe function?  Set phy_id_mask to 0 and
> have the probe function return ENODEV if it's the wrong device.  I think the
> driver layer will go through all matching drivers, calling each one's probe
> function, until one of them claims the device.
Thanks, I'll try that.

- Felix

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

end of thread, other threads:[~2008-06-05 20:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-04 20:55 RFC: Custom PHY device detection functions Felix Fietkau
2008-06-05 18:52 ` Trent Piepho
2008-06-05 20:19   ` Felix Fietkau

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).