musb-ux500 and ab8500-usb updates
Subsystems (2)
v2 cover musb-ux500 and ab8500-usb updates
Hello Felipe,
this is the v2 of my initial update series for ux500's musb.
Changes from v1:
- turn off vbus on USB_EVENT_VBUS event
Thanks,
Fabio
Fabio Baltieri (4):
usb: musb: ux500: implement musb_set_vbus
usb: musb: ux500: add otg notifier support
usb: otg: ab8500-usb: drop support for ab8500 pre v2.0
usb: otg: ab8500-usb: update irq handling code
Virupax Sadashivpetimath (1):
usb: musb: ux500_dma: add missing MEM resource check
drivers/usb/musb/ux500.c | 107 +++++++++ drivers/usb/musb/ux500_dma.c | 12 +- drivers/usb/otg/ab8500-usb.c | 531 ++++++++++++++++++++++++++--------------- include/linux/usb/musb-ux500.h | 31 +++ 4 files changed, 483 insertions(+), 198 deletions(-) create mode 100644 include/linux/usb/musb-ux500.h
Signature · 1 line
1.8.1.3
PATCH v2 1/5 usb: musb: ux500_dma: add missing MEM resource check
From: Virupax Sadashivpetimath <[email protected]>
Fix dma_controller_create() fail path in case memory resource is missing.
--- drivers/usb/musb/ux500_dma.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/usb/musb/ux500_dma.c +11 -1
@@ -372,12 +372,17 @@ struct dma_controller *dma_controller_create(struct musb *musb, controller =kzalloc (sizeof (*controller),GFP_KERNEL );if (!controller) -return NULL ; + goto kzalloc_fail; controller->private_data = musb;/* Save physical address for DMA controller. */ iomem =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!iomem) { +dev_err (musb->controller,"no memory resource defined\n" ); + goto plat_get_fail; + } + controller->phy_base = (dma_addr_t ) iomem->start; controller->controller.start = ux500_dma_controller_start;
@@ -389,4 +394,9 @@ struct dma_controller *dma_controller_create(struct musb *musb, controller->controller.is_compatible = ux500_dma_is_compatible;return &controller->controller; + +plat_get_fail: +kfree (controller); +kzalloc_fail: +return NULL ; }
Signature · 1 line
1.8.1.3
PATCH v2 2/5 usb: musb: ux500: implement musb_set_vbus
In reply to Fabio BaltieriAdd ux500_musb_set_vbus() implementation for ux500.
This is based on the version originally developed inside ST-Ericsson.
--- drivers/usb/musb/ux500.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+)
drivers/usb/musb/ux500.c +64 -0
@@ -36,6 +36,68 @@ struct ux500_glue { };#define glue_to_musb (g) platform_get_drvdata(g->musb) +static void ux500_musb_set_vbus (struct musb *musb,int is_on) +{ +u8 devctl; +unsigned long timeout = jiffies +msecs_to_jiffies (1000 ); +/* HDRC controls CPEN, but beware current surges during device +* connect. They can trigger transient overcurrent conditions +* that must be ignored. +*/ + + devctl =musb_readb (musb->mregs,MUSB_DEVCTL ); + +if (is_on) { +if (musb->xceiv->state ==OTG_STATE_A_IDLE ) { +/* start the session */ + devctl |=MUSB_DEVCTL_SESSION ; +musb_writeb (musb->mregs,MUSB_DEVCTL , devctl); +/* +* Wait for the musb to set as A device to enable the +* VBUS +*/ +while (musb_readb (musb->mregs,MUSB_DEVCTL ) &0x80 ) { + +if (time_after (jiffies, timeout)) { +dev_err (musb->controller, +"configured as A device timeout" ); +break ; + } + } + + }else { + musb->is_active =1 ; + musb->xceiv->otg->default_a =1 ; + musb->xceiv->state =OTG_STATE_A_WAIT_VRISE ; + devctl |=MUSB_DEVCTL_SESSION ; +MUSB_HST_MODE (musb); + } + }else { + musb->is_active =0 ; + +/* NOTE: we're skipping A_WAIT_VFALL -> A_IDLE and jumping +* right to B_IDLE... +*/ + musb->xceiv->otg->default_a =0 ; + devctl &= ~MUSB_DEVCTL_SESSION ; +MUSB_DEV_MODE (musb); + } +musb_writeb (musb->mregs,MUSB_DEVCTL , devctl); + +/* +* Devctl values will be updated after vbus goes below +* session_valid. The time taken depends on the capacitance +* on VBUS line. The max discharge time can be upto 1 sec +* as per the spec. Typically on our platform, it is 200ms +*/ +if (!is_on) +mdelay (200 ); + +dev_dbg (musb->controller,"VBUS %s, devctl %02x\n" , +otg_state_string (musb->xceiv->state), +musb_readb (musb->mregs,MUSB_DEVCTL )); +} +static irqreturn_t ux500_musb_interrupt (int irq,void *__hci) {unsigned long flags;
@@ -79,6 +141,8 @@ static int ux500_musb_exit(struct musb *musb)static const struct musb_platform_ops ux500_ops = { .init = ux500_musb_init, .exit = ux500_musb_exit, + + .set_vbus = ux500_musb_set_vbus, };static int ux500_probe (struct platform_device *pdev)
Signature · 1 line
1.8.1.3
PATCH v2 3/5 usb: musb: ux500: add otg notifier support
In reply to Fabio BaltieriAdd transceiver notifier event handling to the ux500 driver to set vbus on specific transceiver events.
--- drivers/usb/musb/ux500.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+)
drivers/usb/musb/ux500.c +42 -0
@@ -98,6 +98,37 @@ static void ux500_musb_set_vbus(struct musb *musb, int is_on) musb_readb(musb->mregs, MUSB_DEVCTL)); } +static int musb_otg_notifications (struct notifier_block *nb, +unsigned long event,void *unused) +{ + struct musb *musb = container_of(nb, struct musb, nb); + +dev_dbg (musb->controller,"musb_otg_notifications %ld %s\n" , + event,otg_state_string (musb->xceiv->state)); + +switch (event) { +case USB_EVENT_ID : +dev_dbg (musb->controller,"ID GND\n" ); +ux500_musb_set_vbus (musb,1 ); +break ; +case USB_EVENT_VBUS : +dev_dbg (musb->controller,"VBUS Connect\n" ); +ux500_musb_set_vbus (musb,0 ); +break ; +case USB_EVENT_NONE : +dev_dbg (musb->controller,"VBUS Disconnect\n" ); +if (is_host_active (musb)) +ux500_musb_set_vbus (musb,0 ); +else + musb->xceiv->state =OTG_STATE_B_IDLE ; +break ; +default : +dev_dbg (musb->controller,"ID float\n" ); +return NOTIFY_DONE ; + } +return NOTIFY_OK ; +} +static irqreturn_t ux500_musb_interrupt (int irq,void *__hci) {unsigned long flags;
@@ -120,12 +151,21 @@ static irqreturn_t ux500_musb_interrupt(int irq, void *__hci)static int ux500_musb_init (struct musb *musb) { +int status; + musb->xceiv =usb_get_phy (USB_PHY_TYPE_USB2 );if (IS_ERR_OR_NULL (musb->xceiv)) {pr_err ("HS USB OTG: no transceiver configured\n" );return -EPROBE_DEFER ; } + musb->nb.notifier_call = musb_otg_notifications; + status =usb_register_notifier (musb->xceiv, &musb->nb); +if (status <0 ) { +dev_dbg (musb->controller,"notification register failed\n" ); +return status; + } + musb->isr = ux500_musb_interrupt;return 0 ;
@@ -133,6 +173,8 @@ static int ux500_musb_init(struct musb *musb)static int ux500_musb_exit (struct musb *musb) { +usb_unregister_notifier (musb->xceiv, &musb->nb); +usb_put_phy (musb->xceiv);return 0 ;
Signature · 1 line
1.8.1.3
PATCH v2 4/5 usb: otg: ab8500-usb: drop support for ab8500 pre v2.0
In reply to Fabio BaltieriAB8500 versions preceding 2.0 were only used internally by ST-Ericsson and are not supported anymore. This patch drops all v1.0 and v1.1 support code.
--- drivers/usb/otg/ab8500-usb.c | 139 ++++--------------------------------------- 1 file changed, 11 insertions(+), 128 deletions(-)
drivers/usb/otg/ab8500-usb.c +11 -128
@@ -42,10 +42,8 @@#define AB8500_BIT_WD_CTRL_ENABLE (1 << 0)#define AB8500_BIT_WD_CTRL_KICK (1 << 1) -#define AB8500_V1x_LINK_STAT_WAIT (HZ/10)#define AB8500_WD_KICK_DELAY_US 100/* usec */ #define AB8500_WD_V11_DISABLE_DELAY_US 100/* usec */ -#define AB8500_WD_V10_DISABLE_DELAY_MS 100/* ms */ /* Usb line status register */ enum ab8500_usb_link_status {
@@ -70,16 +68,12 @@ enum ab8500_usb_link_status {struct ab8500_usb {struct usb_phy phy;struct device *dev; -int irq_num_id_rise; -int irq_num_id_fall; -int irq_num_vbus_rise; -int irq_num_vbus_fall; +struct ab8500 *ab8500;int irq_num_link_status;unsigned vbus_draw;struct delayed_work dwork;struct work_struct phy_dis_work;unsigned long link_status_wait; -int rev; };static inline struct ab8500_usb *phy_to_ab (struct usb_phy *x)
@@ -102,10 +96,7 @@ static void ab8500_usb_wd_workaround(struct ab8500_usb *ab) (AB8500_BIT_WD_CTRL_ENABLE | AB8500_BIT_WD_CTRL_KICK)); -if (ab->rev >0x10 )/* v1.1 v2.0 */ -udelay (AB8500_WD_V11_DISABLE_DELAY_US ); -else /* v1.0 */ -msleep (AB8500_WD_V10_DISABLE_DELAY_MS ); +udelay (AB8500_WD_V11_DISABLE_DELAY_US ); abx500_set_register_interruptible(ab->dev, AB8500_SYS_CTRL2_BLOCK,
@@ -225,29 +216,6 @@ static void ab8500_usb_delayed_work(struct work_struct *work)ab8500_usb_link_status_update (ab); } -static irqreturn_t ab8500_usb_v1x_common_irq (int irq,void *data) -{ -struct ab8500_usb *ab = (struct ab8500_usb *) data; - -/* Wait for link status to become stable. */ -schedule_delayed_work (&ab->dwork, ab->link_status_wait); - -return IRQ_HANDLED ; -} - -static irqreturn_t ab8500_usb_v1x_vbus_fall_irq (int irq,void *data) -{ -struct ab8500_usb *ab = (struct ab8500_usb *) data; - -/* Link status will not be updated till phy is disabled. */ -ab8500_usb_peri_phy_dis (ab); - -/* Wait for link status to become stable. */ -schedule_delayed_work (&ab->dwork, ab->link_status_wait); - -return IRQ_HANDLED ; -} -static irqreturn_t ab8500_usb_v20_irq (int irq,void *data) {struct ab8500_usb *ab = (struct ab8500_usb *) data;
@@ -361,86 +329,7 @@ static int ab8500_usb_set_host(struct usb_otg *otg, struct usb_bus *host)static void ab8500_usb_irq_free (struct ab8500_usb *ab) { -if (ab->rev <0x20 ) { -free_irq (ab->irq_num_id_rise, ab); -free_irq (ab->irq_num_id_fall, ab); -free_irq (ab->irq_num_vbus_rise, ab); -free_irq (ab->irq_num_vbus_fall, ab); - }else { -free_irq (ab->irq_num_link_status, ab); - } -} - -static int ab8500_usb_v1x_res_setup (struct platform_device *pdev, -struct ab8500_usb *ab) -{ -int err; - - ab->irq_num_id_rise =platform_get_irq_byname (pdev,"ID_WAKEUP_R" ); -if (ab->irq_num_id_rise <0 ) { -dev_err (&pdev->dev,"ID rise irq not found\n" ); -return ab->irq_num_id_rise; - } - err =request_threaded_irq (ab->irq_num_id_rise,NULL , - ab8500_usb_v1x_common_irq, -IRQF_NO_SUSPEND |IRQF_SHARED , -"usb-id-rise" , ab); -if (err <0 ) { -dev_err (ab->dev,"request_irq failed for ID rise irq\n" ); - goto fail0; - } - - ab->irq_num_id_fall =platform_get_irq_byname (pdev,"ID_WAKEUP_F" ); -if (ab->irq_num_id_fall <0 ) { -dev_err (&pdev->dev,"ID fall irq not found\n" ); -return ab->irq_num_id_fall; - } - err =request_threaded_irq (ab->irq_num_id_fall,NULL , - ab8500_usb_v1x_common_irq, -IRQF_NO_SUSPEND |IRQF_SHARED , -"usb-id-fall" , ab); -if (err <0 ) { -dev_err (ab->dev,"request_irq failed for ID fall irq\n" ); - goto fail1; - } - - ab->irq_num_vbus_rise =platform_get_irq_byname (pdev,"VBUS_DET_R" ); -if (ab->irq_num_vbus_rise <0 ) { -dev_err (&pdev->dev,"VBUS rise irq not found\n" ); -return ab->irq_num_vbus_rise; - } - err =request_threaded_irq (ab->irq_num_vbus_rise,NULL , - ab8500_usb_v1x_common_irq, -IRQF_NO_SUSPEND |IRQF_SHARED , -"usb-vbus-rise" , ab); -if (err <0 ) { -dev_err (ab->dev,"request_irq failed for Vbus rise irq\n" ); - goto fail2; - } - - ab->irq_num_vbus_fall =platform_get_irq_byname (pdev,"VBUS_DET_F" ); -if (ab->irq_num_vbus_fall <0 ) { -dev_err (&pdev->dev,"VBUS fall irq not found\n" ); -return ab->irq_num_vbus_fall; - } - err =request_threaded_irq (ab->irq_num_vbus_fall,NULL , - ab8500_usb_v1x_vbus_fall_irq, -IRQF_NO_SUSPEND |IRQF_SHARED , -"usb-vbus-fall" , ab); -if (err <0 ) { -dev_err (ab->dev,"request_irq failed for Vbus fall irq\n" ); - goto fail3; - } - -return 0 ; -fail3: -free_irq (ab->irq_num_vbus_rise, ab); -fail2: -free_irq (ab->irq_num_id_fall, ab); -fail1: -free_irq (ab->irq_num_id_rise, ab); -fail0: -return err; +free_irq (ab->irq_num_link_status, ab); } static int ab8500_usb_v2_res_setup(struct platform_device *pdev,
@@ -471,16 +360,16 @@ static int ab8500_usb_v2_res_setup(struct platform_device *pdev,static int ab8500_usb_probe (struct platform_device *pdev) {struct ab8500_usb *ab; +struct ab8500 *ab8500;struct usb_otg *otg;int err;int rev; + ab8500 =dev_get_drvdata (pdev->dev.parent); rev =abx500_get_chip_id (&pdev->dev); -if (rev <0 ) { -dev_err (&pdev->dev,"Chip id read failed\n" ); -return rev; - }else if (rev <0x10 ) { -dev_err (&pdev->dev,"Unsupported AB8500 chip\n" ); + +if (is_ab8500_1p1_or_earlier (ab8500)) { +dev_err (&pdev->dev,"Unsupported AB8500 chip rev=%d\n" , rev);return -ENODEV ; }
@@ -495,7 +384,7 @@ static int ab8500_usb_probe(struct platform_device *pdev) } ab->dev = &pdev->dev; - ab->rev = rev; + ab->ab8500 = ab8500; ab->phy.dev = ab->dev; ab->phy.otg = otg; ab->phy.label ="ab8500" ;
@@ -519,13 +408,7 @@ static int ab8500_usb_probe(struct platform_device *pdev)/* all: Disable phy when called from set_host and set_peripheral */ INIT_WORK (&ab->phy_dis_work, ab8500_usb_phy_disable_work); -if (ab->rev <0x20 ) { - err =ab8500_usb_v1x_res_setup (pdev, ab); - ab->link_status_wait = AB8500_V1x_LINK_STAT_WAIT; - }else { - err =ab8500_usb_v2_res_setup (pdev, ab); - } - + err =ab8500_usb_v2_res_setup (pdev, ab);if (err <0 ) goto fail0;
@@ -535,7 +418,7 @@ static int ab8500_usb_probe(struct platform_device *pdev) goto fail1; } -dev_info (&pdev->dev,"AB8500 usb driver initialized\n" ); +dev_info (&pdev->dev,"revision 0x%2x driver initialized\n" , rev);return 0 ; fail1:
Signature · 1 line
1.8.1.3
PATCH v2 5/5 usb: otg: ab8500-usb: update irq handling code
In reply to Fabio BaltieriUpdate irq handling code to notify all possible link status changes of AB8500 and AB8505 to the ux500-musb glue driver. The additional event codes will be used for pm-runtime implementation, and are defined in a separate ux500-specific header.
This also modify the irq registration code to use devm_* helpers and drop all non necessary fail path code.
--- drivers/usb/musb/ux500.c | 7 +- drivers/usb/otg/ab8500-usb.c | 440 ++++++++++++++++++++++++++++++++--------- include/linux/usb/musb-ux500.h | 31 +++ 3 files changed, 382 insertions(+), 96 deletions(-) create mode 100644 include/linux/usb/musb-ux500.h
drivers/usb/musb/ux500.c +4 -3
@@ -26,6 +26,7 @@#include <linux/err.h> #include <linux/io.h> #include <linux/platform_device.h> +#include <linux/usb/musb-ux500.h> #include "musb_core.h"
@@ -107,15 +108,15 @@ static int musb_otg_notifications(struct notifier_block *nb, event, otg_state_string(musb->xceiv->state));switch (event) { -case USB_EVENT_ID : +case UX500_MUSB_ID :dev_dbg (musb->controller,"ID GND\n" );ux500_musb_set_vbus (musb,1 );break ; -case USB_EVENT_VBUS : +case UX500_MUSB_VBUS :dev_dbg (musb->controller,"VBUS Connect\n" );ux500_musb_set_vbus (musb,0 );break ; -case USB_EVENT_NONE : +case UX500_MUSB_NONE :dev_dbg (musb->controller,"VBUS Disconnect\n" );if (is_host_active (musb))ux500_musb_set_vbus (musb,0 );
drivers/usb/otg/ab8500-usb.c +347 -93
557 lines not on this page · raw message
include/linux/usb/musb-ux500.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* Copyright (C) 2013 ST-Ericsson AB +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef __MUSB_UX500_H__ +#define __MUSB_UX500_H__ + +enum ux500_musb_vbus_id_status { +UX500_MUSB_NONE =0 , +UX500_MUSB_VBUS , +UX500_MUSB_ID , +UX500_MUSB_CHARGER , +UX500_MUSB_ENUMERATED , +UX500_MUSB_RIDA , +UX500_MUSB_RIDB , +UX500_MUSB_RIDC , +UX500_MUSB_PREPARE , +UX500_MUSB_CLEAN , +}; + +#endif /* __MUSB_UX500_H__ */
Signature · 1 line
1.8.1.3