From nobody Tue Nov 26 04:43:33 2024 Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (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 287E81F427E for ; Mon, 21 Oct 2024 13:02:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729515760; cv=none; b=ZcSnhdycyboag2OKc+ZQiRUzNTYzxfvxGuMz2JURekzJYQIcBf3vPvNQ11vVUOTN+cPOMx9evGn4UlZzCDw4BiBkSH6sVyFmdi+CIju0nb78+yTOxmKIBM6nUXL58ABVKlAHmwbN9HfvIZRxkCWuljqpv3Oakjem2RUsSCjMvJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729515760; c=relaxed/simple; bh=rGc3MWfnfDGr6DVhiTPyA4ENZmPwmhTHYX0jVVNz4Pg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F9sBMbfpn2HQazR6AW4koOcB2lgk61Cyo3hvdHCJ/UDaZRQLZhxTvwQ0Z+mgM1CQzLg9oT+leIw1utWloj3eLrZ2rByaf42USfcj/x4wt8Uc7Vg+qKCC0b80+v6jFU6QLeYfZ9f08e9Y6af8KsBb0e4uQeFuZnRDLgOHCQYFBkg= 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=k1oyHZjP; arc=none smtp.client-ip=209.85.218.49 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="k1oyHZjP" Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a7aa086b077so510761166b.0 for ; Mon, 21 Oct 2024 06:02:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729515755; x=1730120555; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZMGdrMcJaMIE/WsVeQifPxez2nYQfB71+FONgrmlyfk=; b=k1oyHZjPOZFF6Nnl4Zfu8b37roYAcXLz9y48PPHuM/bIyXJEtoAOugAikzqQL9HKeO bCszx1jPas93Dnxd/YWfpv5K6fZQU2kGDKqamHjC+vWSze+SQDQcw2ui8kNj3KALWnCJ BcNGEZrRXEpDBRlxB4vgyAQEzzqBXYfox0FkXTAkHA7myjKy/NWVVUDUmok6ohdRYau0 vQShNL987ofwmFqKfnEepVSMUrHQSA2zc/RPBkMVzvIK11GhZlAZEvBXIRWiUzVcLwix FcZOd0RRxOyHAuMgIViURP+gO+K1sYqits68X6UM0gDb8yRRZIxRRSqSSIhhyo+dnwVb bTIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729515755; x=1730120555; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZMGdrMcJaMIE/WsVeQifPxez2nYQfB71+FONgrmlyfk=; b=B/p0Yxy9jvMrbAe/q/Dq9WEpTEyE0v7ByZqzwJZXvxX+94loPNLzHffDAOk2DPYem8 BSEaYaUM7FsmZ1hacPMnZ6s8iOpI1eIdU103xoQo/yzx2w/x+yoM643slGsMUTcccjqw sIentcsWd1RAN9J/nRTLq2VmLTPZARITuqrMCcOKa8WOv+5zZDktHlnSM4ehPqqzs46t hIUCZnsnr9IYqFQuVU6jARHQ9buTDDFij7lu+FYpLvo3EnY62dBU6s7XTA+7xieFS4Hr nL6N0GnaCum19LfgbA8olbXgMJcQGEi+Cl2V74IWjyZgxqWUfsInVVRTmKC9ZrXZ7F1r 6yHg== X-Forwarded-Encrypted: i=1; AJvYcCWw2Pzoh8Hcm1MA3Mn45mEPcJ50UEyrp5XLyoXOjxWts125pgTk9NuXKiiqx4xWSB5cyEsQpkO88ru6ym0=@vger.kernel.org X-Gm-Message-State: AOJu0YybzoZbsYnLaQERzNJHXJkZVIdyAfTlVOvwD2fK4BgKWR7FRThl KniGHsb7ybrJm5ghGY0+u4Cb4e7DUOTW7Sjfc/brhM3xrl1f62Xwh0RkegsqIIc= X-Google-Smtp-Source: AGHT+IFkz8SL5tRoEjiGw3OR74ITdupWm+6UEIZV8nbsB9DktPH3yo+8/SVwqYy+2px7vXfLIHf/iQ== X-Received: by 2002:a17:907:742:b0:a9a:5a14:b8d8 with SMTP id a640c23a62f3a-a9a69c9b867mr1237004366b.43.1729515755342; Mon, 21 Oct 2024 06:02:35 -0700 (PDT) Received: from neptune.lan ([188.27.132.100]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a91370e33sm202310366b.120.2024.10.21.06.02.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 06:02:34 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: jic23@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, michael.hennerich@analog.com, gstols@baylibre.com, dlechner@baylibre.com, Alexandru Ardelean Subject: [PATCH 1/6] iio: adc: ad7606: fix/persist oversampling_ratio setting Date: Mon, 21 Oct 2024 16:02:16 +0300 Message-ID: <20241021130221.1469099-2-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241021130221.1469099-1-aardelean@baylibre.com> References: <20241021130221.1469099-1-aardelean@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When the mutexes were reworked to guards, the caching of the oversampling_ratio values was removed by accident. The main effect of this change is that, after setting the oversampling_ratio value, reading it back would result in the initial value (of 1). The value would get sent to the device correctly though. Fixes 2956979dbd0d: ("iio: adc: ad7606: switch mutexes to guard") Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7606.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index 0e830a17fc19..ae49f4ba50d9 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -753,6 +753,7 @@ static int ad7606_write_raw(struct iio_dev *indio_dev, ret =3D st->write_os(indio_dev, i); if (ret < 0) return ret; + st->oversampling =3D st->oversampling_avail[i]; =20 return 0; case IIO_CHAN_INFO_SAMP_FREQ: --=20 2.46.1 From nobody Tue Nov 26 04:43:33 2024 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (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 D18821F1311 for ; Mon, 21 Oct 2024 13:02:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729515763; cv=none; b=oPG7IzzuXmHR3BV+S4/crK2QZZLHZcyHwTS+lfkHGmpVkiHPgsS2c/sG2/7HPINt4rDC9EHXp2o2uktHiJ+0PFv5UlIF0ITWBfiG9oeRpvRiM3Hj/G5T/Vz7MuVu0sMKGwMXJbTZnBG0atuwkBpkiJ59GTetkFuS+tKaPEf0OvE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729515763; c=relaxed/simple; bh=/vHDMY5+soiiVfTJjsDcl+Tcn8eg5D/9fZbUdcL/foU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GZDyLN+gflCTV7q0Vs/HEpypaIoEb6mI1Hgh12oe2Q6SVmyuDRjWYPvIfb0wnF+YU1ecpK1fn6E9PqpUnVNGwUvhtdl+t0N4q1BthKToiPnoQ+jfEbgLneZAwd8yvzuAV11ev4BFDNmGAFu17r8pD1g0klDkVHxGKFO5cWZkNPI= 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=Q9dbUDkt; arc=none smtp.client-ip=209.85.218.43 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="Q9dbUDkt" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a9a2cdc6f0cso611331166b.2 for ; Mon, 21 Oct 2024 06:02:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729515759; x=1730120559; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZsfTKhMEzsTUvMUHcKoet4fyDQT+vLa6vltcamFvJHs=; b=Q9dbUDktySgU9j5QJ7gXGiL003SRWdcLbxVNVIPmuUkuoRpC5oXLFGTbY1GNaCpT/V yjH1aTZ8qCjWDsQJxuxyk9dJzKtEzQxX6zaKS7sDJf16zXOFmKzt2eX7nZkZupeEK/S9 FktvbDki6mCItCccsuuE4SBqFAv6s1/tJbukB49rv+U6BjttRtMmokoCRTLCs4bASvwf Tz3SZ16aiM9/Z4Q82Wn64kmk/qXIoN4mhKspfa6WoSHzJZfTwTWYaGuL3zmaDYgN3Yzz mudJA03ovz7L1/Q7aORCfWtuueMsaGXVydfUHM1NekWnfZXRfSEYtnvPvjvWBOcNgwZQ POCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729515759; x=1730120559; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZsfTKhMEzsTUvMUHcKoet4fyDQT+vLa6vltcamFvJHs=; b=j7IaKolSCAAFRTsujTn9T4Ny0ZOIuWcNxeB/vrxMYKZDjr9coAJFBXy+gRvUALutq5 hIZRtb0uoV+avDqLNWEiIrmdPioFIzkvDSjD0AfMnVteKFF2jKs1j7GLCt/JYNQkpq/C Xr/9aeZEmNxLVsITQgekBxwQNLPLVzQ0IxRJr+2OXu8m99yzyZsaAhmw9G05H8n3ENql +FrrzKTQOMrKgNhl+Z9r21NAD6UXz/9xD8yU1JPBFCznwon1WuAx+tjW9QlsUsqueXW4 XEPdPFhQ5UXVJFU3DCBYJKgabBqeDDHucvQHq/MJvOp56khiBE5CwHmL2e6KdNpUZjYs 6yKA== X-Forwarded-Encrypted: i=1; AJvYcCWKZpxywDSRvizpM4Cpxg3f/mgUUpLMwHInwOkZyIH6rjQN2Ks5aSWlwhj1fL4I5MxXrz8SdXnQLDA8VRI=@vger.kernel.org X-Gm-Message-State: AOJu0Yx3Q6kAX8k2yCc5foZHNUbD9FH+m2CCaAUDcCH82xSUsMhqh4EY o1g8qYXsgihMZ4tE0z5Hvi71KfGXMe3enR9YBtqlwddi4Q36IiYcytUhG0iT5SQ= X-Google-Smtp-Source: AGHT+IEPUP36vChr4GiXp1vvE557inTV7I5+nNTM1UCGdCqVCiic3/5/zLwBJM3KSQWg0TPXeB1srg== X-Received: by 2002:a17:907:7409:b0:a9a:80bd:2920 with SMTP id a640c23a62f3a-a9a80bd2eaamr637181266b.53.1729515759121; Mon, 21 Oct 2024 06:02:39 -0700 (PDT) Received: from neptune.lan ([188.27.132.100]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a91370e33sm202310366b.120.2024.10.21.06.02.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 06:02:38 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: jic23@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, michael.hennerich@analog.com, gstols@baylibre.com, dlechner@baylibre.com, Alexandru Ardelean Subject: [PATCH 2/6] iio: adc: ad7606: fix issue/quirk with find_closest() for oversampling Date: Mon, 21 Oct 2024 16:02:17 +0300 Message-ID: <20241021130221.1469099-3-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241021130221.1469099-1-aardelean@baylibre.com> References: <20241021130221.1469099-1-aardelean@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There's a small issue with setting oversampling-ratio that seems to have been there since the driver was in staging. Trying to set an oversampling value of '2' will set an oversampling value of '1'. This is because find_closest() does an average + rounding of 1 + 2, and we get '1'. This is the only issue with find_closest(), at least in this setup. The other values (above 2) work reasonably well. Setting 3, rounds to 2, so a quick fix is to round 'val' to 3 (if userspace provides 2). Fixes 41f71e5e7daf: ("staging: iio: adc: ad7606: Use find_closest() macro") Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7606.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index ae49f4ba50d9..d0fe9fd65f3f 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -748,6 +748,9 @@ static int ad7606_write_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_OVERSAMPLING_RATIO: if (val2) return -EINVAL; + /* Minor trick, so that OS of 2, doesn't get rounded to 1 */ + if (val =3D=3D 2) + val++; i =3D find_closest(val, st->oversampling_avail, st->num_os_ratios); ret =3D st->write_os(indio_dev, i); --=20 2.46.1 From nobody Tue Nov 26 04:43:33 2024 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.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 B79771F706A for ; Mon, 21 Oct 2024 13:02:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729515766; cv=none; b=E0Ipe9CQ3aOK2uMsgGgVRIHbFr8vuaZleudlfl3r9apkEa+hV6gaxtzO6TDO9a69q4t0j6XfN4aa+SPMWfH5RXkIN225tI7I9gHPoFzmobf4lUduJti0toesu4bYgep2jQ49lg7i3I9MZ2LFRjb0byfJcTC8eki6xgKF0+BgOHs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729515766; c=relaxed/simple; bh=WKgeKu9BKiyFb382szdmwaGYbhsRt+mpw7oK76e+Juw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R2LnTbmbbfAUgixOAHioFBfu048u77bRY9FTCpzZ7x3PLnezangFpfCVHJclzutRmVuVdMVoqZse43TKebbZg6d2ZO9ZwDdyBlr8lwPksUwOLqW269vlgD2ruwRZfqakji4sKhFSt4zeteS1p2zYQem/nlS2X96iHDanmsgbOJQ= 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=kIccRN1d; arc=none smtp.client-ip=209.85.218.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="kIccRN1d" Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a9a3dc089d8so616860866b.3 for ; Mon, 21 Oct 2024 06:02:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729515762; x=1730120562; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=exnou0jkm74QB50DFbZVtG627VNG9ugvQrtDOKEght8=; b=kIccRN1dXFGNOrUonzPxNsWrlUQsxVZXbDOPOQzCjVWZqzqU5oZg8TCNAH/ojV8aKr +8LlP5h7K8G6Ycjj6bTTiCD3P2agVnZHAWCzFpFGJNCB80E7irBACDLobRfBIxjVQtPD sQNzoDTzXjmWtNUm2X/QMPiTxo85hdCdUfnXg2ffta6yc3g3FCMjT3cNCta9CKALXi93 4gfvS8JwZbl8eKVa6FWVZZolB2LEHW8ZrssylPxnsOXS/xw41EP6+/bCbpcpPtzRUQCm P8XjHBNF1WMlZG0t/qzCbbG62ivxWqEJPXajoN0YH+uaI4avWqqY3d8C/nl+eeEyyVbl d6og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729515762; x=1730120562; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=exnou0jkm74QB50DFbZVtG627VNG9ugvQrtDOKEght8=; b=Gro9feAhpbkOQEoRbw1TBFGQtPkFsjkn8Kwx4F83wlnWusDz79Prxmt7GRBPmpA4e8 +z5TGE37rWxJRydsffW8w6HfpGONZNMKHYPby68cgpQzOZNToZHWTZbWzJKwruXmotuK FsPuRHbvl2TCofztNV1PmHCY72yRcBgkcLQLj0IENvXR32WkOMAdGB6qtjVE4SOvXZNg G4lvA6TSfT/c4GgxRot/cgeB9jH35aX+ummzigLgTxFudlR2mQ6HbXUWDUMubrfNkdA4 059C84v1Bh61uIZbSqXr9n91H79AxmG6I4HO1fbnO5nTGrO4H9OTeeVayG12MKaAazlu +5Dg== X-Forwarded-Encrypted: i=1; AJvYcCWOnbNVpkDfa5sNckr/0wueYow4jBzDvyca9L8fS7RYNIkRjrOlrCZ/EP6KpcCtmJYqe3UcJlsui1HbhMk=@vger.kernel.org X-Gm-Message-State: AOJu0YwUKCczZyC13K185EPCjm3Xc6d6Tr415cu9wRzcyYK9Hn4PkwM4 p4LNIctRuyXNd9JS2NghHQBYUjaOcVBQRra3VMIC1STU0iKzJbhOYnam/nSeYmg= X-Google-Smtp-Source: AGHT+IHpgT9Fnvdd8Os6CvbTIWJb/pht/ROcNHvodcKIAP9VYk00V2IhRdT7gRJOIpwjFKL4MBk0Hg== X-Received: by 2002:a17:907:6e89:b0:a7a:9144:e23a with SMTP id a640c23a62f3a-a9a69c687d8mr1274360966b.43.1729515761922; Mon, 21 Oct 2024 06:02:41 -0700 (PDT) Received: from neptune.lan ([188.27.132.100]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a91370e33sm202310366b.120.2024.10.21.06.02.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 06:02:41 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: jic23@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, michael.hennerich@analog.com, gstols@baylibre.com, dlechner@baylibre.com, Alexandru Ardelean Subject: [PATCH 3/6] iio: adc: ad7606: use realbits for sign-extending in scan_direct Date: Mon, 21 Oct 2024 16:02:18 +0300 Message-ID: <20241021130221.1469099-4-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241021130221.1469099-1-aardelean@baylibre.com> References: <20241021130221.1469099-1-aardelean@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently the 'ad7606' driver supports parts with 18 and 16 bits resolutions. But when adding support for AD7607 (which has a 14-bit resolution) we should check for the 'realbits' field, to be able to sign-extend correctly. Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7606.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index d0fe9fd65f3f..a1f0c2feb04a 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -568,7 +568,7 @@ static int ad7606_scan_direct(struct iio_dev *indio_dev= , unsigned int ch, int *val) { struct ad7606_state *st =3D iio_priv(indio_dev); - unsigned int storagebits =3D st->chip_info->channels[1].scan_type.storage= bits; + unsigned int realbits =3D st->chip_info->channels[1].scan_type.realbits; const struct iio_chan_spec *chan; int ret; =20 @@ -603,15 +603,29 @@ static int ad7606_scan_direct(struct iio_dev *indio_d= ev, unsigned int ch, =20 chan =3D &indio_dev->channels[ch + 1]; if (chan->scan_type.sign =3D=3D 'u') { - if (storagebits > 16) + switch (realbits) { + case 18: *val =3D st->data.buf32[ch]; - else + break; + case 16: *val =3D st->data.buf16[ch]; + break; + default: + ret =3D -EINVAL; + break; + } } else { - if (storagebits > 16) + switch (realbits) { + case 18: *val =3D sign_extend32(st->data.buf32[ch], 17); - else + break; + case 16: *val =3D sign_extend32(st->data.buf16[ch], 15); + break; + default: + ret =3D -EINVAL; + break; + } } =20 error_ret: --=20 2.46.1 From nobody Tue Nov 26 04:43:33 2024 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.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 54EA01F9A9C for ; Mon, 21 Oct 2024 13:02:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729515770; cv=none; b=d2GQ+Lb7+Rv6ctyWrt62757pkveqAzRYERLnArQIPpZPR0bRHiQ/ijiFTuVopqikBXuMWBLtAWRb5rHKfOt77+DBPQjoAXqVam/hIyy1nv2JCYwEhFCFxF9nRnWTLqf7FDqfZUDwcBpiAmxSctaOR6SDyJ5lvWeuTbNM/AdS24Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729515770; c=relaxed/simple; bh=oGAAGK33rN6lVMDA+tGG6MD/gh3DQW+kiA2XkZMVS0A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TUXyvGq+LbX9R00u9AzYpWP7+oeKjEtar7LMaaEFqJ9vhfHyTuDglTFuzYcbOB47QWVJExc2np7WjM1p6P/z1upJ3Ohgq0+2TQVdEBa4b6Evrud5M4vVE7ELRQn0QTjufpjeB2aFSmoMz8MdC+jbN/7pYvfLSAuXpmT4snSWy0g= 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=B6Jhw/P7; arc=none smtp.client-ip=209.85.218.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="B6Jhw/P7" Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a9a0cee600aso561170866b.1 for ; Mon, 21 Oct 2024 06:02:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729515765; x=1730120565; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FRkM0XwtKZDbCSKn99mRdzWAKJPxnYQCvEvKP5OzOgU=; b=B6Jhw/P77M7h8JY19BYu69NMpjC4Vr3JYCk2WPBA6j9XksQJTWNwMniyc4TkGxkYu3 IwNhDrkuAoRMd0LCvpkuMV9Ldmuo5PnpQohpt9LZYOBpBgcjMw+KGwIOiKn5tDEOpSrB LmkPs5KmxesCoy57256SARssbz1fJtA63rmG1ELS3V24XHfr58ZC7mYn8NCufTR8TqBX CxWqsUzTAv3ezW43oEYq7HkWkcpAd0EU2dVQzoLgPkLSSAG9pe6PxXkcedWvHo3mnCdI rA1t64VTJI1qOSKA1SHB4BBaHzch/k0WpkSK77YElXJR3NsH5rnaCdt2BJmd5V4AlFf4 60HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729515765; x=1730120565; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FRkM0XwtKZDbCSKn99mRdzWAKJPxnYQCvEvKP5OzOgU=; b=M5NYf9qYcaM1BpVSL6B+SHjyT2sXZX7ReCgZ7Hwflw+sS0QqtKRGteAo60ldAUm6Zv XVWRGyOu7UoJVJaNYwyM5mcgbpS+kVhZrHxP8+9VBcwwkZZMxSr1KZhtth/mOULV/93K iWibMM4H/dfeKOGiFCIwPsKOfpWOVMFofoZj1gQ+XJ74cj5qAjsVi9jfLGS6B7ltMcmU 3Si3LwVTV1oqhx5KYb6n13/2s8nzKI/icmcUl4zIKnkgp9DMzWXHLsugIeyXzHB4Sd0S mjoSxwmDjGc+zw2D0YuaA9uZskfzStFWAdG+aZwRCfiCJ+7DFjG/iBHWIitcoZ/zQuX5 nRYw== X-Forwarded-Encrypted: i=1; AJvYcCXGOcI0Pu+Ce5ANMJ+Tzd4+Fg87Ba/y8oGKT1G2tkbG8HNhsFnJDq4fodB8Ry8deZasIrbHlEgoe11rKqI=@vger.kernel.org X-Gm-Message-State: AOJu0YzGcHVd5kLqfonZPPs2oUhZmF4SKM7xTe2P/0PdmOvlVMyaSq30 2pJW14DNITwfAZIhd4pFyjE7AmU9rFgM1j/CU4ojjIHEKvKvOv3AxLJXzatTLTFviLbOylnts37 eJoU= X-Google-Smtp-Source: AGHT+IFCFTYPvRkNohH2NScP5QOQ8P4j7zJ8kE0hLDY5hhwiho26NPw9+Y6IaAkMsV1wcnV8+sabuQ== X-Received: by 2002:a17:907:1b98:b0:a9a:7f34:351b with SMTP id a640c23a62f3a-a9a7f343622mr500996166b.3.1729515765413; Mon, 21 Oct 2024 06:02:45 -0700 (PDT) Received: from neptune.lan ([188.27.132.100]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a91370e33sm202310366b.120.2024.10.21.06.02.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 06:02:45 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: jic23@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, michael.hennerich@analog.com, gstols@baylibre.com, dlechner@baylibre.com, Alexandru Ardelean Subject: [PATCH 4/6] iio: adc: ad7606: rework scale-available to be static Date: Mon, 21 Oct 2024 16:02:19 +0300 Message-ID: <20241021130221.1469099-5-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241021130221.1469099-1-aardelean@baylibre.com> References: <20241021130221.1469099-1-aardelean@baylibre.com> 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 The main driver for this change is the AD7607 part, which has a scale of "1.220703" for the =C2=B110V range. The AD7607 has a resolution of 14-bits. So, just adding the scale-available list for that part would require some quirks to handle just that scale value. But to do it more neatly, the best approach is to rework the scale available lists to have the same format as it is returned to userspace. That way, we can also get rid of the allocation for the 'scale_avail_show' array. Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7606.c | 106 ++++++++++++++++++--------------------- drivers/iio/adc/ad7606.h | 6 +-- 2 files changed, 50 insertions(+), 62 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index a1f0c2feb04a..115c27ae02f3 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -33,42 +33,44 @@ =20 /* * Scales are computed as 5000/32768 and 10000/32768 respectively, - * so that when applied to the raw values they provide mV values + * so that when applied to the raw values they provide mV values. + * The scale arrays are kept as IIO_VAL_INT_PLUS_MICRO, so index + * X is the integer part and X + 1 is the fractional part. */ -static const unsigned int ad7606_16bit_hw_scale_avail[2] =3D { - 152588, 305176 +static const unsigned int ad7606_16bit_hw_scale_avail[2][2] =3D { + { 0, 152588 }, { 0, 305176 } }; =20 -static const unsigned int ad7606_18bit_hw_scale_avail[2] =3D { - 38147, 76294 +static const unsigned int ad7606_18bit_hw_scale_avail[2][2] =3D { + { 0, 38147 }, { 0, 76294 } }; =20 -static const unsigned int ad7606c_16bit_single_ended_unipolar_scale_avail[= 3] =3D { - 76294, 152588, 190735, +static const unsigned int ad7606c_16bit_single_ended_unipolar_scale_avail[= 3][2] =3D { + { 0, 76294 }, { 0, 152588 }, { 0, 190735 } }; =20 -static const unsigned int ad7606c_16bit_single_ended_bipolar_scale_avail[5= ] =3D { - 76294, 152588, 190735, 305176, 381470 +static const unsigned int ad7606c_16bit_single_ended_bipolar_scale_avail[5= ][2] =3D { + { 0, 76294 }, { 0, 152588 }, { 0, 190735 }, { 0, 305176 }, { 0, 381470 } }; =20 -static const unsigned int ad7606c_16bit_differential_bipolar_scale_avail[4= ] =3D { - 152588, 305176, 381470, 610352 +static const unsigned int ad7606c_16bit_differential_bipolar_scale_avail[4= ][2] =3D { + { 0, 152588 }, { 0, 305176 }, { 0, 381470 }, { 0, 610352 } }; =20 -static const unsigned int ad7606c_18bit_single_ended_unipolar_scale_avail[= 3] =3D { - 19073, 38147, 47684 +static const unsigned int ad7606c_18bit_single_ended_unipolar_scale_avail[= 3][2] =3D { + { 0, 19073 }, { 0, 38147 }, { 0, 47684 } }; =20 -static const unsigned int ad7606c_18bit_single_ended_bipolar_scale_avail[5= ] =3D { - 19073, 38147, 47684, 76294, 95367 +static const unsigned int ad7606c_18bit_single_ended_bipolar_scale_avail[5= ][2] =3D { + { 0, 19073 }, { 0, 38147 }, { 0, 47684 }, { 0, 76294 }, { 0, 95367 } }; =20 -static const unsigned int ad7606c_18bit_differential_bipolar_scale_avail[4= ] =3D { - 38147, 76294, 95367, 152588 +static const unsigned int ad7606c_18bit_differential_bipolar_scale_avail[4= ][2] =3D { + { 0, 38147 }, { 0, 76294 }, { 0, 95367 }, { 0, 152588 } }; =20 -static const unsigned int ad7606_16bit_sw_scale_avail[3] =3D { - 76293, 152588, 305176 +static const unsigned int ad7606_16bit_sw_scale_avail[3][2] =3D { + { 0, 76293 }, { 0, 152588 }, { 0, 305176 } }; =20 static const unsigned int ad7606_oversampling_avail[7] =3D { @@ -663,8 +665,8 @@ static int ad7606_read_raw(struct iio_dev *indio_dev, if (st->sw_mode_en) ch =3D chan->address; cs =3D &st->chan_scales[ch]; - *val =3D 0; - *val2 =3D cs->scale_avail[cs->range]; + *val =3D cs->scale_avail[cs->range][0]; + *val2 =3D cs->scale_avail[cs->range][1]; return IIO_VAL_INT_PLUS_MICRO; case IIO_CHAN_INFO_OVERSAMPLING_RATIO: *val =3D st->oversampling; @@ -681,21 +683,6 @@ static int ad7606_read_raw(struct iio_dev *indio_dev, return -EINVAL; } =20 -static ssize_t ad7606_show_avail(char *buf, const unsigned int *vals, - unsigned int n, bool micros) -{ - size_t len =3D 0; - int i; - - for (i =3D 0; i < n; i++) { - len +=3D scnprintf(buf + len, PAGE_SIZE - len, - micros ? "0.%06u " : "%u ", vals[i]); - } - buf[len - 1] =3D '\n'; - - return len; -} - static ssize_t in_voltage_scale_available_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -703,8 +690,16 @@ static ssize_t in_voltage_scale_available_show(struct = device *dev, struct iio_dev *indio_dev =3D dev_to_iio_dev(dev); struct ad7606_state *st =3D iio_priv(indio_dev); struct ad7606_chan_scale *cs =3D &st->chan_scales[0]; + const unsigned int (*vals)[2] =3D cs->scale_avail; + unsigned int i; + size_t len =3D 0; =20 - return ad7606_show_avail(buf, cs->scale_avail, cs->num_scales, true); + for (i =3D 0; i < cs->num_scales; i++) + len +=3D scnprintf(buf + len, PAGE_SIZE - len, "%u.%06u ", + vals[i][0], vals[i][1]); + buf[len - 1] =3D '\n'; + + return len; } =20 static IIO_DEVICE_ATTR_RO(in_voltage_scale_available, 0); @@ -742,6 +737,7 @@ static int ad7606_write_raw(struct iio_dev *indio_dev, long mask) { struct ad7606_state *st =3D iio_priv(indio_dev); + unsigned int scale_avail[AD760X_MAX_SCALES]; struct ad7606_chan_scale *cs; int i, ret, ch =3D 0; =20 @@ -752,7 +748,12 @@ static int ad7606_write_raw(struct iio_dev *indio_dev, if (st->sw_mode_en) ch =3D chan->address; cs =3D &st->chan_scales[ch]; - i =3D find_closest(val2, cs->scale_avail, cs->num_scales); + for (i =3D 0; i < cs->num_scales; i++) { + scale_avail[i] =3D cs->scale_avail[i][0] * 1000000 + + cs->scale_avail[i][1]; + } + val =3D val * 1000000 + val2; + i =3D find_closest(val, scale_avail, cs->num_scales); ret =3D st->write_scale(indio_dev, ch, i + cs->reg_offset); if (ret < 0) return ret; @@ -788,9 +789,15 @@ static ssize_t ad7606_oversampling_ratio_avail(struct = device *dev, { struct iio_dev *indio_dev =3D dev_to_iio_dev(dev); struct ad7606_state *st =3D iio_priv(indio_dev); + const unsigned int *vals =3D st->oversampling_avail; + unsigned int i; + size_t len =3D 0; =20 - return ad7606_show_avail(buf, st->oversampling_avail, - st->num_os_ratios, false); + for (i =3D 0; i < st->num_os_ratios; i++) + len +=3D scnprintf(buf + len, PAGE_SIZE - len, "%u ", vals[i]); + buf[len - 1] =3D '\n'; + + return len; } =20 static IIO_DEVICE_ATTR(oversampling_ratio_available, 0444, @@ -944,8 +951,8 @@ static int ad7606_read_avail(struct iio_dev *indio_dev, ch =3D chan->address; =20 cs =3D &st->chan_scales[ch]; - *vals =3D cs->scale_avail_show; - *length =3D cs->num_scales * 2; + *vals =3D (int *)cs->scale_avail; + *length =3D cs->num_scales; *type =3D IIO_VAL_INT_PLUS_MICRO; =20 return IIO_AVAIL_LIST; @@ -1068,24 +1075,9 @@ static int ad7606_chan_scales_setup(struct iio_dev *= indio_dev) indio_dev->channels =3D chans; =20 for (ch =3D 0; ch < num_channels; ch++) { - struct ad7606_chan_scale *cs; - int i; - ret =3D st->chip_info->scale_setup_cb(st, &chans[ch + 1], ch); if (ret) return ret; - - cs =3D &st->chan_scales[ch]; - - if (cs->num_scales * 2 > AD760X_MAX_SCALE_SHOW) - return dev_err_probe(st->dev, -ERANGE, - "Driver error: scale range too big"); - - /* Generate a scale_avail list for showing to userspace */ - for (i =3D 0; i < cs->num_scales; i++) { - cs->scale_avail_show[i * 2] =3D 0; - cs->scale_avail_show[i * 2 + 1] =3D cs->scale_avail[i]; - } } =20 return 0; diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index 2c629a15cc33..32c6f776c5df 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -103,8 +103,6 @@ struct ad7606_chip_info { /** * struct ad7606_chan_scale - channel scale configuration * @scale_avail pointer to the array which stores the available scales - * @scale_avail_show a duplicate of 'scale_avail' which is readily formatt= ed - * such that it can be read via the 'read_avail' hook * @num_scales number of elements stored in the scale_avail array * @range voltage range selection, selects which scale to apply * @reg_offset offset for the register value, to be applied when @@ -112,9 +110,7 @@ struct ad7606_chip_info { */ struct ad7606_chan_scale { #define AD760X_MAX_SCALES 16 -#define AD760X_MAX_SCALE_SHOW (AD760X_MAX_SCALES * 2) - const unsigned int *scale_avail; - int scale_avail_show[AD760X_MAX_SCALE_SHOW]; + const unsigned int (*scale_avail)[2]; unsigned int num_scales; unsigned int range; unsigned int reg_offset; --=20 2.46.1 From nobody Tue Nov 26 04:43:33 2024 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.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 226971FA252 for ; Mon, 21 Oct 2024 13:02:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729515773; cv=none; b=ay+xF9rd6QlLof+sa02eVxKqE2AoX2c2XklB6K2/SNN7CRxMspXuXbdg34orPB2UTkmWmz+RztshY5l4Bqdgkspkw34SNPNTx5KkeqxorF/VvjOgPckxtZBWdYm8q4OL31+2S3FCtXUBPmOkGLr+1AQbCzUYv798AlqIkJtO7/U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729515773; c=relaxed/simple; bh=UPblkw53lzncb25Tu6KKdBbVcH1Rxwx9uYPtlL0G030=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rErUfzgqEsKIyQzQjdW7CYv020Tjr+Kc6TpmRuW/mnLuBARpWojQCxbcK/fa64AAvCmLJv9RXd+CCmFrRIm5Pj3b44eX/Lmg8yR0bnjacGFr8uj1K+NhO8Wln+l2ojx+bc7a3/i7re9//j0pYIJWT97iqt4K9LnjFVbuBLOzpv8= 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=Ib65VqwW; arc=none smtp.client-ip=209.85.218.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="Ib65VqwW" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a9a68480164so396444166b.3 for ; Mon, 21 Oct 2024 06:02:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729515768; x=1730120568; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JlAIxOTbWyu2Rw7zFdBhuqCcECL8XcGJhiWh79pHgY4=; b=Ib65VqwWhCfahPoeuUMnvJBEgUrCcRGpsda7aK5Wip9HTfJnI8UFYiW5XM2Y3zK5Th TxolhR4DZHWBQsGEsrJI+ARTDPStn7zcIDacA76by+PJnJit8FjCbMW5ioTXXeA7SrWm A3Uwu/UytPH21G5W65LzOu+o9sF2qsVbjVpiuWWV5aigozGVO6W4cEiyp9obIsRuTIjD xOUcrr/svk0tbdmlkI193awt1qi1YuzsXhCMVim7aw4Esfru83IT+ykXpgirD9js08Ex WlDq0ssjQVU/ARwLMvwM6w/o7wj1p+2QsGRPDFkv703HVEjoJoyu4GC/qvPTgFFYLeTA TDkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729515768; x=1730120568; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JlAIxOTbWyu2Rw7zFdBhuqCcECL8XcGJhiWh79pHgY4=; b=e7sJaUSmYV70RgvRZHkX6IL9xyIFuBhNK+e5H51uH7oZeJWpnHrpUSKp/sBEtI8jCM e13bp4cAqhE12bLPwroqOhRuEcXjFplxUbrVkDsnQpNn9oE2GaQuP47VNPz+IlvdNugC oqSKqPBJ+acfKZ02uIoeDaS8hISUvoKFKEnSV8X+mm6yZeELmoiwgFLMRHhKkyxdl+IZ le9WPuzQYa6NUAxIaCkSTBkaGVGnBu7MSvx1vN6fSx99014tIGbbEkncNC+C0NqDMUa2 N4Ad/runMP0/v2Ake9s/651s8+HtZT6Wpbe40BwE8N1iSFCTkdyKEzEuxb6vQB4BvkRH FqDQ== X-Forwarded-Encrypted: i=1; AJvYcCWhKiSJz/KFLNJIoCEUOGQIH8ysEcBZfPAuaFH+JV2+Jxp3De3avv/jB4vOHY7DSBwXE31KxYKstoFFtJA=@vger.kernel.org X-Gm-Message-State: AOJu0YxUImnS0x+4847ZC+x+v6snY4p0eXkqVxgbZnTJfu8mtQTf3xC7 WIr3sXUmN6Kiox5Nf7DWBSVsf0YYMxyHDxO0tcRG9U0Xkqp9NtohCSDWrbEVv3M= X-Google-Smtp-Source: AGHT+IGTninUCYxKIMVO802oyPqqPEoBY089f3BVRWcxEG3HcKrxFvhS9FtKlcj/b3xJ0iBTgZY86A== X-Received: by 2002:a17:907:6e90:b0:a99:f1aa:a71f with SMTP id a640c23a62f3a-a9a69a671a8mr1157254966b.11.1729515768318; Mon, 21 Oct 2024 06:02:48 -0700 (PDT) Received: from neptune.lan ([188.27.132.100]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a91370e33sm202310366b.120.2024.10.21.06.02.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 06:02:47 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: jic23@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, michael.hennerich@analog.com, gstols@baylibre.com, dlechner@baylibre.com, Alexandru Ardelean Subject: [PATCH 5/6] dt-bindings: iio: adc: adi,ad7606: document AD760{7,8,9} parts Date: Mon, 21 Oct 2024 16:02:20 +0300 Message-ID: <20241021130221.1469099-6-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241021130221.1469099-1-aardelean@baylibre.com> References: <20241021130221.1469099-1-aardelean@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This change adds the AD7607, AD7608 & AD7609 parts to the binding doc of the ad7606 driver. Signed-off-by: Alexandru Ardelean Acked-by: Conor Dooley --- .../devicetree/bindings/iio/adc/adi,ad7606.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml b/Do= cumentation/devicetree/bindings/iio/adc/adi,ad7606.yaml index 0a612844029a..ab5881d0d017 100644 --- a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml @@ -16,6 +16,9 @@ description: | https://www.analog.com/media/en/technical-documentation/data-sheets/AD76= 06B.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/ad76= 06c-16.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/ad76= 06c-18.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/ad76= 07.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/ad76= 08.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/ad76= 09.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/AD76= 16.pdf =20 properties: @@ -28,6 +31,9 @@ properties: - adi,ad7606b - adi,ad7606c-16 - adi,ad7606c-18 + - adi,ad7607 + - adi,ad7608 + - adi,ad7609 - adi,ad7616 =20 reg: @@ -250,6 +256,9 @@ allOf: - adi,ad7606-4 - adi,ad7606-6 - adi,ad7606-8 + - adi,ad7607 + - adi,ad7608 + - adi,ad7609 then: properties: adi,sw-mode: false --=20 2.46.1 From nobody Tue Nov 26 04:43:33 2024 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (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 3620E1FAC35 for ; Mon, 21 Oct 2024 13:02:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729515776; cv=none; b=PPdjgreBn1YF4jPv9jlygcvB6vKbpWwLPlxFJsVL6aHs9MPZTlE72hwgREMMJzpZyRN+yIzyTjNpND0+pIFyMK+mDTQO5GX5Wtr7JQxVkETXgnGhGNrmVmGXTth3Qr+yts2IiDqjhNQ06KR3/pbPW6VK16m2gFpvwlnVCGRKCG0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729515776; c=relaxed/simple; bh=oXqTxF9VWK8spgNkRuVzdppEVicpI+c/R0Ca6Sd5358=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LR/zqyaa+HFk50oO5ixvdv61O7k41zeAzc93nD4PoPupBNlpWHwY7/JigsXTm3JrF/XrOpCDBzP1xU3KQLth4o7msyokM6wkfhLBt3u+gwkiWUOJecQ5LKzoFg7Rb3VrV4mxGOq+pE8UpFs1hlEqC7JApW/SI4AyuCZKFlBG3GU= 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=fpg6TLno; arc=none smtp.client-ip=209.85.218.46 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="fpg6TLno" Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a9a3dc089d8so616891066b.3 for ; Mon, 21 Oct 2024 06:02:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729515771; x=1730120571; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LJ2LCg07GYlBH6GupA4iFYXClhhNkNEGEenRcEJ0yFM=; b=fpg6TLnowc6uCs61eWJNO09Zb6dlc75ROxAoQTjZrNQ8Y1VjeJXQSvyUwviMF1e6Tr 9HqHBVDzpTXgN2QYdDJDP4BgMCzyAyVyNw+3lYLGT1BpATG+N0HyBGtfZwuDUq4vahBI CwsLXnxELhhwRSzlGlNtT5ofLabJdGBuviKV8UoGYmWEnZj8rTaRlPzGI2sj0vqGBb8/ g2l/Jfmra3avTDNapp1xh3xxVhnDsLb3RnHfPuRIF+Ns6je/36voW4cCTFpUVZd+dde6 j/EPSYv2JNNP6A/I0Wz1jy4GRVbxwF+m13Lu1d7jKgEMIXj72oInDxEDSEC8Xt2yRJZS 7tEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729515771; x=1730120571; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LJ2LCg07GYlBH6GupA4iFYXClhhNkNEGEenRcEJ0yFM=; b=gn9TcnEA/eCfqJSP2fNopcJazrWslg+uHN9C1yTtcsk3xBAAOC0r5pnW+vTsG3DJNl VboerUIBKYlaaSJ9ZS7DI77aW1lErfeITSCp8UCEXtOX2DT3ovDPSojQOfDcetcYYwcp mBb840CVdB0Xpu3xc4z1zKofBSCbWN09BKyY11zUFUcpz3CAKqMbReHi9R/Q0K3RtFSj /JUJM04U6xUoE4tzZFXFogzbYs3PaYB2+nMAoM5eHe56mVkgya7QRDWKH1a4P+mVxyjm anN7OzTUygiyBZm8tiHxXl6gZ8lwn3uGRvFo5/CJoPKLAmYRgBcHeJ8iiitI4E8Z5Sar K11A== X-Forwarded-Encrypted: i=1; AJvYcCU+7/zpoBeG3NXGFDy03hwXqwVhshCYJjyEVZJi3xOJW6KxQGwhJmgXVagk6nuLExOXoAMREwoK4DRPfxE=@vger.kernel.org X-Gm-Message-State: AOJu0YxJ58VuWQ/szvS7BZKwtRstXaULH8gjrJN75PEqWgIgAD8MmgJ3 va41a6GShVJ9on8EZ/PdKDnzPMNNlqgCts/NSyqvxvm/aKDLGpCpd0XEbIo17TMyuT5r81Rcz2z 7nhc= X-Google-Smtp-Source: AGHT+IFZ5uGNLM8bq4gI2PcPzrLtzeswE16SNAze5hedsX/YoKVGkdMHiiglNRj9LenMGSxHpmCx7w== X-Received: by 2002:a17:907:3d90:b0:a86:82e2:8c64 with SMTP id a640c23a62f3a-a9a69b75728mr1243432466b.35.1729515771365; Mon, 21 Oct 2024 06:02:51 -0700 (PDT) Received: from neptune.lan ([188.27.132.100]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a91370e33sm202310366b.120.2024.10.21.06.02.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 06:02:50 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: jic23@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, michael.hennerich@analog.com, gstols@baylibre.com, dlechner@baylibre.com, Alexandru Ardelean Subject: [PATCH 6/6] iio: adc: ad7606: add support for AD760{7,8,9} parts Date: Mon, 21 Oct 2024 16:02:21 +0300 Message-ID: <20241021130221.1469099-7-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241021130221.1469099-1-aardelean@baylibre.com> References: <20241021130221.1469099-1-aardelean@baylibre.com> 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 The AD7607, AD7608 and AD7609 are some older parts of the AD7606 family. They are hardware-only, meaning that they don't have any registers accessible via SPI or Parallel interface. They are more similar to the AD7605-4 part, which is supported by the 'ad7606' driver, and are configurable via GPIOs. Like the AD7605-4 part, all 3 parts have 2 CONVST (Conversion Start) pins (CONVST A and CONVST B). But in practice, these should be tied together to make reading of samples easier via a serial line. The AD7607 has an 14-bit resolution and AD7608 & AD7609 have an 18-bit resolution. The main difference between the AD7608 & AD7609 is that the AD7609 has a larger range (=C2=B110V & =C2=B120V) vs the =C2=B15V & =C2=B11= 0V ranges for AD7608. However, unlike AD7605-4 part, these 3 parts have oversampling which is configurable (like for the AD7606 in HW-mode) via GPIOs. Datasheet: https://www.analog.com/media/en/technical-documentation/data-she= ets/ad7607.pdf Datasheet: https://www.analog.com/media/en/technical-documentation/data-she= ets/ad7608.pdf Datasheet: https://www.analog.com/media/en/technical-documentation/data-she= ets/ad7609.pdf Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7606.c | 108 +++++++++++++++++++++++++++++++++++ drivers/iio/adc/ad7606.h | 3 + drivers/iio/adc/ad7606_par.c | 6 ++ drivers/iio/adc/ad7606_spi.c | 42 ++++++++++++++ 4 files changed, 159 insertions(+) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index 115c27ae02f3..4204b91da7db 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -73,6 +73,14 @@ static const unsigned int ad7606_16bit_sw_scale_avail[3]= [2] =3D { { 0, 76293 }, { 0, 152588 }, { 0, 305176 } }; =20 +static const unsigned int ad7607_hw_scale_avail[2][2] =3D { + { 0, 610352 }, { 1, 220703 } +}; + +static const unsigned int ad7609_hw_scale_avail[2][2] =3D { + { 0, 152588 }, { 0, 305176 } +}; + static const unsigned int ad7606_oversampling_avail[7] =3D { 1, 2, 4, 8, 16, 32, 64, }; @@ -113,6 +121,30 @@ static const struct iio_chan_spec ad7606_channels_18bi= t[] =3D { AD7606_CHANNEL(7, 18), }; =20 +static const struct iio_chan_spec ad7607_channels[] =3D { + IIO_CHAN_SOFT_TIMESTAMP(8), + AD7606_CHANNEL(0, 14), + AD7606_CHANNEL(1, 14), + AD7606_CHANNEL(2, 14), + AD7606_CHANNEL(3, 14), + AD7606_CHANNEL(4, 14), + AD7606_CHANNEL(5, 14), + AD7606_CHANNEL(6, 14), + AD7606_CHANNEL(7, 14), +}; + +static const struct iio_chan_spec ad7608_channels[] =3D { + IIO_CHAN_SOFT_TIMESTAMP(8), + AD7606_CHANNEL(0, 18), + AD7606_CHANNEL(1, 18), + AD7606_CHANNEL(2, 18), + AD7606_CHANNEL(3, 18), + AD7606_CHANNEL(4, 18), + AD7606_CHANNEL(5, 18), + AD7606_CHANNEL(6, 18), + AD7606_CHANNEL(7, 18), +}; + /* * The current assumption that this driver makes for AD7616, is that it's * working in Hardware Mode with Serial, Burst and Sequencer modes activat= ed. @@ -149,6 +181,12 @@ static int ad7606c_16bit_chan_scale_setup(struct ad760= 6_state *st, struct iio_chan_spec *chan, int ch); static int ad7606_16bit_chan_scale_setup(struct ad7606_state *st, struct iio_chan_spec *chan, int ch); +static int ad7607_chan_scale_setup(struct ad7606_state *st, + struct iio_chan_spec *chan, int ch); +static int ad7608_chan_scale_setup(struct ad7606_state *st, + struct iio_chan_spec *chan, int ch); +static int ad7609_chan_scale_setup(struct ad7606_state *st, + struct iio_chan_spec *chan, int ch); =20 const struct ad7606_chip_info ad7605_4_info =3D { .channels =3D ad7605_channels, @@ -215,6 +253,39 @@ const struct ad7606_chip_info ad7606c_16_info =3D { }; EXPORT_SYMBOL_NS_GPL(ad7606c_16_info, IIO_AD7606); =20 +const struct ad7606_chip_info ad7607_info =3D { + .channels =3D ad7607_channels, + .name =3D "ad7607", + .num_adc_channels =3D 8, + .num_channels =3D 9, + .oversampling_avail =3D ad7606_oversampling_avail, + .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), + .scale_setup_cb =3D ad7607_chan_scale_setup, +}; +EXPORT_SYMBOL_NS_GPL(ad7607_info, IIO_AD7606); + +const struct ad7606_chip_info ad7608_info =3D { + .channels =3D ad7608_channels, + .name =3D "ad7608", + .num_adc_channels =3D 8, + .num_channels =3D 9, + .oversampling_avail =3D ad7606_oversampling_avail, + .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), + .scale_setup_cb =3D ad7608_chan_scale_setup, +}; +EXPORT_SYMBOL_NS_GPL(ad7608_info, IIO_AD7606); + +const struct ad7606_chip_info ad7609_info =3D { + .channels =3D ad7608_channels, + .name =3D "ad7609", + .num_adc_channels =3D 8, + .num_channels =3D 9, + .oversampling_avail =3D ad7606_oversampling_avail, + .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), + .scale_setup_cb =3D ad7609_chan_scale_setup, +}; +EXPORT_SYMBOL_NS_GPL(ad7609_info, IIO_AD7606); + const struct ad7606_chip_info ad7606c_18_info =3D { .channels =3D ad7606_channels_18bit, .name =3D "ad7606c18", @@ -441,6 +512,39 @@ 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, + struct iio_chan_spec *chan, int ch) +{ + struct ad7606_chan_scale *cs =3D &st->chan_scales[ch]; + + cs->range =3D 0; + cs->scale_avail =3D ad7607_hw_scale_avail; + cs->num_scales =3D ARRAY_SIZE(ad7607_hw_scale_avail); + return 0; +} + +static int ad7608_chan_scale_setup(struct ad7606_state *st, + struct iio_chan_spec *chan, int ch) +{ + struct ad7606_chan_scale *cs =3D &st->chan_scales[ch]; + + cs->range =3D 0; + cs->scale_avail =3D ad7606_18bit_hw_scale_avail; + cs->num_scales =3D ARRAY_SIZE(ad7606_18bit_hw_scale_avail); + return 0; +} + +static int ad7609_chan_scale_setup(struct ad7606_state *st, + struct iio_chan_spec *chan, int ch) +{ + struct ad7606_chan_scale *cs =3D &st->chan_scales[ch]; + + cs->range =3D 0; + cs->scale_avail =3D ad7609_hw_scale_avail; + cs->num_scales =3D ARRAY_SIZE(ad7609_hw_scale_avail); + return 0; +} + static int ad7606_reg_access(struct iio_dev *indio_dev, unsigned int reg, unsigned int writeval, @@ -610,6 +714,7 @@ static int ad7606_scan_direct(struct iio_dev *indio_dev= , unsigned int ch, *val =3D st->data.buf32[ch]; break; case 16: + case 14: *val =3D st->data.buf16[ch]; break; default: @@ -624,6 +729,9 @@ static int ad7606_scan_direct(struct iio_dev *indio_dev= , unsigned int ch, case 16: *val =3D sign_extend32(st->data.buf16[ch], 15); break; + case 14: + *val =3D sign_extend32(st->data.buf16[ch], 13); + break; default: ret =3D -EINVAL; break; diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index 32c6f776c5df..998814a92b82 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -237,6 +237,9 @@ extern const struct ad7606_chip_info ad7606_4_info; extern const struct ad7606_chip_info ad7606b_info; extern const struct ad7606_chip_info ad7606c_16_info; extern const struct ad7606_chip_info ad7606c_18_info; +extern const struct ad7606_chip_info ad7607_info; +extern const struct ad7606_chip_info ad7608_info; +extern const struct ad7606_chip_info ad7609_info; extern const struct ad7606_chip_info ad7616_info; =20 #ifdef CONFIG_PM_SLEEP diff --git a/drivers/iio/adc/ad7606_par.c b/drivers/iio/adc/ad7606_par.c index 4e729777d373..a25182a3daa7 100644 --- a/drivers/iio/adc/ad7606_par.c +++ b/drivers/iio/adc/ad7606_par.c @@ -211,6 +211,9 @@ static const struct platform_device_id ad7606_driver_id= s[] =3D { { .name =3D "ad7606-6", .driver_data =3D (kernel_ulong_t)&ad7606_6_info, = }, { .name =3D "ad7606-8", .driver_data =3D (kernel_ulong_t)&ad7606_8_info, = }, { .name =3D "ad7606b", .driver_data =3D (kernel_ulong_t)&ad7606b_info, }, + { .name =3D "ad7607", .driver_data =3D (kernel_ulong_t)&ad7607_info, }, + { .name =3D "ad7608", .driver_data =3D (kernel_ulong_t)&ad7608_info, }, + { .name =3D "ad7609", .driver_data =3D (kernel_ulong_t)&ad7609_info, }, { } }; MODULE_DEVICE_TABLE(platform, ad7606_driver_ids); @@ -221,6 +224,9 @@ static const struct of_device_id ad7606_of_match[] =3D { { .compatible =3D "adi,ad7606-6", .data =3D &ad7606_6_info }, { .compatible =3D "adi,ad7606-8", .data =3D &ad7606_8_info }, { .compatible =3D "adi,ad7606b", .data =3D &ad7606b_info }, + { .compatible =3D "adi,ad7607", .data =3D &ad7607_info }, + { .compatible =3D "adi,ad7608", .data =3D &ad7608_info }, + { .compatible =3D "adi,ad7609", .data =3D &ad7609_info }, { } }; MODULE_DEVICE_TABLE(of, ad7606_of_match); diff --git a/drivers/iio/adc/ad7606_spi.c b/drivers/iio/adc/ad7606_spi.c index 44c6031e9e9a..0662300cde8d 100644 --- a/drivers/iio/adc/ad7606_spi.c +++ b/drivers/iio/adc/ad7606_spi.c @@ -132,6 +132,19 @@ static int ad7606_spi_read_block(struct device *dev, return 0; } =20 +static int ad7606_spi_read_block14to16(struct device *dev, + int count, void *buf) +{ + struct spi_device *spi =3D to_spi_device(dev); + struct spi_transfer xfer =3D { + .bits_per_word =3D 14, + .len =3D count * sizeof(u16), + .rx_buf =3D buf, + }; + + return spi_sync_transfer(spi, &xfer, 1); +} + static int ad7606_spi_read_block18to32(struct device *dev, int count, void *buf) { @@ -325,6 +338,14 @@ static const struct ad7606_bus_ops ad7606_spi_bops =3D= { .read_block =3D ad7606_spi_read_block, }; =20 +static const struct ad7606_bus_ops ad7607_spi_bops =3D { + .read_block =3D ad7606_spi_read_block14to16, +}; + +static const struct ad7606_bus_ops ad7608_spi_bops =3D { + .read_block =3D ad7606_spi_read_block18to32, +}; + static const struct ad7606_bus_ops ad7616_spi_bops =3D { .read_block =3D ad7606_spi_read_block, .reg_read =3D ad7606_spi_reg_read, @@ -387,6 +408,21 @@ static const struct ad7606_bus_info ad7606c_18_bus_inf= o =3D { .bops =3D &ad7606c_18_spi_bops, }; =20 +static const struct ad7606_bus_info ad7607_bus_info =3D { + .chip_info =3D &ad7607_info, + .bops =3D &ad7607_spi_bops, +}; + +static const struct ad7606_bus_info ad7608_bus_info =3D { + .chip_info =3D &ad7608_info, + .bops =3D &ad7608_spi_bops, +}; + +static const struct ad7606_bus_info ad7609_bus_info =3D { + .chip_info =3D &ad7609_info, + .bops =3D &ad7608_spi_bops, +}; + static const struct ad7606_bus_info ad7616_bus_info =3D { .chip_info =3D &ad7616_info, .bops =3D &ad7616_spi_bops, @@ -408,6 +444,9 @@ static const struct spi_device_id ad7606_id_table[] =3D= { { "ad7606b", (kernel_ulong_t)&ad7606b_bus_info }, { "ad7606c-16", (kernel_ulong_t)&ad7606c_16_bus_info }, { "ad7606c-18", (kernel_ulong_t)&ad7606c_18_bus_info }, + { "ad7607", (kernel_ulong_t)&ad7607_bus_info }, + { "ad7608", (kernel_ulong_t)&ad7608_bus_info }, + { "ad7609", (kernel_ulong_t)&ad7609_bus_info }, { "ad7616", (kernel_ulong_t)&ad7616_bus_info }, { } }; @@ -421,6 +460,9 @@ static const struct of_device_id ad7606_of_match[] =3D { { .compatible =3D "adi,ad7606b", .data =3D &ad7606b_bus_info }, { .compatible =3D "adi,ad7606c-16", .data =3D &ad7606c_16_bus_info }, { .compatible =3D "adi,ad7606c-18", .data =3D &ad7606c_18_bus_info }, + { .compatible =3D "adi,ad7607", .data =3D &ad7607_bus_info }, + { .compatible =3D "adi,ad7608", .data =3D &ad7608_bus_info }, + { .compatible =3D "adi,ad7609", .data =3D &ad7609_bus_info }, { .compatible =3D "adi,ad7616", .data =3D &ad7616_bus_info }, { } }; --=20 2.46.1