From patchwork Fri Oct 25 09:59:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 13850392 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (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 DB0F31D63EA for ; Fri, 25 Oct 2024 09:59:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729850394; cv=none; b=AvcbfItqpdrNBNNQa9YqSAcKe/nj26vO6tupw+ziQxyUs3etPPxtdykI0rSWszZ7b4aAUZFA0+98bWIs942gUndrwPBLipm50CsrLE2X0e6yOTk9rMO0eTaNPiA2Rt8rvHV70OwMbW57Prwgyb0Fw+1stS/xdXcSNs6fiWtwUcI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729850394; c=relaxed/simple; bh=rGc3MWfnfDGr6DVhiTPyA4ENZmPwmhTHYX0jVVNz4Pg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n/Xzhu/oU/tXL+wzueJjJBkq5pJxq3SgPAQsqaCucSoPFzThE7cFtUTptDJUNl+WFtURYMIham9lOCXf6Ts/UmaOkSat1MeQoIhFxQJgHiBWWA45qPmFa1cZR4UHQ73XxM+B2m7VzZgAt/JMU8ITWGhG6o2T+se9cNLEhH9yotY= 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=W+MefqaC; arc=none smtp.client-ip=209.85.208.51 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="W+MefqaC" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-5c948c41edeso2134192a12.1 for ; Fri, 25 Oct 2024 02:59:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729850390; x=1730455190; 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=W+MefqaCmXKrfcbB+KWDoEWvL5VQOL5ZIm+dpBDcnsc39HcYuFa+336drolcn4LRn5 45Cht9ul6SEngeKqkk6dHrqzZ+MXTqKXSGwiaibB5SDIuI3xGexBn7ZVeQ9QWXU5Y2Or eiMMIuVzm54PzqKVZ6GZk31yz+Dj0Jr60C9/Jckcm32HfA3JutzI21Qf0KOTQU/LNTUz UwyQnBrInWiJvFby1W0GezX9o8cV9EVEKwHqB1ei0ruScJiVyPbvAvu47fgAgyev2eF7 P8PDuyehqXL3/7l0U7S2zNQunqaba15hNbuOZKxrV9knpfzFSNdKzpl8KTvrYtosAZMO aNdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729850390; x=1730455190; 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=cGDm8Ot1JJNxZNrat4mmnpXo+cWAY/Lkldbu8vfK5KgcHY7KFzWNA3VpyBt7rNVnrD bFHRlfH8lDueLb2laNTdim4ppuSAxWbFgNUckWptX1dT7Se6e7d2wsoXbN12hpO3EHwI Mg7Y4N2MYC2fO8EyJ3SO3X/TOSoiaojSjkClXIyGK2kMgce09zm+ZtK3o8y1BsaF0U+L ZdrD0kloMQpIQ47dX3fzAUi0NIs9NRcvmahQbHzr5Ntmtfo29ILrXSpkzJQU2L/luift iBwU9Dte6UQBGce3uQRRgrRvM9dHjWqroAB5vmhJ9PSJcHx3+aV0LJJK6+d/zIK3soJA Y7Ug== X-Gm-Message-State: AOJu0YwrUhjLf1z0vMCxrUHzu8KZX1kodOOAilI8rXhCZpEMT9jZXpDs 2HQXdtaRYgVadpoPojeE1fL3msMIF8hkFbMikKaq1sXFOs+i8b+liEMdA/GU/Vyl4ggLbZsHYVU uT4Y= X-Google-Smtp-Source: AGHT+IFHx4c5CALGB7W5EOFi/W4CgKWigUrzNoYjfJYsnyAu+NVG1D+ZwiEpouJlqZdc8Zwp0c9FeA== X-Received: by 2002:a17:907:1c12:b0:a9a:4cf:5cea with SMTP id a640c23a62f3a-a9abf9a588amr851098666b.54.1729850389745; Fri, 25 Oct 2024 02:59:49 -0700 (PDT) Received: from localhost.localdomain ([188.27.128.50]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1f02951esm51737266b.71.2024.10.25.02.59.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2024 02:59:49 -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, conor.dooley@microchip.com, Alexandru Ardelean Subject: [PATCH v2 1/5] iio: adc: ad7606: fix/persist oversampling_ratio setting Date: Fri, 25 Oct 2024 12:59:35 +0300 Message-ID: <20241025095939.271811-2-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241025095939.271811-1-aardelean@baylibre.com> References: <20241025095939.271811-1-aardelean@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 = st->write_os(indio_dev, i); if (ret < 0) return ret; + st->oversampling = st->oversampling_avail[i]; return 0; case IIO_CHAN_INFO_SAMP_FREQ: From patchwork Fri Oct 25 09:59:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 13850393 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (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 CB0081D9A79 for ; Fri, 25 Oct 2024 09:59:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729850396; cv=none; b=XqQbU4f/t66V6A9AvpK5bAnJGQL/MfV8iryZwZOK0TITjcFcJxiVQvN130Er6Bad6lTsNSLaV++6hOSBLFsYQfaVmPE/b4iIuDSZVfW502ZgHjlkK1k3TFMV1BpkiCMS4CRrHnUXh/i0DsP+0R0QJJtM4KABCeqIYaYylrLgJMQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729850396; c=relaxed/simple; bh=thXhUwQLx0ic152I/8ZIoekXqTF65zPinRE8fIvjkp4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZNGaLv8/H4myoBhHTqjAQAJlACOMVgyOjD/hBptGBOIuCVvINfBIqcwHmO+vb3PCSuojfxHq/rCEmCCWAxy77LmyxxygFptZqxdZeiBbfBM7jU3adhauQdHB5+kApL1hwxvSDq/wZCm/He20psIFYsscZ+7sAL7vRgXFhblvSgA= 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=X0cpvvEK; arc=none smtp.client-ip=209.85.218.44 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="X0cpvvEK" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a9932aa108cso280578466b.2 for ; Fri, 25 Oct 2024 02:59:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729850392; x=1730455192; 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=7eIz+/d8S1VI98YfeSXtMvF+ChCheDsXPx+QBArarYM=; b=X0cpvvEK0/v13/DGizmwZtwZcicFOzD0rJHXHZHBWGZSyvXXCrvHsQGeaVNvCHrd81 k6XNZxFagWBk+yEvFrHPKdfkcIe/jLdkp29sXc3ixaZo8mF4FO/EyRRKROLbs+ALZtLO F8gzml1zdO8wjhCPFkXTF7mZSmEIrdTJCjpiAH32yCt1MUWuQVavTlEkeZDwrhOTo0Dm A0rUPePq4FjAUB3qWzjLU2wG4QKlG+vJx96Z68XyZ0dBWgp0IoQ/QhD6T+O6CJlws0Fj qhKa/D9QfXkMQ2Yw31SuxX58CyHTKkH5VoEgxJLp9BzR9q8HRaVu5blUTFOyjEX4zRWx YEZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729850392; x=1730455192; 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=7eIz+/d8S1VI98YfeSXtMvF+ChCheDsXPx+QBArarYM=; b=sPu5Wrf1xQMO5r6yEgrS3RykX1n1sF57CLs6MQQGfZ0kNCpkqMXhy6sNMhr5LsJM3E aFXIgxpHeALy15nfoP0qhfoSR/v0LbUneL1oPaPyVf27/kLjVcLAypgXekQMdEHDvkc5 wcWnvYH3CNyu7YCUH2XaquRyncUAFMIfvEy4+ugEesytnLMTbM5W/gK4iuhY31S0lxms b8KNLOj5yWnEAsUlTxNsLLmDEZT0yt9LHbgt+fy+JArwH4sLHA+Pf+uZLckec6H3xe0l njEjaePYsi/gnR3HLzX3JSGViq9yZhGgcZCcP/KoERM0+W9WXzE+6arg7yvgBFpszTNf tJcA== X-Gm-Message-State: AOJu0YwR9rXUuc9y3LZMyqC/YBKJZlatgVL+KyLVNi1QhH/8s37iTsn7 Z97+O39ScMq44du6Z+0szHatfFYfFg1NqwpSOHPRGnSWY2FeZFqoCvtMNZqsMImVZBveaqa44Tt ubbo= X-Google-Smtp-Source: AGHT+IF08eLYlnCW/ybZxW+hu8+oUE5zIA5uhxkWd2NWFN12lvQV4rLrwcF+j4/GG6fKFTUULtQzMA== X-Received: by 2002:a17:906:7309:b0:a99:dde6:9f42 with SMTP id a640c23a62f3a-a9abf96ce04mr899693866b.47.1729850391685; Fri, 25 Oct 2024 02:59:51 -0700 (PDT) Received: from localhost.localdomain ([188.27.128.50]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1f02951esm51737266b.71.2024.10.25.02.59.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2024 02:59:51 -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, conor.dooley@microchip.com, Alexandru Ardelean Subject: [PATCH v2 2/5] iio: adc: ad7606: use realbits for sign-extending in scan_direct Date: Fri, 25 Oct 2024 12:59:36 +0300 Message-ID: <20241025095939.271811-3-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241025095939.271811-1-aardelean@baylibre.com> References: <20241025095939.271811-1-aardelean@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index ae49f4ba50d9..effb98b4dc77 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 = iio_priv(indio_dev); - unsigned int storagebits = st->chip_info->channels[1].scan_type.storagebits; + unsigned int realbits = st->chip_info->channels[1].scan_type.realbits; const struct iio_chan_spec *chan; int ret; @@ -603,15 +603,15 @@ static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch, chan = &indio_dev->channels[ch + 1]; if (chan->scan_type.sign == 'u') { - if (storagebits > 16) + if (realbits > 16) *val = st->data.buf32[ch]; else *val = st->data.buf16[ch]; } else { - if (storagebits > 16) - *val = sign_extend32(st->data.buf32[ch], 17); + if (realbits > 16) + *val = sign_extend32(st->data.buf32[ch], realbits - 1); else - *val = sign_extend32(st->data.buf16[ch], 15); + *val = sign_extend32(st->data.buf16[ch], realbits - 1); } error_ret: From patchwork Fri Oct 25 09:59:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 13850394 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.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 F29311DE895 for ; Fri, 25 Oct 2024 09:59:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729850398; cv=none; b=P2YPUQLG7eQcZlH1zZnARkt+N2uJUiv0fuW21KkY25dMKsVZH7jv91s7Y5nYnll0ZVc4/Ftb3kXTrsE0x6rlPwRjhjlxmc4lPF3jdAD6PqD+3forkyYoZWnKFno7EXRSjWDZAEAm6B3lAsi7NQLVQWKY1dTiw03Pfb0i8pTEfWs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729850398; c=relaxed/simple; bh=bnh6k+2nsTlVPGOPQPnS6MUhhFKm2XQJVM/36CFpswI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TsWE07RfphWebPCxv2zU4GfWK3+TdmqQVjaCsreqbJk1rTDwN6QE7LLZgRIILY/HZL/h9SWyqWTumRn46Tf8O//rAfesiHInsqcWqjep8KGPrT1UtEDux9wQCo/wycpYV83LkMimwT9P3R5aDG9felDQBnwD5slHSV0ROglWgvU= 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=ZzTVltuU; arc=none smtp.client-ip=209.85.218.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="ZzTVltuU" Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a99f1fd20c4so257355766b.0 for ; Fri, 25 Oct 2024 02:59:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729850394; x=1730455194; 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=PGoGtNY9UtsrMSYGprOqDMvN9BiGWMz+YiNB4/Bovi0=; b=ZzTVltuU80JUGGq/SDxc/Y4FLEnkYnYQJSjWDIxE8A7To4N8pEAGePUFg7aQXOVTtY RQk6o7yt7LBiIrw5d5B81kK+e9/NT9Aidnm3fyrkLro67bPN4Gnn/ti02Os1tq4yjYdO 1dv+BPKEg+HJrKTyqnzHNoKemw/lPfDlM1CnQm6ldyHzf3+k6+RceDfGmNXFl8oqfZzw Rnbbwavfi9SGXRLnRA60sgpenT8ssy1WOQav6totKjkn6T3r2NnHyQGXNO2JUme9QIsJ MfGHEhHWCDdf1VSHNt+S1NDJL8/4kg6jtrWfYnDsaklupfBC5ERmQD0QfqVXAPQPjp2N jppw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729850394; x=1730455194; 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=PGoGtNY9UtsrMSYGprOqDMvN9BiGWMz+YiNB4/Bovi0=; b=wXwAYqs7gocS7r/fU0N7gx36XWJYEPXTU4/iu5J11df4S8qNFKzM5KOxutZcopvHS3 sO9kJvpBMCoH++UrWCjLTUdsojcUfINvMqat/kiNpMNTUYwYTJJ844SyxZTw9fauzcBq rYjhrunBvlRr4GcM6q5nZfy/WCzsbNwvWlh8YlScOMngVGEJ4V7ZZ0i6ha7QTJJypQ+7 //vMq4Mawqpq3XkzP8c1WhuUvODOnQhkt1hU06RGwIMo/ugwWkRUOeKqvBszLGirDs7O vaIIfua5BJ7O7GVV2NOCPefvcOnw91FJwJ0Ykep69AiV9Yd9TtWryBmDPqgNa2F+vuy6 YbUg== X-Gm-Message-State: AOJu0YyQP2bp+/PCHiwW4e+koGAy7OTvnQcd7UMw3uzSYKJH72ct7LFR LhyVz1JPRwHu0mDeslxzbkZOOEJEduNJNP8KhDLo0yyDAKErtrkxcVGrUlu77xcIWiBrnoIT8Ft enmc= X-Google-Smtp-Source: AGHT+IFMtmJpPN1a5j/r7T2Jvn7suJkfOXqhDLSHqOMT3yOEa2QZQmBW3GF5Q/ArO2jjFvM4A8g9kg== X-Received: by 2002:a17:907:31c5:b0:a9a:a5c:e23b with SMTP id a640c23a62f3a-a9abf96aa4cmr870774166b.58.1729850393935; Fri, 25 Oct 2024 02:59:53 -0700 (PDT) Received: from localhost.localdomain ([188.27.128.50]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1f02951esm51737266b.71.2024.10.25.02.59.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2024 02:59:53 -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, conor.dooley@microchip.com, Alexandru Ardelean Subject: [PATCH v2 3/5] iio: adc: ad7606: rework scale-available to be static Date: Fri, 25 Oct 2024 12:59:37 +0300 Message-ID: <20241025095939.271811-4-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241025095939.271811-1-aardelean@baylibre.com> References: <20241025095939.271811-1-aardelean@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The main driver for this change is the AD7607 part, which has a scale of "1.220703" for the ±10V 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 effb98b4dc77..94756bb87b95 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -33,42 +33,44 @@ /* * 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] = { - 152588, 305176 +static const unsigned int ad7606_16bit_hw_scale_avail[2][2] = { + { 0, 152588 }, { 0, 305176 } }; -static const unsigned int ad7606_18bit_hw_scale_avail[2] = { - 38147, 76294 +static const unsigned int ad7606_18bit_hw_scale_avail[2][2] = { + { 0, 38147 }, { 0, 76294 } }; -static const unsigned int ad7606c_16bit_single_ended_unipolar_scale_avail[3] = { - 76294, 152588, 190735, +static const unsigned int ad7606c_16bit_single_ended_unipolar_scale_avail[3][2] = { + { 0, 76294 }, { 0, 152588 }, { 0, 190735 } }; -static const unsigned int ad7606c_16bit_single_ended_bipolar_scale_avail[5] = { - 76294, 152588, 190735, 305176, 381470 +static const unsigned int ad7606c_16bit_single_ended_bipolar_scale_avail[5][2] = { + { 0, 76294 }, { 0, 152588 }, { 0, 190735 }, { 0, 305176 }, { 0, 381470 } }; -static const unsigned int ad7606c_16bit_differential_bipolar_scale_avail[4] = { - 152588, 305176, 381470, 610352 +static const unsigned int ad7606c_16bit_differential_bipolar_scale_avail[4][2] = { + { 0, 152588 }, { 0, 305176 }, { 0, 381470 }, { 0, 610352 } }; -static const unsigned int ad7606c_18bit_single_ended_unipolar_scale_avail[3] = { - 19073, 38147, 47684 +static const unsigned int ad7606c_18bit_single_ended_unipolar_scale_avail[3][2] = { + { 0, 19073 }, { 0, 38147 }, { 0, 47684 } }; -static const unsigned int ad7606c_18bit_single_ended_bipolar_scale_avail[5] = { - 19073, 38147, 47684, 76294, 95367 +static const unsigned int ad7606c_18bit_single_ended_bipolar_scale_avail[5][2] = { + { 0, 19073 }, { 0, 38147 }, { 0, 47684 }, { 0, 76294 }, { 0, 95367 } }; -static const unsigned int ad7606c_18bit_differential_bipolar_scale_avail[4] = { - 38147, 76294, 95367, 152588 +static const unsigned int ad7606c_18bit_differential_bipolar_scale_avail[4][2] = { + { 0, 38147 }, { 0, 76294 }, { 0, 95367 }, { 0, 152588 } }; -static const unsigned int ad7606_16bit_sw_scale_avail[3] = { - 76293, 152588, 305176 +static const unsigned int ad7606_16bit_sw_scale_avail[3][2] = { + { 0, 76293 }, { 0, 152588 }, { 0, 305176 } }; static const unsigned int ad7606_oversampling_avail[7] = { @@ -649,8 +651,8 @@ static int ad7606_read_raw(struct iio_dev *indio_dev, if (st->sw_mode_en) ch = chan->address; cs = &st->chan_scales[ch]; - *val = 0; - *val2 = cs->scale_avail[cs->range]; + *val = cs->scale_avail[cs->range][0]; + *val2 = cs->scale_avail[cs->range][1]; return IIO_VAL_INT_PLUS_MICRO; case IIO_CHAN_INFO_OVERSAMPLING_RATIO: *val = st->oversampling; @@ -667,21 +669,6 @@ static int ad7606_read_raw(struct iio_dev *indio_dev, return -EINVAL; } -static ssize_t ad7606_show_avail(char *buf, const unsigned int *vals, - unsigned int n, bool micros) -{ - size_t len = 0; - int i; - - for (i = 0; i < n; i++) { - len += scnprintf(buf + len, PAGE_SIZE - len, - micros ? "0.%06u " : "%u ", vals[i]); - } - buf[len - 1] = '\n'; - - return len; -} - static ssize_t in_voltage_scale_available_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -689,8 +676,16 @@ static ssize_t in_voltage_scale_available_show(struct device *dev, struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ad7606_state *st = iio_priv(indio_dev); struct ad7606_chan_scale *cs = &st->chan_scales[0]; + const unsigned int (*vals)[2] = cs->scale_avail; + unsigned int i; + size_t len = 0; - return ad7606_show_avail(buf, cs->scale_avail, cs->num_scales, true); + for (i = 0; i < cs->num_scales; i++) + len += scnprintf(buf + len, PAGE_SIZE - len, "%u.%06u ", + vals[i][0], vals[i][1]); + buf[len - 1] = '\n'; + + return len; } static IIO_DEVICE_ATTR_RO(in_voltage_scale_available, 0); @@ -728,6 +723,7 @@ static int ad7606_write_raw(struct iio_dev *indio_dev, long mask) { struct ad7606_state *st = iio_priv(indio_dev); + unsigned int scale_avail_uv[AD760X_MAX_SCALES]; struct ad7606_chan_scale *cs; int i, ret, ch = 0; @@ -738,7 +734,12 @@ static int ad7606_write_raw(struct iio_dev *indio_dev, if (st->sw_mode_en) ch = chan->address; cs = &st->chan_scales[ch]; - i = find_closest(val2, cs->scale_avail, cs->num_scales); + for (i = 0; i < cs->num_scales; i++) { + scale_avail_uv[i] = cs->scale_avail[i][0] * MICRO + + cs->scale_avail[i][1]; + } + val = (val * MICRO) + val2; + i = find_closest(val, scale_avail_uv, cs->num_scales); ret = st->write_scale(indio_dev, ch, i + cs->reg_offset); if (ret < 0) return ret; @@ -771,9 +772,15 @@ static ssize_t ad7606_oversampling_ratio_avail(struct device *dev, { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ad7606_state *st = iio_priv(indio_dev); + const unsigned int *vals = st->oversampling_avail; + unsigned int i; + size_t len = 0; - return ad7606_show_avail(buf, st->oversampling_avail, - st->num_os_ratios, false); + for (i = 0; i < st->num_os_ratios; i++) + len += scnprintf(buf + len, PAGE_SIZE - len, "%u ", vals[i]); + buf[len - 1] = '\n'; + + return len; } static IIO_DEVICE_ATTR(oversampling_ratio_available, 0444, @@ -927,8 +934,8 @@ static int ad7606_read_avail(struct iio_dev *indio_dev, ch = chan->address; cs = &st->chan_scales[ch]; - *vals = cs->scale_avail_show; - *length = cs->num_scales * 2; + *vals = (int *)cs->scale_avail; + *length = cs->num_scales; *type = IIO_VAL_INT_PLUS_MICRO; return IIO_AVAIL_LIST; @@ -1051,24 +1058,9 @@ static int ad7606_chan_scales_setup(struct iio_dev *indio_dev) indio_dev->channels = chans; for (ch = 0; ch < num_channels; ch++) { - struct ad7606_chan_scale *cs; - int i; - ret = st->chip_info->scale_setup_cb(st, &chans[ch + 1], ch); if (ret) return ret; - - cs = &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 = 0; i < cs->num_scales; i++) { - cs->scale_avail_show[i * 2] = 0; - cs->scale_avail_show[i * 2 + 1] = cs->scale_avail[i]; - } } 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 formatted - * 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; From patchwork Fri Oct 25 09:59:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 13850395 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.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 4FD501E6321 for ; Fri, 25 Oct 2024 09:59:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729850400; cv=none; b=Tzj8ooUTUUYdiCExDgiw0ChnflPNlm+/dlCdf5Vsnn1X3E81hxq/8KeQwS0DIHjzCurU2LkXaUMUkgpyjAq5gqNsvzUNpaaO+GalCmCVK2spFY/IwASkJqIC69NSPPQbPmGAiPlSpW5X0wDcBZAEEX2nM9L6wmlQWi+s/Sp2peI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729850400; c=relaxed/simple; bh=AHr8+bZPxOirShIhCBXHwG+5r586Z0HInHo9tKzwsOg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=beYGkSjpnTJPLMuZRy7JYxR97EcwvCcZNg6JcqWh4RoYi6Q5SIJx4LsckpjSEP+Yhjrz7SNMw/yqOYSaebiCm0cogAKeKKjzdq9WP5jsMFnGTyWZGi+te1Ealdx9ShAihEsAoR/Cg23eewCAkMGhfvjMwoZHgHfKlVU93WwJWkQ= 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=2qRjA9Se; arc=none smtp.client-ip=209.85.218.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="2qRjA9Se" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a9a68480164so243768466b.3 for ; Fri, 25 Oct 2024 02:59:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729850396; x=1730455196; 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=TJ6DHZ27Ytkbo5yrreDnReoJRhwwE+fVxb3ObxqCfkc=; b=2qRjA9Se3jGVT0kScf7/7IhFew8OQBfgHGPbaSaPj/f4M8UiWus+QVbhTIE8vkkXA9 sZyVEA0Sw9RsifW70Qe1ZcN2J9OnpeqHsgFgw9/2b4hdVnJA+QeeBgGMBz7bnfd7dYLU ABxaRezj5N4s3IAdVOIEmEVVuUpx+7aKcJ5yvmJxBuxV9zEYVmf2t5g3ZRhtdDZ1+wB5 pQaS4/jwa1Z1hyD3WVcoAJwCZBAXfzbUyp/WagNpBsnEwwIv+CrrbJtke5PPwyE9TEXd 1VlImwaawsQWPG3Te1KVpUPMYpPtFoEk+pFPUfQGfOh4IJQaCPzMNOa0NBHLWMZ9JKsJ u+5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729850396; x=1730455196; 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=TJ6DHZ27Ytkbo5yrreDnReoJRhwwE+fVxb3ObxqCfkc=; b=gSaCWBDffclrz7nwd7ZaVf93ns4AZV3tWJosLzEVWLJsYYj38r9fjwf/X8wc3irJ/C KKvtgxWAMfCsd3cHRJe2Irjx4g5afVh2GmV+zQMalYABeOqF/fMP4j49TJoypAx8JVhC 5NJkILQtZ0LMIL/0BQlVqmt8WkWnTS503Ytr9jZlQIol60+MBdShb4JtKiqvKRJS52oF xKWsmZdHyDBoV6tMwct9zyWsYfmKH60nGj4VzqC1f/3HXzh8BoCG18gXBOb6gcbpMtyI 99NUxEvNQIz4oW37E1MH0ZCp9wrJyhxQAaS0BudzdVhUjWXScq7qTbGHF/IVdHxSmL9r QYIQ== X-Gm-Message-State: AOJu0YyR+ZrUtezetKUvhZnbpNdxm7bYB6er/BY/6atc+t15KyazpkpD 0mEkftufSRH5I+1BgPoiedX6vzRN5rWKG6+Wd4c8k658zBYajIB/oUAGJk7wd26mAXGmZ0uQL+5 AWuM= X-Google-Smtp-Source: AGHT+IGC4Odl99z+7cktPBrI3HzWr9YCRt8QG1Iui8MG4JArqRNHoC2e+scaEn36iNftnLDlwe4gDg== X-Received: by 2002:a17:907:3daa:b0:a9a:7f37:2b62 with SMTP id a640c23a62f3a-a9ad2815a49mr445493766b.49.1729850396140; Fri, 25 Oct 2024 02:59:56 -0700 (PDT) Received: from localhost.localdomain ([188.27.128.50]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1f02951esm51737266b.71.2024.10.25.02.59.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2024 02:59:55 -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, conor.dooley@microchip.com, Alexandru Ardelean Subject: [PATCH v2 4/5] dt-bindings: iio: adc: adi,ad7606: document AD760{7,8,9} parts Date: Fri, 25 Oct 2024 12:59:38 +0300 Message-ID: <20241025095939.271811-5-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241025095939.271811-1-aardelean@baylibre.com> References: <20241025095939.271811-1-aardelean@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This change adds the AD7607, AD7608 & AD7609 parts to the binding doc of the ad7606 driver. Acked-by: Conor Dooley Signed-off-by: Alexandru Ardelean --- .../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/Documentation/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/AD7606B.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/ad7606c-16.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/ad7606c-18.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7607.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7608.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7609.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/AD7616.pdf properties: @@ -28,6 +31,9 @@ properties: - adi,ad7606b - adi,ad7606c-16 - adi,ad7606c-18 + - adi,ad7607 + - adi,ad7608 + - adi,ad7609 - adi,ad7616 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 From patchwork Fri Oct 25 09:59:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 13850396 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (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 356BD1F76B9 for ; Fri, 25 Oct 2024 10:00:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729850403; cv=none; b=YHt2wQ24HpJYDlT3xoy4a67ADAQAKs7pDpJlcEYFEU7gpNMWLIf09F9frzjO1uKsRQsDLzRvritJ14GdBHV/pgZXwS8HXXAkKgy67RgHvlBHYXTwDISBHfPEoQTZpqiCPnUolEmvpxWaIKZRp8sQg8+8baN8cPsFYtPrKsURal8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729850403; c=relaxed/simple; bh=ZPKDDOSxbYilgrG4tLmWXDC2qLPxGrrf6mFdnqanB6s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qmd0BaXL3jyU1wS5pv1Qb3lKmt2qvgrwZe9cecJvrlrLJ0u29tV4YoXFLXK+ycHjCaelptuJfYCweE42q7YRV1oQb1sxdT2R/QLzpQ4iZG2QalH/ndtnGbBjghqCCq71zCa1z+NzuoWiyYzeEyy/NCN1QAuPx8yE6ys6tQarVhw= 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=MrjrMUym; arc=none smtp.client-ip=209.85.218.51 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="MrjrMUym" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a99f646ff1bso236459466b.2 for ; Fri, 25 Oct 2024 02:59:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729850398; x=1730455198; 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=2Z2Cp/0RuXPja2VnWMLGnI6YXRWhekI54aEssV25Ags=; b=MrjrMUym/JRNWlmUg1TqXkZ8dy9tnyaP1Z/XjtzVsI9lY77I7LdIezlDzfUsmLcijC 5Ro4lB3JFgjGD/CidyqGe/rGkjDPH9HzHn/SSMwl4/aRDZqgd1KRZ1JPimYe8z6jWQzN 84+R99KeNogKm3/dL61kbmzzir6z/B2us/hZoJSpJNSt2hskLC3OG2Qh3qehnjyijQxM d4+PiPi925Mu62z5l8Rojux+7W1iQc8t/nclYYP/1R1wq7NYl4OKnh7kUkSAb761KnRA eoPVUZC2dd5sJ+7V8i7Q+VwRNObjr8DpCuvuVPH6+Tgk9Y2pW5Q32Xf4WJ9KEGND4TYL I89w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729850398; x=1730455198; 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=2Z2Cp/0RuXPja2VnWMLGnI6YXRWhekI54aEssV25Ags=; b=eR20vh7LMUqrXSU+UuzaNEi80bQJcxa76ZJe3q/3sg4OxuePLhDE0FV3HrAw8yF4ZV XAEWU20OWBRUM+GZbHkCS6aMKHjEb5LINaefdWehjbU5y2K9yUe8cvCYiE8Kz8sFq+op 82NJWiG1FMMGPLVWPiFF19I+LaZetvOos14faZbfkCoP1D4oJyHSWWwwuoVN6+4n/iEg lY1TRbjFmIWxw0bGcYzcx60FN0EbUmiEOqEL340lCqrubcbBNDpkmhxQIaCtxebmEHkC bc/TL0xZQXht1vmFKituui+Za1XAefmTtCLBN/38xxXm53Zu94VqMPU5XU/uji1zug57 91Bg== X-Gm-Message-State: AOJu0Yw4LsobdxEwx8QWd6oJy1+6PES3nh5htVc9fvzAFBENo0zqgTyr sPYrk3zxUwQQwJoByAFNn/NdTN9dp+z+1CLE1c5pxDsX7pG6JgaRBRw9AblL39k+E7Y3G9EF9FP fd5k= X-Google-Smtp-Source: AGHT+IHo763g2tkSjDl77LlrxX9SC1j1w+RUJ1QYoF0MngkHKTcL+wMwFjjlOSz5xZhNREiseAJRkA== X-Received: by 2002:a17:906:c148:b0:a9a:3718:6d6 with SMTP id a640c23a62f3a-a9abf964714mr955294666b.58.1729850398115; Fri, 25 Oct 2024 02:59:58 -0700 (PDT) Received: from localhost.localdomain ([188.27.128.50]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1f02951esm51737266b.71.2024.10.25.02.59.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2024 02:59:57 -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, conor.dooley@microchip.com, Alexandru Ardelean Subject: [PATCH v2 5/5] iio: adc: ad7606: add support for AD760{7,8,9} parts Date: Fri, 25 Oct 2024 12:59:39 +0300 Message-ID: <20241025095939.271811-6-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241025095939.271811-1-aardelean@baylibre.com> References: <20241025095939.271811-1-aardelean@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 (±10V & ±20V) vs the ±5V & ±10V 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-sheets/ad7607.pdf Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/ad7608.pdf Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/ad7609.pdf Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7606.c | 104 +++++++++++++++++++++++++++++++++++ drivers/iio/adc/ad7606.h | 3 + drivers/iio/adc/ad7606_par.c | 6 ++ drivers/iio/adc/ad7606_spi.c | 42 ++++++++++++++ 4 files changed, 155 insertions(+) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index 94756bb87b95..8b2046baaa3e 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] = { { 0, 76293 }, { 0, 152588 }, { 0, 305176 } }; +static const unsigned int ad7607_hw_scale_avail[2][2] = { + { 0, 610352 }, { 1, 220703 } +}; + +static const unsigned int ad7609_hw_scale_avail[2][2] = { + { 0, 152588 }, { 0, 305176 } +}; + static const unsigned int ad7606_oversampling_avail[7] = { 1, 2, 4, 8, 16, 32, 64, }; @@ -113,6 +121,30 @@ static const struct iio_chan_spec ad7606_channels_18bit[] = { AD7606_CHANNEL(7, 18), }; +static const struct iio_chan_spec ad7607_channels[] = { + 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[] = { + 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 activated. @@ -149,6 +181,12 @@ static int ad7606c_16bit_chan_scale_setup(struct ad7606_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); const struct ad7606_chip_info ad7605_4_info = { .channels = ad7605_channels, @@ -215,6 +253,39 @@ const struct ad7606_chip_info ad7606c_16_info = { }; EXPORT_SYMBOL_NS_GPL(ad7606c_16_info, IIO_AD7606); +const struct ad7606_chip_info ad7607_info = { + .channels = ad7607_channels, + .name = "ad7607", + .num_adc_channels = 8, + .num_channels = 9, + .oversampling_avail = ad7606_oversampling_avail, + .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), + .scale_setup_cb = ad7607_chan_scale_setup, +}; +EXPORT_SYMBOL_NS_GPL(ad7607_info, IIO_AD7606); + +const struct ad7606_chip_info ad7608_info = { + .channels = ad7608_channels, + .name = "ad7608", + .num_adc_channels = 8, + .num_channels = 9, + .oversampling_avail = ad7606_oversampling_avail, + .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), + .scale_setup_cb = ad7608_chan_scale_setup, +}; +EXPORT_SYMBOL_NS_GPL(ad7608_info, IIO_AD7606); + +const struct ad7606_chip_info ad7609_info = { + .channels = ad7608_channels, + .name = "ad7609", + .num_adc_channels = 8, + .num_channels = 9, + .oversampling_avail = ad7606_oversampling_avail, + .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), + .scale_setup_cb = ad7609_chan_scale_setup, +}; +EXPORT_SYMBOL_NS_GPL(ad7609_info, IIO_AD7606); + const struct ad7606_chip_info ad7606c_18_info = { .channels = ad7606_channels_18bit, .name = "ad7606c18", @@ -441,6 +512,39 @@ static int ad7606c_16bit_chan_scale_setup(struct ad7606_state *st, return 0; } +static int ad7607_chan_scale_setup(struct ad7606_state *st, + struct iio_chan_spec *chan, int ch) +{ + struct ad7606_chan_scale *cs = &st->chan_scales[ch]; + + cs->range = 0; + cs->scale_avail = ad7607_hw_scale_avail; + cs->num_scales = 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 = &st->chan_scales[ch]; + + cs->range = 0; + cs->scale_avail = ad7606_18bit_hw_scale_avail; + cs->num_scales = 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 = &st->chan_scales[ch]; + + cs->range = 0; + cs->scale_avail = ad7609_hw_scale_avail; + cs->num_scales = ARRAY_SIZE(ad7609_hw_scale_avail); + return 0; +} + static int ad7606_reg_access(struct iio_dev *indio_dev, unsigned int reg, unsigned int writeval, 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; #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_ids[] = { { .name = "ad7606-6", .driver_data = (kernel_ulong_t)&ad7606_6_info, }, { .name = "ad7606-8", .driver_data = (kernel_ulong_t)&ad7606_8_info, }, { .name = "ad7606b", .driver_data = (kernel_ulong_t)&ad7606b_info, }, + { .name = "ad7607", .driver_data = (kernel_ulong_t)&ad7607_info, }, + { .name = "ad7608", .driver_data = (kernel_ulong_t)&ad7608_info, }, + { .name = "ad7609", .driver_data = (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[] = { { .compatible = "adi,ad7606-6", .data = &ad7606_6_info }, { .compatible = "adi,ad7606-8", .data = &ad7606_8_info }, { .compatible = "adi,ad7606b", .data = &ad7606b_info }, + { .compatible = "adi,ad7607", .data = &ad7607_info }, + { .compatible = "adi,ad7608", .data = &ad7608_info }, + { .compatible = "adi,ad7609", .data = &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; } +static int ad7606_spi_read_block14to16(struct device *dev, + int count, void *buf) +{ + struct spi_device *spi = to_spi_device(dev); + struct spi_transfer xfer = { + .bits_per_word = 14, + .len = count * sizeof(u16), + .rx_buf = 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 = { .read_block = ad7606_spi_read_block, }; +static const struct ad7606_bus_ops ad7607_spi_bops = { + .read_block = ad7606_spi_read_block14to16, +}; + +static const struct ad7606_bus_ops ad7608_spi_bops = { + .read_block = ad7606_spi_read_block18to32, +}; + static const struct ad7606_bus_ops ad7616_spi_bops = { .read_block = ad7606_spi_read_block, .reg_read = ad7606_spi_reg_read, @@ -387,6 +408,21 @@ static const struct ad7606_bus_info ad7606c_18_bus_info = { .bops = &ad7606c_18_spi_bops, }; +static const struct ad7606_bus_info ad7607_bus_info = { + .chip_info = &ad7607_info, + .bops = &ad7607_spi_bops, +}; + +static const struct ad7606_bus_info ad7608_bus_info = { + .chip_info = &ad7608_info, + .bops = &ad7608_spi_bops, +}; + +static const struct ad7606_bus_info ad7609_bus_info = { + .chip_info = &ad7609_info, + .bops = &ad7608_spi_bops, +}; + static const struct ad7606_bus_info ad7616_bus_info = { .chip_info = &ad7616_info, .bops = &ad7616_spi_bops, @@ -408,6 +444,9 @@ static const struct spi_device_id ad7606_id_table[] = { { "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[] = { { .compatible = "adi,ad7606b", .data = &ad7606b_bus_info }, { .compatible = "adi,ad7606c-16", .data = &ad7606c_16_bus_info }, { .compatible = "adi,ad7606c-18", .data = &ad7606c_18_bus_info }, + { .compatible = "adi,ad7607", .data = &ad7607_bus_info }, + { .compatible = "adi,ad7608", .data = &ad7608_bus_info }, + { .compatible = "adi,ad7609", .data = &ad7609_bus_info }, { .compatible = "adi,ad7616", .data = &ad7616_bus_info }, { } };