From patchwork Mon Dec 15 22:42:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Shtylyov X-Patchwork-Id: 5498071 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 40C8A9F30B for ; Mon, 15 Dec 2014 22:42:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 43B89209E5 for ; Mon, 15 Dec 2014 22:42:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4E65B209C3 for ; Mon, 15 Dec 2014 22:42:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751034AbaLOWmS (ORCPT ); Mon, 15 Dec 2014 17:42:18 -0500 Received: from mail-lb0-f175.google.com ([209.85.217.175]:60285 "EHLO mail-lb0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750949AbaLOWmR (ORCPT ); Mon, 15 Dec 2014 17:42:17 -0500 Received: by mail-lb0-f175.google.com with SMTP id u10so10145399lbd.34 for ; Mon, 15 Dec 2014 14:42:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:organization :user-agent:mime-version:content-transfer-encoding:content-type; bh=JA6yaTfJl3ylOuS5zgaexB3DtKXvmfbXFmANT81IFiE=; b=N0pnYUoE8YICQX9wbYRx8WxnvoFObFXWpN87ugQIrH6Nyw/Go4P0UddMNQuNzpxi5R j8mkQbXIPoxqI79g5/feIy6UxBki6dxxLsGaF7sgPX6RklARDtKUbhuZZA1qwoOxOX1t iuIuCwrWjyhFFVJgyFqyVViI+Sp27Q2+pObRU0ybKgwFa6IK1v2TKVNqnBQHS0bDJUb9 njkYxmD35xJr1z7nYXZmURW7qw+3/AocMsdMweRwx4be6tPHQnPxj7WaYnr35goQYdWc lWaK2Fjk/l8IYtmitswSeDX4e3eR90OUy2VLPFzW+wlGg5e8irLLJGRHyNK0MOlHMAWD 1JQw== X-Gm-Message-State: ALoCoQlXEy9MGz8OCZFME/omevyRS06KN2tSX/EoDzik5zDX5DU8cGq6VYZ8XkcI3Cw0yBC+Ciz7 X-Received: by 10.152.36.165 with SMTP id r5mr32275053laj.93.1418683336120; Mon, 15 Dec 2014 14:42:16 -0800 (PST) Received: from wasted.cogentembedded.com (ppp24-177.pppoe.mtu-net.ru. [81.195.24.177]) by mx.google.com with ESMTPSA id kw10sm2970579lac.45.2014.12.15.14.42.14 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Dec 2014 14:42:15 -0800 (PST) From: Sergei Shtylyov To: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, balbi@ti.com Cc: linux-sh@vger.kernel.org Subject: [PATCH] renesas_usbhs: add OTG ID signal sensing Date: Tue, 16 Dec 2014 01:42:13 +0300 Message-ID: <7850767.LfC2Jrg0a5@wasted.cogentembedded.com> Organization: Cogent Embedded Inc. User-Agent: KMail/4.14.3 (Linux/3.17.4-200.fc20.x86_64; KDE/4.14.3; x86_64; ; ) MIME-Version: 1.0 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@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=ham 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 On the Renesas R8A7791 SoC based boards there's MAX3355 USB OTG chip and mini-AB USB connector corresponding to USB port 0 driven either by EHCI/OHCI or Renesas USBHS gadget controller. And we'd like the host/gadget drivers to work based on the cable type connected. An 'extcon' driver for MAX3355 has been written, so we only need to bind to it via device tree which I'm doing in this patch. (Perhaps, it would also make sense to use OTG HNP when the USBHS host mode is active and a B-cable is connected but I don't have access to host-capable USBHS, so wouldn't be able to test it.) Signed-off-by: Sergei Shtylyov --- This patch is against the 'next' branch of Felipe Balbi's 'usb.git' repo. It needs the recent 'extcon' core in order to properly handle probe deferral. drivers/usb/renesas_usbhs/common.c | 17 +++++++++++++++++ drivers/usb/renesas_usbhs/common.h | 3 +++ 2 files changed, 20 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: usb/drivers/usb/renesas_usbhs/common.c =================================================================== --- usb.orig/drivers/usb/renesas_usbhs/common.c +++ usb/drivers/usb/renesas_usbhs/common.c @@ -363,6 +363,7 @@ static void usbhsc_hotplug(struct usbhs_ struct usbhs_mod *mod = usbhs_mod_get_current(priv); int id; int enable; + int cable; int ret; /* @@ -376,6 +377,16 @@ static void usbhsc_hotplug(struct usbhs_ id = usbhs_platform_call(priv, get_id, pdev); if (enable && !mod) { + if (priv->edev) { + cable = extcon_get_cable_state(priv->edev, "USB-HOST"); + if ((cable > 0 && id != USBHS_HOST) || + (!cable && id != USBHS_GADGET)) { + dev_info(&pdev->dev, + "USB cable plugged in doesn't match the selected role!\n"); + return; + } + } + ret = usbhs_mod_change(priv, id); if (ret < 0) return; @@ -514,6 +525,12 @@ static int usbhs_probe(struct platform_d if (IS_ERR(priv->base)) return PTR_ERR(priv->base); + if (of_property_read_bool(pdev->dev.of_node, "extcon")) { + priv->edev = extcon_get_edev_by_phandle(&pdev->dev, 0); + if (IS_ERR(priv->edev)) + return PTR_ERR(priv->edev); + } + /* * care platform info */ Index: usb/drivers/usb/renesas_usbhs/common.h =================================================================== --- usb.orig/drivers/usb/renesas_usbhs/common.h +++ usb/drivers/usb/renesas_usbhs/common.h @@ -17,6 +17,7 @@ #ifndef RENESAS_USB_DRIVER_H #define RENESAS_USB_DRIVER_H +#include #include #include @@ -254,6 +255,8 @@ struct usbhs_priv { struct delayed_work notify_hotplug_work; struct platform_device *pdev; + struct extcon_dev *edev; + spinlock_t lock; u32 flags;