Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp281522yba; Wed, 3 Apr 2019 08:37:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqwhG08bE4jBB6oA4Ovj0tTkzHckCHrn4XaT+Hv0raZGEF0jj/1aTbaoWUwh7lwzUueIPDhn X-Received: by 2002:a62:e80f:: with SMTP id c15mr31898pfi.93.1554305862476; Wed, 03 Apr 2019 08:37:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554305862; cv=none; d=google.com; s=arc-20160816; b=ujpDrHaEjNXxpQiPeqIpY7ssoxaEHMWMxe4HxlPeseZifkCCqod/qTCMLw4X/sYQiE TjhWQZqfvt6u80rchWYada/Q2l7XmG+K/6GFE4AO09TCiZAafdNJ+2VivsCQkgYKtuSb 9Bj35XNQ1Lj435H/tVN5KyDe2fgKvw3B94ci7ocOBdGEP7rCHXXABQujONUWc+yytJxN PsSYgXrBD6inoCTDa4+iqRjjg4aZhAHk5HmsyDtLnlXJqHoV1jeBFGHkojltyg4Np5VZ LIHWYSRDIpBG1no6RYLY3eeIPrFeWoo1pBJsHqLxvPDGB2tTRxAye9iCW33Lgt4T3Jr2 vozQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=1PqxlDSB/yup+I5RPK8mK9xg9Ow2LmDYOD8f7wc+SOM=; b=LzgL/Y4CoXvtr+0A87GQzJpbq6jVNGi3GE0LIaX6cyFjkCq4sYYiqTokfdhbF/9+yw GIgf/qcYa8BxBS+pG+/5TsLCiOaCAjJWe/BQgJHuJ4wT0nR8+JlelyIaij3DGXsHL2r4 Co+9NEmd0+qUFxXFdhFUhn3AHtoS4KwzLIbMjjMgyF2SLJ3Fs5O4yO+yuibZwDi4GLe7 ZIuupKnJ4+Lonsnyjhd85kaNCsyqFYpwTTLA0FRAaLc3lPn4IXC3LCNNwCS14543o0g/ zXhUtCXyrb8DxEZiZSqroegxkcWIZiqW6GM4i6+n2HJpWt0k8t9kVlrXUv3tYBzGxn/T PQcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=PhhWKAn3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h1si4134244pfj.187.2019.04.03.08.37.27; Wed, 03 Apr 2019 08:37:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=PhhWKAn3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726705AbfDCPgT (ORCPT + 99 others); Wed, 3 Apr 2019 11:36:19 -0400 Received: from mail-io1-f68.google.com ([209.85.166.68]:41753 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726084AbfDCPgS (ORCPT ); Wed, 3 Apr 2019 11:36:18 -0400 Received: by mail-io1-f68.google.com with SMTP id v10so14427654iom.8 for ; Wed, 03 Apr 2019 08:36:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=1PqxlDSB/yup+I5RPK8mK9xg9Ow2LmDYOD8f7wc+SOM=; b=PhhWKAn3OFEsGp+QpuM2D2iyq/k9grlr4nUM54mq4DQf4N48/ltFnwRWcnxNigRBXe Eg+AeVrA4iieUnRDh/C9jNgyUq21WY4qGELpA5DThki6sWcNH0P52JdM1gqLwsV5Nsxo igNLHrc7QsC30ZhF6tTHPfbe3ojjGvVCwy8GIf4inGJOtjvmy6bQxWDg2lLJjaH/HmjD vSOXUeftMaAuSgKtxI/2dAFWuAz0+P5VVl6cADryy0OW4RRekR3MZJM4vkbm/vZORbma YmxXvbuzSGKe5sn2WkoLyuDJuerYKsKSER2ypVjHezpCFi6LTqCsxlj5fxOhY+gERqE5 RQqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=1PqxlDSB/yup+I5RPK8mK9xg9Ow2LmDYOD8f7wc+SOM=; b=gfrm8/iU8mqrEXotwCHRdq29x4eAHnBx1Mf1+lZpGhI9+Gp/C2H2+mCtI+YkIMWARK wxspzC6NYHkZzWmtrcyudvdjtTLcQA+BTYd2s5Pfc5eZj3ZvWqK+2cHwTAcf/Km6ZsEJ KO2z0Wzu3ProT//Xhi9OcWTvJvH2mA9Ty6GcxqmBx/LkrdYFabUuvOhAGvJF2lp9A7Ov GB96IwsSrpBi3jEB8oNy455tH1TuW9Qg5j0F75KtO4nI4QVu66WqYt3ec1VmsZzUA59F zacObf/VjMbwl1WbHiFTygD6y4K/04XJWzzOz0oU0yIKFzxaAGlUoQ154rG99QrP3WY6 U2BA== X-Gm-Message-State: APjAAAXIx1kek6tLWH/jG5Yg0MPjKgJpxXaBgLwicAFMwXEKVxNmG5hU tU8OZNwyQ8eEY9ousQlW9oFJEFSeqGZedQWd3Z5LHg== X-Received: by 2002:a6b:4e17:: with SMTP id c23mr555941iob.212.1554305777867; Wed, 03 Apr 2019 08:36:17 -0700 (PDT) MIME-Version: 1.0 References: <20190329093334.3885-1-brgl@bgdev.pl> <20190329093334.3885-4-brgl@bgdev.pl> In-Reply-To: <20190329093334.3885-4-brgl@bgdev.pl> From: Bartosz Golaszewski Date: Wed, 3 Apr 2019 17:36:07 +0200 Message-ID: Subject: Re: [PATCH v2 3/6] usb: ohci-da8xx: disable the regulator if the overcurrent irq fired To: Sekhar Nori , Kevin Hilman , Alan Stern , Greg Kroah-Hartman Cc: Linux ARM , Linux Kernel Mailing List , linux-usb@vger.kernel.org, Bartosz Golaszewski Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org pt., 29 mar 2019 o 10:33 Bartosz Golaszewski napisa=C5=82(a= ): > > 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, vo= id *data) > { > struct da8xx_ohci_hcd *da8xx_ohci =3D 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 =3D data; > + struct device *dev =3D da8xx_ohci->hcd->self.controller; > + int ret; > + > + ret =3D 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 =3D devm_request_irq(dev, oc_irq, ohci_da8xx_oc_han= dler, > - IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLIN= G, > - "OHCI over-current indicator", da8xx_ohci= ); > + error =3D devm_request_threaded_irq(dev, oc_irq, > + ohci_da8xx_oc_handler, ohci_da8xx_oc_thre= ad, > + IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLIN= G | > + IRQF_ONESHOT, "OHCI over-current indicato= r", > + da8xx_ohci); Ugh I noticed a problem with this patch if the module is built-in - after calling devm_request_threaded_irq() any subsequent msleep() will hang. This doesn't happen if the driver is built as a module. I'm not sure what the reason is yet. Bart > if (error) > goto err; > } > -- > 2.21.0 >