From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752002AbbCSJHF (ORCPT ); Thu, 19 Mar 2015 05:07:05 -0400 Received: from mail-bn1bon0137.outbound.protection.outlook.com ([157.56.111.137]:6528 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751195AbbCSJG7 (ORCPT ); Thu, 19 Mar 2015 05:06:59 -0400 X-Greylist: delayed 1981 seconds by postgrey-1.27 at vger.kernel.org; Thu, 19 Mar 2015 05:06:59 EDT Date: Thu, 19 Mar 2015 16:26:59 +0800 From: Li Jun To: Roger Quadros CC: , , , , , , , , , Subject: Re: [RFC][PATCH 3/9] usb: otg: add OTG core Message-ID: <20150319082656.GA4210@shlinux1.ap.freescale.net> References: <1426686963-11613-1-git-send-email-rogerq@ti.com> <1426686963-11613-4-git-send-email-rogerq@ti.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <1426686963-11613-4-git-send-email-rogerq@ti.com> User-Agent: Mutt/1.5.20 (2009-06-14) X-EOPAttributedMessage: 0 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=b47624@freescale.com; vger.kernel.org; dkim=none (message not signed) header.d=none; X-Forefront-Antispam-Report: CIP:192.88.168.50;CTRY:US;IPV:NLI;EFV:NLI;BMV:1;SFV:NSPM;SFS:(10019020)(6009001)(339900001)(199003)(24454002)(51704005)(189002)(105606002)(77096005)(46406003)(83506001)(85426001)(50986999)(76176999)(54356999)(92566002)(62966003)(77156002)(47776003)(46102003)(2950100001)(23726002)(104016003)(33656002)(6806004)(19580405001)(19580395003)(50466002)(106466001)(110136001)(87936001)(97756001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM2PR0301MB1229;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;MLV:sfv;A:1;MX:1;LANG:en; X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB1229; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5002010)(5005006);SRVR:DM2PR0301MB1229;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB1229; X-Forefront-PRVS: 052017CAF1 X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Mar 2015 08:33:55.4399 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0301MB1229 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 18, 2015 at 03:55:57PM +0200, 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 > --- > +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; > + struct usb_hcd *shared_hcd; /* if shared HCD registered */ > + > + /* 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; > + bool gadget_can_start; /* OTG FSM says gadget can start */ > + bool host_can_start; /* OTG FSM says host can start */ Do not understand above 2 *_can_start flags from the patch, which are set only when you really start host/gadget, to prevent host/gadget driver to start it out of otg fsm control? Li Jun > + > + /* use otg->fsm.lock for serializing access */ > +}; > + > + * Can be called in IRQ context. > + */ > +void usb_otg_sync_inputs(struct otg_fsm *fsm) > +{ > + struct otg_data *otgd = container_of(fsm, struct otg_data, fsm); > + > + /* Don't kick FSM till it has started */ > + if (!otgd->fsm_running) > + return; > + > + /* Kick FSM */ > + queue_work(otgd->wq, &otgd->work); > +} > +EXPORT_SYMBOL_GPL(usb_otg_sync_inputs); > + > +/** > + * usb_otg_kick_fsm - Kick the OTG state machine > + * @hcd_gcd_device: Host/Gadget controller device > + * > + * Used by USB host/device stack to sync OTG related > + * events to the OTG state machine. > + * e.g. change in host_bus->b_hnp_enable, gadget->b_hnp_enable > + * There are quite a few otg fsm variables which should be updated when events/interrupts(b_conn, a_srp_det, ...) occur, how is your plan to update them? Still rely on specific controller driver irq handler to capture all those events and update them? Li Jun > + * Returns: 0 on success, error value otherwise. > + */ > +int usb_otg_kick_fsm(struct device *hcd_gcd_device) > +{ > + struct otg_data *otgd; > + > + mutex_lock(&otg_list_mutex); > + otgd = usb_otg_device_get_otgd(hcd_gcd_device->parent); > + if (!otgd) { > + dev_err(hcd_gcd_device, "%s: invalid host/gadget device\n", > + __func__); > + mutex_unlock(&otg_list_mutex); > + return -ENODEV; > + } > + > + mutex_unlock(&otg_list_mutex); > + usb_otg_sync_inputs(&otgd->fsm); > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(usb_otg_kick_fsm); > -- > 2.1.0 > From mboxrd@z Thu Jan 1 00:00:00 1970 From: Li Jun Subject: Re: [RFC][PATCH 3/9] usb: otg: add OTG core Date: Thu, 19 Mar 2015 16:26:59 +0800 Message-ID: <20150319082656.GA4210@shlinux1.ap.freescale.net> References: <1426686963-11613-1-git-send-email-rogerq@ti.com> <1426686963-11613-4-git-send-email-rogerq@ti.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Return-path: Content-Disposition: inline In-Reply-To: <1426686963-11613-4-git-send-email-rogerq-l0cyMroinI0@public.gmane.org> Sender: linux-usb-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Roger Quadros Cc: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org, balbi-l0cyMroinI0@public.gmane.org, stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org, dan.j.williams-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org, peter.chen-KZfg59tc24xl57MIdRCFDg@public.gmane.org, jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org, mathias.nyman-VuQAYsv1563Yd54FQh9/CA@public.gmane.org, linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-omap-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-Id: linux-omap@vger.kernel.org On Wed, Mar 18, 2015 at 03:55:57PM +0200, 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 > --- > +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; > + struct usb_hcd *shared_hcd; /* if shared HCD registered */ > + > + /* 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; > + bool gadget_can_start; /* OTG FSM says gadget can start */ > + bool host_can_start; /* OTG FSM says host can start */ Do not understand above 2 *_can_start flags from the patch, which are set only when you really start host/gadget, to prevent host/gadget driver to start it out of otg fsm control? Li Jun > + > + /* use otg->fsm.lock for serializing access */ > +}; > + > + * Can be called in IRQ context. > + */ > +void usb_otg_sync_inputs(struct otg_fsm *fsm) > +{ > + struct otg_data *otgd = container_of(fsm, struct otg_data, fsm); > + > + /* Don't kick FSM till it has started */ > + if (!otgd->fsm_running) > + return; > + > + /* Kick FSM */ > + queue_work(otgd->wq, &otgd->work); > +} > +EXPORT_SYMBOL_GPL(usb_otg_sync_inputs); > + > +/** > + * usb_otg_kick_fsm - Kick the OTG state machine > + * @hcd_gcd_device: Host/Gadget controller device > + * > + * Used by USB host/device stack to sync OTG related > + * events to the OTG state machine. > + * e.g. change in host_bus->b_hnp_enable, gadget->b_hnp_enable > + * There are quite a few otg fsm variables which should be updated when events/interrupts(b_conn, a_srp_det, ...) occur, how is your plan to update them? Still rely on specific controller driver irq handler to capture all those events and update them? Li Jun > + * Returns: 0 on success, error value otherwise. > + */ > +int usb_otg_kick_fsm(struct device *hcd_gcd_device) > +{ > + struct otg_data *otgd; > + > + mutex_lock(&otg_list_mutex); > + otgd = usb_otg_device_get_otgd(hcd_gcd_device->parent); > + if (!otgd) { > + dev_err(hcd_gcd_device, "%s: invalid host/gadget device\n", > + __func__); > + mutex_unlock(&otg_list_mutex); > + return -ENODEV; > + } > + > + mutex_unlock(&otg_list_mutex); > + usb_otg_sync_inputs(&otgd->fsm); > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(usb_otg_kick_fsm); > -- > 2.1.0 > -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html