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
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
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.
15 Signed-off-by: Pawel Dembicki <paweldembicki@gmail.com>
17 drivers/power/reset/linkstation-poweroff.c | 43 ++++++++++++++++++++++
18 1 file changed, 43 insertions(+)
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
25 #define MII_MARVELL_PHY_PAGE 22
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
33 #define LED2_FORCE_ON (0x8 << 8)
34 #define LEDMASK GENMASK(11,8)
36 +#define MII_88E1318S_PHY_LED_POL_LED2 BIT(4)
38 struct power_off_cfg {
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);
45 +static void readynas_mvphy_set_reg(bool restart)
47 + int rc = 0, saved_page;
51 + data = MII_88E1318S_PHY_LED_POL_LED2;
53 + saved_page = phy_select_page(phydev, MII_MARVELL_LED_PAGE);
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);
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.
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);
72 + rc = phy_restore_page(phydev, saved_page, rc);
74 + dev_err(&phydev->mdio.dev, "Write register failed, %d\n", rc);
77 static const struct power_off_cfg linkstation_power_off_cfg = {
78 .mdio_node_name = "mdio",
79 .phy_set_reg = linkstation_mvphy_reg_intn,
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,
87 static int linkstation_reboot_notifier(struct notifier_block *nb,
88 unsigned long action, void *unused)
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,
94 + { .compatible = "netgear,readynas-duo-v2",
95 + .data = &readynas_power_off_cfg,