Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp3217300rwr; Sun, 7 May 2023 07:09:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4wVk43oEddtl4aQrZ0jGz6d2YujZ7ZIJ/kA7Y6FIpEvQPU7XEEX4ufKy9zl9bR18WqaiDC X-Received: by 2002:a17:90a:fc85:b0:24e:12ac:932c with SMTP id ci5-20020a17090afc8500b0024e12ac932cmr7852046pjb.6.1683468572485; Sun, 07 May 2023 07:09:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683468572; cv=none; d=google.com; s=arc-20160816; b=peSKd3WzU1UOFVz9bzLIJQGwsvRwlrEtsMa8n6C9aWZHGQIy+923ZU449GLkMIocl6 XdQxK4TnjzTnjDXdX17/xKHdGKGc3a3G0jsi7r4LfiVw7fBZnvn7q6o9SrsCxJQaDMYF xqBEOU9s/V8Fy2DWAgEoBB7OQtIk2FO0CtDAnytR0vf4/6ea9KXtyGWAA8iuIKRgkQOj R07mKWvW3AeiVsLqjfT8AtbYLWWbqPC2Be7FvcLnZulMl0fjyD4sGv+BZG620gDYtiUG Wb1Xgg2PIwFoj73UVG8jnx9/l/dkgOHoi2ICabDqql95b8geEAvOLMPnSTFdNj+qFsjS fsbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=XCsWKE2+GcBi2iOP5+S6beSuiAjQ3UNSR2x0QO/2bgY=; b=yeCJIC8aQ+zfwGzFUWjaiv5SDHvlcECDw8bGthOKl3eTQd/bwgS8AFG9CyufHyWs99 1cd42S6Nbi2ZVa898Lrelt3ut62KL2WuJGay0Qg1zTqRjAjm9uwanO/cvC8oyIyue4aU 19tSjCWcmBHvMBms9Bb/eLeB72MTcY0N8S+jeMHxfW8uy/h0IuIpuFefocB1FlCk3tfM vCuJzbptyUZteaFj2ABJICL4VbuFTckpLRnZtP2jXQYo2qgsfplmEeIRckVAM020iqoe 2+lqa9wsjFxCXCeSzbRBB8KRJtoIhfOMBO4kCsmIGpou+hsNL3VZlkcTbaPCjgeJfwja 5BRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aqIvBdJF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n6-20020a637206000000b0051aeaf666dfsi6151118pgc.668.2023.05.07.07.09.16; Sun, 07 May 2023 07:09:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aqIvBdJF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229578AbjEGOGt (ORCPT + 99 others); Sun, 7 May 2023 10:06:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229454AbjEGOGr (ORCPT ); Sun, 7 May 2023 10:06:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75B2BF0; Sun, 7 May 2023 07:06:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0AB0E60C37; Sun, 7 May 2023 14:06:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2EB48C433D2; Sun, 7 May 2023 14:06:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683468404; bh=uKRagPtWPQ0otbYUeeaNhIlFQq3x79fkP54v0RwfeSE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=aqIvBdJFSifhBSTGjV+4U1jcoHF3YkabGzCxyItuaS3a2unzlekx17EdYbwh1Zoq+ VyeI1QkVivhNk22h9t2UgzBZi5z8ehsobCehwxNH+H95LmdMBeFiVIAPsObH67V4UB vCg3JJLdx/gJm/zT0cFk6pbUULUJdiv6qcydon5x54o+82JXnqUMGhzSNSGModCroH Xho3IEz84uyiefBi/VK4yLCvEtKS+IBjHrlJls92+7E5gQgJFzyxtRUCDli8tRtSrL zcbXnfi0kIRIbblO/UWQQD1+8ztKgtXwzNTVTpUq8l2PlXU9q3cCR6lJvsHMF0Wflh t5FKioIELNv1Q== Date: Sun, 7 May 2023 15:22:36 +0100 From: Jonathan Cameron To: "Vaittinen, Matti" Cc: Matti Vaittinen , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Andy Shevchenko , Shreeya Patel , Zhigang Shi , Paul Gazzillo , "linux-iio@vger.kernel.org" , "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Andi Shyti Subject: Re: [PATCH v3 4/5] iio: light: ROHM BU27008 color sensor Message-ID: <20230507152236.46aba096@jic23-huawei> In-Reply-To: <91463df1-5aba-484a-92ea-f8979ec30535@fi.rohmeurope.com> References: <20230501152014.7789aa42@jic23-huawei> <91463df1-5aba-484a-92ea-f8979ec30535@fi.rohmeurope.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.37; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > > > >> + > >> + if (i2c->irq) { > >> + ret = devm_iio_triggered_buffer_setup(dev, idev, > >> + &iio_pollfunc_store_time, > >> + bu27008_trigger_handler, > >> + &bu27008_buffer_ops); > >> + if (ret) > >> + return dev_err_probe(dev, ret, > >> + "iio_triggered_buffer_setup_ext FAIL\n"); > >> + > >> + itrig = devm_iio_trigger_alloc(dev, "%sdata-rdy-dev%d", > >> + idev->name, iio_device_id(idev)); > >> + if (!itrig) > >> + return -ENOMEM; > >> + > >> + data->trig = itrig; > >> + > >> + itrig->ops = &bu27008_trigger_ops; > >> + iio_trigger_set_drvdata(itrig, data); > >> + > >> + name = devm_kasprintf(dev, GFP_KERNEL, "%s-bu27008", > >> + dev_name(dev)); > >> + > >> + ret = devm_request_threaded_irq(dev, i2c->irq, > >> + iio_pollfunc_store_time, > > > > This is on the wrong irq. > > Seems like I have some homework to do :) > > Right. I now see I pass the iio_pollfunc_store_time() as top half for > both the "real IRQ" generated by the device (here), as well as a > top-half for the devm_iio_triggered_buffer_setup(). Ideally I like the > idea of taking the timestamp in the top half for the device-generated > IRQ as it is closer the moment HW did acquire the sample - but it really > would make no difference here (even if I did it correctly). It's the matter of few function calls later. So trivial timing wise. > > iio_pollfunc_store_time is used with the trigger not > > here. Basically what happens is the caller of iio_poll_trigger() fires the input > > to a software irq chip that then signals all the of the downstream irqs (which > > are the individual consumers of the triggers). If that's triggered from the > > top half / non threaded bit of the interrupt the iio_pollfunc_store_time() > > will be called in that non threaded context before the individual threads > > for the trigger consumer are started. > > Oh. So, you mean the iio_pollfunc_store_time() is automatically called > already before kicking the SW-IRQ? So we don't need it in > devm_iio_triggered_buffer_setup() anymore? No. Whatever you register as the top half of the poll_func in the call to devm_iio_triggered_buffer_setup() will be called as part of the SW irq chip handling - not this isn't a SW-IRQ at all, it's just some demultiplexing code. The top half of an IIO poll func runs in the the trigger interrupt handler (under iio_trigger_poll) before those in turn start their own interrupt threads to handle whatever you registered as the threads in devm_iio_trigger_buffer_setup() > > > If there is nothing to do in the actual interrupt as it's a data ready > > only signal, then you should just call iio_trigger_poll() in the top half and > > use devm_request_irq() only as there is no thread in this interrupt (though > > there is one for the interrupt below the software interrupt chip). > > I haven't tested this yet so please ignore me if I am writing nonsense - > but... The BU27008 will keep the IRQ line asserted until a register is > read. We can't read the register form HW-IRQ so we need to keep the IRQ > disabled until the threaded trigger handler is ran. With the setup we > have here, the IRQF_ONESHOT, took care of this. I assume that changing > to call the iio_poll_trigger() from top-half means I need to explicitly > disable the IRQ and re-enable it at the end of the trigger thread after > reading the register which debounces the IRQ line? Hmm. I'm trying to remember how this works (wrote this a very long time ago). I'm fairly sure it's not an issue because we use IRQF_ONESHOT down one level so exercise the same prevention of the threads triggering multiple times etc. https://elixir.bootlin.com/linux/latest/source/drivers/iio/buffer/industrialio-triggered-buffer.c#L57 It doesn't matter if the device interrupt fires again as it will still be masked at our software irqchip level and will then get queued up and the thread will run again. > > > > > > >> + &bu27008_irq_thread_handler, > >> + IRQF_ONESHOT, name, idev->pollfunc); > >> + if (ret) > >> + return dev_err_probe(dev, ret, > >> + "Could not request IRQ\n"); > >> + > >> + > >> + ret = devm_iio_trigger_register(dev, itrig); > >> + if (ret) > >> + return dev_err_probe(dev, ret, > >> + "Trigger registration failed\n"); > >> + } else { > >> + dev_warn(dev, "No IRQ configured\n"); > > > > Why is it a warning? Either driver works without an IRQ, or it doesn't. > > dev_dbg() or dev_info() at most. > > Some of it works. Well, maybe I'll change it to tell that device works > in raw_read only mode. > > Thanks again for the help! > > Yours, > -- Matti >