usb: misc: usb3503: get optional clock by devm_clk_get_optional()
When the driver tries to get optional clock, it ignores all errors except -EPROBE_DEFER, but if only ignores -ENOENT, it will cover some real errors, such as -ENOMEM, so use devm_clk_get_optional() to get optional clock. And remove unnecessary stack variable clk. Cc: Dongjin Kim <tobetter@gmail.com> Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
08048c04cc
commit
bbe2028f43
|
@ -172,7 +172,6 @@ static int usb3503_probe(struct usb3503 *hub)
|
||||||
hub->gpio_reset = pdata->gpio_reset;
|
hub->gpio_reset = pdata->gpio_reset;
|
||||||
hub->mode = pdata->initial_mode;
|
hub->mode = pdata->initial_mode;
|
||||||
} else if (np) {
|
} else if (np) {
|
||||||
struct clk *clk;
|
|
||||||
u32 rate = 0;
|
u32 rate = 0;
|
||||||
hub->port_off_mask = 0;
|
hub->port_off_mask = 0;
|
||||||
|
|
||||||
|
@ -198,34 +197,29 @@ static int usb3503_probe(struct usb3503 *hub)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clk = devm_clk_get(dev, "refclk");
|
hub->clk = devm_clk_get_optional(dev, "refclk");
|
||||||
if (IS_ERR(clk) && PTR_ERR(clk) != -ENOENT) {
|
if (IS_ERR(hub->clk)) {
|
||||||
dev_err(dev, "unable to request refclk (%ld)\n",
|
dev_err(dev, "unable to request refclk (%ld)\n",
|
||||||
PTR_ERR(clk));
|
PTR_ERR(hub->clk));
|
||||||
return PTR_ERR(clk);
|
return PTR_ERR(hub->clk);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IS_ERR(clk)) {
|
if (rate != 0) {
|
||||||
hub->clk = clk;
|
err = clk_set_rate(hub->clk, rate);
|
||||||
|
|
||||||
if (rate != 0) {
|
|
||||||
err = clk_set_rate(hub->clk, rate);
|
|
||||||
if (err) {
|
|
||||||
dev_err(dev,
|
|
||||||
"unable to set reference clock rate to %d\n",
|
|
||||||
(int) rate);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
err = clk_prepare_enable(hub->clk);
|
|
||||||
if (err) {
|
if (err) {
|
||||||
dev_err(dev,
|
dev_err(dev,
|
||||||
"unable to enable reference clock\n");
|
"unable to set reference clock rate to %d\n",
|
||||||
|
(int)rate);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = clk_prepare_enable(hub->clk);
|
||||||
|
if (err) {
|
||||||
|
dev_err(dev, "unable to enable reference clock\n");
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
property = of_get_property(np, "disabled-ports", &len);
|
property = of_get_property(np, "disabled-ports", &len);
|
||||||
if (property && (len / sizeof(u32)) > 0) {
|
if (property && (len / sizeof(u32)) > 0) {
|
||||||
int i;
|
int i;
|
||||||
|
@ -324,8 +318,7 @@ static int usb3503_i2c_remove(struct i2c_client *i2c)
|
||||||
struct usb3503 *hub;
|
struct usb3503 *hub;
|
||||||
|
|
||||||
hub = i2c_get_clientdata(i2c);
|
hub = i2c_get_clientdata(i2c);
|
||||||
if (hub->clk)
|
clk_disable_unprepare(hub->clk);
|
||||||
clk_disable_unprepare(hub->clk);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -348,8 +341,7 @@ static int usb3503_platform_remove(struct platform_device *pdev)
|
||||||
struct usb3503 *hub;
|
struct usb3503 *hub;
|
||||||
|
|
||||||
hub = platform_get_drvdata(pdev);
|
hub = platform_get_drvdata(pdev);
|
||||||
if (hub->clk)
|
clk_disable_unprepare(hub->clk);
|
||||||
clk_disable_unprepare(hub->clk);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -358,18 +350,14 @@ static int usb3503_platform_remove(struct platform_device *pdev)
|
||||||
static int usb3503_suspend(struct usb3503 *hub)
|
static int usb3503_suspend(struct usb3503 *hub)
|
||||||
{
|
{
|
||||||
usb3503_switch_mode(hub, USB3503_MODE_STANDBY);
|
usb3503_switch_mode(hub, USB3503_MODE_STANDBY);
|
||||||
|
clk_disable_unprepare(hub->clk);
|
||||||
if (hub->clk)
|
|
||||||
clk_disable_unprepare(hub->clk);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usb3503_resume(struct usb3503 *hub)
|
static int usb3503_resume(struct usb3503 *hub)
|
||||||
{
|
{
|
||||||
if (hub->clk)
|
clk_prepare_enable(hub->clk);
|
||||||
clk_prepare_enable(hub->clk);
|
|
||||||
|
|
||||||
usb3503_switch_mode(hub, hub->mode);
|
usb3503_switch_mode(hub, hub->mode);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue