brcm2708: add kernel 4.14 support
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.14 / 950-0257-lan78xx-Read-LED-states-from-Device-Tree.patch
1 From b6be512663a34f85e79bd6dd6caeece57d9f6fe0 Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.org>
3 Date: Wed, 21 Mar 2018 15:59:26 +0000
4 Subject: [PATCH 257/454] lan78xx: Read LED states from Device Tree
5
6 Add support for DT property "microchip,led-modes", a vector of two
7 cells (u32s) in the range 0-15, each of which sets the mode for one
8 of the two LEDs. The possible values are:
9
10 0=link/activity 1=link1000/activity
11 2=link100/activity 3=link10/activity
12 4=link100/1000/activity 5=link10/1000/activity
13 6=link10/100/activity 14=off 15=on
14
15 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
16 ---
17 drivers/net/usb/lan78xx.c | 27 +++++++++++++++++++--------
18 1 file changed, 19 insertions(+), 8 deletions(-)
19
20 --- a/drivers/net/usb/lan78xx.c
21 +++ b/drivers/net/usb/lan78xx.c
22 @@ -1998,7 +1998,9 @@ static int lan78xx_phy_init(struct lan78
23 {
24 int ret;
25 u32 mii_adv;
26 - u32 led_modes;
27 + u32 led_modes[2];
28 + u32 led_modes_reg;
29 + int i;
30 struct phy_device *phydev = dev->net->phydev;
31
32 phydev = phy_find_first(dev->mdiobus);
33 @@ -2071,18 +2073,27 @@ static int lan78xx_phy_init(struct lan78
34 mii_adv = (u32)mii_advertise_flowctrl(dev->fc_request_control);
35 phydev->advertising |= mii_adv_to_ethtool_adv_t(mii_adv);
36
37 - /* Change LED defaults:
38 - * orange = link1000/activity
39 - * green = link10/link100/activity
40 + /* Set LED modes:
41 * led: 0=link/activity 1=link1000/activity
42 * 2=link100/activity 3=link10/activity
43 * 4=link100/1000/activity 5=link10/1000/activity
44 * 6=link10/100/activity 14=off 15=on
45 */
46 - led_modes = phy_read(phydev, 0x1d);
47 - led_modes &= ~0xff;
48 - led_modes |= (1 << 0) | (6 << 4);
49 - (void)phy_write(phydev, 0x1d, led_modes);
50 +
51 + memset(led_modes, ~0, sizeof(led_modes));
52 +
53 + of_property_read_u32_array(dev->udev->dev.of_node,
54 + "microchip,led-modes",
55 + led_modes, ARRAY_SIZE(led_modes));
56 +
57 + led_modes_reg = phy_read(phydev, 0x1d);
58 + for (i = 0; i < ARRAY_SIZE(led_modes); i++) {
59 + if (led_modes[i] != ~0) {
60 + led_modes_reg &= ~(0xf << (i * 4));
61 + led_modes_reg |= (led_modes[i] & 0xf) << (i * 4);
62 + }
63 + }
64 + (void)phy_write(phydev, 0x1d, led_modes_reg);
65
66 genphy_config_aneg(phydev);
67