From patchwork Tue Mar 15 08:38:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sanchayan X-Patchwork-Id: 8586301 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6EFB49F54C for ; Tue, 15 Mar 2016 08:54:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 449B22021B for ; Tue, 15 Mar 2016 08:54:33 +0000 (UTC) Received: from bombadil.infradead.org (unknown [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3F790201EF for ; Tue, 15 Mar 2016 08:54:32 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1afkao-0000An-W7; Tue, 15 Mar 2016 08:44:43 +0000 Received: from mail-pf0-x22a.google.com ([2607:f8b0:400e:c00::22a]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1afkad-000057-IX for linux-arm-kernel@lists.infradead.org; Tue, 15 Mar 2016 08:44:32 +0000 Received: by mail-pf0-x22a.google.com with SMTP id 124so20040455pfg.0 for ; Tue, 15 Mar 2016 01:44:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=LZijJywVfUpAurA9qHgMrmkL4RNsCbMwixDnolwMXLU=; b=CVrG+/CfvtpAUMA2eRnhRxT8wvtjgWjjZk/7WI7BJXK3OJxksI9PomkvQ2RgmA51gg kdAsUsYCzgVpikaovQNQvm16oe4Ydjyna/8B25172DiqdmKosVpM599rXamg0adlMiWq XC8qQDs/xn3z6OyGUhnKqHrdCa2Xc0BQ/Q0n3qiXo8xO6vBZ08Dieu9hfQbg3fAl5D4W rGbbdh7T6F7L4FTu74CAeeDuoz/qltJuBdLAX6ic+H3DPWb9FzCDmqfIiJbTwhhjyhcW YlQXatiWDF39IOQCJYPTjrQiULVVINQPuMOSvw/wOl5aw40keUk6Ymny52ua/ozhAWnY vNFg== 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:in-reply-to :references:in-reply-to:references; bh=LZijJywVfUpAurA9qHgMrmkL4RNsCbMwixDnolwMXLU=; b=X6MnPfa6GK5w8wdWVOzlotiPZNapgayHnOevdOyDTUC5Y7Y+8wEZHf8F6SjQxti5dk TXHAlYdavZjoDk6Fbja8gUdcH0JY/ma/5+ljmUgcThHpmUH6hkFnMNX8NXKweTp57UCU Jx0Ho9iERJOqf6vVXJYn3k7d+c3MwYz9QTqaIofeXSHMtE8V3bAstGt2iRpcTsYC8v+z 5kHMj/8FHzhCHNkqq/CwuALPdnpIcXTTV+xnXqJgKHbdvG6bRSO/0nyG9OC7IGU1sQCb 2uWVRDsryxaAM8RdeFKIi7DaqKLLjr+xgtm6g3B2q2rTJKPe+WqEqsxy+b0vdYpfI3Se o4xQ== X-Gm-Message-State: AD7BkJIDNdGwv+uCgB09mtUx2SO1e8VDfZUFPvXDAbLVeFWgw8hmgW8LivIg6RbNDgFRuA== X-Received: by 10.66.140.39 with SMTP id rd7mr44472338pab.92.1458031454778; Tue, 15 Mar 2016 01:44:14 -0700 (PDT) Received: from localhost ([115.115.225.206]) by smtp.gmail.com with ESMTPSA id 82sm37662523pfi.78.2016.03.15.01.44.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Mar 2016 01:44:13 -0700 (PDT) From: Sanchayan Maity To: Peter.Chen@nxp.com Subject: [RFC PATCH 1/4] usb: chipidea: Do not rely on OTG while using extcon Date: Tue, 15 Mar 2016 14:08:27 +0530 Message-Id: X-Mailer: git-send-email 2.7.3 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160315_014431_672774_44923F51 X-CRM114-Status: GOOD ( 16.45 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, stefan@agner.ch, Sanchayan Maity , ivan.ivanov@linaro.org, shawnguo@kernel.org, linux-arm-kernel@lists.infradead.org, marcel@ziswiler.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RDNS_NONE, T_DKIM_INVALID, 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 The existing usage of extcon in Chipidea driver relies on OTG registers. In case of SoC with dual role device but not a true OTG controller, this does not work. Such SoC's should specify the existing CI_HDRC_DUAL_ROLE_NOT_OTG flag and do the role switch without checking any of the OTG registers. This patch almost reverts most of commit "usb: chipidea: Use extcon framework for VBUS and ID detect". We do not rely anymore on emulating an OTG capable controller by faking OTG controller reads. Signed-off-by: Sanchayan Maity --- drivers/usb/chipidea/core.c | 64 ++++++++++++++++++++++++-------------------- drivers/usb/chipidea/otg.c | 39 +-------------------------- include/linux/usb/chipidea.h | 2 -- 3 files changed, 36 insertions(+), 69 deletions(-) diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index 7404064..d29118d 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c @@ -607,14 +607,15 @@ static int ci_vbus_notifier(struct notifier_block *nb, unsigned long event, struct ci_hdrc_cable *vbus = container_of(nb, struct ci_hdrc_cable, nb); struct ci_hdrc *ci = vbus->ci; + pm_runtime_get_sync(ci->dev); + if (event) - vbus->state = true; + usb_gadget_vbus_connect(&ci->gadget); else - vbus->state = false; + usb_gadget_vbus_disconnect(&ci->gadget); - vbus->changed = true; + pm_runtime_put_sync(ci->dev); - ci_irq(ci->irq, ci); return NOTIFY_DONE; } @@ -624,14 +625,19 @@ static int ci_id_notifier(struct notifier_block *nb, unsigned long event, struct ci_hdrc_cable *id = container_of(nb, struct ci_hdrc_cable, nb); struct ci_hdrc *ci = id->ci; - if (event) - id->state = false; - else - id->state = true; + pm_runtime_get_sync(ci->dev); + + ci_role_stop(ci); + + hw_wait_phy_stable(); + + if (ci_role_start(ci, event ? CI_ROLE_HOST : CI_ROLE_GADGET)) + dev_err(ci->dev, + "Can't start %s role\n", + event ? "host" : "gadget"); - id->changed = true; + pm_runtime_put_sync(ci->dev); - ci_irq(ci->irq, ci); return NOTIFY_DONE; } @@ -738,25 +744,10 @@ static int ci_get_platdata(struct device *dev, cable->nb.notifier_call = ci_vbus_notifier; cable->edev = ext_vbus; - if (!IS_ERR(ext_vbus)) { - ret = extcon_get_cable_state_(cable->edev, EXTCON_USB); - if (ret) - cable->state = true; - else - cable->state = false; - } - cable = &platdata->id_extcon; cable->nb.notifier_call = ci_id_notifier; cable->edev = ext_id; - if (!IS_ERR(ext_id)) { - ret = extcon_get_cable_state_(cable->edev, EXTCON_USB_HOST); - if (ret) - cable->state = false; - else - cable->state = true; - } return 0; } @@ -896,6 +887,7 @@ static int ci_hdrc_probe(struct platform_device *pdev) void __iomem *base; int ret; enum usb_dr_mode dr_mode; + struct ci_hdrc_cable *cable; if (!dev_get_platdata(dev)) { dev_err(dev, "platform data missing\n"); @@ -963,6 +955,12 @@ static int ci_hdrc_probe(struct platform_device *pdev) ci_get_otg_capable(ci); + ret = ci_extcon_register(ci); + if (ret) { + dev_err(dev, "extcon registration failed\n"); + goto deinit_phy; + } + dr_mode = ci->platdata->dr_mode; /* initialize role(s) before the interrupt is requested */ if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) { @@ -1003,6 +1001,12 @@ static int ci_hdrc_probe(struct platform_device *pdev) * user can switch it through debugfs. */ ci->role = CI_ROLE_GADGET; + cable = &ci->platdata->id_extcon; + if (!IS_ERR(cable->edev)) { + if (extcon_get_cable_state(cable->edev, + "USB-HOST") == true) + ci->role = CI_ROLE_HOST; + } } } else { ci->role = ci->roles[CI_ROLE_HOST] @@ -1021,6 +1025,12 @@ static int ci_hdrc_probe(struct platform_device *pdev) ci_role(ci)->name); goto stop; } + cable = &ci->platdata->vbus_extcon; + if (!IS_ERR(cable->edev)) { + if ((ci->role == CI_ROLE_GADGET) && + (extcon_get_cable_state(cable->edev, "USB") == true)) + usb_gadget_vbus_connect(&ci->gadget); + } } platform_set_drvdata(pdev, ci); @@ -1029,10 +1039,6 @@ static int ci_hdrc_probe(struct platform_device *pdev) if (ret) goto stop; - ret = ci_extcon_register(ci); - if (ret) - goto stop; - if (ci->supports_runtime_pm) { pm_runtime_set_active(&pdev->dev); pm_runtime_enable(&pdev->dev); diff --git a/drivers/usb/chipidea/otg.c b/drivers/usb/chipidea/otg.c index 45f86da..3169c51 100644 --- a/drivers/usb/chipidea/otg.c +++ b/drivers/usb/chipidea/otg.c @@ -30,44 +30,7 @@ */ u32 hw_read_otgsc(struct ci_hdrc *ci, u32 mask) { - struct ci_hdrc_cable *cable; - u32 val = hw_read(ci, OP_OTGSC, mask); - - /* - * If using extcon framework for VBUS and/or ID signal - * detection overwrite OTGSC register value - */ - cable = &ci->platdata->vbus_extcon; - if (!IS_ERR(cable->edev)) { - if (cable->changed) - val |= OTGSC_BSVIS; - else - val &= ~OTGSC_BSVIS; - - cable->changed = false; - - if (cable->state) - val |= OTGSC_BSV; - else - val &= ~OTGSC_BSV; - } - - cable = &ci->platdata->id_extcon; - if (!IS_ERR(cable->edev)) { - if (cable->changed) - val |= OTGSC_IDIS; - else - val &= ~OTGSC_IDIS; - - cable->changed = false; - - if (cable->state) - val |= OTGSC_ID; - else - val &= ~OTGSC_ID; - } - - return val; + return hw_read(ci, OP_OTGSC, mask); } /** diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h index 5dd75fa..f70ab21 100644 --- a/include/linux/usb/chipidea.h +++ b/include/linux/usb/chipidea.h @@ -20,8 +20,6 @@ struct ci_hdrc; * @conn: used for notification registration */ struct ci_hdrc_cable { - bool state; - bool changed; struct extcon_dev *edev; struct ci_hdrc *ci; struct notifier_block nb;