* [PATCH] usb: imx-us-phy: add vbus_valid ro parameter
@ 2021-08-24 10:46 Marco Felsch
2021-08-24 11:01 ` Ahmad Fatoum
0 siblings, 1 reply; 4+ messages in thread
From: Marco Felsch @ 2021-08-24 10:46 UTC (permalink / raw)
To: barebox
The parameter can be used by init scripts to detect a plugged usb cable.
Upon a plugged usb cable the barebox behaviour can be changed which can
be useful e.g. during production to apply a special production
environment.
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
drivers/usb/imx/imx-usb-phy.c | 34 +++++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/imx/imx-usb-phy.c b/drivers/usb/imx/imx-usb-phy.c
index 32098ef248..9420c8c109 100644
--- a/drivers/usb/imx/imx-usb-phy.c
+++ b/drivers/usb/imx/imx-usb-phy.c
@@ -37,9 +37,12 @@
#define BM_USBPHY_CTRL_ENHOSTDISCONDETECT BIT(1)
#define ANADIG_USB1_CHRG_DETECT_SET 0x1b4
-#define ANADIG_USB2_CHRG_DETECT_SET 0x214
#define ANADIG_USB1_CHRG_DETECT_EN_B BIT(20)
#define ANADIG_USB1_CHRG_DETECT_CHK_CHRG_B BIT(19)
+#define ANADIG_USB1_VBUS_DETECT_STAT 0x1c0
+#define ANADIG_USB1_VBUS_DETECT_STAT_VBUS_VALID BIT(3)
+#define ANADIG_USB2_CHRG_DETECT_SET 0x214
+#define ANADIG_USB2_VBUS_DETECT_STAT 0x220
struct imx_usbphy {
struct usb_phy usb_phy;
@@ -132,6 +135,27 @@ static const struct phy_ops imx_phy_ops = {
.to_usbphy = imx_usbphy_to_usbphy,
};
+/* Albeit the access can only happen serial use two variables */
+unsigned int vbus_valid_usb1;
+unsigned int vbus_valid_usb2;
+
+static int imx_usbphy_get_vbus_state(struct param_d *p, void *priv)
+{
+ struct imx_usbphy *imxphy = priv;
+ unsigned int *vbus_valid;
+ unsigned int reg, val;
+
+ reg = imxphy->port_id ?
+ ANADIG_USB1_VBUS_DETECT_STAT :
+ ANADIG_USB2_VBUS_DETECT_STAT;
+ val = readl(imxphy->anatop + reg);
+
+ vbus_valid = imxphy->port_id ? &vbus_valid_usb1 : &vbus_valid_usb2;
+ *vbus_valid = !!(val & ANADIG_USB1_VBUS_DETECT_STAT_VBUS_VALID);
+
+ return 0;
+}
+
static int imx_usbphy_probe(struct device_d *dev)
{
struct resource *iores;
@@ -149,11 +173,19 @@ static int imx_usbphy_probe(struct device_d *dev)
imxphy->port_id = ret;
if (of_get_property(np, "fsl,anatop", NULL)) {
+ unsigned int *vbus_valid = imxphy->port_id ?
+ &vbus_valid_usb1 :
+ &vbus_valid_usb2;
+
imxphy->anatop =
syscon_base_lookup_by_phandle(np, "fsl,anatop");
ret = PTR_ERR_OR_ZERO(imxphy->anatop);
if (ret)
goto err_free;
+
+ dev_add_param_bool(dev, "vbus_valid", param_set_readonly,
+ imx_usbphy_get_vbus_state, vbus_valid,
+ imxphy);
}
iores = dev_request_mem_resource(dev, 0);
--
2.30.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] usb: imx-us-phy: add vbus_valid ro parameter
2021-08-24 10:46 [PATCH] usb: imx-us-phy: add vbus_valid ro parameter Marco Felsch
@ 2021-08-24 11:01 ` Ahmad Fatoum
2021-08-24 11:13 ` Marco Felsch
0 siblings, 1 reply; 4+ messages in thread
From: Ahmad Fatoum @ 2021-08-24 11:01 UTC (permalink / raw)
To: Marco Felsch, barebox
Hello Marco,
On 24.08.21 12:46, Marco Felsch wrote:
> The parameter can be used by init scripts to detect a plugged usb cable.
> Upon a plugged usb cable the barebox behaviour can be changed which can
> be useful e.g. during production to apply a special production
> environment.
>
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> ---
> drivers/usb/imx/imx-usb-phy.c | 34 +++++++++++++++++++++++++++++++++-
> 1 file changed, 33 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/imx/imx-usb-phy.c b/drivers/usb/imx/imx-usb-phy.c
> index 32098ef248..9420c8c109 100644
> --- a/drivers/usb/imx/imx-usb-phy.c
> +++ b/drivers/usb/imx/imx-usb-phy.c
> @@ -37,9 +37,12 @@
> #define BM_USBPHY_CTRL_ENHOSTDISCONDETECT BIT(1)
>
> #define ANADIG_USB1_CHRG_DETECT_SET 0x1b4
> -#define ANADIG_USB2_CHRG_DETECT_SET 0x214
> #define ANADIG_USB1_CHRG_DETECT_EN_B BIT(20)
> #define ANADIG_USB1_CHRG_DETECT_CHK_CHRG_B BIT(19)
> +#define ANADIG_USB1_VBUS_DETECT_STAT 0x1c0
> +#define ANADIG_USB1_VBUS_DETECT_STAT_VBUS_VALID BIT(3)
> +#define ANADIG_USB2_CHRG_DETECT_SET 0x214
> +#define ANADIG_USB2_VBUS_DETECT_STAT 0x220
>
> struct imx_usbphy {
> struct usb_phy usb_phy;
> @@ -132,6 +135,27 @@ static const struct phy_ops imx_phy_ops = {
> .to_usbphy = imx_usbphy_to_usbphy,
> };
>
> +/* Albeit the access can only happen serial use two variables */
> +unsigned int vbus_valid_usb1;
> +unsigned int vbus_valid_usb2;
> +
> +static int imx_usbphy_get_vbus_state(struct param_d *p, void *priv)
> +{
> + struct imx_usbphy *imxphy = priv;
> + unsigned int *vbus_valid;
> + unsigned int reg, val;
> +
> + reg = imxphy->port_id ?
> + ANADIG_USB1_VBUS_DETECT_STAT :
> + ANADIG_USB2_VBUS_DETECT_STAT;
> + val = readl(imxphy->anatop + reg);
> +
> + vbus_valid = imxphy->port_id ? &vbus_valid_usb1 : &vbus_valid_usb2;
> + *vbus_valid = !!(val & ANADIG_USB1_VBUS_DETECT_STAT_VBUS_VALID);
> +
> + return 0;
> +}
> +
> static int imx_usbphy_probe(struct device_d *dev)
> {
> struct resource *iores;
> @@ -149,11 +173,19 @@ static int imx_usbphy_probe(struct device_d *dev)
> imxphy->port_id = ret;
>
> if (of_get_property(np, "fsl,anatop", NULL)) {
> + unsigned int *vbus_valid = imxphy->port_id ?
> + &vbus_valid_usb1 :
> + &vbus_valid_usb2;
Can you allocate this in imxphy? That way you avoid globals
and don't hardcode the existance of only two phys into the driver.
> +
> imxphy->anatop =
> syscon_base_lookup_by_phandle(np, "fsl,anatop");
> ret = PTR_ERR_OR_ZERO(imxphy->anatop);
> if (ret)
> goto err_free;
> +
> + dev_add_param_bool(dev, "vbus_valid", param_set_readonly,
> + imx_usbphy_get_vbus_state, vbus_valid,
> + imxphy);
I assume valid == usb port is in gadget mode and host is supplying vbus?
What happens when port is in host mode? A comment explaining this would
be nice.
> }
>
> iores = dev_request_mem_resource(dev, 0);
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] usb: imx-us-phy: add vbus_valid ro parameter
2021-08-24 11:01 ` Ahmad Fatoum
@ 2021-08-24 11:13 ` Marco Felsch
2021-08-24 11:21 ` Ahmad Fatoum
0 siblings, 1 reply; 4+ messages in thread
From: Marco Felsch @ 2021-08-24 11:13 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
Hi Ahmad,
On 21-08-24 13:01, Ahmad Fatoum wrote:
> Hello Marco,
>
> On 24.08.21 12:46, Marco Felsch wrote:
> > The parameter can be used by init scripts to detect a plugged usb cable.
> > Upon a plugged usb cable the barebox behaviour can be changed which can
> > be useful e.g. during production to apply a special production
> > environment.
> >
> > Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> > ---
> > drivers/usb/imx/imx-usb-phy.c | 34 +++++++++++++++++++++++++++++++++-
> > 1 file changed, 33 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/usb/imx/imx-usb-phy.c b/drivers/usb/imx/imx-usb-phy.c
> > index 32098ef248..9420c8c109 100644
> > --- a/drivers/usb/imx/imx-usb-phy.c
> > +++ b/drivers/usb/imx/imx-usb-phy.c
> > @@ -37,9 +37,12 @@
> > #define BM_USBPHY_CTRL_ENHOSTDISCONDETECT BIT(1)
> >
> > #define ANADIG_USB1_CHRG_DETECT_SET 0x1b4
> > -#define ANADIG_USB2_CHRG_DETECT_SET 0x214
> > #define ANADIG_USB1_CHRG_DETECT_EN_B BIT(20)
> > #define ANADIG_USB1_CHRG_DETECT_CHK_CHRG_B BIT(19)
> > +#define ANADIG_USB1_VBUS_DETECT_STAT 0x1c0
> > +#define ANADIG_USB1_VBUS_DETECT_STAT_VBUS_VALID BIT(3)
> > +#define ANADIG_USB2_CHRG_DETECT_SET 0x214
> > +#define ANADIG_USB2_VBUS_DETECT_STAT 0x220
> >
> > struct imx_usbphy {
> > struct usb_phy usb_phy;
> > @@ -132,6 +135,27 @@ static const struct phy_ops imx_phy_ops = {
> > .to_usbphy = imx_usbphy_to_usbphy,
> > };
> >
> > +/* Albeit the access can only happen serial use two variables */
> > +unsigned int vbus_valid_usb1;
> > +unsigned int vbus_valid_usb2;
> > +
> > +static int imx_usbphy_get_vbus_state(struct param_d *p, void *priv)
> > +{
> > + struct imx_usbphy *imxphy = priv;
> > + unsigned int *vbus_valid;
> > + unsigned int reg, val;
> > +
> > + reg = imxphy->port_id ?
> > + ANADIG_USB1_VBUS_DETECT_STAT :
> > + ANADIG_USB2_VBUS_DETECT_STAT;
> > + val = readl(imxphy->anatop + reg);
> > +
> > + vbus_valid = imxphy->port_id ? &vbus_valid_usb1 : &vbus_valid_usb2;
> > + *vbus_valid = !!(val & ANADIG_USB1_VBUS_DETECT_STAT_VBUS_VALID);
> > +
> > + return 0;
> > +}
> > +
> > static int imx_usbphy_probe(struct device_d *dev)
> > {
> > struct resource *iores;
> > @@ -149,11 +173,19 @@ static int imx_usbphy_probe(struct device_d *dev)
> > imxphy->port_id = ret;
> >
> > if (of_get_property(np, "fsl,anatop", NULL)) {
> > + unsigned int *vbus_valid = imxphy->port_id ?
> > + &vbus_valid_usb1 :
> > + &vbus_valid_usb2;
>
> Can you allocate this in imxphy? That way you avoid globals
> and don't hardcode the existance of only two phys into the driver.
You're right, good point.
> > +
> > imxphy->anatop =
> > syscon_base_lookup_by_phandle(np, "fsl,anatop");
> > ret = PTR_ERR_OR_ZERO(imxphy->anatop);
> > if (ret)
> > goto err_free;
> > +
> > + dev_add_param_bool(dev, "vbus_valid", param_set_readonly,
> > + imx_usbphy_get_vbus_state, vbus_valid,
> > + imxphy);
>
> I assume valid == usb port is in gadget mode and host is supplying vbus?
Your're right.
> What happens when port is in host mode? A comment explaining this would
> be nice.
That's a good question didn't checked this and the datasheet don't
distinguish between those modes. I will test it and add a comment.
Regards,
Marco
>
> > }
> >
> > iores = dev_request_mem_resource(dev, 0);
> >
>
>
> --
> Pengutronix e.K. | |
> Steuerwalder Str. 21 | http://www.pengutronix.de/ |
> 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] usb: imx-us-phy: add vbus_valid ro parameter
2021-08-24 11:13 ` Marco Felsch
@ 2021-08-24 11:21 ` Ahmad Fatoum
0 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2021-08-24 11:21 UTC (permalink / raw)
To: Marco Felsch; +Cc: barebox
On 24.08.21 13:13, Marco Felsch wrote:
> Hi Ahmad,
>
> On 21-08-24 13:01, Ahmad Fatoum wrote:
>> Hello Marco,
>>
>> On 24.08.21 12:46, Marco Felsch wrote:
>>> The parameter can be used by init scripts to detect a plugged usb cable.
>>> Upon a plugged usb cable the barebox behaviour can be changed which can
>>> be useful e.g. during production to apply a special production
>>> environment.
>>>
>>> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
>>> ---
>>> drivers/usb/imx/imx-usb-phy.c | 34 +++++++++++++++++++++++++++++++++-
>>> 1 file changed, 33 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/usb/imx/imx-usb-phy.c b/drivers/usb/imx/imx-usb-phy.c
>>> index 32098ef248..9420c8c109 100644
>>> --- a/drivers/usb/imx/imx-usb-phy.c
>>> +++ b/drivers/usb/imx/imx-usb-phy.c
>>> @@ -37,9 +37,12 @@
>>> #define BM_USBPHY_CTRL_ENHOSTDISCONDETECT BIT(1)
>>>
>>> #define ANADIG_USB1_CHRG_DETECT_SET 0x1b4
>>> -#define ANADIG_USB2_CHRG_DETECT_SET 0x214
>>> #define ANADIG_USB1_CHRG_DETECT_EN_B BIT(20)
>>> #define ANADIG_USB1_CHRG_DETECT_CHK_CHRG_B BIT(19)
>>> +#define ANADIG_USB1_VBUS_DETECT_STAT 0x1c0
>>> +#define ANADIG_USB1_VBUS_DETECT_STAT_VBUS_VALID BIT(3)
>>> +#define ANADIG_USB2_CHRG_DETECT_SET 0x214
>>> +#define ANADIG_USB2_VBUS_DETECT_STAT 0x220
>>>
>>> struct imx_usbphy {
>>> struct usb_phy usb_phy;
>>> @@ -132,6 +135,27 @@ static const struct phy_ops imx_phy_ops = {
>>> .to_usbphy = imx_usbphy_to_usbphy,
>>> };
>>>
>>> +/* Albeit the access can only happen serial use two variables */
>>> +unsigned int vbus_valid_usb1;
>>> +unsigned int vbus_valid_usb2;
>>> +
>>> +static int imx_usbphy_get_vbus_state(struct param_d *p, void *priv)
>>> +{
>>> + struct imx_usbphy *imxphy = priv;
>>> + unsigned int *vbus_valid;
>>> + unsigned int reg, val;
>>> +
>>> + reg = imxphy->port_id ?
>>> + ANADIG_USB1_VBUS_DETECT_STAT :
>>> + ANADIG_USB2_VBUS_DETECT_STAT;
>>> + val = readl(imxphy->anatop + reg);
>>> +
>>> + vbus_valid = imxphy->port_id ? &vbus_valid_usb1 : &vbus_valid_usb2;
>>> + *vbus_valid = !!(val & ANADIG_USB1_VBUS_DETECT_STAT_VBUS_VALID);
>>> +
>>> + return 0;
>>> +}
>>> +
>>> static int imx_usbphy_probe(struct device_d *dev)
>>> {
>>> struct resource *iores;
>>> @@ -149,11 +173,19 @@ static int imx_usbphy_probe(struct device_d *dev)
>>> imxphy->port_id = ret;
>>>
>>> if (of_get_property(np, "fsl,anatop", NULL)) {
>>> + unsigned int *vbus_valid = imxphy->port_id ?
>>> + &vbus_valid_usb1 :
>>> + &vbus_valid_usb2;
>>
>> Can you allocate this in imxphy? That way you avoid globals
>> and don't hardcode the existance of only two phys into the driver.
>
> You're right, good point.
>
>>> +
>>> imxphy->anatop =
>>> syscon_base_lookup_by_phandle(np, "fsl,anatop");
>>> ret = PTR_ERR_OR_ZERO(imxphy->anatop);
>>> if (ret)
>>> goto err_free;
>>> +
>>> + dev_add_param_bool(dev, "vbus_valid", param_set_readonly,
>>> + imx_usbphy_get_vbus_state, vbus_valid,
>>> + imxphy);
>>
>> I assume valid == usb port is in gadget mode and host is supplying vbus?
>
> Your're right.
>
>> What happens when port is in host mode? A comment explaining this would
>> be nice.
>
> That's a good question didn't checked this and the datasheet don't
> distinguish between those modes. I will test it and add a comment.
prt_imx6_check_usb_boot may also be interesting to you. The protonic boards
use this to detect whether a USB drive is connected or not.
Combining those could give you a usb.connected_to={gadget,host,none}
(or some other better name)
Cheers,
Ahmad
>
> Regards,
> Marco
>
>>
>>> }
>>>
>>> iores = dev_request_mem_resource(dev, 0);
>>>
>>
>>
>> --
>> Pengutronix e.K. | |
>> Steuerwalder Str. 21 | http://www.pengutronix.de/ |
>> 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
>> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
>>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-08-24 11:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-24 10:46 [PATCH] usb: imx-us-phy: add vbus_valid ro parameter Marco Felsch
2021-08-24 11:01 ` Ahmad Fatoum
2021-08-24 11:13 ` Marco Felsch
2021-08-24 11:21 ` Ahmad Fatoum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox