From patchwork Wed Jun 8 13:48:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 9164735 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0201B60572 for ; Wed, 8 Jun 2016 13:51:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E66AC25D91 for ; Wed, 8 Jun 2016 13:50:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB6EB2824F; Wed, 8 Jun 2016 13:50:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4043F25D91 for ; Wed, 8 Jun 2016 13:50:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933189AbcFHNur (ORCPT ); Wed, 8 Jun 2016 09:50:47 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:23585 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753189AbcFHNsY (ORCPT ); Wed, 8 Jun 2016 09:48:24 -0400 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O8G00IBXH0MGC70@mailout2.w1.samsung.com>; Wed, 08 Jun 2016 14:48:22 +0100 (BST) X-AuditID: cbfec7f4-f796c6d000001486-99-575822269cea Received: from eusync1.samsung.com ( [203.254.199.211]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 43.8D.05254.62228575; Wed, 8 Jun 2016 14:48:22 +0100 (BST) Received: from AMDC2174.DIGITAL.local ([106.120.53.17]) by eusync1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0O8G00M68H0F9I60@eusync1.samsung.com>; Wed, 08 Jun 2016 14:48:22 +0100 (BST) From: Krzysztof Kozlowski To: MyungJoo Ham , Chanwoo Choi , Rob Herring , Mark Rutland , Kukjin Kim , Krzysztof Kozlowski , Marek Szyprowski , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org Cc: rogerq@ti.com, Peter Chen , "Ivan T. Ivanov" , balbi@ti.com, kishon@ti.com, Bartlomiej Zolnierkiewicz Subject: [RFC v4 4/7] extcon: usb-gpio: Add support for VBUS detection Date: Wed, 08 Jun 2016 15:48:03 +0200 Message-id: <1465393686-16644-5-git-send-email-k.kozlowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1465393686-16644-1-git-send-email-k.kozlowski@samsung.com> References: <1465393686-16644-1-git-send-email-k.kozlowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrILMWRmVeSWpSXmKPExsVy+t/xy7pqShHhBv+vcFpsnLGe1eLg/XqL 61+es1rMP3KO1eLZxIeMFq9fGFr0P37NbHHhaQ+bxabH11gtLu+aw2Yx4/w+Jou1R+6yWyy9 fpHJ4nbjCjaLY7P/Mlm07j3CbtHzSMtB0GPNvDWMHv8O9zN5bFrVyeaxeUm9x6b905g9+ras YvQ4fmM7k8fnTXIBHFFcNimpOZllqUX6dglcGV9PLmUtmGhU8eV3UgPja/UuRk4OCQETiftz 77JB2GISF+6tB7K5OIQEljJKXF3eB+U0Mkmc+dsPVsUmYCyxefkSsISIwCJmieOdPUwgDrPA NkaJG70/mLsYOTiEBdwk1s33BWlgEVCV2H5hIjOIzSvgLnGx4zY7xDo5iZPHJrOC2JwCHhIX ty9jBLGFgGp+f57IMoGRdwEjwypG0dTS5ILipPRcQ73ixNzi0rx0veT83E2MkID+soNx8TGr Q4wCHIxKPLwKhuHhQqyJZcWVuYcYJTiYlUR4dWQiwoV4UxIrq1KL8uOLSnNSiw8xSnOwKInz zt31PkRIID2xJDU7NbUgtQgmy8TBKdXAyH5orfr3C4q3Jr1pDksv3PzZd2ravdlO1hf3bd+1 uFWXuaRnjucOUYvlldc2sTp+0jZrcZjps2y5z07utPoZhmm+wZ901Z7vsSuuu6D/SOL/94qv JjJ9lpGbu36cPnawoiVQw39S7tnfndLK5jqHnmtrvr2lF7T2jX7w2bNrTu04/HaJ8r2HvUos xRmJhlrMRcWJAICJBjZkAgAA Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add VBUS pin detection support to extcon-usb-gpio driver for boards which have both VBUS and ID pins, or only one of them. The logic behind reporting USB and USB-HOST extcon cables is not affected. The driver however will report extcon changes for USB-VBUS and USB-ID. Signed-off-by: Robert Baldyga Signed-off-by: Krzysztof Kozlowski --- Some parts base on old Robert's patchset. --- drivers/extcon/extcon-usb-gpio.c | 125 +++++++++++++++++++++++++++++++-------- 1 file changed, 99 insertions(+), 26 deletions(-) diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c index a36aab007022..85b8a0ce5731 100644 --- a/drivers/extcon/extcon-usb-gpio.c +++ b/drivers/extcon/extcon-usb-gpio.c @@ -35,7 +35,9 @@ struct usb_extcon_info { struct extcon_dev *edev; struct gpio_desc *id_gpiod; + struct gpio_desc *vbus_gpiod; int id_irq; + int vbus_irq; unsigned long debounce_jiffies; struct delayed_work wq_detcable; @@ -44,6 +46,8 @@ struct usb_extcon_info { static const unsigned int usb_extcon_cable[] = { EXTCON_USB, EXTCON_USB_HOST, + EXTCON_USB_ID, + EXTCON_USB_VBUS, EXTCON_NONE, }; @@ -55,7 +59,8 @@ static void usb_extcon_detect_cable(struct work_struct *work) wq_detcable); /* check ID and update cable state */ - id = gpiod_get_value_cansleep(info->id_gpiod); + id = info->id_gpiod ? gpiod_get_value_cansleep(info->id_gpiod) : 1; + if (id) { /* * ID = 1 means USB HOST cable detached. @@ -73,6 +78,14 @@ static void usb_extcon_detect_cable(struct work_struct *work) extcon_set_cable_state_(info->edev, EXTCON_USB, false); extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, true); } + + if (info->id_gpiod) + extcon_set_cable_state_(info->edev, EXTCON_USB_ID, id); + if (info->vbus_gpiod) { + int vbus = gpiod_get_value_cansleep(info->vbus_gpiod); + + extcon_set_cable_state_(info->edev, EXTCON_USB_VBUS, vbus); + } } static irqreturn_t usb_irq_handler(int irq, void *dev_id) @@ -100,9 +113,11 @@ static int usb_extcon_probe(struct platform_device *pdev) return -ENOMEM; info->dev = dev; - info->id_gpiod = devm_gpiod_get(&pdev->dev, "id", GPIOD_IN); - if (IS_ERR(info->id_gpiod)) { - dev_err(dev, "failed to get ID GPIO\n"); + info->id_gpiod = devm_gpiod_get_optional(&pdev->dev, "id", GPIOD_IN); + info->vbus_gpiod = devm_gpiod_get_optional(&pdev->dev, "vbus", + GPIOD_IN); + if (!info->id_gpiod && !info->vbus_gpiod) { + dev_err(dev, "failed to get GPIOs\n"); return PTR_ERR(info->id_gpiod); } @@ -118,27 +133,54 @@ static int usb_extcon_probe(struct platform_device *pdev) return ret; } - ret = gpiod_set_debounce(info->id_gpiod, - USB_GPIO_DEBOUNCE_MS * 1000); + if (info->id_gpiod) + ret = gpiod_set_debounce(info->id_gpiod, + USB_GPIO_DEBOUNCE_MS * 1000); + if (!ret && info->vbus_gpiod) { + ret = gpiod_set_debounce(info->vbus_gpiod, + USB_GPIO_DEBOUNCE_MS * 1000); + if (ret < 0 && info->id_gpiod) + gpiod_set_debounce(info->vbus_gpiod, 0); + } if (ret < 0) info->debounce_jiffies = msecs_to_jiffies(USB_GPIO_DEBOUNCE_MS); INIT_DELAYED_WORK(&info->wq_detcable, usb_extcon_detect_cable); - info->id_irq = gpiod_to_irq(info->id_gpiod); - if (info->id_irq < 0) { - dev_err(dev, "failed to get ID IRQ\n"); - return info->id_irq; + if (info->id_gpiod) { + info->id_irq = gpiod_to_irq(info->id_gpiod); + if (info->id_irq < 0) { + dev_err(dev, "failed to get ID IRQ\n"); + return info->id_irq; + } + ret = devm_request_threaded_irq(dev, info->id_irq, NULL, + usb_irq_handler, + IRQF_TRIGGER_RISING | + IRQF_TRIGGER_FALLING | + IRQF_ONESHOT, + pdev->name, info); + if (ret < 0) { + dev_err(dev, "failed to request handler for ID IRQ\n"); + return ret; + } } - ret = devm_request_threaded_irq(dev, info->id_irq, NULL, - usb_irq_handler, - IRQF_TRIGGER_RISING | - IRQF_TRIGGER_FALLING | IRQF_ONESHOT, - pdev->name, info); - if (ret < 0) { - dev_err(dev, "failed to request handler for ID IRQ\n"); - return ret; + if (info->vbus_gpiod) { + info->vbus_irq = gpiod_to_irq(info->vbus_gpiod); + if (info->vbus_irq < 0) { + dev_err(dev, "failed to get VBUS IRQ\n"); + return info->vbus_irq; + } + ret = devm_request_threaded_irq(dev, info->vbus_irq, NULL, + usb_irq_handler, + IRQF_TRIGGER_RISING | + IRQF_TRIGGER_FALLING | + IRQF_ONESHOT, + pdev->name, info); + if (ret < 0) { + dev_err(dev, "failed to request handler for VBUS IRQ\n"); + return ret; + } } platform_set_drvdata(pdev, info); @@ -166,9 +208,16 @@ static int usb_extcon_suspend(struct device *dev) int ret = 0; if (device_may_wakeup(dev)) { - ret = enable_irq_wake(info->id_irq); - if (ret) - return ret; + if (info->id_gpiod) { + ret = enable_irq_wake(info->id_irq); + if (ret) + return ret; + } + if (info->vbus_gpiod) { + ret = enable_irq_wake(info->vbus_irq); + if (ret) + goto err; + } } /* @@ -176,8 +225,16 @@ static int usb_extcon_suspend(struct device *dev) * as GPIOs used behind I2C subsystem might not be * accessible until resume completes. So disable IRQ. */ - disable_irq(info->id_irq); + if (info->id_gpiod) + disable_irq(info->id_irq); + if (info->vbus_gpiod) + disable_irq(info->vbus_irq); + + return ret; +err: + if (info->id_gpiod) + disable_irq_wake(info->id_irq); return ret; } @@ -187,17 +244,33 @@ static int usb_extcon_resume(struct device *dev) int ret = 0; if (device_may_wakeup(dev)) { - ret = disable_irq_wake(info->id_irq); - if (ret) - return ret; + if (info->id_gpiod) { + ret = disable_irq_wake(info->id_irq); + if (ret) + return ret; + } + if (info->vbus_gpiod) { + ret = disable_irq_wake(info->vbus_irq); + if (ret) + goto err; + } } - enable_irq(info->id_irq); + if (info->id_gpiod) + enable_irq(info->id_irq); + if (info->vbus_gpiod) + enable_irq(info->vbus_irq); + if (!device_may_wakeup(dev)) queue_delayed_work(system_power_efficient_wq, &info->wq_detcable, 0); return ret; + +err: + if (info->id_gpiod) + enable_irq_wake(info->id_irq); + return ret; } #endif