From patchwork Tue Feb 5 08:00:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 2096771 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 40758DF24C for ; Tue, 5 Feb 2013 08:04:34 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1U2dSy-0004cN-Qe; Tue, 05 Feb 2013 08:01:20 +0000 Received: from co9ehsobe003.messaging.microsoft.com ([207.46.163.26] helo=co9outboundpool.messaging.microsoft.com) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1U2dSs-0004Za-TU for linux-arm-kernel@lists.infradead.org; Tue, 05 Feb 2013 08:01:17 +0000 Received: from mail202-co9-R.bigfish.com (10.236.132.235) by CO9EHSOBE041.bigfish.com (10.236.130.104) with Microsoft SMTP Server id 14.1.225.23; Tue, 5 Feb 2013 08:01:08 +0000 Received: from mail202-co9 (localhost [127.0.0.1]) by mail202-co9-R.bigfish.com (Postfix) with ESMTP id D7F7220033A; Tue, 5 Feb 2013 08:01:08 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 0 X-BigFish: VS0(zzzz1ee6h1de0h1202h1e76h1d1ah1d2ahzz8275bhz2dh2a8h668h839hd24he5bhf0ah1288h12a5h12a9h12bdh12e5h1354h137ah139eh13b6h1441h1504h1537h162dh1631h1758h1898h18e1h1946h1155h) Received: from mail202-co9 (localhost.localdomain [127.0.0.1]) by mail202-co9 (MessageSwitch) id 1360051266994566_27950; Tue, 5 Feb 2013 08:01:06 +0000 (UTC) Received: from CO9EHSMHS023.bigfish.com (unknown [10.236.132.226]) by mail202-co9.bigfish.com (Postfix) with ESMTP id E4DB944004A; Tue, 5 Feb 2013 08:01:06 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CO9EHSMHS023.bigfish.com (10.236.130.33) with Microsoft SMTP Server (TLS) id 14.1.225.23; Tue, 5 Feb 2013 08:01:06 +0000 Received: from tx30smr01.am.freescale.net (10.81.153.31) by 039-SN1MMR1-005.039d.mgd.msft.net (10.84.1.17) with Microsoft SMTP Server (TLS) id 14.2.318.3; Tue, 5 Feb 2013 08:01:05 +0000 Received: from localhost.localdomain (nchen-desktop.ap.freescale.net [10.192.242.40]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id r1580G06007412; Tue, 5 Feb 2013 01:00:59 -0700 From: Peter Chen To: Subject: [PATCH v8 4/8] usb: chipidea: consolidate kinds of APIs for both roles Date: Tue, 5 Feb 2013 16:00:11 +0800 Message-ID: <1360051215-27722-5-git-send-email-peter.chen@freescale.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1360051215-27722-1-git-send-email-peter.chen@freescale.com> References: <1360051215-27722-1-git-send-email-peter.chen@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130205_030115_185883_72E93A17 X-CRM114-Status: GOOD ( 18.69 ) X-Spam-Score: -1.2 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [207.46.163.26 listed in list.dnswl.org] 3.0 KHOP_BIG_TO_CC Sent to 10+ recipients instaed of Bcc or a list -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: marex@denx.de, m.grzeschik@pengutronix.de, gregkh@linuxfoundation.org, pkondeti@codeaurora.org, linux-usb@vger.kernel.org, balbi@ti.com, mkl@pengutronix.de, kernel@pengutronix.de, matt@genesi-usa.com, shawn.guo@linaro.org, festevam@gmail.com, linux-arm-kernel@lists.infradead.org, linuxzsc@gmail.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org - Create/destroy the gadget at udc's init and destory function - start/stop API are used at otg id switch and probe routine - Defer some gadget operations at ci's delayed work queue Signed-off-by: Peter Chen diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h index 325d790..3ebe87a 100644 --- a/drivers/usb/chipidea/ci.h +++ b/drivers/usb/chipidea/ci.h @@ -205,7 +205,6 @@ static inline void ci_role_stop(struct ci13xxx *ci) ci->roles[role]->stop(ci); } - /****************************************************************************** * REGISTERS *****************************************************************************/ diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index fbb6984..eacaf9f 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c @@ -360,27 +360,16 @@ static void ci_handle_id_switch(struct ci13xxx *ci) ci_role(ci)->name, ci->roles[role]->name); /* 1. Finish the current role */ - if (ci->role == CI_ROLE_GADGET) { - usb_gadget_vbus_disconnect(&ci->gadget); - /* host doesn't care B_SESSION_VALID event */ - ci_clear_otg_interrupt(ci, OTGSC_BSVIS); - ci_disable_otg_interrupt(ci, OTGSC_BSVIE); - ci->role = CI_ROLE_END; - /* reset controller */ - hw_device_reset(ci, USBMODE_CM_IDLE); - } else if (ci->role == CI_ROLE_HOST) { - ci_role_stop(ci); - /* reset controller */ - hw_device_reset(ci, USBMODE_CM_IDLE); - } + ci_role_stop(ci); + hw_device_reset(ci, USBMODE_CM_IDLE); /* 2. Turn on/off vbus according to coming role */ - if (ci_otg_role(ci) == CI_ROLE_GADGET) { + if (role == CI_ROLE_GADGET) { otg_set_vbus(&ci->otg, false); /* wait vbus lower than OTGSC_BSV */ hw_wait_reg(ci, OP_OTGSC, OTGSC_BSV, 0, CI_VBUS_STABLE_TIMEOUT); - } else if (ci_otg_role(ci) == CI_ROLE_HOST) { + } else if (role == CI_ROLE_HOST) { otg_set_vbus(&ci->otg, true); /* wait vbus higher than OTGSC_AVV */ hw_wait_reg(ci, OP_OTGSC, OTGSC_AVV, OTGSC_AVV, @@ -388,13 +377,7 @@ static void ci_handle_id_switch(struct ci13xxx *ci) } /* 3. Begin the new role */ - if (ci_otg_role(ci) == CI_ROLE_GADGET) { - ci->role = role; - ci_clear_otg_interrupt(ci, OTGSC_BSVIS); - ci_enable_otg_interrupt(ci, OTGSC_BSVIE); - } else if (ci_otg_role(ci) == CI_ROLE_HOST) { - ci_role_start(ci, role); - } + ci_role_start(ci, role); } } @@ -433,8 +416,24 @@ static void ci_delayed_work(struct work_struct *work) struct delayed_work *dwork = to_delayed_work(work); struct ci13xxx *ci = container_of(dwork, struct ci13xxx, dwork); - otg_set_vbus(&ci->otg, true); + if (ci->role == CI_ROLE_GADGET) { + /* + * if it is device mode: + * - Enable vbus detect + * - If it has already connected to host, notify udc + */ + ci_enable_otg_interrupt(ci, OTGSC_BSVIE); + ci_handle_vbus_change(ci); + } else if (ci->is_otg && (ci->role == CI_ROLE_HOST)) { + /* USB Device at the MicroB to A cable */ + otg_set_vbus(&ci->otg, true); + } +} +static inline void ci_role_destroy(struct ci13xxx *ci) +{ + ci_hdrc_gadget_destroy(ci); + ci_hdrc_host_destroy(ci); } static ssize_t show_role(struct device *dev, struct device_attribute *attr, @@ -577,7 +576,6 @@ static int ci_hdrc_probe(struct platform_device *pdev) void __iomem *base; int ret; enum usb_dr_mode dr_mode; - u32 otgsc; if (!dev->platform_data) { dev_err(dev, "platform data missing\n"); @@ -674,18 +672,7 @@ static int ci_hdrc_probe(struct platform_device *pdev) if (ret) { dev_err(dev, "can't start %s role\n", ci_role(ci)->name); ret = -ENODEV; - goto rm_wq; - } - - otgsc = hw_read(ci, OP_OTGSC, ~0); - /* - * if it is device mode: - * - Enable vbus detect - * - If it has already connected to host, notify udc - */ - if (ci->role == CI_ROLE_GADGET) { - ci_enable_otg_interrupt(ci, OTGSC_BSVIE); - ci_handle_vbus_change(ci); + goto free_memory; } platform_set_drvdata(pdev, ci); @@ -696,18 +683,22 @@ static int ci_hdrc_probe(struct platform_device *pdev) ret = device_create_file(dev, &dev_attr_role); if (ret) - goto rm_attr; + goto free_irq; - /* Handle the situation that usb device at the MicroB to A cable */ - if (ci->is_otg && !(otgsc & OTGSC_ID)) - queue_delayed_work(ci->wq, &ci->dwork, msecs_to_jiffies(500)); + /* Defer some operations */ + queue_delayed_work(ci->wq, &ci->dwork, msecs_to_jiffies(200)); return ret; -rm_attr: - device_remove_file(dev, &dev_attr_role); +free_irq: + free_irq(ci->irq, ci); stop: - ci_role_stop(ci); + ci_role_destroy(ci); +free_memory: + if (ci->roles[CI_ROLE_HOST]) + devm_kfree(dev, ci->roles[CI_ROLE_HOST]); + if (ci->roles[CI_ROLE_GADGET]) + devm_kfree(dev, ci->roles[CI_ROLE_GADGET]); rm_wq: flush_workqueue(ci->wq); destroy_workqueue(ci->wq); @@ -723,7 +714,7 @@ static int ci_hdrc_remove(struct platform_device *pdev) destroy_workqueue(ci->wq); device_remove_file(ci->dev, &dev_attr_role); free_irq(ci->irq, ci); - ci_role_stop(ci); + ci_role_destroy(ci); return 0; } diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c index 8e9d312..ead3158 100644 --- a/drivers/usb/chipidea/host.c +++ b/drivers/usb/chipidea/host.c @@ -105,3 +105,9 @@ int ci_hdrc_host_init(struct ci13xxx *ci) return 0; } + +void ci_hdrc_host_destroy(struct ci13xxx *ci) +{ + if (ci->role == CI_ROLE_HOST) + host_stop(ci); +} diff --git a/drivers/usb/chipidea/host.h b/drivers/usb/chipidea/host.h index 761fb1f..5fd03a4 100644 --- a/drivers/usb/chipidea/host.h +++ b/drivers/usb/chipidea/host.h @@ -4,13 +4,15 @@ #ifdef CONFIG_USB_CHIPIDEA_HOST int ci_hdrc_host_init(struct ci13xxx *ci); - +void ci_hdrc_host_destroy(struct ci13xxx *ci); #else static inline int ci_hdrc_host_init(struct ci13xxx *ci) { return -ENXIO; } +static void ci_hdrc_host_destroy(struct ci13xxx *ci) +{} #endif diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index 83e54bb..e82dae4 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c @@ -31,6 +31,7 @@ #include "ci.h" #include "udc.h" +#include "otg.h" #include "bits.h" #include "debug.h" @@ -1743,7 +1744,12 @@ static int udc_start(struct ci13xxx *ci) if (!IS_ERR_OR_NULL(ci->transceiver)) { retval = otg_set_peripheral(ci->transceiver->otg, &ci->gadget); - if (retval) + /* + * If we implement all USB functions using chipidea drivers, + * it doesn't need to call above API, meanwhile, if we only + * use gadget function, calling above API is useless. + */ + if (retval && retval != -ENOTSUPP) goto remove_dbg; } @@ -1780,12 +1786,27 @@ free_qh_pool: return retval; } +static int udc_id_switch_for_device(struct ci13xxx *ci) +{ + ci_clear_otg_interrupt(ci, OTGSC_BSVIS); + ci_enable_otg_interrupt(ci, OTGSC_BSVIE); + + return 0; +} + +static void udc_id_switch_for_host(struct ci13xxx *ci) +{ + /* host doesn't care B_SESSION_VALID event */ + ci_clear_otg_interrupt(ci, OTGSC_BSVIS); + ci_disable_otg_interrupt(ci, OTGSC_BSVIE); +} + /** - * udc_remove: parent remove must call this to remove UDC + * ci_hdrc_gadget_destroy: parent remove must call this to remove UDC * * No interrupts active, the IRQ has been released */ -static void udc_stop(struct ci13xxx *ci) +void ci_hdrc_gadget_destroy(struct ci13xxx *ci) { if (ci == NULL) return; @@ -1804,15 +1825,13 @@ static void udc_stop(struct ci13xxx *ci) } dbg_remove_files(&ci->gadget.dev); device_unregister(&ci->gadget.dev); - /* my kobject is dynamic, I swear! */ - memset(&ci->gadget, 0, sizeof(ci->gadget)); } /** * ci_hdrc_gadget_init - initialize device related bits * ci: the controller * - * This function enables the gadget role, if the device is "device capable". + * This function initializes gadget, if the device is "device capable". */ int ci_hdrc_gadget_init(struct ci13xxx *ci) { @@ -1825,11 +1844,11 @@ int ci_hdrc_gadget_init(struct ci13xxx *ci) if (!rdrv) return -ENOMEM; - rdrv->start = udc_start; - rdrv->stop = udc_stop; + rdrv->start = udc_id_switch_for_device; + rdrv->stop = udc_id_switch_for_host; rdrv->irq = udc_irq; rdrv->name = "gadget"; ci->roles[CI_ROLE_GADGET] = rdrv; - return 0; + return udc_start(ci); } diff --git a/drivers/usb/chipidea/udc.h b/drivers/usb/chipidea/udc.h index 4ff2384..6c42d49 100644 --- a/drivers/usb/chipidea/udc.h +++ b/drivers/usb/chipidea/udc.h @@ -80,6 +80,7 @@ struct ci13xxx_req { #ifdef CONFIG_USB_CHIPIDEA_UDC int ci_hdrc_gadget_init(struct ci13xxx *ci); +void ci_hdrc_gadget_destroy(struct ci13xxx *ci); #else @@ -87,7 +88,8 @@ static inline int ci_hdrc_gadget_init(struct ci13xxx *ci) { return -ENXIO; } - +static void ci_hdrc_gadget_destroy(struct ci13xxx *ci) +{} #endif #endif /* __DRIVERS_USB_CHIPIDEA_UDC_H */