Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

phy: micrel: add of configuration for LED mode

Add support for the led-mode property for the following PHYs
which have a single LED mode configuration value.

KSZ8001 and KSZ8041 which both use register 0x1e bits 15,14 and
KSZ8021, KSZ8031 and KSZ8051 which use register 0x1f bits 5,4
to control the LED configuration.

Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Ben Dooks and committed by
David S. Miller
20d8435a 94fcf696

+63 -4
+18
Documentation/devicetree/bindings/net/micrel.txt
··· 1 + Micrel PHY properties. 2 + 3 + These properties cover the base properties Micrel PHYs. 4 + 5 + Optional properties: 6 + 7 + - micrel,led-mode : LED mode value to set for PHYs with configurable LEDs. 8 + 9 + Configure the LED mode with single value. The list of PHYs and 10 + the bits that are currently supported: 11 + 12 + KSZ8001: register 0x1e, bits 15..14 13 + KSZ8041: register 0x1e, bits 15..14 14 + KSZ8021: register 0x1f, bits 5..4 15 + KSZ8031: register 0x1f, bits 5..4 16 + KSZ8051: register 0x1f, bits 5..4 17 + 18 + See the respective PHY datasheet for the mode values.
+45 -4
drivers/net/phy/micrel.c
··· 148 148 return rc < 0 ? rc : 0; 149 149 } 150 150 151 + static int kszphy_setup_led(struct phy_device *phydev, 152 + unsigned int reg, unsigned int shift) 153 + { 154 + 155 + struct device *dev = &phydev->dev; 156 + struct device_node *of_node = dev->of_node; 157 + int rc, temp; 158 + u32 val; 159 + 160 + if (!of_node && dev->parent->of_node) 161 + of_node = dev->parent->of_node; 162 + 163 + if (of_property_read_u32(of_node, "micrel,led-mode", &val)) 164 + return 0; 165 + 166 + temp = phy_read(phydev, reg); 167 + if (temp < 0) 168 + return temp; 169 + 170 + temp &= 3 << shift; 171 + temp |= val << shift; 172 + rc = phy_write(phydev, reg, temp); 173 + 174 + return rc < 0 ? rc : 0; 175 + } 176 + 151 177 static int kszphy_config_init(struct phy_device *phydev) 152 178 { 153 179 return 0; 154 180 } 155 181 182 + static int kszphy_config_init_led8041(struct phy_device *phydev) 183 + { 184 + /* single led control, register 0x1e bits 15..14 */ 185 + return kszphy_setup_led(phydev, 0x1e, 14); 186 + } 187 + 156 188 static int ksz8021_config_init(struct phy_device *phydev) 157 189 { 158 - int rc; 159 190 const u16 val = KSZPHY_OMSO_B_CAST_OFF | KSZPHY_OMSO_RMII_OVERRIDE; 191 + int rc; 192 + 193 + rc = kszphy_setup_led(phydev, 0x1f, 4); 194 + if (rc) 195 + dev_err(&phydev->dev, "failed to set led mode\n"); 196 + 160 197 phy_write(phydev, MII_KSZPHY_OMSO, val); 161 198 rc = ksz_config_flags(phydev); 162 199 return rc < 0 ? rc : 0; ··· 202 165 static int ks8051_config_init(struct phy_device *phydev) 203 166 { 204 167 int rc; 168 + 169 + rc = kszphy_setup_led(phydev, 0x1f, 4); 170 + if (rc) 171 + dev_err(&phydev->dev, "failed to set led mode\n"); 205 172 206 173 rc = ksz_config_flags(phydev); 207 174 return rc < 0 ? rc : 0; ··· 368 327 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause 369 328 | SUPPORTED_Asym_Pause), 370 329 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 371 - .config_init = kszphy_config_init, 330 + .config_init = kszphy_config_init_led8041, 372 331 .config_aneg = genphy_config_aneg, 373 332 .read_status = genphy_read_status, 374 333 .ack_interrupt = kszphy_ack_interrupt, ··· 383 342 .features = PHY_BASIC_FEATURES | 384 343 SUPPORTED_Pause | SUPPORTED_Asym_Pause, 385 344 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 386 - .config_init = kszphy_config_init, 345 + .config_init = kszphy_config_init_led8041, 387 346 .config_aneg = genphy_config_aneg, 388 347 .read_status = genphy_read_status, 389 348 .ack_interrupt = kszphy_ack_interrupt, ··· 412 371 .phy_id_mask = 0x00ffffff, 413 372 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), 414 373 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 415 - .config_init = kszphy_config_init, 374 + .config_init = kszphy_config_init_led8041, 416 375 .config_aneg = genphy_config_aneg, 417 376 .read_status = genphy_read_status, 418 377 .ack_interrupt = kszphy_ack_interrupt,