%s/initlization/initialization

Reply-To: 
In-Reply-To: <1390182980-8349-3-git-send-email-b47...@freescale.com>

On Mon, Jan 20, 2014 at 09:56:13AM +0800, Li Jun wrote:
> This patch adds OTG fsm related initizations when do otg init,
> add a seperate file for OTG fsm related utilities.

%s/initlization/initialization

> 
> Signed-off-by: Li Jun <b47...@freescale.com>
> ---
>  drivers/usb/chipidea/Makefile  |    1 +
>  drivers/usb/chipidea/ci.h      |    1 +
>  drivers/usb/chipidea/otg.c     |    7 ++++
>  drivers/usb/chipidea/otg_fsm.c |   69 
> ++++++++++++++++++++++++++++++++++++++++
>  drivers/usb/chipidea/otg_fsm.h |   29 +++++++++++++++++
>  5 files changed, 107 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile
> index 7345d21..5e1ecc5 100644
> --- a/drivers/usb/chipidea/Makefile
> +++ b/drivers/usb/chipidea/Makefile
> @@ -6,6 +6,7 @@ ci_hdrc-y                             := core.o otg.o
>  ci_hdrc-$(CONFIG_USB_CHIPIDEA_UDC)   += udc.o
>  ci_hdrc-$(CONFIG_USB_CHIPIDEA_HOST)  += host.o
>  ci_hdrc-$(CONFIG_USB_CHIPIDEA_DEBUG) += debug.o
> +ci_hdrc-$(CONFIG_USB_OTG_FSM)                += otg_fsm.o

Let's wait Felipe's response, if we can only use CONFIG_USB_OTG.

>  
>  # Glue/Bridge layers go here
>  
> diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h
> index 88b80f7..54409d0 100644
> --- a/drivers/usb/chipidea/ci.h
> +++ b/drivers/usb/chipidea/ci.h
> @@ -174,6 +174,7 @@ struct ci_hdrc {
>       struct ci_role_driver           *roles[CI_ROLE_END];
>       enum ci_role                    role;
>       bool                            is_otg;
> +     struct otg_fsm                  *fsm;
>       struct work_struct              work;
>       struct workqueue_struct         *wq;
>  
> diff --git a/drivers/usb/chipidea/otg.c b/drivers/usb/chipidea/otg.c
> index 39bd7ec..cbf0167 100644
> --- a/drivers/usb/chipidea/otg.c
> +++ b/drivers/usb/chipidea/otg.c
> @@ -22,6 +22,7 @@
>  #include "ci.h"
>  #include "bits.h"
>  #include "otg.h"
> +#include "otg_fsm.h"
>  
>  /**
>   * ci_otg_role - pick role based on ID pin state
> @@ -95,6 +96,12 @@ static void ci_otg_work(struct work_struct *work)
>   */
>  int ci_hdrc_otg_init(struct ci_hdrc *ci)
>  {
> +     int retval = 0;
> +
> +     retval = ci_hdrc_otg_fsm_init(ci);
> +     if (retval)
> +             return retval;
> +
>       INIT_WORK(&ci->work, ci_otg_work);
>       ci->wq = create_singlethread_workqueue("ci_otg");
>       if (!ci->wq) {
> diff --git a/drivers/usb/chipidea/otg_fsm.c b/drivers/usb/chipidea/otg_fsm.c
> new file mode 100644
> index 0000000..567510a
> --- /dev/null
> +++ b/drivers/usb/chipidea/otg_fsm.c
> @@ -0,0 +1,69 @@
> +/*
> + * otg_fsm.c - ChipIdea USB IP core OTG FSM driver
> + *
> + * Copyright (C) 2014 Freescale Semiconductor, Inc.
> + *
> + * Author: Jun Li
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + */
> +
> +/*
> + * This file mainly handles OTG fsm, it includes OTG fsm operations
> + * for HNP and SRP.
> + */
> +
> +#include <linux/usb/otg.h>
> +#include <linux/usb/gadget.h>
> +#include <linux/usb/chipidea.h>
> +
> +#include "ci.h"
> +#include "bits.h"
> +#include "otg.h"
> +#include "otg_fsm.h"
> +
> +int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci)
> +{
> +     if (ci->platdata->dr_mode != USB_DR_MODE_OTG)
> +             return 0;
> +
> +     ci->transceiver->otg = devm_kzalloc(ci->dev,
> +                     sizeof(struct usb_otg), GFP_KERNEL);
> +     if (!ci->transceiver->otg) {
> +             dev_err(ci->dev,
> +             "Failed to allocate usb_otg structure for ci hdrc otg!\n");
> +             return -ENOMEM;
> +     }
> +
> +     ci->fsm = devm_kzalloc(ci->dev,
> +                     sizeof(struct otg_fsm), GFP_KERNEL);
> +     if (!ci->fsm) {
> +             dev_err(ci->dev,
> +             "Failed to allocate otg_fsm structure for ci hdrc otg!\n");
> +             return -ENOMEM;
> +     }
> +
> +     ci->fsm->power_up = 1;
> +     ci->fsm->id = hw_read(ci, OP_OTGSC, OTGSC_ID);
> +     ci->fsm->otg = ci->transceiver->otg;
> +     ci->fsm->otg->phy = ci->transceiver;
> +     ci->fsm->otg->gadget = &ci->gadget;
> +     ci->transceiver->state = OTG_STATE_UNDEFINED;
> +
> +     mutex_init(&ci->fsm->lock);
> +
> +     /* enable ID and A vbus valid irq */
> +     hw_write(ci, OP_OTGSC, OTGSC_INT_EN_BITS | OTGSC_INT_STATUS_BITS,
> +                                             OTGSC_IDIE | OTGSC_AVVIE);

At comment, you said it only set enable bits, but the code also
clear status bits if they are existed.

The status bits are cleared at: ci_get_otg_capable.
The IDIE is set at: ci_hdrc_probe.
So, it is better you only enable OTGSC_AVVIE since you
said dual-role switch has still worked if the user has
not enabled OTG.

Peter


> +
> +     if (ci->fsm->id) {
> +             ci->fsm->b_ssend_srp =
> +                     hw_read(ci, OP_OTGSC, OTGSC_BSV) ? 0 : 1;
> +             ci->fsm->b_sess_vld =
> +                     hw_read(ci, OP_OTGSC, OTGSC_BSV) ? 1 : 0;
> +     }
> +
> +     return 0;
> +}
> diff --git a/drivers/usb/chipidea/otg_fsm.h b/drivers/usb/chipidea/otg_fsm.h
> new file mode 100644
> index 0000000..bf20a85
> --- /dev/null
> +++ b/drivers/usb/chipidea/otg_fsm.h
> @@ -0,0 +1,29 @@
> +/*
> + * Copyright (C) 2014 Freescale Semiconductor, Inc.
> + *
> + * Author: Jun Li
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + */
> +
> +#ifndef __DRIVERS_USB_CHIPIDEA_OTG_FSM_H
> +#define __DRIVERS_USB_CHIPIDEA_OTG_FSM_H
> +
> +#include <linux/usb/otg-fsm.h>
> +
> +#ifdef CONFIG_USB_OTG_FSM
> +
> +int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci);
> +
> +#else
> +
> +static inline int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci)
> +{
> +     return 0;
> +}
> +
> +#endif
> +
> +#endif /* __DRIVERS_USB_CHIPIDEA_OTG_FSM_H */
> -- 
> 1.7.8
> 
> 

-- 

Best Regards,
Peter Chen

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

Reply via email to