From patchwork Sun Mar 17 18:23:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grazvydas Ignotas X-Patchwork-Id: 2284291 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 4DD66E00DD for ; Sun, 17 Mar 2013 18:24:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932774Ab3CQSYE (ORCPT ); Sun, 17 Mar 2013 14:24:04 -0400 Received: from mail-ee0-f48.google.com ([74.125.83.48]:33999 "EHLO mail-ee0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932755Ab3CQSXu (ORCPT ); Sun, 17 Mar 2013 14:23:50 -0400 Received: by mail-ee0-f48.google.com with SMTP id t10so2333184eei.35 for ; Sun, 17 Mar 2013 11:23:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=0mNPSHgnuDD5d1+l36u7FV70bgCzCDPgwEjxcBSZZA4=; b=GSrOzU2BuomaXQ+30Ug37h7+RM/9VQ2TCX9gLTiKL5UEd7QhfprNr52JGnoqmthKdC cF4XAlWg5ZKJfFRafsTTrtTQdsv+w3hZ5WWs4BkPRMP1zXPxChMaYrtiS40Dl+cbeZLo zIvINv6dPfMKX4qTE/5Kq2HmH2LKFw+E3wBD0bK3qzkgc61kik5yOoAUmolmIy80fx/7 6ogumh3WoGPM/8tg4RjKkTzNQlFCJiP0BQy63wovJH2DBRAHcmtrtSmqBSpGxCa8ckjW L/JIRWZ147tCbysZ+1dff3LQMKkQUpjCgEfU9fd3fLUaMiOey7TBRnFCN2ooXOzMa0Mw n4aQ== X-Received: by 10.14.194.198 with SMTP id m46mr25843400een.8.1363544629303; Sun, 17 Mar 2013 11:23:49 -0700 (PDT) Received: from localhost.localdomain (ip-88-119-226-136.static.b4net.lt. [88.119.226.136]) by mx.google.com with ESMTPS id a1sm22724358eep.2.2013.03.17.11.23.47 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 17 Mar 2013 11:23:48 -0700 (PDT) From: Grazvydas Ignotas To: linux-usb@vger.kernel.org Cc: linux-omap@vger.kernel.org, Felipe Balbi , NeilBrown , kishon , Grazvydas Ignotas Subject: [PATCHv2 5/7] usb: phy: twl4030-usb: check if vbus is driven by twl itself Date: Sun, 17 Mar 2013 20:23:25 +0200 Message-Id: <1363544607-17634-6-git-send-email-notasas@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1363544607-17634-1-git-send-email-notasas@gmail.com> References: <1363544607-17634-1-git-send-email-notasas@gmail.com> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org At least on pandora, STS_VBUS gets set even when VBUS is driven by twl itself. Reporting VBUS in this case confuses OMAP musb glue and charger driver, so check if OTG VBUS charge pump is on before reporting VBUS event to avoid this problem. Signed-off-by: Grazvydas Ignotas --- drivers/usb/phy/phy-twl4030-usb.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/drivers/usb/phy/phy-twl4030-usb.c b/drivers/usb/phy/phy-twl4030-usb.c index 425c18a..87bf11d 100644 --- a/drivers/usb/phy/phy-twl4030-usb.c +++ b/drivers/usb/phy/phy-twl4030-usb.c @@ -248,11 +248,31 @@ twl4030_usb_clear_bits(struct twl4030_usb *twl, u8 reg, u8 bits) /*-------------------------------------------------------------------------*/ +static bool twl4030_is_driving_vbus(struct twl4030_usb *twl) +{ + int ret; + + ret = twl4030_usb_read(twl, PHY_CLK_CTRL_STS); + if (ret < 0 || !(ret & PHY_DPLL_CLK)) + /* + * if clocks are off, registers are not updated, + * but we can assume we don't drive VBUS in this case + */ + return false; + + ret = twl4030_usb_read(twl, ULPI_OTG_CTRL); + if (ret < 0) + return false; + + return (ret & (ULPI_OTG_DRVVBUS | ULPI_OTG_CHRGVBUS)) ? true : false; +} + static enum omap_musb_vbus_id_status twl4030_usb_linkstat(struct twl4030_usb *twl) { int status; enum omap_musb_vbus_id_status linkstat = OMAP_MUSB_UNKNOWN; + bool driving_vbus = false; twl->vbus_supplied = false; @@ -270,20 +290,26 @@ static enum omap_musb_vbus_id_status if (status < 0) dev_err(twl->dev, "USB link status err %d\n", status); else if (status & (BIT(7) | BIT(2))) { - if (status & (BIT(7))) - twl->vbus_supplied = true; + if (status & BIT(7)) { + driving_vbus = twl4030_is_driving_vbus(twl); + if (driving_vbus) + status &= ~BIT(7); + } if (status & BIT(2)) linkstat = OMAP_MUSB_ID_GROUND; - else + else if (status & BIT(7)) { linkstat = OMAP_MUSB_VBUS_VALID; + twl->vbus_supplied = true; + } else + linkstat = OMAP_MUSB_VBUS_OFF; } else { if (twl->linkstat != OMAP_MUSB_UNKNOWN) linkstat = OMAP_MUSB_VBUS_OFF; } - dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n", - status, status, linkstat); + dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x; link %d, driving_vbus %d\n", + status, linkstat, driving_vbus); /* REVISIT this assumes host and peripheral controllers * are registered, and that both are active...