From patchwork Fri Dec 13 21:19:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13907861 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 50489186294; Fri, 13 Dec 2024 21:19:20 +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=1734124762; cv=none; b=QLEw3d/hB7OMAsUgnk17xJCtihCfVG/UmYaj2AND1WEPnqPyz3a1wC6PLlF0g4VZrKoU1zGsVcjEeHG0O+NNc6otGK+9pnbTaew1BCO3t9od5JncT/e2A46pIzB8kWO0xwdSszWce24N4diUpU7wtw41S9cvA/ydC1wLdb0Sze8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734124762; c=relaxed/simple; bh=Cr1713WajhHzvYvE8UfeGtOFiIQNZyadluwSxA0FUrg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=m3nS3/Zha2NLs7SiBWWMiobEs1JmHgRjCPeLdhoo3hmtZ9HBfYzhaPe6tJA7MJnPjxzRP8vyhiOAbzqTOIDeJ7Sy7nbzX2olO36ImPmjW7YIwp/zIh8J1BTjnzqLFrc/nHXu/4F8UuySWKZoBmHR4LcNk7okoEM2FZeQKoA2S90= 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=JAzS4F+N; 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="JAzS4F+N" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4361aa6e517so2487905e9.2; Fri, 13 Dec 2024 13:19:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734124759; x=1734729559; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HYXh6GxOLbpXiurdOh608cToA5zl7Wcej6r5BOVjdKA=; b=JAzS4F+NavfaX02i0Jxj/wyRUUq5dWMVHhyPL7kmL5cMU0Tdt+5LvMVBiNe4u24vI9 JIgaOxwzT3VuUpB2TbE9oOV+OqdqdjQc0LgZMH+JGiduIPCX1wXfveTEX6RXB4JSoJVa V6w7VAfbxiJn8uuRQZ0FnUgi7SdbeSoA8OSDevcCr9/NsJlm3W7dWzgQ/zncLr4ypGuK u2JQuDsrJvA2L3sFkpULaFXW1Uz2QBZuitrkfzyBFvaDojvSm9ElINeBVfP02YYh4pgb HEyPVbPWIe9VNkbhEMr0ngVM74wtPEvdeuyJZLC2eC8Y8qP0nUAJyQ741Pk1ELkzXQBD rVFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734124759; x=1734729559; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HYXh6GxOLbpXiurdOh608cToA5zl7Wcej6r5BOVjdKA=; b=cImvU5BNZnghEWjpuaafDPSrSH66u/NPnsrXyR29g3v9ps7nj4Vkjbi7za+EYsMQVf xC3l1v6KEI/peiy5kWXWmpNiB+0NX19OSL1AuD+CqYsx37N+wkCB0qInPwr3o7OfM12N pnEdIKwAw3/79zVJS2YuTjjBTHkBCsVwv65jxACzj+SL+OuRl/qQqnl3nXMrEWH6e6XC MdvFDjvV+XevFTQK90cdhROPcRJY/eYJkF6Tce5Sf7yFXZ5Jfl9MpYKIAM2aj0a7F5bU tc3m5EdKo01bmIMYaxGY+neWxzOgby20ilwicN4rl+vWNBiYi1NZ7lpmbuz6jYIYZz3f tjJg== X-Forwarded-Encrypted: i=1; AJvYcCV0arI5kOkRD5VPvdhP+xxnmcG5sdGnFukHqmJv/HC8oueD4S9lc/ysp21QmG+KMLpEccp2ydNDA/5FZVSa@vger.kernel.org, AJvYcCVAhN3gWWonXwoKi9lgz8A5aDYcmHpS4Pwz0FG0S7i43AhUID6Gc6ZCI0DMAyHGfNfGedOWeFtvJWg=@vger.kernel.org X-Gm-Message-State: AOJu0YwksOWRyVKESjKd7j0xDjiK0twogoUrO2vgsFPbeyCTXi9z2+/D hPGA1MnRQNZVbjcgZTcd76hw+sBsLNNhs76O+ySjdTy0F3NfrQWN X-Gm-Gg: ASbGnctS7lEnE0oEFTALonzjTe9Wp9z7I62SfN4n7lJADijy6hZDD7onv3oeIWfhVUK 9ZS+jyb+JArHvxqoYnKNx2cMXV1CecGw1Binb0hCKABPP0Ls2iZTA5AqNpoDUs3KpIBvqpG1hh4 IK1Tw86pQGB+/SYfT9/kOBK3rjrfYffV1Z7xWfYqhRFvJNGRUI5MoQ0ka2jFIM5HLJZ3Fc1Iith oYdMLdAOnTPVEDu3MgHxfL4pymxfknQIRmo9fADJUbj6odRO/Yo9XSQl1R40Dw802mMRqX8/81a gjm+YYGOfee/vVDnBSF7d+OaYCkt8bHMjIM= X-Google-Smtp-Source: AGHT+IEUEIVWjEfgKbM8Cc8zH/n9VX8CQxTXDlBMaTADnP3GWvmd/JKE2uz/zdWjMIiotMQeD5v83w== X-Received: by 2002:a05:600c:3552:b0:434:f335:85c with SMTP id 5b1f17b1804b1-4362aaaab94mr12988415e9.6.1734124758517; Fri, 13 Dec 2024 13:19:18 -0800 (PST) Received: from d9dabf0abd47.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-388c801acfdsm552484f8f.57.2024.12.13.13.19.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Dec 2024 13:19:18 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v7 1/7] iio: accel: adxl345: add function to switch measuring mode Date: Fri, 13 Dec 2024 21:19:03 +0000 Message-Id: <20241213211909.40896-2-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241213211909.40896-1-l.rubusch@gmail.com> References: <20241213211909.40896-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replace the powerup / powerdown functions by a generic function to put the sensor in STANDBY, or MEASURE mode. When configuring the FIFO for several features of the accelerometer, it is recommended to put measuring in STANDBY mode. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 42 +++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 88df9547b..b48bc838c 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -138,6 +138,34 @@ static int adxl345_write_raw_get_fmt(struct iio_dev *indio_dev, } } +/** + * adxl345_set_measure_en() - Enable and disable measuring. + * + * @st: The device data. + * @en: Enable measurements, else standby mode. + * + * For lowest power operation, standby mode can be used. In standby mode, + * current consumption is supposed to be reduced to 0.1uA (typical). In this + * mode no measurements are made. Placing the device into standby mode + * preserves the contents of FIFO. + * + * Return: Returns 0 if successful, or a negative error value. + */ +static int adxl345_set_measure_en(struct adxl345_state *st, bool en) +{ + unsigned int val = 0; + + val = (en) ? ADXL345_POWER_CTL_MEASURE : ADXL345_POWER_CTL_STANDBY; + return regmap_write(st->regmap, ADXL345_REG_POWER_CTL, val); +} + +static void adxl345_powerdown(void *ptr) +{ + struct adxl345_state *st = ptr; + + adxl345_set_measure_en(st, false); +} + static IIO_CONST_ATTR_SAMP_FREQ_AVAIL( "0.09765625 0.1953125 0.390625 0.78125 1.5625 3.125 6.25 12.5 25 50 100 200 400 800 1600 3200" ); @@ -158,16 +186,6 @@ static const struct iio_info adxl345_info = { .write_raw_get_fmt = adxl345_write_raw_get_fmt, }; -static int adxl345_powerup(void *regmap) -{ - return regmap_write(regmap, ADXL345_REG_POWER_CTL, ADXL345_POWER_CTL_MEASURE); -} - -static void adxl345_powerdown(void *regmap) -{ - regmap_write(regmap, ADXL345_REG_POWER_CTL, ADXL345_POWER_CTL_STANDBY); -} - /** * adxl345_core_probe() - Probe and setup for the accelerometer. * @dev: Driver model representation of the device @@ -237,11 +255,11 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, regval, ADXL345_DEVID); /* Enable measurement mode */ - ret = adxl345_powerup(st->regmap); + ret = adxl345_set_measure_en(st, true); if (ret < 0) return dev_err_probe(dev, ret, "Failed to enable measurement mode\n"); - ret = devm_add_action_or_reset(dev, adxl345_powerdown, st->regmap); + ret = devm_add_action_or_reset(dev, adxl345_powerdown, st); if (ret < 0) return ret; From patchwork Fri Dec 13 21:19:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13907862 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B5031922CC; Fri, 13 Dec 2024 21:19:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734124763; cv=none; b=V/xCx+nit46jx9prOv40ss47oT9nVYl59q1VRp723AJK3ACaX7vj9V/udZMHw5Is5hVXqwv3kvH14QGrAGslpRCh/EUsDwGRBCwU3sosIYJNpaxpJNIscO4idGY8F3pB4arRg64MrZoD7flhtao+oTKRThnPMb0PJwxJCoteu2c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734124763; c=relaxed/simple; bh=NU4JbdrsQg87bOi61vUISeaVNwRoypO/AVKmenkMmFQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eVDfxpQh0NGrzZjcdDiW53JtTB3ND2q1pwedPiWjF7h7YOMMQYvpa8k5bowcdHI9L193ut5KAZXbuxKg2+zpLZZjTXORPWlOguTUoWn0l3T/Qcd1xynPm+uaCfrOvNG4FPqqvLrWxmsri3Pmpn6hVQCjHRITp7TcLCLufHn4MUo= 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=bg3mc8WP; arc=none smtp.client-ip=209.85.221.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bg3mc8WP" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-385db79aafbso174474f8f.1; Fri, 13 Dec 2024 13:19:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734124760; x=1734729560; 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=P2lr25cDx/YgeOG1ygYvcK0LTENnBnexDb7bSksAIok=; b=bg3mc8WPv0VNmRlv7aDXq7y0iWHUyxXETgMdWz5/DB7Wwm4Gf24QVu3hHM8e5DqHF0 i5Gqo585XPFw5yOxvLaKXNSqxnxdKFNDqoFl7wwAdPeEv4spf/5Mg4/vpiHT+fblGXz+ fHPfHw5Zl6OgnJ7bRmQ1gtt3Dp79vjqdqEBCuV37YHodpaui90JJcg2242DFPIfdgo9k aERK9nli1ZESmFiUW7ZQInsAQBjTaonTodaQV0EDHulWaITtZRzKdc/uO59g2i1hmCmf nnHbZfSZ4QFKbYALHKbIB8UqpkvaQiY8Y6Vlt4SZ4oenpTZWsmEtV37D6liPfHWBtUxV DgjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734124760; x=1734729560; 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=P2lr25cDx/YgeOG1ygYvcK0LTENnBnexDb7bSksAIok=; b=QdKmNSbSjQG8vfDksc2Y5isZvDdszeneYB3vfMBnayqDzbx5s7Zo7THh1gBWhnnjPr ke54yK/kCNBHuUw8H+1R6BSetQQHyAQJ6wFDIb8z8NO41k3pftbYamUi0G4Sd5uPr5Hc kAIiRCXuiWB17d0IvqDzIlHsTjdk8KQack7IkXnc4pYO0O/08s6irku5hjW/jyz9rQJp +5ro4Lf0hs2J0TiRZYH3PWVyimy9iY3mMv04KJJhr3JZJi1KuhfQWyZhF5maZzj8DKNE 4H34oMXwvOJ2VBQ1pwN+0dJzNh0NnorM60fTCXXLXw8fgZGohAnP7eDgV4XX5VMtnoHw /0rg== X-Forwarded-Encrypted: i=1; AJvYcCVoD8FhMHVrNnMnWdTMng+kIT3RVbwJaGtrQ9KwXaSENbW/bnelMPdXQkzGInAiRk7G1cIWzy8tw/M=@vger.kernel.org, AJvYcCXP9D2nmkJgf6yxfjZ/9gqEj73tLaTON4LS9SinSJMdMZ6hWRE60OG0A/mN1CT58HUvFQFkQ6F4zG/W9j5i@vger.kernel.org X-Gm-Message-State: AOJu0YxVtETalFlOr9bQLcMPxehZRDIEtr187jG6lhhbKwGvs3XOOmKS I//t5dgDoI7VzyFYPNdsr1cEJLzuhr87VobF060b+nEuUC5Wfwy5 X-Gm-Gg: ASbGnctBgqWizvZC8i8hbtteDCV4solAg/OI6hHoGSe9bsetuJMa+ozcNW57K4zbNxU as60SKL+KUK5EqhD39r05rTgGHaK5/i10VooziXzYBQCyjKl6wdADEePM6rkv28oyAqF8pOyA4W uI0+4M9yqRJPynJEpcUZg0oM+Wvxc/aimXTUb0INnfhcUAkAqkr//GcQVJGJM50jAk7pPqdF0je 4hPT7ERSXwMV8TJePyG6+N4wIXmJcDARt+Tzf3d97gyLhYI2Zhx7Uc5/d3I1Bp/66wA0nSXyreV q8TvR5B/NdnK/ZbugsE+VA8/3ojLPAl5X8Q= X-Google-Smtp-Source: AGHT+IEA0AQO4R1cUGDiXpbOqZYKUVQrghKYgZjET699HiuYI7NmxFhucYLLDcjImsQUnCC59Hq69Q== X-Received: by 2002:a05:600c:4f0b:b0:434:941c:9df2 with SMTP id 5b1f17b1804b1-4362aab44b3mr14042745e9.8.1734124759486; Fri, 13 Dec 2024 13:19:19 -0800 (PST) Received: from d9dabf0abd47.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-388c801acfdsm552484f8f.57.2024.12.13.13.19.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Dec 2024 13:19:19 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v7 2/7] dt-bindings: iio: accel: adxl345: make interrupts not a required property Date: Fri, 13 Dec 2024 21:19:04 +0000 Message-Id: <20241213211909.40896-3-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241213211909.40896-1-l.rubusch@gmail.com> References: <20241213211909.40896-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Remove interrupts from the list of required properties. The ADXL345 does not need interrupts for basic accelerometer functionality. The sensor offers optional events which can be indicated on one of two interrupt lines. Signed-off-by: Lothar Rubusch Acked-by: Krzysztof Kozlowski --- Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml b/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml index 280ed479e..bc46ed00f 100644 --- a/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml +++ b/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml @@ -40,7 +40,6 @@ properties: required: - compatible - reg - - interrupts allOf: - $ref: /schemas/spi/spi-peripheral-props.yaml# From patchwork Fri Dec 13 21:19:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13907863 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 3A458194AEE; Fri, 13 Dec 2024 21:19:23 +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=1734124764; cv=none; b=JgRcVSa2EIfxaxGTHbYTrKhLUGK3TFF6aBSozz1hfO1sYRbhE50YJfHOST0UP6qdfTCsGh76UQt85/uRSxQeyN6+k7FTQHyf1l7voeKdvPMjLLQlrYm8djiW1E2NlivRYaueBc0KfeidAnDr/nX4pknL002dX/VGEYJA4tUJ3fQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734124764; c=relaxed/simple; bh=VN1pT1soceWpBRL1Ff/Xu3C46TBaJ+7J7MPPx/IwKw8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ek6PnIuFfZFBxVRDtjtUNK+7qA16/p7EfpgRCI8AR3xkBBEMmLakyZ+XB1lj/c/uci3wid35X70gbkARSezZ3LTuP1ObRv8uETUMmEEuJyoZ9Httiz6ku7Oa0A1qpTqasCYgp2gLBma4a972VsGz1llZMXU9YTRpSYztkvRKUDY= 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=EKH1fXkh; 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="EKH1fXkh" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-436203f1203so2122115e9.2; Fri, 13 Dec 2024 13:19:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734124761; x=1734729561; 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=vdD/19e5UCPRHcpX6fbB0zxAQ1c/6JKAgU5L9Fu+S8A=; b=EKH1fXkhZ1y3P4wt6Z06sYSsaciGdIj+NpZV4y0hET6zOV7A+K5Gi9J+W2ia10VYpA 0lqs76BEdY7p510+Xiy/KLIxHs0vvfGKF8SLcp7Mx0q4GL8ZEX6WcVwy0ugh6tnQoOLJ eItEgvXTuzzgq2UkMCFkiZ0wuFP11pmfK9SEu+fBXxEFuWRvQdtOrHuNE5+58lqhAdv4 DO0nNixsg2h40viYGKCtQPvl0e6RRsffL2G3/5/9QB/rlBJShJzsqGw0/GEA8DrSEXGn 4f5ER0FLLna4vcFjETTnDLMrWcn7C2NuMSZzE9ofbutG8jp3ouO6GmCegs0BBQ91xWIc f3Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734124761; x=1734729561; 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=vdD/19e5UCPRHcpX6fbB0zxAQ1c/6JKAgU5L9Fu+S8A=; b=er/K6+yOH69nihqZgf5MESAH7WalV7FiZom9CV3PaOxULTuHkdTtg7GryQG13r3s9Q Ij3i6pumE4SGAj2iq0jrVtewdwsYc2+kG5117eUVL5UfKDBfZYsAeXJY+8FWQvHQ+9fM ANAnUVZzl3TG/zbAg5MN91LNRSvx6pj4pMv1GzY4S72tuvIasXXImIa1A0rTTrvaUCda QHSN1Vg0GK41VTIThO0+6NX/AjSL8FfXEXKZxYqytKX5rQlJoFSLy9KZN/n5KsEK12RA cSBBpuKAMfo8jIkEdgcxwZWL2Njtk4dSnI1MC/4/77hCdLjGoxN/jUHxbhHgpg8r9ybC eSaQ== X-Forwarded-Encrypted: i=1; AJvYcCVd01jNTvRKBmeH4DKs6iYauSvQNMsSXyatESwXTm2bvff4YaCuy37SSxj+HcoOXvea28qxVB81bnI+CIKR@vger.kernel.org, AJvYcCX4TmBnborZp+FfmnE4UUdCyXWwPbBZDJYNtvcvT8Y1ekBjw2OGOy2sS2cGmWp1QrrqCtZ0xlFioq0=@vger.kernel.org X-Gm-Message-State: AOJu0Yz64Eb1IfVxIYN7rKcWYHkxAdOu6DVCMXf390f1taQl/yDXS51J sP7G6esQ+PxChQasvT7FYVGlOXCqfde1JNurPbCtR42qVuqojnvS X-Gm-Gg: ASbGnctS790F3hqgzQXJKtY7d6b7LRFbPsyh+v7qi+EIybmcyoBm00DbEOCbxZIqT0d IPtky6l0JifWLgvY3OLeTQhHg/mHQeNuRZ9/38Q5WO12cG1ZFucDNw/JGgJjg2dZOcr38YHz75E XWMKPMkGpqt0fScgNiqccWIVVBzggX5B4z5hEXw19lDU3w7CrVeaPm9zSR6Ts1UCSJwsfagsawe eJw5C3cgXlsv346AJkrYajYWT3ny1BHb11+Fnpb0IZIXmRfPUS/sAOmWtKvi3bqQk63FvIOOSyM Yw1Od7kccb2hs3kTvGtO/3QQx/U/VB0PkKk= X-Google-Smtp-Source: AGHT+IF0bko2WOIywFKeHNWnHmJRPLjjE7KSWwBu0xE4s5zDpafSbkJ9DMrewmjaXpkxGsDTsybY1Q== X-Received: by 2002:a05:600c:35c6:b0:434:a30b:5433 with SMTP id 5b1f17b1804b1-4362aa9f021mr13815045e9.5.1734124761315; Fri, 13 Dec 2024 13:19:21 -0800 (PST) Received: from d9dabf0abd47.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-388c801acfdsm552484f8f.57.2024.12.13.13.19.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Dec 2024 13:19:20 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v7 3/7] dt-bindings: iio: accel: adxl345: add interrupt-names Date: Fri, 13 Dec 2024 21:19:05 +0000 Message-Id: <20241213211909.40896-4-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241213211909.40896-1-l.rubusch@gmail.com> References: <20241213211909.40896-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add interrupt-names INT1 and INT2 for the two interrupt lines of the sensor. When one of the two interrupt lines is connected, the interrupt as its interrupt-name, need to be declared in the devicetree. The driver then configures the sensor to indicate its events on either INT1 or INT2. If no interrupt is configured, then no interrupt-name should be configured, and vice versa. In this case the sensor runs in FIFO BYPASS mode. This allows sensor measurements, but none of the sensor events. Signed-off-by: Lothar Rubusch --- .../devicetree/bindings/iio/accel/adi,adxl345.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml b/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml index bc46ed00f..4f971035b 100644 --- a/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml +++ b/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml @@ -37,6 +37,14 @@ properties: interrupts: maxItems: 1 + interrupt-names: + items: + - enum: [INT1, INT2] + +dependencies: + interrupts: [ 'interrupt-names' ] + interrupt-names: [ 'interrupts' ] + required: - compatible - reg @@ -60,6 +68,7 @@ examples: reg = <0x2a>; interrupt-parent = <&gpio0>; interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "INT1"; }; }; - | @@ -78,5 +87,6 @@ examples: spi-cpha; interrupt-parent = <&gpio0>; interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "INT2"; }; }; From patchwork Fri Dec 13 21:19:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13907864 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47547198A32; Fri, 13 Dec 2024 21:19:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734124765; cv=none; b=L/K4npcU390sEz7qjjKonOodzhQsNVJT70bCaSLIPJwVwMeDagv2rEZNfXdEp6FvxQQgoMl7VHFAycqwJo/TtixRVdekkQw4AUhnd8wb4msOKnanBO1Sym07zCa0oxxUeGpI3o6Q6q4SmnsNV8NmAMfyKrMDfOxcdbzSYqtCg+A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734124765; c=relaxed/simple; bh=OnEi/NtWpRQrR4crDgkQmPpkIr60sP3pUIwvNBRDZyI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YZCzg5Q02+7FHdM85g4apXa0iHvq+ZfSXP7dS9Xuk9hGifNdJki3QY7RZ0PWFqOIyc6oVAjMxEwdOtk4VwaKNCX0BNEPAd2B4JdZl5c+AZ7I6FSreSlNjDzzDGIYHmt/MKY6szHmjPFqectXpPhEY9JUu8h7am+2+rqbd0TcTjg= 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=I93g6yBK; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="I93g6yBK" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4361aa6e517so2487995e9.2; Fri, 13 Dec 2024 13:19:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734124762; x=1734729562; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JWLUOvAYC/+QKYOvlVecoPGtDiIOOdHySdnie/FYzsE=; b=I93g6yBKg8fmsa/HB22YfQCo8WNETL3qgq+DSPzje1DpBUIbSHvGLxnsdypfZ/pGJq Kwjsnm8Bye8/vcXvrXVR4Oxd3MYNm8wGqD1FBlFlC4yuCqB/NK2/Hm3+gcVVynw2efch phGAyrTh93+4VuJYD6Ro+t/5AonLRRZraSyRpnbsPhkhn2DfEPH4LphJYR/5SyMc6xLs puWdwBtFSbHdOmBnm3cg83/b4UWMlzMrbPM/y3CG61xB17c28BQZlsGk46tVC7ztM6ij O+ZRuqd5lgMZUaXmEEdYZQPiO9n11NuFsT2oBc36TYtVyxI8hSll7XNneezhZzARXx4d ojow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734124762; x=1734729562; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JWLUOvAYC/+QKYOvlVecoPGtDiIOOdHySdnie/FYzsE=; b=OUSlcXOVZWiT30sJlklm+hAzlxcTO5L6Apr7PNLydbjSzSZmERQ2i8eO4YFXcbM8+i ggg/3qfscIAbPqCZIieeHSQlg+6qtZYjl4UY7vAQ6hPRNITdeKbNHG7sf4X0vaSWwPY0 JOYytGoL1FZR5sA1DYuyQ9MMByFXs9mkEyXcPgRf0mekkoM+aSS1ZRwUfm3KAkj+QlHz DVgnKoKFi7ZKSphNSzfK0OxhELlcOa3R0pTy0wsFPcyAr8cXJj5ZIGscwi22O1QSutI5 D4OOAEzssexZkszoREgJDpYsaTHbZj7WhgZPEgOX/ZWv0c7knHxmlPGGUJIKWEfyzO6u xVoA== X-Forwarded-Encrypted: i=1; AJvYcCVQ9b4uf5hcXXzqvZM1JNmMoPba/Zvk5QtBFEAIrQSL5wGH3UbuqP4OvMz+ZTJ0FDnT8Okv7vmQ3U1D6paS@vger.kernel.org, AJvYcCXKv2QuYa8my11/WXf7L4TrvxnoH4/9GabXQI8ymHkQCwHOEVljfaHxXKf+C4S/d+wxuwnZdh65EuE=@vger.kernel.org X-Gm-Message-State: AOJu0YwVktupCm9c36KPqDQ2T/W/3Ih6rVXYVPu+6xYYNB9jW1CIxb/g kriMudZ2y9Wep7fSEd+yy3KGqMyUtnYXGqGeFFpFJ6updYJfTdGh X-Gm-Gg: ASbGncs6m5HVE41kdO8OTxT3vLX4/qn+DF7Kt1uYm8NuXzJRjP6Tk+dg3N/LBMBvCcZ v45jk1s19H7/5Puy86+w56Ecnh0evNwXLd1dZMeRgsI911i8YCQ9opvp0radoC6fPWdhFxIAfBl MjYGEwXhLlW6cwz2e30fIpVnLWmbSs5yoXSck88PlsHnDa2UpIIBRRAT1X89uWnm0VS649UvERQ SRmwodKD7m6LgJdBQ2wOJjMsmEZRqSTt5LVrsGixNwhIdW+fbaqZfbUnJM458uOmu2RKZ+x0VDd VTyLE85VrzfO7P41axIktKyLcbCYqUkTL80= X-Google-Smtp-Source: AGHT+IEaB8ELntB6TFtQtjeN4DzEyRiil0MGC4A8CGZ6SVnONMmopDnvD9kZVWRZ+WHmSWxnK2hZDQ== X-Received: by 2002:a5d:6d09:0:b0:385:df17:214f with SMTP id ffacd0b85a97d-3888e0f4580mr1234953f8f.9.1734124762342; Fri, 13 Dec 2024 13:19:22 -0800 (PST) Received: from d9dabf0abd47.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-388c801acfdsm552484f8f.57.2024.12.13.13.19.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Dec 2024 13:19:22 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v7 4/7] iio: accel: adxl345: introduce interrupt handling Date: Fri, 13 Dec 2024 21:19:06 +0000 Message-Id: <20241213211909.40896-5-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241213211909.40896-1-l.rubusch@gmail.com> References: <20241213211909.40896-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add the possibility to claim an interrupt. Init the state structure with an interrupt line obtained from the DT. The adxl345 can use two different interrupt lines for event handling. Only one is used. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index b48bc838c..fb3b45d99 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -11,15 +11,22 @@ #include #include #include +#include #include #include #include "adxl345.h" +#define ADXL345_INT_NONE 0xff +#define ADXL345_INT1 0 +#define ADXL345_INT2 1 + struct adxl345_state { + int irq; const struct adxl345_chip_info *info; struct regmap *regmap; + u8 intio; }; #define ADXL345_CHANNEL(index, axis) { \ @@ -213,6 +220,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, st = iio_priv(indio_dev); st->regmap = regmap; + st->info = device_get_match_data(dev); if (!st->info) return -ENODEV; @@ -263,6 +271,15 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, if (ret < 0) return ret; + st->intio = ADXL345_INT1; + st->irq = fwnode_irq_get_byname(dev_fwnode(dev), "INT1"); + if (st->irq < 0) { + st->intio = ADXL345_INT2; + st->irq = fwnode_irq_get_byname(dev_fwnode(dev), "INT2"); + if (st->irq < 0) + st->intio = ADXL345_INT_NONE; + } + return devm_iio_device_register(dev, indio_dev); } EXPORT_SYMBOL_NS_GPL(adxl345_core_probe, IIO_ADXL345); From patchwork Fri Dec 13 21:19:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13907865 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56EB01A256C; Fri, 13 Dec 2024 21:19:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734124767; cv=none; b=pWb0ODjTuttWP8RNfUKGjOP5TODR/PGhXchaHA2WBNMryxjwUW8NRwTE0aOh+HltxypHH4zmwxykscGQqZtP8ab7hllWWiOfTOCdCVvdpBWrU/orExDjSCNCVCamN9LTw3JRT4RAMVdxC9iQp4rhAoEaueL0kby1TC4Tg/Xv0uc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734124767; c=relaxed/simple; bh=j5DGeUfnb4uyusC39IXORvfxvwnQUHOflIxNU4SSH1g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PSY3aSXqlW+LiLAic+s8zeI5gGDzbpQ5U8D9CaSmTEcxX7a9F1IZkNYl20OywtRjYAgQy7nRyYHaqWnWMrmbNo/nVfgYwyy3XIi7YnGd8r8VJwRrprWmguwhcOmOR8L3AA5TYEoZLX1CG7S6nWmZ3ThIzpRWgGyy9uhw8SY72EE= 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=jbZyMkJt; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jbZyMkJt" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-385e44a1a2dso226977f8f.3; Fri, 13 Dec 2024 13:19:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734124763; x=1734729563; 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=kTNf16r333zqsw4HO/Fw7K3fX8m4wdYfwIGp1t2rbUQ=; b=jbZyMkJteJiJxkKeK3p2k/cJbhtoPd06LTA3pIRMMsm5RgUyqZSYDTwo1EnQEqUhk8 8nU78N7D89xWiMTi9M+1nC9D0cfYwjUnpznmmplOR+M9HFPZ2UhGiRaBkb8FWBaNZCSv ZMcu17e2Dr8Y8SxRKumLA4AMd6TRmUlVAMxBb7+JRPCDPr3YJxWIm5b/Xc7ZZh210p0j WPA6QzQbz+tFiRXyvA641WfSlC2D1OUEaPq+ovD0VVOyPC58kxQ2JGORB2PtWSou9+yx WMnNIhxVt59DEye3rDTpPMBl9ciq1iDdsNiREB100sMNMLurdtD8mUJxjCYGJoDT4Uu+ htFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734124763; x=1734729563; 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=kTNf16r333zqsw4HO/Fw7K3fX8m4wdYfwIGp1t2rbUQ=; b=HxmJFKp+7lA4dLiXrjbCadaHe4sO2ZVU0FNcMhBO6+JdIJeK7alnYJB8D4shdaFujG 9TfQybewVW/lGTbffRVmgF3JsfS6Otyg517oKDYkxceSykFZtr3w1Ux8idrn8eH7tJvr ajcsqS0xjAJmUXMmgFS+8S8ICNShr0fA3xIgrfRMflBRCDepKzcqWm3iB0/B7GYCam3A /alX0apEfB4juvnW1J9P91KucgjO4sbDUwXDtGJcsh0J+G86LMz2c8D99hkVkX+NZXK8 h3WRHm+HXzGfRt5+hSQthsa56zZ5KxruakxTcLPCYLHxT4utdzYp6HBjW5ESQOZQ9ESI qQ+g== X-Forwarded-Encrypted: i=1; AJvYcCUP6NSMpPBVh/goni5LJAZtwsLUTy6vZI5/H/1kSTaRo7KzF46OATdVIp0jRkOirZRZdW1gl6WNd4o=@vger.kernel.org, AJvYcCVk6h7k165j3hWMAL1dc7U9wrIIiHsyoKJnxRm7sy9yCyDp9Mt4dusEA3aYpTUrhgnpfAK2aIWOXYlrDMqO@vger.kernel.org X-Gm-Message-State: AOJu0YyGVw7k30gvtfmv4Fgk/wSCfScSQmhar4bjJ39kAMYOqpFhwXr6 NVW46QPZpc1Vq2jCPpoM4EBgq9sLph1fiAkilsVuQhS2F5UcwvU5 X-Gm-Gg: ASbGncs5JNMT5KpNpq5wWAUTsxuxrzLG7bbGCS+KLTzURSfuy6CZtOTQya/7InL9wx+ sHozX2QyTtWyDsznyuPm7PNEPY7AEkSHiHx9mkaLTWOIZhT8jSfkyZs/psotkrbUHWKhSAU0cXB ZOVgZagMWIwuuFCpSOR9NTPWJ8e7wXOBuQGSjCauVjoRuMp3ENBeT6gkayXd1fmqRqtRpqJdNXv P6F5Ok6NCCv5/VfRtpO0wfYTR822YtTcd1r+9eX/jnvcDP7Z0OyDydJSxnQtG7bVEua2hdilZZu wl+fL7RPoV+BRGCCkhqGy+HlrNUsS2qos60= X-Google-Smtp-Source: AGHT+IEBDnbOwxQdPvaxvSQchaiU9PLHKL7smE29ee/gA4RxFYYhBFP70McK7tuJQwVUvDg+ZWTGvg== X-Received: by 2002:a05:6000:799:b0:386:3213:5b78 with SMTP id ffacd0b85a97d-38880ac18cbmr1260180f8f.3.1734124763434; Fri, 13 Dec 2024 13:19:23 -0800 (PST) Received: from d9dabf0abd47.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-388c801acfdsm552484f8f.57.2024.12.13.13.19.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Dec 2024 13:19:23 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v7 5/7] iio: accel: adxl345: initialize FIFO delay value for SPI Date: Fri, 13 Dec 2024 21:19:07 +0000 Message-Id: <20241213211909.40896-6-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241213211909.40896-1-l.rubusch@gmail.com> References: <20241213211909.40896-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add the possibility to delay FIFO access when SPI is used. According to the datasheet this is needed for the adxl345. When initialization happens over SPI the need for delay is to be signalized, and the delay will be used. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345.h | 1 + drivers/iio/accel/adxl345_core.c | 12 ++++++++++++ drivers/iio/accel/adxl345_i2c.c | 2 +- drivers/iio/accel/adxl345_spi.c | 7 +++++-- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/iio/accel/adxl345.h b/drivers/iio/accel/adxl345.h index 3d5c8719d..6f39f16d3 100644 --- a/drivers/iio/accel/adxl345.h +++ b/drivers/iio/accel/adxl345.h @@ -62,6 +62,7 @@ struct adxl345_chip_info { }; int adxl345_core_probe(struct device *dev, struct regmap *regmap, + bool fifo_delay_default, int (*setup)(struct device*, struct regmap*)); #endif /* _ADXL345_H_ */ diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index fb3b45d99..fc4f89f22 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -26,6 +26,7 @@ struct adxl345_state { int irq; const struct adxl345_chip_info *info; struct regmap *regmap; + bool fifo_delay; /* delay: delay is needed for SPI */ u8 intio; }; @@ -197,12 +198,21 @@ static const struct iio_info adxl345_info = { * adxl345_core_probe() - Probe and setup for the accelerometer. * @dev: Driver model representation of the device * @regmap: Regmap instance for the device + * @fifo_delay_default: Using FIFO with SPI needs delay * @setup: Setup routine to be executed right before the standard device * setup * + * For SPI operation greater than 1.6 MHz, it is necessary to deassert the CS + * pin to ensure a total delay of 5 us; otherwise, the delay is not sufficient. + * The total delay necessary for 5 MHz operation is at most 3.4 us. This is not + * a concern when using I2C mode because the communication rate is low enough + * to ensure a sufficient delay between FIFO reads. + * Ref: "Retrieving Data from FIFO", p. 21 of 36, Data Sheet ADXL345 Rev. G + * * Return: 0 on success, negative errno on error */ int adxl345_core_probe(struct device *dev, struct regmap *regmap, + bool fifo_delay_default, int (*setup)(struct device*, struct regmap*)) { struct adxl345_state *st; @@ -225,6 +235,8 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, if (!st->info) return -ENODEV; + st->fifo_delay = fifo_delay_default; + indio_dev->name = st->info->name; indio_dev->info = &adxl345_info; indio_dev->modes = INDIO_DIRECT_MODE; diff --git a/drivers/iio/accel/adxl345_i2c.c b/drivers/iio/accel/adxl345_i2c.c index 4065b8f7c..28d997c58 100644 --- a/drivers/iio/accel/adxl345_i2c.c +++ b/drivers/iio/accel/adxl345_i2c.c @@ -27,7 +27,7 @@ static int adxl345_i2c_probe(struct i2c_client *client) if (IS_ERR(regmap)) return dev_err_probe(&client->dev, PTR_ERR(regmap), "Error initializing regmap\n"); - return adxl345_core_probe(&client->dev, regmap, NULL); + return adxl345_core_probe(&client->dev, regmap, false, NULL); } static const struct adxl345_chip_info adxl345_i2c_info = { diff --git a/drivers/iio/accel/adxl345_spi.c b/drivers/iio/accel/adxl345_spi.c index 61fd9a6f5..e03915ece 100644 --- a/drivers/iio/accel/adxl345_spi.c +++ b/drivers/iio/accel/adxl345_spi.c @@ -12,6 +12,7 @@ #include "adxl345.h" #define ADXL345_MAX_SPI_FREQ_HZ 5000000 +#define ADXL345_MAX_FREQ_NO_FIFO_DELAY 1500000 static const struct regmap_config adxl345_spi_regmap_config = { .reg_bits = 8, @@ -28,6 +29,7 @@ static int adxl345_spi_setup(struct device *dev, struct regmap *regmap) static int adxl345_spi_probe(struct spi_device *spi) { struct regmap *regmap; + bool needs_delay; /* Bail out if max_speed_hz exceeds 5 MHz */ if (spi->max_speed_hz > ADXL345_MAX_SPI_FREQ_HZ) @@ -38,10 +40,11 @@ static int adxl345_spi_probe(struct spi_device *spi) if (IS_ERR(regmap)) return dev_err_probe(&spi->dev, PTR_ERR(regmap), "Error initializing regmap\n"); + needs_delay = spi->max_speed_hz > ADXL345_MAX_FREQ_NO_FIFO_DELAY; if (spi->mode & SPI_3WIRE) - return adxl345_core_probe(&spi->dev, regmap, adxl345_spi_setup); + return adxl345_core_probe(&spi->dev, regmap, needs_delay, adxl345_spi_setup); else - return adxl345_core_probe(&spi->dev, regmap, NULL); + return adxl345_core_probe(&spi->dev, regmap, needs_delay, NULL); } static const struct adxl345_chip_info adxl345_spi_info = { From patchwork Fri Dec 13 21:19:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13907866 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 365DE1A9B5D; Fri, 13 Dec 2024 21:19:27 +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=1734124769; cv=none; b=qTFb5CSbOIuxt/etmNrnmYGuVyyYj7oYMFv3LM8uiSQ7cc9PJupoxP/Qbo7x+3dQ6SteliUySn5nto70pgY4J4YplNs1sdKfTLEATCoq2wukzaVVhraasVUCoNSwpuqE965IXYH7MF3OnPh6R5Ne4SMn3L6tbjVixc1XQI7n0VI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734124769; c=relaxed/simple; bh=rqxanvAwt5GjmMDQHIo1PiGibGwZLos7u8UdcuKi60Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Brf6juG81uGa7sHodVe7oo0axzU83AyAVK93en5w/ZnlOD0lmPMtwlsXabE/EPJgfeVeohloO/Amn70SfAeQKSnUr6EKWji6NxFWCraXYbcXL8ZHYiF4nY+4do3auvaOnFKQW/so0rigwpIHJlKNy7CE3ihAKSGjYiUcjoDElw0= 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=KS8iZFq8; 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="KS8iZFq8" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-3862e570832so239684f8f.0; Fri, 13 Dec 2024 13:19:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734124765; x=1734729565; 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=td5opudK4E//6f8GciLiEGMyM4CWMS13OyWPAT8pU9s=; b=KS8iZFq8AOMfrw/lqvUoXqhuHvnfh3KSjXNmuhUvmBUW7xkui1jYVPZyiz5wgFpnM8 1uPLBDeABXVzOtsH8DSfko0An2+CryFxtL6F1mKfKkIL5VufLaijGQ5MwQnhTmOgrAV9 8r5+a0yZkNRPlC8j+jHuaz9Wg9P+SQac/tWqElyR8VbBFlLHMu7kRStEcoxA1fJGFyP1 axkRjcmzKs3IyTdOAATATY3oI+bWtgN1PcyRNgNSwdwgEnqarRMO/aT5i708lsslSCfw y6wijBN4JPVK9wfniMX2SddB4i208LSpkOeyJLRTi4KZxOdHLfmTAmzdWsnuAki+9T0t nuKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734124765; x=1734729565; 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=td5opudK4E//6f8GciLiEGMyM4CWMS13OyWPAT8pU9s=; b=XCsk3kDn2J1mt/UMBpwrb2sDliSamXvo4U4oxpNQvOGiA+fgR2/yVRltTGDmQLfXpI jFA2OVmIcU6/iu5yCk7RaGAUIDFUggkZnKnRe+mytJwBj2ETVblNq1fCkBMGbOjqBEAt arsOuCQdRZCkuqm5OipneWXLqML5c6DAASRY1NTbRI7mm2vN3Ar0JJiVtHfofdK+Sax6 fioTM0PB1+KEWqyU+4Uhda0L7hTIG9wDs0rrN0KfRgwcpB1rFopVYhhK76x+T6VcCOvs FpeGqdOg07miN5hX1jNd/83c2J0H5riYpzmQGVQUofhVb3+3Owj2ulexOB4kFgQkvZhu BdNQ== X-Forwarded-Encrypted: i=1; AJvYcCVGpwU4M1cktv4oQf4lzmkBERuwHyPMZpOschHVDW8NGVJnW3pYWSVq318k9KBPh2OlDaRzAfnvZqNc5+qf@vger.kernel.org, AJvYcCWTnaV27eWausQLp5ra19dAaUlZ2d5xz/YPUE/lpOQHdyp/5c/HZ3vxLC4hjPsDiCQpW6tdqMgcies=@vger.kernel.org X-Gm-Message-State: AOJu0Yy6DgIjiB35rKLE79DamwtgWJnOlQ6zFXBeV9Eof5xvwEUgIq3C nMRLVl2YQcXk0VfhI4woMkwVNEXmRcYBWMQMrxDwEmOmiQVntjWO X-Gm-Gg: ASbGncssPwWfVijQp4HdxcxVGLVyjurfCiakNqFvmFl/w7Ni4CpdQ87jO5sPvGj1yai y4Qb5PjSEZLSra9pVmmd4aa9wpbeNTzehNp5iPIRjHx5Y6/jFKT+MyODDdiZ+5bLb6k+x5MgLkO s2C16i81ahWXox4MA7pwmVKyyUR5ZJ0XymVlU343bakVckqiaD+i46yBEZS0cUVSwXOiL3ilJ4Q aye+rbdUwkZIJsWlxxXCnufd4bo/DqLkenjuTFDjUbEaIRL/0qa/f9SLtZFvCNrTSTT5fH15oUO 9yUpyWdhH2j8UnzZ/cNJl/vGTidXZ4nzDpY= X-Google-Smtp-Source: AGHT+IGMTAbZJJpWfnE/VoCWGodZwxCWeQxs6nCSFLAt5X64lIsGc2w8kpVwPfa+JAvL83xRuB1s8g== X-Received: by 2002:a5d:6da6:0:b0:385:e10a:4d98 with SMTP id ffacd0b85a97d-38880ada7c6mr1501605f8f.8.1734124765284; Fri, 13 Dec 2024 13:19:25 -0800 (PST) Received: from d9dabf0abd47.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-388c801acfdsm552484f8f.57.2024.12.13.13.19.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Dec 2024 13:19:24 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v7 6/7] iio: accel: adxl345: add FIFO with watermark events Date: Fri, 13 Dec 2024 21:19:08 +0000 Message-Id: <20241213211909.40896-7-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241213211909.40896-1-l.rubusch@gmail.com> References: <20241213211909.40896-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add a basic setup for FIFO with configurable watermark. Add a handler for watermark interrupt events and extend the channel for the scan_index needed for the iio channel. The sensor is configurable to use a FIFO_BYPASSED mode or a FIFO_STREAM mode. For the FIFO_STREAM mode now a watermark can be configured, or disabled by setting 0. Further features require a working FIFO setup. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345.h | 27 ++- drivers/iio/accel/adxl345_core.c | 308 ++++++++++++++++++++++++++++++- 2 files changed, 324 insertions(+), 11 deletions(-) diff --git a/drivers/iio/accel/adxl345.h b/drivers/iio/accel/adxl345.h index 6f39f16d3..bf9e86cff 100644 --- a/drivers/iio/accel/adxl345.h +++ b/drivers/iio/accel/adxl345.h @@ -15,18 +15,32 @@ #define ADXL345_REG_OFS_AXIS(index) (ADXL345_REG_OFSX + (index)) #define ADXL345_REG_BW_RATE 0x2C #define ADXL345_REG_POWER_CTL 0x2D +#define ADXL345_REG_INT_ENABLE 0x2E +#define ADXL345_REG_INT_MAP 0x2F +#define ADXL345_REG_INT_SOURCE 0x30 +#define ADXL345_REG_INT_SOURCE_MSK 0xFF #define ADXL345_REG_DATA_FORMAT 0x31 -#define ADXL345_REG_DATAX0 0x32 -#define ADXL345_REG_DATAY0 0x34 -#define ADXL345_REG_DATAZ0 0x36 -#define ADXL345_REG_DATA_AXIS(index) \ - (ADXL345_REG_DATAX0 + (index) * sizeof(__le16)) +#define ADXL345_REG_XYZ_BASE 0x32 +#define ADXL345_REG_DATA_AXIS(index) \ + (ADXL345_REG_XYZ_BASE + (index) * sizeof(__le16)) +#define ADXL345_REG_FIFO_CTL 0x38 +#define ADXL345_REG_FIFO_STATUS 0x39 +#define ADXL345_REG_FIFO_STATUS_MSK 0x3F + +#define ADXL345_FIFO_CTL_SAMPLES(x) FIELD_PREP(GENMASK(4, 0), x) +/* 0: INT1, 1: INT2 */ +#define ADXL345_FIFO_CTL_TRIGGER(x) FIELD_PREP(BIT(5), x) +#define ADXL345_FIFO_CTL_MODE(x) FIELD_PREP(GENMASK(7, 6), x) + +#define ADXL345_INT_DATA_READY BIT(7) +#define ADXL345_INT_WATERMARK BIT(1) +#define ADXL345_INT_OVERRUN BIT(0) #define ADXL345_BW_RATE GENMASK(3, 0) #define ADXL345_BASE_RATE_NANO_HZ 97656250LL -#define ADXL345_POWER_CTL_MEASURE BIT(3) #define ADXL345_POWER_CTL_STANDBY 0x00 +#define ADXL345_POWER_CTL_MEASURE BIT(3) #define ADXL345_DATA_FORMAT_RANGE GENMASK(1, 0) /* Set the g range */ #define ADXL345_DATA_FORMAT_JUSTIFY BIT(2) /* Left-justified (MSB) mode */ @@ -40,6 +54,7 @@ #define ADXL345_DATA_FORMAT_16G 3 #define ADXL345_DEVID 0xE5 +#define ADXL345_FIFO_SIZE 32 /* * In full-resolution mode, scale factor is maintained at ~4 mg/LSB diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index fc4f89f22..e31a7cb3f 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -15,9 +15,17 @@ #include #include +#include +#include #include "adxl345.h" +#define ADXL345_FIFO_BYPASS 0 +#define ADXL345_FIFO_FIFO 1 +#define ADXL345_FIFO_STREAM 2 + +#define ADXL345_DIRS 3 + #define ADXL345_INT_NONE 0xff #define ADXL345_INT1 0 #define ADXL345_INT2 1 @@ -26,27 +34,68 @@ struct adxl345_state { int irq; const struct adxl345_chip_info *info; struct regmap *regmap; + __le16 fifo_buf[ADXL345_DIRS * ADXL345_FIFO_SIZE + 1]; bool fifo_delay; /* delay: delay is needed for SPI */ u8 intio; + u8 int_map; + u8 watermark; + u8 fifo_mode; }; -#define ADXL345_CHANNEL(index, axis) { \ +#define ADXL345_CHANNEL(index, reg, axis) { \ .type = IIO_ACCEL, \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \ - .address = index, \ + .address = (reg), \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ BIT(IIO_CHAN_INFO_CALIBBIAS), \ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .scan_index = (index), \ + .scan_type = { \ + .sign = 's', \ + .realbits = 13, \ + .storagebits = 16, \ + .endianness = IIO_LE, \ + }, \ } +enum adxl345_chans { + chan_x, chan_y, chan_z, +}; + static const struct iio_chan_spec adxl345_channels[] = { - ADXL345_CHANNEL(0, X), - ADXL345_CHANNEL(1, Y), - ADXL345_CHANNEL(2, Z), + ADXL345_CHANNEL(0, chan_x, X), + ADXL345_CHANNEL(1, chan_y, Y), + ADXL345_CHANNEL(2, chan_z, Z), }; +static const unsigned long adxl345_scan_masks[] = { + BIT(chan_x) | BIT(chan_y) | BIT(chan_z), + 0, +}; + +static int adxl345_set_interrupts(struct adxl345_state *st) +{ + int ret; + unsigned int int_enable = st->int_map; + unsigned int int_map; + + /* + * Any bits set to 0 in the INT map register send their respective + * interrupts to the INT1 pin, whereas bits set to 1 send their respective + * interrupts to the INT2 pin. The intio shall convert this accordingly. + */ + int_map = FIELD_GET(ADXL345_REG_INT_SOURCE_MSK, + st->intio ? st->int_map : ~st->int_map); + + ret = regmap_write(st->regmap, ADXL345_REG_INT_MAP, int_map); + if (ret) + return ret; + + return regmap_write(st->regmap, ADXL345_REG_INT_ENABLE, int_enable); +} + static int adxl345_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) @@ -132,6 +181,25 @@ static int adxl345_write_raw(struct iio_dev *indio_dev, return -EINVAL; } +static int adxl345_set_watermark(struct iio_dev *indio_dev, unsigned int value) +{ + struct adxl345_state *st = iio_priv(indio_dev); + unsigned int fifo_mask = 0x1F; + int ret; + + if (value > ADXL345_FIFO_SIZE) + value = ADXL345_FIFO_SIZE - 1; + + ret = regmap_update_bits(st->regmap, ADXL345_REG_FIFO_CTL, fifo_mask, value); + if (ret) + return ret; + + st->watermark = value; + st->int_map |= ADXL345_INT_WATERMARK; + + return 0; +} + static int adxl345_write_raw_get_fmt(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, long mask) @@ -187,11 +255,220 @@ static const struct attribute_group adxl345_attrs_group = { .attrs = adxl345_attrs, }; +static int adxl345_set_fifo(struct adxl345_state *st) +{ + u8 fifo_ctl; + int ret; + + /* FIFO should only be configured while in standby mode */ + ret = adxl345_set_measure_en(st, false); + if (ret < 0) + return ret; + + fifo_ctl = ADXL345_FIFO_CTL_SAMPLES(st->watermark) | + ADXL345_FIFO_CTL_TRIGGER(st->intio) | + ADXL345_FIFO_CTL_MODE(st->fifo_mode); + + ret = regmap_write(st->regmap, ADXL345_REG_FIFO_CTL, fifo_ctl); + if (ret < 0) + return ret; + + return adxl345_set_measure_en(st, true); +} + +/** + * adxl345_get_samples() - Read number of FIFO entries. + * @st: The initialized state instance of this driver. + * + * The sensor does not support treating any axis individually, or exclude them + * from measuring. + * + * Return: negative error, or value. + */ +static int adxl345_get_samples(struct adxl345_state *st) +{ + unsigned int regval = 0; + int ret; + + ret = regmap_read(st->regmap, ADXL345_REG_FIFO_STATUS, ®val); + if (ret < 0) + return ret; + + return FIELD_GET(ADXL345_REG_FIFO_STATUS_MSK, regval); +} + +/** + * adxl345_fifo_transfer() - Read samples number of elements. + * @st: The instance of the state object of this sensor. + * @samples: The number of lines in the FIFO referred to as fifo_entry. + * + * It is recommended that a multiple-byte read of all registers be performed to + * prevent a change in data between reads of sequential registers. That is to + * read out the data registers X0, X1, Y0, Y1, Z0, Z1, i.e. 6 bytes at once. + * + * Return: 0 or error value. + */ +static int adxl345_fifo_transfer(struct adxl345_state *st, int samples) +{ + size_t count; + int i, ret = 0; + + /* count is the 3x the fifo_buf element size, hence 6B */ + count = sizeof(st->fifo_buf[0]) * ADXL345_DIRS; + for (i = 0; i < samples; i++) { + /* read 3x 2 byte elements from base address into next fifo_buf position */ + ret = regmap_bulk_read(st->regmap, ADXL345_REG_XYZ_BASE, + st->fifo_buf + (i * count / 2), count); + if (ret < 0) + return ret; + + /* + * To ensure that the FIFO has completely popped, there must be at least 5 + * us between the end of reading the data registers, signified by the + * transition to register 0x38 from 0x37 or the CS pin going high, and the + * start of new reads of the FIFO or reading the FIFO_STATUS register. For + * SPI operation at 1.5 MHz or lower, the register addressing portion of the + * transmission is sufficient delay to ensure the FIFO has completely + * popped. It is necessary for SPI operation greater than 1.5 MHz to + * de-assert the CS pin to ensure a total of 5 us, which is at most 3.4 us + * at 5 MHz operation. + */ + if (st->fifo_delay && (samples > 1)) + udelay(3); + } + return ret; +} + +/** + * adxl345_fifo_reset() - Empty the FIFO in error condition. + * @st: The instance to the state object of the sensor. + * + * Read all elements of the FIFO. Reading the interrupt source register + * resets the sensor. + */ +static void adxl345_fifo_reset(struct adxl345_state *st) +{ + int regval; + int samples; + + adxl345_set_measure_en(st, false); + + samples = adxl345_get_samples(st); + if (samples > 0) + adxl345_fifo_transfer(st, samples); + + regmap_read(st->regmap, ADXL345_REG_INT_SOURCE, ®val); + + adxl345_set_measure_en(st, true); +} + +static int adxl345_buffer_postenable(struct iio_dev *indio_dev) +{ + struct adxl345_state *st = iio_priv(indio_dev); + int ret; + + ret = adxl345_set_interrupts(st); + if (ret < 0) + return ret; + + st->fifo_mode = ADXL345_FIFO_STREAM; + return adxl345_set_fifo(st); +} + +static int adxl345_buffer_predisable(struct iio_dev *indio_dev) +{ + struct adxl345_state *st = iio_priv(indio_dev); + int ret; + + st->fifo_mode = ADXL345_FIFO_BYPASS; + ret = adxl345_set_fifo(st); + if (ret < 0) + return ret; + + st->int_map = 0x00; + return adxl345_set_interrupts(st); +} + +static const struct iio_buffer_setup_ops adxl345_buffer_ops = { + .postenable = adxl345_buffer_postenable, + .predisable = adxl345_buffer_predisable, +}; + +static int adxl345_get_status(struct adxl345_state *st) +{ + int ret; + unsigned int regval; + + ret = regmap_read(st->regmap, ADXL345_REG_INT_SOURCE, ®val); + if (ret < 0) + return ret; + + return FIELD_GET(ADXL345_REG_INT_SOURCE_MSK, regval); +} + +static int adxl345_fifo_push(struct iio_dev *indio_dev, + int samples) +{ + struct adxl345_state *st = iio_priv(indio_dev); + int i, ret; + + if (samples <= 0) + return -EINVAL; + + ret = adxl345_fifo_transfer(st, samples); + if (ret) + return ret; + + for (i = 0; i < ADXL345_DIRS * samples; i += ADXL345_DIRS) + iio_push_to_buffers(indio_dev, &st->fifo_buf[i]); + + return 0; +} + +/** + * adxl345_irq_handler() - Handle irqs of the ADXL345. + * @irq: The irq being handled. + * @p: The struct iio_device pointer for the device. + * + * Return: The interrupt was handled. + */ +static irqreturn_t adxl345_irq_handler(int irq, void *p) +{ + struct iio_dev *indio_dev = p; + struct adxl345_state *st = iio_priv(indio_dev); + int int_stat; + int samples; + + int_stat = adxl345_get_status(st); + if (int_stat <= 0) + return IRQ_NONE; + + if (int_stat & ADXL345_INT_OVERRUN) + goto err; + + if (int_stat & ADXL345_INT_WATERMARK) { + samples = adxl345_get_samples(st); + if (samples < 0) + goto err; + + if (adxl345_fifo_push(indio_dev, samples) < 0) + goto err; + + } + return IRQ_HANDLED; + +err: + adxl345_fifo_reset(st); + + return IRQ_HANDLED; +} + static const struct iio_info adxl345_info = { .attrs = &adxl345_attrs_group, .read_raw = adxl345_read_raw, .write_raw = adxl345_write_raw, .write_raw_get_fmt = adxl345_write_raw_get_fmt, + .hwfifo_set_watermark = adxl345_set_watermark, }; /** @@ -222,6 +499,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, ADXL345_DATA_FORMAT_JUSTIFY | ADXL345_DATA_FORMAT_FULL_RES | ADXL345_DATA_FORMAT_SELF_TEST); + u8 fifo_ctl; int ret; indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); @@ -242,6 +520,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->channels = adxl345_channels; indio_dev->num_channels = ARRAY_SIZE(adxl345_channels); + indio_dev->available_scan_masks = adxl345_scan_masks; if (setup) { /* Perform optional initial bus specific configuration */ @@ -292,6 +571,25 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, st->intio = ADXL345_INT_NONE; } + if (st->intio != ADXL345_INT_NONE) { + /* FIFO_STREAM mode is going to be activated later */ + ret = devm_iio_kfifo_buffer_setup(dev, indio_dev, &adxl345_buffer_ops); + if (ret) + return ret; + + ret = devm_request_threaded_irq(dev, st->irq, NULL, &adxl345_irq_handler, + IRQF_SHARED | IRQF_ONESHOT, + indio_dev->name, indio_dev); + if (ret) + return ret; + } else { + /* FIFO_BYPASS mode */ + fifo_ctl = ADXL345_FIFO_CTL_MODE(ADXL345_FIFO_BYPASS); + ret = regmap_write(st->regmap, ADXL345_REG_FIFO_CTL, fifo_ctl); + if (ret < 0) + return ret; + } + return devm_iio_device_register(dev, indio_dev); } EXPORT_SYMBOL_NS_GPL(adxl345_core_probe, IIO_ADXL345); From patchwork Fri Dec 13 21:19:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13907867 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B32A71EBA07; Fri, 13 Dec 2024 21:19:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734124770; cv=none; b=KCZojISsW94RRsamIF8uu2OjqRQKR5xU/vpVW8mz7Y205LW7yjsz1GkqTUgY8Ihy1eaeKE/+5aIb3B/6YyYnWX0kIXD3AROHu8nrLRlpsd6/x0UKjqhkNgKz4giGUf/WetDkgftK5Qt2gsjB2G2BDJY3JRXbCfUomjRqqtmwk+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734124770; c=relaxed/simple; bh=s/2Sud8tbTn3DV/gVz7omCuTc6DCCbix5hAZkUvCcyc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CVSxaKfqVV8kwgwsTK5xSE5Qw0j2m574rwS96z084Av/jBQegesnPEs4Ab7ZixNyjFXs1RU/zdah1gDaQUpz56q9Jx9mon1xakUEUzfXpEptBw38ylcdfotir/UHGZyxprbatpGW2oo7Z4/56sd1s0f0qpoqfC7w2qYZAXFuFyE= 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=cnWnPVKe; arc=none smtp.client-ip=209.85.221.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cnWnPVKe" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-385e0d47720so179831f8f.0; Fri, 13 Dec 2024 13:19:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734124766; x=1734729566; 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=CYq2MT/kLJ5VNDS2ggKYbL2pEgZu56efpig6dGEeYSQ=; b=cnWnPVKenN4x0F9G004Cl+8yfBqHmRHy0QBm8nD0/dIxDujYahbLPf8VU3MLy9ulfc dbTqE0xVX8vVwri9ygA2YbLy+tBlBhzDc+hG6uoXjqLwPF/wMPTA5rcmsu8gvCttizpn mMBrFBFr2U4OR+iBUyNf7rOGMF6ELrs+X8qAdcs3VMZF9iajuyuelhGJZjGHIw6gOx4W cwxz4pV5lhSc1YgBlYky8h1mkGp+ArEDAk86yBl8eE8DMS53vAsEiHtghn1Kxo4+4+bz NkTXJiBOqFnBbak8ruwpplDRsymHpOwQcPXjCtCk0sQsbRavLNW3zEm7EZXh9CFOT6bX ukuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734124766; x=1734729566; 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=CYq2MT/kLJ5VNDS2ggKYbL2pEgZu56efpig6dGEeYSQ=; b=T0mZiC0uoy/1ARYWAfn+E0mHyg2Zc60xF9rH319xHep4ZQPR2X2I1nXJaayEw8VV7o E7Ree467KxEbgXv/J0WggSLLDfJTiYjnT/educMR0UUxc4SMUYArM7dULE2hHJ06odxC snHprRBYncEwMgyTx8ka/L/rmxvkIWk/cmXMU8sp2UZlrhFw0h0cBkU306IH03xczjZh g+jX2sGBELN/5l7PnaWqqcWJ9fCtYUvwLRL+ydB4cOnk4ytcJI0ybc8U0eeg2l2efEIe rlJJZuYKCb3/20Yl9shZjGfz8m3Qrime4yvq00QlhfgqAErK/PvP4Zpj1n+Xv2Sjz/3l rrMQ== X-Forwarded-Encrypted: i=1; AJvYcCUm6e526eA3+4aVuL4oOV41+JgapfCEztv2tRW2Qrbs3YeC8SoxUYtzKLqhnu2aCON3IWZWdkBjNtE=@vger.kernel.org, AJvYcCVLT2d9QzrS41EuG/v76D2N59arA+1flOTCxb9zqfYznCb6/SO0XkCQ87orZ42iG7xBy//1ctkKnE0rwKk2@vger.kernel.org X-Gm-Message-State: AOJu0YzIjG6M9QdDVuT5MpustR+PpkiAP1dw2S75VxdEF8bwpv+jUiz2 M4/ibT3ByjKcSBphgB86aLvN7XcpVCM/8+coXaIlHbCEUf1H1qiJ X-Gm-Gg: ASbGncus7LgDg1nPjRT5ZQVC84IlV1SRiM/WSA6yf/ZxbCKN4bc2UZaMT5A4DYAa0y6 fyVuY0uoBkfD1pNkkLm2FzC4MfvVYxTVdTxMzyMpudkctjDJLVBNdtg+RCbRidQG0E0Vy8wUx9F 9Sseqzj4Z8/YJnKTP1ch+/id15qARNof75k1AiKbwxjVvkWEU1wgwDpoZXzDbJoVgL7KwMixvBi xyvpTwLSiQ0yNo4FDqZ8S++vg6g+Fjd2rSYKbwdFF2aHG5qNT17dODIsyO7CreImFGMF+OUlXWJ PsEIR2mB2n41dL8GZ5KMWaxUieovBMuNMGQ= X-Google-Smtp-Source: AGHT+IEXNihsN8XxqgC7drI8y5j/V5W3EJ0WOgSZSqHoe+pvSP11CUBMZGS7mFc5Zqk+njfPyD0HaA== X-Received: by 2002:a05:6000:154e:b0:385:decf:becf with SMTP id ffacd0b85a97d-3888e0b8793mr1084569f8f.11.1734124766520; Fri, 13 Dec 2024 13:19:26 -0800 (PST) Received: from d9dabf0abd47.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-388c801acfdsm552484f8f.57.2024.12.13.13.19.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Dec 2024 13:19:26 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v7 7/7] iio: accel: adxl345: complete the list of defines Date: Fri, 13 Dec 2024 21:19:09 +0000 Message-Id: <20241213211909.40896-8-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241213211909.40896-1-l.rubusch@gmail.com> References: <20241213211909.40896-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Having interrupts events and FIFO available allows to evaluate the sensor events. Cover the list of interrupt based sensor events. Keep them in the header file for readability. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345.h | 57 +++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/drivers/iio/accel/adxl345.h b/drivers/iio/accel/adxl345.h index bf9e86cff..df3977bda 100644 --- a/drivers/iio/accel/adxl345.h +++ b/drivers/iio/accel/adxl345.h @@ -9,10 +9,35 @@ #define _ADXL345_H_ #define ADXL345_REG_DEVID 0x00 +#define ADXL345_REG_THRESH_TAP 0x1D #define ADXL345_REG_OFSX 0x1E #define ADXL345_REG_OFSY 0x1F #define ADXL345_REG_OFSZ 0x20 #define ADXL345_REG_OFS_AXIS(index) (ADXL345_REG_OFSX + (index)) + +/* Tap duration */ +#define ADXL345_REG_DUR 0x21 +/* Tap latency */ +#define ADXL345_REG_LATENT 0x22 +/* Tap window */ +#define ADXL345_REG_WINDOW 0x23 +/* Activity threshold */ +#define ADXL345_REG_THRESH_ACT 0x24 +/* Inactivity threshold */ +#define ADXL345_REG_THRESH_INACT 0x25 +/* Inactivity time */ +#define ADXL345_REG_TIME_INACT 0x26 +/* Axis enable control for activity and inactivity detection */ +#define ADXL345_REG_ACT_INACT_CTRL 0x27 +/* Free-fall threshold */ +#define ADXL345_REG_THRESH_FF 0x28 +/* Free-fall time */ +#define ADXL345_REG_TIME_FF 0x29 +/* Axis control for single tap or double tap */ +#define ADXL345_REG_TAP_AXIS 0x2A +/* Source of single tap or double tap */ +#define ADXL345_REG_ACT_TAP_STATUS 0x2B +/* Data rate and power mode control */ #define ADXL345_REG_BW_RATE 0x2C #define ADXL345_REG_POWER_CTL 0x2D #define ADXL345_REG_INT_ENABLE 0x2E @@ -34,20 +59,40 @@ #define ADXL345_FIFO_CTL_MODE(x) FIELD_PREP(GENMASK(7, 6), x) #define ADXL345_INT_DATA_READY BIT(7) +#define ADXL345_INT_SINGLE_TAP BIT(6) +#define ADXL345_INT_DOUBLE_TAP BIT(5) +#define ADXL345_INT_ACTIVITY BIT(4) +#define ADXL345_INT_INACTIVITY BIT(3) +#define ADXL345_INT_FREE_FALL BIT(2) #define ADXL345_INT_WATERMARK BIT(1) #define ADXL345_INT_OVERRUN BIT(0) + +#define ADXL345_S_TAP_MSK ADXL345_INT_SINGLE_TAP +#define ADXL345_D_TAP_MSK ADXL345_INT_DOUBLE_TAP + +/* + * BW_RATE bits - Bandwidth and output data rate. The default value is + * 0x0A, which translates to a 100 Hz output data rate + */ #define ADXL345_BW_RATE GENMASK(3, 0) +#define ADXL345_BW_LOW_POWER BIT(4) #define ADXL345_BASE_RATE_NANO_HZ 97656250LL #define ADXL345_POWER_CTL_STANDBY 0x00 +#define ADXL345_POWER_CTL_WAKEUP GENMASK(1, 0) +#define ADXL345_POWER_CTL_SLEEP BIT(2) #define ADXL345_POWER_CTL_MEASURE BIT(3) +#define ADXL345_POWER_CTL_AUTO_SLEEP BIT(4) +#define ADXL345_POWER_CTL_LINK BIT(5) -#define ADXL345_DATA_FORMAT_RANGE GENMASK(1, 0) /* Set the g range */ -#define ADXL345_DATA_FORMAT_JUSTIFY BIT(2) /* Left-justified (MSB) mode */ -#define ADXL345_DATA_FORMAT_FULL_RES BIT(3) /* Up to 13-bits resolution */ -#define ADXL345_DATA_FORMAT_SPI_3WIRE BIT(6) /* 3-wire SPI mode */ -#define ADXL345_DATA_FORMAT_SELF_TEST BIT(7) /* Enable a self test */ - +/* Set the g range */ +#define ADXL345_DATA_FORMAT_RANGE GENMASK(1, 0) +/* Data is left justified */ +#define ADXL345_DATA_FORMAT_JUSTIFY BIT(2) +/* Up to 13-bits resolution */ +#define ADXL345_DATA_FORMAT_FULL_RES BIT(3) +#define ADXL345_DATA_FORMAT_SPI_3WIRE BIT(6) +#define ADXL345_DATA_FORMAT_SELF_TEST BIT(7) #define ADXL345_DATA_FORMAT_2G 0 #define ADXL345_DATA_FORMAT_4G 1 #define ADXL345_DATA_FORMAT_8G 2