diff options
author | Richard Leitner <richard.leitner@skidata.com> | 2017-12-11 07:16:57 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-12-13 11:22:53 -0500 |
commit | 3a30ae6ef3cba29c83ca791bde0d06f182d5678d (patch) | |
tree | f2da147aeebdf7292a3e1b46e657ca623382310a | |
parent | 9cca5d2f1be941c2fbe0ac192a139fe1b93d2c3c (diff) |
phylib: Add device reset delay support
Some PHYs need a minimum time after the reset gpio was asserted and/or
deasserted. To ensure we meet these timing requirements add two new
optional devicetree parameters for the phy: reset-delay-us and
reset-post-delay-us.
Signed-off-by: Richard Leitner <richard.leitner@skidata.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | Documentation/devicetree/bindings/net/phy.txt | 10 | ||||
-rw-r--r-- | drivers/net/phy/mdio_device.c | 13 | ||||
-rw-r--r-- | drivers/of/of_mdio.c | 4 | ||||
-rw-r--r-- | include/linux/mdio.h | 2 |
4 files changed, 27 insertions, 2 deletions
diff --git a/Documentation/devicetree/bindings/net/phy.txt b/Documentation/devicetree/bindings/net/phy.txt index c05479f5ac7c..72860ce7f610 100644 --- a/Documentation/devicetree/bindings/net/phy.txt +++ b/Documentation/devicetree/bindings/net/phy.txt | |||
@@ -55,6 +55,12 @@ Optional Properties: | |||
55 | 55 | ||
56 | - reset-gpios: The GPIO phandle and specifier for the PHY reset signal. | 56 | - reset-gpios: The GPIO phandle and specifier for the PHY reset signal. |
57 | 57 | ||
58 | - reset-delay-us: Delay after the reset was asserted in microseconds. | ||
59 | If this property is missing the delay will be skipped. | ||
60 | |||
61 | - reset-post-delay-us: Delay after the reset was deasserted in microseconds. | ||
62 | If this property is missing the delay will be skipped. | ||
63 | |||
58 | Example: | 64 | Example: |
59 | 65 | ||
60 | ethernet-phy@0 { | 66 | ethernet-phy@0 { |
@@ -62,4 +68,8 @@ ethernet-phy@0 { | |||
62 | interrupt-parent = <&PIC>; | 68 | interrupt-parent = <&PIC>; |
63 | interrupts = <35 IRQ_TYPE_EDGE_RISING>; | 69 | interrupts = <35 IRQ_TYPE_EDGE_RISING>; |
64 | reg = <0>; | 70 | reg = <0>; |
71 | |||
72 | reset-gpios = <&gpio1 4 GPIO_ACTIVE_LOW>; | ||
73 | reset-delay-us = <1000>; | ||
74 | reset-post-delay-us = <2000>; | ||
65 | }; | 75 | }; |
diff --git a/drivers/net/phy/mdio_device.c b/drivers/net/phy/mdio_device.c index 75d97dd9fb28..843c1dde93e4 100644 --- a/drivers/net/phy/mdio_device.c +++ b/drivers/net/phy/mdio_device.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
25 | #include <linux/string.h> | 25 | #include <linux/string.h> |
26 | #include <linux/unistd.h> | 26 | #include <linux/unistd.h> |
27 | #include <linux/delay.h> | ||
27 | 28 | ||
28 | void mdio_device_free(struct mdio_device *mdiodev) | 29 | void mdio_device_free(struct mdio_device *mdiodev) |
29 | { | 30 | { |
@@ -118,8 +119,16 @@ EXPORT_SYMBOL(mdio_device_remove); | |||
118 | 119 | ||
119 | void mdio_device_reset(struct mdio_device *mdiodev, int value) | 120 | void mdio_device_reset(struct mdio_device *mdiodev, int value) |
120 | { | 121 | { |
121 | if (mdiodev->reset) | 122 | unsigned int d; |
122 | gpiod_set_value(mdiodev->reset, value); | 123 | |
124 | if (!mdiodev->reset) | ||
125 | return; | ||
126 | |||
127 | gpiod_set_value(mdiodev->reset, value); | ||
128 | |||
129 | d = value ? mdiodev->reset_delay : mdiodev->reset_post_delay; | ||
130 | if (d) | ||
131 | usleep_range(d, d + max_t(unsigned int, d / 10, 100)); | ||
123 | } | 132 | } |
124 | EXPORT_SYMBOL(mdio_device_reset); | 133 | EXPORT_SYMBOL(mdio_device_reset); |
125 | 134 | ||
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c index 98258583abb0..7c8767176315 100644 --- a/drivers/of/of_mdio.c +++ b/drivers/of/of_mdio.c | |||
@@ -77,6 +77,10 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, | |||
77 | if (of_property_read_bool(child, "broken-turn-around")) | 77 | if (of_property_read_bool(child, "broken-turn-around")) |
78 | mdio->phy_ignore_ta_mask |= 1 << addr; | 78 | mdio->phy_ignore_ta_mask |= 1 << addr; |
79 | 79 | ||
80 | of_property_read_u32(child, "reset-delay-us", &phy->mdio.reset_delay); | ||
81 | of_property_read_u32(child, "reset-post-delay-us", | ||
82 | &phy->mdio.reset_post_delay); | ||
83 | |||
80 | /* Associate the OF node with the device structure so it | 84 | /* Associate the OF node with the device structure so it |
81 | * can be looked up later */ | 85 | * can be looked up later */ |
82 | of_node_get(child); | 86 | of_node_get(child); |
diff --git a/include/linux/mdio.h b/include/linux/mdio.h index 92d4e55ffe67..e37c21d8eb19 100644 --- a/include/linux/mdio.h +++ b/include/linux/mdio.h | |||
@@ -41,6 +41,8 @@ struct mdio_device { | |||
41 | int addr; | 41 | int addr; |
42 | int flags; | 42 | int flags; |
43 | struct gpio_desc *reset; | 43 | struct gpio_desc *reset; |
44 | unsigned int reset_delay; | ||
45 | unsigned int reset_post_delay; | ||
44 | }; | 46 | }; |
45 | #define to_mdio_device(d) container_of(d, struct mdio_device, dev) | 47 | #define to_mdio_device(d) container_of(d, struct mdio_device, dev) |
46 | 48 | ||