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 75F73C282CE for ; Thu, 11 Apr 2019 09:30:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 43E2F20850 for ; Thu, 11 Apr 2019 09:30:41 +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="kTqCVK7K" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727148AbfDKJaj (ORCPT ); Thu, 11 Apr 2019 05:30:39 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:43796 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727034AbfDKJae (ORCPT ); Thu, 11 Apr 2019 05:30:34 -0400 Received: by mail-wr1-f67.google.com with SMTP id k17so1698880wrx.10 for ; Thu, 11 Apr 2019 02:30:33 -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=gLM5OGxjE0bCxoX8JlJuO36BhilSPuFc/F1r8G6fLDQ=; b=kTqCVK7KW2nICs9vZ+KD+6b+DSOAtYDAxd86WeMhviCAJ5AzDCPp54RhmjT6bIRh19 HRFMGkRlpJts4gmBdMQY1SY/DZe1leK7jg9x+LBo78FLcJxzYGWvYUJA3o/CeP6B7If7 1bgQ7hQIXj8lIuZn7A9v69OzDJ3a1KHVEL4QWCpj6AltXKu/zU7FpVJeXEI52IUV0D5P pGCCi+IcQr3uIqPX3SVNJrCm6vdRovYoX40RmU0qAqMgvq0y40ON2qmDnF8sm9e2iRFE S3GS9JBqjq25/qyVNtIhsYPtitZ1i6Pe2Xz0EKmK3hDB9my1C6desP/0xkBu8xsR1BAr RoDw== 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=gLM5OGxjE0bCxoX8JlJuO36BhilSPuFc/F1r8G6fLDQ=; b=nQGQVYXGvgQXFBRYU9HrliHxLgRJ0yrNPWKe2m8iTjBiXvYRzDw+BpARcGbM67X8u1 RO0a8z/I5r0V+Ebgy8S8E51lu+qlslUDPERgPeBZLo20LQ0zoAT+cHRoZQHnttbHTalO qZXBcggW0B7+eZ6fwyULqqp9NDyx3KVm35JkjEqoLwzrpFdJdK97dnWHik8oaiRjgsTW Z4x2Kjsc7usoOeRs7RSiHOxJrvaj4zMPhRxoG7eCOWaknVNvaQ8slDF6+7ekg9bkdlaW L6cfWA/YzNyQmZJUUWjiVvkfgBAGA0Kq6r2Lk4ody1hk+Uq3sffGjPvFiSa7u0x9+AIo YeGA== X-Gm-Message-State: APjAAAUxGLKiOqh9XPAMxo8HpZQpRKah6H/Q5iFdzLYSGYpPhL90w/2P g+/9UEZuiNAGi+CvH2y3p32s9g== X-Google-Smtp-Source: APXvYqyHM8EWTB/2wtehfWQZl0eBdijqY2jIKEOZfGb6/5GYPgQzV9nBvd7auUSU0dkB6PodjxgjQQ== X-Received: by 2002:a05:6000:12c8:: with SMTP id l8mr29648948wrx.80.1554975033237; Thu, 11 Apr 2019 02:30:33 -0700 (PDT) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id a9sm37517228wrt.29.2019.04.11.02.30.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Apr 2019 02:30:32 -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 v4 3/6] usb: ohci-da8xx: disable the regulator if the overcurrent irq fired Date: Thu, 11 Apr 2019 11:30:21 +0200 Message-Id: <20190411093024.23555-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190411093024.23555-1-brgl@bgdev.pl> References: <20190411093024.23555-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 | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c index 209a262b5565..6158408b1ea0 100644 --- a/drivers/usb/host/ohci-da8xx.c +++ b/drivers/usb/host/ohci-da8xx.c @@ -202,12 +202,24 @@ 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 +446,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 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Subject: [v4,3/6] usb: ohci-da8xx: disable the regulator if the overcurrent irq fired From: Bartosz Golaszewski Message-Id: <20190411093024.23555-4-brgl@bgdev.pl> Date: Thu, 11 Apr 2019 11:30:21 +0200 To: Sekhar Nori , Kevin Hilman , Alan Stern , Greg Kroah-Hartman Cc: linux-arm-kernel@lists.infradead.org, linux-kernel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Aob2NfaXJxIDwgMCkKIAkJCWdvdG8gZXJyOwogCi0JCWVycm9yID0g ZGV2bV9yZXF1ZXN0X2lycShkZXYsIG9jX2lycSwgb2hjaV9kYTh4eF9vY19oYW5kbGVyLAotCQkJ CUlSUUZfVFJJR0dFUl9SSVNJTkcgfCBJUlFGX1RSSUdHRVJfRkFMTElORywKKwkJZXJyb3IgPSBk ZXZtX3JlcXVlc3RfdGhyZWFkZWRfaXJxKGRldiwgb2NfaXJxLCBOVUxMLAorCQkJCW9oY2lfZGE4 eHhfb2NfdGhyZWFkLCBJUlFGX1RSSUdHRVJfUklTSU5HIHwKKwkJCQlJUlFGX1RSSUdHRVJfRkFM TElORyB8IElSUUZfT05FU0hPVCwKIAkJCQkiT0hDSSBvdmVyLWN1cnJlbnQgaW5kaWNhdG9yIiwg ZGE4eHhfb2hjaSk7CiAJCWlmIChlcnJvcikKIAkJCWdvdG8gZXJyOwo= 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 1B51DC10F13 for ; Thu, 11 Apr 2019 09:31:08 +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 DA28520850 for ; Thu, 11 Apr 2019 09:31:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ri93yCCp"; 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="kTqCVK7K" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DA28520850 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=ajLQ9AYW6mgpCvYvwxJRaDQCXYeMtJbdf9XXSMmQ+NE=; b=ri93yCCpoA+wqo m0wuzNx4anQXL0SLUyh2GwP4hua34+cIidNliOiOvIdUEV0dJCeJt2Pw/zERteUrShbWOLxHAWmjr yejKu+uxTR0uD9YPJmGjaP1mqPiUSDdwAH1rGWZahKCiv9H+JmdIiu/yuB88+cPBtCDpgW26zfmNG EMulG28Fq5DUQfA6OlX0xlKEbEHljhz3rC3gU/bsqzYGs0ykzzYNVGKjUhr5/0m9K9pF8JCH+sesM mdmwtJqm6pLtF9eZgPcqsLW4VLjYamkb7c7/19SiHAQSq6IeI7OG/kf+4s0jJYODWmUp8sBRkpMvR VJqRA12oo5tY7LBKTujA==; 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 1hEW30-0004ya-Ts; Thu, 11 Apr 2019 09:31:06 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEW2U-0004Hr-Fv for linux-arm-kernel@lists.infradead.org; Thu, 11 Apr 2019 09:30:36 +0000 Received: by mail-wr1-x441.google.com with SMTP id r4so6346636wrq.8 for ; Thu, 11 Apr 2019 02:30:34 -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=gLM5OGxjE0bCxoX8JlJuO36BhilSPuFc/F1r8G6fLDQ=; b=kTqCVK7KW2nICs9vZ+KD+6b+DSOAtYDAxd86WeMhviCAJ5AzDCPp54RhmjT6bIRh19 HRFMGkRlpJts4gmBdMQY1SY/DZe1leK7jg9x+LBo78FLcJxzYGWvYUJA3o/CeP6B7If7 1bgQ7hQIXj8lIuZn7A9v69OzDJ3a1KHVEL4QWCpj6AltXKu/zU7FpVJeXEI52IUV0D5P pGCCi+IcQr3uIqPX3SVNJrCm6vdRovYoX40RmU0qAqMgvq0y40ON2qmDnF8sm9e2iRFE S3GS9JBqjq25/qyVNtIhsYPtitZ1i6Pe2Xz0EKmK3hDB9my1C6desP/0xkBu8xsR1BAr RoDw== 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=gLM5OGxjE0bCxoX8JlJuO36BhilSPuFc/F1r8G6fLDQ=; b=TyQ3wi4Fmv1m9ufg57JvW/FmdF+JJFcpULWsyJxUbGxrkDF1xeCZJCg6w7XRAML/ej 5Cf83+0ia3iVcsjULToRyZlxQuUvYhO8hy2f7XFkqQhB4zTDHEVIOUhVNFTq0vu0FyeI eXpZdPqqk/MBuYYUmA/gRSNm1RVSOq+8muAcXBgbhYUOload7VBP1daRWuoWtmOLo7Cb WVbDjTiODPLlsZDiIg/pAk19+mBmZL2APgCHiYx22B6kG3rjIzxTxwQZ1VQfuKNvxTJ+ dMmlXd2JTjr6q1Ygc7dPEuzJXWoN2FAf9EPbxn4KoZbx/og+2coHhqGTomfyTH8XdAYU 5WQQ== X-Gm-Message-State: APjAAAUM9KfDRL7ozh5tloEiACWC6ZLN9gv+anopTUmI7p8oBdGpbCoq AEtPphbPRVl+sWOZ7/3JLU+Ycw== X-Google-Smtp-Source: APXvYqyHM8EWTB/2wtehfWQZl0eBdijqY2jIKEOZfGb6/5GYPgQzV9nBvd7auUSU0dkB6PodjxgjQQ== X-Received: by 2002:a05:6000:12c8:: with SMTP id l8mr29648948wrx.80.1554975033237; Thu, 11 Apr 2019 02:30:33 -0700 (PDT) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id a9sm37517228wrt.29.2019.04.11.02.30.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Apr 2019 02:30:32 -0700 (PDT) From: Bartosz Golaszewski To: Sekhar Nori , Kevin Hilman , Alan Stern , Greg Kroah-Hartman Subject: [PATCH v4 3/6] usb: ohci-da8xx: disable the regulator if the overcurrent irq fired Date: Thu, 11 Apr 2019 11:30:21 +0200 Message-Id: <20190411093024.23555-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190411093024.23555-1-brgl@bgdev.pl> References: <20190411093024.23555-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190411_023034_830064_FE3799ED X-CRM114-Status: GOOD ( 16.53 ) 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 | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c index 209a262b5565..6158408b1ea0 100644 --- a/drivers/usb/host/ohci-da8xx.c +++ b/drivers/usb/host/ohci-da8xx.c @@ -202,12 +202,24 @@ 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 +446,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