ath25: switch default kernel to 5.15
[openwrt/openwrt.git] / target / linux / kirkwood / patches-5.10 / 800-power-reset-linkstation-poweroff-prepare-for-new-dev.patch
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
5 devices
6
7 This commit prepare driver for another device support.
8
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.
12
13 Signed-off-by: Pawel Dembicki <paweldembicki@gmail.com>
14 ---
15 drivers/power/reset/linkstation-poweroff.c | 35 ++++++++++++++++++----
16 1 file changed, 29 insertions(+), 6 deletions(-)
17
18 --- a/drivers/power/reset/linkstation-poweroff.c
19 +++ b/drivers/power/reset/linkstation-poweroff.c
20 @@ -29,11 +29,21 @@
21 #define LED2_FORCE_ON (0x8 << 8)
22 #define LEDMASK GENMASK(11,8)
23
24 +struct power_off_cfg {
25 + char *mdio_node_name;
26 + void (*phy_set_reg)(bool restart);
27 +};
28 +
29 static struct phy_device *phydev;
30 +static const struct power_off_cfg *cfg;
31
32 -static void mvphy_reg_intn(u16 data)
33 +static void linkstation_mvphy_reg_intn(bool restart)
34 {
35 int rc = 0, saved_page;
36 + u16 data = 0;
37 +
38 + if(restart)
39 + data = MII_88E1318S_PHY_LED_TCR_FORCE_INT;
40
41 saved_page = phy_select_page(phydev, MII_MARVELL_LED_PAGE);
42 if (saved_page < 0)
43 @@ -66,11 +76,16 @@ err:
44 dev_err(&phydev->mdio.dev, "Write register failed, %d\n", rc);
45 }
46
47 +static const struct power_off_cfg linkstation_power_off_cfg = {
48 + .mdio_node_name = "mdio",
49 + .phy_set_reg = linkstation_mvphy_reg_intn,
50 +};
51 +
52 static int linkstation_reboot_notifier(struct notifier_block *nb,
53 unsigned long action, void *unused)
54 {
55 if (action == SYS_RESTART)
56 - mvphy_reg_intn(MII_88E1318S_PHY_LED_TCR_FORCE_INT);
57 + cfg->phy_set_reg(true);
58
59 return NOTIFY_DONE;
60 }
61 @@ -82,14 +97,18 @@ static struct notifier_block linkstation
62 static void linkstation_poweroff(void)
63 {
64 unregister_reboot_notifier(&linkstation_reboot_nb);
65 - mvphy_reg_intn(0);
66 + cfg->phy_set_reg(false);
67
68 kernel_restart("Power off");
69 }
70
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,
76 + },
77 + { .compatible = "buffalo,ls421de",
78 + .data = &linkstation_power_off_cfg,
79 + },
80 { },
81 };
82
83 @@ -97,13 +116,17 @@ static int __init linkstation_poweroff_i
84 {
85 struct mii_bus *bus;
86 struct device_node *dn;
87 + const struct of_device_id *match;
88
89 dn = of_find_matching_node(NULL, ls_poweroff_of_match);
90 if (!dn)
91 return -ENODEV;
92 of_node_put(dn);
93
94 - dn = of_find_node_by_name(NULL, "mdio");
95 + match = of_match_node(ls_poweroff_of_match, dn);
96 + cfg = match->data;
97 +
98 + dn = of_find_node_by_name(NULL, cfg->mdio_node_name);
99 if (!dn)
100 return -ENODEV;
101