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 --- a/drivers/power/reset/linkstation-poweroff.c
19 +++ b/drivers/power/reset/linkstation-poweroff.c
21 #define LED2_FORCE_ON (0x8 << 8)
22 #define LEDMASK GENMASK(11,8)
24 +struct power_off_cfg {
25 + char *mdio_node_name;
26 + void (*phy_set_reg)(bool restart);
29 static struct phy_device *phydev;
30 +static const struct power_off_cfg *cfg;
32 -static void mvphy_reg_intn(u16 data)
33 +static void linkstation_mvphy_reg_intn(bool restart)
35 int rc = 0, saved_page;
39 + data = MII_88E1318S_PHY_LED_TCR_FORCE_INT;
41 saved_page = phy_select_page(phydev, MII_MARVELL_LED_PAGE);
43 @@ -66,11 +76,16 @@ err:
44 dev_err(&phydev->mdio.dev, "Write register failed, %d\n", rc);
47 +static const struct power_off_cfg linkstation_power_off_cfg = {
48 + .mdio_node_name = "mdio",
49 + .phy_set_reg = linkstation_mvphy_reg_intn,
52 static int linkstation_reboot_notifier(struct notifier_block *nb,
53 unsigned long action, void *unused)
55 if (action == SYS_RESTART)
56 - mvphy_reg_intn(MII_88E1318S_PHY_LED_TCR_FORCE_INT);
57 + cfg->phy_set_reg(true);
61 @@ -82,14 +97,18 @@ static struct notifier_block linkstation
62 static void linkstation_poweroff(void)
64 unregister_reboot_notifier(&linkstation_reboot_nb);
66 + cfg->phy_set_reg(false);
68 kernel_restart("Power off");
71 static const struct of_device_id ls_poweroff_of_match[] = {
72 - { .compatible = "buffalo,ls421d" },
73 - { .compatible = "buffalo,ls421de" },
74 + { .compatible = "buffalo,ls421d",
75 + .data = &linkstation_power_off_cfg,
77 + { .compatible = "buffalo,ls421de",
78 + .data = &linkstation_power_off_cfg,
83 @@ -97,13 +116,17 @@ static int __init linkstation_poweroff_i
86 struct device_node *dn;
87 + const struct of_device_id *match;
89 dn = of_find_matching_node(NULL, ls_poweroff_of_match);
94 - dn = of_find_node_by_name(NULL, "mdio");
95 + match = of_match_node(ls_poweroff_of_match, dn);
98 + dn = of_find_node_by_name(NULL, cfg->mdio_node_name);