Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4063601yba; Tue, 9 Apr 2019 10:19:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqxoFq8U+aZwtumEhbcALSnuwRZg9dC7x+i3EuuJntDZMBMe/aMj3bsLepVbLoQ2BJxply0z X-Received: by 2002:a65:47c6:: with SMTP id f6mr35677037pgs.173.1554830396214; Tue, 09 Apr 2019 10:19:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554830396; cv=none; d=google.com; s=arc-20160816; b=G4uoIhhMCYdA+fvbg3iRit9iHZSHEqZvvLos51x5sJigIrB24vEorCOin4DEVfNAzZ yVXb3XX2mAOvAkMij0Qijre2Gu6RXaO3/0PxcZAFAMe1IDPU89pgeHNN1Zep/09S8gSG Rcj5GalapzOwrpUk4LihuCZLdSsWL1OmxX0/jFMtcoo5TLWaQWQHM5vRgdpz04L5R2TI gqD4kyLET47WN5MGhUgUgxt9QS/No7l3ccNTZ5Dg+WfDnRxGskHBTfWLv9N16CXLGizb 4gRQJAEaf5XAkyITBJ6n/rlkqse932U+PMOp4+Wmj/rqvHKjHe8E2MuD0A9NsT626phN UN5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date; bh=QvnZBdEcu8lGM7HWPRm1JLV15/EtukXTebKT5A1kTME=; b=WHEVf3Wt7/0a+jW0grG2uR5+sJH66Ck9cnP66InfODizbJdASts4ZHkHTX+d7r2mn1 yKprN0rcyT5HY5gCLoR6ysUiQS5VtCqabUBlw4jEZbDI/n3QfD/8BYdUnFlYOoXymeaN gfBS/B/jv4lPvHZ0BBanCorAnnqgYSaSMQq9Pn+Socj1etyz73r8eBdelfpvnGcuQFvG yvHZcYWKhh94KEQ9CSySh8gk8W0frJDIRNfswNREEGMbnMnrEwuik5AovX6oVdlGRg3d eJCanC6ZZl/zMF9TTRANsPJyzj4QKbau8AKONbDco3XRR7ySCP+bJGlYEdnCYgOFW/wQ JvFw== ARC-Authentication-Results: i=1; mx.google.com; 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 l7si5795227pgq.263.2019.04.09.10.19.39; Tue, 09 Apr 2019 10:19:56 -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; 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 S1726564AbfDIRRp (ORCPT + 99 others); Tue, 9 Apr 2019 13:17:45 -0400 Received: from iolanthe.rowland.org ([192.131.102.54]:46604 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1726499AbfDIRRp (ORCPT ); Tue, 9 Apr 2019 13:17:45 -0400 Received: (qmail 5532 invoked by uid 2102); 9 Apr 2019 13:17:44 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 9 Apr 2019 13:17:44 -0400 Date: Tue, 9 Apr 2019 13:17:44 -0400 (EDT) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: Bartosz Golaszewski cc: Sekhar Nori , Kevin Hilman , Greg Kroah-Hartman , , , , Bartosz Golaszewski Subject: Re: [PATCH v3 3/6] usb: ohci-da8xx: disable the regulator if the overcurrent irq fired In-Reply-To: <20190409082855.15373-4-brgl@bgdev.pl> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 9 Apr 2019, Bartosz Golaszewski wrote: > 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 9c6d1f03b871..108fe0a1b962 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; > Acked-by: Alan Stern