From nobody Sun Nov 24 05:49:20 2024 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (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 6C22F1CACEB for ; Thu, 21 Nov 2024 10:18:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732184310; cv=none; b=SiRi4P+QNfFUDSBRxfToJQVyPw4AEOHuNGfyqWpuDDCI305WaWxiKwuIBj1tYnUc0t9vhm7SCtuOuS2gwZ8mfr8sZiwOcwtFQBAU+ps5HE5eyfUr8VZfE+k+XOjPtO/GVb1D6tZT/bpPZT4WQZ4fFKr23GhcuLSdkVRR5ClZr4k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732184310; c=relaxed/simple; bh=PHTMCmT/JNZAJ8tBmAYl1/C8jdAsP/TB/pJeHR93ts4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VxQaE9d9DC2EXBkTdkgo6clEr3UD/xLNc5SMXT+7ljqnx6LjpO3XhLF5PBKagaVJ0Q/2b3dLL6EQxgJDM6QoC7rc9kr/UC19sfQYDzEe0DRGsSE1ZshI9YHIM25jmw33k1NSHfSe09sFePynxB5z9qeU2wM3AIWsPk54FW68fqo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=mC/aZ5xE; arc=none smtp.client-ip=209.85.221.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="mC/aZ5xE" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-3823eaad37aso1174090f8f.0 for ; Thu, 21 Nov 2024 02:18:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1732184307; x=1732789107; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=wTw0R04K1dGYu7GZvOewojhPzbOYqmqS+JgRfKTlmyU=; b=mC/aZ5xEZa5lpkmp0ufrWraHWE4t/8v2jtPhBx5AAKDKIs+HsYpcopOZc2ttfuqu6J lK6RvvTLT8YE2lbcWDQeIwlVIDa8he7TpOuJgQ34B9elowvT1KE+l5/vZ5I/6oUMG7jx emqppFjbriG4WKzVfCS8ed4nM0tGH1ozhYTM+2v8FzmH9Ldhal/LIP9e1epVckxseedz O25sUFT8JhJfjgvi8Kp5fwzfpWqCswZ/E/Vm2otaj+Rhj05fEvme4vJof9V2Yb595Cgs CsN8hVtfiSsnuo1UaaErE4GAOTxHzkzhMXGCwrxGx46j+ZVsy2+Y+7gymMHcS9mZOcuK rH+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732184307; x=1732789107; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wTw0R04K1dGYu7GZvOewojhPzbOYqmqS+JgRfKTlmyU=; b=YtOX92lnmOIy+NubhzSQykroRwNZqbSGfkMODa758F/z5yuzLP1IxG5ntevatIJVow lNyK6NjhS6XxwFehIl0H99Qw8615i7f3fEvPSlEMY3/tFtJcsr4wpnt4/OhCo5tvRFPM SnwQv+5xl4MFL8KdPn2KbhSccJEEKaEfVsFtJnYupdDTCRGMcehG4rtDTzeF7s5fjIOs q8hASpiqnAKQgSjbMm9CCzOtf6jc6Oxd5npIObDYmG//avex1nFD5nqF9gaOHiDy0Qbu tswYXWmgUMJjsfvoeCW5payMIsVXkm5m3wqnasD34/X6a6cv5vZI1CFADfUxL9kkk/fE 50SA== X-Forwarded-Encrypted: i=1; AJvYcCWXARvxtkm9qcAUhVXQM3kZT27wpsz0Q4jrVw+kBKRWoXWuN2UzkP+ifru6y5st/nj7dc3LEhqEHxggrnI=@vger.kernel.org X-Gm-Message-State: AOJu0YwGzleS/GqzwGXxL7ug3p8MQtYGbrGfawELnR9d7AiXHxXkJjXR 8IgLij0KkGbizt8vK65GbeauRqAOG75lRiRnP1lebg5/k8n9V5D3WgZleIKpVDt2UCgqmIz1052 F X-Google-Smtp-Source: AGHT+IEg8IFzn3kj3RMQfK+MJs5HdLwVjqD+5w0EG73Mt48p4SY/LUesRPiI/nAD6+HIn5imewwmJA== X-Received: by 2002:a5d:64a1:0:b0:382:2e9e:d695 with SMTP id ffacd0b85a97d-38259d257cdmr2408842f8f.24.1732184306398; Thu, 21 Nov 2024 02:18:26 -0800 (PST) Received: from [127.0.1.1] (frhb82016ds.ikexpress.com. [185.246.87.17]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38254910796sm4598065f8f.47.2024.11.21.02.18.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 02:18:26 -0800 (PST) From: Guillaume Stols Date: Thu, 21 Nov 2024 10:18:23 +0000 Subject: [PATCH 1/9] iio: adc: ad7606: Fix hardcoded offset in the ADC channels Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-ad7606_add_iio_backend_software_mode-v1-1-8a693a5e3fa9@baylibre.com> References: <20241121-ad7606_add_iio_backend_software_mode-v1-0-8a693a5e3fa9@baylibre.com> In-Reply-To: <20241121-ad7606_add_iio_backend_software_mode-v1-0-8a693a5e3fa9@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Nuno Sa , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Hennerich , devicetree@vger.kernel.org, dlechner@baylibre.com, jstephan@baylibre.com, aardelean@baylibre.com, adureghello@baylibre.com, Guillaume Stols X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1732184304; l=7242; i=gstols@baylibre.com; s=20240417; h=from:subject:message-id; bh=PHTMCmT/JNZAJ8tBmAYl1/C8jdAsP/TB/pJeHR93ts4=; b=ZmGA8QbDH3UwfSxgRpRSWkutaJ1SlCH/WmEyCZ3Z1k7EUK4FTc40yhCysNFl3infgFdAfMMqG +m25KauyEgeDygXSTxgTe3vXze7AWrrAbmaSsYl6KXCp8eZ2rp/jlNq X-Developer-Key: i=gstols@baylibre.com; a=ed25519; pk=XvMm5WHuV67sGYOJZqIYzXndbaJOlNd8Q6li6vnb4Cs= When introducing num_adc_channels, I overlooked some new functions created in a meanwhile that had also the hardcoded offset. This commit adds the new logic to these functions. Fixes: 7a671afeb592 ("iio: adc: ad7606: Introduce num_adc_channels") Signed-off-by: Guillaume Stols --- drivers/iio/adc/ad7606.c | 48 ++++++++++++++++++++++++++++----------------= ---- drivers/iio/adc/ad7606.h | 2 +- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index 8b2046baaa3e..893b93b86aa7 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -175,17 +175,17 @@ static const struct iio_chan_spec ad7616_channels[] = =3D { AD7606_CHANNEL(15, 16), }; =20 -static int ad7606c_18bit_chan_scale_setup(struct ad7606_state *st, +static int ad7606c_18bit_chan_scale_setup(struct iio_dev *indio_dev, struct iio_chan_spec *chan, int ch); -static int ad7606c_16bit_chan_scale_setup(struct ad7606_state *st, +static int ad7606c_16bit_chan_scale_setup(struct iio_dev *indio_dev, struct iio_chan_spec *chan, int ch); -static int ad7606_16bit_chan_scale_setup(struct ad7606_state *st, +static int ad7606_16bit_chan_scale_setup(struct iio_dev *indio_dev, struct iio_chan_spec *chan, int ch); -static int ad7607_chan_scale_setup(struct ad7606_state *st, +static int ad7607_chan_scale_setup(struct iio_dev *indio_dev, struct iio_chan_spec *chan, int ch); -static int ad7608_chan_scale_setup(struct ad7606_state *st, +static int ad7608_chan_scale_setup(struct iio_dev *indio_dev, struct iio_chan_spec *chan, int ch); -static int ad7609_chan_scale_setup(struct ad7606_state *st, +static int ad7609_chan_scale_setup(struct iio_dev *indio_dev, struct iio_chan_spec *chan, int ch); =20 const struct ad7606_chip_info ad7605_4_info =3D { @@ -323,9 +323,10 @@ int ad7606_reset(struct ad7606_state *st) } EXPORT_SYMBOL_NS_GPL(ad7606_reset, IIO_AD7606); =20 -static int ad7606_16bit_chan_scale_setup(struct ad7606_state *st, +static int ad7606_16bit_chan_scale_setup(struct iio_dev *indio_dev, struct iio_chan_spec *chan, int ch) { + struct ad7606_state *st =3D iio_priv(indio_dev); struct ad7606_chan_scale *cs =3D &st->chan_scales[ch]; =20 if (!st->sw_mode_en) { @@ -345,10 +346,12 @@ static int ad7606_16bit_chan_scale_setup(struct ad760= 6_state *st, return 0; } =20 -static int ad7606_get_chan_config(struct ad7606_state *st, int ch, +static int ad7606_get_chan_config(struct iio_dev *indio_dev, int ch, bool *bipolar, bool *differential) { - unsigned int num_channels =3D st->chip_info->num_channels - 1; + struct ad7606_state *st =3D iio_priv(indio_dev); + unsigned int num_channels =3D st->chip_info->num_adc_channels; + unsigned int offset =3D indio_dev->num_channels - st->chip_info->num_adc_= channels; struct device *dev =3D st->dev; int ret; =20 @@ -364,7 +367,7 @@ static int ad7606_get_chan_config(struct ad7606_state *= st, int ch, continue; =20 /* channel number (here) is from 1 to num_channels */ - if (reg =3D=3D 0 || reg > num_channels) { + if (reg < offset || reg > num_channels) { dev_warn(dev, "Invalid channel number (ignoring): %d\n", reg); continue; @@ -399,9 +402,10 @@ static int ad7606_get_chan_config(struct ad7606_state = *st, int ch, return 0; } =20 -static int ad7606c_18bit_chan_scale_setup(struct ad7606_state *st, +static int ad7606c_18bit_chan_scale_setup(struct iio_dev *indio_dev, struct iio_chan_spec *chan, int ch) { + struct ad7606_state *st =3D iio_priv(indio_dev); struct ad7606_chan_scale *cs =3D &st->chan_scales[ch]; bool bipolar, differential; int ret; @@ -413,7 +417,7 @@ static int ad7606c_18bit_chan_scale_setup(struct ad7606= _state *st, return 0; } =20 - ret =3D ad7606_get_chan_config(st, ch, &bipolar, &differential); + ret =3D ad7606_get_chan_config(indio_dev, ch, &bipolar, &differential); if (ret) return ret; =20 @@ -455,9 +459,10 @@ static int ad7606c_18bit_chan_scale_setup(struct ad760= 6_state *st, return 0; } =20 -static int ad7606c_16bit_chan_scale_setup(struct ad7606_state *st, +static int ad7606c_16bit_chan_scale_setup(struct iio_dev *indio_dev, struct iio_chan_spec *chan, int ch) { + struct ad7606_state *st =3D iio_priv(indio_dev); struct ad7606_chan_scale *cs =3D &st->chan_scales[ch]; bool bipolar, differential; int ret; @@ -469,7 +474,7 @@ static int ad7606c_16bit_chan_scale_setup(struct ad7606= _state *st, return 0; } =20 - ret =3D ad7606_get_chan_config(st, ch, &bipolar, &differential); + ret =3D ad7606_get_chan_config(indio_dev, ch, &bipolar, &differential); if (ret) return ret; =20 @@ -512,9 +517,10 @@ static int ad7606c_16bit_chan_scale_setup(struct ad760= 6_state *st, return 0; } =20 -static int ad7607_chan_scale_setup(struct ad7606_state *st, +static int ad7607_chan_scale_setup(struct iio_dev *indio_dev, struct iio_chan_spec *chan, int ch) { + struct ad7606_state *st =3D iio_priv(indio_dev); struct ad7606_chan_scale *cs =3D &st->chan_scales[ch]; =20 cs->range =3D 0; @@ -523,9 +529,10 @@ static int ad7607_chan_scale_setup(struct ad7606_state= *st, return 0; } =20 -static int ad7608_chan_scale_setup(struct ad7606_state *st, +static int ad7608_chan_scale_setup(struct iio_dev *indio_dev, struct iio_chan_spec *chan, int ch) { + struct ad7606_state *st =3D iio_priv(indio_dev); struct ad7606_chan_scale *cs =3D &st->chan_scales[ch]; =20 cs->range =3D 0; @@ -534,9 +541,10 @@ static int ad7608_chan_scale_setup(struct ad7606_state= *st, return 0; } =20 -static int ad7609_chan_scale_setup(struct ad7606_state *st, +static int ad7609_chan_scale_setup(struct iio_dev *indio_dev, struct iio_chan_spec *chan, int ch) { + struct ad7606_state *st =3D iio_priv(indio_dev); struct ad7606_chan_scale *cs =3D &st->chan_scales[ch]; =20 cs->range =3D 0; @@ -1146,8 +1154,8 @@ static int ad7606_sw_mode_setup(struct iio_dev *indio= _dev) =20 static int ad7606_chan_scales_setup(struct iio_dev *indio_dev) { - unsigned int num_channels =3D indio_dev->num_channels - 1; struct ad7606_state *st =3D iio_priv(indio_dev); + unsigned int offset =3D indio_dev->num_channels - st->chip_info->num_adc_= channels; struct iio_chan_spec *chans; size_t size; int ch, ret; @@ -1161,8 +1169,8 @@ static int ad7606_chan_scales_setup(struct iio_dev *i= ndio_dev) memcpy(chans, indio_dev->channels, size); indio_dev->channels =3D chans; =20 - for (ch =3D 0; ch < num_channels; ch++) { - ret =3D st->chip_info->scale_setup_cb(st, &chans[ch + 1], ch); + for (ch =3D 0; ch < st->chip_info->num_adc_channels; ch++) { + ret =3D st->chip_info->scale_setup_cb(indio_dev, &chans[ch + offset], ch= ); if (ret) return ret; } diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index 998814a92b82..8778ffe515b3 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -69,7 +69,7 @@ =20 struct ad7606_state; =20 -typedef int (*ad7606_scale_setup_cb_t)(struct ad7606_state *st, +typedef int (*ad7606_scale_setup_cb_t)(struct iio_dev *indio_dev, struct iio_chan_spec *chan, int ch); =20 /** --=20 2.34.1 From nobody Sun Nov 24 05:49:20 2024 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (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 4040E1CC885 for ; Thu, 21 Nov 2024 10:18:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732184311; cv=none; b=MkQg7sSn7gOvnBFYe1QBnoeioCecqOu1QU1FByaTgoKuuxwltfSREaPHxza4hAhqoqL2K4QkrNXlQwo7RoHIE8NdEzqkIxYWb911aLee3zVYjyjgPTXjJSKWfjaNxz5esBB4Zs5VZ+dsM7HwBtqImZnzUc48YJc+Es2crRV5jZw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732184311; c=relaxed/simple; bh=v67VGnWIkBdnUdS985qH7iF4x838r3raMc0/Xi1uuz0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FZAPgiPW0YowRYKx8CpITO9GoRhavnfrDvDNl+89+4l33jRcU9zOEEuP7Z8mcnCmX+Jh5EXQRlITaucfTG52nJmSAlA/vXH8yRdXZy+A/zLMkx/SCdoh0KvEEsydcJr29tVCjaOGC/ukv5kMOMd3FSS+gqEVLNs63JIevQzTchw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=NEVF6SPv; arc=none smtp.client-ip=209.85.221.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="NEVF6SPv" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-3825a721ae5so309907f8f.1 for ; Thu, 21 Nov 2024 02:18:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1732184307; x=1732789107; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=eIvcv/w9nbdD6Pqexc2MWqksh6TFH2yfbr5I0uzs1Ow=; b=NEVF6SPvXAK9CQP41gSpXHH27D25I3vUOlaGILU1E+idTIiXZYUyiE1nOQSDHs/zsK yy7ET7nWEcGBgqbvFtvLCE02hla9yrJSPrzNU21M5viPcOoYF7V5QiL/k8Br3vN7fw+b RlahcnK76wq0WauWfEiblUdfXKSftCSQ26E8pnI2X/L97wXyqlnfb1FPaGbsNLQ1e+5w lRvjCOMwW6TFDyt/FDaE5LjSiyp8DcWAus/9oimhlBKVFpOWDQ0KOcEf3KIFObgOmwO0 JBnS8egmwzj753Ius/Hd/9jOFrkZMmimFQjMxQPOdH6UXViawkauL+pNZ650UKuScIm+ b92w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732184307; x=1732789107; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eIvcv/w9nbdD6Pqexc2MWqksh6TFH2yfbr5I0uzs1Ow=; b=osTGCynw1rbhGr1oaDIXZKk6seuG72GCVjIqhPb60o/uauoidkzJNhDn0Jw4HTPl/b 02MKYzfkY02p+EiPNOQzRfHtANjWlc7qK9LcFB3WJv5P8SzWgQk3akPlg+OsETtKoD4v HKl/izx8DRHolIDGwTCQ/uNHmAntu4SBBGqcuyofINaEeqpw9X2iQm/G8XSO0vLth7S4 4vx4LE7csMAg8/2svwQumc3JDq0Nc0diOAJS//ZXg6YOpwqVkDc6wslfjHRS37szM6YV x9Adw2zadLmNWj2CQK+oy5K4/9JwIC+Z4XGpojnPRlWBC+oLQkeYX7fn1O47FYJffk1B 8qXA== X-Forwarded-Encrypted: i=1; AJvYcCXWpheAM8oxvKSCw1S4pblhXNqQrZ3ET8w5DnWJeLyHrUy1p3gupr9h6JxggeOWqu3lSgBAlGDU4hkUPUc=@vger.kernel.org X-Gm-Message-State: AOJu0YwajkbNbhFrxD6r71a/5EXi4nFwyoaTVcZF3Tm0o5awDUOEn9pe fpSKjes5MHqNRGRe+kfYud8jpVOvzuHXSnYUhKw4+xDmzLVIwhg2NoFznJ9lI4FQ10tQCYZ97H/ 3 X-Google-Smtp-Source: AGHT+IHW3IoGYshb8tI/heRPJw81Fxm5YJNDYBrO0MNrtp6fR81LenEdtACfP7PMDMzdfSEwm1RPBQ== X-Received: by 2002:a05:6000:1886:b0:382:47d0:64b0 with SMTP id ffacd0b85a97d-38259cb82fcmr1930200f8f.2.1732184307226; Thu, 21 Nov 2024 02:18:27 -0800 (PST) Received: from [127.0.1.1] (frhb82016ds.ikexpress.com. [185.246.87.17]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38254910796sm4598065f8f.47.2024.11.21.02.18.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 02:18:26 -0800 (PST) From: Guillaume Stols Date: Thu, 21 Nov 2024 10:18:24 +0000 Subject: [PATCH 2/9] dt-bindings: iio: dac: adi-axi-adc: Add ad7606 variant Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-ad7606_add_iio_backend_software_mode-v1-2-8a693a5e3fa9@baylibre.com> References: <20241121-ad7606_add_iio_backend_software_mode-v1-0-8a693a5e3fa9@baylibre.com> In-Reply-To: <20241121-ad7606_add_iio_backend_software_mode-v1-0-8a693a5e3fa9@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Nuno Sa , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Hennerich , devicetree@vger.kernel.org, dlechner@baylibre.com, jstephan@baylibre.com, aardelean@baylibre.com, adureghello@baylibre.com, Guillaume Stols X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1732184304; l=1599; i=gstols@baylibre.com; s=20240417; h=from:subject:message-id; bh=v67VGnWIkBdnUdS985qH7iF4x838r3raMc0/Xi1uuz0=; b=BSCWsqYm2zQ3VQ9FR8Ee7VEGYr/D2HqyqSOK7+yxzAwrchTplIL+IiV03WSiO/t0OMzTyH4ga q/0j+S/DAu4BGe/8m+7zbfncy8M0wERcF1zDO9C1aR/lRwVTWu08Dw3 X-Developer-Key: i=gstols@baylibre.com; a=ed25519; pk=XvMm5WHuV67sGYOJZqIYzXndbaJOlNd8Q6li6vnb4Cs= A new compatible is added to reflect the specialized version of the HDL that is not covered by the IIO backend paradigm: We use the parallel interface to write the ADC's registers, and accessing this interface requires to use ADI_AXI_REG_CONFIG_RD,ADI_AXI_REG_CONFIG_WR and ADI_AXI_REG_CONFIG_CTRL in a custom fashion. Signed-off-by: Guillaume Stols --- Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml b/D= ocumentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml index e1f450b80db2..43bc0440c678 100644 --- a/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml +++ b/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml @@ -17,13 +17,20 @@ description: | interface for the actual ADC, while this IP core will interface to the data-lines of the ADC and handle the streaming of data into memory via DMA. + In some cases, the AXI ADC interface is used to perform specialized + operation to a particular ADC, e.g access the physical bus through + some special register to write ADC registers. + In this case, a different compatible is used, and the driver behaves + slightly differently according to the special needs. =20 https://wiki.analog.com/resources/fpga/docs/axi_adc_ip + http://analogdevicesinc.github.io/hdl/library/axi_ad7606x/index.html =20 properties: compatible: enum: - adi,axi-adc-10.0.a + - adi,axi-ad7606x =20 reg: maxItems: 1 --=20 2.34.1 From nobody Sun Nov 24 05:49:20 2024 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 30CFB1CCEC3 for ; Thu, 21 Nov 2024 10:18:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732184312; cv=none; b=UofrH91OS+tQHqEfZtrliKRk6tZpwPhZ6oVD+eEPWZ/OfAlDVCXpzX6w3MRf/MXYDmGqZ2q86MkOkBuqcxg8MfAakBLF6R68E9HscA94fIbv3Qpn4nsJ31k6ZA6ji2aj/37oo0uUk7krCkBg4N8Rfe4wKh8Be63Z2L+wYN/03X4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732184312; c=relaxed/simple; bh=2RdUP0opgSj121kEt066DF0V8khGTWZlShuPPaqbCi8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EzSToxqSkk54G0KCVA1sRguvwhU17a3koRPJYA+HfOezeDxy/yERslmyowtw/MrqmsHRxQ7cq430NyLBjoYOnMTWOphIF7bCFbF42WHMOTtbkU7EpVi/u7+mF6YsHmXwHZ8rjC0sAk81/vVNlKiE37eKWZhRWJ+xugoRwiElj4g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=V9f9Ww4t; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="V9f9Ww4t" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4315f24a6bbso5478785e9.1 for ; Thu, 21 Nov 2024 02:18:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1732184308; x=1732789108; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=NnR4UV0w6VSKY/f8yPux4iBG+LYvQ7mliatLzcIQdBM=; b=V9f9Ww4tyqz0n6oEURYAOXPqlup7oxzLucuhvRjX7zp8pg++J8yL+0m1GTFaovql9z pnn3q+m1b51pvbxWMx417U8Cex3FTpH/Wwm3TZm+LM+WD8wUfIb4dHPfn6V1Lbnt2woh DbaX+bmgzdjv1OH/DNKcUK0Q1ICwF0CMTvW+Lq8N3pOexhQ+Ge/uaAfStM8UiHfDHUvi 8b9HzmgyHgcmUOTHrVs3Vo9x4jsQigvk6BvZXHKRTntZMK3xJpBq71W2f0HM/0JRETbi lo8ssBhimOLRDWKY6pLx7njwM6qbdP4I1aurmw/zXvhtMFP9+aJecXNbyDhBVoqEA95F pfdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732184308; x=1732789108; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NnR4UV0w6VSKY/f8yPux4iBG+LYvQ7mliatLzcIQdBM=; b=kivqvOz/gqwLebdJ/rZnoSWL8/cKOBmX7iLetsJ8zqjnUXt7FA+bDJJzqD4iKmJt2C c+XoupJyL5m56I9SeIQ/xBgcqVWQavZtDlLR5JJIFIXLvlBEIYFU6ij/u42FvkGoMcDb HqvuHQE+84uFNbcbzUimXXKl8MT2dhVTqD3x4BePUP6qzOsfRyq+H98au/YxfdF4GJo9 L+u1wNQ8RnIjP9qnj4FstFC35r9wsbdHzWgP3ZPMuqS7qVVbKfLqzWmilk25GCQ351Xd CtI59HYlAQYCSfdO10UqZsNhkmxqBO5PKBI2NCXDW/c3l61jHYx6iC3SHa+YV+9FirJl 6KGw== X-Forwarded-Encrypted: i=1; AJvYcCXCMMp7T2KmNJHfRvgzXGn7DhROdnQzUexj7vh5njDy4DE6Va0THMbm7dVNe360Wri8soEWn4oJjsYUAr8=@vger.kernel.org X-Gm-Message-State: AOJu0Ywbm1i/k/8ZspAwNGaT9hL1f41fkLCzDSIQdJNQcUUasfSkaMIZ zWsF5PGtpISW0/lTGtHYVl+3pBen21H3VeN6P1dYPxccE9bBfZG0lLgHZKqnVxgbO0MH9EsMHut h X-Gm-Gg: ASbGncvYXJ9+B3MZLP7TTHbTFTvretsmMFDgAuMYqpYsko/uj1f9gsJ0T+aMef1XDe2 YyexOPjbfWtPKyfLt/dfydbAd0FY4I2gkJG5lgMQhsKf1+O2Ia+OBc8nMX/AchVY/D27sYCNtDu mPfuLR8cg66Fav8TjOKmxW9/ynWY3IOxGzf7HfWV5YEKn+0gyQVamFzSezaPzMnV/lSSbubBp6j XB0ImC1aofiz4QSbTDL0Ng8P872NbPNxJ4g+C0U7oQFu298QfSArcRyyIclIil3ATCZ94bupw== X-Google-Smtp-Source: AGHT+IEFrv/RthM6qz+7szeDYPM6+coRBlRKnKO/IHtuqFfBkoi0rE1EWyE4uO8xzlFLoYrtCCfo9w== X-Received: by 2002:a05:6000:144d:b0:382:397f:3df5 with SMTP id ffacd0b85a97d-38254b21914mr4328291f8f.38.1732184308058; Thu, 21 Nov 2024 02:18:28 -0800 (PST) Received: from [127.0.1.1] (frhb82016ds.ikexpress.com. [185.246.87.17]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38254910796sm4598065f8f.47.2024.11.21.02.18.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 02:18:27 -0800 (PST) From: Guillaume Stols Date: Thu, 21 Nov 2024 10:18:25 +0000 Subject: [PATCH 3/9] iio:adc: ad7606: Move the software mode configuration Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-ad7606_add_iio_backend_software_mode-v1-3-8a693a5e3fa9@baylibre.com> References: <20241121-ad7606_add_iio_backend_software_mode-v1-0-8a693a5e3fa9@baylibre.com> In-Reply-To: <20241121-ad7606_add_iio_backend_software_mode-v1-0-8a693a5e3fa9@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Nuno Sa , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Hennerich , devicetree@vger.kernel.org, dlechner@baylibre.com, jstephan@baylibre.com, aardelean@baylibre.com, adureghello@baylibre.com, Guillaume Stols X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1732184304; l=2020; i=gstols@baylibre.com; s=20240417; h=from:subject:message-id; bh=2RdUP0opgSj121kEt066DF0V8khGTWZlShuPPaqbCi8=; b=h2ujr71zPBn32R8QCoM2rO5GdcOeQwiHdz8qEQORU/AXJdpiejQlKCfEYCdxWP2UUsq8DD6jk ldIWgG6+mHBBDZzv5osKXZMHnV4EXY0SlPnf0jydyZi25SVnsOFQAeO X-Developer-Key: i=gstols@baylibre.com; a=ed25519; pk=XvMm5WHuV67sGYOJZqIYzXndbaJOlNd8Q6li6vnb4Cs= This is a preparation for the intoduction of the sofware functions in the iio backend version of the driver. The software mode configuration must be executed once the channels are configured, and the number of channels is known. This is not the case before iio-backend's configuration is called, and iio backend version of the driver does not have a timestamp channel. Also the sw_mode_config callback is configured during the iio-backend configuration. For clarity purpose, I moved the entire block instead of just the concerned function calls. Signed-off-by: Guillaume Stols --- drivers/iio/adc/ad7606.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index 893b93b86aa7..828603ed18f6 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -1246,17 +1246,6 @@ int ad7606_probe(struct device *dev, int irq, void _= _iomem *base_address, return -ERESTARTSYS; } =20 - st->write_scale =3D ad7606_write_scale_hw; - st->write_os =3D ad7606_write_os_hw; - - ret =3D ad7606_sw_mode_setup(indio_dev); - if (ret) - return ret; - - ret =3D ad7606_chan_scales_setup(indio_dev); - if (ret) - return ret; - /* If convst pin is not defined, setup PWM. */ if (!st->gpio_convst) { st->cnvst_pwm =3D devm_pwm_get(dev, NULL); @@ -1334,6 +1323,20 @@ int ad7606_probe(struct device *dev, int irq, void _= _iomem *base_address, return ret; } =20 + st->write_scale =3D ad7606_write_scale_hw; + st->write_os =3D ad7606_write_os_hw; + + st->sw_mode_en =3D st->chip_info->sw_setup_cb && + device_property_present(st->dev, "adi,sw-mode"); + if (st->sw_mode_en) { + indio_dev->info =3D &ad7606_info_sw_mode; + st->chip_info->sw_setup_cb(indio_dev); + } + + ret =3D ad7606_chan_scales_setup(indio_dev); + if (ret) + return ret; + return devm_iio_device_register(dev, indio_dev); } EXPORT_SYMBOL_NS_GPL(ad7606_probe, IIO_AD7606); --=20 2.34.1 From nobody Sun Nov 24 05:49:20 2024 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 E0FC11D0488 for ; Thu, 21 Nov 2024 10:18:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732184313; cv=none; b=YJvXKHLtIuHiYxQ2x3sWjwtU5ZuVG20rmJU6s6VGXkIPkTuRCUc3xng4yg+ePniww8tWTBVWGU36K5oYzZp0y9ZwI4/SPd53i8s1VNhl6y9UsDBtadgBJCAIeMjKQxRCEn9Ul3Eg9JY6WkF7ff5TEAQkAkf3i3gWNqZOw7pfwIM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732184313; c=relaxed/simple; bh=I8peenOs3+A/hxXv5G48baZvl1ThPxqQ6j9EI+NJj2E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NIDPjU9385i1KbPxn0Y80Z0VkW1qrtCumw1PGF2HiYHRythgRZfOb0E2SUhibaEk5IFy2Azj6gPYPhEZ+OXFciaFWsEZMLn6q2kGWAJQXrECKT7LCeUSmQC5rqSmxLJf0J8IIsZP8tklFIP+bYaDEaEOOmQII8h8sj5lwYgRSUA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=WgKRltHE; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="WgKRltHE" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-38241435528so445070f8f.2 for ; Thu, 21 Nov 2024 02:18:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1732184309; x=1732789109; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=jz/Jf9i+qzqUD9OC/Im10oe3TDhR8/H6yb+9VnZPKzE=; b=WgKRltHEWFZzL0bx0LJu1V0gXS30wZrWVlNtOeBqZMZLAGjrOb1IZgV0zJwcoXUVju dAZSqp+JEiPaqpv+8jfvUkObcoFHZENR3S/QuvG+zUNA+XiBgSprVrl9bJlwc2h5AExH OCmeO6C5tTY9OYJSUWukvsmIPAplzassvkw+potY4pejiBpy2JxZFAR8s9nrO6H3qY7H iw9zLkEhn2r2dsgLCBCuqKOmI9BH1uh73jS50HHr1N90IvmwXOgUGMFzeutZBTgdVXhl 0ITMrj1846wCJkhItmeZeoOtnL1tY/ezlXCrU7VLOEDr7BBUDeCty+/Fg8YzT5mXpAx5 jmyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732184309; x=1732789109; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jz/Jf9i+qzqUD9OC/Im10oe3TDhR8/H6yb+9VnZPKzE=; b=YBqhQ0JoG3JT6B0B11N9j2ZKMl0/JC9G1mWRrJzHMHaS2YE5R3ADcL3/mwpr0JyJ9S W8uQTExHsIp9kkqBYGXWJbv4fAM3auq+iY8GlEzVYU7XSJD/MA2Z65YjA9Iw4Rb/wiJU 9mQxKG4fuL5aKNG70nIQ8FxSfglpBP5CMj18ErGm7rr6Wy9zCv0kQwzmotAsIkykYNZZ TtuAiSDW2a4365zvOwzSeb8KgSqrAg9JdTZhfEu19uMwAAZ7jfY3mQxa+JGIK5qR7sKQ CkFvb3hIOGQFTIKYcugdYMqNtL8TFRED38BesLCxLtyVejbczm9ZsSGxJYvmBfDRDCKV qQKg== X-Forwarded-Encrypted: i=1; AJvYcCVHLJjTYOkW/8ilOB2zKR44h6rjl8v1o4pudoGjAkPh4z/sHO+crcjhP0k2ZqeuRQzdvictyprTLU3KySY=@vger.kernel.org X-Gm-Message-State: AOJu0Yy3IPLCiqI9nQxaUKZAjiZ6nZS57D3wYZ/DzOCPJVDdHXVbLcoZ Uk5l1Va+jZ1J5c2WRU10ep7BkdEsOYxZt/PWDHWAfbIUiAL7psyvpcYLX2jvjdVXwyo/rBeSAtU e X-Google-Smtp-Source: AGHT+IHvbGiqlY44oV0CUFj3hcN2B71NTiYyCb/kFKisZV54NpUo924WC5nKdleVOIKzbj0eakjlaQ== X-Received: by 2002:a5d:5887:0:b0:382:4fd6:405e with SMTP id ffacd0b85a97d-38254afa8ecmr4335021f8f.29.1732184308998; Thu, 21 Nov 2024 02:18:28 -0800 (PST) Received: from [127.0.1.1] (frhb82016ds.ikexpress.com. [185.246.87.17]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38254910796sm4598065f8f.47.2024.11.21.02.18.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 02:18:28 -0800 (PST) From: Guillaume Stols Date: Thu, 21 Nov 2024 10:18:26 +0000 Subject: [PATCH 4/9] iio: adc: ad7606: Move software functions into common file Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-ad7606_add_iio_backend_software_mode-v1-4-8a693a5e3fa9@baylibre.com> References: <20241121-ad7606_add_iio_backend_software_mode-v1-0-8a693a5e3fa9@baylibre.com> In-Reply-To: <20241121-ad7606_add_iio_backend_software_mode-v1-0-8a693a5e3fa9@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Nuno Sa , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Hennerich , devicetree@vger.kernel.org, dlechner@baylibre.com, jstephan@baylibre.com, aardelean@baylibre.com, adureghello@baylibre.com, Guillaume Stols X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1732184304; l=16090; i=gstols@baylibre.com; s=20240417; h=from:subject:message-id; bh=I8peenOs3+A/hxXv5G48baZvl1ThPxqQ6j9EI+NJj2E=; b=ZvRMuVy7dIP52Oc7B/thhWU1XD1WhIMjG9F84n7a2YWhrYH4zg7yH61P4yhKkm2Gbdhc9MKKW Nrt+W7yu2AEDjvV+8mlbMRKoX7vWfZtHIlfGRlLVjfj9ghCqsrCsX2P X-Developer-Key: i=gstols@baylibre.com; a=ed25519; pk=XvMm5WHuV67sGYOJZqIYzXndbaJOlNd8Q6li6vnb4Cs= Since the register are always the same, whatever bus is used, moving the software functions into the main file avoids the code to be duplicated in both SPI and parallel version of the driver. Signed-off-by: Guillaume Stols --- drivers/iio/adc/ad7606.c | 128 +++++++++++++++++++++++++++++++++++++++= +-- drivers/iio/adc/ad7606.h | 37 ++++++++++-- drivers/iio/adc/ad7606_spi.c | 131 +--------------------------------------= ---- 3 files changed, 156 insertions(+), 140 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index 828603ed18f6..df0e49bc4bdb 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -85,6 +85,10 @@ static const unsigned int ad7606_oversampling_avail[7] = =3D { 1, 2, 4, 8, 16, 32, 64, }; =20 +static const unsigned int ad7606B_oversampling_avail[9] =3D { + 1, 2, 4, 8, 16, 32, 64, 128, 256 +}; + static const unsigned int ad7616_oversampling_avail[8] =3D { 1, 2, 4, 8, 16, 32, 64, 128, }; @@ -187,6 +191,8 @@ static int ad7608_chan_scale_setup(struct iio_dev *indi= o_dev, struct iio_chan_spec *chan, int ch); static int ad7609_chan_scale_setup(struct iio_dev *indio_dev, struct iio_chan_spec *chan, int ch); +static int ad7616_sw_mode_setup(struct iio_dev *indio_dev); +static int ad7606B_sw_mode_setup(struct iio_dev *indio_dev); =20 const struct ad7606_chip_info ad7605_4_info =3D { .channels =3D ad7605_channels, @@ -239,6 +245,7 @@ const struct ad7606_chip_info ad7606b_info =3D { .oversampling_avail =3D ad7606_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), .scale_setup_cb =3D ad7606_16bit_chan_scale_setup, + .sw_setup_cb =3D ad7606B_sw_mode_setup, }; EXPORT_SYMBOL_NS_GPL(ad7606b_info, IIO_AD7606); =20 @@ -250,6 +257,7 @@ const struct ad7606_chip_info ad7606c_16_info =3D { .oversampling_avail =3D ad7606_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), .scale_setup_cb =3D ad7606c_16bit_chan_scale_setup, + .sw_setup_cb =3D ad7606B_sw_mode_setup, }; EXPORT_SYMBOL_NS_GPL(ad7606c_16_info, IIO_AD7606); =20 @@ -294,6 +302,7 @@ const struct ad7606_chip_info ad7606c_18_info =3D { .oversampling_avail =3D ad7606_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), .scale_setup_cb =3D ad7606c_18bit_chan_scale_setup, + .sw_setup_cb =3D ad7606B_sw_mode_setup, }; EXPORT_SYMBOL_NS_GPL(ad7606c_18_info, IIO_AD7606); =20 @@ -307,6 +316,7 @@ const struct ad7606_chip_info ad7616_info =3D { .oversampling_num =3D ARRAY_SIZE(ad7616_oversampling_avail), .os_req_reset =3D true, .scale_setup_cb =3D ad7606_16bit_chan_scale_setup, + .sw_setup_cb =3D ad7616_sw_mode_setup, }; EXPORT_SYMBOL_NS_GPL(ad7616_info, IIO_AD7606); =20 @@ -1138,16 +1148,122 @@ static const struct iio_trigger_ops ad7606_trigger= _ops =3D { .validate_device =3D iio_trigger_validate_own_device, }; =20 -static int ad7606_sw_mode_setup(struct iio_dev *indio_dev) +static int ad7606_write_mask(struct ad7606_state *st, + unsigned int addr, + unsigned long mask, + unsigned int val) +{ + int readval; + + readval =3D st->bops->reg_read(st, addr); + if (readval < 0) + return readval; + + readval &=3D ~mask; + readval |=3D val; + + return st->bops->reg_write(st, addr, readval); +} + +static int ad7616_write_scale_sw(struct iio_dev *indio_dev, int ch, int va= l) { struct ad7606_state *st =3D iio_priv(indio_dev); + unsigned int ch_addr, mode, ch_index; =20 - st->sw_mode_en =3D st->bops->sw_mode_config && - device_property_present(st->dev, "adi,sw-mode"); - if (!st->sw_mode_en) - return 0; + /* + * Ad7616 has 16 channels divided in group A and group B. + * The range of channels from A are stored in registers with address 4 + * while channels from B are stored in register with address 6. + * The last bit from channels determines if it is from group A or B + * because the order of channels in iio is 0A, 0B, 1A, 1B... + */ + ch_index =3D ch >> 1; + + ch_addr =3D AD7616_RANGE_CH_ADDR(ch_index); + + if ((ch & 0x1) =3D=3D 0) /* channel A */ + ch_addr +=3D AD7616_RANGE_CH_A_ADDR_OFF; + else /* channel B */ + ch_addr +=3D AD7616_RANGE_CH_B_ADDR_OFF; + + /* 0b01 for 2.5v, 0b10 for 5v and 0b11 for 10v */ + mode =3D AD7616_RANGE_CH_MODE(ch_index, ((val + 1) & 0b11)); + + return ad7606_write_mask(st, ch_addr, AD7616_RANGE_CH_MSK(ch_index), + mode); +} + +static int ad7616_write_os_sw(struct iio_dev *indio_dev, int val) +{ + struct ad7606_state *st =3D iio_priv(indio_dev); + + return ad7606_write_mask(st, AD7616_CONFIGURATION_REGISTER, + AD7616_OS_MASK, val << 2); +} + +static int ad7606_write_scale_sw(struct iio_dev *indio_dev, int ch, int va= l) +{ + struct ad7606_state *st =3D iio_priv(indio_dev); + + return ad7606_write_mask(st, + AD7606_RANGE_CH_ADDR(ch), + AD7606_RANGE_CH_MSK(ch), + AD7606_RANGE_CH_MODE(ch, val)); +} + +static int ad7606_write_os_sw(struct iio_dev *indio_dev, int val) +{ + struct ad7606_state *st =3D iio_priv(indio_dev); + + return st->bops->reg_write(st, AD7606_OS_MODE, val); +} + +static int ad7616_sw_mode_setup(struct iio_dev *indio_dev) +{ + struct ad7606_state *st =3D iio_priv(indio_dev); + int ret; + + /* + * Scale can be configured individually for each channel + * in software mode. + */ + + st->write_scale =3D ad7616_write_scale_sw; + st->write_os =3D &ad7616_write_os_sw; + + ret =3D st->bops->sw_mode_config(indio_dev); + if (ret) + return ret; + + /* Activate Burst mode and SEQEN MODE */ + return ad7606_write_mask(st, + AD7616_CONFIGURATION_REGISTER, + AD7616_BURST_MODE | AD7616_SEQEN_MODE, + AD7616_BURST_MODE | AD7616_SEQEN_MODE); +} + +static int ad7606B_sw_mode_setup(struct iio_dev *indio_dev) +{ + struct ad7606_state *st =3D iio_priv(indio_dev); + DECLARE_BITMAP(os, 3); + + bitmap_fill(os, 3); + /* + * Software mode is enabled when all three oversampling + * pins are set to high. If oversampling gpios are defined + * in the device tree, then they need to be set to high, + * otherwise, they must be hardwired to VDD + */ + if (st->gpio_os) { + gpiod_set_array_value(st->gpio_os->ndescs, + st->gpio_os->desc, st->gpio_os->info, os); + } + /* OS of 128 and 256 are available only in software mode */ + st->oversampling_avail =3D ad7606B_oversampling_avail; + st->num_os_ratios =3D ARRAY_SIZE(ad7606B_oversampling_avail); =20 - indio_dev->info =3D &ad7606_info_sw_mode; + st->write_scale =3D ad7606_write_scale_sw; + st->write_os =3D &ad7606_write_os_sw; =20 return st->bops->sw_mode_config(indio_dev); } diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index 8778ffe515b3..7a044b499cfe 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -10,6 +10,36 @@ =20 #define AD760X_MAX_CHANNELS 16 =20 +#define AD7616_CONFIGURATION_REGISTER 0x02 +#define AD7616_OS_MASK GENMASK(4, 2) +#define AD7616_BURST_MODE BIT(6) +#define AD7616_SEQEN_MODE BIT(5) +#define AD7616_RANGE_CH_A_ADDR_OFF 0x04 +#define AD7616_RANGE_CH_B_ADDR_OFF 0x06 +/* + * Range of channels from a group are stored in 2 registers. + * 0, 1, 2, 3 in a register followed by 4, 5, 6, 7 in second register. + * For channels from second group(8-15) the order is the same, only with + * an offset of 2 for register address. + */ +#define AD7616_RANGE_CH_ADDR(ch) ((ch) >> 2) +/* The range of the channel is stored in 2 bits */ +#define AD7616_RANGE_CH_MSK(ch) (0b11 << (((ch) & 0b11) * 2)) +#define AD7616_RANGE_CH_MODE(ch, mode) ((mode) << ((((ch) & 0b11)) * 2)) + +#define AD7606_CONFIGURATION_REGISTER 0x02 +#define AD7606_SINGLE_DOUT 0x00 + +/* + * Range for AD7606B channels are stored in registers starting with addres= s 0x3. + * Each register stores range for 2 channels(4 bits per channel). + */ +#define AD7606_RANGE_CH_MSK(ch) (GENMASK(3, 0) << (4 * ((ch) & 0x1))) +#define AD7606_RANGE_CH_MODE(ch, mode) \ + ((GENMASK(3, 0) & (mode)) << (4 * ((ch) & 0x1))) +#define AD7606_RANGE_CH_ADDR(ch) (0x03 + ((ch) >> 1)) +#define AD7606_OS_MODE 0x08 + #define AD760X_CHANNEL(num, mask_sep, mask_type, mask_all, bits) { \ .type =3D IIO_VOLTAGE, \ .indexed =3D 1, \ @@ -71,6 +101,7 @@ struct ad7606_state; =20 typedef int (*ad7606_scale_setup_cb_t)(struct iio_dev *indio_dev, struct iio_chan_spec *chan, int ch); +typedef int (*ad7606_sw_setup_cb_t)(struct iio_dev *indio_dev); =20 /** * struct ad7606_chip_info - chip specific information @@ -80,6 +111,7 @@ typedef int (*ad7606_scale_setup_cb_t)(struct iio_dev *i= ndio_dev, * @num_channels: number of channels * @num_adc_channels the number of channels the ADC actually inputs. * @scale_setup_cb: callback to setup the scales for each channel + * @sw_setup_cb: callback to setup the software mode if available. * @oversampling_avail pointer to the array which stores the available * oversampling ratios. * @oversampling_num number of elements stored in oversampling_avail array @@ -94,6 +126,7 @@ struct ad7606_chip_info { unsigned int num_adc_channels; unsigned int num_channels; ad7606_scale_setup_cb_t scale_setup_cb; + ad7606_sw_setup_cb_t sw_setup_cb; const unsigned int *oversampling_avail; unsigned int oversampling_num; bool os_req_reset; @@ -206,10 +239,6 @@ struct ad7606_bus_ops { int (*reg_write)(struct ad7606_state *st, unsigned int addr, unsigned int val); - int (*write_mask)(struct ad7606_state *st, - unsigned int addr, - unsigned long mask, - unsigned int val); int (*update_scan_mode)(struct iio_dev *indio_dev, const unsigned long *s= can_mask); u16 (*rd_wr_cmd)(int addr, char isWriteOp); }; diff --git a/drivers/iio/adc/ad7606_spi.c b/drivers/iio/adc/ad7606_spi.c index 0662300cde8d..640e36092662 100644 --- a/drivers/iio/adc/ad7606_spi.c +++ b/drivers/iio/adc/ad7606_spi.c @@ -15,36 +15,6 @@ =20 #define MAX_SPI_FREQ_HZ 23500000 /* VDRIVE above 4.75 V */ =20 -#define AD7616_CONFIGURATION_REGISTER 0x02 -#define AD7616_OS_MASK GENMASK(4, 2) -#define AD7616_BURST_MODE BIT(6) -#define AD7616_SEQEN_MODE BIT(5) -#define AD7616_RANGE_CH_A_ADDR_OFF 0x04 -#define AD7616_RANGE_CH_B_ADDR_OFF 0x06 -/* - * Range of channels from a group are stored in 2 registers. - * 0, 1, 2, 3 in a register followed by 4, 5, 6, 7 in second register. - * For channels from second group(8-15) the order is the same, only with - * an offset of 2 for register address. - */ -#define AD7616_RANGE_CH_ADDR(ch) ((ch) >> 2) -/* The range of the channel is stored in 2 bits */ -#define AD7616_RANGE_CH_MSK(ch) (0b11 << (((ch) & 0b11) * 2)) -#define AD7616_RANGE_CH_MODE(ch, mode) ((mode) << ((((ch) & 0b11)) * 2)) - -#define AD7606_CONFIGURATION_REGISTER 0x02 -#define AD7606_SINGLE_DOUT 0x00 - -/* - * Range for AD7606B channels are stored in registers starting with addres= s 0x3. - * Each register stores range for 2 channels(4 bits per channel). - */ -#define AD7606_RANGE_CH_MSK(ch) (GENMASK(3, 0) << (4 * ((ch) & 0x1))) -#define AD7606_RANGE_CH_MODE(ch, mode) \ - ((GENMASK(3, 0) & mode) << (4 * ((ch) & 0x1))) -#define AD7606_RANGE_CH_ADDR(ch) (0x03 + ((ch) >> 1)) -#define AD7606_OS_MODE 0x08 - static const struct iio_chan_spec ad7616_sw_channels[] =3D { IIO_CHAN_SOFT_TIMESTAMP(16), AD7616_CHANNEL(0), @@ -194,76 +164,6 @@ static int ad7606_spi_reg_write(struct ad7606_state *s= t, return spi_write(spi, &st->d16[0], sizeof(st->d16[0])); } =20 -static int ad7606_spi_write_mask(struct ad7606_state *st, - unsigned int addr, - unsigned long mask, - unsigned int val) -{ - int readval; - - readval =3D st->bops->reg_read(st, addr); - if (readval < 0) - return readval; - - readval &=3D ~mask; - readval |=3D val; - - return st->bops->reg_write(st, addr, readval); -} - -static int ad7616_write_scale_sw(struct iio_dev *indio_dev, int ch, int va= l) -{ - struct ad7606_state *st =3D iio_priv(indio_dev); - unsigned int ch_addr, mode, ch_index; - - - /* - * Ad7616 has 16 channels divided in group A and group B. - * The range of channels from A are stored in registers with address 4 - * while channels from B are stored in register with address 6. - * The last bit from channels determines if it is from group A or B - * because the order of channels in iio is 0A, 0B, 1A, 1B... - */ - ch_index =3D ch >> 1; - - ch_addr =3D AD7616_RANGE_CH_ADDR(ch_index); - - if ((ch & 0x1) =3D=3D 0) /* channel A */ - ch_addr +=3D AD7616_RANGE_CH_A_ADDR_OFF; - else /* channel B */ - ch_addr +=3D AD7616_RANGE_CH_B_ADDR_OFF; - - /* 0b01 for 2.5v, 0b10 for 5v and 0b11 for 10v */ - mode =3D AD7616_RANGE_CH_MODE(ch_index, ((val + 1) & 0b11)); - return st->bops->write_mask(st, ch_addr, AD7616_RANGE_CH_MSK(ch_index), - mode); -} - -static int ad7616_write_os_sw(struct iio_dev *indio_dev, int val) -{ - struct ad7606_state *st =3D iio_priv(indio_dev); - - return st->bops->write_mask(st, AD7616_CONFIGURATION_REGISTER, - AD7616_OS_MASK, val << 2); -} - -static int ad7606_write_scale_sw(struct iio_dev *indio_dev, int ch, int va= l) -{ - struct ad7606_state *st =3D iio_priv(indio_dev); - - return ad7606_spi_write_mask(st, - AD7606_RANGE_CH_ADDR(ch), - AD7606_RANGE_CH_MSK(ch), - AD7606_RANGE_CH_MODE(ch, val)); -} - -static int ad7606_write_os_sw(struct iio_dev *indio_dev, int val) -{ - struct ad7606_state *st =3D iio_priv(indio_dev); - - return ad7606_spi_reg_write(st, AD7606_OS_MODE, val); -} - static int ad7616_sw_mode_config(struct iio_dev *indio_dev) { struct ad7606_state *st =3D iio_priv(indio_dev); @@ -274,38 +174,12 @@ static int ad7616_sw_mode_config(struct iio_dev *indi= o_dev) */ indio_dev->channels =3D ad7616_sw_channels; =20 - st->write_scale =3D ad7616_write_scale_sw; - st->write_os =3D &ad7616_write_os_sw; - - /* Activate Burst mode and SEQEN MODE */ - return st->bops->write_mask(st, - AD7616_CONFIGURATION_REGISTER, - AD7616_BURST_MODE | AD7616_SEQEN_MODE, - AD7616_BURST_MODE | AD7616_SEQEN_MODE); + return 0; } =20 static int ad7606B_sw_mode_config(struct iio_dev *indio_dev) { struct ad7606_state *st =3D iio_priv(indio_dev); - DECLARE_BITMAP(os, 3); - - bitmap_fill(os, 3); - /* - * Software mode is enabled when all three oversampling - * pins are set to high. If oversampling gpios are defined - * in the device tree, then they need to be set to high, - * otherwise, they must be hardwired to VDD - */ - if (st->gpio_os) { - gpiod_set_array_value(st->gpio_os->ndescs, - st->gpio_os->desc, st->gpio_os->info, os); - } - /* OS of 128 and 256 are available only in software mode */ - st->oversampling_avail =3D ad7606B_oversampling_avail; - st->num_os_ratios =3D ARRAY_SIZE(ad7606B_oversampling_avail); - - st->write_scale =3D ad7606_write_scale_sw; - st->write_os =3D &ad7606_write_os_sw; =20 /* Configure device spi to output on a single channel */ st->bops->reg_write(st, @@ -350,7 +224,6 @@ static const struct ad7606_bus_ops ad7616_spi_bops =3D { .read_block =3D ad7606_spi_read_block, .reg_read =3D ad7606_spi_reg_read, .reg_write =3D ad7606_spi_reg_write, - .write_mask =3D ad7606_spi_write_mask, .rd_wr_cmd =3D ad7616_spi_rd_wr_cmd, .sw_mode_config =3D ad7616_sw_mode_config, }; @@ -359,7 +232,6 @@ static const struct ad7606_bus_ops ad7606b_spi_bops =3D= { .read_block =3D ad7606_spi_read_block, .reg_read =3D ad7606_spi_reg_read, .reg_write =3D ad7606_spi_reg_write, - .write_mask =3D ad7606_spi_write_mask, .rd_wr_cmd =3D ad7606B_spi_rd_wr_cmd, .sw_mode_config =3D ad7606B_sw_mode_config, }; @@ -368,7 +240,6 @@ static const struct ad7606_bus_ops ad7606c_18_spi_bops = =3D { .read_block =3D ad7606_spi_read_block18to32, .reg_read =3D ad7606_spi_reg_read, .reg_write =3D ad7606_spi_reg_write, - .write_mask =3D ad7606_spi_write_mask, .rd_wr_cmd =3D ad7606B_spi_rd_wr_cmd, .sw_mode_config =3D ad7606c_18_sw_mode_config, }; --=20 2.34.1 From nobody Sun Nov 24 05:49:20 2024 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (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 C0E7B1D0DC0 for ; Thu, 21 Nov 2024 10:18:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732184314; cv=none; b=tPJ6TQwoyApnbNxXO4+oe+ZEW7keEFMqMBtIziNcSqETxgo00TsFQxOBfxlX8tMWsd4pV2qH9GS5/D+zatge+CMBJfnFKRCnZhG8Yg2fPyGX2GfMEQ2tLEbv5xofl9S2pDd7R0q5BkQy+35iYdP/fQUPCKnn0N13NFnZj+IZ8Ak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732184314; c=relaxed/simple; bh=HHOSoPIWfNm0HnbAMkX8836VUfYDnNBWup0D9xZOL+0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Q8Nc6Xqibslc7/DDUkqojDMIfBZ5qaQtmOVsL23f4IIwd1Y5gF6Fb/ItW2t6NdtaL2qpR5FyKiexnwRipZ2Ku851CKXkr2MFp0MxJGPeBZ86c8wDWAimFPi7inzEMqpoXpmkvcI6aYwqKk2CmEnCqTytUtXKOAnR2l6p0Kcj/xI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=ULBJOm0P; arc=none smtp.client-ip=209.85.221.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="ULBJOm0P" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-382296631f1so476283f8f.3 for ; Thu, 21 Nov 2024 02:18:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1732184310; x=1732789110; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Hi5bVanQGTryoQ83MNFt/N/BFoKRDteIDz8dPQygmAk=; b=ULBJOm0PZzk+p2S0GgBJKZU9eMgSLmhn43AlAOf/kbS9tKoWA0MrKh0X0+R1udseV1 XP0LVlzz7rZefs6/6NF8IdoTt5RpBYyJk7QdEvQno0InzkmqXkr2tCMZXCDE2fw5wJJN WKs5mxTLlz4m4TEc2YxnOayIaRu/1ARKK7j7S/XYdF6V6sETdLxejWqOqSuDAmt8cBSq qgFs2Km8dh/6szfz9YG/kyK9aryduXvd8p5d7c81dt47351cG4J/yF2yNgbl1BvYtPAB FQ0cirLE0+vKhf0hAhXCRGgsSSPLrheE6RqF41N/jDTGOXmwvzGM9rNoYq+Ilt+7HVpG Tu6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732184310; x=1732789110; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Hi5bVanQGTryoQ83MNFt/N/BFoKRDteIDz8dPQygmAk=; b=BnNdEtyydG1YIvYnwpS2hRPNqY2PJpM4qTOg55D5UnGglyhd9v+Qc07ivc2e38b4ZD eFS14xXHtMoFS4eyqutm6VLNKW+6FqOYln17rdQ4i4Wm9xj5Eu/z6Ij8HNSGpmn/smeQ /mxk6hxO5XOjuVA9czdVK92uaF4BucuZh3Zink3Z/+47WVjo7B7MuCpc6HyJGIRnK3g6 Tz71hgDkWK9k6HLvCTN0MWdp/jVCv1psHYHAxGGJEVkRlqjZjAGb9DPM45xltRLS//oH Cy3UrbJgBXa6m4OIf5F30qNZJ5LYoN2sa8MiaeSlV7om93+DF/4Q7bpHrGVC0SGjeMz6 F7qw== X-Forwarded-Encrypted: i=1; AJvYcCU9oeTZ15vh2OEGHiXcWYYAewUgTi6POrOfcSgdPtFNfjnbi50+ksobzF1NVVss6RGku52uD76I7SH6w/4=@vger.kernel.org X-Gm-Message-State: AOJu0YwwmKwczQDBQ2dWqG9GLSUKXKSAHudE/Q8FR31cAzA+F9NSoCqE mjucBUk16UkQFG5H1GCeJUYsFku00Q7SAH5Tr2TENZoIscBXlHAqyi0mbgnlRO9SvAKHq/03Wg7 6 X-Gm-Gg: ASbGncuN16lzCLQ80h0sd7YGxDsxKUIDs+EfELd1zHqVaVRpCjwXMnaaWkbpmznZIlh n0rnJqUjMXWBXTas39QbPrt+R5/V4r6lsZlhHZZtbVWGnBlI1p9EW+7QYyMgm5MpIXBQ/dFM4wF MR96teaFmCUkKAPS7Bd65ksogJljgcHWFz8NkoGR4yySx3ehlUi7vJ8GJ03fZoohiNGgbDW/uhN 4knGTEtjsf0VcYZOgbbqMPmzBV4e5ho21Tji5DRos0VZDnoW5wjEBJl8dK175rbG+O3ALyAhA== X-Google-Smtp-Source: AGHT+IFhAX7+7XznixvsNJsjc3q81w2BiVcH2N32ixt+KbqUuzLZi9a/71WYWQUP9twJX5zY1CJQSg== X-Received: by 2002:a5d:47a1:0:b0:382:511c:b994 with SMTP id ffacd0b85a97d-38254adec9emr4465833f8f.12.1732184309848; Thu, 21 Nov 2024 02:18:29 -0800 (PST) Received: from [127.0.1.1] (frhb82016ds.ikexpress.com. [185.246.87.17]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38254910796sm4598065f8f.47.2024.11.21.02.18.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 02:18:29 -0800 (PST) From: Guillaume Stols Date: Thu, 21 Nov 2024 10:18:27 +0000 Subject: [PATCH 5/9] iio: adc: adi-axi-adc: Add platform children support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-ad7606_add_iio_backend_software_mode-v1-5-8a693a5e3fa9@baylibre.com> References: <20241121-ad7606_add_iio_backend_software_mode-v1-0-8a693a5e3fa9@baylibre.com> In-Reply-To: <20241121-ad7606_add_iio_backend_software_mode-v1-0-8a693a5e3fa9@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Nuno Sa , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Hennerich , devicetree@vger.kernel.org, dlechner@baylibre.com, jstephan@baylibre.com, aardelean@baylibre.com, adureghello@baylibre.com, Guillaume Stols X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1732184304; l=4168; i=gstols@baylibre.com; s=20240417; h=from:subject:message-id; bh=HHOSoPIWfNm0HnbAMkX8836VUfYDnNBWup0D9xZOL+0=; b=cdgJjwHaT6JBL+245zHbg1ONOImGhBi77kCCrt1ejDxZ6LxMrlkvAbVlXXaXQZqBmbY+b/brp Mdb2kJjvKBBC/wdL8A0A2BEQq3sB2HTjGXGChTzLiJvEtD7V7UtCCa1 X-Developer-Key: i=gstols@baylibre.com; a=ed25519; pk=XvMm5WHuV67sGYOJZqIYzXndbaJOlNd8Q6li6vnb4Cs= This is a preparation for the next commit adding support for register read and write functions on AD7606. Since sometimes a bus will be used, it has been agreed during ad3552's driver implementation that the device's driver bus is the backend, whose device node will be a child node. To provide the special callbacks for setting the register, axi-adc needs to pass them to the child device's driver through platform data. Signed-off-by: Guillaume Stols --- drivers/iio/adc/adi-axi-adc.c | 79 +++++++++++++++++++++++++++++++++++++++= +--- 1 file changed, 74 insertions(+), 5 deletions(-) diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c index 5c8c87eb36d1..704ebd6ea83e 100644 --- a/drivers/iio/adc/adi-axi-adc.c +++ b/drivers/iio/adc/adi-axi-adc.c @@ -80,7 +80,18 @@ ADI_AXI_REG_CHAN_CTRL_FMT_EN | \ ADI_AXI_REG_CHAN_CTRL_ENABLE) =20 +struct axi_adc_info { + unsigned int version; + const struct iio_backend_info *backend_info; + bool bus_controller; + const void *pdata; + unsigned int pdata_sz; +}; + struct adi_axi_adc_state { + /* Target ADC platform device */ + struct platform_device *adc_pdev; + const struct axi_adc_info *info; struct regmap *regmap; struct device *dev; /* lock to protect multiple accesses to the device registers */ @@ -325,6 +336,40 @@ static const struct regmap_config axi_adc_regmap_confi= g =3D { .reg_stride =3D 4, }; =20 +static void axi_adc_child_remove(void *data) +{ + struct adi_axi_adc_state *st =3D data; + + platform_device_unregister(st->adc_pdev); +} + +static int axi_adc_create_platform_device(struct adi_axi_adc_state *st, + struct fwnode_handle *child) +{ + struct platform_device_info pi =3D { + .parent =3D st->dev, + .name =3D fwnode_get_name(child), + .id =3D PLATFORM_DEVID_AUTO, + .fwnode =3D child, + .data =3D st->info->pdata, + .size_data =3D st->info->pdata_sz, + }; + struct platform_device *pdev; + int ret; + + pdev =3D platform_device_register_full(&pi); + if (IS_ERR(pdev)) + return PTR_ERR(pdev); + + st->adc_pdev =3D pdev; + + ret =3D devm_add_action_or_reset(st->dev, axi_adc_child_remove, st); + if (ret) + return ret; + + return 0; +} + static const struct iio_backend_ops adi_axi_adc_ops =3D { .enable =3D axi_adc_enable, .disable =3D axi_adc_disable, @@ -370,7 +415,9 @@ static int adi_axi_adc_probe(struct platform_device *pd= ev) return dev_err_probe(&pdev->dev, PTR_ERR(st->regmap), "failed to init register map\n"); =20 - expected_ver =3D device_get_match_data(&pdev->dev); + st->info =3D device_get_match_data(&pdev->dev); + + expected_ver =3D &st->info->version; if (!expected_ver) return -ENODEV; =20 @@ -408,6 +455,25 @@ static int adi_axi_adc_probe(struct platform_device *p= dev) return dev_err_probe(&pdev->dev, ret, "failed to register iio backend\n"); =20 + if (st->info->bus_controller) { + device_for_each_child_node_scoped(&pdev->dev, child) { + int val; + + /* Processing only reg 0 node */ + ret =3D fwnode_property_read_u32(child, "reg", &val); + if (ret || val !=3D 0) + continue; + ret =3D fwnode_property_read_u32(child, "io-backends", + &val); + if (ret) + continue; + + ret =3D axi_adc_create_platform_device(st, child); + if (ret) + continue; + } + } + dev_info(&pdev->dev, "AXI ADC IP core (%d.%.2d.%c) probed\n", ADI_AXI_PCORE_VER_MAJOR(ver), ADI_AXI_PCORE_VER_MINOR(ver), @@ -416,12 +482,15 @@ static int adi_axi_adc_probe(struct platform_device *= pdev) return 0; } =20 -static unsigned int adi_axi_adc_10_0_a_info =3D ADI_AXI_PCORE_VER(10, 0, '= a'); +static const struct axi_adc_info adc_generic =3D { + .version =3D ADI_AXI_PCORE_VER(10, 0, 'a'), + .backend_info =3D &adi_axi_adc_generic, +}; + =20 -/* Match table for of_platform binding */ static const struct of_device_id adi_axi_adc_of_match[] =3D { - { .compatible =3D "adi,axi-adc-10.0.a", .data =3D &adi_axi_adc_10_0_a_inf= o }, - { /* end of list */ } + { .compatible =3D "adi,axi-adc-10.0.a", .data =3D &adc_generic }, + { } }; MODULE_DEVICE_TABLE(of, adi_axi_adc_of_match); =20 --=20 2.34.1 From nobody Sun Nov 24 05:49:20 2024 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (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 972041D14E8 for ; Thu, 21 Nov 2024 10:18:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732184315; cv=none; b=uc8e4np9LO3/tI5C9T3KgmR02PlV9X71NGiZhVJ1KxafedYJ5lp3Jahh0Xb/AY92/haQCPcVB9fFUvApZVCzupZWBKLmrL10ZeInNMTlgOTLdrZW/9cDt+6z6LVwFjuxAy/xKsnpFRVkRjL6Pr29nA2HTRhPl1CiVNxBUT1jpg0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732184315; c=relaxed/simple; bh=wZoWe2uh7o0wDxPA6+E9EMFl/wLAdO0Fg4I6Jk0xuyk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NKqurDQYu7ZdY6LazBBy8j+KovTv7JiffUGBEafxhFYR7wweNH2f14WLqVH7sos/Tx/2VJeDrILiv3F0uspw+hZD1v/snSGaM0io0+O2iqIKe5KOlo34QMqe4bpWCQHt0iJHVYnGDfmLValUy8tQn4eu0BIjZJxNCoWaOszWJHQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=TU+cWkdh; arc=none smtp.client-ip=209.85.221.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="TU+cWkdh" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-382411ea5eeso375483f8f.0 for ; Thu, 21 Nov 2024 02:18:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1732184311; x=1732789111; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Fg+uPrEXF11/PRnUyC5yKUWGEQV9hpuZekI2ZQLsxVA=; b=TU+cWkdhPfFRUd5anBCBvT5USUYh4pFgODMiC82q+ir1TbYtoyqajjFNXrwGeONq0E ebmlwqWIDrBNKYXD/nInapxtAk6fV3LvZb6/2oo4r+sp+gnooGsnkYDodoWR+BJiLz1L icTDB1VndQm89cK+XZc9MrGN5kjlpA+QOwCWjMZvwq8zZMEuSwSSQYjsmLp5eo8knII/ xAoWHcvEOtLbw7jEsR2rrt0TOZeFbR/HxDWpaBpd261LxNgB3zav/0/z2nVCe4WsesRJ 3FxCvBOQqzkA1xfEYR1Tj3l5T7bACWvrMkOdyeuiNG3vhqqhJKdvgNme4YGcB4z4RDvi WsEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732184311; x=1732789111; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Fg+uPrEXF11/PRnUyC5yKUWGEQV9hpuZekI2ZQLsxVA=; b=UvqtzGekK6VESX6nlshx3CwXcnPkbpxNvJTXIc4Az9wbv6QG4lJ+2UTeORkKiSs1gc 47uAI8+f4MSJ/CxoPwHOJc9ucFjCDTWSDNv+brnbd0aN645Q8Q7BjpxTRsekb/v6P23T nH+y+Zyi4s/BIMUHkDTmeyAswYNEfvBSVjDJB+p6D0VL8y4hV6IGvqyAnffMuF/dMQeD qxl03oQ9cTDahZSoRrcyTvjrEyrCW0upFLNr3S8Gb74IZs/Xuwid22uJ3v2eoqzIiw32 tBD9SX0s+3bpvWdFNh0tVLCy5Btv644eC6fussue9L0I0z9xlpFcg0VQGyZy92t6Dumf c/UA== X-Forwarded-Encrypted: i=1; AJvYcCXfxym7RIExERXPJfldak5Wt3e7TNLubleqCRPTeR+YjnBr9zSr2cT4sNPYQp9puPgsHcx1aMTVlH3YXAs=@vger.kernel.org X-Gm-Message-State: AOJu0YzZwuj1KjCvSaQZ0OHvn+HQws5fEYRuPqe9B7Y1dJvmagJzj90f CO7LXzhJvUMrhTiT6p/m+afLy4upZKY36e7JM+cAesgRfYUoJcstsrik4XM6ENHcL2e6BGXxk52 9 X-Google-Smtp-Source: AGHT+IHlDNuJJTOOvoxL7zbj9Zrz4uncleEVmbSRywR9I8Nxpfo6Tdsysq27z9w2ER26L8rzgLmJVw== X-Received: by 2002:a05:6000:1886:b0:382:4b69:9ca4 with SMTP id ffacd0b85a97d-38259d25ec7mr1919620f8f.26.1732184310663; Thu, 21 Nov 2024 02:18:30 -0800 (PST) Received: from [127.0.1.1] (frhb82016ds.ikexpress.com. [185.246.87.17]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38254910796sm4598065f8f.47.2024.11.21.02.18.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 02:18:30 -0800 (PST) From: Guillaume Stols Date: Thu, 21 Nov 2024 10:18:28 +0000 Subject: [PATCH 6/9] iio: adc: adi-axi-adc: Add support for AD7606 register writing Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-ad7606_add_iio_backend_software_mode-v1-6-8a693a5e3fa9@baylibre.com> References: <20241121-ad7606_add_iio_backend_software_mode-v1-0-8a693a5e3fa9@baylibre.com> In-Reply-To: <20241121-ad7606_add_iio_backend_software_mode-v1-0-8a693a5e3fa9@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Nuno Sa , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Hennerich , devicetree@vger.kernel.org, dlechner@baylibre.com, jstephan@baylibre.com, aardelean@baylibre.com, adureghello@baylibre.com, Guillaume Stols X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1732184304; l=5448; i=gstols@baylibre.com; s=20240417; h=from:subject:message-id; bh=wZoWe2uh7o0wDxPA6+E9EMFl/wLAdO0Fg4I6Jk0xuyk=; b=pKU291JFm5SCHkK3zmu0MvLY5KrgkniaEw1tcrkUYwWPsSW/o4djZJGL6ttU2q9QTDBxCED8V ya4O52LVVuYBnoRh3/AynuhdbC4lXiXOYRsIruLbllugCWCA2jIhP9Z X-Developer-Key: i=gstols@baylibre.com; a=ed25519; pk=XvMm5WHuV67sGYOJZqIYzXndbaJOlNd8Q6li6vnb4Cs= Since we must access the bus parallel bus using a custom procedure, let's add a specialized compatible, and define specialized callbacks for writing the registers using the parallel interface. Signed-off-by: Guillaume Stols --- drivers/iio/adc/ad7606_bi.h | 16 +++++++ drivers/iio/adc/adi-axi-adc.c | 99 +++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 115 insertions(+) diff --git a/drivers/iio/adc/ad7606_bi.h b/drivers/iio/adc/ad7606_bi.h new file mode 100644 index 000000000000..9ade23ec61dd --- /dev/null +++ b/drivers/iio/adc/ad7606_bi.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2010-2024 Analog Devices Inc. + * Copyright (c) 2024 Baylibre, SAS + */ +#ifndef __LINUX_PLATFORM_DATA_AD7606_H__ +#define __LINUX_PLATFORM_DATA_AD7606_H__ + +#include + +struct ad7606_platform_data { + int (*bus_reg_read)(struct iio_backend *back, u32 reg, u32 *val); + int (*bus_reg_write)(struct iio_backend *back, u32 reg, u32 val); +}; + +#endif /* __LINUX_PLATFORM_DATA_AD7606_H__ */ diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c index 704ebd6ea83e..d3cc7c25f163 100644 --- a/drivers/iio/adc/adi-axi-adc.c +++ b/drivers/iio/adc/adi-axi-adc.c @@ -27,6 +27,7 @@ #include #include =20 +#include "ad7606_bi.h" /* * Register definitions: * https://wiki.analog.com/resources/fpga/docs/axi_adc_ip#register_map @@ -73,6 +74,12 @@ #define ADI_AXI_ADC_REG_DELAY(l) (0x0800 + (l) * 0x4) #define AXI_ADC_DELAY_CTRL_MASK GENMASK(4, 0) =20 +#define ADI_AXI_REG_CONFIG_WR 0x0080 +#define ADI_AXI_REG_CONFIG_RD 0x0084 +#define ADI_AXI_REG_CONFIG_CTRL 0x008c +#define ADI_AXI_REG_CONFIG_CTRL_READ 0x03 +#define ADI_AXI_REG_CONFIG_CTRL_WRITE 0x01 + #define ADI_AXI_ADC_MAX_IO_NUM_LANES 15 =20 #define ADI_AXI_REG_CHAN_CTRL_DEFAULTS \ @@ -80,6 +87,11 @@ ADI_AXI_REG_CHAN_CTRL_FMT_EN | \ ADI_AXI_REG_CHAN_CTRL_ENABLE) =20 +/* AD7606's specific */ +#define AD7606_REG_READ_BIT 0x8000 +#define AD7606_REG_ADDRESS_MASK 0xff00 +#define AD7606_REG_VALUE_MASK 0x00ff + struct axi_adc_info { unsigned int version; const struct iio_backend_info *backend_info; @@ -313,6 +325,80 @@ static struct iio_buffer *axi_adc_request_buffer(struc= t iio_backend *back, return iio_dmaengine_buffer_setup(st->dev, indio_dev, dma_name); } =20 +static int axi_adc_raw_write(struct iio_backend *back, void *buf, unsigned= int len) +{ + struct adi_axi_adc_state *st =3D iio_backend_get_priv(back); + u32 data; + u32 *bdata =3D buf; + + data =3D *bdata; + regmap_write(st->regmap, ADI_AXI_REG_CONFIG_WR, data); + regmap_write(st->regmap, ADI_AXI_REG_CONFIG_CTRL, + ADI_AXI_REG_CONFIG_CTRL_WRITE); + usleep_range(50, 100); + regmap_write(st->regmap, ADI_AXI_REG_CONFIG_CTRL, 0x00); + usleep_range(50, 100); + + return 0; +} + +static int axi_adc_raw_read(struct iio_backend *back, void *buf, unsigned = int len) +{ + struct adi_axi_adc_state *st =3D iio_backend_get_priv(back); + u32 *bdata =3D buf; + + regmap_write(st->regmap, ADI_AXI_REG_CONFIG_CTRL, + ADI_AXI_REG_CONFIG_CTRL_READ); + usleep_range(50, 100); + regmap_read(st->regmap, ADI_AXI_REG_CONFIG_RD, bdata); + regmap_write(st->regmap, ADI_AXI_REG_CONFIG_CTRL, 0x00); + usleep_range(50, 100); + + return 0; +} + +static int ad7606_bi_reg_read(struct iio_backend *back, u32 reg, u32 *val) +{ + struct adi_axi_adc_state *st =3D iio_backend_get_priv(back); + u32 buf; + + guard(mutex)(&st->lock); + + /* + * The address is written on the highest weight byte, and the MSB set at 1 + * indicates a read operation. + */ + buf =3D FIELD_PREP(AD7606_REG_ADDRESS_MASK, reg) | AD7606_REG_READ_BIT; + axi_adc_raw_write(back, &buf, 4); + axi_adc_raw_read(back, val, 4); + + /* Write 0x0 on the bus to get back to ADC mode */ + buf =3D 0; + axi_adc_raw_write(back, &buf, 4); + return 0; +} + +static int ad7606_bi_reg_write(struct iio_backend *back, u32 reg, u32 val) +{ + struct adi_axi_adc_state *st =3D iio_backend_get_priv(back); + u32 buf; + + guard(mutex)(&st->lock); + + /* Read any register to switch to register mode */ + buf =3D 0xaf00; + axi_adc_raw_write(back, &buf, 4); + + buf =3D FIELD_PREP(AD7606_REG_ADDRESS_MASK, reg) | FIELD_PREP(AD7606_REG_= VALUE_MASK, val); + axi_adc_raw_write(back, &buf, 4); + + /* Write 0x0 on the bus to get back to ADC mode */ + buf =3D 0; + axi_adc_raw_write(back, &buf, 4); + + return 0; +} + static void axi_adc_free_buffer(struct iio_backend *back, struct iio_buffer *buffer) { @@ -487,9 +573,22 @@ static const struct axi_adc_info adc_generic =3D { .backend_info =3D &adi_axi_adc_generic, }; =20 +static const struct ad7606_platform_data ad7606_pdata =3D { + .bus_reg_read =3D ad7606_bi_reg_read, + .bus_reg_write =3D ad7606_bi_reg_write, +}; + +static const struct axi_adc_info adc_ad7606 =3D { + .version =3D ADI_AXI_PCORE_VER(10, 0, 'a'), + .backend_info =3D &adi_axi_adc_generic, + .bus_controller =3D true, + .pdata =3D &ad7606_pdata, + .pdata_sz =3D sizeof(ad7606_pdata), +}; =20 static const struct of_device_id adi_axi_adc_of_match[] =3D { { .compatible =3D "adi,axi-adc-10.0.a", .data =3D &adc_generic }, + { .compatible =3D "adi,axi-ad7606x", .data =3D &adc_ad7606 }, { } }; MODULE_DEVICE_TABLE(of, adi_axi_adc_of_match); --=20 2.34.1 From nobody Sun Nov 24 05:49:20 2024 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 60CC71CC175 for ; Thu, 21 Nov 2024 10:18:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732184316; cv=none; b=oTIpGJUEcl6503sar05SStkcehOlyPAVgRsYDyQY1XYofM3sVkWsEnHl96TyUteVvMAQuST3AAjHEmkG/dMwD0JGf9lK4ZuzVeyQhWwdL76OCDdF1KGEdyvUZa1ekWMg6aamkzC0ncZ0/0PGthu+DFWSbCl0B8H80e0hUprXoeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732184316; c=relaxed/simple; bh=mWJbdcOWnTk8n2J8/cPHfEYESRSRxBYKsYYWv0QF/pU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bQ6ANM14hcgYd9xj0wklGuaD3NiR6KUpgGR4b++uK4kyC+2MZAFbAacm74m3dzJJaxLgeyh8BQullOeID5KPy4sa+b4MSxHOGxw+bNUsTVeH/fmLrO8PHhkXE5ajqPMeGmRSP2x+DGDyj8jR3JY7Obhr5IKnkV5ogCWypAvuA/E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=hpuMVC1E; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="hpuMVC1E" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-4316f3d3c21so5746075e9.3 for ; Thu, 21 Nov 2024 02:18:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1732184312; x=1732789112; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=6yvppB0Gb4awnhkXwOsnVnHx1N5K4iFDBORsNpfC5gc=; b=hpuMVC1EnBpQXzhLPNmk0iWUDAwsQKk3M5f5Sh4HspOhBmf+MdypO/VKy37bYYgu36 HqGD3DNobIajVIojUW+XC8Ek5k2qyGY29ry8bmEz9mOfA3fRTBKEI5KQBvAJmu/eylWA 9AvkCt4vvsJiEZ9mwQJXyfJe33z7g9v5H2UfIUlKoNeptlTNrQ/UoJu+OmYhdMiSJnhb 3FEvtHFRu6z9H/6W/g7epeM+8wFpOOR1ZUSR3r8SXYaQ75W3savvj/CD+yxaeYBqs0yd keYd5B+yMTBq5ziXJXDNQa3VtfRDRy68vmumPrrSnuspLdBNpo0dI0MW/WbsR6XHpS5b RX3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732184312; x=1732789112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6yvppB0Gb4awnhkXwOsnVnHx1N5K4iFDBORsNpfC5gc=; b=t6wQkaIID+HauS/BZD+kP/tYuVYVpftMtakHyQE/MFLierKaVikVJ8uVZomiGA1LUn NRlPXBR9bf0d4OwTQjH46kBENSQbsABKLo1hFWPK9kR70MsPp6euJPrQBsSPxLkhb3ZJ dpmxTgyXk0Wj//IfYjvpmnXYi/xSrcTEJmUz0tGvfF2CRaByje4fG54UjO4+r+PX2XEp oaRglM70GF5snu79FwDWJkXXihmKMQnRU8/mhyYwhopTY/0F+a1o4b+wYeWsdZsuvQNG GQVRFGpt1Lai/IK4+ykxs2XV5z0pkJNOCv2uqNswqH7Kky4h2Xh9T+YRXI2flR4TTA8H O8yg== X-Forwarded-Encrypted: i=1; AJvYcCXjDZfGauBKpIheaoB/ttrWjFFAn1BAuObiWuIWJrvdw6zYPqYZsHYikD6DV5isdWmJ2wl8rFOOU4DcW4c=@vger.kernel.org X-Gm-Message-State: AOJu0Yy8eHUaVD8CR7cJF6Q6NvwekG1dfREtNlvqdN+JPlGpneZ/9Lx8 /SctKmyLfCMtPCl4aGwJkSsmiPSIOSekq0GjpIRcx+DWmFI8FKlTKRI5BMFRT4prMf0fJKhjDNZ Q X-Google-Smtp-Source: AGHT+IEbtJaMjzbWoTEULoBN2rcmiUHCqNBc1aBfOYl+g/90jVcFbWCQozFZpOC51CEECLcdqQ8Ctg== X-Received: by 2002:a05:6000:1f85:b0:382:43ab:7d68 with SMTP id ffacd0b85a97d-38254ade764mr4596133f8f.12.1732184311542; Thu, 21 Nov 2024 02:18:31 -0800 (PST) Received: from [127.0.1.1] (frhb82016ds.ikexpress.com. [185.246.87.17]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38254910796sm4598065f8f.47.2024.11.21.02.18.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 02:18:31 -0800 (PST) From: Guillaume Stols Date: Thu, 21 Nov 2024 10:18:29 +0000 Subject: [PATCH 7/9] iio: adc: ad7606: change r/w_register signature Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-ad7606_add_iio_backend_software_mode-v1-7-8a693a5e3fa9@baylibre.com> References: <20241121-ad7606_add_iio_backend_software_mode-v1-0-8a693a5e3fa9@baylibre.com> In-Reply-To: <20241121-ad7606_add_iio_backend_software_mode-v1-0-8a693a5e3fa9@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Nuno Sa , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Hennerich , devicetree@vger.kernel.org, dlechner@baylibre.com, jstephan@baylibre.com, aardelean@baylibre.com, adureghello@baylibre.com, Guillaume Stols X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1732184304; l=6300; i=gstols@baylibre.com; s=20240417; h=from:subject:message-id; bh=mWJbdcOWnTk8n2J8/cPHfEYESRSRxBYKsYYWv0QF/pU=; b=v0wbCrnNqagKEBoeuGktHDzPiFQXMbyEU4gIKTCneCAtkY3DYEU15wNrGmXjqXw5l3p/DYhfh aYc82Pj46lKC+KR7xMVXgQVy2EwKSrQJnD2/SWMrtEu+Z+kKKUxOCBi X-Developer-Key: i=gstols@baylibre.com; a=ed25519; pk=XvMm5WHuV67sGYOJZqIYzXndbaJOlNd8Q6li6vnb4Cs= The register read/write with IIO backend will require to claim the direct mode, and doing so requires passing the corresponding iio_dev structure. So we need to modify the function signature to pass the iio_dev structure. Signed-off-by: Guillaume Stols --- drivers/iio/adc/ad7606.c | 25 +++++++++++-------------- drivers/iio/adc/ad7606.h | 8 ++++---- drivers/iio/adc/ad7606_spi.c | 10 +++++----- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index df0e49bc4bdb..ef1c79587edb 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -574,13 +574,13 @@ static int ad7606_reg_access(struct iio_dev *indio_de= v, guard(mutex)(&st->lock); =20 if (readval) { - ret =3D st->bops->reg_read(st, reg); + ret =3D st->bops->reg_read(indio_dev, reg); if (ret < 0) return ret; *readval =3D ret; return 0; } else { - return st->bops->reg_write(st, reg, writeval); + return st->bops->reg_write(indio_dev, reg, writeval); } } =20 @@ -1148,26 +1148,26 @@ static const struct iio_trigger_ops ad7606_trigger_= ops =3D { .validate_device =3D iio_trigger_validate_own_device, }; =20 -static int ad7606_write_mask(struct ad7606_state *st, +static int ad7606_write_mask(struct iio_dev *indio_dev, unsigned int addr, unsigned long mask, unsigned int val) { + struct ad7606_state *st =3D iio_priv(indio_dev); int readval; =20 - readval =3D st->bops->reg_read(st, addr); + readval =3D st->bops->reg_read(indio_dev, addr); if (readval < 0) return readval; =20 readval &=3D ~mask; readval |=3D val; =20 - return st->bops->reg_write(st, addr, readval); + return st->bops->reg_write(indio_dev, addr, readval); } =20 static int ad7616_write_scale_sw(struct iio_dev *indio_dev, int ch, int va= l) { - struct ad7606_state *st =3D iio_priv(indio_dev); unsigned int ch_addr, mode, ch_index; =20 /* @@ -1189,23 +1189,20 @@ static int ad7616_write_scale_sw(struct iio_dev *in= dio_dev, int ch, int val) /* 0b01 for 2.5v, 0b10 for 5v and 0b11 for 10v */ mode =3D AD7616_RANGE_CH_MODE(ch_index, ((val + 1) & 0b11)); =20 - return ad7606_write_mask(st, ch_addr, AD7616_RANGE_CH_MSK(ch_index), + return ad7606_write_mask(indio_dev, ch_addr, AD7616_RANGE_CH_MSK(ch_index= ), mode); } =20 static int ad7616_write_os_sw(struct iio_dev *indio_dev, int val) { - struct ad7606_state *st =3D iio_priv(indio_dev); =20 - return ad7606_write_mask(st, AD7616_CONFIGURATION_REGISTER, + return ad7606_write_mask(indio_dev, AD7616_CONFIGURATION_REGISTER, AD7616_OS_MASK, val << 2); } =20 static int ad7606_write_scale_sw(struct iio_dev *indio_dev, int ch, int va= l) { - struct ad7606_state *st =3D iio_priv(indio_dev); - - return ad7606_write_mask(st, + return ad7606_write_mask(indio_dev, AD7606_RANGE_CH_ADDR(ch), AD7606_RANGE_CH_MSK(ch), AD7606_RANGE_CH_MODE(ch, val)); @@ -1215,7 +1212,7 @@ static int ad7606_write_os_sw(struct iio_dev *indio_d= ev, int val) { struct ad7606_state *st =3D iio_priv(indio_dev); =20 - return st->bops->reg_write(st, AD7606_OS_MODE, val); + return st->bops->reg_write(indio_dev, AD7606_OS_MODE, val); } =20 static int ad7616_sw_mode_setup(struct iio_dev *indio_dev) @@ -1236,7 +1233,7 @@ static int ad7616_sw_mode_setup(struct iio_dev *indio= _dev) return ret; =20 /* Activate Burst mode and SEQEN MODE */ - return ad7606_write_mask(st, + return ad7606_write_mask(indio_dev, AD7616_CONFIGURATION_REGISTER, AD7616_BURST_MODE | AD7616_SEQEN_MODE, AD7616_BURST_MODE | AD7616_SEQEN_MODE); diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index 7a044b499cfe..eca7ea99e24d 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -235,10 +235,10 @@ struct ad7606_bus_ops { int (*iio_backend_config)(struct device *dev, struct iio_dev *indio_dev); int (*read_block)(struct device *dev, int num, void *data); int (*sw_mode_config)(struct iio_dev *indio_dev); - int (*reg_read)(struct ad7606_state *st, unsigned int addr); - int (*reg_write)(struct ad7606_state *st, - unsigned int addr, - unsigned int val); + int (*reg_read)(struct iio_dev *indio_dev, unsigned int addr); + int (*reg_write)(struct iio_dev *indio_dev, + unsigned int addr, + unsigned int val); int (*update_scan_mode)(struct iio_dev *indio_dev, const unsigned long *s= can_mask); u16 (*rd_wr_cmd)(int addr, char isWriteOp); }; diff --git a/drivers/iio/adc/ad7606_spi.c b/drivers/iio/adc/ad7606_spi.c index 640e36092662..376b8a72e8d4 100644 --- a/drivers/iio/adc/ad7606_spi.c +++ b/drivers/iio/adc/ad7606_spi.c @@ -128,8 +128,9 @@ static int ad7606_spi_read_block18to32(struct device *d= ev, return spi_sync_transfer(spi, &xfer, 1); } =20 -static int ad7606_spi_reg_read(struct ad7606_state *st, unsigned int addr) +static int ad7606_spi_reg_read(struct iio_dev *indio_dev, unsigned int add= r) { + struct ad7606_state *st =3D iio_priv(indio_dev); struct spi_device *spi =3D to_spi_device(st->dev); struct spi_transfer t[] =3D { { @@ -152,10 +153,11 @@ static int ad7606_spi_reg_read(struct ad7606_state *s= t, unsigned int addr) return be16_to_cpu(st->d16[1]); } =20 -static int ad7606_spi_reg_write(struct ad7606_state *st, +static int ad7606_spi_reg_write(struct iio_dev *indio_dev, unsigned int addr, unsigned int val) { + struct ad7606_state *st =3D iio_priv(indio_dev); struct spi_device *spi =3D to_spi_device(st->dev); =20 st->d16[0] =3D cpu_to_be16((st->bops->rd_wr_cmd(addr, 1) << 8) | @@ -166,8 +168,6 @@ static int ad7606_spi_reg_write(struct ad7606_state *st, =20 static int ad7616_sw_mode_config(struct iio_dev *indio_dev) { - struct ad7606_state *st =3D iio_priv(indio_dev); - /* * Scale can be configured individually for each channel * in software mode. @@ -182,7 +182,7 @@ static int ad7606B_sw_mode_config(struct iio_dev *indio= _dev) struct ad7606_state *st =3D iio_priv(indio_dev); =20 /* Configure device spi to output on a single channel */ - st->bops->reg_write(st, + st->bops->reg_write(indio_dev, AD7606_CONFIGURATION_REGISTER, AD7606_SINGLE_DOUT); =20 --=20 2.34.1 From nobody Sun Nov 24 05:49:20 2024 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 3DAFA1D2F74 for ; Thu, 21 Nov 2024 10:18:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732184316; cv=none; b=d1r/orGArXVqbtSYL/SXoA1YDgLYQffOs6HYFUv1T2l6rqsoMetcSCmvuZGJKpQlDXkn6jpVKK+wfJ7d1P+jr4DkRoxQRau2SFDIkctdtjpAYp3W5CpVyVL6OjFReUTAB0ntW4M0rCcfA5EaSxM0o6s4tOl2Tmlf5+iSNjQZCjg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732184316; c=relaxed/simple; bh=Rm7fdKwuILN1wABcMwtBOX8LaUe3ccIFEyDzCkBVoDQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TgrazN0/eijrGgzmL9ZtVTbSB3fXwttXoz1jC5XxK1vIP4uBqRki8LigQN5e8JbXEyrxohWwF2+NUlDBE48AdzaFGq0vdXXmZqsMRT6fL3g51ALcoipjvg4NM/O2HKbOj4r27GTccuEbHqv08A5xdKuapDOUc81gh/Mv6eqEzOo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=Fmoj9FCx; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="Fmoj9FCx" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-3823eaad37aso1174164f8f.0 for ; Thu, 21 Nov 2024 02:18:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1732184313; x=1732789113; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=wHaSxL3+Y30jYFHs/JHdzuANlkeArnNpuo2+kK7YYpY=; b=Fmoj9FCxo9XRZKTpii/pRYEd71/sPatc9Euyh13M1fesvmOlzIh1DQEM8w/BEUckJq yAhv/HePjRcKKHaOyJi2YwNw/a2up90wh1WNPieAOKsf4s2xGtmrHyJgXDCgmrZHW7hW Ds6PvzZEVyRq9SfE0wFvngby8Sl9UIsrrgIdrnReRQiiKDj0oPiiy+ucYTTu7NxsPt1F blDiJFGGHDFNR3LbcC29uCk+S2CfuiTFebbbtPHnPML0dEGav6+EPM8a1yAqDoUmhhrO ENCjpRoATkUPkEg4BKwThBiSkqxOpygU2B6aXpqT+nrfKTcn7RJVs1wQyush7MaDBp7d WPEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732184313; x=1732789113; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wHaSxL3+Y30jYFHs/JHdzuANlkeArnNpuo2+kK7YYpY=; b=O6HXldgeHzFNzBIgFXmcq6le9nW1TBKhNkuZDUQ8mNzogcefz4GYwPwIripp7EybVb PNLKlFvms4B/b98W/4++nkUd7AdjCc+zoXdnkX8457ITHccOPKDk5ai/dZ9LkUHX/xbn Tx2H88/CPckN2Vn8BYwg2uLYKIZHu4j3AW8YFBfr9WorSIHhLrETb050If8pSVx+sLXg 16KpRoDUoyfzHw2TR+649BLXMRmyLjDaQDJVIQcoy2ouwHJromhw0QbgKURHnV66JD9l N+jdthpRNhfezkdT5IX69YgV2qkyhrY6sGRRKNe9pvXnpRtq0xxBvBl03TI9fWg+Dwbq TB9A== X-Forwarded-Encrypted: i=1; AJvYcCUuMUQhWCJOJJbxBkWmhdwfXIH7+kdi0lJa7XRA444HhPmuREaSFRUZ3Db6kQmq+CJssf7s3Gd/7VTmGGA=@vger.kernel.org X-Gm-Message-State: AOJu0YzzZ9SvBj+4fVNMe8/GbR56RLKRu3zyFhQ5p1ZwI256SboRpYxV uzWsmbxRBVUvEZDUrz/p4mDdVsEIPkhR5DBsP18JxqMqGVgi6iPwnez7Jd157uasrDfJD6PjJKt J X-Google-Smtp-Source: AGHT+IHG6NXlIBhSHjBBI33tsOYshaSt/FYtyInlElG+QJyXqLXRCysPCVrrRaxPhu/BywhhESHpQQ== X-Received: by 2002:a5d:64ce:0:b0:37d:34e7:6d24 with SMTP id ffacd0b85a97d-38259d2b848mr2047885f8f.18.1732184312352; Thu, 21 Nov 2024 02:18:32 -0800 (PST) Received: from [127.0.1.1] (frhb82016ds.ikexpress.com. [185.246.87.17]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38254910796sm4598065f8f.47.2024.11.21.02.18.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 02:18:31 -0800 (PST) From: Guillaume Stols Date: Thu, 21 Nov 2024 10:18:30 +0000 Subject: [PATCH 8/9] iio: adc: ad7606: Simplify channel macros Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-ad7606_add_iio_backend_software_mode-v1-8-8a693a5e3fa9@baylibre.com> References: <20241121-ad7606_add_iio_backend_software_mode-v1-0-8a693a5e3fa9@baylibre.com> In-Reply-To: <20241121-ad7606_add_iio_backend_software_mode-v1-0-8a693a5e3fa9@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Nuno Sa , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Hennerich , devicetree@vger.kernel.org, dlechner@baylibre.com, jstephan@baylibre.com, aardelean@baylibre.com, adureghello@baylibre.com, Guillaume Stols X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1732184304; l=3067; i=gstols@baylibre.com; s=20240417; h=from:subject:message-id; bh=Rm7fdKwuILN1wABcMwtBOX8LaUe3ccIFEyDzCkBVoDQ=; b=PeM+F7Unq5hw0qEHvjQSXhzdr0HCrmaP/6KBbQl3LVfPREko98epnF7/FmSX40NPefdf3wTE+ XW38P2aduRIASA6qwyuPT6eMhTvxk8EiUcwME6QBmz28QFQzYAZTZ9e X-Developer-Key: i=gstols@baylibre.com; a=ed25519; pk=XvMm5WHuV67sGYOJZqIYzXndbaJOlNd8Q6li6vnb4Cs= This is a preparation to add the new channels for software mode and hardware mode in iio backend mod more easily. Signed-off-by: Guillaume Stols --- drivers/iio/adc/ad7606.h | 51 ++++++++++++++++++++++++--------------------= ---- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index eca7ea99e24d..74896d9f1929 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -40,37 +40,19 @@ #define AD7606_RANGE_CH_ADDR(ch) (0x03 + ((ch) >> 1)) #define AD7606_OS_MODE 0x08 =20 -#define AD760X_CHANNEL(num, mask_sep, mask_type, mask_all, bits) { \ +#define AD760X_CHANNEL(num, mask_sep, mask_type, mask_all, \ + mask_sep_avail, mask_all_avail, bits) { \ .type =3D IIO_VOLTAGE, \ .indexed =3D 1, \ .channel =3D num, \ .address =3D num, \ .info_mask_separate =3D mask_sep, \ + .info_mask_separate_available =3D \ + mask_sep_avail, \ .info_mask_shared_by_type =3D mask_type, \ .info_mask_shared_by_all =3D mask_all, \ - .scan_index =3D num, \ - .scan_type =3D { \ - .sign =3D 's', \ - .realbits =3D (bits), \ - .storagebits =3D (bits) > 16 ? 32 : 16, \ - .endianness =3D IIO_CPU, \ - }, \ -} - -#define AD7606_SW_CHANNEL(num, bits) { \ - .type =3D IIO_VOLTAGE, \ - .indexed =3D 1, \ - .channel =3D num, \ - .address =3D num, \ - .info_mask_separate =3D \ - BIT(IIO_CHAN_INFO_RAW) | \ - BIT(IIO_CHAN_INFO_SCALE), \ - .info_mask_separate_available =3D \ - BIT(IIO_CHAN_INFO_SCALE), \ - .info_mask_shared_by_all =3D \ - BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ .info_mask_shared_by_all_available =3D \ - BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + mask_all_avail, \ .scan_index =3D num, \ .scan_type =3D { \ .sign =3D 's', \ @@ -82,12 +64,28 @@ =20 #define AD7605_CHANNEL(num) \ AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_RAW), \ - BIT(IIO_CHAN_INFO_SCALE), 0, 16) + BIT(IIO_CHAN_INFO_SCALE), 0, 0, 0, 16) =20 #define AD7606_CHANNEL(num, bits) \ AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_RAW), \ BIT(IIO_CHAN_INFO_SCALE), \ - BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), bits) + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + 0, 0, bits) + +#define AD7606_SW_CHANNEL(num, bits) \ + AD760X_CHANNEL(num, \ + /* mask separate */ \ + BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE), \ + /* mask type */ \ + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + /* mask all */ \ + 0, \ + /* mask separate available */ \ + BIT(IIO_CHAN_INFO_SCALE), \ + /* mask all available */ \ + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + bits) =20 #define AD7616_CHANNEL(num) AD7606_SW_CHANNEL(num, 16) =20 @@ -95,7 +93,8 @@ AD760X_CHANNEL(num, 0, \ BIT(IIO_CHAN_INFO_SCALE), \ BIT(IIO_CHAN_INFO_SAMP_FREQ) | \ - BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 16) + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + 0, 0, 16) =20 struct ad7606_state; =20 --=20 2.34.1 From nobody Sun Nov 24 05:49:20 2024 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (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 9025D1D432A for ; Thu, 21 Nov 2024 10:18:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732184319; cv=none; b=o/7zVX9EhzuzR6+IHK+Rg/VSgM52En23BcfawH9aN/vVK8TtxAINMFIo/Lx58QfxBAeVMubxHuKlD8zapQ4/2M+HKtw8mo5BvbLxilFdtsbGvphN5dm99rpDpNKvMJgVMG6FxcN8MOYndfmM041mK/Sy1lBl3OxoFQUynWtGkeI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732184319; c=relaxed/simple; bh=tdpf/A32vha/ko+aQ4RiDlCU44C08sRlPZcE4GA5DLw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hWbcqtBFPquW1q1hPW51/AQ4MrwMvCdL1c+8q8n3HBO+l3AqTggflnXoSGXvw32XU3lG73WByXEGuaCGh9cv2PYjwa1OamtfONr2rNFCzDc+JUTGo5eNZODX6N0FKuQxYqM4qOSZ0tbhpHKVugXlfYFhwhqs4nKBA0ptZdC5Uus= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=DykALw7/; arc=none smtp.client-ip=209.85.167.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="DykALw7/" Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-53da2140769so731749e87.3 for ; Thu, 21 Nov 2024 02:18:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1732184314; x=1732789114; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=oRi3cIGaDlxTwStqxhJi+pjnXvvxLtR6kDzgcy0nvWU=; b=DykALw7/frZ4guuLjcJy3QLI27TsYnjlBF+Rp26TY0HOr++EB8A492iHO1HMMlSuvT ECioZDo0EtB47ArSfNy3Zx5MshJwOPADKbwjk2cbjbAp/desRpNEeZJPBcWMPkonU1T8 CbhWyz8VXpbY/rv71T/7rulwOffJfYoj0lG+84JavTWxa5c4ayfPkBYUD2mO82WKryWz KW8wNahBNtUVMRkSLoAtMjOlOKPfqrU27gkSAXTy6igFG+vo+XTHISimcw4SefuRc7M4 oJYG+mPGTna0hDTAS6vVWp+F/4Dc/M/VbVbNroocfbl2A4mezBpT8cmOJHcGIPk3PzsP zf2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732184314; x=1732789114; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oRi3cIGaDlxTwStqxhJi+pjnXvvxLtR6kDzgcy0nvWU=; b=gMq+qcbiU+z60o+pD/2oE1ropUydZxdULA/kflOUZ90Ofz8lla7xQjhPHef7rsyy0Z FeBtgoHRD3xrxqKDWlsxDiA8KwYfch8uy4eQSnACeojAqQCPc34cfUTlPGOXbY3zP/ji xgxG3bcYoqsZN0lCIJLkjsUobGNB9Hkzg3iiLaovMhX9HTMHirwkkVTvqQQBvx+wKJtg Dj5BVzKh7rQVzyijrI6TsMWW1Xrr+gDetOYWhgt36H+Y2c0vzFphMaybqs5yak6Ogrv+ neQDOLnZHi+ElpTsweWjvA49Z+PixqsS0izG1FwGvKHfXrQmCk3vJguPPPZs80bqnpGI KmzA== X-Forwarded-Encrypted: i=1; AJvYcCU0TEqEZwS8Fftj7zwURTobj37jWJqfxbqskXP+XOyGbD5ajJfAGUhdYrDJHxjZK9arc/NDH07mEJI+IpI=@vger.kernel.org X-Gm-Message-State: AOJu0Yx6Wqvc06DfusKLZ6+sxQZETinGmw0owghPiLOskDaFc3Mf38sV kHIsoEJFRCeUtg9hc9S2TdE1mZhjqZ6OJ2R+lNogsBurXkdc586dp82V1z0VjkShNbgfWh2r6OI o X-Google-Smtp-Source: AGHT+IFd0X5sd0gLrWTrdWHzSVGz3bjzzQ0tWK2LA5BLwCGIn3GL8B7rGGMHcyvlWsAO9re9qR5F2w== X-Received: by 2002:a05:6512:53c:b0:53d:a309:7fa3 with SMTP id 2adb3069b0e04-53dc1368c75mr2424566e87.41.1732184313217; Thu, 21 Nov 2024 02:18:33 -0800 (PST) Received: from [127.0.1.1] (frhb82016ds.ikexpress.com. [185.246.87.17]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38254910796sm4598065f8f.47.2024.11.21.02.18.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 02:18:32 -0800 (PST) From: Guillaume Stols Date: Thu, 21 Nov 2024 10:18:31 +0000 Subject: [PATCH 9/9] iio: adc: ad7606: Add support for writing registers when using backend Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-ad7606_add_iio_backend_software_mode-v1-9-8a693a5e3fa9@baylibre.com> References: <20241121-ad7606_add_iio_backend_software_mode-v1-0-8a693a5e3fa9@baylibre.com> In-Reply-To: <20241121-ad7606_add_iio_backend_software_mode-v1-0-8a693a5e3fa9@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Nuno Sa , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Hennerich , devicetree@vger.kernel.org, dlechner@baylibre.com, jstephan@baylibre.com, aardelean@baylibre.com, adureghello@baylibre.com, Guillaume Stols X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1732184304; l=4035; i=gstols@baylibre.com; s=20240417; h=from:subject:message-id; bh=tdpf/A32vha/ko+aQ4RiDlCU44C08sRlPZcE4GA5DLw=; b=IG8R0F6BS7ExulQfzVIBxrGS6fS4qof4AM1NKLiCQyCH0n6OvosUfzcczsrHesp1cJt3Lyfo+ apRxWf5SaiKAiTV14WHE7FXNgmJPpz53QR3HGCdb4Gc/yULdOclYON/ X-Developer-Key: i=gstols@baylibre.com; a=ed25519; pk=XvMm5WHuV67sGYOJZqIYzXndbaJOlNd8Q6li6vnb4Cs= Adds the logic for effectively enabling the software mode for the iio-backend, i.e enabling the software mode channel configuration and implementing the register writing functions. Signed-off-by: Guillaume Stols --- drivers/iio/adc/ad7606.h | 15 ++++++++++++ drivers/iio/adc/ad7606_par.c | 58 ++++++++++++++++++++++++++++++++++++++++= +++- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index 74896d9f1929..a54dc110839f 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -96,6 +96,21 @@ BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ 0, 0, 16) =20 +#define AD7606_BI_SW_CHANNEL(num) \ + AD760X_CHANNEL(num, \ + /* mask separate */ \ + BIT(IIO_CHAN_INFO_SCALE), \ + /* mask type */ \ + 0, \ + /* mask all */ \ + BIT(IIO_CHAN_INFO_SAMP_FREQ) | \ + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + /* mask separate available */ \ + BIT(IIO_CHAN_INFO_SCALE), \ + /* mask all available */ \ + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + 16) + struct ad7606_state; =20 typedef int (*ad7606_scale_setup_cb_t)(struct iio_dev *indio_dev, diff --git a/drivers/iio/adc/ad7606_par.c b/drivers/iio/adc/ad7606_par.c index a25182a3daa7..0c1177f436f3 100644 --- a/drivers/iio/adc/ad7606_par.c +++ b/drivers/iio/adc/ad7606_par.c @@ -13,12 +13,14 @@ #include #include #include +#include #include =20 #include #include =20 #include "ad7606.h" +#include "ad7606_bi.h" =20 static const struct iio_chan_spec ad7606b_bi_channels[] =3D { AD7606_BI_CHANNEL(0), @@ -31,6 +33,17 @@ static const struct iio_chan_spec ad7606b_bi_channels[] = =3D { AD7606_BI_CHANNEL(7), }; =20 +static const struct iio_chan_spec ad7606b_bi_sw_channels[] =3D { + AD7606_BI_SW_CHANNEL(0), + AD7606_BI_SW_CHANNEL(1), + AD7606_BI_SW_CHANNEL(2), + AD7606_BI_SW_CHANNEL(3), + AD7606_BI_SW_CHANNEL(4), + AD7606_BI_SW_CHANNEL(5), + AD7606_BI_SW_CHANNEL(6), + AD7606_BI_SW_CHANNEL(7), +}; + static int ad7606_bi_update_scan_mode(struct iio_dev *indio_dev, const uns= igned long *scan_mask) { struct ad7606_state *st =3D iio_priv(indio_dev); @@ -70,7 +83,7 @@ static int ad7606_bi_setup_iio_backend(struct device *dev= , struct iio_dev *indio if (ret) return ret; =20 - ret =3D devm_iio_backend_enable(dev, st->back); + ret =3D devm_iio_backend_enable(st->dev, st->back); if (ret) return ret; =20 @@ -86,9 +99,52 @@ static int ad7606_bi_setup_iio_backend(struct device *de= v, struct iio_dev *indio return 0; } =20 +static int ad7606_bi_reg_read(struct iio_dev *indio_dev, unsigned int addr) +{ + struct ad7606_state *st =3D iio_priv(indio_dev); + int val, ret; + struct ad7606_platform_data *pdata =3D st->dev->platform_data; + + iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { + ret =3D pdata->bus_reg_read(st->back, + addr, + &val); + } + if (ret < 0) + return ret; + + return val; +} + +static int ad7606_bi_reg_write(struct iio_dev *indio_dev, + unsigned int addr, + unsigned int val) +{ + struct ad7606_state *st =3D iio_priv(indio_dev); + struct ad7606_platform_data *pdata =3D st->dev->platform_data; + int ret; + + iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { + ret =3D pdata->bus_reg_write(st->back, + addr, + val); + } + return ret; +} + +static int ad7606_bi_sw_mode_config(struct iio_dev *indio_dev) +{ + indio_dev->channels =3D ad7606b_bi_sw_channels; + + return 0; +} + static const struct ad7606_bus_ops ad7606_bi_bops =3D { .iio_backend_config =3D ad7606_bi_setup_iio_backend, .update_scan_mode =3D ad7606_bi_update_scan_mode, + .reg_read =3D ad7606_bi_reg_read, + .reg_write =3D ad7606_bi_reg_write, + .sw_mode_config =3D ad7606_bi_sw_mode_config, }; =20 static int ad7606_par16_read_block(struct device *dev, --=20 2.34.1