From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Subject: [v5,3/6] usb: ohci-da8xx: disable the regulator if the overcurrent irq fired From: Bartosz Golaszewski Message-Id: <20190412123640.11437-4-brgl@bgdev.pl> Date: Fri, 12 Apr 2019 14:36:37 +0200 To: Sekhar Nori , Kevin Hilman , Alan Stern , Greg Kroah-Hartman Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Bartosz Golaszewski List-ID: RnJvbTogQmFydG9zeiBHb2xhc3pld3NraSA8YmdvbGFzemV3c2tpQGJheWxpYnJlLmNvbT4KCkhp c3RvcmljYWxseSB0aGUgcG93ZXIgc3VwcGx5IG1hbmFnZW1lbnQgaW4gdGhpcyBkcml2ZXIgaGFz IGJlZW4gaGFuZGxlZAppbiB0d28gc2VwYXJhdGUgcGxhY2VzIGluIHBhcmFsbGVsLiBEZXZpY2Ut dHJlZSB1c2VycyBzaW1wbHkgZGVmaW5lZCBhbgphcHByb3ByaWF0ZSByZWd1bGF0b3IsIHdoaWxl IHR3byBib2FyZHMgd2l0aCBubyBEVCBzdXBwb3J0IChkYTgzMC1ldm0gYW5kCm9tYXBsMTM4LWhh d2spIHBhc3NlZCBmdW5jdGlvbnMgZGVmaW5lZCBpbiB0aGVpciByZXNwZWN0aXZlIGJvYXJkIGZp bGVzCm92ZXIgcGxhdGZvcm0gZGF0YS4gVGhlc2UgZnVuY3Rpb25zIHNpbXBseSB1c2VkIGxlZ2Fj eSBHUElPIGNhbGxzIHRvCndhdGNoIHRoZSBvYyBHUElPIGZvciBpbnRlcnJ1cHRzIGFuZCBkaXNh YmxlIHRoZSB2YnVzIEdQSU8gd2hlbiB0aGUgaXJxCmZpcmVzLgoKQ29tbWl0IGQxOTNhYmYxYzkx MyAoInVzYjogb2hjaS1kYTh4eDogYWRkIHZidXMgYW5kIG92ZXJjdXJyZW50IGdwaW9zIikKdXB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ZXQpCisJCQkJZGV2X2Vy cihkZXYsCisJCQkJCSJGYWlsZWQgdG8gZGlzYWJsZSByZWd1bGF0b3I6ICVkXG4iLAorCQkJCQly ZXQpOworCQl9CisJfQogCiAJcmV0dXJuIElSUV9IQU5ETEVEOwogfQpAQCAtNDM0LDggKzQ0NSw5 IEBAIHN0YXRpYyBpbnQgb2hjaV9kYTh4eF9wcm9iZShzdHJ1Y3QgcGxhdGZvcm1fZGV2aWNlICpw ZGV2KQogCQlpZiAob2NfaXJxIDwgMCkKIAkJCWdvdG8gZXJyOwogCi0JCWVycm9yID0gZGV2bV9y ZXF1ZXN0X2lycShkZXYsIG9jX2lycSwgb2hjaV9kYTh4eF9vY19oYW5kbGVyLAotCQkJCUlSUUZf VFJJR0dFUl9SSVNJTkcgfCBJUlFGX1RSSUdHRVJfRkFMTElORywKKwkJZXJyb3IgPSBkZXZtX3Jl cXVlc3RfdGhyZWFkZWRfaXJxKGRldiwgb2NfaXJxLCBOVUxMLAorCQkJCW9oY2lfZGE4eHhfb2Nf dGhyZWFkLCBJUlFGX1RSSUdHRVJfUklTSU5HIHwKKwkJCQlJUlFGX1RSSUdHRVJfRkFMTElORyB8 IElSUUZfT05FU0hPVCwKIAkJCQkiT0hDSSBvdmVyLWN1cnJlbnQgaW5kaWNhdG9yIiwgZGE4eHhf b2hjaSk7CiAJCWlmIChlcnJvcikKIAkJCWdvdG8gZXJyOwo= From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02B04C10F0E for ; Fri, 12 Apr 2019 12:37:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C7FB32082E for ; Fri, 12 Apr 2019 12:37:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="hgQLpCvy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728665AbfDLMhJ (ORCPT ); Fri, 12 Apr 2019 08:37:09 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:36653 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727497AbfDLMgs (ORCPT ); Fri, 12 Apr 2019 08:36:48 -0400 Received: by mail-wm1-f66.google.com with SMTP id h18so10835232wml.1 for ; Fri, 12 Apr 2019 05:36:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OmZNDj/ROqmmydwLVfrSm5YpHHAqTHz5p0ofV4c+h88=; b=hgQLpCvyQWkGA2+C2SVC+yttOyqCs79IPSMazHMDa5D/84A9fokZ/J6nVKCozEc+d/ 1wn1YKFAmx3OMtjLtetWgWH3h9ZRDkowGbxcMxoWdgx9zZlyfS7PvfBY3KKXcM5yHmEU 7Nn65q9oRScO4qvbKi+HN2z5+PmH5mIzDZXfjcIqlul6bL9tdn+zrpu1lTVSgyaebUsI eJV2MjdxrBWTyLiMkQEJEj6FZV2t2One7G5SE/y0sjcstKtjupUgdhryil3RSNKAfRAG xIKrlA0oe450dJNe1BD79oWMG7wzq8gs0XrB130U127+8Gej98UNSFNEeEsGwBjsf652 J6CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OmZNDj/ROqmmydwLVfrSm5YpHHAqTHz5p0ofV4c+h88=; b=XiXnCs5cPmMHR06P0Al1y8yhOA/nOz8JGjOxgeJMGu6uNxSMhMWr/JMC+NF8KoVxVg PrWBg+D+r6I1vuiL7xgvnX/2WmpDhRbKHQ3emgSWZsHHsae1RXAMXgcKgQ3uQES4vilo hderWlj1xBgNIkm2kMKFQnDVRD4YCGCQwczCAlBpxObtsLF20/fEqVZmVymE8GIo7emP eVD1Upqlv/Gzg1C1we81esPgo4P8LDLqjMVc6ISvRlMnv1CXBbPJimzDwRFbOF+mavf5 rHvLoxtP9bYQFOqypdNgDQXwAt6eaMvZglPIpuYpJHbHeYSl3EmgZZFmgHXQwos31n2p POYQ== X-Gm-Message-State: APjAAAWW1+i2cJBkf3u5z6I+ZoaSMgZj5RMebsC9Dg6XkAh9jB+THNC3 FNV5dNozeCaiY8yo33YbKK+7kw== X-Google-Smtp-Source: APXvYqwolTlOkBeqh0vywQsBopUex17ovDjGm26J7GwepQL2sUOHtRZs/QRwZB/kPFkyAVSqQrrnCw== X-Received: by 2002:a1c:7e8a:: with SMTP id z132mr11430786wmc.92.1555072606977; Fri, 12 Apr 2019 05:36:46 -0700 (PDT) Received: from localhost.localdomain (aputeaux-684-1-35-248.w90-86.abo.wanadoo.fr. [90.86.90.248]) by smtp.gmail.com with ESMTPSA id v190sm12384030wme.18.2019.04.12.05.36.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Apr 2019 05:36:46 -0700 (PDT) From: Bartosz Golaszewski To: Sekhar Nori , Kevin Hilman , Alan Stern , Greg Kroah-Hartman Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v5 3/6] usb: ohci-da8xx: disable the regulator if the overcurrent irq fired Date: Fri, 12 Apr 2019 14:36:37 +0200 Message-Id: <20190412123640.11437-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190412123640.11437-1-brgl@bgdev.pl> References: <20190412123640.11437-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Message-ID: <20190412123637.Yeg8m9A6xROmamGfiXNgcwD0Vt8oWnRlqndvHAPwMBc@z> From: Bartosz Golaszewski Historically the power supply management in this driver has been handled in two separate places in parallel. Device-tree users simply defined an appropriate regulator, while two boards with no DT support (da830-evm and omapl138-hawk) passed functions defined in their respective board files over platform data. These functions simply used legacy GPIO calls to watch the oc GPIO for interrupts and disable the vbus GPIO when the irq fires. Commit d193abf1c913 ("usb: ohci-da8xx: add vbus and overcurrent gpios") updated these GPIO calls to the modern API and moved them inside the driver. This however is not the optimal solution for the vbus GPIO which should be modeled as a fixed regulator that can be controlled with a GPIO. In order to keep the overcurrent protection available once we move the board files to using fixed regulators we need to disable the enable_reg regulator when the overcurrent indicator interrupt fires. Since we cannot call regulator_disable() from interrupt context, we need to switch to using a oneshot threaded interrupt. Signed-off-by: Bartosz Golaszewski --- drivers/usb/host/ohci-da8xx.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c index 209a262b5565..f69b339d45e5 100644 --- a/drivers/usb/host/ohci-da8xx.c +++ b/drivers/usb/host/ohci-da8xx.c @@ -202,12 +202,23 @@ static int ohci_da8xx_regulator_event(struct notifier_block *nb, return 0; } -static irqreturn_t ohci_da8xx_oc_handler(int irq, void *data) +static irqreturn_t ohci_da8xx_oc_thread(int irq, void *data) { struct da8xx_ohci_hcd *da8xx_ohci = data; + struct device *dev = da8xx_ohci->hcd->self.controller; + int ret; - if (gpiod_get_value(da8xx_ohci->oc_gpio)) - gpiod_set_value(da8xx_ohci->vbus_gpio, 0); + if (gpiod_get_value_cansleep(da8xx_ohci->oc_gpio)) { + if (da8xx_ohci->vbus_gpio) { + gpiod_set_value_cansleep(da8xx_ohci->vbus_gpio, 0); + } else if (da8xx_ohci->vbus_reg) { + ret = regulator_disable(da8xx_ohci->vbus_reg); + if (ret) + dev_err(dev, + "Failed to disable regulator: %d\n", + ret); + } + } return IRQ_HANDLED; } @@ -434,8 +445,9 @@ static int ohci_da8xx_probe(struct platform_device *pdev) if (oc_irq < 0) goto err; - error = devm_request_irq(dev, oc_irq, ohci_da8xx_oc_handler, - IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, + error = devm_request_threaded_irq(dev, oc_irq, NULL, + ohci_da8xx_oc_thread, IRQF_TRIGGER_RISING | + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, "OHCI over-current indicator", da8xx_ohci); if (error) goto err; -- 2.21.0 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A141C10F0E for ; Fri, 12 Apr 2019 12:37:26 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DBEC02082E for ; Fri, 12 Apr 2019 12:37:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="BoyROxvd"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="hgQLpCvy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DBEC02082E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=t27f5Z0wJoEmnGCNI2bzV3CKt24xE5rZOiP18f+0BYY=; b=BoyROxvdYoBONf ALuGQrfB82qDHkdEzfaRTDYYhVPHpJVqBZjlxhspn/YXbJqcKriZ2a5Dzhie2RJLzUNzTIuvX6djn VvnRe22chaM/ig0X7aq0Wqy08W2xL+XC6csMB5MEuTEBQw8/pQQ40ip6M0R5E00aPFiyAC00NM2ov Zs7Su7rAK8zUwmVctwFiKb3PGMafBgT264t2/F6fDfDpIAWA9r+ALz/YExnRMbCJiTfgrkSxJcHOy 2aMmaifTzvgYXIVne0bESeAZzxTgOU8gN3orLmTONaYFEIeRFexx3aeba/x0rJIgXvw61ZTqkp4Up Ye/8lvtdOgKFBpz89ORw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEvQn-00050i-12; Fri, 12 Apr 2019 12:37:21 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEvQG-0004OK-GA for linux-arm-kernel@lists.infradead.org; Fri, 12 Apr 2019 12:36:51 +0000 Received: by mail-wm1-x341.google.com with SMTP id 4so11039550wmf.1 for ; Fri, 12 Apr 2019 05:36:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OmZNDj/ROqmmydwLVfrSm5YpHHAqTHz5p0ofV4c+h88=; b=hgQLpCvyQWkGA2+C2SVC+yttOyqCs79IPSMazHMDa5D/84A9fokZ/J6nVKCozEc+d/ 1wn1YKFAmx3OMtjLtetWgWH3h9ZRDkowGbxcMxoWdgx9zZlyfS7PvfBY3KKXcM5yHmEU 7Nn65q9oRScO4qvbKi+HN2z5+PmH5mIzDZXfjcIqlul6bL9tdn+zrpu1lTVSgyaebUsI eJV2MjdxrBWTyLiMkQEJEj6FZV2t2One7G5SE/y0sjcstKtjupUgdhryil3RSNKAfRAG xIKrlA0oe450dJNe1BD79oWMG7wzq8gs0XrB130U127+8Gej98UNSFNEeEsGwBjsf652 J6CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OmZNDj/ROqmmydwLVfrSm5YpHHAqTHz5p0ofV4c+h88=; b=PaNbRhm8GazMDox+3KkdOgoe98iblFlhZWwMnwAUPwJZXCE+E7J4s5sYLNSDigrmI8 3Ketp6Rs27KkHedzv1PQuI+owYerb0fNLb43TB8sgaNYVUBf9MOLwJkqaZYPLOjJ/9I4 tymFT/q/tveBFLrLrJXTh6Khc4DNGZGO7IFJ3tHXy3ex45yu9aJ7bgiGnTXxn645RGGg zNTUUWcw97eniCJoLnnuEeAQjWfxoJhsQ7okKdkepmpbQ+qZTPu9NNHVEQvf31iK7hto 0VvDdbRIO3RxkJKaTSXl1whBlH8m+rHuseQbIRqBGKMXTVuwF1JZv5F+KTiOnX+3si8Q qhbQ== X-Gm-Message-State: APjAAAX0oXiYqb338eIsnXcWhPdiFaHGO8IMLD4I2QwDzFqy81O6Q8h0 5dRDYIiRb50uETpPVazJHcOqGA== X-Google-Smtp-Source: APXvYqwolTlOkBeqh0vywQsBopUex17ovDjGm26J7GwepQL2sUOHtRZs/QRwZB/kPFkyAVSqQrrnCw== X-Received: by 2002:a1c:7e8a:: with SMTP id z132mr11430786wmc.92.1555072606977; Fri, 12 Apr 2019 05:36:46 -0700 (PDT) Received: from localhost.localdomain (aputeaux-684-1-35-248.w90-86.abo.wanadoo.fr. [90.86.90.248]) by smtp.gmail.com with ESMTPSA id v190sm12384030wme.18.2019.04.12.05.36.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Apr 2019 05:36:46 -0700 (PDT) From: Bartosz Golaszewski To: Sekhar Nori , Kevin Hilman , Alan Stern , Greg Kroah-Hartman Subject: [PATCH v5 3/6] usb: ohci-da8xx: disable the regulator if the overcurrent irq fired Date: Fri, 12 Apr 2019 14:36:37 +0200 Message-Id: <20190412123640.11437-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190412123640.11437-1-brgl@bgdev.pl> References: <20190412123640.11437-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190412_053648_682470_19668FEB X-CRM114-Status: GOOD ( 16.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bartosz Golaszewski , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Bartosz Golaszewski Historically the power supply management in this driver has been handled in two separate places in parallel. Device-tree users simply defined an appropriate regulator, while two boards with no DT support (da830-evm and omapl138-hawk) passed functions defined in their respective board files over platform data. These functions simply used legacy GPIO calls to watch the oc GPIO for interrupts and disable the vbus GPIO when the irq fires. Commit d193abf1c913 ("usb: ohci-da8xx: add vbus and overcurrent gpios") updated these GPIO calls to the modern API and moved them inside the driver. This however is not the optimal solution for the vbus GPIO which should be modeled as a fixed regulator that can be controlled with a GPIO. In order to keep the overcurrent protection available once we move the board files to using fixed regulators we need to disable the enable_reg regulator when the overcurrent indicator interrupt fires. Since we cannot call regulator_disable() from interrupt context, we need to switch to using a oneshot threaded interrupt. Signed-off-by: Bartosz Golaszewski --- drivers/usb/host/ohci-da8xx.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c index 209a262b5565..f69b339d45e5 100644 --- a/drivers/usb/host/ohci-da8xx.c +++ b/drivers/usb/host/ohci-da8xx.c @@ -202,12 +202,23 @@ static int ohci_da8xx_regulator_event(struct notifier_block *nb, return 0; } -static irqreturn_t ohci_da8xx_oc_handler(int irq, void *data) +static irqreturn_t ohci_da8xx_oc_thread(int irq, void *data) { struct da8xx_ohci_hcd *da8xx_ohci = data; + struct device *dev = da8xx_ohci->hcd->self.controller; + int ret; - if (gpiod_get_value(da8xx_ohci->oc_gpio)) - gpiod_set_value(da8xx_ohci->vbus_gpio, 0); + if (gpiod_get_value_cansleep(da8xx_ohci->oc_gpio)) { + if (da8xx_ohci->vbus_gpio) { + gpiod_set_value_cansleep(da8xx_ohci->vbus_gpio, 0); + } else if (da8xx_ohci->vbus_reg) { + ret = regulator_disable(da8xx_ohci->vbus_reg); + if (ret) + dev_err(dev, + "Failed to disable regulator: %d\n", + ret); + } + } return IRQ_HANDLED; } @@ -434,8 +445,9 @@ static int ohci_da8xx_probe(struct platform_device *pdev) if (oc_irq < 0) goto err; - error = devm_request_irq(dev, oc_irq, ohci_da8xx_oc_handler, - IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, + error = devm_request_threaded_irq(dev, oc_irq, NULL, + ohci_da8xx_oc_thread, IRQF_TRIGGER_RISING | + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, "OHCI over-current indicator", da8xx_ohci); if (error) goto err; -- 2.21.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel