Re: [PATCH] phy: rcar-gen3-usb2: add sysfs for usb role swap
Hi Shimoda-san, On Tue, Oct 18, 2016 at 8:19 AM, Yoshihiro Shimodawrote: >> From: geert.uytterhoe...@gmail.com >> Sent: Monday, October 17, 2016 9:28 PM >> On Mon, Oct 17, 2016 at 9:10 AM, Yoshihiro Shimoda >> wrote: >> > This patch adds sysfs "otg_inputs" for usb role swap. This parameter >> > is write-only and if you use them as the following, you can swap >> > the usb role. >> >> Thank you for your patch! > > Thank you for the review! > >> > For example: >> > 1) connect a usb cable using 2 salvator-x boards >> > 2) On A-device (as host), you input the following command: >> ># echo a_bus_req/ > >> > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs >> > 3) On B-device (as peripheral), you input the following command: >> ># echo b_bus_req > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs >> >> At first, I thought the trailing "/" was a typo... >> >> > --- /dev/null >> > +++ b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 >> > @@ -0,0 +1,11 @@ >> > +What: /sys/devices/platform//otg-inputs >> > +Date: October 2016 >> > +KernelVersion: 4.10 >> > +Contact: Yoshihiro Shimoda >> > +Description: >> > + This write-only file changes the phy mode for role swap of >> > usb. >> > + This file accepts the following strings: >> > +"a_bus_req/" - switching from A-Host to A-Peripheral >> > +"a_bus_drop" - switching from A-Peripheral to A-Host >> > +"b_bus_req" - switching from B-Peripheral to B-Host >> > +"b_bus_req/" - switching from B-Host to B-Peripheral >> >> ... until I read the above. >> >> What's the rationale of doing it like this? I.e. >> 1. Why differentiate by trailing "/"? > > This usb role swap feature is not compatible with USB OTG though, > but this strings are from the manual that usb.org released: > http://www.usb.org/developers/docs/usb20_docs/ > --> usb_20_091216.zip > --> USB OTG and Embedded Host/USB_OTG_and_EH_2-0-version 1_1a.pdf >Please refer to the following figures: > - Figure 7-1: OTG A-device with HNP State Diagram > - Figure 7-4: OTG B-device with HNP State Diagram > > So, it seems the "/" means FALSE. > >> 2. Why the asymmetry ("a_bus_drop" vs. "a_bus_req")? > > This is also related the document. > - From "a_host" to "a_suspend" state if "a_bus_req/" event happens. > - From "a_suspend" to "a_host" state if "a_bus_req" event happens. > (But the driver doesn't support it and we can use "a_bus_drop".) > - From "a_peripheral" to "a_wait_vfall" state if "a_bus_drop" event happens. Thanks for the explanation! Regardless, I think it would be good to CC the USB maintainer and mailing list on next submission. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Re: [PATCH] phy: rcar-gen3-usb2: add sysfs for usb role swap
Hi Shimoda-san, On Tue, Oct 18, 2016 at 8:19 AM, Yoshihiro Shimoda wrote: >> From: geert.uytterhoe...@gmail.com >> Sent: Monday, October 17, 2016 9:28 PM >> On Mon, Oct 17, 2016 at 9:10 AM, Yoshihiro Shimoda >> wrote: >> > This patch adds sysfs "otg_inputs" for usb role swap. This parameter >> > is write-only and if you use them as the following, you can swap >> > the usb role. >> >> Thank you for your patch! > > Thank you for the review! > >> > For example: >> > 1) connect a usb cable using 2 salvator-x boards >> > 2) On A-device (as host), you input the following command: >> ># echo a_bus_req/ > >> > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs >> > 3) On B-device (as peripheral), you input the following command: >> ># echo b_bus_req > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs >> >> At first, I thought the trailing "/" was a typo... >> >> > --- /dev/null >> > +++ b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 >> > @@ -0,0 +1,11 @@ >> > +What: /sys/devices/platform//otg-inputs >> > +Date: October 2016 >> > +KernelVersion: 4.10 >> > +Contact: Yoshihiro Shimoda >> > +Description: >> > + This write-only file changes the phy mode for role swap of >> > usb. >> > + This file accepts the following strings: >> > +"a_bus_req/" - switching from A-Host to A-Peripheral >> > +"a_bus_drop" - switching from A-Peripheral to A-Host >> > +"b_bus_req" - switching from B-Peripheral to B-Host >> > +"b_bus_req/" - switching from B-Host to B-Peripheral >> >> ... until I read the above. >> >> What's the rationale of doing it like this? I.e. >> 1. Why differentiate by trailing "/"? > > This usb role swap feature is not compatible with USB OTG though, > but this strings are from the manual that usb.org released: > http://www.usb.org/developers/docs/usb20_docs/ > --> usb_20_091216.zip > --> USB OTG and Embedded Host/USB_OTG_and_EH_2-0-version 1_1a.pdf >Please refer to the following figures: > - Figure 7-1: OTG A-device with HNP State Diagram > - Figure 7-4: OTG B-device with HNP State Diagram > > So, it seems the "/" means FALSE. > >> 2. Why the asymmetry ("a_bus_drop" vs. "a_bus_req")? > > This is also related the document. > - From "a_host" to "a_suspend" state if "a_bus_req/" event happens. > - From "a_suspend" to "a_host" state if "a_bus_req" event happens. > (But the driver doesn't support it and we can use "a_bus_drop".) > - From "a_peripheral" to "a_wait_vfall" state if "a_bus_drop" event happens. Thanks for the explanation! Regardless, I think it would be good to CC the USB maintainer and mailing list on next submission. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
RE: [PATCH] phy: rcar-gen3-usb2: add sysfs for usb role swap
Hi Geert-san, > From: geert.uytterhoe...@gmail.com > Sent: Monday, October 17, 2016 9:28 PM > > Hi Shimoda-san, > > On Mon, Oct 17, 2016 at 9:10 AM, Yoshihiro Shimoda >wrote: > > This patch adds sysfs "otg_inputs" for usb role swap. This parameter > > is write-only and if you use them as the following, you can swap > > the usb role. > > Thank you for your patch! Thank you for the review! > > For example: > > 1) connect a usb cable using 2 salvator-x boards > > 2) On A-device (as host), you input the following command: > ># echo a_bus_req/ > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs > > 3) On B-device (as peripheral), you input the following command: > ># echo b_bus_req > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs > > At first, I thought the trailing "/" was a typo... > > > --- /dev/null > > +++ b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 > > @@ -0,0 +1,11 @@ > > +What: /sys/devices/platform//otg-inputs > > +Date: October 2016 > > +KernelVersion: 4.10 > > +Contact: Yoshihiro Shimoda > > +Description: > > + This write-only file changes the phy mode for role swap of > > usb. > > + This file accepts the following strings: > > +"a_bus_req/" - switching from A-Host to A-Peripheral > > +"a_bus_drop" - switching from A-Peripheral to A-Host > > +"b_bus_req" - switching from B-Peripheral to B-Host > > +"b_bus_req/" - switching from B-Host to B-Peripheral > > ... until I read the above. > > What's the rationale of doing it like this? I.e. > 1. Why differentiate by trailing "/"? This usb role swap feature is not compatible with USB OTG though, but this strings are from the manual that usb.org released: http://www.usb.org/developers/docs/usb20_docs/ --> usb_20_091216.zip --> USB OTG and Embedded Host/USB_OTG_and_EH_2-0-version 1_1a.pdf Please refer to the following figures: - Figure 7-1: OTG A-device with HNP State Diagram - Figure 7-4: OTG B-device with HNP State Diagram So, it seems the "/" means FALSE. > 2. Why the asymmetry ("a_bus_drop" vs. "a_bus_req")? This is also related the document. - From "a_host" to "a_suspend" state if "a_bus_req/" event happens. - From "a_suspend" to "a_host" state if "a_bus_req" event happens. (But the driver doesn't support it and we can use "a_bus_drop".) - From "a_peripheral" to "a_wait_vfall" state if "a_bus_drop" event happens. > I do not really follow USB development, so I please accepty my apologies if > I missed the discussion and valid arguments that lead to this. > > I did find Documentation/ABI/testing/sysfs-platform-chipidea-usb-otg, > which uses similar naming, but a slightly different mechanism (multiple > sysfs virtual files with 0/1 states). I also did look at the document. But, I prefer one parameter to control it. Best regards, Yoshihiro Shimoda > Thanks! > > Gr{oetje,eeting}s, > > Geert > > -- > Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- > ge...@linux-m68k.org > > In personal conversations with technical people, I call myself a hacker. But > when I'm talking to journalists I just say "programmer" or something like > that. > -- Linus Torvalds
RE: [PATCH] phy: rcar-gen3-usb2: add sysfs for usb role swap
Hi Geert-san, > From: geert.uytterhoe...@gmail.com > Sent: Monday, October 17, 2016 9:28 PM > > Hi Shimoda-san, > > On Mon, Oct 17, 2016 at 9:10 AM, Yoshihiro Shimoda > wrote: > > This patch adds sysfs "otg_inputs" for usb role swap. This parameter > > is write-only and if you use them as the following, you can swap > > the usb role. > > Thank you for your patch! Thank you for the review! > > For example: > > 1) connect a usb cable using 2 salvator-x boards > > 2) On A-device (as host), you input the following command: > ># echo a_bus_req/ > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs > > 3) On B-device (as peripheral), you input the following command: > ># echo b_bus_req > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs > > At first, I thought the trailing "/" was a typo... > > > --- /dev/null > > +++ b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 > > @@ -0,0 +1,11 @@ > > +What: /sys/devices/platform//otg-inputs > > +Date: October 2016 > > +KernelVersion: 4.10 > > +Contact: Yoshihiro Shimoda > > +Description: > > + This write-only file changes the phy mode for role swap of > > usb. > > + This file accepts the following strings: > > +"a_bus_req/" - switching from A-Host to A-Peripheral > > +"a_bus_drop" - switching from A-Peripheral to A-Host > > +"b_bus_req" - switching from B-Peripheral to B-Host > > +"b_bus_req/" - switching from B-Host to B-Peripheral > > ... until I read the above. > > What's the rationale of doing it like this? I.e. > 1. Why differentiate by trailing "/"? This usb role swap feature is not compatible with USB OTG though, but this strings are from the manual that usb.org released: http://www.usb.org/developers/docs/usb20_docs/ --> usb_20_091216.zip --> USB OTG and Embedded Host/USB_OTG_and_EH_2-0-version 1_1a.pdf Please refer to the following figures: - Figure 7-1: OTG A-device with HNP State Diagram - Figure 7-4: OTG B-device with HNP State Diagram So, it seems the "/" means FALSE. > 2. Why the asymmetry ("a_bus_drop" vs. "a_bus_req")? This is also related the document. - From "a_host" to "a_suspend" state if "a_bus_req/" event happens. - From "a_suspend" to "a_host" state if "a_bus_req" event happens. (But the driver doesn't support it and we can use "a_bus_drop".) - From "a_peripheral" to "a_wait_vfall" state if "a_bus_drop" event happens. > I do not really follow USB development, so I please accepty my apologies if > I missed the discussion and valid arguments that lead to this. > > I did find Documentation/ABI/testing/sysfs-platform-chipidea-usb-otg, > which uses similar naming, but a slightly different mechanism (multiple > sysfs virtual files with 0/1 states). I also did look at the document. But, I prefer one parameter to control it. Best regards, Yoshihiro Shimoda > Thanks! > > Gr{oetje,eeting}s, > > Geert > > -- > Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- > ge...@linux-m68k.org > > In personal conversations with technical people, I call myself a hacker. But > when I'm talking to journalists I just say "programmer" or something like > that. > -- Linus Torvalds
Re: [PATCH] phy: rcar-gen3-usb2: add sysfs for usb role swap
Hi Shimoda-san, On Mon, Oct 17, 2016 at 9:10 AM, Yoshihiro Shimodawrote: > This patch adds sysfs "otg_inputs" for usb role swap. This parameter > is write-only and if you use them as the following, you can swap > the usb role. Thank you for your patch! > For example: > 1) connect a usb cable using 2 salvator-x boards > 2) On A-device (as host), you input the following command: ># echo a_bus_req/ > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs > 3) On B-device (as peripheral), you input the following command: ># echo b_bus_req > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs At first, I thought the trailing "/" was a typo... > --- /dev/null > +++ b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 > @@ -0,0 +1,11 @@ > +What: /sys/devices/platform//otg-inputs > +Date: October 2016 > +KernelVersion: 4.10 > +Contact: Yoshihiro Shimoda > +Description: > + This write-only file changes the phy mode for role swap of > usb. > + This file accepts the following strings: > +"a_bus_req/" - switching from A-Host to A-Peripheral > +"a_bus_drop" - switching from A-Peripheral to A-Host > +"b_bus_req" - switching from B-Peripheral to B-Host > +"b_bus_req/" - switching from B-Host to B-Peripheral ... until I read the above. What's the rationale of doing it like this? I.e. 1. Why differentiate by trailing "/"? 2. Why the asymmetry ("a_bus_drop" vs. "a_bus_req")? I do not really follow USB development, so I please accepty my apologies if I missed the discussion and valid arguments that lead to this. I did find Documentation/ABI/testing/sysfs-platform-chipidea-usb-otg, which uses similar naming, but a slightly different mechanism (multiple sysfs virtual files with 0/1 states). Thanks! Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Re: [PATCH] phy: rcar-gen3-usb2: add sysfs for usb role swap
Hi Shimoda-san, On Mon, Oct 17, 2016 at 9:10 AM, Yoshihiro Shimoda wrote: > This patch adds sysfs "otg_inputs" for usb role swap. This parameter > is write-only and if you use them as the following, you can swap > the usb role. Thank you for your patch! > For example: > 1) connect a usb cable using 2 salvator-x boards > 2) On A-device (as host), you input the following command: ># echo a_bus_req/ > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs > 3) On B-device (as peripheral), you input the following command: ># echo b_bus_req > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs At first, I thought the trailing "/" was a typo... > --- /dev/null > +++ b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 > @@ -0,0 +1,11 @@ > +What: /sys/devices/platform//otg-inputs > +Date: October 2016 > +KernelVersion: 4.10 > +Contact: Yoshihiro Shimoda > +Description: > + This write-only file changes the phy mode for role swap of > usb. > + This file accepts the following strings: > +"a_bus_req/" - switching from A-Host to A-Peripheral > +"a_bus_drop" - switching from A-Peripheral to A-Host > +"b_bus_req" - switching from B-Peripheral to B-Host > +"b_bus_req/" - switching from B-Host to B-Peripheral ... until I read the above. What's the rationale of doing it like this? I.e. 1. Why differentiate by trailing "/"? 2. Why the asymmetry ("a_bus_drop" vs. "a_bus_req")? I do not really follow USB development, so I please accepty my apologies if I missed the discussion and valid arguments that lead to this. I did find Documentation/ABI/testing/sysfs-platform-chipidea-usb-otg, which uses similar naming, but a slightly different mechanism (multiple sysfs virtual files with 0/1 states). Thanks! Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
[PATCH] phy: rcar-gen3-usb2: add sysfs for usb role swap
This patch adds sysfs "otg_inputs" for usb role swap. This parameter is write-only and if you use them as the following, you can swap the usb role. For example: 1) connect a usb cable using 2 salvator-x boards 2) On A-device (as host), you input the following command: # echo a_bus_req/ > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs 3) On B-device (as peripheral), you input the following command: # echo b_bus_req > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs Then, the A-device acts as a peripheral (A-peripheral) and the B-device acts as a host (B-host). Please note that A-device must input the following command if you want the board to act as a host again. (even if you disconnect the usb cable, since id state may be the same, the condition keeps "A-peripheral".) # echo a_bus_drop > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs Also you can use the following command if you want the B-device board to act as a peripheral again. # echo b_bus_req/ > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs Signed-off-by: Yoshihiro Shimoda--- This patch is based on the linux-phy.git / phy-for-4.9-resolved_v3 tag. (commit id = c4b0bf82f705747ed7de90c5736b07248cbb29cd) .../ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 | 11 ++ drivers/phy/phy-rcar-gen3-usb2.c | 124 - 2 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 diff --git a/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 new file mode 100644 index 000..c7e715af --- /dev/null +++ b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 @@ -0,0 +1,11 @@ +What: /sys/devices/platform//otg-inputs +Date: October 2016 +KernelVersion: 4.10 +Contact: Yoshihiro Shimoda +Description: + This write-only file changes the phy mode for role swap of usb. + This file accepts the following strings: +"a_bus_req/" - switching from A-Host to A-Peripheral +"a_bus_drop" - switching from A-Peripheral to A-Host +"b_bus_req" - switching from B-Peripheral to B-Host +"b_bus_req/" - switching from B-Host to B-Peripheral diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c index 3d97ead..80f5bcc 100644 --- a/drivers/phy/phy-rcar-gen3-usb2.c +++ b/drivers/phy/phy-rcar-gen3-usb2.c @@ -70,6 +70,7 @@ #define USB2_LINECTRL1_DP_RPD BIT(18) #define USB2_LINECTRL1_DMRPD_ENBIT(17) #define USB2_LINECTRL1_DM_RPD BIT(16) +#define USB2_LINECTRL1_OPMODE_NODRVBIT(6) /* ADPCTRL */ #define USB2_ADPCTRL_OTGSESSVLDBIT(20) @@ -161,6 +162,43 @@ static void rcar_gen3_init_for_peri(struct rcar_gen3_chan *ch) schedule_work(>work); } +static void rcar_gen3_init_for_b_host(struct rcar_gen3_chan *ch) +{ + void __iomem *usb2_base = ch->base; + u32 val; + + val = readl(usb2_base + USB2_LINECTRL1); + writel(val | USB2_LINECTRL1_OPMODE_NODRV, usb2_base + USB2_LINECTRL1); + + rcar_gen3_set_linectrl(ch, 1, 1); + rcar_gen3_set_host_mode(ch, 1); + rcar_gen3_enable_vbus_ctrl(ch, 0); + + val = readl(usb2_base + USB2_LINECTRL1); + writel(val & ~USB2_LINECTRL1_OPMODE_NODRV, usb2_base + USB2_LINECTRL1); +} + +static void rcar_gen3_init_for_a_peri(struct rcar_gen3_chan *ch) +{ + rcar_gen3_set_linectrl(ch, 0, 1); + rcar_gen3_set_host_mode(ch, 0); + rcar_gen3_enable_vbus_ctrl(ch, 1); +} + +static void rcar_gen3_init_from_a_peri_to_a_host(struct rcar_gen3_chan *ch) +{ + void __iomem *usb2_base = ch->base; + u32 val; + + val = readl(usb2_base + USB2_OBINTEN); + writel(val & ~USB2_OBINT_BITS, usb2_base + USB2_OBINTEN); + + rcar_gen3_enable_vbus_ctrl(ch, 0); + rcar_gen3_init_for_host(ch); + + writel(val | USB2_OBINT_BITS, usb2_base + USB2_OBINTEN); +} + static bool rcar_gen3_check_id(struct rcar_gen3_chan *ch) { return !!(readl(ch->base + USB2_ADPCTRL) & USB2_ADPCTRL_IDDIG); @@ -174,6 +212,71 @@ static void rcar_gen3_device_recognition(struct rcar_gen3_chan *ch) rcar_gen3_init_for_peri(ch); } +/* + * The following table is a state transition for usb phy mode: + * State Event Next state + * disconnected: E1 a_host + * E2 b_peripheral + * A-Device - a_host: E2 b_peripheral + * E3 disconnected + * E4 a_suspend + * A-Device - a_suspend: E2 b_peripheral + * E3 disconnected + * E5 a_host + * E6 a_peripheral + *
[PATCH] phy: rcar-gen3-usb2: add sysfs for usb role swap
This patch adds sysfs "otg_inputs" for usb role swap. This parameter is write-only and if you use them as the following, you can swap the usb role. For example: 1) connect a usb cable using 2 salvator-x boards 2) On A-device (as host), you input the following command: # echo a_bus_req/ > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs 3) On B-device (as peripheral), you input the following command: # echo b_bus_req > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs Then, the A-device acts as a peripheral (A-peripheral) and the B-device acts as a host (B-host). Please note that A-device must input the following command if you want the board to act as a host again. (even if you disconnect the usb cable, since id state may be the same, the condition keeps "A-peripheral".) # echo a_bus_drop > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs Also you can use the following command if you want the B-device board to act as a peripheral again. # echo b_bus_req/ > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs Signed-off-by: Yoshihiro Shimoda --- This patch is based on the linux-phy.git / phy-for-4.9-resolved_v3 tag. (commit id = c4b0bf82f705747ed7de90c5736b07248cbb29cd) .../ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 | 11 ++ drivers/phy/phy-rcar-gen3-usb2.c | 124 - 2 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 diff --git a/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 new file mode 100644 index 000..c7e715af --- /dev/null +++ b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 @@ -0,0 +1,11 @@ +What: /sys/devices/platform//otg-inputs +Date: October 2016 +KernelVersion: 4.10 +Contact: Yoshihiro Shimoda +Description: + This write-only file changes the phy mode for role swap of usb. + This file accepts the following strings: +"a_bus_req/" - switching from A-Host to A-Peripheral +"a_bus_drop" - switching from A-Peripheral to A-Host +"b_bus_req" - switching from B-Peripheral to B-Host +"b_bus_req/" - switching from B-Host to B-Peripheral diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c index 3d97ead..80f5bcc 100644 --- a/drivers/phy/phy-rcar-gen3-usb2.c +++ b/drivers/phy/phy-rcar-gen3-usb2.c @@ -70,6 +70,7 @@ #define USB2_LINECTRL1_DP_RPD BIT(18) #define USB2_LINECTRL1_DMRPD_ENBIT(17) #define USB2_LINECTRL1_DM_RPD BIT(16) +#define USB2_LINECTRL1_OPMODE_NODRVBIT(6) /* ADPCTRL */ #define USB2_ADPCTRL_OTGSESSVLDBIT(20) @@ -161,6 +162,43 @@ static void rcar_gen3_init_for_peri(struct rcar_gen3_chan *ch) schedule_work(>work); } +static void rcar_gen3_init_for_b_host(struct rcar_gen3_chan *ch) +{ + void __iomem *usb2_base = ch->base; + u32 val; + + val = readl(usb2_base + USB2_LINECTRL1); + writel(val | USB2_LINECTRL1_OPMODE_NODRV, usb2_base + USB2_LINECTRL1); + + rcar_gen3_set_linectrl(ch, 1, 1); + rcar_gen3_set_host_mode(ch, 1); + rcar_gen3_enable_vbus_ctrl(ch, 0); + + val = readl(usb2_base + USB2_LINECTRL1); + writel(val & ~USB2_LINECTRL1_OPMODE_NODRV, usb2_base + USB2_LINECTRL1); +} + +static void rcar_gen3_init_for_a_peri(struct rcar_gen3_chan *ch) +{ + rcar_gen3_set_linectrl(ch, 0, 1); + rcar_gen3_set_host_mode(ch, 0); + rcar_gen3_enable_vbus_ctrl(ch, 1); +} + +static void rcar_gen3_init_from_a_peri_to_a_host(struct rcar_gen3_chan *ch) +{ + void __iomem *usb2_base = ch->base; + u32 val; + + val = readl(usb2_base + USB2_OBINTEN); + writel(val & ~USB2_OBINT_BITS, usb2_base + USB2_OBINTEN); + + rcar_gen3_enable_vbus_ctrl(ch, 0); + rcar_gen3_init_for_host(ch); + + writel(val | USB2_OBINT_BITS, usb2_base + USB2_OBINTEN); +} + static bool rcar_gen3_check_id(struct rcar_gen3_chan *ch) { return !!(readl(ch->base + USB2_ADPCTRL) & USB2_ADPCTRL_IDDIG); @@ -174,6 +212,71 @@ static void rcar_gen3_device_recognition(struct rcar_gen3_chan *ch) rcar_gen3_init_for_peri(ch); } +/* + * The following table is a state transition for usb phy mode: + * State Event Next state + * disconnected: E1 a_host + * E2 b_peripheral + * A-Device - a_host: E2 b_peripheral + * E3 disconnected + * E4 a_suspend + * A-Device - a_suspend: E2 b_peripheral + * E3 disconnected + * E5 a_host + * E6 a_peripheral + * A-Device - a_peripheral:E2 b_peripheral + *