From patchwork Fri Jun 24 15:14:03 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sonasath, Moiz" X-Patchwork-Id: 916752 X-Patchwork-Delegate: me@felipebalbi.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p5OFGrvJ002172 for ; Fri, 24 Jun 2011 15:16:53 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757436Ab1FXPQv (ORCPT ); Fri, 24 Jun 2011 11:16:51 -0400 Received: from comal.ext.ti.com ([198.47.26.152]:35698 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754190Ab1FXPQu (ORCPT ); Fri, 24 Jun 2011 11:16:50 -0400 Received: from dlep33.itg.ti.com ([157.170.170.112]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id p5OFGj4m008854 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 24 Jun 2011 10:16:45 -0500 Received: from dlep26.itg.ti.com (smtp-le.itg.ti.com [157.170.170.27]) by dlep33.itg.ti.com (8.13.7/8.13.8) with ESMTP id p5OFGjOd028620; Fri, 24 Jun 2011 10:16:45 -0500 (CDT) Received: from dlee74.ent.ti.com (localhost [127.0.0.1]) by dlep26.itg.ti.com (8.13.8/8.13.8) with ESMTP id p5OFGjEn006864; Fri, 24 Jun 2011 10:16:45 -0500 (CDT) Received: from dlelxv24.itg.ti.com (172.17.1.199) by dlee74.ent.ti.com (157.170.170.8) with Microsoft SMTP Server id 8.3.106.1; Fri, 24 Jun 2011 10:16:45 -0500 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dlelxv24.itg.ti.com (8.13.8/8.13.8) with ESMTP id p5OFGivU028969; Fri, 24 Jun 2011 10:16:44 -0500 Received: from lina0132712 (lina0132712.am.dhcp.ti.com [128.247.78.215]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id p5OFGif18732; Fri, 24 Jun 2011 10:16:44 -0500 (CDT) Received: by lina0132712 (Postfix, from userid 1000) id E99E53005E6; Fri, 24 Jun 2011 10:14:03 -0500 (CDT) From: Moiz Sonasath To: CC: linux-omap@vger.kernel.org, balbi@ti.com, gregkh@suse.de, Moiz Sonasath Subject: [PATCH] USB: OTG: Use work_queue in set_vbus for TWL6030 transciever Date: Fri, 24 Jun 2011 10:14:03 -0500 Message-ID: <1308928443-15352-1-git-send-email-m-sonasath@ti.com> X-Mailer: git-send-email 1.6.0.4 MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Fri, 24 Jun 2011 15:16:53 +0000 (UTC) From: Moiz Sonasath With this commit: cccad6d4b103e53fb3d1fc1467f654ecb572d047 usb: otg: notifier: switch to atomic notifier Following dumps are observed on attach/detach for MUSB HOST mode and on a detach for MUSB Device mode. BUG: sleeping function called from invalid context at kernel/mutex.c:85 where, the source is: twl6030_usb_irq ->atomic_notifier_call_chain ->musb_otg_notifications ->twl6030_set_vbus ->twl_i2c_write_u8 ->mutex_lock This patch moves the i2c writes in set_vbus function to a work-queue thereby avoiding I2C writes in atomic context. Tested HOST and Device mode functionality on OMAP4460 Signed-off-by: Moiz Sonasath --- drivers/usb/otg/twl6030-usb.c | 33 +++++++++++++++++++++++++++------ 1 files changed, 27 insertions(+), 6 deletions(-) diff --git a/drivers/usb/otg/twl6030-usb.c b/drivers/usb/otg/twl6030-usb.c index cfb5aa7..857de79 100644 --- a/drivers/usb/otg/twl6030-usb.c +++ b/drivers/usb/otg/twl6030-usb.c @@ -95,11 +95,15 @@ struct twl6030_usb { struct regulator *usb3v3; + /* used to set vbus, in atomic path */ + struct work_struct set_vbus_work; + int irq1; int irq2; u8 linkstat; u8 asleep; bool irq_enabled; + bool vbus_enable; unsigned long features; }; @@ -370,20 +374,35 @@ static int twl6030_enable_irq(struct otg_transceiver *x) return 0; } +static void otg_set_vbus_work(struct work_struct *data) +{ + struct twl6030_usb *twl = container_of(data, struct twl6030_usb, + set_vbus_work); + + if (twl->vbus_enable) + twl6030_writeb(twl, TWL_MODULE_MAIN_CHARGE , 0x40, + CHARGERUSB_CTRL1); + else + twl6030_writeb(twl, TWL_MODULE_MAIN_CHARGE , 0x00, + CHARGERUSB_CTRL1); +} + static int twl6030_set_vbus(struct otg_transceiver *x, bool enabled) { struct twl6030_usb *twl = xceiv_to_twl(x); + if (enabled) + twl->vbus_enable = 1; + else + twl->vbus_enable = 0; + /* * Start driving VBUS. Set OPA_MODE bit in CHARGERUSB_CTRL1 * register. This enables boost mode. */ - if (enabled) - twl6030_writeb(twl, TWL_MODULE_MAIN_CHARGE , 0x40, - CHARGERUSB_CTRL1); - else - twl6030_writeb(twl, TWL_MODULE_MAIN_CHARGE , 0x00, - CHARGERUSB_CTRL1); + + schedule_work(&twl->set_vbus_work); + return 0; } @@ -444,6 +463,8 @@ static int __devinit twl6030_usb_probe(struct platform_device *pdev) ATOMIC_INIT_NOTIFIER_HEAD(&twl->otg.notifier); + INIT_WORK(&twl->set_vbus_work, otg_set_vbus_work); + twl->irq_enabled = true; status = request_threaded_irq(twl->irq1, NULL, twl6030_usbotg_irq, IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,