From patchwork Thu Nov 14 23:09:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13875724 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14B031B21B3; Thu, 14 Nov 2024 23:10:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625819; cv=none; b=e3XOgGxetiAJeBfRBSbeMWwQFAHxoUXQZIqgkzA0MAz4wOwmnxMIEClEUuq6w0i3huaM2K2rT6Lo+F0lNagQGoelJVRof6mN/HqvfiXWls5lGvITSez0LwX416ZDWxuZel6DEttKDxE2U4ZdMUOTfJqryOH03/nwexYXPCAhO9w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625819; c=relaxed/simple; bh=aiLZjS3wh04TbJHljnL7BqHglqHGbfGl5zjpMcJ5K9I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SCY6JoebpOS9lByKI3p9Ye0V0A9GKWy4V/vhZtZT8osgo13mXGHzL0ylhGzXS8KppcJ7mfdTs8w6K5dkYfGDsK6laVdYB3lYFUzDwGlIytyAkwkdKOCZpU/T+wt4DJd9NzeDxvTplI8ILZ35V4bah3hqwnembAROlu/UebCYSeQ= 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=cVW4nAc0; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cVW4nAc0" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4315549c4d5so1409555e9.0; Thu, 14 Nov 2024 15:10:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731625815; x=1732230615; 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=AG4Ni7KzeRb+ZTbiEyqqdopwxe2k/jzkggqNyDeFT80=; b=cVW4nAc0vT3hOqh5YPlLUoqH9darh1QmFGV32gyuC6Xoq4aw05rIxrCAczpv6liYvE wxgyGPWpNfOpaLZMLJeKWjFB4MqmzM7tQqqeQvNxj3rhTl2KsTpc6z52cJsSZuOG7ty8 HdJwGOcGrxHvzE34AQqIlh3gVPj3fnpu5chJGlXM+hA9ETqDA1vRNH4qK9fhxbSUU9mA oc1d80kz14KugMwdWmDStz+N9vyniJqznHfKj0n33D0ZgmFohSEMdgtdgwdm//1vsOgu DedSjWEGcOKCBhytKv5SPqjuJQGMNaMwvMwwqlzTsV2D6l8MLY5QqSZbbNV5kF2YHkNw rRHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731625815; x=1732230615; 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=AG4Ni7KzeRb+ZTbiEyqqdopwxe2k/jzkggqNyDeFT80=; b=ijaQeXtWVUwP+cL3oHySMsbCUzVekG/zwRg4nXRI57oWkitapH356QwRL5sC+0MObA IFIWm2k7EwkUBcjF/mu1nAaUPnk9h2JK3oZbgyNAVzM+o38B96Hhs7h15EapPHjzfFAQ EKBDx3JgNOwpjIHq6BJl+PbLljd1SfCEB4T2VyYXGG4pOO/wUCNtn239fa9mKN45yAdW jwKtIcV9KVO+wEw6sNIAdB9cIYuFiXZFvv5NM/mEh4shR0fHxe6Tj2omf6wvgFCYZY5n gH0nVHCls6TM2GpM6UHG0/tzsGRXbqZ1MwVKN6cE8ehYUFiMr2HoZYrQlBM7CHGtpWjU eC9g== X-Forwarded-Encrypted: i=1; AJvYcCUD3u9+RiMEvS/WaasZjDiBUn3qCuMnak7QFv1l2dugJJlm1J4NdffXMrMPXQFmZu2L1IR1/pX1aNSziD1m@vger.kernel.org, AJvYcCXCdwQk7aST6bg8ndr/Y6TxYuKhDG5DxV3Gl1AKzWDE0P+WPwBCI4twGPdLz3RK54bPjeBUqeDq9R8=@vger.kernel.org X-Gm-Message-State: AOJu0Yz0jEVfioCLZgPynuBaDSXb7sBwdt7kNy1G0gyhqA7rmp4kFcSV Xz3+S8Ew4nYKsAfM7RHpkt4D/zHXnqUAQCJGYHPIr1mEz9i3tOrm X-Google-Smtp-Source: AGHT+IEbgXJPAS9eq02cqKvDMQpsHbjyytZLtrV0zIAleuM/FP70X+eAjC0jjh4hWYN/wB7kqE2lUw== X-Received: by 2002:a05:600c:510f:b0:431:50b9:fa81 with SMTP id 5b1f17b1804b1-432df7995f3mr1611425e9.7.1731625815167; Thu, 14 Nov 2024 15:10:15 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dab789fasm36464265e9.18.2024.11.14.15.10.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 15:10:14 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: l.rubusch@gmx.ch, Lothar Rubusch Subject: [PATCH 01/22] iio: accel: adxl345: fix comment on probe Date: Thu, 14 Nov 2024 23:09:41 +0000 Message-Id: <20241114231002.98595-2-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241114231002.98595-1-l.rubusch@gmail.com> References: <20241114231002.98595-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Fix comment on the probe function. Add covered sensors and fix typo. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 006ce66c0a..d121caf839 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -170,7 +170,7 @@ static void adxl345_powerdown(void *regmap) /** * adxl345_core_probe() - probe and setup for the adxl345 accelerometer, - * also covers the adlx375 accelerometer + * also covers the adxl375 and adxl346 accelerometer * @dev: Driver model representation of the device * @regmap: Regmap instance for the device * @setup: Setup routine to be executed right before the standard device From patchwork Thu Nov 14 23:09:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13875725 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 987DE1B21B9; Thu, 14 Nov 2024 23:10:18 +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=1731625820; cv=none; b=B7cYfr1XjEeg78CubQ/nTdMm1wUuV0YPjva8Lu2fzDyha2TMLcvaMP8LaqD2z59MDlckQs/+kWbjzkHE8eEH3jUKxjttQlW+ks+OSaG8UiisexyIdAi3kQgoVLAnjnO8WSxewJQoO+5RSpAP5kivHV/OIfaPBOaOKVIUEitEgtw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625820; c=relaxed/simple; bh=vXMd3bUouv/WV7BNNEBeLPEuXmjltJJ2I4sZLLnoAXA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QllKxwauv5dk5bc6nnAw63xXpbXwYw8Plzrr2iuC3YBAgq8cDAl/tyUkW1/BCy8f4Bt540flQHb0+ZAA6GCP6WYfHphOSc2KqHEG1g0pJo1NxpSJ9MZmO0pvBbT6uDF5c2lLwa/INpi2yulB6Pb0Pv/w1re1zQdWTilzOY9IVYY= 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=C1mj8GUo; 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="C1mj8GUo" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-37d432f9f5aso60006f8f.3; Thu, 14 Nov 2024 15:10:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731625817; x=1732230617; 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=dL7aJCXSASL5a/Feg30aFqhCV24wGmaLRDtir+JmL5k=; b=C1mj8GUo7JyutNGnrjSuIJ2MF51ZyqTO57Bh12dWad/HSexezhdybxCV5XqIN0ohCi Yh4T6qOHLOhYFOVE5HucOLztxF/AT4kdiIGX/eI36u6MvdYv7Y2+FyPb+Dbp1b7AabPF nJjE4PoLoADYlf/qimwAxPkSfhRbCUkgOcmot23+5jQyGAVpTDaD+rM8e9bXxdcnxebl ddWkhVtNsIB/fB29Mp8Agy8i5+FzTepy/TzvRPvhApeL6xT/TktZYva8ldov2erl4OZz +caFcUUW2mcnzP+9ZEtGRFh48bXaUR/WW1ZMivUmCedsN/Adwumb9qUMfKws2gPQGYY5 16HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731625817; x=1732230617; 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=dL7aJCXSASL5a/Feg30aFqhCV24wGmaLRDtir+JmL5k=; b=mtSiXy5Jr6FaWExnaXJJojDmQL+B3sq8Jiex480ONcyPa5oV1lk84j0zXh4rSz5NjH u/4RCDXygBYrwK5mydRjJT+9IRv8Sf3lE4JAc6Oa1ipCd0Zal8c2wGHT4lmjVCOegzBB xyTgEfU2tDdaT753Dub5p6gvL3EtFWKUZH0wLixEJ6fE5TtOW8E9cRxQlC2offaK5zUJ ZI0YceVubzK71wIE0peIQHibEmfQW9XDtPwbs7M/HmPcP2QLPG85IW7PxXPMJ7K3qiEf OGzWnmbt19unR/bwBu3dWwZ9Dt4MG+dtuji0BGyX2HPnWmTnWtFhbrAVttBupGn1g4NO Q/Rg== X-Forwarded-Encrypted: i=1; AJvYcCW41hHOmdclPYtnynIpOFXJV78W2B/pGXNXpviWjRlSAX/pf6UUZ7Hmk0Zf9TEcAYfpz7KKK2XCWbyAU2JU@vger.kernel.org, AJvYcCXo2zeScRGDgOQOlVQPcgDnyWYLqP1lPzwLUOoc60wvINHkKslHAe8+8O/bdG956R1G07Yim8CDoOM=@vger.kernel.org X-Gm-Message-State: AOJu0YxnJXoXoz/Ltw3i1u/nU4S+dua5dAj+Z+k4QiG+q5tdn8/nGc1I 0GfaWqyuyEss0Pm8wxYPEFf7O1H642hEnr2EkMEKCiAgFOOUWEHn X-Google-Smtp-Source: AGHT+IEOUNbTCQ4D3xhfcr9oaq9a76+9sXJvK1TxKNmF8DAb7EydMz88hAAyjJcRsEJHg0tLv2gHDA== X-Received: by 2002:a05:600c:3589:b0:42c:c59a:ac21 with SMTP id 5b1f17b1804b1-432df7229eamr1715315e9.2.1731625816737; Thu, 14 Nov 2024 15:10:16 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dab789fasm36464265e9.18.2024.11.14.15.10.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 15:10:15 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: l.rubusch@gmx.ch, Lothar Rubusch Subject: [PATCH 02/22] iio: accel: adxl345: rename variable data to st Date: Thu, 14 Nov 2024 23:09:42 +0000 Message-Id: <20241114231002.98595-3-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241114231002.98595-1-l.rubusch@gmail.com> References: <20241114231002.98595-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Rename the locally used variable data to st. The st refers to "state", representing the internal state of the driver object. Further it prepares the usage of an internal data pointer needed for the implementation of the sensor features. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 42 ++++++++++++++++---------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index d121caf839..3fb7a7b1b7 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -43,7 +43,7 @@ static int adxl345_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { - struct adxl345_data *data = iio_priv(indio_dev); + struct adxl345_data *st = iio_priv(indio_dev); __le16 accel; long long samp_freq_nhz; unsigned int regval; @@ -56,7 +56,7 @@ static int adxl345_read_raw(struct iio_dev *indio_dev, * ADXL345_REG_DATA(X0/Y0/Z0) contain the least significant byte * and ADXL345_REG_DATA(X0/Y0/Z0) + 1 the most significant byte */ - ret = regmap_bulk_read(data->regmap, + ret = regmap_bulk_read(st->regmap, ADXL345_REG_DATA_AXIS(chan->address), &accel, sizeof(accel)); if (ret < 0) @@ -66,10 +66,10 @@ static int adxl345_read_raw(struct iio_dev *indio_dev, return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: *val = 0; - *val2 = data->info->uscale; + *val2 = st->info->uscale; return IIO_VAL_INT_PLUS_MICRO; case IIO_CHAN_INFO_CALIBBIAS: - ret = regmap_read(data->regmap, + ret = regmap_read(st->regmap, ADXL345_REG_OFS_AXIS(chan->address), ®val); if (ret < 0) return ret; @@ -81,7 +81,7 @@ static int adxl345_read_raw(struct iio_dev *indio_dev, return IIO_VAL_INT; case IIO_CHAN_INFO_SAMP_FREQ: - ret = regmap_read(data->regmap, ADXL345_REG_BW_RATE, ®val); + ret = regmap_read(st->regmap, ADXL345_REG_BW_RATE, ®val); if (ret < 0) return ret; @@ -99,7 +99,7 @@ static int adxl345_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask) { - struct adxl345_data *data = iio_priv(indio_dev); + struct adxl345_data *st = iio_priv(indio_dev); s64 n; switch (mask) { @@ -108,14 +108,14 @@ static int adxl345_write_raw(struct iio_dev *indio_dev, * 8-bit resolution at +/- 2g, that is 4x accel data scale * factor */ - return regmap_write(data->regmap, + return regmap_write(st->regmap, ADXL345_REG_OFS_AXIS(chan->address), val / 4); case IIO_CHAN_INFO_SAMP_FREQ: n = div_s64(val * NANOHZ_PER_HZ + val2, ADXL345_BASE_RATE_NANO_HZ); - return regmap_update_bits(data->regmap, ADXL345_REG_BW_RATE, + return regmap_update_bits(st->regmap, ADXL345_REG_BW_RATE, ADXL345_BW_RATE, clamp_val(ilog2(n), 0, ADXL345_BW_RATE)); @@ -181,7 +181,7 @@ static void adxl345_powerdown(void *regmap) int adxl345_core_probe(struct device *dev, struct regmap *regmap, int (*setup)(struct device*, struct regmap*)) { - struct adxl345_data *data; + struct adxl345_data *st; struct iio_dev *indio_dev; u32 regval; unsigned int data_format_mask = (ADXL345_DATA_FORMAT_RANGE | @@ -190,17 +190,17 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, ADXL345_DATA_FORMAT_SELF_TEST); int ret; - indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); + indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); if (!indio_dev) return -ENOMEM; - data = iio_priv(indio_dev); - data->regmap = regmap; - data->info = device_get_match_data(dev); - if (!data->info) + st = iio_priv(indio_dev); + st->regmap = regmap; + st->info = device_get_match_data(dev); + if (!st->info) return -ENODEV; - indio_dev->name = data->info->name; + indio_dev->name = st->info->name; indio_dev->info = &adxl345_info; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->channels = adxl345_channels; @@ -208,12 +208,12 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, if (setup) { /* Perform optional initial bus specific configuration */ - ret = setup(dev, data->regmap); + ret = setup(dev, st->regmap); if (ret) return ret; /* Enable full-resolution mode */ - ret = regmap_update_bits(data->regmap, ADXL345_REG_DATA_FORMAT, + ret = regmap_update_bits(st->regmap, ADXL345_REG_DATA_FORMAT, data_format_mask, ADXL345_DATA_FORMAT_FULL_RES); if (ret) @@ -222,14 +222,14 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, } else { /* Enable full-resolution mode (init all data_format bits) */ - ret = regmap_write(data->regmap, ADXL345_REG_DATA_FORMAT, + ret = regmap_write(st->regmap, ADXL345_REG_DATA_FORMAT, ADXL345_DATA_FORMAT_FULL_RES); if (ret) return dev_err_probe(dev, ret, "Failed to set data range\n"); } - ret = regmap_read(data->regmap, ADXL345_REG_DEVID, ®val); + ret = regmap_read(st->regmap, ADXL345_REG_DEVID, ®val); if (ret < 0) return dev_err_probe(dev, ret, "Error reading device ID\n"); @@ -238,11 +238,11 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, regval, ADXL345_DEVID); /* Enable measurement mode */ - ret = adxl345_powerup(data->regmap); + ret = adxl345_powerup(st->regmap); if (ret < 0) return dev_err_probe(dev, ret, "Failed to enable measurement mode\n"); - ret = devm_add_action_or_reset(dev, adxl345_powerdown, data->regmap); + ret = devm_add_action_or_reset(dev, adxl345_powerdown, st->regmap); if (ret < 0) return ret; From patchwork Thu Nov 14 23:09:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13875727 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 3C9F11B3930; Thu, 14 Nov 2024 23:10:19 +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=1731625822; cv=none; b=Rnb2Vj8wwlhAAdinzz7cHOUGKoGpeZJttNh6VDx2U4BNY1Qm9Efub5MEQjGfsUom/6RpRqMImKU9lFsaF6KG6J+ACYJIP7ou1Cp+eXBFveJ1bxCjJMAVBtxN7RSiHjumDQ3mX+NWLeVi/QvAB9VoLUQxsECCej2Nhy0iG3yJqQU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625822; c=relaxed/simple; bh=+PHQLrTNWeQsXdijBQ7PsCkFbdsNKrzTG1/AdiqprSk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=c/ZUyZwpReZIQ3P7i7RgMqavVhw7jH2O3K0WM2qnlEVzWmpgOjRNAuYu9NJzXtumvuCqheQrSbyF0rCrCqCXBxW30i7ZJ8L6tF1Fd9Ujk+5nKrWIzq5kH9H5VDkwLofBTQJ4TQbI2gK24d7TckJKTzyYunTMQV9jjvHydmjIzK4= 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=X4vFl3zo; 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="X4vFl3zo" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-43158124a54so1398085e9.3; Thu, 14 Nov 2024 15:10:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731625818; x=1732230618; 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=gqLCx7ko/pTUy6BjX7kjCxNomdFNpbjuzoAFnkseXBA=; b=X4vFl3zosW5E1gtNfuOtAnzS+bDXVRQvuGc+dBNuI29mZYRcAnV+eaaAu4IX2+GNmr qNUKr+u16PjwIMRUOZ216JCxdmYMCj/kqL0QrBBoihF5H5QQxO4C0+nxAANy+OL93CM+ MMEfWKCoO+O0j5iufkoJCn6RRxUThadFUx61No9yyaOgm/I0ZckPRxjjC69G2xCESSax HBC5ss53xFpoWyTF2TTazImbpcAfErktHZHQrEFeBCYm5vkrtlEWMhceDqgE4ajivRZe MXhpqBskmp6tIek3T2Lh4p0PpfQXG0KTNIbqEmjoP4ziIpefjbRlWHC2qYR83RQg2llt hEjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731625818; x=1732230618; 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=gqLCx7ko/pTUy6BjX7kjCxNomdFNpbjuzoAFnkseXBA=; b=n70C11PuAyExE23sjpiyx9b32adtOwN7dGiMplwi2V8bYwhlmLhIY9SuJNUiMZTKBd WxKF6pEJltePKay57NMmTkyrnXibwbLEHHipLZvzjiY+iGC6jEagEkNTbzy9GLSoJlnU fGWtQkTmuWH+zs3j4IMY2uq8tU1xKgB4W6hYCQ0WaV/PoVeK5mTiazHDt+Gtnrar1QIe juJJk0Cd//W4pe/630o4kh5Agx6A9Yj24F/TuWL54fef/0Umn7CoPhf2pHV+nCsSw7/+ CC9sitSzRzAsFWwnf0IV6SeSSSCFK67EeAnFKVsYapR1Kv9qMguvOAqAUWZBhFAiB05a 8OuA== X-Forwarded-Encrypted: i=1; AJvYcCU7E8wmIBe9eNgU8aKczEuBEwH70O2dqcjiGK4FgXLdyZPkYoeHuBlr9J+kqKEF8eQbVt0jqrLNvPVWOQHX@vger.kernel.org, AJvYcCWbwdvYpwOHFK9N9H2XVW9YONVn6ANq/2o9fp+WMU+qSZI1sVOlpEn6snfUJNmlnZLXg+5rSmOrjAE=@vger.kernel.org X-Gm-Message-State: AOJu0YzdB1Re8oPqnq0IhtXF0PdMBY9h5O35avWekbEp0MjwoHdZkjgq kmlYn2YcISfZvs6Zyad+dyZU3Zq3JoFBBH3GL+JiyBacwczatAt6 X-Google-Smtp-Source: AGHT+IHb+tBVY+6h0mvrGFljj2gzLndNaKfnXnQk9XMn0RgE/qcWzg1m+TsyPeMhNSplGRMWrjxD7Q== X-Received: by 2002:a05:600c:3ca8:b0:431:5316:6752 with SMTP id 5b1f17b1804b1-432df71e06fmr1709965e9.2.1731625817658; Thu, 14 Nov 2024 15:10:17 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dab789fasm36464265e9.18.2024.11.14.15.10.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 15:10:17 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: l.rubusch@gmx.ch, Lothar Rubusch Subject: [PATCH 03/22] iio: accel: adxl345: rename struct adxl34x_state Date: Thu, 14 Nov 2024 23:09:43 +0000 Message-Id: <20241114231002.98595-4-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241114231002.98595-1-l.rubusch@gmail.com> References: <20241114231002.98595-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Rename the struct "adxl345_data" to "adxl34x_state". First, the data structure is supposed to be extended to represent state rather than only hold sensor data. The data will be a separate member pointer. Second, the driver not only covers the adxl345 accelerometer, it also supports the adxl345, adxl346 and adxl375. Thus "adxl34x_" is a choice for a common prefix. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 3fb7a7b1b7..30896555a4 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -17,7 +17,7 @@ #include "adxl345.h" -struct adxl345_data { +struct adxl34x_state { const struct adxl345_chip_info *info; struct regmap *regmap; }; @@ -43,7 +43,7 @@ static int adxl345_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { - struct adxl345_data *st = iio_priv(indio_dev); + struct adxl34x_state *st = iio_priv(indio_dev); __le16 accel; long long samp_freq_nhz; unsigned int regval; @@ -99,7 +99,7 @@ static int adxl345_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask) { - struct adxl345_data *st = iio_priv(indio_dev); + struct adxl34x_state *st = iio_priv(indio_dev); s64 n; switch (mask) { @@ -181,7 +181,7 @@ static void adxl345_powerdown(void *regmap) int adxl345_core_probe(struct device *dev, struct regmap *regmap, int (*setup)(struct device*, struct regmap*)) { - struct adxl345_data *st; + struct adxl34x_state *st; struct iio_dev *indio_dev; u32 regval; unsigned int data_format_mask = (ADXL345_DATA_FORMAT_RANGE | From patchwork Thu Nov 14 23:09:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13875726 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 4BA831B3933; Thu, 14 Nov 2024 23:10:20 +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=1731625821; cv=none; b=eRLMbj09nMeQDoqxyB4qWRCu5Aa5zSqw+N4GNq62S2e8hTDyejqt1RxolCDV6epnwPQ7MkxVh7XoFn0EGlKIE+/eouAu46llkb7jJ+RKbgZ/wmbOdbQGkSzEe5veLgIktdqHXHx2a9yB+E0qpAeeypPUlzHYeh2lyBtp3/6SiNY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625821; c=relaxed/simple; bh=L3andXkjRLQymvf8LjCuX+TX6xCi6V06lsEpXcccsP4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EUxtAwpHfqBwuX63UXDgG0tfqZoDcW69nFA+l2x3eMq5BfsEhfipSgNinMGoh4yIXZX5jRkh5p0NERg741zuQJb+1ZNesa4ire3GSfaC+Ftzf0PUHhiFeK2UZ6mQ40LG3ObnLmekwf/Q0VfuYd3aaNDPw+Jv3JDbDQCjYmD5MVs= 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=ILgxozwh; 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="ILgxozwh" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-3821b30684cso78814f8f.3; Thu, 14 Nov 2024 15:10:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731625818; x=1732230618; 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=JNurtUxYaSEIK0NoQH6+V7C+YpTyLjyZoXEozbLOm/g=; b=ILgxozwh39N23j7FPEyP5Txxg+ffSMMMfRTy4NouAxa7/t1ZYADuC2BPip6fDwwYsu vI4WnrAxyALTojBAfHE/V8Q8eyWgkJupuW/I+W/uvF0pcfQKEd9dDqhgRV7J5Jpy/z7l KcbxLMCeoiUntI5u+pe82Fus0h2yNIoq4hJUsE1vwz01GzSKqETtVDOZIFZCFlOglJcO bkkJcAsw59h7soxe+L7TZ+jrFiiN5an1usCgodjTRFJCYcuPIJi8f8UYfHcrnPYcXl5g neLYHs4+NyIydP+oDiLQVfmxr5dPSEVcWxdh5ocHEVfqr2ENJXpqp7yG6qwKOn+Yi0eA jZpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731625818; x=1732230618; 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=JNurtUxYaSEIK0NoQH6+V7C+YpTyLjyZoXEozbLOm/g=; b=wE7JKSdE06Sdsv+jj5IvZVSOfBzW0T4PxG5/nq1ByI3mdFRn/aQ8K8+QONEeA4NiEt homX3ZA210c5n/ScvxQptPf4kQ3Z5GqIkNEiQ/i2YT8YJuYqTPlzjwHBzE2gqYH8EyUL nhBpjDqZxu8LXWa9xICad3MYGJayCJDzipNSCBtlYjs03yVfd1gXWhhdM3uh35Dc5ciQ WVw5XIHYxu8yFP+MbdtNDOZ21T2pvnEBYh/dXQK1SaT3x+Vv+r95OgNadbMRrSB6F6ka mNGaoH0reN9SzXaYE0qlBLa6UtaLTXpnpLiLAHgA5EPRFKXZ7QVzq5CucLcymHDlc0T4 fYEg== X-Forwarded-Encrypted: i=1; AJvYcCUd3NQS86PkBW1krQ0ONsljL/OEz8QIg+flRlX01RfAI5RDRDvcTlNDfOJLt6bG7x0jZVBluy+IFYc=@vger.kernel.org, AJvYcCWeS/OEF/GK2/j56+aVjLOD73Esc8qXSz2B7Was/pWnQtWWQBYeCDdA3BXvzAqvVqjS1mXjDrJRlvdX9FYI@vger.kernel.org X-Gm-Message-State: AOJu0YwEEF8nqB8E/5E/S0wsnD0f1MusGR035eYf619VAhNNdZauekH+ SQsELuKb8e2xLz57qBnFWe7xNAhtGlTNj5KLNNyFvb2lKTiDw2PHhuSbbnFR X-Google-Smtp-Source: AGHT+IFlW1Qx+q9Sg148hCAMvFMzQOQbQcyYnHjdh55F2el8aja+nQrfFWYAQDwNUFM1OGIg33yfhA== X-Received: by 2002:a05:600c:5117:b0:42c:b8da:c79b with SMTP id 5b1f17b1804b1-432df787865mr1627115e9.5.1731625818548; Thu, 14 Nov 2024 15:10:18 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dab789fasm36464265e9.18.2024.11.14.15.10.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 15:10:18 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: l.rubusch@gmx.ch, Lothar Rubusch Subject: [PATCH 04/22] iio: accel: adxl345: rename to adxl34x_channels Date: Thu, 14 Nov 2024 23:09:44 +0000 Message-Id: <20241114231002.98595-5-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241114231002.98595-1-l.rubusch@gmail.com> References: <20241114231002.98595-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Rename the "adxl345_channels" to "adxl34x_channels". The driver supports several Analog accelerometers equally, e.g. adxl346 and adxl375. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 30896555a4..2b62e79248 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -33,7 +33,7 @@ struct adxl34x_state { BIT(IIO_CHAN_INFO_SAMP_FREQ), \ } -static const struct iio_chan_spec adxl345_channels[] = { +static const struct iio_chan_spec adxl34x_channels[] = { ADXL345_CHANNEL(0, X), ADXL345_CHANNEL(1, Y), ADXL345_CHANNEL(2, Z), @@ -203,8 +203,8 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, indio_dev->name = st->info->name; indio_dev->info = &adxl345_info; indio_dev->modes = INDIO_DIRECT_MODE; - indio_dev->channels = adxl345_channels; - indio_dev->num_channels = ARRAY_SIZE(adxl345_channels); + indio_dev->channels = adxl34x_channels; + indio_dev->num_channels = ARRAY_SIZE(adxl34x_channels); if (setup) { /* Perform optional initial bus specific configuration */ From patchwork Thu Nov 14 23:09:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13875728 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66F3A1B3949; Thu, 14 Nov 2024 23:10:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625823; cv=none; b=a/HPJmHGUVTisNOgCFnBWjM8xFo7GT6MyZu3RcEUaBsrUxnm3MJ8M8n2DGQLU94ogOtcMHHmCR6KgiLg3x61y3YH1SCBuVznG1q1dR9wBdLGkKFfLo0v2sf3+q100R08kQT3a7ZQCZ0uXbEJIh90RXNHLizH6Za6hQ+wczGBuTA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625823; c=relaxed/simple; bh=3+8TGTdnmuRDOCovADWFx3rULEh3tRTgXMyrKonxBas=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=D8hvib6DSfYOcVIkByPn+ulPYhhTJjdulkYtkHl1m0Q1zhSxaM5o/gOFRfygG02VzVIdhATy+YCCSfeL0yvvFZ4r14qJTkc3mjS7kUdkTCKcygqbXuqKTyrjdCS+UlXu7ZQefdQhIXEMg+LmtCwoAZL6DwYgMEL+u2cI38Ypsn8= 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=mvPiZnAX; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mvPiZnAX" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-43152fa76aaso1069975e9.1; Thu, 14 Nov 2024 15:10:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731625820; x=1732230620; 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=vpq3lBbChwHQ1yWypFmrljsNCSzIVAAQbPGcSyQvPoU=; b=mvPiZnAXQ75EdQFywFG6SOq6aU92XdJPql4ZOTiiwDzWaW5BLxJexN8HqNHZJgcYW1 FjGmIvmo+6sIoSln+z98iRFR4ddV2lahWSpnfVCQo1LL9c/bEZd/7T3Wihd3yvCFI8Fu 51ty2JYbIS6xqVEkl8M8/13jvtuYN+ls27dDYEDCH5qBidTgZ4R5pgvxuvGisgQhuLTS yiTguUWMyIo68uunYOaSXcKFoLBlKYofnn80Rz8GIBs9u1c4Q8P1Zy96UCF/pf9mDhe5 JksPOmBAJybuimrI0vWgP2kdyaGyq8HXHQIbeguud9cYJAhYRn8ONeLjPcnbeMTvoprG 6+aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731625820; x=1732230620; 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=vpq3lBbChwHQ1yWypFmrljsNCSzIVAAQbPGcSyQvPoU=; b=Wu8g5xoOB/7i58PgV3EVzdKYUhl74Yc+1qd2K9qJTAIHlgB7qGfal5b96iOOGN8CkL LzkSKQ8PvyAFC18bYynTbJ4qiF5ZdwPnCNOVNKbVr45A9A+K+GJNml/+i343habBT40a XQSETHS3E3xcOVuUfLxpNxPTYq0wL0w5a3RVqrI/mQNGsP2lSIehYt1qXvDWPkxK9fuR A+EkYOcP+sbiJ4JArjORT25AZs8BKQB6CJnlucuATiq4c6pSnk6psdn1I88IVrk+MQxY dNtVLKMVv9s1gGkbxekAKI2goaqfgRCaNcs1EA+nSY+hLYNkFRO35HKV7y5h081n1vhk 0L6w== X-Forwarded-Encrypted: i=1; AJvYcCVIa8Fkrh6dRVH4lazVfLm1hgUQOxnU/YS4daK7Ue2AARU3XDxktGVQP7FhkjbFycFVXCV8Le/iEZXzJcj7@vger.kernel.org, AJvYcCXNncABkz9TKjsGrRklsCd7qju6CFikXyW/JSefrj0+E+TalNuOSU5ux1AIpMWqmCYMQhxCsu3toGE=@vger.kernel.org X-Gm-Message-State: AOJu0Yzh+xaQl1JA4JAObP9jDNI1kFgyV+Sfi0EO3iw2TtDH7JeutQpT A4qxq2t5ldd40zYtR7wbNtYJp2sQ7ezb+mPQzyC5CD3x8RvXXYnK/EIQidIu X-Gm-Gg: ASbGncvz/8Xk/5CPidKuJlfazqKhoBNR3q2DeJ1BHX9a7hjkl1e141zEF7DBI3pa6Lf AUlI198f22Y7kbDnicbyM90jhdfLgcmGURxgnQZHut8lXlkrZ3w3xKEkcwR/azNxU6F8Qbd0BKJ 1k4dyhAnVDxlwzgdat8xyK5DCdueyffwJUI6iMEVST/eO9FhfrdbogquHtIAkbifnpiBQnBkcom xKoNWxJ0dVQyiZD7gn++ZoLLKQ41opbUZL9Y1Ri6j+PnLFTnxu1WHnBz7cqikkCfqXlGHkl4Oh/ LHfPwtWvfI4998oJeAUqd3Un+xPm X-Google-Smtp-Source: AGHT+IGU97K/j+iu3cMhre3pgJnmMA40jSRhp1AgIVMrXApFSHlnBSTVg1hBlprgYeqz/uT0rQfz6Q== X-Received: by 2002:a05:600c:354b:b0:42c:aeee:80b with SMTP id 5b1f17b1804b1-432df797e02mr1636225e9.8.1731625819388; Thu, 14 Nov 2024 15:10:19 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dab789fasm36464265e9.18.2024.11.14.15.10.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 15:10:19 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: l.rubusch@gmx.ch, Lothar Rubusch Subject: [PATCH 05/22] iio: accel: adxl345: measure right-justified Date: Thu, 14 Nov 2024 23:09:45 +0000 Message-Id: <20241114231002.98595-6-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241114231002.98595-1-l.rubusch@gmail.com> References: <20241114231002.98595-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Make measurements right-justified, since it is the default for the driver and sensor. By not setting the ADXL345_DATA_FORMAT_JUSTIFY bit, the data becomes right-judstified. This was the original setting, there is no reason to change it to left-justified, where right-justified simplifies working on the registers. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 2b62e79248..926e397678 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -184,8 +184,13 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, struct adxl34x_state *st; struct iio_dev *indio_dev; u32 regval; + + /* NB: ADXL345_DATA_FORMAT_JUSTIFY or 0: + * do right-justified: 0, then adjust resolution according to 10-bit + * through 13-bit in channel - this is the default behavior, and can + * be modified here by oring ADXL345_DATA_FORMAT_JUSTIFY + */ unsigned int data_format_mask = (ADXL345_DATA_FORMAT_RANGE | - ADXL345_DATA_FORMAT_JUSTIFY | ADXL345_DATA_FORMAT_FULL_RES | ADXL345_DATA_FORMAT_SELF_TEST); int ret; From patchwork Thu Nov 14 23:09:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13875729 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.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 3568D1B4F08; Thu, 14 Nov 2024 23:10:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625824; cv=none; b=F/MWeTHnYgNXCwqTcN9ExUqN0UaPkxZhQrYk/0nJmXn6VESrGlhiTnepWm/Lhm4DeVoYo+vAtnJOv9niodcjeR1AMCvxKiS66ufRY4sdlSBXyD+x26ep8ZBGlG/SsCPXWhR4mkXGRT3reDRMbzxgcOyQBJkIuRSWFTX7u/A1ooA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625824; c=relaxed/simple; bh=gHYu12Rw5/dkV3YGL2sO3N01Roy+URU34yCpf9G7WpU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eKKJnc1LSM4sDzSeVo1P7jv39cTR5mcJCdG/l3m7wkXJPjXpE8eSw1kFJtwvKm24tCYF83OFnZvx5xHQmjL+oOlNfeTueGWySp/qt/HxsDdzkSmmSDxHl2k2avjSCJT5MuV4/s2yitLiVpX+BeryJzStjmSmcBS8LunN/2wIvgU= 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=lTK8mM01; arc=none smtp.client-ip=209.85.128.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="lTK8mM01" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-432d796a57eso1407575e9.1; Thu, 14 Nov 2024 15:10:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731625820; x=1732230620; 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=O5DVuhpbt65Tb2WFhtaXDExhTn0sEn63wQnWqfaY7lM=; b=lTK8mM01kc1cYTwGpDNtfsMB1D5Vio/Qn/URQmchASlXafybKrdYUNs6Pds67MUmsO iTTNe7Br2HUTGxHMGLVVirYM6u3wNNkOwfYa2m6I4FpASO3cTcVY5WbVaQt2JihaDrdm KQgi1CHmB8HyZKcXMh1sv6xgR+CYuj0HRZtkCufCZTO++hqf7WESm5N+oUxgxHBlaPYT jjU7juN+y0HmU0v9Y6YGSi27q1IdBUqQ+4V1JO6rnfeJp+IbhUw0rBXXaZp/NJUk+K54 DTxUPC8P9H6D66vIPW+d3B7/6ygl6SXZY6N/x9PW8D3QuD6n/JMjmoM0hGVI0pv+4kBN HYWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731625820; x=1732230620; 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=O5DVuhpbt65Tb2WFhtaXDExhTn0sEn63wQnWqfaY7lM=; b=U8aYR/cVy7oD5pJ37I8y2Kehy/pPyOmgZ2tUvKJYFgKHoBft5C2Lg8bWO1VcJqxJGS qC5922AvfkAL3n7nvazTGupOh5/7t5qhc9ieUYI8/P+1XeCsg26XhOdLOvaamJFD+WE6 jLwqPerVvECeB0jY5I1mvs/psJCR7E5xq/BFTKYADoS7gzoNOGuOVfaMtzZsgSoUjXHP LlSIOZ/QWlv6buxdUo5YhS0w5QjJTm3mcNhqF9o7mTy4LXY4ki38iGcLOOZoltrDoAM+ BK2bjGzMNV4T6X9NUQikoUnKirtqgJPRFm2Re818ovu2PN3k/jyHT3HrOJDmMAe65aWc WnHw== X-Forwarded-Encrypted: i=1; AJvYcCUfsNLduakWt4V9aPmzpknjFihFXEubuMbkBU0HRL/ZZSVzvf8JjdkpOTX8DFDMtt39oSik15obQjlS4NKn@vger.kernel.org, AJvYcCXhFBmvTkkXp+V/Vjpb0meRMKu+8ubZdW0/28+/auRAB1fuZ+DXVoQuuNP//4OVyoOA481gNBbDE78=@vger.kernel.org X-Gm-Message-State: AOJu0Yye+UM7XGbHYXwMTr0W8NagOMhZV7uZpm4XpZUPag90iKhSTmop 7bru9MqvWXo68ELXW3LHagc/H3b4WXPn4KTgQ+tz/xfIt3yNLVBPswZBSg2J X-Google-Smtp-Source: AGHT+IGnLpyW7H9Y1VJWXggAltSHjuIV49gVf56bMpwC75H0RQx3h7POr/4wUCoo2fWL/AswOiZ8hA== X-Received: by 2002:a05:600c:5250:b0:42c:c0d8:bf34 with SMTP id 5b1f17b1804b1-432df679bfdmr1778515e9.0.1731625820340; Thu, 14 Nov 2024 15:10:20 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dab789fasm36464265e9.18.2024.11.14.15.10.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 15:10:20 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: l.rubusch@gmx.ch, Lothar Rubusch Subject: [PATCH 06/22] iio: accel: adxl345: add function to switch measuring Date: Thu, 14 Nov 2024 23:09:46 +0000 Message-Id: <20241114231002.98595-7-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241114231002.98595-1-l.rubusch@gmail.com> References: <20241114231002.98595-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replace the powerup / powerdown functions by a generic function to put the sensor in STANDBY, or MEASURE mode. This is needed for several features of the accelerometer. It allows to change e.g. FIFO settings. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 51 ++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 926e397678..bcec3a8e05 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -138,6 +138,37 @@ static int adxl345_write_raw_get_fmt(struct iio_dev *indio_dev, } } +/** + * 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. + * + * Unloading the driver puts the device in standby mode (measuring off). + * + * @st: The device data. + * @en: Enable measurements, else standby mode. + */ +static int adxl345_set_measure_en(struct adxl34x_state *st, bool en) +{ + unsigned int val = 0; + int ret; + + val = (en) ? ADXL345_POWER_CTL_MEASURE : ADXL345_POWER_CTL_STANDBY; + ret = regmap_write(st->regmap, ADXL345_REG_POWER_CTL, val); + if (ret) + return -EINVAL; + + return 0; +} + +static void adxl345_powerdown(void *ptr) +{ + struct adxl34x_state *st = ptr; + + adxl345_set_measure_en(st, false); +} + static IIO_CONST_ATTR_SAMP_FREQ_AVAIL( "0.09765625 0.1953125 0.390625 0.78125 1.5625 3.125 6.25 12.5 25 50 100 200 400 800 1600 3200" ); @@ -158,16 +189,6 @@ static const struct iio_info adxl345_info = { .write_raw_get_fmt = adxl345_write_raw_get_fmt, }; -static int adxl345_powerup(void *regmap) -{ - return regmap_write(regmap, ADXL345_REG_POWER_CTL, ADXL345_POWER_CTL_MEASURE); -} - -static void adxl345_powerdown(void *regmap) -{ - regmap_write(regmap, ADXL345_REG_POWER_CTL, ADXL345_POWER_CTL_STANDBY); -} - /** * adxl345_core_probe() - probe and setup for the adxl345 accelerometer, * also covers the adxl375 and adxl346 accelerometer @@ -242,14 +263,12 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, return dev_err_probe(dev, -ENODEV, "Invalid device ID: %x, expected %x\n", regval, ADXL345_DEVID); - /* Enable measurement mode */ - ret = adxl345_powerup(st->regmap); + ret = devm_add_action_or_reset(dev, adxl345_powerdown, st); if (ret < 0) - return dev_err_probe(dev, ret, "Failed to enable measurement mode\n"); + return dev_err_probe(dev, ret, "Failed to add action or reset\n"); - ret = devm_add_action_or_reset(dev, adxl345_powerdown, st->regmap); - if (ret < 0) - return ret; + /* Enable measurement mode */ + adxl345_set_measure_en(st, true); return devm_iio_device_register(dev, indio_dev); } From patchwork Thu Nov 14 23:09:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13875730 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 317491B652B; Thu, 14 Nov 2024 23:10:22 +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=1731625825; cv=none; b=qZCklLzbz4kZuH3wpwkvVepUmEPbrnEh5V8obVHpsgXmUrypHhhvbA73/DULXdf5jmFpsTQM5MCAw5AS9/hlMMn+rlm1kMUg9uM1yUiW3D2wqDBc70vF4RfzlKrqcnp83HIDePOsjBLLWgfXDZapbXw+ZIu/xR9QGRJ3NgWEx+Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625825; c=relaxed/simple; bh=P6fP/53q4Y/fGhQc7znhU6vSxa5i0hA/JOshgdNgSSc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qtRYv23C4+JVOD3lNcg+RpPwVxGv1AbxNywNl8L1c8z1cOoXCBjW83M0+qVbKGWLKQT9p1X/4Zaczv/7xC3vbeTyLt+5EIxWrZX8Vft4/uFuOdSf3EYrxeYI1G+GENaqYBr66bQL2WmNfgQq1YuLA4KK3Ew0fBhnbhnIf1m2Y1k= 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=h0cet28v; 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="h0cet28v" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-3821ae348e3so97451f8f.1; Thu, 14 Nov 2024 15:10:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731625821; x=1732230621; 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=UmxRbwjCLcQZiy0Ryza4mLE/JTiqL1qzBY9++dH1cFk=; b=h0cet28vdR4G88cQi6N+1RiwHS/ddJjt4TszwL4EVW3UuwenJwAS8hjO3L2+K5G6Pm W2jFgMx6yJT7lQof0gnvf8zD5B9jrFTUPBSSLxv7yffKGmdcAbvcQuN234KnfxTo7Cqt ps6wkCKvHidCZCsBYgZHimMTQeo/rqVAnwFr3n892KUQsQ7Lt7dkNBBPoiza0o+4Vspq x3DuHjwGnG8ezpBCJIvsRJCRzS7sti3YBppfxwxCUA+qGFZy3lDdim2xKnJPfu/UpMGk joI6+crIqAZh6e/+pHRpC5NFmzBXEQGNifsfXYfXq9vu9nHTytnBg86/E8ybnPVIKdva h/DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731625821; x=1732230621; 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=UmxRbwjCLcQZiy0Ryza4mLE/JTiqL1qzBY9++dH1cFk=; b=X2lkWadjUrIn1z8Pe2OR883jWT7Y/ir43ZObPfSWBJt4BTYqbCzGlLypWzIy8lyI04 uTOdRfVa4KSe8fNXsSpgE4/3vLzyRMnvHFivCc1O1zff4yWxLxe0OaBhcIEATKPiwng5 zdS5NMoUqQazf2rvll5l0X9+I8wzAu40/p8pTit9xu6tDQwQXkbElJOqW2X4uwCD1+Wf A2+Pt53DQ2FKsIAINuiQPd07V19/pwgBN7EBtbPS/S73qsyvHb+EGXiD+nhWMzCHO0r3 SSrmbE2vnzGmCVqpdZzqKxfujswkhCZBE0DVyiz0JbBgvow4rJa38nmV+bFfJcbYfz8C U/tQ== X-Forwarded-Encrypted: i=1; AJvYcCV96JxWRkm9Z1xvGDQHPE4b9JK/+hyHRt2xAF2ZOzD7TBfCR8foyy25sp1SPN8/5YqDQIDImJpYgb71gfPE@vger.kernel.org, AJvYcCWiNS1QK5BfIN9i6EAOeDdALO6U/wM1Lfszvh6J9SFCZFPUzUB4oEfHsQ6pA2Zj88mQGSV+4QqZ0B8=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+Nk+BdU0Fb7uZWZjxRsVo7TUPtXtqqB0X5JruQ532yV0AEGvn BjziEthEpr0h6bzN0+8Ob6kyoZvllC0RglbobK9mSaNxJJVY88TX X-Google-Smtp-Source: AGHT+IFa8xPLtLnV/VOR1rKadOtXIa8vEqe+EAZtR1A1XHfdKWs7qy+LTT5qraKkx/sGMZ2J5F88cg== X-Received: by 2002:a05:600c:45d4:b0:431:5632:4480 with SMTP id 5b1f17b1804b1-432df793c51mr1577105e9.6.1731625821365; Thu, 14 Nov 2024 15:10:21 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dab789fasm36464265e9.18.2024.11.14.15.10.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 15:10:20 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: l.rubusch@gmx.ch, Lothar Rubusch Subject: [PATCH 07/22] iio: accel: adxl345: initialize IRQ number Date: Thu, 14 Nov 2024 23:09:47 +0000 Message-Id: <20241114231002.98595-8-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241114231002.98595-1-l.rubusch@gmail.com> References: <20241114231002.98595-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add the possibility to claim an interrupt and init the state structure with interrupt number and interrupt line to use. The adxl345 can use two different interrupt lines, mainly to signal FIFO watermark events, single or double tap, activity, etc. Hence, having the interrupt line available is crucial to implement such features. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345.h | 1 + drivers/iio/accel/adxl345_core.c | 6 ++++++ drivers/iio/accel/adxl345_i2c.c | 2 +- drivers/iio/accel/adxl345_spi.c | 8 ++++++-- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/iio/accel/adxl345.h b/drivers/iio/accel/adxl345.h index 3d5c8719db..cf4132715c 100644 --- a/drivers/iio/accel/adxl345.h +++ b/drivers/iio/accel/adxl345.h @@ -62,6 +62,7 @@ struct adxl345_chip_info { }; int adxl345_core_probe(struct device *dev, struct regmap *regmap, + int irq, int (*setup)(struct device*, struct regmap*)); #endif /* _ADXL345_H_ */ diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index bcec3a8e05..57bc530cc3 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -18,6 +19,7 @@ #include "adxl345.h" struct adxl34x_state { + int irq; const struct adxl345_chip_info *info; struct regmap *regmap; }; @@ -194,12 +196,14 @@ static const struct iio_info adxl345_info = { * also covers the adxl375 and adxl346 accelerometer * @dev: Driver model representation of the device * @regmap: Regmap instance for the device + * @irq: Interrupt handling for async usage * @setup: Setup routine to be executed right before the standard device * setup * * Return: 0 on success, negative errno on error */ int adxl345_core_probe(struct device *dev, struct regmap *regmap, + int irq, int (*setup)(struct device*, struct regmap*)) { struct adxl34x_state *st; @@ -222,6 +226,8 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, st = iio_priv(indio_dev); st->regmap = regmap; + + st->irq = irq; st->info = device_get_match_data(dev); if (!st->info) return -ENODEV; diff --git a/drivers/iio/accel/adxl345_i2c.c b/drivers/iio/accel/adxl345_i2c.c index 4065b8f7c8..604b706c29 100644 --- a/drivers/iio/accel/adxl345_i2c.c +++ b/drivers/iio/accel/adxl345_i2c.c @@ -27,7 +27,7 @@ static int adxl345_i2c_probe(struct i2c_client *client) if (IS_ERR(regmap)) return dev_err_probe(&client->dev, PTR_ERR(regmap), "Error initializing regmap\n"); - return adxl345_core_probe(&client->dev, regmap, NULL); + return adxl345_core_probe(&client->dev, regmap, client->irq, NULL); } static const struct adxl345_chip_info adxl345_i2c_info = { diff --git a/drivers/iio/accel/adxl345_spi.c b/drivers/iio/accel/adxl345_spi.c index 61fd9a6f5f..39e7d71e1d 100644 --- a/drivers/iio/accel/adxl345_spi.c +++ b/drivers/iio/accel/adxl345_spi.c @@ -39,9 +39,13 @@ static int adxl345_spi_probe(struct spi_device *spi) return dev_err_probe(&spi->dev, PTR_ERR(regmap), "Error initializing regmap\n"); if (spi->mode & SPI_3WIRE) - return adxl345_core_probe(&spi->dev, regmap, adxl345_spi_setup); + return adxl345_core_probe(&spi->dev, regmap, + spi->irq, + adxl345_spi_setup); else - return adxl345_core_probe(&spi->dev, regmap, NULL); + return adxl345_core_probe(&spi->dev, regmap, + spi->irq, + NULL); } static const struct adxl345_chip_info adxl345_spi_info = { From patchwork Thu Nov 14 23:09:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13875731 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 195191B6CFD; Thu, 14 Nov 2024 23:10:23 +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=1731625825; cv=none; b=eSYKYIH5kvQbRiHiNxr+PoGIi02PgMrKRdRssEtWnEVZBx4vfEEQrrNSrLinb/fWCU3wPGDIzu0izJFkxDOJCJcx5QUcbRuCPAPUc6TXeDNu240GuAF8RHqTbyv++KzSSkRQrCanqsew0Dah//hAXKMgH2E+h6nnlYwIZ+Kdxpc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625825; c=relaxed/simple; bh=/tlYLFbF5U0jBlu3EZcSiAo93PeJTn0dkOQHzGrZgw8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DFzgZ6B0qhxYX49TUKbzRmhhOpH4/otGelbD4LEMXPd8/zCNiS6BPfsrRyNwhRbQK/5jFxF+M5gZos3phn+c12W+3f5PvQV5OD5WCi1NFhDNEmbvA7xVAvFZwk4elOfSw8znzdKaiELgpjgPcELrvKpTJA7uXhPKV08wLoorcro= 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=ivrb82qg; 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="ivrb82qg" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-3821b30684cso78824f8f.3; Thu, 14 Nov 2024 15:10:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731625822; x=1732230622; 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=0nQfd9oBiFTMVAk4ml+D0pBoUO3sBiue9pIvFVoIsxY=; b=ivrb82qgcj3h6y62T0sWG20Tck+Bsocvb2cN4XYilhP+Fo+rCMP4xIcnFjbl+Lo87F efFJnCTrmhi1+vrG10gHgn9wGWoCoOh7NN6sWOjb10MS1zpq31GFCmK56/whrPfd26Yo eMyNQ/ZrGTMg7C8Gucx9/k6A8mVPjVSpcAlMByCfmc01IT/2bWBTmnOko2aOnxtRhHjg 7vaCAxl4c3NGxGd/VZbwN+64ELDNZxbwlrZ0PB6whhMlXJcBlUnULNl8uv0c5MA2q4jt U6pA4Ibw76HNOFoF84SPMhx9ZndCuiqBETZx8gTPI6ywWDNpMJhA+p5O8sY6C0zj/yba tfAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731625822; x=1732230622; 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=0nQfd9oBiFTMVAk4ml+D0pBoUO3sBiue9pIvFVoIsxY=; b=mFtPAkJ7fSo7i6Kfc5G8PWeeZcj6tIOY8lZIeAVnFfC8t+UmWJB/bK0tuQpm1qmTAA 2RS1YiISlawvfG221IF4uRSDGnB7sdPEhZR0zrHKGv1oDhmWWZDsgEM5IUs6WSVvqO2i qiKkfjoVj5j5rXtmk1RHFsFLwNoc1TAZPa/TP37wAPNy76gkdS8qoYLCwpA8VV5V3Sb9 01bQD7wRfbEYcvnvALqVrjLQt2P49WxSzXx23/TUhCixSknbTekmqb0p+hfpXiOk7Whn VyX17yZ+pbqfLzQY8vVFytm9+S5zsXVc2LJZydX6ZzmT4EEm1/CqjuiUejwvJoh1pqCo fKXg== X-Forwarded-Encrypted: i=1; AJvYcCUjjS0yaCyf7/FPm+WYfOzfLj756fky42PPBWT7K4kBoH6IkmRpglDWqLbQbhsFI2463GGBNXEBwigpKtHh@vger.kernel.org, AJvYcCXlTt4OLhXcgqJi37rmCmIC8HG0Cv5LXZIOvXcMTS0wYfeGL4/8m4dfOFYdV3rKT/3ba3ofxg6O4L4=@vger.kernel.org X-Gm-Message-State: AOJu0YyRwit++myfysxX86BEMdvFe/o6cNxU//JQhj7cNQyW/3rcX2O2 Uyx91CG1o+BUXEAQew6dXzAYN6l6i4ElP5P3SRsmETIgdsd4TSq+ X-Google-Smtp-Source: AGHT+IFn3QBADN+EayYdZk68AeKItCRkqrPOgOoeOilai8nsnbbD1w8ngdKT7stj0dgA/GpydAkyVw== X-Received: by 2002:a05:600c:4710:b0:42c:ba6c:d9a7 with SMTP id 5b1f17b1804b1-432df7878bcmr1569915e9.4.1731625822289; Thu, 14 Nov 2024 15:10:22 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dab789fasm36464265e9.18.2024.11.14.15.10.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 15:10:22 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: l.rubusch@gmx.ch, Lothar Rubusch Subject: [PATCH 08/22] iio: accel: adxl345: initialize FIFO delay value for SPI Date: Thu, 14 Nov 2024 23:09:48 +0000 Message-Id: <20241114231002.98595-9-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241114231002.98595-1-l.rubusch@gmail.com> References: <20241114231002.98595-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add the possibility to delay FIFO access when SPI is used. According to the datasheet this is needed for the adxl345. When initialization happens over SPI the need for delay is to be signalized, and the delay will be used. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345.h | 2 +- drivers/iio/accel/adxl345_core.c | 6 +++++- drivers/iio/accel/adxl345_i2c.c | 2 +- drivers/iio/accel/adxl345_spi.c | 3 +++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/iio/accel/adxl345.h b/drivers/iio/accel/adxl345.h index cf4132715c..4ba493f636 100644 --- a/drivers/iio/accel/adxl345.h +++ b/drivers/iio/accel/adxl345.h @@ -62,7 +62,7 @@ struct adxl345_chip_info { }; int adxl345_core_probe(struct device *dev, struct regmap *regmap, - int irq, + int irq, bool fifo_delay_default, int (*setup)(struct device*, struct regmap*)); #endif /* _ADXL345_H_ */ diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 57bc530cc3..ef3b7d9fb4 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -22,6 +22,7 @@ struct adxl34x_state { int irq; const struct adxl345_chip_info *info; struct regmap *regmap; + bool fifo_delay; /* delay: delay is needed for SPI */ }; #define ADXL345_CHANNEL(index, axis) { \ @@ -197,13 +198,14 @@ static const struct iio_info adxl345_info = { * @dev: Driver model representation of the device * @regmap: Regmap instance for the device * @irq: Interrupt handling for async usage + * @fifo_delay_default: Using FIFO with SPI needs delay * @setup: Setup routine to be executed right before the standard device * setup * * Return: 0 on success, negative errno on error */ int adxl345_core_probe(struct device *dev, struct regmap *regmap, - int irq, + int irq, bool fifo_delay_default, int (*setup)(struct device*, struct regmap*)) { struct adxl34x_state *st; @@ -232,6 +234,8 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, if (!st->info) return -ENODEV; + st->fifo_delay = fifo_delay_default; + indio_dev->name = st->info->name; indio_dev->info = &adxl345_info; indio_dev->modes = INDIO_DIRECT_MODE; diff --git a/drivers/iio/accel/adxl345_i2c.c b/drivers/iio/accel/adxl345_i2c.c index 604b706c29..fa1b7e7026 100644 --- a/drivers/iio/accel/adxl345_i2c.c +++ b/drivers/iio/accel/adxl345_i2c.c @@ -27,7 +27,7 @@ static int adxl345_i2c_probe(struct i2c_client *client) if (IS_ERR(regmap)) return dev_err_probe(&client->dev, PTR_ERR(regmap), "Error initializing regmap\n"); - return adxl345_core_probe(&client->dev, regmap, client->irq, NULL); + return adxl345_core_probe(&client->dev, regmap, client->irq, false, NULL); } static const struct adxl345_chip_info adxl345_i2c_info = { diff --git a/drivers/iio/accel/adxl345_spi.c b/drivers/iio/accel/adxl345_spi.c index 39e7d71e1d..75940d9c1c 100644 --- a/drivers/iio/accel/adxl345_spi.c +++ b/drivers/iio/accel/adxl345_spi.c @@ -12,6 +12,7 @@ #include "adxl345.h" #define ADXL345_MAX_SPI_FREQ_HZ 5000000 +#define ADXL345_MAX_FREQ_NO_FIFO_DELAY 1500000 static const struct regmap_config adxl345_spi_regmap_config = { .reg_bits = 8, @@ -41,10 +42,12 @@ static int adxl345_spi_probe(struct spi_device *spi) if (spi->mode & SPI_3WIRE) return adxl345_core_probe(&spi->dev, regmap, spi->irq, + spi->max_speed_hz > ADXL345_MAX_FREQ_NO_FIFO_DELAY, adxl345_spi_setup); else return adxl345_core_probe(&spi->dev, regmap, spi->irq, + spi->max_speed_hz > ADXL345_MAX_FREQ_NO_FIFO_DELAY, NULL); } From patchwork Thu Nov 14 23:09:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13875732 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 118B81B85C0; Thu, 14 Nov 2024 23:10:24 +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=1731625827; cv=none; b=enJAgxqx3e/xSex3hiJXTWniWkeUYGVSnP9xpTlBG+yvLji7lkYmUMoInGkQaE+sebMNuBu8BSbgduM8NOV9PkoS/BHs5hBPl8IRzHyCcf5kJKBsXYPypFu6zR3xGhuqRf+wfSB1xv+OTKNPEYUhrdf+yuQg/jOlcaEDk7LqWfc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625827; c=relaxed/simple; bh=7+m0CAHrYqU3p6xK2iEjWnKpXgzhg8yUS22idpVYSd4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Kc8RTH3tbwOcaCcsoesiaAeYTxivbfmKjU6qqTrXd7XbYNTtaoVkjddmFu7N13GkMesjvAPiSKRJfB4W+XvDFOXsVE5b63G/Glow5VPbAlcuVzRJ/QZUSEaehnO4hq/bHBFBMS8qThBpcGPwY3aOyc7adWiYUprbdccHVp1IXdA= 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=UNcCOcw1; 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="UNcCOcw1" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-37d4ee8d15aso63654f8f.2; Thu, 14 Nov 2024 15:10:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731625823; x=1732230623; 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=6vv5fixYPGPRNonfE4GIcQOrFio/YyumK9RtjRaJG10=; b=UNcCOcw19SJ/tUAka5mvkey000mygt6JliBrHSk3BFTySR58A0z4AKDuSkfKNAfwOy Esmj1vn2C/zNdWecc/3w2SbWk1h7ts2cxkqS2k4uwnQ6Ty2OzXXqjdUdUrutRi+iGmvA ZVxIpWmqkm3vaOeq2FB1CbRBLiaYU9oG9KZwU+IpypAIvWQcU54YkQMYoEkBKv5I9Nii B9EVLDSjCw5e4U6w7+D12rwGj2bRVfo7ig30ASIqaGqdFeuLi/21d4aJiV9pyua3Nedp yZr9ItCPT7FcP7Fv281O4HuiP+vT65ulP2U/fBSfKWwkDwVXIho1bvSJoCFC6vhNwa9s vsVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731625823; x=1732230623; 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=6vv5fixYPGPRNonfE4GIcQOrFio/YyumK9RtjRaJG10=; b=FWQnwDi+sS2KGzSkK0V9fuoTAAo5hKUCPJNl35jigUqqYVHXaGrVm5e8wfufPXckLt feObA9jgjww3LaA7ASDzsTTHTslC+RLi8tiFqXM/BDyiadunX2zyjULKtDO0XxtkuSVC NyC5xYSRYpjxzehUwUj2/uoLXD4gRCmmlN0E41m74WPsADcwSZyQjf2TsBqLyDaQTxNL DCsdAuIumNJ9NxykOrL8/gZ0oXsMRxhSdRwQoPTk/kYuugHpoKVOcTPWSGeB8xpO/h9U Ih5gDL/WmEsvXblPYmOEKa17BueVuYh0p5fxaLRhlGHW6WZ3/wKcU7dKrM09IWbbiPrC wYpw== X-Forwarded-Encrypted: i=1; AJvYcCVDbovqj1nTsbsghBIGZJBwRJpHPRlrsp/2mHfF+tzY1O1SFPC88Eexob82DxFl5qBf0jl96z1ut2I=@vger.kernel.org, AJvYcCXHQil0vJPQbFE4VafpGxG1MJ1ywxima/X+twb48VHSbK1eXvkcdVfAx4XqSVHX0J3P56O4j1qK3JA45gLC@vger.kernel.org X-Gm-Message-State: AOJu0Yw02AYmOWTJyAXFerP0eBm0dYWrh4UhpeyD2Ma1nfgCGf+Sv5U5 N6raavGJ/tOUbgBspzY4oDS2aUpSZY/7xtInzlPPtdcQuNvPiLXZ X-Google-Smtp-Source: AGHT+IFOwUpNDI5kv+wboKBnODpiq0EuaNS+fc5jPwt0MKQ2RJMGjSWkQ3Ff4S21bxjPSbpcIcd2fw== X-Received: by 2002:a05:600c:1f94:b0:431:4e73:a515 with SMTP id 5b1f17b1804b1-432df72be59mr1660565e9.3.1731625823107; Thu, 14 Nov 2024 15:10:23 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dab789fasm36464265e9.18.2024.11.14.15.10.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 15:10:22 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: l.rubusch@gmx.ch, Lothar Rubusch Subject: [PATCH 09/22] iio: accel: adxl345: unexpose private defines Date: Thu, 14 Nov 2024 23:09:49 +0000 Message-Id: <20241114231002.98595-10-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241114231002.98595-1-l.rubusch@gmail.com> References: <20241114231002.98595-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 For the implementation of features like FIFO-usage, watermark, single tap, double tap, freefall, etc. most of the constants do not need to be exposed in the header file, but are rather of private nature. Reduce namespace pollution by moving them to the core source file. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345.h | 33 +--------- drivers/iio/accel/adxl345_core.c | 108 +++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 31 deletions(-) diff --git a/drivers/iio/accel/adxl345.h b/drivers/iio/accel/adxl345.h index 4ba493f636..c9d2a82fa6 100644 --- a/drivers/iio/accel/adxl345.h +++ b/drivers/iio/accel/adxl345.h @@ -8,38 +8,9 @@ #ifndef _ADXL345_H_ #define _ADXL345_H_ -#define ADXL345_REG_DEVID 0x00 -#define ADXL345_REG_OFSX 0x1E -#define ADXL345_REG_OFSY 0x1F -#define ADXL345_REG_OFSZ 0x20 -#define ADXL345_REG_OFS_AXIS(index) (ADXL345_REG_OFSX + (index)) -#define ADXL345_REG_BW_RATE 0x2C -#define ADXL345_REG_POWER_CTL 0x2D -#define ADXL345_REG_DATA_FORMAT 0x31 -#define ADXL345_REG_DATAX0 0x32 -#define ADXL345_REG_DATAY0 0x34 -#define ADXL345_REG_DATAZ0 0x36 -#define ADXL345_REG_DATA_AXIS(index) \ - (ADXL345_REG_DATAX0 + (index) * sizeof(__le16)) - -#define ADXL345_BW_RATE GENMASK(3, 0) -#define ADXL345_BASE_RATE_NANO_HZ 97656250LL - -#define ADXL345_POWER_CTL_MEASURE BIT(3) -#define ADXL345_POWER_CTL_STANDBY 0x00 - -#define ADXL345_DATA_FORMAT_RANGE GENMASK(1, 0) /* Set the g range */ -#define ADXL345_DATA_FORMAT_JUSTIFY BIT(2) /* Left-justified (MSB) mode */ -#define ADXL345_DATA_FORMAT_FULL_RES BIT(3) /* Up to 13-bits resolution */ +/* Regs and bits needed to be declared globally */ +#define ADXL345_REG_DATA_FORMAT 0x31 /* r/w Data format control */ #define ADXL345_DATA_FORMAT_SPI_3WIRE BIT(6) /* 3-wire SPI mode */ -#define ADXL345_DATA_FORMAT_SELF_TEST BIT(7) /* Enable a self test */ - -#define ADXL345_DATA_FORMAT_2G 0 -#define ADXL345_DATA_FORMAT_4G 1 -#define ADXL345_DATA_FORMAT_8G 2 -#define ADXL345_DATA_FORMAT_16G 3 - -#define ADXL345_DEVID 0xE5 /* * In full-resolution mode, scale factor is maintained at ~4 mg/LSB diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index ef3b7d9fb4..aac49b3d03 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -18,6 +18,114 @@ #include "adxl345.h" +/* ADXL345 register map */ +#define ADXL345_REG_DEVID 0x00 /* r Device ID */ +#define ADXL345_REG_THRESH_TAP 0x1D /* r/w Tap Threshold */ +#define ADXL345_REG_OFSX 0x1E /* r/w X-axis offset */ +#define ADXL345_REG_OFSY 0x1F /* r/w Y-axis offset */ +#define ADXL345_REG_OFSZ 0x20 /* r/w Z-axis offset */ +#define ADXL345_REG_DUR 0x21 /* r/w Tap duration */ +#define ADXL345_REG_LATENT 0x22 /* r/w Tap latency */ +#define ADXL345_REG_WINDOW 0x23 /* r/w Tap window */ +#define ADXL345_REG_THRESH_ACT 0x24 /* r/w Activity threshold */ +#define ADXL345_REG_THRESH_INACT 0x25 /* r/w Inactivity threshold */ +#define ADXL345_REG_TIME_INACT 0x26 /* r/w Inactivity time */ +#define ADXL345_REG_ACT_INACT_CTRL 0x27 /* r/w Axis enable control for */ + /* activity and inactivity */ + /* detection */ +#define ADXL345_REG_THRESH_FF 0x28 /* r/w Free-fall threshold */ +#define ADXL345_REG_TIME_FF 0x29 /* r/w Free-fall time */ +#define ADXL345_REG_TAP_AXIS 0x2A /* r/w Axis control for */ + /* single tap or double tap */ +#define ADXL345_REG_ACT_TAP_STATUS 0x2B /* r Source of single tap or */ + /* double tap */ +#define ADXL345_REG_BW_RATE 0x2C /* r/w Data rate and power */ + /* mode control */ +#define ADXL345_REG_POWER_CTL 0x2D /* r/w Power-saving features */ +#define ADXL345_REG_INT_ENABLE 0x2E /* r/w Interrupt enable control */ +#define ADXL345_REG_INT_MAP 0x2F /* r/w Interrupt mapping */ + /* control */ +#define ADXL345_REG_INT_SOURCE 0x30 /* r Source of interrupts */ +/* NB: ADXL345_REG_DATA_FORMAT 0x31 r/w Data format control, + * (defined in header) + */ + +#define ADXL345_REG_XYZ_BASE 0x32 /* r Base address to read out */ + /* X-, Y- and Z-axis data 0 */ + /* and 1 */ +#define ADXL345_REG_DATA_AXIS(index) \ + (ADXL345_REG_XYZ_BASE + (index) * sizeof(__le16)) +/* NB: having DATAX0 and DATAX1 makes 2x sizeof(__le16) */ + +#define ADXL345_REG_FIFO_CTL 0x38 /* r/w FIFO control */ +#define ADXL345_REG_FIFO_STATUS 0x39 /* r FIFO status */ + +/* DEVID(s) */ +#define ADXL345_DEVID 0xE5 + +/* FIFO */ +#define ADXL345_FIFO_CTL_SAMLPES(x) (0x1f & (x)) +#define ADXL345_FIFO_CTL_TRIGGER(x) (0x20 & ((x) << 5)) /* set 1: INT2, 0: INT1 */ +#define ADXL345_FIFO_CTL_MODE(x) (0xc0 & ((x) << 6)) + +/* INT_ENABLE, INT_MAP, INT_SOURCE bits */ +#define ADXL345_INT_DATA_READY BIT(7) +#define ADXL345_INT_SINGLE_TAP BIT(6) +#define ADXL345_INT_DOUBLE_TAP BIT(5) +#define ADXL345_INT_ACTIVITY BIT(4) +#define ADXL345_INT_INACTIVITY BIT(3) +#define ADXL345_INT_FREE_FALL BIT(2) +#define ADXL345_INT_WATERMARK BIT(1) +#define ADXL345_INT_OVERRUN BIT(0) + +#define ADXL34X_S_TAP_MSK ADXL345_INT_SINGLE_TAP +#define ADXL34X_D_TAP_MSK ADXL345_INT_DOUBLE_TAP + +/* INT1 or INT2 */ +#define ADXL345_INT1 0 +#define ADXL345_INT2 1 + +/* BW_RATE bits - Bandwidth and output data rate. The default value is + * 0x0A, which translates to a 100 Hz output data rate + */ +#define ADXL345_BW_RATE GENMASK(3, 0) +#define ADXL345_BW_LOW_POWER BIT(4) +#define ADXL345_BASE_RATE_NANO_HZ 97656250LL + +/* POWER_CTL bits */ +#define ADXL345_POWER_CTL_STANDBY 0x00 + +/* NB: + * BIT(0), BIT(1) for explicit wakeup (not implemented) + * BIT(2) for explicit sleep (not implemented) + */ +#define ADXL345_POWER_CTL_MEASURE BIT(3) +#define ADXL345_POWER_CTL_AUTO_SLEEP BIT(4) +#define ADXL345_POWER_CTL_LINK BIT(5) + +/* DATA_FORMAT bits */ +#define ADXL345_DATA_FORMAT_RANGE GENMASK(1, 0) /* Set the g range */ +#define ADXL345_DATA_FORMAT_JUSTIFY BIT(2) /* 1: left-justified (MSB) mode, 0: right-just'd */ +#define ADXL345_DATA_FORMAT_FULL_RES BIT(3) /* Up to 13-bits resolution */ +/* NB: BIT(6): 3-wire SPI mode (defined in header) */ + +#define ADXL345_DATA_FORMAT_SELF_TEST BIT(7) /* Enable a self test */ +#define ADXL345_DATA_FORMAT_2G 0 +#define ADXL345_DATA_FORMAT_4G 1 +#define ADXL345_DATA_FORMAT_8G 2 +#define ADXL345_DATA_FORMAT_16G 3 + +#define ADXL345_REG_OFS_AXIS(index) (ADXL345_REG_OFSX + (index)) + +/* The ADXL345 include a 32 sample FIFO + * + * FIFO stores a maximum of 32 entries, which equates to a maximum of 33 + * entries available at any given time because an additional entry is available + * at the output filter of the device. + * (see datasheet FIFO_STATUS description on "Entries Bits") + */ +#define ADXL34x_FIFO_SIZE 33 + struct adxl34x_state { int irq; const struct adxl345_chip_info *info; From patchwork Thu Nov 14 23:09:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13875733 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD24D1BBBD0; Thu, 14 Nov 2024 23:10:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625828; cv=none; b=GNmoXx8F785bktntuXIQJd9kkUcEJSZ/B2CDvZGfai7VjHVrPgX8K4DCleQjbRZrRJEIi8PNRMhqSutx4lZn/P5z+Bz4GmhsMIDRA8dOkKCwCyoSnh9EIC0DV+SY5RaI+bKDYcpn0ozNQaLpsf0V9Z1LGy6c9WQQRmZH9b+91tc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625828; c=relaxed/simple; bh=BJud18EDREVXZJkzHnfXHc1yREntMLZOOXob7nNkI7M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dlilUYS/n+nd3GmD5xbuss1R3Zt7eJfCvzBAije7gGb4hwMosvExwx7GkPYGQ75MPjIBRKGnIfOD18GekVhGE4+WheI1TPxvPWCB9F7mGkroqcQUPmkcWOYiXEJ/G/SRzT3acNSpSPrZ1V9Izd6xTlCsNRZNC+WFp+LdYUQhygw= 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=Oxx1oDNO; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Oxx1oDNO" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-43152fa76aaso1070055e9.1; Thu, 14 Nov 2024 15:10:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731625824; x=1732230624; 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=J7GEt5vc7jPXUU2i44DeVWa773kql6tCMRoKXi+rtmQ=; b=Oxx1oDNOy/+QXpy8vr2QYOu1ljoxR4DXIrZvNbBhooTQc9gSC5Oiu2qfOwvfx+TtEO Va87TBk/DMNxvOAvxIQD6tjPVTPkDWr3aJ6tZaeqntRUbjAo+2pzyJWw2yNcezTW38mH bSbdztr8viE4WMW+p/7ABgG/FOtc2Lfqeh/IDzGHfMqbx05DFPU71Zi3EBLMKpvKHeoL gw5uc1yGabE4j09uH2iZ9hWapw3Od2VfcRGmBiowcA9AUW+BWGj0z/Yl9z5kY5PXUqkf M+JBBn3S1Wlo9nOYq0OhoRNsHueYyq+bLDrr1Yv65OYvCf6mwsP8i9h+OXK/MRpD1+ls qf+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731625824; x=1732230624; 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=J7GEt5vc7jPXUU2i44DeVWa773kql6tCMRoKXi+rtmQ=; b=f390EjQZCBEJAUeJRq+JyN/3kirf0SgdWKqwZt/+9YF4rwGwvmvi5tBHTecxKE+OfA fWZaIguA1Qi7SFnqrMbs9Gl5MXKmxt3nzpqUitL4bj5XwZ1A5dpZ/tFQ5kii5ldFGQ56 hr3QRTy+hC+0hAeW0hbrRStYH9bYJv997PHFv9YJlHkPRu9oCNdc2AV819qZIZQteppW yzniah76ycpr6JDlnuUvmW/cyfPSj9MkC+lPK3ZUd3UAWzGv23mDI+1ceHvE8dDsstSk iiilE6o9BpXwiC/5DnMcnkvCQYW7YQF0/4x2PHBTri2qv3rVuL4lkfjD37wSJiQj76wE lu3A== X-Forwarded-Encrypted: i=1; AJvYcCUBYZZr+YxPDwkxaWvHyd1QtK5QrgOUb66/7IPPM5q9EI6y1L84Lad1kuBzUNwstKFG6dYD3pIBkng=@vger.kernel.org, AJvYcCUQjZKbJ53hPWeSSynfP7iEcvWm3Z17OeBUXhxAnxdmWF3j4KkuPSaq1IW83UBJMDFsDCQHXiL5YBZr/RmP@vger.kernel.org X-Gm-Message-State: AOJu0YwvbC6WZddQNgokofHraLbs/oR+ewKfU6e3wA39WKlS7Igm9/WE X9uRKDbXXtJjzjlvCSrGy+137sobkJRdHQMd1RrBPXVopvHvMf4l X-Gm-Gg: ASbGncvKX7cFqgUNPE24MZ+J40ddQzJG21mMI0pKIcD+nnwJuA1HhOLaNIp7ADLrNs4 8FBFHMTOdBzpmcizJooeSYhjyctqYRwnmFvzpRJc1w3UtH64urEG9Q+uZYlNhdVXrGJVIGhbveQ pi2ApdLPB23m8Ep5ByfdT+WATYVEgzsCzzY70d+7ZaCSSKoyimPDNgb7dsqa1M5H8fcPR7cfX/k u3vU/Mvq1AKzwaSKvXtvtsgyrxD9DyEJSI/0SbXuH6+3I2tCH3nKfcSy0tmaHbMZJ8AsQo/WGjs YjZ3+MZcnfDQTYNxM64/9/2RJ8Yf X-Google-Smtp-Source: AGHT+IFcjQSnNlUFYpmye+fKVSoLZiKP1rGGoo7/HK9K+9eGATt3VcPLXYElzMwwkcABZ7BHTvzRnA== X-Received: by 2002:a05:600c:3b97:b0:430:4db0:3ffd with SMTP id 5b1f17b1804b1-432df78c83amr1587255e9.4.1731625823965; Thu, 14 Nov 2024 15:10:23 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dab789fasm36464265e9.18.2024.11.14.15.10.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 15:10:23 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: l.rubusch@gmx.ch, Lothar Rubusch Subject: [PATCH 10/22] iio: accel: adxl345: set interrupt line to INT1 Date: Thu, 14 Nov 2024 23:09:50 +0000 Message-Id: <20241114231002.98595-11-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241114231002.98595-1-l.rubusch@gmail.com> References: <20241114231002.98595-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The adxl345 sensor uses one of two interrupt lines, INT1 or INT2. The interrupt lines are used to signal feature events such as watermark reached, single tap, double tap, activity, etc. Only one interrupt line is used and must be configured. The adxl345 default is to use INT1 and in many installations only INT1 is even connected. Therefore configure INT1 as the sensor's default interrupt line. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index aac49b3d03..949847fad2 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -131,6 +131,7 @@ struct adxl34x_state { const struct adxl345_chip_info *info; struct regmap *regmap; bool fifo_delay; /* delay: delay is needed for SPI */ + u8 intio; }; #define ADXL345_CHANNEL(index, axis) { \ @@ -343,6 +344,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, return -ENODEV; st->fifo_delay = fifo_delay_default; + st->intio = ADXL345_INT1; indio_dev->name = st->info->name; indio_dev->info = &adxl345_info; From patchwork Thu Nov 14 23:09:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13875734 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B9491BC9EE; Thu, 14 Nov 2024 23:10:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625830; cv=none; b=nwUIcpNS8uaZVjztbRp/FcyUxtzwsMvoOQwbNmqhPHc+m5rH9ggjglhsyS6IETd59PQGd7Ala+q7gZu9sD7i99RG6PtJuErT6EJwBEjEDiRbF5GPBfV/xrnAreck/KHY3tyaDvRhx1CBAK4XKtg6U1zjLbAgeITKbZVjk+b8fK8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625830; c=relaxed/simple; bh=ev2Wu/gXNSjSOij9PQO/6WznPrulhD2PnlcIqOoQrTU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eTE1jz3iQ0k7NXX8zNVKamnW/RQo7WMhyoSGsKri4PJdGofIK2VbnBsX0rAyeuTMTRzoE8CTGbDm6KPXbDq0T8DUx5vWw2be/0lKCWHJl+2Vz52L/ZOPouidV8JHVygKmi+2dE0aeUFclQHXOHO5AIYmGEOlc+chR+QbVfey++s= 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=fyLyteaL; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fyLyteaL" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-43160c5bad8so625735e9.3; Thu, 14 Nov 2024 15:10:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731625826; x=1732230626; 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=MIqKzIejoyfItsKpIgyA1dC0uX/NO9YX2lqUdNJFK/Y=; b=fyLyteaLJ9juT/+PmM06MrY9QsWdG1vLWHLSiJomtb5EaV6aH+qiQqisrUKBN7Winr tohCe7Y13igiokE4rOvoIJHmTGdD02gIQDVslpSMZmETdRtiDoajfVKK+af7PZ+73q7Q XGzOYCB51zdBhBYD9c9qaBjdMc5xW8QqJ/HypxbWPQVqYja0Xjnt0ABdbeeC/ufthQ6I 2+CTzcf/ofLQe+tMWSC1txmh23IGgq6P/0Trux2f/l7WOz1tStXERXN5TSm5g3SzuaZE Uar/meJAAF/TqqL3sNJLGq2gSggJ7qgya7YQqw6L3Q2o7pk7yrehLH1tCr6Y/MuUbtcI oYew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731625826; x=1732230626; 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=MIqKzIejoyfItsKpIgyA1dC0uX/NO9YX2lqUdNJFK/Y=; b=hPk4AJfiMA8Nr6uryZbheWtEBZGWDmWYwAamQVkMgKeuDE9yjrcNtbodknS+zcEk+G dxaKT1FlHCq1qNQ5gaBn1mjbdu22/qZ7fVZl57XY52jEgOKifosujbX/h5nn/ZuSACVI QrJgvgxy/16GPdT5EG204s4Jw6H5MIVYUJfmzYfkCeqiqtjRgGJPOfT51u32tkebfgWh kM+hu+Dx6JzPDtxXvjRq4/I8B8eahePWJaZPVKz7ixlLjq+YTaifNJHrKQaH4LyKJ1hu OZzbk63Av7/Z1XuyO8+t4ngXOeepYMiODGnOy4HgWcqgi+G0wbG88VNJTavpOZmMxttp ti7w== X-Forwarded-Encrypted: i=1; AJvYcCU/yN0bEq13gx12PF5lCkDrfZrIxxR4Tw0sai+vxL+Os+dKwAVq8X5zilJ0TfAtdaMy0Kvo0nOepyXafbu8@vger.kernel.org, AJvYcCXZiIS9iOnc6IBJDOHlF2ceUQ2IZM6PuCiOJwKZVVc1YMGV3QWcaqnVMxIX21E3tGZJAoEApCOKFIM=@vger.kernel.org X-Gm-Message-State: AOJu0Ywr/x8rnPJQNEM6Cwu5JgaUz/0TVuEIaQQweDGtuM9Zlg9igXah ZZBj2/LvcLMvSWe1CmWEwr6aoG/mqL2E+mytRZAJc1xXsRUrcD82 X-Google-Smtp-Source: AGHT+IEyRmOqna4BTj63MSyNIFOcJGxI/aFIyTftVp+alwqZ6kJ7NbhPXKooO/CAyfDaLlfkwOz1Ew== X-Received: by 2002:a05:600c:1991:b0:42c:ba83:3efa with SMTP id 5b1f17b1804b1-432df6841femr1834715e9.0.1731625825488; Thu, 14 Nov 2024 15:10:25 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dab789fasm36464265e9.18.2024.11.14.15.10.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 15:10:25 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: l.rubusch@gmx.ch, Lothar Rubusch Subject: [PATCH 11/22] iio: accel: adxl345: import adxl345 general data Date: Thu, 14 Nov 2024 23:09:51 +0000 Message-Id: <20241114231002.98595-12-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241114231002.98595-1-l.rubusch@gmail.com> References: <20241114231002.98595-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use struct adxl34x_platform_data from the included public header of the input driver for ADXL34x with the following argumentation for this approach: - The iio driver for the ADXL34x covers features also implemented in the older input driver. The iio driver will implement the same features but can also benefit from including the common header and struct adxl34x_platform_data. Once complete, the input driver could be faded out. - The fields in the input driver are identical to the fields the IIO implementation will need. Including the header over reimplementing, avoids a duplication of almost identical headers in IIO and iio. - The header for the input driver is public. It provides a public interface for adxl34x related implementation and is not private to the input system. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 949847fad2..57ecf33d60 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -16,6 +16,8 @@ #include #include +#include + #include "adxl345.h" /* ADXL345 register map */ @@ -126,10 +128,15 @@ */ #define ADXL34x_FIFO_SIZE 33 +static const struct adxl34x_platform_data adxl345_default_init = { + .tap_axis_control = ADXL_TAP_X_EN | ADXL_TAP_Y_EN | ADXL_TAP_Z_EN, +}; + struct adxl34x_state { int irq; const struct adxl345_chip_info *info; struct regmap *regmap; + struct adxl34x_platform_data data; /* watermark, fifo_mode, etc */ bool fifo_delay; /* delay: delay is needed for SPI */ u8 intio; }; @@ -329,6 +336,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, unsigned int data_format_mask = (ADXL345_DATA_FORMAT_RANGE | ADXL345_DATA_FORMAT_FULL_RES | ADXL345_DATA_FORMAT_SELF_TEST); + const struct adxl34x_platform_data *data; int ret; indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); @@ -344,6 +352,16 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, return -ENODEV; st->fifo_delay = fifo_delay_default; + data = dev_get_platdata(dev); + if (!data) { + dev_dbg(dev, "No platform data: Using default initialization\n"); + data = &adxl345_default_init; + } + st->data = *data; + + /* some reasonable pre-initialization */ + st->data.act_axis_control = 0xFF; + st->intio = ADXL345_INT1; indio_dev->name = st->info->name; From patchwork Thu Nov 14 23:09:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13875735 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.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 CEDA51BD00A; Thu, 14 Nov 2024 23:10:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625830; cv=none; b=jJDA9lzCURsXQbMAl1VASq0Y5dq1ygUsfaaFMxpHusmamOevnOcBD1cL4KsBNbSL8xmeLpEx3VT2sD3DT6OnKaEmNoRXoAohm+kn0Fp8xyMOqKUfq8lUq8V5D1BWGnJLHu4bBMNcsWdsJ1muJS+8lc8ZNXrBNy3ZvvLr69oSM5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625830; c=relaxed/simple; bh=FnUMRnVfqPwzn2GWw4P4fw/zWcW37qtrq67wAyadi3o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QxJrxQdMrL7Aroc1SOsRKrAsSrthlQqyOuVUDJXyMg+hDitoEbhCoQS35l46zDtUbMLkwOrifM0DvHPCiVdvGFWoHWfWwSz33H5S0arrmq946RamdSsmdl1SrgOY2uo4S3N3dUIAxnuxEYff6kAQkzpmJ6W+wAVbCNxtjvEMFrg= 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=Nx3OCFW/; arc=none smtp.client-ip=209.85.128.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="Nx3OCFW/" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-43152fa76aaso1070095e9.1; Thu, 14 Nov 2024 15:10:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731625827; x=1732230627; 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=252n9N3GvWh31+SjJ6a2GxPMS/1QTtURFdXXkWDSmNI=; b=Nx3OCFW/E8Y6WhD3CuxMhGgjPeeao0PPpeuHTSqXFDGIrwIVww3XzPmel3krzOc0tz hG81trKaB1IgVG+YzRKq1Ycq/0Zox2aQBQ/WPo2+V6BoLMo7rvXgp1xjoIYMhNR/qhE9 IyY+JdpVJkca9iSOfhrxo3SzhXTpEPo60pFvr4YFhq0ALPASNp4NGBEspWes8wDcJBZC SrMhWAG2lyiFpT39qek0AyJZ+AUB7WQ7zo+h0jz5Smbwfp6PEtCbk8CbNYSmTTbZVnNl A0LHH3OYnnPkVOEffPmQLbJGyhwgJsbvBDy9hp+oQ34A5PdcbAxdGMcUxC+8w8dp6c7K xB/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731625827; x=1732230627; 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=252n9N3GvWh31+SjJ6a2GxPMS/1QTtURFdXXkWDSmNI=; b=L46PaqfLYv7sDXcBAuaIkfl7lTArti1IorOwqBkux7MWg7Ye8Fh7bXE11fpDQlgmuy 3/eMtuKVp4mkQkEU8FJ7qF9QL9Oms1PCI+5y1G0lfO5EbJAYei1BHwCUngJwLo/ag85z 130eWF3KkZYCuHkya0TfrcaccR/uJI50FvSK9antble/uTvyz/Vs3yVX5DGTsRJm9QU5 dOgUItRUQ8XwaWbae3KMt/bA5Rbuk34k1cqNvAY/Oi3vBSMuk1Ucp+aQ+f6TQlU9byZN ytltrWnxDDq28CRw0vM7Lx0PzN9M0XfNAnYwcTkQqUUXP38BXbd5xiYo13U/Lm1t45Pw svpw== X-Forwarded-Encrypted: i=1; AJvYcCUPlXGuIMmI128iqlUMDPbdMWPZQKy5mr0wQNQ49/xawzluN4Zb3As0qseVJk1XUcjh54rPIG4GzJU=@vger.kernel.org, AJvYcCURLvQqx5JYLOZTpLmiNbJGKk3hDrhEG4uHBHYMXoiqOIdXvzIkPzTezCfQcbQ0Yf2qbllcZkbEzj9fQlIK@vger.kernel.org X-Gm-Message-State: AOJu0YzJNDixeuy4gb/kUPz9QeXnsxrS896Iw/6dexLnJOa2IHOzt2J1 GFBdEkeilVrukENMxt/yZGQolGhZPiLSd1TLqAnVg0+28KCjRoxC X-Gm-Gg: ASbGncuWsBb9GsYdM1EvHleuviGX++KJfKuex/7R1c6CoE67N6rXrcZf6iMx5gosD3R 63UDhcklh/+EsQUP2o5aEENm8pFgb1ffUkk/uGCuHgPqIiYDv4Z6vAxODFG//a+NavjIjWWqQ6k djPtj3Hnd4Wq1xPcbX1yNsFFocMXWP1gsyM84MrGmawAVu8K520BUR0ipRaB6Xe9wJUCpDdH2QO zhN2YIQgrfrnZOWJrnazaLt0s7IYOxqZVU2Ek0xDrt16IXZZZFlt8VGY7F2Ho1/ZPonGPFxdni3 qDtL2gsjO97GJ8EEgju2PGtMxVGE X-Google-Smtp-Source: AGHT+IHESrZpJmgl/AzIXO1ZP1opZt2LD4GqP7iZbH22OZDYNRPd5BWgXMr4OTGD+8bFaSFAoXu1xg== X-Received: by 2002:a05:600c:3588:b0:42c:ba61:d20b with SMTP id 5b1f17b1804b1-432df728caamr1681875e9.3.1731625827064; Thu, 14 Nov 2024 15:10:27 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dab789fasm36464265e9.18.2024.11.14.15.10.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 15:10:26 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: l.rubusch@gmx.ch, Lothar Rubusch Subject: [PATCH 12/22] iio: accel: adxl345: elaborate iio channel definition Date: Thu, 14 Nov 2024 23:09:52 +0000 Message-Id: <20241114231002.98595-13-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241114231002.98595-1-l.rubusch@gmail.com> References: <20241114231002.98595-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Make the channel definition ready to allow for feature implementation for this accelerometer sensor. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 36 +++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 57ecf33d60..7e607534df 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -141,21 +141,33 @@ struct adxl34x_state { u8 intio; }; -#define ADXL345_CHANNEL(index, axis) { \ - .type = IIO_ACCEL, \ - .modified = 1, \ - .channel2 = IIO_MOD_##axis, \ - .address = index, \ - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ - BIT(IIO_CHAN_INFO_CALIBBIAS), \ - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ - BIT(IIO_CHAN_INFO_SAMP_FREQ), \ +#define ADXL34x_CHANNEL(index, reg, axis) { \ + .type = IIO_ACCEL, \ + .address = (reg), \ + .modified = 1, \ + .channel2 = IIO_MOD_##axis, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_CALIBBIAS), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .scan_index = (index), \ + .scan_type = { \ + .sign = 's', \ + .realbits = 13, \ + .storagebits = 16, \ + .shift = 0, \ + .endianness = IIO_LE, \ + }, \ } +enum adxl34x_chans { + chan_x, chan_y, chan_z, +}; + static const struct iio_chan_spec adxl34x_channels[] = { - ADXL345_CHANNEL(0, X), - ADXL345_CHANNEL(1, Y), - ADXL345_CHANNEL(2, Z), + ADXL34x_CHANNEL(0, chan_x, X), + ADXL34x_CHANNEL(1, chan_y, Y), + ADXL34x_CHANNEL(2, chan_z, Z), }; static int adxl345_read_raw(struct iio_dev *indio_dev, From patchwork Thu Nov 14 23:09:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13875736 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DAC2C1BD4F1; Thu, 14 Nov 2024 23:10:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625831; cv=none; b=uoLD0rFbs0DA2FhUAJ2E8/LJUnSa0F/CKkmaRv66YhCJhPHF6in3XgCfamALKe6/I1Z1x0BmZIGOCrTVyxQzWKe6jgeIt2JlFhgitsSa9HLFgd9lmdY13osNgex2LPXA0zrE8mztsa+JRwNqgkU78r25GjPEQ68qnybyvqlzCMU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625831; c=relaxed/simple; bh=Qe87npJOJ+/IaVN9tHz550rK0cIOqPjrDDeeKh3+79w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=u47tKlQThFkl/W8vavwZedRh5L4mkEid9PPzVTpvbf0fjDSa/gk5hs0Ktv5Z88g7YGzw6V40Ucfk0MXDF/FUKrlAXGZqzsf0/CYrSknDTBiUzmXDABfvP+GPsg4dJTWUmGKgFY4jbmPcBbdyPtiKeRxPdWn7yKiAKjemgw5oVkc= 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=OOOlXBn0; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OOOlXBn0" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-43152fa76aaso1070105e9.1; Thu, 14 Nov 2024 15:10:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731625828; x=1732230628; 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=i5fLWgiG6X9Z8EV7WoH09eywkpTwsg6we3ZixqL9jKU=; b=OOOlXBn0vFhhoJLaOT//LtW90uInVvAQ2Et/plvid0N1Xs64vc8DwmM699lDyldb/n 5X8JsLOdZr1WLZ5aS06SpWtPei4AMKaZZ+bdgoj+HrsLZAL2SsqNu7DqdEb6ywffEgm4 0QImLavKjFuBRL6NJ2QD3J2PKewyKH+MFjiHuSqrgX78sq06Dru9TJL4bqZUBsJac+oE n3MTBCl/KUS3BRIVGIHrhBVmX9JrslXaXaEguLYU4MiKmfYmRwHqhsAB9pIs8ZfURf0k QxtO5LIx2kV+dVaT+oiTlnoTbJBw5AXpIoW0h4ggLIZGt7UAIWd3hrSC3byLRPIomHhu /Kzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731625828; x=1732230628; 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=i5fLWgiG6X9Z8EV7WoH09eywkpTwsg6we3ZixqL9jKU=; b=cAD3Fh49JbpNJMr1oVsZYyrsqcVEweMov3nPqWmV9To0VhimbNw8QLvILFCf2eaqVD QXM6e9jZMa+YMg/Qs9q4iBaVwD9h42mBY0AI3MsrzvgHCTnnVvGqFRdzqNwYEJWUVqL8 NIOVOREaQ2ln3LrHve7ked0RIuQCkKRQQKfgAGqpBEpY/KS30AodVRHRu32c+QLXGMEZ hqk+Rr/Zs2o0WSmodBSMMwzbXUOfxOJiG8oTxkL0XFQdo34vlRmxSgaYsF8wgQwTNqSw J28uGzJkxWEYaC1Mv00nG3+wgeVv4heAd83vcNEu17hLQ/mljNSjm9d84TloMZ08pb22 8zgw== X-Forwarded-Encrypted: i=1; AJvYcCXCDG/qpfiK34xwKoj5dc0sjjXZ4Ak1P0ASk0M1S8VzJWk4v9fP6/Q0GnY25OFwiBql5T4mmfDM754YDpRl@vger.kernel.org, AJvYcCXQcDKFaRoj5yoDOPP3cQfWo7dYN2spcA5PvJBKhKQMqGF5QpLueabSJL38NH2w60ZbHsTtoSj1IbU=@vger.kernel.org X-Gm-Message-State: AOJu0YyRaKMGvFL4fu9JWeP1ok2chfXAiSrUHLSjNQIMgdw+aiCrfBMT tyc0dkkJwYdLQ9dpJD6xTIr3NwEEAFZaUyeAf1cdifYVDLNGONMM X-Gm-Gg: ASbGncvlVDLbCFjkRCkO2EOiptxp3sJ4mMpleKidq+lkYiDVlNMTXj6+PaIAO9tmxLy hlCKUHdOVFjRpWrnJaiuDFsNjmGuiuDEFbftU5XmmU5QwCVI6ZFyuyvIxjrM0ECQzD/aK1L7z38 UByXZOXBv/uXLmVLyG1cUgQMvSG5DSbep0+YiPtLrbxa3MgY/SXAVf1WcDfDKfZw/oVb6DbpTsL Vm130Az9RJIFGFFJ7TpFqs+H8Gu0tAEM5E4YqdP2h8Pu6zd1YCb7xiXGHSdF0FG1IujGmY98QmX DxYvSM+dC4HZanJY0pi6Hmw+koA0 X-Google-Smtp-Source: AGHT+IHTDVs5sk34sIs2Md1tJEYvnpBZX6JiMRYXVtnpy7VaMS2MbG0JvK6Q9ftI01DOLCZCREuPLw== X-Received: by 2002:a05:600c:354b:b0:42c:aeee:80b with SMTP id 5b1f17b1804b1-432df797e02mr1637045e9.8.1731625827978; Thu, 14 Nov 2024 15:10:27 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dab789fasm36464265e9.18.2024.11.14.15.10.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 15:10:27 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: l.rubusch@gmx.ch, Lothar Rubusch Subject: [PATCH 13/22] iio: accel: adxl345: add trigger handler Date: Thu, 14 Nov 2024 23:09:53 +0000 Message-Id: <20241114231002.98595-14-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241114231002.98595-1-l.rubusch@gmail.com> References: <20241114231002.98595-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add basic setup to the interrupt handler function and prepare probe for using and not using the FIFO on the adxl345. Interrupt handler and basic structure integration is needed to evaluate interrupt source register. This is crucial for implementing further features of the sensor. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 106 ++++++++++++++++++++++++++++++- 1 file changed, 104 insertions(+), 2 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 7e607534df..dbd07308a7 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -15,6 +15,9 @@ #include #include +#include +#include +#include #include @@ -137,6 +140,7 @@ struct adxl34x_state { const struct adxl345_chip_info *info; struct regmap *regmap; struct adxl34x_platform_data data; /* watermark, fifo_mode, etc */ + u8 int_map; bool fifo_delay; /* delay: delay is needed for SPI */ u8 intio; }; @@ -300,6 +304,10 @@ static void adxl345_powerdown(void *ptr) adxl345_set_measure_en(st, false); } +static const struct iio_dev_attr *adxl345_fifo_attributes[] = { + NULL, +}; + static IIO_CONST_ATTR_SAMP_FREQ_AVAIL( "0.09765625 0.1953125 0.390625 0.78125 1.5625 3.125 6.25 12.5 25 50 100 200 400 800 1600 3200" ); @@ -313,6 +321,76 @@ static const struct attribute_group adxl345_attrs_group = { .attrs = adxl345_attrs, }; +static const struct iio_buffer_setup_ops adxl345_buffer_ops = { +}; + +static int adxl345_get_status(struct adxl34x_state *st, u8 *int_stat) +{ + int ret; + unsigned int regval; + + *int_stat = 0; + ret = regmap_read(st->regmap, ADXL345_REG_INT_SOURCE, ®val); + if (ret) { + pr_warn("%s(): Failed to read INT_SOURCE register\n", __func__); + return -EINVAL; + } + + *int_stat = 0xff & regval; + pr_debug("%s(): int_stat 0x%02X (INT_SOURCE)\n", __func__, *int_stat); + + return 0; +} + +/** + * Interrupt handler used for several features of the ADXL345. + * - DATA_READY / FIFO watermark + * - single tap / double tap + * - activity / inactivity + * - freefall detection + * - overrun + * + * @irq: The interrupt number. Having an interrupt imples FIFO_STREAM mode was + * enabled. Since this is given there will no be further test for being in + * FIFO_BYPASS mode. FIFO_TRIGGER and FIFO_FIFO mode (being similar to + * FIFO_STREAM mode) are not separately implemented so far. Both should be + * work smoothly with the same way of interrupt handling. + * @p: The iio poll function instance, used to derive the device and data. + */ +static irqreturn_t adxl345_trigger_handler(int irq, void *p) +{ + struct iio_dev *indio_dev = ((struct iio_poll_func *) p)->indio_dev; + struct adxl34x_state *st = iio_priv(indio_dev); + u8 int_stat; + int ret; + + ret = adxl345_get_status(st, &int_stat); + if (ret < 0) + goto done; + + /* Ignore already read event by reissued too fast */ + if (int_stat == 0x0) + goto done; + + /* evaluation */ + + if (int_stat & ADXL345_INT_OVERRUN) { + pr_debug("%s(): OVERRUN event detected\n", __func__); + goto done; + } + + if (int_stat & (ADXL345_INT_DATA_READY | ADXL345_INT_WATERMARK)) + pr_debug("%s(): WATERMARK or DATA_READY event detected\n", __func__); + + goto done; +done: + + if (indio_dev) + iio_trigger_notify_done(indio_dev->trig); + + return IRQ_HANDLED; +} + static const struct iio_info adxl345_info = { .attrs = &adxl345_attrs_group, .read_raw = adxl345_read_raw, @@ -349,6 +427,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, ADXL345_DATA_FORMAT_FULL_RES | ADXL345_DATA_FORMAT_SELF_TEST); const struct adxl34x_platform_data *data; + u8 fifo_ctl; int ret; indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); @@ -417,9 +496,32 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, if (ret < 0) return dev_err_probe(dev, ret, "Failed to add action or reset\n"); - /* Enable measurement mode */ - adxl345_set_measure_en(st, true); + /* Basic common initialization of the driver is done now */ + + if (st->irq) { /* Initialization to prepare for FIFO_STREAM mode */ + ret = devm_iio_triggered_buffer_setup_ext(dev, indio_dev, + NULL, + adxl345_trigger_handler, + IIO_BUFFER_DIRECTION_IN, + &adxl345_buffer_ops, + adxl345_fifo_attributes); + if (ret) + return dev_err_probe(dev, ret, "Failed to setup triggered buffer\n"); + + } else { /* Initialization to prepare for FIFO_BYPASS mode (fallback) */ + /* The following defaults to 0x00, anyway */ + fifo_ctl = 0x00 | ADXL345_FIFO_CTL_MODE(ADXL_FIFO_BYPASS); + + dev_dbg(dev, "fifo_ctl 0x%02X [0x00]\n", fifo_ctl); + ret = regmap_write(st->regmap, ADXL345_REG_FIFO_CTL, fifo_ctl); + if (ret < 0) + return ret; + + /* Enable measurement mode */ + adxl345_set_measure_en(st, true); + } + dev_dbg(dev, "Driver operational\n"); return devm_iio_device_register(dev, indio_dev); } EXPORT_SYMBOL_NS_GPL(adxl345_core_probe, IIO_ADXL345); From patchwork Thu Nov 14 23:09:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13875737 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 61D731BF7E8; Thu, 14 Nov 2024 23:10:31 +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=1731625833; cv=none; b=nJr3tohlCjQW5jBRXol/hqVzuRDtegEQEfG97HofWbFG3EDoA2gqcbEAEJgQyDXzATmwPjTNqOt0t2C5pM2LLTTM34jUVFEr33qTzqvOtsL5ffw4W9exyXY2LAugQxu71RGGDr/AVpLkEsZuaDEsG7EGiA9GpDbg7byZA0Px4u8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625833; c=relaxed/simple; bh=VTjudC1dZDTt9qTyghk+MnqF7fLa2Slp9EpRSzCv/Ec=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UTAdTRXaE8lTK9XFh0lTWUELGLGUHQFofYZg2mt3GhsGqm2qxJeIr+ozwJ2G/HMk1Z3F9KqZEo939nPaj53po40WhBqtR+mvhJ0RGUpentZS9xO1qIO64vEtDz6KfhVVc2Zou0NBxphRZMoZz6i3muJZjyWOntG+9h59EGIGCNk= 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=G3oHEvhC; 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="G3oHEvhC" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-37d5045987dso63269f8f.1; Thu, 14 Nov 2024 15:10:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731625830; x=1732230630; 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=mrVTxUcme1sdmvG64RbMNErOdNfzvL7ULZB0bFVTdEM=; b=G3oHEvhCiusyqOjSLnYJjDG3DmFOCVjHRvSy8kivjEvPA6dFiGgxbj3vmsNVcbCLvH 5jnXIjhx7+nko3eyjyOGBUCSU1aLxqtXaRUFl6KdszmDUbYsRNvoaRnjj64p8y/iIexH TUWqK765AwN2TgG4kILMAwvLzvLk4vDNhAVb3e691sl2cQ+4QW3fsgYV2sdHVz8QLtZp 2PUbmmRmiK7Rgo6lCLliuLHlLXrJEFNVQDwOm+sHvIoEG7HEwwRQMZNmcStIpwSpLkH9 qUbr/us0ueV5bsR0rpfN3v2wo3E3Zjd/K8C4eTNuhkjDSy0Ynl8tOsgR9rGSIVGx0xCo 4ZkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731625830; x=1732230630; 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=mrVTxUcme1sdmvG64RbMNErOdNfzvL7ULZB0bFVTdEM=; b=pyct0Rl9OxECjfmdzpBGU4XOqRTdFs4Ip3XwqbG8dw5rHjgkTnobD+3HLzknX8VOBk yghyK2xzANPVb037Jt5Ix+vizqZnkjwZikLvsoOJOBZRqsZZisuVPl/qEVVm76/frK61 pOFinY423WLLPGAnswc+SgcWJLbkjVBrCs95OtKibOr6BXF1ZbeTmBwG4I1EdQYZ+Ggc PvoPRkjopH34A7kBMUaBWwL8iiLAJcmPCHvCUzTrMMumJ3FvI3lLtrCleGxUOjcLLmMA 4H+FfuutUx/HJYDSp9VxwEUwUjZX+7T0pL0Uga0bFggX6/RuajN/N214UMclGUvxUZm6 TlfQ== X-Forwarded-Encrypted: i=1; AJvYcCVS83T3oKopJsTaQPiXo2V/gE9eM2MqpqbjDQqapCKXEW9k9sKkedYeCYDNUN9SVDgOAp4lxy8kXEQU7Czj@vger.kernel.org, AJvYcCVU7YcT139IxiY9O72ewFZbXDAhAw31uj/s5SQzSFZwLvPKp81vwy+pO00xiVMArA2PA5Aizq76fZI=@vger.kernel.org X-Gm-Message-State: AOJu0YwYrVPPrXbhot8aq4fxlvRfKzDOKsCw6xYQz5LEiEwAGA3Vb1/c bZEAXNuJ/Te+sfgZZjJ0+ZB+iKVN+hWWZ48cv+mQrivXD/u7u3F7 X-Google-Smtp-Source: AGHT+IF6YX+xiD5e+PPFvGXH2KT7Dtg5yeTeDA+Q0+Hj0s45GLBOA0yx6RhApfclfpOr74kwaoS3bg== X-Received: by 2002:a05:600c:4710:b0:42c:ba6c:d9a7 with SMTP id 5b1f17b1804b1-432df7878bcmr1570885e9.4.1731625829559; Thu, 14 Nov 2024 15:10:29 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dab789fasm36464265e9.18.2024.11.14.15.10.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 15:10:28 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: l.rubusch@gmx.ch, Lothar Rubusch Subject: [PATCH 14/22] iio: accel: adxl345: read FIFO entries Date: Thu, 14 Nov 2024 23:09:54 +0000 Message-Id: <20241114231002.98595-15-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241114231002.98595-1-l.rubusch@gmail.com> References: <20241114231002.98595-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add a function to read the elements of the adxl345 FIFO. This will flush the FIFO, and brings it into a ready state. The read out is used to read the elemnts and to reset the fifo again. The cleanup equally needs a read on the INT_SOURCE register. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index dbd07308a7..57bca112ea 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -140,6 +140,8 @@ struct adxl34x_state { const struct adxl345_chip_info *info; struct regmap *regmap; struct adxl34x_platform_data data; /* watermark, fifo_mode, etc */ + + __le16 fifo_buf[3 * ADXL34x_FIFO_SIZE] __aligned(IIO_DMA_MINALIGN); u8 int_map; bool fifo_delay; /* delay: delay is needed for SPI */ u8 intio; @@ -321,6 +323,27 @@ static const struct attribute_group adxl345_attrs_group = { .attrs = adxl345_attrs, }; +/** + * Read number of FIFO entries into *fifo_entries + */ +static int adxl345_get_fifo_entries(struct adxl34x_state *st, int *fifo_entries) +{ + unsigned int regval = 0; + int ret; + + ret = regmap_read(st->regmap, ADXL345_REG_FIFO_STATUS, ®val); + if (ret) { + pr_warn("%s(): Failed to read FIFO_STATUS register\n", __func__); + *fifo_entries = 0; + return ret; + } + + *fifo_entries = 0x3f & regval; + pr_debug("%s(): fifo_entries %d\n", __func__, *fifo_entries); + + return 0; +} + static const struct iio_buffer_setup_ops adxl345_buffer_ops = { }; @@ -362,6 +385,7 @@ static irqreturn_t adxl345_trigger_handler(int irq, void *p) struct iio_dev *indio_dev = ((struct iio_poll_func *) p)->indio_dev; struct adxl34x_state *st = iio_priv(indio_dev); u8 int_stat; + int fifo_entries; int ret; ret = adxl345_get_status(st, &int_stat); @@ -379,9 +403,11 @@ static irqreturn_t adxl345_trigger_handler(int irq, void *p) goto done; } - if (int_stat & (ADXL345_INT_DATA_READY | ADXL345_INT_WATERMARK)) + if (int_stat & (ADXL345_INT_DATA_READY | ADXL345_INT_WATERMARK)) { pr_debug("%s(): WATERMARK or DATA_READY event detected\n", __func__); - + if (adxl345_get_fifo_entries(st, &fifo_entries) < 0) + goto done; + } goto done; done: From patchwork Thu Nov 14 23:09:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13875738 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E42791C07D9; Thu, 14 Nov 2024 23:10:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625834; cv=none; b=sSCy0TFYkHOaHhMLfDBsvjtojjxfcU/SAuDQwhX80dkt9F/N9jcAcESWlP0Wr3kKjHBnJt2zLstCzUhJWgspmkLyekRwmFNaMeq100W1dtzwVCU8Hf/MCNtL4ch+sHznKM7jFydFM75vq8uGF/dJLWK0glOSI9Yyv4qcXovWHU0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625834; c=relaxed/simple; bh=FYtcqjQShpDDoo5l9S/bvpOPxAEPAmNqverQq+5wlGU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=F+U+5Lb7/AffEN6DQFncFbXAwpm82T6JNTJ04kflLBy28YqApa/hvLGkeZtnNluWdn6gYIUOuK56G1hxyfGXzvPJYYmvgNLHFVPI2jMWWxQ5q1XQjMS9hYJs4bHt5CR/5opqJrhm3kxNuCWsz4KwfQvZA8tndheAfyJPsXuSV1I= 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=CU2azQWk; arc=none smtp.client-ip=209.85.221.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CU2azQWk" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-37d4ee8d15aso63665f8f.2; Thu, 14 Nov 2024 15:10:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731625831; x=1732230631; 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=QWT/eem4w+KatBeCaD6Tg/CeKVsKpn15/8QuQoUGEWs=; b=CU2azQWk+OP9KT1Lu/kg8O0mLsM+WioLfvXVZiibGHHnt1Fpbkq+20tJec2AtoP33d eSYGgHCUAPUMs/6JEzSZxEM3e3brVCzPwRYxckJe67+9w88lDdQYp18e39AsdkQYPvFz 97qTUv/wx2+0anboiW4zQmnOzrn3MnAZsnVU61oI0KvjyHrhpidaU918zjIPwJYSRZPt kI1bSayrfDIwpr1a5OGxrTfbXXbNJbHHczBuT7/5QxWZF+T3/MH1je73ovx07f9H746T NpikSLOry3w3ftV/PpFCmfiW7ZoOjnhymZlVBxxfJrsdc77Ebs5HUR0RkzGLNkARud4n IpZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731625831; x=1732230631; 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=QWT/eem4w+KatBeCaD6Tg/CeKVsKpn15/8QuQoUGEWs=; b=EVqKXZkoJxGuzw7XZ2orZKDAE7vBRmi4RTuKlWGUfJDOJrniYBj6Lqdrax+psh/iCJ zSFSMTFNHetuPhINF5rET2hi92AHdOs9caRYpaaswcb77NWfxbNOwSytlOlOclOeTnkb XlGE2tcfPPeVHMEDTkoxYreTyFjAC0Ks4N4VfTP+73IkRD3Hw6zSpG5Z3p6ay/dL4mPF dw4aCzUqPAteCcDQ+2k2Q5M4rpgP5Mexe+IbyjLa0yOcWiGpsOJP/btk/D6DCANULpI5 u0j69Su2YRd5+E0uM2+n8twBKNZfj+GCsrdNp25hnTxQ8Cbh6f/WoE6UFTZt/jOqvm7k zkyg== X-Forwarded-Encrypted: i=1; AJvYcCVHUfrzUyRJTc2+peZxC2SX7MmurCbuH0LLh1bJ5xT7fscrVZzPHXd/ZCryuJgYV0WGdQEST1z2WK/gcmVL@vger.kernel.org, AJvYcCVe78C9HjLkZKX0ou8d5lIWY4n7jZkpTZr6UYqqNY4TzgAi7IR9vEe7GL+EfKDEmA7cCyE3UGbPQqE=@vger.kernel.org X-Gm-Message-State: AOJu0YyhH+b/cdWZfjI0+DFmVEmTtl61EemSmGJZ0hP8kDDzcSY8m9Sf pum+h/CbbSaIRJCvgdHxzQ3uylV8n2JWdhO7HjmNo9aSxb/8bGSM X-Google-Smtp-Source: AGHT+IGTsIWmVqyzSz6WpSL8m6dJCl3rUSBDrg+GOCAYR8JmtaXnIo0QA7h1SPe5TfTS2fOzeSF5rQ== X-Received: by 2002:a05:600c:4710:b0:42c:ba6c:d9a7 with SMTP id 5b1f17b1804b1-432df7878bcmr1571135e9.4.1731625831163; Thu, 14 Nov 2024 15:10:31 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dab789fasm36464265e9.18.2024.11.14.15.10.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 15:10:30 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: l.rubusch@gmx.ch, Lothar Rubusch Subject: [PATCH 15/22] iio: accel: adxl345: reset the FIFO on error Date: Thu, 14 Nov 2024 23:09:55 +0000 Message-Id: <20241114231002.98595-16-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241114231002.98595-1-l.rubusch@gmail.com> References: <20241114231002.98595-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add a function to empty the FIFO and reset the INT_SOURCE register. Reading out is used to reset the fifo again. For cleanup also a read on the INT_SOURCE register is needed to allow the adxl345 to issue interrupts again. Without clearing the fields no further interrupts will happen. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 70 ++++++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 8 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 57bca112ea..ece28825fb 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -344,6 +344,56 @@ static int adxl345_get_fifo_entries(struct adxl34x_state *st, int *fifo_entries) return 0; } +/** + * Read fifo_entries number of elements into *st + * + * It is recommended that a multiple-byte read of all registers be + * performed to prevent a change in data between reads of sequential + * registers. + * That is to read out the data registers X0, X1, Y0, Y1, Z0, Z1 at once. + * + * @st: The instance of the state object of this sensor. + * @fifo_entries: The number of lines in the FIFO referred to as fifo_entry, + * a fifo_entry has 3 elements for X, Y and Z direction of 2 bytes each. + */ +static int adxl345_read_fifo_elements(struct adxl34x_state *st, int fifo_entries) +{ + size_t count, ndirs = 3; + int i, ret; + + count = 2 * ndirs; /* 2 byte per direction */ + for (i = 0; i < fifo_entries; i++) { + ret = regmap_noinc_read(st->regmap, ADXL345_REG_XYZ_BASE, + st->fifo_buf + (i * count / 2), count); + if (ret) { + pr_warn("%s(): regmap_noinc_read() failed\n", __func__); + return -EFAULT; + } + } + + return 0; +} + +/** + * Empty the fifo. This is needed also in case of overflow or error handling. + * Read out all remaining elements and reset the fifo_entries counter. + * + * @st: The instance to the state object of the sensor. + */ +void adxl345_empty_fifo(struct adxl34x_state *st) +{ + int regval; + int fifo_entries; + + /* In case the HW is not "clean" just read out remaining elements */ + adxl345_get_fifo_entries(st, &fifo_entries); + if (fifo_entries > 0) + adxl345_read_fifo_elements(st, fifo_entries); + + /* Reset the INT_SOURCE register by reading the register */ + regmap_read(st->regmap, ADXL345_REG_INT_SOURCE, ®val); +} + static const struct iio_buffer_setup_ops adxl345_buffer_ops = { }; @@ -390,30 +440,34 @@ static irqreturn_t adxl345_trigger_handler(int irq, void *p) ret = adxl345_get_status(st, &int_stat); if (ret < 0) - goto done; + goto err; /* Ignore already read event by reissued too fast */ if (int_stat == 0x0) - goto done; + goto err; /* evaluation */ if (int_stat & ADXL345_INT_OVERRUN) { pr_debug("%s(): OVERRUN event detected\n", __func__); - goto done; + goto err; } if (int_stat & (ADXL345_INT_DATA_READY | ADXL345_INT_WATERMARK)) { pr_debug("%s(): WATERMARK or DATA_READY event detected\n", __func__); if (adxl345_get_fifo_entries(st, &fifo_entries) < 0) - goto done; - } - goto done; -done: + goto err; - if (indio_dev) iio_trigger_notify_done(indio_dev->trig); + } + goto done; +err: + iio_trigger_notify_done(indio_dev->trig); + adxl345_empty_fifo(st); + return IRQ_NONE; + +done: return IRQ_HANDLED; } From patchwork Thu Nov 14 23:09:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13875739 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.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 167381C174A; Thu, 14 Nov 2024 23:10:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625836; cv=none; b=LbFH+12op33JMyKdMVHyARTWdJ2QUheRuTZcC0l9XVYA44lssZp8uJlRaQUD0NNON1haYm+KvUsVisXC4I9nAYMk9BtHC0URdZwcvHUi+vP07mmvb7i4aAhWnx1F5fqda4zDtTk975oMdHi2Z4XUuQEIiQPBwIZlM74q2C33JdQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625836; c=relaxed/simple; bh=sY+Ab9dVCHVOyUUyEkNDMvcTT+/rCji8j1U9wYtsSQ0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NFXNfSJei45JTIythYPaFh8rO87l9tFGSWknvG+BpCgKURdjmbZ7yTaArja9N0URNHyHIaaN1a4u9unKmrMWmDfQNOctdfFzg2LKfNbiTelWWa8/XJwFYV7wwJItm646XObWHTbvOddsYZYOPCj/ToLYPFRfP3SFWarDnfrEla0= 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=P7rRuZTn; arc=none smtp.client-ip=209.85.128.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="P7rRuZTn" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-43158124a54so1398135e9.3; Thu, 14 Nov 2024 15:10:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731625833; x=1732230633; 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=gkksSsuxTUaRkIx07ILVW/vn6ACzPEWeMmqegAUVg0o=; b=P7rRuZTnCjTiysiU4uIDg7FhFOqgxMYwCxJFs92r+oVk8c0RvPs4YPJVTXV3StDN5E UIh3LVJcIWadcM1jc2rL37jCp5krmPlo3pOVL1uMJaAKV0m465hl8KSLlFVJxkGC1ZvY lK37MTavk2E+RrISOO7gkAv2qhMrEo+xhQLayTQGhsERRyErU/zSXNqbd4muwhjFny8z 1X4cZKm9nVkJI/ANihzR9uUkYnWP119EXOf0S6M8GB6RdiTb13S15/T1eIw6wMmBGfej uEG8dddf26tqduxzXoGdwESZRh0++ubl5gnjhH4W94v2/Zar5/M+gmVxXdL8Xh5qG9LQ jmwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731625833; x=1732230633; 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=gkksSsuxTUaRkIx07ILVW/vn6ACzPEWeMmqegAUVg0o=; b=sMcrIz3i7cjDMYE4I978iTuACDmZ3bQC5FJw0R4vMnOkFyurQK8V4uP0U5BguDW2yT 6eHJYLXJoX/GoTw/Bd3V/zJiEOq2ApLLTZMgM3rfjCK5JgYWAv4D/+ntkbV3N4UOhH4N JeBH3OjCw0ybJr2m540UnyUCiyJPSeG8z+UG0MckZ70P/0Cm+jCXxYe+3p/AZLG3pg9f wnPC50IPVCdvbIQaukDRufWnfLGjnsspTYsONN0hqfCwxImwHCMRYf4Hh+s4M0tOlt0i MIlRkE1ExTCCwDNmbNxBHmZ41sZArA+8oV8O3zImaQ1mUD9wkbvmgLCpXQSWhOX2fSQK IyyQ== X-Forwarded-Encrypted: i=1; AJvYcCUUR086+vhQriGUK23Vhl76BUKbrfhdXKmTryisigtfI04GFF0Loj2RymFEDcO29jzgN6zVFVguA7s=@vger.kernel.org, AJvYcCWrFzAzCYWN/qkCTFIiWBbCaE4PlJwlXqKptjaLPgZxArVzZqE3DbiNht7hwYDjkdPDvgv4lVxW7Vi7e5dk@vger.kernel.org X-Gm-Message-State: AOJu0YwT5O2oB53khQs8kGG6vk8NOT/oSiYBukEbHuYrF3aqcm7QcJ2P H4z2i+vshaUHDuuBcHOgeWWrl6hKJP1GXciuTYaFHeg5b1/hqdHq X-Google-Smtp-Source: AGHT+IEQizjoipF34T8Ul4oja7Vl7resZ4y7LdIl9j723eTo5dacvImb9Yj/esnYvSHKJf8+MWTasQ== X-Received: by 2002:a05:600c:19cb:b0:42c:aeee:e603 with SMTP id 5b1f17b1804b1-432df78fd8dmr1619135e9.7.1731625833460; Thu, 14 Nov 2024 15:10:33 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dab789fasm36464265e9.18.2024.11.14.15.10.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 15:10:32 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: l.rubusch@gmx.ch, Lothar Rubusch Subject: [PATCH 16/22] iio: accel: adxl345: register trigger ops Date: Thu, 14 Nov 2024 23:09:56 +0000 Message-Id: <20241114231002.98595-17-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241114231002.98595-1-l.rubusch@gmail.com> References: <20241114231002.98595-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add trigger options to the sensor driver. Reacting to the sensor events communicated by IRQ, the FIFO handling and the trigger will be core events for further feature implementation. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index ece28825fb..b917b02245 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -15,6 +15,9 @@ #include #include +#include +#include +#include #include #include #include @@ -140,11 +143,13 @@ struct adxl34x_state { const struct adxl345_chip_info *info; struct regmap *regmap; struct adxl34x_platform_data data; /* watermark, fifo_mode, etc */ + struct iio_trigger *trig_dready; __le16 fifo_buf[3 * ADXL34x_FIFO_SIZE] __aligned(IIO_DMA_MINALIGN); u8 int_map; bool fifo_delay; /* delay: delay is needed for SPI */ u8 intio; + bool watermark_en; }; #define ADXL34x_CHANNEL(index, reg, axis) { \ @@ -415,6 +420,35 @@ static int adxl345_get_status(struct adxl34x_state *st, u8 *int_stat) return 0; } +/* data ready trigger */ + +static int adxl345_trig_dready(struct iio_trigger *trig, bool state) +{ + struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); + struct adxl34x_state *st = iio_priv(indio_dev); + + st->int_map = 0x00; + if (state) { + /* Setting also ADXL345_INT_DATA_READY results in just a single + * generated interrupt, and no continuously re-generation. NB that the + * INT_DATA_READY as well as the INT_OVERRUN are managed automatically, + * setting their bits here is not needed. + */ + if (st->watermark_en) + st->int_map |= ADXL345_INT_WATERMARK; + + pr_debug("%s(): preparing st->int_map 0x%02X\n", + __func__, st->int_map); + } + + return 0; +} + +static const struct iio_trigger_ops adxl34x_trig_dready_ops = { + .validate_device = &iio_trigger_validate_own_device, + .set_trigger_state = adxl345_trig_dready, +}; + /** * Interrupt handler used for several features of the ADXL345. * - DATA_READY / FIFO watermark From patchwork Thu Nov 14 23:09:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13875740 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 6C0511C2323; Thu, 14 Nov 2024 23:10:37 +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=1731625839; cv=none; b=gQo7UkeCkimNjI05VUnikrugZoytHfmj5ENtZmsirq1BzFG2qVcogLiKdebNOmzf1ff8dmmJ7ii78N6xEKYrVlKqilOhd4Tv7q09km62Eny+eET+UAqA6dCxB6D3V+HL2u8Nvaq0BzTFQjwfZySkkSwWc54zoyvlmuPXYmGODQ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625839; c=relaxed/simple; bh=qR/sCQci0olPDHNGyPvQt4E28w+O0k5TA3wmzOJrj0M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XRixYMxmmZegQ2u++gsHrpaVm2Wra/C206zTOh91DWBpeQtcaXgL1/8bijA7HaXHJ1ARwnepbRoGNqkp/8iDNgPxDcUGkitxJ8iiL8LJ/uJF5fKmHsTcdhXyZdhEc7shjwXPiFizjPKHYlpm7IKFWaTWcGp3FP4f/4qWtFq7Ujc= 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=ZTCHNLJl; 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="ZTCHNLJl" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4315dfa3e0bso1419205e9.0; Thu, 14 Nov 2024 15:10:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731625836; x=1732230636; 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=I1YfXIBJlmygh5jtMiNQIlnvrPVWfGPBojvJxihEMvs=; b=ZTCHNLJlvFHqqghHnCXhuAqGXDStLQvUd0Q6oOvxDj4wKi5JIg3iYZ4zQjhv4gK73V wskTE3SOlTJOfcj5u+HLwcD9WVQbbnDtGufxtD8DvbftU9J/ChDeE2CLmwcThXuL/iVx /kyk7HhJhV8LLEn2ijb2mzimhjlvHjTvqBTnCMaQY10Oj//XUal03mWxNeAq8KraynET cz/BpIljIMgYST8vpSOa40jVghW/qpcfG/82Hj3RiG+8Di9bucIQh/99dPq7+rmTKW/3 i+B+AfZAQNgbtV/ynhUpyLOx+A0+3XiIe2hGTgv1vB+h6tStZAg7sTG3vcLILCTmW0hP MW0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731625836; x=1732230636; 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=I1YfXIBJlmygh5jtMiNQIlnvrPVWfGPBojvJxihEMvs=; b=NHcp3Ho7hGjBTc2Zycvatb/7KzXkIZszTQ2ZOSxUADw+MDlkCMkMEbxUPQbVi06V+I wQnsG3MC0IGGNka7SlbrRPMk12KDApwq3QdB8SxcHvZozVZoyLn5tCv3GEFSIhSejtnJ 2zDyKQU0Dr7bkTV8kHlCf5ITj2w4qV7ieBWgVVzJridcw2emYn9IMkRphbGDUVY3uSzf Mu9MH92RF9pmAvUFzwdyFVmzZ421ukS9T7wcyCd6TeNy7lQVBNrZqCKuhTVmmzYpkrMF jQyDoro9EtExXY7vFSLYAfuk/jvOj2vDIxHDfEXWe51Q785+8TJFqZ3VC7dMI3XZi4+W xXZg== X-Forwarded-Encrypted: i=1; AJvYcCXDGDVM2t7kBP0bVuh/CGk+9M2TtunI9JtlJ1DVMhxY10+srKPKCoqKHzu6pCJjv0zndDN8349+elE1vK1y@vger.kernel.org, AJvYcCXNOa3uXCY4fyamBwFdUeHcf+3iy9IwiFnbbLq+8+k4bbFNCz0yGo/6gclySAxaBiiECk0fn4iqj/A=@vger.kernel.org X-Gm-Message-State: AOJu0Yze7c720rtXyzJvRy86dbopApBT+2GQOTlD4ANPPkvPigwcHo+Q D0SGKTDm1AADswROesoSsVmrbzfl2RrUMFnvHThHjmsH44H57asz X-Google-Smtp-Source: AGHT+IHelWCwPBw7LJw1a+gm+mce0LetN3EoVahQMD1vsZynmcWULUKrOhwig+e5HzuxGMqijhSOKA== X-Received: by 2002:a05:600c:3ca8:b0:431:5316:6752 with SMTP id 5b1f17b1804b1-432df71e06fmr1712075e9.2.1731625835730; Thu, 14 Nov 2024 15:10:35 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dab789fasm36464265e9.18.2024.11.14.15.10.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 15:10:34 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: l.rubusch@gmx.ch, Lothar Rubusch Subject: [PATCH 17/22] iio: accel: adxl345: push FIFO data to iio Date: Thu, 14 Nov 2024 23:09:57 +0000 Message-Id: <20241114231002.98595-18-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241114231002.98595-1-l.rubusch@gmail.com> References: <20241114231002.98595-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add FIFO and hwfifo handling. Add some functions to deal with FIFO entries and configuration. This feature will be needed for e.g. watermark setting. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index b917b02245..f686037df3 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -420,6 +420,41 @@ static int adxl345_get_status(struct adxl34x_state *st, u8 *int_stat) return 0; } +static int adxl345_push_fifo_data(struct iio_dev *indio_dev, + u8 status, + int fifo_entries) +{ + struct adxl34x_state *st = iio_priv(indio_dev); + int ndirs = 3; /* 3 directions */ + int i, ret; + + if (fifo_entries <= 0) + return true; + + ret = adxl345_read_fifo_elements(st, fifo_entries); + if (ret) + return false; + + for (i = 0; i < ndirs * fifo_entries; i += ndirs) { + /* To ensure that the FIFO has completely popped, there must be at least 5 + * us between the end of reading the data registers, signified by the + * transition to register 0x38 from 0x37 or the CS pin going high, and the + * start of new reads of the FIFO or reading the FIFO_STATUS register. For + * SPI operation at 1.5 MHz or lower, the register addressing portion of the + * transmission is sufficient delay to ensure the FIFO has completely + * popped. It is necessary for SPI operation greater than 1.5 MHz to + * de-assert the CS pin to ensure a total of 5 us, which is at most 3.4 us + * at 5 MHz operation. + */ + if (st->fifo_delay && (fifo_entries > 1)) + udelay(3); + + iio_push_to_buffers(indio_dev, &st->fifo_buf[i]); + } + + return true; +} + /* data ready trigger */ static int adxl345_trig_dready(struct iio_trigger *trig, bool state) @@ -492,6 +527,9 @@ static irqreturn_t adxl345_trigger_handler(int irq, void *p) if (adxl345_get_fifo_entries(st, &fifo_entries) < 0) goto err; + if (adxl345_push_fifo_data(indio_dev, int_stat, fifo_entries) < 0) + goto err; + iio_trigger_notify_done(indio_dev->trig); } From patchwork Thu Nov 14 23:09:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13875741 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 148C21C243C; Thu, 14 Nov 2024 23:10:38 +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=1731625840; cv=none; b=eiuRf5K56SjT8llZvaIVcegpBXw/1Xxya98FBPdSNG7V+2Al0J8UvilSVGzrefrrVtJI2wAAiUC4mBAdHem0LkaWBlnquabn8TZHxmWvIG/Y8C0OqFWEVYrO6aYfy4Qzge3xN3ciISw7NbuCQJ7r5BcAK/QuhH+ZhFphQ2SOr30= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625840; c=relaxed/simple; bh=GtWePVG860SxLDAycMC+2V4CVWFP6S+iiM4qVAUho3U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=N1FaGCi+uAhXZLQqjy+eyepOPCcpZEcsLmugLrxC9weSMXYZEDge3VDnI8hTqhvfAf3bBul7L5xsqpvaYUA0kMDugG7vyWFTgMqNX4IsMhtIL+vxl//c0qalU6LTripc672N+BzRMogzyqUzpSmnlodcTxV9lz48QSRhF+R+6ls= 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=m08286w5; 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="m08286w5" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-37d5231f71cso161242f8f.2; Thu, 14 Nov 2024 15:10:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731625837; x=1732230637; 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=oP5cXLy2LL0l0G0KnSB+0lFPN9e6gBigDfbVNZI3xWY=; b=m08286w5ArmrWCDg1NBy+o+Q269+JDzt7B8rUXqFjexip+HIrsD/STMMfWNLwoqQ0u 0GN7kESDfHKIl9R9a3lywiqKY4lTbvM9MDH0n87/hhu/CDjD+lRlk+VvI69iD0meI7dy 2kHM7yteyTyXD7ZrLqIekyaRcgdVzVVnu7OSWcBM34vId2SsBlL5VGELTZ7YxNCTllAx YXVAA/ZTd3JES7d4kHnE4C0cbvfTmhcQs1Xx+GBXYgBcWu4goo9muaRRJe7TJFnSbj8f x0kbfEshJBEaZ1qb+zEvg2qVSRsZxtrEBYNkbLM8iOfq1n2ahn1tisSUj1XlfG+P/Rme GnNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731625837; x=1732230637; 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=oP5cXLy2LL0l0G0KnSB+0lFPN9e6gBigDfbVNZI3xWY=; b=uSkT9ewubvwEZ1qmceCieQvdD/O7NVDMP8uJWBNNSaMzJglcOKR8YRivQi+8OGl/lQ 9lhZxO2vpU66kPXT7QTccMc571wHE+xbtuXLKCzAI3+IIZwsPnvXyztLS8lYdZ1kk/K3 ggjcR98fNQ+b0c7pVPR1fDbnE45LdqNBJtErq8McvEsyw9HPYnbTEtHSKcWJhBNso9o9 9yALQ5P+uv8MYn4XC1P0OMTXp2UK/6Y3RqRnGaPvzL6Gopjhb9N0tSl54VA68HhZ/vXK M6Tz8zm+NUHXQGGnDDRuV7JrbH/m1KBHFxZ/CExFDCp7J1Ek9tVhEPNgMyZ2JL3JZQjj qiOg== X-Forwarded-Encrypted: i=1; AJvYcCXAcUQSdQyx/AyDyyThC+Djelrtbkc4XDtuPhVTmt8zsLcVum5emzW/+AExPcABfLBepM7YhsR981SVVfLU@vger.kernel.org, AJvYcCXkz/gU4tlRUYREO0xYmMi7sETbtVBynPW2ZO10sL4eKxNvyRzdbkSPEbTO6D7bCvBa7SmSfdYhCos=@vger.kernel.org X-Gm-Message-State: AOJu0YxwXE1UL4HPu2dvac6klNLavOvnZN7P7BGAQs/yUk+kkJ+UKomG uWjcSnw4ZWWi9Myg2v6efCxtcCJ9vLeU8DeAJ1ZeXnQNAd4eMvgj X-Google-Smtp-Source: AGHT+IEid8nFGtPXGMNkKaJAjMqJogkHklne/CWbhxjp5u/iP30k9r+qlyzowRLjhI5qX8E5y5EoXg== X-Received: by 2002:a05:600c:1c1f:b0:430:52ec:1e2a with SMTP id 5b1f17b1804b1-432df790752mr1681865e9.7.1731625837305; Thu, 14 Nov 2024 15:10:37 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dab789fasm36464265e9.18.2024.11.14.15.10.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 15:10:36 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: l.rubusch@gmx.ch, Lothar Rubusch Subject: [PATCH 18/22] iio: accel: adxl345: start measure at buffer en/disable Date: Thu, 14 Nov 2024 23:09:58 +0000 Message-Id: <20241114231002.98595-19-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241114231002.98595-1-l.rubusch@gmail.com> References: <20241114231002.98595-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add and initialize the buffer options to use the FIFO and watermark feature of the adxl345 sensor. In this way measure enable will happen in at enabling the buffer. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 105 +++++++++++++++++++++++++++++-- 1 file changed, 101 insertions(+), 4 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index f686037df3..a5b2efa69e 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -181,6 +181,28 @@ static const struct iio_chan_spec adxl34x_channels[] = { ADXL34x_CHANNEL(2, chan_z, Z), }; +static int adxl345_set_interrupts(struct adxl34x_state *st) +{ + int ret; + unsigned int int_enable = st->int_map; + unsigned int int_map; + + /* Any bits set to 0 in the INT map register send their respective + * interrupts to the INT1 pin, whereas bits set to 1 send their respective + * interrupts to the INT2 pin. The intio shall convert this accordingly. + */ + int_map = 0xFF & (st->intio ? st->int_map : ~st->int_map); + pr_debug("%s(): Setting INT_MAP 0x%02X\n", __func__, int_map); + + ret = regmap_write(st->regmap, ADXL345_REG_INT_MAP, int_map); + if (ret) + return ret; + + pr_debug("%s(): Setting INT_ENABLE 0x%02X\n", __func__, int_enable); + ret = regmap_write(st->regmap, ADXL345_REG_INT_ENABLE, int_enable); + return ret; +} + static int adxl345_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) @@ -328,6 +350,41 @@ static const struct attribute_group adxl345_attrs_group = { .attrs = adxl345_attrs, }; +static int adxl345_set_fifo(struct adxl34x_state *st) +{ + struct adxl34x_platform_data *data = &st->data; + u8 fifo_ctl; + int ret; + + /* FIFO should be configured while in standby mode */ + adxl345_set_measure_en(st, false); + + /* The watermark bit is set when the number of samples in FIFO + * equals the value stored in the samples bits (register + * FIFO_CTL). The watermark bit is cleared automatically when + * FIFO is read, and the content returns to a value below the + * value stored in the samples bits. + */ + fifo_ctl = 0x00 | + ADXL345_FIFO_CTL_SAMLPES(data->watermark) | + ADXL345_FIFO_CTL_TRIGGER(st->intio) | + ADXL345_FIFO_CTL_MODE(data->fifo_mode); + + pr_debug("%s(): fifo_ctl 0x%02X\n", __func__, fifo_ctl); + + /* The watermark bit is set when the number of samples in FIFO + * equals the value stored in the samples bits (register + * FIFO_CTL). The watermark bit is cleared automatically when + * FIFO is read, and the content returns to a value below the + * value stored in the samples bits. + */ + ret = regmap_write(st->regmap, ADXL345_REG_FIFO_CTL, fifo_ctl); + if (ret < 0) + return ret; + + return adxl345_set_measure_en(st, true); +} + /** * Read number of FIFO entries into *fifo_entries */ @@ -399,7 +456,50 @@ void adxl345_empty_fifo(struct adxl34x_state *st) regmap_read(st->regmap, ADXL345_REG_INT_SOURCE, ®val); } +static int adxl345_buffer_postenable(struct iio_dev *indio_dev) +{ + struct adxl34x_state *st = iio_priv(indio_dev); + struct adxl34x_platform_data *data = &st->data; + int ret; + + ret = adxl345_set_interrupts(st); + if (ret) + return -EINVAL; + + /* Default to FIFO mode: STREAM, since it covers the general usage + * and does not bypass the FIFO + */ + data->fifo_mode = ADXL_FIFO_STREAM; + adxl345_set_fifo(st); + + return 0; +} + +static int adxl345_buffer_predisable(struct iio_dev *indio_dev) +{ + struct adxl34x_state *st = iio_priv(indio_dev); + struct adxl34x_platform_data *data = &st->data; + int ret; + + /* Turn off interrupts */ + st->int_map = 0x00; + + ret = adxl345_set_interrupts(st); + if (ret) { + pr_warn("%s(): Failed to disable INTs\n", __func__); + return -EINVAL; + } + + /* Set FIFO mode: BYPASS, according to the situation */ + data->fifo_mode = ADXL_FIFO_BYPASS; + adxl345_set_fifo(st); + + return 0; +} + static const struct iio_buffer_setup_ops adxl345_buffer_ops = { + .postenable = adxl345_buffer_postenable, + .predisable = adxl345_buffer_predisable, }; static int adxl345_get_status(struct adxl34x_state *st, u8 *int_stat) @@ -609,7 +709,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, indio_dev->name = st->info->name; indio_dev->info = &adxl345_info; - indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE; indio_dev->channels = adxl34x_channels; indio_dev->num_channels = ARRAY_SIZE(adxl34x_channels); @@ -669,9 +769,6 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, ret = regmap_write(st->regmap, ADXL345_REG_FIFO_CTL, fifo_ctl); if (ret < 0) return ret; - - /* Enable measurement mode */ - adxl345_set_measure_en(st, true); } dev_dbg(dev, "Driver operational\n"); return devm_iio_device_register(dev, indio_dev); From patchwork Thu Nov 14 23:09:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13875742 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 8722D1C3021; Thu, 14 Nov 2024 23:10:40 +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=1731625842; cv=none; b=M5CQrHP41PsiOWiAe5K+ASSfiFtkiLcRcaqwNt/HlvErf1EIA/nIP2OIv1tEhPVQwxStxfUUHMD5X3YJ+yaXdlrZupNekm+4yTFckt3zVBxNiGcHoMTJpNlVBUK2NahtvJUunOpcCPLHQDA3tLQeuWG/tkWhlhtZesbIWajX/pU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625842; c=relaxed/simple; bh=AOcx0u3Q57oRK1lQ25ugyv/KGeGnaRFT2BWpyL0ilY8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oIbHhIU5hYrfw8pml1sprlQ5mtI0u/3Ycp21miYJxbUVIv5NPKezvz9UvWBEKRBquLD+K1EaA3J+oB5m4dN6p5Ssz/CkrID1jko+BoEELuXftxMxx5714sxON2f8pp31VYyu6P1jQfEntKQ+wVvK/gxpFvPxmPNQD43f5DEPbxk= 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=DE4sgnFe; 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="DE4sgnFe" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-37d5231f71cso161244f8f.2; Thu, 14 Nov 2024 15:10:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731625839; x=1732230639; 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=b0VFauSqujulbnKXaeTxZ9RqE35ZagjP+SnH3hIrISE=; b=DE4sgnFek+bjjNytxabvs29UyYwtKRKH13zaHBujQ22A7ZYmZhjQSL3PmFR76ZZA4p FMQbt+yWmvyQhpDmrcHZFTkLKzPW6UIPvusK3kVE/NvPAg1kBDqHWTxlyZjiNxEjeuTw fk+sOhFFkAQ9NK8BgV9KLQVg1u+YvPcFhA+IIxy1ICrwihRnah5jeB46oJwM+dvPJt6Q PlsVtovXuoq3ukYH1lYCeIr+5VlbPtC7VDJrAiu15OGko6yXoSzRV0aXaVRESo4hAhq+ DwnDgBdXmK99BxZtkadTw8pwHnWoDLOTREslomBvdpPZrsSTH+qYv1E8eKivzMY+a3au 3Wzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731625839; x=1732230639; 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=b0VFauSqujulbnKXaeTxZ9RqE35ZagjP+SnH3hIrISE=; b=aIyr3L2WgwbyXroHQGqSTDHOokseLzUMaZEoblPbGwFQDIryu2MUNUa6ZxpnDF+GBS /kq+1+ek1zHiXhiKc9NzHh8bL9vHzcdTMim8XMq7XoMK2XX79xEMQ+6K4/1XWEHiXr7R HY5OSp7GTQ5d2/RHpWnFMA5AHS/kpIiAnJxW1dkWau2n7kkRjbxYn3kMH9iidxeqfneA 0ZjldeuFNNBvyQCxH/46AgYD+WrJOmGL8v0/Kg4sUtRlswUwmjxO7BWMuVLfEGdLxC4k 8EdJAxqAl85EaEvBlHxV/Ly1CcO0g3CH6/giivyLTRuFXb6JHb8fEXRd2ESCP714+Gwl SYnA== X-Forwarded-Encrypted: i=1; AJvYcCVOxVJGLY0UnUMpjdxg39g9x2Ebwdu4jIZQCgufce8vh2uXOZkwPhXPqjUId4NJPg/rFttTWvqEfbc=@vger.kernel.org, AJvYcCW669mIyV8zQQTnOLAHrJ9igqlasaMPvkI0Mwfm/ZuwQlklMb8y5UT6PLlo9Yfz2LC7vwNSXqGYAt1eTQzz@vger.kernel.org X-Gm-Message-State: AOJu0YyvV91N+S+Y/PKomcrs0+tqoYmzikR1U4OjcbJa8jXeuVv00+OQ oPzwFrfXguo3+FhkSoZlwqloiAzC6dHgmC8SGtby79PszK2wg15f X-Google-Smtp-Source: AGHT+IF4yaBvsDLjzUS7HN0s2JYpYZC4j/knJHgVQAIVFtx1wQaB5VbMWb84BrkqpPUESbt/iUMMMA== X-Received: by 2002:a05:600c:1c1f:b0:430:52ec:1e2a with SMTP id 5b1f17b1804b1-432df790752mr1682095e9.7.1731625838922; Thu, 14 Nov 2024 15:10:38 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dab789fasm36464265e9.18.2024.11.14.15.10.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 15:10:37 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: l.rubusch@gmx.ch, Lothar Rubusch Subject: [PATCH 19/22] iio: accel: adxl345: prepare FIFO watermark handling Date: Thu, 14 Nov 2024 23:09:59 +0000 Message-Id: <20241114231002.98595-20-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241114231002.98595-1-l.rubusch@gmail.com> References: <20241114231002.98595-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add the feature of the adxl345 and related sensors to manage a FIFO in stream mode by a watermark level. Provide means to set the watermark through the IIO api and sysfs interface. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 94 ++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index a5b2efa69e..c99b8176f0 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -288,6 +288,26 @@ static int adxl345_write_raw(struct iio_dev *indio_dev, return -EINVAL; } +static int adxl345_set_watermark(struct iio_dev *indio_dev, unsigned int value) +{ + struct adxl34x_state *st = iio_priv(indio_dev); + struct adxl34x_platform_data *data = &st->data; + unsigned int fifo_mask = 0x1F; + int ret; + + if (value > ADXL34x_FIFO_SIZE) + value = ADXL34x_FIFO_SIZE; + pr_debug("%s(): set watermark to 0x%02x\n", __func__, value); + + ret = regmap_update_bits(st->regmap, ADXL345_REG_FIFO_CTL, + fifo_mask, value); + if (ret) + return ret; + + data->watermark = value; + return 0; +} + static int adxl345_write_raw_get_fmt(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, long mask) @@ -333,7 +353,76 @@ static void adxl345_powerdown(void *ptr) adxl345_set_measure_en(st, false); } +/* fifo */ + +static ssize_t adxl345_get_fifo_enabled(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct adxl34x_state *st = iio_priv(indio_dev); + struct adxl34x_platform_data *data = &st->data; + + return sysfs_emit(buf, "%d\n", data->fifo_mode); +} + +static ssize_t adxl345_get_fifo_watermark(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct adxl34x_state *st = iio_priv(indio_dev); + struct adxl34x_platform_data *data = &st->data; + + return sprintf(buf, "%d\n", data->watermark); +} + +static ssize_t watermark_en_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct adxl34x_state *st = iio_priv(indio_dev); + + return sysfs_emit(buf, "%d\n", st->watermark_en); +} + +static ssize_t watermark_en_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct adxl34x_state *st = iio_priv(indio_dev); + bool val; + + if (kstrtobool(buf, &val)) + return -EINVAL; + st->watermark_en = val; + return len; +} + +/* + * NB: The buffer/hwfifo_watermark is a read-only entry to display the + * currently set hardware FIFO watermark. First set a value to buffer0/length. + * This allows to configure buffer0/watermark. After enabling buffer0/enable + * the hwfifo_watermark shall show the configured FIFO watermark value. + * + * ref: Documentation/ABI/testing/sysfs-bus-iio + */ +IIO_STATIC_CONST_DEVICE_ATTR(hwfifo_watermark_min, "1"); +IIO_STATIC_CONST_DEVICE_ATTR(hwfifo_watermark_max, + __stringify(ADXL34x_FIFO_SIZE)); +static IIO_DEVICE_ATTR(hwfifo_watermark, 0444, + adxl345_get_fifo_watermark, NULL, 0); +static IIO_DEVICE_ATTR(hwfifo_enabled, 0444, + adxl345_get_fifo_enabled, NULL, 0); + +static IIO_DEVICE_ATTR_RW(watermark_en, 0); + static const struct iio_dev_attr *adxl345_fifo_attributes[] = { + &iio_dev_attr_hwfifo_watermark_min, + &iio_dev_attr_hwfifo_watermark_max, + &iio_dev_attr_hwfifo_watermark, + &iio_dev_attr_hwfifo_enabled, NULL, }; @@ -343,6 +432,7 @@ static IIO_CONST_ATTR_SAMP_FREQ_AVAIL( static struct attribute *adxl345_attrs[] = { &iio_const_attr_sampling_frequency_available.dev_attr.attr, + &iio_dev_attr_watermark_en.dev_attr.attr, NULL }; @@ -648,6 +738,7 @@ static const struct iio_info adxl345_info = { .read_raw = adxl345_read_raw, .write_raw = adxl345_write_raw, .write_raw_get_fmt = adxl345_write_raw_get_fmt, + .hwfifo_set_watermark = adxl345_set_watermark, }; /** @@ -705,6 +796,9 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, /* some reasonable pre-initialization */ st->data.act_axis_control = 0xFF; + /* default is all features turned off */ + st->watermark_en = 0; + st->intio = ADXL345_INT1; indio_dev->name = st->info->name; From patchwork Thu Nov 14 23:10:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13875743 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.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 D74521C3F0E; Thu, 14 Nov 2024 23:10:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625844; cv=none; b=PNdGgUPR1pjGj0PWwTHv4n9M2XHhVOBuhAB+Z35fLGag3UkUTsPU3YeH134bo8NE/Fojid36maIydPiPtBlebVlPvLvbiTlvQ5dIFrtoPHUey1PIf9IUiKb2H+/9JuiqOLB6suep9jwPB0JFUMgD2cNqSdf6RduW7QggnIhqUwQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625844; c=relaxed/simple; bh=EBs8YAdk/98rJPrf092AW2M34oEylWTxPcS/4zaMr5A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KK7ovjQ4pth0uOQ9OXfHGA/ooWxk6Gt7BPDa/hqLEKvYlrAuGCXgXcJHRdJV/fo7V7G7YCa+gg6QrO0Sxr+jfS1YuoczW+T2kG+/jdjBHG1smZs7QIoEue/8S890n3dfChGpGhzW7CWoOSlsqKQrW7ee8TGoODSau8sHfd1l9/M= 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=U+iMx7xM; arc=none smtp.client-ip=209.85.128.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="U+iMx7xM" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-432d796a57eso1407675e9.1; Thu, 14 Nov 2024 15:10:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731625841; x=1732230641; 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=QNm2QdDqnaGddIKwK+pE7qQtuDe8fNMcfOP3pPhPlIU=; b=U+iMx7xMkgtgQDEAh6aqrKeGZHuh9xjUV739vMo07Flco52w2FWcNKh/hVWGolchjA JnRcCH5M8AuOgMPA04yvTnWXTWfm8NYTbDr/33SZwk/GrH8tau0lj0CExvkKR/I+/IEQ Ecl5SC8zL9DhiB7gXYXh9YU1c/AC5lu3IVuvhL9rASR0Wqb1UhGk7Bmk6VYJtQbLy+ff N+e4Tc0aQKkeBDcnDSvafvKz3N9qk2zAnbuyrunOxTxfxaa4xVpENJFzNqBLAL+R+vKn QyUanyYE2lwmVOgcXBWAM+0ht8bHf3gx3SXbvDUYd5uC0jeXJcZvTJuw2t/icEyHSicI XFcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731625841; x=1732230641; 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=QNm2QdDqnaGddIKwK+pE7qQtuDe8fNMcfOP3pPhPlIU=; b=jhF9nrOBmEAd/jhk3+mTJSOmyKjUpLf8vgGZnNEJw/xdnOMg0F3eJR+OyQVpQui5bI HyFfy/QBvYogLPyYPJOX/Hee+FH6Sov7ltJjnrt7WwQjL2zfjNh3prKBGRNRwOO0kAv+ 3C+AzGFpejirmCogixvXQQMvPftUQNYWOoVvXjkTFqxzjdpBRTmiwQHGjFzKeCD/P+WX RN9H2Dq7+1DyPxP01hW1u00DpzvxWxwaUVJLODm2VJpcWs2WVfPCYIYHO05sXaR/cyZv w8ClD7dMOuoeTTCL5QOi2BN/Tv0ymE//I1gtmGwAIhP5HAPBHZ9Wjl5zC+LFw/PLefI8 Sx/A== X-Forwarded-Encrypted: i=1; AJvYcCUMazfyI96Jpgn3vgWRsMfjbcUObkwKanzliBdLmm3kU8iJsZvQFFxFJooH6Ut2Al+NxP728+l7wv8RZ80a@vger.kernel.org, AJvYcCXU3YLCa6ySduRjGFRbZhAyJZLr0FhFBHrevA2x85Hlvz9X2IhSFECz46q3D5EwKICLqUGJNaPmxE8=@vger.kernel.org X-Gm-Message-State: AOJu0Yx4jBBh0YoIpyL9kTZowOpM19nb8cp4diT4RIW9vFsivP5GqoT4 QGp2YyXXY7rXEGarfqpNMdjQHT+a8d7nm/QADRWnb9FFiV6EJw73 X-Google-Smtp-Source: AGHT+IGlqVBkjFRciP+03ZxqOA1xBt4bW8kF15JLb2JJhrTY/r23RcNX8Ead8XF9s9jCj/PkD2V0rA== X-Received: by 2002:a05:600c:4f02:b0:42c:bfd6:9d2f with SMTP id 5b1f17b1804b1-432df71d75fmr1683445e9.1.1731625841202; Thu, 14 Nov 2024 15:10:41 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dab789fasm36464265e9.18.2024.11.14.15.10.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 15:10:40 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: l.rubusch@gmx.ch, Lothar Rubusch Subject: [PATCH 20/22] iio: accel: adxl345: use FIFO with watermark IRQ Date: Thu, 14 Nov 2024 23:10:00 +0000 Message-Id: <20241114231002.98595-21-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241114231002.98595-1-l.rubusch@gmail.com> References: <20241114231002.98595-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Enable the watermark feature of the adxl345 sensor. The feature uses a FIFO to be configured by the IIO fifo sysfs handles. The sensor configures the FIFO to streaming mode for measurements, or bypass for configuration. The sensor issues an interrupt on the configured line to signal several signals (data available, overrun or watermark reached). The setup allows for extension of further features based on the interrupt handler and the FIFO setup. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index c99b8176f0..ab39fd8eb5 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -854,6 +854,45 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, if (ret) return dev_err_probe(dev, ret, "Failed to setup triggered buffer\n"); + dev_dbg(dev, "IRQ: allocating data ready trigger\n"); + st->trig_dready = devm_iio_trigger_alloc(dev, + "%s-dev%d-dready", + indio_dev->name, + iio_device_id(indio_dev)); + if (!st->trig_dready) + return dev_err_probe(dev, -ENOMEM, + "Failed to setup triggered buffer\n"); + dev_dbg(dev, "IRQ: allocating data ready trigger ok\n"); + + st->trig_dready->ops = &adxl34x_trig_dready_ops; + dev_dbg(dev, "IRQ: Setting data ready trigger ops ok\n"); + + iio_trigger_set_drvdata(st->trig_dready, indio_dev); + dev_dbg(dev, "IRQ: Setting up data ready trigger as driver data ok\n"); + + ret = devm_iio_trigger_register(dev, st->trig_dready); + if (ret < 0) + return dev_err_probe(dev, ret, + "Failed to register dready trigger\n"); + dev_dbg(dev, "Registering data ready trigger ok\n"); + + indio_dev->trig = iio_trigger_get(st->trig_dready); + + dev_dbg(dev, "Requesting threaded IRQ, indio_dev->name '%s'\n", + indio_dev->name); + + ret = devm_request_threaded_irq(dev, st->irq, + iio_trigger_generic_data_rdy_poll, + NULL, + IRQF_TRIGGER_RISING | IRQF_ONESHOT, + indio_dev->name, st->trig_dready); + if (ret < 0) + return dev_err_probe(dev, ret, "Failed to request IRQ handler\n"); + dev_dbg(dev, "Requesting threaded IRQ handler ok\n"); + + /* Cleanup */ + adxl345_empty_fifo(st); + } else { /* Initialization to prepare for FIFO_BYPASS mode (fallback) */ /* The following defaults to 0x00, anyway */ From patchwork Thu Nov 14 23:10:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13875744 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.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 C20AF1C4A0A; Thu, 14 Nov 2024 23:10:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625846; cv=none; b=HW8A7gLI0/i7wpflHGYQRs6Pf7fbbN2xlzDkIJzpLv0Mzvfdy6JVXlS43ROnTT/MR0n0oDyOgzLd3KDDCFUFgrMRrSxXqxxe0UDwfDQ6kLfU1Oh1DbUZFJRI7BlAuoX9GrUh+/TLglBeD104TBTlhCzR+MXmAvnwIbYES5FeKJ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625846; c=relaxed/simple; bh=qjcvQiDwqWl74/TaQREodbiQV4n8D4Oz2kxdCCVLkkA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ErOUDxThWLUGMlWubjZeVYFDZiYTLrp/3N9Lza98Mi7LOCnrLSxOFzuOxbcNGI+U3CL1Vx2AM4LrWF07QSPuiT8GR/Re/tGH8DqLJfk5hsmEto122mcBNUV8fFUHxVjLeNhDjdOMazeAPQtNDYwRhOYvKCMN1SBwE9CNxRhL4mo= 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=WS6QGxjA; arc=none smtp.client-ip=209.85.128.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="WS6QGxjA" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4315b957ae8so626835e9.1; Thu, 14 Nov 2024 15:10:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731625843; x=1732230643; 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=mhHizrLkDaUDWUHXJf8ydQRCylx5R9sjJE+vTDEeYi8=; b=WS6QGxjAjvEYuJYhBTUVwF2YWWinXtTNhIt5fOBVHaF76Ko3/dv5XRImX/XWUDx8tr g03iW5RRmUkynljxJJVDo/irbNGss4nbZ0I4eIqD/V7LRNGXL7gFESCxTEic3iKdQa59 r//e/DW/l5uvNsG9EY8jvTXAfa8IMWqc1035DlYcfrpHuAu+Nf8wM+Rln+3NCQda+L0T RHRbZcggFFeqCBDpKNyM+zU2JRja9mi8/neNumWS/UGUbOyrQYezpNfrYaFJk8yUcXh/ eLwmMo7YD4r9hopHUGb1J7O4ODW1ozOAm+IhA2HYLWeBSLwCsqysyBfLqeRbiUDS0jFf eOQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731625843; x=1732230643; 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=mhHizrLkDaUDWUHXJf8ydQRCylx5R9sjJE+vTDEeYi8=; b=cq/Kx5yiS2zs7G+a4TNpqFWEOxC6WErwfGv6fDjqitKLsTxgZmVmpq5iN7esqPMsr9 zgVcjeoS+ae3yLigtItJrCrGPLcLWELu725/uGbsAXAZcN0/1ZtYytY8QZLSdTMWEJfU 0QgmCb09CnUXFq3CyMN5PCLzCgVtGWYSXbwbPrYTxwHSs9gqFZmABay+MQphwm3Nj26R WC4EBQ8wvlpK6xr8ocdRz9sTsH6ftPj1vGn4YqFilSSTxVI8iZdWnqxS5Hhv9CKInF11 r1eJgWucmwSylBJ10AxzMebxGaEJLoOkYJvE9TUuvhvw7qlrpCaoA5SCyoP4qnHZaWGL S+ww== X-Forwarded-Encrypted: i=1; AJvYcCULWA+SUhFs2wLAQJyoTJ78y2t1XQtS/ntnfh/UzcUEpHnPWspSjTiEZDCQYeAxxdJNwN01E44FBknZLLDS@vger.kernel.org, AJvYcCUPbNYk2ZBL/xTGQCoUyrLFKk3vAHqJ1QbB9HgWmLcKDu6moLUHuk/NoCL6kBFxnMoeofr8ECIoOGo=@vger.kernel.org X-Gm-Message-State: AOJu0YxNJ7hcEIqcIKc2s0C7UbqUe+1xDU54ky/ZKQow4U8GoYutyoVl MJO+mJl8CZhyAXiyaCuuK4nVBI8mVoCupjfIqKeWizq9DONtdEp3 X-Google-Smtp-Source: AGHT+IFguQvS/rPoEmbopV/ojY5tjFUWE8vkv9yEqF+Mg534bt6RxXEnD23G+ND+KZ1THEN++M24DQ== X-Received: by 2002:a05:600c:1d0f:b0:42c:ba6c:d9b1 with SMTP id 5b1f17b1804b1-432df78abf8mr1626495e9.4.1731625842826; Thu, 14 Nov 2024 15:10:42 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dab789fasm36464265e9.18.2024.11.14.15.10.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 15:10:42 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: l.rubusch@gmx.ch, Lothar Rubusch Subject: [PATCH 21/22] iio: accel: adxl345: sync FIFO reading with sensor Date: Thu, 14 Nov 2024 23:10:01 +0000 Message-Id: <20241114231002.98595-22-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241114231002.98595-1-l.rubusch@gmail.com> References: <20241114231002.98595-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Pause the measurement while reading fifo values. Initially an interrupt is triggered if watermark of the FIFO is reached, or in case of OVERRUN. The sensor stays mute until FIFO is cleared and interrupts are read. Situations now can arise when the watermark is configured to a lower value. While reading the values, new values arrive such that a permanent OVERRUN state of the FIFO is reached, i.e. either the FIFO never gets emptied entirely because of permanently new arriving measurements. No more interrupts will be issued and the setup results in OVERRUN. To avoid such situation, stop measuring while solving an OVERRUN condition and generally reading FIFO entries. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index ab39fd8eb5..8025dfeb84 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -714,6 +714,11 @@ static irqreturn_t adxl345_trigger_handler(int irq, void *p) if (int_stat & (ADXL345_INT_DATA_READY | ADXL345_INT_WATERMARK)) { pr_debug("%s(): WATERMARK or DATA_READY event detected\n", __func__); + + /* Pause measuring, at low watermarks this would easily brick the + * sensor in permanent OVERRUN state + */ + adxl345_set_measure_en(st, false); if (adxl345_get_fifo_entries(st, &fifo_entries) < 0) goto err; @@ -721,12 +726,15 @@ static irqreturn_t adxl345_trigger_handler(int irq, void *p) goto err; iio_trigger_notify_done(indio_dev->trig); + adxl345_set_measure_en(st, true); } goto done; err: iio_trigger_notify_done(indio_dev->trig); + adxl345_set_measure_en(st, false); adxl345_empty_fifo(st); + adxl345_set_measure_en(st, true); return IRQ_NONE; done: From patchwork Thu Nov 14 23:10:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13875745 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 3D4571C4A1A; Thu, 14 Nov 2024 23:10:46 +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=1731625848; cv=none; b=pkzjs0+6NvigDITStLYJQQEiyRPuU51nMiwurxmaPoAoKbsvgtMdcIpqFGyQeDzuJEp/58WURV3B84ZoKDnFLDW49KFF6dQyjp52sisqC/2Ed94VZbyEeMlc65xP+E7iagt1Eu5XZk9akefLxVmDUvNL8sUSep5TXassmonNyjA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731625848; c=relaxed/simple; bh=XVBaT7tI4WC3TxeQZRnASdggvZWpWUDYexXxWgAysew=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=O2zoMDbLPiYaXyIAon9AlaW0+9t+6qe69PoSqKqSbOikrm1HXEPTdtqXPL54WRhuifjMmgPJX1PllP3E5JioXvzN2YhVJnnKK0fMRzjt20SF4o20Kr9HQuZhQqetsJii2si3JL7Lt5Os1KWmcSSRmw+BnC+kAf7HA32eW9SJEdQ= 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=Ejp+WL1A; 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="Ejp+WL1A" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-3821ae348e3so97513f8f.1; Thu, 14 Nov 2024 15:10:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731625844; x=1732230644; 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=76W9ZF4PZtMV17rjIpg8P7SpS5XYC97O8Bnuf6JYvP4=; b=Ejp+WL1AMtpsEjGWpN5jMhfwB/CDkjfAnrl0XP/qSKza0UnpTWjEVrmaY5jW2RnNuT T4XBjdfWD69QYWkC2ibUPnnxO0SKQGyYMsR/G9IvkaHY7v9SYem5ncCdK06QMZa+ZV46 OzCtHLfclvfsz2pEKW87r083u3uDC5hQNhhxi7zqTS3H5iXoO7cx2aGqAvujLijycNkD AcTRMBWsrLgXq0UJo/NtSnaYCVvYpeifTgOdApnkNUZMwcDv7aeAOosBI8dHAUdmFpMh tAbDjFLJyx5qnyOv1EcopFusHPlGb6w/zT+JQfomoaE47Q7tU/ov17P1/tfs7AciLLw8 hbwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731625844; x=1732230644; 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=76W9ZF4PZtMV17rjIpg8P7SpS5XYC97O8Bnuf6JYvP4=; b=L/gAxQZnGSwqpTPjuj/c7gpdsZ7iiaQykff95s0slyceDNHsEs8tlLrJJ+jIJlAaAc 8qpuInpSdk8FrkcXFqUiRNv2boN1vA22F7RA+UO5/oQVgXY0lbL8k5VUhBIH69BdTzBE YnRxzCXqprT7+Rq24muA37eIyTN1Mm9+D8iC9URKDr7TCLpFbaMEtbl0mOana535G8RN wgh+FD01PmIlJOYxtM3D2RJGdzM+P3Wro1iay24wZfzd/B0pbJTrwBuG76qPhlgEcAwG 0oO/kcr/R1z6S5BKMZelc/e3UTZaF9remMigpoN80HaqZfl4hyeHCL5YPbM4+snkgkJ2 LkjA== X-Forwarded-Encrypted: i=1; AJvYcCVdeTc1Pq8Wor/2cCteo0kwgiprYbE/M1ZzfIJ9oCtmyWR9X1LYG9PaL331DcQZ7UolARvtDwZw7V4=@vger.kernel.org, AJvYcCX9TdDh9cv6ejHE2vltnQXEdyci2mduMws0NyOhZg8mw35ivfpjYjsyEB8naxApY0qSpLa/CKzoh/jBnVi+@vger.kernel.org X-Gm-Message-State: AOJu0YxlBwGI4kFIg5tq0a1DbCTrp744/NL8bL1/2vjnv7jDtJ68xj34 2e1NOADHfahjelwevKIJEeY6N/nvOyc0WYsrH4yI61e/LsEGluJwGklS53Uq X-Google-Smtp-Source: AGHT+IEXex+1ImFX1NZKJrs9laoUabfJkQRS5OoHyNocpuHjQladGWpksvee4OXA8i0s3JZQ6az7LQ== X-Received: by 2002:a05:600c:a44:b0:42c:b870:c52e with SMTP id 5b1f17b1804b1-432df722ad4mr1689025e9.1.1731625844422; Thu, 14 Nov 2024 15:10:44 -0800 (PST) Received: from 5dfbf0f66296.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dab789fasm36464265e9.18.2024.11.14.15.10.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 15:10:44 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: l.rubusch@gmx.ch, Lothar Rubusch Subject: [PATCH 22/22] iio: accel: adxl345: add debug printout Date: Thu, 14 Nov 2024 23:10:02 +0000 Message-Id: <20241114231002.98595-23-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241114231002.98595-1-l.rubusch@gmail.com> References: <20241114231002.98595-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add debug prints to allow to debug the sensor based on dynamic debug. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 95 ++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 8025dfeb84..e416a50dd0 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -26,6 +26,9 @@ #include "adxl345.h" +/* debugging registers */ +#define DEBUG_ADXL345 0 + /* ADXL345 register map */ #define ADXL345_REG_DEVID 0x00 /* r Device ID */ #define ADXL345_REG_THRESH_TAP 0x1D /* r/w Tap Threshold */ @@ -181,6 +184,78 @@ static const struct iio_chan_spec adxl34x_channels[] = { ADXL34x_CHANNEL(2, chan_z, Z), }; +/* + * Debugging + */ + +__maybe_unused +static void adxl345_debug_registers(const char *func, struct adxl34x_state *st) +{ +#if DEBUG_ADXL345 == 1 + struct regmap *regmap = st->regmap; + unsigned int regval = 0; + + regmap_read(regmap, ADXL345_REG_THRESH_TAP, ®val); + pr_debug("%s(): DEBUG - 0x%02X\t- ADXL345_REG_THRESH_TAP\n", + func, 0xff & regval); + + regmap_read(regmap, ADXL345_REG_DUR, ®val); + pr_debug("%s(): DEBUG - 0x%02X\t- ADXL345_REG_DUR\n", + func, 0xff & regval); + + regmap_read(regmap, ADXL345_REG_LATENT, ®val); + pr_debug("%s(): DEBUG - 0x%02X\t- ADXL345_REG_LATENT\n", + func, 0xff & regval); + + regmap_read(regmap, ADXL345_REG_WINDOW, ®val); + pr_debug("%s(): DEBUG - 0x%02X\t- ADXL345_REG_WINDOW\n", + func, 0xff & regval); + + regmap_read(regmap, ADXL345_REG_ACT_TAP_STATUS, ®val); + pr_debug("%s(): DEBUG - 0x%02X\t- ADXL345_REG_ACT_TAP_STATUS\n", + func, 0xff & regval); + + regmap_read(regmap, ADXL345_REG_POWER_CTL, ®val); + pr_debug("%s(): DEBUG - 0x%02X\t- ADXL345_REG_POWER_CTL\n", + func, 0xff & regval); + + regmap_read(regmap, ADXL345_REG_INT_ENABLE, ®val); + pr_debug("%s(): DEBUG - 0x%02X\t- ADXL345_REG_INT_ENABLE\n", + func, 0xff & regval); + + regmap_read(regmap, ADXL345_REG_INT_MAP, ®val); + pr_debug("%s(): DEBUG - 0x%02X\t- ADXL345_REG_INT_MAP\n", + func, 0xff & regval); + + regmap_read(regmap, ADXL345_REG_INT_SOURCE, ®val); + pr_debug("%s(): DEBUG - 0x%02X\t- ADXL345_REG_INT_SOURCE\n", + func, 0xff & regval); + + regmap_read(regmap, ADXL345_REG_FIFO_CTL, ®val); + pr_debug("%s(): DEBUG - 0x%02X\t- ADXL345_REG_FIFO_CTL\n", + func, 0xff & regval); + + regmap_read(regmap, ADXL345_REG_FIFO_STATUS, ®val); + pr_debug("%s(): DEBUG - 0x%02X\t- ADXL345_REG_FIFO_STATUS\n", + func, 0xff & regval); +# endif +} + +__maybe_unused +static void adxl345_debug_fifo(const char *func, s16 *fifo_buf, int entries_line) +{ +#if DEBUG_ADXL345 == 1 + s16 xval, yval, zval; + + xval = fifo_buf[0 + entries_line]; + yval = fifo_buf[1 + entries_line]; + zval = fifo_buf[2 + entries_line]; + + pr_debug("%s(): FIFO[%d] - x=%d, y=%d, z=%d\n", + func, entries_line/3, xval, yval, zval); +#endif +} + static int adxl345_set_interrupts(struct adxl34x_state *st) { int ret; @@ -513,6 +588,8 @@ static int adxl345_read_fifo_elements(struct adxl34x_state *st, int fifo_entries size_t count, ndirs = 3; int i, ret; + pr_debug("%s(): fifo_entries = %d\n", __func__, fifo_entries); + count = 2 * ndirs; /* 2 byte per direction */ for (i = 0; i < fifo_entries; i++) { ret = regmap_noinc_read(st->regmap, ADXL345_REG_XYZ_BASE, @@ -522,6 +599,7 @@ static int adxl345_read_fifo_elements(struct adxl34x_state *st, int fifo_entries return -EFAULT; } } + adxl345_debug_registers(__func__, st); return 0; } @@ -639,6 +717,7 @@ static int adxl345_push_fifo_data(struct iio_dev *indio_dev, if (st->fifo_delay && (fifo_entries > 1)) udelay(3); + adxl345_debug_fifo(__func__, st->fifo_buf, i); iio_push_to_buffers(indio_dev, &st->fifo_buf[i]); } @@ -666,6 +745,7 @@ static int adxl345_trig_dready(struct iio_trigger *trig, bool state) __func__, st->int_map); } + adxl345_debug_registers(__func__, st); return 0; } @@ -697,6 +777,7 @@ static irqreturn_t adxl345_trigger_handler(int irq, void *p) int fifo_entries; int ret; + pr_debug("%s(): IRQ caught!\n", __func__); ret = adxl345_get_status(st, &int_stat); if (ret < 0) goto err; @@ -731,6 +812,7 @@ static irqreturn_t adxl345_trigger_handler(int irq, void *p) goto done; err: + pr_debug("%s(): error termination\n", __func__); iio_trigger_notify_done(indio_dev->trig); adxl345_set_measure_en(st, false); adxl345_empty_fifo(st); @@ -738,6 +820,7 @@ static irqreturn_t adxl345_trigger_handler(int irq, void *p) return IRQ_NONE; done: + pr_debug("%s(): regular termination\n", __func__); return IRQ_HANDLED; } @@ -788,6 +871,9 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, st = iio_priv(indio_dev); st->regmap = regmap; + dev_dbg(dev, "irq '%d'\n", irq); + if (!irq) /* fall back to bypass mode w/o IRQ */ + dev_dbg(dev, "no IRQ, FIFO mode will stay in BYPASS_MODE\n"); st->irq = irq; st->info = device_get_match_data(dev); if (!st->info) @@ -815,7 +901,11 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, indio_dev->channels = adxl34x_channels; indio_dev->num_channels = ARRAY_SIZE(adxl34x_channels); + dev_dbg(dev, "setting up indio_dev ok\n"); + if (setup) { + dev_dbg(dev, "setup() was provided\n"); + /* Perform optional initial bus specific configuration */ ret = setup(dev, st->regmap); if (ret) @@ -830,6 +920,8 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, "Failed to set data range\n"); } else { + dev_dbg(dev, "No setup() provided\n"); + /* Enable full-resolution mode (init all data_format bits) */ ret = regmap_write(st->regmap, ADXL345_REG_DATA_FORMAT, ADXL345_DATA_FORMAT_FULL_RES); @@ -838,6 +930,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, "Failed to set data range\n"); } + dev_dbg(dev, "Retrieving DEVID\n"); ret = regmap_read(st->regmap, ADXL345_REG_DEVID, ®val); if (ret < 0) return dev_err_probe(dev, ret, "Error reading device ID\n"); @@ -845,7 +938,9 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, if (regval != ADXL345_DEVID) return dev_err_probe(dev, -ENODEV, "Invalid device ID: %x, expected %x\n", regval, ADXL345_DEVID); + dev_dbg(dev, "Retrieving DEVID ok\n"); + dev_dbg(dev, "Registering power down function\n"); ret = devm_add_action_or_reset(dev, adxl345_powerdown, st); if (ret < 0) return dev_err_probe(dev, ret, "Failed to add action or reset\n");