From patchwork Fri Nov 20 16:34:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chanwoo Choi X-Patchwork-Id: 7669511 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 85FF2BF90C for ; Fri, 20 Nov 2015 16:37:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7B12920435 for ; Fri, 20 Nov 2015 16:37:05 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [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 659362042C for ; Fri, 20 Nov 2015 16:37:04 +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 1ZzoeT-00011A-TT; Fri, 20 Nov 2015 16:35:09 +0000 Received: from mail-pa0-x236.google.com ([2607:f8b0:400e:c03::236]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZzoeP-0000Li-K0 for linux-arm-kernel@lists.infradead.org; Fri, 20 Nov 2015 16:35:07 +0000 Received: by pacdm15 with SMTP id dm15so121000137pac.3 for ; Fri, 20 Nov 2015 08:34:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-type:content-transfer-encoding; bh=IrkFYtfefxuqFjFAXyIpDoBx86Nh9yVdhnFI5iKmIjY=; b=W+qSw24jaXeIt1hOT7AiBGsJV4+cJvZTAUuC7RA1hnTeZq4xv2etnpZocRYPcrrOKd gyuOtirtFMfs6LJlsjpkK36LcB31imldOz3iXvB8o4bJa/0KBueYW4Y41PomGXpCK7XL sN1v0xgY8eVrAwyTvWZ2IblyXcGolGaom+8AN0//kjoQTAdgFjkKCTdNH/Z6kfi1/ZSb U3xvLBY0wuxoVxBeYJzFlf/XlSjh1QqoMg/urgl0WPM2hxtf9XgLEZpD5MQ5mnjs1Tvm 2SK+WX4O8nd6Da0roGA129m/hcz5Vlm6KB7nGAXQ6Fs0b2f5xViq21FNiDVrfsJq4exW Kyyg== X-Received: by 10.68.218.194 with SMTP id pi2mr20831021pbc.38.1448037284949; Fri, 20 Nov 2015 08:34:44 -0800 (PST) Received: from ChanMacBookPro.local ([59.9.135.113]) by smtp.gmail.com with ESMTPSA id d7sm269787pas.31.2015.11.20.08.34.41 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 20 Nov 2015 08:34:44 -0800 (PST) Subject: Re: [PATCH] extcon: palmas: add support for using VBUSDET output To: Felipe Balbi , Chanwoo Choi , Tony Lindgren , Rob Herring , MyungJoo Ham References: <1447350781-20649-1-git-send-email-balbi@ti.com> <1447351034-21150-1-git-send-email-balbi@ti.com> <564EB0A6.4060407@samsung.com> <564EB332.5090406@samsung.com> <87io4wenz5.fsf@saruman.tx.rr.com> From: Chanwoo Choi Message-ID: <564F4B9F.7000100@gmail.com> Date: Sat, 21 Nov 2015 01:34:39 +0900 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <87io4wenz5.fsf@saruman.tx.rr.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151120_083505_774597_C8B886AB X-CRM114-Status: GOOD ( 24.78 ) X-Spam-Score: -2.5 (--) 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: Linux OMAP Mailing List , Linux Kernel Mailing List , Linux ARM Kernel Mailing List Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 Hi Felipe, On 2015. 11. 20. ?? 11:37, Felipe Balbi wrote: > > Hi Chanwoo, > > Chanwoo Choi writes: >> Hi Felipe, >> >> On 2015? 11? 20? 14:33, Chanwoo Choi wrote: >>> Hi Felipe, >>> >>> Looks good to me. But I have one comment. >>> >>> On 2015? 11? 13? 02:57, Felipe Balbi wrote: >>>> TPS659038 can remux its GPIO_1 as VBUSDET output, >>>> which can be tied to a SoC GPIO and used as a VBUS >>>> interrupt. >>>> >>>> Beagle X15 uses that, in fact, and without it, I >>>> could not get USB peripheral working with that >>>> board. >>>> >>>> Signed-off-by: Felipe Balbi >>>> --- >>>> drivers/extcon/extcon-palmas.c | 22 ++++++++++++++++++++-- >>>> 1 file changed, 20 insertions(+), 2 deletions(-) >>>> >>>> diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c >>>> index 93c30a885740..7985d092c069 100644 >>>> --- a/drivers/extcon/extcon-palmas.c >>>> +++ b/drivers/extcon/extcon-palmas.c >>>> @@ -296,10 +296,28 @@ static int palmas_usb_probe(struct platform_device *pdev) >>>> } >>>> >>>> if (palmas_usb->enable_vbus_detection) { >>>> + int irq = platform_get_irq(pdev, 0); >>>> + >>>> + if (irq > 0) { >>>> + /* 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 << 3)); >>> >>> PALMAS_PRIMARY_SECONDARY_PAD1_GPIO_1_SHIFT is appropriate instead of >>> using '3'. > > good point :-) > >>>> + if (status < 0) { >>>> + dev_err(&pdev->dev, "can't remux GPIO1\n"); >>>> + return status; >>>> + } >>>> + >>>> + palmas_usb->vbus_irq = irq; >>>> + } else { >>>> + irq = regmap_irq_get_virq(palmas->irq_data, >>>> + PALMAS_VBUS_IRQ); >>>> + palmas_usb->vbus_irq = irq; >>>> + } >>>> + >>>> palmas_usb->vbus_otg_irq = regmap_irq_get_virq(palmas->irq_data, >>>> PALMAS_VBUS_OTG_IRQ); >>>> - palmas_usb->vbus_irq = regmap_irq_get_virq(palmas->irq_data, >>>> - PALMAS_VBUS_IRQ); >>>> status = devm_request_threaded_irq(palmas_usb->dev, >>>> palmas_usb->vbus_irq, NULL, >>>> palmas_vbus_irq_handler, >>>> >>> >>> Thanks, >>> Chanwoo Choi >>> -- >>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in >>> the body of a message to majordomo@vger.kernel.org >>> More majordomo info at http://vger.kernel.org/majordomo-info.html >>> Please read the FAQ at http://www.tux.org/lkml/ >>> >> >> If you are OK about following patch, I'll apply it on extcon branch. > > that's perfect, thanks for fixing it :-) > Before applying this patch, I think that there are more generic method? So, I check the extcon-palmas.c driver again. There is similiar case for id detection. In some case, id detection use whether 'enable_id_detection' with own interrupt or 'enable_gpio_id_dectection' with specific h/w gpio like this case of vbus. In result, I implement the following patch for vbus gpio detection. But, I'm not sure because I have not any H/W board for test. If you possible, could you test it with following patch? Thanks, Chanwoo Choi diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c index 93c30a8..885ee95 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 13e1d96..7b2526f 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)