From patchwork Thu Dec 5 17:13:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13895828 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.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 02172224B1D; Thu, 5 Dec 2024 17:13:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733418835; cv=none; b=Qaf3HvsqJrZnAVk19oLkXFsjwaaZgbhRpZ+SSMUSc87P+3MbRLFRkguB1pHyr1gLecAnDyvRwiJ6pW6LXo1MhFH17go+3dGuY0UOZsQ4igb0oVnmo3fEmdwPsL/VOPlARZ4w8rWy2hf7FvKdHYWcEbtPO9BuASMARaICVPsGdx0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733418835; c=relaxed/simple; bh=MJRcOjRxqauR3VIt4oFjuLbKiHlmawUNI5WmBsNNWfY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=c9v0cKoIRQJcOnRVyF2pzi8TnZtRZhsv1Tbtz1BxmgQn5aLz48O85POjtGjXSPrtnxQrUDdHQch2ANqTMcIDV3aJ3n1eQQtAYYijsHy/Kx3xeO1oTzH58HRXr368M321IHfFALw7r7OGaRkuFZI0WgNmNaNc7hkZr0EHUxc+Ock= 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=KrHy9fVv; arc=none smtp.client-ip=209.85.208.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="KrHy9fVv" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-5d0cdff12b4so157738a12.1; Thu, 05 Dec 2024 09:13:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733418832; x=1734023632; 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=ItFtpbeRue66V6lbrgr6VbuNzJvE3GBXZAD5o5I2hDY=; b=KrHy9fVvMCOfY1DK7S3xT/vIGUgVLu0dXC2vPz/acvlopp2pIwZPzpY7218M9LqCRv tXUavNoOXBRFerD366GqeE/ADldz8yny75I+B+zd9x+uDsVFba8yJYVINLMi7SYH2Inx low4hL/q8MkFFAxxvHqxp8WaDYsPyzQetrxMdOvdYd6yNge7j9DHXulh5wmrzynPStRB u/X6SScoIj8wn3hHkZhbweaHUzVFQU8uarVK8njYlxjn9gFn/ksEorrNTBe9VHdZB9zc 5HlfGGoh4c5/t/+7ZWJwrbb+QQR4ldhNENBXd+k/xbL2gXu+ZW6TOfJ/u6xMPIk6zpdW ZT0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733418832; x=1734023632; 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=ItFtpbeRue66V6lbrgr6VbuNzJvE3GBXZAD5o5I2hDY=; b=RbnpdbH3piKGFpeIkIY6LEJliDl+uGZtJd0X6iRsdMW+VywMVUyeiAQK+dDbaDTVOH AuTOD3TIguMa3340yIjPdE7nxjlilT7LZTIGYLeg49d9HRJSLn4gQpmKOyCp4lpNQ0QL 4fWK+z7IlPCjgAPkwOcG0yXu0TCkLwg9De3TBLHDYzLf+LeCBfZFin7/Tcqh8lZVE30Q h+rd8miw1f8dORdam65nK3/zkz5Cz+QAAXmoC7kmFau+jgaswGIs5O2LQm1gUvjl8Eoi RelcTQu0bdEFjse7WpwsEaksVy2j0VjoWtfyHnRbmRO246qZcFL3r7f9xcNYE+to9WQX f8lg== X-Forwarded-Encrypted: i=1; AJvYcCUA3Q0KVmZ1FPtVZYo6K/8wTW8pOxTtE/IhZ7S5g2CSsi0oDQl9uWW4laLbqI/yE7vX3xSSEGVI3nkEoA1l@vger.kernel.org, AJvYcCVG0IIpDNaDR3xCKxMzhb14+lS1dnuZuHtvpOt3MfTPDuJdNIm2LvKIQ/VcScZVyDRODvT/VlWrguQ=@vger.kernel.org X-Gm-Message-State: AOJu0YycuhWYEQy98hcJz8V82o9JLUv9XSI5ahbYU2+qW4Sw4MC+Eiyp ELVlqCAinf35ljBUWPP2lUGyBTBwxQpCiFjWN4nw41m1PLEvSUNJ X-Gm-Gg: ASbGnctG5NbuuTJqZehapao1n0fgXUTiO2BErUhBJEd6quCCDcG7pqhZMWLXNxZrYdq xDJpFo8npC5IePJGylAorc0gUo4IV+tpLGsKSVa4Z8Tjc+sNLRKRn2ohLVbvhS0iaRb9pZBG7lS XWwLveAm8rsnCq/e4zOKNYPkP16xkRdL7xoWYZKkBdT3X43NuIdOgRanMW6rNEC79Z+Ghej/qn6 8syzaYo7R4sQ0Y+8LkdVz3sLj7yrQFUNG4sCxI/9A43HcqVgL+DLhtVX36jkC5oVpgJ4qK3KOzY fiLUGtSFHwdTjUjP00IayDlKkjTc X-Google-Smtp-Source: AGHT+IHmtP89Hd42kGV5XG6wzg+Ft2bMoyYlcGKQLUi4Rsl9ZPuf3KxmWSund5x/E42vQ6Oqh+dizQ== X-Received: by 2002:a05:6402:35d6:b0:5d0:defb:ed2e with SMTP id 4fb4d7f45d1cf-5d10cbaaf71mr4362107a12.10.1733418832125; Thu, 05 Dec 2024 09:13:52 -0800 (PST) Received: from 7b58d44c4ff6.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d149a48a38sm1026078a12.23.2024.12.05.09.13.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 09:13:51 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v5 01/10] iio: accel: adxl345: refrase comment on probe Date: Thu, 5 Dec 2024 17:13:34 +0000 Message-Id: <20241205171343.308963-2-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241205171343.308963-1-l.rubusch@gmail.com> References: <20241205171343.308963-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 Refrase comment on the probe function, avoid naming different hardware. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 006ce66c0aa..eb3ce4434a5 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -169,8 +169,7 @@ static void adxl345_powerdown(void *regmap) } /** - * adxl345_core_probe() - probe and setup for the adxl345 accelerometer, - * also covers the adlx375 accelerometer + * adxl345_core_probe() - Probe and setup for the accelerometer. * @dev: Driver model representation of the device * @regmap: Regmap instance for the device * @setup: Setup routine to be executed right before the standard device From patchwork Thu Dec 5 17:13:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13895829 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.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 471FA225787; Thu, 5 Dec 2024 17:13:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733418837; cv=none; b=VF/LsIEBdg/uLxvh6T1fxVqcDALshWJ+cbsnDVZwMU2B4wjM7+4JIa9rm6YlLEzgDS5gRj8Je8Zg9NkctzbX3NzKtCnpNzGenVfFiKz+21V7tCzHG/+it3/378U/u3JsuiBYkcq3pl9lj6K6b05JU4dc3EKWIYrpRMignSW9tVI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733418837; c=relaxed/simple; bh=ebMgkYB23U8EmKhJlfYxI1oX1jRs6zqA7+xkC/VZIJ0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=r4soDF0H77SoYhjAZ55U27nCaDWnUia9gUNxAVpBU+hrpu1NRaXmZuALw/S55Yd+Ghxi92L6ZAiv7LyYBStK/P4X+Yf5cMpXMxTkiZc0/9G3KyevkP0cpJjzZ17a1RgsmtJyXuTi5X25vliCqSEezFXkuqbboI5JSaj5CjjRQOw= 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=VIIwlIX2; arc=none smtp.client-ip=209.85.208.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="VIIwlIX2" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-5d0b85c5574so171301a12.2; Thu, 05 Dec 2024 09:13:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733418833; x=1734023633; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Cm3ofDFIyWdFD3BL9+CgltgTWGwpBkqmG5EmpobcGu4=; b=VIIwlIX272mq9UeTuEfTi62Xs4d5qHflPTbINWEZrCccXfpVz6bSFfHXjJugfNi0bf Wh494h5uV0NTmt71W6mg8sIvtwRILsq54ABIgRMOz8+cPOzodMIqqSdIWtZAHg+/yYxr TNUIdC76Mw1Jr5Hk6KQvNi40iRmQF2e98IAw4G2E28E9CeBTChHw3FgeT6gFiNe5ACDU n35BEdy20XFt1bmG74ghUE4ki3q3sinnsgGntiL8KoYzcbifJtm2gZaxY9P7qg0c38hV TU7qjTOLoANQMwwA+pfY6UJEZg3TC3JWLIgUUMR5i2v+PNLd3RNWAAYIg/xrp+23mh+i DHJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733418833; x=1734023633; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Cm3ofDFIyWdFD3BL9+CgltgTWGwpBkqmG5EmpobcGu4=; b=cIQFs32XBiR+7CZrjXdCsBi+MHScFs537JuIJH1tbsrCtbU6T2wPSt26fn76NGhuow kL3hJo+jBcmEDERLP7WWJH1bJ0irRXm1FMj499a6QuNGCZUoN8FdnVPbxAVn6PoyBC/f r+pphZaCRj1gLzJkPlLbJUeWS9RLKn2UnsC1FtLhxMAh/2gViRMeZqXRsXhfOPofP7pk AZCvKo+olRy8TSQwiWLjVUY1ffrBgSoqSPkloxudHP6cwSDPnfkyXBnKpkoyDlJBB6If dY9pEsr+JMVQq/mpwjfKNghqTn+fwdZ73rDgbNyyNLVFZ0dHwdqpl6IHEwW5rdsKjgCu onjg== X-Forwarded-Encrypted: i=1; AJvYcCVRfTC7pB0VJAg/TOw92cLzMfSbiwCpLXB6K/vKXeRF5II8f0pJP55DzOPwNeBSBqbzeGDUm9DRdzrY2SWc@vger.kernel.org, AJvYcCVpD8IYKSAgCD8zxFrSQbk6o+guJdRYQe7DW32dyrIcokn9Dd9cq7f9tWRia1uAAEJE5DByjaU7cuo=@vger.kernel.org X-Gm-Message-State: AOJu0Yzj4mDQUBwMfp6BA4VHPK4npOwh4UykE3xDtyR2f1av3Aze3/7p xmPRRvM2P2jfqQ/LITAg/el49VDCLexvwa8RswC4JOK1XDuupSAJ1lFi7A== X-Gm-Gg: ASbGncv1UqEwdyjc2hfTaULssy/wAfWNhyPkqjJQPpn/CXww+qJJsKBieZFLPPDTZbx IZF+tVi3w9gxKuGkDqFKPOO0HcHWRdWZvhSy0ZEJuXE/I/XVML53WCevZkJNJjZZqkD+WN2zhRf JmZl9Gal5oS4OQ7DhDivu/lBQo5IYM7edQgOW0Smj9Gjy+z172XrF06EiszPvQHwWffLlKDH9WB gCX+eK0RX1Atu8w90Fc1fdKcxPIBUpTIMZR8t2LO1vEUlm/++iH8F7WJ72y+IroUQIzvdjOrtjc GlxHjB1t5fh2S1Ttzil9kuZafdQb X-Google-Smtp-Source: AGHT+IHrr//m0ja8VQ6jXf2ws7mp45otghmQaUxXSsRXoD32kRkIRPZApLyCDvPbQ7FsVloDwpIkJw== X-Received: by 2002:a05:6402:5292:b0:5d2:727d:dc04 with SMTP id 4fb4d7f45d1cf-5d2727dee72mr890508a12.8.1733418833422; Thu, 05 Dec 2024 09:13:53 -0800 (PST) Received: from 7b58d44c4ff6.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d149a48a38sm1026078a12.23.2024.12.05.09.13.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 09:13:53 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v5 02/10] iio: accel: adxl345: rename variable data to st Date: Thu, 5 Dec 2024 17:13:35 +0000 Message-Id: <20241205171343.308963-3-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241205171343.308963-1-l.rubusch@gmail.com> References: <20241205171343.308963-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Rename the locally used variable data to st. The st refers to "state", representing the internal state of the driver object. Further it prepares the usage of an internal data pointer needed for the implementation of the sensor features. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 44 ++++++++++++++++---------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index eb3ce4434a5..88df9547bd6 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -17,7 +17,7 @@ #include "adxl345.h" -struct adxl345_data { +struct adxl345_state { const struct adxl345_chip_info *info; struct regmap *regmap; }; @@ -43,7 +43,7 @@ static int adxl345_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { - struct adxl345_data *data = iio_priv(indio_dev); + struct adxl345_state *st = iio_priv(indio_dev); __le16 accel; long long samp_freq_nhz; unsigned int regval; @@ -56,7 +56,7 @@ static int adxl345_read_raw(struct iio_dev *indio_dev, * ADXL345_REG_DATA(X0/Y0/Z0) contain the least significant byte * and ADXL345_REG_DATA(X0/Y0/Z0) + 1 the most significant byte */ - ret = regmap_bulk_read(data->regmap, + ret = regmap_bulk_read(st->regmap, ADXL345_REG_DATA_AXIS(chan->address), &accel, sizeof(accel)); if (ret < 0) @@ -66,10 +66,10 @@ static int adxl345_read_raw(struct iio_dev *indio_dev, return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: *val = 0; - *val2 = data->info->uscale; + *val2 = st->info->uscale; return IIO_VAL_INT_PLUS_MICRO; case IIO_CHAN_INFO_CALIBBIAS: - ret = regmap_read(data->regmap, + ret = regmap_read(st->regmap, ADXL345_REG_OFS_AXIS(chan->address), ®val); if (ret < 0) return ret; @@ -81,7 +81,7 @@ static int adxl345_read_raw(struct iio_dev *indio_dev, return IIO_VAL_INT; case IIO_CHAN_INFO_SAMP_FREQ: - ret = regmap_read(data->regmap, ADXL345_REG_BW_RATE, ®val); + ret = regmap_read(st->regmap, ADXL345_REG_BW_RATE, ®val); if (ret < 0) return ret; @@ -99,7 +99,7 @@ static int adxl345_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask) { - struct adxl345_data *data = iio_priv(indio_dev); + struct adxl345_state *st = iio_priv(indio_dev); s64 n; switch (mask) { @@ -108,14 +108,14 @@ static int adxl345_write_raw(struct iio_dev *indio_dev, * 8-bit resolution at +/- 2g, that is 4x accel data scale * factor */ - return regmap_write(data->regmap, + return regmap_write(st->regmap, ADXL345_REG_OFS_AXIS(chan->address), val / 4); case IIO_CHAN_INFO_SAMP_FREQ: n = div_s64(val * NANOHZ_PER_HZ + val2, ADXL345_BASE_RATE_NANO_HZ); - return regmap_update_bits(data->regmap, ADXL345_REG_BW_RATE, + return regmap_update_bits(st->regmap, ADXL345_REG_BW_RATE, ADXL345_BW_RATE, clamp_val(ilog2(n), 0, ADXL345_BW_RATE)); @@ -180,7 +180,7 @@ static void adxl345_powerdown(void *regmap) int adxl345_core_probe(struct device *dev, struct regmap *regmap, int (*setup)(struct device*, struct regmap*)) { - struct adxl345_data *data; + struct adxl345_state *st; struct iio_dev *indio_dev; u32 regval; unsigned int data_format_mask = (ADXL345_DATA_FORMAT_RANGE | @@ -189,17 +189,17 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, ADXL345_DATA_FORMAT_SELF_TEST); int ret; - indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); + indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); if (!indio_dev) return -ENOMEM; - data = iio_priv(indio_dev); - data->regmap = regmap; - data->info = device_get_match_data(dev); - if (!data->info) + st = iio_priv(indio_dev); + st->regmap = regmap; + st->info = device_get_match_data(dev); + if (!st->info) return -ENODEV; - indio_dev->name = data->info->name; + indio_dev->name = st->info->name; indio_dev->info = &adxl345_info; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->channels = adxl345_channels; @@ -207,12 +207,12 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, if (setup) { /* Perform optional initial bus specific configuration */ - ret = setup(dev, data->regmap); + ret = setup(dev, st->regmap); if (ret) return ret; /* Enable full-resolution mode */ - ret = regmap_update_bits(data->regmap, ADXL345_REG_DATA_FORMAT, + ret = regmap_update_bits(st->regmap, ADXL345_REG_DATA_FORMAT, data_format_mask, ADXL345_DATA_FORMAT_FULL_RES); if (ret) @@ -221,14 +221,14 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, } else { /* Enable full-resolution mode (init all data_format bits) */ - ret = regmap_write(data->regmap, ADXL345_REG_DATA_FORMAT, + ret = regmap_write(st->regmap, ADXL345_REG_DATA_FORMAT, ADXL345_DATA_FORMAT_FULL_RES); if (ret) return dev_err_probe(dev, ret, "Failed to set data range\n"); } - ret = regmap_read(data->regmap, ADXL345_REG_DEVID, ®val); + ret = regmap_read(st->regmap, ADXL345_REG_DEVID, ®val); if (ret < 0) return dev_err_probe(dev, ret, "Error reading device ID\n"); @@ -237,11 +237,11 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, regval, ADXL345_DEVID); /* Enable measurement mode */ - ret = adxl345_powerup(data->regmap); + ret = adxl345_powerup(st->regmap); if (ret < 0) return dev_err_probe(dev, ret, "Failed to enable measurement mode\n"); - ret = devm_add_action_or_reset(dev, adxl345_powerdown, data->regmap); + ret = devm_add_action_or_reset(dev, adxl345_powerdown, st->regmap); if (ret < 0) return ret; From patchwork Thu Dec 5 17:13:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13895830 Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.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 ED673226EE1; Thu, 5 Dec 2024 17:13:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733418838; cv=none; b=Bsa62vVWo1c9RkDCU0jD7IwJfF5cSkYkZr2NOgLq156dwW5ncI3pIHVagxxmpop4nE7uJ49VB9i1qJ2VYWLMEeWUIwd7EDa6eMheDfwZ8LhefFch05QB4SPprbzigbpZ2TftQGs/CVf+sYaj63R58ROb8pZ+gMNyRAHLfCromqk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733418838; c=relaxed/simple; bh=tvlpR3ACIZjZ26sU6DfiM9q4+OrGk/guXwAtGKWdyjc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Yf9SwPn+tJUQVYRX4vo1xZD15YPPNv9OJzZsJ4jhWPic3Z3G1vFYmYLUtvC2sn+ZOeMayGexg4HwMrgEBT/025JyKurlUoNmwckQ+TEFkbxRpRynkhC8KodhDjEuTyBf/TruCSyxcptK2UT5Nqv64t7QHF9//Wh2o5FG8XnbrFQ= 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=daZ1ttaI; arc=none smtp.client-ip=209.85.208.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="daZ1ttaI" Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-5d071ac3f35so199770a12.3; Thu, 05 Dec 2024 09:13:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733418835; x=1734023635; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=M/9VPQ+Uf/rRtf7/eLBAF/0nGYfYrUrX91JqSy1ZhlA=; b=daZ1ttaInfSQrLywFWmmSIws9Yj+rsOsGj9R+/3xtkYTDy6T+TAYYBATALi2KM71dG vvVKcy66fCcq79ULpw2lPRi+0F8w7sGbUZeORpmTuJBzISCN0TbOn4ggcfFJcdcICtxd TtQ3YgIno5lMuvQbUbPtDPiPQAZSUgOByuDWGGXVSPPr06dhkf3gPAk/DIEJ82CsoBSA Inl3wvSyjpyEoAb8VPXoiLO0MLF03Ekk4LNx+ZH5G9VfqxB9cfL4Z4O/txkfhHLxUAEe KMpBf4TrJXF7QHUmUFYY/ZIqa09vi/V0WQ+jPqwoyKGS6S2TUxk9FngTPRvELnLAGQEu 4krg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733418835; x=1734023635; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M/9VPQ+Uf/rRtf7/eLBAF/0nGYfYrUrX91JqSy1ZhlA=; b=uVxDebyZdywcPwQ4p1iGDO2HU6SNoOU8Axg+l4RY1QbcPQll5oxz7u0bexIhy+E1iR daNg7gX++sfe2sZ0pF76GM+Rmm5O+x3hkGMb2Ah8XF0j409RKjz10zJHCTznhEWU5rmI mwmGcgBVHY8v8EUvhZCmCOVJVhqzae+bG/yqWD8rA5FaJZgyAMbmu2u5lLlH/P4KHbMU 1s6n40M1xv0wPwL/G7ysdhDh0p0/uGsJC2I7kYVuTfdjWbg0EO9/zbgW9xP0GNVzj4zg eecdYgJWYNXmUgrZejDg8dp0z9rVRusPstapfvlSgU5uPsYa29hvaizxJ935NIvGEMCr lgXQ== X-Forwarded-Encrypted: i=1; AJvYcCUnv/dP3kleP11T+gV2BkKzlsSg+VsQ0+h8PUsY2pb2NtsM4kju6Dyv2efKTR6Fp2d+kpreoTndO58A9nyP@vger.kernel.org, AJvYcCV+lswd1cZ8yl5mYfA6c3e8i8RqFqtBMzlTyu4xsxiZgo4Yr16TyVycjpvLElFyrL3Wc6n+ET9coZY=@vger.kernel.org X-Gm-Message-State: AOJu0YxG52nuktf8b0rWda3YcA6fryGX8Rtm/m+YMMLfeS+qdrt0TMK3 wbTYsG931k2bqR9CdVg/4pw4+Q0L6WI6nhm+F1bjhiei2iju4cHN X-Gm-Gg: ASbGncv/dhU04ZmQgZYkOdJ9QlQTkivWvg3pRfIusAy6Buuo9TS+MrS6Ri3t2HVr/8i doPkHvoaWsW2xA6eXsh2wamFEKpSlX+bVrir9PjUTS+8+2Tkh6rNt5F5ugCD+5eALNG6KSI/ETg /LD7MpwAhsCk8BUb/Jpruj4iNLQTvaOJyRXsNpubsqAspmX72Tt1S68EANm0eZ7d+0Pyegqalcf Wxg887nRrqCeePrlGNkqdGzDBvwfmj63n+W+8vjfuM4pkfcfMWFlkbkjOSYnt6loz4M7Dt01Tsr ddCnxr59XPijjH/4o7fAlHL9mYLQ X-Google-Smtp-Source: AGHT+IHxniLzjtZZeihCKuYCDWQbeQp69Zkp3YB2hcdmv9Z/VAazVP8MlMX8EXaUqEsfEQlcf208GA== X-Received: by 2002:a17:907:868f:b0:a9a:2523:b4fa with SMTP id a640c23a62f3a-aa5f7d1cecemr489437866b.4.1733418835073; Thu, 05 Dec 2024 09:13:55 -0800 (PST) Received: from 7b58d44c4ff6.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d149a48a38sm1026078a12.23.2024.12.05.09.13.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 09:13:54 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v5 03/10] iio: accel: adxl345: measure right-justified Date: Thu, 5 Dec 2024 17:13:36 +0000 Message-Id: <20241205171343.308963-4-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241205171343.308963-1-l.rubusch@gmail.com> References: <20241205171343.308963-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Make measurements right-justified, since it is the default for the driver and sensor. By not setting the ADXL345_DATA_FORMAT_JUSTIFY bit, the data becomes right-judstified. This was the original setting, there is no reason to change it to left-justified, where right-justified simplifies working on the registers. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 88df9547bd6..98ff37271f1 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -184,7 +184,6 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, struct iio_dev *indio_dev; u32 regval; unsigned int data_format_mask = (ADXL345_DATA_FORMAT_RANGE | - ADXL345_DATA_FORMAT_JUSTIFY | ADXL345_DATA_FORMAT_FULL_RES | ADXL345_DATA_FORMAT_SELF_TEST); int ret; From patchwork Thu Dec 5 17:13:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13895831 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06B47227B80; Thu, 5 Dec 2024 17:13:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733418839; cv=none; b=BqCl46Sc+yrSt+4jdrfC1ymqTG0KEPRKSM12SEQTI+zi8CKlNmSX++1i1ejk98jdoa8XwGVuDM8rsngHNNVh+PLs1rfYBfviiSp0+oLwp9bjJ3SzmE47SIpuMyxim/ruLaIEiwN9fRM9dPe3LUow9CWyueLJvDE5JQW0d5s5MQc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733418839; c=relaxed/simple; bh=gOf02a1jPfvJOuetJm2rPZvTaAz1JfUZwEdwhYgo87U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=d7NFFQWW/G7q5ZRenIg/EwRwLbLgZRhG/UeWvG/XrD71FWKhT6BIf4DQt6cAW84q7aoKN0atZA9ruIjsQJ/bXUr/gG4gRGe8H0dMEO7MesiWfPas9MpsLO8++HUWJOFF02UY7TVvtqHtla/OhyydHSP7dUZ5lEKr4vJO2z9XH30= 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=j1aXfuo/; arc=none smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="j1aXfuo/" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5d0d81eff58so179220a12.0; Thu, 05 Dec 2024 09:13:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733418836; x=1734023636; 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=FRuw2enA1+kkdjSgQgqyvtqwVBm94V5xgygsnwgPZM4=; b=j1aXfuo/2SIjM58zp4nPVjn3oaaOT4Mk1Z4LIx84zhii7VXzxagHGiqkCCOiXXOArQ I0feG5EJnAgCQr9NBygUVm++3Ij4tlhv3OXM4P57EmjJfFxTY4JY5lOcjQarBz1kD6Xe sRT1c8KWuS1heYgFy6XX/mc0/ogbf1k4paxVbSBgLTWn2peJGN6Gaecb8NwkL0p9SMCj /m2sQZFuueBpseMRnZrUTnb5NaR9ebfbsKemKhQVnoYdrOyzWrtD2baL7gn9H/KDhtEI xfaJlatTY7scS4gAKinFTA6MHQYGRTAdqiFTM0cFlXx4oOfuyOlbufY+tofqqKbPmHNK XiHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733418836; x=1734023636; 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=FRuw2enA1+kkdjSgQgqyvtqwVBm94V5xgygsnwgPZM4=; b=MKTfqkboAZtirhrV4gZO4+BmHUqWBAFLUH1DgbuTa1qhfiQZHGNNEpb7QN94Vzkitr DQZrHNowCzlUYFo3HbLz8eHAEJOT+PcSNWR9V/m0490NCLEV/yWgRhLNfvBJaf96Wlk2 HlGVDSeCtCuq49HZzH7u181HPd1cyHf8gx6LLAL3RKDZ0eU/e16FHws/sKPy/Ugg5A/N MUUbnnyJwjwwTzFQPnSim7MFSOSSEVhSnZCHEf46Tq7pgfqbPGln68uO+5Ic6/MmdxuW guFKhj32aBL6+RdhuQT5NgUZ2ht7YeXUxKZ3pjQf8o6YM6FzbEh/LLbU/rKeoLQCnp11 1Kfg== X-Forwarded-Encrypted: i=1; AJvYcCUAh8C6VPkUvJ0xEpxIK6GOKR5xv1qwi83gnW801qSA/EF72VRY7eKCjMzHOb6RFLq6RO5fDlGuReo=@vger.kernel.org, AJvYcCWwwI1zB5KVr2EMYzzcNGBXi16wz6p3hkXOJsq2y8te5mcS4rJ15pHNgW9e9qkB3hvXv3MZ1Pq7q9+JaZNy@vger.kernel.org X-Gm-Message-State: AOJu0YxR5gpWPznO4fOaXRsp39+uE2mpTlGoOTHfQJRwbdFf8a5JNpM/ 9DQpf/W6PUCJlWnk6oYmK8kAv+mIxJxo27GTDFIPcWF7yNauEOKP X-Gm-Gg: ASbGncuMYcrIBg5iXLugrJyDYbjGABhNBuUhhrdo4C4zcsPjQgut/zUDVzbh8X/kdl/ tCdg4AicI0rPTwkdOfmxVuWfEQ8UyWp/0r7REK0ede/jto6vzCzNk9xMCqSXhSzD/4v/7xWcjEM IMaUNq6XQrtQhiAsI9nEjwHK/iGIDv2vjcPfHO5g3MlZbvcjmFImsm1Uif1rZG4/jnLA6FMcfa0 q5sF5EyWB/g0FPFOKK0GySOyb9a0RZHTCr7Jk9Yo8FH3vV7ZkhyKFd4V/86x9BZILCK9iNCrcgf a5lyYFXBZtuRkr8BDvi8rYQQHSTM X-Google-Smtp-Source: AGHT+IEPmmIHEU8L9dudNBH7URQZNM1P0X5zrxs/mSndPxxhnR2eSsDA7khSQngJ2D7rowE41ySI8Q== X-Received: by 2002:a05:6402:27d1:b0:5d0:e852:dca0 with SMTP id 4fb4d7f45d1cf-5d10cbad297mr3915551a12.11.1733418836208; Thu, 05 Dec 2024 09:13:56 -0800 (PST) Received: from 7b58d44c4ff6.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d149a48a38sm1026078a12.23.2024.12.05.09.13.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 09:13:55 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v5 04/10] iio: accel: adxl345: add function to switch measuring mode Date: Thu, 5 Dec 2024 17:13:37 +0000 Message-Id: <20241205171343.308963-5-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241205171343.308963-1-l.rubusch@gmail.com> References: <20241205171343.308963-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replace the powerup / powerdown functions by a generic function to put the sensor in STANDBY, or MEASURE mode. When configuring the FIFO for several features of the accelerometer, it is recommended to put measuring in STANDBY mode. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 44 ++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 98ff37271f1..1d020b0d79c 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -138,6 +138,34 @@ static int adxl345_write_raw_get_fmt(struct iio_dev *indio_dev, } } +/** + * adxl345_set_measure_en() - Enable and disable measuring. + * + * @st: The device data. + * @en: Enable measurements, else standby mode. + * + * For lowest power operation, standby mode can be used. In standby mode, + * current consumption is supposed to be reduced to 0.1uA (typical). In this + * mode no measurements are made. Placing the device into standby mode + * preserves the contents of FIFO. + * + * Return: Returns 0 if successful, or a negative error value. + */ +static int adxl345_set_measure_en(struct adxl345_state *st, bool en) +{ + unsigned int val = 0; + + val = (en) ? ADXL345_POWER_CTL_MEASURE : ADXL345_POWER_CTL_STANDBY; + return regmap_write(st->regmap, ADXL345_REG_POWER_CTL, val); +} + +static void adxl345_powerdown(void *ptr) +{ + struct adxl345_state *st = ptr; + + adxl345_set_measure_en(st, false); +} + static IIO_CONST_ATTR_SAMP_FREQ_AVAIL( "0.09765625 0.1953125 0.390625 0.78125 1.5625 3.125 6.25 12.5 25 50 100 200 400 800 1600 3200" ); @@ -158,16 +186,6 @@ static const struct iio_info adxl345_info = { .write_raw_get_fmt = adxl345_write_raw_get_fmt, }; -static int adxl345_powerup(void *regmap) -{ - return regmap_write(regmap, ADXL345_REG_POWER_CTL, ADXL345_POWER_CTL_MEASURE); -} - -static void adxl345_powerdown(void *regmap) -{ - regmap_write(regmap, ADXL345_REG_POWER_CTL, ADXL345_POWER_CTL_STANDBY); -} - /** * adxl345_core_probe() - Probe and setup for the accelerometer. * @dev: Driver model representation of the device @@ -236,13 +254,13 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, regval, ADXL345_DEVID); /* Enable measurement mode */ - ret = adxl345_powerup(st->regmap); + ret = adxl345_set_measure_en(st, true); if (ret < 0) return dev_err_probe(dev, ret, "Failed to enable measurement mode\n"); - ret = devm_add_action_or_reset(dev, adxl345_powerdown, st->regmap); + ret = devm_add_action_or_reset(dev, adxl345_powerdown, st); if (ret < 0) - return ret; + return dev_err_probe(dev, ret, "Failed to add action or reset\n"); return devm_iio_device_register(dev, indio_dev); } From patchwork Thu Dec 5 17:13:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13895832 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24607227B9A; Thu, 5 Dec 2024 17:13:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733418840; cv=none; b=L3dIIEgHsKYMKCJ0XlqAq3NzrEzobavAjJy8kY1siPC6tvl/SmwS5N4dAULzRjqJg4tNynADPqzMTTpwu7MvJ2p3DcEVjLnl3P6k+ch/cdl25OeP4tR+nCoY82xgl8zxJ9gjSjM7GcrOtlLsTfX8sTh2uVaXLbw3Xsybz/2x+Zo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733418840; c=relaxed/simple; bh=xlamxEB29KLW/kB5qDjRmFtRz+0Olyx4qFv/pVdhRQ0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XjgxxdbuknRLNIXL2047563BlV3WOT5/1jmUBZfXgKTDv/R8BXgPKvKvmRs+8WoO1dZ7zYkinOtLDwVwDSIyAkWCZ4UfcmvF2Y5i5wFQ1gb22yRb5Qek+XIp8GA/X+UR5m+Dr4hwZlPfaFFgq6n/nB7E+Tsc5vl5ws9+nTq7FMY= 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=IHMZ3s7K; arc=none smtp.client-ip=209.85.208.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IHMZ3s7K" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-5d0ac3be718so161853a12.1; Thu, 05 Dec 2024 09:13:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733418837; x=1734023637; 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=2Fd+RIYfyJGlnD0kUkio9w5hOzwFeUW/miLAqJR8L8E=; b=IHMZ3s7KsaDi8KFje/8dWd/BexIiAeK6SJum36UvwClxQoxXfQ6w39XQoBBXZurFEg X9pabtFeNozJZDI8wGGNYVWO0RAfR+NARpA60lD16ZJO6GEA7nUMsqkVxk1+i+zclII1 dArcY1PYpvyLcy8+g63r/bligltnTryjl/NjbyESaysLH0qyw58XYT9FcL59BBgF3L+r H7ltYRMTtEryGqL/jKVSMyje3XQCRGZKicRNlNYuaEVrDUEgHrJNScXPwwvMm4Ky4UEc VYGaC5UF0UwHsC0ItRyZFipJPcmYW/wQPSgDsBjFzyjBy85h3dEd9UGcKn5PcBcQ9zpJ Zv5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733418837; x=1734023637; 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=2Fd+RIYfyJGlnD0kUkio9w5hOzwFeUW/miLAqJR8L8E=; b=aRdanDsQknY70QCO6gO9ZYwcpIVBgGQmdbyhW9Pp/ZSPfwi584bNRpevtFi8vacrSR /yVRCtXjWPWSbW95f2sCc+6UixODplrRifieaFFvxEsVuWp4ffbc9i97oNJeNrofyGLo 6OsEnznMlXurYHCdCgQbC4rhGhNJZ85fRlLZYZaaPC29ENrDCs5ep1TZH4E8GjjneKPb 7nITJIJX7SkBTtl1IL08TFruGVwT+Q+l12SxsDoImvAKUcW+pURNUKYkynKJF5uK/uXn fLNb4+IFnjvg2fC15Oqhmn0Or6Qkj/JISVQ0ijG3Jik4ka2BJVJXWdi8grPDESEeGBNN WFqw== X-Forwarded-Encrypted: i=1; AJvYcCUOzkgtRMcn+Eki8bSP3ySot9AG6nEqPppo5lFz0zjUJOf2XSAaQ+onvaBg8MX1VWQ5QhEXtV3FxG8=@vger.kernel.org, AJvYcCW+pJh0mt81HkAdXldDBudrtIM/0b+QV44zwOmyV1BrivJLLUYKlziZ8H/J1q13H4o56e3inOiOr4lpGLbC@vger.kernel.org X-Gm-Message-State: AOJu0YzJrf42H4vc+9+wsNV9psCj2NvKHKw8oWoy6gTIabpQqq6hw2eh lQikROHO3CDQGFrAoDblO7ZpbXAH2inK0gnjoTnvavxf0hEkhGLhxhS6PQ== X-Gm-Gg: ASbGncseridOQ+RdcwpnEbV/01QtzLJxxgLq9atEHU2gx2vtnApSIspPagU/2CnsKEN IupNboz/n8wFl5aLjgVhepyXCc27HntgzqCriKgIF0SyxUCvF9pG+XbAz02F0RGHqGij52qwuRN UATCAJiJsLw6k8oGpq3il6bDBZg23vdk+jA9kSaTIEkJHnDrJmqNppiYMYMBY0W710jxHWxFE5S tzPJYvaHT8KJ2mLwePy2Wlc27Sl9oJu8N6VZWq8WoPTNhuHsfBvtmUx/+m7UWGNHXoUDk59aT0K W3n2WKl5RWXZKoU5Z4clze+h3mMw X-Google-Smtp-Source: AGHT+IEIZpV3kkLWrQBzqU54SQXuuO0R56GVBUwq91zwGdpJF+UX39JNePuZtaL1CPgj8pYkE0UNJQ== X-Received: by 2002:a05:6402:26c7:b0:5d0:bd3b:b9a9 with SMTP id 4fb4d7f45d1cf-5d10cb99b97mr4068335a12.8.1733418837277; Thu, 05 Dec 2024 09:13:57 -0800 (PST) Received: from 7b58d44c4ff6.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d149a48a38sm1026078a12.23.2024.12.05.09.13.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 09:13:57 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v5 05/10] iio: accel: adxl345: complete list of defines Date: Thu, 5 Dec 2024 17:13:38 +0000 Message-Id: <20241205171343.308963-6-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241205171343.308963-1-l.rubusch@gmail.com> References: <20241205171343.308963-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Extend the list of constants. Keep them the header file for readability. The defines allow the implementation of events like watermark, single tap, double tap, freefall, etc. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345.h | 89 ++++++++++++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 12 deletions(-) diff --git a/drivers/iio/accel/adxl345.h b/drivers/iio/accel/adxl345.h index 3d5c8719db3..ed81d5cf445 100644 --- a/drivers/iio/accel/adxl345.h +++ b/drivers/iio/accel/adxl345.h @@ -9,37 +9,102 @@ #define _ADXL345_H_ #define ADXL345_REG_DEVID 0x00 +#define ADXL345_REG_THRESH_TAP 0x1D #define ADXL345_REG_OFSX 0x1E #define ADXL345_REG_OFSY 0x1F #define ADXL345_REG_OFSZ 0x20 -#define ADXL345_REG_OFS_AXIS(index) (ADXL345_REG_OFSX + (index)) +/* Tap duration */ +#define ADXL345_REG_DUR 0x21 +/* Tap latency */ +#define ADXL345_REG_LATENT 0x22 +/* Tap window */ +#define ADXL345_REG_WINDOW 0x23 +/* Activity threshold */ +#define ADXL345_REG_THRESH_ACT 0x24 +/* Inactivity threshold */ +#define ADXL345_REG_THRESH_INACT 0x25 +/* Inactivity time */ +#define ADXL345_REG_TIME_INACT 0x26 +/* Axis enable control for activity and inactivity detection */ +#define ADXL345_REG_ACT_INACT_CTRL 0x27 +/* Free-fall threshold */ +#define ADXL345_REG_THRESH_FF 0x28 +/* Free-fall time */ +#define ADXL345_REG_TIME_FF 0x29 +/* Axis control for single tap or double tap */ +#define ADXL345_REG_TAP_AXIS 0x2A +/* Source of single tap or double tap */ +#define ADXL345_REG_ACT_TAP_STATUS 0x2B +/* Data rate and power mode control */ #define ADXL345_REG_BW_RATE 0x2C #define ADXL345_REG_POWER_CTL 0x2D +#define ADXL345_REG_INT_ENABLE 0x2E +#define ADXL345_REG_INT_MAP 0x2F +#define ADXL345_REG_INT_SOURCE 0x30 #define ADXL345_REG_DATA_FORMAT 0x31 -#define ADXL345_REG_DATAX0 0x32 -#define ADXL345_REG_DATAY0 0x34 -#define ADXL345_REG_DATAZ0 0x36 -#define ADXL345_REG_DATA_AXIS(index) \ - (ADXL345_REG_DATAX0 + (index) * sizeof(__le16)) +#define ADXL345_REG_XYZ_BASE 0x32 +#define ADXL345_REG_DATA_AXIS(index) \ + (ADXL345_REG_XYZ_BASE + (index) * sizeof(__le16)) + +#define ADXL345_REG_FIFO_CTL 0x38 +#define ADXL345_REG_FIFO_STATUS 0x39 + +#define ADXL345_DEVID 0xE5 + +#define ADXL345_FIFO_CTL_SAMLPES(x) (0x1f & (x)) +#define ADXL345_FIFO_CTL_TRIGGER(x) (0x20 & ((x) << 5)) /* 0: INT1, 1: INT2 */ +#define ADXL345_FIFO_CTL_MODE(x) (0xc0 & ((x) << 6)) +#define ADXL345_INT_DATA_READY BIT(7) +#define ADXL345_INT_SINGLE_TAP BIT(6) +#define ADXL345_INT_DOUBLE_TAP BIT(5) +#define ADXL345_INT_ACTIVITY BIT(4) +#define ADXL345_INT_INACTIVITY BIT(3) +#define ADXL345_INT_FREE_FALL BIT(2) +#define ADXL345_INT_WATERMARK BIT(1) +#define ADXL345_INT_OVERRUN BIT(0) + +#define ADXL345_S_TAP_MSK ADXL345_INT_SINGLE_TAP +#define ADXL345_D_TAP_MSK ADXL345_INT_DOUBLE_TAP + +#define ADXL345_INT1 0 +#define ADXL345_INT2 1 + +/* + * BW_RATE bits - Bandwidth and output data rate. The default value is + * 0x0A, which translates to a 100 Hz output data rate + */ #define ADXL345_BW_RATE GENMASK(3, 0) +#define ADXL345_BW_LOW_POWER BIT(4) #define ADXL345_BASE_RATE_NANO_HZ 97656250LL -#define ADXL345_POWER_CTL_MEASURE BIT(3) #define ADXL345_POWER_CTL_STANDBY 0x00 +#define ADXL345_POWER_CTL_WAKEUP GENMASK(1, 0) +#define ADXL345_POWER_CTL_SLEEP BIT(2) +#define ADXL345_POWER_CTL_MEASURE BIT(3) +#define ADXL345_POWER_CTL_AUTO_SLEEP BIT(4) +#define ADXL345_POWER_CTL_LINK BIT(5) #define ADXL345_DATA_FORMAT_RANGE GENMASK(1, 0) /* Set the g range */ -#define ADXL345_DATA_FORMAT_JUSTIFY BIT(2) /* Left-justified (MSB) mode */ +#define ADXL345_DATA_FORMAT_IS_LEFT_JUSTIFIED BIT(2) #define ADXL345_DATA_FORMAT_FULL_RES BIT(3) /* Up to 13-bits resolution */ -#define ADXL345_DATA_FORMAT_SPI_3WIRE BIT(6) /* 3-wire SPI mode */ -#define ADXL345_DATA_FORMAT_SELF_TEST BIT(7) /* Enable a self test */ - +#define ADXL345_DATA_FORMAT_SPI_3WIRE BIT(6) +#define ADXL345_DATA_FORMAT_SELF_TEST BIT(7) #define ADXL345_DATA_FORMAT_2G 0 #define ADXL345_DATA_FORMAT_4G 1 #define ADXL345_DATA_FORMAT_8G 2 #define ADXL345_DATA_FORMAT_16G 3 -#define ADXL345_DEVID 0xE5 +#define ADXL345_REG_OFS_AXIS(index) (ADXL345_REG_OFSX + (index)) + +/* + * FIFO stores a maximum of 32 entries, which equates to a maximum of 33 entries + * available at any given time because an additional entry is available at the + * output filter of the device. + * + * (see datasheet FIFO_STATUS description on "Entries Bits") + */ +#define ADXL345_FIFO_SIZE 33 /* * In full-resolution mode, scale factor is maintained at ~4 mg/LSB From patchwork Thu Dec 5 17:13:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13895833 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.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 E988D229B08; Thu, 5 Dec 2024 17:14:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733418842; cv=none; b=WhGmPaqqIaNYL5azFDQqbZE5oTYDygQ550YVBbnAxOXtFgHpICt5OpCb6E/s82to313gQUhoSDJzlD9alh/vch8RhJHSvq6QojUVpZUOY+i4ZMhYmE74udZm3H/jMUgSc26zWPKBwp3vizIDSdTQpSKPPZeKss972S7agCP4eSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733418842; c=relaxed/simple; bh=DsRIegOFuHGSg0vE7VksllcTePQRArPVTkkMqQna8f4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NUUagjO4pGNAEhdpMIhw1OZGPl1M33hPJJLCvCNnkeOyxy10k44uYLJG9IjE2wi3HZpuJPTzklQdcA3YR682CjKHNqSHyE4hyUO8HwwcKsybrMp3HwS5pbg9fXxwbtHLDcaTw7HgEHhqGL3xQBZhooSsNmMxb4l9lAEqjcGCQ88= 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=avzACSvN; arc=none smtp.client-ip=209.85.208.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="avzACSvN" Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-5d0e4f60251so179380a12.2; Thu, 05 Dec 2024 09:14:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733418839; x=1734023639; 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=A8lsmxVB2omsrMm6z/32rsJzuI9/t8xsIVZSIv9D1K0=; b=avzACSvNP42MrtHmWOTa8h9LOpFGWSGE/rfqDiw45AsDJkxfM6hDkfhRbvo5T1UIda J0mNXZLbir0QvftJ7qvGQQqccHra7+DMNqXpvzE/o6bbxtgwe233IEkIhie6SMvuHEXY TQtf0rVi350tS7lA/VtuTZiGSgybHkGUzV/JOEH0PKKWyq2u/YeutHlpdAviME7Ls8hf Wg1driRg8fj+nYmJ8idwXWUp3bBALGOi9LlRB0TcHygT45JhDJeg7x7nZkGPE9LdBrMz NPWFqycAn7u2fBCye6WOzePpBDBzyqctq5uX4F/kb1iqZuDH4HgFG1Po6pTjsD5vJ21m ff8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733418839; x=1734023639; 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=A8lsmxVB2omsrMm6z/32rsJzuI9/t8xsIVZSIv9D1K0=; b=bl2RrUazxhgyd7y+TC387NrioAseY6X/i4L75v9s80QsXjSv/kMnHWyRuKFjz4frNl rM9XleLOTmYDKwvfUPbuQE0IywW8tKbFeWEb6yrobaQ3vxYRW3Wv+sqt2FJJmXhBvQnE P4v5tacUHidKayeEa0/IED7I7fEu5BGp/fZ/L3wOSLXOquKtYBnvuUyujYcw+akcIbv3 YyR7CJInxmBGR2ca0WdSG7rDyddYnz/Qaxk5vPkZ6Cga0SiFHdfZHhxRSAcgbInY72VS Ghonxe2bIIGjxiriviJyLLBAGeIjl6AdmLQnecV0DZGrht6FRL8JiWh0kz3OeQ8/kj7T xtpQ== X-Forwarded-Encrypted: i=1; AJvYcCWFndIoy6v7Ma1FRPTsZp6Xxa29QgrLIi0RdnmOEgFBoCr1QOV03mhPe5pIsnr5Q60SohDEaPM031DqZRE6@vger.kernel.org, AJvYcCXbr+CAuNHLTmG9KWecqoESuCHEDy0FeuvsYHOMeAalrrnrtpehmUXeVISjU5qNqhEwQGWJO5fVWqA=@vger.kernel.org X-Gm-Message-State: AOJu0YzsZrifyiax7CJDazwlfiYO/aJnhFlr2YNL5QuxheLpbZUb13XR Uito3F/D3VzyU0+6zLOGIBDldomwWGqzuM3SmMtUvezgTInTvmBD X-Gm-Gg: ASbGnctNDwjN1ta6MF6eCEcME+tfhWujZ/Fx/m7TBP1e6UXrBHKDWggeWxxcvMJlUE0 c8SM6YTZi1BKjHFyQpm7v2D9qNde5c/WZzk9O5Nk9fAgiFt3m9qWWnY1Pr9rW/ZrLPM/aQ7LAHQ vZjk9nY4z4I9Zg2IVQYhMifBwxD51J/Vb5j4XaODaxf6nuAUaI7CXuJfrDgniMzrxJ0BggSQdds 8ncN1hLh/A1qK/iVKTfwA7k4I3rYdY7/bxhSG0pMau8x9BjR78R0XVN1BC1bXy7brKKjPRBWnDK j6MAqWqULObFJDcxb476Dwq59umwiY4D X-Google-Smtp-Source: AGHT+IHjtbMgzH2r69k9e8KVIJIcxquU81vmNXpGebYBAFGvp3+JuN7wqUYI0bksK2pkRjWi3J5Uog== X-Received: by 2002:a05:6402:849:b0:5d2:7262:9492 with SMTP id 4fb4d7f45d1cf-5d2726295dfmr819469a12.2.1733418839176; Thu, 05 Dec 2024 09:13:59 -0800 (PST) Received: from 7b58d44c4ff6.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d149a48a38sm1026078a12.23.2024.12.05.09.13.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 09:13:58 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v5 06/10] dt-bindings: iio: accel: add interrupt-names Date: Thu, 5 Dec 2024 17:13:39 +0000 Message-Id: <20241205171343.308963-7-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241205171343.308963-1-l.rubusch@gmail.com> References: <20241205171343.308963-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add interrupt-names INT1 and INT2 for the two interrupt lines of the sensor. Only one line will be connected for incoming events. The driver needs to be configured accordingly. If no interrupt line is set up, the sensor will still measure, but no events are possible. Signed-off-by: Lothar Rubusch --- .../devicetree/bindings/iio/accel/adi,adxl345.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml b/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml index 280ed479ef5..67e2c029a6c 100644 --- a/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml +++ b/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml @@ -37,6 +37,11 @@ properties: interrupts: maxItems: 1 + interrupt-names: + description: Use either INT1 or INT2 for events, or ignore events. + items: + - enum: [INT1, INT2] + required: - compatible - reg @@ -61,6 +66,7 @@ examples: reg = <0x2a>; interrupt-parent = <&gpio0>; interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "INT1"; }; }; - | @@ -79,5 +85,6 @@ examples: spi-cpha; interrupt-parent = <&gpio0>; interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "INT2"; }; }; From patchwork Thu Dec 5 17:13:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Rubusch X-Patchwork-Id: 13895834 Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.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 7C6B522B8B0; Thu, 5 Dec 2024 17:14:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733418845; cv=none; b=acCfiHRZdNlCtXxGnNKR3C7vSLnEiVG5TNm4vIXOwtn4M242hgm1egEYM8WGiX78EoaG9xmMsW6UTzmNxgJ69SsG/C4Cul3via4au2tBMhTEadcyrKIr/6RCFhdDwCtZ3kHyDFcwzIGuI4tixB1fZJrPdOuqehkM01GPDbjGhZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733418845; c=relaxed/simple; bh=DNVEhDMJmPlkCOLPbA9YCV7kbaVuS7EEz+47Is7CTEM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Iz4vHmWx9jYglkuXr6wn1TYK09wGzUrP8uzun+bffgLvkNF5hmqquPSD+7mjGuFhyYstCGp0wHt0+mdmKVYkABI+ZsCVXsSXLbkZP7KanDcxULENUC/1Ve8KvMvxQ9RqZz2z4njJqN02XqhWwggpdF9AIvIqKo+cgZ6x2XHAcNQ= 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=W93ZXfi6; arc=none smtp.client-ip=209.85.208.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="W93ZXfi6" Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-5d071ac3f35so199800a12.3; Thu, 05 Dec 2024 09:14:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733418842; x=1734023642; 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=ooJ274uvhKmoCEz5rGR7u9j6kRhYQqTeS8QB6cKiNxw=; b=W93ZXfi6+48RUidBRKXTiN7yk2GyJ9497YZ2e1deUcL5Tikv1UMjLfASCmg3YbyR1e 0pBWdvSotCxMKSLjjFapm2a6kn1EyYr9XjlHFe3Xx8RWnSSDPNMqMZbgVme1yKIUO8Ki JUd8LReuA6iZKZITz7SocU/sVp8qIL9smNoE7XD8W1eUAMZ/XwCuFoLP07FvF8XeCOfm 2pZvpNtOaGkDmuiUOKiXJUF7GJlBBvYiZRVLS4C/0uFQWo4CjiMV4YD2sXXxpuNchNLf GwyHBzCrO4p+Dc1jrVZtLoLPrnvmN3QwF9IS5nZSQYeyr1la+QPQM0oyPHuOSnUeJtw0 wvBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733418842; x=1734023642; 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=ooJ274uvhKmoCEz5rGR7u9j6kRhYQqTeS8QB6cKiNxw=; b=oFQGdOfz3U65Zvq6PmVgZFVUSBvpKXFsFEc+bCMdxh0CrqdNnCdX64Rm59GZ9Adr4u aUrgAIuW76jEYE/mmtqdLAP7BiXefd+eW2jG65pi9F27ZyVS0HKg23gNImidouP0Q/Nb oOS3VK9R0ZB7/rxjZK/vzv/4jsSI/rEeIkmHsT9MYGkloCeBdteLqx3R1qwqIpVzR1bT 19AOu/j2W5LBkYvm1odXZ7zkMNTBphBePlbj/AP3YtE1nz3ueiAZ0hUtKEq3LQoExnLn uZpWU5IQV0B0DCKM+QOw4ayomh2UOWg0IxwlSSOOhuNxLN+lbGXawZuC3f9PBZZU2AGH BayA== X-Forwarded-Encrypted: i=1; AJvYcCUwbQ8JHih3oxULspsZAOyuVVfFY1HcnyYNrab55iQ9yckMOoKw/PtRNkEKKMxlA44BHY/KJzXPWZc=@vger.kernel.org, AJvYcCXXj6+JmUNNC0HVB4a8o4KN32+wKURjffXM9PR6EfzJ+mHvWMpJekXMRm5aG0TDvp+oFDQyWQMHXe+m01ap@vger.kernel.org X-Gm-Message-State: AOJu0Yzr/agioqe/2qMglNT5QY/85r5RHUXL9XKIy1Vn8Cu74PiYBuG4 CSdfvDFUHQ97dP2VkLSO4UjBMurqHZ8IsFsRsrE/2YhX8/0+bEw2 X-Gm-Gg: ASbGncsVJKS+4ZjFtLoDcq7/uEpJ+oHEVlFIpieB4t8WC847zpMW3Skd+BiSfcCHzWN pgdCgeyuOAYX8DEcoZ5EBBWQ392WZxNTin2E3czoAwUVWJVw4ivCwKCimo4Uway0lALS8WrpGFX FQ4BUNB4iZC2nzD1kjiQYY+lq+nTT1fK1uzARNorzKt9gV+wKDjBm/LFT+Cpcv2xWuj+jVfFCMV 04Odkxrhy8js5892oJtNnK1MIa3VhSIVUyuR8bhoc+rlYH7i8dovlApe2hk9G4y0XmgpNGVnzJh qBGHYfet2LaIxm++hC9YIw4TN17L X-Google-Smtp-Source: AGHT+IFe38z1xRo3uqmxUHzVoerDbRxkJ8LFyH5rUiT/0wpMEEspjDL0imPwxHkekg9FrRKZVMSZsA== X-Received: by 2002:a05:6402:520c:b0:5d0:bf79:e92e with SMTP id 4fb4d7f45d1cf-5d10cb7f978mr3994076a12.6.1733418841700; Thu, 05 Dec 2024 09:14:01 -0800 (PST) Received: from 7b58d44c4ff6.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d149a48a38sm1026078a12.23.2024.12.05.09.13.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 09:14:00 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v5 07/10] iio: accel: adxl345: introduce interrupt handling Date: Thu, 5 Dec 2024 17:13:40 +0000 Message-Id: <20241205171343.308963-8-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241205171343.308963-1-l.rubusch@gmail.com> References: <20241205171343.308963-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add the possibility to claim an interrupt. Init the state structure with an interrupt line obtained from the DT. The adxl345 can use two different interrupt lines for event handling. Only one is used. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 1d020b0d79c..e0a8b32239f 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -18,8 +19,10 @@ #include "adxl345.h" struct adxl345_state { + int irq; const struct adxl345_chip_info *info; struct regmap *regmap; + u8 intio; }; #define ADXL345_CHANNEL(index, axis) { \ @@ -212,6 +215,17 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, st = iio_priv(indio_dev); st->regmap = regmap; + + st->intio = -1; + st->irq = fwnode_irq_get_byname(dev_fwnode(dev), "INT1"); + if (st->irq > 0) + st->intio = ADXL345_INT1; + else { + st->irq = fwnode_irq_get_byname(dev_fwnode(dev), "INT2"); + if (st->irq > 0) + st->intio = ADXL345_INT2; + } + st->info = device_get_match_data(dev); if (!st->info) return -ENODEV; From patchwork Thu Dec 5 17:13: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: 13895835 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.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 836D922B8D9; Thu, 5 Dec 2024 17:14:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733418847; cv=none; b=oip9GJmlp+LkAS6wop0EMfRkQOgtpfwIZx7oyxq9xEjn5s9xVk+uhs8HjzNl1o7t2NUnsuCy78RvHYGft32WbS/bhQmYXm+w5M6wfNsjAHUMnftMyIOphFABzdE3O/O9oB+4U+FLF9o62WgGN4l89c+jKd/BJmHUqNzVjFDIBOw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733418847; c=relaxed/simple; bh=1JB2wb1ixUQ2tLhVrAdRSy7hUKQW2Tn/gK7Kv0OWlYM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iQWsa/UC2htIdAZ/KeJfohFm1jos16vUvkHQ/QSAOM+L1x9hJ4C1xXsreFYDEAxu8SY0le+/AyC5WCCXS1S8L9HI2oa7OFul3uJpGoL1lfaK6SwBTCZXcYszUw2LpPcEBvsBWcvRSMNW4bzmL2X6LkgQB9NjthDnIg0ABqnOjwc= 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=UfFWHvuE; arc=none smtp.client-ip=209.85.208.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="UfFWHvuE" Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-5d0bdb7ea5cso154893a12.0; Thu, 05 Dec 2024 09:14:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733418844; x=1734023644; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xNQM2De0uWsZzOP6u/2v236oC/9A63z8kL2Apq3LH5U=; b=UfFWHvuEBHXjwZ/V5s0WxRcH2opkbdtzGCnDxkLsmDTSzLAbxcRhNzXhDwkcv5c9oP 3FNE4CiITqpYa4gfFL2LG+dPVlE1e/PHFWQh5gTXQ9Z2hktgCWpPCQaUE1jGaiIkpiI8 q0AjOgTPsELj/2k4ow9+fkLv9wz0fe2aLSu6N2Px/FQQYW9cbuiW7xjcNv8rJjBdnmaH FJnmKqJIrrPhUJd/J53DFIbMAOyOjx9z5TZtZ8es/K4MOhABME8GoXUyAeALtWZQ/Ed2 skU1gA9Opx9DszsGK35yHGPh537jvfzDpDAa6LKfmfJXVVS+NuSCohuQXPRyw5nVl84y 0kQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733418844; x=1734023644; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xNQM2De0uWsZzOP6u/2v236oC/9A63z8kL2Apq3LH5U=; b=rVbeF2w6PDS0zLzz0Cwvdm99/Ki+i3rOvFfzgqVuehmB0o2Sws52g1/wWL0p7zxhki 0O0ceM4/CVppnTrP4ScZoMbQ1d2bLoVNyyiWnLDAe1/lB6S2qgiYk0HosON1TQk81yGm TxbvraBG2aUnVFBh3Kqi56wsC+NFOctSiayEX/0hD4LAKZtjO0QS1CU2AWJ+rRDX733l 6ELTUh3YVVnCi9qPwF2CQakq1bvxmZwApFVb32CZaJxOS/Se7UAA95nNYXTCcZcttYXA Zxd/ip/CTobFGaiVXgJ78hmrzjk/SdlOWeb+OSIDsAoospzXXzLgF2QZsgyh/yOnIKjB G2bw== X-Forwarded-Encrypted: i=1; AJvYcCVK3hYW6cXdZxIUqDa0HsSF8prkTwn1j8J6os9Y0ENKqknuD+yIvBvS+IafSGznjkKj7YQF3BQ6WZX3Ciq1@vger.kernel.org, AJvYcCVg98Y11MOF5464V7cEFznGtG7btsUiNe0CNC1VdwhfGj7Hgf1hFC3ibwgR1RtBNmaG3Qf+GLaltQ8=@vger.kernel.org X-Gm-Message-State: AOJu0YyOhkCEIqPBG26a23Jktok4YlsLQkvxalE7+b2dTvpH9pA7mJzL PxmufFCqT/AlC9ay0sUKxkxhz1BXP7Ya38kbQKmO/r5s+pfJ+Lr8 X-Gm-Gg: ASbGnctZoHIJlct9qOllrmGCt5B5IuzEE19J3ZuKbFsJpw6ygrDNBSJNrQLdL0UNH2r w9NkJ4LX3GHn7unciZE9aCOmWKl1YnSsPMuVLE4Mdo+G5O8B7PwH7srAgqmPPvWnAtlRiKFDTjM PhPeXpuUuczQ5mUsj9ukMBY1Zf8Nw899CpsaPpgrufaRZgZIE1GDonMe3ju836I/gMGUvBsoPkl +NwTwysLd72tI5LnZhdVKVMSOLM9VYn4h7+tx9xblYMrLlC7R6vlmkmfW42ZHH+cFVE8RwU3aUK 6XA2Cieib8Ge4stET64+4sp9GG/o X-Google-Smtp-Source: AGHT+IGq4lg6H7FLfQErxCEZpDhhsul+87GsgCeZ+A3HHj801HBO8Wz7dmM0P4nit/lDz16rSpbnkQ== X-Received: by 2002:a05:6402:26c7:b0:5d0:bd3b:b9a9 with SMTP id 4fb4d7f45d1cf-5d10cb99b97mr4068454a12.8.1733418843531; Thu, 05 Dec 2024 09:14:03 -0800 (PST) Received: from 7b58d44c4ff6.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d149a48a38sm1026078a12.23.2024.12.05.09.14.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 09:14:03 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v5 08/10] iio: accel: adxl345: initialize FIFO delay value for SPI Date: Thu, 5 Dec 2024 17:13:41 +0000 Message-Id: <20241205171343.308963-9-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241205171343.308963-1-l.rubusch@gmail.com> References: <20241205171343.308963-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add the possibility to delay FIFO access when SPI is used. According to the datasheet this is needed for the adxl345. When initialization happens over SPI the need for delay is to be signalized, and the delay will be used. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345.h | 1 + drivers/iio/accel/adxl345_core.c | 12 ++++++++++++ drivers/iio/accel/adxl345_i2c.c | 2 +- drivers/iio/accel/adxl345_spi.c | 7 +++++-- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/iio/accel/adxl345.h b/drivers/iio/accel/adxl345.h index ed81d5cf445..c07709350d3 100644 --- a/drivers/iio/accel/adxl345.h +++ b/drivers/iio/accel/adxl345.h @@ -127,6 +127,7 @@ struct adxl345_chip_info { }; int adxl345_core_probe(struct device *dev, struct regmap *regmap, + bool fifo_delay_default, int (*setup)(struct device*, struct regmap*)); #endif /* _ADXL345_H_ */ diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index e0a8b32239f..0696e908bdf 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -22,6 +22,7 @@ struct adxl345_state { int irq; const struct adxl345_chip_info *info; struct regmap *regmap; + bool fifo_delay; /* delay: delay is needed for SPI */ u8 intio; }; @@ -193,12 +194,21 @@ static const struct iio_info adxl345_info = { * adxl345_core_probe() - Probe and setup for the accelerometer. * @dev: Driver model representation of the device * @regmap: Regmap instance for the device + * @fifo_delay_default: Using FIFO with SPI needs delay * @setup: Setup routine to be executed right before the standard device * setup * + * For SPI operation greater than 1.6 MHz, it is necessary to deassert the CS + * pin to ensure a total delay of 5 us; otherwise, the delay is not sufficient. + * The total delay necessary for 5 MHz operation is at most 3.4 us. This is not + * a concern when using I2C mode because the communication rate is low enough + * to ensure a sufficient delay between FIFO reads. + * Ref: "Retrieving Data from FIFO", p. 21 of 36, Data Sheet ADXL345 Rev. G + * * Return: 0 on success, negative errno on error */ int adxl345_core_probe(struct device *dev, struct regmap *regmap, + bool fifo_delay_default, int (*setup)(struct device*, struct regmap*)) { struct adxl345_state *st; @@ -230,6 +240,8 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, if (!st->info) return -ENODEV; + st->fifo_delay = fifo_delay_default; + indio_dev->name = st->info->name; indio_dev->info = &adxl345_info; indio_dev->modes = INDIO_DIRECT_MODE; diff --git a/drivers/iio/accel/adxl345_i2c.c b/drivers/iio/accel/adxl345_i2c.c index 4065b8f7c8a..28d997c5860 100644 --- a/drivers/iio/accel/adxl345_i2c.c +++ b/drivers/iio/accel/adxl345_i2c.c @@ -27,7 +27,7 @@ static int adxl345_i2c_probe(struct i2c_client *client) if (IS_ERR(regmap)) return dev_err_probe(&client->dev, PTR_ERR(regmap), "Error initializing regmap\n"); - return adxl345_core_probe(&client->dev, regmap, NULL); + return adxl345_core_probe(&client->dev, regmap, false, NULL); } static const struct adxl345_chip_info adxl345_i2c_info = { diff --git a/drivers/iio/accel/adxl345_spi.c b/drivers/iio/accel/adxl345_spi.c index 61fd9a6f5fc..9829d5d3d43 100644 --- a/drivers/iio/accel/adxl345_spi.c +++ b/drivers/iio/accel/adxl345_spi.c @@ -12,6 +12,7 @@ #include "adxl345.h" #define ADXL345_MAX_SPI_FREQ_HZ 5000000 +#define ADXL345_MAX_FREQ_NO_FIFO_DELAY 1500000 static const struct regmap_config adxl345_spi_regmap_config = { .reg_bits = 8, @@ -28,6 +29,7 @@ static int adxl345_spi_setup(struct device *dev, struct regmap *regmap) static int adxl345_spi_probe(struct spi_device *spi) { struct regmap *regmap; + bool needs_delay; /* Bail out if max_speed_hz exceeds 5 MHz */ if (spi->max_speed_hz > ADXL345_MAX_SPI_FREQ_HZ) @@ -38,10 +40,11 @@ static int adxl345_spi_probe(struct spi_device *spi) if (IS_ERR(regmap)) return dev_err_probe(&spi->dev, PTR_ERR(regmap), "Error initializing regmap\n"); + needs_delay = (spi->max_speed_hz > ADXL345_MAX_FREQ_NO_FIFO_DELAY); if (spi->mode & SPI_3WIRE) - return adxl345_core_probe(&spi->dev, regmap, adxl345_spi_setup); + return adxl345_core_probe(&spi->dev, regmap, needs_delay, adxl345_spi_setup); else - return adxl345_core_probe(&spi->dev, regmap, NULL); + return adxl345_core_probe(&spi->dev, regmap, needs_delay, NULL); } static const struct adxl345_chip_info adxl345_spi_info = { From patchwork Thu Dec 5 17:13: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: 13895836 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.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 94DBC22B8C2; Thu, 5 Dec 2024 17:14:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733418848; cv=none; b=Bhg/6FXNO7Tvnb1+J/tDZALgAQg1Buoh6h1Q1Ig8xKfnbzcEg4/cDyLGU4dY5Oi2+CZa0KBRtzLruhJRAhmrR8tv0uP7Pbd45tX2HwcclH/q8PAZBX90WUX0a8eTL88rTQR6zUoFYMv8ifdTB+XK7qux1q4ymgnu3XA1RoTWWz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733418848; c=relaxed/simple; bh=iLDUgU8WNcAh/t6tBH4v0q05mowuF+6hmrNXfHJwFoA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ufyLDVtrDHLIVkeSimC6opSapDBJX45rELyiLbq2ZZZD+ASMDyQyr55UwL7/veBAyi3HvWIy7dyenXxYsmUz1/CaMwKk/RTnCOSl6TikqvSwrIeHMQFzfxJecmu25rwvXej5BezDWXLFuHkOwswPoN/sFfiPruIstkQbUj+LZV4= 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=hzDTAEuZ; arc=none smtp.client-ip=209.85.208.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="hzDTAEuZ" Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-5d071ac3f35so199813a12.3; Thu, 05 Dec 2024 09:14:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733418845; x=1734023645; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GgoVWnhvP406HqfDsdu4WH7uW2K8Xa/wgeBTdZ1+3jg=; b=hzDTAEuZ++zxApzhj6bXUs8s9hClVQzdiDWWMnrSfh1pxw+0PT2tQOoinr+JIDXOvQ cw6hPT2dJDb73PHO8zm0QvR2Gy8/J1/hfYSgxRlSVGJXEfGFVDJEYk0L6IQgfzVg1cZQ MjeyncfzzXoYItoZJHy4Xv6nt6gGQpcllh+gqbrGCxHxVQAmBdcVkxH/67Ar3Dw1Uza+ n5SaoJf6ClzN2mzZ2Rl+PPvCDnfqlPXRQGxVbaRopagpdTECD3hWBsCUgEmaJoroTpYC pV3Sobk4KrKXqXkgun3yUpt/xLNLalQ9SCMERpUzF/jibRIO4wTLsSELPAAoBcl36CJI 5ikQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733418845; x=1734023645; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GgoVWnhvP406HqfDsdu4WH7uW2K8Xa/wgeBTdZ1+3jg=; b=PpyL+RS9gG5UoJhWePILK8A0rzUUnVd6ELtOTPlyjheAi2uXZaBOwMu6EZJYp3NUOq SPL1QR5G9ODr6AzTbs/YN2Tj9m7CMT4dUpSzJVSOaN/H/vaXPFDy0YOEUwKjFetMUFmH P3OzgNrGxT14joMEyyw9l1YClmEBpy1NpcnxDVv4ihS6wOILT0Trw2WQ/TrwWgd7LIoi 3aqlmcp2jBYhjz2mggT+02HhLql47g67KvmaMGf+YYvgtAwXLBXGPDsMKGAa9afP65jN OYy10NwaLFdpqQzUjA4NwROxbN4OJL5N4ndXacMA3WhbDhEyt65Y+fhhTjnfIWjWU4w+ 408A== X-Forwarded-Encrypted: i=1; AJvYcCVJZX8zcFgYwYkvMQJ361z2UR9Ov8bhn4jSbpiqO2vQipm1Rr5IIqWdppZmrZZKhSx0W+L4PUcwKMA7AE07@vger.kernel.org, AJvYcCVuIvjg4p/m/hQD/9eRDeSF+c48rxaG2P2pcZdWHIefBP8uKyzkijGJ4khxsAKJvmOAnOoMtjOkvTA=@vger.kernel.org X-Gm-Message-State: AOJu0Yzx7zMKCe4GE4n+qkkEc6FeUm8QTVxLfUdOvLDBH6rK3rqFj9rc k37zwBiFAwexwuBkmBjKi++l62U6k7k5ZqJjpZhR4aQ5o0yga3FF X-Gm-Gg: ASbGncujjeWuul0jGsMMGOM6+ts8XW26dA7LoPl6gugDkYtX0+PwZYEg3p8b9husWun VDHib/1R+rDOCRm0WmGQX9fxawuJIqCsBOqbSOPVYN4rITBb/+VtWmgfd4QwCDTPCHcNYlHNxRP nxPwpR5Qop48kx7JI5OSefH0JO4QuKDF2xd29amx/vWuwVoFE+I8MQZaW0RBLw5/tCBLlocRiXL FashVV5dX6PwRom9kh2Ai7sSPoVjiyxYQDcxeoCC39WGv4eE8KD77clf38g0uoX8ojarkfsjsUi OWEJ2EOcF8yujctzQ/DqvtgXX5nI X-Google-Smtp-Source: AGHT+IHupydN7u5UoHUv8Up/y/vujjHXDYpRrXcnAREL4xFBRVIksMwEo0cvdnr9oIMHiXqJQbhs1A== X-Received: by 2002:a05:6402:2111:b0:5d0:b7c5:c40b with SMTP id 4fb4d7f45d1cf-5d10cb4e07cmr4101115a12.1.1733418844765; Thu, 05 Dec 2024 09:14:04 -0800 (PST) Received: from 7b58d44c4ff6.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d149a48a38sm1026078a12.23.2024.12.05.09.14.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 09:14:04 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v5 09/10] iio: accel: adxl345: prepare channel for scan_index Date: Thu, 5 Dec 2024 17:13:42 +0000 Message-Id: <20241205171343.308963-10-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241205171343.308963-1-l.rubusch@gmail.com> References: <20241205171343.308963-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add separate fields for register and index to the channel definition. The scan_index is set up with the kfifo in the follow up patches. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 0696e908bdf..3067a70c54e 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -26,21 +26,26 @@ struct adxl345_state { u8 intio; }; -#define ADXL345_CHANNEL(index, axis) { \ +#define ADXL345_CHANNEL(index, reg, axis) { \ .type = IIO_ACCEL, \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \ - .address = index, \ + .address = (reg), \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ BIT(IIO_CHAN_INFO_CALIBBIAS), \ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .scan_index = (index), \ } +enum adxl345_chans { + chan_x, chan_y, chan_z, +}; + static const struct iio_chan_spec adxl345_channels[] = { - ADXL345_CHANNEL(0, X), - ADXL345_CHANNEL(1, Y), - ADXL345_CHANNEL(2, Z), + ADXL345_CHANNEL(0, chan_x, X), + ADXL345_CHANNEL(1, chan_y, Y), + ADXL345_CHANNEL(2, chan_z, Z), }; static int adxl345_read_raw(struct iio_dev *indio_dev, From patchwork Thu Dec 5 17:13: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: 13895837 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1DBD22D4D0; Thu, 5 Dec 2024 17:14:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733418849; cv=none; b=io/I5hkNUzvwo5nS4tglgz3O8QJcV5ABjxoVBea6NOIOWDWV18eJqT53V83RSzTc+N30Hcjsl1yclNiv2JlvNcoinRFPAj0YqGdpeoo7j+nEvrW9KplxmZpGzhH3ZvTQT96wsuNMeHyFj3xgtkMXRAqWu2BoUuUgkTV//YAhyxE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733418849; c=relaxed/simple; bh=ouiB3B4vc2uXHgZKY7KoVBDYrYDMYIWxcrixINDjfB8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MyS2DTvSFTg0Xy1nJ9/h5Mho7QZhs04+DrMyX/cAGZIWeG5ejqRiYnazlpva1IJseTyFxcacaifasGVnlbQvtm17J6/mP8uRk9cbo0tAdB0P0i2DnhbyadAe15pEp8qNKv03luiHXcF98IJSe4VHFpFJCLqIFg6R11el/Tx9NJ8= 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=Hz34ODfe; arc=none smtp.client-ip=209.85.208.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Hz34ODfe" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-5d0d40fba2dso179498a12.1; Thu, 05 Dec 2024 09:14:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733418846; x=1734023646; 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=19cmypSDvl2qvZse+lbr7CC+6tE6QkbEy/nf+fZunuI=; b=Hz34ODfeUo5h8AU3xegkLZ5Go7nXkXw4Iii1y58ma5hhKHnPoH51QTq4jHwy78nWUt apHHnp2wU9HpxnCXQ1p7txrYY3IoZ83E1FPSyMwZKD+v0Xxj8GOV8yUYTgN/mhpNRvtG VSypPZl1Yhvoy1s2C4VIZfXuL9uuWUePHSQ/x/UYbSJS1RZb9yx8qlfzRtMkpgNIDe0m CQbwNa+T4LQzbNwvrglajouAm+6NkAl45niI2AAUjQZeAFzDEqtZIyCPjCKxSHKueiAs edhcbpe31jmbwG1cOpp7peiha+b3XeSUvnfZ+xmU9XRhWm41m6riCkqweRW4pCqbnnLe ZtoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733418846; x=1734023646; 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=19cmypSDvl2qvZse+lbr7CC+6tE6QkbEy/nf+fZunuI=; b=YSWa0scPfd3GvzoB3YO+ZvvTahLhLrs+mHVxknsj9cMnfzc3C/E+z4Xg84ud+SO0I1 1FCNqinGuVMiwc28beGP7hvW4aN8/Lg934uwmvUTMDNRtn8Ur81IEYn4s0zrBiGbQVdi L8vu1eYEMG23JjCy3cr2eX3dFR7P1GPS8BY5XCFdXKW1e/oydmquy3MgWccQzIuRWPEe xVK32dWro/ehXVyMbid3cL7TeeuFPCOF4HRFG/RfAT2PbuNuswtORKlWLExxSZ8174Yl Ll6FlqaBDQggP2lNTu23W5wkIeJVEwcuiaDDF8OKi3n81pxuDRFtrg6jZMfGC39JWuRN +7AA== X-Forwarded-Encrypted: i=1; AJvYcCWD8Fpwi1Qiw88mWvRkK57BWL50MskuXHF0NM0gaXClYo5yrhlw0+zLuwHlBBKf3rwNffZo8z82vZ4=@vger.kernel.org, AJvYcCWTXRno5uyu4h0eKH/waADbyrqag3M/JZHrBlRG50pwaYFT3JknYQIuVXhRT6PNRx4dFPmAJQVEvVEbSaks@vger.kernel.org X-Gm-Message-State: AOJu0Yzkf3LDh/M/VVarotm+0sTD5FMowhHBzJ7LBs/zgHaCA+CNzh8R LWX8CPv85zg1ePJqJSl67UHbBEVX9XUfsSkHhVzKsIUh6X1Rpfb9 X-Gm-Gg: ASbGnct7qE5btce1lqhuHlx9RmNb0pGNiaqgIezG1NLh4xDVvAOt56aS36ThsxjkSlx Squtj7jXC5jh9/tplM6rP1UYr3LSc3xxX5trdstVT7jcqviAH2VuqIYPsbxv7DXKXA2id5HLtic uhulD7AdN2P+f7ZIHGZoYufcXjJqX56ruxLqQS9k1iKx2Di7xhksh/3sg/rzjvK47haupekZF60 2wrFXqo/CESGh9WpwtQk3OXO/WjCfZ5WL1b0DP0rbJQkOVO6GykC+OwbUm9D76Wh/LW1m5HiWMy uJiVHKefb3OK35YE5PFYC51g5Ri+ X-Google-Smtp-Source: AGHT+IFdZZt/TG/R335JOuTpNAFCstOddX9DIG64BNbltmsV29VyaaQJgub+2dsNzOEwa/FtPfz4OQ== X-Received: by 2002:a05:6402:27ca:b0:5d0:8111:e958 with SMTP id 4fb4d7f45d1cf-5d10cb99badmr4186728a12.9.1733418846016; Thu, 05 Dec 2024 09:14:06 -0800 (PST) Received: from 7b58d44c4ff6.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d149a48a38sm1026078a12.23.2024.12.05.09.14.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 09:14:05 -0800 (PST) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v5 10/10] iio: accel: adxl345: add FIFO with watermark events Date: Thu, 5 Dec 2024 17:13:43 +0000 Message-Id: <20241205171343.308963-11-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241205171343.308963-1-l.rubusch@gmail.com> References: <20241205171343.308963-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add a basic setup for FIFO with configurable watermark. Add a handler for watermark interrupt events and extend the channel for the scan_index needed for the iio channel. The sensor is configurable to use a FIFO_BYPASSED mode or a FIFO_STREAM mode. For the FIFO_STREAM mode now a watermark can be configured, or disabled by setting 0. Further features require a working FIFO setup. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 300 +++++++++++++++++++++++++++++++ 1 file changed, 300 insertions(+) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 3067a70c54e..58ed82d66dc 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -15,15 +15,28 @@ #include #include +#include +#include +#include #include "adxl345.h" +#define ADXL345_FIFO_BYPASS 0 +#define ADXL345_FIFO_FIFO 1 +#define ADXL345_FIFO_STREAM 2 + +#define ADXL345_DIRS 3 + struct adxl345_state { int irq; const struct adxl345_chip_info *info; struct regmap *regmap; + __le16 fifo_buf[ADXL345_DIRS * ADXL345_FIFO_SIZE]; bool fifo_delay; /* delay: delay is needed for SPI */ u8 intio; + u8 int_map; + u8 watermark; + u8 fifo_mode; }; #define ADXL345_CHANNEL(index, reg, axis) { \ @@ -36,6 +49,13 @@ struct adxl345_state { .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ BIT(IIO_CHAN_INFO_SAMP_FREQ), \ .scan_index = (index), \ + .scan_type = { \ + .sign = 's', \ + .realbits = 13, \ + .storagebits = 16, \ + .shift = 0, \ + .endianness = IIO_LE, \ + }, \ } enum adxl345_chans { @@ -48,6 +68,25 @@ static const struct iio_chan_spec adxl345_channels[] = { ADXL345_CHANNEL(2, chan_z, Z), }; +static int adxl345_set_interrupts(struct adxl345_state *st) +{ + int ret; + unsigned int int_enable = st->int_map; + unsigned int int_map; + + /* Any bits set to 0 in the INT map register send their respective + * interrupts to the INT1 pin, whereas bits set to 1 send their respective + * interrupts to the INT2 pin. The intio shall convert this accordingly. + */ + int_map = 0xFF & (st->intio ? st->int_map : ~st->int_map); + + ret = regmap_write(st->regmap, ADXL345_REG_INT_MAP, int_map); + if (ret) + return ret; + + return regmap_write(st->regmap, ADXL345_REG_INT_ENABLE, int_enable); +} + static int adxl345_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) @@ -133,6 +172,31 @@ static int adxl345_write_raw(struct iio_dev *indio_dev, return -EINVAL; } +static int adxl345_set_watermark(struct iio_dev *indio_dev, unsigned int value) +{ + struct adxl345_state *st = iio_priv(indio_dev); + unsigned int fifo_mask = 0x1F; + int ret; + + if (value == 0) { + st->int_map &= ~ADXL345_INT_WATERMARK; + return 0; + } + + if (value > ADXL345_FIFO_SIZE) + value = ADXL345_FIFO_SIZE; + + ret = regmap_update_bits(st->regmap, ADXL345_REG_FIFO_CTL, + fifo_mask, value); + if (ret) + return ret; + + st->watermark = value; + st->int_map |= ADXL345_INT_WATERMARK; + + return 0; +} + static int adxl345_write_raw_get_fmt(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, long mask) @@ -188,11 +252,224 @@ static const struct attribute_group adxl345_attrs_group = { .attrs = adxl345_attrs, }; +static int adxl345_set_fifo(struct adxl345_state *st) +{ + u8 fifo_ctl; + int ret; + + /* FIFO should only be configured while in standby mode */ + ret = adxl345_set_measure_en(st, false); + if (ret < 0) + return ret; + + fifo_ctl = ADXL345_FIFO_CTL_SAMLPES(st->watermark) | + ADXL345_FIFO_CTL_TRIGGER(st->intio) | + ADXL345_FIFO_CTL_MODE(st->fifo_mode); + + ret = regmap_write(st->regmap, ADXL345_REG_FIFO_CTL, fifo_ctl); + if (ret < 0) + return ret; + + return adxl345_set_measure_en(st, true); +} + +/** + * adxl345_get_samples() - Read number of FIFO entries. + * @st: The initialized state instance of this driver. + * + * The sensor does not support treating any axis individually, or exclude them + * from measuring. + * + * Return: negative error, or value. + */ +static int adxl345_get_samples(struct adxl345_state *st) +{ + unsigned int regval = 0; + int ret; + + ret = regmap_read(st->regmap, ADXL345_REG_FIFO_STATUS, ®val); + if (ret < 0) + return ret; + + return 0x3f & regval; +} + +/** + * adxl345_fifo_transfer() - Read samples number of elements. + * @st: The instance of the state object of this sensor. + * @samples: The number of lines in the FIFO referred to as fifo_entry, + * a fifo_entry has 3 elements for X, Y and Z direction of 2 bytes each. + * + * It is recommended that a multiple-byte read of all registers be performed to + * prevent a change in data between reads of sequential registers. That is to + * read out the data registers X0, X1, Y0, Y1, Z0, Z1 at once. + * + * Return: 0 or error value. + */ +static int adxl345_fifo_transfer(struct adxl345_state *st, int samples) +{ + size_t count; + int i, ret; + + count = sizeof(st->fifo_buf[0]) * ADXL345_DIRS; + for (i = 0; i < samples; i++) { + ret = regmap_noinc_read(st->regmap, ADXL345_REG_XYZ_BASE, + st->fifo_buf + (i * count / 2), count); + if (ret < 0) + return ret; + } + return ret; +} + +/** + * adxl345_fifo_reset() - Empty the FIFO in error condition. + * @st: The instance to the state object of the sensor. + * + * Read all elements of the FIFO. Reading the interrupt source register + * resets the sensor. + */ +static void adxl345_fifo_reset(struct adxl345_state *st) +{ + int regval; + int samples; + + adxl345_set_measure_en(st, false); + + samples = adxl345_get_samples(st); + if (samples > 0) + adxl345_fifo_transfer(st, samples); + + regmap_read(st->regmap, ADXL345_REG_INT_SOURCE, ®val); + + adxl345_set_measure_en(st, true); +} + +static int adxl345_buffer_postenable(struct iio_dev *indio_dev) +{ + struct adxl345_state *st = iio_priv(indio_dev); + int ret; + + ret = adxl345_set_interrupts(st); + if (ret < 0) + return ret; + + st->fifo_mode = ADXL345_FIFO_STREAM; + return adxl345_set_fifo(st); +} + +static int adxl345_buffer_predisable(struct iio_dev *indio_dev) +{ + struct adxl345_state *st = iio_priv(indio_dev); + int ret; + + st->int_map = 0x00; + + ret = adxl345_set_interrupts(st); + if (ret < 0) + return ret; + + st->fifo_mode = ADXL345_FIFO_BYPASS; + return adxl345_set_fifo(st); +} + +static const struct iio_buffer_setup_ops adxl345_buffer_ops = { + .postenable = adxl345_buffer_postenable, + .predisable = adxl345_buffer_predisable, +}; + +static int adxl345_get_status(struct adxl345_state *st) +{ + int ret; + unsigned int regval; + + ret = regmap_read(st->regmap, ADXL345_REG_INT_SOURCE, ®val); + if (ret < 0) + return ret; + + return (0xff & regval); +} + +static int adxl345_fifo_push(struct iio_dev *indio_dev, + int samples) +{ + struct adxl345_state *st = iio_priv(indio_dev); + int i, ret; + + if (samples <= 0) + return -EINVAL; + + ret = adxl345_fifo_transfer(st, samples); + if (ret) + return ret; + + for (i = 0; i < ADXL345_DIRS * samples; i += ADXL345_DIRS) { + /* + * To ensure that the FIFO has completely popped, there must be at least 5 + * us between the end of reading the data registers, signified by the + * transition to register 0x38 from 0x37 or the CS pin going high, and the + * start of new reads of the FIFO or reading the FIFO_STATUS register. For + * SPI operation at 1.5 MHz or lower, the register addressing portion of the + * transmission is sufficient delay to ensure the FIFO has completely + * popped. It is necessary for SPI operation greater than 1.5 MHz to + * de-assert the CS pin to ensure a total of 5 us, which is at most 3.4 us + * at 5 MHz operation. + */ + if (st->fifo_delay && (samples > 1)) + udelay(3); + + iio_push_to_buffers(indio_dev, &st->fifo_buf[i]); + } + + return 0; +} + +/** + * adxl345_event_handler() - Handle events of the ADXL345. + * @irq: The irq being handled. + * @p: The struct iio_device pointer for the device. + * + * Return: The interrupt was handled. + */ +static irqreturn_t adxl345_event_handler(int irq, void *p) +{ + struct iio_dev *indio_dev = p; + struct adxl345_state *st = iio_priv(indio_dev); + u8 int_stat; + int samples; + + int_stat = adxl345_get_status(st); + if (int_stat < 0) + return IRQ_NONE; + + if (int_stat == 0x0) + goto err; + + if (int_stat & ADXL345_INT_OVERRUN) + goto err; + + if (int_stat & (ADXL345_INT_DATA_READY | ADXL345_INT_WATERMARK)) { + samples = adxl345_get_samples(st); + if (samples < 0) + goto err; + + if (adxl345_fifo_push(indio_dev, samples) < 0) + goto err; + + } + return IRQ_HANDLED; + +err: + adxl345_fifo_reset(st); + + return IRQ_HANDLED; +} + static const struct iio_info adxl345_info = { .attrs = &adxl345_attrs_group, .read_raw = adxl345_read_raw, .write_raw = adxl345_write_raw, .write_raw_get_fmt = adxl345_write_raw_get_fmt, + .hwfifo_set_watermark = adxl345_set_watermark, }; /** @@ -222,6 +499,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, unsigned int data_format_mask = (ADXL345_DATA_FORMAT_RANGE | ADXL345_DATA_FORMAT_FULL_RES | ADXL345_DATA_FORMAT_SELF_TEST); + u8 fifo_ctl; int ret; indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); @@ -293,6 +571,28 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, if (ret < 0) return dev_err_probe(dev, ret, "Failed to add action or reset\n"); + if (st->irq > 0) { + dev_dbg(dev, "initialize for FIFO_STREAM mode\n"); + + ret = devm_iio_kfifo_buffer_setup(dev, indio_dev, &adxl345_buffer_ops); + if (ret) + return ret; + + ret = devm_request_threaded_irq(dev, st->irq, NULL, &adxl345_event_handler, + IRQF_SHARED | IRQF_ONESHOT, + indio_dev->name, indio_dev); + if (ret) + return dev_err_probe(dev, ret, "Failed to setup triggered buffer\n"); + + } else { + dev_dbg(dev, "initialize for FIFO_BYPASS mode (fallback)\n"); + + fifo_ctl = ADXL345_FIFO_CTL_MODE(ADXL345_FIFO_BYPASS); + + ret = regmap_write(st->regmap, ADXL345_REG_FIFO_CTL, fifo_ctl); + if (ret < 0) + return ret; + } return devm_iio_device_register(dev, indio_dev); } EXPORT_SYMBOL_NS_GPL(adxl345_core_probe, IIO_ADXL345);