The driver has matched "microchip,lan9354-mdio" since commit 13248b975038 ("net: dsa: LAN9303: Add basic support for LAN9354"), but the binding only documents the two SMSC compatibles. A board using the LAN9354 therefore fails dtbs_check even though the driver binds. Add the compatible to the enum and mention the LAN9354 in the title and description. Signed-off-by: Paul Louvel (Schneider Electric) --- Documentation/devicetree/bindings/net/dsa/smsc,lan9303.yaml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/net/dsa/smsc,lan9303.yaml b/Documentation/devicetree/bindings/net/dsa/smsc,lan9303.yaml index 42f8473538a0..95abf043a118 100644 --- a/Documentation/devicetree/bindings/net/dsa/smsc,lan9303.yaml +++ b/Documentation/devicetree/bindings/net/dsa/smsc,lan9303.yaml @@ -4,15 +4,16 @@ $id: http://devicetree.org/schemas/net/dsa/smsc,lan9303.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: SMSC/MicroChip LAN9303 three port ethernet switch +title: SMSC/MicroChip LAN9303/LAN9354 three port ethernet switch maintainers: - Frank Li description: - The LAN9303 is a three port ethernet switch with integrated PHYs for the - two external ports. The third port is an RMII/MII interface to a host - processor. The device can be managed via I2C or MDIO. + The LAN9303 and LAN9354 are three port ethernet switches with integrated + PHYs for the two external ports. The third port is an RMII/MII interface + to a host processor. The LAN9303 can be managed via I2C or MDIO. The + LAN9354 is supported in MDIO mode. Note - always use 'reg = <0/1/2>;' for the three DSA ports, even if the device is configured to use 1/2/3 instead. This hardware configuration @@ -23,6 +24,7 @@ properties: enum: - smsc,lan9303-i2c - smsc,lan9303-mdio + - microchip,lan9354-mdio reg: maxItems: 1 -- 2.56.1 The LAN9303 and LAN9354 select the function of all six LED pins with a single LED_FUN field. On some boards the LED straps double as configuration straps for other functions, such as the PHY address or the EEPROM size, so the desired LED mode cannot be strapped. Document an optional "smsc,led-mode" property. The value 110b is reserved on the LAN9354. Signed-off-by: Paul Louvel (Schneider Electric) --- .../devicetree/bindings/net/dsa/smsc,lan9303.yaml | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Documentation/devicetree/bindings/net/dsa/smsc,lan9303.yaml b/Documentation/devicetree/bindings/net/dsa/smsc,lan9303.yaml index 95abf043a118..f044589b643d 100644 --- a/Documentation/devicetree/bindings/net/dsa/smsc,lan9303.yaml +++ b/Documentation/devicetree/bindings/net/dsa/smsc,lan9303.yaml @@ -40,6 +40,18 @@ properties: default: 200 $ref: /schemas/types.yaml#/definitions/uint32 + smsc,led-mode: + description: | + LED function mode. + + This value will apply a predefined configuration to all six LED pins of + both external ports. See the "LED Operation" section of the datasheet. + + When the property is absent, the value sampled from the configuration + straps is kept. + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0 + required: - compatible - reg @@ -48,6 +60,19 @@ unevaluatedProperties: false allOf: - $ref: dsa.yaml# + - if: + properties: + compatible: + contains: + const: microchip,lan9354-mdio + then: + properties: + smsc,led-mode: + enum: [0, 1, 2, 3, 4, 5, 7] + else: + properties: + smsc,led-mode: + maximum: 3 examples: - | -- 2.56.1 The LED function of the LAN9303 and LAN9354 is selected by a single LED_FUN field that applies to all six LED pins of the two external ports. On some boards the LED straps double as configuration straps for other functions, such as the PHY address or the EEPROM size, so the desired LED mode cannot be strapped and has to be programmed by the driver. The LED subsystem is not used here: it models each LED independently, while this hardware has one function field for all LEDs. Read the optional "smsc,led-mode", and configure the device accordingly. Signed-off-by: Paul Louvel (Schneider Electric) --- drivers/net/dsa/lan9303-core.c | 74 ++++++++++++++++++++++++++++++++++++++++-- include/linux/dsa/lan9303.h | 8 +++++ 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/lan9303-core.c b/drivers/net/dsa/lan9303-core.c index 8eeb8953ff24..6a9ade873e42 100644 --- a/drivers/net/dsa/lan9303-core.c +++ b/drivers/net/dsa/lan9303-core.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -63,6 +64,13 @@ #define LAN9303_SWITCH_CSR_CMD_BUSY BIT(31) #define LAN9303_SWITCH_CSR_CMD_RW BIT(30) #define LAN9303_SWITCH_CSR_CMD_LANES (BIT(19) | BIT(18) | BIT(17) | BIT(16)) +#define LAN9303_LED_CFG 0x6f +# define LAN9303_LED_CFG_LED_FUN_MAX_VAL 0x7 +# define LAN9303_LED_CFG_LED_FUN_SHIFT 8 +# define LAN9303_LED_CFG_LED_FUN_MASK GENMASK(9, 8) +# define LAN9303_LED_CFG_LED_MODES GENMASK(3, 0) +# define LAN9354_LED_CFG_LED_FUN_MASK GENMASK(10, 8) +# define LAN9354_LED_CFG_LED_MODES (GENMASK(5, 0) | BIT(7)) #define LAN9303_VIRT_PHY_BASE 0x70 #define LAN9303_VIRT_SPECIAL_CTRL 0x77 #define LAN9303_VIRT_SPECIAL_TURBO BIT(10) /*Turbo MII Enable*/ @@ -240,6 +248,16 @@ static unsigned int flow_ctl_reg[] = { LAN9303_MANUAL_FC_2 }; +static const struct lan9303_led_info lan9303_led_info = { + .fun_mask = LAN9303_LED_CFG_LED_FUN_MASK, + .avail_modes = LAN9303_LED_CFG_LED_MODES, +}; + +static const struct lan9303_led_info lan9354_led_info = { + .fun_mask = LAN9354_LED_CFG_LED_FUN_MASK, + .avail_modes = LAN9354_LED_CFG_LED_MODES, +}; + static int lan9303_read(struct regmap *regmap, unsigned int offset, u32 *reg) { int ret, i; @@ -778,6 +796,20 @@ static int lan9303_enable_processing_port(struct lan9303 *chip, LAN9303_MAC_TX_CFG_X_TX_ENABLE); } +static int lan9303_setup_leds(struct lan9303 *chip) +{ + unsigned int val; + + if (chip->led_sel_mode >= 0) { + val = chip->led_sel_mode << LAN9303_LED_CFG_LED_FUN_SHIFT; + + return regmap_update_bits(chip->regmap, LAN9303_LED_CFG, chip->led_info->fun_mask, + val); + } + + return 0; +} + /* forward special tagged packets from port 0 to port 1 *or* port 2 */ static int lan9303_setup_tagging(struct lan9303 *chip) { @@ -902,8 +934,14 @@ static int lan9303_check_device(struct lan9303 *chip) return ret; } - if (((reg >> 16) != LAN9303_CHIP_ID) && - ((reg >> 16) != LAN9354_CHIP_ID)) { + switch (reg >> 16) { + case LAN9303_CHIP_ID: + chip->led_info = &lan9303_led_info; + break; + case LAN9354_CHIP_ID: + chip->led_info = &lan9354_led_info; + break; + default: dev_err(chip->dev, "unexpected device found: LAN%4.4X\n", reg >> 16); return -ENODEV; @@ -932,6 +970,30 @@ static int lan9303_check_device(struct lan9303 *chip) return 0; } +static int lan9303_parse_dt(struct lan9303 *chip) +{ + u32 led_mode; + int ret; + + if (!device_property_present(chip->dev, "smsc,led-mode")) { + chip->led_sel_mode = -1; + } else { + ret = device_property_read_u32(chip->dev, "smsc,led-mode", &led_mode); + if (ret) + return ret; + + if (led_mode > LAN9303_LED_CFG_LED_FUN_MAX_VAL || + !(chip->led_info->avail_modes & BIT(led_mode))) { + dev_err(chip->dev, "invalid led mode %u\n", led_mode); + return -EINVAL; + } + + chip->led_sel_mode = led_mode; + } + + return 0; +} + /* ---------------------------- DSA -----------------------------------*/ static enum dsa_tag_protocol lan9303_get_tag_protocol(struct dsa_switch *ds, @@ -964,6 +1026,10 @@ static int lan9303_setup(struct dsa_switch *ds) regmap_write(chip->regmap, LAN9303_VIRT_SPECIAL_CTRL, reg); } + ret = lan9303_setup_leds(chip); + if (ret) + dev_err(chip->dev, "failed to setup leds %d\n", ret); + ret = lan9303_setup_tagging(chip); if (ret) dev_err(chip->dev, "failed to setup port tagging %d\n", ret); @@ -1477,6 +1543,10 @@ int lan9303_probe(struct lan9303 *chip, struct device_node *np) if (ret) return ret; + ret = lan9303_parse_dt(chip); + if (ret) + return ret; + ret = lan9303_register_switch(chip); if (ret) { dev_dbg(chip->dev, "Failed to register switch: %d\n", ret); diff --git a/include/linux/dsa/lan9303.h b/include/linux/dsa/lan9303.h index 3ce7cbcc37a3..f0111ad7fb7f 100644 --- a/include/linux/dsa/lan9303.h +++ b/include/linux/dsa/lan9303.h @@ -17,6 +17,11 @@ struct lan9303_alr_cache_entry { u8 stp_override; /* non zero if set LAN9303_ALR_DAT1_AGE_OVERRID */ }; +struct lan9303_led_info { + u32 fun_mask; + u32 avail_modes; +}; + struct lan9303 { struct device *dev; struct regmap *regmap; @@ -30,6 +35,9 @@ struct lan9303 { const struct lan9303_phy_ops *ops; bool is_bridged; /* true if port 1 and 2 are bridged */ + const struct lan9303_led_info *led_info; + int led_sel_mode; + /* remember LAN9303_SWE_PORT_STATE while not bridged */ u32 swe_port_state; /* LAN9303 do not offer reading specific ALR entry. Cache all -- 2.56.1