1 From 11cab9f5cd9390cd83747e579957c8f5b807c09c Mon Sep 17 00:00:00 2001
2 From: Pawel Dembicki <paweldembicki@gmail.com>
3 Date: Fri, 18 Jun 2021 12:37:27 +0200
4 Subject: [PATCH 1/2] power: reset: linkstation-poweroff: prepare for new
7 This commit prepare driver for another device support.
9 New power_off_cfg structure describes two most important things: name of
10 mdio bus and pointer to register setting function. It allow to add new
11 device with different mdio bus node and other phy register config.
13 Signed-off-by: Pawel Dembicki <paweldembicki@gmail.com>
15 drivers/power/reset/linkstation-poweroff.c | 35 ++++++++++++++++++----
16 1 file changed, 29 insertions(+), 6 deletions(-)
18 diff --git a/drivers/power/reset/linkstation-poweroff.c b/drivers/power/reset/linkstation-poweroff.c
19 index f1e843df0e16..8691cf98600d 100644
20 --- a/drivers/power/reset/linkstation-poweroff.c
21 +++ b/drivers/power/reset/linkstation-poweroff.c
23 #define LED2_FORCE_ON (0x8 << 8)
24 #define LEDMASK GENMASK(11,8)
26 +struct power_off_cfg {
27 + char *mdio_node_name;
28 + void (*phy_set_reg)(bool restart);
31 static struct phy_device *phydev;
32 +static const struct power_off_cfg *cfg;
34 -static void mvphy_reg_intn(u16 data)
35 +static void linkstation_mvphy_reg_intn(bool restart)
37 int rc = 0, saved_page;
41 + data = MII_88E1318S_PHY_LED_TCR_FORCE_INT;
43 saved_page = phy_select_page(phydev, MII_MARVELL_LED_PAGE);
45 @@ -66,11 +76,16 @@ static void mvphy_reg_intn(u16 data)
46 dev_err(&phydev->mdio.dev, "Write register failed, %d\n", rc);
49 +static const struct power_off_cfg linkstation_power_off_cfg = {
50 + .mdio_node_name = "mdio",
51 + .phy_set_reg = linkstation_mvphy_reg_intn,
54 static int linkstation_reboot_notifier(struct notifier_block *nb,
55 unsigned long action, void *unused)
57 if (action == SYS_RESTART)
58 - mvphy_reg_intn(MII_88E1318S_PHY_LED_TCR_FORCE_INT);
59 + cfg->phy_set_reg(true);
63 @@ -82,14 +97,18 @@ static struct notifier_block linkstation_reboot_nb = {
64 static void linkstation_poweroff(void)
66 unregister_reboot_notifier(&linkstation_reboot_nb);
68 + cfg->phy_set_reg(false);
70 kernel_restart("Power off");
73 static const struct of_device_id ls_poweroff_of_match[] = {
74 - { .compatible = "buffalo,ls421d" },
75 - { .compatible = "buffalo,ls421de" },
76 + { .compatible = "buffalo,ls421d",
77 + .data = &linkstation_power_off_cfg,
79 + { .compatible = "buffalo,ls421de",
80 + .data = &linkstation_power_off_cfg,
85 @@ -97,13 +116,17 @@ static int __init linkstation_poweroff_init(void)
88 struct device_node *dn;
89 + const struct of_device_id *match;
91 dn = of_find_matching_node(NULL, ls_poweroff_of_match);
96 - dn = of_find_node_by_name(NULL, "mdio");
97 + match = of_match_node(ls_poweroff_of_match, dn);
100 + dn = of_find_node_by_name(NULL, cfg->mdio_node_name);