Re: [RFC][PATCH v2 05/13] usb: otg: add OTG core

2015-04-16 Thread Roger Quadros
On 16/04/15 15:02, Peter Chen wrote:
> On Tue, Apr 14, 2015 at 01:41:52PM +0300, Roger Quadros wrote:
>> The OTG core instantiates the OTG Finite State Machine
>> per OTG controller and manages starting/stopping the
>> host and gadget controllers based on the bus state.
>>
>> It provides APIs for the following tasks
>>
>> - Registering an OTG capable controller
>> - Registering Host and Gadget controllers to OTG core
>> - Providing inputs to and kicking the OTG state machine
>>
>> TODO:
>> - sysfs interface to allow application inputs to OTG state machine
>> - otg class?
>>
>> Signed-off-by: Roger Quadros 
>> ---
>>  drivers/usb/Makefile |   1 +
>>  drivers/usb/common/Makefile  |   1 +
>>  drivers/usb/common/usb-otg.c | 743 
>> +++
>>  drivers/usb/common/usb-otg.h |  71 +
>>  drivers/usb/core/Kconfig |   8 +
>>  include/linux/usb/usb-otg.h  |  94 ++
> 
> There is otg.h at include/linux/usb/, why create another usb-otg.h,
> it may confuse the user in future

I can reuse that file.

> 
> If I understand correct, in your plan, both DRD and OTG FSM devices will run
> OTG state machine code, right?

That was my original plan but then I thought it unnecessary to initialize
all those OTG timers if only DRD operation is needed so I've implemented a
very simple DRD state machine. see patch 7.

cheers,
-roger

> 
> Peter
> 
>>  6 files changed, 918 insertions(+)
>>  create mode 100644 drivers/usb/common/usb-otg.c
>>  create mode 100644 drivers/usb/common/usb-otg.h
>>  create mode 100644 include/linux/usb/usb-otg.h
>>
>> diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
>> index 2f1e2aa..07f59a5 100644
>> --- a/drivers/usb/Makefile
>> +++ b/drivers/usb/Makefile
>> @@ -60,5 +60,6 @@ obj-$(CONFIG_USB_RENESAS_USBHS)+= renesas_usbhs/
>>  obj-$(CONFIG_USB_GADGET)+= gadget/
>>  
>>  obj-$(CONFIG_USB_COMMON)+= common/
>> +obj-$(CONFIG_USB_OTG_CORE)  += common/
>>  
>>  obj-$(CONFIG_USBIP_CORE)+= usbip/
>> diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile
>> index ca2f8bd..573fc75 100644
>> --- a/drivers/usb/common/Makefile
>> +++ b/drivers/usb/common/Makefile
>> @@ -7,3 +7,4 @@ usb-common-y   += common.o
>>  usb-common-$(CONFIG_USB_LED_TRIG) += led.o
>>  
>>  obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o
>> +obj-$(CONFIG_USB_OTG_CORE) += usb-otg.o
>> diff --git a/drivers/usb/common/usb-otg.c b/drivers/usb/common/usb-otg.c
>> new file mode 100644
>> index 000..e848e08
>> --- /dev/null
>> +++ b/drivers/usb/common/usb-otg.c
>> @@ -0,0 +1,743 @@
>> +/**
>> + * drivers/usb/common/usb-otg.c - USB OTG core
>> + *
>> + * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
>> + * Author: Roger Quadros 
>> + *
>> + * 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 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.
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include   /* enum usb_otg_state */
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#include "usb-otg.h"
>> +
>> +/* to link timer with callback data */
>> +struct otg_timer {
>> +struct hrtimer timer;
>> +ktime_t timeout;
>> +/* callback data */
>> +int *timeout_bit;
>> +struct otg_data *otgd;
>> +};
>> +
>> +struct otg_hcd {
>> +struct usb_hcd *hcd;
>> +unsigned int irqnum;
>> +unsigned long irqflags;
>> +};
>> +
>> +struct otg_data {
>> +struct device *dev; /* HCD & GCD's parent device */
>> +
>> +struct otg_fsm fsm;
>> +/* HCD, GCD and usb_otg_state are present in otg_fsm->otg
>> + * HCD is bus_to_hcd(fsm->otg->host)
>> + * GCD is fsm->otg->gadget
>> + */
>> +struct otg_fsm_ops fsm_ops; /* private copy for override */
>> +struct usb_otg otg; /* allocator for fsm->otg */
>> +
>> +struct otg_hcd primary_hcd;
>> +struct otg_hcd shared_hcd;
>> +
>> +/* saved hooks to OTG device */
>> +int (*start_host)(struct otg_fsm *fsm, int on);
>> +int (*start_gadget)(struct otg_fsm *fsm, int on);
>> +
>> +struct list_head list;
>> +
>> +struct work_struct work;/* OTG FSM work */
>> +struct workqueue_struct *wq;
>> +
>> +struct otg_timer timers[NUM_OTG_FSM_TIMERS];
>> +
>> +bool fsm_running;
>> +/* use otg->fsm.lock for serializing access */
>> +};
>> +
>> +/* OTG device list */
>> +LIST_HEAD(otg_list);
>> +static DEFINE_MUTEX(otg_list_mutex);
>> +
>> +/**
>> + * check if device is in our OTG list and return
>> + * otg_data, else NULL.
>> + *
>> + * otg_list_mutex must be held.
>> + */
>> +static struct otg_data *usb_otg_de

Re: [RFC][PATCH v2 05/13] usb: otg: add OTG core

2015-04-16 Thread Peter Chen
On Tue, Apr 14, 2015 at 01:41:52PM +0300, Roger Quadros wrote:
> The OTG core instantiates the OTG Finite State Machine
> per OTG controller and manages starting/stopping the
> host and gadget controllers based on the bus state.
> 
> It provides APIs for the following tasks
> 
> - Registering an OTG capable controller
> - Registering Host and Gadget controllers to OTG core
> - Providing inputs to and kicking the OTG state machine
> 
> TODO:
> - sysfs interface to allow application inputs to OTG state machine
> - otg class?
> 
> Signed-off-by: Roger Quadros 
> ---
>  drivers/usb/Makefile |   1 +
>  drivers/usb/common/Makefile  |   1 +
>  drivers/usb/common/usb-otg.c | 743 
> +++
>  drivers/usb/common/usb-otg.h |  71 +
>  drivers/usb/core/Kconfig |   8 +
>  include/linux/usb/usb-otg.h  |  94 ++

There is otg.h at include/linux/usb/, why create another usb-otg.h,
it may confuse the user in future

If I understand correct, in your plan, both DRD and OTG FSM devices will run
OTG state machine code, right?

Peter

>  6 files changed, 918 insertions(+)
>  create mode 100644 drivers/usb/common/usb-otg.c
>  create mode 100644 drivers/usb/common/usb-otg.h
>  create mode 100644 include/linux/usb/usb-otg.h
> 
> diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
> index 2f1e2aa..07f59a5 100644
> --- a/drivers/usb/Makefile
> +++ b/drivers/usb/Makefile
> @@ -60,5 +60,6 @@ obj-$(CONFIG_USB_RENESAS_USBHS) += renesas_usbhs/
>  obj-$(CONFIG_USB_GADGET) += gadget/
>  
>  obj-$(CONFIG_USB_COMMON) += common/
> +obj-$(CONFIG_USB_OTG_CORE)   += common/
>  
>  obj-$(CONFIG_USBIP_CORE) += usbip/
> diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile
> index ca2f8bd..573fc75 100644
> --- a/drivers/usb/common/Makefile
> +++ b/drivers/usb/common/Makefile
> @@ -7,3 +7,4 @@ usb-common-y+= common.o
>  usb-common-$(CONFIG_USB_LED_TRIG) += led.o
>  
>  obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o
> +obj-$(CONFIG_USB_OTG_CORE) += usb-otg.o
> diff --git a/drivers/usb/common/usb-otg.c b/drivers/usb/common/usb-otg.c
> new file mode 100644
> index 000..e848e08
> --- /dev/null
> +++ b/drivers/usb/common/usb-otg.c
> @@ -0,0 +1,743 @@
> +/**
> + * drivers/usb/common/usb-otg.c - USB OTG core
> + *
> + * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
> + * Author: Roger Quadros 
> + *
> + * 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 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.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include/* enum usb_otg_state */
> +#include 
> +#include 
> +#include 
> +
> +#include "usb-otg.h"
> +
> +/* to link timer with callback data */
> +struct otg_timer {
> + struct hrtimer timer;
> + ktime_t timeout;
> + /* callback data */
> + int *timeout_bit;
> + struct otg_data *otgd;
> +};
> +
> +struct otg_hcd {
> + struct usb_hcd *hcd;
> + unsigned int irqnum;
> + unsigned long irqflags;
> +};
> +
> +struct otg_data {
> + struct device *dev; /* HCD & GCD's parent device */
> +
> + struct otg_fsm fsm;
> + /* HCD, GCD and usb_otg_state are present in otg_fsm->otg
> +  * HCD is bus_to_hcd(fsm->otg->host)
> +  * GCD is fsm->otg->gadget
> +  */
> + struct otg_fsm_ops fsm_ops; /* private copy for override */
> + struct usb_otg otg; /* allocator for fsm->otg */
> +
> + struct otg_hcd primary_hcd;
> + struct otg_hcd shared_hcd;
> +
> + /* saved hooks to OTG device */
> + int (*start_host)(struct otg_fsm *fsm, int on);
> + int (*start_gadget)(struct otg_fsm *fsm, int on);
> +
> + struct list_head list;
> +
> + struct work_struct work;/* OTG FSM work */
> + struct workqueue_struct *wq;
> +
> + struct otg_timer timers[NUM_OTG_FSM_TIMERS];
> +
> + bool fsm_running;
> + /* use otg->fsm.lock for serializing access */
> +};
> +
> +/* OTG device list */
> +LIST_HEAD(otg_list);
> +static DEFINE_MUTEX(otg_list_mutex);
> +
> +/**
> + * check if device is in our OTG list and return
> + * otg_data, else NULL.
> + *
> + * otg_list_mutex must be held.
> + */
> +static struct otg_data *usb_otg_device_get_otgd(struct device *parent_dev)
> +{
> + struct otg_data *otgd;
> +
> + list_for_each_entry(otgd, &otg_list, list) {
> + if (otgd->dev == parent_dev)
> + return otgd;
> + }
> +
> + return NULL;
> +}
> +
> +/**
> + * timer callback to set timeout bit and kick FSM
> + */
> +static enum hrtimer_restart set_tmout(struct hrtimer *data)
>

Re: [RFC][PATCH v2 05/13] usb: otg: add OTG core

2015-04-15 Thread Roger Quadros
On 15/04/15 12:29, Paul Bolle wrote:
> (This will go into a minor detail. That's probably not what you want
> when posting an RFC. But this patch got caught by an email filter I use
> and a future, non-RFC, version will get caught too. So I decided to
> bother you with this now.)
> 
> On Tue, 2015-04-14 at 13:41 +0300, Roger Quadros wrote:
>> --- a/drivers/usb/common/Makefile
>> +++ b/drivers/usb/common/Makefile
> 
>> +obj-$(CONFIG_USB_OTG_CORE) += usb-otg.o
> 
> This creates a module usb-otg.ko if CONFIG_USB_OTG_CORE is 'm', built
> from just usb-otg.c.
> 
>> --- /dev/null
>> +++ b/drivers/usb/common/usb-otg.c
> 
>> + * 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 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.
> 
>> +EXPORT_SYMBOL_GPL(usb_otg_register);
> 
>> +EXPORT_SYMBOL_GPL(usb_otg_unregister);
> 
>> +EXPORT_SYMBOL_GPL(usb_otg_sync_inputs);
> 
>> +EXPORT_SYMBOL_GPL(usb_otg_kick_fsm);
> 
>> +EXPORT_SYMBOL_GPL(usb_otg_register_hcd);
> 
>> +EXPORT_SYMBOL_GPL(usb_otg_unregister_hcd);
> 
>> +EXPORT_SYMBOL_GPL(usb_otg_register_gadget);
> 
>> +EXPORT_SYMBOL_GPL(usb_otg_unregister_gadget);
>  
>> +EXPORT_SYMBOL_GPL(usb_otg_fsm_to_dev);
> 
> This code adds no MODULE_LICENSE() macro in this patch and usb-otg.ko
> will carry no license field. So I think the loading of that module
> (triggered by loading another module that uses one of the exported
> symbols, I suppose) taints the kernel. Am I correct?

Right. I will fix this. Thanks.

cheers,
-roger

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


Re: [RFC][PATCH v2 05/13] usb: otg: add OTG core

2015-04-15 Thread Paul Bolle
(This will go into a minor detail. That's probably not what you want
when posting an RFC. But this patch got caught by an email filter I use
and a future, non-RFC, version will get caught too. So I decided to
bother you with this now.)

On Tue, 2015-04-14 at 13:41 +0300, Roger Quadros wrote:
> --- a/drivers/usb/common/Makefile
> +++ b/drivers/usb/common/Makefile

> +obj-$(CONFIG_USB_OTG_CORE) += usb-otg.o

This creates a module usb-otg.ko if CONFIG_USB_OTG_CORE is 'm', built
from just usb-otg.c.

> --- /dev/null
> +++ b/drivers/usb/common/usb-otg.c

> + * 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 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.

> +EXPORT_SYMBOL_GPL(usb_otg_register);

> +EXPORT_SYMBOL_GPL(usb_otg_unregister);

> +EXPORT_SYMBOL_GPL(usb_otg_sync_inputs);

> +EXPORT_SYMBOL_GPL(usb_otg_kick_fsm);

> +EXPORT_SYMBOL_GPL(usb_otg_register_hcd);

> +EXPORT_SYMBOL_GPL(usb_otg_unregister_hcd);

> +EXPORT_SYMBOL_GPL(usb_otg_register_gadget);

> +EXPORT_SYMBOL_GPL(usb_otg_unregister_gadget);
 
> +EXPORT_SYMBOL_GPL(usb_otg_fsm_to_dev);

This code adds no MODULE_LICENSE() macro in this patch and usb-otg.ko
will carry no license field. So I think the loading of that module
(triggered by loading another module that uses one of the exported
symbols, I suppose) taints the kernel. Am I correct?


Paul Bolle

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