Re: [PATCH v3 08/13] usb: chipidea: OTG fsm timers initialization.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Mar 06, 2014 at 12:30:40PM +0800, Peter Chen wrote:
> On Thu, Feb 27, 2014 at 07:38:26AM +0800, Li Jun wrote:
> > This patch adds OTG fsm timers initialization, which use controller's 1ms
> > interrupt as timeout counter, also adds some local timers which are not
> > in otg_fsm_timer list.
> > 
> > Signed-off-by: Li Jun <b47624@xxxxxxxxxxxxx>
> > ---
> >  drivers/usb/chipidea/bits.h    |    1 +
> >  drivers/usb/chipidea/otg_fsm.c |  190 ++++++++++++++++++++++++++++++++++++++++
> >  drivers/usb/chipidea/otg_fsm.h |   65 ++++++++++++++
> >  3 files changed, 256 insertions(+)
> > 
> > diff --git a/drivers/usb/chipidea/bits.h b/drivers/usb/chipidea/bits.h
> > index c42eb35..302cde7 100644
> > --- a/drivers/usb/chipidea/bits.h
> > +++ b/drivers/usb/chipidea/bits.h
> > @@ -83,6 +83,7 @@
> >  #define OTGSC_VC	      BIT(1)
> >  #define OTGSC_IDPU	      BIT(5)
> >  #define OTGSC_HADP	      BIT(6)
> > +#define OTGSC_HABA	      BIT(7)
> >  #define OTGSC_ID	      BIT(8)
> >  #define OTGSC_AVV	      BIT(9)
> >  #define OTGSC_ASV	      BIT(10)
> > diff --git a/drivers/usb/chipidea/otg_fsm.c b/drivers/usb/chipidea/otg_fsm.c
> > index aa24466..f9e536b 100644
> > --- a/drivers/usb/chipidea/otg_fsm.c
> > +++ b/drivers/usb/chipidea/otg_fsm.c
> > @@ -25,6 +25,22 @@
> >  #include "otg.h"
> >  #include "otg_fsm.h"
> >  
> > +static struct ci_otg_fsm_timer *otg_timer_initializer
> > +(struct ci_hdrc *ci, void (*function)(void *, unsigned long),
> > +			unsigned long expires, unsigned long data)
> > +{
> > +	struct ci_otg_fsm_timer *timer;
> > +
> > +	timer = devm_kzalloc(ci->dev, sizeof(struct ci_otg_fsm_timer),
> > +								GFP_KERNEL);
> > +	if (!timer)
> > +		return NULL;
> > +	timer->function = function;
> > +	timer->expires = expires;
> > +	timer->data = data;
> > +	return timer;
> > +}
> > +
> >  /* Add timer to active timer list */
> >  static void ci_otg_add_timer(struct ci_hdrc *ci, enum ci_otg_fsm_timer_index t)
> >  {
> > @@ -75,6 +91,163 @@ static void ci_otg_del_timer(struct ci_hdrc *ci, enum ci_otg_fsm_timer_index t)
> >  		ci_disable_otg_interrupt(ci, OTGSC_1MSIE);
> >  }
> >  
> > +/*
> > + * Reduce timer count by 1, and find timeout conditions.
> > + * Called by otg 1ms timer interrupt
> > + */
> > +static int ci_otg_tick_timer(struct ci_hdrc *ci)
> > +{
> > +	struct ci_otg_fsm_timer *tmp_timer, *del_tmp;
> > +	struct list_head *active_timers = &ci->fsm_timer->active_timers;
> > +	int expired = 0;
> > +
> > +	list_for_each_entry_safe(tmp_timer, del_tmp, active_timers, list) {
> > +		tmp_timer->count--;
> > +		/* check if timer expires */
> > +		if (!tmp_timer->count) {
> > +			list_del(&tmp_timer->list);
> > +			tmp_timer->function(ci, tmp_timer->data);
> > +			expired = 1;
> > +		}
> > +	}
> > +
> > +	/* disable 1ms irq if there is no any timer active */
> > +	if ((expired == 1) && list_empty(active_timers))
> > +		ci_disable_otg_interrupt(ci, OTGSC_1MSIE);
> > +
> > +	return expired;
> > +}
> 
> The above function is much like ci_otg_del_timer at your 7th patch,
> is it possible to use the same API?
> 
> > +
> > +/* The timeout callback function to set time out bit */
> > +static void set_tmout(void *ptr, unsigned long indicator)
> > +{
> > +	*(int *)indicator = 1;
> > +}
> > +
> > +static void set_tmout_and_fsm(void *ptr, unsigned long indicator)
> > +{
> > +	struct ci_hdrc *ci = (struct ci_hdrc *)ptr;
> > +
> > +	set_tmout(ci, indicator);
> > +
> > +	/* trans from a_wait_bcon to a_wait_vfall */
> > +	disable_irq_nosync(ci->irq);
> > +	queue_work(ci->wq, &ci->work);
> > +}
> > +
> > +static void b_ssend_srp_tmout_func(void *ptr, unsigned long indicator)
> > +{
> > +	struct ci_hdrc *ci = (struct ci_hdrc *)ptr;
> > +	set_tmout(ci, indicator);
> > +
> > +	/* only vbus fall below B_sess_vld in b_idle state */
> > +	if (ci->transceiver->state == OTG_STATE_B_IDLE) {
> > +		disable_irq_nosync(ci->irq);
> > +		queue_work(ci->wq, &ci->work);
> > +	}
> > +}
> > +
> > +static void b_sess_vld_tmout_func(void *ptr, unsigned long indicator)
> > +{
> > +	struct ci_hdrc *ci = (struct ci_hdrc *)ptr;
> > +
> > +	/* Check if A detached */
> > +	if (!(hw_read(ci, OP_OTGSC, OTGSC_BSV))) {
> > +		ci->fsm->b_sess_vld = 0;
> > +		ci_otg_add_timer(ci, B_SSEND_SRP);
> > +		disable_irq_nosync(ci->irq);
> > +		queue_work(ci->wq, &ci->work);
> > +	}
> > +}
> > +
> > +static void b_data_pulse_end(void *ptr, unsigned long indicator)
> > +{
> > +	struct ci_hdrc *ci = (struct ci_hdrc *)ptr;
> > +
> > +	ci->fsm->b_srp_done = 1;
> > +	ci->fsm->b_bus_req = 0;
> > +	if (ci->fsm->power_up)
> > +		ci->fsm->power_up = 0;
> > +
> > +	hw_write(ci, OP_OTGSC, OTGSC_INT_STATUS_BITS | OTGSC_HABA, 0);
> > +
> > +	disable_irq_nosync(ci->irq);
> > +	queue_work(ci->wq, &ci->work);
> > +}
> > +
> > +/* Initialize timers */
> > +static int ci_otg_init_timers(struct ci_hdrc *ci)
> > +{
> > +	struct otg_fsm *fsm = ci->fsm;
> > +
> > +	/* FSM used timers */
> > +	ci->fsm_timer->timer_list[A_WAIT_VRISE] =
> > +		otg_timer_initializer(ci, &set_tmout, TA_WAIT_VRISE,
> > +			(unsigned long)&fsm->a_wait_vrise_tmout);
> > +	if (ci->fsm_timer->timer_list[A_WAIT_VRISE] == NULL)
> > +		return -ENOMEM;
> > +
> > +	ci->fsm_timer->timer_list[A_WAIT_VFALL] =
> > +		otg_timer_initializer(ci, &set_tmout_and_fsm, TA_WAIT_VFALL,
> > +				(unsigned long)&fsm->a_wait_vfall_tmout);
> > +	if (ci->fsm_timer->timer_list[A_WAIT_VFALL] == NULL)
> > +		return -ENOMEM;
> > +
> > +	ci->fsm_timer->timer_list[A_WAIT_BCON] =
> > +		otg_timer_initializer(ci, &set_tmout_and_fsm, TA_WAIT_BCON,
> > +				(unsigned long)&fsm->a_wait_bcon_tmout);
> > +	if (ci->fsm_timer->timer_list[A_WAIT_BCON] == NULL)
> > +		return -ENOMEM;
> > +
> > +	ci->fsm_timer->timer_list[A_AIDL_BDIS] =
> > +		otg_timer_initializer(ci, &set_tmout_and_fsm, TA_AIDL_BDIS,
> > +				(unsigned long)&fsm->a_aidl_bdis_tmout);
> > +	if (ci->fsm_timer->timer_list[A_AIDL_BDIS] == NULL)
> > +		return -ENOMEM;
> > +
> > +	ci->fsm_timer->timer_list[A_BIDL_ADIS] =
> > +		otg_timer_initializer(ci, &set_tmout_and_fsm, TA_BIDL_ADIS,
> > +				(unsigned long)&fsm->a_bidl_adis_tmout);
> > +	if (ci->fsm_timer->timer_list[A_BIDL_ADIS] == NULL)
> > +		return -ENOMEM;
> > +
> > +	ci->fsm_timer->timer_list[B_ASE0_BRST] =
> > +		otg_timer_initializer(ci, &set_tmout, TB_ASE0_BRST,
> > +			(unsigned long)&fsm->b_ase0_brst_tmout);
> > +	if (ci->fsm_timer->timer_list[B_ASE0_BRST] == NULL)
> > +		return -ENOMEM;
> > +
> > +	ci->fsm_timer->timer_list[B_SE0_SRP] =
> > +		otg_timer_initializer(ci, &set_tmout_and_fsm, TB_SE0_SRP,
> > +					(unsigned long)&fsm->b_se0_srp);
> > +	if (ci->fsm_timer->timer_list[B_SE0_SRP] == NULL)
> > +		return -ENOMEM;
> > +
> > +	ci->fsm_timer->timer_list[B_SSEND_SRP] =
> > +		otg_timer_initializer(ci, &b_ssend_srp_tmout_func, TB_SSEND_SRP,
> > +					(unsigned long)&fsm->b_ssend_srp);
> > +	if (ci->fsm_timer->timer_list[B_SSEND_SRP] == NULL)
> > +		return -ENOMEM;
> > +
> > +	ci->fsm_timer->timer_list[B_SRP_FAIL] =
> > +		otg_timer_initializer(ci, &set_tmout, TB_SRP_FAIL,
> > +				(unsigned long)&fsm->b_srp_done);
> > +	if (ci->fsm_timer->timer_list[B_SRP_FAIL] == NULL)
> > +		return -ENOMEM;
> > +
> > +	ci->fsm_timer->timer_list[B_DATA_PLS] =
> > +		otg_timer_initializer(ci, &b_data_pulse_end, TB_DATA_PLS, 0);
> > +	if (ci->fsm_timer->timer_list[B_DATA_PLS] == NULL)
> > +		return -ENOMEM;
> > +
> > +	ci->fsm_timer->timer_list[B_SESS_VLD] =	otg_timer_initializer(ci,
> > +					&b_sess_vld_tmout_func, TB_SESS_VLD, 0);
> > +	if (ci->fsm_timer->timer_list[B_SESS_VLD] == NULL)
> > +		return -ENOMEM;
> > +
> > +	return 0;

I did not see A_WAIT_ENUM, why?

> > +}
> > +
> >  /* -------------------------------------------------------------*/
> >  /* Operations that will be called from OTG Finite State Machine */
> >  /* -------------------------------------------------------------*/
> > @@ -256,6 +429,8 @@ static struct otg_fsm_ops ci_otg_ops = {
> >  
> >  int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci)
> >  {
> > +	int retval = 0;
> > +
> >  	if (ci->platdata->dr_mode != USB_DR_MODE_OTG)
> >  		return 0;
> >  
> > @@ -285,6 +460,21 @@ int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci)
> >  
> >  	mutex_init(&ci->fsm->lock);
> >  
> > +	ci->fsm_timer = devm_kzalloc(ci->dev,
> > +			sizeof(struct ci_otg_fsm_timer_list), GFP_KERNEL);
> > +	if (!ci->fsm_timer) {
> > +		dev_err(ci->dev,
> > +		"Failed to allocate timer structure for ci hdrc otg!\n");
> > +		return -ENOMEM;
> > +	}
> > +
> > +	INIT_LIST_HEAD(&ci->fsm_timer->active_timers);
> > +	retval = ci_otg_init_timers(ci);
> > +	if (retval) {
> > +		dev_err(ci->dev, "Couldn't init OTG timers\n");
> > +		return retval;
> > +	}
> > +
> >  	/* Enable A vbus valid irq */
> >  	ci_enable_otg_interrupt(ci, OTGSC_AVVIE);
> >  
> > diff --git a/drivers/usb/chipidea/otg_fsm.h b/drivers/usb/chipidea/otg_fsm.h
> > index 1f85ad3..77b604b 100644
> > --- a/drivers/usb/chipidea/otg_fsm.h
> > +++ b/drivers/usb/chipidea/otg_fsm.h
> > @@ -13,6 +13,71 @@
> >  
> >  #include <linux/usb/otg-fsm.h>
> >  
> > +/*
> > + *  A-DEVICE timing  constants
> > + */
> > +
> > +/* Wait for VBUS Rise  */
> > +#define TA_WAIT_VRISE	(100)	/* a_wait_vrise 100 ms, section: 6.6.5.1 */
> > +
> > +/* Wait for VBUS Fall  */
> > +#define TA_WAIT_VFALL   (1000)  /* a_wait_vfall: Used by A device to wait
> > +				 * Vbus to fall below Votg_bus_lkg 7.4.5.2
> > +				 * TSSEND_LKG 1 sec */
> > +/* Wait for B-Connect */
> > +#define TA_WAIT_BCON	(10000)  /* a_wait_bcon > 1 sec, section: 6.6.5.2
> > +				  * This is only used to get out of
> > +				  * OTG_STATE_A_WAIT_BCON state if there was
> > +				  * no connection for these many milliseconds
> > +				  */
> > +
> > +/* A-Idle to B-Disconnect */
> > +/* It is necessary for this timer to be more than 750 ms because of a bug in OPT
> > + * test 5.4 in which B OPT disconnects after 750 ms instead of 75ms as stated
> > + * in the test description
> > + */
> > +#define TA_AIDL_BDIS	(5000)	/* a_suspend minimum 200 ms, section: 6.6.5.3 */
> > +
> > +/* B-Idle to A-Disconnect */
> > +#define TA_BIDL_ADIS	(500)	/* 3 to 200 ms */
> > +
> > +/* B-device timing constants */
> > +
> > +
> > +/* Data-Line Pulse Time*/
> > +#define TB_DATA_PLS	(10)	/* b_srp_init,continue 5~10ms, section:5.3.3 */
> > +#define TB_DATA_PLS_MIN	(5)	/* minimum 5 ms */
> > +#define TB_DATA_PLS_MAX	(10)	/* maximum 10 ms */
> > +
> > +/* SRP Initiate Time  */
> > +#define TB_SRP_INIT	(100)	/* b_srp_init,maximum 100 ms, section:5.3.8 */
> > +
> > +/* SRP Fail Time  */
> > +#define TB_SRP_FAIL	(7000)	/* b_srp_init,Fail time 5~30s, section:6.8.2.2*/
> > +
> > +/* SRP result wait time */
> > +#define TB_SRP_WAIT	(60)
> > +
> > +/* VBus time */
> > +#define TB_VBUS_PLS	(30)	/* time to keep vbus pulsing asserted */
> > +
> > +/* Discharge time */
> > +/* This time should be less than 10ms. It varies from system to system. */
> > +#define TB_VBUS_DSCHRG	(8)
> > +
> > +/* A-SE0 to B-Reset  */
> > +#define TB_ASE0_BRST	(20)	/* b_wait_acon, mini 3.125 ms,section:6.8.2.4 */
> > +
> > +/* A bus suspend timer before we can switch to b_wait_aconn */
> > +#define TB_A_SUSPEND	(7)
> > +#define TB_BUS_RESUME	(12)
> > +
> > +/* SE0 Time Before SRP */
> > +#define TB_SE0_SRP	(2)	/* b_idle,minimum 2 ms, section:5.3.2 */
> > +/* SSEND time before SRP, 1.5 sec min */
> > +#define TB_SSEND_SRP    (1500)  /* Table 5-1, Session end to SRP init */
> > +#define TB_SESS_VLD     (1000)
> > +
> >  enum ci_otg_fsm_timer_index {
> >  	/* CI specific timers, start from the end
> >  	 * of standard and auxiliary OTG timers */
> > -- 
> > 1.7.9.5
> > 
> > 
> 
> I find some definitions and comments are not correct, for example:
> TA_WAIT_BCON is 1.1-30s, and reference section is 5.2.1.
> I am using OTG and EH Revision 2.0 version 1.1a specification.
> 
> -- 
> 
> Best Regards,
> Peter Chen
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> 

-- 

Best Regards,
Peter Chen

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux