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: [v2,3/6] usb: ohci-da8xx: disable the regulator if the overcurrent irq fired From: Bartosz Golaszewski Message-Id: <20190329093334.3885-4-brgl@bgdev.pl> Date: Fri, 29 Mar 2019 10:33:31 +0100 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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ICJGYWlsZWQgdG8gZGlzYWJsZSByZWd1bGF0b3I6ICVkXG4iLCByZXQpOwogCiAJ cmV0dXJuIElSUV9IQU5ETEVEOwogfQpAQCAtNDM0LDkgKzQ1MSwxMSBAQCBzdGF0aWMgaW50IG9o Y2lfZGE4eHhfcHJvYmUoc3RydWN0IHBsYXRmb3JtX2RldmljZSAqcGRldikKIAkJaWYgKG9jX2ly cSA8IDApCiAJCQlnb3RvIGVycjsKIAotCQllcnJvciA9IGRldm1fcmVxdWVzdF9pcnEoZGV2LCBv Y19pcnEsIG9oY2lfZGE4eHhfb2NfaGFuZGxlciwKLQkJCQlJUlFGX1RSSUdHRVJfUklTSU5HIHwg SVJRRl9UUklHR0VSX0ZBTExJTkcsCi0JCQkJIk9IQ0kgb3Zlci1jdXJyZW50IGluZGljYXRvciIs IGRhOHh4X29oY2kpOworCQllcnJvciA9IGRldm1fcmVxdWVzdF90aHJlYWRlZF9pcnEoZGV2LCBv Y19pcnEsCisJCQkJb2hjaV9kYTh4eF9vY19oYW5kbGVyLCBvaGNpX2RhOHh4X29jX3RocmVhZCwK KwkJCQlJUlFGX1RSSUdHRVJfUklTSU5HIHwgSVJRRl9UUklHR0VSX0ZBTExJTkcgfAorCQkJCUlS UUZfT05FU0hPVCwgIk9IQ0kgb3Zlci1jdXJyZW50IGluZGljYXRvciIsCisJCQkJZGE4eHhfb2hj aSk7CiAJCWlmIChlcnJvcikKIAkJCWdvdG8gZXJyOwogCX0K 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,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 D3582C43381 for ; Fri, 29 Mar 2019 09:34:25 +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 957C82082F for ; Fri, 29 Mar 2019 09:34: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="tQha1Na4"; 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="CUQ7KKfd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 957C82082F 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=OFAagzm2KnWRNjjkMYEvR308amUAvF6ivv5VUGUDFyc=; b=tQha1Na4qjUZm0 k4ffmxZcaWWJOnxzrzLTG9i79xyRAVt46MzaHHlyhbpiIME99ZDx59ylKMlTYyIr3lv4gSlpW/4o4 AqHLsaHndjppZwQCrEoL5Ipvr/zmCiJv0PyisvQHibJTWJ1yvZtH5MSozzVpEwM3u66kzAvLl6t/i WN2vaAfhS3Yc7c0rFxw4SPTknPM1NzTmCRVKKBeNBv8QJucZEBShXHMx91EdRDmu2WH/G59RejrGt x4uub7Bv0Gl/s8PXm6lEcegjYGjl7GB8/eEFrJOSrGxYo9OdpMdPFKtk6HdSzEzn7tRNzQbfCGIyA mAtd07YSvkYtZj5TDA2Q==; 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 1h9nu0-0002CJ-Mr; Fri, 29 Mar 2019 09:34:20 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h9ntS-0001Ud-Tw for linux-arm-kernel@lists.infradead.org; Fri, 29 Mar 2019 09:33:48 +0000 Received: by mail-wm1-x342.google.com with SMTP id a184so1770515wma.2 for ; Fri, 29 Mar 2019 02:33:46 -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=qxVFTCKVfhfrjJriQ7IFcj6eKhxdNdDEXDDI5+KStxc=; b=CUQ7KKfdW8+ryhjSUNXaiFX89azn2tYpx2isT2sVjj6MMYlDDZb59OKxxSo4i5+is9 jcPishfNrPUJLOkdwWo2BPE2E4sr7Cdu+VK+J4/kdk3jUigrmH77ObhZrQVGNpg2ebbG 7sa6hG2AgJmcIxOE0cST8nIBPDVRCpGo4O/sjbvzF+IUiTzbw7Rlac7HUq5LvkRRzmno idvbBMW2bAe3nTKKP27RmtWsivWJdLV68yw8/xHWELdO/BHC1GFd7f2NwYbTcowSkXTg VHQ/xjeGtJ6VzOPNkqQtxFDLscOLzh7ewjH2aCcx/sAyRh6ePgeHgsVcFK+Zo8VeoqXa kD4g== 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=qxVFTCKVfhfrjJriQ7IFcj6eKhxdNdDEXDDI5+KStxc=; b=etzJd84wKFy+xa0VfTOH7jEtUxYr+CXSkHyX6D5ULiW6oXLl3ISJ3VyvqUY7/Ovcaw wKJyzo6AvNwsrbrA0RWKYwDhXAjwRqpo3WXmwTL/O+1J5gmab7spm3oukSqUkO3rCLla d6oNWqPjNnztlw7CvU7DDa5TIomoKzcU6sNBlk4SKngva4JqtD4Fv7qAvArCMcKwzh9u 3biD/uH+rmBVunQfLUAHfhOOqJXWuFnR5PpRG+p2jD/u7s9qsL8uiUtyN8zB4gUXc3EB U9OZUWSpqK/R8/7/9cVWx7FQIhIzucr//ap+jNzSeoNT0dZICpScXSngA4WzlYtS3p7l lhiw== X-Gm-Message-State: APjAAAXVnNOezK8aOmPLyYueWhnpNE8Qzi+xZnOExhiQyehnMEOOIIZw +VhfN/fsojCQeYIvmPh9+7o/sg== X-Google-Smtp-Source: APXvYqy+zZg4B2VxgIKMbzMvBv4CBQGWIh4gIel8gfANT8NUSAkwF5Q59QfXQdw6RoUD5ZGBE3xtyQ== X-Received: by 2002:a1c:96d5:: with SMTP id y204mr1145423wmd.22.1553852025666; Fri, 29 Mar 2019 02:33:45 -0700 (PDT) Received: from localhost.localdomain (aputeaux-684-1-29-77.w90-86.abo.wanadoo.fr. [90.86.254.77]) by smtp.gmail.com with ESMTPSA id s12sm1957125wmj.42.2019.03.29.02.33.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Mar 2019 02:33:44 -0700 (PDT) From: Bartosz Golaszewski To: Sekhar Nori , Kevin Hilman , Alan Stern , Greg Kroah-Hartman Subject: [PATCH v2 3/6] usb: ohci-da8xx: disable the regulator if the overcurrent irq fired Date: Fri, 29 Mar 2019 10:33:31 +0100 Message-Id: <20190329093334.3885-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190329093334.3885-1-brgl@bgdev.pl> References: <20190329093334.3885-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190329_023346_966202_227B8E4F X-CRM114-Status: GOOD ( 15.99 ) 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 | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c index 9c6d1f03b871..35eb2cb96a8f 100644 --- a/drivers/usb/host/ohci-da8xx.c +++ b/drivers/usb/host/ohci-da8xx.c @@ -206,8 +206,25 @@ static irqreturn_t ohci_da8xx_oc_handler(int irq, void *data) { struct da8xx_ohci_hcd *da8xx_ohci = data; - if (gpiod_get_value(da8xx_ohci->oc_gpio)) - gpiod_set_value(da8xx_ohci->vbus_gpio, 0); + if (gpiod_get_value(da8xx_ohci->oc_gpio)) { + if (da8xx_ohci->vbus_gpio) + gpiod_set_value(da8xx_ohci->vbus_gpio, 0); + else if (da8xx_ohci->vbus_reg) + return IRQ_WAKE_THREAD; + } + + return IRQ_HANDLED; +} + +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; + + ret = regulator_disable(da8xx_ohci->vbus_reg); + if (ret) + dev_err(dev, "Failed to disable regulator: %d\n", ret); return IRQ_HANDLED; } @@ -434,9 +451,11 @@ 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, - "OHCI over-current indicator", da8xx_ohci); + error = devm_request_threaded_irq(dev, oc_irq, + ohci_da8xx_oc_handler, 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 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_MED,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 2E388C43381 for ; Fri, 29 Mar 2019 09:33:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F27672082F for ; Fri, 29 Mar 2019 09:33:51 +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="CUQ7KKfd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728840AbfC2Jdu (ORCPT ); Fri, 29 Mar 2019 05:33:50 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:37731 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728782AbfC2Jdr (ORCPT ); Fri, 29 Mar 2019 05:33:47 -0400 Received: by mail-wm1-f66.google.com with SMTP id v14so1964432wmf.2 for ; Fri, 29 Mar 2019 02:33:46 -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=qxVFTCKVfhfrjJriQ7IFcj6eKhxdNdDEXDDI5+KStxc=; b=CUQ7KKfdW8+ryhjSUNXaiFX89azn2tYpx2isT2sVjj6MMYlDDZb59OKxxSo4i5+is9 jcPishfNrPUJLOkdwWo2BPE2E4sr7Cdu+VK+J4/kdk3jUigrmH77ObhZrQVGNpg2ebbG 7sa6hG2AgJmcIxOE0cST8nIBPDVRCpGo4O/sjbvzF+IUiTzbw7Rlac7HUq5LvkRRzmno idvbBMW2bAe3nTKKP27RmtWsivWJdLV68yw8/xHWELdO/BHC1GFd7f2NwYbTcowSkXTg VHQ/xjeGtJ6VzOPNkqQtxFDLscOLzh7ewjH2aCcx/sAyRh6ePgeHgsVcFK+Zo8VeoqXa kD4g== 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=qxVFTCKVfhfrjJriQ7IFcj6eKhxdNdDEXDDI5+KStxc=; b=iH/oxsweYkizBwg2tuIrjhj4/XBhz8aUFzMr3FFEjxzvMHH8+fwA3NGTLU/WavOtqn WPZI4y566vvxJ3WHdY1uQHyoD8biQf34o4dmWJ2YiDt03oeLHyWReBnlwwT7thM3HZsx lY9T+n5bCP6gIJfPhYBNfI6Mp4SyFX5AeVzAMm6Y+qO3BO4Y9OzCdYWgMNj/BmpJa8kX Y3QNbcNPK4qWJ/xjPAKt5IKgCy/YWvsb6g55ocEH+EQ/WInYAF9P5Gx7KoZG2YAoQh3W HBmQdedVW05bWlhINBzjNIk7nfKZR4yPbC1XcOBLEhmYEHnHBKzUElWpRwGYgti65DKW /QwA== X-Gm-Message-State: APjAAAXx0LDFbCKSwf9aTfvcCbN4/9j4GXfV6I6YiLzq757rPQQn/KK5 RyYEk6GPFpsQV/39U1tsIF3/8Q== X-Google-Smtp-Source: APXvYqy+zZg4B2VxgIKMbzMvBv4CBQGWIh4gIel8gfANT8NUSAkwF5Q59QfXQdw6RoUD5ZGBE3xtyQ== X-Received: by 2002:a1c:96d5:: with SMTP id y204mr1145423wmd.22.1553852025666; Fri, 29 Mar 2019 02:33:45 -0700 (PDT) Received: from localhost.localdomain (aputeaux-684-1-29-77.w90-86.abo.wanadoo.fr. [90.86.254.77]) by smtp.gmail.com with ESMTPSA id s12sm1957125wmj.42.2019.03.29.02.33.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Mar 2019 02:33:44 -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 v2 3/6] usb: ohci-da8xx: disable the regulator if the overcurrent irq fired Date: Fri, 29 Mar 2019 10:33:31 +0100 Message-Id: <20190329093334.3885-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190329093334.3885-1-brgl@bgdev.pl> References: <20190329093334.3885-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c index 9c6d1f03b871..35eb2cb96a8f 100644 --- a/drivers/usb/host/ohci-da8xx.c +++ b/drivers/usb/host/ohci-da8xx.c @@ -206,8 +206,25 @@ static irqreturn_t ohci_da8xx_oc_handler(int irq, void *data) { struct da8xx_ohci_hcd *da8xx_ohci = data; - if (gpiod_get_value(da8xx_ohci->oc_gpio)) - gpiod_set_value(da8xx_ohci->vbus_gpio, 0); + if (gpiod_get_value(da8xx_ohci->oc_gpio)) { + if (da8xx_ohci->vbus_gpio) + gpiod_set_value(da8xx_ohci->vbus_gpio, 0); + else if (da8xx_ohci->vbus_reg) + return IRQ_WAKE_THREAD; + } + + return IRQ_HANDLED; +} + +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; + + ret = regulator_disable(da8xx_ohci->vbus_reg); + if (ret) + dev_err(dev, "Failed to disable regulator: %d\n", ret); return IRQ_HANDLED; } @@ -434,9 +451,11 @@ 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, - "OHCI over-current indicator", da8xx_ohci); + error = devm_request_threaded_irq(dev, oc_irq, + ohci_da8xx_oc_handler, 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