a929aacfd03476f1a51882e13e3bf450df30b68a
[openwrt/staging/ldir.git] / target / linux / kirkwood / patches-5.10 / 801-power-reset-linkstation-poweroff-add-new-device.patch
1 From a2d9c86df8d12646f5bf66920e4f1e6d940cfc62 Mon Sep 17 00:00:00 2001
2 From: Pawel Dembicki <paweldembicki@gmail.com>
3 Date: Fri, 18 Jun 2021 13:25:33 +0200
4 Subject: [PATCH 2/2] power: reset: linkstation-poweroff: add new device
5
6 This commit introduces support for NETGEAR ReadyNAS Duo v2.
7 This device use bit 4 of LED[2:0] Polarity Control Register to indicate
8 AC Power loss.
9
10 For more details about AC loss detection in NETGEAR ReadyNAS Duo v2,
11 please look at the file:
12 RND_5.3.13_WW.src/u-boot/board/mv_feroceon/mv_hal/usibootup/usibootup.c
13 from Netgear GPL sources.
14
15 Signed-off-by: Pawel Dembicki <paweldembicki@gmail.com>
16 ---
17 drivers/power/reset/linkstation-poweroff.c | 43 ++++++++++++++++++++++
18 1 file changed, 43 insertions(+)
19
20 --- a/drivers/power/reset/linkstation-poweroff.c
21 +++ b/drivers/power/reset/linkstation-poweroff.c
22 @@ -19,6 +19,7 @@
23 #define MII_MARVELL_PHY_PAGE 22
24
25 #define MII_PHY_LED_CTRL 16
26 +#define MII_PHY_LED_POL_CTRL 17
27 #define MII_88E1318S_PHY_LED_TCR 18
28 #define MII_88E1318S_PHY_WOL_CTRL 16
29 #define MII_M1011_IEVENT 19
30 @@ -29,6 +30,8 @@
31 #define LED2_FORCE_ON (0x8 << 8)
32 #define LEDMASK GENMASK(11,8)
33
34 +#define MII_88E1318S_PHY_LED_POL_LED2 BIT(4)
35 +
36 struct power_off_cfg {
37 char *mdio_node_name;
38 void (*phy_set_reg)(bool restart);
39 @@ -76,11 +79,48 @@ err:
40 dev_err(&phydev->mdio.dev, "Write register failed, %d\n", rc);
41 }
42
43 +static void readynas_mvphy_set_reg(bool restart)
44 +{
45 + int rc = 0, saved_page;
46 + u16 data = 0;
47 +
48 + if(restart)
49 + data = MII_88E1318S_PHY_LED_POL_LED2;
50 +
51 + saved_page = phy_select_page(phydev, MII_MARVELL_LED_PAGE);
52 + if (saved_page < 0)
53 + goto err;
54 +
55 + /* Set the LED[2].0 Polarity bit to the required state */
56 + __phy_modify(phydev, MII_PHY_LED_POL_CTRL,
57 + MII_88E1318S_PHY_LED_POL_LED2, data);
58 +
59 + if (!data) {
60 +
61 + /* If WOL was enabled and a magic packet was received before powering
62 + * off, we won't be able to wake up by sending another magic packet.
63 + * Clear WOL status.
64 + */
65 + __phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_MARVELL_WOL_PAGE);
66 + __phy_set_bits(phydev, MII_88E1318S_PHY_WOL_CTRL,
67 + MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS);
68 + }
69 +err:
70 + rc = phy_restore_page(phydev, saved_page, rc);
71 + if (rc < 0)
72 + dev_err(&phydev->mdio.dev, "Write register failed, %d\n", rc);
73 +}
74 +
75 static const struct power_off_cfg linkstation_power_off_cfg = {
76 .mdio_node_name = "mdio",
77 .phy_set_reg = linkstation_mvphy_reg_intn,
78 };
79
80 +static const struct power_off_cfg readynas_power_off_cfg = {
81 + .mdio_node_name = "mdio-bus",
82 + .phy_set_reg = readynas_mvphy_set_reg,
83 +};
84 +
85 static int linkstation_reboot_notifier(struct notifier_block *nb,
86 unsigned long action, void *unused)
87 {
88 @@ -109,6 +149,9 @@ static const struct of_device_id ls_powe
89 { .compatible = "buffalo,ls421de",
90 .data = &linkstation_power_off_cfg,
91 },
92 + { .compatible = "netgear,readynas-duo-v2",
93 + .data = &readynas_power_off_cfg,
94 + },
95 { },
96 };
97