From patchwork Wed Dec 11 23:06: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: 13904344 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A12A61EC4FF; Wed, 11 Dec 2024 23:07:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733958423; cv=none; b=ZPijx/dYjyO/2cXYB7BJbkFJYRqJYOjnursnUw27RctbelnkQVrIIQEA/yQG0AeEJbiAne1mAf+2ZE0WRU0sTO3vroFqnZilNB8KhSF63W4pWGJPW4Ya1FANWE+4+MDKHSsHm1XzLB6jeikZ71UgHMTS37snsD+dHUcvXEbYKF0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733958423; c=relaxed/simple; bh=Cr1713WajhHzvYvE8UfeGtOFiIQNZyadluwSxA0FUrg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KchltmpCB9+F8qqZcEBDAnK3yDDalqbpZOldrZe+Gxm7GndJ1SyePdAgj9B1feyHts+eR4FayV/gt/cFktO/TeP22pUps4x8cscWQ9BoR+ezg5hDM02DQoChkTZ4s2T2KbbU9GbKh8HXTJUIo3xZzhDdTiam50bbevBCh0k/aeU= 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=g3yDtt7D; arc=none smtp.client-ip=209.85.218.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="g3yDtt7D" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-aa6647a7556so87950666b.2; Wed, 11 Dec 2024 15:07:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733958420; x=1734563220; 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=HYXh6GxOLbpXiurdOh608cToA5zl7Wcej6r5BOVjdKA=; b=g3yDtt7DUDpdKoTSGXB85LpG8etrAnurkBoOkqAfk/WeT1r5guGKTyPcy6RsCvj4Km IuVzu/bFxR4woy9zWeplf0O/7YW9dbn2kltVQFaE+za3U0Al7QOom5OZbGb6QPbndvkh Yt6t637mEI1JRBDIQ37ySkvNzhwJ/BEv286dqxMTjYVebrGd1cBomzpUS0zj9G+sL81u 1EjmexoPeoKiMm4nKseSy+uvHB66xO7igByiHCfvCoAuIfBpWedMmg9KQVOWFnaIDYpe wV9dJDQ2mDOqjvB49SZGlsWeisO3yY0NFdN2zF+PJzkp5LTdwPjy3/aXoxi94aNQvt/t ElEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733958420; x=1734563220; 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=HYXh6GxOLbpXiurdOh608cToA5zl7Wcej6r5BOVjdKA=; b=g35UAlwJ6fzQdIAR49uyeEUbC1tOL1bbWbYIV9rlvG3OnvvFmuaO763bMA1VXPeRqe MN7pQdW1nKcwXz9I9e2/tFV7iJivkwzurtVVQqZWDZ4lHEBJsOsl4lAuKI49Iolbz173 hv55mQjTJsv33JLFOx4Ray/OmZmD6uPdqFAKQQ7vLpqs0eu1hEK7DeKzkeEtpTly/e00 cHtSlQMpbvVQ3cqjTJqTPVJDsX91vxDOs/387Jsv03tYYW5Lj4CvnZdlYn0SqbawDhoi YhR1hezuMSujci4WoJbKN7FfQeukup9HXve6/yEEz6B6IbF9wuxZpomWO8aVhq7Wyqxh b70g== X-Forwarded-Encrypted: i=1; AJvYcCU8vrFtb1vnbdqJht4yvuYzRcFuNOg/BtEdo7HGLKF60z+etUPxW3I9PEJtg3DyG1tZoD/e5gQkeZQ=@vger.kernel.org, AJvYcCVBFP0drTIgWhkPNnb3Bb3EgXqWHN1j4cwnDJAniWo0uK0JNkI6GuxTPLIGa/AAAxLjPxZAXOPRzUuykowa@vger.kernel.org X-Gm-Message-State: AOJu0Yz/BX8asDKslio+ra40hikb2TK1n/B7RFuRyLpUlHyH6AnOixqd lTerQH16W0dO1ydCi/tdUEflRfkStLwe9DsHJOTu7Q5c8w7jxUXY X-Gm-Gg: ASbGncujj6TeDfx4aRkDwuO0laOTPnzlUb7BN68QPWKIecjMevuB+PlbU3ITXykauw2 GQnUolp4mVCiJEJAO31M7UV+lTn5I7QRTJ9NkvajnmuHy/vy6vJsnBbyV0spqgmtRpPObZSqUlZ Afs1g60slqUt8AK3hZiPoHWFAKQ8vTFW5rQl1IKrtWgHZqQ7wJ7aRmr80nbpTHXTvf5xhktFFWp g96FDw8mOWr7AnpBceiJvF44J9IjrgZfciQb+UPLrsKLFryUbhzAU1SjGJcuHDmHBKQ6CUWDZEK Y1pglIrRlsAIN/DwtP5OzEnllC4Q0mkU X-Google-Smtp-Source: AGHT+IEFF3GX2KIaaQ+lPo1rC79c6kJOxwphBFX1Gsk71okY1+VlVIwJClchcNR/YvSE3MXuAU1tFA== X-Received: by 2002:a17:907:7d8c:b0:aa6:9631:923f with SMTP id a640c23a62f3a-aa6b13aff95mr164687766b.12.1733958419659; Wed, 11 Dec 2024 15:06:59 -0800 (PST) Received: from 34fd2088d136.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa655653d96sm747350366b.185.2024.12.11.15.06.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 15:06:59 -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 v6 1/7] iio: accel: adxl345: add function to switch measuring mode Date: Wed, 11 Dec 2024 23:06:42 +0000 Message-Id: <20241211230648.205806-2-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241211230648.205806-1-l.rubusch@gmail.com> References: <20241211230648.205806-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. When configuring the FIFO for several features of the accelerometer, it is recommended to put measuring in STANDBY mode. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 42 +++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 88df9547b..b48bc838c 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 @@ -237,11 +255,11 @@ 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; From patchwork Wed Dec 11 23:06: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: 13904345 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.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 3BF161F239D; Wed, 11 Dec 2024 23:07:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733958425; cv=none; b=gEaAhe328819d3lnlA1NvGsgQ1xdNVPzyPdO8zBcdVzRN/hxZZSxHlqczKk2Vud3w+iaMrWX2Hzqw6PuUUTr/KSopIayeZkI3aiXM+DoB4GBHyp3+sxUv4SXrBPOYf/oHplsm7ubpWgdO5EdIOvo+FATZMebxQ6x3I+LuWNyTo0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733958425; c=relaxed/simple; bh=fMMAUA8MptsJ3tdTNT6UnSlPGNtDXVuoCwGlqdh+Xtw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=E9mc/P6+M86/E58rarWGqXtg5yZzqV4CX/FeY40pqU6h0QCLuiJNRTuYtxghoesb+7TZRjOTMbaGflWoNAusm2Z3F0KntkZZfMlEIvYIaU23WJOvmePcLP7NbXy110o9pkPKlZX1p9xSUzD9/z5qJNM+MYeWcJ5w2ML3qabjtwI= 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=hAl0jbsD; arc=none smtp.client-ip=209.85.218.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="hAl0jbsD" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-aa67bc91f88so79732066b.0; Wed, 11 Dec 2024 15:07:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733958421; x=1734563221; 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=XODishcc6/xg5cdHfCN0TyWgzzavYyLFRNEsZR4w8DY=; b=hAl0jbsD1ZO/r2sgTNStC8DhX18yYJhJrSLz463V/fPet6g6xVqy/UHiFnEZ1ADAsS Is/QMf6M2PPqNZrwzT+0NbrgNuHTB9xJPbew7GFzytvU+NfewlnH4vpYWeQ1G4N+xiXs XzLufLLzFCtYgeXEf41YjtnKd2G9n1NuD0rzOGcnvHDJHkTpcQ+AkjgkiOwSfrr/zaP+ j6vFwe7OJaUUonPBVikqNqoGRjd5QIGkcVDF97TzIEIjUDdYexkPxauZk1ll/h5n9/md t/bJOAW5V3KHlX5enNvlCHuxwudbyx/7EGLuOJOzshkG+e4T2MQNGDCJKvMCEthjATYA usIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733958421; x=1734563221; 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=XODishcc6/xg5cdHfCN0TyWgzzavYyLFRNEsZR4w8DY=; b=gB5SGdmTc66DqKNvrtcrB5VCIVVH4qK3Zu/nSUhYAqXSZLK2T9i99kSyvsOagkjxze +8muJ8nIqx4G+WUi9tsNTRPOs6YsxaZHWCXWKWp3fxGTkjEmri8qSHR/W3ownctWkx9b Gvr1B+fhMJOIdKSCC9abHVlYSjI6GPh0LOC06IUVa3WkNoQjVGJtNozdsbU83Z701ac5 MqFqvOf+7mMIcbO3YzDqtoyWY9qVV/VR8puQpDkwfsk8k+OS7yEYrv0Xw/XD3dfq7iLX z/V87t1mLtlcHZAbVnHVxQVf5DGAtUdEE82d0LZqq3K8gs5oV5Hg/AmHkAz84qd45Kw1 k/CA== X-Forwarded-Encrypted: i=1; AJvYcCUZPrk8OnTe3UZT9LM+7XKmvxXXzFtjK+SLYSlhnP5oz4/zLRNBU6jDwFuaXdiLTbbJ3Gdn+kBtqi8=@vger.kernel.org, AJvYcCUu0Igf1pZNJ+n2WKKG7j+JPbJTpUhayh1gFcQ506tVMM7ch0xdMS9OY4SEVPIjbSxOv1TMEuH1GmC2ezKb@vger.kernel.org X-Gm-Message-State: AOJu0Yx+C/GMwhBQT3zUSJigdGBC9h9HsUgBx9KJKc4NyjSkuJYrMv06 1SgQ/jIKqivetk6x2Ex3RTNN6Auha9fp/TzCQTX585Op3js+8hbN X-Gm-Gg: ASbGncukgadk421F4Hi/iZ3wpEPs1WOxv8uc/LKUAisOnP+X2JQ0UwQ+jGp38P6QAPI mBLu6ThhT4R+ey+8LLO5DtzAKPjhkaQuxxB26v0vEaowz/5KVOmdg3aWzKhxJdEjfHWCn18VK4y KfA14HqpRy806Gs7UE70aYPrIkYIxymRQdhnMTMkkA6R+WwI53A5Ckkp3LTDAKUlsv0khOpYyTE +da5ZAzvrMndCG4Yl6d1hudN1WKHM8HMv9B72EDHk5cWGyIDBq5YeCUOR+UUHGyvsiUvvk652Y1 +OjkQl05T7v4qHm2iN7FAeyCcp/QcCb1 X-Google-Smtp-Source: AGHT+IGdPNzBKAWaLyNaRDXPezhm7V0aYVDnHkJLhFb2R3YtseqUmcXQBFVK2JtQ0PVTcGfx3BBe9Q== X-Received: by 2002:a17:907:2d8d:b0:aa5:3e81:5aa2 with SMTP id a640c23a62f3a-aa6b1180512mr177755566b.4.1733958421446; Wed, 11 Dec 2024 15:07:01 -0800 (PST) Received: from 34fd2088d136.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa655653d96sm747350366b.185.2024.12.11.15.06.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 15:07:01 -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 v6 2/7] iio: accel: adxl345: complete the list of defines Date: Wed, 11 Dec 2024 23:06:43 +0000 Message-Id: <20241211230648.205806-3-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241211230648.205806-1-l.rubusch@gmail.com> References: <20241211230648.205806-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 defines allow the implementation of events like watermark, single tap, double tap, freefall, etc. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345.h | 92 +++++++++++++++++++++++++++++++------ 1 file changed, 79 insertions(+), 13 deletions(-) diff --git a/drivers/iio/accel/adxl345.h b/drivers/iio/accel/adxl345.h index 3d5c8719d..9c73474c6 100644 --- a/drivers/iio/accel/adxl345.h +++ b/drivers/iio/accel/adxl345.h @@ -9,37 +9,103 @@ #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_SAMPLES(x) FIELD_PREP(GENMASK(4, 0), x) +/* 0: INT1, 1: INT2 */ +#define ADXL345_FIFO_CTL_TRIGGER(x) FIELD_PREP(BIT(5), x) +#define ADXL345_FIFO_CTL_MODE(x) FIELD_PREP(GENMASK(7, 6), x) + +#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 + +/* + * 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_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 */ - +/* Set the g range */ +#define ADXL345_DATA_FORMAT_RANGE GENMASK(1, 0) +/* Data is left justified */ +#define ADXL345_DATA_FORMAT_JUSTIFY BIT(2) +/* Up to 13-bits resolution */ +#define ADXL345_DATA_FORMAT_FULL_RES BIT(3) +#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 +/* + * 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 11 23:06: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: 13904346 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.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 10C3B1F2C5F; Wed, 11 Dec 2024 23:07:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733958426; cv=none; b=dhCdD+aKjHaGWL3QbBmLYvnw+seKFsNSIZOW4BSvl7Y/2LbLmH3sJujTNya2YkSwLIdeuMwlL8xA73nMnErMLEdVb+xppnvXBTwBTJdWqtXKVm3Cnqdx7gmoS3WP3F+3IGNibCk218QEkTgcou420ZnjbpH9njrf0YaHIiOLn/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733958426; c=relaxed/simple; bh=eNdXn7NceJXq1oIEmRCXkUh+Np6+3pkh1tPJdSSMFZg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=shVq0PNd6mjRhL23iCh5YZPc/jDvlua2iqm4O8qEEXHDm/FS+fXy1LWgeqAbz9tuYWG3jpCccKoiTPblzp8D5C2pqnekMlPduOkcNriZgSOAeNHfasRX2NDRp4H4C7AEDATb3hUiP3b5KljbN9CoAuaHa/9fnDyF1n3FVw3S3UE= 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=OOLkl+dm; arc=none smtp.client-ip=209.85.218.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="OOLkl+dm" Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-aa680fafb3eso52276866b.3; Wed, 11 Dec 2024 15:07:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733958423; x=1734563223; 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=2Z7lFECm3AQjaZy7M+SmPHtp3Ebh5+HDY93z6/0ZpTA=; b=OOLkl+dmdIoadlGZxMwe5W3imve0LEg+bDv73DVALx2OBivJJZiHQG9GOozzW5FVpq KgCQg1T6lhtbspQXvmMnJUnZNOW52AFM6NKoLKATRtpSqsCysTpRhMmEaEm8bRofHIBi ufMoFfGHpI1I7uVnB+qIXWzZyjdddyTtISUrhmMpWTsJaYfEpnA/+djckuoVcOm09HQN ePjPZer1bHOnX2tVtwe1y/KWoeS4TQ42PaT1RSWED+J7hD6V8cD6NifFmdk7uYZ02M/E 6Nd76UWtT7Q2zP/Tw6Yc7mH6KKkTORJzLQyUtZ0syrA636Kz+8Ip7G13EQc5jhgqxuZ0 5WSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733958423; x=1734563223; 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=2Z7lFECm3AQjaZy7M+SmPHtp3Ebh5+HDY93z6/0ZpTA=; b=DQj2UJmQDFxprqsc54oKpFIpYMVwVx6KCoZTdDxc06fiPy8swvbTbKlJptRP8ayO2e xx6iQOEMrINRmKon/aC5ktD2Ly9onune78IVJrILEHdnHl6IUWZAGzANOsl9u2gIPMsQ +m2SVmkx5JmJDvtHpXHPBG6BW3Z2uVCXqylYGu8jR5p+YGaTggvCfnlNYKJgZbwqEyy9 uEhZIyKUtn/dmASadQw4FzOvEoqwi1Vz/HSd/hG/ZrfxJExX4QudyiksLPb9WCkUXtjf paClvkXhdxpFkjfMxKBH+Uv57Sims6kFGVUSPqy98cpx+LDPZECAyJKyr7OKgpDFC/zo tYqA== X-Forwarded-Encrypted: i=1; AJvYcCUUJWbxMtgMpHyEXfPKoIT7jLPNfDzqG4teRZAX1bKzAF0SI+2658DXsg1xj2+4zgAg8gg15eVAt4qfbhPE@vger.kernel.org, AJvYcCVgJHNk0IpxCIpuSmN1TyXJIwroxwCgQXY3eiQ8w0WsHBLGLD5UE3e9JFNKbWD6M0AptCxBBDYDvi8=@vger.kernel.org X-Gm-Message-State: AOJu0YwUjN1YZmecJNL0L42wO8PVrjQnwAkOzgkTFFiyb6VptbBvEBeD robQX518c683kNifejRjmHJHDRb91WYc2liL8lMa1+PN8OD2KyKW X-Gm-Gg: ASbGncsAmBISskO8oALNQ+0wymX4FbiwIkd2hQLU+VG1CHkxa5//ID5aeApC+yx/3e9 nXQHf8mYSModJnaLDztzuqj3qsf4RBh0fwxj3oW2bzOuSkEnqAMpg2cc2oMJAP+CmQ/b0/rNObG kNK2gxkLfzl7wD37oHYEVEcJJGjw1bd7QagZXKM6T2sOqEKHlNENp1Wn7kHclEcvYLdLUnixs9p OUZa3Y9dBXDLh55Cj4zaTRVHZXeaHtwVCi8OD/2v9qbzlkW4nRNrRDNBQZcErRtfI1MMbf4h3GB mymO2h6Gmx+d02soX8AanJMvfyV/xOtk X-Google-Smtp-Source: AGHT+IGO+oPBgBBEczX1RCqAD7vN572wRMfy+QkrNc8EKbcrChq6BKQ3emh291CVaE9LdP+ZRTPWnA== X-Received: by 2002:a17:907:94c1:b0:a99:a6e0:fa0b with SMTP id a640c23a62f3a-aa6b116812emr187323666b.5.1733958423203; Wed, 11 Dec 2024 15:07:03 -0800 (PST) Received: from 34fd2088d136.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa655653d96sm747350366b.185.2024.12.11.15.07.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 15:07:02 -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 v6 3/7] dt-bindings: iio: accel: adxl345: add interrupt-names Date: Wed, 11 Dec 2024 23:06:44 +0000 Message-Id: <20241211230648.205806-4-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241211230648.205806-1-l.rubusch@gmail.com> References: <20241211230648.205806-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 fall back to FIFO bypass mode and still measure, but no interrupt based events are possible. Signed-off-by: Lothar Rubusch --- .../devicetree/bindings/iio/accel/adi,adxl345.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml b/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml index 280ed479e..0fe878473 100644 --- a/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml +++ b/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml @@ -37,6 +37,10 @@ properties: interrupts: maxItems: 1 + interrupt-names: + items: + - enum: [INT1, INT2] + required: - compatible - reg @@ -61,6 +65,7 @@ examples: reg = <0x2a>; interrupt-parent = <&gpio0>; interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "INT1"; }; }; - | @@ -79,5 +84,6 @@ examples: spi-cpha; interrupt-parent = <&gpio0>; interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "INT2"; }; }; From patchwork Wed Dec 11 23:06: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: 13904347 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.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 08F5F1F37D2; Wed, 11 Dec 2024 23:07:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733958427; cv=none; b=QnJLVCc3EcsOhnJyL2cUBohYEhBPzZXyxc0qwH8wc94oBdSfTq43/XPdGoOBIkAxxT4cdT5RMQIo4zeSn8BMbzSuo0n59jdlsXbdbpm9kau+gMtGVjdNE8arcKpW44M9iJSSM0XLhJnxc9ooN3Ox9jPS40OMyZxECof+ODS6XR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733958427; c=relaxed/simple; bh=cDAHLzux6aHRWWnsY3+0U/aloJ8h3SyTDyFzxnTYKJU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=m4KNixbpgregGZBLrB68z+MyxlSKB86n1Va0mm+iemt+/4fK4HfhajXuVAG4G4sQx8FZnILMrgYcKxeDVQAGkK8GZ8iELy0Nih+L9H5teEEFsrvyVAoKxuCxl5H5+d3LdxNGXgtCltvgXPpdcBKPgWuwnxCrdmVZJTqH+rBqR6k= 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=bK82DZmo; arc=none smtp.client-ip=209.85.218.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="bK82DZmo" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-aa6965ad2a5so54131466b.3; Wed, 11 Dec 2024 15:07:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733958424; x=1734563224; 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=IRX2NGc6xiJDIFTWsff7g/BwiHLtEz3Oya0LbXKu14E=; b=bK82DZmoszPT8viLTe8XK7RskK96Ct5DIfRXE8TB52fXeI7X4hHZIZv90w4IuN+J6o BS07CbtCUUi66s4R4YBskt8n7NHi0LgT7Ak2rc2ICr6Gjf7gYveAAzBWIcVqqbTkMtyh f40WgUXt8EgA01XhLtcsmMIs8aEQ9wkMUk3/eYqK5de3LjJya30ZbOcRmHZuVulkJ6IY BTGYqOnE524MRBG0OUDKY2x8lzGgZz3grO4pmmNzfLqJjHRfrK1Jom9x6kcd7p8xM5AH TCG0Ynle5wmUSbCNwKrrn9LQ2vTJ5CvKwYviyqBBM21b/PnG9ty9IcLTGGR8B9+oLZ/c niMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733958424; x=1734563224; 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=IRX2NGc6xiJDIFTWsff7g/BwiHLtEz3Oya0LbXKu14E=; b=qCsZ9tojpWDpLhVVxcHILQnPXcWal4jGAPsj7cbK2k0G7WRZn/CPF7985vC36hUkQO 2ymxZCg+P9SwL+xFuqux/G6MnJBTA95ivWySzRYPQAvU/8LPjhu9S6Ec/AEAscBTOJsJ tmF1p68rz2cxaH/20H4OnY7tQNKqNfzbgiIqWTsoeeNhrbsK/dC9S4S4nv1Ni7vShxTU vFpj2QmOxaxtsfqD0US9i8pLdU5D3EYFOioB838I+s1uFD3Xr1sLG1Cc/oakBjKJDLS7 YT+twdzAh57ti/S5En4APz2Ei1UTl6vdVnPUQ4jee1eFF6LPuEhUk5ffnrcc71PWgaoF tm5g== X-Forwarded-Encrypted: i=1; AJvYcCUeb3hgBW+8vmiAVu1Mb4YlWWDBi8oJgTh6gIt2aVy54XY6DQZZgRNA5ZHAZ4pJ3dwyjNmri7Lp/kU=@vger.kernel.org, AJvYcCWJvzTQazu2GBqKgRp++tHbQu2htttPbiLMpIWNbg8SrJEB3HKlJ+kMe8PCIVFNFv2/n54vbiEbehDMK0l2@vger.kernel.org X-Gm-Message-State: AOJu0YymglDUM3thmPrTJhHENt+8cF+1HFidDQII1bwlL8BwYV4EoPvW B8Q9QDue8udgSnDWq67R+WN1uVj+Gw/TQ2KmaYalZBnCt7pA/xfM X-Gm-Gg: ASbGncurz+ZOY2xLyBU/jWk49agIgEH4txaziQ9rlBh8XLNn3/v/yRU6BWj5QRgUMd3 xJknDv3Rie9/8Amx1hb4iIFhSawWn5rzvUQqfIltEm579qAV1KLHKNg81ce+IzUZ0iO+Utttlvy U5hXMAfj3LbYHS+yJH9Fcfhtjt4aPP1aXuQgF/G2mtIEoeekdackaHRMeL9119dh/V4jV70ylHV g1QJlFfoQALAe3wxUtZ8Jzv9SjfPlDJI1UGCwtChuvnnKNgShirbumOAsvhdE012Pt7KHw84bsj iwiB48lwWT/Z939Xs8YBfiQ5yxqUUZmw X-Google-Smtp-Source: AGHT+IFCajiOnKG0joD/Pc72pLzJNIcC7CVEAUzytwko3T9q+T0Yj3qsLLg5w1Fd1b59uL/0bJtFcA== X-Received: by 2002:a17:907:94c7:b0:aa5:a36c:88f0 with SMTP id a640c23a62f3a-aa6b13b9a75mr165068166b.12.1733958424307; Wed, 11 Dec 2024 15:07:04 -0800 (PST) Received: from 34fd2088d136.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa655653d96sm747350366b.185.2024.12.11.15.07.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 15:07: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 v6 4/7] dt-bindings: iio: accel: adxl345: make interrupts not a required property Date: Wed, 11 Dec 2024 23:06:45 +0000 Message-Id: <20241211230648.205806-5-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241211230648.205806-1-l.rubusch@gmail.com> References: <20241211230648.205806-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 Remove interrupts from the list of required properties. The ADXL345 provides two interrupt lines. Anyway, the interrupts are an option, to be used for additional event features. The driver can measure without interrupts. Hence, interrupts should never have been required for the ADXL345. Thus having interrupts required can be considered to be a mistake. Signed-off-by: Lothar Rubusch --- Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml b/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml index 0fe878473..30ba4d3fb 100644 --- a/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml +++ b/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml @@ -44,7 +44,6 @@ properties: required: - compatible - reg - - interrupts allOf: - $ref: /schemas/spi/spi-peripheral-props.yaml# From patchwork Wed Dec 11 23:06: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: 13904348 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.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 914BE1F4E3F; Wed, 11 Dec 2024 23:07:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733958430; cv=none; b=QynwI9PhEWiJ9f8UjucQ5rzpvM/QmIPyzsXO4u0hoyesC66pWxJ4cDWAa+dUnWLAfwY6LxITDCYPcgqZXTXxzixbLH2bHeKtBnchCAFnJy52mrKsQPcdIYVluS8d3JAJzZd1klLjoxpfnkmSTtHD5B/MbT9DKbBPIqYmXWWwePU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733958430; c=relaxed/simple; bh=OnEi/NtWpRQrR4crDgkQmPpkIr60sP3pUIwvNBRDZyI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BlD/htOJN6arpSNfXh2/f+UdDq5Jqr9meLKLQyEAc9Fe1CNXo2o40M/JQ5dH6AZ3Bh8NH19RO48VRgnNEoY4kSWcD9HDlnmY3Y4CaoQI7qFJTz4np3CjD1NDzSlvXwvNSGah4zJsI9jhW/epGtLPNQjWoIHBU0gN1MhF2RT2LCc= 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=LacziqSq; arc=none smtp.client-ip=209.85.208.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="LacziqSq" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5d3be7f663cso871986a12.2; Wed, 11 Dec 2024 15:07:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733958427; x=1734563227; 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=JWLUOvAYC/+QKYOvlVecoPGtDiIOOdHySdnie/FYzsE=; b=LacziqSqUsHJmZeXlpvRrlLGDUU9Fsa8lCGiXptAPqVdQUH2WSqMn7Mfdwk0qd99hb Roztf01NbP7Fj5LgRbr6gb0GZIypQQnXW3a19qMuLuVLj9KxljHy9UT1HwWilNJi8O3u jRsqXGeVQZ4ku45g/vQBCFtfZvezG7FkIwppDRxOklwzHoGemevBET64IFo+J+nIAlJm 8I56lD6H2gXo+wDvxaqDiBVc2jwILtWpC/+dtJ28suu426oC9y2hwwFsGOmzSicJX7Wm 0zHz31//BG+8tnSfCcHmRQk1sd/CBmlK4U+U/a6jqWos6WZTGL+/jxQkSWckRCvYi9Mm N3EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733958427; x=1734563227; 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=JWLUOvAYC/+QKYOvlVecoPGtDiIOOdHySdnie/FYzsE=; b=cFs1l9GMGskuwMooi4cIZ3Syx2rDaR23kgyjLbVRShTDFnZaKvJ1Jkc1XQZwwNd8NX q/YOl1sc/6Dl0aXrcDInYAJWB/tjyxG8zQ9JAxc94tKom9GLo/9ZU7sMznW8MBADrLsa DL+TbKpenll5GtjnV7Ql4qSIGUGPGLA+bw2FavFlSZLcIuLUpInJqhRXn1Nl7hljM3qz AJSqBUCgcWVfXKTQ9aMvXUCMNtCctXVKRYtzZ/fSzAZy5tGWX16chO7w16Ijjq39ZRR2 4a/9U9gX0QGwLsygUgaT/w1H6lf2YT8pLDFUwWL2ffYliSR4x4SRQCz5LnKr7+XRI/V4 I/MQ== X-Forwarded-Encrypted: i=1; AJvYcCV/DpBX3HVseqXi9TICw/C8DE2sSWoH0GXDFsMli7RCVB+tTsZUL/rkD5L5EB9U/jE++6E+ZEQtEboW/Q8x@vger.kernel.org, AJvYcCX5qw0Xc0Ec0UTxRYeqrugB6ZvUAzsXei/5vACpUjvaAv8Q8rOfd1bOoZrZPH+Ie6/oSkeT6aaMtS4=@vger.kernel.org X-Gm-Message-State: AOJu0YxVwVOzwVV0omfWvZRvM07pSWViKxaTOd2GPVfAZlg3FeVCJjsf Sy3//zkp5bk7MscvNGvksjsbRqiixk3Wwhp27N1H922docUDi1dP X-Gm-Gg: ASbGnctX+PI108UVng0nhUV/Ju/nV1969mn5FvYyRqHqZ+g3p2IbfWDW3DOKt5T3gBN az5iUSG98dSyv3azNUaQ+iv8Ifm8pQwHjfGjwp/kIrvHuolLVzrdTkDmbmiTJSY5ySNDvOyB2DE cHdZNuUHx6sqCuLvGgc4Bv5RnbIyzJXrs1sdw8TA2d/RA2CGaVrvzqjDmBIS/QR6zVKUt03zhqE SAOOCa8b/tzt2WmxvsL0ZZ6GdIU5oKXZPHwD98745syq/ZbiplqVZt8SwvdFN/c2FAvFo3nzW/e 2kX01i6fCV1K8sgqxz9Vsao/v353idtQ X-Google-Smtp-Source: AGHT+IEbMeN+CFn5kcg2r4O75MDjqNXtmni+IaNtiGkbeq9G0JluHtLSqTHNITX1PXbvALxreETbhA== X-Received: by 2002:a17:907:94c1:b0:aa6:273c:a616 with SMTP id a640c23a62f3a-aa6b117f479mr185961666b.4.1733958426755; Wed, 11 Dec 2024 15:07:06 -0800 (PST) Received: from 34fd2088d136.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa655653d96sm747350366b.185.2024.12.11.15.07.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 15:07: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 v6 5/7] iio: accel: adxl345: introduce interrupt handling Date: Wed, 11 Dec 2024 23:06:46 +0000 Message-Id: <20241211230648.205806-6-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241211230648.205806-1-l.rubusch@gmail.com> References: <20241211230648.205806-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. Init the state structure with an interrupt line obtained from the DT. The adxl345 can use two different interrupt lines for event handling. Only one is used. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index b48bc838c..fb3b45d99 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -11,15 +11,22 @@ #include #include #include +#include #include #include #include "adxl345.h" +#define ADXL345_INT_NONE 0xff +#define ADXL345_INT1 0 +#define ADXL345_INT2 1 + struct adxl345_state { + int irq; const struct adxl345_chip_info *info; struct regmap *regmap; + u8 intio; }; #define ADXL345_CHANNEL(index, axis) { \ @@ -213,6 +220,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, st = iio_priv(indio_dev); st->regmap = regmap; + st->info = device_get_match_data(dev); if (!st->info) return -ENODEV; @@ -263,6 +271,15 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, if (ret < 0) return ret; + st->intio = ADXL345_INT1; + st->irq = fwnode_irq_get_byname(dev_fwnode(dev), "INT1"); + if (st->irq < 0) { + st->intio = ADXL345_INT2; + st->irq = fwnode_irq_get_byname(dev_fwnode(dev), "INT2"); + if (st->irq < 0) + st->intio = ADXL345_INT_NONE; + } + return devm_iio_device_register(dev, indio_dev); } EXPORT_SYMBOL_NS_GPL(adxl345_core_probe, IIO_ADXL345); From patchwork Wed Dec 11 23:06: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: 13904349 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.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 712BA1F63C5; Wed, 11 Dec 2024 23:07:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733958432; cv=none; b=UOfqSr2o1vKQEmWZmscWpQ9Q+bx4FmEgFqZOON7GT7vkkaz3koD8kJ3qp4ryXRDFx841lqOChddgBfpyhUG2YBAZcze7l5SDbcjtghr+0nUZATys0nP0CMeHqWgutBWrcKQXhuwIQUJ1TbLfCLxZMd7Aq4ocRmc6Nrt3jdl/BmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733958432; c=relaxed/simple; bh=ObTa3JazhoAQcFMklvFSOpfm1xZr71KI3SPq9H9WPvM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DlxCsk8qFLkS+JL9SE3KhVouggsklvGeqr0jqnXkV+i5QXNHKFVx513QnbYTPwLiBZbBZxKQGWn6/o1ufv94w0SgD0RP84zI8lsXYQb7J1FPrxG40gXlIDVhgOGPwhO0ooryV/tgn0TBl7VsBa+upLOMlq1qy55fUez9O7sxKa0= 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=SDFQpqEI; arc=none smtp.client-ip=209.85.218.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="SDFQpqEI" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-aa659775dd5so63088666b.0; Wed, 11 Dec 2024 15:07:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733958429; x=1734563229; 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=PNZ2uE9KrjIGOERXYlwpOGPZIPht42dZVF0Un6tFn/A=; b=SDFQpqEIlQuVMORJW+FyWk3Lb1QEQnbwV6jZzRelocUXINx7nJocfQXEFpwx7GBWaA u+p7k+3xviug8vSXxST9/kRWavq2naoTCqKQykGGmNbkwCzRM8o0WxRxE0ZiFi3BhiN4 XwM5LFcFSPQidYh12Bli603aCbCfPkRzy9vE1nXYCcAuY4ELIkdFfLi0zpUokyech+5l Txw5YWKsaUAcbtQNJC7VgC5IBpW5cQzMt1wUVandc6zUeEIEkzb7L87e3j/U2jGslz74 l5Cffe6D6UrfQ+u/Ldr0KIgWjx8ySYZ+t+929Z0Prj5/5CIh+M94DDNW6KGb5kTCOZ/3 R2ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733958429; x=1734563229; 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=PNZ2uE9KrjIGOERXYlwpOGPZIPht42dZVF0Un6tFn/A=; b=Y5AmpIAANx9TRXgUdYfJxiZm51fubGg4FstlvC9O7MRq61UOXg590HBh2eSQ7rXt4Q PgLCkdUf2a2KYOFmf+xoi8pUGyTjdkotGmDpupLalqbp/b+bc36Im+M7qvdhluJkk+vt ghDKOpR3wOYS0oUwNLmTCFWxV/skCwjMk6ymDTZylGwgNu2yQkdT+K10K5fbqVESNsf+ 2ulZgztpKFo1Lf56IDevTJCG2c1q1WoZyNz9XCuyiiWKzS5KbdJvTzua/q4cVICePPYb lhSdOXHBzzFZkz3kDycOMbHO1JnvK1gZIjYxj7F5l1WgKkzvPfNidAQchyqY8W03IZyP 3SyA== X-Forwarded-Encrypted: i=1; AJvYcCW1qfXr9vEJOSpmVXPbXc1pB1rhnEH5pm3lRIaJcDHXstON7r38g6OSQLwxXlNLbrS1qLLaAGU5lKC6Ptuc@vger.kernel.org, AJvYcCW2ppjxmdFXhtKzk+RTOR/SW5XUePUdHfJpUP53cut2k+EkLD0figbXRNbii4kiwtlvC1KbQ/h9d80=@vger.kernel.org X-Gm-Message-State: AOJu0YyvaMrU+Oh1tLoHAivSbkB5QqfMz61udgIBIpKQ8tQ0Xa9sshA6 /0we/e16HgaaBjc1uEJ8rUoAJL3XCWDtGBXXMzGHPSzUzKOXu446 X-Gm-Gg: ASbGncuMU1d646RLNZH2f9tHAVbZnaV5S6g0Ir2FCFd2yxXS82i6NUCLFJ7RDFx1uAD n0OOzvo1kaocPv8QDy5CTHymgDhqWZkyR9Tls/gBYIpxexyjDoJXIyPQcHtkEzjwzOgK1QwHeK3 Y5QqOo/eQixu/WgfMXAOzUmaHydrqjM13NZCzBoKwRzNe90Gz/KtT8GqJoKeVpFRToVTZ1QPY/S SIrNuwgAJeywSZzrITlhkjJZILNZl9U12cyMWfnrPQvAxfLite/7pqj9AOuzw3XhxcyUEJmcOoe cN0zZo3QEXe2nRb3YtmxXJheKn3U+dtf X-Google-Smtp-Source: AGHT+IER1MdtZVLMQ2vYkNkJUhFmq/aDJi3GLKO4MHNDAmOZdIEWQmMpJy6tfS7sJKI4Qf+4QXDusw== X-Received: by 2002:a17:907:1c1f:b0:a9a:1a17:e1cc with SMTP id a640c23a62f3a-aa6b0f3f19bmr165729666b.0.1733958428638; Wed, 11 Dec 2024 15:07:08 -0800 (PST) Received: from 34fd2088d136.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa655653d96sm747350366b.185.2024.12.11.15.07.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 15:07: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 v6 6/7] iio: accel: adxl345: initialize FIFO delay value for SPI Date: Wed, 11 Dec 2024 23:06:47 +0000 Message-Id: <20241211230648.205806-7-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241211230648.205806-1-l.rubusch@gmail.com> References: <20241211230648.205806-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 9c73474c6..3c2e12452 100644 --- a/drivers/iio/accel/adxl345.h +++ b/drivers/iio/accel/adxl345.h @@ -128,6 +128,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 fb3b45d99..fc4f89f22 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -26,6 +26,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; }; @@ -197,12 +198,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; @@ -225,6 +235,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 4065b8f7c..28d997c58 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 61fd9a6f5..e03915ece 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 11 23:06: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: 13904350 Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74ED11F63DC; Wed, 11 Dec 2024 23:07:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733958434; cv=none; b=HKq5lXqzKvtBF+x5r/out+yGqrkuRg3ILaTNifz4MgkM9EHPqHfMQ9GuaVPBNi6UaIqT1UlenYOcPBivSt0BWvT/WyFSIXyrNR6ooSf0n7vmcIKH6ggOzsRzCjFF7xNm3QFnBRseLw/jniuGdBBfhaQJJ2GXyjwgSXo2afsPHMk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733958434; c=relaxed/simple; bh=uyuuNqCUhTh6PsNFzf1gqV8796nQZKFFkD4/dxc71cI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BrK7SZNqY1FsjB+1G7ido+D2miCGLISSP5T6565QC/BBSlf6DMmsqKEAnneop84Ize2kqbPLfO+ZX2ytaACA6tLqMrK49pYpUk9fTo3cIW66T/uWsnEYzwdoZJjnW4GittfHUG0lsjbAuvfgDq9MGawlbrV7a9cFd9JVat6o7t4= 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=Vm5oXJd4; arc=none smtp.client-ip=209.85.218.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="Vm5oXJd4" Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-aa659775dd5so63088766b.0; Wed, 11 Dec 2024 15:07:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733958431; x=1734563231; 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=W9+60i128BFsYVtDJnM1GnUpwBAGwJV3rhgLTU/dojM=; b=Vm5oXJd4evafbut4oXHoxqj9hv/crrxsJ7hYX78YO/qnISjyk5sBHSSWa1k0dEnAuY AHl4usR3eibStO+DucjNeHxt3hTVflQMZZn1Dh3mPueGh+vFjVWIDYUkHPVDliCB8HMQ page/fY0hF6j+QrmX+qm3rU2IzOkyrYdQ6X2bANExqOr36X6eGOfGnELEEj1Pl33QZPD +NG8fKJ+tsiwoqg/GLEz8MAIoPq6eQnqJLRsOU5MV3QwyR6VQAE+gh0MRDIUaxO12228 tyQ/9PC5NIM5clxCdU4n/UWpUzVvJzCg4eX26HLRuyLVqVvqW32vXpjUmiyezoxVDOMR tdMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733958431; x=1734563231; 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=W9+60i128BFsYVtDJnM1GnUpwBAGwJV3rhgLTU/dojM=; b=evEMQSFMSedhrSWn3pRI2OIYqOUkRbzMv9qOarUl0uuG06UhfdVprMSka/WPgfbeaA 5tpk5YGZU7kA6km4IdEnye/vJRCUcnuh0sVwe4RlwKnWAzhesIIpOTUz+wpz7nPrcUSs 7JRyiEuFefXIjCZHp72MyVs3OyL2sNEH5vHDQ/PJAC7P4khrSPICrbi97st4xwGYcCmK wWl4Ib3mAxY5ZECEqektM/l/ob81MoIpER1F9JtyVbjT5lw2LqrLQzuRNoVokrH5BThW r4zHnBxu1A2804G6waEsyVsak/bHj/fZ5cuP811xvUGHR3VL6lGiuQ9nxoGZQe3wq5g0 /Fcg== X-Forwarded-Encrypted: i=1; AJvYcCV7Yp/O5ZmlZ3nIGj1HcUasIRQjG5JWMhWqX+QUvxia0HthVU7z/YKsOTWZmkx4ILMcpk+ySfQWllk=@vger.kernel.org, AJvYcCXyjXQ1euBh+YF7smVPqoDl+ctKUNnIV+kV5JFvBiENtb+F+lHhPUgFwJ9ztvT5GeoQSpsYnC1UisYfXAxd@vger.kernel.org X-Gm-Message-State: AOJu0YybCYEV1MjH3rEGCvhJGVevYFRsC9TAaIwKiHnpO5h9qtYaltD/ Ape3u01eK+OcNMThPfBslkwQD1sVh9Z/wGxDB7rCkQD2umaLaSuC X-Gm-Gg: ASbGncugxLPk4Me1z97o5ryS9MEz7cY7ISZ+i4ScqJdCgNnGV0fcA+jWj0O1nfeTkGG 3dxN9u8RvLMhJ0tW1j2snvOEu38S2hJ/LaYdiVEvo9RbYiL/9XInXKgrOymp8XYfJVhv/oBK6zR 9J/5HDM2eX68nshd/dtaOkHFIFFCx9mckzO3uoweaEtrqqXiwSMF1PV6uWqwZpWzelu4DPIm3ex aG4MufXgnBvxEFF2EMdzqv87U6dPJ6W+evzz3KZPsRdc1pmQLQWD16V2u+LeVsyemwvSI7WrD8F MdKHpUE6I61aq08JCHYCZpGBnTqm8ixB X-Google-Smtp-Source: AGHT+IH26ufAE/q2GhMSKYt7No5Y8a0NsC7Ifnd7R3lxk8vY+x4VEq4yGXPLcsQ2J6FIxD5n1GKnAQ== X-Received: by 2002:a17:907:9710:b0:aa6:91ca:3674 with SMTP id a640c23a62f3a-aa6b1168062mr181001366b.4.1733958430498; Wed, 11 Dec 2024 15:07:10 -0800 (PST) Received: from 34fd2088d136.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa655653d96sm747350366b.185.2024.12.11.15.07.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 15:07: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 v6 7/7] iio: accel: adxl345: add FIFO with watermark events Date: Wed, 11 Dec 2024 23:06:48 +0000 Message-Id: <20241211230648.205806-8-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241211230648.205806-1-l.rubusch@gmail.com> References: <20241211230648.205806-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 FIFO with configurable watermark. Add a handler for watermark interrupt events and extend the channel for the scan_index needed for the iio channel. The sensor is configurable to use a FIFO_BYPASSED mode or a FIFO_STREAM mode. For the FIFO_STREAM mode now a watermark can be configured, or disabled by setting 0. Further features require a working FIFO setup. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345.h | 2 + drivers/iio/accel/adxl345_core.c | 314 ++++++++++++++++++++++++++++++- 2 files changed, 311 insertions(+), 5 deletions(-) diff --git a/drivers/iio/accel/adxl345.h b/drivers/iio/accel/adxl345.h index 3c2e12452..1faad1c8c 100644 --- a/drivers/iio/accel/adxl345.h +++ b/drivers/iio/accel/adxl345.h @@ -43,6 +43,7 @@ #define ADXL345_REG_INT_ENABLE 0x2E #define ADXL345_REG_INT_MAP 0x2F #define ADXL345_REG_INT_SOURCE 0x30 +#define ADXL345_REG_INT_SOURCE_MSK 0xFF #define ADXL345_REG_DATA_FORMAT 0x31 #define ADXL345_REG_XYZ_BASE 0x32 #define ADXL345_REG_DATA_AXIS(index) \ @@ -50,6 +51,7 @@ #define ADXL345_REG_FIFO_CTL 0x38 #define ADXL345_REG_FIFO_STATUS 0x39 +#define ADXL345_REG_FIFO_STATUS_MSK 0x3F #define ADXL345_DEVID 0xE5 diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index fc4f89f22..f429b8f56 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -15,9 +15,17 @@ #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 + #define ADXL345_INT_NONE 0xff #define ADXL345_INT1 0 #define ADXL345_INT2 1 @@ -26,27 +34,68 @@ 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, 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), \ + .scan_type = { \ + .sign = 's', \ + .realbits = 13, \ + .storagebits = 16, \ + .endianness = IIO_LE, \ + }, \ } +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 const unsigned long adxl345_scan_masks[] = { + BIT(chan_x) | BIT(chan_y) | BIT(chan_z), + 0, +}; + +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 = FIELD_GET(ADXL345_REG_INT_SOURCE_MSK, + 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) @@ -132,6 +181,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) @@ -187,11 +261,220 @@ 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_SAMPLES(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 FIELD_GET(ADXL345_REG_FIFO_STATUS_MSK, 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. + * + * 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, i.e. 6 bytes at once. + * + * Return: 0 or error value. + */ +static int adxl345_fifo_transfer(struct adxl345_state *st, int samples) +{ + size_t count; + int i, ret = 0; + + /* count is the 3x the fifo_buf element size, hence 6B */ + count = sizeof(st->fifo_buf[0]) * ADXL345_DIRS; + for (i = 0; i < samples; i++) { + /* read 3x 2 byte elements from base address into next fifo_buf position */ + ret = regmap_bulk_read(st->regmap, ADXL345_REG_XYZ_BASE, + st->fifo_buf + (i * count / 2), count); + if (ret < 0) + return ret; + + /* + * 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); + } + 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->fifo_mode = ADXL345_FIFO_BYPASS; + ret = adxl345_set_fifo(st); + if (ret < 0) + return ret; + + st->int_map = 0x00; + return adxl345_set_interrupts(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 FIELD_GET(ADXL345_REG_INT_SOURCE_MSK, 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) + iio_push_to_buffers(indio_dev, &st->fifo_buf[i]); + + return 0; +} + +/** + * adxl345_irq_handler() - Handle irqs 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_irq_handler(int irq, void *p) +{ + struct iio_dev *indio_dev = p; + struct adxl345_state *st = iio_priv(indio_dev); + int int_stat; + int samples; + + int_stat = adxl345_get_status(st); + if (int_stat <= 0) + return IRQ_NONE; + + if (int_stat & ADXL345_INT_OVERRUN) + goto err; + + if (int_stat & 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 +505,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, ADXL345_DATA_FORMAT_JUSTIFY | ADXL345_DATA_FORMAT_FULL_RES | ADXL345_DATA_FORMAT_SELF_TEST); + u8 fifo_ctl; int ret; indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); @@ -242,6 +526,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->channels = adxl345_channels; indio_dev->num_channels = ARRAY_SIZE(adxl345_channels); + indio_dev->available_scan_masks = adxl345_scan_masks; if (setup) { /* Perform optional initial bus specific configuration */ @@ -292,6 +577,25 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, st->intio = ADXL345_INT_NONE; } + if (st->intio != ADXL345_INT_NONE) { + /* FIFO_STREAM mode is going to be activated later */ + 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_irq_handler, + IRQF_SHARED | IRQF_ONESHOT, + indio_dev->name, indio_dev); + if (ret) + return ret; + } else { + /* FIFO_BYPASS mode */ + 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);