提交 bd27fa44 编写于 作者: R Roger Quadros 提交者: Felipe Balbi

usb: phy: generic: Don't use regulator framework for RESET line

Modelling the RESET line as a regulator supply wasn't a good idea
as it kind of abuses the regulator framework and also makes adaptation
code more complex.

Instead, manage the RESET gpio line directly in the driver. Update
the device tree binding information.

This also makes us easy to migrate to a dedicated GPIO RESET controller
whenever it becomes available.
Signed-off-by: NRoger Quadros <rogerq@ti.com>
Signed-off-by: NFelipe Balbi <balbi@ti.com>
上级 8e933359
...@@ -15,7 +15,7 @@ Optional properties: ...@@ -15,7 +15,7 @@ Optional properties:
- vcc-supply: phandle to the regulator that provides RESET to the PHY. - vcc-supply: phandle to the regulator that provides RESET to the PHY.
- reset-supply: phandle to the regulator that provides power to the PHY. - reset-gpios: Should specify the GPIO for reset.
Example: Example:
...@@ -25,10 +25,9 @@ Example: ...@@ -25,10 +25,9 @@ Example:
clocks = <&osc 0>; clocks = <&osc 0>;
clock-names = "main_clk"; clock-names = "main_clk";
vcc-supply = <&hsusb1_vcc_regulator>; vcc-supply = <&hsusb1_vcc_regulator>;
reset-supply = <&hsusb1_reset_regulator>; reset-gpios = <&gpio1 7 GPIO_ACTIVE_LOW>;
}; };
hsusb1_phy is a NOP USB PHY device that gets its clock from an oscillator hsusb1_phy is a NOP USB PHY device that gets its clock from an oscillator
and expects that clock to be configured to 19.2MHz by the NOP PHY driver. and expects that clock to be configured to 19.2MHz by the NOP PHY driver.
hsusb1_vcc_regulator provides power to the PHY and hsusb1_reset_regulator hsusb1_vcc_regulator provides power to the PHY and GPIO 7 controls RESET.
controls RESET.
...@@ -53,7 +53,7 @@ static int am335x_phy_probe(struct platform_device *pdev) ...@@ -53,7 +53,7 @@ static int am335x_phy_probe(struct platform_device *pdev)
} }
ret = usb_phy_gen_create_phy(dev, &am_phy->usb_phy_gen, ret = usb_phy_gen_create_phy(dev, &am_phy->usb_phy_gen,
USB_PHY_TYPE_USB2, 0, false, false); USB_PHY_TYPE_USB2, 0, false);
if (ret) if (ret)
return ret; return ret;
......
...@@ -35,6 +35,9 @@ ...@@ -35,6 +35,9 @@
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/regulator/consumer.h> #include <linux/regulator/consumer.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/gpio.h>
#include <linux/delay.h>
#include "phy-generic.h" #include "phy-generic.h"
...@@ -64,6 +67,23 @@ static int nop_set_suspend(struct usb_phy *x, int suspend) ...@@ -64,6 +67,23 @@ static int nop_set_suspend(struct usb_phy *x, int suspend)
return 0; return 0;
} }
static void nop_reset_set(struct usb_phy_gen_xceiv *nop, int asserted)
{
int value;
if (!gpio_is_valid(nop->gpio_reset))
return;
value = asserted;
if (nop->reset_active_low)
value = !value;
gpio_set_value_cansleep(nop->gpio_reset, value);
if (!asserted)
usleep_range(10000, 20000);
}
int usb_gen_phy_init(struct usb_phy *phy) int usb_gen_phy_init(struct usb_phy *phy)
{ {
struct usb_phy_gen_xceiv *nop = dev_get_drvdata(phy->dev); struct usb_phy_gen_xceiv *nop = dev_get_drvdata(phy->dev);
...@@ -76,11 +96,8 @@ int usb_gen_phy_init(struct usb_phy *phy) ...@@ -76,11 +96,8 @@ int usb_gen_phy_init(struct usb_phy *phy)
if (!IS_ERR(nop->clk)) if (!IS_ERR(nop->clk))
clk_prepare_enable(nop->clk); clk_prepare_enable(nop->clk);
if (!IS_ERR(nop->reset)) { /* De-assert RESET */
/* De-assert RESET */ nop_reset_set(nop, 0);
if (regulator_enable(nop->reset))
dev_err(phy->dev, "Failed to de-assert reset\n");
}
return 0; return 0;
} }
...@@ -90,11 +107,8 @@ void usb_gen_phy_shutdown(struct usb_phy *phy) ...@@ -90,11 +107,8 @@ void usb_gen_phy_shutdown(struct usb_phy *phy)
{ {
struct usb_phy_gen_xceiv *nop = dev_get_drvdata(phy->dev); struct usb_phy_gen_xceiv *nop = dev_get_drvdata(phy->dev);
if (!IS_ERR(nop->reset)) { /* Assert RESET */
/* Assert RESET */ nop_reset_set(nop, 1);
if (regulator_disable(nop->reset))
dev_err(phy->dev, "Failed to assert reset\n");
}
if (!IS_ERR(nop->clk)) if (!IS_ERR(nop->clk))
clk_disable_unprepare(nop->clk); clk_disable_unprepare(nop->clk);
...@@ -136,8 +150,7 @@ static int nop_set_host(struct usb_otg *otg, struct usb_bus *host) ...@@ -136,8 +150,7 @@ static int nop_set_host(struct usb_otg *otg, struct usb_bus *host)
} }
int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop, int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop,
enum usb_phy_type type, u32 clk_rate, bool needs_vcc, enum usb_phy_type type, u32 clk_rate, bool needs_vcc)
bool needs_reset)
{ {
int err; int err;
...@@ -168,12 +181,22 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop, ...@@ -168,12 +181,22 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop,
return -EPROBE_DEFER; return -EPROBE_DEFER;
} }
nop->reset = devm_regulator_get(dev, "reset"); if (gpio_is_valid(nop->gpio_reset)) {
if (IS_ERR(nop->reset)) { unsigned long gpio_flags;
dev_dbg(dev, "Error getting reset regulator: %ld\n",
PTR_ERR(nop->reset)); /* Assert RESET */
if (needs_reset) if (nop->reset_active_low)
return -EPROBE_DEFER; gpio_flags = GPIOF_OUT_INIT_LOW;
else
gpio_flags = GPIOF_OUT_INIT_HIGH;
err = devm_gpio_request_one(dev, nop->gpio_reset,
gpio_flags, dev_name(dev));
if (err) {
dev_err(dev, "Error requesting RESET GPIO %d\n",
nop->gpio_reset);
return err;
}
} }
nop->dev = dev; nop->dev = dev;
...@@ -202,31 +225,36 @@ static int usb_phy_gen_xceiv_probe(struct platform_device *pdev) ...@@ -202,31 +225,36 @@ static int usb_phy_gen_xceiv_probe(struct platform_device *pdev)
int err; int err;
u32 clk_rate = 0; u32 clk_rate = 0;
bool needs_vcc = false; bool needs_vcc = false;
bool needs_reset = false;
nop = devm_kzalloc(dev, sizeof(*nop), GFP_KERNEL);
if (!nop)
return -ENOMEM;
nop->reset_active_low = true; /* default behaviour */
if (dev->of_node) { if (dev->of_node) {
struct device_node *node = dev->of_node; struct device_node *node = dev->of_node;
enum of_gpio_flags flags;
if (of_property_read_u32(node, "clock-frequency", &clk_rate)) if (of_property_read_u32(node, "clock-frequency", &clk_rate))
clk_rate = 0; clk_rate = 0;
needs_vcc = of_property_read_bool(node, "vcc-supply"); needs_vcc = of_property_read_bool(node, "vcc-supply");
needs_reset = of_property_read_bool(node, "reset-supply"); nop->gpio_reset = of_get_named_gpio_flags(node, "reset-gpios",
0, &flags);
if (nop->gpio_reset == -EPROBE_DEFER)
return -EPROBE_DEFER;
nop->reset_active_low = flags & OF_GPIO_ACTIVE_LOW;
} else if (pdata) { } else if (pdata) {
type = pdata->type; type = pdata->type;
clk_rate = pdata->clk_rate; clk_rate = pdata->clk_rate;
needs_vcc = pdata->needs_vcc; needs_vcc = pdata->needs_vcc;
needs_reset = pdata->needs_reset; nop->gpio_reset = pdata->gpio_reset;
} }
nop = devm_kzalloc(dev, sizeof(*nop), GFP_KERNEL); err = usb_phy_gen_create_phy(dev, nop, type, clk_rate, needs_vcc);
if (!nop)
return -ENOMEM;
err = usb_phy_gen_create_phy(dev, nop, type, clk_rate, needs_vcc,
needs_reset);
if (err) if (err)
return err; return err;
......
...@@ -6,14 +6,14 @@ struct usb_phy_gen_xceiv { ...@@ -6,14 +6,14 @@ struct usb_phy_gen_xceiv {
struct device *dev; struct device *dev;
struct clk *clk; struct clk *clk;
struct regulator *vcc; struct regulator *vcc;
struct regulator *reset; int gpio_reset;
bool reset_active_low;
}; };
int usb_gen_phy_init(struct usb_phy *phy); int usb_gen_phy_init(struct usb_phy *phy);
void usb_gen_phy_shutdown(struct usb_phy *phy); void usb_gen_phy_shutdown(struct usb_phy *phy);
int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop, int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop,
enum usb_phy_type type, u32 clk_rate, bool needs_vcc, enum usb_phy_type type, u32 clk_rate, bool needs_vcc);
bool needs_reset);
#endif #endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册