Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp5621916rwr; Mon, 1 May 2023 08:26:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ52lUc6jC7VHZCsl8EsfmKXwS9KOZzisIOAdYTZwnPF9n/Wha/QTS8M0rdyZ8jYJgtROgwl X-Received: by 2002:a17:902:c94b:b0:1a8:626:6d9d with SMTP id i11-20020a170902c94b00b001a806266d9dmr18435699pla.62.1682954798736; Mon, 01 May 2023 08:26:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682954798; cv=none; d=google.com; s=arc-20160816; b=WK+21F8rvDHA98Rs3uxudZnu1noweh3Jh7YFXDK5b0YhH2BRdFDM7m5V6fc3nvquD4 lfEboOEfx8ckBBJHnczGMscQejhtwJwXOAL04s30Q41c3iQu/P1h42v3RuTB7Hz0EU5R XB6ri+wp5wshlildEB+ZmSjF26Eier3FG0aARPdZLlQsRRpInOgFt1DbaHG4dw+qpk5E M9XDxzmCIfpdrhaEIe717+CR9zml+uD06O2u1k79Szw1DVjicecZFefDlrzjOFBzUsom QT7dZFhuWrIscLFj6zD5HqLNmiI7PhANFuqOLyUBFOkldRFjLbViIpMikF58nkQ5JBWa tiow== 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=yj7JbfUhcigYwy4OCOsZthvmRkzEknnYXpNBFXl+4OA=; b=i/qxWjiBQ1M7NYnsVthNU5tv08QWjrLvzz/sgUuuQJW2R3dddiHOtC1GSIX2tjqgVS QENJgMsxAUmEtebROqXUNAcs4He5jlL+3Ck+NWsUEOJDfdez3vo9IMatwFViC4KeL66h 38b3rDV9WNtC9WZsiZM3hbayubHH1fegUInsi7mDI5iItWorU4fS/gVgBO4S4QPR7dcA XGEq3aIzY5sYQL8lTeEwVLO5aQf1GxFKdBFh0D0hXK2Kl8qY3kor+r1KD4Z9+cgxnEii Q8UIVT93PJP61tGPBvjdDaEPW3gYUTEGBSzjhIujQCQRP276tE/WM71ibflIpmUcMJLn yM8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nkvOUfde; 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 f11-20020a170902684b00b001a229e52c19si27888899pln.91.2023.05.01.08.26.26; Mon, 01 May 2023 08:26:38 -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=nkvOUfde; 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 S232255AbjEAPUj (ORCPT + 99 others); Mon, 1 May 2023 11:20:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231438AbjEAPUi (ORCPT ); Mon, 1 May 2023 11:20:38 -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 512A39D; Mon, 1 May 2023 08:20:37 -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 E0BDD60F57; Mon, 1 May 2023 15:20:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 683E0C433EF; Mon, 1 May 2023 15:20:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1682954436; bh=cXKx8RHLfWUL+DcWZDzIKJ2jk/FY5c2pwahXmdny2Gw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=nkvOUfde2tNSTHI+ibNL3QEV+eC8UCOlGBVkR0/xNaBj6oj3DTobvAah+oqDmArCP nrKq95J8NwXyFDvHS5nc6C9cdgzssZiv8PUhK0dNhDs4ksDyCA8IIdVcsx50HKHk6F MB2VKyceLVayBTP7mV/IZx8oR1VnOcFpVzzdcnBDtbB59kQAyR4ugpNUvF/1bVR9tR v7ML4lcVO473iKfrfDFdATMtd+f03cnjJ3sAbfSgn6whZrAuLauZLiY3/im2HzGwGP aBQxuzDX/mvop35k76kLSuwEBYJvpNtU+cEOzAieIe6AbfOEFro9bYB7EJJzklDDAz braydZW30U9lQ== Date: Mon, 1 May 2023 16:36:20 +0100 From: Jonathan Cameron To: Matti Vaittinen Cc: Matti Vaittinen , Lars-Peter Clausen , Andy Shevchenko , Paul Gazzillo , Shreeya Patel , Dmitry Osipenko , Zhigang Shi , linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org Subject: Re: [PATCH v1 2/3] iio: light: ROHM BU27008 color sensor Message-ID: <20230501163621.52c311b8@jic23-huawei> In-Reply-To: References: <28ace0e26267df5618fbd23625425292391ad7f0.1682067567.git.mazziesaccount@gmail.com> <20230423135706.008206da@jic23-huawei> 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.6 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 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 On Mon, 24 Apr 2023 13:14:56 +0300 Matti Vaittinen wrote: > On 4/23/23 15:57, Jonathan Cameron wrote: > > On Fri, 21 Apr 2023 12:39:36 +0300 > > Matti Vaittinen wrote: > > > >> The ROHM BU27008 is a sensor with 5 photodiodes (red, green, blue, clear > >> and IR) with four configurable channels. Red and green being always > >> available and two out of the rest three (blue, clear, IR) can be > >> selected to be simultaneously measured. Typical application is adjusting > >> LCD backlight of TVs, mobile phones and tablet PCs. > >> > >> Add initial support for the ROHM BU27008 color sensor. > >> - raw_read() of RGB and clear channels > >> - triggered buffer w/ DRDY interrtupt > >> > >> Signed-off-by: Matti Vaittinen > >> + > >> +static int bu27008_meas_set(struct bu27008_data *data, bool enable) > >> +{ > >> + if (enable) > >> + return regmap_set_bits(data->regmap, BU27008_REG_MODE_CONTROL3, > >> + BU27008_MASK_MEAS_EN); > >> + > >> + return regmap_clear_bits(data->regmap, BU27008_REG_MODE_CONTROL3, > >> + BU27008_MASK_MEAS_EN); > > > > Might be cleaner with regmap_update_bits() > > > >> +} > > Hm. I need to disagree on this although I think it depends on what one > is used to :) > > For me adding a variable for value to be used is slightly more complex > than just using clear or set function depending on the enable/disable. I > remember thinking the same as you and preferring the update_bits also on > enable/disable cases - until I wrote my first power-supply driver and > Sebasian Reichel told me to not do: > > int val; > > if (foo) > val = mask; > else > val = 0; > > return regmap_update_bits(regmap, reg, mask, val); > > but use set/clear bits. This allows killing the 'int val;'. I remember I > had to sleep over night on it but I later started seeing the set/clear > bits as a simpler thing. > > Sure we could also do > > if (foo) > return regmap_update_bits(map, reg, mask, mask); > else > return regmap_update_bits(map, reg, mask, 0); > > - but here we just replace: > > regmap_set_bits(map, reg, mask) with > regmap_update_bits(map, reg, mask, mask) > > and > > regmap_clear_bits(map, reg, mask) > regmap_update_bits(map, reg, mask, 0) > > with longer but functionally same variants - which kind of says "I think > the "regmap_set_bits() and regmap_clear_bits()" are useless ;) > > After saying this - I can use the regmap_update_bits() if you insist, > but in my (not always so) humble opinion this does not improve the function. Makes sense. Leave it as it stands. > > > >> + > >> +static int bu27008_set_drdy_irq(struct bu27008_data *data, bool state) > >> +{ > >> + if (state) > >> + return regmap_set_bits(data->regmap, BU27008_REG_MODE_CONTROL3, > >> + BU27008_MASK_INT_EN); > >> + return regmap_clear_bits(data->regmap, BU27008_REG_MODE_CONTROL3, > >> + BU27008_MASK_INT_EN); > > regmap_update_bits() maybe with the mask and value supplied. > > Same weak objection here as was with the bu27008_meas_set(). Eg, can > change if required but please reconsider :) Sure. Was a 'maybe' :) > > >> +} > >> + > >> + > >> +static irqreturn_t bu27008_irq_thread_handler(int irq, void *private) > >> +{ > >> + struct iio_dev *idev = private; > >> + struct bu27008_data *data = iio_priv(idev); > >> + irqreturn_t ret = IRQ_NONE; > >> + > >> + mutex_lock(&data->mutex); > >> + if (data->trigger_enabled) { > >> + iio_trigger_poll_nested(data->trig); > > > > Add a comment here on why it makes sense to hold the mutex whilst > > calling this. > > After revising this - I don't think it makes. Nor do I think we need the > trigger_enable flag so we don't propably need the mutex in buffer enable > either as all raw-write configs are claiming the direct mode. Clearing this out meant I noticed the oddity of doing this in the thread at all. So all good in the end ;) Jonathan