diff mbox series

net: phy: add driver for Motorcomm yt8511 phy

Message ID 20210511214605.2937099-1-pgwipeout@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: phy: add driver for Motorcomm yt8511 phy | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Guessed tree name to be net-next
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch warning WARNING: please write a paragraph that describes the config symbol fully
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link

Commit Message

Peter Geis May 11, 2021, 9:46 p.m. UTC
Add a driver for the Motorcomm yt8511 phy that will be used in the
production Pine64 rk3566-quartz64 development board.
It supports gigabit transfer speeds, rgmii, and 125mhz clk output.

Signed-off-by: Peter Geis <pgwipeout@gmail.com>
---
 MAINTAINERS                 |  6 +++
 drivers/net/phy/Kconfig     |  6 +++
 drivers/net/phy/Makefile    |  1 +
 drivers/net/phy/motorcomm.c | 85 +++++++++++++++++++++++++++++++++++++
 4 files changed, 98 insertions(+)
 create mode 100644 drivers/net/phy/motorcomm.c

Comments

Russell King (Oracle) May 11, 2021, 9:56 p.m. UTC | #1
Hi,

On Tue, May 11, 2021 at 05:46:06PM -0400, Peter Geis wrote:
> +static int yt8511_config_init(struct phy_device *phydev)
> +{
> +	int ret, val, oldpage;
> +
> +	/* set clock mode to 125mhz */
> +	oldpage = phy_select_page(phydev, YT8511_EXT_CLK_GATE);
> +	if (oldpage < 0)
> +		goto err_restore_page;
> +
> +	val = __phy_read(phydev, YT8511_PAGE);
> +	val |= (YT8511_CLK_125M);
> +	ret = __phy_write(phydev, YT8511_PAGE, val);

Please consider __phy_modify(), and handle any error it returns.

> +
> +	/* disable auto sleep */
> +	ret = __phy_write(phydev, YT8511_PAGE_SELECT, YT8511_EXT_SLEEP_CTRL);

Please consider handling a failure to write here.

> +	val = __phy_read(phydev, YT8511_PAGE);
> +	val &= (~BIT(15));
> +	ret = __phy_write(phydev, YT8511_PAGE, val);

Also a use for __phy_modify().

> +
> +err_restore_page:
> +	return phy_restore_page(phydev, oldpage, ret);
> +}
> +
> +static struct phy_driver motorcomm_phy_drvs[] = {
> +	{
> +		PHY_ID_MATCH_EXACT(PHY_ID_YT8511),
> +		.name		= "YT8511 Gigabit Ethernet",
> +		.config_init	= &yt8511_config_init,

Please drop the '&' here, it's unnecessary.

Thanks.
Peter Geis May 11, 2021, 10:56 p.m. UTC | #2
On Tue, May 11, 2021 at 5:56 PM Russell King - ARM Linux admin
<linux@armlinux.org.uk> wrote:
>
> Hi,
>
> On Tue, May 11, 2021 at 05:46:06PM -0400, Peter Geis wrote:
> > +static int yt8511_config_init(struct phy_device *phydev)
> > +{
> > +     int ret, val, oldpage;
> > +
> > +     /* set clock mode to 125mhz */
> > +     oldpage = phy_select_page(phydev, YT8511_EXT_CLK_GATE);
> > +     if (oldpage < 0)
> > +             goto err_restore_page;
> > +
> > +     val = __phy_read(phydev, YT8511_PAGE);
> > +     val |= (YT8511_CLK_125M);
> > +     ret = __phy_write(phydev, YT8511_PAGE, val);
>
> Please consider __phy_modify(), and handle any error it returns.

Hey that's really neat, thanks!

>
> > +
> > +     /* disable auto sleep */
> > +     ret = __phy_write(phydev, YT8511_PAGE_SELECT, YT8511_EXT_SLEEP_CTRL);
>
> Please consider handling a failure to write here.

Will do.

>
> > +     val = __phy_read(phydev, YT8511_PAGE);
> > +     val &= (~BIT(15));
> > +     ret = __phy_write(phydev, YT8511_PAGE, val);
>
> Also a use for __phy_modify().
>
> > +
> > +err_restore_page:
> > +     return phy_restore_page(phydev, oldpage, ret);
> > +}
> > +
> > +static struct phy_driver motorcomm_phy_drvs[] = {
> > +     {
> > +             PHY_ID_MATCH_EXACT(PHY_ID_YT8511),
> > +             .name           = "YT8511 Gigabit Ethernet",
> > +             .config_init    = &yt8511_config_init,
>
> Please drop the '&' here, it's unnecessary.

Will do, thank you.

>
> Thanks.
>
> --
> RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
> FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
Leon Romanovsky May 18, 2021, 8:59 a.m. UTC | #3
On Tue, May 11, 2021 at 05:46:06PM -0400, Peter Geis wrote:
> Add a driver for the Motorcomm yt8511 phy that will be used in the
> production Pine64 rk3566-quartz64 development board.
> It supports gigabit transfer speeds, rgmii, and 125mhz clk output.
> 
> Signed-off-by: Peter Geis <pgwipeout@gmail.com>
> ---
>  MAINTAINERS                 |  6 +++
>  drivers/net/phy/Kconfig     |  6 +++
>  drivers/net/phy/Makefile    |  1 +
>  drivers/net/phy/motorcomm.c | 85 +++++++++++++++++++++++++++++++++++++
>  4 files changed, 98 insertions(+)
>  create mode 100644 drivers/net/phy/motorcomm.c

<...>

> +static const struct mdio_device_id __maybe_unused motorcomm_tbl[] = {
> +	{ PHY_ID_MATCH_EXACT(PHY_ID_YT8511) },
> +	{ /* sentinal */ }
> +}

Why is this "__maybe_unused"? This *.c file doesn't have any compilation option
to compile part of it.

The "__maybe_unused" is not needed in this case.

Thanks
Peter Geis May 19, 2021, 12:20 a.m. UTC | #4
On Tue, May 18, 2021 at 4:59 AM Leon Romanovsky <leon@kernel.org> wrote:
>
> On Tue, May 11, 2021 at 05:46:06PM -0400, Peter Geis wrote:
> > Add a driver for the Motorcomm yt8511 phy that will be used in the
> > production Pine64 rk3566-quartz64 development board.
> > It supports gigabit transfer speeds, rgmii, and 125mhz clk output.
> >
> > Signed-off-by: Peter Geis <pgwipeout@gmail.com>
> > ---
> >  MAINTAINERS                 |  6 +++
> >  drivers/net/phy/Kconfig     |  6 +++
> >  drivers/net/phy/Makefile    |  1 +
> >  drivers/net/phy/motorcomm.c | 85 +++++++++++++++++++++++++++++++++++++
> >  4 files changed, 98 insertions(+)
> >  create mode 100644 drivers/net/phy/motorcomm.c
>
> <...>
>
> > +static const struct mdio_device_id __maybe_unused motorcomm_tbl[] = {
> > +     { PHY_ID_MATCH_EXACT(PHY_ID_YT8511) },
> > +     { /* sentinal */ }
> > +}
>
> Why is this "__maybe_unused"? This *.c file doesn't have any compilation option
> to compile part of it.
>
> The "__maybe_unused" is not needed in this case.

I was simply following convention, for example the realtek.c,
micrel.c, and smsc.c drivers all have this as well.

>
> Thanks
Leon Romanovsky May 19, 2021, 8:18 a.m. UTC | #5
On Tue, May 18, 2021 at 08:20:03PM -0400, Peter Geis wrote:
> On Tue, May 18, 2021 at 4:59 AM Leon Romanovsky <leon@kernel.org> wrote:
> >
> > On Tue, May 11, 2021 at 05:46:06PM -0400, Peter Geis wrote:
> > > Add a driver for the Motorcomm yt8511 phy that will be used in the
> > > production Pine64 rk3566-quartz64 development board.
> > > It supports gigabit transfer speeds, rgmii, and 125mhz clk output.
> > >
> > > Signed-off-by: Peter Geis <pgwipeout@gmail.com>
> > > ---
> > >  MAINTAINERS                 |  6 +++
> > >  drivers/net/phy/Kconfig     |  6 +++
> > >  drivers/net/phy/Makefile    |  1 +
> > >  drivers/net/phy/motorcomm.c | 85 +++++++++++++++++++++++++++++++++++++
> > >  4 files changed, 98 insertions(+)
> > >  create mode 100644 drivers/net/phy/motorcomm.c
> >
> > <...>
> >
> > > +static const struct mdio_device_id __maybe_unused motorcomm_tbl[] = {
> > > +     { PHY_ID_MATCH_EXACT(PHY_ID_YT8511) },
> > > +     { /* sentinal */ }
> > > +}
> >
> > Why is this "__maybe_unused"? This *.c file doesn't have any compilation option
> > to compile part of it.
> >
> > The "__maybe_unused" is not needed in this case.
> 
> I was simply following convention, for example the realtek.c,
> micrel.c, and smsc.c drivers all have this as well.

Maybe they have a reason, but this specific driver doesn't have such.

Thanks

> 
> >
> > Thanks
Heiner Kallweit May 19, 2021, 10:37 a.m. UTC | #6
On 19.05.2021 10:18, Leon Romanovsky wrote:
> On Tue, May 18, 2021 at 08:20:03PM -0400, Peter Geis wrote:
>> On Tue, May 18, 2021 at 4:59 AM Leon Romanovsky <leon@kernel.org> wrote:
>>>
>>> On Tue, May 11, 2021 at 05:46:06PM -0400, Peter Geis wrote:
>>>> Add a driver for the Motorcomm yt8511 phy that will be used in the
>>>> production Pine64 rk3566-quartz64 development board.
>>>> It supports gigabit transfer speeds, rgmii, and 125mhz clk output.
>>>>
>>>> Signed-off-by: Peter Geis <pgwipeout@gmail.com>
>>>> ---
>>>>  MAINTAINERS                 |  6 +++
>>>>  drivers/net/phy/Kconfig     |  6 +++
>>>>  drivers/net/phy/Makefile    |  1 +
>>>>  drivers/net/phy/motorcomm.c | 85 +++++++++++++++++++++++++++++++++++++
>>>>  4 files changed, 98 insertions(+)
>>>>  create mode 100644 drivers/net/phy/motorcomm.c
>>>
>>> <...>
>>>
>>>> +static const struct mdio_device_id __maybe_unused motorcomm_tbl[] = {
>>>> +     { PHY_ID_MATCH_EXACT(PHY_ID_YT8511) },
>>>> +     { /* sentinal */ }
>>>> +}
>>>
>>> Why is this "__maybe_unused"? This *.c file doesn't have any compilation option
>>> to compile part of it.
>>>
>>> The "__maybe_unused" is not needed in this case.
>>
>> I was simply following convention, for example the realtek.c,
>> micrel.c, and smsc.c drivers all have this as well.
> 
> Maybe they have a reason, but this specific driver doesn't have such.
> 

It's used like this:
MODULE_DEVICE_TABLE(mdio, <mdio_device_id_tbl>);

And MODULE_DEVICE_TABLE is a no-op if MODULE isn't defined:

#ifdef MODULE
/* Creates an alias so file2alias.c can find device table. */
#define MODULE_DEVICE_TABLE(type, name)					\
extern typeof(name) __mod_##type##__##name##_device_table		\
  __attribute__ ((unused, alias(__stringify(name))))
#else  /* !MODULE */
#define MODULE_DEVICE_TABLE(type, name)
#endif

In this case the table is unused.

> Thanks
> 
>>
>>>
>>> Thanks
Leon Romanovsky May 19, 2021, 11:50 a.m. UTC | #7
On Wed, May 19, 2021 at 12:37:43PM +0200, Heiner Kallweit wrote:
> On 19.05.2021 10:18, Leon Romanovsky wrote:
> > On Tue, May 18, 2021 at 08:20:03PM -0400, Peter Geis wrote:
> >> On Tue, May 18, 2021 at 4:59 AM Leon Romanovsky <leon@kernel.org> wrote:
> >>>
> >>> On Tue, May 11, 2021 at 05:46:06PM -0400, Peter Geis wrote:
> >>>> Add a driver for the Motorcomm yt8511 phy that will be used in the
> >>>> production Pine64 rk3566-quartz64 development board.
> >>>> It supports gigabit transfer speeds, rgmii, and 125mhz clk output.
> >>>>
> >>>> Signed-off-by: Peter Geis <pgwipeout@gmail.com>
> >>>> ---
> >>>>  MAINTAINERS                 |  6 +++
> >>>>  drivers/net/phy/Kconfig     |  6 +++
> >>>>  drivers/net/phy/Makefile    |  1 +
> >>>>  drivers/net/phy/motorcomm.c | 85 +++++++++++++++++++++++++++++++++++++
> >>>>  4 files changed, 98 insertions(+)
> >>>>  create mode 100644 drivers/net/phy/motorcomm.c
> >>>
> >>> <...>
> >>>
> >>>> +static const struct mdio_device_id __maybe_unused motorcomm_tbl[] = {
> >>>> +     { PHY_ID_MATCH_EXACT(PHY_ID_YT8511) },
> >>>> +     { /* sentinal */ }
> >>>> +}
> >>>
> >>> Why is this "__maybe_unused"? This *.c file doesn't have any compilation option
> >>> to compile part of it.
> >>>
> >>> The "__maybe_unused" is not needed in this case.
> >>
> >> I was simply following convention, for example the realtek.c,
> >> micrel.c, and smsc.c drivers all have this as well.
> > 
> > Maybe they have a reason, but this specific driver doesn't have such.
> > 
> 
> It's used like this:
> MODULE_DEVICE_TABLE(mdio, <mdio_device_id_tbl>);
> 
> And MODULE_DEVICE_TABLE is a no-op if MODULE isn't defined:
> 
> #ifdef MODULE
> /* Creates an alias so file2alias.c can find device table. */
> #define MODULE_DEVICE_TABLE(type, name)					\
> extern typeof(name) __mod_##type##__##name##_device_table		\
>   __attribute__ ((unused, alias(__stringify(name))))
> #else  /* !MODULE */
> #define MODULE_DEVICE_TABLE(type, name)
> #endif
> 
> In this case the table is unused.

Do you see compilation warning for such scenario?

Thanks

> 
> > Thanks
> > 
> >>
> >>>
> >>> Thanks
> 
>
Peter Geis May 19, 2021, 12:45 p.m. UTC | #8
On Wed, May 19, 2021 at 7:50 AM Leon Romanovsky <leon@kernel.org> wrote:
>
> On Wed, May 19, 2021 at 12:37:43PM +0200, Heiner Kallweit wrote:
> > On 19.05.2021 10:18, Leon Romanovsky wrote:
> > > On Tue, May 18, 2021 at 08:20:03PM -0400, Peter Geis wrote:
> > >> On Tue, May 18, 2021 at 4:59 AM Leon Romanovsky <leon@kernel.org> wrote:
> > >>>
> > >>> On Tue, May 11, 2021 at 05:46:06PM -0400, Peter Geis wrote:
> > >>>> Add a driver for the Motorcomm yt8511 phy that will be used in the
> > >>>> production Pine64 rk3566-quartz64 development board.
> > >>>> It supports gigabit transfer speeds, rgmii, and 125mhz clk output.
> > >>>>
> > >>>> Signed-off-by: Peter Geis <pgwipeout@gmail.com>
> > >>>> ---
> > >>>>  MAINTAINERS                 |  6 +++
> > >>>>  drivers/net/phy/Kconfig     |  6 +++
> > >>>>  drivers/net/phy/Makefile    |  1 +
> > >>>>  drivers/net/phy/motorcomm.c | 85 +++++++++++++++++++++++++++++++++++++
> > >>>>  4 files changed, 98 insertions(+)
> > >>>>  create mode 100644 drivers/net/phy/motorcomm.c
> > >>>
> > >>> <...>
> > >>>
> > >>>> +static const struct mdio_device_id __maybe_unused motorcomm_tbl[] = {
> > >>>> +     { PHY_ID_MATCH_EXACT(PHY_ID_YT8511) },
> > >>>> +     { /* sentinal */ }
> > >>>> +}
> > >>>
> > >>> Why is this "__maybe_unused"? This *.c file doesn't have any compilation option
> > >>> to compile part of it.
> > >>>
> > >>> The "__maybe_unused" is not needed in this case.
> > >>
> > >> I was simply following convention, for example the realtek.c,
> > >> micrel.c, and smsc.c drivers all have this as well.
> > >
> > > Maybe they have a reason, but this specific driver doesn't have such.
> > >
> >
> > It's used like this:
> > MODULE_DEVICE_TABLE(mdio, <mdio_device_id_tbl>);
> >
> > And MODULE_DEVICE_TABLE is a no-op if MODULE isn't defined:
> >
> > #ifdef MODULE
> > /* Creates an alias so file2alias.c can find device table. */
> > #define MODULE_DEVICE_TABLE(type, name)                                       \
> > extern typeof(name) __mod_##type##__##name##_device_table             \
> >   __attribute__ ((unused, alias(__stringify(name))))
> > #else  /* !MODULE */
> > #define MODULE_DEVICE_TABLE(type, name)
> > #endif
> >
> > In this case the table is unused.
>
> Do you see compilation warning for such scenario?

The issue you are describing has been fixed since 2010:

commit cf93c94581bab447a5634c6d737c1cf38c080261
Author: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Date:   Sun Oct 3 23:43:32 2010 +0000

    net/phy: fix many "defined but unused" warnings

    MODULE_DEVICE_TABLE only expands to something if it's compiled
    for a module.  So when building-in support for the phys, the
    mdio_device_id tables are unused.  Marking them with __maybe_unused
    fixes the following warnings:

There is a strong push to fix all warnings during build, including W=1 warnings.
For fun I rebuilt without module support and confirmed that removing
this does trigger a W=1 warning.

>
> Thanks
>
> >
> > > Thanks
> > >
> > >>
> > >>>
> > >>> Thanks
> >
> >
Leon Romanovsky May 19, 2021, 12:56 p.m. UTC | #9
On Wed, May 19, 2021 at 08:45:21AM -0400, Peter Geis wrote:
> On Wed, May 19, 2021 at 7:50 AM Leon Romanovsky <leon@kernel.org> wrote:
> >
> > On Wed, May 19, 2021 at 12:37:43PM +0200, Heiner Kallweit wrote:
> > > On 19.05.2021 10:18, Leon Romanovsky wrote:
> > > > On Tue, May 18, 2021 at 08:20:03PM -0400, Peter Geis wrote:
> > > >> On Tue, May 18, 2021 at 4:59 AM Leon Romanovsky <leon@kernel.org> wrote:
> > > >>>
> > > >>> On Tue, May 11, 2021 at 05:46:06PM -0400, Peter Geis wrote:
> > > >>>> Add a driver for the Motorcomm yt8511 phy that will be used in the
> > > >>>> production Pine64 rk3566-quartz64 development board.
> > > >>>> It supports gigabit transfer speeds, rgmii, and 125mhz clk output.
> > > >>>>
> > > >>>> Signed-off-by: Peter Geis <pgwipeout@gmail.com>
> > > >>>> ---
> > > >>>>  MAINTAINERS                 |  6 +++
> > > >>>>  drivers/net/phy/Kconfig     |  6 +++
> > > >>>>  drivers/net/phy/Makefile    |  1 +
> > > >>>>  drivers/net/phy/motorcomm.c | 85 +++++++++++++++++++++++++++++++++++++
> > > >>>>  4 files changed, 98 insertions(+)
> > > >>>>  create mode 100644 drivers/net/phy/motorcomm.c
> > > >>>
> > > >>> <...>
> > > >>>
> > > >>>> +static const struct mdio_device_id __maybe_unused motorcomm_tbl[] = {
> > > >>>> +     { PHY_ID_MATCH_EXACT(PHY_ID_YT8511) },
> > > >>>> +     { /* sentinal */ }
> > > >>>> +}
> > > >>>
> > > >>> Why is this "__maybe_unused"? This *.c file doesn't have any compilation option
> > > >>> to compile part of it.
> > > >>>
> > > >>> The "__maybe_unused" is not needed in this case.
> > > >>
> > > >> I was simply following convention, for example the realtek.c,
> > > >> micrel.c, and smsc.c drivers all have this as well.
> > > >
> > > > Maybe they have a reason, but this specific driver doesn't have such.
> > > >
> > >
> > > It's used like this:
> > > MODULE_DEVICE_TABLE(mdio, <mdio_device_id_tbl>);
> > >
> > > And MODULE_DEVICE_TABLE is a no-op if MODULE isn't defined:
> > >
> > > #ifdef MODULE
> > > /* Creates an alias so file2alias.c can find device table. */
> > > #define MODULE_DEVICE_TABLE(type, name)                                       \
> > > extern typeof(name) __mod_##type##__##name##_device_table             \
> > >   __attribute__ ((unused, alias(__stringify(name))))
> > > #else  /* !MODULE */
> > > #define MODULE_DEVICE_TABLE(type, name)
> > > #endif
> > >
> > > In this case the table is unused.
> >
> > Do you see compilation warning for such scenario?
> 
> The issue you are describing has been fixed since 2010:
> 
> commit cf93c94581bab447a5634c6d737c1cf38c080261
> Author: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> Date:   Sun Oct 3 23:43:32 2010 +0000
> 
>     net/phy: fix many "defined but unused" warnings
> 
>     MODULE_DEVICE_TABLE only expands to something if it's compiled
>     for a module.  So when building-in support for the phys, the
>     mdio_device_id tables are unused.  Marking them with __maybe_unused
>     fixes the following warnings:
> 
> There is a strong push to fix all warnings during build, including W=1 warnings.
> For fun I rebuilt without module support and confirmed that removing
> this does trigger a W=1 warning.

I'm sorry that I continue to ask, but is net/phy/* usable without MODULE?
If not, the better fix is to require it in Kconfig instead of fixing all drivers.

Thanks for your answers.

> 
> >
> > Thanks
> >
> > >
> > > > Thanks
> > > >
> > > >>
> > > >>>
> > > >>> Thanks
> > >
> > >
Russell King (Oracle) May 19, 2021, 1:15 p.m. UTC | #10
On Wed, May 19, 2021 at 03:56:18PM +0300, Leon Romanovsky wrote:
> I'm sorry that I continue to ask, but is net/phy/* usable without MODULE?

Simple answer: it is.
Peter Geis May 19, 2021, 1:25 p.m. UTC | #11
On Wed, May 19, 2021 at 9:15 AM Russell King (Oracle)
<linux@armlinux.org.uk> wrote:
>
> On Wed, May 19, 2021 at 03:56:18PM +0300, Leon Romanovsky wrote:
> > I'm sorry that I continue to ask, but is net/phy/* usable without MODULE?
>
> Simple answer: it is.

As far as I can tell, so correct me if I'm wrong, MODULE_DEVICE_TABLE
is what permits the module system to automatically load the correct
module for the device.

>
> --
> RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
> FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
diff mbox series

Patch

diff --git a/MAINTAINERS b/MAINTAINERS
index 601b5ae0368a..2a2e406238fc 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12388,6 +12388,12 @@  F:	Documentation/userspace-api/media/drivers/meye*
 F:	drivers/media/pci/meye/
 F:	include/uapi/linux/meye.h
 
+MOTORCOMM PHY DRIVER
+M:	Peter Geis <pgwipeout@gmail.com>
+L:	netdev@vger.kernel.org
+S:	Maintained
+F:	drivers/net/phy/motorcomm.c
+
 MOXA SMARTIO/INDUSTIO/INTELLIO SERIAL CARD
 S:	Orphan
 F:	Documentation/driver-api/serial/moxa-smartio.rst
diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index 288bf405ebdb..16db9f8037b5 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -229,6 +229,12 @@  config MICROSEMI_PHY
 	help
 	  Currently supports VSC8514, VSC8530, VSC8531, VSC8540 and VSC8541 PHYs
 
+config MOTORCOMM_PHY
+	tristate "Motorcomm PHYs"
+	help
+	  Enables support for Motorcomm network PHYs.
+	  Currently supports the YT8511 gigabit PHY.
+
 config NATIONAL_PHY
 	tristate "National Semiconductor PHYs"
 	help
diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
index bcda7ed2455d..37ffbc6e3c87 100644
--- a/drivers/net/phy/Makefile
+++ b/drivers/net/phy/Makefile
@@ -70,6 +70,7 @@  obj-$(CONFIG_MICREL_PHY)	+= micrel.o
 obj-$(CONFIG_MICROCHIP_PHY)	+= microchip.o
 obj-$(CONFIG_MICROCHIP_T1_PHY)	+= microchip_t1.o
 obj-$(CONFIG_MICROSEMI_PHY)	+= mscc/
+obj-$(CONFIG_MOTORCOMM_PHY)	+= motorcomm.o
 obj-$(CONFIG_NATIONAL_PHY)	+= national.o
 obj-$(CONFIG_NXP_C45_TJA11XX_PHY)	+= nxp-c45-tja11xx.o
 obj-$(CONFIG_NXP_TJA11XX_PHY)	+= nxp-tja11xx.o
diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c
new file mode 100644
index 000000000000..c6923dcf9f8f
--- /dev/null
+++ b/drivers/net/phy/motorcomm.c
@@ -0,0 +1,85 @@ 
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Driver for Motorcomm PHYs
+ *
+ * Author: Peter Geis <pgwipeout@gmail.com>
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/phy.h>
+
+#define PHY_ID_YT8511		0x0000010a
+
+#define YT8511_PAGE_SELECT	0x1e
+#define YT8511_PAGE		0x1f
+#define YT8511_EXT_CLK_GATE	0x0c
+#define YT8511_EXT_SLEEP_CTRL	0x27
+
+/* 2b00 25m from pll
+ * 2b01 25m from xtl *default*
+ * 2b10 62.m from pll
+ * 2b11 125m from pll
+ */
+#define YT8511_CLK_125M		(BIT(2) | BIT(1))
+
+static int yt8511_read_page(struct phy_device *phydev)
+{
+	return __phy_read(phydev, YT8511_PAGE_SELECT);
+};
+
+static int yt8511_write_page(struct phy_device *phydev, int page)
+{
+	return __phy_write(phydev, YT8511_PAGE_SELECT, page);
+};
+
+static int yt8511_config_init(struct phy_device *phydev)
+{
+	int ret, val, oldpage;
+
+	/* set clock mode to 125mhz */
+	oldpage = phy_select_page(phydev, YT8511_EXT_CLK_GATE);
+	if (oldpage < 0)
+		goto err_restore_page;
+
+	val = __phy_read(phydev, YT8511_PAGE);
+	val |= (YT8511_CLK_125M);
+	ret = __phy_write(phydev, YT8511_PAGE, val);
+
+	/* disable auto sleep */
+	ret = __phy_write(phydev, YT8511_PAGE_SELECT, YT8511_EXT_SLEEP_CTRL);
+	val = __phy_read(phydev, YT8511_PAGE);
+	val &= (~BIT(15));
+	ret = __phy_write(phydev, YT8511_PAGE, val);
+
+err_restore_page:
+	return phy_restore_page(phydev, oldpage, ret);
+}
+
+static struct phy_driver motorcomm_phy_drvs[] = {
+	{
+		PHY_ID_MATCH_EXACT(PHY_ID_YT8511),
+		.name		= "YT8511 Gigabit Ethernet",
+		.config_init	= &yt8511_config_init,
+		.get_features	= genphy_read_abilities,
+		.config_aneg	= genphy_config_aneg,
+		.read_status	= genphy_read_status,
+		.suspend	= genphy_suspend,
+		.resume		= genphy_resume,
+		.read_page	= yt8511_read_page,
+		.write_page	= yt8511_write_page,
+	},
+};
+
+module_phy_driver(motorcomm_phy_drvs);
+
+MODULE_DESCRIPTION("Motorcomm PHY driver");
+MODULE_AUTHOR("Peter Geis");
+MODULE_LICENSE("GPL");
+
+static const struct mdio_device_id __maybe_unused motorcomm_tbl[] = {
+	{ PHY_ID_MATCH_EXACT(PHY_ID_YT8511) },
+	{ /* sentinal */ }
+};
+
+MODULE_DEVICE_TABLE(mdio, motorcomm_tbl);