Message ID | 1389174428-31414-3-git-send-email-rogerq@ti.com |
---|---|
State | Not Applicable |
Delegated to: | David Miller |
Headers | show |
Hi Roger, On Wednesday 08 January 2014 03:17 PM, Roger Quadros wrote: > From: Balaji T K <balajitk@ti.com> > > Some platforms have a PHY hooked up to the > SATA controller. The PHY needs to be initialized > and powered up for SATA to work. We do that > using the PHY framework. > > [Roger Q] Cleaned up. > > CC: Tejun Heo <tj@kernel.org> > Signed-off-by: Balaji T K <balajitk@ti.com> > Signed-off-by: Roger Quadros <rogerq@ti.com> > --- > drivers/ata/ahci.h | 2 ++ > drivers/ata/ahci_platform.c | 28 +++++++++++++++++++++++++++- > 2 files changed, 29 insertions(+), 1 deletion(-) > > diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h > index 2289efd..f9bbada 100644 > --- a/drivers/ata/ahci.h > +++ b/drivers/ata/ahci.h > @@ -37,6 +37,7 @@ > > #include <linux/clk.h> > #include <linux/libata.h> > +#include <linux/phy/phy.h> > > /* Enclosure Management Control */ > #define EM_CTRL_MSG_TYPE 0x000f0000 > @@ -322,6 +323,7 @@ struct ahci_host_priv { > u32 em_buf_sz; /* EM buffer size in byte */ > u32 em_msg_type; /* EM message type */ > struct clk *clk; /* Only for platforms supporting clk */ > + struct phy *phy; /* If platform uses phy */ > void *plat_data; /* Other platform data */ > }; > > diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c > index d5ced13..f61093b 100644 > --- a/drivers/ata/ahci_platform.c > +++ b/drivers/ata/ahci_platform.c > @@ -142,6 +142,21 @@ static int ahci_probe(struct platform_device *pdev) > } > } > > + hpriv->phy = devm_phy_get(dev, "sata-phy"); > + if (IS_ERR(hpriv->phy)) { > + dev_dbg(dev, "can't get sata-phy\n"); > + /* return only if -EPROBE_DEFER */ > + if (PTR_ERR(hpriv->phy) == -EPROBE_DEFER) { > + rc = -EPROBE_DEFER; > + goto disable_unprepare_clk; > + } > + } > + > + if (!IS_ERR(hpriv->phy)) { > + phy_init(hpriv->phy); Don't we have to check the return values of phy_init and phy_power_on? Is it not needed because it is an optional phy? Thanks Kishon -- To unsubscribe from this list: send the line "unsubscribe linux-ide" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wednesday 08 January 2014 15:29:18 Kishon Vijay Abraham I wrote: > > + hpriv->phy = devm_phy_get(dev, "sata-phy"); > > + if (IS_ERR(hpriv->phy)) { > > + dev_dbg(dev, "can't get sata-phy\n"); > > + /* return only if -EPROBE_DEFER */ > > + if (PTR_ERR(hpriv->phy) == -EPROBE_DEFER) { > > + rc = -EPROBE_DEFER; > > + goto disable_unprepare_clk; > > + } > > + } This should probably check for all errors except "not present" rather than checking for -EPROBE_DEFER. We want to abort the probe function for deferred probe as well as the case where we a PHY was listed but isn't working properly. > > + if (!IS_ERR(hpriv->phy)) { > > + phy_init(hpriv->phy); > > Don't we have to check the return values of phy_init and phy_power_on? Is it > not needed because it is an optional phy? Right. I think we should set hpriv->phy to NULL if it's not there and then call the functions only if it's actually present but bail out on an error. Arnd -- To unsubscribe from this list: send the line "unsubscribe linux-ide" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On 01/08/2014 03:35 PM, Arnd Bergmann wrote: > On Wednesday 08 January 2014 15:29:18 Kishon Vijay Abraham I wrote: >>> + hpriv->phy = devm_phy_get(dev, "sata-phy"); >>> + if (IS_ERR(hpriv->phy)) { >>> + dev_dbg(dev, "can't get sata-phy\n"); >>> + /* return only if -EPROBE_DEFER */ >>> + if (PTR_ERR(hpriv->phy) == -EPROBE_DEFER) { >>> + rc = -EPROBE_DEFER; >>> + goto disable_unprepare_clk; >>> + } >>> + } > > This should probably check for all errors except "not present" > rather than checking for -EPROBE_DEFER. We want to abort the > probe function for deferred probe as well as the case where we > a PHY was listed but isn't working properly. OK. > >>> + if (!IS_ERR(hpriv->phy)) { >>> + phy_init(hpriv->phy); >> >> Don't we have to check the return values of phy_init and phy_power_on? Is it >> not needed because it is an optional phy? > > Right. I think we should set hpriv->phy to NULL if it's not there and > then call the functions only if it's actually present but bail out on > an error. OK. How does this look? hpriv->phy = devm_phy_get(dev, "sata-phy"); if (IS_ERR(hpriv->phy)) { if (PTR_ERR(hpriv->phy) == -ENODEV) goto continue; dev_err(dev, "couldn't get sata-phy\n"); rc = PTR_ERR(hpriv->phy); goto disable_unprepare_clk; } continue: if (!IS_ERR(hpriv->phy)) { rc = phy_init(hpriv->phy); if (rc) goto disable_unprepare_clk; rc = phy_power_on(hpriv->phy); if (rc) { phy_exit(hpriv->phy); goto disable_unprepare_clk; } } cheers, -roger -- To unsubscribe from this list: send the line "unsubscribe linux-ide" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On 01/08/2014 04:58 PM, Roger Quadros wrote: > On 01/08/2014 03:35 PM, Arnd Bergmann wrote: >> On Wednesday 08 January 2014 15:29:18 Kishon Vijay Abraham I wrote: >>>> + hpriv->phy = devm_phy_get(dev, "sata-phy"); >>>> + if (IS_ERR(hpriv->phy)) { >>>> + dev_dbg(dev, "can't get sata-phy\n"); >>>> + /* return only if -EPROBE_DEFER */ >>>> + if (PTR_ERR(hpriv->phy) == -EPROBE_DEFER) { >>>> + rc = -EPROBE_DEFER; >>>> + goto disable_unprepare_clk; >>>> + } >>>> + } >> >> This should probably check for all errors except "not present" >> rather than checking for -EPROBE_DEFER. We want to abort the >> probe function for deferred probe as well as the case where we >> a PHY was listed but isn't working properly. > > OK. > >> >>>> + if (!IS_ERR(hpriv->phy)) { >>>> + phy_init(hpriv->phy); >>> >>> Don't we have to check the return values of phy_init and phy_power_on? Is it >>> not needed because it is an optional phy? >> >> Right. I think we should set hpriv->phy to NULL if it's not there and >> then call the functions only if it's actually present but bail out on >> an error. > > OK. How does this look? > > hpriv->phy = devm_phy_get(dev, "sata-phy"); > if (IS_ERR(hpriv->phy)) { > if (PTR_ERR(hpriv->phy) == -ENODEV) > goto continue; yikes :P goto phyinit; > > dev_err(dev, "couldn't get sata-phy\n"); > rc = PTR_ERR(hpriv->phy); > goto disable_unprepare_clk; > } > > continue: phyinit: > > if (!IS_ERR(hpriv->phy)) { > rc = phy_init(hpriv->phy); > if (rc) > goto disable_unprepare_clk; > > rc = phy_power_on(hpriv->phy); > if (rc) { > phy_exit(hpriv->phy); > goto disable_unprepare_clk; > } > } > > cheers, > -roger > -- To unsubscribe from this list: send the line "unsubscribe linux-ide" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wednesday 08 January 2014 16:58:15 Roger Quadros wrote: > hpriv->phy = devm_phy_get(dev, "sata-phy"); > if (IS_ERR(hpriv->phy)) { > if (PTR_ERR(hpriv->phy) == -ENODEV) > goto continue; > > dev_err(dev, "couldn't get sata-phy\n"); > rc = PTR_ERR(hpriv->phy); > goto disable_unprepare_clk; > } > > continue: > > if (!IS_ERR(hpriv->phy)) { > rc = phy_init(hpriv->phy); > if (rc) > goto disable_unprepare_clk; > > rc = phy_power_on(hpriv->phy); > if (rc) { > phy_exit(hpriv->phy); > goto disable_unprepare_clk; > } > } As I said, I'd prefer to set hpriv->phy to NULL in case of -ENODEV, but functionally it seems right (with the fixup from your other mail). One more comment: you shouldn't print an error message before returning -EPROBE_DEFER, so if you want to keep that message, you have to check for that return value after all. Arnd -- To unsubscribe from this list: send the line "unsubscribe linux-ide" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi, On 01/08/2014 12:28 PM, Roger Quadros wrote: > On 01/08/2014 03:35 PM, Arnd Bergmann wrote: >> On Wednesday 08 January 2014 15:29:18 Kishon Vijay Abraham I wrote: >>>> + hpriv->phy = devm_phy_get(dev, "sata-phy"); >>>> + if (IS_ERR(hpriv->phy)) { >>>> + dev_dbg(dev, "can't get sata-phy\n"); >>>> + /* return only if -EPROBE_DEFER */ >>>> + if (PTR_ERR(hpriv->phy) == -EPROBE_DEFER) { >>>> + rc = -EPROBE_DEFER; >>>> + goto disable_unprepare_clk; >>>> + } >>>> + } >> >> This should probably check for all errors except "not present" >> rather than checking for -EPROBE_DEFER. We want to abort the >> probe function for deferred probe as well as the case where we >> a PHY was listed but isn't working properly. > > OK. > >> >>>> + if (!IS_ERR(hpriv->phy)) { >>>> + phy_init(hpriv->phy); >>> >>> Don't we have to check the return values of phy_init and phy_power_on? Is it >>> not needed because it is an optional phy? >> >> Right. I think we should set hpriv->phy to NULL if it's not there and >> then call the functions only if it's actually present but bail out on >> an error. > > OK. How does this look? > > hpriv->phy = devm_phy_get(dev, "sata-phy"); > if (IS_ERR(hpriv->phy)) { > if (PTR_ERR(hpriv->phy) == -ENODEV) > goto continue; -ENODEV is not the right errno to check for, if there is no phy specified in the dt then you will get -EINVAL (no phy-names property) or -ENODATA (phy-names property is there but name not found). Also you don't want to log an error on PROBE_DEFERRAL. Here is what I've for similar code I'm working on for ehci-platform.c and ohci-platform.c : priv->phy = devm_phy_get(&dev->dev, "phy0"); if (IS_ERR(priv->phy)) { err = PTR_ERR(priv->phy); if (err != -EINVAL && err != -ENODATA) { if (err != -EPROBE_DEFER) dev_err(&dev->dev, "Error getting phy\n"); goto err_put_hcd; } priv->phy = NULL; } And from then on I simply use "if (priv->phy)" checks, and of course check phy_init and phy_power_on return values. Regards, Hans -- To unsubscribe from this list: send the line "unsubscribe linux-ide" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi, On 01/08/2014 02:14 PM, Hans de Goede wrote: > Hi, > > On 01/08/2014 12:28 PM, Roger Quadros wrote: >> On 01/08/2014 03:35 PM, Arnd Bergmann wrote: >>> On Wednesday 08 January 2014 15:29:18 Kishon Vijay Abraham I wrote: >>>>> + hpriv->phy = devm_phy_get(dev, "sata-phy"); >>>>> + if (IS_ERR(hpriv->phy)) { >>>>> + dev_dbg(dev, "can't get sata-phy\n"); >>>>> + /* return only if -EPROBE_DEFER */ >>>>> + if (PTR_ERR(hpriv->phy) == -EPROBE_DEFER) { >>>>> + rc = -EPROBE_DEFER; >>>>> + goto disable_unprepare_clk; >>>>> + } >>>>> + } >>> >>> This should probably check for all errors except "not present" >>> rather than checking for -EPROBE_DEFER. We want to abort the >>> probe function for deferred probe as well as the case where we >>> a PHY was listed but isn't working properly. >> >> OK. >> >>> >>>>> + if (!IS_ERR(hpriv->phy)) { >>>>> + phy_init(hpriv->phy); >>>> >>>> Don't we have to check the return values of phy_init and phy_power_on? Is it >>>> not needed because it is an optional phy? >>> >>> Right. I think we should set hpriv->phy to NULL if it's not there and >>> then call the functions only if it's actually present but bail out on >>> an error. >> >> OK. How does this look? >> >> hpriv->phy = devm_phy_get(dev, "sata-phy"); >> if (IS_ERR(hpriv->phy)) { >> if (PTR_ERR(hpriv->phy) == -ENODEV) >> goto continue; > > -ENODEV is not the right errno to check for, > if there is no phy specified in the dt then > you will get -EINVAL (no phy-names property) or > -ENODATA (phy-names property is there but name > not found). > > Also you don't want to log an error on > PROBE_DEFERRAL. > > Here is what I've for similar code I'm working on > for ehci-platform.c and ohci-platform.c : > > priv->phy = devm_phy_get(&dev->dev, "phy0"); > if (IS_ERR(priv->phy)) { > err = PTR_ERR(priv->phy); > if (err != -EINVAL && err != -ENODATA) { > if (err != -EPROBE_DEFER) > dev_err(&dev->dev, > "Error getting phy\n"); > goto err_put_hcd; > } > priv->phy = NULL; > } Scrap that I was reading the code wrong. Indeed if there is no devicetree phy info it will return -ENODEV. Actually it will only ever return one of -ENOPROBE or -ENODEV, so only checking for -ENOPROBE and then fail silently be enough. This also has the advantage of being future proof, if the error code for no phy found ever changes, things won't break. Regards, Hans -- To unsubscribe from this list: send the line "unsubscribe linux-ide" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On 01/08/2014 05:16 PM, Arnd Bergmann wrote: > On Wednesday 08 January 2014 16:58:15 Roger Quadros wrote: >> hpriv->phy = devm_phy_get(dev, "sata-phy"); >> if (IS_ERR(hpriv->phy)) { >> if (PTR_ERR(hpriv->phy) == -ENODEV) >> goto continue; >> >> dev_err(dev, "couldn't get sata-phy\n"); >> rc = PTR_ERR(hpriv->phy); >> goto disable_unprepare_clk; >> } >> >> continue: >> >> if (!IS_ERR(hpriv->phy)) { >> rc = phy_init(hpriv->phy); >> if (rc) >> goto disable_unprepare_clk; >> >> rc = phy_power_on(hpriv->phy); >> if (rc) { >> phy_exit(hpriv->phy); >> goto disable_unprepare_clk; >> } >> } > > As I said, I'd prefer to set hpriv->phy to NULL in case of -ENODEV, > but functionally it seems right (with the fixup from your other mail). > Why do you prefer setting hpriv->phy to NULL instead of using IS_ERR() check before hpriv->phy is used? The latter seems to be the norm at least among clock framework users. > One more comment: you shouldn't print an error message before > returning -EPROBE_DEFER, so if you want to keep that message, > you have to check for that return value after all. > Right. cheers, -roger -- To unsubscribe from this list: send the line "unsubscribe linux-ide" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thursday 09 January 2014, Roger Quadros wrote: > >> if (!IS_ERR(hpriv->phy)) { > >> rc = phy_init(hpriv->phy); > >> if (rc) > >> goto disable_unprepare_clk; > >> > >> rc = phy_power_on(hpriv->phy); > >> if (rc) { > >> phy_exit(hpriv->phy); > >> goto disable_unprepare_clk; > >> } > >> } > > > > As I said, I'd prefer to set hpriv->phy to NULL in case of -ENODEV, > > but functionally it seems right (with the fixup from your other mail). > > > > Why do you prefer setting hpriv->phy to NULL instead of using IS_ERR() check > before hpriv->phy is used? > The latter seems to be the norm at least among clock framework users. Two reasons: 1. It feels more natural to read "if (clk)" in driver code as a check for "a clock exists" than "if (!IS_ERR(clk))". 2. It clarifies that this code path is only there to check for the clk-not-present case, not for other errors. Obviously the first check after clk_get needs to be IS_ERR() because that is the documented interface, but then you should decide on the action based on the specific error. Arnd -- To unsubscribe from this list: send the line "unsubscribe linux-ide" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h index 2289efd..f9bbada 100644 --- a/drivers/ata/ahci.h +++ b/drivers/ata/ahci.h @@ -37,6 +37,7 @@ #include <linux/clk.h> #include <linux/libata.h> +#include <linux/phy/phy.h> /* Enclosure Management Control */ #define EM_CTRL_MSG_TYPE 0x000f0000 @@ -322,6 +323,7 @@ struct ahci_host_priv { u32 em_buf_sz; /* EM buffer size in byte */ u32 em_msg_type; /* EM message type */ struct clk *clk; /* Only for platforms supporting clk */ + struct phy *phy; /* If platform uses phy */ void *plat_data; /* Other platform data */ }; diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c index d5ced13..f61093b 100644 --- a/drivers/ata/ahci_platform.c +++ b/drivers/ata/ahci_platform.c @@ -142,6 +142,21 @@ static int ahci_probe(struct platform_device *pdev) } } + hpriv->phy = devm_phy_get(dev, "sata-phy"); + if (IS_ERR(hpriv->phy)) { + dev_dbg(dev, "can't get sata-phy\n"); + /* return only if -EPROBE_DEFER */ + if (PTR_ERR(hpriv->phy) == -EPROBE_DEFER) { + rc = -EPROBE_DEFER; + goto disable_unprepare_clk; + } + } + + if (!IS_ERR(hpriv->phy)) { + phy_init(hpriv->phy); + phy_power_on(hpriv->phy); + } + /* * Some platforms might need to prepare for mmio region access, * which could be done in the following init call. So, the mmio @@ -151,7 +166,7 @@ static int ahci_probe(struct platform_device *pdev) if (pdata && pdata->init) { rc = pdata->init(dev, hpriv->mmio); if (rc) - goto disable_unprepare_clk; + goto disable_phy; } ahci_save_initial_config(dev, hpriv, @@ -221,6 +236,12 @@ static int ahci_probe(struct platform_device *pdev) pdata_exit: if (pdata && pdata->exit) pdata->exit(dev); +disable_phy: + if (!IS_ERR(hpriv->phy)) { + phy_power_off(hpriv->phy); + phy_exit(hpriv->phy); + } + disable_unprepare_clk: if (!IS_ERR(hpriv->clk)) clk_disable_unprepare(hpriv->clk); @@ -239,6 +260,11 @@ static void ahci_host_stop(struct ata_host *host) if (pdata && pdata->exit) pdata->exit(dev); + if (!IS_ERR(hpriv->phy)) { + phy_power_off(hpriv->phy); + phy_exit(hpriv->phy); + } + if (!IS_ERR(hpriv->clk)) { clk_disable_unprepare(hpriv->clk); clk_put(hpriv->clk);