From nobody Sat Oct 11 08:26:19 2025 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 CDB30284B2E; Tue, 10 Jun 2025 21:59:44 +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=1749592786; cv=none; b=V5DZjc10D5hlgwMYUiF2kPOEHbSJ3lG4d2nXAq4f4bKs6yi7WzBeycIOUxQ8P00nfSxWCWbg3Yl+bKseKR0ix6T/Ls4cV6zGQtEzVtMgRNj4TXL1CLUP/op2sL9i12WgvwVzfpkc0lUJoh5VjW4GYBjN+6ppoJMtzx3hbzY6U1U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749592786; c=relaxed/simple; bh=P/CvMntAZfwSjd7Rps/sieqyJ/DLxzwH2VXuz0YLSTI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=d6KqviLi6vnqHZzR6nDdFTIh3tyP7RhVjGp4FyViLmOcDxGWNs6tA/4ShubWg2xRKW6Ssy81n+EKM0AQAwEsKmzx3KsK8E4vb6vv3/5clp4blVIpmU4LLZKyBfo1hGI7dfucMU9FYK6PE9kNTQCUD7FWqh1Zg+wV9r0X9I9JBPA= 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=QZHuxBQD; 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="QZHuxBQD" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-45306433f71so2014795e9.0; Tue, 10 Jun 2025 14:59:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749592783; x=1750197583; 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=H7FO+Je9Jcwva34+VYHJAZ+BzdqveRP/gaDdKN5wlsQ=; b=QZHuxBQDVRnkNFlfsKqlTao4i4w/7HhwzYIEjefFvxpDYgA4Vb+lVa5Woe37HdhuLN FKPhsweSzy+VpYAYHHCJDIYn8L/3qQNuLPoq2RmmEnbTVDLViYlrTMkJ1iUy414byRYm 7g9VjS5OrHpdPdRrqkDsaiV4a10EJ8jItDUwukuh0V89g/SsBKNdWVJm3k8EGxqjbveS XfAQwnhp2iF5aDk8aDPTj4AYqOoGaesb0FYwfYA1g7xFlZYp3oM3qk7Z4r/32finaict Y/ZoAvzAOlVt5vgvsA+9CquYfsi5tWC+Y4JR2i+NvzoNx7UTqVoANWlF2jJP5/Mri3OO Asvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749592783; x=1750197583; 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=H7FO+Je9Jcwva34+VYHJAZ+BzdqveRP/gaDdKN5wlsQ=; b=PCY8lG/zAvoiO3+mcIuc6kdgKwK0AA0WvyyEIgnG0kuBO1ukIhFN9XRD3CDaX+l6qC X/MovDGeZlwn+Viu9WB49kdVSmzQrcr6RuccgZBmiMq/C2R6NSnWb2To/DtAOoK3HNyU NUbkTbhhAiWacHma/6aN439O/SN+xwi28h/LKwln3mMxb71PTzU/VMa59S9dJa3g7TIy cBj+kHIh1svjPsYEnkhVhUEJleJajHka4NmqAQyfdJyGSl6GUtAvQKWKou1iuNMo5lBH FRxQHCyHXGccSinCgk3NrFsKzjYSsUSyVCVhATq1EwHA68ESA5KHgOSzBT44CNUyNR8l 20oQ== X-Forwarded-Encrypted: i=1; AJvYcCV6IRjY0bU2esAj45zWph6coEyiNdPUMjus9jt7X5TYdLq1cZQXlIylL55LQCZle7Jlw/jA5pJbKJvCZtP8@vger.kernel.org, AJvYcCVtwd/bZOQwUXuJGfTh8o4m5xNZ/TghT0O82zmObTd0P1DcvXkHzQpu+mvpEp1SaTeDugebkeaiEf8=@vger.kernel.org X-Gm-Message-State: AOJu0YzZxRaqhKgKSFGsTLQc5j5zjshGTaaluN5BDAwmarwaAtg5vsRZ ap4C+bQamJY1DsGmHkk7MPw/skFS0ALawS68or92dU93o5bZS8C7+dyB X-Gm-Gg: ASbGncvkpfCPxN/ngLJVVCWvOsTolo9LB9CgspF2DFt1DL9DS2JOmvpekkbJPlNcGpr qC3FF8311Z9vrfADd1V6VEFiXrlLdlcyb5JroPeC1clWMYeENt+kLaGb8InX59GB8K8V9JBFS/1 pLTBiLaheZLKbbEX82kZgnLZmcGr+gKmkm4cygsWlmbq1cbm4UsmawGZa5bQuI1DY+84lZyQviF PMSEWpEuMBW0w3LLFnzOqlDqM9UmO/Hs8IGF/SV8NwId2hh4zatcWUrVBT2PrN96yjVhJMafAYy 7avYOCSjlPW/LUkv4OylKaerHj1mcPwnepNbaIrXUebrspsGGIlwNHdhmxiEdPKW2H9N9LZlO9V Ci1EncbzKUebw6hrmD4jBCCyiy+10u248RB2AR6fHnDE= X-Google-Smtp-Source: AGHT+IE7KTpu9246gYxZ165ddvXaFZhc5FqHKJuaRE0QQUUwGsfRiRI5icWbta6TyUMscW53nDtohg== X-Received: by 2002:a05:6000:2504:b0:3a5:2ee8:ee1d with SMTP id ffacd0b85a97d-3a558a1ef01mr172863f8f.16.1749592782939; Tue, 10 Jun 2025 14:59:42 -0700 (PDT) Received: from localhost.localdomain (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a53244f04dsm13312647f8f.73.2025.06.10.14.59.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 14:59:41 -0700 (PDT) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, corbet@lwn.net Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v9 01/11] iio: accel: adxl345: apply scale factor to tap threshold Date: Tue, 10 Jun 2025 21:59:23 +0000 Message-Id: <20250610215933.84795-2-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250610215933.84795-1-l.rubusch@gmail.com> References: <20250610215933.84795-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The threshold for tap detection was still not scaled. The datasheet sets a scale factor of 62.5mg/LSB. Remove commit about not scaled threshold for tap detection, and apply scaling to it. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_c= ore.c index 7c093c0241de..d80efb68d113 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -697,17 +697,15 @@ static int adxl345_read_event_value(struct iio_dev *i= ndio_dev, switch (info) { case IIO_EV_INFO_VALUE: /* - * The scale factor would be 62.5mg/LSB (i.e. 0xFF =3D 16g) but - * not applied here. In context of this general purpose sensor, - * what imports is rather signal intensity than the absolute - * measured g value. + * Scale factor is 62.5mg/LSB i.e. 0xff =3D 16g */ ret =3D regmap_read(st->regmap, ADXL345_REG_THRESH_TAP, &tap_threshold); if (ret) return ret; - *val =3D sign_extend32(tap_threshold, 7); - return IIO_VAL_INT; + *val =3D 62500 * sign_extend32(tap_threshold, 7); + *val2 =3D MICRO; + return IIO_VAL_FRACTIONAL; case IIO_EV_INFO_TIMEOUT: *val =3D st->tap_duration_us; *val2 =3D 1000000; @@ -746,6 +744,7 @@ static int adxl345_write_event_value(struct iio_dev *in= dio_dev, case IIO_EV_TYPE_GESTURE: switch (info) { case IIO_EV_INFO_VALUE: + val =3D DIV_ROUND_CLOSEST(val * MICRO + val2, 62500); ret =3D regmap_write(st->regmap, ADXL345_REG_THRESH_TAP, min(val, 0xFF)); if (ret) --=20 2.39.5 From nobody Sat Oct 11 08:26:19 2025 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.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 65044285412; Tue, 10 Jun 2025 21:59:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749592788; cv=none; b=ZiHGgfI7Q0JnZBUehuFM9tC2gymiGzQOARKt6LzC0RjhD0/Uwtm8KahuNMuZVsORBYY6DkhD75jLEg6J7NHMg3uhFWPbbWJMY0asvBayFBZN+NKXe7ObZUy2DKrk8oIsCJ+SAemW8vims7xIqt5mjjymLgGiizGDXENI9Tf4TgI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749592788; c=relaxed/simple; bh=8vHmggxLoSxfMCfpacFahdMv3fo81otuy0QGvoZZLrg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=K0JC3oTDu6fFh0s9cOj3cmphxjiHf8PpPok6JFrs1NZG6MMS2kuHlL4H3nC8vQRvEHbh1iiLP4LyWaYfqPs/LA5vamLEpZWuSxwzj+JnCCfaBsaD+xfY8qPmaRHIY621oImRyWwzBjXAzTNtZlOhKx0fikoyLGvO/XdyIoGttMQ= 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=W+S9tnaK; arc=none smtp.client-ip=209.85.221.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="W+S9tnaK" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-3a4eb4acf29so736555f8f.0; Tue, 10 Jun 2025 14:59:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749592785; x=1750197585; 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=PQlnrgZ5mvFwl5ucyOyz9AjeVps6b8rGKCvnmyIQJ6Q=; b=W+S9tnaKabGI8injmoPnrVe93jpV0YWfuemnqxBeIsZApMOhKo0dNcfnXe8k/isw3v lvf7xdCpS6yzkeuIvqmc/S3VKSMYfPKGVTdPWopapV8uPa7zxiNw3Ww1ohiV6Cno1MH+ miMo9bixKHxVVTSltPFSWNTgnH39eU9Plwpdah7nhV/ValMXpM7u61U3Z628vWJx0NST 5H/zAuuXvOw97jESPBbF5JaM1UILgfm5UaZ+egeUV5maBMHUs/udboyXdGYyahDNbW5u 7jqk+RUPzUDdsJqZdRRh0w4TKn2PePG3vEaTYT202MdNbHLMYfpuBOIM3QcD+Zc8CYTm h47g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749592785; x=1750197585; 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=PQlnrgZ5mvFwl5ucyOyz9AjeVps6b8rGKCvnmyIQJ6Q=; b=MucV3pA1K50hoPWuKdj79NJdyI8aHUQCn14rJ+EdUSqDN7KUeGopJRWV54GpXPW7rW MNyCb8ntqwgCoVJYKMhXyhfiEAkDH7cdN1rTTpTzf784E3FtkHmWuq0l9g5L1SHcG5+J aXpJTynv70wPDTZ4izgrajmH0NgDHeyHZrTyKJN7pr+WGxsYH4GHzcjYjZei86az10sP hc3MeN/8SRZHjy8gDK32jTN/cQSTB7/arGxokdpOf3MBV/c0rHLIaS9Y0BxeqapiU+T5 9BVfoue2SZvGuNalbEP0QTauk6yRSxTYKIozLKlKl1eCqC2Y6vWJx5VClsX42keGK71Y 4eSg== X-Forwarded-Encrypted: i=1; AJvYcCVZ7EdKhuOo/sBbW+SmFbYSSmTKSG99AB5I5AaqdZfBl5guH/EHaVyEwUuXtAFVFtqA85BdSE02PO3O2uL2@vger.kernel.org, AJvYcCWGiGTSTRNoBosjnk5QgoWJcKau18x1XxEpv+EbER4Jtet7NqostH9VZztotMJQYimuKhaEUdHSo4c=@vger.kernel.org X-Gm-Message-State: AOJu0YyouthsdUxgG0AiVDaRDEArg0MdirFqcMP/HSMbHm9YSoR8/U8h hxfKIsMtUhMJdrIXO0u9ybp1WyudtOqde9n1rT2aY2CG2EzD4U4J519o X-Gm-Gg: ASbGncvdzJd9AaIbE+uZHfWHKB3iMkkKstu5gKzXpy3LacH+PHaQfemAk0ECULDelVX Y6qLIJMXvSesoQFoKWtZd6dCiO1RV5qw9DtsHkRneJaZHbeh+em23bUUcZrmCRCrCYrJ6+AXyzW yUGJEXd7P0y06pW5Lg0nu9t0ob4smSx5FbZLyhct7TW0OLLxvCbeerm9VwDG4QoxKkGUCSy7s3K 1ZTdKu0MtsG4YFmHZqSMXxbcwl/YHEKYj8DnIvnU9r3zVAofsbYC5W8Li1Q4FVd349P/f8Gcadh cNk/7pl26aBpj5Kx5CNYjDAUG1yTC+DJziuKQU3z3rYTT+Wo04tPCryXq8zHyjTlNzprTSTifbP WhLdTsS78uF8cG2+4/7cfH9H3FHyOtdN4 X-Google-Smtp-Source: AGHT+IEVotE5JhRIqghzgJ0R3Mj2ZNKwZd+LDJtLlXSc7+CSygYJpqFTOdi3cz8bCtjsMrpuzlzEYA== X-Received: by 2002:a05:6000:26c1:b0:3a4:f8a9:ba02 with SMTP id ffacd0b85a97d-3a5586b8858mr199514f8f.1.1749592784654; Tue, 10 Jun 2025 14:59:44 -0700 (PDT) Received: from localhost.localdomain (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a53244f04dsm13312647f8f.73.2025.06.10.14.59.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 14:59:43 -0700 (PDT) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, corbet@lwn.net Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v9 02/11] iio: accel: adxl345: make data struct variable irq function local Date: Tue, 10 Jun 2025 21:59:24 +0000 Message-Id: <20250610215933.84795-3-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250610215933.84795-1-l.rubusch@gmail.com> References: <20250610215933.84795-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove variable irq from the struct state and make it a function local variable, because it is not necessary to be kept struct-wise. This is a refactoring change and should not impact functionality. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_c= ore.c index d80efb68d113..07abab82d093 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -133,7 +133,6 @@ struct adxl345_state { const struct adxl345_chip_info *info; struct regmap *regmap; bool fifo_delay; /* delay: delay is needed for SPI */ - int irq; u8 watermark; u8 fifo_mode; =20 @@ -1119,6 +1118,7 @@ int adxl345_core_probe(struct device *dev, struct reg= map *regmap, ADXL345_DATA_FORMAT_FULL_RES | ADXL345_DATA_FORMAT_SELF_TEST); unsigned int tap_threshold; + int irq; int ret; =20 indio_dev =3D devm_iio_device_alloc(dev, sizeof(*st)); @@ -1203,11 +1203,11 @@ int adxl345_core_probe(struct device *dev, struct r= egmap *regmap, if (ret) return ret; =20 - st->irq =3D fwnode_irq_get_byname(dev_fwnode(dev), "INT1"); - if (st->irq < 0) { + irq =3D fwnode_irq_get_byname(dev_fwnode(dev), "INT1"); + if (irq < 0) { intio =3D ADXL345_INT2; - st->irq =3D fwnode_irq_get_byname(dev_fwnode(dev), "INT2"); - if (st->irq < 0) + irq =3D fwnode_irq_get_byname(dev_fwnode(dev), "INT2"); + if (irq < 0) intio =3D ADXL345_INT_NONE; } =20 @@ -1232,7 +1232,7 @@ int adxl345_core_probe(struct device *dev, struct reg= map *regmap, if (ret) return ret; =20 - ret =3D devm_request_threaded_irq(dev, st->irq, NULL, + ret =3D devm_request_threaded_irq(dev, irq, NULL, &adxl345_irq_handler, IRQF_SHARED | IRQF_ONESHOT, indio_dev->name, indio_dev); --=20 2.39.5 From nobody Sat Oct 11 08:26:19 2025 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A345C286D62; Tue, 10 Jun 2025 21:59:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749592789; cv=none; b=MdU8mij5lvwbcqfCrV5leH5+cPOPL2LcFtJH9beDeYyGiUl69O4OCfOA1iYaFz11OepheGtVhzDuLbnU/ArATo+nrIJQJ1kliTpG+Mrl6v2NgfAvfcvVmpI2WkKpVQFkFO1u5Q+3Icc5Jd7NO300p+D4Wz/+LL87s+Hy/HMj2XU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749592789; c=relaxed/simple; bh=ix3pF4nDjDULKTSRXDO4PMOHHFtggSVSx9q/iho6mEM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=B3BJgqtb9YgQkEcuquKNwUHJ8o9E7hOn+QPRRhqiZCl9FY/cOFoT5RMdFpznqtWD/M870hT7qyETFaZtx2i06G2hmU1uwFzcbFWAUiT265AeUvtmxCVsjv3N7Ybql1sTfm2ntS5hOlYTd01WPxv68++mzBzU6cBa33cJEcLKhM0= 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=FRcal9Ye; arc=none smtp.client-ip=209.85.221.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FRcal9Ye" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-3a4ebbfb18fso528355f8f.3; Tue, 10 Jun 2025 14:59:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749592786; x=1750197586; 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=aZihwrESiDdk0o7BFmuednPt2Ppfv/QodaVRhK+kps8=; b=FRcal9Ye0jtIBdLY9elEVK1QIYhQej8JjpKwoWM+sfhjgWcSIDVTod/q5bvdwh8BWh xPeqWZm7dvcTW23qJqoILLvQQd7gH8Vjkkmrl82Nt2KDNyHc4LSGL8pObiR9ktLYYcNC yvkIUvERmE+cyQ1zfRbZWVrrN42qThsrima28QEWHtE66NSlSZ9VDPJJMQjVjrCmacIu CfBJCnNlPsmBUgMvG62mL/uVGGQUi6o/XOKiIx40165/dqexajDZbhc6iRBacJVWmC9K gHUtaNG+Mx3REIcXjPrmW+v5L59Y64rNPbZPkXvpz4DCdgYQvrroketAcyxVM+ncY72w KTsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749592786; x=1750197586; 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=aZihwrESiDdk0o7BFmuednPt2Ppfv/QodaVRhK+kps8=; b=MJhKptXc1Kl3m65Fj4Uj3UDUBHwPofSVh3TOXVa4Kt/TgPe8I1/6Y4DPvAVVStyk3P cOFMU1RDAVaK6SUzgqEYrOdBdR2oOrCBUTu1qi2hkBETVJdmkxX4pvJOi+Xo1UJ2TV6M ix5IVRNm1VrwAnR0e58uKoOynu1ShCXV6Z3Hxoh8GKYdvaGjqCAH35v1G5gW9P05k8hZ MbeQGGJDnqoJReycaHFOkbVYs8YTsxeTn7+WSBi6hgksCYUjxIYiAwFAmhP+tTtjHhUN 4MR4pz2qNncdS8leDzfacWnV1PvBEailAvpDL9mghmpgdTAIidUwoI6ug8Z1TTRwEvtr o4zQ== X-Forwarded-Encrypted: i=1; AJvYcCUK16JNYMcFU6Au2BFdTME5zAfRrOx0HthcG1nPaLrUxCQDQS0CMRp1DTkHd0GXa733+VI9IcBeH8o=@vger.kernel.org, AJvYcCVfJx1p9rlcvMGt4CsePXTZymQLUrUUXgn7DWq4xVmtW6b7qdJyMyYwHQ4siL5/djgXKLvKzYlfTBTzIL5w@vger.kernel.org X-Gm-Message-State: AOJu0YwHckA6l0QhSxM9zkl8Vo/AobE5zmFENpIcP3+Uz4rJKugI41Lw Ce63XlT2YgRy90rg/89ahym0lWaQTseDtFZBm83xYK82xjQOOHd7mT+q X-Gm-Gg: ASbGncuPr1NW2XUgBAGRHjT8FO3vwuBm0t5Xb7Y1A9Exnw6qqVGVeK0UUtOlW1Ue7OO /EpD/uyS8RePrRG6Q+K9PylwUWII9oh6oEf/t0wiq3gV6ybyA+U7V402/2LIazw1XEfCtA3ODjS 0nc1My+qOcRqeVXHXyAAHTugMHBGIx4zE6ct1K+KNoGRa+Ce9Eg/pK8h+W4ZAFlzZMLAXqjtCwJ gnop5tEAb33KpteG9cWjmYwR8zNayroFMFcNmLcFP7P95Il7VNr09ej0DQMRw6w4bv5VN6sgyi2 fquBtGpjcCxwz3G+yz69P5QuNi6AhPl/AxKd2v5oHxPh+ycYA+G8L28BTV69g1gTrQB2RpN2jm/ XsVb34rQNvFpyp+L28IPNdOutkmznVobF X-Google-Smtp-Source: AGHT+IHemCnKV+zCoQj9ZCH0kIyA00khi+iNc6zWGNxAwyW8NoqG5fnpY+G85f+UPPqdY36d/eaz4g== X-Received: by 2002:a05:6000:438a:b0:3a4:eed9:755b with SMTP id ffacd0b85a97d-3a5586c414dmr221554f8f.4.1749592785662; Tue, 10 Jun 2025 14:59:45 -0700 (PDT) Received: from localhost.localdomain (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a53244f04dsm13312647f8f.73.2025.06.10.14.59.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 14:59:45 -0700 (PDT) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, corbet@lwn.net Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v9 03/11] iio: accel: adxl345: simplify measure enable Date: Tue, 10 Jun 2025 21:59:25 +0000 Message-Id: <20250610215933.84795-4-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250610215933.84795-1-l.rubusch@gmail.com> References: <20250610215933.84795-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Simplify the function to enable or disable measurement. Replace the separate decision logic and call to regmap_update_bits() by a single call to regmap_assign_bits() taking a boolean argument directly. This is a refactoring change and should not impact functionality. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345.h | 1 - drivers/iio/accel/adxl345_core.c | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/iio/accel/adxl345.h b/drivers/iio/accel/adxl345.h index 6c1f96406136..9385affdefe3 100644 --- a/drivers/iio/accel/adxl345.h +++ b/drivers/iio/accel/adxl345.h @@ -73,7 +73,6 @@ #define ADXL345_BW_LOW_POWER BIT(4) #define ADXL345_BASE_RATE_NANO_HZ 97656250LL =20 -#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) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_c= ore.c index 07abab82d093..cae9e37e216f 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -233,9 +233,8 @@ EXPORT_SYMBOL_NS_GPL(adxl345_is_volatile_reg, "IIO_ADXL= 345"); */ static int adxl345_set_measure_en(struct adxl345_state *st, bool en) { - unsigned int val =3D en ? ADXL345_POWER_CTL_MEASURE : ADXL345_POWER_CTL_S= TANDBY; - - return regmap_write(st->regmap, ADXL345_REG_POWER_CTL, val); + return regmap_assign_bits(st->regmap, ADXL345_REG_POWER_CTL, + ADXL345_POWER_CTL_MEASURE, en); } =20 /* tap */ --=20 2.39.5 From nobody Sat Oct 11 08:26:19 2025 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 240DA2882B8; Tue, 10 Jun 2025 21:59:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749592790; cv=none; b=PcovuRFMiWt9EgUUHiTws9oobPsAkXoI3PempyPFdiKLdZjyd6YEHCbJGDe9BUdd+39ylkamsNWtQUiksvmTlTGEIvZGL2pbd24MgVUbsEjqCgCMjn3BSBz+GcyWbs1WjqrX6PL/tSvqPjHgFzbX5sCSkwfMybkrRuHMs+FwQF4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749592790; c=relaxed/simple; bh=gLYNKyZfadjn5qum66b4keW5vghvWeQtJMgk7Q7EcA8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UOLSF8cohFW9foyi1D0/cUz5dPSKf3i5y2Xuq77OW3niQoaB43uL8rni36Mdj7o7HMjbcE5yLS0XYSy+3G2aqtm5IkhjJD5WfdkFUr2gw1iLXMfKE385bLaLRJ1GCk90C/VU7JwkEsRksoWLQ/EbgExZTI4f9rACdTsge2gsBZE= 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=LGPBiut/; arc=none smtp.client-ip=209.85.221.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LGPBiut/" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-3a4e6a0c274so748365f8f.2; Tue, 10 Jun 2025 14:59:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749592787; x=1750197587; 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=fGhgqRwNMDzn/g47+sfXdw7f8ynPaKXSjobY4O9cee0=; b=LGPBiut/hybLtDBDs7Esymti4KTj0KYVV+4Le4hBUfw24nr3VDJYY3xEh+GDFiOZKX SG7oJmpTRR8Y8b6YwCscajjkBZRkYy1twFBD355S9W2OAiCB/k3lygVWVoCrvqPKgnwJ 59UPuveFoacy0LSpnMK2W5aCvPwUMjbsvcEsFXfEadg57JkPN9gSGilLGGMmdYPE38XA 2u11f4dS2W9lbbLr6VLrQdAwejmvTEwAtZzqPcK2BCCOpb7nyl+TgFKqMuFmAIkV5dgN MNu7zRQZw5efdhOSyP+pEE10XtenxUEYcoZuaGouKcPhP+10QIL/YlYhiSzEdtzL+0S0 OjiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749592787; x=1750197587; 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=fGhgqRwNMDzn/g47+sfXdw7f8ynPaKXSjobY4O9cee0=; b=gx3R7iySddD8GuLErLv0MFdEWat4Zi+11Ri/pwY/IjxSotK0V2XdXOieXPUK/GVFMj 5KvplYCEVYoFXsaOdZogTWv+JspH15GGCQ9egh2EwFCx1bpSOfh1MxjMl+ngNTT7ONrG a4KEBu6Kzy3MJmkwN+jB2rDv8LBlpeegRcGr7ac/H+xqL40xF3hWqWzDoHJwbd7s+R8R XXp/9NRW1cCw5xD9t6m5iolfV7YhpXmmuH0w5fK2+iYhXwXl2JE/i7pjxKkdmcE+hF16 QU4CCayXhoflso3yK/XGeN1kJqJ1caULlrRXSUxuW24ZaR5J51p8C4eNbN3Q8GfGasmi 0OXg== X-Forwarded-Encrypted: i=1; AJvYcCVRf8Akxj9taFntjkIjXrFnoHe9V6kPNNytpRXc6wOiYX3WlL+vgCFucxreVRHkpIqkkg+3XalYtJ4U+ZJ/@vger.kernel.org, AJvYcCXQa4sr9RkeE9/LSDEri+8nxEcPX6p6r0gVOuYOpB6ABgcLTCmfoZGv18+c1HG21xUkNaOrm2yeXi8=@vger.kernel.org X-Gm-Message-State: AOJu0YzidJpmOnRRGWJOdSvZtn1oiJKGIFLutu47/GmPjJ9ABbgus9+x RxxZc+GMokTBC1CLA1wEn2Lu+3y6ODPJ8cc9xkGZNebFg+nuUfApAYYc X-Gm-Gg: ASbGncsPPuwPtGiYUd78mguS7SZ4CzBR+n5/6ojgfUObz6Y5VmtS8jhLjEC9ZfkDLmU lkQq+qPUeI829I+8kxUHaYGOgSROUhr7cE9Sli/16GA2auV5n0zh5FPfLju41Q/h4GfdEz5Qzr7 evYNn5noN2cF23Vor9YrTKv00Lj0N4uDqjQJby5sjxQ7P63DOwJjWUBmYG3FhAuh5yNT4WPOaAa IP3NcL0wPT2N7pLjcp2zD3DSUBOwPuvVsg3VB30WQ2KcNR/5kZdp1IP1kVhgTdrOT3UeQynnbR3 ZRj14CRk/wUWDpTNoyUeprQwU3WttTveVlfkS/8D0bb1iHxEvXJ98/MPlUxy/Y4lsG35tBtj49G Japlxkqb8VUib0T/iGXbwsy/ibTA5g71CZ0OlxZjnPFc= X-Google-Smtp-Source: AGHT+IHTU4elXrcJiKN3xNjpaTdbAvznXETnWPAb0sKX/d/YhvKdT1EkMMK213gdyMiX2D2K0ia6rA== X-Received: by 2002:a05:6000:4284:b0:3a3:71fb:7903 with SMTP id ffacd0b85a97d-3a55880794emr173135f8f.10.1749592787289; Tue, 10 Jun 2025 14:59:47 -0700 (PDT) Received: from localhost.localdomain (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a53244f04dsm13312647f8f.73.2025.06.10.14.59.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 14:59:46 -0700 (PDT) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, corbet@lwn.net Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v9 04/11] iio: accel: adxl345: simplify interrupt mapping Date: Tue, 10 Jun 2025 21:59:26 +0000 Message-Id: <20250610215933.84795-5-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250610215933.84795-1-l.rubusch@gmail.com> References: <20250610215933.84795-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Replace mapping all sensor interrupts to the corresponding interrupt line using regmap_assign_bits() since it takes a boolean directly. Further prefer the units.h identifier to cover the full register when bits are set. This is a refactoring change and should not impact functionality. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_c= ore.c index cae9e37e216f..18c625d323ba 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -1216,9 +1216,8 @@ int adxl345_core_probe(struct device *dev, struct reg= map *regmap, * interrupts to the INT1 pin, whereas bits set to 1 send their respecti= ve * interrupts to the INT2 pin. The intio shall convert this accordingly. */ - regval =3D intio ? 0xff : 0; - - ret =3D regmap_write(st->regmap, ADXL345_REG_INT_MAP, regval); + ret =3D regmap_assign_bits(st->regmap, ADXL345_REG_INT_MAP, + U8_MAX, intio); if (ret) return ret; =20 --=20 2.39.5 From nobody Sat Oct 11 08:26:19 2025 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ACC58288C0C; Tue, 10 Jun 2025 21:59:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749592792; cv=none; b=nN1tzJjsDbWjj399Ml5NKm70p0lQQdhAmGaB1nPjXg9jGvnJhmgzUoiLCIaDZ2wioJlgq8tq0S8cBeregB4IyDJpZyapWhELSztUS58KjRoHpovKCvbdGjyREB55Mk4eMyTq2QrKZXT7Vx0FlQYc6Uy9dKes/zOG7cCMrlSesvE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749592792; c=relaxed/simple; bh=54bn4lQ7mU/PAKH83cOXrL5Q+ZOVpicKVQAuJhn6SaY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iq5XqcPl+nYvazWPz9+p6NRb7DlT7WkJ4bjx4HB56DNRA9l+sNZnXNO0A6fX3R0AhfMb4xEzqyNUwGm/9JqQ5VrXyTqA3EnA3uvJdwXlUPPlNra6/vKIvTnx9si8slkHjLWPVWruU3ML7gg7sMZ4+W8KGTFtDxbjhB3t7ZUHvFs= 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=M2rvy+pj; arc=none smtp.client-ip=209.85.221.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M2rvy+pj" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-3a524caf77eso796639f8f.3; Tue, 10 Jun 2025 14:59:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749592789; x=1750197589; 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=c+p92P536pnFRq0gbfd6NRDeuq5jfHDQEUuWlYeMLe8=; b=M2rvy+pjLml4NhruD18O9uazM/E7flfTM8nc20CW4DoB+63nftXKui7kSwDg+WT2AE E49YSeRH4q4KRK0d78ZLbq5ogukOrn0qgEwXxR0R0ZqzrHh1NLBW7lOr7kVT2qVzv0qt qvVl7RWGyKBl6BVCV+NmJrJKbW6nzehSVi+70bVpFb5Z3llqw26fjUxdW/yczdsANgfM E1F9OhWWBgyk0VcdwSHeo6YlrnuNV3EYZj5QSpS5S056n2pQp6WBUt1tb4KwRqKOgnce iZ2DMvTMHYaOeUt2JuNtJ0BBF+9leAlh7vTHF1v8QavZ7EUAiXOt358xyWgLkhlJIXN/ 1zgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749592789; x=1750197589; 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=c+p92P536pnFRq0gbfd6NRDeuq5jfHDQEUuWlYeMLe8=; b=MA+GFt4YROWrOUlEt3SA581hnkm7QVEXaXclBAZcHwcLqaXBlRmY36mMWMIYpIpCX+ 7Z5mDE/r7IGdVaHbrffkSQh/SE8aTt7O+1E8u3sIbPC+4Kzx4zgl2pQTqNkVhP/0+MgZ a3NWYL7K/+J+3YwrQhcXOMJUhyCqj8bbq6tRikKJdwbXEVW2F7MDJkgPa508tKFx1Qs9 rhyi1fgW0EwYMmBrXMt0eag3FH2mP9cWFZjHmzSpczw8Z1talK584XD8GDEMYl3zingd EvMP6bz4nK4VIMKRc7i/dm8WqazUboFWr2TxZD/gTgcWF0z1Db3DxX5ST7QR/CYBuI08 2FDg== X-Forwarded-Encrypted: i=1; AJvYcCWq7B25sqZ9Xi0KvcWJSnHXx/t2kcckxBhEGD6jXwun4vxqoYIDfiSMSHhw1wF4qCFesPupTeTKJYE=@vger.kernel.org, AJvYcCXf9/g83Q9fgjbmKP/6nLi8i2Brc+sycShvbrupVV7nfCQiM1GX1PtqJ9Jd/wOqoXlMLLqAb1KAEJBxeWNV@vger.kernel.org X-Gm-Message-State: AOJu0Yw/S4SEQL9qIEAdF//CY9yQ1jR9agTJaafMCS4uGhFWAtkJOx49 /CaTombbYwNhBNi6PCjr/H8RVO4spnr9nELjTAvTy2PXjv4Ho/s2zj5W X-Gm-Gg: ASbGncuzqFjOSnYp2LmnAG+yinXk2um1mRDHJdeLDcqVyUqcRWpBQ2+qNKqZMXVAaBK vfeN8bZtVefb6nqdXcaru0JUX9Zdn+G88qUq27mULN3VUIFwtGbhD/hKiktn0j1r0N2t3W/X3H3 3gYjdDvkIC0RvnS+JVS5fhqTGX1YIsTioUBB2shw/KM4OZ1IVjOct7wiHscXHiwVSlD4qhdlLsG ddTXgKoQQ8L2IzQa25p88SmZjnDz/QFTuTN6mynfhpjbOI3V3fGnJ82W+yzd6FTTIQ6ZLErpfBt 4S2v3fL0uSMoP/Mf3saD7enOWMWe9EAPMCg3lyu4YQJL9z38wiohwi8jvtY19BUwnJjIwLstFVY IxRDuICSQ9pHIgNoMyI4z0D1Rw6G7WK9E X-Google-Smtp-Source: AGHT+IFzln4u1I7lP7661yh4U+ZYHN37VdTCF6E6HlOX5FAG1Dy9xh/dbtGtPsSNekH1Ye1JoMq5Sg== X-Received: by 2002:a05:6000:1a8e:b0:3a4:f744:e019 with SMTP id ffacd0b85a97d-3a558a1f200mr168473f8f.16.1749592788963; Tue, 10 Jun 2025 14:59:48 -0700 (PDT) Received: from localhost.localdomain (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a53244f04dsm13312647f8f.73.2025.06.10.14.59.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 14:59:48 -0700 (PDT) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, corbet@lwn.net Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v9 05/11] iio: accel: adxl345: simplify reading the FIFO Date: Tue, 10 Jun 2025 21:59:27 +0000 Message-Id: <20250610215933.84795-6-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250610215933.84795-1-l.rubusch@gmail.com> References: <20250610215933.84795-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Bulk reading from the FIFO can be simplified. Remove unnecessary variables and simplify reading sets of x-, y- and z-axis measurements. This is a refactoring change and should not impact functionality. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_c= ore.c index 18c625d323ba..dcfbfe4cac0f 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -884,15 +884,13 @@ static int adxl345_get_samples(struct adxl345_state *= st) */ static int adxl345_fifo_transfer(struct adxl345_state *st, int samples) { - size_t count; int i, ret =3D 0; =20 - /* count is the 3x the fifo_buf element size, hence 6B */ - count =3D sizeof(st->fifo_buf[0]) * ADXL345_DIRS; for (i =3D 0; i < samples; i++) { /* read 3x 2 byte elements from base address into next fifo_buf position= */ ret =3D regmap_bulk_read(st->regmap, ADXL345_REG_XYZ_BASE, - st->fifo_buf + (i * count / 2), count); + st->fifo_buf + (i * ADXL345_DIRS), + 2 * ADXL345_DIRS); if (ret) return ret; =20 --=20 2.39.5 From nobody Sat Oct 11 08:26:19 2025 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B828928934A; Tue, 10 Jun 2025 21:59:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749592793; cv=none; b=XD/HPh9jBLqr2EAhmJpbLl80aZowBiIKmoXtveTp+JVJ0mSMg6Umq14axBMwwgW9TR8yzJsfJUpm0aZzw4LPHlTGkvjTBIZ0MPtzIW+jEly3cvNhfUM44QoIlgALw/HAKEH5JnoXhFvPniLAcq9jYD5bawRSeP0NhAsFjAFmjjI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749592793; c=relaxed/simple; bh=Excy6KTjLJIcHfsatlEND0MXIgSw996D4QyB7VyZH+E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EtnYUjMALA+/hN7gYQ2rCYtooUAeIsYjIGIRCbCW3T/sCjuvXZLz9FGKLCs2ZGKvEt+UB0V+dxVGmqu2cGW+4CFIzB1Xyqcs74gM7zTjMdb6mMdnU7eYPWQFUtI0xRT2AnHKrityW3QM8p9qG/kox8c2VFYLIfosUThVqOrE+b4= 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=GCVCAqON; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GCVCAqON" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-450cfb8b335so4806635e9.2; Tue, 10 Jun 2025 14:59:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749592790; x=1750197590; 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=38n/wHuxAFqfv+bXMk8iuWO10rdnMupQMWYBFpyvjP0=; b=GCVCAqONxlFg9OWNlWT2yRwMMacJGwnxAzStMW1nhUwWFG/QaKa61DFX44c00Kt9NI 8mZxerRIQwZFDsPyxg4InU3upofdAW7nFDjrzEw0dmHoe5SEJuFxZwUTKWb26ZrZk2AY U1Ct+2lk+Fvw3AqcT8vHPreLE1P8iqZf84Nmiw2Jkex0UMuSQJmWEe2Y74LAWBULkwlq ndn70v+XqJrik06sd/wZ926R2wIQY+J+iL8zRxU1QjSfHnqwPXh/+8RR8NbcQTr62moP 7B6EJzOBQknyDc+XJYt0/0KUyaJhQ4r4xjP4ck/ialT7AMa5NXrp8V7ent63JbNh6TbZ U0gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749592790; x=1750197590; 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=38n/wHuxAFqfv+bXMk8iuWO10rdnMupQMWYBFpyvjP0=; b=FosnDYpg1c2zhjzzKAhpHL1w/kTSRE00YpaqlVrxvULLbNqdWdEfil8bHNQqJR/Mpx TRb8RCnXfGdSc7Jg/2p3E4Jk66RlibYKZgMGIZcCjHX+YkvT3mgEoQunJCYksCBcH9HU aWqro3ms/IetPaO1htonfRKBIEpOzCf3FRCUvQlBpciah7YuTUOS/4iRycSH7p2065ki O0/CDTQxA2DiYIkq/bfIasjGQYc+Wl4iZZ7N9VkwEsv+xQGLHcOMhFFSGHZ+4G2czCua zSYp04YfmBQT5yOR1t5B9w3yPlnbvKCRTk+l7Q1ziefbiNYzb7qrND1ecjP/YC9SJkD1 MOwg== X-Forwarded-Encrypted: i=1; AJvYcCUr5x+scTid3XlCCztGNzDA4ARU5rxU9MxinXGQg2ROnrxWDyP4hwVn0RgCYY9GlhTtNiFOJ3JFQ6M=@vger.kernel.org, AJvYcCWVUNmRxXc55uaHLlg0HKzKK+ZcB6midoJpsoLt82vBsqL0ZHiyyD+DxywlA3ur0JnhDZBncfCbFHduS0d1@vger.kernel.org X-Gm-Message-State: AOJu0YzFhTBvV7lwjTZ3JAjg/fVPbqbUyvn4mCp+ncaCPEyyuaRMOSGT m9KLrvodhqLsmQo7LEdqmalzv+s80MAO+z3IfDHIJi5jgld2iQm3pme2 X-Gm-Gg: ASbGncts3fbnr3r+VwtXp4Evh/U3uV8XWDKl1qXrUIbJgAuqKDfvWiBNNaeDcj7lYst G5ZLFLxrVAYlxc7wLD4LSAtAz/ZXMKvCU9hyv5VI3uETMRJIa8IutmeW5sapA7MnsQ+kN/80Fh4 q5aCTMbg3vXoskdyGf8grzB0AQwFhIgxY5dQ1Eb5wrZunpwASwLqOX/9O18ry1ExfwbP3vt2mZ8 uadrX6Fqly9sFCzh3s3Ho3xhqKngsb1x78eqQOo7hz8+9Wa9VxA2B/N5lX+AptpaUg5vnOsOAqk tas/2AKKqNmAEViy/vOXof6JaWIyHCQcIeU3SbcmRC01JnQ6b0Ip33sUh2wbR7eUyz4B4rnrbBA +xYi84fpmlvhMG+5gvkr6DLz5xN56RDNR6LABTWYDNN8= X-Google-Smtp-Source: AGHT+IGVqLp7cfzlbv6IeIgX5XQLg1EU8xkx6mx7eveL+YYGlnUwKoSKNw7QdXeGuFmn4wSjXldcMA== X-Received: by 2002:a5d:64c8:0:b0:3a4:e8bc:596 with SMTP id ffacd0b85a97d-3a558821f8bmr190540f8f.12.1749592789934; Tue, 10 Jun 2025 14:59:49 -0700 (PDT) Received: from localhost.localdomain (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a53244f04dsm13312647f8f.73.2025.06.10.14.59.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 14:59:49 -0700 (PDT) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, corbet@lwn.net Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v9 06/11] iio: accel: adxl345: replace magic numbers by unit expressions Date: Tue, 10 Jun 2025 21:59:28 +0000 Message-Id: <20250610215933.84795-7-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250610215933.84795-1-l.rubusch@gmail.com> References: <20250610215933.84795-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Replace absolute numbers by their expressions from units.h to avoid using magic numbers. Use uniform expressions to clarify their usage. This is a refactoring change and should not impact functionality. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_c= ore.c index dcfbfe4cac0f..2c4f045c741c 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -706,15 +706,15 @@ static int adxl345_read_event_value(struct iio_dev *i= ndio_dev, return IIO_VAL_FRACTIONAL; case IIO_EV_INFO_TIMEOUT: *val =3D st->tap_duration_us; - *val2 =3D 1000000; + *val2 =3D MICRO; return IIO_VAL_FRACTIONAL; case IIO_EV_INFO_RESET_TIMEOUT: *val =3D st->tap_window_us; - *val2 =3D 1000000; + *val2 =3D MICRO; return IIO_VAL_FRACTIONAL; case IIO_EV_INFO_TAP2_MIN_DELAY: *val =3D st->tap_latent_us; - *val2 =3D 1000000; + *val2 =3D MICRO; return IIO_VAL_FRACTIONAL; default: return -EINVAL; --=20 2.39.5 From nobody Sat Oct 11 08:26:19 2025 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.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 CA1C0284B4A; Tue, 10 Jun 2025 21:59:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749592794; cv=none; b=gXz2KLFQQ7AZpf8/rM1mclDWp7LXZtzWt09uR3DG+kb3YziXcEoKjPjK9a4MW0IyZ6e4hhO8xQ3TdtP8x2QVlgXmOJDa4p8Rz/cU1DoHaOxFDDIuU5RhmaiWyoD3VmWQdRT7X+OJLvDNhL5z/CHppVwrNGBjtGDegliFcuDu7VU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749592794; c=relaxed/simple; bh=Jsj037GkRZrMWcRwPNezEY24we0hZ51pw2yLxPNmPfU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Yo150vTt+E+8T/d/9i8E1bJCW+7LXjq0xdhZExg4Kn8IOUYrhpZ6k9WWx+H2v8QPNtNkAIGbmqCfrgvwaEZmsLcOioAw0rV43DYxp16daOUc7EQWtbPnrxFqD0ivJjzTS1u1sRuD/aC2XglFfJj7+0Xbhq6MxZkLWNQJo4JjkFA= 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=m/P0F71m; arc=none smtp.client-ip=209.85.221.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="m/P0F71m" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-3a4e749d7b2so794985f8f.0; Tue, 10 Jun 2025 14:59:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749592791; x=1750197591; 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=d2Kh1AXLqZ10k32T7HjAyP7XDK1Denw+eFx0BnkCDuc=; b=m/P0F71mHe4FAa03OqrIN7RP5VAnr7Af/Twb/mlNoFI2/8X+NuV09rHBNNHP99pg7M /4qm/ooHy3ZQkGOziyF7slp6a1bsk8Yr9v1eYIX5xgw0tA4NKHUMXKw1VnvEPKj8Kv2f n+4dErIWlzYf6kYwNhrhHt+nNxf77NcG3ancUtd3PoGts+idmRql7q0u0ShH1WD1fz1B JoFVyDZxNx0MlfmCiWUGqMHitQIQ6gil/D6pKnEhOKfhaNmYzrFzzQ0QYttdNoiAOk5n 7tAyiKOQjJ8jgildngjj/6sDG1G+E5AYj3xvIPFuMUBVyd5BStABE8uPHfn1lsFjeMhf iomA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749592791; x=1750197591; 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=d2Kh1AXLqZ10k32T7HjAyP7XDK1Denw+eFx0BnkCDuc=; b=KFIm2kOvhvNg8mXCSpYV2GLIAcW7eUIPC8EXUq3UFxhkOA5fcJPft4U6R21dmYgLtD 4pmXaNqgcLTr5qo278pj1SV1mqerjnO2TWzg4xuWDUafS93oYsB4ZKOcRGGaeLPdQI5I GD4mwVrlSJPeABjlRfPz3yWe2UrGWIDm/FVRk4fz8GugYH8oZF52/SUONG0yEeL5NL7A n4uJOWI45T4JwLegXNF5n6SCr841iC/II6i+84NgVopKHSOVsK8HLt70jl3m7Rh3f7h+ EYussEL7wpm8Dt1va9t+ajUgO+nucD9ZLl71JIBMA3Ug1dny1saA1RJ0aRk5Fuu5ruBK 6GVg== X-Forwarded-Encrypted: i=1; AJvYcCWh2pO4mqhRE5LxT+/Cq/QFDF2UslhrTgNPX+O+MpkBF8xBpIq9a51uaNj7Cw9I7xmqvjwuwNqiS7c=@vger.kernel.org, AJvYcCXZyjLto9pkAS38T0d1iKZDdatA0LBiLnhVUm4qtt8ndp17Q6J6MNHK5db8pIeMSiUG8hn9OSt4SYpuJsG3@vger.kernel.org X-Gm-Message-State: AOJu0YzerKrTmtL2MD47u7mnAQw9EDibFvEorpM38kQ4wfUAxvNtd3C7 GNEHKWSdx/FEKrAX4Xbvsfms5QzPLpZAwRovweT2Xq9+BVi/lmm1Tgr1 X-Gm-Gg: ASbGncv/2UdlbT3Dpg+2I/4IgxOI2KIY7S7TAg+oNRFAfVICw6OauFfyjEnc5//q7p8 mtK0eFOCgwV4+MiPbOpd3PHKko6Hi1iVqAOmlHReLSIfXl7IbgfdXztlNHOBHjzUgg0YmalaRnI tqa3ErB/6wO6KWD/oXx0cDyJdtwRjhTANIqZ22UL3hNHaGofGlaFDQldlis2MJyYkT7941SLWZl M5BUYdZDOzPW0h8zbG4m1B8z30ryDW+b3rQWywR5lHLqKG2yqZN8u1b2iJs7iayudeRTKy0tqi4 esqGDVWD+nKTuQsjTGRgs2AWJE+S9LxL5XILhw7z5sauNYhG8F6+d5UqWi62P2bDADzDuyi70co 8jiJSMGiuangKKORJR2BGqW1nPuBCKMrpeI2bxi+F464= X-Google-Smtp-Source: AGHT+IGYIkaFaA6u3u+KgA8g3E9SI1brP3MVK3iWDe6KbEVWyof8EI+CID/TdwzzidctfvItxKlQkw== X-Received: by 2002:a05:6000:4284:b0:3a3:71fb:7903 with SMTP id ffacd0b85a97d-3a55880794emr173161f8f.10.1749592790954; Tue, 10 Jun 2025 14:59:50 -0700 (PDT) Received: from localhost.localdomain (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a53244f04dsm13312647f8f.73.2025.06.10.14.59.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 14:59:50 -0700 (PDT) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, corbet@lwn.net Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v9 07/11] iio: accel: adxl345: add activity event feature Date: Tue, 10 Jun 2025 21:59:29 +0000 Message-Id: <20250610215933.84795-8-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250610215933.84795-1-l.rubusch@gmail.com> References: <20250610215933.84795-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Make the sensor detect and issue interrupts at activity. Activity events are configured by a threshold. Initialize the activity threshold register to a reasonable default value in probe. The value is taken from the older ADXL345 input driver, to provide a similar behavior. Activity, ODR configuration together with the range setting prepare the activity/inactivity hysteresis setup, implemented in a follow up patch. Thus parts of this patch prepare switch/case setups for the follow up patches. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 205 ++++++++++++++++++++++++++++++- 1 file changed, 202 insertions(+), 3 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_c= ore.c index 2c4f045c741c..04b9f155872f 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -36,11 +36,16 @@ #define ADXL345_REG_TAP_AXIS_MSK GENMASK(2, 0) #define ADXL345_REG_TAP_SUPPRESS_MSK BIT(3) #define ADXL345_REG_TAP_SUPPRESS BIT(3) +#define ADXL345_REG_ACT_AXIS_MSK GENMASK(6, 4) =20 #define ADXL345_TAP_Z_EN BIT(0) #define ADXL345_TAP_Y_EN BIT(1) #define ADXL345_TAP_X_EN BIT(2) =20 +#define ADXL345_ACT_Z_EN BIT(4) +#define ADXL345_ACT_Y_EN BIT(5) +#define ADXL345_ACT_X_EN BIT(6) + /* single/double tap */ enum adxl345_tap_type { ADXL345_SINGLE_TAP, @@ -64,6 +69,19 @@ static const unsigned int adxl345_tap_time_reg[] =3D { [ADXL345_TAP_TIME_DUR] =3D ADXL345_REG_DUR, }; =20 +/* activity/inactivity */ +enum adxl345_activity_type { + ADXL345_ACTIVITY, +}; + +static const unsigned int adxl345_act_int_reg[] =3D { + [ADXL345_ACTIVITY] =3D ADXL345_INT_ACTIVITY, +}; + +static const unsigned int adxl345_act_thresh_reg[] =3D { + [ADXL345_ACTIVITY] =3D ADXL345_REG_THRESH_ACT, +}; + enum adxl345_odr { ADXL345_ODR_0P10HZ =3D 0, ADXL345_ODR_0P20HZ, @@ -144,6 +162,13 @@ struct adxl345_state { }; =20 static struct iio_event_spec adxl345_events[] =3D { + { + /* activity */ + .type =3D IIO_EV_TYPE_MAG, + .dir =3D IIO_EV_DIR_RISING, + .mask_shared_by_type =3D BIT(IIO_EV_INFO_ENABLE) | + BIT(IIO_EV_INFO_VALUE), + }, { /* single tap */ .type =3D IIO_EV_TYPE_GESTURE, @@ -237,6 +262,90 @@ static int adxl345_set_measure_en(struct adxl345_state= *st, bool en) ADXL345_POWER_CTL_MEASURE, en); } =20 +/* act/inact */ + +static int adxl345_is_act_inact_en(struct adxl345_state *st, + enum adxl345_activity_type type) +{ + unsigned int regval; + u32 axis_ctrl; + bool en; + int ret; + + ret =3D regmap_read(st->regmap, ADXL345_REG_ACT_INACT_CTRL, &axis_ctrl); + if (ret) + return ret; + + switch (type) { + case ADXL345_ACTIVITY: + en =3D FIELD_GET(ADXL345_ACT_X_EN, axis_ctrl) | + FIELD_GET(ADXL345_ACT_Y_EN, axis_ctrl) | + FIELD_GET(ADXL345_ACT_Z_EN, axis_ctrl); + break; + default: + return -EINVAL; + } + + if (!en) + return en; + + /* Check if corresponding interrupts are enabled */ + ret =3D regmap_read(st->regmap, ADXL345_REG_INT_ENABLE, ®val); + if (ret) + return ret; + + return adxl345_act_int_reg[type] & regval; +} + +static int adxl345_set_act_inact_en(struct adxl345_state *st, + enum adxl345_activity_type type, + bool cmd_en) +{ + bool en; + unsigned int threshold; + u32 axis_ctrl; + int ret; + + if (type =3D=3D ADXL345_ACTIVITY) { + axis_ctrl =3D ADXL345_ACT_X_EN | ADXL345_ACT_Y_EN | + ADXL345_ACT_Z_EN; + } else { + axis_ctrl =3D 0x00; + } + + /* Start configuring the sensor registers */ + ret =3D adxl345_set_measure_en(st, false); + if (ret) + return ret; + + ret =3D regmap_assign_bits(st->regmap, ADXL345_REG_ACT_INACT_CTRL, + axis_ctrl, cmd_en); + if (ret) + return ret; + + ret =3D regmap_read(st->regmap, adxl345_act_thresh_reg[type], &threshold); + if (ret) + return ret; + + en =3D false; + + switch (type) { + case ADXL345_ACTIVITY: + en =3D FIELD_GET(ADXL345_REG_ACT_AXIS_MSK, axis_ctrl) && + threshold; + break; + default: + return -EINVAL; + } + + ret =3D regmap_assign_bits(st->regmap, ADXL345_REG_INT_ENABLE, + adxl345_act_int_reg[type], cmd_en && en); + if (ret) + return ret; + + return adxl345_set_measure_en(st, true); +} + /* tap */ =20 static int _adxl345_set_tap_int(struct adxl345_state *st, @@ -634,6 +743,13 @@ static int adxl345_read_event_config(struct iio_dev *i= ndio_dev, int ret; =20 switch (type) { + case IIO_EV_TYPE_MAG: + switch (dir) { + case IIO_EV_DIR_RISING: + return adxl345_is_act_inact_en(st, ADXL345_ACTIVITY); + default: + return -EINVAL; + } case IIO_EV_TYPE_GESTURE: switch (dir) { case IIO_EV_DIR_SINGLETAP: @@ -665,6 +781,15 @@ static int adxl345_write_event_config(struct iio_dev *= indio_dev, struct adxl345_state *st =3D iio_priv(indio_dev); =20 switch (type) { + case IIO_EV_TYPE_MAG: + switch (dir) { + case IIO_EV_DIR_RISING: + return adxl345_set_act_inact_en(st, + ADXL345_ACTIVITY, + state); + default: + return -EINVAL; + } case IIO_EV_TYPE_GESTURE: switch (dir) { case IIO_EV_DIR_SINGLETAP: @@ -687,10 +812,30 @@ static int adxl345_read_event_value(struct iio_dev *i= ndio_dev, int *val, int *val2) { struct adxl345_state *st =3D iio_priv(indio_dev); + unsigned int act_threshold; unsigned int tap_threshold; int ret; =20 switch (type) { + case IIO_EV_TYPE_MAG: + switch (info) { + case IIO_EV_INFO_VALUE: + switch (dir) { + case IIO_EV_DIR_RISING: + ret =3D regmap_read(st->regmap, + adxl345_act_thresh_reg[ADXL345_ACTIVITY], + &act_threshold); + if (ret) + return ret; + *val =3D 62500 * act_threshold; + *val2 =3D MICRO; + return IIO_VAL_FRACTIONAL; + default: + return -EINVAL; + } + default: + return -EINVAL; + } case IIO_EV_TYPE_GESTURE: switch (info) { case IIO_EV_INFO_VALUE: @@ -739,6 +884,26 @@ static int adxl345_write_event_value(struct iio_dev *i= ndio_dev, return ret; =20 switch (type) { + case IIO_EV_TYPE_MAG: + switch (info) { + case IIO_EV_INFO_VALUE: + switch (dir) { + case IIO_EV_DIR_RISING: + val =3D DIV_ROUND_CLOSEST(val * MICRO + val2, 62500); + ret =3D regmap_write(st->regmap, + adxl345_act_thresh_reg[ADXL345_ACTIVITY], + val); + if (ret) + return ret; + break; + default: + return -EINVAL; + } + break; + default: + return -EINVAL; + } + break; case IIO_EV_TYPE_GESTURE: switch (info) { case IIO_EV_INFO_VALUE: @@ -980,7 +1145,8 @@ static int adxl345_fifo_push(struct iio_dev *indio_dev, } =20 static int adxl345_push_event(struct iio_dev *indio_dev, int int_stat, - enum iio_modifier tap_dir) + enum iio_modifier tap_dir, + enum iio_modifier act_dir) { s64 ts =3D iio_get_time_ns(indio_dev); struct adxl345_state *st =3D iio_priv(indio_dev); @@ -1007,6 +1173,16 @@ static int adxl345_push_event(struct iio_dev *indio_= dev, int int_stat, return ret; } =20 + if (FIELD_GET(ADXL345_INT_ACTIVITY, int_stat)) { + ret =3D iio_push_event(indio_dev, + IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, act_dir, + IIO_EV_TYPE_MAG, + IIO_EV_DIR_RISING), + ts); + if (ret) + return ret; + } + if (FIELD_GET(ADXL345_INT_WATERMARK, int_stat)) { samples =3D adxl345_get_samples(st); if (samples < 0) @@ -1034,6 +1210,7 @@ static irqreturn_t adxl345_irq_handler(int irq, void = *p) struct adxl345_state *st =3D iio_priv(indio_dev); unsigned int regval; enum iio_modifier tap_dir =3D IIO_NO_MOD; + enum iio_modifier act_dir =3D IIO_NO_MOD; u32 axis_ctrl; int int_stat; int ret; @@ -1042,7 +1219,8 @@ static irqreturn_t adxl345_irq_handler(int irq, void = *p) if (ret) return IRQ_NONE; =20 - if (FIELD_GET(ADXL345_REG_TAP_AXIS_MSK, axis_ctrl)) { + if (FIELD_GET(ADXL345_REG_TAP_AXIS_MSK, axis_ctrl) || + FIELD_GET(ADXL345_REG_ACT_AXIS_MSK, axis_ctrl)) { ret =3D regmap_read(st->regmap, ADXL345_REG_ACT_TAP_STATUS, ®val); if (ret) return IRQ_NONE; @@ -1053,12 +1231,19 @@ static irqreturn_t adxl345_irq_handler(int irq, voi= d *p) tap_dir =3D IIO_MOD_Y; else if (FIELD_GET(ADXL345_TAP_X_EN, regval)) tap_dir =3D IIO_MOD_X; + + if (FIELD_GET(ADXL345_ACT_Z_EN, regval)) + act_dir =3D IIO_MOD_Z; + else if (FIELD_GET(ADXL345_ACT_Y_EN, regval)) + act_dir =3D IIO_MOD_Y; + else if (FIELD_GET(ADXL345_ACT_X_EN, regval)) + act_dir =3D IIO_MOD_X; } =20 if (regmap_read(st->regmap, ADXL345_REG_INT_SOURCE, &int_stat)) return IRQ_NONE; =20 - if (adxl345_push_event(indio_dev, int_stat, tap_dir)) + if (adxl345_push_event(indio_dev, int_stat, tap_dir, act_dir)) goto err; =20 if (FIELD_GET(ADXL345_INT_OVERRUN, int_stat)) @@ -1219,6 +1404,20 @@ int adxl345_core_probe(struct device *dev, struct re= gmap *regmap, if (ret) return ret; =20 + /* + * Initialization with reasonable values to simplify operation + * of the sensor. The default values are partly taken from the + * older input driver for the ADXL345, and partly based on + * recommendations in the datasheet. + */ + ret =3D regmap_write(st->regmap, ADXL345_REG_ACT_INACT_CTRL, 0); + if (ret) + return ret; + + ret =3D regmap_write(st->regmap, ADXL345_REG_THRESH_ACT, 6); + if (ret) + return ret; + ret =3D regmap_write(st->regmap, ADXL345_REG_THRESH_TAP, tap_threshold); if (ret) return ret; --=20 2.39.5 From nobody Sat Oct 11 08:26:19 2025 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70317284B5F; Tue, 10 Jun 2025 21:59:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749592796; cv=none; b=nN7Uj8VJaqk/ssa5pSFnCuYJI2ptXfDnTfdbBDYLk00yyERsSIHyUD+xSCHA3uGuVPmCTBJ8DYD748KOpIxzr0YX7+tLmwRrc6goIedhhFMsSKevX44WYLZRPxJtQLRqq04wQoliDl2a0bzUVUDOfWxxNTqUWOCSxtKtTU4ia0U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749592796; c=relaxed/simple; bh=jdy5l0MnZlu8kyfiZl4nOPTBPnHnbBvRA7qN16pHvd4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=K6YyhgJPsbmoRTwUia5M4+pNvPHWn1gtmD8zqjzPf9xmKCh01bMh5q6UxReO08V0ZATqOMU02FG9YeuiB30eU3JDgrl52nQNmKLaGTYbxLGO81IweQDEp33MsGxuKy3TJ7tLrYhnYECRO342U6C1U4GVER4AqxkyKCFYpSRLvhQ= 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=GXz7L+yP; arc=none smtp.client-ip=209.85.221.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GXz7L+yP" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-3a52878d37aso1012026f8f.2; Tue, 10 Jun 2025 14:59:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749592793; x=1750197593; 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=3YMcbhaYsBJDy79eUfY5SGgotLclNWTNMFqNoTRNhww=; b=GXz7L+yPag9/McIqHiRpiEDGZf3ZtlLlYBM7PCtw8R+LJqUdaqGG6s+XWnDxeNNPN8 k9DCpe35xQ41e4npb5EryRdyqOo1pc0pa0lzymGNS9kZDv/88+O3CYlGJG2Bl/N2R2Bw extANQO8edInwvuv+lH+/Rr2qyvjRwe3PCZG001xLX3efPL/5vWMTV7FrD+LwUu1mqiO h7KH9X5rk3AZHKZnive0/dVND577u5NDGFvkp9OMyufgmonuGQOGbMCpgjlkWsS+8EVA VBmHLA54Tdh7nP1YZwLiRboV5NVzuXByke41uEdSUnILSKEVJP1tUi9yLCR3MxwDmlIy 5G9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749592793; x=1750197593; 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=3YMcbhaYsBJDy79eUfY5SGgotLclNWTNMFqNoTRNhww=; b=lmHxlGJzKZnhRGq+EB7zrMFNbEgvu1Ey3KU2QWy1aX7ar7Q3SYvEBmDSeIhuH/k9Bl eclRc49q94Ts0zHbJ8GvuzAgR4QdO9LINnn7FHvMxu7DAsrHztRf+GRkQ4ehzfTwhqLh zrDUFCefwhN3CMNhJuHkiYtbuCbzUEDX+aa73Mqo8fCPsfwpYcxZTgN/TfA0uM+vsygJ 4r1YzNkeW2GjJv7brTJ8u0TgAPfvY26J8IJHM4BGUgGAFYoNgNlEm5JEWMxeVuxctSXP cB+sUogwBtV+g3TIa9PZ97SfI+uwvW3WtwWoEahdj9CO3NTpCK5yixUKdM6xYEeeONEK KzAQ== X-Forwarded-Encrypted: i=1; AJvYcCUtObbsUycTS2/eKvE1CMgK/4usucIoZIWKEp0uBm9gvs4zCzUld5xHXw2WrdnhCfE/GC+lvzg1NWo=@vger.kernel.org, AJvYcCVgiAqiFuZTaGuX2sFoWJg1sRlLzFulkX1ig4SBqcjwJQuYhaylsreIQiTG3akda88bhTYKbDwtaJbXlHO5@vger.kernel.org X-Gm-Message-State: AOJu0YxAwsPrbUFTrJoMdAoPtZDvCZ2BXEciQnoI+nDz6SuBW2SRkY9R nNWL95ZEqBVzA++E5Ig6/Q1kPNDhB1sbnanUzZPLZcIGQ87QeDnicv1L X-Gm-Gg: ASbGnct3PPNHBtCIfn/SCb/m2cJCEVmWpXWl7oTOIKOy1MZfxZzbkCYiOuDBOSjzQg3 +715ndBFMi0xnX3b49TCpt9lqf7bp8hXcdglYFC+xYyYvZqOKJkxb5zN/9skN7LhkKslfyynquP qkd7ax1n0qwZg151nIUBYgDSSpIWOgF+cN2+3WgPhX33l/imHsss9PKWP1g9hdV2jxZ85MUR24y ORZ7BVzDLcZBgixT8gzgOG0vK4CJr4UaRPekHMHQWot5q/yRUTGwXlOh0D9o5nXtueObKxdL5aZ /Zmd+j5KFsPE1BuG/DI9U2AQ+ikoDk70SnR851sq1lYAw3cSYVAIOKN3zZACb5nn7J4OlTPZ7yY m//6ap8rt/22JF5VSdhHH4G4+Y7gk89BpKBaTj/tFS5k= X-Google-Smtp-Source: AGHT+IFeMIC3wVB7KtB2p1XAhjze6E2Y2BTMZadsUcQbE+QtA0iRXAlCFyM5MGO7wcBNHhlHiRySdw== X-Received: by 2002:a05:6000:3112:b0:3a4:eeeb:7e70 with SMTP id ffacd0b85a97d-3a5586c5cafmr186441f8f.4.1749592792617; Tue, 10 Jun 2025 14:59:52 -0700 (PDT) Received: from localhost.localdomain (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a53244f04dsm13312647f8f.73.2025.06.10.14.59.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 14:59:52 -0700 (PDT) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, corbet@lwn.net Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v9 08/11] iio: accel: adxl345: add inactivity feature Date: Tue, 10 Jun 2025 21:59:30 +0000 Message-Id: <20250610215933.84795-9-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250610215933.84795-1-l.rubusch@gmail.com> References: <20250610215933.84795-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add the inactivity feature of the sensor to the driver. When activity and inactivity are enabled, a link bit will be set linking activity and inactivity handling. Additionally, the auto-sleep mode will be enabled. Due to the link bit the sensor is going to auto-sleep when inactivity was detected. Inactivity detection needs a threshold to be configured and a period of time in seconds. After, it will transition to inactivity state, if measurements stay below inactivity threshold. When a ODR is configured the period for inactivity is adjusted with a corresponding reasonable default value, in order to have higher frequencies, lower inactivity times, and lower sample frequency but give more time until inactivity. Both with reasonable upper and lower boundaries, since many of the sensor's features (e.g. auto-sleep) will need to operate between 12.5 Hz and 400 Hz. This is a default setting when actively changing sample frequency, explicitly setting the time until inactivity will overwrite the default. Similarly, setting the g-range will provide a default value for the activity and inactivity thresholds. Both are implicit defaults, but equally can be overwritten to be explicitly configured. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 238 +++++++++++++++++++++++++++++-- 1 file changed, 227 insertions(+), 11 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_c= ore.c index 04b9f155872f..1670315ebd63 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -37,11 +37,17 @@ #define ADXL345_REG_TAP_SUPPRESS_MSK BIT(3) #define ADXL345_REG_TAP_SUPPRESS BIT(3) #define ADXL345_REG_ACT_AXIS_MSK GENMASK(6, 4) +#define ADXL345_REG_INACT_AXIS_MSK GENMASK(2, 0) +#define ADXL345_POWER_CTL_INACT_MSK (ADXL345_POWER_CTL_AUTO_SLEEP | ADXL34= 5_POWER_CTL_LINK) =20 #define ADXL345_TAP_Z_EN BIT(0) #define ADXL345_TAP_Y_EN BIT(1) #define ADXL345_TAP_X_EN BIT(2) =20 +#define ADXL345_INACT_Z_EN BIT(0) +#define ADXL345_INACT_Y_EN BIT(1) +#define ADXL345_INACT_X_EN BIT(2) + #define ADXL345_ACT_Z_EN BIT(4) #define ADXL345_ACT_Y_EN BIT(5) #define ADXL345_ACT_X_EN BIT(6) @@ -72,14 +78,17 @@ static const unsigned int adxl345_tap_time_reg[] =3D { /* activity/inactivity */ enum adxl345_activity_type { ADXL345_ACTIVITY, + ADXL345_INACTIVITY, }; =20 static const unsigned int adxl345_act_int_reg[] =3D { [ADXL345_ACTIVITY] =3D ADXL345_INT_ACTIVITY, + [ADXL345_INACTIVITY] =3D ADXL345_INT_INACTIVITY, }; =20 static const unsigned int adxl345_act_thresh_reg[] =3D { [ADXL345_ACTIVITY] =3D ADXL345_REG_THRESH_ACT, + [ADXL345_INACTIVITY] =3D ADXL345_REG_THRESH_INACT, }; =20 enum adxl345_odr { @@ -147,6 +156,14 @@ static const int adxl345_fullres_range_tbl[][2] =3D { [ADXL345_16G_RANGE] =3D { 0, 38312 }, }; =20 +/* scaling */ +static const int adxl345_range_factor_tbl[] =3D { + [ADXL345_2G_RANGE] =3D 1, + [ADXL345_4G_RANGE] =3D 2, + [ADXL345_8G_RANGE] =3D 4, + [ADXL345_16G_RANGE] =3D 8, +}; + struct adxl345_state { const struct adxl345_chip_info *info; struct regmap *regmap; @@ -213,10 +230,29 @@ enum adxl345_chans { chan_x, chan_y, chan_z, }; =20 +static const struct iio_event_spec adxl345_fake_chan_events[] =3D { + { + /* inactivity */ + .type =3D IIO_EV_TYPE_MAG, + .dir =3D IIO_EV_DIR_FALLING, + .mask_separate =3D BIT(IIO_EV_INFO_ENABLE), + .mask_shared_by_type =3D BIT(IIO_EV_INFO_VALUE) | + BIT(IIO_EV_INFO_PERIOD), + }, +}; + static const struct iio_chan_spec adxl345_channels[] =3D { ADXL345_CHANNEL(0, chan_x, X), ADXL345_CHANNEL(1, chan_y, Y), ADXL345_CHANNEL(2, chan_z, Z), + { + .type =3D IIO_ACCEL, + .modified =3D 1, + .channel2 =3D IIO_MOD_X_AND_Y_AND_Z, + .scan_index =3D -1, /* Fake channel */ + .event_spec =3D adxl345_fake_chan_events, + .num_event_specs =3D ARRAY_SIZE(adxl345_fake_chan_events), + }, }; =20 static const unsigned long adxl345_scan_masks[] =3D { @@ -264,6 +300,51 @@ static int adxl345_set_measure_en(struct adxl345_state= *st, bool en) =20 /* act/inact */ =20 +/** + * adxl345_set_inact_time - Configure inactivity time explicitly or by ODR. + * @st: The sensor state instance. + * @val_s: A desired time value, between 0 and 255. + * + * Inactivity time can be configured between 1 and 255 sec. If a val_s of 0 + * is configured by a user, then a default inactivity time will be compute= d. + * + * In such case, it should take power consumption into consideration. Thus= it + * shall be shorter for higher frequencies and longer for lower frequencie= s. + * Hence, frequencies above 255 Hz shall default to 10 s and frequencies b= elow + * 10 Hz shall result in 255 s to detect inactivity. + * + * The approach simply subtracts the pre-decimal figure of the configured + * sample frequency from 255 s to compute inactivity time [s]. Sub-Hz are = thus + * ignored in this estimation. The recommended ODRs for various features + * (activity/inactivity, sleep modes, free fall, etc.) lie between 12.5 Hz= and + * 400 Hz, thus higher or lower frequencies will result in the boundary + * defaults or need to be explicitly specified via val_s. + * + * Return: 0 or error value. + */ +static int adxl345_set_inact_time(struct adxl345_state *st, u32 val_s) +{ + unsigned int max_boundary =3D 255; + unsigned int min_boundary =3D 10; + unsigned int val =3D min(val_s, max_boundary); + enum adxl345_odr odr; + unsigned int regval; + int ret; + + if (val =3D=3D 0) { + ret =3D regmap_read(st->regmap, ADXL345_REG_BW_RATE, ®val); + if (ret) + return ret; + + odr =3D FIELD_GET(ADXL345_BW_RATE_MSK, regval); + + val =3D (adxl345_odr_tbl[odr][0] > max_boundary) + ? min_boundary : max_boundary - adxl345_odr_tbl[odr][0]; + } + + return regmap_write(st->regmap, ADXL345_REG_TIME_INACT, val); +} + static int adxl345_is_act_inact_en(struct adxl345_state *st, enum adxl345_activity_type type) { @@ -282,6 +363,11 @@ static int adxl345_is_act_inact_en(struct adxl345_stat= e *st, FIELD_GET(ADXL345_ACT_Y_EN, axis_ctrl) | FIELD_GET(ADXL345_ACT_Z_EN, axis_ctrl); break; + case ADXL345_INACTIVITY: + en =3D FIELD_GET(ADXL345_INACT_X_EN, axis_ctrl) | + FIELD_GET(ADXL345_INACT_Y_EN, axis_ctrl) | + FIELD_GET(ADXL345_INACT_Z_EN, axis_ctrl); + break; default: return -EINVAL; } @@ -302,22 +388,25 @@ static int adxl345_set_act_inact_en(struct adxl345_st= ate *st, bool cmd_en) { bool en; + unsigned int inact_time_s; unsigned int threshold; u32 axis_ctrl; + int act_en, inact_en; int ret; =20 + /* Start configuring the sensor registers */ + ret =3D adxl345_set_measure_en(st, false); + if (ret) + return ret; + if (type =3D=3D ADXL345_ACTIVITY) { axis_ctrl =3D ADXL345_ACT_X_EN | ADXL345_ACT_Y_EN | ADXL345_ACT_Z_EN; } else { - axis_ctrl =3D 0x00; + axis_ctrl =3D ADXL345_INACT_X_EN | ADXL345_INACT_Y_EN | + ADXL345_INACT_Z_EN; } =20 - /* Start configuring the sensor registers */ - ret =3D adxl345_set_measure_en(st, false); - if (ret) - return ret; - ret =3D regmap_assign_bits(st->regmap, ADXL345_REG_ACT_INACT_CTRL, axis_ctrl, cmd_en); if (ret) @@ -334,12 +423,37 @@ static int adxl345_set_act_inact_en(struct adxl345_st= ate *st, en =3D FIELD_GET(ADXL345_REG_ACT_AXIS_MSK, axis_ctrl) && threshold; break; + case ADXL345_INACTIVITY: + ret =3D regmap_read(st->regmap, ADXL345_REG_TIME_INACT, &inact_time_s); + if (ret) + return ret; + + en =3D FIELD_GET(ADXL345_REG_INACT_AXIS_MSK, axis_ctrl) && + threshold && inact_time_s; + break; default: return -EINVAL; } =20 ret =3D regmap_assign_bits(st->regmap, ADXL345_REG_INT_ENABLE, - adxl345_act_int_reg[type], cmd_en && en); + adxl345_act_int_reg[type], cmd_en); + if (ret) + return ret; + + /* Set sleep and link bit when ACT and INACT are enabled. */ + act_en =3D adxl345_is_act_inact_en(st, ADXL345_ACTIVITY); + if (act_en < 0) + return act_en; + + inact_en =3D adxl345_is_act_inact_en(st, ADXL345_INACTIVITY); + if (inact_en < 0) + return inact_en; + + en =3D en && act_en && inact_en; + + ret =3D regmap_assign_bits(st->regmap, ADXL345_REG_POWER_CTL, + (ADXL345_POWER_CTL_AUTO_SLEEP | ADXL345_POWER_CTL_LINK), + en); if (ret) return ret; =20 @@ -575,9 +689,16 @@ static int adxl345_find_odr(struct adxl345_state *st, = int val, =20 static int adxl345_set_odr(struct adxl345_state *st, enum adxl345_odr odr) { - return regmap_update_bits(st->regmap, ADXL345_REG_BW_RATE, + int ret; + + ret =3D regmap_update_bits(st->regmap, ADXL345_REG_BW_RATE, ADXL345_BW_RATE_MSK, FIELD_PREP(ADXL345_BW_RATE_MSK, odr)); + if (ret) + return ret; + + /* update inactivity time by ODR */ + return adxl345_set_inact_time(st, 0); } =20 static int adxl345_find_range(struct adxl345_state *st, int val, int val2, @@ -598,9 +719,49 @@ static int adxl345_find_range(struct adxl345_state *st= , int val, int val2, =20 static int adxl345_set_range(struct adxl345_state *st, enum adxl345_range = range) { - return regmap_update_bits(st->regmap, ADXL345_REG_DATA_FORMAT, + unsigned int act_threshold, inact_threshold; + unsigned int range_old; + unsigned int regval; + int ret; + + ret =3D regmap_read(st->regmap, ADXL345_REG_DATA_FORMAT, ®val); + if (ret) + return ret; + range_old =3D FIELD_GET(ADXL345_DATA_FORMAT_RANGE, regval); + + ret =3D regmap_read(st->regmap, + adxl345_act_thresh_reg[ADXL345_ACTIVITY], + &act_threshold); + if (ret) + return ret; + + ret =3D regmap_read(st->regmap, + adxl345_act_thresh_reg[ADXL345_INACTIVITY], + &inact_threshold); + if (ret) + return ret; + + ret =3D regmap_update_bits(st->regmap, ADXL345_REG_DATA_FORMAT, ADXL345_DATA_FORMAT_RANGE, FIELD_PREP(ADXL345_DATA_FORMAT_RANGE, range)); + if (ret) + return ret; + + act_threshold =3D act_threshold * adxl345_range_factor_tbl[range_old] + / adxl345_range_factor_tbl[range]; + act_threshold =3D min(U8_MAX, max(1, act_threshold)); + + inact_threshold =3D inact_threshold * adxl345_range_factor_tbl[range_old] + / adxl345_range_factor_tbl[range]; + inact_threshold =3D min(U8_MAX, max(1, inact_threshold)); + + ret =3D regmap_write(st->regmap, adxl345_act_thresh_reg[ADXL345_ACTIVITY], + act_threshold); + if (ret) + return ret; + + return regmap_write(st->regmap, adxl345_act_thresh_reg[ADXL345_INACTIVITY= ], + inact_threshold); } =20 static int adxl345_read_avail(struct iio_dev *indio_dev, @@ -747,6 +908,8 @@ static int adxl345_read_event_config(struct iio_dev *in= dio_dev, switch (dir) { case IIO_EV_DIR_RISING: return adxl345_is_act_inact_en(st, ADXL345_ACTIVITY); + case IIO_EV_DIR_FALLING: + return adxl345_is_act_inact_en(st, ADXL345_INACTIVITY); default: return -EINVAL; } @@ -787,6 +950,10 @@ static int adxl345_write_event_config(struct iio_dev *= indio_dev, return adxl345_set_act_inact_en(st, ADXL345_ACTIVITY, state); + case IIO_EV_DIR_FALLING: + return adxl345_set_act_inact_en(st, + ADXL345_INACTIVITY, + state); default: return -EINVAL; } @@ -812,7 +979,8 @@ static int adxl345_read_event_value(struct iio_dev *ind= io_dev, int *val, int *val2) { struct adxl345_state *st =3D iio_priv(indio_dev); - unsigned int act_threshold; + unsigned int act_threshold, inact_threshold; + unsigned int inact_time_s; unsigned int tap_threshold; int ret; =20 @@ -830,9 +998,26 @@ static int adxl345_read_event_value(struct iio_dev *in= dio_dev, *val =3D 62500 * act_threshold; *val2 =3D MICRO; return IIO_VAL_FRACTIONAL; + case IIO_EV_DIR_FALLING: + ret =3D regmap_read(st->regmap, + adxl345_act_thresh_reg[ADXL345_INACTIVITY], + &inact_threshold); + if (ret) + return ret; + *val =3D 62500 * inact_threshold; + *val2 =3D MICRO; + return IIO_VAL_FRACTIONAL; default: return -EINVAL; } + case IIO_EV_INFO_PERIOD: + ret =3D regmap_read(st->regmap, + ADXL345_REG_TIME_INACT, + &inact_time_s); + if (ret) + return ret; + *val =3D inact_time_s; + return IIO_VAL_INT; default: return -EINVAL; } @@ -887,19 +1072,31 @@ static int adxl345_write_event_value(struct iio_dev = *indio_dev, case IIO_EV_TYPE_MAG: switch (info) { case IIO_EV_INFO_VALUE: + val =3D DIV_ROUND_CLOSEST(val * MICRO + val2, 62500); switch (dir) { case IIO_EV_DIR_RISING: - val =3D DIV_ROUND_CLOSEST(val * MICRO + val2, 62500); ret =3D regmap_write(st->regmap, adxl345_act_thresh_reg[ADXL345_ACTIVITY], val); if (ret) return ret; break; + case IIO_EV_DIR_FALLING: + ret =3D regmap_write(st->regmap, + adxl345_act_thresh_reg[ADXL345_INACTIVITY], + val); + if (ret) + return ret; + break; default: return -EINVAL; } break; + case IIO_EV_INFO_PERIOD: + ret =3D adxl345_set_inact_time(st, val); + if (ret) + return ret; + break; default: return -EINVAL; } @@ -1183,6 +1380,17 @@ static int adxl345_push_event(struct iio_dev *indio_= dev, int int_stat, return ret; } =20 + if (FIELD_GET(ADXL345_INT_INACTIVITY, int_stat)) { + ret =3D iio_push_event(indio_dev, + IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, + IIO_MOD_X_AND_Y_AND_Z, + IIO_EV_TYPE_MAG, + IIO_EV_DIR_FALLING), + ts); + if (ret) + return ret; + } + if (FIELD_GET(ADXL345_INT_WATERMARK, int_stat)) { samples =3D adxl345_get_samples(st); if (samples < 0) @@ -1414,10 +1622,18 @@ int adxl345_core_probe(struct device *dev, struct r= egmap *regmap, if (ret) return ret; =20 + ret =3D regmap_write(st->regmap, ADXL345_REG_TIME_INACT, 0x37); + if (ret) + return ret; + ret =3D regmap_write(st->regmap, ADXL345_REG_THRESH_ACT, 6); if (ret) return ret; =20 + ret =3D regmap_write(st->regmap, ADXL345_REG_THRESH_INACT, 4); + if (ret) + return ret; + ret =3D regmap_write(st->regmap, ADXL345_REG_THRESH_TAP, tap_threshold); if (ret) return ret; --=20 2.39.5 From nobody Sat Oct 11 08:26:19 2025 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (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 A431528A722; Tue, 10 Jun 2025 21:59:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749592798; cv=none; b=UxPCiNXD1WOgcP8AYBl3cZGwSGwMdiflmPnalAqPF6kN09zGyDY+niEFXkgO7hPAjMRFTKZB6ArmQCHEYYA5wE8EdWx5ownlyUO7a3ju/w0EL7+7inaQuZrzWxFg5h+Xgq+AH3GOOsarQUtzqvdE36wSvlyZcFhmDmpp9g/lSGM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749592798; c=relaxed/simple; bh=OaBykbMp2Rq+XQ6YOQqafgwYQWK8i3391T2Jes/VIEo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Fu+LaHTRZPK/4UipJSOSrlz1ziGl/KEIzDJLIuiCIl6TM7PVwRuV34hfZQWzFKIh6bkd1aRhLHwMgmNLB2SkG3BJoAOqnQ32smU/QVdH8fpoO/GD/DBfZQZmgtXCcVanOKLZXPS9ePXu4I6wRvQfMrwCi87Zouc4T+wnAZalpCk= 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=UnQtAmz3; arc=none smtp.client-ip=209.85.221.51 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="UnQtAmz3" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-3a4e575db1aso777686f8f.2; Tue, 10 Jun 2025 14:59:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749592794; x=1750197594; 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=Rtr6bY8fpgZFbG5TN0BX0c8IK6uZXcYU2zsMpVhTsgM=; b=UnQtAmz335PrRqOsl/Bxbl5hXxMa4d3q/xFw1m/tOqwvqotmqITB4t9eSjllEkhhDr K2FvvONJlKHKZZAOmOfd+cBAUEjUp/r1xJn4EPUyZukoMD8vA2Dq8KbY5DbWGzlC6nMh kFhpnzEyqsgDSPgDpS9ocy/MxqanPqbfGkLHoWXFh2CMvbcfr8D8aGHl+YiPaK54GPTg ZbHcjQvboQfxWWvtntSzQ1LjncyPtTFRIxdHnytfukgItetPJOxO8+w/N2lqyU2sj3jT FEe8hTeJBnn99LydEjsmkITBNnW3oBjWfLgcOMa/YxbP/OnCvmaB7xcorVOrAg+dcz1J yfaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749592794; x=1750197594; 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=Rtr6bY8fpgZFbG5TN0BX0c8IK6uZXcYU2zsMpVhTsgM=; b=YNvw8V/+p/TJrQagcSiChlZlErGu45ip9JxGx18D/YWMP76PmN0678M2pcRyK4lWxZ DBylH6wsMzTbPyW4GxUbhppuv8IcEqQdHTsWz25bWLfSCBPGHPIHNJng9HyJB+7fkA7i uuzvvWB4yB0vh3DOS1u+VMYPaEFJLWmGSCzaHz1O0OiMwJbmd12NFJ2qxYYC0Ob1rFGS Mka1velWK07zN43aOke3UViM6PlWPsQdKgrdmPN1bjEXQY42j0DpocJB3pGQjbfQfuVU B1bLxW7sQMWPQlf435upr19eFHycRDLQvPEHzN9hr/BjTk1Jqe3bwqd4/5eGv3+3y6j0 kK0A== X-Forwarded-Encrypted: i=1; AJvYcCUwdNBcc5EMMgMJZdTYJIvqDR5VPfbrJ8Ow90SsBXEVvdp0TpxdVmkt2PWuorTnzi5GNtpPUhJEKnMPXaP7@vger.kernel.org, AJvYcCWFDbl7lt2EaLacu77Ff00Lr5//hhIxtVZBbYNnZA87ZxldGD1pxl2uSO08kAtQ3OC+sIBLAQrW2RM=@vger.kernel.org X-Gm-Message-State: AOJu0YyfN6MirOzkma8NLETUzTWG4UYlnxwUsD02sJP2HGHqqHU48q5G v3pqMDmFIX5oxippNmuaFvRFSWVLJKa5twBCHANL/s+gSCWbgEjf0GZh X-Gm-Gg: ASbGncsnKsUZUXwf5Jsi2OBkEpzh4OwQG0DfYf2eLhD7MnMb9N1Gk8J3Qn2YBRnNp2J s57eYHMWvhHC2rFb5cP3mNMoMk1m0RbKtfdv8cphvwZRGnZGr+/278IZr9aumb6fHUa1RhUdh0L VIVXVj9MovxAsgSucDr4gime4NFpymNApma6K4g+DUYkme8YnMbN8FI660VVzHowbDVAnjd9ghr Tsrqd3C7T8pDp6fMD1strYBGUnXU/VhadEsir+4pKFlygHONOvrLDNdCa9lh/1q3B2V4CJR2QuR el4zZCEOddrJZcTsCnUKBwpiih4JnDXDD9iD5s3smoRWjUnEkVOIcYNj3thm+dfrg2DXz7SmmZY 7dyHrVL7xqeHbpnnmWKvE7rr2FQwEWMr7 X-Google-Smtp-Source: AGHT+IHysEb5U2dHkrbETPEX5l+2SWnkrEwe1BN2KMYt5LB3eyR+00UJwt5HnP/PHFMoKMfH7HrgRA== X-Received: by 2002:a5d:64ca:0:b0:3a5:2d42:aa1e with SMTP id ffacd0b85a97d-3a558a1af38mr213843f8f.15.1749592793633; Tue, 10 Jun 2025 14:59:53 -0700 (PDT) Received: from localhost.localdomain (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a53244f04dsm13312647f8f.73.2025.06.10.14.59.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 14:59:53 -0700 (PDT) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, corbet@lwn.net Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v9 09/11] iio: accel: adxl345: add coupling detection for activity/inactivity Date: Tue, 10 Jun 2025 21:59:31 +0000 Message-Id: <20250610215933.84795-10-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250610215933.84795-1-l.rubusch@gmail.com> References: <20250610215933.84795-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add adaptive coupling activity/inactivity detection by setting the AC/DC bit. This is an additional configuration to the activity and inactivity magnitude events, respectively. DC-coupled event generation takes the configured threshold values directly, where AC-coupled event generation references to the acceleration value at the start of the activity detection. New samples of acceleration are then compared to this reference. Both types are implemented using MAG for DC-coupled activity/inactivity, but MAG_ADAPTIVE for AC-coupled activity inactivity events. Threshold and periods can be configured by different sysfs handles, but share the same registers at the sensor. Therefore activity and inactivity, respectively, cannot be configured with AC- and DC-coupling at the same time, e.g. configuring DC-coupled and AC-coupled activity will result in AC-coupled activity, or generally the most recent one being configured. This patch implicitly regroups adxl345_read/write_event_value() and adxl345_read/write_event_config() where now redundant parts, due to similar event handling for AC-coupling, are moved to a separate function adxl345_read/write_mag_config() and adxl345_read/write_mag_value(), respectively. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 498 ++++++++++++++++++++++++------- 1 file changed, 382 insertions(+), 116 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_c= ore.c index 1670315ebd63..6a4af559ad9e 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -37,7 +37,9 @@ #define ADXL345_REG_TAP_SUPPRESS_MSK BIT(3) #define ADXL345_REG_TAP_SUPPRESS BIT(3) #define ADXL345_REG_ACT_AXIS_MSK GENMASK(6, 4) +#define ADXL345_REG_ACT_ACDC_MSK BIT(7) #define ADXL345_REG_INACT_AXIS_MSK GENMASK(2, 0) +#define ADXL345_REG_INACT_ACDC_MSK BIT(3) #define ADXL345_POWER_CTL_INACT_MSK (ADXL345_POWER_CTL_AUTO_SLEEP | ADXL34= 5_POWER_CTL_LINK) =20 #define ADXL345_TAP_Z_EN BIT(0) @@ -52,6 +54,9 @@ #define ADXL345_ACT_Y_EN BIT(5) #define ADXL345_ACT_X_EN BIT(6) =20 +#define ADXL345_COUPLING_DC 0 +#define ADXL345_COUPLING_AC 1 + /* single/double tap */ enum adxl345_tap_type { ADXL345_SINGLE_TAP, @@ -79,16 +84,29 @@ static const unsigned int adxl345_tap_time_reg[] =3D { enum adxl345_activity_type { ADXL345_ACTIVITY, ADXL345_INACTIVITY, + ADXL345_ACTIVITY_AC, + ADXL345_INACTIVITY_AC, }; =20 static const unsigned int adxl345_act_int_reg[] =3D { [ADXL345_ACTIVITY] =3D ADXL345_INT_ACTIVITY, [ADXL345_INACTIVITY] =3D ADXL345_INT_INACTIVITY, + [ADXL345_ACTIVITY_AC] =3D ADXL345_INT_ACTIVITY, + [ADXL345_INACTIVITY_AC] =3D ADXL345_INT_INACTIVITY, }; =20 static const unsigned int adxl345_act_thresh_reg[] =3D { [ADXL345_ACTIVITY] =3D ADXL345_REG_THRESH_ACT, [ADXL345_INACTIVITY] =3D ADXL345_REG_THRESH_INACT, + [ADXL345_ACTIVITY_AC] =3D ADXL345_REG_THRESH_ACT, + [ADXL345_INACTIVITY_AC] =3D ADXL345_REG_THRESH_INACT, +}; + +static const unsigned int adxl345_act_acdc_msk[] =3D { + [ADXL345_ACTIVITY] =3D ADXL345_REG_ACT_ACDC_MSK, + [ADXL345_INACTIVITY] =3D ADXL345_REG_INACT_ACDC_MSK, + [ADXL345_ACTIVITY_AC] =3D ADXL345_REG_ACT_ACDC_MSK, + [ADXL345_INACTIVITY_AC] =3D ADXL345_REG_INACT_ACDC_MSK, }; =20 enum adxl345_odr { @@ -186,6 +204,13 @@ static struct iio_event_spec adxl345_events[] =3D { .mask_shared_by_type =3D BIT(IIO_EV_INFO_ENABLE) | BIT(IIO_EV_INFO_VALUE), }, + { + /* activity, ac bit set */ + .type =3D IIO_EV_TYPE_MAG_ADAPTIVE, + .dir =3D IIO_EV_DIR_RISING, + .mask_shared_by_type =3D BIT(IIO_EV_INFO_ENABLE) | + BIT(IIO_EV_INFO_VALUE), + }, { /* single tap */ .type =3D IIO_EV_TYPE_GESTURE, @@ -239,6 +264,14 @@ static const struct iio_event_spec adxl345_fake_chan_e= vents[] =3D { .mask_shared_by_type =3D BIT(IIO_EV_INFO_VALUE) | BIT(IIO_EV_INFO_PERIOD), }, + { + /* inactivity, AC bit set */ + .type =3D IIO_EV_TYPE_MAG_ADAPTIVE, + .dir =3D IIO_EV_DIR_FALLING, + .mask_separate =3D BIT(IIO_EV_INFO_ENABLE), + .mask_shared_by_type =3D BIT(IIO_EV_INFO_VALUE) | + BIT(IIO_EV_INFO_PERIOD), + }, }; =20 static const struct iio_chan_spec adxl345_channels[] =3D { @@ -345,12 +378,108 @@ static int adxl345_set_inact_time(struct adxl345_sta= te *st, u32 val_s) return regmap_write(st->regmap, ADXL345_REG_TIME_INACT, val); } =20 +/** + * adxl345_is_act_inact_ac() - Verify if AC or DC coupling is currently en= abled. + * + * @st: The device data. + * @type: The activity or inactivity type. + * + * Given a type of activity / inactivity combined with either AC coupling = set or + * default to DC, this function verifies if the combination is currently + * configured, hence enabled or not. + * + * Return: true if configured coupling matches the provided type, else a n= egative + * error value. + */ +static int adxl345_is_act_inact_ac(struct adxl345_state *st, + enum adxl345_activity_type type) +{ + unsigned int regval; + bool coupling; + int ret; + + ret =3D regmap_read(st->regmap, ADXL345_REG_ACT_INACT_CTRL, ®val); + if (ret) + return ret; + + coupling =3D adxl345_act_acdc_msk[type] & regval; + + if (type =3D=3D ADXL345_ACTIVITY || type =3D=3D ADXL345_INACTIVITY) + return coupling =3D=3D ADXL345_COUPLING_DC; + else + return coupling =3D=3D ADXL345_COUPLING_AC; + + return 0; +} + +/** + * adxl345_set_act_inact_ac() - Configure AC coupling or DC coupling. + * + * @st: The device data. + * @type: Provide a type of activity or inactivity. + * + * Enables AC coupling or DC coupling depending on the provided type argum= ent. + * Note: Activity and inactivity can be either AC coupled or DC coupled not + * both at the same time. + * + * Return: 0 if successful, else error value. + */ +static int adxl345_set_act_inact_ac(struct adxl345_state *st, + enum adxl345_activity_type type) +{ + unsigned int coupling; + + if (type =3D=3D ADXL345_ACTIVITY_AC || type =3D=3D ADXL345_INACTIVITY_AC) + coupling =3D ADXL345_COUPLING_AC; + else + coupling =3D ADXL345_COUPLING_DC; + + /* + * A setting of false selects dc-coupled operation, and a setting of + * true enables ac-coupled operation. In dc-coupled operation, the + * current acceleration magnitude is compared directly with + * ADXL345_REG_THRESH_ACT and ADXL345_REG_THRESH_INACT to determine + * whether activity or inactivity is detected. + * + * In ac-coupled operation for activity detection, the acceleration + * value at the start of activity detection is taken as a reference + * value. New samples of acceleration are then compared to this + * reference value, and if the magnitude of the difference exceeds the + * ADXL345_REG_THRESH_ACT value, the device triggers an activity + * interrupt. + * + * Similarly, in ac-coupled operation for inactivity detection, a + * reference value is used for comparison and is updated whenever the + * device exceeds the inactivity threshold. After the reference value + * is selected, the device compares the magnitude of the difference + * between the reference value and the current acceleration with + * ADXL345_REG_THRESH_INACT. If the difference is less than the value in + * ADXL345_REG_THRESH_INACT for the time in ADXL345_REG_TIME_INACT, the + * device is considered inactive and the inactivity interrupt is + * triggered. [quoted from p. 24, ADXL345 datasheet Rev. G] + * + * In a conclusion, the first acceleration snapshot sample which hit the + * threshold in a particular direction is always taken as acceleration + * reference value to that direction. Since for the hardware activity + * and inactivity depend on the x/y/z axis, so do ac and dc coupling. + * Note, this sw driver always enables or disables all three x/y/z axis + * for detection via act_axis_ctrl and inact_axis_ctrl, respectively. + * Where in dc-coupling samples are compared against the thresholds, in + * ac-coupling measurement difference to the first acceleration + * reference value are compared against the threshold. So, ac-coupling + * allows for a bit more dynamic compensation depending on the initial + * sample. + */ + return regmap_assign_bits(st->regmap, ADXL345_REG_ACT_INACT_CTRL, + adxl345_act_acdc_msk[type], coupling); +} + static int adxl345_is_act_inact_en(struct adxl345_state *st, enum adxl345_activity_type type) { unsigned int regval; u32 axis_ctrl; - bool en; + bool coupling_en, int_en, en; int ret; =20 ret =3D regmap_read(st->regmap, ADXL345_REG_ACT_INACT_CTRL, &axis_ctrl); @@ -359,11 +488,13 @@ static int adxl345_is_act_inact_en(struct adxl345_sta= te *st, =20 switch (type) { case ADXL345_ACTIVITY: + case ADXL345_ACTIVITY_AC: en =3D FIELD_GET(ADXL345_ACT_X_EN, axis_ctrl) | FIELD_GET(ADXL345_ACT_Y_EN, axis_ctrl) | FIELD_GET(ADXL345_ACT_Z_EN, axis_ctrl); break; case ADXL345_INACTIVITY: + case ADXL345_INACTIVITY_AC: en =3D FIELD_GET(ADXL345_INACT_X_EN, axis_ctrl) | FIELD_GET(ADXL345_INACT_Y_EN, axis_ctrl) | FIELD_GET(ADXL345_INACT_Z_EN, axis_ctrl); @@ -379,8 +510,48 @@ static int adxl345_is_act_inact_en(struct adxl345_stat= e *st, ret =3D regmap_read(st->regmap, ADXL345_REG_INT_ENABLE, ®val); if (ret) return ret; + int_en =3D adxl345_act_int_reg[type] & regval; + + /* Check if coupling is enabled */ + ret =3D adxl345_is_act_inact_ac(st, type); + if (ret < 0) + return ret; + coupling_en =3D ret; =20 - return adxl345_act_int_reg[type] & regval; + return coupling_en && int_en; +} + +static int adxl345_set_act_inact_linkbit(struct adxl345_state *st, + enum adxl345_activity_type type, + bool en) +{ + int act_en, act_ac_en, inact_en, inact_ac_en; + + act_en =3D adxl345_is_act_inact_en(st, ADXL345_ACTIVITY); + if (act_en < 0) + return act_en; + + act_ac_en =3D adxl345_is_act_inact_en(st, ADXL345_ACTIVITY_AC); + if (act_ac_en < 0) + return act_ac_en; + + act_en =3D act_en || act_ac_en; + + inact_en =3D adxl345_is_act_inact_en(st, ADXL345_INACTIVITY); + if (inact_en < 0) + return inact_en; + + inact_ac_en =3D adxl345_is_act_inact_en(st, ADXL345_INACTIVITY_AC); + if (inact_ac_en < 0) + return inact_ac_en; + + inact_en =3D inact_en || inact_ac_en; + + en =3D en && act_en && inact_en; + + return regmap_assign_bits(st->regmap, ADXL345_REG_POWER_CTL, + (ADXL345_POWER_CTL_AUTO_SLEEP | ADXL345_POWER_CTL_LINK), + en); } =20 static int adxl345_set_act_inact_en(struct adxl345_state *st, @@ -391,15 +562,24 @@ static int adxl345_set_act_inact_en(struct adxl345_st= ate *st, unsigned int inact_time_s; unsigned int threshold; u32 axis_ctrl; - int act_en, inact_en; int ret; =20 + /* + * In case of turning off, assure turning off a correspondent coupling + * event. In case of not matching coupling, simply return. + */ + if (!cmd_en) { + /* Expected positive true if coupling matches coupling type */ + if (adxl345_is_act_inact_ac(st, type) <=3D 0) + return 0; + } + /* Start configuring the sensor registers */ ret =3D adxl345_set_measure_en(st, false); if (ret) return ret; =20 - if (type =3D=3D ADXL345_ACTIVITY) { + if (type =3D=3D ADXL345_ACTIVITY || type =3D=3D ADXL345_ACTIVITY_AC) { axis_ctrl =3D ADXL345_ACT_X_EN | ADXL345_ACT_Y_EN | ADXL345_ACT_Z_EN; } else { @@ -407,12 +587,16 @@ static int adxl345_set_act_inact_en(struct adxl345_st= ate *st, ADXL345_INACT_Z_EN; } =20 + ret =3D regmap_read(st->regmap, adxl345_act_thresh_reg[type], &threshold); + if (ret) + return ret; + ret =3D regmap_assign_bits(st->regmap, ADXL345_REG_ACT_INACT_CTRL, axis_ctrl, cmd_en); if (ret) return ret; =20 - ret =3D regmap_read(st->regmap, adxl345_act_thresh_reg[type], &threshold); + ret =3D adxl345_set_act_inact_ac(st, type); if (ret) return ret; =20 @@ -420,10 +604,12 @@ static int adxl345_set_act_inact_en(struct adxl345_st= ate *st, =20 switch (type) { case ADXL345_ACTIVITY: + case ADXL345_ACTIVITY_AC: en =3D FIELD_GET(ADXL345_REG_ACT_AXIS_MSK, axis_ctrl) && threshold; break; case ADXL345_INACTIVITY: + case ADXL345_INACTIVITY_AC: ret =3D regmap_read(st->regmap, ADXL345_REG_TIME_INACT, &inact_time_s); if (ret) return ret; @@ -435,25 +621,14 @@ static int adxl345_set_act_inact_en(struct adxl345_st= ate *st, return -EINVAL; } =20 + /* Enable interrupts accordingly. */ ret =3D regmap_assign_bits(st->regmap, ADXL345_REG_INT_ENABLE, - adxl345_act_int_reg[type], cmd_en); + adxl345_act_int_reg[type], cmd_en && en); if (ret) return ret; =20 /* Set sleep and link bit when ACT and INACT are enabled. */ - act_en =3D adxl345_is_act_inact_en(st, ADXL345_ACTIVITY); - if (act_en < 0) - return act_en; - - inact_en =3D adxl345_is_act_inact_en(st, ADXL345_INACTIVITY); - if (inact_en < 0) - return inact_en; - - en =3D en && act_en && inact_en; - - ret =3D regmap_assign_bits(st->regmap, ADXL345_REG_POWER_CTL, - (ADXL345_POWER_CTL_AUTO_SLEEP | ADXL345_POWER_CTL_LINK), - en); + ret =3D adxl345_set_act_inact_linkbit(st, type, en); if (ret) return ret; =20 @@ -894,6 +1069,40 @@ static int adxl345_write_raw(struct iio_dev *indio_de= v, return adxl345_set_measure_en(st, true); } =20 +static int adxl345_read_mag_config(struct adxl345_state *st, + const struct iio_chan_spec *chan, + enum iio_event_direction dir, + enum adxl345_activity_type type_act, + enum adxl345_activity_type type_inact) +{ + switch (dir) { + case IIO_EV_DIR_RISING: + return adxl345_is_act_inact_en(st, type_act); + case IIO_EV_DIR_FALLING: + return adxl345_is_act_inact_en(st, type_inact); + default: + return -EINVAL; + } +} + +static int adxl345_write_mag_config(struct adxl345_state *st, + const struct iio_chan_spec *chan, + enum iio_event_direction dir, + enum iio_event_type type, + enum adxl345_activity_type type_act, + enum adxl345_activity_type type_inact, + bool state) +{ + switch (dir) { + case IIO_EV_DIR_RISING: + return adxl345_set_act_inact_en(st, type_act, state); + case IIO_EV_DIR_FALLING: + return adxl345_set_act_inact_en(st, type_inact, state); + default: + return -EINVAL; + } +} + static int adxl345_read_event_config(struct iio_dev *indio_dev, const struct iio_chan_spec *chan, enum iio_event_type type, @@ -905,14 +1114,13 @@ static int adxl345_read_event_config(struct iio_dev = *indio_dev, =20 switch (type) { case IIO_EV_TYPE_MAG: - switch (dir) { - case IIO_EV_DIR_RISING: - return adxl345_is_act_inact_en(st, ADXL345_ACTIVITY); - case IIO_EV_DIR_FALLING: - return adxl345_is_act_inact_en(st, ADXL345_INACTIVITY); - default: - return -EINVAL; - } + return adxl345_read_mag_config(st, chan, dir, + ADXL345_ACTIVITY, + ADXL345_INACTIVITY); + case IIO_EV_TYPE_MAG_ADAPTIVE: + return adxl345_read_mag_config(st, chan, dir, + ADXL345_ACTIVITY_AC, + ADXL345_INACTIVITY_AC); case IIO_EV_TYPE_GESTURE: switch (dir) { case IIO_EV_DIR_SINGLETAP: @@ -945,27 +1153,100 @@ static int adxl345_write_event_config(struct iio_de= v *indio_dev, =20 switch (type) { case IIO_EV_TYPE_MAG: + return adxl345_write_mag_config(st, chan, dir, type, + ADXL345_ACTIVITY, + ADXL345_INACTIVITY, + state); + case IIO_EV_TYPE_MAG_ADAPTIVE: + return adxl345_write_mag_config(st, chan, dir, type, + ADXL345_ACTIVITY_AC, + ADXL345_INACTIVITY_AC, + state); + case IIO_EV_TYPE_GESTURE: + switch (dir) { + case IIO_EV_DIR_SINGLETAP: + return adxl345_set_singletap_en(st, chan->channel2, state); + case IIO_EV_DIR_DOUBLETAP: + return adxl345_set_doubletap_en(st, state); + default: + return -EINVAL; + } + default: + return -EINVAL; + } +} + +static int adxl345_read_mag_value(struct adxl345_state *st, + enum adxl345_activity_type type_act, + enum adxl345_activity_type type_inact, /* TODO needed */ + enum iio_event_direction dir, + enum iio_event_info info, + int *val, int *val2) +{ + unsigned int act_threshold, inact_threshold; + int ret; + + switch (info) { + case IIO_EV_INFO_VALUE: switch (dir) { case IIO_EV_DIR_RISING: - return adxl345_set_act_inact_en(st, - ADXL345_ACTIVITY, - state); + ret =3D regmap_read(st->regmap, + adxl345_act_thresh_reg[type_act], + &act_threshold); + if (ret) + return ret; + *val =3D 62500 * act_threshold; + *val2 =3D MICRO; + return IIO_VAL_FRACTIONAL; case IIO_EV_DIR_FALLING: - return adxl345_set_act_inact_en(st, - ADXL345_INACTIVITY, - state); + ret =3D regmap_read(st->regmap, + adxl345_act_thresh_reg[type_inact], + &inact_threshold); + if (ret) + return ret; + *val =3D 62500 * inact_threshold; + *val2 =3D MICRO; + return IIO_VAL_FRACTIONAL; default: return -EINVAL; } - case IIO_EV_TYPE_GESTURE: + case IIO_EV_INFO_PERIOD: + ret =3D regmap_read(st->regmap, + ADXL345_REG_TIME_INACT, + val); + return IIO_VAL_INT; + default: + return -EINVAL; + } +} + +static int adxl345_write_mag_value(struct adxl345_state *st, + enum adxl345_activity_type type_act, + enum adxl345_activity_type type_inact, + enum iio_event_direction dir, + enum iio_event_info info, + int val, int val2) +{ + switch (info) { + case IIO_EV_INFO_VALUE: + /* + * Scaling factor 62.5mg/LSB, i.e. ~16g corresponds to 0xff + */ + val =3D DIV_ROUND_CLOSEST(val * MICRO + val2, 62500); switch (dir) { - case IIO_EV_DIR_SINGLETAP: - return adxl345_set_singletap_en(st, chan->channel2, state); - case IIO_EV_DIR_DOUBLETAP: - return adxl345_set_doubletap_en(st, state); + case IIO_EV_DIR_RISING: + return regmap_write(st->regmap, + adxl345_act_thresh_reg[type_act], + val); + case IIO_EV_DIR_FALLING: + return regmap_write(st->regmap, + adxl345_act_thresh_reg[type_inact], + val); default: return -EINVAL; } + case IIO_EV_INFO_PERIOD: + return adxl345_set_inact_time(st, val); default: return -EINVAL; } @@ -979,48 +1260,18 @@ static int adxl345_read_event_value(struct iio_dev *= indio_dev, int *val, int *val2) { struct adxl345_state *st =3D iio_priv(indio_dev); - unsigned int act_threshold, inact_threshold; - unsigned int inact_time_s; unsigned int tap_threshold; int ret; =20 switch (type) { case IIO_EV_TYPE_MAG: - switch (info) { - case IIO_EV_INFO_VALUE: - switch (dir) { - case IIO_EV_DIR_RISING: - ret =3D regmap_read(st->regmap, - adxl345_act_thresh_reg[ADXL345_ACTIVITY], - &act_threshold); - if (ret) - return ret; - *val =3D 62500 * act_threshold; - *val2 =3D MICRO; - return IIO_VAL_FRACTIONAL; - case IIO_EV_DIR_FALLING: - ret =3D regmap_read(st->regmap, - adxl345_act_thresh_reg[ADXL345_INACTIVITY], - &inact_threshold); - if (ret) - return ret; - *val =3D 62500 * inact_threshold; - *val2 =3D MICRO; - return IIO_VAL_FRACTIONAL; - default: - return -EINVAL; - } - case IIO_EV_INFO_PERIOD: - ret =3D regmap_read(st->regmap, - ADXL345_REG_TIME_INACT, - &inact_time_s); - if (ret) - return ret; - *val =3D inact_time_s; - return IIO_VAL_INT; - default: - return -EINVAL; - } + return adxl345_read_mag_value(st, ADXL345_ACTIVITY, + ADXL345_INACTIVITY, dir, info, + val, val2); + case IIO_EV_TYPE_MAG_ADAPTIVE: + return adxl345_read_mag_value(st, ADXL345_ACTIVITY_AC, + ADXL345_INACTIVITY_AC, dir, info, + val, val2); case IIO_EV_TYPE_GESTURE: switch (info) { case IIO_EV_INFO_VALUE: @@ -1070,36 +1321,20 @@ static int adxl345_write_event_value(struct iio_dev= *indio_dev, =20 switch (type) { case IIO_EV_TYPE_MAG: - switch (info) { - case IIO_EV_INFO_VALUE: - val =3D DIV_ROUND_CLOSEST(val * MICRO + val2, 62500); - switch (dir) { - case IIO_EV_DIR_RISING: - ret =3D regmap_write(st->regmap, - adxl345_act_thresh_reg[ADXL345_ACTIVITY], - val); - if (ret) - return ret; - break; - case IIO_EV_DIR_FALLING: - ret =3D regmap_write(st->regmap, - adxl345_act_thresh_reg[ADXL345_INACTIVITY], - val); - if (ret) - return ret; - break; - default: - return -EINVAL; - } - break; - case IIO_EV_INFO_PERIOD: - ret =3D adxl345_set_inact_time(st, val); - if (ret) - return ret; - break; - default: - return -EINVAL; - } + ret =3D adxl345_write_mag_value(st, + ADXL345_ACTIVITY, + ADXL345_INACTIVITY, + dir, info, val, val2); + if (ret) + return ret; + break; + case IIO_EV_TYPE_MAG_ADAPTIVE: + ret =3D adxl345_write_mag_value(st, + ADXL345_ACTIVITY_AC, + ADXL345_INACTIVITY_AC, + dir, info, val, val2); + if (ret) + return ret; break; case IIO_EV_TYPE_GESTURE: switch (info) { @@ -1347,6 +1582,7 @@ static int adxl345_push_event(struct iio_dev *indio_d= ev, int int_stat, { s64 ts =3D iio_get_time_ns(indio_dev); struct adxl345_state *st =3D iio_priv(indio_dev); + unsigned int regval; int samples; int ret =3D -ENOENT; =20 @@ -1371,22 +1607,52 @@ static int adxl345_push_event(struct iio_dev *indio= _dev, int int_stat, } =20 if (FIELD_GET(ADXL345_INT_ACTIVITY, int_stat)) { - ret =3D iio_push_event(indio_dev, - IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, act_dir, - IIO_EV_TYPE_MAG, - IIO_EV_DIR_RISING), - ts); + ret =3D regmap_read(st->regmap, ADXL345_REG_ACT_INACT_CTRL, ®val); + if (ret) + return ret; + + if (FIELD_GET(ADXL345_REG_ACT_ACDC_MSK, regval)) { + /* AC coupled */ + ret =3D iio_push_event(indio_dev, + IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, act_dir, + IIO_EV_TYPE_MAG_ADAPTIVE, + IIO_EV_DIR_RISING), + ts); + + } else { + /* DC coupled, relying on THRESH */ + ret =3D iio_push_event(indio_dev, + IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, act_dir, + IIO_EV_TYPE_MAG, + IIO_EV_DIR_RISING), + ts); + } if (ret) return ret; } =20 if (FIELD_GET(ADXL345_INT_INACTIVITY, int_stat)) { - ret =3D iio_push_event(indio_dev, - IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, - IIO_MOD_X_AND_Y_AND_Z, - IIO_EV_TYPE_MAG, - IIO_EV_DIR_FALLING), - ts); + ret =3D regmap_read(st->regmap, ADXL345_REG_ACT_INACT_CTRL, ®val); + if (ret) + return ret; + + if (FIELD_GET(ADXL345_REG_INACT_ACDC_MSK, regval)) { + /* AC coupled */ + ret =3D iio_push_event(indio_dev, + IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, + IIO_MOD_X_AND_Y_AND_Z, + IIO_EV_TYPE_MAG_ADAPTIVE, + IIO_EV_DIR_FALLING), + ts); + } else { + /* DC coupled, relying on THRESH */ + ret =3D iio_push_event(indio_dev, + IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, + IIO_MOD_X_AND_Y_AND_Z, + IIO_EV_TYPE_MAG, + IIO_EV_DIR_FALLING), + ts); + } if (ret) return ret; } --=20 2.39.5 From nobody Sat Oct 11 08:26:19 2025 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.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 8E93228AAE1; Tue, 10 Jun 2025 21:59:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749592798; cv=none; b=rIexOX1RoYbDnPdvscWRh8u/CBzp69hNa0WgoJ2JdH9dB97g6n3pcgxGPJpBkzdIg4TK/5/ou+KFpGZ88L6rQjzpNDVQstWWbcw8QjUHCoKBKs7IaOWAp1rZyVd41Fp0RsQ5HcZ2q2grdYhdeAFDpGU3g1m2unqwPUezrGoPZ68= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749592798; c=relaxed/simple; bh=zdf2o3GNT0PrZvxhGuy5bqYI3XGJGMj/MsOvR4fg08U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eLZIUKsc55yApWviE2/SifA8IJf5E4/hfQ8CFCfhb5OWneiMqTRqFSG1kwdkYCqI4pTXRmXnPD7ezy3dYDwpBv5FsenULD+CUiCQZDEW/h2LI7w014nlrc5WIVoqYWLr4cgr76zjjHiaBHSVPD3FwGuNjWT0Otn8Lfk8yVweCg8= 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=OfIY0Rvt; arc=none smtp.client-ip=209.85.221.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="OfIY0Rvt" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-3a528e301b0so790635f8f.1; Tue, 10 Jun 2025 14:59:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749592795; x=1750197595; 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=yNcLrTnvuT1Qe76HK2Tsx4xoyXpLEnvpzok27cKhlGs=; b=OfIY0Rvt6ARBWISqev1jYHeLny/eDQY495SmjTXBmip5AcfpG76JiXbiXb04nOT77q YcFstIO/rH7H2rTNGqNa5TCa77MrtUyhalZVfhA0QnP7xDAd3kBwpO0uCjgdx9YQ7a1n GrbHj25EktoRB4zbLBAe6NaEq5tTydbLFAdWIRaMYuelZ7gvD9iE43JkbYvgxgrEuP2q Un7W/u+b94wXbqAcYSPRqJrUE/Dm3nZZTbuZ0DlCvSCGA7w8WVMuD8PMeHAKQRidxj7/ 5LtO1aYrw7a8kQvG5y6IynIbeI8Uvj1EoSUDUCksiH2Zmx0/APqtPb8QvhVtnNCEVyFB ABjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749592795; x=1750197595; 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=yNcLrTnvuT1Qe76HK2Tsx4xoyXpLEnvpzok27cKhlGs=; b=Q6q+hbcM+ArHkdeZlLBNnVNEn7uNb4aBfI7z/56WuMPbuTC3CZaEHqBzwn/1tPAb62 xXigQH+s+kMOs5TWi2DORYCimz473jTFwELtsj8DHbgUnPngcWB8XjdDLe+n/h1OIQaE ymujpO3CDl2KANuOECIAVzFi1IzU5BfbDmPuNHN5rArtEOgkeLpTlA443WlEJMQHD8Bz c61qqkR1c/LaaNbzNOlp+yzhciSzKkzlAsBtGxFv9L1JG4H3owKMIWfiv6yKYIv84EXu t52qB+xWADoEntItKMWn2n2wkE++2BhOfgWpC9TXarnqaOjtCi+TmucOw2dHiICnN7XP Pf4A== X-Forwarded-Encrypted: i=1; AJvYcCW9d4PRhi3HE0epdWyEeDaebp1LvngVTOfxnJIWVm5mtEXhP2dpt6l6Rr1NVs+NP4mDd+Fk2Bb1CgjIelAa@vger.kernel.org, AJvYcCXNa2Q8o7GICfhSXYR6Mcx6rTWRvrHOh8paGeTfbmHg79lIPqLq2k7LFM3BMZVc7ZaYDzUp2TmjzpI=@vger.kernel.org X-Gm-Message-State: AOJu0Yz26/gwsJ4lREtOqLZiJ2mX+qVRbUIQIowXh7Mgy5sbwEUJ+b2p HWaQSUX3q91hfSnsLRcLN3xJjPp+6bwBeRm/dqscDTSLTnEVEQAn09nu X-Gm-Gg: ASbGnct9cS3xJRHB6vRtS8QQT87oXiQPfW0LyGnVjuInVV4No0pyKirxJCw+y6gMF6M 0Cs1bM9TZ55HrA1FDpmE+aPcvqBDgkW46jSirXv6fqhZNd7X7KnVhzQuLZ1JGWZRYmcv6BJZyLt s2cTnwyj8afm0MLBthH46s6UJED9BpAn7Llfl26uj/tN4u69VDfgrFN/LWtXRz+MSdS7Ad3Bpqo p1CRXOS3Bn2n21LfaVXHpSritHIA1xnYruFtEyk7pbdI4wQWTxRvtg7CN4OPWSmdd7SfB3grZlh yldCJbjhKeglH1WpyNI7TjyhdONI/nqKh8lKJ+pCOaBRxGhHz+iwnKCfhCRFL+PmSnyU+wZgZOp SKGDNyzM7Xc2QYECI/gRIR3ncMMYLqaZT X-Google-Smtp-Source: AGHT+IEiW8tg7bjLO6DvY9j56OPoVKVgh2PcwkstE+NGubL4mWPgXzIyA1Z8e6dZ8p/rI9c6KKd0Aw== X-Received: by 2002:a05:6000:2507:b0:3a4:f7d9:9617 with SMTP id ffacd0b85a97d-3a55864e245mr199312f8f.0.1749592794630; Tue, 10 Jun 2025 14:59:54 -0700 (PDT) Received: from localhost.localdomain (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a53244f04dsm13312647f8f.73.2025.06.10.14.59.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 14:59:54 -0700 (PDT) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, corbet@lwn.net Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v9 10/11] iio: accel: adxl345: extend inactivity time for less than 1s Date: Tue, 10 Jun 2025 21:59:32 +0000 Message-Id: <20250610215933.84795-11-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250610215933.84795-1-l.rubusch@gmail.com> References: <20250610215933.84795-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Inactivity event and free-fall event are actually the same type of sensor events. Hence, inactivity detection using a period of 1 to 255s can be extended to be used for lower periods than 1s for covering free-fall detection. When lower periods are defined, the driver automatically will setup threshold and period on the free-fall register, while using the inactivity threshold and period for periods above 1s. Using the free-fall register, no link bit will be set, and therefore no auto-sleep can be set in cases where also activity will be enabled. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 165 +++++++++++++++++++++---------- 1 file changed, 113 insertions(+), 52 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_c= ore.c index 6a4af559ad9e..7afc120b4a45 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -86,6 +86,7 @@ enum adxl345_activity_type { ADXL345_INACTIVITY, ADXL345_ACTIVITY_AC, ADXL345_INACTIVITY_AC, + ADXL345_INACTIVITY_FF, }; =20 static const unsigned int adxl345_act_int_reg[] =3D { @@ -93,6 +94,7 @@ static const unsigned int adxl345_act_int_reg[] =3D { [ADXL345_INACTIVITY] =3D ADXL345_INT_INACTIVITY, [ADXL345_ACTIVITY_AC] =3D ADXL345_INT_ACTIVITY, [ADXL345_INACTIVITY_AC] =3D ADXL345_INT_INACTIVITY, + [ADXL345_INACTIVITY_FF] =3D ADXL345_INT_FREE_FALL, }; =20 static const unsigned int adxl345_act_thresh_reg[] =3D { @@ -100,6 +102,7 @@ static const unsigned int adxl345_act_thresh_reg[] =3D { [ADXL345_INACTIVITY] =3D ADXL345_REG_THRESH_INACT, [ADXL345_ACTIVITY_AC] =3D ADXL345_REG_THRESH_ACT, [ADXL345_INACTIVITY_AC] =3D ADXL345_REG_THRESH_INACT, + [ADXL345_INACTIVITY_FF] =3D ADXL345_REG_THRESH_FF, }; =20 static const unsigned int adxl345_act_acdc_msk[] =3D { @@ -107,6 +110,7 @@ static const unsigned int adxl345_act_acdc_msk[] =3D { [ADXL345_INACTIVITY] =3D ADXL345_REG_INACT_ACDC_MSK, [ADXL345_ACTIVITY_AC] =3D ADXL345_REG_ACT_ACDC_MSK, [ADXL345_INACTIVITY_AC] =3D ADXL345_REG_INACT_ACDC_MSK, + [ADXL345_INACTIVITY_FF] =3D 0x00, }; =20 enum adxl345_odr { @@ -189,6 +193,9 @@ struct adxl345_state { u8 watermark; u8 fifo_mode; =20 + u8 inact_threshold; + u32 inact_time_ms; + u32 tap_duration_us; u32 tap_latent_us; u32 tap_window_us; @@ -333,12 +340,31 @@ static int adxl345_set_measure_en(struct adxl345_stat= e *st, bool en) =20 /* act/inact */ =20 +static int adxl345_set_inact_threshold(struct adxl345_state *st, + unsigned int threshold) +{ + int ret; + + st->inact_threshold =3D min(U8_MAX, threshold); + + ret =3D regmap_write(st->regmap, + adxl345_act_thresh_reg[ADXL345_INACTIVITY], + st->inact_threshold); + if (ret) + return ret; + + return regmap_write(st->regmap, + adxl345_act_thresh_reg[ADXL345_INACTIVITY_FF], + st->inact_threshold); +} + /** * adxl345_set_inact_time - Configure inactivity time explicitly or by ODR. * @st: The sensor state instance. - * @val_s: A desired time value, between 0 and 255. + * @val_int: The inactivity time, integer part. + * @val_fract: The inactivity time, fractional part when val_int is 0. * - * Inactivity time can be configured between 1 and 255 sec. If a val_s of 0 + * Inactivity time can be configured between 1 and 255 sec. If a val_s of = 0.00 * is configured by a user, then a default inactivity time will be compute= d. * * In such case, it should take power consumption into consideration. Thus= it @@ -355,16 +381,18 @@ static int adxl345_set_measure_en(struct adxl345_stat= e *st, bool en) * * Return: 0 or error value. */ -static int adxl345_set_inact_time(struct adxl345_state *st, u32 val_s) +static int adxl345_set_inact_time(struct adxl345_state *st, u32 val_int, + u32 val_fract) { unsigned int max_boundary =3D 255; unsigned int min_boundary =3D 10; - unsigned int val =3D min(val_s, max_boundary); + unsigned int val; enum adxl345_odr odr; unsigned int regval; int ret; =20 - if (val =3D=3D 0) { + if (val_int =3D=3D 0 && val_fract =3D=3D 0) { + /* Generated inactivity time based on ODR */ ret =3D regmap_read(st->regmap, ADXL345_REG_BW_RATE, ®val); if (ret) return ret; @@ -373,9 +401,41 @@ static int adxl345_set_inact_time(struct adxl345_state= *st, u32 val_s) =20 val =3D (adxl345_odr_tbl[odr][0] > max_boundary) ? min_boundary : max_boundary - adxl345_odr_tbl[odr][0]; + + st->inact_time_ms =3D MILLI * val; + + /* Inactivity time in s */ + ret =3D regmap_write(st->regmap, ADXL345_REG_TIME_INACT, val); + if (ret) + return ret; + + } else if (val_int =3D=3D 0 && val_fract > 0) { + /* time < 1s, free-fall */ + + /* + * Datasheet max. value is 255 * 5000 us =3D 1.275000 seconds. + * + * Recommended values between 100ms and 350ms (0x14 to 0x46) + */ + st->inact_time_ms =3D DIV_ROUND_UP(val_fract, MILLI); + + ret =3D regmap_write(st->regmap, ADXL345_REG_TIME_FF, + DIV_ROUND_CLOSEST(val_fract, 5)); + if (ret) + return ret; + } else if (val_int > 0) { + /* Time >=3D 1s, inactivity */ + st->inact_time_ms =3D MILLI * val_int; + + ret =3D regmap_write(st->regmap, ADXL345_REG_TIME_INACT, val_int); + if (ret) + return ret; + } else { + /* Do not support negative or wrong input. */ + return -EINVAL; } =20 - return regmap_write(st->regmap, ADXL345_REG_TIME_INACT, val); + return 0; } =20 /** @@ -398,6 +458,9 @@ static int adxl345_is_act_inact_ac(struct adxl345_state= *st, bool coupling; int ret; =20 + if (type =3D=3D ADXL345_INACTIVITY_FF) + return 1; + ret =3D regmap_read(st->regmap, ADXL345_REG_ACT_INACT_CTRL, ®val); if (ret) return ret; @@ -499,6 +562,9 @@ static int adxl345_is_act_inact_en(struct adxl345_state= *st, FIELD_GET(ADXL345_INACT_Y_EN, axis_ctrl) | FIELD_GET(ADXL345_INACT_Z_EN, axis_ctrl); break; + case ADXL345_INACTIVITY_FF: + en =3D true; + break; default: return -EINVAL; } @@ -537,15 +603,19 @@ static int adxl345_set_act_inact_linkbit(struct adxl3= 45_state *st, =20 act_en =3D act_en || act_ac_en; =20 - inact_en =3D adxl345_is_act_inact_en(st, ADXL345_INACTIVITY); - if (inact_en < 0) - return inact_en; + if (type =3D=3D ADXL345_INACTIVITY_FF) { + inact_en =3D false; + } else { + inact_en =3D adxl345_is_act_inact_en(st, ADXL345_INACTIVITY); + if (inact_en < 0) + return inact_en; =20 - inact_ac_en =3D adxl345_is_act_inact_en(st, ADXL345_INACTIVITY_AC); - if (inact_ac_en < 0) - return inact_ac_en; + inact_ac_en =3D adxl345_is_act_inact_en(st, ADXL345_INACTIVITY_AC); + if (inact_ac_en < 0) + return inact_ac_en; =20 - inact_en =3D inact_en || inact_ac_en; + inact_en =3D inact_en || inact_ac_en; + } =20 en =3D en && act_en && inact_en; =20 @@ -559,7 +629,6 @@ static int adxl345_set_act_inact_en(struct adxl345_stat= e *st, bool cmd_en) { bool en; - unsigned int inact_time_s; unsigned int threshold; u32 axis_ctrl; int ret; @@ -582,14 +651,16 @@ static int adxl345_set_act_inact_en(struct adxl345_st= ate *st, if (type =3D=3D ADXL345_ACTIVITY || type =3D=3D ADXL345_ACTIVITY_AC) { axis_ctrl =3D ADXL345_ACT_X_EN | ADXL345_ACT_Y_EN | ADXL345_ACT_Z_EN; + + ret =3D regmap_read(st->regmap, adxl345_act_thresh_reg[type], &threshold= ); + if (ret) + return ret; } else { axis_ctrl =3D ADXL345_INACT_X_EN | ADXL345_INACT_Y_EN | ADXL345_INACT_Z_EN; - } =20 - ret =3D regmap_read(st->regmap, adxl345_act_thresh_reg[type], &threshold); - if (ret) - return ret; + threshold =3D st->inact_threshold; + } =20 ret =3D regmap_assign_bits(st->regmap, ADXL345_REG_ACT_INACT_CTRL, axis_ctrl, cmd_en); @@ -610,12 +681,9 @@ static int adxl345_set_act_inact_en(struct adxl345_sta= te *st, break; case ADXL345_INACTIVITY: case ADXL345_INACTIVITY_AC: - ret =3D regmap_read(st->regmap, ADXL345_REG_TIME_INACT, &inact_time_s); - if (ret) - return ret; - + case ADXL345_INACTIVITY_FF: en =3D FIELD_GET(ADXL345_REG_INACT_AXIS_MSK, axis_ctrl) && - threshold && inact_time_s; + threshold && st->inact_time_ms; break; default: return -EINVAL; @@ -873,7 +941,7 @@ static int adxl345_set_odr(struct adxl345_state *st, en= um adxl345_odr odr) return ret; =20 /* update inactivity time by ODR */ - return adxl345_set_inact_time(st, 0); + return adxl345_set_inact_time(st, 0, 0); } =20 static int adxl345_find_range(struct adxl345_state *st, int val, int val2, @@ -910,12 +978,6 @@ static int adxl345_set_range(struct adxl345_state *st,= enum adxl345_range range) if (ret) return ret; =20 - ret =3D regmap_read(st->regmap, - adxl345_act_thresh_reg[ADXL345_INACTIVITY], - &inact_threshold); - if (ret) - return ret; - ret =3D regmap_update_bits(st->regmap, ADXL345_REG_DATA_FORMAT, ADXL345_DATA_FORMAT_RANGE, FIELD_PREP(ADXL345_DATA_FORMAT_RANGE, range)); @@ -926,6 +988,7 @@ static int adxl345_set_range(struct adxl345_state *st, = enum adxl345_range range) / adxl345_range_factor_tbl[range]; act_threshold =3D min(U8_MAX, max(1, act_threshold)); =20 + inact_threshold =3D st->inact_threshold; inact_threshold =3D inact_threshold * adxl345_range_factor_tbl[range_old] / adxl345_range_factor_tbl[range]; inact_threshold =3D min(U8_MAX, max(1, inact_threshold)); @@ -935,8 +998,7 @@ static int adxl345_set_range(struct adxl345_state *st, = enum adxl345_range range) if (ret) return ret; =20 - return regmap_write(st->regmap, adxl345_act_thresh_reg[ADXL345_INACTIVITY= ], - inact_threshold); + return adxl345_set_inact_threshold(st, inact_threshold); } =20 static int adxl345_read_avail(struct iio_dev *indio_dev, @@ -1183,7 +1245,7 @@ static int adxl345_read_mag_value(struct adxl345_stat= e *st, enum iio_event_info info, int *val, int *val2) { - unsigned int act_threshold, inact_threshold; + unsigned int act_threshold; int ret; =20 switch (info) { @@ -1199,22 +1261,16 @@ static int adxl345_read_mag_value(struct adxl345_st= ate *st, *val2 =3D MICRO; return IIO_VAL_FRACTIONAL; case IIO_EV_DIR_FALLING: - ret =3D regmap_read(st->regmap, - adxl345_act_thresh_reg[type_inact], - &inact_threshold); - if (ret) - return ret; - *val =3D 62500 * inact_threshold; + *val =3D 62500 * st->inact_threshold; *val2 =3D MICRO; return IIO_VAL_FRACTIONAL; default: return -EINVAL; } case IIO_EV_INFO_PERIOD: - ret =3D regmap_read(st->regmap, - ADXL345_REG_TIME_INACT, - val); - return IIO_VAL_INT; + *val =3D st->inact_time_ms; + *val2 =3D MILLI; + return IIO_VAL_FRACTIONAL; default: return -EINVAL; } @@ -1239,14 +1295,12 @@ static int adxl345_write_mag_value(struct adxl345_s= tate *st, adxl345_act_thresh_reg[type_act], val); case IIO_EV_DIR_FALLING: - return regmap_write(st->regmap, - adxl345_act_thresh_reg[type_inact], - val); + return adxl345_set_inact_threshold(st, val); default: return -EINVAL; } case IIO_EV_INFO_PERIOD: - return adxl345_set_inact_time(st, val); + return adxl345_set_inact_time(st, val, val2); default: return -EINVAL; } @@ -1657,6 +1711,17 @@ static int adxl345_push_event(struct iio_dev *indio_= dev, int int_stat, return ret; } =20 + if (FIELD_GET(ADXL345_INT_FREE_FALL, int_stat)) { + ret =3D iio_push_event(indio_dev, + IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, + IIO_MOD_X_AND_Y_AND_Z, + IIO_EV_TYPE_MAG, + IIO_EV_DIR_FALLING), + ts); + if (ret) + return ret; + } + if (FIELD_GET(ADXL345_INT_WATERMARK, int_stat)) { samples =3D adxl345_get_samples(st); if (samples < 0) @@ -1888,15 +1953,11 @@ int adxl345_core_probe(struct device *dev, struct r= egmap *regmap, if (ret) return ret; =20 - ret =3D regmap_write(st->regmap, ADXL345_REG_TIME_INACT, 0x37); - if (ret) - return ret; - ret =3D regmap_write(st->regmap, ADXL345_REG_THRESH_ACT, 6); if (ret) return ret; =20 - ret =3D regmap_write(st->regmap, ADXL345_REG_THRESH_INACT, 4); + ret =3D adxl345_set_inact_threshold(st, 4); if (ret) return ret; =20 --=20 2.39.5 From nobody Sat Oct 11 08:26:19 2025 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9394428BA95; Tue, 10 Jun 2025 21:59:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749592804; cv=none; b=f1RB8VpMCK/SIe0uF1UeUlBESgbR57qs83Aimgn+VxeIZeN6IoeEtAQ5wDNcMOMzj5j/go3Vxhd/rwtoRMmCdBEeKto2YBSoAzg1H5av49Syp9EA+7C8KtBE+A9vDURY+O4dzEknamLrXON/SdI3stmC5Dxey8a49J2S+ampOLw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749592804; c=relaxed/simple; bh=JXp/+L4rKHxi/p+II76hnjQkQLdZkkvEl2EjQYDLvs0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=icWTTYzUANlhznl0huxg7wrKnxD2489djJW2Y7vQsoHSI1tfeY3Fb2WFSoZ+BTDOlb89uneHOtAkHJkDU5IITjcLd6esoRJKQwadwE3efy8NC0eu9lSjyLnZ92H7+kLhg0NK8NRz/qObbDK2+QoEbCAfyXl1ZY08+zbpsHOL44o= 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=MnEIyQn4; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MnEIyQn4" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-45306433f71so2015155e9.0; Tue, 10 Jun 2025 14:59:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749592797; x=1750197597; 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=EoxP6s5uxHp/o4oT/QnESDAwKlxvEu/SMGL9oOCHEqs=; b=MnEIyQn4OUFg++v13QXMoX+0fcsYHjw0I39gccLuJrDuVkVC/fJKHLLorJSba8KT66 NsRHpOUL++19nYZPmtXsJv/00LIkCEQKDygUfPRPasXBceMnOnJpj5JYw51vFuaCG95s s4HsmC+znWa1yiJcRQZRb9DEWLaweO0zYY7rNRFqzbW2h4HmdNKydeKAdpbfsMegCgyO ACJikHgRmWfQrigm3j6QUXtHKY0Cipb81xqqQASuDqF3w8r8179uRRYj2raY3mCOckBM HO5FQa0PqYBegCBJD+fV78KAYmMdmw0vy/2XVlFphEEcMzkaxo8wWdTfx9Ja7BYc8ZTe okuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749592797; x=1750197597; 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=EoxP6s5uxHp/o4oT/QnESDAwKlxvEu/SMGL9oOCHEqs=; b=Gd6z6vLQ8NrR8qsMNI5iS6qbcSyivIV4mZnZ/TCy7jrovExy/Suwign33KE2FAgmxn gLD4J0bP63INyMtxXPWsC3qau2EzD4HUmzXwjM7U+26c/U94g6om7h8/zx5SPaa/3Y3r D5qk9VSBRbjaTtYzdwYLjIa9Anuu/qyNv4NmJeQobVszOM82NU+el0M8Oc3DRjPJ4Snz V7Umcck4p0u3TviuXbh36/7VERShQWU80PsonnFYLcVFaDUBS7luRnc2fidHab9EKbcg pqVvtB/0nfzxLH0iPC9WlSqgZ6pKcEfE+SSSv/oAknxBXVqNtPHcGWasiPeugavaBVjo kGDg== X-Forwarded-Encrypted: i=1; AJvYcCUIzPfegrKDh6sebDpb4leKx4LQoERPkO2wAGpby67NXmNkO+w79PQAtEwGDljr+poauvqialOiZTr5Ht58@vger.kernel.org, AJvYcCVWiJ36sdZlTyKlnnNg+Zr/lihizsM9Bv6+llvcLjW4Cj26YMN4WJsQgXr+2ejXmdnfLntubLKn3RM=@vger.kernel.org X-Gm-Message-State: AOJu0YwiIG0tjdYdHbk/Ut66LYh0Q9w6NQ/DqI7Bz9JEFfEJ1ifi6wO9 GVs1aqK+8RbpzdglQuJeopl3tOUcM57goaXyyMZjZG2Ml9qCFiGYzE4F X-Gm-Gg: ASbGncu/1njH47BoNWuzTOr2w6MJtFMF5KrMRFWNiLYMfQ+4wUtmOKO8J//Bub2nxk5 7bJW8XvfAecIINuxs2zjLqM3hXNVILPxg+tvnF84pu4h1ETlILxJJCp3kwNSOrLevhMOToBbJbB lHMV0PoHlylghk/KimKpPvgcWmhuM0jDhRx8KzzUBAm+MiseDrpkGSQLK3GlTh/PaXhoMh/HkQy ypKWiv/mK+xJXr23rOqHYg98hTfA/UKVu+RemPwQskHNjReQQGQUoCrZp/d1wRc8/4STATl6MgR s9il0EJqxyM1YFD44/KuJOxc+RLhwJI5xTAO0SXsPXxiZktxpD25oRypWNHZz+5LTkxIs2mVy7t 8se1mgHeMutYhQkVszAwLAN5zOK+KpAwQ X-Google-Smtp-Source: AGHT+IGwTojfGLY3oK/HaDh/HKr0Dq2Y1ed24RGPGOp9YQw7YiRKk2M4v2hJ8QJz3li8p4h9fcTExg== X-Received: by 2002:a05:6000:40c9:b0:3a4:e667:9226 with SMTP id ffacd0b85a97d-3a558803f93mr194845f8f.10.1749592796422; Tue, 10 Jun 2025 14:59:56 -0700 (PDT) Received: from localhost.localdomain (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a53244f04dsm13312647f8f.73.2025.06.10.14.59.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 14:59:55 -0700 (PDT) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, corbet@lwn.net Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v9 11/11] docs: iio: add documentation for adxl345 driver Date: Tue, 10 Jun 2025 21:59:33 +0000 Message-Id: <20250610215933.84795-12-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250610215933.84795-1-l.rubusch@gmail.com> References: <20250610215933.84795-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The documentation describes the ADXL345 driver, IIO interface, interface usage and configuration. Signed-off-by: Lothar Rubusch --- Documentation/iio/adxl345.rst | 429 ++++++++++++++++++++++++++++++++++ Documentation/iio/index.rst | 1 + 2 files changed, 430 insertions(+) create mode 100644 Documentation/iio/adxl345.rst diff --git a/Documentation/iio/adxl345.rst b/Documentation/iio/adxl345.rst new file mode 100644 index 000000000000..2908c90dc943 --- /dev/null +++ b/Documentation/iio/adxl345.rst @@ -0,0 +1,429 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +ADXL345 driver +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +This driver supports Analog Device's ADXL345/375 on SPI/I2C bus. + +1. Supported Devices +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +* `ADXL345 `_ +* `ADXL375 `_ + +The ADXL345 is a generic purpose low power, 3-axis accelerometer with sele= ctable +measurement ranges. The ADXL345 supports the =C2=B12 g, =C2=B14 g, =C2=B18= g, and =C2=B116 g ranges. + +2. Device Attributes +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Each IIO device, has a device folder under ``/sys/bus/iio/devices/iio:devi= ceX``, +where X is the IIO index of the device. Under these folders reside a set of +device files, depending on the characteristics and features of the hardware +device in questions. These files are consistently generalized and document= ed in +the IIO ABI documentation. + +The following table shows the ADXL345 related device files, found in the +specific device folder path ``/sys/bus/iio/devices/iio:deviceX``. + ++-------------------------------------------+-----------------------------= -----------------------------+ +| 3-Axis Accelerometer related device files | Description = | ++-------------------------------------------+-----------------------------= -----------------------------+ +| in_accel_sampling_frequency | Currently selected sample ra= te. | ++-------------------------------------------+-----------------------------= -----------------------------+ +| in_accel_sampling_frequency_available | Available sampling frequency= configurations. | ++-------------------------------------------+-----------------------------= -----------------------------+ +| in_accel_scale | Scale/range for the accelero= meter channels. | ++-------------------------------------------+-----------------------------= -----------------------------+ +| in_accel_scale_available | Available scale ranges for t= he accelerometer channel. | ++-------------------------------------------+-----------------------------= -----------------------------+ +| in_accel_x_calibbias | Calibration offset for the X= -axis accelerometer channel. | ++-------------------------------------------+-----------------------------= -----------------------------+ +| in_accel_x_raw | Raw X-axis accelerometer cha= nnel value. | ++-------------------------------------------+-----------------------------= -----------------------------+ +| in_accel_y_calibbias | y-axis acceleration offset c= orrection | ++-------------------------------------------+-----------------------------= -----------------------------+ +| in_accel_y_raw | Raw Y-axis accelerometer cha= nnel value. | ++-------------------------------------------+-----------------------------= -----------------------------+ +| in_accel_z_calibbias | Calibration offset for the Z= -axis accelerometer channel. | ++-------------------------------------------+-----------------------------= -----------------------------+ +| in_accel_z_raw | Raw Z-axis accelerometer cha= nnel value. | ++-------------------------------------------+-----------------------------= -----------------------------+ + +Channel Processed Values +------------------------- + +A channel value can be read from its _raw attribute. The value returned is= the +raw value as reported by the devices. To get the processed value of the ch= annel, +apply the following formula: + +.. code-block:: bash + + processed value =3D (_raw + _offset) * _scale + +Where _offset and _scale are device attributes. If no _offset attribute is +present, simply assume its value is 0. + ++-------------------------------------+---------------------------+ +| Channel type | Measurement unit | ++-------------------------------------+---------------------------+ +| Acceleration on X, Y, and Z axis | Meters per second squared | ++-------------------------------------+---------------------------+ + +Sensor Events +------------- + +Particular IIO events will be triggered by the corresponding interrupts. T= he +sensor driver supports no or one active INT line, where the sensor has two +possible INT IOs. Configure the used INT line in the devicetree. If no INT= line +is configured, the sensor falls back to FIFO bypass mode and no events are +possible, only X, Y and Z axis measurements are possible. + +The following table shows the ADXL345 related device files, found in the +specific device folder path ``/sys/bus/iio/devices/iio:deviceX/events``. +Note, the default activity/inactivity is DC coupled. Thus only AC coupled +activity and inactivity are mentioned explicitly. + ++---------------------------------------------+---------------------------= ------------------+ +| Event handle | Description = | ++---------------------------------------------+---------------------------= ------------------+ +| in_accel_gesture_doubletap_en | Enable double tap detectio= n on all axis | ++---------------------------------------------+---------------------------= ------------------+ +| in_accel_gesture_doubletap_reset_timeout | Double tap window in [us] = | ++---------------------------------------------+---------------------------= ------------------+ +| in_accel_gesture_doubletap_tap2_min_delay | Double tap latent in [us] = | ++---------------------------------------------+---------------------------= ------------------+ +| in_accel_gesture_singletap_timeout | Single tap duration in [us= ] | ++---------------------------------------------+---------------------------= ------------------+ +| in_accel_gesture_singletap_value | Single tap threshold value= in 62.5/LSB | ++---------------------------------------------+---------------------------= ------------------+ +| in_accel_mag_falling_period | Inactivity time in seconds= | ++---------------------------------------------+---------------------------= ------------------+ +| in_accel_mag_falling_value | Inactivity threshold value= in 62.5/LSB | ++---------------------------------------------+---------------------------= ------------------+ +| in_accel_mag_adaptive_rising_en | Enable AC coupled activity= on X axis | ++---------------------------------------------+---------------------------= ------------------+ +| in_accel_mag_adaptive_falling_period | AC coupled inactivity time= in seconds | ++---------------------------------------------+---------------------------= ------------------+ +| in_accel_mag_adaptive_falling_value | AC coupled inactivity thre= shold in 62.5/LSB | ++---------------------------------------------+---------------------------= ------------------+ +| in_accel_mag_adaptive_rising_value | AC coupled activity thresh= old in 62.5/LSB | ++---------------------------------------------+---------------------------= ------------------+ +| in_accel_mag_rising_en | Enable activity detection = on X axis | ++---------------------------------------------+---------------------------= ------------------+ +| in_accel_mag_rising_value | Activity threshold value i= n 62.5/LSB | ++---------------------------------------------+---------------------------= ------------------+ +| in_accel_x_gesture_singletap_en | Enable single tap detectio= n on X axis | ++---------------------------------------------+---------------------------= ------------------+ +| in_accel_x&y&z_mag_falling_en | Enable inactivity detectio= n on all axis | ++---------------------------------------------+---------------------------= ------------------+ +| in_accel_x&y&z_mag_adaptive_falling_en | Enable AC coupled inactivi= ty on all axis | ++---------------------------------------------+---------------------------= ------------------+ +| in_accel_y_gesture_singletap_en | Enable single tap detectio= n on Y axis | ++---------------------------------------------+---------------------------= ------------------+ +| in_accel_z_gesture_singletap_en | Enable single tap detectio= n on Z axis | ++---------------------------------------------+---------------------------= ------------------+ + +Find a detailed description of a particular functionality in the sensor +datasheet. + +Setting the **ODR** explicitly will result in estimated adjusted default v= alues +for the inactivity time detection, where higher frequencies shall default = to +longer wait periods, and vice versa. It is also possible to explicitly +configure inactivity wait times, if the defaulting approach does not match +application requirements. Setting 0 here, will fall back to default settin= g. + +The **g range** configuration also tries to estimate activity and inactivi= ty +thresholds when switching to another g range. The default range will be +factorized by the relation of old range divided by new range. The value ne= ver +becomes 0 and will be at least 1 and at most 255 i.e. 62.5g/LSB according = to +the datasheet. Nevertheless activity and inactivity thresholds can be +overwritten by explicit values. + +When **activity** and **inactivity** events are enabled, the driver automa= tically +will implement its hysteresis solution by setting link bit and auto-sleep = bit. +The link bit serially links the activity and inactivity functions. On the = other +side, the auto-sleep function switches the sensor to sleep mode if the +inactivity function is enabled. This will reduce current consumption to the +sub-12.5Hz rate. Inactivity time can be configured between 1s and 255s. As= ide of +inactivity the sensor offers a free-fall detection. Free-fall detection is= in +terms of IIO the same kind of falling mag(nitude) event on all axis. In te= rms of +the sensor, free-fall uses an inactivity period of 0.000s to 1.000s. The d= river +now implements the following: When an inactivity period of 1s or more is +provided, it uses the inactivity register. This event may be linked to act= ivity, +use auto-sleep and can be AC-coupled or DC-coupled. When less than 1s of +inactivity period is provided, it will behave as plain inactivity detectio= n or +free-fall, respectively. There won't be auto-sleep or coupling in such cas= e. +When 0.000s is configured as inactivity time, the driver will define a +reasonable period of inactivity, depending on a heuristic approach to opti= mize +power consumption (above 1s, so using the inactivity register). + +Note, using the activity register, the inactivity register, or the free-fa= ll +register is recommended for 12.5 Hz ODR up to 400 Hz. By the datasheet, +free-fall threshold is recommended between 300mg and 600mg (0x05 to 0x09),= and +free-fall time is recommended to be set between 100ms and 350ms (0x14 to 0= x46). + +In **DC-coupled** operation, the current acceleration magnitude is compared +directly with THRESH_ACT and THRESH_INACT registers to determine whether +activity or inactivity was detected. In AC-coupled operation for activity +detection, the acceleration value at the start of activity detection is ta= ken +as a reference value. New samples are then compared to this reference valu= e. +Where DC-coupled is the default case detecting against the configured thre= shold, +AC-coupled measurements are referenced against an internal filter depending +on the configured threshold. +Activity detection can be enabled on particular axis. Inactivity detection= on +the other side, is enabled or disabled on all axis. + +AC-coupling and DC-coupling are individually set for activity and/or +inactivity detection, and cannot be set both at the same time. Enabling +AC-coupled activity detection, and then DC-coupled activity detection will +result in performing DC-coupled activity detection only. Hence, only the m= ost +recent configuration will valid. + +**Single tap** detection can be configured according to the datasheet by s= pecifying +threshold and duration. If only the single tap is in use, the single tap +interrupt is triggered when the acceleration goes above threshold (i.e. DUR +start) and below the threshold, as long as duration is not exceeded. If si= ngle +tap and double tap are in use, the single tap is triggered when the double= tap +event has been either validated or invalidated. + +For **double tap** configure additionally window and latency in [us]. Late= ncy +starts counting when the single tap goes below threshold and is a waiting +period, any spikes here are ignored for double tap detection. After latenc= y, +the window starts. Any rise above threshold, with a consequent fall below +threshold within window time, rises a double tap signal when going below +threshold. + +Double tap event detection is best described in the datasheet. After a +single tap event was detected, a double tap event can be detected. Therefo= re the +signal must match several criteria, and detection can also considered inva= lid +for three reasons: +* If the **suppress bit** is set and when still in the tap latency period,= any +measurement of acceleration spike above the tap threshold invalidates doub= le tap +detection immediately, i.e. during latency must not occur spikes for doubl= e tap +detection when the suppress bit is set. +* A double tap event is considered invalid, if acceleration lies above the +threshold at the start of the window time for double tap. +* Additionally, double tap detection can be considered invalid, if an +acceleration exceeds the time limit for taps, set by duration register. + +Since for double tap the same duration counts, i.e. when measruements rise= above +threshold, a consequent falling below threshold has to be within duration = time. +Note here the suppress bit is generally set when double tap is enabled. + +Usage Examples +-------------- + +Show device name: + +.. code-block:: bash + + root:/sys/bus/iio/devices/iio:device0> cat name + adxl345 + +Show accelerometer channels value: + +.. code-block:: bash + + root:/sys/bus/iio/devices/iio:device0> cat in_accel_x_raw + -1 + root:/sys/bus/iio/devices/iio:device0> cat in_accel_y_raw + 2 + root:/sys/bus/iio/devices/iio:device0> cat in_accel_z_raw + -253 + +Set calibration offset for accelerometer channels: + +.. code-block:: bash + + root:/sys/bus/iio/devices/iio:device0> cat in_accel_x_calibbias + 0 + + root:/sys/bus/iio/devices/iio:device0> echo 50 > in_accel_x_calibb= ias + root:/sys/bus/iio/devices/iio:device0> cat in_accel_x_calibbias + 50 + +Given the 13-bit full resolution, the available ranges are calculated by t= he +following formula: + +.. code-block:: bash + + (g * 2 * 9.80665) / (2^(resolution) - 1) * 100; for g :=3D 2|4|8|16 + +Scale range configuration: + +.. code-block:: bash + + root:/sys/bus/iio/devices/iio:device0> cat ./in_accel_scale + 0.478899 + root:/sys/bus/iio/devices/iio:device0> cat ./in_accel_scale_availa= ble + 0.478899 0.957798 1.915595 3.831190 + + root:/sys/bus/iio/devices/iio:device0> echo 1.915595 > ./in_accel_= scale + root:/sys/bus/iio/devices/iio:device0> cat ./in_accel_scale + 1.915595 + +Set output data rate (ODR): + +.. code-block:: bash + + root:/sys/bus/iio/devices/iio:device0> cat ./in_accel_sampling_fre= quency + 200.000000 + + root:/sys/bus/iio/devices/iio:device0> cat ./in_accel_sampling_fre= quency_available + 0.097000 0.195000 0.390000 0.781000 1.562000 3.125000 6.250000 12.= 500000 25.000000 50.000000 100.000000 200.000000 400.000000 800.000000 1600= .000000 3200.000000 + + root:/sys/bus/iio/devices/iio:device0> echo 1.562000 > ./in_accel_= sampling_frequency + root:/sys/bus/iio/devices/iio:device0> cat ./in_accel_sampling_fre= quency + 1.562000 + +Configure one or several events: + +.. code-block:: bash + + root:> cd /sys/bus/iio/devices/iio:device0 + + root:/sys/bus/iio/devices/iio:device0> echo 1 > ./buffer0/in_accel= _x_en + root:/sys/bus/iio/devices/iio:device0> echo 1 > ./buffer0/in_accel= _y_en + root:/sys/bus/iio/devices/iio:device0> echo 1 > ./buffer0/in_accel= _z_en + + root:/sys/bus/iio/devices/iio:device0> echo 1 > ./scan_elements/in= _accel_x_en + root:/sys/bus/iio/devices/iio:device0> echo 1 > ./scan_elements/in= _accel_y_en + root:/sys/bus/iio/devices/iio:device0> echo 1 > ./scan_elements/in= _accel_z_en + + root:/sys/bus/iio/devices/iio:device0> echo 14 > ./in_accel_x_ca= libbias + root:/sys/bus/iio/devices/iio:device0> echo 2 > ./in_accel_y_ca= libbias + root:/sys/bus/iio/devices/iio:device0> echo -250 > ./in_accel_z_ca= libbias + + root:/sys/bus/iio/devices/iio:device0> echo 24 > ./buffer0/length + + ## AC coupled activity, threshold [62.5/LSB] + root:/sys/bus/iio/devices/iio:device0> echo 6 > ./events/in_accel_= mag_adaptive_rising_value + + ## AC coupled inactivity, threshold, [62.5/LSB] + root:/sys/bus/iio/devices/iio:device0> echo 4 > ./events/in_accel_= mag_adaptive_falling_value + + ## AC coupled inactivity, time [s] + root:/sys/bus/iio/devices/iio:device0> echo 3 > ./events/in_accel_= mag_adaptive_falling_period + + ## singletap, threshold + root:/sys/bus/iio/devices/iio:device0> echo 35 > ./events/in_accel= _gesture_singletap_value + + ## singletap, duration [us] + root:/sys/bus/iio/devices/iio:device0> echo 0.001875 > ./events/i= n_accel_gesture_singletap_timeout + + ## doubletap, window [us] + root:/sys/bus/iio/devices/iio:device0> echo 0.025 > ./events/in_ac= cel_gesture_doubletap_reset_timeout + + ## doubletap, latent [us] + root:/sys/bus/iio/devices/iio:device0> echo 0.025 > ./events/in_ac= cel_gesture_doubletap_tap2_min_delay + + ## AC coupled activity, enable + root:/sys/bus/iio/devices/iio:device0> echo 1 > ./events/in_accel_= mag_adaptive_rising_en + + ## AC coupled inactivity, enable + root:/sys/bus/iio/devices/iio:device0> echo 1 > ./events/in_accel_= x\&y\&z_mag_adaptive_falling_en + + ## singletap, enable + root:/sys/bus/iio/devices/iio:device0> echo 1 > ./events/in_accel_= x_gesture_singletap_en + root:/sys/bus/iio/devices/iio:device0> echo 1 > ./events/in_accel_= y_gesture_singletap_en + root:/sys/bus/iio/devices/iio:device0> echo 1 > ./events/in_accel_= z_gesture_singletap_en + + ## doubletap, enable + root:/sys/bus/iio/devices/iio:device0> echo 1 > ./events/in_accel_= gesture_doubletap_en + +Verify incoming events: + +.. code-block:: bash + + root:# iio_event_monitor adxl345 + Found IIO device with name adxl345 with device number 0 + Event: time: 1739063415957073383, type: accel(z), channel: 0, evty= pe: mag, direction: rising + Event: time: 1739063415963770218, type: accel(z), channel: 0, evty= pe: mag, direction: rising + Event: time: 1739063416002563061, type: accel(z), channel: 0, evty= pe: gesture, direction: singletap + Event: time: 1739063426271128739, type: accel(x&y&z), channel: 0, = evtype: mag, direction: falling + Event: time: 1739063436539080713, type: accel(x&y&z), channel: 0, = evtype: mag, direction: falling + Event: time: 1739063438357970381, type: accel(z), channel: 0, evty= pe: mag, direction: rising + Event: time: 1739063446726161586, type: accel(z), channel: 0, evty= pe: mag, direction: rising + Event: time: 1739063446727892670, type: accel(z), channel: 0, evty= pe: mag, direction: rising + Event: time: 1739063446743019768, type: accel(z), channel: 0, evty= pe: mag, direction: rising + Event: time: 1739063446744650696, type: accel(z), channel: 0, evty= pe: mag, direction: rising + Event: time: 1739063446763559386, type: accel(z), channel: 0, evty= pe: gesture, direction: singletap + Event: time: 1739063448818126480, type: accel(x&y&z), channel: 0, = evtype: mag, direction: falling + ... + +Activity and inactivity belong together and indicate state changes as foll= ows + +.. code-block:: bash + + root:# iio_event_monitor adxl345 + Found IIO device with name adxl345 with device number 0 + Event: time: 1744648001133946293, type: accel(x), channel: 0, evty= pe: mag, direction: rising + + Event: time: 1744648057724775499, type: accel(x&y&z), channel: 0, = evtype: mag, direction: falling + ... + +3. Device Buffers +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +This driver supports IIO buffers. + +All devices support retrieving the raw acceleration and temperature measur= ements +using buffers. + +Usage examples +-------------- + +Select channels for buffer read: + +.. code-block:: bash + + root:/sys/bus/iio/devices/iio:device0> echo 1 > scan_elements/in_a= ccel_x_en + root:/sys/bus/iio/devices/iio:device0> echo 1 > scan_elements/in_a= ccel_y_en + root:/sys/bus/iio/devices/iio:device0> echo 1 > scan_elements/in_a= ccel_z_en + +Set the number of samples to be stored in the buffer: + +.. code-block:: bash + + root:/sys/bus/iio/devices/iio:device0> echo 10 > buffer/length + +Enable buffer readings: + +.. code-block:: bash + + root:/sys/bus/iio/devices/iio:device0> echo 1 > buffer/enable + +Obtain buffered data: + +.. code-block:: bash + + root:> iio_readdev -b 16 -s 1024 adxl345 | hexdump -d + WARNING: High-speed mode not enabled + 0000000 00003 00012 00013 00005 00010 00011 00005 = 00011 + 0000010 00013 00004 00012 00011 00003 00012 00014 = 00007 + 0000020 00011 00013 00004 00013 00014 00003 00012 = 00013 + 0000030 00004 00012 00013 00005 00011 00011 00005 = 00012 + 0000040 00014 00005 00012 00014 00004 00010 00012 = 00004 + 0000050 00013 00011 00003 00011 00012 00005 00011 = 00013 + 0000060 00003 00012 00012 00003 00012 00012 00004 = 00012 + 0000070 00012 00003 00013 00013 00003 00013 00012 = 00005 + 0000080 00012 00013 00003 00011 00012 00005 00012 = 00013 + 0000090 00003 00013 00011 00005 00013 00014 00003 = 00012 + 00000a0 00012 00003 00012 00013 00004 00012 00015 = 00004 + 00000b0 00014 00011 00003 00014 00013 00004 00012 = 00011 + 00000c0 00004 00012 00013 00004 00014 00011 00004 = 00013 + 00000d0 00012 00002 00014 00012 00005 00012 00013 = 00005 + 00000e0 00013 00013 00003 00013 00013 00005 00012 = 00013 + 00000f0 00004 00014 00015 00005 00012 00011 00005 = 00012 + ... + +See ``Documentation/iio/iio_devbuf.rst`` for more information about how bu= ffered +data is structured. + +4. IIO Interfacing Tools +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +See ``Documentation/iio/iio_tools.rst`` for the description of the availab= le IIO +interfacing tools. diff --git a/Documentation/iio/index.rst b/Documentation/iio/index.rst index 2d6afc5a8ed5..c333720c1c9f 100644 --- a/Documentation/iio/index.rst +++ b/Documentation/iio/index.rst @@ -32,6 +32,7 @@ Industrial I/O Kernel Drivers adis16480 adis16550 adxl380 + adxl345 bno055 ep93xx_adc opt4060 --=20 2.39.5