Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1001245rwd; Tue, 13 Jun 2023 03:31:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5lNCzhp4AGU3Vb8i4Epn5Znji7vWQE+KaTE45uByFcMu+G/SE/f7asEL8GSXA49kFzmlIo X-Received: by 2002:a17:906:db0c:b0:96f:e5af:ac5f with SMTP id xj12-20020a170906db0c00b0096fe5afac5fmr11727653ejb.47.1686652273689; Tue, 13 Jun 2023 03:31:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686652273; cv=none; d=google.com; s=arc-20160816; b=d6QwO6el19mq2VrgZr94oKlSoE90DzfFRCdnyx870B60qGVa3/DTaHqqCw3tplIy+B hsEOJGyxU8ZoQMcMDu9+hxKMX3u//0PCvvY8xKJB04mfF+LOi1/MXz18W5La1xgorj3i WUqAbmcNXeYs4NqAnRPcKHY1OkW93k6xuGKrppZT21so+JUhBi3HNpALejDohn2DGTGX MYEM5/MzMKfcpOQUkfXtcVtEEPQkeJxyT4SNIgqodiDBL7NiFPryPfFuhSEyOlGpUpPa M8gX8arvLHbWyVs4+FZiGM4vRRDGz0P+n2g+rasOWHDbzGW+1lx6AI9D3wzt0mAyjNwh jQkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dQ2ryCXqr7uPo1ZCZAFxYzmrawKO4U75wlR0TUXTjbE=; b=OpXZxTtCKSzht1W5zLtqSBBh6adBdgj5gI2RXFEAduOuDrnAPtCD1MiBE42m3pqEiL Gc6o15fURLXLe42+QnFMhTY36iald3DQ8aSkBrV0IXGY3LDfjhTcISZ87wBmAZVzf88u 3o4+AykYZQaNjpPdOS1m6ZKZ+LjAL9fUfLfUPuMzf4QS1dD5toDfs3xq8d470skmiukC K8vm2o4dBZl3/vDbp0J2NyfKxVdYGoJr2IUw2g7E6pTGq2XrSd41rQWup1IaAcejr+QU FLs0okA5wWrxi6gek08GlDg1PnrXh6oSteqYf+gRJYrZ7uD1ejdTrlCqZCUDIRcF94N4 YXug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=QJYDWIQd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gz22-20020a170906f2d600b00973771bddcdsi6833902ejb.685.2023.06.13.03.30.47; Tue, 13 Jun 2023 03:31:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=QJYDWIQd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242021AbjFMKXx (ORCPT + 99 others); Tue, 13 Jun 2023 06:23:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241422AbjFMKXG (ORCPT ); Tue, 13 Jun 2023 06:23:06 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 804AF173E; Tue, 13 Jun 2023 03:23:04 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-5187aa14e3bso205240a12.3; Tue, 13 Jun 2023 03:23:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686651783; x=1689243783; 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=dQ2ryCXqr7uPo1ZCZAFxYzmrawKO4U75wlR0TUXTjbE=; b=QJYDWIQdS25P7MIbgpsu+uhtKApKjnUGWqGM5KFmdW2GbMKrZa4yVDOfkX9b0YleT2 CrFdxwq4oYCBsiynQckKX9imxyKtp72RjWVrEAcrVk1CmsF/yzUZuN3hZU50uLqxfmUn hUybiOGE6zuyI6ilWj38iES72y4eOwolvgGiWONseyBDTuB+nIy6hgXmNtPu8fwBgbvF SHrP810tZmKhrp91tDQEEAhgOds+POnkI86uyd6ZTJWopMX6Qwmc1RuejQ3JyjcWJrn8 LGXIwuAVqJiMo/o66YYZV8O0rRwtdw+rKj2z7BtwkSndlDbbsbH6364CBkQ9u/P9O1H0 Z7gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686651783; x=1689243783; 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=dQ2ryCXqr7uPo1ZCZAFxYzmrawKO4U75wlR0TUXTjbE=; b=llFWT3rLIvZDmNUMGwo4goeR6567MfuQHoSvu29WCpZZLLa0YH/YfaFFeQfnCwHtYj /7CU9QiSg3Qfg+qYdsZd5KvpXe/LVEOdM9y546ljwoJYrpZrIRyabwD167l4pEppZPWP OsCdaP4/j9RxHkM3oEj5ZVkAw8EA3BZn2PDXsEjIRkX/5cBSIMzGVqqzjexuksGAHmbc HWe48g/EzHEH/UsLR7C1gtEf5VUxhi6SqVr4/SpAKPRE6oIvAroBhrMc9B66h7hbjeW+ dbXk3A9OrSIoYpy8E1k3HQ8q8aGfyVucm4FEv9iXOoI7aUiUrkBzBvZGItuD5vACNos6 U/6Q== X-Gm-Message-State: AC+VfDzVkOxgkxOz7cvx6C9b7MMMWy8YU6p8+u/1rwLj48LHkjqCXCTg U3R+sCPSvcMncm6l+GOhSo0= X-Received: by 2002:a17:906:9749:b0:977:c406:f8cf with SMTP id o9-20020a170906974900b00977c406f8cfmr13116876ejy.73.1686651782945; Tue, 13 Jun 2023 03:23:02 -0700 (PDT) Received: from localhost.localdomain ([2a02:8109:aa3f:ead8::298a]) by smtp.gmail.com with ESMTPSA id b7-20020a170906038700b009787b18c253sm6492493eja.181.2023.06.13.03.23.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 03:23:02 -0700 (PDT) From: Mehdi Djait To: jic23@kernel.org, mazziesaccount@gmail.com Cc: krzysztof.kozlowski+dt@linaro.org, andriy.shevchenko@linux.intel.com, robh+dt@kernel.org, lars@metafoo.de, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Mehdi Djait Subject: [PATCH v6 6/7] iio: accel: kionix-kx022a: Add a function to retrieve number of bytes in buffer Date: Tue, 13 Jun 2023 12:22:39 +0200 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since Kionix accelerometers use various numbers of bits to report data, a device-specific function is required. Implement the function as a callback in the device-specific chip_info structure Reviewed-by: Matti Vaittinen Signed-off-by: Mehdi Djait --- v6: - directly return KX022A_FIFO_MAX_BYTES as suggested by Andy v5: - no changes v4: - removed the comment about "bogus value from i2c" - removed regmap_get_device(data->regmap); dev is present in the driver's private data v3: - no changes v2: - separated this change from the chip_info introduction and made it a patch in v2 - changed the function from generic implementation for to device-specific one - removed blank lines pointed out by checkpatch - changed the allocation of the "buffer" array in __kx022a_fifo_flush drivers/iio/accel/kionix-kx022a.c | 28 ++++++++++++++++++---------- drivers/iio/accel/kionix-kx022a.h | 4 ++++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c index 0bab3f109e4e..0b0f14dca17f 100644 --- a/drivers/iio/accel/kionix-kx022a.c +++ b/drivers/iio/accel/kionix-kx022a.c @@ -596,26 +596,33 @@ static int kx022a_drop_fifo_contents(struct kx022a_data *data) return regmap_write(data->regmap, data->chip_info->buf_clear, 0x0); } +static int kx022a_get_fifo_bytes(struct kx022a_data *data) +{ + int ret, fifo_bytes; + + ret = regmap_read(data->regmap, KX022A_REG_BUF_STATUS_1, &fifo_bytes); + if (ret) { + dev_err(data->dev, "Error reading buffer status\n"); + return ret; + } + + if (fifo_bytes == KX022A_FIFO_FULL_VALUE) + return KX022A_FIFO_MAX_BYTES; + + return fifo_bytes; +} + static int __kx022a_fifo_flush(struct iio_dev *idev, unsigned int samples, bool irq) { struct kx022a_data *data = iio_priv(idev); - struct device *dev = regmap_get_device(data->regmap); uint64_t sample_period; int count, fifo_bytes; bool renable = false; int64_t tstamp; int ret, i; - ret = regmap_read(data->regmap, KX022A_REG_BUF_STATUS_1, &fifo_bytes); - if (ret) { - dev_err(dev, "Error reading buffer status\n"); - return ret; - } - - /* Let's not overflow if we for some reason get bogus value from i2c */ - if (fifo_bytes == KX022A_FIFO_FULL_VALUE) - fifo_bytes = KX022A_FIFO_MAX_BYTES; + fifo_bytes = data->chip_info->get_fifo_bytes(data); if (fifo_bytes % KX022A_FIFO_SAMPLES_SIZE_BYTES) dev_warn(data->dev, "Bad FIFO alignment. Data may be corrupt\n"); @@ -1023,6 +1030,7 @@ const struct kx022a_chip_info kx022a_chip_info = { .inc5 = KX022A_REG_INC5, .inc6 = KX022A_REG_INC6, .xout_l = KX022A_REG_XOUT_L, + .get_fifo_bytes = kx022a_get_fifo_bytes, }; EXPORT_SYMBOL_NS_GPL(kx022a_chip_info, IIO_KX022A); diff --git a/drivers/iio/accel/kionix-kx022a.h b/drivers/iio/accel/kionix-kx022a.h index 0e5026019213..c9f9aee7e597 100644 --- a/drivers/iio/accel/kionix-kx022a.h +++ b/drivers/iio/accel/kionix-kx022a.h @@ -76,6 +76,8 @@ struct device; +struct kx022a_data; + /** * struct kx022a_chip_info - Kionix accelerometer chip specific information * @@ -99,6 +101,7 @@ struct device; * @inc5: interrupt control register 5 * @inc6: interrupt control register 6 * @xout_l: x-axis output least significant byte + * @get_fifo_bytes: function pointer to get number of bytes in the FIFO buffer */ struct kx022a_chip_info { const char *name; @@ -121,6 +124,7 @@ struct kx022a_chip_info { u8 inc5; u8 inc6; u8 xout_l; + int (*get_fifo_bytes)(struct kx022a_data *); }; int kx022a_probe_internal(struct device *dev, const struct kx022a_chip_info *chip_info); -- 2.30.2