From patchwork Mon Feb 24 18:34:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13988741 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (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 8E6582661B6; Mon, 24 Feb 2025 18:34:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740422066; cv=none; b=qDbqHgmOuvxHZXFYtb5AyEXse8N9cQ+cjCOYf+FLSn5aJN/FFN4VdtuTUZEoldRTnq98ROL4eoItKTZ6JsF/yyOXP+R2Me6LUGokFOzQI/BiKUu7prH95mqwpDx/k+PSeBFkRv649j+Ejv9p729B/H5uo857PNjQVEE+RZghOBg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740422066; c=relaxed/simple; bh=ptpLCzQ6BNa0qLiSCk4X/p1uRBpcdAzC37NT2TsZkIk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JpAEdADsj6yVhZ3/Mw8Kc7I8DXnseyAbTH/ge3c0w9T/fYcu8Vh0YoxsD9q6FrJAfaXrA2s0AZzz/NG1Z35wXBvDqw0Qi0SV7p48ohrEFl2rgcjFBSVQI5+nLz6VkQxNfkn9I2e9JzbM4Guw36ABxk9yErWoD79K9RWpds9kOrE= 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=FfhfRoEX; arc=none smtp.client-ip=209.85.208.178 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="FfhfRoEX" Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-30a3092a9ebso54511471fa.1; Mon, 24 Feb 2025 10:34:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740422062; x=1741026862; 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=KGcm2bkFDPXzL23Cd0xQolPfqoEIsDRM3DUNg3w1Cy8=; b=FfhfRoEX9FiTMUtcNBXqFhAi6S1yLqp8i9Xswxpnv3hQRHnLSZax8SuRfHAH+7F+Yw HBq+NxzvGT1/lwSxN0bSqPlIPZsHK2mBXj7D7A6I8M4ngyrDWUbRqtGJEwEu/9ZscsvN CzHBEv/ynnYGHiKgcUGSzQCcIPW+hUumZZLFfZrLd3Luj0V9GxCBoY2p8HMwh5bwslZ2 XtwZ50jQXcK+VQNfTgztsJ4MuZpVovzYNjc/UWD5hzX9gunus5q7apAtlnFxMmfraHMH oUJHrdDMi2mwZHt9HbRezToYQ+6vzCE44EnhGW6OfIW9Z19ViHQyWsbQQ3Zjho1vozLs U0LQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740422062; x=1741026862; 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=KGcm2bkFDPXzL23Cd0xQolPfqoEIsDRM3DUNg3w1Cy8=; b=PqA24OKH+E7a6R2wAwLwWa4mMS9lFlletXf3a3ud+CnKq2Jm0VCdO++lYZVWQbNbHy RAGPEr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TICf43gI9GYjWMeuzoXueW9q3u78pSnVDpUV6USbgCm4lh7BA/MgvFLTVsiRfffxZ/UhS KmY0pgJ/SwUKTv9hkF+8zbGkx3kc/siYuQD927JeXmPoD6rui7rA73BqdiKbG4tuPyUx6k34/wo J0XjR4K9MOSIi5HZGXFLVTlNiDBatKvd X-Google-Smtp-Source: AGHT+IFEpds9WAAPmdXGIB+EMRIMZX8JJNMGJEFMaa6SvRSCJp+geS/XDIi8N88vVzGAieZpjJvTTw== X-Received: by 2002:a2e:8017:0:b0:300:4107:6294 with SMTP id 38308e7fff4ca-30a5b216a46mr47097571fa.35.1740422062295; Mon, 24 Feb 2025 10:34:22 -0800 (PST) Received: from mva-rohm ([2a10:a5c0:800d:dd00:8fdf:935a:2c85:d703]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-30a819e0a4fsm58811fa.2.2025.02.24.10.34.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 10:34:20 -0800 (PST) Date: Mon, 24 Feb 2025 20:34:16 +0200 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Matti Vaittinen , Lad Prabhakar , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Hugo Villeneuve , Nuno Sa , David Lechner , Javier Carrasco , Guillaume Stols , Olivier Moysan , Dumitru Ceclan , Trevor Gamblin , Matteo Martelli , Alisa-Dariana Roman , Ramona Alexandra Nechita , AngeloGioacchino Del Regno , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH v4 07/10] iio: adc: ti-ads7924: Respect device tree config Message-ID: <20dd0e4ea72fe39b90b611f9c08dbd4bc1d5217f.1740421248.git.mazziesaccount@gmail.com> References: Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The ti-ads7924 driver ignores the device-tree ADC channel specification and always exposes all 4 channels to users whether they are present in the device-tree or not. Additionally, the "reg" values in the channel nodes are ignored, although an error is printed if they are out of range. Register only the channels described in the device-tree, and use the reg property as a channel ID. Signed-off-by: Matti Vaittinen --- Revision history: v3 => v4: - Adapt to 'drop diff-channel support' changes to ADC-helpers - select ADC helpers in the Kconfig v2 => v3: New patch Please note that this is potentially breaking existing users if they have wrong values in the device-tree. I believe the device-tree should ideally be respected, and if it says device X has only one channel, then we should believe it and not register 4. Well, we don't live in the ideal world, so even though I believe this is TheRightThingToDo - it may cause havoc because correct device-tree has not been required from the day 1. So, please review and test and apply at your own risk :) As a side note, this might warrant a fixes tag but the adc-helper -stuff is hardly worth to be backported... (And I've already exceeded my time budget with this series - hence I'll leave crafting backportable fix to TI people ;) ) This has only been compile tested! All testing is highly appreciated. --- drivers/iio/adc/Kconfig | 1 + drivers/iio/adc/ti-ads7924.c | 78 ++++++++++++++++-------------------- 2 files changed, 36 insertions(+), 43 deletions(-) diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index 0993008a1586..d16082ac2e1f 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -1476,6 +1476,7 @@ config TI_ADS7924 tristate "Texas Instruments ADS7924 ADC" depends on I2C select REGMAP_I2C + select IIO_ADC_HELPER help If you say yes here you get support for Texas Instruments ADS7924 4 channels, 12-bit I2C ADC chip. diff --git a/drivers/iio/adc/ti-ads7924.c b/drivers/iio/adc/ti-ads7924.c index b1f745f75dbe..e3ac170c73f4 100644 --- a/drivers/iio/adc/ti-ads7924.c +++ b/drivers/iio/adc/ti-ads7924.c @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -119,15 +120,12 @@ #define ADS7924_TOTAL_CONVTIME_US (ADS7924_PWRUPTIME_US + ADS7924_ACQTIME_US + \ ADS7924_CONVTIME_US) -#define ADS7924_V_CHAN(_chan, _addr) { \ - .type = IIO_VOLTAGE, \ - .indexed = 1, \ - .channel = _chan, \ - .address = _addr, \ - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ - .datasheet_name = "AIN"#_chan, \ -} +static const struct iio_chan_spec ads7924_chan_template = { + .type = IIO_VOLTAGE, + .indexed = 1, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), +}; struct ads7924_data { struct device *dev; @@ -182,13 +180,6 @@ static const struct regmap_config ads7924_regmap_config = { .writeable_reg = ads7924_is_writeable_reg, }; -static const struct iio_chan_spec ads7924_channels[] = { - ADS7924_V_CHAN(0, ADS7924_DATA0_U_REG), - ADS7924_V_CHAN(1, ADS7924_DATA1_U_REG), - ADS7924_V_CHAN(2, ADS7924_DATA2_U_REG), - ADS7924_V_CHAN(3, ADS7924_DATA3_U_REG), -}; - static int ads7924_get_adc_result(struct ads7924_data *data, struct iio_chan_spec const *chan, int *val) { @@ -251,32 +242,35 @@ static const struct iio_info ads7924_info = { .read_raw = ads7924_read_raw, }; -static int ads7924_get_channels_config(struct device *dev) +static int ads7924_get_channels_config(struct iio_dev *indio_dev, + struct device *dev) { - struct fwnode_handle *node; - int num_channels = 0; + struct iio_chan_spec *chan_array; + int num_channels = 0, i; + static const char * const datasheet_names[] = { + "AIN0", "AIN1", "AIN2", "AIN3" + }; - device_for_each_child_node(dev, node) { - u32 pval; - unsigned int channel; + num_channels = devm_iio_adc_device_alloc_chaninfo_se(dev, + &ads7924_chan_template, + ARRAY_SIZE(datasheet_names) - 1, + &chan_array); - if (fwnode_property_read_u32(node, "reg", &pval)) { - dev_err(dev, "invalid reg on %pfw\n", node); - continue; - } + if (num_channels < 0) + return num_channels; - channel = pval; - if (channel >= ADS7924_CHANNELS) { - dev_err(dev, "invalid channel index %d on %pfw\n", - channel, node); - continue; - } + if (!num_channels) + return -EINVAL; - num_channels++; + for (i = 0; i < num_channels; i++) { + int ch_id = chan_array[i].channel; + + chan_array[i].address = ADS7924_DATA0_U_REG + ch_id; + chan_array[i].datasheet_name = datasheet_names[ch_id]; } - if (!num_channels) - return -EINVAL; + indio_dev->channels = chan_array; + indio_dev->num_channels = num_channels; return 0; } @@ -370,18 +364,15 @@ static int ads7924_probe(struct i2c_client *client) mutex_init(&data->lock); - indio_dev->name = "ads7924"; - indio_dev->modes = INDIO_DIRECT_MODE; - - indio_dev->channels = ads7924_channels; - indio_dev->num_channels = ARRAY_SIZE(ads7924_channels); - indio_dev->info = &ads7924_info; - - ret = ads7924_get_channels_config(dev); + ret = ads7924_get_channels_config(indio_dev, dev); if (ret < 0) return dev_err_probe(dev, ret, "failed to get channels configuration\n"); + indio_dev->name = "ads7924"; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->info = &ads7924_info; + data->regmap = devm_regmap_init_i2c(client, &ads7924_regmap_config); if (IS_ERR(data->regmap)) return dev_err_probe(dev, PTR_ERR(data->regmap), @@ -469,3 +460,4 @@ module_i2c_driver(ads7924_driver); MODULE_AUTHOR("Hugo Villeneuve "); MODULE_DESCRIPTION("Texas Instruments ADS7924 ADC I2C driver"); MODULE_LICENSE("GPL"); +MODULE_IMPORT_NS("IIO_DRIVER");