Message ID | 20191218203450.71037-1-stephan@gerhold.net (mailing list archive) |
---|---|
State | Mainlined |
Commit | c4a68b4da65ad388bbe3c3791f60655c4dd81173 |
Headers | show |
Series | usb: phy: ab8500-usb: Keep PHY turned on in UART mode | expand |
Hi Stephan, On Wed, Dec 18, 2019 at 9:37 PM Stephan Gerhold <stephan@gerhold.net> wrote: > AB8505 supports an "UART carkit mode" which makes UART accessible > through the USB connector. Upon detection of the UART cable, > this mode has to be manually enabled by: > > 1. Turning on the PHY in peripheral mode > 2. Reconfiguring PHY/pins to route UART signals to USB pins > > At the moment, we do not handle the UART link statuses at all, > which means that UART stops working as soon as phy-ab8500-usb is loaded > (since we disable the PHY after initialization). > > Keeping UART working if the cable is inserted before turning on the device > is quite simple: In this case, early boot firmware has already set up > the necessary PHY/pin configuration. The presence of the UART cable > is reported by a special value in the USB link status register. > > We can check for that value in ab8505_usb_link_status_update() > and set the PHY back to peripheral mode to restore UART. > (Note: This will result in some minor garbage since we still > temporarily disable the PHY during initialization...) > > Fully implementing this feature is more complicated: > For some reason, AB8505 does not update UART link status after bootup. > Regular USB cables work fine, but the link status register does not change > its state if an UART cable is inserted/removed. > > It seems likely that the hardware is not actually capable of detecting > UART cables autonomously. In addition to the USB link status register, > implementations in the vendor kernel also manually measure > the ID resistance to detect additional cable types. For UART cables, > the USB link status register might simply reflect the PHY configuration > instead of the actual link status. > > Implementing that functionality requires significant additions, > so for now just implement the simple case. This allows using UART > when inserting the cable before turning on the device. > > Cc: Linus Walleij <linus.walleij@linaro.org> > Signed-off-by: Stephan Gerhold <stephan@gerhold.net> This is my understanding of how it works as well: Reviewed-by: Linus Walleij <linus.walleij@linaro.org> I am a bit allergic to using the word "manually" describing anything a computer does (no man involved) but many people use this way of describing things so who am I to tell. I tend to try to write "directly", "iteratively", "imperatively" or something, which is arguably harder to understand for some. Yours, Linus Walleij
On Wed, Dec 18, 2019 at 10:30:59PM +0100, Linus Walleij wrote: > Hi Stephan, > > On Wed, Dec 18, 2019 at 9:37 PM Stephan Gerhold <stephan@gerhold.net> wrote: > > > AB8505 supports an "UART carkit mode" which makes UART accessible > > through the USB connector. Upon detection of the UART cable, > > this mode has to be manually enabled by: > > > > 1. Turning on the PHY in peripheral mode > > 2. Reconfiguring PHY/pins to route UART signals to USB pins > > > > At the moment, we do not handle the UART link statuses at all, > > which means that UART stops working as soon as phy-ab8500-usb is loaded > > (since we disable the PHY after initialization). > > > > Keeping UART working if the cable is inserted before turning on the device > > is quite simple: In this case, early boot firmware has already set up > > the necessary PHY/pin configuration. The presence of the UART cable > > is reported by a special value in the USB link status register. > > > > We can check for that value in ab8505_usb_link_status_update() > > and set the PHY back to peripheral mode to restore UART. > > (Note: This will result in some minor garbage since we still > > temporarily disable the PHY during initialization...) > > > > Fully implementing this feature is more complicated: > > For some reason, AB8505 does not update UART link status after bootup. > > Regular USB cables work fine, but the link status register does not change > > its state if an UART cable is inserted/removed. > > > > It seems likely that the hardware is not actually capable of detecting > > UART cables autonomously. In addition to the USB link status register, > > implementations in the vendor kernel also manually measure > > the ID resistance to detect additional cable types. For UART cables, > > the USB link status register might simply reflect the PHY configuration > > instead of the actual link status. > > > > Implementing that functionality requires significant additions, > > so for now just implement the simple case. This allows using UART > > when inserting the cable before turning on the device. > > > > Cc: Linus Walleij <linus.walleij@linaro.org> > > Signed-off-by: Stephan Gerhold <stephan@gerhold.net> > > This is my understanding of how it works as well: > Reviewed-by: Linus Walleij <linus.walleij@linaro.org> > > I am a bit allergic to using the word "manually" describing > anything a computer does (no man involved) but many people > use this way of describing things so who am I to tell. > I tend to try to write "directly", "iteratively", "imperatively" or > something, which is arguably harder to understand for some. I never really thought about it that way. :) Maybe it makes slightly more sense if you consider it from the perspective of the person writing the code. For example, the "UART over USB" functionality is often implemented using an extra IC, usually called MUIC (Micro-USB Interface Controller). The ones I have worked it all measure the ID resistance automatically, and route UART to USB when needed without any software interaction. AB8505 does not do that, so in this case we need to *manually* write code to [let the computer] instruct AB8505 to route UART to the USB pins. Ideally, once the code is working there will be no more manual work needed. But currently manual work is still needed for writing code :)
diff --git a/drivers/usb/phy/phy-ab8500-usb.c b/drivers/usb/phy/phy-ab8500-usb.c index 4bb4b1d42f32..20c0f082bf9c 100644 --- a/drivers/usb/phy/phy-ab8500-usb.c +++ b/drivers/usb/phy/phy-ab8500-usb.c @@ -108,7 +108,8 @@ enum ab8500_usb_mode { USB_IDLE = 0, USB_PERIPHERAL, USB_HOST, - USB_DEDICATED_CHG + USB_DEDICATED_CHG, + USB_UART }; /* Register USB_LINK_STATUS interrupt */ @@ -393,6 +394,24 @@ static int ab8505_usb_link_status_update(struct ab8500_usb *ab, usb_phy_set_event(&ab->phy, USB_EVENT_CHARGER); break; + /* + * FIXME: For now we rely on the boot firmware to set up the necessary + * PHY/pin configuration for UART mode. + * + * AB8505 does not seem to report any status change for UART cables, + * possibly because it cannot detect them autonomously. + * We may need to measure the ID resistance manually to reliably + * detect UART cables after bootup. + */ + case USB_LINK_SAMSUNG_UART_CBL_PHY_EN_8505: + case USB_LINK_SAMSUNG_UART_CBL_PHY_DISB_8505: + if (ab->mode == USB_IDLE) { + ab->mode = USB_UART; + ab8500_usb_peri_phy_en(ab); + } + + break; + default: break; } @@ -566,6 +585,11 @@ static irqreturn_t ab8500_usb_disconnect_irq(int irq, void *data) ab->vbus_draw = 0; } + if (ab->mode == USB_UART) { + ab8500_usb_peri_phy_dis(ab); + ab->mode = USB_IDLE; + } + if (is_ab8500_2p0(ab->ab8500)) { if (ab->mode == USB_DEDICATED_CHG) { ab8500_usb_wd_linkstatus(ab,
AB8505 supports an "UART carkit mode" which makes UART accessible through the USB connector. Upon detection of the UART cable, this mode has to be manually enabled by: 1. Turning on the PHY in peripheral mode 2. Reconfiguring PHY/pins to route UART signals to USB pins At the moment, we do not handle the UART link statuses at all, which means that UART stops working as soon as phy-ab8500-usb is loaded (since we disable the PHY after initialization). Keeping UART working if the cable is inserted before turning on the device is quite simple: In this case, early boot firmware has already set up the necessary PHY/pin configuration. The presence of the UART cable is reported by a special value in the USB link status register. We can check for that value in ab8505_usb_link_status_update() and set the PHY back to peripheral mode to restore UART. (Note: This will result in some minor garbage since we still temporarily disable the PHY during initialization...) Fully implementing this feature is more complicated: For some reason, AB8505 does not update UART link status after bootup. Regular USB cables work fine, but the link status register does not change its state if an UART cable is inserted/removed. It seems likely that the hardware is not actually capable of detecting UART cables autonomously. In addition to the USB link status register, implementations in the vendor kernel also manually measure the ID resistance to detect additional cable types. For UART cables, the USB link status register might simply reflect the PHY configuration instead of the actual link status. Implementing that functionality requires significant additions, so for now just implement the simple case. This allows using UART when inserting the cable before turning on the device. Cc: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Stephan Gerhold <stephan@gerhold.net> --- drivers/usb/phy/phy-ab8500-usb.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-)