The Realtek RTL8211E allows customization of the PHY LED behavior,
like which LEDs are on for certain link speeds and which LEDs blink
when there is traffic. By default EEE LED mode is enabled, in which
a blinking LED is on for 400ms and off for 2s. This series adds
support for configuring the LED behavior through device tree
properties.
The RTL8211E supports Spread Spectrum Clocking (SSC), which reduces
clock noise that may affect other board functions. By default SSC
is disabled, this series adds support for enabling it through a
device tree property.
Certain registers on the RTL8211E can only be accessed through
a vendor specific extended page mechanism. Extended pages need
to be accessed for the LED configuration and enabling SSC. This
series adds helpers to facilitate accessing extended pages.
Matthias Kaehlcke (7):
dt-bindings: net: Add bindings for Realtek PHYs
net: phy: realtek: Allow disabling RTL8211E EEE LED mode
dt-bindings: net: realtek: Add property to enable SSC
net: phy: realtek: Add helpers for accessing RTL8211E extension pages
net: phy: realtek: Support SSC for the RTL8211E
dt-bindings: net: realtek: Add property to configure LED mode
net: phy: realtek: configure RTL8211E LEDs
.../devicetree/bindings/net/realtek.txt | 47 +++++
drivers/net/phy/realtek.c | 171 ++++++++++++++++--
include/dt-bindings/net/realtek.h | 18 ++
3 files changed, 221 insertions(+), 15 deletions(-)
create mode 100644 Documentation/devicetree/bindings/net/realtek.txt
create mode 100644 include/dt-bindings/net/realtek.h
--
2.22.0.410.gd8fdbe21b5-goog
EEE LED mode is enabled by default on the RTL8211E. Disable it when
the device tree property 'realtek,eee-led-mode-disable' exists.
The magic values to disable EEE LED mode were taken from the RTL8211E
datasheet, unfortunately they are not further documented.
Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
TODO: DT validation
Changes in v3:
- don't have two versions of rtl8211e_config_init()
(was due to my dev kernel being 4.19, which doesn't have
this function yet)
- changed return type of rtl8211e_disable_eee_led_mode() to void
- added empty line after rtl8211e_config_init()
Changes in v2:
- patch added to the series
---
drivers/net/phy/realtek.c | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
@@ -53,6 +58,26 @@ static int rtl821x_write_page(struct phy_device *phydev, int page)return__phy_write(phydev,RTL821x_PAGE_SELECT,page);}+staticvoidrtl8211e_disable_eee_led_mode(structphy_device*phydev)+{+intoldpage;+interr=0;++oldpage=phy_select_page(phydev,5);+if(oldpage<0)+gotoout;++/* write magic values to disable EEE LED mode */+err=__phy_write(phydev,RTL8211E_EEE_LED_MODE1,0x8b82);+if(err)+gotoout;++err=__phy_write(phydev,RTL8211E_EEE_LED_MODE2,0x052b);++out:+phy_restore_page(phydev,oldpage,err);+}+staticintrtl8201_ack_interrupt(structphy_device*phydev){interr;
@@ -184,9 +209,13 @@ static int rtl8211f_config_init(struct phy_device *phydev)staticintrtl8211e_config_init(structphy_device*phydev){+structdevice*dev=&phydev->mdio.dev;intret=0,oldpage;u16val;+if(of_property_read_bool(dev->of_node,"realtek,eee-led-mode-disable"))+rtl8211e_disable_eee_led_mode(phydev);+/* enable TX/RX delay for rgmii-* modes, and disable them for rgmii. */switch(phydev->interface){casePHY_INTERFACE_MODE_RGMII:
Configure the RTL8211E LEDs behavior when the device tree property
'realtek,led-modes' is specified.
Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
TODO: DT validation
Changes in v3:
- sanity check led-modes values
- set LACR bits in a more readable way
- use phydev_err() instead of dev_err()
- log an error if LED configuration fails
Changes in v2:
- patch added to the series
---
drivers/net/phy/realtek.c | 72 +++++++++++++++++++++++++++++++++++++--
1 file changed, 70 insertions(+), 2 deletions(-)
@@ -123,6 +134,62 @@ static void rtl8211e_disable_eee_led_mode(struct phy_device *phydev)phy_restore_page(phydev,oldpage,err);}+staticintrtl8211e_config_leds(structphy_device*phydev)+{+structdevice*dev=&phydev->mdio.dev;+intcount,i,oldpage,ret;+u16lacr_bits=0,lcr_bits=0;++if(!dev->of_node)+return0;++if(of_property_read_bool(dev->of_node,"realtek,eee-led-mode-disable"))+rtl8211e_disable_eee_led_mode(phydev);++count=of_property_count_elems_of_size(dev->of_node,+"realtek,led-modes",+sizeof(u32));+if(count<0||count>3)+return-EINVAL;++for(i=0;i<count;i++){+u32val;++of_property_read_u32_index(dev->of_node,+"realtek,led-modes",i,&val);+if((val>RTL8211E_LINK_10_100_1000&&+val<RTL8211E_LINK_ACTIVITY)||+val>(RTL8211E_LINK_ACTIVITY|RTL8211E_LINK_10_100_1000))+return-EINVAL;++if(val&RTL8211E_LINK_ACTIVITY)+lacr_bits|=BIT(RLT8211E_LACR_LEDACTCTRL_SHIFT+i);++lcr_bits|=(u16)(val&0xf)<<(i*4);+}++oldpage=rtl8211e_select_ext_page(phydev,44);+if(oldpage<0){+phydev_err(phydev,"failed to select extended page: %d\n",oldpage);+gotoerr;+}++ret=__phy_modify(phydev,RTL8211E_LACR,+RLT8211E_LACR_LEDACTCTRL_MASK,lacr_bits);+if(ret){+phydev_err(phydev,"failed to write LACR reg: %d\n",ret);+gotoerr;+}++ret=__phy_modify(phydev,RTL8211E_LCR,+RTL8211E_LCR_LEDCTRL_MASK,lcr_bits);+if(ret)+phydev_err(phydev,"failed to write LCR reg: %d\n",ret);++err:+returnphy_restore_page(phydev,oldpage,ret);+}+staticintrtl8201_ack_interrupt(structphy_device*phydev){interr;
@@ -267,8 +334,9 @@ static int rtl8211e_config_init(struct phy_device *phydev)ret);}-if(of_property_read_bool(dev->of_node,"realtek,eee-led-mode-disable"))-rtl8211e_disable_eee_led_mode(phydev);+ret=rtl8211e_config_leds(phydev);+if(ret)+phydev_err(phydev,"LED configuration failed: %d\n",ret);/* enable TX/RX delay for rgmii-* modes, and disable them for rgmii. */switch(phydev->interface){
Add the 'realtek,enable-ssc' property to enable Spread Spectrum
Clocking (SSC) on Realtek PHYs that support it.
Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
Changes in v3:
- changed wording for supported PHY models
Changes in v2:
- patch added to the series (kind of, it already existed, but now
the binding is created by another patch)
---
Documentation/devicetree/bindings/net/realtek.txt | 5 +++++
1 file changed, 5 insertions(+)
@@ -15,6 +15,10 @@ Optional properties: Only supported for "realtek,rtl8211e".+- realtek,enable-ssc : Enable Spread Spectrum Clocking (SSC) on this port.++ Only supported for "realtek,rtl8211e".+ Example:
The LED behavior of some Realtek PHYs is configurable. Add the
property 'realtek,led-modes' to specify the configuration of the
LEDs.
Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
Changes in v3:
- added RTL8211E_LED_OFF to LED modes
- changed wording for supported PHY models
Changes in v2:
- patch added to the series
---
.../devicetree/bindings/net/realtek.txt | 11 +++++++++++
include/dt-bindings/net/realtek.h | 18 ++++++++++++++++++
2 files changed, 29 insertions(+)
create mode 100644 include/dt-bindings/net/realtek.h
@@ -19,6 +19,14 @@ Optional properties: Only supported for "realtek,rtl8211e".+- realtek,led-modes: LED mode configuration.++ A 0..3 element vector, with each element configuring the operating+ mode of an LED. Omitted LEDs are turned off. Allowed values are+ defined in "include/dt-bindings/net/realtek.h".++ Only supported for "realtek,rtl8211e".+ Example:
By default Spread-Spectrum Clocking (SSC) is disabled on the RTL8211E.
Enable it if the device tree property 'realtek,enable-ssc' exists.
Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
TODO: DT validation
Changes in v3:
- use phydev_err() instead of dev_err()
Changes in v2:
- enable SSC in config_init() instead of probe()
- fixed error check after enabling SSC
---
drivers/net/phy/realtek.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
@@ -250,8 +255,18 @@ static int rtl8211f_config_init(struct phy_device *phydev)staticintrtl8211e_config_init(structphy_device*phydev){structdevice*dev=&phydev->mdio.dev;+intret;u16val;+if(of_property_read_bool(dev->of_node,"realtek,enable-ssc")){+ret=rtl8211e_modify_ext_paged(phydev,0xa0,RTL8211E_SCR,+RTL8211E_SCR_DISABLE_RXC_SSC,+0);+if(ret<0)+phydev_err(phydev,"failed to enable SSC on RXC: %d\n",+ret);+}+if(of_property_read_bool(dev->of_node,"realtek,eee-led-mode-disable"))rtl8211e_disable_eee_led_mode(phydev);
The RTL8211E has extension pages, which can be accessed after
selecting a page through a custom method. Add a function to
modify bits in a register of an extension page and a helper for
selecting an ext page. Use rtl8211e_modify_ext_paged() in
rtl8211e_config_init() instead of doing things 'manually'.
rtl8211e_modify_ext_paged() is inspired by its counterpart
phy_modify_paged().
Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
Changes in v3:
- use the new function in rtl8211e_config_init() instead of
doing things 'manually'
- use existing RTL8211E_EXT_PAGE instead of adding a new define
- updated commit message
Changes in v2:
- use phy_select_page() and phy_restore_page(), get rid of
rtl8211e_restore_page()
- s/rtl821e_select_ext_page/rtl8211e_select_ext_page/
- updated commit message
---
drivers/net/phy/realtek.c | 57 +++++++++++++++++++++++++++++----------
1 file changed, 43 insertions(+), 14 deletions(-)
Add the 'realtek,eee-led-mode-disable' property to disable EEE
LED mode on Realtek PHYs that support it.
Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
TODO: adapt PHY core to deal with optional compatible strings
Changes in v3:
- added entry for compatible string
- added compatible string to example
- mention that the new property is only available for RTL8211E
Changes in v2:
- document 'realtek,eee-led-mode-disable' instead of
'realtek,enable-ssc' in the initial version
---
.../devicetree/bindings/net/realtek.txt | 31 +++++++++++++++++++
1 file changed, 31 insertions(+)
create mode 100644 Documentation/devicetree/bindings/net/realtek.txt
@@ -0,0 +1,31 @@+Realtek PHY properties.++This document describes properties of Realtek PHYs.++Optional properties:+- compatible: should be one of the following:+ "realtek,rtl8201cp", "realtek,rtl8201f", "realtek,rtl8211",+ "realtek,rtl8211b", "realtek,rtl8211c", "realtek,rtl8211dn",+ "realtek,rtl8211e", "realtek,rtl8211f", "rtl8366rb"++ the property is required if any of the properties are specified that+ are only supported for certain Realtek PHYs.++- realtek,eee-led-mode-disable: Disable EEE LED mode on this port.++ Only supported for "realtek,rtl8211e".+++Example:++mdio0 {+ compatible = "snps,dwmac-mdio";+ #address-cells = <1>;+ #size-cells = <0>;++ ethphy: ethernet-phy@1 {+ compatible = "realtek,rtl8211e";+ reg = <1>;+ realtek,eee-led-mode-disable;+ };+};
From: Andrew Lunn <andrew@lunn.ch> Date: 2019-07-08 19:46:27
On Mon, Jul 08, 2019 at 12:24:53PM -0700, Matthias Kaehlcke wrote:
Add the 'realtek,eee-led-mode-disable' property to disable EEE
LED mode on Realtek PHYs that support it.
Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
TODO: adapt PHY core to deal with optional compatible strings
Yes. Does this even work at the moment? I would expect
of_mdiobus_child_is_phy() to return false, indicating the device is
not actually a PHY.
Andrew
From: Andrew Lunn <andrew@lunn.ch> Date: 2019-07-08 19:48:41
On Mon, Jul 08, 2019 at 12:24:58PM -0700, Matthias Kaehlcke wrote:
The LED behavior of some Realtek PHYs is configurable. Add the
property 'realtek,led-modes' to specify the configuration of the
LEDs.
Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
Hi Matthias
Humm. I thought you were going to drop this and the next patch?
Andrew
On Mon, Jul 08, 2019 at 09:46:15PM +0200, Andrew Lunn wrote:
On Mon, Jul 08, 2019 at 12:24:53PM -0700, Matthias Kaehlcke wrote:
quoted
Add the 'realtek,eee-led-mode-disable' property to disable EEE
LED mode on Realtek PHYs that support it.
Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
TODO: adapt PHY core to deal with optional compatible strings
Yes. Does this even work at the moment? I would expect
of_mdiobus_child_is_phy() to return false, indicating the device is
not actually a PHY.
Indeed, it currently doesn't work atm. I found that removing the check
for dev->of_node in of_mdiobus_link_mdiodev() helps, but I imagine
doing (only) this might have undesired side-effects.
Hi Andrew,
On Mon, Jul 08, 2019 at 09:48:34PM +0200, Andrew Lunn wrote:
On Mon, Jul 08, 2019 at 12:24:58PM -0700, Matthias Kaehlcke wrote:
quoted
The LED behavior of some Realtek PHYs is configurable. Add the
property 'realtek,led-modes' to specify the configuration of the
LEDs.
Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
Hi Matthias
Humm. I thought you were going to drop this and the next patch?
It wasn't clear to me whether not introducing a generic interface is a
definitive NACK and tought I could at least post a version with the
review comments addressed. If there is no way forward without a
generic interface I'll drop the two patches.
From: Andrew Lunn <andrew@lunn.ch> Date: 2019-07-08 21:14:02
On Mon, Jul 08, 2019 at 01:01:36PM -0700, Matthias Kaehlcke wrote:
On Mon, Jul 08, 2019 at 09:46:15PM +0200, Andrew Lunn wrote:
quoted
On Mon, Jul 08, 2019 at 12:24:53PM -0700, Matthias Kaehlcke wrote:
quoted
Add the 'realtek,eee-led-mode-disable' property to disable EEE
LED mode on Realtek PHYs that support it.
Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
TODO: adapt PHY core to deal with optional compatible strings
Yes. Does this even work at the moment? I would expect
of_mdiobus_child_is_phy() to return false, indicating the device is
not actually a PHY.
Indeed, it currently doesn't work atm. I found that removing the check
for dev->of_node in of_mdiobus_link_mdiodev() helps, but I imagine
doing (only) this might have undesired side-effects.
O.K.
Please put RFC in patches like this which don't actually work and so
should not be merged. We don't want David accidentally merging them!
Andrew