From patchwork Wed Dec 4 18:24: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: 13894164 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 F34922907; Wed, 4 Dec 2024 18:25:06 +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=1733336708; cv=none; b=uKfp8DOyVmyXBULabCcmkg+xfuw5cNgkgjLu13O/ohrLgAUzngtQB3LN0V8Uf2Ch15OPHCmtJ/0FhIARuRWVhlch0GuZeAXbaQ1jV+c2UoYkz5A7OgCjm2xGcDRCUPp4XsSfiCFHgSejIbHQ3Hnup2NBbq3109M1u3MUqGm3MCU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733336708; c=relaxed/simple; bh=UvnTsLO5ozk9S3WreBtY5lNgLOymsUczM7dGCW0Qn78=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Nt1H377E/t8XGCIvlZNMR6qpuot/ZvjE+FybU/hPo3c71GoEy311KInoAJ55YOFIpYnmJBpK+1N7ppMhefjI2JW/jqjpNE+gbBHmiw2DIR+rN5VzC5pawj34X2luDKIocYiHPO+cw2kmMYc2nNkJOCv+PNLdu0XjGVK2eo5ED4k= 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=jMCUHovT; 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="jMCUHovT" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4349d25eb5bso141555e9.0; Wed, 04 Dec 2024 10:25:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733336705; x=1733941505; 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=cH7SC8VXu89oQ7d/dEv/9qfp3f8Jr/wcNDca9ETQOKY=; b=jMCUHovT9eZj3Sb80RBQc72zHyrQnvc0aT1+GGQMGU2mVV1ux9MvrFv2lnoUXW/FLM Ude22AQwULzHI1TLhAQJ+trN+3yzAKa5oO5PFLanzLRK8Q5Vjyx3LeBhKJ5++24rsHSu UdodAAnXQcRFoM9QwKcbiGXcLPcvhXQw59BAyU4yMq641yrYPcHbzK0vRQi8k1dLnYK9 O8Hh8XymTebgdymbaFGWwskWuRYwOFd6Qqb6vn7IvssBlnmArQiTS7zKzN5ttiMHgzN8 lMzwBaio3CqTLOaoVZXh8HyQtxtTU59dXiInR5RNG/rQCh5Jn/emGfKNJtG/RHkpVBWC GcIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733336705; x=1733941505; 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=cH7SC8VXu89oQ7d/dEv/9qfp3f8Jr/wcNDca9ETQOKY=; b=vleLYZYaqvWjrDprdUQoL5eQ34p0r3pQucnxyJKiwWPCdle0noUqNK/9P9TOWs30s3 AZ8f7BuV2ksJXxM9Bz77MXjspXpDeT26beXRYo7weUwS9VVwHPZU3w8/80SPduZRAtwo U7LqJtHf7Is9qElRL/w0GlaV3D6PGjxLTkotlLm6PMrz9jrlntsMY2kxxa/q0NzxwHR7 GjP5qfJz4ndmV1D9Rn5i+y3CVp7HQBk7zyRDycmK8Q6T9ITCqGZGmS3CmKav7D3XyDPp Ry5M/t6BXhD3rEvNGMqnjm2G8VUjUUzJetcMgCuGlLs9vvI2FAnd8pDwY4rjrgw8SZyp DeoQ== X-Forwarded-Encrypted: i=1; AJvYcCWh+WCzvrS/jhcRT3/aH4lqCdTRXx2qvKJn1/0CdZQhmUmDvHTrCQDy5oF6R+zx0V99llH/Qz+O/YLiqTZV@vger.kernel.org, AJvYcCXsrSeULna1fW8DU/7Kl6NCM/EqoiSP0z6+I0uxuOjFUI34MI+Q7k5M4dUV3p5ACsocRXzYKwaXHSA=@vger.kernel.org X-Gm-Message-State: AOJu0YwhSa0FC6SOdjwDKeOhTcX6Z8QNIIaPk4Rp26dcJmNQarm4B4Dy PzxTozmWSOcOyiZ1LNYeEJ/2WrbhlgQy8tDVSqw+P8iAlx+8twJS X-Gm-Gg: ASbGncvKXjZVbrTlf/vGjXfhYsF3cgKAD18Ak3OOv1e3SfGVltty11YhPCgDY5LVh+m YWuDy3pd4eDwYnR7Dh1Qd4F5awK0j6MuvLMRzyeka9WtYDt+xh6l0E8T0Z5V1f3eQ1FsfVogoxp Sz7OAlr27z9sOLi52sf1c7FPM5FcHAxhC8dQXUDzA8H3q4fYS3R5noETq7KNXZndR6lQfYkiN4u LFzOn+ED2R52RODhxYaW+qMto5s79f476Z0nNqKMG0eMxdA1DJzEsrxkD5evz0hvSxnQiDaM58Q POoLVUF8fMyUtLpRNBpBbMnuxVZ0 X-Google-Smtp-Source: AGHT+IGZBmaKjVmHGjIVdmGfKhZ87j+cZV0btRRuwh1bnwxC4RdmJmIuFEf3D92eu/EGEmuREJoRkQ== X-Received: by 2002:a5d:6d82:0:b0:385:e8e7:d0ac with SMTP id ffacd0b85a97d-385fde34d9bmr2258021f8f.13.1733336704890; Wed, 04 Dec 2024 10:25:04 -0800 (PST) Received: from 7b58d44c4ff6.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-434d52cbf57sm31959755e9.39.2024.12.04.10.25.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 10:25:03 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v4 01/10] iio: accel: adxl345: fix comment on probe Date: Wed, 4 Dec 2024 18:24:42 +0000 Message-Id: <20241204182451.144381-2-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241204182451.144381-1-l.rubusch@gmail.com> References: <20241204182451.144381-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 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 006ce66c0aa..eb3ce4434a5 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -169,8 +169,7 @@ static void adxl345_powerdown(void *regmap) } /** - * adxl345_core_probe() - probe and setup for the adxl345 accelerometer, - * also covers the adlx375 accelerometer + * adxl345_core_probe() - Probe and setup for the 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 Wed Dec 4 18:24: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: 13894165 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 07BB41A8F9A; Wed, 4 Dec 2024 18:25:07 +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=1733336709; cv=none; b=HYObV3FgnR61FqVoQTi+Ad8Mu0Pc/KFnoXwxR2T5NqSql5IqPGaLKsLtbb/HcFzj+sw5kt24TyiZWIPPd9YE+rntkJ42tyYCGEmoe5jk4+OWZRS3pJ4i8AL2cFRO41M7tT7hUpFsrzeMlrxb9Q8Ipp7QIkqOOhiuCT7Tf3DK7Gw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733336709; c=relaxed/simple; bh=ebMgkYB23U8EmKhJlfYxI1oX1jRs6zqA7+xkC/VZIJ0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FonTpzjyB80kq0nknh5sDLrCRy1j4jta+IEH/LNXC5vBck884SUun6YDaoBWTx55nvupZKw423H6kIRix/YNPuzMXPqkYzBRWZP6e2+QajNJgYEBJjj4ya5FqvueJdiws41/FaTudrZOAd+t9jkIdIFeLxVwfuGPI6nBhy2gdfE= 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=kPcWl7H6; 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="kPcWl7H6" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-434a0300d4cso116595e9.3; Wed, 04 Dec 2024 10:25:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733336706; x=1733941506; 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=Cm3ofDFIyWdFD3BL9+CgltgTWGwpBkqmG5EmpobcGu4=; b=kPcWl7H68FMu9XeMYemsp4WU6gzfVvJbX/9ecv1RBxFU+N0qiQ2tEdtdKoLQZLFpZf t3BB65xL0HYNFoWOR4OWz/r4/N8h9gEnTyt+5VE9DxTlycTRKyVvwcxeFiVytI9bkQ/4 k3aGhyvQeM+43MQYt2KAe2Bseo2xH3Fnj7G3fkm2BecY32aqY4qievzpSkM4N85w5KNN SulhqwTjMq/9GOKopk6UeC30ck6cLNqJDo7u79B5HgG2SSJIw6dhcabyROiS6k2vdn4j J/pQAA4JIhrlqg50/KCJwhY29jk//bnmhfoVNFkBEQWPjCCuOxEv1Gq4adj8gOdnINlh RoJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733336706; x=1733941506; 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=Cm3ofDFIyWdFD3BL9+CgltgTWGwpBkqmG5EmpobcGu4=; b=UzFg/vOoidjLh7oi+jT9+WVrbDmLFRjPvxqtPxR4uYxBuIrJKtIBVR4LL+QKaW2ZyF ZSmuLEBE/FjsrPX8VepyvE1ImP0SlQqVI5MfRAYreEUwADKMC1XcM4MFseOYGI57KJw4 Seshv7lZnlQBYf9fqXa/4nEPogYF5+SfpYpGQnFteSD0rpVfA+A4+jabBsUszWEXnQsf 6AdBUvzHpUmEZ5C4w82WqA6QEKYLrXp7PtU+OFZDXVitnNFsHWg4V4QlWkor/0mP1AAg QDVGXNa4TCE2ZG9whuvb9b/QYx4v8igUIj447TRmwQK1tVIYS9pvheaEFUd34IY5yaan nnnQ== X-Forwarded-Encrypted: i=1; AJvYcCWW7tJbiUN6y/hpx97OuNGnY1ukA+LB7a+JiIn8EkORHFfdq2705lkQQLXbNej+SyZOWHDZnTrya02l1zng@vger.kernel.org, AJvYcCXf9ITsQQnDWdwCR3KGD1yp20XRzzNdt6QkeHugBfvSVLHqkVXlm5PjDfElZ0vCMfLuS+TIcu4If8E=@vger.kernel.org X-Gm-Message-State: AOJu0Yy1yzYbe1mUGaVHLlLoPsvoMQpguGVPBRZJWwOirF0nyxf713d8 gZ0VOhWwIzlvnfF+yi9xbkm84dE3/3vcJw5CR4wMVNlLCcJEWCca X-Gm-Gg: ASbGncv+w+bn/6W0DKgaqkxNfsJNSBWhYxrSYeGTUE4oSN8ZIy24ncvgF6bxL3tLSJK D7DOfbUjCqc4J6BnsKMED7ZSlMeV8V2nEF/OaQd/7+cnzHVgM2mANb2kOCDzK0yz6cwVtK74Enb 0I3aSwgxq33+BEhfddyM1XA65ugLWXQfFm/RtUl6RRaRgdzT2JZpeeO61KQe9YateIJe5o7rT/S 5EYGcZDx0QKEfUWyQ1g+jHK0ECCM6sT2UiybdJPzYQo1mCQqigh+zIR/b/fk/3LVuSzN0Xmy6oz lnHC/WIWHtoJwmVl+qamVVTavt5y X-Google-Smtp-Source: AGHT+IE7bLuAVoCpyuUvlUIiAFM+ELTHiS32XSm+OjYltBG0NlOumsDIYcKiAEXyWeVCsSekrDkvIA== X-Received: by 2002:a05:600c:138a:b0:42c:b55f:f4f with SMTP id 5b1f17b1804b1-434d11c73d3mr25464195e9.6.1733336705949; Wed, 04 Dec 2024 10:25:05 -0800 (PST) Received: from 7b58d44c4ff6.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-434d52cbf57sm31959755e9.39.2024.12.04.10.25.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 10:25:05 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v4 02/10] iio: accel: adxl345: rename variable data to st Date: Wed, 4 Dec 2024 18:24:43 +0000 Message-Id: <20241204182451.144381-3-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241204182451.144381-1-l.rubusch@gmail.com> References: <20241204182451.144381-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 | 44 ++++++++++++++++---------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index eb3ce4434a5..88df9547bd6 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 adxl345_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 *data = iio_priv(indio_dev); + struct adxl345_state *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_state *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)); @@ -180,7 +180,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_state *st; struct iio_dev *indio_dev; u32 regval; unsigned int data_format_mask = (ADXL345_DATA_FORMAT_RANGE | @@ -189,17 +189,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; @@ -207,12 +207,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) @@ -221,14 +221,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"); @@ -237,11 +237,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 Wed Dec 4 18:24: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: 13894166 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 E2F3C1C3BE0; Wed, 4 Dec 2024 18:25:08 +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=1733336710; cv=none; b=M7ohjAg7WxZCqhKOo+QXm8W7M1fkcEdl0Sx4WvQyn/Ne2erM7AhT/ycUon/SthZDcPVNuRNg0h7e0d6G89oAjWOPGc9i65cATY4B1ckAYiZX+YNGRYGtTLrZ1uicQtEZTqSb5Z7AN+2L60enu+iHVpYbAF5MK3qZnsAaqoRl+0c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733336710; c=relaxed/simple; bh=tvlpR3ACIZjZ26sU6DfiM9q4+OrGk/guXwAtGKWdyjc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aVbjjO6dhaW5SS+wYD0qSjzIKPWWMIfbrlMVFpUTpXRKuArs8KXLKPFE9uqeq3gqn2uAJn2D3gdRL9b2kkl4cuJl+T5nKC7CjxcasvmgZUqmo69R988QVaXMVP4BTglSGXKd8+MZHNAOND96piQEPeXM6fsPNvGPb1q4fNni/2M= 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=Rw1f6eFh; 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="Rw1f6eFh" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-434941aac88so81925e9.3; Wed, 04 Dec 2024 10:25:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733336707; x=1733941507; 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=M/9VPQ+Uf/rRtf7/eLBAF/0nGYfYrUrX91JqSy1ZhlA=; b=Rw1f6eFh46K9lGiwlUffSKCl6MFy8BsiKLhDE750jfzyTPoQJ7Fj7jcGy+0hqIqk+D iHtzGp5wv3xTURcqmPkmwmeHj1q+SnDru2I+iQaKP1QcjZ0MakNbs3GRkX1oXuuaVezk LfULqV6AnaVtyeCG2CDPuGSyu9BoDz6sYkpfE/c7ISAOw3AFmd90GPS8KEcXMyhDM2V3 D6U3wqXeJ1ezw9BKIjH9sRDayuFxnUfoPwxtByoc2R9Ca6o8JqEf0RgTSc3kKymPeNIm 3dgwSq1pNrpX+e0NF9IAk6NPaLwVQqsmZo3fhoSWF5xk2pfR/AuPdhoWY3NsczSEGiww UTiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733336707; x=1733941507; 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=M/9VPQ+Uf/rRtf7/eLBAF/0nGYfYrUrX91JqSy1ZhlA=; b=eM1m+STT3h+rganHectlvU2OTTyKFbKCsd/RzBUGTbbe16Z8eCxSZEsNrQFkXWXHEm AfTwghKsEDRtuppvK1qhvThcGzFiyrnpDYWJfWhfD0CcxsAhvCb8F+eutT5y6Tw1QMhN e9cGfI43gmcRUN2tUJ2+ZGZqJMkFzkSkcDCT7M73fWCc+K+twFMaNKpSdF5LA6Xy82ry DqozrObw8gmnez6xYGC/vHIaMIh6dVBl0Vf9gOJnELLceQoCZXXpXxvc/OCtuD0vkxeJ CdO+zZvwLJOdFgrmfNCJyw0Afw7Pn/PPR4wxr1GCYb84VW3nAeiu0VoGAfXi98zwV37y /dDg== X-Forwarded-Encrypted: i=1; AJvYcCVIqmep5Xnb+thDiEXyG03OHFwKwwCP26VfnHmmL/IJ0zlowPrsho8EAZez35m7RgPVq0QZOD7ctpU=@vger.kernel.org, AJvYcCXuQQXZi4L05OncpKUPIWn4NgQ43gEnoN4e/eJSbou0mSj6diGR/ehMD6yiP8KHA4Tu2n2egP4LAGS5Ubta@vger.kernel.org X-Gm-Message-State: AOJu0Yw1FZuPeDtu3xMBlQfhQYafCNCd0uPra6rx/nsMbn0KY86cYH8q WA0DoNId+an1BQT5zltVGAidM91R54ORQA30s3LM9BitVR/HfsCx X-Gm-Gg: ASbGncsT6r1BGHmjbLCC1y/iPZt1lr7G/mAEmIpX0yVpMqavfGViZnorECghMb8l7AE iCyNhLnEtpo71AzJzlKUqXXHD7rODybnUCuq4mmCCKzOAI7h3P8abOc8FLBG/P7IBQijq34xyK8 rlAP/LrOdT1ZFt41QPO5YWxW+7ExtoVQgbgz4qzVe2HXltV3R0qTLBXGSEgWSPLcRA/Wbcz9d8Z ew5DosNsf5VunIrUNZkclBKJ4qZ4XTB/JaTEfeCoNs96xKFMjuIPohWgQN4pKa/fW9rUKqp6RlT npIr1nM7Z2sBL44Q8BaHGt4L/QDr X-Google-Smtp-Source: AGHT+IGBK16Wfkp6DmkPPYO6dYJRTTYXFNoNlGHE0svRXVvuPdhxFoZy1LtwU+riSKz+flyH3vgdnA== X-Received: by 2002:a05:600c:450c:b0:431:5632:448d with SMTP id 5b1f17b1804b1-434d0a3568cmr27402295e9.9.1733336707131; Wed, 04 Dec 2024 10:25:07 -0800 (PST) Received: from 7b58d44c4ff6.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-434d52cbf57sm31959755e9.39.2024.12.04.10.25.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 10:25:06 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v4 03/10] iio: accel: adxl345: measure right-justified Date: Wed, 4 Dec 2024 18:24:44 +0000 Message-Id: <20241204182451.144381-4-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241204182451.144381-1-l.rubusch@gmail.com> References: <20241204182451.144381-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 | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 88df9547bd6..98ff37271f1 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -184,7 +184,6 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, struct iio_dev *indio_dev; u32 regval; 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 Wed Dec 4 18:24: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: 13894167 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 1BD3C1A8F82; Wed, 4 Dec 2024 18:25:09 +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=1733336712; cv=none; b=RVDdxeJu3u87Q2D18pHhVOBQcswJIwxzN2+ZVcr+rVnYapl3FppQXG8QcwmRn/YJ3RspmyNOn/A2Z45R3aPhwHhr2YcnEmTpK50a2qUj8w2s5ybc6IFwH73hjPeUh28SYddqzx0QiCxcPD9PhNRCPO64UrPTvzXhm3PXKVCi8bs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733336712; c=relaxed/simple; bh=rxiKIZQkPVzmr99j0RAua0ES27Pg7Fg0w4gEPFpU3jA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CK9zE6viZOjlxO2DhgAWkOuyk0NZIzRSj56iwNsI38yBclnW5ml1j0Qvq0Z8+68akdgAJOaK+EWSgIE/wFJb9dZhdUYBASTiD6XgAmYHAE4iVLrlZbsgQwqgZnq4WhINEn15ugN4PnwA2zJb20lgj+qLaVGqL1PKw65eeReyt7Q= 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=kAhAkTat; 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="kAhAkTat" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-434975a1fb1so98745e9.0; Wed, 04 Dec 2024 10:25:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733336708; x=1733941508; 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=h7JIjZWbIOMoe/2eSa/rWUO+LqGQL2t9BFTUB/CwynY=; b=kAhAkTatqIA5j0lWn+VoFfIZCoY875WxcFqcTjQMcs+RSacu2lGxg3lAygF4+caMkC CgN/XIDcXfZN514+M79ufimkotvA2DABL5mkUhJBXZS1nV97mkvjpQgfSVSkb+2y2PZl yBJCKSDNbu3ZKB72GaGWOABQ951Kh86uMr78PGegnco3JFGRfP7A2ixVm47b6zGjIEN0 UOJX08T7BdHfyBeWJA2mO7Cl37SvEJq0p6yoSTsvj0IhNsFSU40lIgPiNkDsob4GGO8H eGVmrahndbsnkZRssdUBJU+dmBrOVI+vbeShAzM/9g4i9OZOJmJNGig5G/bBXIW5mIOp 5aKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733336708; x=1733941508; 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=h7JIjZWbIOMoe/2eSa/rWUO+LqGQL2t9BFTUB/CwynY=; b=SYvo7O97uRAxHuWk/vjp5DVMRtYOnXNMx66IrxW+IuK6EdyyU7bSOq4iiM6gRRjM4m bE6GKYBHQaLGuiYtUwjaBi0Rkz4B+xTQn7CyMASiOJOWoPv7Hn2Gaq9Gbj4ItDifdBz0 6Ic3Pf7wO/AxGFXdhNcKbNQAEzKg8X9ZFSUwNmjhHnGIZnZDC4ucNYxiahTqX+a+ZTcw +jOaT9F0xH4FKeSnUW9NA6/mHUl0SOOVfG9WmGfL0oO5ulUhhz0Il8NtSnwHzkl9/A1Z ptg/toEH6WBSeZDRdcWMFGDo162PL015DYCjZzrCY1tXwTN0E2h828Fl34aVZxA79sHY DvCA== X-Forwarded-Encrypted: i=1; AJvYcCVT6hUuVryXqVmRnhKkuuN9MyfDuLedz8YhGKhBT8IjXDiD2KqHKn9El+que990PC/+fv58F9Bc0NPgTTPF@vger.kernel.org, AJvYcCWXGv72RMR4MBNH8bmc0+v1JjI66TLHc2qjssG+B2IkYEVebZOp+q5SLz6ygX+0ZwNKqXsqOWt2Tnk=@vger.kernel.org X-Gm-Message-State: AOJu0YxZ2Nnq0aEzHOQQkjsJxjpzhC068ooqcQbIxF0sKS2eQDX/Rapk UGu6HW9GshF7+i9ck/kU0Gjcz0I0uT5dFTXjqxnvy2/OBSaTS8eJ X-Gm-Gg: ASbGncsjbZzlOCQ7g4/qrdWezWXUNCnPxkagMQfpZ4CaUSo3Kwa6xMd9MMSg4w0wae3 7p575YNiBJ7DWPRDQVd54MkeO83pmNsHUxUTwfIq/rRBVtw0rkNRXEibbXEq0SRT3AcWE0hyVVe Ey4anHRmXo2a6qSEL47/hSHM3EE59TIBea2BjJe1Hg3jIE2+ETmrkN7CR8Y7lEZnZ9+kj6f5sii KV2rMdzFm1U9cL58vnS3OzeUnArs8ThczKT78sU+yaZ0L5IYachf8jrGMf2iNIxHj+DhKu5mPxV tvymU+W//6lcfum2IUYt/2n24nbj X-Google-Smtp-Source: AGHT+IGtG+e3RRn6to6WOvlt3yydehGRfNTspWCra9KsGGxPBs0vozSgJFL0cKOEbWlzAVddBhe61w== X-Received: by 2002:a05:600c:3594:b0:434:a1e4:d32d with SMTP id 5b1f17b1804b1-434d08eef18mr26824655e9.0.1733336708315; Wed, 04 Dec 2024 10:25:08 -0800 (PST) Received: from 7b58d44c4ff6.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-434d52cbf57sm31959755e9.39.2024.12.04.10.25.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 10:25:07 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v4 04/10] iio: accel: adxl345: add function to switch measuring Date: Wed, 4 Dec 2024 18:24:45 +0000 Message-Id: <20241204182451.144381-5-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241204182451.144381-1-l.rubusch@gmail.com> References: <20241204182451.144381-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 | 44 ++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 98ff37271f1..1d020b0d79c 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -138,6 +138,34 @@ 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 adxl345_state *st, bool en) +{ + unsigned int val = 0; + + val = (en) ? ADXL345_POWER_CTL_MEASURE : ADXL345_POWER_CTL_STANDBY; + return regmap_write(st->regmap, ADXL345_REG_POWER_CTL, val); +} + +static void adxl345_powerdown(void *ptr) +{ + struct adxl345_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 +186,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 accelerometer. * @dev: Driver model representation of the device @@ -236,13 +254,13 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, regval, ADXL345_DEVID); /* Enable measurement mode */ - ret = adxl345_powerup(st->regmap); + ret = adxl345_set_measure_en(st, true); if (ret < 0) return dev_err_probe(dev, ret, "Failed to enable measurement mode\n"); - ret = devm_add_action_or_reset(dev, adxl345_powerdown, st->regmap); + ret = devm_add_action_or_reset(dev, adxl345_powerdown, st); if (ret < 0) - return ret; + return dev_err_probe(dev, ret, "Failed to add action or reset\n"); return devm_iio_device_register(dev, indio_dev); } From patchwork Wed Dec 4 18:24: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: 13894168 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.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 60A1E1F03C5; Wed, 4 Dec 2024 18:25:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733336713; cv=none; b=MmvvmAETJAGikrBQkVV22E9mXk6FnsDldtDrCYoT34rE2/ZV/FkTOQZwfoleiW1h3z0gMj0wjzC5hTfQ7HwkZLL20buoN7B2ZcKvQDOlKKBqCfdR8Y8qaHjiFaaiFgR9csPSGn6IG7pBk8CEbSFb/OqUfqHOs/QwRLKa8QnU8rQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733336713; c=relaxed/simple; bh=ovRKtQYK618KQAT7xksv0b6oZxulWAFP/r65yBLnjJc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kR5o0cjqKsSs4XshANTgP0hG57SLwOohCvG1D0iWrm//1E/6lDmAuha6eWg6nP3pf41AqeX9580E3HLJKoRxFtWRpNmP3qFfEdszPMOCnwhT3nHsBwwcc8ZTiiTlm1xpa7F11jIi8aPVx0S5ZnWbwVkqbE/lsvXqImtjr2J7ozI= 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=EqclULk5; arc=none smtp.client-ip=209.85.128.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="EqclULk5" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4349ec4708bso84065e9.2; Wed, 04 Dec 2024 10:25:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733336710; x=1733941510; 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=e7z7JJ9yAoVzYehdb1uFB7loYdyMG6J39Tna2NdUaaw=; b=EqclULk5jVMWt7vx8leooNUXzs5TxEDzHhVthYYY2Vahb5dVLritEhoJiGH1r9sGxI EblujPYnub3TE21cDeI3U6iL0toRUY3obFe+k2U48weNLFcXF10sB1abIBZRZ4wrHY1b fKNeIhuR3Nw7ooEKb1Z72ckxilcmF85l4/FVh2ZXNbb9ETnHbHcQ6vBNDBO1E94gtBSD TpDoMPZmNAyWQ+TTwj713JnoHqLWjTCAMpvFoCj6GgmzxSfWpxq1brAAOAVtBtDup80q KYcH7eevpK0Ytodw1dhIWa3uDhlsU8BHDMizhmIPCYft9hKEvqk7vyAHRrbjS19xZKbW LGew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733336710; x=1733941510; 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=e7z7JJ9yAoVzYehdb1uFB7loYdyMG6J39Tna2NdUaaw=; b=d5k+Vw07dCCPn5W1N1K4wX85KkuNW/GGcElDjxGbzy3roPwflMZLHk2Msj/9F/mzzz Jc5sneGHp0mG4MfonGV5i5dzj7if7MmspLSvjHD09EYwH0mUqS1QycndmvJctBzc+EQ6 6ytbQIEifDQS1CV00yQ6/3ltpwTonxRnNL7niJ5ocYiko9JsrIIOhSRLMXYqtwyMlzXH 51A7Kxugd+FcTYUgD4MNPA6K2VETsbqhIT5eOmWqULhC49rpC3n7K9dwtgqbinVLe+CI j0NYJvT2llP0KPbnVfKSZjFVuXhqZ+xJH8A9HQj+S8nTzV5Uwze+OvETXWu58uAd+6z5 g/sQ== X-Forwarded-Encrypted: i=1; AJvYcCWg8cI3DLbkosVqon88TZg3Stm87NAaSlnTZmmoFGkq2xItYEJXYqBldA3ihevRlfl4bLCvTGUr3cmcBRtS@vger.kernel.org, AJvYcCWif7jViRnbSuK4bfD/oVVyJBWvV44FdiEiaQdBV1ahvSJLQ1MLHivAmYhIsi53spc6VV5WMwieqO0=@vger.kernel.org X-Gm-Message-State: AOJu0YzY+4ZKulYzWiXSV9PjodwYCS12iFEzBVyhi7UPpFBKxiGTnnu+ tZ12IAnyXCu12Lzmu7xNKQqaEoneRpDPGHb1bsl9uGMqwFamDxSk2p+tuA== X-Gm-Gg: ASbGnct7VCJFxao3O74/kw48i9KoLWg8HoyY2M9b+ziEIJLmu3lXkOw9LIytO3FSecp QbTXRRw/0obQzFiyjm16kTfrlULbY2RL8tMZR54yvr5W66uHsONNj5Vb25KdLMKi6M2/lcvBLDI sdgiXjVWaY535l7SCvAT2AH3s++Y8vESWSm3HjZBpxqE4WGBCBqZLpoc4jZ4aZbMhIOY8yWLWoz 0YlMAPLwHvZyXSrRR8WDrknMds1EyPdTrdwuGsdNfVjaBTV2wPpcu7WVhoIFa5RKVBkYPeDWLhW 7hRoGz8ofAMn3xoJ2comiExOjWYd X-Google-Smtp-Source: AGHT+IHE8SXsbpXZSHNLMaGjZ2a2vzAycZ+3bDp+ty6QQecn0m681DvDIp0IxDnOFuMhww7hC/s7JQ== X-Received: by 2002:a05:600c:1ca2:b0:434:9d0d:1347 with SMTP id 5b1f17b1804b1-434d0a03f25mr26594415e9.5.1733336709510; Wed, 04 Dec 2024 10:25:09 -0800 (PST) Received: from 7b58d44c4ff6.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-434d52cbf57sm31959755e9.39.2024.12.04.10.25.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 10:25:09 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v4 05/10] iio: accel: adxl345: extend list of defines Date: Wed, 4 Dec 2024 18:24:46 +0000 Message-Id: <20241204182451.144381-6-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241204182451.144381-1-l.rubusch@gmail.com> References: <20241204182451.144381-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 Extend the list of constants. Keep them the header file for readability. The constants allow the implementation of events like FIFO-watermark, single tap, double tap, freefall, etc. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345.h | 89 ++++++++++++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 12 deletions(-) diff --git a/drivers/iio/accel/adxl345.h b/drivers/iio/accel/adxl345.h index 3d5c8719db3..ed81d5cf445 100644 --- a/drivers/iio/accel/adxl345.h +++ b/drivers/iio/accel/adxl345.h @@ -9,37 +9,102 @@ #define _ADXL345_H_ #define ADXL345_REG_DEVID 0x00 +#define ADXL345_REG_THRESH_TAP 0x1D #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)) +/* Tap duration */ +#define ADXL345_REG_DUR 0x21 +/* Tap latency */ +#define ADXL345_REG_LATENT 0x22 +/* Tap window */ +#define ADXL345_REG_WINDOW 0x23 +/* Activity threshold */ +#define ADXL345_REG_THRESH_ACT 0x24 +/* Inactivity threshold */ +#define ADXL345_REG_THRESH_INACT 0x25 +/* Inactivity time */ +#define ADXL345_REG_TIME_INACT 0x26 +/* Axis enable control for activity and inactivity detection */ +#define ADXL345_REG_ACT_INACT_CTRL 0x27 +/* Free-fall threshold */ +#define ADXL345_REG_THRESH_FF 0x28 +/* Free-fall time */ +#define ADXL345_REG_TIME_FF 0x29 +/* Axis control for single tap or double tap */ +#define ADXL345_REG_TAP_AXIS 0x2A +/* Source of single tap or double tap */ +#define ADXL345_REG_ACT_TAP_STATUS 0x2B +/* Data rate and power mode control */ #define ADXL345_REG_BW_RATE 0x2C #define ADXL345_REG_POWER_CTL 0x2D +#define ADXL345_REG_INT_ENABLE 0x2E +#define ADXL345_REG_INT_MAP 0x2F +#define ADXL345_REG_INT_SOURCE 0x30 #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_REG_XYZ_BASE 0x32 +#define ADXL345_REG_DATA_AXIS(index) \ + (ADXL345_REG_XYZ_BASE + (index) * sizeof(__le16)) + +#define ADXL345_REG_FIFO_CTL 0x38 +#define ADXL345_REG_FIFO_STATUS 0x39 + +#define ADXL345_DEVID 0xE5 + +#define ADXL345_FIFO_CTL_SAMLPES(x) (0x1f & (x)) +#define ADXL345_FIFO_CTL_TRIGGER(x) (0x20 & ((x) << 5)) /* 0: INT1, 1: INT2 */ +#define ADXL345_FIFO_CTL_MODE(x) (0xc0 & ((x) << 6)) +#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 ADXL345_S_TAP_MSK ADXL345_INT_SINGLE_TAP +#define ADXL345_D_TAP_MSK ADXL345_INT_DOUBLE_TAP + +#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 -#define ADXL345_POWER_CTL_MEASURE BIT(3) #define ADXL345_POWER_CTL_STANDBY 0x00 +#define ADXL345_POWER_CTL_WAKEUP GENMASK(1, 0) +#define ADXL345_POWER_CTL_SLEEP BIT(2) +#define ADXL345_POWER_CTL_MEASURE BIT(3) +#define ADXL345_POWER_CTL_AUTO_SLEEP BIT(4) +#define ADXL345_POWER_CTL_LINK BIT(5) #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_IS_LEFT_JUSTIFIED BIT(2) #define ADXL345_DATA_FORMAT_FULL_RES BIT(3) /* Up to 13-bits resolution */ -#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_SPI_3WIRE BIT(6) +#define ADXL345_DATA_FORMAT_SELF_TEST BIT(7) #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 +#define ADXL345_REG_OFS_AXIS(index) (ADXL345_REG_OFSX + (index)) + +/* + * 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 ADXL345_FIFO_SIZE 33 /* * In full-resolution mode, scale factor is maintained at ~4 mg/LSB From patchwork Wed Dec 4 18:24: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: 13894169 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A0461C3C01; Wed, 4 Dec 2024 18:25:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733336714; cv=none; b=eWmlZ0gTrLigaTRo6GBtPPJuyWRJieOqbd4Ak+z66LddyDByu7AhuIvQDU1Cb5MPjHEG36urrPY84XaH9nEnAzFCHmklnpUTK596JsFQX/I/gFcWhxc1GFXu7E/lLdtUYZNHpfwzMVisMbGp+eQzS49gmmP4kcbo47bBaiXgcPQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733336714; c=relaxed/simple; bh=zbFy/cRHMsKtsS6MBJ522L4RfoZH1lwPSDpEDSOUF3s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=L7a3mF5l65x7L8ZMTMFsLzNWTK6MtQAWG9VF9aeRWGdbUa0ngd/FhQu/v2EJ0Qk/1GmL1SWBNsPP/eitfV5trC4reL5e8tQEfX2p1y47DyIdvO47Hj9IFM3FTThgfYec0KPscoijFKD7VIKr/yorOGDQBlVyuNj74i/EWNWUo7s= 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=Isj71JC3; arc=none smtp.client-ip=209.85.128.53 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="Isj71JC3" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-434a1095fe4so98075e9.1; Wed, 04 Dec 2024 10:25:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733336711; x=1733941511; 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=JAvJZxpxE2h2mD5CczkRDaQ3jMJAQT+3HBKnhDyYiwU=; b=Isj71JC35SM+1dlw/2YVAAbEeKiAj/dQHHeARTpPQp/a+no6Pd235XyfD1w8/e0I0b 8oOmagd+k/0ik1muSvary2t0ezYdjkEZHQURo1e7/Tg772aIjuPiGwkZwiQPs3gFzE7z 69jLuVTQcd0XhExNd83JLWYRKiyKKiwFYzljYhs1t6HwWqMEbSK+AEr5LcU+EmULN+pK 5aHpE29YzZElSvAQ1Fv/Uwuqv1pdQEMfXHkWD6dC8D9sCGnckYzpfg/R71sEg/0ZQT98 eImMTdwYXTsUd5RIfIBq05Xh4PIB68cIG4QGYoBOAAQvFoog2IqWPqwAltu7TJAYJDHR eF9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733336711; x=1733941511; 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=JAvJZxpxE2h2mD5CczkRDaQ3jMJAQT+3HBKnhDyYiwU=; b=GoIPGPou9Cffse9xYm+7RZ/xrOFhPnG9PEKx5DMGyuW6SopPjhhxjIB6IWApAViAiS VUTf+Fj3o8dhlxTWeAcx4GsKMbQ0nQzX0e7UkXUSN4bW5jU68E09I3+g4V8txUUYN5IA rL2nuDZAYpSUPVtxEbE1Df5g6HeSh1fWX5oDrmKvViGShXI1Se7CjPhmrVb5lquFouhP djSuUxGJFMLnOH0sYycxHMlozvn5nDUJtkHGUw/6IisU2tENSDY+2wED1zg2htKDAS40 gjW31LKFj1IDh5bJc1UT1CYdv/TBE3vVSs/vKG4/ExWKmJuknHum+PnQASj/43g/UFhv qhNg== X-Forwarded-Encrypted: i=1; AJvYcCUyWXpRfdMJ6EnWyL4NeC/o/kCn+/as34Q6DY0NYao5U0/D3lS3SYZ+htzxlXyLULPFm4qrzWlM3NA=@vger.kernel.org, AJvYcCVaiCturdPnXF9XLJItXXMeBZW1D0KjaMao9XMDRcnea5dNHFnLpnyO6UmuEEV0r2Q5cgMYA7LM1fZETZwp@vger.kernel.org X-Gm-Message-State: AOJu0Yw01Cy+xHptXGfRvnxgNluTMDUahSiMT+vGNLTY/U71eHZRZxfz Y/lK7LeMWN2S94RT8UD+VL7F7HGx1dAjMK0KqjkAI+VYML6T564oVDTYgg== X-Gm-Gg: ASbGncsJ1mCJw8Gd1enJA2G1rH6JVWHsKyc6nyYNF0/mUbEm6b8PrWfHR2DMxEoVzbl ozzmyVf+JAf0gDKjCNp0OtkJHHBNBNEDSmI7tX81gxwnnsVpS9MOziw7XIMemRaTEYQouhMX03a CKBi3QyXGCC0cRUGq/FqPOH48FLMlGFen0AE94W78z5gQdAZn8UfdXhl5XqisI/PJbChi7p91dX 7kbhWudcfICGn519sJSxvWG3E6xvVcA6fAHPUjNFNvCL18dXIRo489P9krrsFDw6mQb16K1hEQp klbl54kAmgweGqx0tmhoEfVuO+2S X-Google-Smtp-Source: AGHT+IGintvniezClYarfwLLOi6+0Ps55YJtVGp+lecYNoe85bxNVbzZxGxD3L/eo5m8iOivrMpMug== X-Received: by 2002:a05:600c:1c02:b0:431:4a7e:a121 with SMTP id 5b1f17b1804b1-434d0a38d88mr26622525e9.9.1733336710693; Wed, 04 Dec 2024 10:25:10 -0800 (PST) Received: from 7b58d44c4ff6.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-434d52cbf57sm31959755e9.39.2024.12.04.10.25.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 10:25:10 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v4 06/10] dt-bindings: iio: accel: add interrupt-names Date: Wed, 4 Dec 2024 18:24:47 +0000 Message-Id: <20241204182451.144381-7-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241204182451.144381-1-l.rubusch@gmail.com> References: <20241204182451.144381-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 interrupt-names INT1 and INT2 for the two interrupt lines of the sensor. Only one line will be connected for incoming events. The driver needs to be configured accordingly. If no interrupt line is set up, the sensor will still measure, but no events are possible. Signed-off-by: Lothar Rubusch --- .../devicetree/bindings/iio/accel/adi,adxl345.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml b/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml index 280ed479ef5..a4c2cefe1a4 100644 --- a/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml +++ b/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml @@ -37,6 +37,15 @@ properties: interrupts: maxItems: 1 + interrupt-names: + description: Use either INT1 or INT2 for events, or ignore events. + minItems: 1 + maxItems: 2 + items: + enum: + - INT1 + - INT2 + required: - compatible - reg @@ -61,6 +70,7 @@ examples: reg = <0x2a>; interrupt-parent = <&gpio0>; interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "INT1"; }; }; - | @@ -79,5 +89,6 @@ examples: spi-cpha; interrupt-parent = <&gpio0>; interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "INT2"; }; }; From patchwork Wed Dec 4 18:24: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: 13894170 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 65C92202C23; Wed, 4 Dec 2024 18:25:14 +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=1733336717; cv=none; b=QuGCwT/oppeupPhX9DK40nnW0jPsJalV1AqOnO8fZzazasesKTQczkqLFcG4gsytdJ0Vh3DkYzhPOa6KeLiJ+XKZ1QL49SKV8NfdSrQ90u3vEFqvAkxHeA/Ni6lQVJi1RQ2oDWUcytDPKGbwWAnDfuZTbJpPf/A2axZLkjf8gYs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733336717; c=relaxed/simple; bh=S0inAZHl0ztwEsx1oI5GmcmBpR7IlLnBA3TzthoW+tA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TrP+mI6mOKdQjdKKDScuEuTZtqtVW2UnXsmtaEkzbamYA5UvFYSCqfhd2+wsXhzXJUehnzrs7lCPirIcs6SbLG4htu3yx1tVPhMKzvlEDkOKK3AL6s9annRD4ry6FDgcxtDv2Z0lE/34AT+TZoB7JH2SxbVOqTH+ROa6sKl6aCA= 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=kIU2fujH; 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="kIU2fujH" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-434a1095fe4so98115e9.1; Wed, 04 Dec 2024 10:25:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733336713; x=1733941513; 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=eXBB/e7iBLl04dNygS4ZhKgIlKO+KsaUlZhrp4pFDcA=; b=kIU2fujH7ujF3k0p73JRbqUNYRXIkNJd4tktMsaxfzVM2whuAGG00WvHTg00LqFMY1 86qg9pms7sXHWsS8rvHCnnx+mdrKy1RE9z+tyr+nnGdt+qBT5gZNJ4fBsqazbpuAi/Kx RLJSYeqx1nGcJe+LnNYRdTarfIea4MxtX9aT0u7bTdJEaM6vNIynOImdkFizuhHuuXDG uUa960f1tUK5SXm2GwlA7p4LDs+XbNHH1kcwm3I2yWiLLNV7vaORQ1yMLih+86f1S7w5 V4YzLFPNBlO59FVR7pKTixqstIsnitqY2tARgHRiOTW+PtTijuxWejsRa/L+gFVUGW08 Xhsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733336713; x=1733941513; 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=eXBB/e7iBLl04dNygS4ZhKgIlKO+KsaUlZhrp4pFDcA=; b=HWSVK/vUGDhGBOMwGgWmtez8VhlFlweD6wUftomFBaa64+Slkc+5O+BaGnHGqkKIZT BGOvpj+9jaSVPXGqwZp1Gz6iIEdIOVE72bLvGkz2mcWtpNQXIoqvuKTybbekWDr85+q9 9x1kp7Rqm9yJO1nu6w+787PP4mvxLXexyWpjqdE3DX3IvfdRJs0vl9Jdrt1TIbxsDA/J ha0xguyccohmX6v/YWS6nNJ70N9vHMSL6dtmLzvhbD6RV6ypSfm5Gxm5XyoyX5vZdCX7 c25zCEViVsYCya9EcFazQ2rsi3awSpBmRaUkxCaiK1MYBHm5Uk15mNM7GTOBxpRjbbgN tRtw== X-Forwarded-Encrypted: i=1; AJvYcCWIpnZV45yyYrO9TtgW2p3B7mQ5er1du9odfL/4KtuWwS92HcDOiutu17ZdZsL9wHCtEzHT20sV8TA=@vger.kernel.org, AJvYcCXAem93eaSM+SVfStEn3wd+rf5BebkBEMw7Zpho/AmG1AEE7W+15kK+AHLQcBX9gzG3K7ANzToiKTRvAgoR@vger.kernel.org X-Gm-Message-State: AOJu0Yy1RBGimhpbLaQXxfRMuswvbbv6MyUrXVJWaC/EAajj2FdxBrZW 6QMOcTA0HM5trQrALSEgKkHnKt2udaaF7em0nP+VliqpbwYAKSHU X-Gm-Gg: ASbGncvsExU18VyQ1QLhFbtOwIe5X0dcLo9dXWleEMPgLSRF8iM2/RjYSnYlKbrbgnA dYj09Zh+YykUA5i8jhlTMWx5W0FmcL3HpmDEePKaNWQYuGHP/E8VcEWB+ncHua7Gw3TEejr0oKZ +pRgkpoxul0Dl2PT1kAUg8GXxshVhvbrM5h8tCljU8v0PGj3fg7uUDJ1O9QBo6a+XIzsdzWaD8X UxsgwElR9/AwCvFsXuje2TC9CanJ8bKSCdQR+WHQQkikTQgDx7bp0/xzqwKNQSOLkhlNBmR8UMT I7Ay3L3ApUB1P0lqwPLqvtD3D7F2 X-Google-Smtp-Source: AGHT+IGagPwAt2PxYUXWY0BQ0/B264RsulgEv9md3QD0MhQb/KiieyqodcaSaPDCuVlCfeE2U+V1EA== X-Received: by 2002:a05:600c:4f4a:b0:432:dc5a:b301 with SMTP id 5b1f17b1804b1-434d0a37b2dmr26897645e9.8.1733336712583; Wed, 04 Dec 2024 10:25:12 -0800 (PST) Received: from 7b58d44c4ff6.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-434d52cbf57sm31959755e9.39.2024.12.04.10.25.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 10:25:11 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v4 07/10] iio: accel: adxl345: initialize IRQ number Date: Wed, 4 Dec 2024 18:24:48 +0000 Message-Id: <20241204182451.144381-8-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241204182451.144381-1-l.rubusch@gmail.com> References: <20241204182451.144381-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_core.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 1d020b0d79c..e0a8b32239f 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,8 +19,10 @@ #include "adxl345.h" struct adxl345_state { + int irq; const struct adxl345_chip_info *info; struct regmap *regmap; + u8 intio; }; #define ADXL345_CHANNEL(index, axis) { \ @@ -212,6 +215,17 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, st = iio_priv(indio_dev); st->regmap = regmap; + + st->intio = -1; + st->irq = fwnode_irq_get_byname(dev_fwnode(dev), "INT1"); + if (st->irq > 0) + st->intio = ADXL345_INT1; + else { + st->irq = fwnode_irq_get_byname(dev_fwnode(dev), "INT2"); + if (st->irq > 0) + st->intio = ADXL345_INT2; + } + st->info = device_get_match_data(dev); if (!st->info) return -ENODEV; From patchwork Wed Dec 4 18:24: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: 13894171 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 1E76B202C35; Wed, 4 Dec 2024 18:25:15 +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=1733336717; cv=none; b=Jyzv6XY0oNG2ip2qBnswnsiCl3VzvgQNg/hwkdmG3TRA5nNEwPplzIrzeWjenM3mT9VQ6QOKbcfhgWWwn9xVr0xcLEtlOgl62a76un83x+2bBm5u5ajUiFaj8WKDzzeF4kuMcQXZnae9zEigrRcDB81QN/hdRjz7OIAA9SsFZvY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733336717; c=relaxed/simple; bh=1JB2wb1ixUQ2tLhVrAdRSy7hUKQW2Tn/gK7Kv0OWlYM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=USFuXxgn7xK2TT5LPnlfQ/5d0AZiuu5Jna6/Z68+FihHQhkgPNkrHg/4AeXCKdl2PFTVcSIyBOvVzwpFi2nOqF4gaEZAvB+fhZvCcCq3dA2HIBlnbTQA94Q17SIaZhIufGDqzx3SmpdHm0lK9Icixjp98r8FfxgEc1gV3E5NVyY= 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=FoJ4basF; 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="FoJ4basF" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-434a36b82b7so90485e9.1; Wed, 04 Dec 2024 10:25:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733336714; x=1733941514; 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=xNQM2De0uWsZzOP6u/2v236oC/9A63z8kL2Apq3LH5U=; b=FoJ4basFxZ+WIAo4uXdC62+WFbq4fsFx0+6/0NNjB5ByLI8oi+2fi1V8Rcz5cSF/oY SjFQd+M2/3vzQAT7ewJWNMF6xsOyKmmvqs96ezsnke9O7TfB+L8gkW4f68Ls8NJpH2Mi bAQ72jA6Tw4BqrOtABcE16K3dZLHFbSK2Uv+C7Xbx1G3njDPSBApJB8SIVDRXHLgy6Ba /KF2CNb1OhMXco5/RPvxBvrUFAwYGSjWyuCbDRGEa9Ozf1zPkh9LsANmtmIYtg486KoI BuJ/NA8EfeoF0YS5F1lvKLSZWFLUL4xHNJ3vGg7ITObJ0HN2ib5SZ1ssni+/5dSsil9E aPkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733336714; x=1733941514; 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=xNQM2De0uWsZzOP6u/2v236oC/9A63z8kL2Apq3LH5U=; b=WX+sKxU3veqe+fJTipGxvOaQRXSII6qeeNTK3E3gqGmT/Wd9heMBoo+wXqoJp6Oaus +/fkTIxs0lruloQSd/L8dOQxenCoX9U/vu+AOqLqNMkuCF4Wa6TFIO6bWwvQZCu2n2H3 e2RFUtRJFtYpY1AKnBibcf+v7GLjRvpAU0EGD7yX9yGbKzsROOTP40QMQ5dHKBYAmwSK URZRuyUkZJMwMX87uhrtKHpPV6oO4CEGf5zFgwdfdPIKgYDR6sV16umgtjRwq4YzCOzK txkO1KYC1Mjx5xs2qOZ1cZaNu5sef4DqeHeA0vvfM1VR1cpwiT3sixswo9RjVUZHff4a iOHA== X-Forwarded-Encrypted: i=1; AJvYcCVsD9wkTrhC8qXvUKXXpyV2s+IIJ68dKbGk0dG/X+AytF7QMLpz28IKYrL7S14k+F1Ky0fv2q4ZYl1ul3bz@vger.kernel.org, AJvYcCXhyEIKAR6GMBpD6vOpkxeV7mjEHiqgE0rToxoKjg+CQlZEZdig0zGk1AREYG3QivwpCp4xRrFP9p4=@vger.kernel.org X-Gm-Message-State: AOJu0YyrVCrMMbpITafBpZ/GFlvPSXCR2uc162sn+ksX83eXuiwQvFvw pCxS2mIjTOhq47yvShr9nQwCKNcJ//OrVBO0k7fRvjJMwGz+tmlO X-Gm-Gg: ASbGncu5hujKtTkJXV9jiXMG5Bz+6s64oYg9Gbejvok4N0yR6Tq95sFHZUATEWpZUWp tqdlc9wLK1aK4pgUr0ajq6jInieXavmf5s4OW2WDoMj/ckWrIVlvPPzoBffHSaNtXbI8y5kcIF6 3NFzMbBJahsfJTMG5DZnlXYt8hj0Bcw7A5lasXA+1nvPoSksnY5H6k0CBuuikbUKkyrmLIC2AW2 9r+7vWqEwjaEJ+xKAjjZKv4Eiqwio/9ROTunTIScYWg/iYbAMy6KkkzARsqPqBF5fNpNbv88kdc sm7GetDJuzF/jE3FhOIc6jcOlKNT X-Google-Smtp-Source: AGHT+IFW1FLYDpdRtB5tR/zp4nXMF6Gn37gIcoA5IgJjlA6tw3LUgBIkGiAgCISOrgI9G/Rng48BPQ== X-Received: by 2002:a05:600c:1ca2:b0:434:9d0d:1347 with SMTP id 5b1f17b1804b1-434d0a03f25mr26595175e9.5.1733336714339; Wed, 04 Dec 2024 10:25:14 -0800 (PST) Received: from 7b58d44c4ff6.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-434d52cbf57sm31959755e9.39.2024.12.04.10.25.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 10:25:13 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v4 08/10] iio: accel: adxl345: initialize FIFO delay value for SPI Date: Wed, 4 Dec 2024 18:24:49 +0000 Message-Id: <20241204182451.144381-9-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241204182451.144381-1-l.rubusch@gmail.com> References: <20241204182451.144381-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 | 1 + drivers/iio/accel/adxl345_core.c | 12 ++++++++++++ drivers/iio/accel/adxl345_i2c.c | 2 +- drivers/iio/accel/adxl345_spi.c | 7 +++++-- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/iio/accel/adxl345.h b/drivers/iio/accel/adxl345.h index ed81d5cf445..c07709350d3 100644 --- a/drivers/iio/accel/adxl345.h +++ b/drivers/iio/accel/adxl345.h @@ -127,6 +127,7 @@ struct adxl345_chip_info { }; int adxl345_core_probe(struct device *dev, struct regmap *regmap, + 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 e0a8b32239f..0696e908bdf 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -22,6 +22,7 @@ struct adxl345_state { int irq; const struct adxl345_chip_info *info; struct regmap *regmap; + bool fifo_delay; /* delay: delay is needed for SPI */ u8 intio; }; @@ -193,12 +194,21 @@ static const struct iio_info adxl345_info = { * adxl345_core_probe() - Probe and setup for the accelerometer. * @dev: Driver model representation of the device * @regmap: Regmap instance for the device + * @fifo_delay_default: Using FIFO with SPI needs delay * @setup: Setup routine to be executed right before the standard device * setup * + * For SPI operation greater than 1.6 MHz, it is necessary to deassert the CS + * pin to ensure a total delay of 5 us; otherwise, the delay is not sufficient. + * The total delay necessary for 5 MHz operation is at most 3.4 us. This is not + * a concern when using I2C mode because the communication rate is low enough + * to ensure a sufficient delay between FIFO reads. + * Ref: "Retrieving Data from FIFO", p. 21 of 36, Data Sheet ADXL345 Rev. G + * * Return: 0 on success, negative errno on error */ int adxl345_core_probe(struct device *dev, struct regmap *regmap, + bool fifo_delay_default, int (*setup)(struct device*, struct regmap*)) { struct adxl345_state *st; @@ -230,6 +240,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 4065b8f7c8a..28d997c5860 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, 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 61fd9a6f5fc..9829d5d3d43 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, @@ -28,6 +29,7 @@ static int adxl345_spi_setup(struct device *dev, struct regmap *regmap) static int adxl345_spi_probe(struct spi_device *spi) { struct regmap *regmap; + bool needs_delay; /* Bail out if max_speed_hz exceeds 5 MHz */ if (spi->max_speed_hz > ADXL345_MAX_SPI_FREQ_HZ) @@ -38,10 +40,11 @@ static int adxl345_spi_probe(struct spi_device *spi) if (IS_ERR(regmap)) return dev_err_probe(&spi->dev, PTR_ERR(regmap), "Error initializing regmap\n"); + needs_delay = (spi->max_speed_hz > ADXL345_MAX_FREQ_NO_FIFO_DELAY); if (spi->mode & SPI_3WIRE) - return adxl345_core_probe(&spi->dev, regmap, adxl345_spi_setup); + return adxl345_core_probe(&spi->dev, regmap, needs_delay, adxl345_spi_setup); else - return adxl345_core_probe(&spi->dev, regmap, NULL); + return adxl345_core_probe(&spi->dev, regmap, needs_delay, NULL); } static const struct adxl345_chip_info adxl345_spi_info = { From patchwork Wed Dec 4 18:24: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: 13894172 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 0F231202C40; Wed, 4 Dec 2024 18:25:16 +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=1733336718; cv=none; b=F6eo1y4QerN2i5djURAqjQq3F8ZVl44ex3r1F67E6h6MK2cHPJ+YgWu2T6T3+7GThQYjg+fbiPY8q+IUrhOYlayvf+9qdCBXW1hVzUmKa7l54e3fND31jPJdjjLl+RO5b7+ZwSJsG9IIbhNxOZ+I4gTs0RwdnhOIjOBBj3B3m4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733336718; c=relaxed/simple; bh=iLDUgU8WNcAh/t6tBH4v0q05mowuF+6hmrNXfHJwFoA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lN34XVfa0HIyZuTOYmJBRKms8KbZL3O3UsWzLwcB6ri6nesXSbhHD+SGWMpETG736oWq6gI5WEn34JckIkwN8/vP52IF6g6DSArXQmIPBvfh7zDiWKN0jPTn5nv1RPD7vExzIXjo/+Ysn7uMrtPX1D5Iv/ntUiwqrtSRJFrH1Vg= 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=hSLCGH1E; 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="hSLCGH1E" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4349dea3e0dso133775e9.3; Wed, 04 Dec 2024 10:25:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733336715; x=1733941515; 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=GgoVWnhvP406HqfDsdu4WH7uW2K8Xa/wgeBTdZ1+3jg=; b=hSLCGH1EajdoFhd63eFHHOeunGnprIQEROaMOHighvV4i3wO8lDMPxfJPuLu1XUN3z w2zBMhlQEOBH24uLnT+4mT1DOasF03CBRf2KJuSEcNAf0FpbS6x2asKbfyxqyZ1FSmLi +mUB+H08ACO6a9tQI/nKKJ6RRC6n+kJXcvso/rBETKZUs8Nu7NqB+/6x2QebHJzlhTOC IkMB8APXyV9J//Gy7stUXL/3xWUiL+dFhy8mAzO8EPbwxZbsmBRJKNSFMKVXHRiFm4V7 7mAGVKtl97qV/gJKkXmBTrI8KgQ1Kmc96bq44V/LE30nuPcZ+ZVgauxQCUKXSuIhqvHv jIlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733336715; x=1733941515; 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=GgoVWnhvP406HqfDsdu4WH7uW2K8Xa/wgeBTdZ1+3jg=; b=DKbIEoMdO2A5mnMz50468iJj+FsbPr4MB5F0PZbhgC5KWqGUXTXH97ROGvm1k1oFj3 S6shz3gSCs92f3QWEnrlR34E4Lx7+0VwUKVoDf1k4WpoToVWJWQI/5AlOO5iCOgJSUu5 bRdiQ6kwK74XH2J74eTJVSn/03zXr285XytLM5BLMUQyEK/X/lPxUncjDi5hzOkadz5f UQt5Do7mtChPwsOXEi6oEL12VJBjo6ARuUiRbpjTAy+YRJf2BLs6+vvLxZmzODI+oW1K Sm7F3bjTUwXpkjvawFaQwRtI4eTwPJ8+eyABIJqg8sHCKrDoiJbSL5gOnQAY5BWMc6mX PR/w== X-Forwarded-Encrypted: i=1; AJvYcCU1e9RZeKfSFgHiSmpUbq1P2jbR603NnhbHWU08qIcGP2cuDtNxYgjuIC8IvwDdiCqDP4qhvTxgwK0=@vger.kernel.org, AJvYcCU6ApsMBI+MJfwhqVFC/vCo7Vx5fDkUmc6QiqTUbo5qMMYp/+oUHOm2kHYeLMfuNTFdcghjF5pGnfRVAuI3@vger.kernel.org X-Gm-Message-State: AOJu0YzapahyMqcwSJPaUmEz80xip829DOtkGtRqWbSE/FW7UA6euN6B ax3GKkzwi2onZFR2JS/ohQyE1zR2o6dN1vGhE3VlNcgwqY+/zenN X-Gm-Gg: ASbGncuMe/JkGX7ZSZh0ipsou8AXLqhfyJv1WzrFPsOkUrJq1osgBI1gnyhI4ohaR33 akNF9FMso/gl3Fw9r+c/SkP34ljcIIrLlpL6c4WB3mTGDc0hP1Ci3K2qUd3vjFZnLzDocTiSIAP qw8REdZf32iM30k+WnU3LQgUTdOmjejvPlCiOFEhv7ajq/OuXKxvPifMFAdqnKIA2XOwy3iibO2 XJLU4myFA7dLZxaeBcUY26KfLVxBcJUDcJHXIQn26gQLQPeQEYey0JsKQ06ZaYaMoayUnOrFaYv 9y6gTBNqC0pjgFUqFvjnOmR0v2e2 X-Google-Smtp-Source: AGHT+IErWUrJvfwAvRKgqHxWUC/Y/1VynWeuYejyRVU2EgvBdjZfbkBC/SO21snZhQAv58/R299m0g== X-Received: by 2002:a05:600c:511b:b0:434:a0cb:6d24 with SMTP id 5b1f17b1804b1-434d117123emr25322285e9.3.1733336715440; Wed, 04 Dec 2024 10:25:15 -0800 (PST) Received: from 7b58d44c4ff6.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-434d52cbf57sm31959755e9.39.2024.12.04.10.25.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 10:25:15 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v4 09/10] iio: accel: adxl345: prepare channel for scan_index Date: Wed, 4 Dec 2024 18:24:50 +0000 Message-Id: <20241204182451.144381-10-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241204182451.144381-1-l.rubusch@gmail.com> References: <20241204182451.144381-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 separate fields for register and index to the channel definition. The scan_index is set up with the kfifo in the follow up patches. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 0696e908bdf..3067a70c54e 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -26,21 +26,26 @@ struct adxl345_state { u8 intio; }; -#define ADXL345_CHANNEL(index, axis) { \ +#define ADXL345_CHANNEL(index, reg, axis) { \ .type = IIO_ACCEL, \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \ - .address = index, \ + .address = (reg), \ .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), \ } +enum adxl345_chans { + chan_x, chan_y, chan_z, +}; + static const struct iio_chan_spec adxl345_channels[] = { - ADXL345_CHANNEL(0, X), - ADXL345_CHANNEL(1, Y), - ADXL345_CHANNEL(2, Z), + ADXL345_CHANNEL(0, chan_x, X), + ADXL345_CHANNEL(1, chan_y, Y), + ADXL345_CHANNEL(2, chan_z, Z), }; static int adxl345_read_raw(struct iio_dev *indio_dev, From patchwork Wed Dec 4 18:24: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: 13894173 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.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 C51EA1C3C01; Wed, 4 Dec 2024 18:25:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733336721; cv=none; b=PNL6pH5h8mqNMTtJ/TZtaikz3F7HNXdiRDPIEmT4pnB4m61h3VVzKXOJnYn0VrQCUxKyAKhpfGKO9APSvxdhgmIbiSOVS+Qm95Y3+xS4QaBrQHGyo30EuAPKgoGBR8OxlWUp97LPKGpUN1uRNmTAJa+AgmIkiwWdSehvng3doZU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733336721; c=relaxed/simple; bh=jJKdK2NjM/lLWJRNdCyLMTdcF0ZHR/hBlHVPi0g4jo4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RFPlSf/E1FfqiJQYgFapYC0sIfRdvkzVeWSxp7OsGgqBsAxdHJb/fDqjnTDAuC1ThFWWNcLYz4yv3iLlQI2h4UTFDoNreHgCCURapDD5fM7fO0BcoJk8sxG5safV4qEUnXvBB8hVS/06/lwdMYfCZyhwYqYJq50V4F3WwR3+H/Q= 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=aFcumhC4; arc=none smtp.client-ip=209.85.128.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="aFcumhC4" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4349c376d4fso153365e9.0; Wed, 04 Dec 2024 10:25:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733336718; x=1733941518; 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=+mOVhuLIyGKGJ+HQN2f/Ng+vmUvRv87Y9eeBkAmiyWI=; b=aFcumhC406rh0opm9s1sV1Yn8HLqswghwO2mK91BNE+LiiU4ewUx4KHIX4xmHVOZ+K S1aOmsCSarqlVeFPwMhoJj758ZGVUZE8vF4UY9wvkCAwWavT1xjqwEU9oI9b7AMJrJXz L/xxw6xh9Fm+YUaxyLJ+fILd/gkHwgDcOyZD2uSdHPQAjKnuW4gR2uK0OnJO6SLACuVI ahwN8VQvSPzpWKklp0HJjvQysZO/OgD/2GrlnCi1CzlmwFtbzx0z0bc4u7nPhUrcxGjX HcrqTBXH0uXq5tT9AB3iKFnkaRMl1kM7QjBdJJ1+3b0m6Dpw8Hi2wJqTquFhpZw0UoHm K8DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733336718; x=1733941518; 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=+mOVhuLIyGKGJ+HQN2f/Ng+vmUvRv87Y9eeBkAmiyWI=; b=VdEgE+S0ucstEOOkkD37oUxhOqSyK/KDpA4JCYDrMVuslfgD3yAfOCni0QHrKiczcv tyb1OAL9TYKlDo5sEgfcdqbDwQ+GdujQ6olq713aaaQtAq79OypNdmCyIfROl1UtarTr NykjwTGKz+QjL0sNIOeGEnbnfiKDJNN4GiY1SFdJ/OpJ2opDDcJ3jlAlkZmyow4dD8nk o8UxxAfaZyqiXPzBPaUMjd7MbwGq3HWvpGdtxqMzn5P/AKY5brkNG/ZNtsYsktrpW/WM cnUWOgC1h/nmrjSV0D/vIYW7na8o8Dpbm4VKKuYlU9wSiIRhT2hHKcafnfdhGdRxfYXh bzPQ== X-Forwarded-Encrypted: i=1; AJvYcCV6EhlluDRWaIGkBRXpCY5gMiAgN/x/f3VAOZnkBDjmCgyzajgQXXKg4Wk3cnOoFnb8V+UYn7KoxOg=@vger.kernel.org, AJvYcCW8Q2UwhnCu+er5Fxfpb9dGuK3R36COaKgAoYM6EZT7kp+QND1ZiQNtKNESQIuxOJ20aGDz/n+ZbDBvFpgl@vger.kernel.org X-Gm-Message-State: AOJu0Yxig1Q0TDgmN5b80eKciINf4jDwLWVRzGQVgGHnzOF8PFDnYLMA ecTMPuEGhXxf6Hj7YxAgDHwyguHG0w6Up+L047wWM2kEcQPmiqqHjCoWfw== X-Gm-Gg: ASbGnctw2R06IZ4ky76ZlPbpIcZKz3DC2c4UPCck9fQDdnOoRZR1ZwaCYN9fLGRToKV lF5LKqrtveGHsfiDOxJWCIIJXJCs1dC16RsVkN8+Q8SiQ4gVl8xKJwt90y+WirVz/qdqTPQIDfV OARuEBNL/D5+zeVMA6uxWiX3M7F9x8fpX5ZPkcz1x1lkRDdNiG7vXH8odhkC+Hv6R9xgdk18bBJ aPA41mSe1pIJttPQGyHNecDhrpAzbhcuhUcM2505kW8i0FxcdKM2/vx2dFbRrXbRYiiisIQxjMB l9gLikYiMXxC1BzszXpvsl4BZw0V X-Google-Smtp-Source: AGHT+IFdtiFVJhR8YWyxMfNxNeu+cs6oHVSNhKfnY/tbEO9udT+mZgEgt5OecpyvGDtAX/uVwNsJ3Q== X-Received: by 2002:a05:600c:63cd:b0:434:a30b:5443 with SMTP id 5b1f17b1804b1-434d0a0742fmr25800825e9.4.1733336718014; Wed, 04 Dec 2024 10:25:18 -0800 (PST) Received: from 7b58d44c4ff6.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-434d52cbf57sm31959755e9.39.2024.12.04.10.25.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 10:25:16 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v4 10/10] iio: accel: adxl345: add kfifo with watermark Date: Wed, 4 Dec 2024 18:24:51 +0000 Message-Id: <20241204182451.144381-11-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241204182451.144381-1-l.rubusch@gmail.com> References: <20241204182451.144381-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 basic setup for kfifo with configurable watermark, add a handler for watermark interrupt events and extend the channel for the scan_index needed for the kfifo. The sensor is configurable to use a FIFO_BYPASSED mode or a FIFO_STREAM mode. For the FIFO_STREAM mode a watermark can be configured, or disabled by setting 0. Further features are based on the FIFO setup. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 300 +++++++++++++++++++++++++++++++ 1 file changed, 300 insertions(+) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 3067a70c54e..58ed82d66dc 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -15,15 +15,28 @@ #include #include +#include +#include +#include #include "adxl345.h" +#define ADXL345_FIFO_BYPASS 0 +#define ADXL345_FIFO_FIFO 1 +#define ADXL345_FIFO_STREAM 2 + +#define ADXL345_DIRS 3 + struct adxl345_state { int irq; const struct adxl345_chip_info *info; struct regmap *regmap; + __le16 fifo_buf[ADXL345_DIRS * ADXL345_FIFO_SIZE]; bool fifo_delay; /* delay: delay is needed for SPI */ u8 intio; + u8 int_map; + u8 watermark; + u8 fifo_mode; }; #define ADXL345_CHANNEL(index, reg, axis) { \ @@ -36,6 +49,13 @@ struct adxl345_state { .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 adxl345_chans { @@ -48,6 +68,25 @@ static const struct iio_chan_spec adxl345_channels[] = { ADXL345_CHANNEL(2, chan_z, Z), }; +static int adxl345_set_interrupts(struct adxl345_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); + + ret = regmap_write(st->regmap, ADXL345_REG_INT_MAP, int_map); + if (ret) + return ret; + + return regmap_write(st->regmap, ADXL345_REG_INT_ENABLE, int_enable); +} + static int adxl345_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) @@ -133,6 +172,31 @@ 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 adxl345_state *st = iio_priv(indio_dev); + unsigned int fifo_mask = 0x1F; + int ret; + + if (value == 0) { + st->int_map &= ~ADXL345_INT_WATERMARK; + return 0; + } + + if (value > ADXL345_FIFO_SIZE) + value = ADXL345_FIFO_SIZE; + + ret = regmap_update_bits(st->regmap, ADXL345_REG_FIFO_CTL, + fifo_mask, value); + if (ret) + return ret; + + st->watermark = value; + st->int_map |= ADXL345_INT_WATERMARK; + + return 0; +} + static int adxl345_write_raw_get_fmt(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, long mask) @@ -188,11 +252,224 @@ static const struct attribute_group adxl345_attrs_group = { .attrs = adxl345_attrs, }; +static int adxl345_set_fifo(struct adxl345_state *st) +{ + u8 fifo_ctl; + int ret; + + /* FIFO should only be configured while in standby mode */ + ret = adxl345_set_measure_en(st, false); + if (ret < 0) + return ret; + + fifo_ctl = ADXL345_FIFO_CTL_SAMLPES(st->watermark) | + ADXL345_FIFO_CTL_TRIGGER(st->intio) | + ADXL345_FIFO_CTL_MODE(st->fifo_mode); + + 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_samples() - Read number of FIFO entries. + * @st: The initialized state instance of this driver. + * + * The sensor does not support treating any axis individually, or exclude them + * from measuring. + * + * Return: negative error, or value. + */ +static int adxl345_get_samples(struct adxl345_state *st) +{ + unsigned int regval = 0; + int ret; + + ret = regmap_read(st->regmap, ADXL345_REG_FIFO_STATUS, ®val); + if (ret < 0) + return ret; + + return 0x3f & regval; +} + +/** + * adxl345_fifo_transfer() - Read samples number of elements. + * @st: The instance of the state object of this sensor. + * @samples: 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. + * + * 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_fifo_transfer(struct adxl345_state *st, int samples) +{ + size_t count; + int i, ret; + + count = sizeof(st->fifo_buf[0]) * ADXL345_DIRS; + for (i = 0; i < samples; i++) { + ret = regmap_noinc_read(st->regmap, ADXL345_REG_XYZ_BASE, + st->fifo_buf + (i * count / 2), count); + if (ret < 0) + return ret; + } + return ret; +} + +/** + * adxl345_fifo_reset() - Empty the FIFO in error condition. + * @st: The instance to the state object of the sensor. + * + * Read all elements of the FIFO. Reading the interrupt source register + * resets the sensor. + */ +static void adxl345_fifo_reset(struct adxl345_state *st) +{ + int regval; + int samples; + + adxl345_set_measure_en(st, false); + + samples = adxl345_get_samples(st); + if (samples > 0) + adxl345_fifo_transfer(st, samples); + + regmap_read(st->regmap, ADXL345_REG_INT_SOURCE, ®val); + + adxl345_set_measure_en(st, true); +} + +static int adxl345_buffer_postenable(struct iio_dev *indio_dev) +{ + struct adxl345_state *st = iio_priv(indio_dev); + int ret; + + ret = adxl345_set_interrupts(st); + if (ret < 0) + return ret; + + st->fifo_mode = ADXL345_FIFO_STREAM; + return adxl345_set_fifo(st); +} + +static int adxl345_buffer_predisable(struct iio_dev *indio_dev) +{ + struct adxl345_state *st = iio_priv(indio_dev); + int ret; + + st->int_map = 0x00; + + ret = adxl345_set_interrupts(st); + if (ret < 0) + return ret; + + st->fifo_mode = ADXL345_FIFO_BYPASS; + return adxl345_set_fifo(st); +} + +static const struct iio_buffer_setup_ops adxl345_buffer_ops = { + .postenable = adxl345_buffer_postenable, + .predisable = adxl345_buffer_predisable, +}; + +static int adxl345_get_status(struct adxl345_state *st) +{ + int ret; + unsigned int regval; + + ret = regmap_read(st->regmap, ADXL345_REG_INT_SOURCE, ®val); + if (ret < 0) + return ret; + + return (0xff & regval); +} + +static int adxl345_fifo_push(struct iio_dev *indio_dev, + int samples) +{ + struct adxl345_state *st = iio_priv(indio_dev); + int i, ret; + + if (samples <= 0) + return -EINVAL; + + ret = adxl345_fifo_transfer(st, samples); + if (ret) + return ret; + + for (i = 0; i < ADXL345_DIRS * samples; i += ADXL345_DIRS) { + /* + * 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 && (samples > 1)) + udelay(3); + + iio_push_to_buffers(indio_dev, &st->fifo_buf[i]); + } + + return 0; +} + +/** + * adxl345_event_handler() - Handle events of the ADXL345. + * @irq: The irq being handled. + * @p: The struct iio_device pointer for the device. + * + * Return: The interrupt was handled. + */ +static irqreturn_t adxl345_event_handler(int irq, void *p) +{ + struct iio_dev *indio_dev = p; + struct adxl345_state *st = iio_priv(indio_dev); + u8 int_stat; + int samples; + + int_stat = adxl345_get_status(st); + if (int_stat < 0) + return IRQ_NONE; + + if (int_stat == 0x0) + goto err; + + if (int_stat & ADXL345_INT_OVERRUN) + goto err; + + if (int_stat & (ADXL345_INT_DATA_READY | ADXL345_INT_WATERMARK)) { + samples = adxl345_get_samples(st); + if (samples < 0) + goto err; + + if (adxl345_fifo_push(indio_dev, samples) < 0) + goto err; + + } + return IRQ_HANDLED; + +err: + adxl345_fifo_reset(st); + + return IRQ_HANDLED; +} + static const struct iio_info adxl345_info = { .attrs = &adxl345_attrs_group, .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, }; /** @@ -222,6 +499,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); + u8 fifo_ctl; int ret; indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); @@ -293,6 +571,28 @@ 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"); + if (st->irq > 0) { + dev_dbg(dev, "initialize for FIFO_STREAM mode\n"); + + ret = devm_iio_kfifo_buffer_setup(dev, indio_dev, &adxl345_buffer_ops); + if (ret) + return ret; + + ret = devm_request_threaded_irq(dev, st->irq, NULL, &adxl345_event_handler, + IRQF_SHARED | IRQF_ONESHOT, + indio_dev->name, indio_dev); + if (ret) + return dev_err_probe(dev, ret, "Failed to setup triggered buffer\n"); + + } else { + dev_dbg(dev, "initialize for FIFO_BYPASS mode (fallback)\n"); + + fifo_ctl = ADXL345_FIFO_CTL_MODE(ADXL345_FIFO_BYPASS); + + ret = regmap_write(st->regmap, ADXL345_REG_FIFO_CTL, fifo_ctl); + if (ret < 0) + return ret; + } return devm_iio_device_register(dev, indio_dev); } EXPORT_SYMBOL_NS_GPL(adxl345_core_probe, IIO_ADXL345);