From patchwork Sun Nov 17 18:26:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13877881 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A9C5192D97; Sun, 17 Nov 2024 18:28:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868097; cv=none; b=KvSUOTTlq36fPk06uoe/1YNyGfeY75LATv0iiT3y9Uhv0Y7FX5p5BaCP5EYlL3+HE+VBb2Gjr01Q3Mo9VpiHx5p32XeiUHG0U5Gc9bZeQk8nwAaD0YN3F+GjRmK80AbDXnSBEGbFoBgJoZD18rLG8FSdisXyhwRepuu+XQcZfBg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868097; c=relaxed/simple; bh=zC4utrncVmy2RjXFLmrGKa3KsfHnCdq9j5x5pTqoYks=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mwSqPyO7ct0T0/ZF2j1ejTVxSPGwtvfvVol/PmxvqVk1/oNB/X7n6DeaaQBGRnX0uuW16oFTwRBnrsyifEoD/cHn1z/s0ZU5JZIps1VNsTJz+cQuel4U5PksictBSBQpVnLzrN3yWpr9deYGDYR6IPyxwp1pI+W+C7mXshlQZNU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=i6e0xhb8; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="i6e0xhb8" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-431506d4f3bso1869395e9.0; Sun, 17 Nov 2024 10:28:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731868095; x=1732472895; 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=wWdIbNe2zK4K5n6rJj1IjwHyeU7rCXgoeLdzNBBqx9M=; b=i6e0xhb8WN8PvNYBfvYdbFMwhHfFNvO3MAqb7zBny6kO2NN+aQHsDUM062Nnkx5F9D 00YSUeFjaarF39EDexnC+aEdVtph3N54xtb2Jm2FYNCAyPM0DiN/dqehEOYfKgojYVGG P4q4pegi8i9yqTX2KXovnlj4QRMlq6iDvcEvESAzXI97+QDggQPrnR/DxKO/pFA29fG/ CBDF0LdKVNOixyi04dgEDwtbUHjUtOOhiqWvgD2Ek0PrZgZDFx5w2a+25efJ9QkwZ09/ HMUX/n6mlG507OZeCa3lAu9mrg+z1gpRAU4ZZC6fBNnDyhQiAqUM4rDYTFDGajjAzF1x LmfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731868095; x=1732472895; 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=wWdIbNe2zK4K5n6rJj1IjwHyeU7rCXgoeLdzNBBqx9M=; b=aXEL/egzqwjpiHkFdpJnERqLik3FwKxgoyGNNHTAzhGciV0fv+XYKxG04CROba9ce/ oE+kBU/xBtenjrs/Jm3Xp/XS9XVdVjQV6mUYF3Shw1DPs9dHrtBlSUjtCd+hbUpmTmp0 GyAv3ZlAYsw7lpoNolDNcYHFt3q2RuMtzBgCNGEwB0jIuNsUD5YdmXRbAPwSSWPfXRt4 0SSmEutPXfdFYWvoCmEaZ+7dSbafDDYe3u66wNf3xXbv42WeRAn+42/VmqzREQIlgyUe En2zikwYvQ/9YGRT+IMJ+ziNmupV0yIdppTXc9h27/5FvVcB7WFma2v07aNvb4YSu89P T6qw== X-Forwarded-Encrypted: i=1; AJvYcCUFwp0lYRo4eoU6dKbiY9bNr5C9GiNs0VmZVkecLtiPWgDcOOL2hrsc8wvu3eNLNVsF7EG0xtDyIxG6pFY=@vger.kernel.org X-Gm-Message-State: AOJu0YxdkQCW9ltOoXPlf3E40hYMyQHK5039+YrYtCnWQpBL00x7Jix6 FlTEmazO4QSOULcc+0V7fxV0qFW1rkCDbnHgT3hv3wXvpmnJ3b5p X-Google-Smtp-Source: AGHT+IFZSuPt4H7aJw432ypeU7GFKezwcXsxnc4bbaFuG0+EoY5pM+xNG77ehGwKDBv0nq1Ukm3qaw== X-Received: by 2002:a5d:5f93:0:b0:37c:c815:a204 with SMTP id ffacd0b85a97d-382258ec38fmr2753762f8f.3.1731868094646; Sun, 17 Nov 2024 10:28:14 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3823f72441bsm3028137f8f.101.2024.11.17.10.28.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Nov 2024 10:28:14 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v2 01/22] iio: accel: adxl345: fix comment on probe Date: Sun, 17 Nov 2024 18:26:30 +0000 Message-Id: <20241117182651.115056-2-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241117182651.115056-1-l.rubusch@gmail.com> References: <20241117182651.115056-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Fix comment on the probe function. Add covered sensors and fix typo. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 006ce66c0a..d121caf839 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -170,7 +170,7 @@ static void adxl345_powerdown(void *regmap) /** * adxl345_core_probe() - probe and setup for the adxl345 accelerometer, - * also covers the adlx375 accelerometer + * also covers the adxl375 and adxl346 accelerometer * @dev: Driver model representation of the device * @regmap: Regmap instance for the device * @setup: Setup routine to be executed right before the standard device From patchwork Sun Nov 17 18:26:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13877882 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.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 6E1261DAC89; Sun, 17 Nov 2024 18:28:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868099; cv=none; b=QC4adGpgwptR6gnenzOi8tce/7NAinsIPTBRx8L4bUquFwOXx+Xxe2JRIn0GQ99SR6fPFstTmcu3+Rp14EMbzlaSoGtxQZXtWHcbLvHRK5agbAPYuFV208UAix92mKIkdnu2Uj0iEJJH5bBgJTEIevhJ2yq4UOzARudQuWF0d8Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868099; c=relaxed/simple; bh=y+a8Dgzwai/8ON1MHAgB0jOka1N/MHSlh7WRmee1oxY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IprK9X0HTHvOgV+oG/9cU2VfRj4PJXoff55gvmp+WYU3CeXNPUizNS4EUxaO/3jWkKhPNUYCO0ruI9jRsNNA568akHp4kLsBDqril0hmXxKHAqCywPj/Gaw/yJRXTBy8EpWYFvy6gCRpJrYeTq6M697kRooN3tXebnbacDK15d0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YzG+BcJS; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YzG+BcJS" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4315b0bd4ddso3683875e9.3; Sun, 17 Nov 2024 10:28:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731868096; x=1732472896; 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=a1FtfPptB+JOVSXxLOLJAca/P/FMUB1susLRkC9Vf5s=; b=YzG+BcJSrDtZ6b1x3VbiWkby+Hm+hI7HRsD68vuCSfZwiT7z5IqqJ+FwjUf7v9yrYo xq2EWOuohJQT1HGT27W87wPA1HmUK++5AIBMww77hAoQACHBdzqW8xGKzk/NdYJtFiHo GfCNxrS/AaMpgqyrGgEmB1CDYhkX4GQniCigYYm2XQ3kFafAvVU0I5oE/85lXKqjlvp+ JxDBldSIijkemEledW6ZPROqsOsO0eeHm8PZfAzEmMn+CCVrLgJ884LjSr0TLsJHtrl9 sP3j2egKt+iaVngrBOdyGyYf+EJHNgmZBNx9BETQu4IEfWikeai+W6bjnc0RpAN+DxI+ eSvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731868096; x=1732472896; 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=a1FtfPptB+JOVSXxLOLJAca/P/FMUB1susLRkC9Vf5s=; b=U5TtQHsn27TzRuMmVOEO4qtzR1R5WaOw7wFd+eLvmDAelekA8vHpOAQ0U2wssZNgwM +Dua9ksx0vCUkUYBuDlgvsbdgTWnNuA1EMjoyVPue+hGQynMp3msDTmaakX6ZYjVlJFT oIdNtCgr8zUYNpgRFpaFgrIHfpMjycQO6exdbqH5+R1z6afYBX8YbB9505HPojr5SAnZ mP9FI+9yN3FYzgejU+IVmiMAyJL/o/05EXz2/PymAmhYwkUoK5MaJ3BAXSKeWEohjVeW irbtJAl6MypAAJjEsB3RjVduXWCzMwflxgnpdbMaoNLsaZgHxzJHg9ZIkfYwv2LVNaMt pUwg== X-Forwarded-Encrypted: i=1; AJvYcCWh0I6XgoB2QhkiA+hQ8n0e4OHq2aiA+bQ0+i74No1cQG32RNPRyb3aEVdyl+C1SqL2IyNOywMo3n05Qrk=@vger.kernel.org X-Gm-Message-State: AOJu0YyPDR8tdjEjSxD8WFmsuIdLEqY25wxePpfE3BXFOtprloGo5u0X hANMzcRJE3cL715y1s+IXbTI5TfcfPIC5gbkhUXLfyb+vKk/fY6U X-Google-Smtp-Source: AGHT+IGq9c9CHYv8u82yRrOBR6ZRdLepWgFwS7Ati+MknlqYR/pCGTwEky5IarfVYbe21d6tGh5Qsw== X-Received: by 2002:a05:600c:1c83:b0:42c:b63d:df3 with SMTP id 5b1f17b1804b1-432df680b0bmr35311295e9.0.1731868095520; Sun, 17 Nov 2024 10:28:15 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3823f72441bsm3028137f8f.101.2024.11.17.10.28.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Nov 2024 10:28:15 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v2 02/22] iio: accel: adxl345: rename variable data to st Date: Sun, 17 Nov 2024 18:26:31 +0000 Message-Id: <20241117182651.115056-3-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241117182651.115056-1-l.rubusch@gmail.com> References: <20241117182651.115056-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Rename the locally used variable data to st. The st refers to "state", representing the internal state of the driver object. Further it prepares the usage of an internal data pointer needed for the implementation of the sensor features. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 42 ++++++++++++++++---------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index d121caf839..3fb7a7b1b7 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -43,7 +43,7 @@ static int adxl345_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { - struct adxl345_data *data = iio_priv(indio_dev); + struct adxl345_data *st = iio_priv(indio_dev); __le16 accel; long long samp_freq_nhz; unsigned int regval; @@ -56,7 +56,7 @@ static int adxl345_read_raw(struct iio_dev *indio_dev, * ADXL345_REG_DATA(X0/Y0/Z0) contain the least significant byte * and ADXL345_REG_DATA(X0/Y0/Z0) + 1 the most significant byte */ - ret = regmap_bulk_read(data->regmap, + ret = regmap_bulk_read(st->regmap, ADXL345_REG_DATA_AXIS(chan->address), &accel, sizeof(accel)); if (ret < 0) @@ -66,10 +66,10 @@ static int adxl345_read_raw(struct iio_dev *indio_dev, return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: *val = 0; - *val2 = data->info->uscale; + *val2 = st->info->uscale; return IIO_VAL_INT_PLUS_MICRO; case IIO_CHAN_INFO_CALIBBIAS: - ret = regmap_read(data->regmap, + ret = regmap_read(st->regmap, ADXL345_REG_OFS_AXIS(chan->address), ®val); if (ret < 0) return ret; @@ -81,7 +81,7 @@ static int adxl345_read_raw(struct iio_dev *indio_dev, return IIO_VAL_INT; case IIO_CHAN_INFO_SAMP_FREQ: - ret = regmap_read(data->regmap, ADXL345_REG_BW_RATE, ®val); + ret = regmap_read(st->regmap, ADXL345_REG_BW_RATE, ®val); if (ret < 0) return ret; @@ -99,7 +99,7 @@ static int adxl345_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask) { - struct adxl345_data *data = iio_priv(indio_dev); + struct adxl345_data *st = iio_priv(indio_dev); s64 n; switch (mask) { @@ -108,14 +108,14 @@ static int adxl345_write_raw(struct iio_dev *indio_dev, * 8-bit resolution at +/- 2g, that is 4x accel data scale * factor */ - return regmap_write(data->regmap, + return regmap_write(st->regmap, ADXL345_REG_OFS_AXIS(chan->address), val / 4); case IIO_CHAN_INFO_SAMP_FREQ: n = div_s64(val * NANOHZ_PER_HZ + val2, ADXL345_BASE_RATE_NANO_HZ); - return regmap_update_bits(data->regmap, ADXL345_REG_BW_RATE, + return regmap_update_bits(st->regmap, ADXL345_REG_BW_RATE, ADXL345_BW_RATE, clamp_val(ilog2(n), 0, ADXL345_BW_RATE)); @@ -181,7 +181,7 @@ static void adxl345_powerdown(void *regmap) int adxl345_core_probe(struct device *dev, struct regmap *regmap, int (*setup)(struct device*, struct regmap*)) { - struct adxl345_data *data; + struct adxl345_data *st; struct iio_dev *indio_dev; u32 regval; unsigned int data_format_mask = (ADXL345_DATA_FORMAT_RANGE | @@ -190,17 +190,17 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, ADXL345_DATA_FORMAT_SELF_TEST); int ret; - indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); + indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); if (!indio_dev) return -ENOMEM; - data = iio_priv(indio_dev); - data->regmap = regmap; - data->info = device_get_match_data(dev); - if (!data->info) + st = iio_priv(indio_dev); + st->regmap = regmap; + st->info = device_get_match_data(dev); + if (!st->info) return -ENODEV; - indio_dev->name = data->info->name; + indio_dev->name = st->info->name; indio_dev->info = &adxl345_info; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->channels = adxl345_channels; @@ -208,12 +208,12 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, if (setup) { /* Perform optional initial bus specific configuration */ - ret = setup(dev, data->regmap); + ret = setup(dev, st->regmap); if (ret) return ret; /* Enable full-resolution mode */ - ret = regmap_update_bits(data->regmap, ADXL345_REG_DATA_FORMAT, + ret = regmap_update_bits(st->regmap, ADXL345_REG_DATA_FORMAT, data_format_mask, ADXL345_DATA_FORMAT_FULL_RES); if (ret) @@ -222,14 +222,14 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, } else { /* Enable full-resolution mode (init all data_format bits) */ - ret = regmap_write(data->regmap, ADXL345_REG_DATA_FORMAT, + ret = regmap_write(st->regmap, ADXL345_REG_DATA_FORMAT, ADXL345_DATA_FORMAT_FULL_RES); if (ret) return dev_err_probe(dev, ret, "Failed to set data range\n"); } - ret = regmap_read(data->regmap, ADXL345_REG_DEVID, ®val); + ret = regmap_read(st->regmap, ADXL345_REG_DEVID, ®val); if (ret < 0) return dev_err_probe(dev, ret, "Error reading device ID\n"); @@ -238,11 +238,11 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, regval, ADXL345_DEVID); /* Enable measurement mode */ - ret = adxl345_powerup(data->regmap); + ret = adxl345_powerup(st->regmap); if (ret < 0) return dev_err_probe(dev, ret, "Failed to enable measurement mode\n"); - ret = devm_add_action_or_reset(dev, adxl345_powerdown, data->regmap); + ret = devm_add_action_or_reset(dev, adxl345_powerdown, st->regmap); if (ret < 0) return ret; From patchwork Sun Nov 17 18:26:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13877883 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E63A11DB548; Sun, 17 Nov 2024 18:28:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868100; cv=none; b=bEQuFl+ld0Zd2vn9pLQDvUOM8sZm/8vo1W6Thg3kpw9EvsSXei7qSTO9k4jJnKtVeMzwQog22p6zHewfzXyvFa5EI9KQhrDdyPDSOYagaISipg9T+OL/NcBii5/Dap3cQRBaPXMrYvRaLt9/cDolxyLgk50ppTskagENNUkjfYM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868100; c=relaxed/simple; bh=M7AmXApmuf6gfTw5V6gmYwXfmU2w2K7nTpX7mMO5UBA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Lxg/9rFDQwsZTLhOgmnO3ZI8hWKq/AHcBQMCB34i2yfJR2TTa4KuUSO9jmSz+o2nf25KEabKNz6BVT1KOC6TN7lMd2bQivU9h+EidX1g6BCxhRb60xU5NR97g0bmro8jdje6dcrH0Df3fSECmloLFEk/42VWK4a1QGzuu3u0vFU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fUHXYuXp; arc=none smtp.client-ip=209.85.221.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fUHXYuXp" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-38235ecd7b4so70984f8f.0; Sun, 17 Nov 2024 10:28:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731868097; x=1732472897; 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=w3LwylrLeCnvqkOwJ5T67HbtRloWHBNMvqG4QkO2RiE=; b=fUHXYuXpVGZ2tLgrgs33dAIP3EKC9TUiPOcaEg0KOmpI6agj574VWj9jlkZvVpQABZ nPYS0mCc0+7Tw7ASTgDLlO/yE1NCUQieSyXd2DQyW9xOpTPi3swgeyK76xgwPxuRKw+4 PB4NXeKAb+pCWUcKFFMH4MwPp/fL6yCVviW7K87KOUvPmRKwjSU6VjQK9yIoCKHeSUq3 /Yc0aAwDkroyhgEOYTjJL+kEazsqcKszkAMCNEJ7Jx36SGZSILb2sFtSgabxfw1ivRKB 0sr/juml72kISF767wkYn9m/LHtSRjqNYJU0aeGC529nswqDRF+xFmjvaWc2IkUlXopx Mchg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731868097; x=1732472897; 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=w3LwylrLeCnvqkOwJ5T67HbtRloWHBNMvqG4QkO2RiE=; b=PIbM9qVj52psEejDWUHaALNHTNI4Wv5csakOtV26e0mvls3gcgVEH9l8V2gWrZD+bL klu9FOGHTG7ZPTmFEZIztT/fNhPtv73jdfEgfdP4zOIwdrnwQBJ9RA8aJ3Zj5CAZr3yy x5sSPEVNshmPatD5ggqbHOAk/nntBjue9BPwrynVdpENSDOmpTuHMpTFgxTUkpHf9Tfc TAfA+CkXWuf4KmUNBSCI4Eej+yQsQfehpovKjl+CY/PObGtAaQ+8rb/pd6O3nJXwQDxz 44p/gUaj5UTRibnutE5p10i9E2xRD5gGwVeI4C/o0ltqcHBabYE3iiVEDKxmvyj/vWc8 i5QA== X-Forwarded-Encrypted: i=1; AJvYcCXOSNiL8jFytmDYsMNsqKIIh78g1Po2lOZhWceLzrEaUGZ6zQeyno/bqkeXAdA9ZSezRkGPDfXhcgQWUNs=@vger.kernel.org X-Gm-Message-State: AOJu0Yxwg8Mq5kPo88rh6dZT12fN6ho+dGvdpJ1lWn56yWpCdEhxTvuR 96BZ784wX7aTz+QpSDBbrw9m2w32V8WAzmVRDGBSORjVJ+FP745L X-Google-Smtp-Source: AGHT+IHUC+id2XwEiadB8CxQIGE2A3DL8ax031c8GiDxZJW6sSHu2nnWbkIAljdtM5IPwryw9ju+Dg== X-Received: by 2002:a5d:59af:0:b0:382:4300:34d2 with SMTP id ffacd0b85a97d-3824300707cmr578426f8f.5.1731868097090; Sun, 17 Nov 2024 10:28:17 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3823f72441bsm3028137f8f.101.2024.11.17.10.28.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Nov 2024 10:28:16 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v2 03/22] iio: accel: adxl345: rename struct adxl34x_state Date: Sun, 17 Nov 2024 18:26:32 +0000 Message-Id: <20241117182651.115056-4-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241117182651.115056-1-l.rubusch@gmail.com> References: <20241117182651.115056-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Rename the struct "adxl345_data" to "adxl34x_state". First, the data structure is supposed to be extended to represent state rather than only hold sensor data. The data will be a separate member pointer. Second, the driver not only covers the adxl345 accelerometer, it also supports the adxl345, adxl346 and adxl375. Thus "adxl34x_" is a choice for a common prefix. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 3fb7a7b1b7..30896555a4 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -17,7 +17,7 @@ #include "adxl345.h" -struct adxl345_data { +struct adxl34x_state { const struct adxl345_chip_info *info; struct regmap *regmap; }; @@ -43,7 +43,7 @@ static int adxl345_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { - struct adxl345_data *st = iio_priv(indio_dev); + struct adxl34x_state *st = iio_priv(indio_dev); __le16 accel; long long samp_freq_nhz; unsigned int regval; @@ -99,7 +99,7 @@ static int adxl345_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask) { - struct adxl345_data *st = iio_priv(indio_dev); + struct adxl34x_state *st = iio_priv(indio_dev); s64 n; switch (mask) { @@ -181,7 +181,7 @@ static void adxl345_powerdown(void *regmap) int adxl345_core_probe(struct device *dev, struct regmap *regmap, int (*setup)(struct device*, struct regmap*)) { - struct adxl345_data *st; + struct adxl34x_state *st; struct iio_dev *indio_dev; u32 regval; unsigned int data_format_mask = (ADXL345_DATA_FORMAT_RANGE | From patchwork Sun Nov 17 18:26:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13877884 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B2971DBB3A; Sun, 17 Nov 2024 18:28:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868102; cv=none; b=pmrGYJbOoTqea8ZOsj2dV5zaAtQHoeEvhZ0YJko5hrSOq349tkC2ccJaCfzQ0fdGc9AiW7or+8QeQhWO2TDy5e51wD78MB92rXH+7dK4u1PqYr8Enwmjm9FNPVPXF7eIyXvjp+rLj9t88XBur3oWdKiM1e4Ikp3OEy+qWj9tPXs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868102; c=relaxed/simple; bh=3g8EJa9v3KFQJgxIp7akK5FmRLEB6X6D1rMGZs8BgCE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rhtbK7WkG+FWQV22ybMBDQz0+bp2pre2HLZ9xuH9FHM/pJo+S18/3+2hNG4wBKxix2QCUc89WKjIM7P2uBt2H6iN2GgYjJWzsF2iRiPVT+AmxEEptz2YW6KlLKIxitcZWr7H4jlFd9b7hiTlD1j0M0qf6ouQR91YMZ9iU8PVuJE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KIHIso4D; arc=none smtp.client-ip=209.85.221.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KIHIso4D" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-3824430afbeso58147f8f.0; Sun, 17 Nov 2024 10:28:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731868099; x=1732472899; 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=O6zP1PdamDLyXOAG7+hHqQLojtOTjSGamcL0fsR/t5E=; b=KIHIso4Dl5mVmCwLabgcfDdV3p93gdLyBaO8q2K+f0BswcVryhOtKE7XQPSqV/s7H1 J6UC7lii5EwsooziBF+18QZgkW11Tm1djyZ0Nhv3iHsVs5AYTOu/CFPI/sRTq/5bv/Hc bDFc8DQKawago26F5ga5JaEB990INSxVreXRg7LgzFqbzdWNhl9LX4zLBq/Iu9qNMYCA Dzj/NEuzfwAWsGcU2hE14LwBfOW51ZmdmDc3ZAJiOHHodLo/kXhWjDG6QijVFqce/hGi O/dp6t5cx0qBjWYfOi1Rti8LwYjWnhUUXlKNS4kVb6wDFn/2xr2VO9jfIVtSLXnlbDo/ 4/Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731868099; x=1732472899; 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=O6zP1PdamDLyXOAG7+hHqQLojtOTjSGamcL0fsR/t5E=; b=iltFsBLPlj8usyoedtRh7MsKUvz9hv+0og8qFWu7rUqoG3HgyqzMkvU0nhGThsshkG 28dawU8qRtahWkihWfd/cxjBYasnkTLQEp4jnTADY3QwZbRRtaqQDwdlZA4/4Ov+IYD6 5pC8TFK2eWVC/kAcZEvOzLCKmLMPhE6jnKi7+xCgWa9+e7IYsv/rTrxiRKD9+ShBMcZv x+M46K9bTObxRIYQxNjTfSOKmMW+Y0w9zzjW0bK7t1r1JG9ShPhb27g6F3gCzwVE1vOY O0+ilAbiNJD6YmldDw3PZhKijRX1DHCY1b97HXte/ZQp3NqH+iCJk9/sWspL2zKmqWe5 TXSw== X-Forwarded-Encrypted: i=1; AJvYcCX5+3G6jeR6aI6WgAeTEDGu1ZJjaA2ovIl+JVAve4LPoKYlU5RwiTGgGf64nskt2ISoooorPaZdMMUe8TQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzmCYsAhqYhX75WGeyl6wOjAzqc+LQ3M0VjsiotB0EXwqyUNIOD ODyA8ePVKSGZsaXwm5d/Ry2Bjzek6GCp/ZZGK3RCM7BoUyhruo18 X-Google-Smtp-Source: AGHT+IEUX8Mud1MCrISvzI8R5Hgm7Um+vAbFPgPYMOGMEjM0bmqIVKaDPZpgBjf4rMj7wjni65oUOg== X-Received: by 2002:a5d:5f4b:0:b0:37c:d0d6:ab1a with SMTP id ffacd0b85a97d-38225a92b39mr3254225f8f.12.1731868098753; Sun, 17 Nov 2024 10:28:18 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3823f72441bsm3028137f8f.101.2024.11.17.10.28.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Nov 2024 10:28:17 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v2 04/22] iio: accel: adxl345: rename to adxl34x_channels Date: Sun, 17 Nov 2024 18:26:33 +0000 Message-Id: <20241117182651.115056-5-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241117182651.115056-1-l.rubusch@gmail.com> References: <20241117182651.115056-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Rename the "adxl345_channels" to "adxl34x_channels". The driver supports several Analog accelerometers equally, e.g. adxl346 and adxl375. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 30896555a4..2b62e79248 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -33,7 +33,7 @@ struct adxl34x_state { BIT(IIO_CHAN_INFO_SAMP_FREQ), \ } -static const struct iio_chan_spec adxl345_channels[] = { +static const struct iio_chan_spec adxl34x_channels[] = { ADXL345_CHANNEL(0, X), ADXL345_CHANNEL(1, Y), ADXL345_CHANNEL(2, Z), @@ -203,8 +203,8 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, indio_dev->name = st->info->name; indio_dev->info = &adxl345_info; indio_dev->modes = INDIO_DIRECT_MODE; - indio_dev->channels = adxl345_channels; - indio_dev->num_channels = ARRAY_SIZE(adxl345_channels); + indio_dev->channels = adxl34x_channels; + indio_dev->num_channels = ARRAY_SIZE(adxl34x_channels); if (setup) { /* Perform optional initial bus specific configuration */ From patchwork Sun Nov 17 18:26:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13877885 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.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 8B8BD1DC198; Sun, 17 Nov 2024 18:28:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868103; cv=none; b=P1NzzvDAn1/XSgXmejPaGUlB/2nBU0I+MbfHrXGjHo5haR8ufBmTvGKBZ7/FiUF2WVUy/qA+8ucB1SjyWHl2hkKWua1CsSAxWIJ//8S5Nyw9sIKeBhfhWlFFKZYHuTqCz5kBAkotwfXLAKnOvJqXn3FiUX2M8sd4MCVylkaEIqk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868103; c=relaxed/simple; bh=sCjWcbEyD7LriiRtOAzp80ukkSkCm2A8Q8W2wmqD4rc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Y7Ga7Mf7GTksLjxhl/MJDzFOiV8GneY+gsS5qj6QH4LyIyNefRXfJK+PzyDrzlgpVzVd5i4A6aGLODmduqWKVvJ8V2u5hlkTcVb3+l9zcrOphScbX6ceTaHh84gurqZId1Xa/syNzJsp5au/4uSI+JbGwCLC3H6f8u+aSDTFiG4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gpsUFiXK; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gpsUFiXK" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4315b957ae8so1868095e9.1; Sun, 17 Nov 2024 10:28:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731868100; x=1732472900; 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=JuMbsXp1aimZf7eMQWmAB0t6+KXECwYUsZhziywkPVU=; b=gpsUFiXK3Sdo8J8anK5+pCTb64QGL2SakQkf3yRi+qFCLSdqO3AZuZ9a+kjJI7frRD eacVRf2HXZBIw9a0peSycmmWvQ1UrSHifxAE/va9S4/1UDMLhMtabHMFpZfSy3ixH8IE fffcXhV9FdIppE+eWFZka701j/lNGHTJjpv+b7/Io0neLMLRBKGBEroU1Zac4UMyMbLg X8K5eBwVlRS4UalwLuvnp1lmhyshszSjgsV6pptZQmwLel7/TnGJTiHyM3BzH9jDaMnR EooWDUkH+Ci8i/2XWPDfcOr91IsN7uZ0a/K5M1YP26kh+3VxVwdRf2fyk7G3RlPAgcCx MWRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731868100; x=1732472900; 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=JuMbsXp1aimZf7eMQWmAB0t6+KXECwYUsZhziywkPVU=; b=SOGyy64vWzQheo64YYzCeTgqAKKbuGe93A7NUd9LNMwJbOfqniY6GKKm78BYc3g8yI +3gRqT0kxf+6r51YotNocN/ODETEaNE2HwXPG6FdOOom5uLn8lMRO0KXR/iBCJxDODU3 +rFOgu4BxXMwxARliTgAUgj7RZF+PdtPOMbW8IGzAG9x5bVz4wrbLgjW4D4mqVqcIwFC d6X18OSbtQ0VYMp5zB8H/VmAtYAH4jX1+54l0MXT20FhcGa0jsKDVsjhNcIfJc/qjXcO BYjaJQQqYyOGh5K/mEEFi4cCqqSKbavwM6ndRVha3PFdBLTB0xXjZTqQm0H7KK6MWS9x cFjA== X-Forwarded-Encrypted: i=1; AJvYcCVGMl6/Tqo5Qc5Yg1M3rDBiPdtDSmZdI5jY5IT1InKIJqsau90221kIGOjdCbI776PAE2I/Q0K//Dy82nk=@vger.kernel.org X-Gm-Message-State: AOJu0Yy1LoLmi7FiZi+VdJjmhTHodX8p40TEnCKt+Retewriza0qFqbV rwvxAQRyS1Ml08fCI7IWiztKcCi792yKx++SVzAZxYBl99eAFlsH X-Google-Smtp-Source: AGHT+IFrXlcEfnDyLN/DAOYLUuRIvqP2BsiP0sUcBuIMY8pAFMAxclH/PGeSWt2e+t3CSziG2fst4A== X-Received: by 2002:a05:6000:400b:b0:382:4538:c0d with SMTP id ffacd0b85a97d-38245380e2bmr506027f8f.2.1731868099749; Sun, 17 Nov 2024 10:28:19 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3823f72441bsm3028137f8f.101.2024.11.17.10.28.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Nov 2024 10:28:19 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v2 05/22] iio: accel: adxl345: measure right-justified Date: Sun, 17 Nov 2024 18:26:34 +0000 Message-Id: <20241117182651.115056-6-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241117182651.115056-1-l.rubusch@gmail.com> References: <20241117182651.115056-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Make measurements right-justified, since it is the default for the driver and sensor. By not setting the ADXL345_DATA_FORMAT_JUSTIFY bit, the data becomes right-judstified. This was the original setting, there is no reason to change it to left-justified, where right-justified simplifies working on the registers. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 2b62e79248..926e397678 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -184,8 +184,13 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, struct adxl34x_state *st; struct iio_dev *indio_dev; u32 regval; + + /* NB: ADXL345_DATA_FORMAT_JUSTIFY or 0: + * do right-justified: 0, then adjust resolution according to 10-bit + * through 13-bit in channel - this is the default behavior, and can + * be modified here by oring ADXL345_DATA_FORMAT_JUSTIFY + */ unsigned int data_format_mask = (ADXL345_DATA_FORMAT_RANGE | - ADXL345_DATA_FORMAT_JUSTIFY | ADXL345_DATA_FORMAT_FULL_RES | ADXL345_DATA_FORMAT_SELF_TEST); int ret; From patchwork Sun Nov 17 18:26:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13877886 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.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 879A21DC749; Sun, 17 Nov 2024 18:28:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868104; cv=none; b=XxlqfOEsIPnNnEZrJA+o3F+sBD89npXCLLCdiF9bTU7wAcKUjv7TKr0JqBb72lQs/EFA2Mbp1SjyNCh3WlXTVKne2EKGo4gHJZfXN2scU9lbdJh3lmFo8tk5eaHC+X2RunbT5gAvkg3RYBuGnpNa4dITJSsrebtF3pKMLDuJdfg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868104; c=relaxed/simple; bh=4r1cVkYdRT9ZfGiUI9fHGkVIlyLVh+osJxxDLNbbpVY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FfTPJ4hSNJsFBpuLMA0zVl3YNgl0e3Ty1/dKpbD8jUStNHabW+fzJ24auu7wpYh5lnLSUUSVqW/fjyi7fbUG9e5rW/fwg1DZ3BSurLNhz9MoD7nFyMgUkacfyQlmPPu0mEYeH3uRSCX10QXdIj+DOm3qB7yyy2alILLYLOM9388= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XUJnB7eE; arc=none smtp.client-ip=209.85.221.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XUJnB7eE" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-3823ef92bd0so73305f8f.2; Sun, 17 Nov 2024 10:28:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731868101; x=1732472901; 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=PPnUNq9UPYs83FPZhXy9S6/EzgNticedB2U5cxlHgYU=; b=XUJnB7eE+VCanka8OhAIJXYjQkaEZiJvcKM8c55l6TUbJJC/+8pCYAKTouY8W4STvp pT17JZ//i/HA5xWUt1cJX4mb9PsJhRKtI8Ce2171E+fgLOFlYwvl7KcIxJG46Pe0SKLe 1LtEF9QXtwqQz+n7nbqKTEJyxrLJovD0aVKOSOWUxUGhQcR+JF+QTeRB+/yLg7uKvnbE pVXU0QhxYT1kmmH16kQ6NPzJKLb39S+jVRQ0+g+4TpBxwR0dQugNAbbzW7RAZdh5IQIy +EZ5pgKRUwavn+M25s7o9knFfNbl0krBdqfyzl2JermF5KnGYlwipMYzFG6Z8zrKA+pq kHuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731868101; x=1732472901; 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=PPnUNq9UPYs83FPZhXy9S6/EzgNticedB2U5cxlHgYU=; b=RzrLl7AJ8s0TclQCogInPCDxfJmKUUS+jhGln92sUfaNZsgDfeXjhjbPNWbPf7LM4M eXRqOUE1LpMCK4+9oUCOaMR2cxjW2L+Kt4sOTgYhlbg+OqozwLb3MovZ7/Xf4VdY5iPt WuNlTlrT3P/EO0EvHN2qpoHsGTl04LXzDJxq5r7bZPKknGSCEY7/K6h75rAjenVARL/X MHwAED2x5IZaemkBEfzV56Trs8nxsdhGIBmz2GY5ClT9JgVayv+V5vDi8rREZ3ScTxFE 7FSGwY4lENueO9L5CP+yDpymXIJgIwBue0sPclyYVVZ8nQXECaOTH4syeLoVwewEGEbE sc6w== X-Forwarded-Encrypted: i=1; AJvYcCV34POV1Pm1I/mTE42K045KTNPEWem3c+o2nQ74TwyN9IQelVp9+Y+GoyMXIjKa0s3zvqs8pVNQcZBoa9k=@vger.kernel.org X-Gm-Message-State: AOJu0YzNl3pOf4RQjpaHmjFwFxOflZ1D8STZmVxO8PZVfzhmLfNcfdhq dbslM/3I91pcd4DFGQLSvDRAsGLwDeFy9q53EZXfDromIH06nwaA X-Gm-Gg: ASbGncvzrDJUnx+IhXzU3vpbjq6uvIP9evrNAcvcQwupEe/OhswPWo/tO7HWb8xNfIc jv+cEW26/0IkZtT1bwLi2Esb5pnke5CI1A818NCKVbYdx61jVefLILmvPqyvE0tf+1J83qnD1O2 BY3tCbzrggxeMTcw9M8NQfx0LgisPtVwkNSNMZGLveG6woa6TupNFkXaL2kUTJcMWnNyPdlt5Kk vXrdTqVCYNUfcX7a8huDZtknTKZbGjJKmeY3qXtBTGPWldnQbWjKg977haaE1eUSoqK+ZiV74G5 7T6nAtA8LmhjKMBCNU1/Wvigeuhe X-Google-Smtp-Source: AGHT+IE0aApcftU5GYHT8HfUFdCRHqXn8jqBx0A+4xGFI6fKxnFqpLfCljv8kWP7MYfXTwu4nmIuWw== X-Received: by 2002:a05:600c:1c29:b0:42c:aeee:80a with SMTP id 5b1f17b1804b1-432df791c54mr36031325e9.7.1731868100706; Sun, 17 Nov 2024 10:28:20 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3823f72441bsm3028137f8f.101.2024.11.17.10.28.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Nov 2024 10:28:20 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v2 06/22] iio: accel: adxl345: add function to switch measuring Date: Sun, 17 Nov 2024 18:26:35 +0000 Message-Id: <20241117182651.115056-7-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241117182651.115056-1-l.rubusch@gmail.com> References: <20241117182651.115056-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replace the powerup / powerdown functions by a generic function to put the sensor in STANDBY, or MEASURE mode. This is needed for several features of the accelerometer. It allows to change e.g. FIFO settings. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 53 ++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 926e397678..81688a9eaf 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -138,6 +138,39 @@ static int adxl345_write_raw_get_fmt(struct iio_dev *indio_dev, } } +/** + * adxl345_set_measure_en() - Enable and disable measuring. + * + * @st: The device data. + * @en: Enable measurements, else standby mode. + * + * For lowest power operation, standby mode can be used. In standby mode, + * current consumption is supposed to be reduced to 0.1uA (typical). In this + * mode no measurements are made. Placing the device into standby mode + * preserves the contents of FIFO. + * + * Return: Returns 0 if successful, or a negative error value. + */ +static int adxl345_set_measure_en(struct adxl34x_state *st, bool en) +{ + unsigned int val = 0; + int ret; + + val = (en) ? ADXL345_POWER_CTL_MEASURE : ADXL345_POWER_CTL_STANDBY; + ret = regmap_write(st->regmap, ADXL345_REG_POWER_CTL, val); + if (ret) + return -EINVAL; + + return 0; +} + +static void adxl345_powerdown(void *ptr) +{ + struct adxl34x_state *st = ptr; + + adxl345_set_measure_en(st, false); +} + static IIO_CONST_ATTR_SAMP_FREQ_AVAIL( "0.09765625 0.1953125 0.390625 0.78125 1.5625 3.125 6.25 12.5 25 50 100 200 400 800 1600 3200" ); @@ -158,16 +191,6 @@ static const struct iio_info adxl345_info = { .write_raw_get_fmt = adxl345_write_raw_get_fmt, }; -static int adxl345_powerup(void *regmap) -{ - return regmap_write(regmap, ADXL345_REG_POWER_CTL, ADXL345_POWER_CTL_MEASURE); -} - -static void adxl345_powerdown(void *regmap) -{ - regmap_write(regmap, ADXL345_REG_POWER_CTL, ADXL345_POWER_CTL_STANDBY); -} - /** * adxl345_core_probe() - probe and setup for the adxl345 accelerometer, * also covers the adxl375 and adxl346 accelerometer @@ -242,14 +265,12 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, return dev_err_probe(dev, -ENODEV, "Invalid device ID: %x, expected %x\n", regval, ADXL345_DEVID); - /* Enable measurement mode */ - ret = adxl345_powerup(st->regmap); + ret = devm_add_action_or_reset(dev, adxl345_powerdown, st); if (ret < 0) - return dev_err_probe(dev, ret, "Failed to enable measurement mode\n"); + return dev_err_probe(dev, ret, "Failed to add action or reset\n"); - ret = devm_add_action_or_reset(dev, adxl345_powerdown, st->regmap); - if (ret < 0) - return ret; + /* Enable measurement mode */ + adxl345_set_measure_en(st, true); return devm_iio_device_register(dev, indio_dev); } From patchwork Sun Nov 17 18:26:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13877887 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 809EC1DD0C6; Sun, 17 Nov 2024 18:28:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868105; cv=none; b=hd8CH9HQvRiBNGR6wd1ozh/1dQWtVncz9FaiZN9uvZoNwK8yDGojox7bFpnLJPG5Gme9uX5sTXZ4cw6CUmn7zUjw/tq2Gz6lgfoeas2F8lpqWXm2XXCPJ5FQORrtj1zwL9PZn5VYK9XaBbryguobse/cGjHPWnlYLkPmkLinqi8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868105; c=relaxed/simple; bh=Cd2tBZUuICf5FU5hTwdZ9b6RrklaSTv0sQOo6W4hS28=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OfJ+hjTVRude/KOXK7vTg+SbUTqO3TDVd14p9D9X828YrnOCgcBDN0/fZdmkAcwtR6YtvsnX1DR/5G7NQZMeQI05Nue1aWqPpvUMGVXRRVhmerFbCchVUDygaX7B89A7ajpLlslCzwJec7a4hKM55UsJWI+3vyW5KmRd0J+Kze0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aCGlbxWI; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aCGlbxWI" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-43159469053so1867395e9.2; Sun, 17 Nov 2024 10:28:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731868102; x=1732472902; 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=2KDSOkAKN9bBRfuUJxFrsniHWtfVPCBalN3GkkFmvHU=; b=aCGlbxWIff6o47n9D8jrg5oRkBwSorKg/rFMwr60O6uLHrSosVspuyrBa6mGhKIN9J GDxwXv1nLeYSl/hFrmzZ9vptMC9E6S7kN9bcfhAbT1PWpMk9rBDOZJAuztmAlajO+J8U HkOEucldiM2LDuxZu585xKVLaxdbVRR9k65oBk4jCfaDF9Cw2KhAT+YeivYRvv811tOH uYzzyzmPCED35aQf8i2DBMe0d0/YP3swv9R0ZivT+BruBq8HPz/glvwrcA1Go6pGcZxq GPA7BPhab8cxXORhxkVDxAHVvp9Qjh6rIRgwcp38LYp74R3vMnIS3YVCpV//B+NWohP5 0++g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731868102; x=1732472902; 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=2KDSOkAKN9bBRfuUJxFrsniHWtfVPCBalN3GkkFmvHU=; b=WCGioxBbomKqVyUZKRrzQe+osKy5YNF0aF9fsoQD732TmSu5jt1jNTMGMDGfsIUiaF r8JMJs0P0oYuIF+pXVy/xE/OPgB/6bP5bi/51kFC1CFW9Q5n81MOQMmldxHAd1SWFNgt UjZvgPrgRQvsCmNZdpIH0ygdzD5imk1BaKZF2IdLdi+rp3PRusNCMIPQ+BI1h6XzFVwE q8DvBb50RDirXSdMWb74vVic9mDDqAfzdfaP8d95Tdev4FyEj0PDJ4sXVy6xbdgeCEun p0pZeEXlrDMcNDlWjSO6qRnIfsdhtvghUQa0UTik9pxLmcLljhrA6Wq2EfZdkrQTMrcE iKWw== X-Forwarded-Encrypted: i=1; AJvYcCVqOr9TdjYk+uBnekP8JmUy151ABeYNih2Wd6kKmA4r/T8johz/zRv1cgYbKAlss0KThSs/pCT3S5vCkHQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzaLsWA90vPdAQDLCbS8NJAIPFz8cdKqFlNRnZLZ099BRQRbg+Y rtEH+ngxFhrA6T+JyQLnkrlCFrq/alw+ZK/N/HKvj94vfWPo1BSQ X-Google-Smtp-Source: AGHT+IHl2ZvOA71B3I+0fttI5e/0p7cmfj8FDx0YnNMQ+reLKTgTiipO6jeV9z3JbDW1Nn4wpfJZVA== X-Received: by 2002:a05:600c:4710:b0:431:558c:d9e9 with SMTP id 5b1f17b1804b1-432df78ac1bmr35727395e9.5.1731868101646; Sun, 17 Nov 2024 10:28:21 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3823f72441bsm3028137f8f.101.2024.11.17.10.28.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Nov 2024 10:28:21 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v2 07/22] iio: accel: adxl345: initialize IRQ number Date: Sun, 17 Nov 2024 18:26:36 +0000 Message-Id: <20241117182651.115056-8-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241117182651.115056-1-l.rubusch@gmail.com> References: <20241117182651.115056-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add the possibility to claim an interrupt and init the state structure with interrupt number and interrupt line to use. The adxl345 can use two different interrupt lines, mainly to signal FIFO watermark events, single or double tap, activity, etc. Hence, having the interrupt line available is crucial to implement such features. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345.h | 1 + drivers/iio/accel/adxl345_core.c | 6 ++++++ drivers/iio/accel/adxl345_i2c.c | 2 +- drivers/iio/accel/adxl345_spi.c | 8 ++++++-- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/iio/accel/adxl345.h b/drivers/iio/accel/adxl345.h index 3d5c8719db..cf4132715c 100644 --- a/drivers/iio/accel/adxl345.h +++ b/drivers/iio/accel/adxl345.h @@ -62,6 +62,7 @@ struct adxl345_chip_info { }; int adxl345_core_probe(struct device *dev, struct regmap *regmap, + int irq, int (*setup)(struct device*, struct regmap*)); #endif /* _ADXL345_H_ */ diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 81688a9eaf..902bd3568b 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -18,6 +19,7 @@ #include "adxl345.h" struct adxl34x_state { + int irq; const struct adxl345_chip_info *info; struct regmap *regmap; }; @@ -196,12 +198,14 @@ static const struct iio_info adxl345_info = { * also covers the adxl375 and adxl346 accelerometer * @dev: Driver model representation of the device * @regmap: Regmap instance for the device + * @irq: Interrupt handling for async usage * @setup: Setup routine to be executed right before the standard device * setup * * Return: 0 on success, negative errno on error */ int adxl345_core_probe(struct device *dev, struct regmap *regmap, + int irq, int (*setup)(struct device*, struct regmap*)) { struct adxl34x_state *st; @@ -224,6 +228,8 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, st = iio_priv(indio_dev); st->regmap = regmap; + + st->irq = irq; st->info = device_get_match_data(dev); if (!st->info) return -ENODEV; diff --git a/drivers/iio/accel/adxl345_i2c.c b/drivers/iio/accel/adxl345_i2c.c index 4065b8f7c8..604b706c29 100644 --- a/drivers/iio/accel/adxl345_i2c.c +++ b/drivers/iio/accel/adxl345_i2c.c @@ -27,7 +27,7 @@ static int adxl345_i2c_probe(struct i2c_client *client) if (IS_ERR(regmap)) return dev_err_probe(&client->dev, PTR_ERR(regmap), "Error initializing regmap\n"); - return adxl345_core_probe(&client->dev, regmap, NULL); + return adxl345_core_probe(&client->dev, regmap, client->irq, NULL); } static const struct adxl345_chip_info adxl345_i2c_info = { diff --git a/drivers/iio/accel/adxl345_spi.c b/drivers/iio/accel/adxl345_spi.c index 61fd9a6f5f..39e7d71e1d 100644 --- a/drivers/iio/accel/adxl345_spi.c +++ b/drivers/iio/accel/adxl345_spi.c @@ -39,9 +39,13 @@ static int adxl345_spi_probe(struct spi_device *spi) return dev_err_probe(&spi->dev, PTR_ERR(regmap), "Error initializing regmap\n"); if (spi->mode & SPI_3WIRE) - return adxl345_core_probe(&spi->dev, regmap, adxl345_spi_setup); + return adxl345_core_probe(&spi->dev, regmap, + spi->irq, + adxl345_spi_setup); else - return adxl345_core_probe(&spi->dev, regmap, NULL); + return adxl345_core_probe(&spi->dev, regmap, + spi->irq, + NULL); } static const struct adxl345_chip_info adxl345_spi_info = { From patchwork Sun Nov 17 18:26:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13877888 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.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 138F21DA628; Sun, 17 Nov 2024 18:28:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868105; cv=none; b=Q/fzd7Pguuz9YWVsCcziX54dgKMR8nZFSGEd9AVUCa9DGzM3scoSVdj+rpTCtZ4GzvRSTvk9VMdKzgipui1/NEoTRi4LZkuUdS+CPq7hnwzfJRsLSvZQyUL4N13p5pzUNScYgmBdkktY48x6a4vkns3GYLyBfFlo3YzR/9fsL3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868105; c=relaxed/simple; bh=RPvfTp2cv2107R2RLYpfauTAm08ezaOfag6H6xQEl70=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=srB4E9iQH3txKxEiNAFWWjh4OtYybZ8gTAiz+oIRMlXYFmu82jipYFO87Ze6b7lGrTEgiTd7nP1NuhYxxtdBvqT84mGQab0ixfTKLFa4rBIgbxC046Qkj28t+yjS3GJ1s6GdoYaL39bkh6TylTRaIHQIlSKaDI9cRF//5gmIQuE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QCuEzZQG; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QCuEzZQG" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-43159469053so1867405e9.2; Sun, 17 Nov 2024 10:28:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731868102; x=1732472902; 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=QH8gYycQZ+3mi37d5ffBI3sVj1MCkPULMK4Fd22p4wI=; b=QCuEzZQGvk3V0wQKNg31ggp1R3i9Ic3FSQ4zQjoo0K7CX69a3jOqK8k9nVK10dR5eQ o+pmAmYkp76IsXdB1QUPNXIyfcyXRH1NiN3JWWeqvqB88DpVXEcBQrNeWR7HU58jUEv4 WvRLj5RkezoQTxcglwyK6gRaWvNibK1DLTsJyXr0HL+eBGlp/AlbrqLvf4iwkpAx9tMx NaXbaiEd+koBNPX7TTE2XeUmPhATc2QGaSfmS9C8MN9FnN2Y4vdzXYtCUV4T9C8e18nL TgP3eUkqo1gOGnTzMnLY6S/LM/Lb1l64SoLdPeNrDnYRoDPBwow+O5bT0ea5AaLck/sq KImQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731868102; x=1732472902; 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=QH8gYycQZ+3mi37d5ffBI3sVj1MCkPULMK4Fd22p4wI=; b=q+Y1GQ01Fdx8i4WqcDv+71Rl/IDrtVKF+eCJq1XmDY6v/M+4bS2eCcQe+sxEr43tXQ M4V/JETkm5AlhJpmt3othnMr/8JO7qCzBm66qgmefCyWNk16F11dXgVtVi3eSoWkvUzh bW6xe6hMgsPFolmuifn6sEt6akswZ94tdZQKB2kovqEVb//KRnhBqVa3zHSFeL/t2R65 Zl22Um7rKll3d8b2HoruEaUkOnCDro2xQcXS9FpYDigELUZ2n/NfsaNJfSv5cM8osBLs Y0B3mqNGoE1omt5yGtxmk2iDOn67u8Yvh0UGobE02Akpp22xSutooSgI0PmJRr5d7kgG belA== X-Forwarded-Encrypted: i=1; AJvYcCXGuZjioMyIcQ7os4G6yrWbFf9paZwnYz8W1M5E26VHS5cHrXbFw9P/xDpJ8/wiRhyeul1Fykd/n5sYhYE=@vger.kernel.org X-Gm-Message-State: AOJu0YxDTFSXFyQuTujZo/KUKTyE2P3vGgsTegaDyZjLmCU7gQlOkP7a xhPOL850PfQFwgiqsqJ1bdSr6E/c10gi37uOFBLeooU8BHiMQyAK X-Google-Smtp-Source: AGHT+IH8mE13aDycfKCqr3mPzQD8LmO8z2ZiHOFC14Lzgc5GTLbASRYC15+JjRmpk0zMJxR6OZqkoQ== X-Received: by 2002:a05:600c:1991:b0:42c:ba83:3efa with SMTP id 5b1f17b1804b1-432df6841femr35135495e9.0.1731868102450; Sun, 17 Nov 2024 10:28:22 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3823f72441bsm3028137f8f.101.2024.11.17.10.28.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Nov 2024 10:28:22 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v2 08/22] iio: accel: adxl345: initialize FIFO delay value for SPI Date: Sun, 17 Nov 2024 18:26:37 +0000 Message-Id: <20241117182651.115056-9-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241117182651.115056-1-l.rubusch@gmail.com> References: <20241117182651.115056-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add the possibility to delay FIFO access when SPI is used. According to the datasheet this is needed for the adxl345. When initialization happens over SPI the need for delay is to be signalized, and the delay will be used. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345.h | 2 +- drivers/iio/accel/adxl345_core.c | 6 +++++- drivers/iio/accel/adxl345_i2c.c | 2 +- drivers/iio/accel/adxl345_spi.c | 3 +++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/iio/accel/adxl345.h b/drivers/iio/accel/adxl345.h index cf4132715c..4ba493f636 100644 --- a/drivers/iio/accel/adxl345.h +++ b/drivers/iio/accel/adxl345.h @@ -62,7 +62,7 @@ struct adxl345_chip_info { }; int adxl345_core_probe(struct device *dev, struct regmap *regmap, - int irq, + int irq, bool fifo_delay_default, int (*setup)(struct device*, struct regmap*)); #endif /* _ADXL345_H_ */ diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 902bd3568b..51b229cc44 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -22,6 +22,7 @@ struct adxl34x_state { int irq; const struct adxl345_chip_info *info; struct regmap *regmap; + bool fifo_delay; /* delay: delay is needed for SPI */ }; #define ADXL345_CHANNEL(index, axis) { \ @@ -199,13 +200,14 @@ static const struct iio_info adxl345_info = { * @dev: Driver model representation of the device * @regmap: Regmap instance for the device * @irq: Interrupt handling for async usage + * @fifo_delay_default: Using FIFO with SPI needs delay * @setup: Setup routine to be executed right before the standard device * setup * * Return: 0 on success, negative errno on error */ int adxl345_core_probe(struct device *dev, struct regmap *regmap, - int irq, + int irq, bool fifo_delay_default, int (*setup)(struct device*, struct regmap*)) { struct adxl34x_state *st; @@ -234,6 +236,8 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, if (!st->info) return -ENODEV; + st->fifo_delay = fifo_delay_default; + indio_dev->name = st->info->name; indio_dev->info = &adxl345_info; indio_dev->modes = INDIO_DIRECT_MODE; diff --git a/drivers/iio/accel/adxl345_i2c.c b/drivers/iio/accel/adxl345_i2c.c index 604b706c29..fa1b7e7026 100644 --- a/drivers/iio/accel/adxl345_i2c.c +++ b/drivers/iio/accel/adxl345_i2c.c @@ -27,7 +27,7 @@ static int adxl345_i2c_probe(struct i2c_client *client) if (IS_ERR(regmap)) return dev_err_probe(&client->dev, PTR_ERR(regmap), "Error initializing regmap\n"); - return adxl345_core_probe(&client->dev, regmap, client->irq, NULL); + return adxl345_core_probe(&client->dev, regmap, client->irq, false, NULL); } static const struct adxl345_chip_info adxl345_i2c_info = { diff --git a/drivers/iio/accel/adxl345_spi.c b/drivers/iio/accel/adxl345_spi.c index 39e7d71e1d..75940d9c1c 100644 --- a/drivers/iio/accel/adxl345_spi.c +++ b/drivers/iio/accel/adxl345_spi.c @@ -12,6 +12,7 @@ #include "adxl345.h" #define ADXL345_MAX_SPI_FREQ_HZ 5000000 +#define ADXL345_MAX_FREQ_NO_FIFO_DELAY 1500000 static const struct regmap_config adxl345_spi_regmap_config = { .reg_bits = 8, @@ -41,10 +42,12 @@ static int adxl345_spi_probe(struct spi_device *spi) if (spi->mode & SPI_3WIRE) return adxl345_core_probe(&spi->dev, regmap, spi->irq, + spi->max_speed_hz > ADXL345_MAX_FREQ_NO_FIFO_DELAY, adxl345_spi_setup); else return adxl345_core_probe(&spi->dev, regmap, spi->irq, + spi->max_speed_hz > ADXL345_MAX_FREQ_NO_FIFO_DELAY, NULL); } From patchwork Sun Nov 17 18:26:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13877889 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C7CB1DD53A; Sun, 17 Nov 2024 18:28:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868108; cv=none; b=VdMCK4ROow/0JMXkbQ6+aOcOL37AVqsNNtkFoNdZdZZX8D6fbgRVkYvNEEWGZlKz0oJKTIIJWBzCBFFC2UGoPxFzra3yMWeQAVy4A1NQedD5RY5FrpBwCjG5qX/HrXhFZADodH6G/BWSVGNrilbJ3t/vbyBiN27AhcFTg4qGM3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868108; c=relaxed/simple; bh=aImB8JXuYGC75dQm5kamc9HRrsDYI8Xb9YEvJJAGpDc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PjdSlib1aMgPp2aD3f+srPZ5Tu/UX6hzJHgqzzL+ZWn7U79hhGA6rbXa4XkFwJpD3AAy6jY+CErevcUVw4Q7LqH+CXCicNzHpMQlOH2DLEwg1kiFVzN1EL+h1vZpfg/qu8NfeWC+EPa8HPoKP7/+ci8HIQy7UhPWdeLeaVnRxQM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fhLDPoEP; arc=none smtp.client-ip=209.85.221.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fhLDPoEP" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-3823ef92bd0so73308f8f.2; Sun, 17 Nov 2024 10:28:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731868104; x=1732472904; 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=5J2EkGurj9OleNaa6X1u3iol/6vzB1gcd9dALyM71LU=; b=fhLDPoEP+PBr6X4Gio9/EQrzS1a04FvwFPCPej96n+MhRrCwt0FwYrOCWCUVVZVQu3 g0Zn6tPixKrsBj05Y8Yxr/bSVN859p36F8ipwqsN3SlfsQeyXjnigjldesI8WDQdjMTB jCbnLxw+WZTFgTodhCfauZwyk87MB0cpR7b59KkqWq7RgvrQWNBVaDcJHkvqSGMHnAVH NeRX0dkwW2XZ+O3qyftWdCbL4Nu8WsPcZK1gTR0HpGGLbUnmjCNY45gV6BkuY0REen5Z j9U2olztXXBZw8BMKhRcFl+uFs6VmNUYmQeNbCuGNK0FxRy5jXIKhy4qi7MK7tI6Fo/X 8MAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731868104; x=1732472904; 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=5J2EkGurj9OleNaa6X1u3iol/6vzB1gcd9dALyM71LU=; b=u3wugT4i+A6aTZKChx5DMs4LZNtw4k02pr1vNYjd1OLdt9n6w0+0jlnd361SwWKFS+ kOGKcQB+/fEwdExJT6/78R4EtxJA9ly73LKs1jF/UUc5EXVnnUTRZVoO/mxmjqdU79L6 knMyoenM+AfmcoVlBGh9uqlFphsmfY88m0oRy6O5zFBIqEu9BHA6UkUanyqifhBQuGNJ r1g6kvoh86NSmKubKlsmfuwIth+xUY7KsaXLajBb5o9l7zNJfGmoagPW/j9uKG+4y51T wdpVnSsDeFfvTjWX8EQlG1IKTeipTmfoRYd21ZCittwSnIweGgPneHSr6ViMm+uEJjTm b/2g== X-Forwarded-Encrypted: i=1; AJvYcCUjjDTfA7XSHOSwNCoP5Vrhl0ffJzUK6pLkVHuC4tZyW9Mfovd1BvuoRwQXtjLiA11P3KQ+BBYlIzLSLO0=@vger.kernel.org X-Gm-Message-State: AOJu0Yxl1Yo5lu6rr9nOQR9RwMAgjyr9h+oVwvohcvmfpfolNx8Pka+Q HAYBHmXtiVyLQ7gvQC0Oy+dg6hHFYWvDPqcOw9p/RjSeg2YqMxj9JhBLmtXp X-Gm-Gg: ASbGncvmY0oNYZ3F/OXXX/xcznIEKzwoTzEu5u0z4l33KA2UDU86yq4j8Z7/ivyoeLf 4UATMLGyFuqRxI8kD18IBxQkrwS112otVYHsu9NZJyCcxkanimXKEyNT4+C7GjHf4jwgnYbjYf9 f6N6/chQ12KV32e+t4i4CijnXfSh8NS6XAwtY0sHHepmRoPBcCxy5jH5eMkze+WFtYYvmpuqX/D zXab4bfjNQ5URIritBicHtmBLP4554pBhdohn1WHIraDFNAEj7SzlcZcIT3iBHJGF6AVIBaOzjx AsEXGhlGxq9uuV72Rpzg6acN70U5 X-Google-Smtp-Source: AGHT+IGdLsh4PSghJudU9ZZLVuBCTp8arYUAPabSuLm1hM3iwmJeVvWz1ywPAiEvs87ecPxRDIQOag== X-Received: by 2002:a05:600c:4fcf:b0:42c:ba83:3f08 with SMTP id 5b1f17b1804b1-432df71af58mr35938235e9.2.1731868104124; Sun, 17 Nov 2024 10:28:24 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3823f72441bsm3028137f8f.101.2024.11.17.10.28.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Nov 2024 10:28:23 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v2 09/22] iio: accel: adxl345: unexpose private defines Date: Sun, 17 Nov 2024 18:26:38 +0000 Message-Id: <20241117182651.115056-10-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241117182651.115056-1-l.rubusch@gmail.com> References: <20241117182651.115056-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 For the implementation of features like FIFO-usage, watermark, single tap, double tap, freefall, etc. most of the constants do not need to be exposed in the header file, but are rather of private nature. Reduce namespace pollution by moving them to the core source file. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345.h | 33 +--------- drivers/iio/accel/adxl345_core.c | 108 +++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 31 deletions(-) diff --git a/drivers/iio/accel/adxl345.h b/drivers/iio/accel/adxl345.h index 4ba493f636..c9d2a82fa6 100644 --- a/drivers/iio/accel/adxl345.h +++ b/drivers/iio/accel/adxl345.h @@ -8,38 +8,9 @@ #ifndef _ADXL345_H_ #define _ADXL345_H_ -#define ADXL345_REG_DEVID 0x00 -#define ADXL345_REG_OFSX 0x1E -#define ADXL345_REG_OFSY 0x1F -#define ADXL345_REG_OFSZ 0x20 -#define ADXL345_REG_OFS_AXIS(index) (ADXL345_REG_OFSX + (index)) -#define ADXL345_REG_BW_RATE 0x2C -#define ADXL345_REG_POWER_CTL 0x2D -#define ADXL345_REG_DATA_FORMAT 0x31 -#define ADXL345_REG_DATAX0 0x32 -#define ADXL345_REG_DATAY0 0x34 -#define ADXL345_REG_DATAZ0 0x36 -#define ADXL345_REG_DATA_AXIS(index) \ - (ADXL345_REG_DATAX0 + (index) * sizeof(__le16)) - -#define ADXL345_BW_RATE GENMASK(3, 0) -#define ADXL345_BASE_RATE_NANO_HZ 97656250LL - -#define ADXL345_POWER_CTL_MEASURE BIT(3) -#define ADXL345_POWER_CTL_STANDBY 0x00 - -#define ADXL345_DATA_FORMAT_RANGE GENMASK(1, 0) /* Set the g range */ -#define ADXL345_DATA_FORMAT_JUSTIFY BIT(2) /* Left-justified (MSB) mode */ -#define ADXL345_DATA_FORMAT_FULL_RES BIT(3) /* Up to 13-bits resolution */ +/* Regs and bits needed to be declared globally */ +#define ADXL345_REG_DATA_FORMAT 0x31 /* r/w Data format control */ #define ADXL345_DATA_FORMAT_SPI_3WIRE BIT(6) /* 3-wire SPI mode */ -#define ADXL345_DATA_FORMAT_SELF_TEST BIT(7) /* Enable a self test */ - -#define ADXL345_DATA_FORMAT_2G 0 -#define ADXL345_DATA_FORMAT_4G 1 -#define ADXL345_DATA_FORMAT_8G 2 -#define ADXL345_DATA_FORMAT_16G 3 - -#define ADXL345_DEVID 0xE5 /* * In full-resolution mode, scale factor is maintained at ~4 mg/LSB diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 51b229cc44..c8d9e1f9e0 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -18,6 +18,114 @@ #include "adxl345.h" +/* ADXL345 register map */ +#define ADXL345_REG_DEVID 0x00 /* r Device ID */ +#define ADXL345_REG_THRESH_TAP 0x1D /* r/w Tap Threshold */ +#define ADXL345_REG_OFSX 0x1E /* r/w X-axis offset */ +#define ADXL345_REG_OFSY 0x1F /* r/w Y-axis offset */ +#define ADXL345_REG_OFSZ 0x20 /* r/w Z-axis offset */ +#define ADXL345_REG_DUR 0x21 /* r/w Tap duration */ +#define ADXL345_REG_LATENT 0x22 /* r/w Tap latency */ +#define ADXL345_REG_WINDOW 0x23 /* r/w Tap window */ +#define ADXL345_REG_THRESH_ACT 0x24 /* r/w Activity threshold */ +#define ADXL345_REG_THRESH_INACT 0x25 /* r/w Inactivity threshold */ +#define ADXL345_REG_TIME_INACT 0x26 /* r/w Inactivity time */ +#define ADXL345_REG_ACT_INACT_CTRL 0x27 /* r/w Axis enable control for */ + /* activity and inactivity */ + /* detection */ +#define ADXL345_REG_THRESH_FF 0x28 /* r/w Free-fall threshold */ +#define ADXL345_REG_TIME_FF 0x29 /* r/w Free-fall time */ +#define ADXL345_REG_TAP_AXIS 0x2A /* r/w Axis control for */ + /* single tap or double tap */ +#define ADXL345_REG_ACT_TAP_STATUS 0x2B /* r Source of single tap or */ + /* double tap */ +#define ADXL345_REG_BW_RATE 0x2C /* r/w Data rate and power */ + /* mode control */ +#define ADXL345_REG_POWER_CTL 0x2D /* r/w Power-saving features */ +#define ADXL345_REG_INT_ENABLE 0x2E /* r/w Interrupt enable control */ +#define ADXL345_REG_INT_MAP 0x2F /* r/w Interrupt mapping */ + /* control */ +#define ADXL345_REG_INT_SOURCE 0x30 /* r Source of interrupts */ +/* NB: ADXL345_REG_DATA_FORMAT 0x31 r/w Data format control, + * (defined in header) + */ + +#define ADXL345_REG_XYZ_BASE 0x32 /* r Base address to read out */ + /* X-, Y- and Z-axis data 0 */ + /* and 1 */ +#define ADXL345_REG_DATA_AXIS(index) \ + (ADXL345_REG_XYZ_BASE + (index) * sizeof(__le16)) +/* NB: having DATAX0 and DATAX1 makes 2x sizeof(__le16) */ + +#define ADXL345_REG_FIFO_CTL 0x38 /* r/w FIFO control */ +#define ADXL345_REG_FIFO_STATUS 0x39 /* r FIFO status */ + +/* DEVID(s) */ +#define ADXL345_DEVID 0xE5 + +/* FIFO */ +#define ADXL345_FIFO_CTL_SAMLPES(x) (0x1f & (x)) +#define ADXL345_FIFO_CTL_TRIGGER(x) (0x20 & ((x) << 5)) /* set 1: INT2, 0: INT1 */ +#define ADXL345_FIFO_CTL_MODE(x) (0xc0 & ((x) << 6)) + +/* INT_ENABLE, INT_MAP, INT_SOURCE bits */ +#define ADXL345_INT_DATA_READY BIT(7) +#define ADXL345_INT_SINGLE_TAP BIT(6) +#define ADXL345_INT_DOUBLE_TAP BIT(5) +#define ADXL345_INT_ACTIVITY BIT(4) +#define ADXL345_INT_INACTIVITY BIT(3) +#define ADXL345_INT_FREE_FALL BIT(2) +#define ADXL345_INT_WATERMARK BIT(1) +#define ADXL345_INT_OVERRUN BIT(0) + +#define ADXL34X_S_TAP_MSK ADXL345_INT_SINGLE_TAP +#define ADXL34X_D_TAP_MSK ADXL345_INT_DOUBLE_TAP + +/* INT1 or INT2 */ +#define ADXL345_INT1 0 +#define ADXL345_INT2 1 + +/* BW_RATE bits - Bandwidth and output data rate. The default value is + * 0x0A, which translates to a 100 Hz output data rate + */ +#define ADXL345_BW_RATE GENMASK(3, 0) +#define ADXL345_BW_LOW_POWER BIT(4) +#define ADXL345_BASE_RATE_NANO_HZ 97656250LL + +/* POWER_CTL bits */ +#define ADXL345_POWER_CTL_STANDBY 0x00 + +/* NB: + * BIT(0), BIT(1) for explicit wakeup (not implemented) + * BIT(2) for explicit sleep (not implemented) + */ +#define ADXL345_POWER_CTL_MEASURE BIT(3) +#define ADXL345_POWER_CTL_AUTO_SLEEP BIT(4) +#define ADXL345_POWER_CTL_LINK BIT(5) + +/* DATA_FORMAT bits */ +#define ADXL345_DATA_FORMAT_RANGE GENMASK(1, 0) /* Set the g range */ +#define ADXL345_DATA_FORMAT_JUSTIFY BIT(2) /* 1: left-justified (MSB) mode, 0: right-just'd */ +#define ADXL345_DATA_FORMAT_FULL_RES BIT(3) /* Up to 13-bits resolution */ +/* NB: BIT(6): 3-wire SPI mode (defined in header) */ + +#define ADXL345_DATA_FORMAT_SELF_TEST BIT(7) /* Enable a self test */ +#define ADXL345_DATA_FORMAT_2G 0 +#define ADXL345_DATA_FORMAT_4G 1 +#define ADXL345_DATA_FORMAT_8G 2 +#define ADXL345_DATA_FORMAT_16G 3 + +#define ADXL345_REG_OFS_AXIS(index) (ADXL345_REG_OFSX + (index)) + +/* The ADXL345 include a 32 sample FIFO + * + * FIFO stores a maximum of 32 entries, which equates to a maximum of 33 + * entries available at any given time because an additional entry is available + * at the output filter of the device. + * (see datasheet FIFO_STATUS description on "Entries Bits") + */ +#define ADXL34x_FIFO_SIZE 33 + struct adxl34x_state { int irq; const struct adxl345_chip_info *info; From patchwork Sun Nov 17 18:26:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13877890 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.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 82FBC1DD862; Sun, 17 Nov 2024 18:28:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868109; cv=none; b=JOLq0Ymmm+npGSziKkhRgWGi4Z+RFlV9KtqlijkOc2Bw9/7T/Om7QgePRBEAAjdhOFJFKx31FMkdNmkGElGRCo20n3xO0qnaGpVJmd7GBikP+J5wqwuKaLnxlhIY9f42bK6Uk1ou4KXogpTNJuSr8qfM/WwiCio/mpaVRWomy5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868109; c=relaxed/simple; bh=7ht4ODhUVZtZWQWhZMHDdqVUX5Z9ixmgQJA5GDPh9ik=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VV05qhWbd79YPvziJmSM05V2quvVr1RXTlpBQSe2CTEssK8XuFzs+DR8+tddDFhQJT2HHGk22jBGtYJN6myYaEWYCid7/YbD5OWiZxsjXy2s/eMboPn+9awL3HxGTHGTWv0Ggx6pHB8neHA935CAlLIe+68t8po4IBdGZ/5eGCM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VaaK+FQ+; arc=none smtp.client-ip=209.85.221.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VaaK+FQ+" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-382377822b9so170665f8f.3; Sun, 17 Nov 2024 10:28:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731868106; x=1732472906; 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=isbyosWHvXydkQYw7H4qCGUq+Q5YVEqyoJq0CjLjPWQ=; b=VaaK+FQ+k4Cipx5B961hZIJV9tET8cYFO7aJVO+j7ilRyBX7phzg1zrgeuzxFWWDBU msp5yIeUSkymR3nwXD5O+MFPE5ZnVdW9dn9OIAU19L7Pqc3B5DxdkHucnNH/A22Pjag+ O2zpeYmh7zehrEhLEfpbV9awj7q1TDwvknm4SgunOWz2Uq0gaIari1h9hNeg/yGAKZY2 sua0eR8sRCdkFprX5c2TpqOwBndGnleJG+JIjYXzmU1E4X3vXyg6e9nkJm9xSglLR15I qyLGoDHGFVnLNKzZHR1hr41kpCioDeN5FiGYl+/TRxwavbUIvz8K6JrgJod+JQLtMpgt gVwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731868106; x=1732472906; 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=isbyosWHvXydkQYw7H4qCGUq+Q5YVEqyoJq0CjLjPWQ=; b=ishLs+4pm6SdP4kQkEdQSwr2IGpM++CE90z5l5JB6H48xKtI7Yyy1SzzPBfPBCJ3sP tZ+qXLituXw3na/2w8g5/ZQdZ2AF3V2X+ZUiuVtlwHM4NjOpCD/PInEMlFhX//BJzISP wMdF5EcYu3pt66WQCzwJGoOmHYnBgC6PRLVsYM48zUcR7/P2QRxtxQy52y2kcg9Z88L1 Ri8o4Rmf3LNClTTbtypmYFgkNaCzJbMcd8iSMxaQ16BhuBC9ficFWkIiqUQL8t6c/UpW LrQT5DpQxvp6g1IoacKkjikrMVDoVln+NHmv1ir3FGavUmve/OjBkPuqDjFgRiYKC8KM nLWA== X-Forwarded-Encrypted: i=1; AJvYcCX8o8JMrdPkc1WKbvVtdPxJWQzMmNVB4DxPnpCTZaYK8RI9xMwnuZwigydpBAsJDTRzDRx0py4We3+u91s=@vger.kernel.org X-Gm-Message-State: AOJu0Ywn2a76rStfz/wRSYVP3MqUpg1Inwe+1gF19XAV8yjsS73XiEle 4V/xgpDlID81y7jbGoLCNotiv2CgYQvXbWvFuVvkRgbx3UFoKy4G X-Google-Smtp-Source: AGHT+IGTTdDTahXCeP6L7HmXPPULpto6bTEyM0vfZwNb93RSc6QlugO/+PPG7NCIkGzWJ4+diKquMA== X-Received: by 2002:a5d:6c65:0:b0:378:955f:d47d with SMTP id ffacd0b85a97d-38225a83057mr3008312f8f.11.1731868105725; Sun, 17 Nov 2024 10:28:25 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3823f72441bsm3028137f8f.101.2024.11.17.10.28.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Nov 2024 10:28:24 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v2 10/22] iio: accel: adxl345: set interrupt line to INT1 Date: Sun, 17 Nov 2024 18:26:39 +0000 Message-Id: <20241117182651.115056-11-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241117182651.115056-1-l.rubusch@gmail.com> References: <20241117182651.115056-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The adxl345 sensor uses one of two interrupt lines, INT1 or INT2. The interrupt lines are used to signal feature events such as watermark reached, single tap, double tap, activity, etc. Only one interrupt line is used and must be configured. The adxl345 default is to use INT1 and in many installations only INT1 is even connected. Therefore configure INT1 as the sensor's default interrupt line. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index c8d9e1f9e0..32163cfe6f 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -131,6 +131,7 @@ struct adxl34x_state { const struct adxl345_chip_info *info; struct regmap *regmap; bool fifo_delay; /* delay: delay is needed for SPI */ + u8 intio; }; #define ADXL345_CHANNEL(index, axis) { \ @@ -345,6 +346,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, return -ENODEV; st->fifo_delay = fifo_delay_default; + st->intio = ADXL345_INT1; indio_dev->name = st->info->name; indio_dev->info = &adxl345_info; From patchwork Sun Nov 17 18:26:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13877891 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.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 2AFF11DD9D1; Sun, 17 Nov 2024 18:28:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868110; cv=none; b=sMb3GIUXeDY4reE8vjzpX/zXnvzJOqdBp2aUkH8vHmcJNEAvVotFFCt3x4whNln3EcwLOkonDJAUwS4xqNlxhaXKx0WE2r0n9L4hW1I+ehWaz2GidrzEE33qISyqgMe0vM19wB4nplZXC+R40B911CuYcAQO3gzRRSu3kq3Ddm4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868110; c=relaxed/simple; bh=p48hX7DozsNTbQ0ynKBuWkKZ0T+mYNhWVNO4AfsJdOI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LPFjvRy1RgX2Mm0anQDpCGBc/Gh4nlg3s/cm4qoTye8Q8wGN5pvDZD1vBkLnuS7fCp5PBG0l2MgG7r4NBvt3OnLYJpHd0x4cgPrJVjaxuzTEnTLAZpA4rPUFyhJJavItPF0Elpe8WlgvXyuqPid0ZB6SXtBjQhAhw9laa1KFQwc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fmO5bc1V; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fmO5bc1V" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4315dfa3e0bso2241185e9.0; Sun, 17 Nov 2024 10:28:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731868107; x=1732472907; 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=2/uskBaS7mbhCAG/rFrauB7qEmDpyzXnB8FlpPp8d/I=; b=fmO5bc1ViL/oWFxG9pUJebzpTB+8m0HA1+FEDzkAsbB5nMVXkm055WwYnk+lCxojeU noYacI1MmOSJ4jezF7HRGakYoB4Jt17o3wiLTV3kbFBNkpoUsoyLV2FtB//PNRaYoPYM pT91YQp8rteo/8LAffSolNyl1kZr5Jca09n4ESgnAdzoCvxUWFbX+kdRHyvry3JyQYH9 VAivN57WFEm1d4Dn5xkq1Q+fJL8rLgVQYzReFrT+ZWPyxCtZCPKcrYc81MpCXUhhxRTq Xm274BOfaofbnwzWgHPuvYfbyuhF9PKM7v7WEPsYKDsJEqBHXcP7g7CfstgKVoKXA5am 3H2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731868107; x=1732472907; 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=2/uskBaS7mbhCAG/rFrauB7qEmDpyzXnB8FlpPp8d/I=; b=W7q1jZq69S1ILolHzCrTHIH8rAlei0/fQyYlXHaZMc2GGAiBcbetdroW86hZj/YG+h gpGw+NfOQLwXLKsPH44YiNWaFR2xsGLpoprvs2x3/Q0FU2ZriJPTRCBkLdaMl97jcXoP BhFZzARHpstgkHnvAj3hXgY3xm41jlvHtfO7FVuBXISkAAhAF5WtWmXDSz+7mSR1XRGT DsZED5kypBHdqbRozhgGsM2vn1NclTK9uQ914RZNQuxzfjdsu+dFn23IlOwES7bo9Lnl xl7Ft7X5sXZRIdftXgYQPqPywdbpqVFGXcoG5zi5OKNezRlCQxN96rGP3i1qFV7M6mcM MKVA== X-Forwarded-Encrypted: i=1; AJvYcCV9s+kFH4tLg+yr5nSDE+EmoBM3DpQPsvAwiducVEwTeSOba2CYRbs+tICpYlffiOMh7wTJL2FWQZinS1g=@vger.kernel.org X-Gm-Message-State: AOJu0Yyvdl27m+vXOcqJqBx0nJnxt9NJNdHc8MlVvatxnbiKwQPc0fBB 0nAD7fDJTTvRoTUmq5SUMHlillyxBXUfWg2rkV9lsyDd78pfzkFz X-Google-Smtp-Source: AGHT+IFP21JkfuJkf7urhHqBZy12c2BFZ34UbDOKW/5jBUZ5QBVW9RmtlY1hWYlphbFphH0qjePlrw== X-Received: by 2002:a5d:64e5:0:b0:37d:4aa2:5cfe with SMTP id ffacd0b85a97d-38225a04721mr3479958f8f.6.1731868107311; Sun, 17 Nov 2024 10:28:27 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3823f72441bsm3028137f8f.101.2024.11.17.10.28.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Nov 2024 10:28:26 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v2 11/22] iio: accel: adxl345: import adxl345 general data Date: Sun, 17 Nov 2024 18:26:40 +0000 Message-Id: <20241117182651.115056-12-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241117182651.115056-1-l.rubusch@gmail.com> References: <20241117182651.115056-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use struct adxl34x_platform_data from the included public header of the input driver for ADXL34x with the following argumentation for this approach: - The iio driver for the ADXL34x covers features also implemented in the older input driver. The iio driver will implement the same features but can also benefit from including the common header and struct adxl34x_platform_data. Once complete, the input driver could be faded out. - The fields in the input driver are identical to the fields the IIO implementation will need. Including the header over reimplementing, avoids a duplication of almost identical headers in IIO and iio. - The header for the input driver is public. It provides a public interface for adxl34x related implementation and is not private to the input system. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 32163cfe6f..b16887ec1c 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -16,6 +16,8 @@ #include #include +#include + #include "adxl345.h" /* ADXL345 register map */ @@ -126,10 +128,15 @@ */ #define ADXL34x_FIFO_SIZE 33 +static const struct adxl34x_platform_data adxl345_default_init = { + .tap_axis_control = ADXL_TAP_X_EN | ADXL_TAP_Y_EN | ADXL_TAP_Z_EN, +}; + struct adxl34x_state { int irq; const struct adxl345_chip_info *info; struct regmap *regmap; + struct adxl34x_platform_data data; /* watermark, fifo_mode, etc */ bool fifo_delay; /* delay: delay is needed for SPI */ u8 intio; }; @@ -331,6 +338,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, unsigned int data_format_mask = (ADXL345_DATA_FORMAT_RANGE | ADXL345_DATA_FORMAT_FULL_RES | ADXL345_DATA_FORMAT_SELF_TEST); + const struct adxl34x_platform_data *data; int ret; indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); @@ -346,6 +354,16 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, return -ENODEV; st->fifo_delay = fifo_delay_default; + data = dev_get_platdata(dev); + if (!data) { + dev_dbg(dev, "No platform data: Using default initialization\n"); + data = &adxl345_default_init; + } + st->data = *data; + + /* some reasonable pre-initialization */ + st->data.act_axis_control = 0xFF; + st->intio = ADXL345_INT1; indio_dev->name = st->info->name; From patchwork Sun Nov 17 18:26:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13877892 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6467E1DDA33; Sun, 17 Nov 2024 18:28:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868112; cv=none; b=QeyDj4wb7WWL+ipJCSxv3ynPRlGwNZDFya3tIX+acsytEnDkYHFdF6cULv3q8wJ7VTeCdsxI+AG+FuBcTUOLEZK1BWZvEPBN+S8Lk0Jnyj3lHc463J0YNZ+ChYQSy2snt7MjBERrLBW9zqoG+7IRiisUDAhjAQJY8LC+wUqQjss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868112; c=relaxed/simple; bh=qWbaygyMbxxCxY2EM69SwvmmEH+qTWZUyJMBN5sPzCk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UeP0NurnZsqY0Wlkc5YIPb6gKUuDNrpJI5uq8EEti6AF1WFeSMkaoKMbK9MYVfLbdJWvfDJRt0Ayb9Z9yZwFPjqwLuRISjHMlUrOS8wNScLCV80wDs3BlJsu7sbqN7mKFQ9KqOZT/eGwbg0lJgefC2gNQWdxjwZO/ptmxqSVBao= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DyRo0AM5; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DyRo0AM5" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-4315dfa3e0bso2241205e9.0; Sun, 17 Nov 2024 10:28:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731868109; x=1732472909; 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=08++XPHng6VQRbZngz7EYFo0cAPTzd2hP395fTftmHY=; b=DyRo0AM55AP5VcCYyKcaw2YjYNirwZmiG7skyHMnJCWYdQAaUi6G0q0I0RNLW7isxp LaI4WCWUS1jyzjHjcBU9ZZOCWDVfK9JnuovphNFFDe63o/MvWnZT0jYwuvt8CIHeB0fY DG5DXqzxbiTFFVQCww0Je1hgyFTC2INaJ5VfCekPLPRidUhvMO1hc8Il+BeJJpf2onZ2 3RkGc8kC9BGBdtlXkSf1DZIqmOKlv6tn1BYngcUSp6XK+E3ECYj1fHxf/iETB5VnDnXQ DQYGTmNhqAhGMQc/x290OC38q+g5qHpNhbk921G7lwzWg9/IcXCbiKiPb+zzVapDWNmz EnFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731868109; x=1732472909; 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=08++XPHng6VQRbZngz7EYFo0cAPTzd2hP395fTftmHY=; b=qHYPabpNLb2z4UosiT79oaqrL8FBarerRuCMGgK9UAoumoHEa0TryQlVRnpx919YZm 0rHzm68sdD5wLKDJaSgvGWMGykuDJHiobc83WJqFLHHODBRfFRphxesw238kxc/kt97q S5ldy1HJwUMkD+7I6BiTTQq73Dgk+xUGkhcU1l6sYDqH2YdtiZro+yuRnnjzpERomLJT UXHDyOUklV5gQVIwy6zhaBUPlmCOltWMB9QsK7Itgj1TUXNSO1PeOxgo4QHHXo5VmxeE tGZHfj1btnYeBjGmMA/YUnXVlwSli1JkWtzmsvQMOqZoEeGW5rXD7BwbG5WAKbtAvj9r 0Lwg== X-Forwarded-Encrypted: i=1; AJvYcCXrFEB1KYubKycJrM686YFP42tMM1AUSS6qNsHkqELtyJa+xBL8w2PXZVTyRHkUyzV7pvSYkezg7gGC5qo=@vger.kernel.org X-Gm-Message-State: AOJu0Yy+c2D3K8hVpN9ZzyrfVAe6Ky5ij2iqh3l3j4REzBUXeOY8SaDL VAHiI6zef2q51e6+d9nZ/PqA1j8J8ntIu2RZgMniQdAXntyw4O/K2PXPizUp X-Google-Smtp-Source: AGHT+IGazw5wStaxXiQcVpMZFABDQof4/ko5McqQJJ/8TPLUhiF9sqpbHZqtAlKdg42KHFV1q6Yx5A== X-Received: by 2002:a05:600c:4f02:b0:42c:bfd6:9d2f with SMTP id 5b1f17b1804b1-432df71d75fmr34800285e9.1.1731868108464; Sun, 17 Nov 2024 10:28:28 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3823f72441bsm3028137f8f.101.2024.11.17.10.28.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Nov 2024 10:28:28 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v2 12/22] iio: accel: adxl345: elaborate iio channel definition Date: Sun, 17 Nov 2024 18:26:41 +0000 Message-Id: <20241117182651.115056-13-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241117182651.115056-1-l.rubusch@gmail.com> References: <20241117182651.115056-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Make the channel definition ready to allow for feature implementation for this accelerometer sensor. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 36 +++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index b16887ec1c..f98ddef4c5 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -141,21 +141,33 @@ struct adxl34x_state { u8 intio; }; -#define ADXL345_CHANNEL(index, axis) { \ - .type = IIO_ACCEL, \ - .modified = 1, \ - .channel2 = IIO_MOD_##axis, \ - .address = index, \ - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ - BIT(IIO_CHAN_INFO_CALIBBIAS), \ - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ - BIT(IIO_CHAN_INFO_SAMP_FREQ), \ +#define ADXL34x_CHANNEL(index, reg, axis) { \ + .type = IIO_ACCEL, \ + .address = (reg), \ + .modified = 1, \ + .channel2 = IIO_MOD_##axis, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_CALIBBIAS), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .scan_index = (index), \ + .scan_type = { \ + .sign = 's', \ + .realbits = 13, \ + .storagebits = 16, \ + .shift = 0, \ + .endianness = IIO_LE, \ + }, \ } +enum adxl34x_chans { + chan_x, chan_y, chan_z, +}; + static const struct iio_chan_spec adxl34x_channels[] = { - ADXL345_CHANNEL(0, X), - ADXL345_CHANNEL(1, Y), - ADXL345_CHANNEL(2, Z), + ADXL34x_CHANNEL(0, chan_x, X), + ADXL34x_CHANNEL(1, chan_y, Y), + ADXL34x_CHANNEL(2, chan_z, Z), }; static int adxl345_read_raw(struct iio_dev *indio_dev, From patchwork Sun Nov 17 18:26:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13877893 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.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 4A8F81DDC02; Sun, 17 Nov 2024 18:28:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868113; cv=none; b=Fwag4qvhMAzrTYkdojtS5ihbrVEuaH4Nlgj+KmDfOr7MrZtYR/nGYfHvGrqyUPH0SsYO6T7t4a2/9HIdkbbZXMLRCUvaC09vx9r3SzwNpZ655QlvUvcqbmGYqL1lMKeFdGmJofYZw0QEL0CBnmOE01jCFnnTJFGBhh7/aRkORTw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868113; c=relaxed/simple; bh=JxslxY6nz+N7Qayo8xOOBDlH/hySO0/OoVvaLU8Mq64=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TxkJogHL1uVP1Q66RaegcaGWK0GPA5K6a0ZA6ZBmBzvmfFm97SuWU7i7fJAq4fnnLY600BId4/wfJduJgSQ6N9yg+mFbTNVblah9QgpS/069R1XzoCOFZkYnMN03Ik0IFH64TRMNMrMNc6wegph/OsNn5LohKYvsPFlBa77GfzU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NbEdO3+U; arc=none smtp.client-ip=209.85.221.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NbEdO3+U" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-38233152c8fso81020f8f.0; Sun, 17 Nov 2024 10:28:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731868110; x=1732472910; 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=CpE9m38atunxHDylQkGqfI57mWJ+meMxLZ5550/ySnA=; b=NbEdO3+UOyWA0+yobEgV+zfhn7tbt6c+1HjG5jSrDIoAbTsPD9pCWbB0bx7EzinIat dPVkXvhnUxRUTlpQIXz9jzzK61hbClzHe7xa2l+xi7LFb/7cTzXE3B3Ve+1Woyl4OoOd w8Tc+sgVzsJNDK1sg978yvn1dtsKk0dL4oy+VYDicRbCVFRdFsAlPO9vIMXlqVK30Cb7 yZ9F9pLVlf73dAvZQRauhZKQAGONxBN+Eh4vF9VvwGOyUXisXaZU+Sw3PEETSTrTKiz6 Lvrj5FNftu+DGmP+oSyghjeCz0p78wAG7GMHgY/g3UIfB0E32aiYo3nR8jmxnAE73BnI ODnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731868110; x=1732472910; 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=CpE9m38atunxHDylQkGqfI57mWJ+meMxLZ5550/ySnA=; b=DeSB0VYaASKSaiEFNukcmP+qPGMW7Zju7Kcl4rCiMBCHmkfGE0azVaVaY4ZhDOse63 wMnd2Y0TheVDcypk5FmZDagYLmzm8qzo3USByZ58rD78iHy5QV284sU0O6V/WPAOJTQy 2bEMnq3wlN9Nb/c9ScC7u8ZrS8ypbCGYIRlOn8dTQ0dDbOVi+fFEsWX2n2LDHKTDjDfl +d9JjGpjAzjzO70XsIZExuh3HMdnxAcCZjZbeE37llRJQWEJfvRfGYy9rvxRYwxDCODU 4m0vxd4XvBvnIF5JbidNJkkXeJgvEouLLdt/XTSnWcut/s547+iwtfz5IRkAheEhLiuj RaGg== X-Forwarded-Encrypted: i=1; AJvYcCXL9hQjKQSChqXaRM31zoYCq9k7eweXjGA5DrnxWyKnEZrsMcBS6WVSK+aVgBVjS/jbKoAcqCLYCMbNiMk=@vger.kernel.org X-Gm-Message-State: AOJu0YyJHT4pSTAd6Os34MKQxyURVMyqFVIwgQudyLyWueZRHxOKpY53 7U10bZ/SJ4y7qeBgVvmYyNl1CW9VSvT44mJbR/ZjNo+5TYKuwrO1 X-Gm-Gg: ASbGncuWg7R6ohpX9OMaezMMZBMwOT1wTvI9Dny7bB7t1lCAV8QwmljRLK5L9FqaZNB qQEtjtVb2iXsVtlNtmVgb35Dxu2ruM5545APFAAK6VToaMu9fDo6IWvnUH6oQJalw5mWo1vbZaz Vv4vH29Earc9+Xh5GXY0kh09rLYExMdD/c3JOvHdsefQZeGGXUoLylVN+4tMo63tPRr3/Jh3Lqi vKqPwlDhQ80nR+wST8kUeoD8kEs1Mj3umR6Yy2cr+t0WZZj3jl4aZosujdEiqetB/4/EMzT8cCG FU/f2Xecy5pThvRuQZRX3qPVnrYT X-Google-Smtp-Source: AGHT+IGw1VMqflB5rOHmMnXMDL+5jOjGPU5J8rgylmSUrJsFU4qhtt/V63HzL2Vs85RlwocOlM4l3Q== X-Received: by 2002:a05:6000:1acb:b0:37d:52cc:c484 with SMTP id ffacd0b85a97d-38225a85c5fmr2813494f8f.9.1731868109574; Sun, 17 Nov 2024 10:28:29 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3823f72441bsm3028137f8f.101.2024.11.17.10.28.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Nov 2024 10:28:29 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v2 13/22] iio: accel: adxl345: add trigger handler Date: Sun, 17 Nov 2024 18:26:42 +0000 Message-Id: <20241117182651.115056-14-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241117182651.115056-1-l.rubusch@gmail.com> References: <20241117182651.115056-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add basic setup to the interrupt handler function and prepare probe for using and not using the FIFO on the adxl345. Interrupt handler and basic structure integration is needed to evaluate interrupt source register. This is crucial for implementing further features of the sensor. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 105 ++++++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 2 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index f98ddef4c5..508de81bb9 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -15,6 +15,9 @@ #include #include +#include +#include +#include #include @@ -137,6 +140,7 @@ struct adxl34x_state { const struct adxl345_chip_info *info; struct regmap *regmap; struct adxl34x_platform_data data; /* watermark, fifo_mode, etc */ + u8 int_map; bool fifo_delay; /* delay: delay is needed for SPI */ u8 intio; }; @@ -302,6 +306,10 @@ static void adxl345_powerdown(void *ptr) adxl345_set_measure_en(st, false); } +static const struct iio_dev_attr *adxl345_fifo_attributes[] = { + NULL, +}; + static IIO_CONST_ATTR_SAMP_FREQ_AVAIL( "0.09765625 0.1953125 0.390625 0.78125 1.5625 3.125 6.25 12.5 25 50 100 200 400 800 1600 3200" ); @@ -315,6 +323,75 @@ static const struct attribute_group adxl345_attrs_group = { .attrs = adxl345_attrs, }; +static const struct iio_buffer_setup_ops adxl345_buffer_ops = { +}; + +static int adxl345_get_status(struct adxl34x_state *st, u8 *int_stat) +{ + int ret; + unsigned int regval; + + *int_stat = 0; + ret = regmap_read(st->regmap, ADXL345_REG_INT_SOURCE, ®val); + if (ret) { + pr_warn("%s(): Failed to read INT_SOURCE register\n", __func__); + return -EINVAL; + } + + *int_stat = 0xff & regval; + pr_debug("%s(): int_stat 0x%02X (INT_SOURCE)\n", __func__, *int_stat); + + return 0; +} + +/** + * irqreturn_t adxl345_trigger_handler() - Interrupt handler used for several + * features of the ADXL345. + * @irq: The interrupt number. + * @p: The iio poll function instance, used to derive the device and data. + * + * Having an interrupt imples FIFO_STREAM mode was enabled. Since this is given + * there will no be further test for being in FIFO_BYPASS mode. FIFO_TRIGGER + * and FIFO_FIFO mode (being similar to FIFO_STREAM mode) are not separately + * implemented so far. Both should be work smoothly with the same way of + * interrupt handling. + * + * Return: Describe if the interrupt was handled. + */ +static irqreturn_t adxl345_trigger_handler(int irq, void *p) +{ + struct iio_dev *indio_dev = ((struct iio_poll_func *) p)->indio_dev; + struct adxl34x_state *st = iio_priv(indio_dev); + u8 int_stat; + int ret; + + ret = adxl345_get_status(st, &int_stat); + if (ret < 0) + goto done; + + /* Ignore already read event by reissued too fast */ + if (int_stat == 0x0) + goto done; + + /* evaluation */ + + if (int_stat & ADXL345_INT_OVERRUN) { + pr_debug("%s(): OVERRUN event detected\n", __func__); + goto done; + } + + if (int_stat & (ADXL345_INT_DATA_READY | ADXL345_INT_WATERMARK)) + pr_debug("%s(): WATERMARK or DATA_READY event detected\n", __func__); + + goto done; +done: + + if (indio_dev) + iio_trigger_notify_done(indio_dev->trig); + + return IRQ_HANDLED; +} + static const struct iio_info adxl345_info = { .attrs = &adxl345_attrs_group, .read_raw = adxl345_read_raw, @@ -351,6 +428,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, ADXL345_DATA_FORMAT_FULL_RES | ADXL345_DATA_FORMAT_SELF_TEST); const struct adxl34x_platform_data *data; + u8 fifo_ctl; int ret; indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); @@ -419,9 +497,32 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, if (ret < 0) return dev_err_probe(dev, ret, "Failed to add action or reset\n"); - /* Enable measurement mode */ - adxl345_set_measure_en(st, true); + /* Basic common initialization of the driver is done now */ + + if (st->irq) { /* Initialization to prepare for FIFO_STREAM mode */ + ret = devm_iio_triggered_buffer_setup_ext(dev, indio_dev, + NULL, + adxl345_trigger_handler, + IIO_BUFFER_DIRECTION_IN, + &adxl345_buffer_ops, + adxl345_fifo_attributes); + if (ret) + return dev_err_probe(dev, ret, "Failed to setup triggered buffer\n"); + + } else { /* Initialization to prepare for FIFO_BYPASS mode (fallback) */ + /* The following defaults to 0x00, anyway */ + fifo_ctl = 0x00 | ADXL345_FIFO_CTL_MODE(ADXL_FIFO_BYPASS); + + dev_dbg(dev, "fifo_ctl 0x%02X [0x00]\n", fifo_ctl); + ret = regmap_write(st->regmap, ADXL345_REG_FIFO_CTL, fifo_ctl); + if (ret < 0) + return ret; + + /* Enable measurement mode */ + adxl345_set_measure_en(st, true); + } + dev_dbg(dev, "Driver operational\n"); return devm_iio_device_register(dev, indio_dev); } EXPORT_SYMBOL_NS_GPL(adxl345_core_probe, IIO_ADXL345); From patchwork Sun Nov 17 18:26:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13877894 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.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 3C4291DDC22; Sun, 17 Nov 2024 18:28:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868114; cv=none; b=BOgRtjCrby1iVFux18dZGTiC4lRIzEmHwbxA2ejFr9erbfXJxNcaAt9CaK7ewLJ8n+HHaRsvFbS9CMo5BocgNHVWZlzfvXsxnqEXJahUw7ggQUq6iLJ599yT1De/SG/wk5Dd4t5JXXX/bOtdyD+KtXeMTOa90zd8MhgSxkxLcxY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868114; c=relaxed/simple; bh=Z7P8zkNLYdTfpu5DhAwcHjffAVE5EbJYRzO8KjJdDWM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=to8EGlTnzZ2gDJln/Jd1bmHrM+QidRll59w01RvusfHr9PH7m6xZIWGARDtUnlsXftjfXXsmsDZyZ0tTYoGydv4SNtXFV5io0z02Sed61bwPVEGs5DYGVA8IHEPPHQ4MpWTqaMDZ/IVmsegPzPXNBNRfcgDFc+FlqtFyM7aPAoo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=W4QwwEyd; arc=none smtp.client-ip=209.85.221.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="W4QwwEyd" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-38231f84d8fso94679f8f.3; Sun, 17 Nov 2024 10:28:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731868111; x=1732472911; 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=s/7YHZgr3ztO/Z4vG8ysu402O+69tdVx/wSYmqJAcik=; b=W4QwwEydxHulD8E35spQP9lgSCkv9/wurCCdkY3ipVgE93at+bbKQzQxptYWdb1IOn uGTGMsyPW9nUiZhS06FnRdXKdn3I4OGU1L4/FMM2UBmGraY2vUtDI5HrqyRZut1NT5tv Y6Tc6G72qHYq8DZpMb17SzEtRezRkqQ5Fm8d/0iBZ1eORZP9IT0DCwRO0PkxUsBfiPVo gKMVjoZP1/SZkS1/rjoFL810vKTF60Ys/pCL7Ie3DlneH++Irj9DcZhiqd3/v79d3MfR sSKAuf3bBmDD7K2tdfm4yuuvwcPRCm9QjPllKmgww/GOVDWp/ZZTi+2VESPt/HaSWoVH zGDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731868111; x=1732472911; 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=s/7YHZgr3ztO/Z4vG8ysu402O+69tdVx/wSYmqJAcik=; b=GXCDhAQDIpTNgV/KyOINRHj9gU3TUdEYImSIJFJothi23YbhH2FcjBXVWL0Lk5+45/ ZOtgUnYH0AimB1XViYwiwlTU/ZczZ7cY91J9vg42DplWw3yjRmB/qKrQXKxuUgqCAfRO 5v26TeZh3x2fRsDsRmIh4A1KliUyoodNQemB+EvhnqYId2h51MI89zZWURBvx4z/QNju K00knBbwp6dtv/bIiaC4VCaL7g9ABK3oUFeCOQ1zEzd0x3Ka4tHvkByYICjSf+qMabjR pyNvLk3p2wT/3FdpkFZONDJ+t6aWtmQVl2sO9wI1+N4QeDbnHPRNjkwa9YTpgfeV/gGH pPkA== X-Forwarded-Encrypted: i=1; AJvYcCVMiNISUI8+R5g8qaaAVvLMW1IlDnJyZdPgc2KgfrfWzdl0mZpezDu2tdTbjAtVzxc5licOtaJ7/Gey4Xs=@vger.kernel.org X-Gm-Message-State: AOJu0Yyy0ZSLLCLHj6EeC1yIsE+c45794oobJ4IhkFyCLqKl62urtXiY 8jdtrOhjRBUAeVIkTpL9Jx47EEs2f3KMpkU7jjlc6Ky7yWuWJB5C X-Gm-Gg: ASbGncseUWhssu6ubX+6VsZHcNAK+VUvs+ztsaz24Y/F+dkm2AXuT4RDO7F6CmIVfSK jfm2/0ZElsJbu58v6ldq7d6Xq6mqDEhP5i4SauRS6B1al6Pwjm25SyYySR1VraXikZTRHOzHful 3HaDAwCCQPnmzxvNkdUbXEC+2WBd83C3mWUG9CfJJu6Zfm0+JMIJiad3HE/s2NtFxDxUxCNex/8 VtdEGbdJPZqNUR6/pJ9HBiNvLFoQs18OC4FTtht2HqtlH2jOTdk6wS6F9OM4PFgbJJLwnXmaP4/ 2Q8SQqv1SVVKWgdjfD71B91F0QYW X-Google-Smtp-Source: AGHT+IEITVBC0lvPuCmdnEbVFgy8ODWuDTFLqnfBjClQ7MvPpmZgoIfPBCQ4/i9CIthX931zsvs8Qw== X-Received: by 2002:a05:6000:4012:b0:378:955f:cc0c with SMTP id ffacd0b85a97d-38225aa2cc0mr3008642f8f.14.1731868110548; Sun, 17 Nov 2024 10:28:30 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3823f72441bsm3028137f8f.101.2024.11.17.10.28.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Nov 2024 10:28:30 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v2 14/22] iio: accel: adxl345: read FIFO entries Date: Sun, 17 Nov 2024 18:26:43 +0000 Message-Id: <20241117182651.115056-15-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241117182651.115056-1-l.rubusch@gmail.com> References: <20241117182651.115056-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add a function to read the elements of the adxl345 FIFO. This will flush the FIFO, and brings it into a ready state. The read out is used to read the elemnts and to reset the fifo again. The cleanup equally needs a read on the INT_SOURCE register. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 40 ++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 508de81bb9..40e78dbdb0 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -140,6 +140,8 @@ struct adxl34x_state { const struct adxl345_chip_info *info; struct regmap *regmap; struct adxl34x_platform_data data; /* watermark, fifo_mode, etc */ + + __le16 fifo_buf[3 * ADXL34x_FIFO_SIZE] __aligned(IIO_DMA_MINALIGN); u8 int_map; bool fifo_delay; /* delay: delay is needed for SPI */ u8 intio; @@ -323,6 +325,37 @@ static const struct attribute_group adxl345_attrs_group = { .attrs = adxl345_attrs, }; +/** + * adxl345_get_fifo_entries() - Read number of FIFO entries into *fifo_entries. + * @st: The initialized state instance of this driver. + * @fifo_entries: A field to be initialized by this function with the number of + * FIFO entries. + * + * Since one read on the FIFO is reading all three axis, X, Y and Z in one, the + * number of FIFO entries corresponds to the number of triples of those values. + * Note, this sensor does not support treating any axis individually, or + * exclude them from measuring. + * + * Return: 0 or error value. + */ +static int adxl345_get_fifo_entries(struct adxl34x_state *st, int *fifo_entries) +{ + unsigned int regval = 0; + int ret; + + ret = regmap_read(st->regmap, ADXL345_REG_FIFO_STATUS, ®val); + if (ret) { + pr_warn("%s(): Failed to read FIFO_STATUS register\n", __func__); + *fifo_entries = 0; + return ret; + } + + *fifo_entries = 0x3f & regval; + pr_debug("%s(): fifo_entries %d\n", __func__, *fifo_entries); + + return 0; +} + static const struct iio_buffer_setup_ops adxl345_buffer_ops = { }; @@ -363,6 +396,7 @@ static irqreturn_t adxl345_trigger_handler(int irq, void *p) struct iio_dev *indio_dev = ((struct iio_poll_func *) p)->indio_dev; struct adxl34x_state *st = iio_priv(indio_dev); u8 int_stat; + int fifo_entries; int ret; ret = adxl345_get_status(st, &int_stat); @@ -380,9 +414,11 @@ static irqreturn_t adxl345_trigger_handler(int irq, void *p) goto done; } - if (int_stat & (ADXL345_INT_DATA_READY | ADXL345_INT_WATERMARK)) + if (int_stat & (ADXL345_INT_DATA_READY | ADXL345_INT_WATERMARK)) { pr_debug("%s(): WATERMARK or DATA_READY event detected\n", __func__); - + if (adxl345_get_fifo_entries(st, &fifo_entries) < 0) + goto done; + } goto done; done: From patchwork Sun Nov 17 18:26:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13877895 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.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 766EE1DDC3B; Sun, 17 Nov 2024 18:28:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868115; cv=none; b=NcHuX+dAjUQOF4SraoSD+2d1Bt0oRwcs/lwNgScuaZNEoJC72xij2r6knqisw1MB+g6pfHlanQZ46QXFT6ND9M/Asirh1jBvLSLj0o5BFWqntuyPdJUjaGihblwJmcIKh6KwyNHdkuxBHqG+yW80TDPuR9G5+87mFhRM1zNzZk8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868115; c=relaxed/simple; bh=Gjs9Jn5a2HaBikdNqoDNQRf3a6i6txlmu3uxs5utFNw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EMwAcRiWu02YxuFCPc0fqiou0dFQwi9nRo6WgL5d0llneyYXTbG/Tbxs7lDe18UVh6p+4cRgB7V0LKZt0R18VZk6mQuR3ZUKbrY2xALfTmDHfTlm0E4Tbjrr6xZJpHNyX3Dul0hJNLtRcwHLxjnRyv5aAdGX99DmaE2Rt/oi4gY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QSUvfpdy; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QSUvfpdy" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4315b0bd4ddso3683935e9.3; Sun, 17 Nov 2024 10:28:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731868112; x=1732472912; 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=T72WGs96X/hPhNiSqEgMrEGXOhYafIkOIpYDkBun90U=; b=QSUvfpdyBJp2KD1beMSDJgPshTYXtv5Zptehc1x6SM91hUWXgnBvQMJM4thO5PPMB7 2zsTMZGS2BImipUBQ/DHvpoUTS/SN28BnZ3cM+uKoSfT5WlVZwSj9FDTRZXpYLZMUH+K b/vw3oxZcWbcQajRwTwPaIWxwz7+pp59hYIZbaQ14Md79sm4Tk4/IWwV7Qu3lavMA3Mk Tpth4MoEl8X8xKz8qjwctUFgCkIRNRnLOMOvUMGTOfEnk9xTD2XjsO/Ud2dNd8zpHRof YdSNdPtjF90+e0EzbQkGPTOcr/OrAfW0g8NeKd/l0nIUeGgaX1kPeInVBymPGX+lIyf9 ViDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731868112; x=1732472912; 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=T72WGs96X/hPhNiSqEgMrEGXOhYafIkOIpYDkBun90U=; b=VCpoKVc3Na650iu2GnljLcAs2oNF/UlaOpdhmhn/mnDBsgayknrHq9YX0gG31JeCII ftjiUw7N6pZX5i1hnVPGgNAiqDHCwKdZL6iNRJj9+JqP3ok6APGQO55UIgEn6yuH0LJH 4brRHs3XuH3cJFj0hwFz0KW63QBm+Pc1DPmN5Grwu0YRzGlI3yQbBoPXsh9tT2WUxHyP K4UDGgX+Xo8cUZi3WpuuvguweFk4Dz4xJIWhv9JRrk+LV3ZfD48Bh1SkbC6XQhunWx5j z2+Y3O2b/P0eDPwa92kDLCFTN2yrLJQu92SbVc1yyzML/6GagJ2IgHNFn0q2I5QGA4n5 ZzGw== X-Forwarded-Encrypted: i=1; AJvYcCV0hxFoNXcyCzn5mhXlzmuxPETFeJFXyt/JWhna6uXGD1jghAd+u1Tyw2/tWqgkziMQ2T5mR+UiW9VOmPM=@vger.kernel.org X-Gm-Message-State: AOJu0Yz3wBiCqJDT2SIiRWBOLXyA7rVl7q7zWr87qbSrvqAMyIOghQx/ x9G0EJ8fAPybQ/FdwB6Gv3dxWx2LTw89u4EllP/PJypiT1v+aVMz X-Google-Smtp-Source: AGHT+IEaW8pRvxt6IR0x878eounjn7Q2WmS9uK8UZtire9MBxFfWVONVUhTCXRwj030CU/7vEE9SRQ== X-Received: by 2002:a05:600c:1c83:b0:42c:b63d:df3 with SMTP id 5b1f17b1804b1-432df680b0bmr35313155e9.0.1731868111439; Sun, 17 Nov 2024 10:28:31 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3823f72441bsm3028137f8f.101.2024.11.17.10.28.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Nov 2024 10:28:31 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v2 15/22] iio: accel: adxl345: reset the FIFO on error Date: Sun, 17 Nov 2024 18:26:44 +0000 Message-Id: <20241117182651.115056-16-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241117182651.115056-1-l.rubusch@gmail.com> References: <20241117182651.115056-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add a function to empty the FIFO and reset the INT_SOURCE register. Reading out is used to reset the fifo again. For cleanup also a read on the INT_SOURCE register is needed to allow the adxl345 to issue interrupts again. Without clearing the fields no further interrupts will happen. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 75 ++++++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 8 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 40e78dbdb0..82bd5c2b78 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -356,6 +356,61 @@ static int adxl345_get_fifo_entries(struct adxl34x_state *st, int *fifo_entries) return 0; } +/** + * adxl345_read_fifo_elements() - Read fifo_entries number of elements. + * @st: The instance of the state object of this sensor. + * @fifo_entries: The number of lines in the FIFO referred to as fifo_entry, + * a fifo_entry has 3 elements for X, Y and Z direction of 2 bytes each. + * + * The FIFO of the sensor is read linewise. The read measurement values are + * queued in the corresponding data structure in *st. + * + * It is recommended that a multiple-byte read of all registers be performed to + * prevent a change in data between reads of sequential registers. That is to + * read out the data registers X0, X1, Y0, Y1, Z0, Z1 at once. + * + * Return: 0 or error value. + */ +static int adxl345_read_fifo_elements(struct adxl34x_state *st, int fifo_entries) +{ + size_t count, ndirs = 3; + int i, ret; + + count = 2 * ndirs; /* 2 byte per direction */ + for (i = 0; i < fifo_entries; i++) { + ret = regmap_noinc_read(st->regmap, ADXL345_REG_XYZ_BASE, + st->fifo_buf + (i * count / 2), count); + if (ret) { + pr_warn("%s(): regmap_noinc_read() failed\n", __func__); + return -EFAULT; + } + } + + return 0; +} + +/** + * adxl345_empty_fifo() - Empty the FIFO. + * @st: The instance to the state object of the sensor. + * + * Reading all elements of the FIFO linewise empties the FIFO. Reading th + * interrupt source register resets the sensor. This is needed also in case of + * overflow or error handling to reenable the sensor to issue interrupts. + */ +static void adxl345_empty_fifo(struct adxl34x_state *st) +{ + int regval; + int fifo_entries; + + /* In case the HW is not "clean" just read out remaining elements */ + adxl345_get_fifo_entries(st, &fifo_entries); + if (fifo_entries > 0) + adxl345_read_fifo_elements(st, fifo_entries); + + /* Reset the INT_SOURCE register by reading the register */ + regmap_read(st->regmap, ADXL345_REG_INT_SOURCE, ®val); +} + static const struct iio_buffer_setup_ops adxl345_buffer_ops = { }; @@ -401,30 +456,34 @@ static irqreturn_t adxl345_trigger_handler(int irq, void *p) ret = adxl345_get_status(st, &int_stat); if (ret < 0) - goto done; + goto err; /* Ignore already read event by reissued too fast */ if (int_stat == 0x0) - goto done; + goto err; /* evaluation */ if (int_stat & ADXL345_INT_OVERRUN) { pr_debug("%s(): OVERRUN event detected\n", __func__); - goto done; + goto err; } if (int_stat & (ADXL345_INT_DATA_READY | ADXL345_INT_WATERMARK)) { pr_debug("%s(): WATERMARK or DATA_READY event detected\n", __func__); if (adxl345_get_fifo_entries(st, &fifo_entries) < 0) - goto done; - } - goto done; -done: + goto err; - if (indio_dev) iio_trigger_notify_done(indio_dev->trig); + } + goto done; +err: + iio_trigger_notify_done(indio_dev->trig); + adxl345_empty_fifo(st); + return IRQ_NONE; + +done: return IRQ_HANDLED; } From patchwork Sun Nov 17 18:26:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13877896 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.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 1E9271DE2AD; Sun, 17 Nov 2024 18:28:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868115; cv=none; b=m+IKgCxOPdzI/RLAuVHcvEi/JnMe9RqG5dmGQJZVD3+ZhaFT61jeh8q3TYZ3o3uxutF4QreK/UxMf/pkpTswbzieGeHwAzWpQAZNqFlAMhCAKde0ZMPomuFZNXIw9Lse/Z7a9OHg1SBrHtXCDAerJPzrgkh+OPniM3t4tSo0niM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868115; c=relaxed/simple; bh=JZlG/xTON17p7l7Hp4Bnp0v9rZe7LzAWNREv7JADzcY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iZuw4Z410Y//Ha7+mvvkTNRB/qqZfl6qwLaWMy0UQkPpR77o5fbnbeseZEeDnuEKP8L+4HadsMjjunzL2eLN5qaDvIfUyDwNXEkGLU3bXkdHWhDO8PZAr8da+udEs6UFJVP4aBqzWlmCLvgLCm7UiDxsftaUPd6QdsjUYs4xmlM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fAUOmzB1; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fAUOmzB1" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-43159469053so1867545e9.2; Sun, 17 Nov 2024 10:28:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731868112; x=1732472912; 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=WoJVYCc5Cph8evW04XEu0kI6t79l5EXNpiq8bQtMDqQ=; b=fAUOmzB1un0cvF3P8zOZKJQ1V4kS3w9ENO6VDCf3JC+VoTmEGpjmltm0jJ2RwFaTfm Ipqv3+TTcODZ7P1RaZ7Z1Z8zjzEvf1mk4x+lB8nn/x7ijq+x0754X8YQd+6LdFQI22JN sq+1HoERUsiCun0/8tLBzmQs8cyyHMrmvwU0NqRrKe7MuhOsibQELYBdJcQHBPbtSp48 iLBL2vlP8zXBjslLE8Q8u9GPFbiKyVxdlasjfH+sP5j3kuzKM6e2w5oMyrDp3ZT7ZUCg AD75KgRnWsYoQ7Bw6MI5jXrxWc6yEfnIN1/TH79nyFt7fsLrXH1rlYFuwOdYLPvb2Oo0 vkaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731868112; x=1732472912; 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=WoJVYCc5Cph8evW04XEu0kI6t79l5EXNpiq8bQtMDqQ=; b=EyDrZQUxIEMHUO9leJobGDB/tcLjDx3skoTI70hc1eNlyh+PdCJQP+wpVjatN/TawQ 0t18agCpuDREDRa13rxKosVoFVCv4cse/ODdmRctj15Pgu5pe1q+gd4aHhfYQrXL4ic1 gFSOWT8gOMMHfOlyJTmy23pvfC5td1aPvre8RUfsVD98NeOpFNm7IiYnDJCYkI72Vyhd xyGbvVMP4UDPxAj9OUHDXgUiRA4zZraZ8tAfW2n+MZycF1Ezitb70ODoitBOjv1qQg1H cwokhaQwuaPx7KRcyzxEY6yBF4Wj4b6e1lyY+9mWWtg8q6wh6F7ME07XGAQv3saMY4zC N9Ow== X-Forwarded-Encrypted: i=1; AJvYcCURSV5MJDzni7JL2Gw/vB/yO2HwyulKau3nQlEIIgR8yarCl/rGKMntMRXpg/K89V1hoIe/KEHgnKdGGyY=@vger.kernel.org X-Gm-Message-State: AOJu0YzHE8X/ET54uECk868ueTULaAyR/lRgoJxbETFR+Xr0ewrYK1IG g7xccEr1b5oDpoFqcJ5uBUtBjn7UBEsomrcpXxW8LOh25YKQpE9c X-Google-Smtp-Source: AGHT+IEplyZrpL4JNBljp9Ae/vlJ8c5dvNSg8cfqnPer89vxT0vzgBthgijy7kM0bQCgyh61pUuy5g== X-Received: by 2002:a05:6000:4808:b0:382:38e6:1eb4 with SMTP id ffacd0b85a97d-38238e6228emr1597165f8f.1.1731868112348; Sun, 17 Nov 2024 10:28:32 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3823f72441bsm3028137f8f.101.2024.11.17.10.28.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Nov 2024 10:28:32 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v2 16/22] iio: accel: adxl345: register trigger ops Date: Sun, 17 Nov 2024 18:26:45 +0000 Message-Id: <20241117182651.115056-17-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241117182651.115056-1-l.rubusch@gmail.com> References: <20241117182651.115056-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add trigger options to the sensor driver. Reacting to the sensor events communicated by IRQ, the FIFO handling and the trigger will be core events for further feature implementation. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 82bd5c2b78..d58e1994ff 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -15,6 +15,9 @@ #include #include +#include +#include +#include #include #include #include @@ -140,11 +143,13 @@ struct adxl34x_state { const struct adxl345_chip_info *info; struct regmap *regmap; struct adxl34x_platform_data data; /* watermark, fifo_mode, etc */ + struct iio_trigger *trig_dready; __le16 fifo_buf[3 * ADXL34x_FIFO_SIZE] __aligned(IIO_DMA_MINALIGN); u8 int_map; bool fifo_delay; /* delay: delay is needed for SPI */ u8 intio; + bool watermark_en; }; #define ADXL34x_CHANNEL(index, reg, axis) { \ @@ -432,6 +437,35 @@ static int adxl345_get_status(struct adxl34x_state *st, u8 *int_stat) return 0; } +/* data ready trigger */ + +static int adxl345_trig_dready(struct iio_trigger *trig, bool state) +{ + struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); + struct adxl34x_state *st = iio_priv(indio_dev); + + st->int_map = 0x00; + if (state) { + /* Setting also ADXL345_INT_DATA_READY results in just a single + * generated interrupt, and no continuously re-generation. NB that the + * INT_DATA_READY as well as the INT_OVERRUN are managed automatically, + * setting their bits here is not needed. + */ + if (st->watermark_en) + st->int_map |= ADXL345_INT_WATERMARK; + + pr_debug("%s(): preparing st->int_map 0x%02X\n", + __func__, st->int_map); + } + + return 0; +} + +static const struct iio_trigger_ops adxl34x_trig_dready_ops = { + .validate_device = &iio_trigger_validate_own_device, + .set_trigger_state = adxl345_trig_dready, +}; + /** * irqreturn_t adxl345_trigger_handler() - Interrupt handler used for several * features of the ADXL345. From patchwork Sun Nov 17 18:26:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13877897 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 D4FE51DE2C0; Sun, 17 Nov 2024 18:28:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868116; cv=none; b=ui3tZMxcC/F897CLd3wd/mlXnkfsGjkfXnDIDAqP1OA9vpZHn5V0+Oxi22qhlCyPVz1HvKj9cUBcogHonTRFwkg+46vTfAmgt+2x4dPXwsgNObaRmD80uhlQMuuIu/zSyQ+PeECT3q4JpwKGlBaiKwqyPe6r4DG1xyUMfZhJKwM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868116; c=relaxed/simple; bh=9ir+vZ/Jv17LXPmR9NGO3MPEoIMmnrvZ2uBx90jwVSg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LkJs4syXQ53Za5p1HdK/HwDjGSuFQbqsuxu1Lx3FiE/dVS02CrDb8rDIvz81mqdEAn98GVw3U7wlhJkHOXhVq2zx31VilrJQxb1H1pXoo6DC9BivIWvMOobxSe/UdaBMPwUIr6LKFzzpXKBeoGq5cxq3IeQ9DTEwJfCyQzJsseU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DsF4V0t1; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DsF4V0t1" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4315ce4d250so2222015e9.2; Sun, 17 Nov 2024 10:28:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731868113; x=1732472913; 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=uB5mGB45X+RMJ3zhFxUgvKmYS4xbQci0s/JjGj03ZEo=; b=DsF4V0t14q+kbl2wiEnstNxCp+dTXPbG8RNMrEeQbVT/4P+RSJ4fq8HKYlzEMGX6QL E3/f4XoqUEwDKVgd+dolaVlZSbGCd4Y1ZZZcxiDTrXDcRvqa3s0JPwZIzE/9rYdoDNoc 1/XhCUbsraBsE+1vJmp0TXgtVNG6+15tx1zQPZa0UNXCsJkuFs2pErMRiPYD8CytxGWS ZbLWnCcUVOLy+hiqf/nAYcqYCxEyLi3cJqrkKgWfhKDxlsoNWmxhEAdoyxVABtJTZsdN BVcLfAxqjrxdWFzw4/86D5FTIU8Kfy18eyGZbL5Pk9CftXlVqGIqUBz6PRq7voRlzzpm yu6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731868113; x=1732472913; 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=uB5mGB45X+RMJ3zhFxUgvKmYS4xbQci0s/JjGj03ZEo=; b=RR+233ezK3wWOlzm98NWcurYbqs9waccsHntuYm+q3LxNqH6nM6/pM0TGUPmzN26hz k5JuBFHDeGMjCNMkCLNdftSrklrp5+w4c2bWUJRB3qEVkwVg1ltw1x+JRwgFfJaNVhGv Mj4ByAkGDvjlfGKX76Uk8x2f26wRR0vDJh0ErMnjv3ZpW0a5P4VPNteSkMMGft54q1Nz 2jeKmwD/7uuUWU3rOv9R4Ma0ZrsdbO0JVqHTl09QCHZsv3pNBaGJHu+FyfoCdGt4QdGk MuAwM1YMPfvt2Gx9FzYbEil+dRkXtoKKMjgXxpvB32ABDATSapTtK+GqJwtoLb8mBkiF 4CKA== X-Forwarded-Encrypted: i=1; AJvYcCUK+zDng3aGNs+8wKDMnm7V/OGwWLHzZQfgCqBfboXNjTq4E83ceXQRq7mJs2v6KtWWXbxCdze2Rok7Ei0=@vger.kernel.org X-Gm-Message-State: AOJu0YxOuAsQ7Pe43kPbhYi+Kj+yr0QV4MQr6U19mF6n1AvZrEvkb8WN JJW3gL4Hre/u08/ZQfxGsVBDdksm/KmJP3Zoo+dMI+ZXTVTXGssy X-Google-Smtp-Source: AGHT+IES29fz+Nj1hxjCALIePv1MBZEWxRWn/hH0czGtFUDPHEDVmL83nGkXai09po8DzcAUJFj02w== X-Received: by 2002:a5d:5f4b:0:b0:37c:d0d6:ab1a with SMTP id ffacd0b85a97d-38225a92b39mr3254337f8f.12.1731868113187; Sun, 17 Nov 2024 10:28:33 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3823f72441bsm3028137f8f.101.2024.11.17.10.28.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Nov 2024 10:28:32 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v2 17/22] iio: accel: adxl345: push FIFO data to iio Date: Sun, 17 Nov 2024 18:26:46 +0000 Message-Id: <20241117182651.115056-18-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241117182651.115056-1-l.rubusch@gmail.com> References: <20241117182651.115056-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add FIFO and hwfifo handling. Add some functions to deal with FIFO entries and configuration. This feature will be needed for e.g. watermark setting. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index d58e1994ff..a653774db8 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -437,6 +437,41 @@ static int adxl345_get_status(struct adxl34x_state *st, u8 *int_stat) return 0; } +static int adxl345_push_fifo_data(struct iio_dev *indio_dev, + u8 status, + int fifo_entries) +{ + struct adxl34x_state *st = iio_priv(indio_dev); + int ndirs = 3; /* 3 directions */ + int i, ret; + + if (fifo_entries <= 0) + return true; + + ret = adxl345_read_fifo_elements(st, fifo_entries); + if (ret) + return false; + + for (i = 0; i < ndirs * fifo_entries; i += ndirs) { + /* To ensure that the FIFO has completely popped, there must be at least 5 + * us between the end of reading the data registers, signified by the + * transition to register 0x38 from 0x37 or the CS pin going high, and the + * start of new reads of the FIFO or reading the FIFO_STATUS register. For + * SPI operation at 1.5 MHz or lower, the register addressing portion of the + * transmission is sufficient delay to ensure the FIFO has completely + * popped. It is necessary for SPI operation greater than 1.5 MHz to + * de-assert the CS pin to ensure a total of 5 us, which is at most 3.4 us + * at 5 MHz operation. + */ + if (st->fifo_delay && (fifo_entries > 1)) + udelay(3); + + iio_push_to_buffers(indio_dev, &st->fifo_buf[i]); + } + + return true; +} + /* data ready trigger */ static int adxl345_trig_dready(struct iio_trigger *trig, bool state) @@ -508,6 +543,9 @@ static irqreturn_t adxl345_trigger_handler(int irq, void *p) if (adxl345_get_fifo_entries(st, &fifo_entries) < 0) goto err; + if (adxl345_push_fifo_data(indio_dev, int_stat, fifo_entries) < 0) + goto err; + iio_trigger_notify_done(indio_dev->trig); } From patchwork Sun Nov 17 18:26:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13877898 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8F461DE3A0; Sun, 17 Nov 2024 18:28:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868117; cv=none; b=k/uBtUFyt7mvWgPTixxkek9tM3cvitgmhdhCjtHpS/CDPfcycEIk15swbi4THnvL2K/aRtEG9nmyK19NZ5mDke3EjhSJFz5HWdJLR+50qtDZHDh83YxPfrR25PgLD3MxFymrrU42cbZRPIntaPu94vAqpTBvWwQhWBqKv5TqwQw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868117; c=relaxed/simple; bh=Uh0ywoa2bWeGJVOO8oOQGygArU/+BUOqW+Ji8r6tx1c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iR9gMtrilixYdjHEvHiB1rLOLnIryqrkWlfZF8Y5Rxzcxj5m6tqHwlPSlYd0nwXRorcBB+JNgAWiQFFKQiDpzamxpoyjVQLQ0ZJXNiUkAMRBzc4KJP814+cKz9WNZCXupSkVN18pT/IqHIFiq+Lr+Lw5OdwCxTwd9e1Ad8Wu6pU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=STZ6xF92; arc=none smtp.client-ip=209.85.221.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="STZ6xF92" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-38242100504so60979f8f.1; Sun, 17 Nov 2024 10:28:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731868114; x=1732472914; 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=nyKdvt/ICGRAgRqip6b9GeQ/e4pq/PhL8HJQ2mj2JdA=; b=STZ6xF92ydRJIEgynf+g5YYd1gLlDBj1SYaZvceDe9B+tWRrk+eVweAwEs7J6DDLCf FrImUCK2LNnTs5OltJSJEcEwiT+vYqleq717CG+5z9y0LIACyLyDqBWcr+SfoTe4G4k/ /939Rn2RR+q691V3NG+aMRmhL1YLOLnGZisuPhtzmt9bNqXyF6j1Ij2DxW5fHfBuJld0 XevpdwBAXexp1s2it74lqkdyljLO5iEwcF9l2Rhjm3rXsnVm2Z19iVkq5mO+N8jPWfWc 6okycpQoAw52+Bbh0b4cYUaCQ0UoJDbja61nnIcSb5Tbcn2PsZzYrO3uNengC0I4D0NI vjfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731868114; x=1732472914; 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=nyKdvt/ICGRAgRqip6b9GeQ/e4pq/PhL8HJQ2mj2JdA=; b=hImjRisylzpRVkiht7bKqAiPQaFfhPsPyXVF6CQkyQPitsdyxNsqDfS0w9f2UfcMcZ HqZIPFNBBAGEHnKhiCaDjvdmLHloRvgH5+xPulyR6QEabBYUSuSPeLFipllgRUdFCTnI h/OYtRGyhAIvOAWJwWXqgBHAOPln3w8HR5O/YcWiQJ/1T8shTL7oPJBREEeRJhJv7w8L Y/pCG2vmy4Wt1VfDy8HR4ANNLYAAKCyqeoseFJQtM58AoRnu2r0T7GsdwPzQdOG4L7wG vfQNSn/RvGUxgaysObc8ATYBG1XVyR53IYawrTqrqow5hhS/4YRvQItn+uEGYZQWqGQK of/g== X-Forwarded-Encrypted: i=1; AJvYcCUQbOZ+7LiuBI9lsIYLIaH+4sZtUIIy405cKH32XLXVM6cJULS0GNcC+tKWCOQdCFyDX9I7oFT3vAQZlkA=@vger.kernel.org X-Gm-Message-State: AOJu0YxQ9tvFldLS3L+iIsT6IwdWxNNGrrbYMjsX8fAkoLLckQtF+6OM i5lYuqLSP9pGcQ8Fp/w2Hu1yLa7IoR75Nm3B3cn5vE9bvWdWHP/q X-Google-Smtp-Source: AGHT+IFZ5g4xBvWHfhoyu7iiS7c4kPCFddWHohSvEYyrOP9k4kQM3dLIHvRHlSdEfbFlSlqrnNujTg== X-Received: by 2002:a05:6000:2ca:b0:382:42c3:83f7 with SMTP id ffacd0b85a97d-38242c385damr813764f8f.10.1731868114192; Sun, 17 Nov 2024 10:28:34 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3823f72441bsm3028137f8f.101.2024.11.17.10.28.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Nov 2024 10:28:33 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v2 18/22] iio: accel: adxl345: start measure at buffer en/disable Date: Sun, 17 Nov 2024 18:26:47 +0000 Message-Id: <20241117182651.115056-19-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241117182651.115056-1-l.rubusch@gmail.com> References: <20241117182651.115056-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add and initialize the buffer options to use the FIFO and watermark feature of the adxl345 sensor. In this way measure enable will happen in at enabling the buffer. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 105 +++++++++++++++++++++++++++++-- 1 file changed, 101 insertions(+), 4 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index a653774db8..b57a123ac9 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -181,6 +181,28 @@ static const struct iio_chan_spec adxl34x_channels[] = { ADXL34x_CHANNEL(2, chan_z, Z), }; +static int adxl345_set_interrupts(struct adxl34x_state *st) +{ + int ret; + unsigned int int_enable = st->int_map; + unsigned int int_map; + + /* Any bits set to 0 in the INT map register send their respective + * interrupts to the INT1 pin, whereas bits set to 1 send their respective + * interrupts to the INT2 pin. The intio shall convert this accordingly. + */ + int_map = 0xFF & (st->intio ? st->int_map : ~st->int_map); + pr_debug("%s(): Setting INT_MAP 0x%02X\n", __func__, int_map); + + ret = regmap_write(st->regmap, ADXL345_REG_INT_MAP, int_map); + if (ret) + return ret; + + pr_debug("%s(): Setting INT_ENABLE 0x%02X\n", __func__, int_enable); + ret = regmap_write(st->regmap, ADXL345_REG_INT_ENABLE, int_enable); + return ret; +} + static int adxl345_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) @@ -330,6 +352,41 @@ static const struct attribute_group adxl345_attrs_group = { .attrs = adxl345_attrs, }; +static int adxl345_set_fifo(struct adxl34x_state *st) +{ + struct adxl34x_platform_data *data = &st->data; + u8 fifo_ctl; + int ret; + + /* FIFO should be configured while in standby mode */ + adxl345_set_measure_en(st, false); + + /* The watermark bit is set when the number of samples in FIFO + * equals the value stored in the samples bits (register + * FIFO_CTL). The watermark bit is cleared automatically when + * FIFO is read, and the content returns to a value below the + * value stored in the samples bits. + */ + fifo_ctl = 0x00 | + ADXL345_FIFO_CTL_SAMLPES(data->watermark) | + ADXL345_FIFO_CTL_TRIGGER(st->intio) | + ADXL345_FIFO_CTL_MODE(data->fifo_mode); + + pr_debug("%s(): fifo_ctl 0x%02X\n", __func__, fifo_ctl); + + /* The watermark bit is set when the number of samples in FIFO + * equals the value stored in the samples bits (register + * FIFO_CTL). The watermark bit is cleared automatically when + * FIFO is read, and the content returns to a value below the + * value stored in the samples bits. + */ + ret = regmap_write(st->regmap, ADXL345_REG_FIFO_CTL, fifo_ctl); + if (ret < 0) + return ret; + + return adxl345_set_measure_en(st, true); +} + /** * adxl345_get_fifo_entries() - Read number of FIFO entries into *fifo_entries. * @st: The initialized state instance of this driver. @@ -416,7 +473,50 @@ static void adxl345_empty_fifo(struct adxl34x_state *st) regmap_read(st->regmap, ADXL345_REG_INT_SOURCE, ®val); } +static int adxl345_buffer_postenable(struct iio_dev *indio_dev) +{ + struct adxl34x_state *st = iio_priv(indio_dev); + struct adxl34x_platform_data *data = &st->data; + int ret; + + ret = adxl345_set_interrupts(st); + if (ret) + return -EINVAL; + + /* Default to FIFO mode: STREAM, since it covers the general usage + * and does not bypass the FIFO + */ + data->fifo_mode = ADXL_FIFO_STREAM; + adxl345_set_fifo(st); + + return 0; +} + +static int adxl345_buffer_predisable(struct iio_dev *indio_dev) +{ + struct adxl34x_state *st = iio_priv(indio_dev); + struct adxl34x_platform_data *data = &st->data; + int ret; + + /* Turn off interrupts */ + st->int_map = 0x00; + + ret = adxl345_set_interrupts(st); + if (ret) { + pr_warn("%s(): Failed to disable INTs\n", __func__); + return -EINVAL; + } + + /* Set FIFO mode: BYPASS, according to the situation */ + data->fifo_mode = ADXL_FIFO_BYPASS; + adxl345_set_fifo(st); + + return 0; +} + static const struct iio_buffer_setup_ops adxl345_buffer_ops = { + .postenable = adxl345_buffer_postenable, + .predisable = adxl345_buffer_predisable, }; static int adxl345_get_status(struct adxl34x_state *st, u8 *int_stat) @@ -625,7 +725,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, indio_dev->name = st->info->name; indio_dev->info = &adxl345_info; - indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE; indio_dev->channels = adxl34x_channels; indio_dev->num_channels = ARRAY_SIZE(adxl34x_channels); @@ -685,9 +785,6 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, ret = regmap_write(st->regmap, ADXL345_REG_FIFO_CTL, fifo_ctl); if (ret < 0) return ret; - - /* Enable measurement mode */ - adxl345_set_measure_en(st, true); } dev_dbg(dev, "Driver operational\n"); return devm_iio_device_register(dev, indio_dev); From patchwork Sun Nov 17 18:26:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13877899 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 BADED1DB546; Sun, 17 Nov 2024 18:28:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868118; cv=none; b=XUUShoMHe5yS/v/yTCB+gQ2xqXFSOcSXUIcg2WUVGIXzt1nEu5P+12vNPKtl2SS9NRGJdTaNrD6+FV1Hp+UoP/Ofxl2n8UJjS8NMVC0X1wWFM/jv/L72fSHR7AmLT2XaGqSWcXpVojMpvPI3JWR1yj2Nia7JxZ29P5Ott8JwjZQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868118; c=relaxed/simple; bh=FJa+BezbGPvPK7+Lh6efUwtb5l4qmZJ2kHSzKX3W0Cg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LFBMax2hmo5/Qgi6BsqC0epoCzD5Uzze4DHrXIQ7tTRlGK6ohG8NyCvR7uyuU7pU0g3VyRzhx8AhmrAcLNgWm8QuTsgcTSPfkmjdATd07gIjQ1K4ZsT6k9TLVHHAsXC+Q6mV3Tf1isotvzP8VGT2QIxfME8hjZ5KlBWqRZ+HUWM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BImxTpUc; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BImxTpUc" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4315b0bd4ddso3683955e9.3; Sun, 17 Nov 2024 10:28:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731868115; x=1732472915; 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=AuFWDVSr0TH1qAG16py992MdgJFvQfRVNyd51fPsQGM=; b=BImxTpUcBiQ36g6zfB7GwGrYLaYlK6Pu7h4Zfqa78TX7yUanmx1GM7ZWF9u9Z1AKwH WZ2HbH/4kO6iz6M4mmszm7Q9x+G3O2mxBiGfH/kvcje9hyt2cz2+QtKc7xr82rc74Si4 lbdlo7pId6nykk4EjsFuSbgTq2mDbeBvUWsIk3bjLowqW2HLRztHTtw3IjGLXzAhmLSZ Ne2DpNzskEs5yUKTVoHW5zAin2Xfu0OWSWorcJxggm+O0U4vHLtUfrUA2vCkO4Dc5NjN BGFbVtEvRDYctnpL1SQZnSsYyU+yRlCDpP3j1DcFUPRm/DcBNFOdrmyYeFW+xd4uqv8F n/7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731868115; x=1732472915; 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=AuFWDVSr0TH1qAG16py992MdgJFvQfRVNyd51fPsQGM=; b=uELDLnlQsoS/lq6p72MTMrb+RMjPxDi+DoBEsybNyqVcD2Vij3qeBhh7GbYdXjDG7d 3yqmg9uEoaJ1BSVL5PiUXMsRNOaOhRjsAotVt0q7jjeIR0kkI9+Vpg65jjN+yLgqPcX/ NbGhYXBP9Ym+vObwaEao23icomSiDBF51FFbJQErZMfd9pxlPX2Xi4aSfySO9n8lQkar JaFYe04fCY0fW7ZRqHVc9cjy7/zxgyk9G1auPtxyA8qd21yLStZAU7DRcO8wGhGSY0rz xsec8L1ajy5KysztIybEfgGN0qt46vft8lk+IsV0a/o1YQVA+r8Hogf/YgKlgAgBSMgx zvDg== X-Forwarded-Encrypted: i=1; AJvYcCUqmN6DKjNhwAZ2eZjClFl7I9KPkE5H4VPlGT0xduXa0Nr+P2VhJ8PVoBjfaLnYLY+mu9Bimrpqjq8bFHE=@vger.kernel.org X-Gm-Message-State: AOJu0YzRPG3sYQc8jGvl6MDqOABhyO4IvPDvJMr5wO+Fqqj8hOH+YuDo KDAyLEO/1pmzPiI99o69wZzvPl6x/E3m3wNGcOawGeySIfxk1a7Q X-Google-Smtp-Source: AGHT+IGmV5mhFROTH/8fZc+TO/kHurvSvIfZfrAaAwWv7OXGY+E7ZcdQp6DrCP6KKhIHJDlVef6Glw== X-Received: by 2002:a05:600c:45d4:b0:431:5632:4480 with SMTP id 5b1f17b1804b1-432df793c51mr35023695e9.6.1731868115057; Sun, 17 Nov 2024 10:28:35 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3823f72441bsm3028137f8f.101.2024.11.17.10.28.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Nov 2024 10:28:34 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v2 19/22] iio: accel: adxl345: prepare FIFO watermark handling Date: Sun, 17 Nov 2024 18:26:48 +0000 Message-Id: <20241117182651.115056-20-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241117182651.115056-1-l.rubusch@gmail.com> References: <20241117182651.115056-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add the feature of the adxl345 and related sensors to manage a FIFO in stream mode by a watermark level. Provide means to set the watermark through the IIO api and sysfs interface. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 94 ++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index b57a123ac9..f7b937fb16 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -288,6 +288,26 @@ static int adxl345_write_raw(struct iio_dev *indio_dev, return -EINVAL; } +static int adxl345_set_watermark(struct iio_dev *indio_dev, unsigned int value) +{ + struct adxl34x_state *st = iio_priv(indio_dev); + struct adxl34x_platform_data *data = &st->data; + unsigned int fifo_mask = 0x1F; + int ret; + + if (value > ADXL34x_FIFO_SIZE) + value = ADXL34x_FIFO_SIZE; + pr_debug("%s(): set watermark to 0x%02x\n", __func__, value); + + ret = regmap_update_bits(st->regmap, ADXL345_REG_FIFO_CTL, + fifo_mask, value); + if (ret) + return ret; + + data->watermark = value; + return 0; +} + static int adxl345_write_raw_get_fmt(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, long mask) @@ -335,7 +355,76 @@ static void adxl345_powerdown(void *ptr) adxl345_set_measure_en(st, false); } +/* fifo */ + +static ssize_t adxl345_get_fifo_enabled(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct adxl34x_state *st = iio_priv(indio_dev); + struct adxl34x_platform_data *data = &st->data; + + return sysfs_emit(buf, "%d\n", data->fifo_mode); +} + +static ssize_t adxl345_get_fifo_watermark(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct adxl34x_state *st = iio_priv(indio_dev); + struct adxl34x_platform_data *data = &st->data; + + return sprintf(buf, "%d\n", data->watermark); +} + +static ssize_t watermark_en_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct adxl34x_state *st = iio_priv(indio_dev); + + return sysfs_emit(buf, "%d\n", st->watermark_en); +} + +static ssize_t watermark_en_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct adxl34x_state *st = iio_priv(indio_dev); + bool val; + + if (kstrtobool(buf, &val)) + return -EINVAL; + st->watermark_en = val; + return len; +} + +/* + * NB: The buffer/hwfifo_watermark is a read-only entry to display the + * currently set hardware FIFO watermark. First set a value to buffer0/length. + * This allows to configure buffer0/watermark. After enabling buffer0/enable + * the hwfifo_watermark shall show the configured FIFO watermark value. + * + * ref: Documentation/ABI/testing/sysfs-bus-iio + */ +IIO_STATIC_CONST_DEVICE_ATTR(hwfifo_watermark_min, "1"); +IIO_STATIC_CONST_DEVICE_ATTR(hwfifo_watermark_max, + __stringify(ADXL34x_FIFO_SIZE)); +static IIO_DEVICE_ATTR(hwfifo_watermark, 0444, + adxl345_get_fifo_watermark, NULL, 0); +static IIO_DEVICE_ATTR(hwfifo_enabled, 0444, + adxl345_get_fifo_enabled, NULL, 0); + +static IIO_DEVICE_ATTR_RW(watermark_en, 0); + static const struct iio_dev_attr *adxl345_fifo_attributes[] = { + &iio_dev_attr_hwfifo_watermark_min, + &iio_dev_attr_hwfifo_watermark_max, + &iio_dev_attr_hwfifo_watermark, + &iio_dev_attr_hwfifo_enabled, NULL, }; @@ -345,6 +434,7 @@ static IIO_CONST_ATTR_SAMP_FREQ_AVAIL( static struct attribute *adxl345_attrs[] = { &iio_const_attr_sampling_frequency_available.dev_attr.attr, + &iio_dev_attr_watermark_en.dev_attr.attr, NULL }; @@ -664,6 +754,7 @@ static const struct iio_info adxl345_info = { .read_raw = adxl345_read_raw, .write_raw = adxl345_write_raw, .write_raw_get_fmt = adxl345_write_raw_get_fmt, + .hwfifo_set_watermark = adxl345_set_watermark, }; /** @@ -721,6 +812,9 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, /* some reasonable pre-initialization */ st->data.act_axis_control = 0xFF; + /* default is all features turned off */ + st->watermark_en = 0; + st->intio = ADXL345_INT1; indio_dev->name = st->info->name; From patchwork Sun Nov 17 18:26:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13877900 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (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 623AB1DE4DA; Sun, 17 Nov 2024 18:28:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868120; cv=none; b=f9meixw2RiFVjsnFpPPZcJdt3NO1uC74L8fCz+Kj9i9vgtJLKM6A7xw+OlVRGW56/Dkvk1QQ/Vh2KP/AlzYFyqj1afVBEtV8aa+jd0GXuJ/ZDrgLf75LvA6b79Fx6cdwI3ShV68ER6pLVHswdB2niJU3v8iAQL7ZmEdRUI/PNis= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868120; c=relaxed/simple; bh=6/0DwltEUb1r+bPdI+XsZRMVxWyPtCMYqzrHqPidDLY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=C64I8qGMGcAz9I2BCSTA3GLBsydUVlzMi66GefCdEbLO6jiwbMmu9gyishVrgn4Cs3OWpiXDBEwjio22QIpD9y5UTTuWVX5USyCAtOA6/+PVLWevffSRPruRIGm5bRBMRUkS77/16OsU+Wgw/HtMID1wQmt2kBl3R6GDwZicU/E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lGw6QPiS; arc=none smtp.client-ip=209.85.221.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lGw6QPiS" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-38242100504so60980f8f.1; Sun, 17 Nov 2024 10:28:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731868117; x=1732472917; 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=+0jDVowXCEL7M7LDBhaoZbZ0uKb3vpVkttp/faRKS9w=; b=lGw6QPiSw8Nlab3TqiBOdrxi7hYvkPUiG8WaET1LGM50kctCzd+GEigGw9+2+9k9vI cOIujhFVW8TkSWcz0TRTRgc1CHyYhuPTqQZftAMemt2j/AjXhv6OaUGFz2BOPbEreHEC P9OXkMC8+UHaDuNWe1wfMiYXW3Z26wK8Y4OFfZQ9qBP0ZuUZZMaPzMQJMECywz7ajwLy oH6NrockvEwkM1i96zm4QtAELzjzb7ZbbZ8TWRIix91x/pi5WOayGEx4romGJ9jdDM0M HAdms/nt5pPj+STwOUuKEIcH8axKHmD2VBCyxryGfD8shPyOUBzvdmabOkcy1wkue+m4 Uo8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731868117; x=1732472917; 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=+0jDVowXCEL7M7LDBhaoZbZ0uKb3vpVkttp/faRKS9w=; b=ZqyjKJYnmf60/F5Eixzez0r8GKFUT6P6lHajpw517BD1Zsnzr5xNfVC6AX8zyJtvf1 smxpdpjD0/TTtzludjDd74gYsqktGiSA7F5cWDrt0D/WQkt6G6wnKRqzxkF8j6EyG57s cFN4ammztQa/EairgPFFKg/LQXxG/aFfJ0tl6TB8+Gaoidg/P/Qm1QhtpafDWKlrSkmW lGJ/EzTu0DN1FE5dTzbbUUlQDudmktjZ90fmWmw7fZntJKNwuiT3rChxKdrMzzaj4xM5 SDFBSezeZnk70ADBSr2xBQyZEbZFO/S/aaEU8grSfkoTNJ/xRBY04u4OLZwNkolFiEAP V+RA== X-Forwarded-Encrypted: i=1; AJvYcCUcr3438M+YVXEMcYpLDgvkbKoILFO0MwzGD5PvnR8ayRpLzHOJm0VuL7Vpu7dzh3YeEUueDfRzWwZDLpw=@vger.kernel.org X-Gm-Message-State: AOJu0YxtdNcDEVAZvYEhDj5sjjAyC0dl8Vw06jzbShz5VMcQeCHxc1sY m2d90Bpa2SFHJwLr95EAXMEzU28blUIIH9nA0aAECjuLNrqW/yeU X-Google-Smtp-Source: AGHT+IFPk2sLRl6XUuJUTITQ+rjKOPPRT9AhnCwgKB21M2FrzSP6gkJC4XF45wUN3a9IEq5LJW9p0g== X-Received: by 2002:a5d:6c69:0:b0:37d:54d0:1f15 with SMTP id ffacd0b85a97d-38225a04715mr3045657f8f.7.1731868116592; Sun, 17 Nov 2024 10:28:36 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3823f72441bsm3028137f8f.101.2024.11.17.10.28.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Nov 2024 10:28:36 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v2 20/22] iio: accel: adxl345: use FIFO with watermark IRQ Date: Sun, 17 Nov 2024 18:26:49 +0000 Message-Id: <20241117182651.115056-21-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241117182651.115056-1-l.rubusch@gmail.com> References: <20241117182651.115056-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Enable the watermark feature of the adxl345 sensor. The feature uses a FIFO to be configured by the IIO fifo sysfs handles. The sensor configures the FIFO to streaming mode for measurements, or bypass for configuration. The sensor issues an interrupt on the configured line to signal several signals (data available, overrun or watermark reached). The setup allows for extension of further features based on the interrupt handler and the FIFO setup. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index f7b937fb16..07c336211f 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -870,6 +870,45 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, if (ret) return dev_err_probe(dev, ret, "Failed to setup triggered buffer\n"); + dev_dbg(dev, "IRQ: allocating data ready trigger\n"); + st->trig_dready = devm_iio_trigger_alloc(dev, + "%s-dev%d-dready", + indio_dev->name, + iio_device_id(indio_dev)); + if (!st->trig_dready) + return dev_err_probe(dev, -ENOMEM, + "Failed to setup triggered buffer\n"); + dev_dbg(dev, "IRQ: allocating data ready trigger ok\n"); + + st->trig_dready->ops = &adxl34x_trig_dready_ops; + dev_dbg(dev, "IRQ: Setting data ready trigger ops ok\n"); + + iio_trigger_set_drvdata(st->trig_dready, indio_dev); + dev_dbg(dev, "IRQ: Setting up data ready trigger as driver data ok\n"); + + ret = devm_iio_trigger_register(dev, st->trig_dready); + if (ret < 0) + return dev_err_probe(dev, ret, + "Failed to register dready trigger\n"); + dev_dbg(dev, "Registering data ready trigger ok\n"); + + indio_dev->trig = iio_trigger_get(st->trig_dready); + + dev_dbg(dev, "Requesting threaded IRQ, indio_dev->name '%s'\n", + indio_dev->name); + + ret = devm_request_threaded_irq(dev, st->irq, + iio_trigger_generic_data_rdy_poll, + NULL, + IRQF_TRIGGER_RISING | IRQF_ONESHOT, + indio_dev->name, st->trig_dready); + if (ret < 0) + return dev_err_probe(dev, ret, "Failed to request IRQ handler\n"); + dev_dbg(dev, "Requesting threaded IRQ handler ok\n"); + + /* Cleanup */ + adxl345_empty_fifo(st); + } else { /* Initialization to prepare for FIFO_BYPASS mode (fallback) */ /* The following defaults to 0x00, anyway */ From patchwork Sun Nov 17 18:26:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13877901 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.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 450411DDC3B; Sun, 17 Nov 2024 18:28:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868120; cv=none; b=dhgk9icyYV/uBWmYXMNNSsWjI1aTGm0HQDw2Q+CL8IYZBbVLddgCp7EUd1t5O5hfnzmxuQcm7BmqfFtM1OdLJfdaTpPrMKefde2N1G7X7aym4hA2lT0qU/H4aYSMXtjY/ZCBHR404UorX6eOTbEi8t961/EbB+3tRMBVe90RSKQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868120; c=relaxed/simple; bh=YLkm6mn91SUYqJEfuee5sOiFr8W1kHKnBkYkooecUUU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=C3AQI681ZLlDSZWq/eswXsf3PImbnza/PhU7otyWUeS26Bo6advaaq4VFscb2oMDWCI4mAXvUrwERWPVsgGJJzIhoeum3tqiMTDykK2LpTgsVORsj6ksrrGqKtp8wCeVvvEoA33kMr3cp9i/sWO8W/GWLHki/yHBD1lGiX4RfdE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WNGuLPMm; arc=none smtp.client-ip=209.85.221.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WNGuLPMm" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-3822e64b2d8so110363f8f.2; Sun, 17 Nov 2024 10:28:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731868118; x=1732472918; 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=WI7RJ0jF3aLy07BJRiIYtdRjEbCy8KHwX14SXuqyAVQ=; b=WNGuLPMmuEO8Unx9slLX6CG/XfHHbXyO1SgKdpJbts8yn6DdSDcsJ1g6DWMzyKc0hu J98hNKnbC51x1Bc6niCcIxAaXW3x6MOvr3iuatbxl7pJHBpmPUeBO0W0w7cuqwr/0Cn2 V00j/CJXpwTqt7cg2D6YuQqQtkMlLFRoU4ntDbSZitekR95quNgVUqmqTA46c6jzZb1X LLt6WUPuvWp4Cp973O4DBVGjbZ1eTmlFzhjAZdG3GUSqXfdH1X4kcXF4qCr1LXkYAdFh ItyjZR3tTKQAGrgJRWH6fbIciA6XF3XKY5tDof+v9BluzPfMNsojyB1bz0Y4Y+mXRHVp pnbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731868118; x=1732472918; 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=WI7RJ0jF3aLy07BJRiIYtdRjEbCy8KHwX14SXuqyAVQ=; b=RAmV1jGZLcxZXdpJ4jpFZCxo61BgIeR3vDub3P+HvYbwS/W+Q9Sq6YLYaAAbFkhTw2 3WsZJkjxBu5Lnvm2AZtBUQ9MINcmDB0pDn7W/n3NatDCXCDUyvYlWtRqIHSYI2+0ipd7 EqiVse2kHvCjaMnDJgrxjd17nJNL8hIFMd6ptUQjYZPdisqL6XCxD/2BcL9LJ0EvBi3F PmgpMDWBmnC9dmRuPRROubutVa6vS/HaG7zHFZsACA2TD02ilYr4/dwINYM19Hkt/Pwe 8zPzFJqYHraZ3u3T0By9STmWBXcj2Y69Fu4WM3vck0YPA85EwgkHppN/YIUV6uvTm5ZV ddhA== X-Forwarded-Encrypted: i=1; AJvYcCWfIxjN6kVpV/KREHCOpSdO3VJxnpWBIOSWLoLdcHA/4otwAKJeERpY2gyN//1B1FICRYY1tmNxd0mMYS4=@vger.kernel.org X-Gm-Message-State: AOJu0YxAVb5saxoQtm+RB2IyLnzEh5vMVEbgMQ0zDE4zX9mgFpmkhCWO fWdxbqoHayu3SE6Ffxr9JzrSer6s3kxIdCXjjHXlgn+TvrMAyBvD X-Google-Smtp-Source: AGHT+IHWoki2ndPtcJuR0/9t1Um4iS6pYJkodJ0sK7bAHT5HE9xEPNGHDiab/51eSX3up4nn/7r76Q== X-Received: by 2002:a5d:584b:0:b0:382:1c58:579d with SMTP id ffacd0b85a97d-38225a04ac3mr3554543f8f.8.1731868117566; Sun, 17 Nov 2024 10:28:37 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3823f72441bsm3028137f8f.101.2024.11.17.10.28.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Nov 2024 10:28:37 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v2 21/22] iio: accel: adxl345: sync FIFO reading with sensor Date: Sun, 17 Nov 2024 18:26:50 +0000 Message-Id: <20241117182651.115056-22-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241117182651.115056-1-l.rubusch@gmail.com> References: <20241117182651.115056-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Pause the measurement while reading fifo values. Initially an interrupt is triggered if watermark of the FIFO is reached, or in case of OVERRUN. The sensor stays mute until FIFO is cleared and interrupts are read. Situations now can arise when the watermark is configured to a lower value. While reading the values, new values arrive such that a permanent OVERRUN state of the FIFO is reached, i.e. either the FIFO never gets emptied entirely because of permanently new arriving measurements. No more interrupts will be issued and the setup results in OVERRUN. To avoid such situation, stop measuring while solving an OVERRUN condition and generally reading FIFO entries. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 07c336211f..c79f0f5e3b 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -730,6 +730,11 @@ static irqreturn_t adxl345_trigger_handler(int irq, void *p) if (int_stat & (ADXL345_INT_DATA_READY | ADXL345_INT_WATERMARK)) { pr_debug("%s(): WATERMARK or DATA_READY event detected\n", __func__); + + /* Pause measuring, at low watermarks this would easily brick the + * sensor in permanent OVERRUN state + */ + adxl345_set_measure_en(st, false); if (adxl345_get_fifo_entries(st, &fifo_entries) < 0) goto err; @@ -737,12 +742,15 @@ static irqreturn_t adxl345_trigger_handler(int irq, void *p) goto err; iio_trigger_notify_done(indio_dev->trig); + adxl345_set_measure_en(st, true); } goto done; err: iio_trigger_notify_done(indio_dev->trig); + adxl345_set_measure_en(st, false); adxl345_empty_fifo(st); + adxl345_set_measure_en(st, true); return IRQ_NONE; done: From patchwork Sun Nov 17 18:26:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13877902 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.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 652291DE89E; Sun, 17 Nov 2024 18:28:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868122; cv=none; b=AYCSeGs0V+HAdp7nnnmqrmHwpURcPpHDCb5y3A7ZVACwqUG/KQiUTuyo877ZF1rPdgwlrRL8X7EWqjeC5w2bjUkisHRrM6jZ8H5fApLjn9V0UDNS0VtlsEkcXDL3NHj88++2hpyXCMjrU5/Zu+HnUJCemd9mic8BGkm1f/Fp7xY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731868122; c=relaxed/simple; bh=6Ty7UcqFwwj0IBvnQHFNDu2DWSapIAHbAbAfG2L6040=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Yot/fPXtF855EuUGuZkcl577qv52g8A23MPBSDHkkOOuFgz3F8hFA2pU8tVzWTEO3wSJKBw7Eq+gn14dmaZHknqhLkCQMCSeemNgXxYHYxLu5zcshjKwe3tkn/N8f8AM9Vk0H0gYKaeDs7anuVUb6J/othF90AhrcozqgxkInjM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FWM8h8r6; arc=none smtp.client-ip=209.85.221.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FWM8h8r6" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-38231f84d8fso94689f8f.3; Sun, 17 Nov 2024 10:28:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731868119; x=1732472919; 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=z7SMjsKTJF3XXwC0PuuMPNue9a73DWC0gkHNPCwn8EQ=; b=FWM8h8r6phdNw/oj0pP8xt+zWBjXgtbdUZFrViVQo4NJIgF74pe+XcgyEFK3L37zg6 PTZXUWM7+Z/nGS+/2LQR+BnZYq5fYPTAmc50M/e3wAMfgPCyTA5oYMabBdacvbB2GtBE qImh1eeFaFSeHryKwPnMWL5tG8459As3EYXK9oqhNjrZgf/df4UEhFGJuwirua+a0jrz FAu8e+9tXEBeHn/Umdq8+ZZPkZ/e3wmnj/7cOSb930VXUfVgOH6B2eytqsJQ7LSAwWtx n5xcoOd3O6132jlmPKAagQ6szq3FvnfHdX/ItMooULlAOsjgLuzKIsRsXXMJVdcN1lH2 E5FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731868119; x=1732472919; 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=z7SMjsKTJF3XXwC0PuuMPNue9a73DWC0gkHNPCwn8EQ=; b=BWB4yzLp5iXPv4XOBtkS/uVTWZPa2OeCbHe0qJud5mndgB3qj5mjPYh9wUJa2+4ho6 nkG0zg3H47QfQ4Gce1qoBSQ1FLTWIRfyo8KJkIzfTa8eCEk80aCwhrhNgu3n2vCSQ6LE gjlxqXLHz3QQj9HeEPvJ30K4V3LUAF+N4OvBM8EAFm4DSwhBdf/qGZml8w6uAQ5lrexS VrBByIzSOPVU2C9ebU+1MnB5JSQYIJuW++OyF6Le/njZpNtYtQ4hJBSB0jmamsfZ+EIl k8LopkryNtMaxO4FTiod6j4P5oXUI8KVeLckAKg/ZOlJwRZIICHnr8iYkpu/8slrVX/t lSYw== X-Forwarded-Encrypted: i=1; AJvYcCWuXCGMAWG4ArYHOeYN6kUYRfUrZ9HGyDISQ15nxpoqdZ270SospKGt+M7fED1EmGb/SxaKrqH1zgqIBOE=@vger.kernel.org X-Gm-Message-State: AOJu0YzLY7GLw3Lm2iumxWt8CxVrSTzXp70yg+KuyqXFYbqGJPmGb8GA IeBYMJ/RiY3d/wnvHKxfpXNZWTAMouVbNhY4pgjYMZJYZ6UsMaD0 X-Gm-Gg: ASbGncs/tJJ+32HXP6oepRaTnxPsHqNn+537xq1kdhTZu5FgXY3M13yFmNm/OHhIjNt xnag+SSTlJrfHyI8+LLugUaEk41kdKcBRkHZBLaFlg3173xi5sm8xdvtBgLzsZvK7iNTs4l+BIm hvh2e/bxbmij82gaNuvmvFXWC8faCY9DC9ymQzTQ0TazziYAa8WFakSBroF9bM5THI0HSPYDqsb TJe3ZxRPWJt/fM95UMdv491emtcrUAX8xhIw692d0sZBAazxJmE10ulzH9H4ku9uYbDyKF1Smg6 xLqPmbScuofTnG4Zx6VbdRlhM4pn X-Google-Smtp-Source: AGHT+IEyBBba2byhxuVdMC2GpE3Mg1u1KL7/jzRwgbHm2Q9MfsRkPxNlfOIAUepCyr3VLaD50PKJFg== X-Received: by 2002:a5d:47cc:0:b0:37d:3a04:62ec with SMTP id ffacd0b85a97d-38225a3959bmr3630275f8f.8.1731868118589; Sun, 17 Nov 2024 10:28:38 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3823f72441bsm3028137f8f.101.2024.11.17.10.28.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Nov 2024 10:28:38 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v2 22/22] iio: accel: adxl345: add debug printout Date: Sun, 17 Nov 2024 18:26:51 +0000 Message-Id: <20241117182651.115056-23-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241117182651.115056-1-l.rubusch@gmail.com> References: <20241117182651.115056-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add debug prints to allow to debug the sensor based on dynamic debug. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 95 ++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index c79f0f5e3b..8d2166a057 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -26,6 +26,9 @@ #include "adxl345.h" +/* debugging registers */ +#define DEBUG_ADXL345 0 + /* ADXL345 register map */ #define ADXL345_REG_DEVID 0x00 /* r Device ID */ #define ADXL345_REG_THRESH_TAP 0x1D /* r/w Tap Threshold */ @@ -181,6 +184,78 @@ static const struct iio_chan_spec adxl34x_channels[] = { ADXL34x_CHANNEL(2, chan_z, Z), }; +/* + * Debugging + */ + +__maybe_unused +static void adxl345_debug_registers(const char *func, struct adxl34x_state *st) +{ +#if DEBUG_ADXL345 == 1 + struct regmap *regmap = st->regmap; + unsigned int regval = 0; + + regmap_read(regmap, ADXL345_REG_THRESH_TAP, ®val); + pr_debug("%s(): DEBUG - 0x%02X\t- ADXL345_REG_THRESH_TAP\n", + func, 0xff & regval); + + regmap_read(regmap, ADXL345_REG_DUR, ®val); + pr_debug("%s(): DEBUG - 0x%02X\t- ADXL345_REG_DUR\n", + func, 0xff & regval); + + regmap_read(regmap, ADXL345_REG_LATENT, ®val); + pr_debug("%s(): DEBUG - 0x%02X\t- ADXL345_REG_LATENT\n", + func, 0xff & regval); + + regmap_read(regmap, ADXL345_REG_WINDOW, ®val); + pr_debug("%s(): DEBUG - 0x%02X\t- ADXL345_REG_WINDOW\n", + func, 0xff & regval); + + regmap_read(regmap, ADXL345_REG_ACT_TAP_STATUS, ®val); + pr_debug("%s(): DEBUG - 0x%02X\t- ADXL345_REG_ACT_TAP_STATUS\n", + func, 0xff & regval); + + regmap_read(regmap, ADXL345_REG_POWER_CTL, ®val); + pr_debug("%s(): DEBUG - 0x%02X\t- ADXL345_REG_POWER_CTL\n", + func, 0xff & regval); + + regmap_read(regmap, ADXL345_REG_INT_ENABLE, ®val); + pr_debug("%s(): DEBUG - 0x%02X\t- ADXL345_REG_INT_ENABLE\n", + func, 0xff & regval); + + regmap_read(regmap, ADXL345_REG_INT_MAP, ®val); + pr_debug("%s(): DEBUG - 0x%02X\t- ADXL345_REG_INT_MAP\n", + func, 0xff & regval); + + regmap_read(regmap, ADXL345_REG_INT_SOURCE, ®val); + pr_debug("%s(): DEBUG - 0x%02X\t- ADXL345_REG_INT_SOURCE\n", + func, 0xff & regval); + + regmap_read(regmap, ADXL345_REG_FIFO_CTL, ®val); + pr_debug("%s(): DEBUG - 0x%02X\t- ADXL345_REG_FIFO_CTL\n", + func, 0xff & regval); + + regmap_read(regmap, ADXL345_REG_FIFO_STATUS, ®val); + pr_debug("%s(): DEBUG - 0x%02X\t- ADXL345_REG_FIFO_STATUS\n", + func, 0xff & regval); +# endif +} + +__maybe_unused +static void adxl345_debug_fifo(const char *func, s16 *fifo_buf, int entries_line) +{ +#if DEBUG_ADXL345 == 1 + s16 xval, yval, zval; + + xval = fifo_buf[0 + entries_line]; + yval = fifo_buf[1 + entries_line]; + zval = fifo_buf[2 + entries_line]; + + pr_debug("%s(): FIFO[%d] - x=%d, y=%d, z=%d\n", + func, entries_line/3, xval, yval, zval); +#endif +} + static int adxl345_set_interrupts(struct adxl34x_state *st) { int ret; @@ -528,6 +603,8 @@ static int adxl345_read_fifo_elements(struct adxl34x_state *st, int fifo_entries size_t count, ndirs = 3; int i, ret; + pr_debug("%s(): fifo_entries = %d\n", __func__, fifo_entries); + count = 2 * ndirs; /* 2 byte per direction */ for (i = 0; i < fifo_entries; i++) { ret = regmap_noinc_read(st->regmap, ADXL345_REG_XYZ_BASE, @@ -537,6 +614,7 @@ static int adxl345_read_fifo_elements(struct adxl34x_state *st, int fifo_entries return -EFAULT; } } + adxl345_debug_registers(__func__, st); return 0; } @@ -656,6 +734,7 @@ static int adxl345_push_fifo_data(struct iio_dev *indio_dev, if (st->fifo_delay && (fifo_entries > 1)) udelay(3); + adxl345_debug_fifo(__func__, st->fifo_buf, i); iio_push_to_buffers(indio_dev, &st->fifo_buf[i]); } @@ -683,6 +762,7 @@ static int adxl345_trig_dready(struct iio_trigger *trig, bool state) __func__, st->int_map); } + adxl345_debug_registers(__func__, st); return 0; } @@ -713,6 +793,7 @@ static irqreturn_t adxl345_trigger_handler(int irq, void *p) int fifo_entries; int ret; + pr_debug("%s(): IRQ caught!\n", __func__); ret = adxl345_get_status(st, &int_stat); if (ret < 0) goto err; @@ -747,6 +828,7 @@ static irqreturn_t adxl345_trigger_handler(int irq, void *p) goto done; err: + pr_debug("%s(): error termination\n", __func__); iio_trigger_notify_done(indio_dev->trig); adxl345_set_measure_en(st, false); adxl345_empty_fifo(st); @@ -754,6 +836,7 @@ static irqreturn_t adxl345_trigger_handler(int irq, void *p) return IRQ_NONE; done: + pr_debug("%s(): regular termination\n", __func__); return IRQ_HANDLED; } @@ -804,6 +887,9 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, st = iio_priv(indio_dev); st->regmap = regmap; + dev_dbg(dev, "irq '%d'\n", irq); + if (!irq) /* fall back to bypass mode w/o IRQ */ + dev_dbg(dev, "no IRQ, FIFO mode will stay in BYPASS_MODE\n"); st->irq = irq; st->info = device_get_match_data(dev); if (!st->info) @@ -831,7 +917,11 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, indio_dev->channels = adxl34x_channels; indio_dev->num_channels = ARRAY_SIZE(adxl34x_channels); + dev_dbg(dev, "setting up indio_dev ok\n"); + if (setup) { + dev_dbg(dev, "setup() was provided\n"); + /* Perform optional initial bus specific configuration */ ret = setup(dev, st->regmap); if (ret) @@ -846,6 +936,8 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, "Failed to set data range\n"); } else { + dev_dbg(dev, "No setup() provided\n"); + /* Enable full-resolution mode (init all data_format bits) */ ret = regmap_write(st->regmap, ADXL345_REG_DATA_FORMAT, ADXL345_DATA_FORMAT_FULL_RES); @@ -854,6 +946,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, "Failed to set data range\n"); } + dev_dbg(dev, "Retrieving DEVID\n"); ret = regmap_read(st->regmap, ADXL345_REG_DEVID, ®val); if (ret < 0) return dev_err_probe(dev, ret, "Error reading device ID\n"); @@ -861,7 +954,9 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, if (regval != ADXL345_DEVID) return dev_err_probe(dev, -ENODEV, "Invalid device ID: %x, expected %x\n", regval, ADXL345_DEVID); + dev_dbg(dev, "Retrieving DEVID ok\n"); + dev_dbg(dev, "Registering power down function\n"); ret = devm_add_action_or_reset(dev, adxl345_powerdown, st); if (ret < 0) return dev_err_probe(dev, ret, "Failed to add action or reset\n");