From nobody Mon Nov 25 19:27:12 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 08A831F5839 for ; Fri, 25 Oct 2024 09:59:59 +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=1729850403; cv=none; b=dsos4Zi7beVNMdgFEkSEDMssqAUnVHMaG1gQ0VrqeLIo/zLfJAwnd7lFa/1cv+ULeEDrdF3FNZdqau4s3xOpjTLRqUXuT/SakE5HHbAe4cmcmSidOjdcpbiL5J3YtTg/isbBFbXhvO9zXjuZFfO2rbbuRAbxBf3tT8n5bhTTX1Y= 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.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="MrjrMUym" Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a9a1b71d7ffso272987166b.1 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=S2S9Na8NXJG+p3IwwBQ85Qjr5MiK2aLplunIf/KiDeSFCi2/kgue94Sjff1byoaRE8 q3gVOfG5e3OGJ8DGhQraF4PBoytHN1RCMNz6k9TsjuOVH1unBdvOgNYKqMCiJ3/Vx3hm 5WYY+qBWUe5ByPleD7qwn93exYWs9l4g5RjP+eiaGmxcxwzY5gN6IyI0WmptuER0yGxi RKv1fVTt/QCqs65hVHhqBbVmqSZfYUydzt8/V7NACGFHtbUJDQEDsu9tkvHKwUYSOtrH xE+iwR3f7Av5R4NPy+xq99fofkCwdyidLeMKXEzrRXvPvzUe1bsn/Bh2iJT9o1R1+r4N zB2A== X-Forwarded-Encrypted: i=1; AJvYcCXpTG6sWOKDfHCshNsKORiqU4wafGcqxaAfp1b/7luJPTerISvR3PKU7YcKNH1cu9NuYuOWkwx91PiQQFE=@vger.kernel.org X-Gm-Message-State: AOJu0YxKEUmCMDCLGXUQyeNy6UPEXnFzUbcBHVk3daRkDpueaWUZgj3V 0yX4HraPMTg1vzxmuKXJGPGNvUeJdjVTGKCWq/g4LYH/0IeOkyixIGRrAmz+iIY= 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-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 | 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] =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, 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