From patchwork Wed Dec 30 00:55:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chanwoo Choi X-Patchwork-Id: 59068 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp2568519lbb; Tue, 29 Dec 2015 16:56:00 -0800 (PST) X-Received: by 10.98.87.216 with SMTP id i85mr89052944pfj.90.1451436958561; Tue, 29 Dec 2015 16:55:58 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xi10si29050127pab.18.2015.12.29.16.55.58; Tue, 29 Dec 2015 16:55:58 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754095AbbL3Az4 (ORCPT + 6 others); Tue, 29 Dec 2015 19:55:56 -0500 Received: from mailout4.samsung.com ([203.254.224.34]:40472 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753903AbbL3Azx (ORCPT ); Tue, 29 Dec 2015 19:55:53 -0500 Received: from epcpsbgr3.samsung.com (u143.gpu120.samsung.co.kr [203.254.230.143]) by mailout4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O05029WHBX38I60@mailout4.samsung.com>; Wed, 30 Dec 2015 09:55:51 +0900 (KST) Received: from epcpsbgm1new.samsung.com ( [172.20.52.115]) by epcpsbgr3.samsung.com (EPCPMTA) with SMTP id 6B.F3.04964.79B23865; Wed, 30 Dec 2015 09:55:51 +0900 (KST) X-AuditID: cbfee68f-f793a6d000001364-7f-56832b97f0d5 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1new.samsung.com (EPCPMTA) with SMTP id 6B.5E.13906.79B23865; Wed, 30 Dec 2015 09:55:51 +0900 (KST) Received: from chan.10.32.193.11 ([10.113.62.212]) by mmp1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0O05008OGBX3D650@mmp1.samsung.com>; Wed, 30 Dec 2015 09:55:51 +0900 (KST) From: Chanwoo Choi To: tony@atomide.com, robh+dt@kernel.org, lee.jones@linaro.org, balbi@ti.com Cc: rogerq@ti.com, kishon@ti.com, george.cherian@ti.com, cw00.choi@samsung.com, myungjoo.ham@samsung.com, linux-kernel@vger.kernel.org, linux@arm.linux.org.uk, linux-omap@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 1/3] extcon: palmas: Add the support for VBUS detection by using GPIO Date: Wed, 30 Dec 2015 09:55:45 +0900 Message-id: <1451436947-22163-2-git-send-email-cw00.choi@samsung.com> X-Mailer: git-send-email 1.8.0 In-reply-to: <1451436947-22163-1-git-send-email-cw00.choi@samsung.com> References: <1451436947-22163-1-git-send-email-cw00.choi@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupikeLIzCtJLcpLzFFi42JZI2JSrDtduznMYN0SA4uD9+strn95zmox /8g5VotTB5ezWlx42sNmcf/rUUaLTY+vsVpc3jWHzWL2kn4Wi9uXeS1uN65gs2jde4TdoueR lsX+K14OfB4tzT1sHt++TmLx2LSqk83jzrU9bB6bl9R79G1Zxehx/MZ2Jo/Pm+QCOKK4bFJS czLLUov07RK4Mm7dmcFecEehYkV3A2MD4yTpLkZODgkBE4mmtauYIGwxiQv31rN1MXJxCAms YJRYNfcjI0zR5v7XzBCJpYwS89r7WSGcL4wSb1qvg1WxCWhJ7H9xgw3EFhHwkVi/+y5YB7NA E5PE7xWTmEESwgJREktbzoHtYxFQlZg7ZQdYM6+Aq8S59hdQd8hJfNjziB3E5hRwk1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5ilOBgVhLhvcACFOJNSaysSi3Kjy8qzUkt PsRoCnTYRGYp0eR8YBLJK4k3NDYxM7I0Mje0MDI2VxLnrb0UGSYkkJ5YkpqdmlqQWgTTx8TB KdXAGJu5X+B9nwlrdOrUqsJHl2av+rdD8BQbx+uLz3ItJ5vvqE/8z6chaHFtzSs/3cwF0/fY JCR+qFxssS2Mfb1vYc3jaW+ab9ZdL01QPb813M5khcKrr4U7mPfJK0zb43RmrqJQ1Qw5s2tt rzbu27B/+9GuPznzhZ4+lDr5z2D9hpVz/36pr5z8T1WJpTgj0VCLuag4EQB79NSd6gIAAA== DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Felipe Balbi This patch support for VBUS detection by using GPIO pin. Signed-off-by: Felipe Balbi Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-palmas.c | 50 ++++++++++++++++++++++++++++++++++++++++++ include/linux/mfd/palmas.h | 3 +++ 2 files changed, 53 insertions(+) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" 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/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c index 93c30a885740..885ee95a6a7b 100644 --- a/drivers/extcon/extcon-palmas.c +++ b/drivers/extcon/extcon-palmas.c @@ -216,11 +216,23 @@ static int palmas_usb_probe(struct platform_device *pdev) return PTR_ERR(palmas_usb->id_gpiod); } + palmas_usb->vbus_gpiod = devm_gpiod_get_optional(&pdev->dev, "vbus", + GPIOD_IN); + if (IS_ERR(palmas_usb->vbus_gpiod)) { + dev_err(&pdev->dev, "failed to get vbus gpio\n"); + return PTR_ERR(palmas_usb->vbus_gpiod); + } + if (palmas_usb->enable_id_detection && palmas_usb->id_gpiod) { palmas_usb->enable_id_detection = false; palmas_usb->enable_gpio_id_detection = true; } + if (palmas_usb->enable_vbus_detection && palmas_usb->vbus_gpiod) { + palmas_usb->enable_vbus_detection = false; + palmas_usb->enable_gpio_vbus_detection = true; + } + if (palmas_usb->enable_gpio_id_detection) { u32 debounce; @@ -311,6 +323,40 @@ static int palmas_usb_probe(struct platform_device *pdev) palmas_usb->vbus_irq, status); return status; } + } else if (palmas_usb->enable_gpio_vbus_detection) { + /* remux GPIO_1 as VBUSDET */ + status = palmas_update_bits(palmas, + PALMAS_PU_PD_OD_BASE, + PALMAS_PRIMARY_SECONDARY_PAD1, + PALMAS_PRIMARY_SECONDARY_PAD1_GPIO_1_MASK, + (1 << PALMAS_PRIMARY_SECONDARY_PAD1_GPIO_1_SHIFT)); + if (status < 0) { + dev_err(&pdev->dev, "can't remux GPIO1\n"); + return status; + } + + palmas_usb->vbus_otg_irq = regmap_irq_get_virq(palmas->irq_data, + PALMAS_VBUS_OTG_IRQ); + palmas_usb->gpio_vbus_irq = gpiod_to_irq(palmas_usb->vbus_gpiod); + if (palmas_usb->gpio_vbus_irq < 0) { + dev_err(&pdev->dev, "failed to get vbus irq\n"); + return palmas_usb->gpio_vbus_irq; + } + status = devm_request_threaded_irq(&pdev->dev, + palmas_usb->gpio_vbus_irq, + NULL, + palmas_vbus_irq_handler, + IRQF_TRIGGER_FALLING | + IRQF_TRIGGER_RISING | + IRQF_ONESHOT | + IRQF_EARLY_RESUME, + "palmas_usb_vbus", + palmas_usb); + if (status < 0) { + dev_err(&pdev->dev, + "failed to request handler for vbus irq\n"); + return status; + } } palmas_enable_irq(palmas_usb); @@ -337,6 +383,8 @@ static int palmas_usb_suspend(struct device *dev) if (device_may_wakeup(dev)) { if (palmas_usb->enable_vbus_detection) enable_irq_wake(palmas_usb->vbus_irq); + if (palmas_usb->enable_gpio_vbus_detection) + enable_irq_wake(palmas_usb->gpio_vbus_irq); if (palmas_usb->enable_id_detection) enable_irq_wake(palmas_usb->id_irq); if (palmas_usb->enable_gpio_id_detection) @@ -352,6 +400,8 @@ static int palmas_usb_resume(struct device *dev) if (device_may_wakeup(dev)) { if (palmas_usb->enable_vbus_detection) disable_irq_wake(palmas_usb->vbus_irq); + if (palmas_usb->enable_gpio_vbus_detection) + disable_irq_wake(palmas_usb->gpio_vbus_irq); if (palmas_usb->enable_id_detection) disable_irq_wake(palmas_usb->id_irq); if (palmas_usb->enable_gpio_id_detection) diff --git a/include/linux/mfd/palmas.h b/include/linux/mfd/palmas.h index 13e1d96935ed..7b2526f7bc9b 100644 --- a/include/linux/mfd/palmas.h +++ b/include/linux/mfd/palmas.h @@ -553,7 +553,9 @@ struct palmas_usb { int vbus_irq; int gpio_id_irq; + int gpio_vbus_irq; struct gpio_desc *id_gpiod; + struct gpio_desc *vbus_gpiod; unsigned long sw_debounce_jiffies; struct delayed_work wq_detectid; @@ -562,6 +564,7 @@ struct palmas_usb { bool enable_vbus_detection; bool enable_id_detection; bool enable_gpio_id_detection; + bool enable_gpio_vbus_detection; }; #define comparator_to_palmas(x) container_of((x), struct palmas_usb, comparator)