From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.208.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794131002; b=QI7p9wJ2o3PyjwOcaLteQaHzDdZynwQiyJjQbwy6x6HgqI/puttLC51py/sHCDHHKGDW fDAJe0k4rrdHR1IeACrIRQKn0Ymb9HRpSyGwDxGQUbiQUyGKOdGof+zt1heO483G8HOjw bdtgEgkCuexDZLlY1vQWap7Dj8QxG7277tZrofxdcrkCPH4D4YIrPNYSEoaa2cCWYNGej ThFK1PsFL14AXJgn2pedXbl3Yjji6cEmfE06EaSmiZSweNPJ4lJqVCoY9RWv17uZovJ1V krCggLn2GF8/N++a+CbZM6nTLwdKGUUYuvwgcI+Qnnk4e+a4+r8ngobl7/LH2P8wJNg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794131002; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=zATDjvi0ueP4ucWse6X9jXoZiNkvGsfI7v1aTgEFm+4=; b=3W8+kT4vs3Ad/RJ3XYFD13RpMZlP5/QSV4PNUqosonnFOwHaXEINFmucT5u7yHOwWcmq usj0576nVjgjZDLh+Bq4lZh4ri+dC2sYpPWpx4MGi+4xh4qnuNu+2AvMDuIrYkwpq9gPr 9Mv65wswkUDn9hiuaPlhogcaCvHdnK1FmkrNbguhDMnbppaS21kEgAodpIVrviZ+fMLSD QLKjqHQpALdlVLTCgVnwEmmOpZe9CN0wg5y+DfyA91IAwMPjRcEaF5a8cWc0vX0wX2fmF 1mYahISQarh4MaxZNop6YAzBzksGiL01CoNcYOTdzZ4lYCDZH0sBJUZcdWteuNzXVvw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=u6p8wtb9; arc=none smtp.remote-ip=209.85.208.47 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E8D2606D801 for ; Sun, 8 Nov 2026 09:43:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6E8D2606D801 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.a=rsa-sha256 header.s=20260707 header.b=u6p8wtb9 Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-6b70d5b07faso15581a12.0 for ; Sun, 08 Nov 2026 01:43:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794131000; x=1794735800; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=zATDjvi0ueP4ucWse6X9jXoZiNkvGsfI7v1aTgEFm+4=; b=u6p8wtb9fGXkf1QKwGVd3g69+9r04WtTaYtjfGj7wq4qgRW/X+UN/lSqD5TxyLeRpT US5wOzpyna4Juh9NH/EJdadRj1Cxk6Roc1MxQW8aPfYQZOVVSciJd3hCaqR1LiLUB2Ei Ow9WXKJXacJawdejKJ+0dO8shVKOKvUzUJL67ca/Cb+42PAjCC86e7zRFpRSx8qcI86F Ppj6LIVCirt/lr0/HBNjFJ8lMetYn0/m4t2aBp0HmTAktV1xNEp4Xgim3z9rwhCmLLF0 XxfjfHP0aN2qm5dkiNHcJOUTBCUGCBYe7B9I2ZW7oA3AMhM5+f/Chdie3/SwKXPSlhkE XBVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794131000; x=1794735800; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=zATDjvi0ueP4ucWse6X9jXoZiNkvGsfI7v1aTgEFm+4=; b=lFN/ZqtIqlEuxbGSSNW38rbwN3lltFeOOxXsFGbKy+wWZG0oos+4olv//KKcxnRlim 9AGq3IBrQZgpo6dpuPB788twB4a0QpU7ZXaGHtNryuA8gpVyqJL06gc8bUVDtqu8BRjw CckDUPWWqfPcq8YtJGHV2FUwFQj3JnQN8rLH4/R2jX/rDsKsC8IsZ1KzXT5zHMacCp6x gPAa8I87qOIYXtPUhrLU4XfnHw/MMtwfK8iVak5IxoXDyiqj6fYy2tEYsPtGFnOIJ543 h5iz2Mg7ltFfddccO3HGJ1IrkgdvzOJWllryrYNNVpFO4XSM3da5dPUmbR6pUN0gh7oV qrng== X-Forwarded-Encrypted: i=1; AL+hErGF3g6T67MY4T7gc5uDneN5RCom/AntqbBqQZs/achnTAZ5cqv3cNQBfGvJK/ZpUNywEkfwQd0CPPg/@vger.kernel.org X-Gm-Message-State: APuU4Z+cCKCtCcTLqMAe425NxjYjrGfFdeDEBh2qqM4SgumngeriiIby ZwBUcy86++V+8h8pbGR4ib6sRi2Dbwd0/p6vpdnRUBtKdLaWtOOEytXK X-Gm-Gg: AYBFou32eiwAviPBfMgcdE9LkZribKu2WlpzaZnaMIT9euBMQjl6X2XsZaDpn++JFt2 +hkduaRTuObtQ+Hu8APqDkIDHyhaSnBsVV4waw3CZjM/d4FDkmW2yxExE0ginrEmduAq9QSfnX5 xQQQzAe6Jsjzse1B1mFNyFO8q7IxGkTdKnKt71xDFtJaGk/lbjqtkgBzOiGqctxJZ3210w50XLA mR/+E2Oo6JEfP4Jko+XS7gPgKPG22yu5Y+YKxV4Ofg2My4g4Q0MGsVAb75ZgN996735LUurqQwY N+geJclWixUqsUOFkoxJDyn6vcxNWCo+P/htxMUlcKC6ZhnWnDI8WgE6LxiPiYK0xf+IKdh4oHy L2GgB/7AHDlxDUnr1fBw8jwD/GLIS+JUisQUPrGVSt8Wph+syxLOs+FySi/86fvTtu7upmAmmgx agBLLFCTkmOZvyrBaepfye2ncE06dLe7+slPL3fl1BfZDdVz2gqK36GuU/XLZiPEcDR1t7JBTue JB7qcOeEFGgdOoseKeE0cgmKXNEmUTAlZc+UdeltYnrvKK+x8QQ4GrrGBxAgzKQpJGnTDLge4Sk aGt3p4r0g2VBU6T19vTarfSJizVzQ0rAXFI+NJwoT3NycWZvOohmhRazSRZPzcEFSW+VD50B5bL 8sDZwhcZ3qA== X-Received: by 2002:a05:6402:1ece:b0:6b5:6546:f7f2 with SMTP id 4fb4d7f45d1cf-6b722462a1cmr546791a12.37.1794130999707; Sun, 08 Nov 2026 01:43:19 -0800 (PST) Received: from xeon ([188.163.112.62]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6b721ea56f2sm436321a12.8.2026.11.08.01.43.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Nov 2026 01:43:17 -0800 (PST) From: Svyatoslav Ryhel To: Jonathan Cameron , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Esben Haabendal , Kuppuswamy Sathyanarayanan , Svyatoslav Ryhel , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig=20=28The=20Capable=20Hub=29?= , Pan Chuang , Hemanth Selam , Antoniu Miclaus , Nikita Travkin Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/4] iio: light: ltr501: Switch to read_avail() op from manual attribute registration Date: Sun, 8 Nov 2026 11:42:50 +0200 Message-ID: <20261108094253.83899-2-clamor95@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261108094253.83899-1-clamor95@gmail.com> References: <20261108094253.83899-1-clamor95@gmail.com> X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Switch to the read_avail() operation from manual attribute group registration. This eliminates the need for per-chip attribute_group structures and related ltr501_chip_info iio_info entries. Adjust LTR501_INTENSITY_CHANNEL to account for the new info_mask_*_available layout, allowing the removal of _shared since all intensity channels share the same layout of available entries. Signed-off-by: Svyatoslav Ryhel --- drivers/iio/light/ltr501.c | 192 +++++++++++++++---------------------- 1 file changed, 76 insertions(+), 116 deletions(-) diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c index 302be2fc314c5..1ddd0dfd55ea2 100644 --- a/drivers/iio/light/ltr501.c +++ b/drivers/iio/light/ltr501.c @@ -133,6 +133,22 @@ static const struct ltr501_gain ltr559_ps_gain_tbl[] = { {0, 15624}, }; +static const int int_time_avail[] = { + 0, 50000, + 0, 100000, + 0, 200000, + 0, 400000 +}; + +static const int samp_freq_avail[] = { + 20, 0, + 10, 0, + 5, 0, + 2, 0, + 1, 0, + 0, 500000 +}; + struct ltr501_chip_info { u8 partid; const struct ltr501_gain *als_gain; @@ -145,8 +161,6 @@ struct ltr501_chip_info { bool no_irq_support; struct iio_chan_spec const *channels; const int no_channels; - const struct iio_info *info; - const struct iio_info *info_no_irq; }; struct ltr501_data { @@ -582,14 +596,18 @@ static const struct iio_event_spec ltr501_pxs_event_spec[] = { }, }; -#define LTR501_INTENSITY_CHANNEL(_idx, _addr, _mod, _shared, \ - _evspec, _evsize) { \ +#define LTR501_INTENSITY_CHANNEL(_idx, _addr, _mod, _evspec, _evsize) { \ .type = IIO_INTENSITY, \ .modified = 1, \ .address = (_addr), \ .channel2 = (_mod), \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ - .info_mask_shared_by_type = (_shared), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_INT_TIME) | \ + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME) | \ + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ .scan_index = (_idx), \ .scan_type = { \ .sign = 'u', \ @@ -609,19 +627,18 @@ static const struct iio_event_spec ltr501_pxs_event_spec[] = { static const struct iio_chan_spec ltr501_channels[] = { LTR501_LIGHT_CHANNEL(), - LTR501_INTENSITY_CHANNEL(0, LTR501_ALS_DATA0, IIO_MOD_LIGHT_BOTH, 0, + LTR501_INTENSITY_CHANNEL(0, LTR501_ALS_DATA0, IIO_MOD_LIGHT_BOTH, ltr501_als_event_spec, ARRAY_SIZE(ltr501_als_event_spec)), - LTR501_INTENSITY_CHANNEL(1, LTR501_ALS_DATA1, IIO_MOD_LIGHT_IR, - BIT(IIO_CHAN_INFO_SCALE) | - BIT(IIO_CHAN_INFO_INT_TIME) | - BIT(IIO_CHAN_INFO_SAMP_FREQ), - NULL, 0), + LTR501_INTENSITY_CHANNEL(1, LTR501_ALS_DATA1, IIO_MOD_LIGHT_IR, NULL, 0), { .type = IIO_PROXIMITY, .address = LTR501_PS_DATA, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + .info_mask_separate_available = BIT(IIO_CHAN_INFO_SCALE), + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME) | + BIT(IIO_CHAN_INFO_SAMP_FREQ), .scan_index = 2, .scan_type = { .sign = 'u', @@ -638,14 +655,10 @@ static const struct iio_chan_spec ltr501_channels[] = { static const struct iio_chan_spec ltr301_channels[] = { LTR501_LIGHT_CHANNEL(), - LTR501_INTENSITY_CHANNEL(0, LTR501_ALS_DATA0, IIO_MOD_LIGHT_BOTH, 0, + LTR501_INTENSITY_CHANNEL(0, LTR501_ALS_DATA0, IIO_MOD_LIGHT_BOTH, ltr501_als_event_spec, ARRAY_SIZE(ltr501_als_event_spec)), - LTR501_INTENSITY_CHANNEL(1, LTR501_ALS_DATA1, IIO_MOD_LIGHT_IR, - BIT(IIO_CHAN_INFO_SCALE) | - BIT(IIO_CHAN_INFO_INT_TIME) | - BIT(IIO_CHAN_INFO_SAMP_FREQ), - NULL, 0), + LTR501_INTENSITY_CHANNEL(1, LTR501_ALS_DATA1, IIO_MOD_LIGHT_IR, NULL, 0), IIO_CHAN_SOFT_TIMESTAMP(2), }; @@ -1111,111 +1124,67 @@ static int ltr501_write_event_config(struct iio_dev *indio_dev, return -EINVAL; } -static ssize_t ltr501_show_proximity_scale_avail(struct device *dev, - struct device_attribute *attr, - char *buf) +static int ltr501_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, int *type, int *length, long mask) { - struct ltr501_data *data = iio_priv(dev_to_iio_dev(dev)); + struct ltr501_data *data = iio_priv(indio_dev); const struct ltr501_chip_info *info = data->chip_info; - ssize_t len = 0; - int i; - - for (i = 0; i < info->ps_gain_tbl_size; i++) { - if (info->ps_gain[i].scale == LTR501_RESERVED_GAIN) - continue; - len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%06d ", - info->ps_gain[i].scale, - info->ps_gain[i].uscale); - } - buf[len - 1] = '\n'; + switch (mask) { + case IIO_CHAN_INFO_SCALE: + if (chan->type == IIO_INTENSITY) { + int valid_als_gains[ARRAY_SIZE(ltr559_als_gain_tbl) * 2]; + int j = 0; + + for (int i = 0; i < info->als_gain_tbl_size; i++) { + if (info->als_gain[i].scale == LTR501_RESERVED_GAIN) + continue; + + valid_als_gains[j++] = info->als_gain[i].scale; + valid_als_gains[j++] = info->als_gain[i].uscale; + } + + *length = j; + *vals = (const int *)valid_als_gains; + } else { + *length = info->ps_gain_tbl_size * 2; + *vals = (const int *)info->ps_gain; + } + *type = IIO_VAL_INT_PLUS_MICRO; + return IIO_AVAIL_LIST; - return len; -} + case IIO_CHAN_INFO_INT_TIME: + *vals = int_time_avail; + *type = IIO_VAL_INT_PLUS_MICRO; + *length = ARRAY_SIZE(int_time_avail); + return IIO_AVAIL_LIST; -static ssize_t ltr501_show_intensity_scale_avail(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct ltr501_data *data = iio_priv(dev_to_iio_dev(dev)); - const struct ltr501_chip_info *info = data->chip_info; - ssize_t len = 0; - int i; + case IIO_CHAN_INFO_SAMP_FREQ: + *vals = samp_freq_avail; + *type = IIO_VAL_INT_PLUS_MICRO; + *length = ARRAY_SIZE(samp_freq_avail); + return IIO_AVAIL_LIST; - for (i = 0; i < info->als_gain_tbl_size; i++) { - if (info->als_gain[i].scale == LTR501_RESERVED_GAIN) - continue; - len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%06d ", - info->als_gain[i].scale, - info->als_gain[i].uscale); + default: + return -EINVAL; } - - buf[len - 1] = '\n'; - - return len; } -static IIO_CONST_ATTR_INT_TIME_AVAIL("0.05 0.1 0.2 0.4"); -static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("20 10 5 2 1 0.5"); - -static IIO_DEVICE_ATTR(in_proximity_scale_available, S_IRUGO, - ltr501_show_proximity_scale_avail, NULL, 0); -static IIO_DEVICE_ATTR(in_intensity_scale_available, S_IRUGO, - ltr501_show_intensity_scale_avail, NULL, 0); - -static struct attribute *ltr501_attributes[] = { - &iio_dev_attr_in_proximity_scale_available.dev_attr.attr, - &iio_dev_attr_in_intensity_scale_available.dev_attr.attr, - &iio_const_attr_integration_time_available.dev_attr.attr, - &iio_const_attr_sampling_frequency_available.dev_attr.attr, - NULL -}; - -static struct attribute *ltr301_attributes[] = { - &iio_dev_attr_in_intensity_scale_available.dev_attr.attr, - &iio_const_attr_integration_time_available.dev_attr.attr, - &iio_const_attr_sampling_frequency_available.dev_attr.attr, - NULL -}; - -static const struct attribute_group ltr501_attribute_group = { - .attrs = ltr501_attributes, -}; - -static const struct attribute_group ltr301_attribute_group = { - .attrs = ltr301_attributes, -}; - static const struct iio_info ltr501_info_no_irq = { .read_raw = ltr501_read_raw, .write_raw = ltr501_write_raw, - .attrs = <r501_attribute_group, + .read_avail = ltr501_read_avail, }; static const struct iio_info ltr501_info = { .read_raw = ltr501_read_raw, .write_raw = ltr501_write_raw, - .attrs = <r501_attribute_group, - .read_event_value = <r501_read_event, - .write_event_value = <r501_write_event, - .read_event_config = <r501_read_event_config, - .write_event_config = <r501_write_event_config, -}; - -static const struct iio_info ltr301_info_no_irq = { - .read_raw = ltr501_read_raw, - .write_raw = ltr501_write_raw, - .attrs = <r301_attribute_group, -}; - -static const struct iio_info ltr301_info = { - .read_raw = ltr501_read_raw, - .write_raw = ltr501_write_raw, - .attrs = <r301_attribute_group, - .read_event_value = <r501_read_event, - .write_event_value = <r501_write_event, - .read_event_config = <r501_read_event_config, - .write_event_config = <r501_write_event_config, + .read_avail = ltr501_read_avail, + .read_event_value = <r501_read_event, + .write_event_value = <r501_write_event, + .read_event_config = <r501_read_event_config, + .write_event_config = <r501_write_event_config, }; static const struct ltr501_chip_info ltr501_chip_info_tbl[] = { @@ -1226,8 +1195,6 @@ static const struct ltr501_chip_info ltr501_chip_info_tbl[] = { .als_mode_active = BIT(0) | BIT(1), .als_gain_mask = BIT(3), .als_gain_shift = 3, - .info = <r301_info, - .info_no_irq = <r301_info_no_irq, .channels = ltr301_channels, .no_channels = ARRAY_SIZE(ltr301_channels), }, @@ -1238,8 +1205,6 @@ static const struct ltr501_chip_info ltr501_chip_info_tbl[] = { .als_mode_active = BIT(0), .als_gain_mask = BIT(2) | BIT(3) | BIT(4), .als_gain_shift = 2, - .info = <r301_info, - .info_no_irq = <r301_info_no_irq, .channels = ltr301_channels, .no_channels = ARRAY_SIZE(ltr301_channels), }, @@ -1251,7 +1216,6 @@ static const struct ltr501_chip_info ltr501_chip_info_tbl[] = { .als_gain_mask = BIT(2) | BIT(3) | BIT(4), .als_gain_shift = 2, .no_irq_support = true, - .info_no_irq = <r301_info_no_irq, .channels = ltr301_channels, .no_channels = ARRAY_SIZE(ltr301_channels), }, @@ -1264,8 +1228,6 @@ static const struct ltr501_chip_info ltr501_chip_info_tbl[] = { .als_mode_active = BIT(0) | BIT(1), .als_gain_mask = BIT(3), .als_gain_shift = 3, - .info = <r501_info, - .info_no_irq = <r501_info_no_irq, .channels = ltr501_channels, .no_channels = ARRAY_SIZE(ltr501_channels), }, @@ -1278,8 +1240,6 @@ static const struct ltr501_chip_info ltr501_chip_info_tbl[] = { .als_mode_active = BIT(0), .als_gain_mask = BIT(2) | BIT(3) | BIT(4), .als_gain_shift = 2, - .info = <r501_info, - .info_no_irq = <r501_info_no_irq, .channels = ltr501_channels, .no_channels = ARRAY_SIZE(ltr501_channels), }, @@ -1548,7 +1508,7 @@ static int ltr501_probe(struct i2c_client *client) &data->near_level)) data->near_level = 0; - indio_dev->info = data->chip_info->info; + indio_dev->info = <r501_info; indio_dev->channels = data->chip_info->channels; indio_dev->num_channels = data->chip_info->no_channels; indio_dev->name = name; @@ -1573,7 +1533,7 @@ static int ltr501_probe(struct i2c_client *client) if (ret) goto powerdown_on_error; } else { - indio_dev->info = data->chip_info->info_no_irq; + indio_dev->info = <r501_info_no_irq; } ret = iio_triggered_buffer_setup(indio_dev, NULL, -- 2.53.0