From nobody Mon Feb 9 15:25:39 2026 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (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 450453D1CB3 for ; Thu, 15 Jan 2026 17:53:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768499644; cv=none; b=QAjyAyDEfGL9QnncInJ3luHV2rrdcD1do/9SXCU9kblJ3cT18v0DbGHFK5IAlF1yNqQcQ5EXCAa3HOoq8RJ9YfTtuA47/ENcd2pf5AHwkTdqEiojdnQ0NYEqj77sCDIGR8BpzENKoRoCj1lpUJ2O5kdWugK6PHRimENUzwoVRCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768499644; c=relaxed/simple; bh=YZChUeoZSlclWou2p1AfaRnTBqUP9N75hd9lkgdhGog=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CpM8ixzVhu87kivJyu1ABOZ9vLJ6ewH4vxoTuhLrPZBAg5+/XzVMIBMZW9DB07gJv//NP8rds0GL28KsiI8m5o7XAyA3caynlkgozp51h3a+hVqlRdqghdZJME39KoiB3of0SP/k3tHKgrh6Ai7zsEbMqmWGN2BoHPhpUPuP1jk= 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=WUPzUHOf; arc=none smtp.client-ip=209.85.218.54 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="WUPzUHOf" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-b87124c6295so186887166b.3 for ; Thu, 15 Jan 2026 09:53:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1768499636; x=1769104436; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=tFuwwtdwwY9t5jaDt+uh7+prGEQmO6XhAru1cfWN/CI=; b=WUPzUHOfKrCSgEkR2XykcFCRKGUEtx4UbSjEOPCbLIXDfy1xGu5yzOH6o+IaxX7A4m KZccugyiipZFAOkiztNWSSpj1V6EQDjlJJ56JbSE5QC01uo9X6lbAZT/De4h7KmLH/LR u1A8fCqVIYJ+Ar5Zui8zABHE5enV4ldKrMzPv3jzqGkRe2Qt4kbP6WfM5ldxhxWpmJzq +WbytF2ZBT/FGhTwBSB09FuaCSyqXRPMJqt3udsnznR3RiXKv1NDQlfmslLqMSUu7rMD wBqf06+PC7Qn1hb2I28xaS89uNnjzRzU3gZ5IQlOZVc5o2H9KE72JZpqpgy+8HzSLOVG BR5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768499636; x=1769104436; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=tFuwwtdwwY9t5jaDt+uh7+prGEQmO6XhAru1cfWN/CI=; b=nARbmrJ0O1fMPGjHhMY7DTC64Co7Ablfbu/TQ74zew2zcJ9TuARNxVz2XIojCFlyVl 8dPRxc51SRYLlAUicPmgbAxbL3TdW4iw+ohRcZTi6N1os7n2v91IkfCiBndaNWuPV0mE O8qyaRtGYgL3QZNgpk8nfiQAJ5+S1WEHl8djfM8jq735pPUGYMINMmiS41pFG4/31HL8 ZjtG2/vPgiznaq+xmcMFdIB3UPB+cubSI2FZKNy5lzED60J9S20y03uHOatgTegYC7YH U2grFIKTKj72l5MnWv3ySBHzSn7htlaQxe1djglw8E4w9AfJqSFKMNGcwl9lj0TG6Yut 4e3Q== X-Forwarded-Encrypted: i=1; AJvYcCVjbldlaMl+5zrfajcxFbgQYoa0QSkSOidAJdAY0LWtZXRH0Vdu7HfZsS1T/zOtlIBNBj6hIHLNkxRm9eQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxncWOU2yjDZV876k0VQuf+z4EwgEBbai5hOCI+g/tW83WWGa0S DhJVT5ItzpWeVHDWvFXNgljaPOzknb+hpADE3Nys5yTyZ9krNKHHyr5/YmztFAHOWVg= X-Gm-Gg: AY/fxX7eYk38r6QLa4zrPDyQPaFqjGWTBJLOjzN6IAHa2r20Bbxo5slD1Ue7SumK8sE BdmAn8pUFDeBcnuHo388YRbbfysXjIA3RsiWUAvx5jjgYkzNsTlLmxGEPYOrNsqk4QC/55JHVde t7NlEXmnqjg2H/+w011hNRR9Ck5W/lCnY/6IQxeFPWvM/NE3ndFEPECfnINaJyOglkXeGShP8nS vi3q3xucsI7LKyPIxf14gOkMb8itwDL6GAFy8rrPAMbM97t14q8e1P8iDriFUMCbyC+78TCjW0G 5YTr0gzSZMRUylRQ3O8M7QnyPRn9Qca6NkPAoxGYML9eX6Z8qu73+P8u7T7qqtLTFbn8qk2mpcU CzuhykdqBc0pdx++eh9c7NYGgsCtiPvMRJLM2x4PZV0rC5PAjP7GbqalrPomQqPbEy3PQNtDIOk ZP X-Received: by 2002:a17:906:c153:b0:b87:2780:1b1e with SMTP id a640c23a62f3a-b8793243a3amr42716266b.41.1768499636065; Thu, 15 Jan 2026 09:53:56 -0800 (PST) Received: from localhost ([151.43.128.48]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b879513e735sm5098666b.13.2026.01.15.09.53.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jan 2026 09:53:55 -0800 (PST) From: Francesco Lavra To: Ramona Gradinariu , Antoniu Miclaus , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] iio: accel: adxl380: Add support for 1 kHz sampling frequency Date: Thu, 15 Jan 2026 18:53:50 +0100 Message-Id: <20260115175350.1045887-4-flavra@baylibre.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260115175350.1045887-1-flavra@baylibre.com> References: <20260115175350.1045887-1-flavra@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=7485; i=flavra@baylibre.com; h=from:subject; bh=YZChUeoZSlclWou2p1AfaRnTBqUP9N75hd9lkgdhGog=; b=owEB7QES/pANAwAKAe3xO3POlDZfAcsmYgBpaSmgEzEsXkfvkr08Il5hsaB4QA4cYusdEWLpT //Bw0aRon6JAbMEAAEKAB0WIQSGV4VPlTvcox7DFObt8TtzzpQ2XwUCaWkpoAAKCRDt8TtzzpQ2 XzH1C/9eJTybGnpw7exYI7UF74mjBVrVFzC0P60Gjw2r5qFoPi93x5eC8xcdEmLWPgpa5wvgeaP Z1+hJI6zFfpawPbAyzEAfRr0QxjwFYXbQRx+egivHZacjZaBMsJrCaCYOBIQf9nFHcsWjisXSn7 K+rWSUirl1RJ5g9r5Hf1in42XZ90KwYL6/mR+mH7gF4xgBNQF/sDBkIFpcTwirBomXXUWSnexkP bqPx/aDGRhWkwdvXl0c2qDHmAShqpPlL0yBLUwZj/86etHb49/PhCch4IxIgIbahootiBvRSjD8 w17mMcuxUTQPrxBJRFqb3MvU1Nft1hpUeZ7aJXM0LKIX8UknTdM34toox7+C6+z9yFXjIrUYDw/ EMtfNyMj6zyKsef6c9ale/0Mn36RcF02qEcCPjmQkwR/otymETbUCfdI7sBXSOK9yNnrq2JHttU bC3XnnrmNXZ2ty3Fx6nnM3/TVLfk5VRlT+TjuEA414ZGAvyJgK8mxaJKGOhCVRPkK9cPg= X-Developer-Key: i=flavra@baylibre.com; a=openpgp; fpr=8657854F953BDCA31EC314E6EDF13B73CE94365F Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In sensor variants (such as ADXL380 and ADXL382) that support low-power mode, the SAR signal path allows sampling acceleration data at lower rates; more specifically, when the sensor operates in VLP mode, the sampling frequency is 1 kHz. To add support for the 1kHz sampling frequency value, modify the operating mode selection logic to take into account the sampling frequency, and configure the decimation filters only when applicable (i.e. when using a sampling frequency that relies on the DSM signal path); in addition, constrain the available sampling frequency values based on whether the sensor is operating in low-power mode. Signed-off-by: Francesco Lavra --- drivers/iio/accel/adxl380.c | 82 ++++++++++++++++++++++++++++--------- drivers/iio/accel/adxl380.h | 10 ++++- 2 files changed, 71 insertions(+), 21 deletions(-) diff --git a/drivers/iio/accel/adxl380.c b/drivers/iio/accel/adxl380.c index b99458a5eae3..7fe94e5cce0f 100644 --- a/drivers/iio/accel/adxl380.c +++ b/drivers/iio/accel/adxl380.c @@ -264,10 +264,12 @@ static int adxl380_set_measure_en(struct adxl380_stat= e *st, bool en) =20 /* * Activity/Inactivity detection available only in VLP/ULP - * mode and for devices that support low power modes. Otherwise - * go straight to measure mode (same bits as ADXL380_OP_MODE_HP). + * mode and for devices that support low power modes. */ if (act_inact_enabled) + st->odr =3D ADXL380_ODR_VLP; + + if (st->odr =3D=3D ADXL380_ODR_VLP) op_mode =3D ADXL380_OP_MODE_VLP; else op_mode =3D ADXL380_OP_MODE_HP; @@ -495,17 +497,22 @@ static int adxl380_set_odr(struct adxl380_state *st, = u8 odr) if (ret) return ret; =20 - ret =3D regmap_update_bits(st->regmap, ADXL380_TRIG_CFG_REG, - ADXL380_TRIG_CFG_DEC_2X_MSK, - FIELD_PREP(ADXL380_TRIG_CFG_DEC_2X_MSK, odr & 1)); - if (ret) - return ret; + if (odr >=3D ADXL380_ODR_DSM) { + u8 mul =3D odr - ADXL380_ODR_DSM; + u8 field; =20 - ret =3D regmap_update_bits(st->regmap, ADXL380_TRIG_CFG_REG, - ADXL380_TRIG_CFG_SINC_RATE_MSK, - FIELD_PREP(ADXL380_TRIG_CFG_SINC_RATE_MSK, odr >> 1)); - if (ret) - return ret; + field =3D FIELD_PREP(ADXL380_TRIG_CFG_DEC_2X_MSK, mul & 1); + ret =3D regmap_update_bits(st->regmap, ADXL380_TRIG_CFG_REG, + ADXL380_TRIG_CFG_DEC_2X_MSK, field); + if (ret) + return ret; + + field =3D FIELD_PREP(ADXL380_TRIG_CFG_SINC_RATE_MSK, mul >> 1); + ret =3D regmap_update_bits(st->regmap, ADXL380_TRIG_CFG_REG, + ADXL380_TRIG_CFG_SINC_RATE_MSK, field); + if (ret) + return ret; + } =20 st->odr =3D odr; ret =3D adxl380_set_measure_en(st, true); @@ -1145,6 +1152,31 @@ static const struct iio_buffer_setup_ops adxl380_buf= fer_ops =3D { .predisable =3D adxl380_buffer_predisable, }; =20 +static int adxl380_samp_freq_avail(struct adxl380_state *st, const int **v= als, + int *length) +{ + bool act_inact_enabled; + int ret; + + if (!st->chip_info->has_low_power) { + *vals =3D st->chip_info->samp_freq_tbl + ADXL380_ODR_DSM; + *length =3D ADXL380_ODR_MAX - ADXL380_ODR_DSM; + return 0; + } + + ret =3D adxl380_act_inact_enabled(st, &act_inact_enabled); + if (!ret) { + /* + * Motion detection is only functional in low-power mode, and + * this affects the available sampling frequencies. + */ + *vals =3D st->chip_info->samp_freq_tbl; + *length =3D act_inact_enabled ? ADXL380_ODR_DSM : ADXL380_ODR_MAX; + } + + return ret; +} + static int adxl380_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long info) @@ -1225,6 +1257,7 @@ static int adxl380_read_avail(struct iio_dev *indio_d= ev, long mask) { struct adxl380_state *st =3D iio_priv(indio_dev); + int ret; =20 if (chan->type !=3D IIO_ACCEL) return -EINVAL; @@ -1236,9 +1269,11 @@ static int adxl380_read_avail(struct iio_dev *indio_= dev, *length =3D ARRAY_SIZE(st->chip_info->scale_tbl) * 2; return IIO_AVAIL_LIST; case IIO_CHAN_INFO_SAMP_FREQ: - *vals =3D (const int *)st->chip_info->samp_freq_tbl; + ret =3D adxl380_samp_freq_avail(st, vals, length); + if (ret) + return ret; + *type =3D IIO_VAL_INT; - *length =3D ARRAY_SIZE(st->chip_info->samp_freq_tbl); return IIO_AVAIL_LIST; case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: *vals =3D (const int *)st->lpf_tbl; @@ -1261,12 +1296,18 @@ static int adxl380_write_raw(struct iio_dev *indio_= dev, int val, int val2, long info) { struct adxl380_state *st =3D iio_priv(indio_dev); + const int *freq_vals; + int freq_count; int odr_index, lpf_index, hpf_index, range_index; + int ret; =20 switch (info) { case IIO_CHAN_INFO_SAMP_FREQ: - odr_index =3D adxl380_find_match_1d_tbl(st->chip_info->samp_freq_tbl, - ARRAY_SIZE(st->chip_info->samp_freq_tbl), + ret =3D adxl380_samp_freq_avail(st, &freq_vals, &freq_count); + if (ret) + return ret; + + odr_index =3D adxl380_find_match_1d_tbl(freq_vals, freq_count, val); return adxl380_set_odr(st, odr_index); case IIO_CHAN_INFO_CALIBBIAS: @@ -1628,7 +1669,7 @@ const struct adxl380_chip_info adxl318_chip_info =3D { [ADXL380_OP_MODE_8G_RANGE] =3D { 0, 2615434 }, [ADXL380_OP_MODE_16G_RANGE] =3D { 0, 5229886 }, }, - .samp_freq_tbl =3D { 8000, 16000, 32000 }, + .samp_freq_tbl =3D { 0, 8000, 16000, 32000 }, /* * The datasheet defines an intercept of 550 LSB at 25 degC * and a sensitivity of 10.2 LSB/C. @@ -1646,7 +1687,7 @@ const struct adxl380_chip_info adxl319_chip_info =3D { [ADXL382_OP_MODE_30G_RANGE] =3D { 0, 9806650 }, [ADXL382_OP_MODE_60G_RANGE] =3D { 0, 19613300 }, }, - .samp_freq_tbl =3D { 16000, 32000, 64000 }, + .samp_freq_tbl =3D { 0, 16000, 32000, 64000 }, /* * The datasheet defines an intercept of 550 LSB at 25 degC * and a sensitivity of 10.2 LSB/C. @@ -1664,7 +1705,7 @@ const struct adxl380_chip_info adxl380_chip_info =3D { [ADXL380_OP_MODE_8G_RANGE] =3D { 0, 2615434 }, [ADXL380_OP_MODE_16G_RANGE] =3D { 0, 5229886 }, }, - .samp_freq_tbl =3D { 8000, 16000, 32000 }, + .samp_freq_tbl =3D { 1000, 8000, 16000, 32000 }, /* * The datasheet defines an intercept of 470 LSB at 25 degC * and a sensitivity of 10.2 LSB/C. @@ -1684,7 +1725,7 @@ const struct adxl380_chip_info adxl382_chip_info =3D { [ADXL382_OP_MODE_30G_RANGE] =3D { 0, 9806650 }, [ADXL382_OP_MODE_60G_RANGE] =3D { 0, 19613300 }, }, - .samp_freq_tbl =3D { 16000, 32000, 64000 }, + .samp_freq_tbl =3D { 1000, 16000, 32000, 64000 }, /* * The datasheet defines an intercept of 570 LSB at 25 degC * and a sensitivity of 10.2 LSB/C. @@ -1923,6 +1964,7 @@ int adxl380_probe(struct device *dev, struct regmap *= regmap, st->dev =3D dev; st->regmap =3D regmap; st->chip_info =3D chip_info; + st->odr =3D ADXL380_ODR_DSM; =20 mutex_init(&st->lock); =20 diff --git a/drivers/iio/accel/adxl380.h b/drivers/iio/accel/adxl380.h index e67c5aab8efc..d2c260c8b2fa 100644 --- a/drivers/iio/accel/adxl380.h +++ b/drivers/iio/accel/adxl380.h @@ -8,10 +8,18 @@ #ifndef _ADXL380_H_ #define _ADXL380_H_ =20 +enum adxl380_odr { + ADXL380_ODR_VLP, + ADXL380_ODR_DSM, + ADXL380_ODR_DSM_2X, + ADXL380_ODR_DSM_4X, + ADXL380_ODR_MAX +}; + struct adxl380_chip_info { const char *name; const int scale_tbl[3][2]; - const int samp_freq_tbl[3]; + const int samp_freq_tbl[ADXL380_ODR_MAX]; const struct iio_info *info; const int temp_offset; const u16 chip_id; --=20 2.39.5