0b3b4ad2d7312d0c7dbc50fe769f18ff0616c164
[openwrt/staging/chunkeey.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 diff --git a/drivers/power/reset/linkstation-poweroff.c b/drivers/power/reset/linkstation-poweroff.c
21 index 8691cf98600d..2a92b6052cac 100644
22 --- a/drivers/power/reset/linkstation-poweroff.c
23 +++ b/drivers/power/reset/linkstation-poweroff.c
24 @@ -19,6 +19,7 @@
25 #define MII_MARVELL_PHY_PAGE 22
26
27 #define MII_PHY_LED_CTRL 16
28 +#define MII_PHY_LED_POL_CTRL 17
29 #define MII_88E1318S_PHY_LED_TCR 18
30 #define MII_88E1318S_PHY_WOL_CTRL 16
31 #define MII_M1011_IEVENT 19
32 @@ -29,6 +30,8 @@
33 #define LED2_FORCE_ON (0x8 << 8)
34 #define LEDMASK GENMASK(11,8)
35
36 +#define MII_88E1318S_PHY_LED_POL_LED2 BIT(4)
37 +
38 struct power_off_cfg {
39 char *mdio_node_name;
40 void (*phy_set_reg)(bool restart);
41 @@ -76,11 +79,48 @@ static void linkstation_mvphy_reg_intn(bool restart)
42 dev_err(&phydev->mdio.dev, "Write register failed, %d\n", rc);
43 }
44
45 +static void readynas_mvphy_set_reg(bool restart)
46 +{
47 + int rc = 0, saved_page;
48 + u16 data = 0;
49 +
50 + if(restart)
51 + data = MII_88E1318S_PHY_LED_POL_LED2;
52 +
53 + saved_page = phy_select_page(phydev, MII_MARVELL_LED_PAGE);
54 + if (saved_page < 0)
55 + goto err;
56 +
57 + /* Set the LED[2].0 Polarity bit to the required state */
58 + __phy_modify(phydev, MII_PHY_LED_POL_CTRL,
59 + MII_88E1318S_PHY_LED_POL_LED2, data);
60 +
61 + if (!data) {
62 +
63 + /* If WOL was enabled and a magic packet was received before powering
64 + * off, we won't be able to wake up by sending another magic packet.
65 + * Clear WOL status.
66 + */
67 + __phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_MARVELL_WOL_PAGE);
68 + __phy_set_bits(phydev, MII_88E1318S_PHY_WOL_CTRL,
69 + MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS);
70 + }
71 +err:
72 + rc = phy_restore_page(phydev, saved_page, rc);
73 + if (rc < 0)
74 + dev_err(&phydev->mdio.dev, "Write register failed, %d\n", rc);
75 +}
76 +
77 static const struct power_off_cfg linkstation_power_off_cfg = {
78 .mdio_node_name = "mdio",
79 .phy_set_reg = linkstation_mvphy_reg_intn,
80 };
81
82 +static const struct power_off_cfg readynas_power_off_cfg = {
83 + .mdio_node_name = "mdio-bus",
84 + .phy_set_reg = readynas_mvphy_set_reg,
85 +};
86 +
87 static int linkstation_reboot_notifier(struct notifier_block *nb,
88 unsigned long action, void *unused)
89 {
90 @@ -109,6 +149,9 @@ static const struct of_device_id ls_poweroff_of_match[] = {
91 { .compatible = "buffalo,ls421de",
92 .data = &linkstation_power_off_cfg,
93 },
94 + { .compatible = "netgear,readynas-duo-v2",
95 + .data = &readynas_power_off_cfg,
96 + },
97 { },
98 };
99
100 --
101 2.25.1
102