From patchwork Tue Feb 24 03:40:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 5869461 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8AD28BF440 for ; Tue, 24 Feb 2015 03:43:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 99894200B4 for ; Tue, 24 Feb 2015 03:43:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3B3B72064E for ; Tue, 24 Feb 2015 03:42:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752612AbbBXDmf (ORCPT ); Mon, 23 Feb 2015 22:42:35 -0500 Received: from cantor2.suse.de ([195.135.220.15]:60629 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752504AbbBXDmb (ORCPT ); Mon, 23 Feb 2015 22:42:31 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "Cc" Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 72CC8AD32; Tue, 24 Feb 2015 03:42:30 +0000 (UTC) From: NeilBrown To: Tony Lindgren , Felipe Balbi , Kishon Vijay Abraham I Date: Tue, 24 Feb 2015 14:40:37 +1100 Subject: [PATCH 4/4] usb: phy: twl4030: test ID resistance to see if charger is present. Cc: linux-omap@vger.kernel.org, lkml Cc: GTA04 owners Message-ID: <20150224034037.31400.48003.stgit@notabene.brown> In-Reply-To: <20150224033730.31400.78200.stgit@notabene.brown> References: <20150224033730.31400.78200.stgit@notabene.brown> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If an 'A' plug is inserted, ID should be pulled to ground. If a 'B' plug, then ID should be floating. If an Accessory Charger Adapter is inserted, then ID will be neither grounded nor floating. In this case tell the USB subsystem that it is an A plug, and the battery charging subsystem that it is a charger. Fortunately, this will treat the Openmoko charger (and other similar chargers) as a charger. Signed-off-by: NeilBrown Acked-by: Pavel Machek --- drivers/phy/phy-twl4030-usb.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/phy/phy-twl4030-usb.c b/drivers/phy/phy-twl4030-usb.c index 759950898df9..8a43080cdbd7 100644 --- a/drivers/phy/phy-twl4030-usb.c +++ b/drivers/phy/phy-twl4030-usb.c @@ -596,9 +596,31 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl) struct twl4030_usb *twl = _twl; enum omap_musb_vbus_id_status status; bool status_changed = false; + bool found_charger = false; status = twl4030_usb_linkstat(twl); + if (status == OMAP_MUSB_ID_GROUND || + status == OMAP_MUSB_VBUS_VALID) { + /* We should check the resistance on the ID pin. + * If not a Ground or Floating, then this is + * likely a charger + */ + enum twl4030_id_status sts = twl4030_get_id(twl); + if (sts > TWL4030_GROUND && + sts < TWL4030_FLOATING) { + /* + * This might be a charger, or an + * Accessory Charger Adapter. + * In either case we can charge, and it + * makes sense to tell the USB system + * that we might be acting as a HOST. + */ + status = OMAP_MUSB_ID_GROUND; + found_charger = true; + } + } + mutex_lock(&twl->lock); if (status >= 0 && status != twl->linkstat) { status_changed = @@ -627,6 +649,12 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl) } omap_musb_mailbox(status); } + if (found_charger && twl->phy.last_event != USB_EVENT_CHARGER) { + twl->phy.last_event = USB_EVENT_CHARGER; + atomic_notifier_call_chain(&twl->phy.notifier, + USB_EVENT_CHARGER, + NULL); + } /* don't schedule during sleep - irq works right then */ if (status == OMAP_MUSB_ID_GROUND && pm_runtime_active(twl->dev)) {