From patchwork Thu Feb 17 12:38:42 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 569911 X-Patchwork-Delegate: me@felipebalbi.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p1HCd6DC019540 for ; Thu, 17 Feb 2011 12:39:28 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932065Ab1BQMjP (ORCPT ); Thu, 17 Feb 2011 07:39:15 -0500 Received: from na3sys009aog117.obsmtp.com ([74.125.149.242]:50371 "EHLO na3sys009aog117.obsmtp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756165Ab1BQMjL (ORCPT ); Thu, 17 Feb 2011 07:39:11 -0500 Received: from source ([209.85.214.46]) (using TLSv1) by na3sys009aob117.postini.com ([74.125.148.12]) with SMTP ID DSNKTV0W7oInWDzMmuvZroK3yGmImqNGHd9f@postini.com; Thu, 17 Feb 2011 04:39:11 PST Received: by mail-bw0-f46.google.com with SMTP id 15so1917926bwz.5 for ; Thu, 17 Feb 2011 04:39:10 -0800 (PST) Received: by 10.204.58.196 with SMTP id i4mr1593260bkh.119.1297946350123; Thu, 17 Feb 2011 04:39:10 -0800 (PST) Received: from localhost (cs181221087.pp.htv.fi [82.181.221.87]) by mx.google.com with ESMTPS id z18sm613286bkf.20.2011.02.17.04.39.08 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 17 Feb 2011 04:39:09 -0800 (PST) From: Felipe Balbi To: Greg KH Cc: Linux USB Mailing List , Linux OMAP Mailing List , Hema HK , Tony Lindgren , Paul Walmsley , Felipe Balbi Subject: [patch-v2.6.39 05/12] usb: otg: enable regulator only on cable/device connect Date: Thu, 17 Feb 2011 14:38:42 +0200 Message-Id: <1297946329-9353-6-git-send-email-balbi@ti.com> X-Mailer: git-send-email 1.7.4.rc2 In-Reply-To: <1297946329-9353-1-git-send-email-balbi@ti.com> References: <1297946329-9353-1-git-send-email-balbi@ti.com> Organization: Texas Instruments\n 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 (demeter1.kernel.org [140.211.167.41]); Thu, 17 Feb 2011 12:39:28 +0000 (UTC) diff --git a/drivers/usb/otg/twl6030-usb.c b/drivers/usb/otg/twl6030-usb.c index 28f7701..eca4591 100644 --- a/drivers/usb/otg/twl6030-usb.c +++ b/drivers/usb/otg/twl6030-usb.c @@ -158,8 +158,6 @@ static int twl6030_phy_init(struct otg_transceiver *x) dev = twl->dev; pdata = dev->platform_data; - regulator_enable(twl->usb3v3); - hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS); if (hw_state & STS_USB_ID) @@ -180,7 +178,6 @@ static void twl6030_phy_shutdown(struct otg_transceiver *x) dev = twl->dev; pdata = dev->platform_data; pdata->phy_power(twl->dev, 0, 0); - regulator_disable(twl->usb3v3); } static int twl6030_usb_ldo_init(struct twl6030_usb *twl) @@ -199,16 +196,6 @@ static int twl6030_usb_ldo_init(struct twl6030_usb *twl) if (IS_ERR(twl->usb3v3)) return -ENODEV; - regulator_enable(twl->usb3v3); - - /* Program the VUSB_CFG_TRANS for ACTIVE state. */ - twl6030_writeb(twl, TWL_MODULE_PM_RECEIVER, 0x3F, - VUSB_CFG_TRANS); - - /* Program the VUSB_CFG_STATE register to ON on all groups. */ - twl6030_writeb(twl, TWL_MODULE_PM_RECEIVER, 0xE1, - VUSB_CFG_STATE); - /* Program the USB_VBUS_CTRL_SET and set VBUS_ACT_COMP bit */ twl6030_writeb(twl, TWL_MODULE_USB, 0x4, USB_VBUS_CTRL_SET); @@ -261,16 +248,23 @@ static irqreturn_t twl6030_usb_irq(int irq, void *_twl) CONTROLLER_STAT1); if (!(hw_state & STS_USB_ID)) { if (vbus_state & VBUS_DET) { + regulator_enable(twl->usb3v3); + twl->asleep = 1; status = USB_EVENT_VBUS; twl->otg.default_a = false; twl->otg.state = OTG_STATE_B_IDLE; + twl->linkstat = status; + blocking_notifier_call_chain(&twl->otg.notifier, + status, twl->otg.gadget); } else { status = USB_EVENT_NONE; - } - if (status >= 0) { twl->linkstat = status; blocking_notifier_call_chain(&twl->otg.notifier, status, twl->otg.gadget); + if (twl->asleep) { + regulator_disable(twl->usb3v3); + twl->asleep = 0; + } } } sysfs_notify(&twl->dev->kobj, NULL, "vbus"); @@ -288,6 +282,8 @@ static irqreturn_t twl6030_usbotg_irq(int irq, void *_twl) if (hw_state & STS_USB_ID) { + regulator_enable(twl->usb3v3); + twl->asleep = 1; twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_EN_HI_CLR, 0x1); twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_EN_HI_SET, 0x10); @@ -437,6 +433,7 @@ static int __devinit twl6030_usb_probe(struct platform_device *pdev) return status; } + twl->asleep = 0; pdata->phy_init(dev); twl6030_enable_irq(&twl->otg); dev_info(&pdev->dev, "Initialized TWL6030 USB module\n");