wireguard-tools: add tunlink option for hostroute
[openwrt/openwrt.git] / target / linux / ar71xx / patches-4.14 / 902-at803x-add-reset-gpio-pdata.patch
1 Add support for configuring AT803x GPIO reset via platform data.
2 This is necessary, because ath79 is not converted to device tree yet.
3
4 Signed-off-by: Felix Fietkau <nbd@nbd.name>
5
6 --- a/include/linux/platform_data/phy-at803x.h
7 +++ b/include/linux/platform_data/phy-at803x.h
8 @@ -6,6 +6,8 @@ struct at803x_platform_data {
9 int enable_rgmii_tx_delay:1;
10 int enable_rgmii_rx_delay:1;
11 int fixup_rgmii_tx_delay:1;
12 + int has_reset_gpio:1;
13 + int reset_gpio;
14 };
15
16 #endif /* _PHY_AT803X_PDATA_H */
17 --- a/drivers/net/phy/at803x.c
18 +++ b/drivers/net/phy/at803x.c
19 @@ -259,6 +259,7 @@ static int at803x_resume(struct phy_devi
20
21 static int at803x_probe(struct phy_device *phydev)
22 {
23 + struct at803x_platform_data *pdata;
24 struct device *dev = &phydev->mdio.dev;
25 struct at803x_priv *priv;
26 struct gpio_desc *gpiod_reset;
27 @@ -271,6 +272,12 @@ static int at803x_probe(struct phy_devic
28 phydev->drv->phy_id != ATH8032_PHY_ID)
29 goto does_not_require_reset_workaround;
30
31 + pdata = dev_get_platdata(dev);
32 + if (pdata && pdata->has_reset_gpio) {
33 + devm_gpio_request(dev, pdata->reset_gpio, "reset");
34 + gpio_direction_output(pdata->reset_gpio, 1);
35 + }
36 +
37 gpiod_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
38 if (IS_ERR(gpiod_reset))
39 return PTR_ERR(gpiod_reset);
40 @@ -402,15 +409,23 @@ static void at803x_link_change_notify(st
41 * cannot recover from by software.
42 */
43 if (phydev->state == PHY_NOLINK) {
44 - if (priv->gpiod_reset && !priv->phy_reset) {
45 + if ((priv->gpiod_reset || (pdata && pdata->has_reset_gpio)) &&
46 + !priv->phy_reset) {
47 struct at803x_context context;
48
49 at803x_context_save(phydev, &context);
50
51 - gpiod_set_value(priv->gpiod_reset, 1);
52 - msleep(1);
53 - gpiod_set_value(priv->gpiod_reset, 0);
54 - msleep(1);
55 + if (pdata && pdata->has_reset_gpio) {
56 + gpio_set_value_cansleep(pdata->reset_gpio, 0);
57 + msleep(1);
58 + gpio_set_value_cansleep(pdata->reset_gpio, 1);
59 + msleep(1);
60 + } else {
61 + gpiod_set_value(priv->gpiod_reset, 1);
62 + msleep(1);
63 + gpiod_set_value(priv->gpiod_reset, 0);
64 + msleep(1);
65 + }
66
67 at803x_context_restore(phydev, &context);
68