From patchwork Fri Jul 5 10:55:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13724944 Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A50F148823; Fri, 5 Jul 2024 10:55:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720176958; cv=none; b=o5v72FKXUweSJbQF+Ig7GjOQ6BAU+GX+YTn6zE6DL/TrEyKtt6bSIwXUZuyLKhyw4PmpCDJSP8dfY+UchUbqM6qSfowUovRVVZZt9EKpu1/Ph22aftA33+H8O3BFyME4ZCQOHB9dldss37ute3WNG6PmzZzIsg+yngwdNUV4rb0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720176958; c=relaxed/simple; bh=bI2hjWVgdl/diApvpjFZCaQlbk4hRekxYDSv0DqE3K8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qWXKHwhiDln/Hl9U1K4oXnbvzXPB4b8Jb7AJJTs3MtEv369hBZJ6OP/+YxX4Ytxu16nU5MzjH/fDxPFK1LPWZWHunO5GJ5d4l1MF5aNQ9IzOg5ePOHAj7PwMk81+cKSRxubOK2ZJtZBhesz+yVOE2WGl+nMcQFjPJoN/3UenWl0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IJJgLAml; arc=none smtp.client-ip=209.85.208.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IJJgLAml" Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2ec3f875e68so18353861fa.0; Fri, 05 Jul 2024 03:55:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720176955; x=1720781755; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=AhGmMPt1lObSup2GfRLJaEn/G3ib3X+5BiBDXfkwc6Y=; b=IJJgLAmlnOK+tODSrYY1lDccBN5swiAfRCIId06PpANrIb9fuYGFjsugt40/rqco2p glUPlmH/8bw4MfLoiNZLHiG9ZvpKZ0EzH26fGr7sgtRCdajonMJomrrm+VdC8BMoL5Ms iLTXNV+s6MWJhmv6rzAcSIxZjUYYUG9pNcfqloWwnW3yk6G+tXqMDsbNFExUNbksLVDI LZz2dKfytY/Jq5pnFiJgXetn3TODD6w503FDqP7PcLAeRI9szec1O6oS9PL9QG4UIK7C wkkbKZyngd+pVGwBYJqrfXJmfhe1pqfcers4j8opAWqE2n+roFpR99YQuTaflQBwRvfs s5SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720176955; x=1720781755; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=AhGmMPt1lObSup2GfRLJaEn/G3ib3X+5BiBDXfkwc6Y=; b=qGnKow8Gb+0M8qnY4NEpvq5MmkoTAY9LHpKrCpE9uqvXqraYLgsVR1nOL9GkMXB78C IhYoe8I90zheDMCZ+jWAiu3+59O1yX0rZqor2GtI7+1CdG/wQn9EsMwCFMNCzfTImDdX qAyCys1t0BjbI5aRId9ydOThoX2U72XUKE6OY9tMqg/E2Kmdi7w7IHn9gqIddkFqrjid aYpeLdUdsij7xH6lUEOl6wRSvm4mss59DcVC/czr2dXI/NAnNVoEMtstOvR9nc5gw5oS MHUKv7cQyYnrNHHc7wZI1w9ArBTPOQROK1bOgsBRQUEbaJQmERSFM7S5OT8iJ+AAUdLW cydA== X-Forwarded-Encrypted: i=1; AJvYcCVwCS8yY6qFkjAN5VjRYnvwet80a1in2SOshaEU99fhEFWwrlG1i0LDiM145Db9Zqlc2FJeEvhOuL6CupjVxE8y1GGtS+JqNrDLAqpDKkmgkE7FLz2SMQsGk593O5ByBKybz1BqReJXaWRXKmfl0FYbKJQPgT1gfH/QY+zBKNU5DnxYgg== X-Gm-Message-State: AOJu0YwrQTB4yay3Q8KyRR1Wdb9OgB7k86RkEXPbsscrv412yrWMXueN 1DeF3xn/5/y3Nog5sqjtE/Ryl50CfrCT/BLzau/oFK+lx51T7zWc X-Google-Smtp-Source: AGHT+IHcU4cGkUjrgtXjRt1PrXQ4b4FmjO1xQSJdylbp2isgPfBuBM0XvqRep2ss7UrEZ0oQwd3XtA== X-Received: by 2002:a05:6512:1096:b0:52e:a60e:3a08 with SMTP id 2adb3069b0e04-52ea60e3bfcmr1323370e87.11.1720176954368; Fri, 05 Jul 2024 03:55:54 -0700 (PDT) Received: from fedora ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52ea2f3f8c2sm321184e87.171.2024.07.05.03.55.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jul 2024 03:55:53 -0700 (PDT) Date: Fri, 5 Jul 2024 13:55:49 +0300 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matti Vaittinen , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 7/7] iio: bu27034: Add a read only HWARDWAREGAIN Message-ID: References: Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The ROHM BU27034 light sensor has two data channels for measuring different frequencies of light. The result from these channels is combined into Lux value while the raw channel values are reported via intensity channels. Both of the intensity channels have adjustable gain setting which impacts the scale of the raw channels. Eg, doubling the gain will double the values read from the raw channels, which halves the scale value. The integration time can also be set for the sensor. This does also have an impact to the scale of the intensity channels because increasing the integration time will also increase the values reported via the raw channels. Impact of integration time to the scale and the fact that the scale value does not start from '1', can make it hard for a human reader to compute the gain values based on the scale. Add read-only HARDWAREGAIN to help debugging. Signed-off-by: Matti Vaittinen --- Revision history: v1 => v2: - fix switch case fallthrough warning by adding explicit return --- drivers/iio/light/rohm-bu27034.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/iio/light/rohm-bu27034.c b/drivers/iio/light/rohm-bu27034.c index ec4f9bef83f8..76711c3cdf7c 100644 --- a/drivers/iio/light/rohm-bu27034.c +++ b/drivers/iio/light/rohm-bu27034.c @@ -148,7 +148,8 @@ static const struct iio_itime_sel_mul bu27034_itimes[] = { .type = IIO_INTENSITY, \ .channel = BU27034_CHAN_##_name, \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ - BIT(IIO_CHAN_INFO_SCALE), \ + BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_HARDWAREGAIN), \ .info_mask_separate_available = BIT(IIO_CHAN_INFO_SCALE), \ .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME), \ .info_mask_shared_by_all_available = \ @@ -989,6 +990,13 @@ static int bu27034_read_raw(struct iio_dev *idev, return IIO_VAL_INT_PLUS_MICRO; + case IIO_CHAN_INFO_HARDWAREGAIN: + ret = bu27034_get_gain(data, chan->channel, val); + if (ret) + return ret; + + return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: return bu27034_get_scale(data, chan->channel, val, val2); @@ -1033,12 +1041,17 @@ static int bu27034_write_raw_get_fmt(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, long mask) { + struct bu27034_data *data = iio_priv(indio_dev); switch (mask) { case IIO_CHAN_INFO_SCALE: return IIO_VAL_INT_PLUS_NANO; case IIO_CHAN_INFO_INT_TIME: return IIO_VAL_INT_PLUS_MICRO; + case IIO_CHAN_INFO_HARDWAREGAIN: + dev_dbg(data->dev, + "HARDWAREGAIN is read-only, use scale to set\n"); + return -EINVAL; default: return -EINVAL; }