From patchwork Mon Jul 15 18:28:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 13733801 Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 9F41810A24 for ; Mon, 15 Jul 2024 18:31:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=85.214.62.61 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721068312; cv=none; b=dtkXKoNy50v17qWrU3PyqiIkBqi9RZStfsPE0e6IEQVF3KEobxcwdj0hOx3LfoW16n2Ws2owu9zHoqEM4DVRj2yrbZCiCoAxDcvD+j/nx5SBm9tppH8X4h08FHIxm7gs91f+Ju7xQ5VERkh3VCHPCcIYkgdmYU7dqCTHjMdGIRA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721068312; c=relaxed/simple; bh=xsC13xZMRfEfQotR1WW+8Mbipsg/fVFLMFsmbftEunA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=oyIaDBu+C0VMNpUi9SWtBtK4ophA9J6LELhg0b04PM3wVDw458BHzhUGYmkWPaFVjXzmnjIt5KzTwLjvOt+kMCPEIKVdOVsl4+Cu5fDcygDB0aaYqM7L0LV9ZYWe1OXC3HCrchBgz9Ve7zAKtD2fqKqX0RLnH6sC4WUzgx/rjfo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=denx.de; spf=pass smtp.mailfrom=denx.de; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.b=EnppYMWb; arc=none smtp.client-ip=85.214.62.61 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=denx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=denx.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.b="EnppYMWb" Received: from tr.lan (ip-86-49-120-218.bb.vodafone.cz [86.49.120.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 9C3BE882B6; Mon, 15 Jul 2024 20:31:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1721068308; bh=mnrus9K1Xf/c8w61xyhTZx6TkpXikt+zrNC4hoN4vYA=; h=From:To:Cc:Subject:Date:From; b=EnppYMWbYOu4Zeb+3lR5DoQVIKhA2JYZvC61HcM3ZJT1trzByQ6vWXSo+i2gS6CbW 9ieWCRwC12hXkbsLa51Zp2CX0dRSX2P4VgQAA/lgI4uW8Nym0D8Q+arY6E0t0TEjgD LlMZFsgUaNt6B69k1Cr7QCfUa+PFWE0VYsdpJNvcmQW21ow4f1g4mwB9hlb0sE1y86 s1RTWVEZv2QbMp+Y+/TRBv7WcgGamz2dvq1sb3vOQzwz/zL44RlCap/niHwAPTmdMS Fe9kdwYLYdezxkf4nc18hrKz4Ix+Ll84xeWIV5d/ihii7j0Flgxu9EhbW5yRyxK0tU syafO/TfyeMXw== From: Marek Vasut To: linux-iio@vger.kernel.org Cc: Marek Vasut , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Jonathan Cameron , Lars-Peter Clausen Subject: [PATCH 1/5] iio: light: noa1305: Simplify noa1305_read_raw() Date: Mon, 15 Jul 2024 20:28:55 +0200 Message-ID: <20240715183120.143417-1-marex@denx.de> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean The only channel this hardware supports is IIO_LIGHT, if the channel is anything else, exit right away. The 'ret' variable is now always only assigned by noa1305_measure(), do not initialize it anymore. Update function parameter indent. No functional change. Signed-off-by: Marek Vasut --- Cc: "Uwe Kleine-König" Cc: Jonathan Cameron Cc: Lars-Peter Clausen Cc: linux-iio@vger.kernel.org --- drivers/iio/light/noa1305.c | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/drivers/iio/light/noa1305.c b/drivers/iio/light/noa1305.c index 596cc48c4c341..a76f158bb50e5 100644 --- a/drivers/iio/light/noa1305.c +++ b/drivers/iio/light/noa1305.c @@ -125,38 +125,27 @@ static const struct iio_chan_spec noa1305_channels[] = { }; static int noa1305_read_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int *val, int *val2, long mask) + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) { - int ret = -EINVAL; struct noa1305_priv *priv = iio_priv(indio_dev); + int ret; + + if (chan->type != IIO_LIGHT) + return -EINVAL; switch (mask) { case IIO_CHAN_INFO_RAW: - switch (chan->type) { - case IIO_LIGHT: - ret = noa1305_measure(priv); - if (ret < 0) - return ret; - *val = ret; - return IIO_VAL_INT; - default: - break; - } - break; + ret = noa1305_measure(priv); + if (ret < 0) + return ret; + *val = ret; + return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: - switch (chan->type) { - case IIO_LIGHT: - return noa1305_scale(priv, val, val2); - default: - break; - } - break; + return noa1305_scale(priv, val, val2); default: - break; + return -EINVAL; } - - return ret; } static const struct iio_info noa1305_info = { From patchwork Mon Jul 15 18:28:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 13733802 Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 BC09B134AB for ; Mon, 15 Jul 2024 18:31:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=85.214.62.61 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721068312; cv=none; b=e+KAlOluR5WSXL+8/7c6luS9Kp8l4TWM90GnTQ0kCYw7kpv1bRbAvdf25nlTSwIsOfI7CithcVeA3WxqLQxrOd7BQnG9D9ejwL3a8IHiq1nj4PvsYG6FEtoGYOEurTH0yKUWTrdy0bx5Kg0IwGRwAPk73Be6uA2nGFbt0g+VPFA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721068312; c=relaxed/simple; bh=H2KB7qrkxH4w+TH5Vu4rp0MG32gfZwnVpxjixsPHa0w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rtCYEzwnhGecN6y8h65Z4IOwc6ri6w2TSBpzX/K5qbZxw7t29WT/9yfTVKS374Y+CzEAwNLPOSaXqmmy66rCPjfXaZRQLLRrGgXEjemgfMyd2W4XCDENqUPUhtxlR9B2zDEYLMvZvrFpeElZZX000a2avQqdla0lO4pbFXGM1F4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=denx.de; spf=pass smtp.mailfrom=denx.de; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.b=Of0mDx/P; arc=none smtp.client-ip=85.214.62.61 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=denx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=denx.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.b="Of0mDx/P" Received: from tr.lan (ip-86-49-120-218.bb.vodafone.cz [86.49.120.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id E7B918881F; Mon, 15 Jul 2024 20:31:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1721068309; bh=dHL0+yBOHZLQ77Ys3+c+pJf+bqEOow2Q+dtAlch1/Sk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Of0mDx/PSpU+aLH/GhK4JPI0f5GWcRKF32mmZUchPV19d/kAX9ZuMzcvoSVNzxW6K gHASRCQ4Sqg7Rd9h7i8t+eJfJ2e9VWjP6wv011ffN/JqAiF2l1qct7vlrzf+O6+m9s kCgZXeFDX0qEOeqddlcI1w4HI2QOMpuwwF/fNgNvuygiTjFtD9tMRlxXHVZ+zIZfPP tYRruhiIBM0wJY+Ha75XWVHj5EUy3s6bQOYtWHsmCsH5tm7NZ6/IDAT9yDM0RLSVFR 9yG1ecg/CeqIMUwZG5c09mY3+9XKpEa1SoT+6GzUUiAbWAmEvb2qQU25wpQfadCSqa hzkOwccjXNPEA== From: Marek Vasut To: linux-iio@vger.kernel.org Cc: Marek Vasut , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Jonathan Cameron , Lars-Peter Clausen Subject: [PATCH 2/5] iio: light: noa1305: Assign val in noa1305_measure() Date: Mon, 15 Jul 2024 20:28:56 +0200 Message-ID: <20240715183120.143417-2-marex@denx.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240715183120.143417-1-marex@denx.de> References: <20240715183120.143417-1-marex@denx.de> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Make noa1305_measure() behave similar to noa1305_scale(), make it assign the 'val' output variable on success and return IIO_VAL_INT. This further simplifies noa1305_read_raw() and allows removal of ret variable altogether. Signed-off-by: Marek Vasut --- Cc: "Uwe Kleine-König" Cc: Jonathan Cameron Cc: Lars-Peter Clausen Cc: linux-iio@vger.kernel.org --- drivers/iio/light/noa1305.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/iio/light/noa1305.c b/drivers/iio/light/noa1305.c index a76f158bb50e5..a7e4c68bea09e 100644 --- a/drivers/iio/light/noa1305.c +++ b/drivers/iio/light/noa1305.c @@ -48,7 +48,7 @@ struct noa1305_priv { struct regmap *regmap; }; -static int noa1305_measure(struct noa1305_priv *priv) +static int noa1305_measure(struct noa1305_priv *priv, int *val) { __le16 data; int ret; @@ -58,7 +58,9 @@ static int noa1305_measure(struct noa1305_priv *priv) if (ret < 0) return ret; - return le16_to_cpu(data); + *val = le16_to_cpu(data); + + return IIO_VAL_INT; } static int noa1305_scale(struct noa1305_priv *priv, int *val, int *val2) @@ -129,18 +131,13 @@ static int noa1305_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long mask) { struct noa1305_priv *priv = iio_priv(indio_dev); - int ret; if (chan->type != IIO_LIGHT) return -EINVAL; switch (mask) { case IIO_CHAN_INFO_RAW: - ret = noa1305_measure(priv); - if (ret < 0) - return ret; - *val = ret; - return IIO_VAL_INT; + return noa1305_measure(priv, val); case IIO_CHAN_INFO_SCALE: return noa1305_scale(priv, val, val2); default: From patchwork Mon Jul 15 18:28:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 13733803 Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 100CA17BA4 for ; Mon, 15 Jul 2024 18:31:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=85.214.62.61 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721068312; cv=none; b=DuXnXqh+iE8zHtCI2p9N5IhDHefh4aUbRcGVGbw2M92np438idZY6TLYN4hCWKEu195KL1iwy8eLn/eFAwYC8k8slq9zFqEpE7F4cjYXm7Q0fF+is+ltdq7SheFgbYtcoCA/8eNkZMuRi9e0/rvAa+q5GBpgjjZmXiCA5QgKDB8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721068312; c=relaxed/simple; bh=KXSHF2+C99GV1LdJQzfUE+zfRxbd65PoAoxwEGL2y+8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Izrt047876O2qWZgW49c2KyQqlglmcitguK9/YaGQxjBRi4gEXR2RnFjQe5gaRt5OAWD4Jl4c42N+h8bT51jLOTTsGXItJ26YEwoDsuTnCEueuvB2DQygW57q72zGZklXxu8BQ1Zsf7mDyGfnpZr+PQC1YT8hR3utohA1WzhVzw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=denx.de; spf=pass smtp.mailfrom=denx.de; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.b=wddb+px4; arc=none smtp.client-ip=85.214.62.61 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=denx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=denx.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.b="wddb+px4" Received: from tr.lan (ip-86-49-120-218.bb.vodafone.cz [86.49.120.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 3766488855; Mon, 15 Jul 2024 20:31:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1721068309; bh=WXPc9M16AAbmrKOwgxAeooHEdh/Erv71yPITv8D14lQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wddb+px4xEux5+L2FzbtRZFv9+ZnhF+4+D7ZFvnkFeuMFvxT3DXZHEUKnKTa8KSI0 njhqNSZIO5vPlz53CR1r4XPkCNWMHCBdBUSFCilv654gI6Gc7f5Pxp8Q4qPRd+nTP8 xXCrQJilJyIdikb3uQGEQUqcm5+/deJ8dux4QamjbUHJBpcF9bFILRwGogibgfenRL 2RjcDATIgKf0sgaLCoC5wKM77/iGLI2qmQi93vDob2g0BaVoP5EbqaDR8yBTItJ+Y9 klzq7agqLsepT7Wn7C9D/UPDu3pWJ/9DwnWgvs/2u+JN2QOvaBUq7Lqs/YK2PqGmkr 2z8Rv7nZfZeGw== From: Marek Vasut To: linux-iio@vger.kernel.org Cc: Marek Vasut , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Jonathan Cameron , Lars-Peter Clausen Subject: [PATCH 3/5] iio: light: noa1305: Use static table lookup of scale values Date: Mon, 15 Jul 2024 20:28:57 +0200 Message-ID: <20240715183120.143417-3-marex@denx.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240715183120.143417-1-marex@denx.de> References: <20240715183120.143417-1-marex@denx.de> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Move scale values into a static table, perform look up of those scale values in noa1305_scale() simply by using the integration time register content as an index, because the integration time register content directly maps to the table values. Signed-off-by: Marek Vasut --- Cc: "Uwe Kleine-König" Cc: Jonathan Cameron Cc: Lars-Peter Clausen Cc: linux-iio@vger.kernel.org --- drivers/iio/light/noa1305.c | 51 +++++++++++-------------------------- 1 file changed, 15 insertions(+), 36 deletions(-) diff --git a/drivers/iio/light/noa1305.c b/drivers/iio/light/noa1305.c index a7e4c68bea09e..202a5c1bbf798 100644 --- a/drivers/iio/light/noa1305.c +++ b/drivers/iio/light/noa1305.c @@ -29,6 +29,7 @@ #define NOA1305_INTEGR_TIME_25MS 0x05 #define NOA1305_INTEGR_TIME_12_5MS 0x06 #define NOA1305_INTEGR_TIME_6_25MS 0x07 +#define NOA1305_INTEGR_TIME_MASK 0x07 #define NOA1305_REG_INT_SELECT 0x3 #define NOA1305_INT_SEL_ACTIVE_HIGH 0x01 #define NOA1305_INT_SEL_ACTIVE_LOW 0x02 @@ -43,6 +44,17 @@ #define NOA1305_DEVICE_ID 0x0519 #define NOA1305_DRIVER_NAME "noa1305" +static int noa1305_scale_available[] = { + 100, 8 * 77, /* 800 ms */ + 100, 4 * 77, /* 400 ms */ + 100, 2 * 77, /* 200 ms */ + 100, 1 * 77, /* 100 ms */ + 1000, 5 * 77, /* 50 ms */ + 10000, 25 * 77, /* 25 ms */ + 100000, 125 * 77, /* 12.5 ms */ + 1000000, 625 * 77, /* 6.25 ms */ +}; + struct noa1305_priv { struct i2c_client *client; struct regmap *regmap; @@ -78,42 +90,9 @@ static int noa1305_scale(struct noa1305_priv *priv, int *val, int *val2) * Integration Constant = 7.7 * Integration Time in Seconds */ - switch (data) { - case NOA1305_INTEGR_TIME_800MS: - *val = 100; - *val2 = 77 * 8; - break; - case NOA1305_INTEGR_TIME_400MS: - *val = 100; - *val2 = 77 * 4; - break; - case NOA1305_INTEGR_TIME_200MS: - *val = 100; - *val2 = 77 * 2; - break; - case NOA1305_INTEGR_TIME_100MS: - *val = 100; - *val2 = 77; - break; - case NOA1305_INTEGR_TIME_50MS: - *val = 1000; - *val2 = 77 * 5; - break; - case NOA1305_INTEGR_TIME_25MS: - *val = 10000; - *val2 = 77 * 25; - break; - case NOA1305_INTEGR_TIME_12_5MS: - *val = 100000; - *val2 = 77 * 125; - break; - case NOA1305_INTEGR_TIME_6_25MS: - *val = 1000000; - *val2 = 77 * 625; - break; - default: - return -EINVAL; - } + data &= NOA1305_INTEGR_TIME_MASK; + *val = noa1305_scale_available[2 * data + 0]; + *val2 = noa1305_scale_available[2 * data + 1]; return IIO_VAL_FRACTIONAL; } From patchwork Mon Jul 15 18:28:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 13733804 Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 66D4618B1A for ; Mon, 15 Jul 2024 18:31:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=85.214.62.61 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721068313; cv=none; b=CvFxHuAWSGjLiySmgQY+j5Xx3hpcbs0wHNjDybm/mOICs7u0SgdzGL1lHYn1NX/+6kl0D+0dig04n+sKvwsstyLopaGTOH7PaxROVhfrT426HqyIOj8L+OdXrv/qRgO5fkPXhpxpH3qyUNtaFBHA1tcMIHu2OqC39d3xxpk29b0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721068313; c=relaxed/simple; bh=LAlSZaW1t3R2wQuNKy/0EykdIUbijoRUH4Yy+C5m8VU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ttJq2/aztMGkyAjOlS2ErUvU34WHV1mP4XXcGKjBXdOE/HoAHBCa0gHeNuMQtgtPu34Z47AuC0k6GNhV5B9cCgxEY6oxcrgDzS6a9STtlbXisatAXdHn/zdN2t2YM20b3E012gkEUOgtevEzGGw+w7fC+qftKnj/5TlHNTq+LQ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=denx.de; spf=pass smtp.mailfrom=denx.de; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.b=XZjcJx2i; arc=none smtp.client-ip=85.214.62.61 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=denx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=denx.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.b="XZjcJx2i" Received: from tr.lan (ip-86-49-120-218.bb.vodafone.cz [86.49.120.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 7CBB48886D; Mon, 15 Jul 2024 20:31:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1721068309; bh=R2R2CWOIXwpSu+iuEJ2+zB4L0z/kJcjqBMsidcigPss=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XZjcJx2i9zViMOQcLOO6JuM7ISjTO7w+NkbYwxezLp+/H/23LHdwL1QcWqgkesscH +t/2yR/bo3f84+IS87kLZ/ppUjF6M0AQ5a6FfSiS0QOVxo6e1sQNtFXhNzt2qfqvBZ 6d3cJZtjqOZt3GegKxbbie9kjIKwEvtVxxTjcqx9JGBdKzaY0MhfnamUhg5hUli5IE qCeOT67YLNu4rEjzqnBIvk4d79FTKmZzitTvusSMJ4sp0hxZXNmLzJUYUh1t5h5tde 5Lgzm+nlJhH6oaqC8xQaMS2vXFz9K+f2LxyiszMnMJcP8jU5yn9UKvvq94vfoPmDNr GSGPLjIO8/yrQ== From: Marek Vasut To: linux-iio@vger.kernel.org Cc: Marek Vasut , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Jonathan Cameron , Lars-Peter Clausen Subject: [PATCH 4/5] iio: light: noa1305: Report available scale values Date: Mon, 15 Jul 2024 20:28:58 +0200 Message-ID: <20240715183120.143417-4-marex@denx.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240715183120.143417-1-marex@denx.de> References: <20240715183120.143417-1-marex@denx.de> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Make use of the new static table of scale values and expose available scale values via sysfs attribute of the IIO device. Signed-off-by: Marek Vasut --- Cc: "Uwe Kleine-König" Cc: Jonathan Cameron Cc: Lars-Peter Clausen Cc: linux-iio@vger.kernel.org --- drivers/iio/light/noa1305.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/iio/light/noa1305.c b/drivers/iio/light/noa1305.c index 202a5c1bbf798..e778714a942a0 100644 --- a/drivers/iio/light/noa1305.c +++ b/drivers/iio/light/noa1305.c @@ -102,9 +102,29 @@ static const struct iio_chan_spec noa1305_channels[] = { .type = IIO_LIGHT, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), + .info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SCALE), } }; +static int noa1305_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, int *type, + int *length, long mask) +{ + if (chan->type != IIO_LIGHT) + return -EINVAL; + + switch (mask) { + case IIO_CHAN_INFO_SCALE: + *vals = noa1305_scale_available; + *length = ARRAY_SIZE(noa1305_scale_available); + *type = IIO_VAL_FRACTIONAL; + return IIO_AVAIL_LIST; + default: + return -EINVAL; + } +} + static int noa1305_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) @@ -125,6 +145,7 @@ static int noa1305_read_raw(struct iio_dev *indio_dev, } static const struct iio_info noa1305_info = { + .read_avail = noa1305_read_avail, .read_raw = noa1305_read_raw, }; From patchwork Mon Jul 15 18:28:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 13733805 Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 851A031758 for ; Mon, 15 Jul 2024 18:31:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=85.214.62.61 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721068313; cv=none; b=ZK/HJi916nnQQ4+b/IqFYFhaDXsGT69+Z+dusR3Ndw5MUAWuSN0fI3xFmlPWgSo28i1j3jRSB+1Uva3T9PIEuVdsB0o49p8icdMO0PZADTX1voPc3HPWPnPw2NUn8YmTyp353IJE3M1Jex/HgbdRhAX/jl5k/hH+fwA+52yZqhs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721068313; c=relaxed/simple; bh=WvUVA4dYsnO3pT80qX0evFD4yD2/e3NkR36i8zd8KAI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fxsXIAoYnbzHhQ2gG21ByvrHsX+ogoip2yf0Df07hXag66L8rYpi+ir1wpZoMdOp5JVl34MDV/mR4UrEFVvbU2zokNl7gH0h8w0+AK06Err13eanD9Bt15+OI7QooK3KSnHHmkyULJ922waYF0DDVTKeSd8u1emlAf4UBG5+/uI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=denx.de; spf=pass smtp.mailfrom=denx.de; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.b=JRBn5QkJ; arc=none smtp.client-ip=85.214.62.61 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=denx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=denx.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.b="JRBn5QkJ" Received: from tr.lan (ip-86-49-120-218.bb.vodafone.cz [86.49.120.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id C15438887A; Mon, 15 Jul 2024 20:31:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1721068309; bh=GhPcUF0/Otf5pFSjLPvzpLNUdQ8qiLuLLnBqV4+RCaU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JRBn5QkJUbZEZg14A3T/MfvCCP0pX99SgmO6oDKoGA4wsdvPcJL9QoPVs+lwwFRl5 QaBNLd0SmUfQr91Y7so1msXysLSAGrbt4Fnfv7zDGzEJ68feT++NPIKuO5wTWATXnp 7y1zIEnZPdGNMvz4/EujV6sn1hCHVtRvB3j/q2G9w1/N9XhhPqvfeQxN0XIdIGP39S 5iXyttMsmgu347H7+aSiuzmzNrc1Eh6KBpG00xXfRzCZEk6Wdw1JNbsr93Q+jj19OE TVg6toOxFWbDxzdf1v0K5Kr8PFv3TL39Q+vym5NBxkStKDVeu9neTZ1H4QIDWzmE0u Yxb1y4qIUYGHg== From: Marek Vasut To: linux-iio@vger.kernel.org Cc: Marek Vasut , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Jonathan Cameron , Lars-Peter Clausen Subject: [PATCH 5/5] iio: light: noa1305: Make integration time configurable Date: Mon, 15 Jul 2024 20:28:59 +0200 Message-ID: <20240715183120.143417-5-marex@denx.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240715183120.143417-1-marex@denx.de> References: <20240715183120.143417-1-marex@denx.de> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add another attribute which is the integration time. Report available integration time settings, support read of integration time currently configured in hardware, and support configuration of integration time into hardware. Signed-off-by: Marek Vasut --- Cc: "Uwe Kleine-König" Cc: Jonathan Cameron Cc: Lars-Peter Clausen Cc: linux-iio@vger.kernel.org --- drivers/iio/light/noa1305.c | 61 +++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/drivers/iio/light/noa1305.c b/drivers/iio/light/noa1305.c index e778714a942a0..da83425fd9100 100644 --- a/drivers/iio/light/noa1305.c +++ b/drivers/iio/light/noa1305.c @@ -55,6 +55,17 @@ static int noa1305_scale_available[] = { 1000000, 625 * 77, /* 6.25 ms */ }; +static int noa1305_int_time_available[] = { + 0, 800000, /* 800 ms */ + 0, 400000, /* 400 ms */ + 0, 200000, /* 200 ms */ + 0, 100000, /* 100 ms */ + 0, 50000, /* 50 ms */ + 0, 25000, /* 25 ms */ + 0, 12500, /* 12.5 ms */ + 0, 6250, /* 6.25 ms */ +}; + struct noa1305_priv { struct i2c_client *client; struct regmap *regmap; @@ -97,12 +108,30 @@ static int noa1305_scale(struct noa1305_priv *priv, int *val, int *val2) return IIO_VAL_FRACTIONAL; } +static int noa1305_int_time(struct noa1305_priv *priv, int *val, int *val2) +{ + int data; + int ret; + + ret = regmap_read(priv->regmap, NOA1305_REG_INTEGRATION_TIME, &data); + if (ret < 0) + return ret; + + data &= NOA1305_INTEGR_TIME_MASK; + *val = noa1305_int_time_available[2 * data + 0]; + *val2 = noa1305_int_time_available[2 * data + 1]; + + return IIO_VAL_INT_PLUS_MICRO; +} + static const struct iio_chan_spec noa1305_channels[] = { { .type = IIO_LIGHT, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), .info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SCALE), + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME), + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME), } }; @@ -120,6 +149,11 @@ static int noa1305_read_avail(struct iio_dev *indio_dev, *length = ARRAY_SIZE(noa1305_scale_available); *type = IIO_VAL_FRACTIONAL; return IIO_AVAIL_LIST; + case IIO_CHAN_INFO_INT_TIME: + *vals = noa1305_int_time_available; + *length = ARRAY_SIZE(noa1305_int_time_available); + *type = IIO_VAL_INT_PLUS_MICRO; + return IIO_AVAIL_LIST; default: return -EINVAL; } @@ -139,14 +173,41 @@ static int noa1305_read_raw(struct iio_dev *indio_dev, return noa1305_measure(priv, val); case IIO_CHAN_INFO_SCALE: return noa1305_scale(priv, val, val2); + case IIO_CHAN_INFO_INT_TIME: + return noa1305_int_time(priv, val, val2); default: return -EINVAL; } } +static int noa1305_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + struct noa1305_priv *priv = iio_priv(indio_dev); + int i; + + if (chan->type != IIO_LIGHT) + return -EINVAL; + + if (mask != IIO_CHAN_INFO_INT_TIME) + return -EINVAL; + + if (val) /* >= 1s integration time not supported */ + return -EINVAL; + + /* Look up integration time register settings and write it if found. */ + for (i = 0; i < ARRAY_SIZE(noa1305_int_time_available); i++) + if (noa1305_int_time_available[2 * i + 1] == val2) + return regmap_write(priv->regmap, NOA1305_REG_INTEGRATION_TIME, i); + + return -EINVAL; +} + static const struct iio_info noa1305_info = { .read_avail = noa1305_read_avail, .read_raw = noa1305_read_raw, + .write_raw = noa1305_write_raw, }; static bool noa1305_writable_reg(struct device *dev, unsigned int reg)