From patchwork Mon Apr 11 20:31:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagath Jog J X-Patchwork-Id: 12809613 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C965C433F5 for ; Mon, 11 Apr 2022 20:31:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231363AbiDKUd6 (ORCPT ); Mon, 11 Apr 2022 16:33:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349795AbiDKUd4 (ORCPT ); Mon, 11 Apr 2022 16:33:56 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29CD035DD3; Mon, 11 Apr 2022 13:31:41 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id e8-20020a17090a118800b001cb13402ea2so519868pja.0; Mon, 11 Apr 2022 13:31:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XLIAY+sHtftiUozOfh7PpmrA81WZfIdoHm67TMrq4Jo=; b=cOZ0d8JaHJWYIzJBXu2RbX1g5Xjeh6e5I3TV34aSgTWP2v6n8i/0N2DFAx3NkWQ2Tc rJhHTIMN7ORcusaw6WqjkvOLuEamcU/l68roG+0ypF1YDum90UbaiFo2p+/zMemKlMb/ vYJ0eQF9JX05x8qZCkKSGfWKTQr8GszA54Ac6ARyR/5JQMgDCMRm2F40ZNzGvuBd+SxF g0LcqQja5DiLw8kbANSjGlIcU3C6UgwHEwldxeBxyChbr8drRzGcaWCFt2pOsLM5TADj ARqD8DoalbHPk2VGCse2asFJfvxXIqBHlsxPEFyDqTr5Lxqny9YjWX1C71ophRJnfceg TjsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XLIAY+sHtftiUozOfh7PpmrA81WZfIdoHm67TMrq4Jo=; b=v58lfQbjb+FhjE5UA37aJOUnN4zHrtuhsD+tzIQOQ7T0u9hpGmbdYaVTeUP7e+0LEK Qmb6mq6b3I/j8Vyw0WOVAKUXaAV1YvL/UbwjQYjD5tnEuK9FBGakiS0h+5lVJ8ZjiMTE Wx2peGTnmxxIVnpcl3zXGnCv0uQqOUMnzlqwOMMwZM+hu3Aa5on9dkmNgNaU5OT934Yt vQM5CUr1KecrFueIf56kOZOxUBkDcvmQ+fGASs8qLk82acHG7FLrEgpVwN+y+T81Qfcp VWyf8i2MV0GSL9PFAVVwX1qcWm4H0vdSr6cRamqZuRM8/fNqSPzbDkeZkKEETQE6t/Q8 Y5Aw== X-Gm-Message-State: AOAM5334hTsrWHX5Bdm4EtqrYjklVlCx60TVYhiOu+vCfTbkxIaUz0AE KfM6vhrliU7mj4jwGOa0N4w= X-Google-Smtp-Source: ABdhPJxtrndmMLAR1wJaZNppLmgQ91Kk7Y+BuJIdwSnzeRQlOrEOZDtQ/qgG6qAxILTRuPRL7gp4Cg== X-Received: by 2002:a17:902:b692:b0:151:5474:d3ee with SMTP id c18-20020a170902b69200b001515474d3eemr34129394pls.139.1649709100606; Mon, 11 Apr 2022 13:31:40 -0700 (PDT) Received: from localhost.localdomain ([27.7.99.112]) by smtp.gmail.com with ESMTPSA id z15-20020a056a001d8f00b004fda37855ddsm34069828pfw.168.2022.04.11.13.31.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 13:31:40 -0700 (PDT) From: Jagath Jog J To: dan@dlrobertson.com, jic23@kernel.org, andy.shevchenko@gmail.com Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/9] iio: accel: bma400: Fix the scale min and max macro values Date: Tue, 12 Apr 2022 02:01:25 +0530 Message-Id: <20220411203133.19929-2-jagathjog1996@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220411203133.19929-1-jagathjog1996@gmail.com> References: <20220411203133.19929-1-jagathjog1996@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Changing the scale macro values to match the bma400 sensitivity for 1 LSB of all the available ranges. Signed-off-by: Jagath Jog J --- drivers/iio/accel/bma400.h | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/iio/accel/bma400.h b/drivers/iio/accel/bma400.h index c4c8d74155c2..5d6a1976503f 100644 --- a/drivers/iio/accel/bma400.h +++ b/drivers/iio/accel/bma400.h @@ -83,8 +83,27 @@ #define BMA400_ACC_ODR_MIN_WHOLE_HZ 25 #define BMA400_ACC_ODR_MIN_HZ 12 -#define BMA400_SCALE_MIN 38357 -#define BMA400_SCALE_MAX 306864 +/* + * BMA400_SCALE_MIN macro value represents m/s^2 for 1 LSB before + * converting to micro values for +-2g range. + * + * For +-2g - 1 LSB = 0.976562 milli g = 0.009576 m/s^2 + * For +-4g - 1 LSB = 1.953125 milli g = 0.019153 m/s^2 + * For +-16g - 1 LSB = 7.8125 milli g = 0.076614 m/s^2 + * + * The raw value which is used to select the different ranges is determined + * by the first bit set position from the scale value, so BMA400_SCALE_MIN + * should be odd. + * + * Scale values for +-2g, +-4g, +-8g and +-16g is populated into bma400_scales + * array by left shifting BMA400_SCALE_MIN. + * eg: + * To select +-2g = 9577 << 0 = raw value to write is 0. + * To select +-8g = 9577 << 2 = raw value to write is 2. + * To select +-16g = 9577 << 3 = raw value to write is 3. + */ +#define BMA400_SCALE_MIN 9577 +#define BMA400_SCALE_MAX 76617 #define BMA400_NUM_REGULATORS 2 #define BMA400_VDD_REGULATOR 0 From patchwork Mon Apr 11 20:31:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagath Jog J X-Patchwork-Id: 12809615 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F334DC4332F for ; Mon, 11 Apr 2022 20:31:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349863AbiDKUeE (ORCPT ); Mon, 11 Apr 2022 16:34:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349840AbiDKUd7 (ORCPT ); Mon, 11 Apr 2022 16:33:59 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8D1135DD4; Mon, 11 Apr 2022 13:31:43 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id 2so16330906pjw.2; Mon, 11 Apr 2022 13:31:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5KLzKGdd8LV7gQ18kh9kvdDgQJKmqje3cmp4naYrraY=; b=Q3QbFzfI60oebxR9Q15Lz1ZK3ABmd+DU55agMXrZq5s+nmemFrEo9gEHxcWRp2b/xb JwmEh8KDzPyO81G2zK/J5bbvdC4D+xzloEskKAFmkyG4ojCJKaL4Af6Sbce1W/cYMXk9 uZXtWpGlD23kubvxBtUCYHbHHPwUBDWlAYhy4KnsyZ80gW/vlp2tdjIZH74SHldP14kt BIrGd6h4IeCNfXT2o83loYBW8w5Gz9ROSwMWMngvXPWmk4zPrOFtOUG5CAxTYJ/7Y8+U n7I/ThGHyb5450OuoK6g72noAuN5iH9uZ4xYz8clxG1HYXmNPJJ4DFwLFBERuTNZ5KGr iT5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5KLzKGdd8LV7gQ18kh9kvdDgQJKmqje3cmp4naYrraY=; b=llNPvt6l3lNDcHg22m2Stf4p+W1JjHdaDgNCyiPga3qGXY6i9gQ71oGkFWf173585A /vm2oMa9eT23ohGRcHfFdVfXlX/WdS/VGdRzuj2MIMtyQLRdBgPJSmQ5wRmU5tpbMw9v AOGFZ2urvAawMoVsxKCoLTNkKJf+8ReT7cQSIoMsKi1ro8Is6OOF0t/cvzqhHAtbpYQv 4mOZCnUFxW7lviCod45KELjxlH91fIrpwlC10vL+3jRlNf2hs3812O33E9bazzWqqRts iHH2NvcpVHLiuujtZwuiPKQ5weazPMogCd0HAY+LhIkVqwaEoyixZHGSTc6DU9fBJ/n/ 4ykg== X-Gm-Message-State: AOAM5336Acgg0AkVva2BMdRFNZwothegjheFJgJbe0pht1/3+T5yJABN hh1lMcyHNIgSXcTq4REM8MNFrfhJkXM= X-Google-Smtp-Source: ABdhPJxNIUc3kuuGLDE83Tl/3vyAMcpRLkw4diFbiR/hUr12amgBmX64Tv3la2ProziLoipCDBI+Yw== X-Received: by 2002:a17:90a:6393:b0:1bf:70e7:27d2 with SMTP id f19-20020a17090a639300b001bf70e727d2mr1005552pjj.1.1649709103334; Mon, 11 Apr 2022 13:31:43 -0700 (PDT) Received: from localhost.localdomain ([27.7.99.112]) by smtp.gmail.com with ESMTPSA id z15-20020a056a001d8f00b004fda37855ddsm34069828pfw.168.2022.04.11.13.31.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 13:31:43 -0700 (PDT) From: Jagath Jog J To: dan@dlrobertson.com, jic23@kernel.org, andy.shevchenko@gmail.com Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/9] iio: accel: bma400: Reordering of header files Date: Tue, 12 Apr 2022 02:01:26 +0530 Message-Id: <20220411203133.19929-3-jagathjog1996@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220411203133.19929-1-jagathjog1996@gmail.com> References: <20220411203133.19929-1-jagathjog1996@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Reordering of header files and removing the iio/sysfs.h since custom attributes are not being used in the driver. Signed-off-by: Jagath Jog J Reviewed-by: Andy Shevchenko --- drivers/iio/accel/bma400_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iio/accel/bma400_core.c b/drivers/iio/accel/bma400_core.c index 043002fe6f63..25ad1f7339bc 100644 --- a/drivers/iio/accel/bma400_core.c +++ b/drivers/iio/accel/bma400_core.c @@ -13,14 +13,14 @@ #include #include -#include -#include #include #include #include #include #include +#include + #include "bma400.h" /* From patchwork Mon Apr 11 20:31:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagath Jog J X-Patchwork-Id: 12809614 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A74AAC433F5 for ; Mon, 11 Apr 2022 20:31:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349795AbiDKUeD (ORCPT ); Mon, 11 Apr 2022 16:34:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349855AbiDKUeB (ORCPT ); Mon, 11 Apr 2022 16:34:01 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5ACD135DDA; Mon, 11 Apr 2022 13:31:46 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id s21so10655508pgv.13; Mon, 11 Apr 2022 13:31:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=l2e3KyH1RI1JashrHIJXtQZiQkoaBw0PIRPaIBjs/qY=; b=Zbez/N35Q2sICIdY3of136PhAlOD3Hn4P7SUXhPTxE+Fu1XJ/Mf4DGF3KiXDZ1Q0et i9NYfEJ4MZvZIN8aB2SeNk5FjN+nRdDuuPY20Cvc4pF5S5YX4o9AU5xBg59YxtucNDNi IsdYhSt1Y0heag4Jvylym57AL9aQ9mXkJBWrWyuwQ2ViW/LqcV53ZJxSjjYvVKm8xLTW 0QB7bg1YQMlYC9mk9CTZtbfiLZcSRJV4qKQqo594s/dshqvHfru88GLpeXsWDybJKeOQ S+VbQ4veqikCIE5hFwk/yvjrd9Lic+ATC4wjsMJllLNocdqDjiM16mHB+9SZkqScJwhX tCLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=l2e3KyH1RI1JashrHIJXtQZiQkoaBw0PIRPaIBjs/qY=; b=2Dnq+4ZC97dfD4EkBT2J4FCplkGRgT5TO+9UmnkbfTYgzFpzX2lKUgaLIgaLD92AaQ h2VbUTTr2pADnXHzV11tzKgAIcZr44Nq2pLQGt0o7R+v7/0OwpCRsRQLyuRxzB+9t4Uq uvteAwKSB61JPtnrU0+V+ExyTX7fq6zIDpYS9CNCClD1H+GzIORfuvl3N/okwy1x0Vkc 7rOsqUKt3GRlMlJwg4ppxouQrCUffkmEJGK9dj6mMq/4LCjAhPahSC4qm9aTtlTmjzQh EnEqZC8Q/OZtzAo863stm9ECFtXxqoa/+nJrnjYW1ACUmgca1/LUcjsDmUOSKuGVFty7 qeqg== X-Gm-Message-State: AOAM532kMiAurAb4CK/j+/uS87MDxXWpq5oE826lXM3pbBxYcLNaUYDP o5K9L2XzzN46olOIkKILHXo= X-Google-Smtp-Source: ABdhPJy4h2t7QgYPiP2bVWney/8dOjGWtxM9WwFF8CFNji7r7Mvo66/Okl6q+Ocsyu9+HnUUWN/jFQ== X-Received: by 2002:a05:6a00:140f:b0:4e0:6995:9c48 with SMTP id l15-20020a056a00140f00b004e069959c48mr34432810pfu.59.1649709105745; Mon, 11 Apr 2022 13:31:45 -0700 (PDT) Received: from localhost.localdomain ([27.7.99.112]) by smtp.gmail.com with ESMTPSA id z15-20020a056a001d8f00b004fda37855ddsm34069828pfw.168.2022.04.11.13.31.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 13:31:45 -0700 (PDT) From: Jagath Jog J To: dan@dlrobertson.com, jic23@kernel.org, andy.shevchenko@gmail.com Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/9] iio: accel: bma400: conversion to device-managed function Date: Tue, 12 Apr 2022 02:01:27 +0530 Message-Id: <20220411203133.19929-4-jagathjog1996@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220411203133.19929-1-jagathjog1996@gmail.com> References: <20220411203133.19929-1-jagathjog1996@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This is a conversion to device-managed by using devm_iio_device_register inside probe function. Previously the bma400 was not put into power down mode in some error paths in probe where it now is, but that should cause no harm. The dev_set_drvdata() call, bma400_remove() function and hooks in the I2C and SPI driver struct is removed as devm_iio_device_register function is used to automatically unregister on driver detach. Signed-off-by: Jagath Jog J Reviewed-by: Andy Shevchenko --- drivers/iio/accel/bma400.h | 2 - drivers/iio/accel/bma400_core.c | 77 ++++++++++++++++----------------- drivers/iio/accel/bma400_i2c.c | 8 ---- drivers/iio/accel/bma400_spi.c | 6 --- 4 files changed, 38 insertions(+), 55 deletions(-) diff --git a/drivers/iio/accel/bma400.h b/drivers/iio/accel/bma400.h index 5d6a1976503f..8dbf85eeb005 100644 --- a/drivers/iio/accel/bma400.h +++ b/drivers/iio/accel/bma400.h @@ -113,6 +113,4 @@ extern const struct regmap_config bma400_regmap_config; int bma400_probe(struct device *dev, struct regmap *regmap, const char *name); -void bma400_remove(struct device *dev); - #endif diff --git a/drivers/iio/accel/bma400_core.c b/drivers/iio/accel/bma400_core.c index 25ad1f7339bc..07674d89d978 100644 --- a/drivers/iio/accel/bma400_core.c +++ b/drivers/iio/accel/bma400_core.c @@ -560,6 +560,26 @@ static void bma400_init_tables(void) } } +static void bma400_regulators_disable(void *data_ptr) +{ + struct bma400_data *data = data_ptr; + + regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators); +} + +static void bma400_power_disable(void *data_ptr) +{ + struct bma400_data *data = data_ptr; + int ret; + + mutex_lock(&data->mutex); + ret = bma400_set_power_mode(data, POWER_MODE_SLEEP); + mutex_unlock(&data->mutex); + if (ret) + dev_warn(data->dev, "Failed to put device into sleep mode (%pe)\n", + ERR_PTR(ret)); +} + static int bma400_init(struct bma400_data *data) { unsigned int val; @@ -569,13 +589,12 @@ static int bma400_init(struct bma400_data *data) ret = regmap_read(data->regmap, BMA400_CHIP_ID_REG, &val); if (ret) { dev_err(data->dev, "Failed to read chip id register\n"); - goto out; + return ret; } if (val != BMA400_ID_REG_VAL) { dev_err(data->dev, "Chip ID mismatch\n"); - ret = -ENODEV; - goto out; + return -ENODEV; } data->regulators[BMA400_VDD_REGULATOR].supply = "vdd"; @@ -589,27 +608,31 @@ static int bma400_init(struct bma400_data *data) "Failed to get regulators: %d\n", ret); - goto out; + return ret; } ret = regulator_bulk_enable(ARRAY_SIZE(data->regulators), data->regulators); if (ret) { dev_err(data->dev, "Failed to enable regulators: %d\n", ret); - goto out; + return ret; } + ret = devm_add_action_or_reset(data->dev, bma400_regulators_disable, data); + if (ret) + return ret; + ret = bma400_get_power_mode(data); if (ret) { dev_err(data->dev, "Failed to get the initial power-mode\n"); - goto err_reg_disable; + return ret; } if (data->power_mode != POWER_MODE_NORMAL) { ret = bma400_set_power_mode(data, POWER_MODE_NORMAL); if (ret) { dev_err(data->dev, "Failed to wake up the device\n"); - goto err_reg_disable; + return ret; } /* * TODO: The datasheet waits 1500us here in the example, but @@ -618,19 +641,23 @@ static int bma400_init(struct bma400_data *data) usleep_range(1500, 2000); } + ret = devm_add_action_or_reset(data->dev, bma400_power_disable, data); + if (ret) + return ret; + bma400_init_tables(); ret = bma400_get_accel_output_data_rate(data); if (ret) - goto err_reg_disable; + return ret; ret = bma400_get_accel_oversampling_ratio(data); if (ret) - goto err_reg_disable; + return ret; ret = bma400_get_accel_scale(data); if (ret) - goto err_reg_disable; + return ret; /* * Once the interrupt engine is supported we might use the @@ -639,12 +666,6 @@ static int bma400_init(struct bma400_data *data) * channel. */ return regmap_write(data->regmap, BMA400_ACC_CONFIG2_REG, 0x00); - -err_reg_disable: - regulator_bulk_disable(ARRAY_SIZE(data->regulators), - data->regulators); -out: - return ret; } static int bma400_read_raw(struct iio_dev *indio_dev, @@ -822,32 +843,10 @@ int bma400_probe(struct device *dev, struct regmap *regmap, const char *name) indio_dev->num_channels = ARRAY_SIZE(bma400_channels); indio_dev->modes = INDIO_DIRECT_MODE; - dev_set_drvdata(dev, indio_dev); - - return iio_device_register(indio_dev); + return devm_iio_device_register(dev, indio_dev); } EXPORT_SYMBOL_NS(bma400_probe, IIO_BMA400); -void bma400_remove(struct device *dev) -{ - struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct bma400_data *data = iio_priv(indio_dev); - int ret; - - mutex_lock(&data->mutex); - ret = bma400_set_power_mode(data, POWER_MODE_SLEEP); - mutex_unlock(&data->mutex); - - if (ret) - dev_warn(dev, "Failed to put device into sleep mode (%pe)\n", ERR_PTR(ret)); - - regulator_bulk_disable(ARRAY_SIZE(data->regulators), - data->regulators); - - iio_device_unregister(indio_dev); -} -EXPORT_SYMBOL_NS(bma400_remove, IIO_BMA400); - MODULE_AUTHOR("Dan Robertson "); MODULE_DESCRIPTION("Bosch BMA400 triaxial acceleration sensor core"); MODULE_LICENSE("GPL"); diff --git a/drivers/iio/accel/bma400_i2c.c b/drivers/iio/accel/bma400_i2c.c index da104ffd3fe0..4f6e01a3b3a1 100644 --- a/drivers/iio/accel/bma400_i2c.c +++ b/drivers/iio/accel/bma400_i2c.c @@ -27,13 +27,6 @@ static int bma400_i2c_probe(struct i2c_client *client, return bma400_probe(&client->dev, regmap, id->name); } -static int bma400_i2c_remove(struct i2c_client *client) -{ - bma400_remove(&client->dev); - - return 0; -} - static const struct i2c_device_id bma400_i2c_ids[] = { { "bma400", 0 }, { } @@ -52,7 +45,6 @@ static struct i2c_driver bma400_i2c_driver = { .of_match_table = bma400_of_i2c_match, }, .probe = bma400_i2c_probe, - .remove = bma400_i2c_remove, .id_table = bma400_i2c_ids, }; diff --git a/drivers/iio/accel/bma400_spi.c b/drivers/iio/accel/bma400_spi.c index 51f23bdc0ea5..28e240400a3f 100644 --- a/drivers/iio/accel/bma400_spi.c +++ b/drivers/iio/accel/bma400_spi.c @@ -87,11 +87,6 @@ static int bma400_spi_probe(struct spi_device *spi) return bma400_probe(&spi->dev, regmap, id->name); } -static void bma400_spi_remove(struct spi_device *spi) -{ - bma400_remove(&spi->dev); -} - static const struct spi_device_id bma400_spi_ids[] = { { "bma400", 0 }, { } @@ -110,7 +105,6 @@ static struct spi_driver bma400_spi_driver = { .of_match_table = bma400_of_spi_match, }, .probe = bma400_spi_probe, - .remove = bma400_spi_remove, .id_table = bma400_spi_ids, }; From patchwork Mon Apr 11 20:31:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagath Jog J X-Patchwork-Id: 12809616 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0053DC433EF for ; Mon, 11 Apr 2022 20:31:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349869AbiDKUeN (ORCPT ); Mon, 11 Apr 2022 16:34:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349840AbiDKUeM (ORCPT ); Mon, 11 Apr 2022 16:34:12 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3F2F35DD4; Mon, 11 Apr 2022 13:31:48 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id md20-20020a17090b23d400b001cb70ef790dso417441pjb.5; Mon, 11 Apr 2022 13:31:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ddvbkMcy0CIRnqmwuQ8y2WAioenTWNXBncUhsH86xMc=; b=JcIGFHsZvu7pjvlRos9JQ1M5p5c9n84e14wgYGpduvunK8WTLoXuvHtxWQmVTXixoS EyTW/zpbMDU//Lg3/f2yln/XVJqXcYtU5JSYmTTdQzbI/6Cjb2ekaRzu8eG6QetRed8R 9QloPGwM6Kzvmv29IZ6eBPCx9cKa2hSThi3cKtCD+C/4rw4/ymUwuRiYf+T/u5JIOqpD 0f66teiOBmnIy+f/TC2fuarPqh2Bs0ORO6Nhzwfe22nEUMlWuPmydKPxb51+Dy7+9wd7 d5QNLVWMHIo4kmtr8tVf5thhIRHRrsNlenSxdZqaOxGwpVZ8NAhAHkmshctkmVhWzQp0 NpeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ddvbkMcy0CIRnqmwuQ8y2WAioenTWNXBncUhsH86xMc=; b=Af+vViae6kANuXulopj1lgCuJR6FYuXTJkGdP/Vhd1UkNwE6+V9XYJ201Gv1t7q+dh 90Ji7H7vRfpnN1sto49B5jTsNzVrViCQXKwICTtiHaMyFQL5CtOCVvBKoUs2FghfRQw5 8QgOn+NdQJg1escjl053aYVj/3yyQaAckLEbff4ROipro7Zed1UVnRNS/7FwK9jpHW3H NIU4TPmmjcea+lP2yS2UAvznsdaEOqWXg2q0JwSmd7mJQ3Ar6lYNrOb57hjDLgOBe9FK RG5wqIZ1jUWRO/zY/JEKBAfQLPS+TC0pEWkQlD67azjNH2Mz4SkNly+5zilGgqgxbaXY hl0g== X-Gm-Message-State: AOAM532CjgO0KJaFW8CEscBjn0xcVkb432EtHe9N01dvTmc8tuybaj37 QV9rLhv9cn+2tBDJpC+vRqA= X-Google-Smtp-Source: ABdhPJyfD9YhSnJqmMPh0HSaqq0m3xoOi5pHWKRjebHfeEjvWM+nlAso68ZHr0RmHFEVRI0EU5tQvw== X-Received: by 2002:a17:902:ba88:b0:158:5849:5a37 with SMTP id k8-20020a170902ba8800b0015858495a37mr8203447pls.133.1649709108160; Mon, 11 Apr 2022 13:31:48 -0700 (PDT) Received: from localhost.localdomain ([27.7.99.112]) by smtp.gmail.com with ESMTPSA id z15-20020a056a001d8f00b004fda37855ddsm34069828pfw.168.2022.04.11.13.31.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 13:31:47 -0700 (PDT) From: Jagath Jog J To: dan@dlrobertson.com, jic23@kernel.org, andy.shevchenko@gmail.com Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 4/9] iio: accel: bma400: Add triggered buffer support Date: Tue, 12 Apr 2022 02:01:28 +0530 Message-Id: <20220411203133.19929-5-jagathjog1996@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220411203133.19929-1-jagathjog1996@gmail.com> References: <20220411203133.19929-1-jagathjog1996@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Added trigger buffer support to read continuous acceleration data from device with data ready interrupt which is mapped to INT1 pin. Signed-off-by: Jagath Jog J --- drivers/iio/accel/Kconfig | 2 + drivers/iio/accel/bma400.h | 10 ++- drivers/iio/accel/bma400_core.c | 153 ++++++++++++++++++++++++++++++-- drivers/iio/accel/bma400_i2c.c | 2 +- drivers/iio/accel/bma400_spi.c | 2 +- 5 files changed, 161 insertions(+), 8 deletions(-) diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig index eac3f02662ae..958097814232 100644 --- a/drivers/iio/accel/Kconfig +++ b/drivers/iio/accel/Kconfig @@ -204,6 +204,8 @@ config BMA220 config BMA400 tristate "Bosch BMA400 3-Axis Accelerometer Driver" select REGMAP + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER select BMA400_I2C if I2C select BMA400_SPI if SPI help diff --git a/drivers/iio/accel/bma400.h b/drivers/iio/accel/bma400.h index 8dbf85eeb005..a7482a66b36b 100644 --- a/drivers/iio/accel/bma400.h +++ b/drivers/iio/accel/bma400.h @@ -62,6 +62,13 @@ #define BMA400_ACC_CONFIG2_REG 0x1b #define BMA400_CMD_REG 0x7e +/* Interrupt registers */ +#define BMA400_INT_CONFIG0_REG 0x1f +#define BMA400_INT_CONFIG1_REG 0x20 +#define BMA400_INT1_MAP_REG 0x21 +#define BMA400_INT_IO_CTRL_REG 0x24 +#define BMA400_INT_DRDY_MSK BIT(7) + /* Chip ID of BMA 400 devices found in the chip ID register. */ #define BMA400_ID_REG_VAL 0x90 @@ -111,6 +118,7 @@ extern const struct regmap_config bma400_regmap_config; -int bma400_probe(struct device *dev, struct regmap *regmap, const char *name); +int bma400_probe(struct device *dev, struct regmap *regmap, int irq, + const char *name); #endif diff --git a/drivers/iio/accel/bma400_core.c b/drivers/iio/accel/bma400_core.c index 07674d89d978..b7b2b67aef31 100644 --- a/drivers/iio/accel/bma400_core.c +++ b/drivers/iio/accel/bma400_core.c @@ -11,6 +11,7 @@ * - Create channel for sensor time */ +#include #include #include #include @@ -20,6 +21,10 @@ #include #include +#include +#include +#include +#include #include "bma400.h" @@ -61,6 +66,13 @@ struct bma400_data { struct bma400_sample_freq sample_freq; int oversampling_ratio; int scale; + struct iio_trigger *trig; + /* Correct time stamp alignment */ + struct { + __le16 buff[3]; + u8 temperature; + s64 ts __aligned(8); + } buffer ____cacheline_aligned; }; static bool bma400_is_writable_reg(struct device *dev, unsigned int reg) @@ -152,7 +164,7 @@ static const struct iio_chan_spec_ext_info bma400_ext_info[] = { { } }; -#define BMA400_ACC_CHANNEL(_axis) { \ +#define BMA400_ACC_CHANNEL(_index, _axis) { \ .type = IIO_ACCEL, \ .modified = 1, \ .channel2 = IIO_MOD_##_axis, \ @@ -164,17 +176,32 @@ static const struct iio_chan_spec_ext_info bma400_ext_info[] = { BIT(IIO_CHAN_INFO_SCALE) | \ BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ .ext_info = bma400_ext_info, \ + .scan_index = _index, \ + .scan_type = { \ + .sign = 's', \ + .realbits = 12, \ + .storagebits = 16, \ + .endianness = IIO_LE, \ + }, \ } static const struct iio_chan_spec bma400_channels[] = { - BMA400_ACC_CHANNEL(X), - BMA400_ACC_CHANNEL(Y), - BMA400_ACC_CHANNEL(Z), + BMA400_ACC_CHANNEL(0, X), + BMA400_ACC_CHANNEL(1, Y), + BMA400_ACC_CHANNEL(2, Z), { .type = IIO_TEMP, .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ), + .scan_index = 3, + .scan_type = { + .sign = 's', + .realbits = 8, + .storagebits = 8, + .endianness = IIO_LE, + }, }, + IIO_CHAN_SOFT_TIMESTAMP(4), }; static int bma400_get_temp_reg(struct bma400_data *data, int *val, int *val2) @@ -659,6 +686,10 @@ static int bma400_init(struct bma400_data *data) if (ret) return ret; + /* Configure INT1 pin to open drain */ + ret = regmap_write(data->regmap, BMA400_INT_IO_CTRL_REG, 0x06); + if (ret) + return ret; /* * Once the interrupt engine is supported we might use the * data_src_reg, but for now ensure this is set to the @@ -807,6 +838,29 @@ static int bma400_write_raw_get_fmt(struct iio_dev *indio_dev, } } +static int bma400_data_rdy_trigger_set_state(struct iio_trigger *trig, + bool state) +{ + struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); + struct bma400_data *data = iio_priv(indio_dev); + int ret; + + ret = regmap_update_bits(data->regmap, BMA400_INT_CONFIG0_REG, + BMA400_INT_DRDY_MSK, + FIELD_PREP(BMA400_INT_DRDY_MSK, state)); + if (ret) + return ret; + + return regmap_update_bits(data->regmap, BMA400_INT1_MAP_REG, + BMA400_INT_DRDY_MSK, + FIELD_PREP(BMA400_INT_DRDY_MSK, state)); +} + +static const unsigned long bma400_avail_scan_masks[] = { + GENMASK(3, 0), + 0 +}; + static const struct iio_info bma400_info = { .read_raw = bma400_read_raw, .read_avail = bma400_read_avail, @@ -814,7 +868,64 @@ static const struct iio_info bma400_info = { .write_raw_get_fmt = bma400_write_raw_get_fmt, }; -int bma400_probe(struct device *dev, struct regmap *regmap, const char *name) +static const struct iio_trigger_ops bma400_trigger_ops = { + .set_trigger_state = &bma400_data_rdy_trigger_set_state, + .validate_device = &iio_trigger_validate_own_device, +}; + +static irqreturn_t bma400_trigger_handler(int irq, void *p) +{ + struct iio_poll_func *pf = p; + struct iio_dev *indio_dev = pf->indio_dev; + struct bma400_data *data = iio_priv(indio_dev); + int ret, temp; + + mutex_lock(&data->mutex); + + /* bulk read six registers, with the base being the LSB register */ + ret = regmap_bulk_read(data->regmap, BMA400_X_AXIS_LSB_REG, + &data->buffer.buff, sizeof(data->buffer.buff)); + mutex_unlock(&data->mutex); + if (ret) + return IRQ_NONE; + + ret = regmap_read(data->regmap, BMA400_TEMP_DATA_REG, &temp); + if (ret) + return IRQ_NONE; + + data->buffer.temperature = temp; + + iio_push_to_buffers_with_timestamp(indio_dev, &data->buffer, + iio_get_time_ns(indio_dev)); + + iio_trigger_notify_done(indio_dev->trig); + return IRQ_HANDLED; +} + +static irqreturn_t bma400_interrupt(int irq, void *private) +{ + struct iio_dev *indio_dev = private; + struct bma400_data *data = iio_priv(indio_dev); + int ret; + __le16 status; + + mutex_lock(&data->mutex); + ret = regmap_bulk_read(data->regmap, BMA400_INT_STAT0_REG, &status, + sizeof(status)); + mutex_unlock(&data->mutex); + if (ret) + return IRQ_NONE; + + if (FIELD_GET(BMA400_INT_DRDY_MSK, le16_to_cpu(status))) { + iio_trigger_poll_chained(data->trig); + return IRQ_HANDLED; + } + + return IRQ_NONE; +} + +int bma400_probe(struct device *dev, struct regmap *regmap, int irq, + const char *name) { struct iio_dev *indio_dev; struct bma400_data *data; @@ -841,8 +952,40 @@ int bma400_probe(struct device *dev, struct regmap *regmap, const char *name) indio_dev->info = &bma400_info; indio_dev->channels = bma400_channels; indio_dev->num_channels = ARRAY_SIZE(bma400_channels); + indio_dev->available_scan_masks = bma400_avail_scan_masks; indio_dev->modes = INDIO_DIRECT_MODE; + if (irq > 0) { + data->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", + indio_dev->name, + iio_device_id(indio_dev)); + if (!data->trig) + return -ENOMEM; + + data->trig->ops = &bma400_trigger_ops; + iio_trigger_set_drvdata(data->trig, indio_dev); + + ret = devm_iio_trigger_register(data->dev, data->trig); + if (ret) + return dev_err_probe(data->dev, ret, + "iio trigger register fail\n"); + + indio_dev->trig = iio_trigger_get(data->trig); + ret = devm_request_threaded_irq(dev, irq, NULL, + &bma400_interrupt, + IRQF_TRIGGER_RISING | IRQF_ONESHOT, + indio_dev->name, indio_dev); + if (ret) + return dev_err_probe(data->dev, ret, + "request irq %d failed\n", irq); + } + + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL, + &bma400_trigger_handler, NULL); + if (ret) + return dev_err_probe(data->dev, ret, + "iio triggered buffer setup failed\n"); + return devm_iio_device_register(dev, indio_dev); } EXPORT_SYMBOL_NS(bma400_probe, IIO_BMA400); diff --git a/drivers/iio/accel/bma400_i2c.c b/drivers/iio/accel/bma400_i2c.c index 4f6e01a3b3a1..1ba2a982ea73 100644 --- a/drivers/iio/accel/bma400_i2c.c +++ b/drivers/iio/accel/bma400_i2c.c @@ -24,7 +24,7 @@ static int bma400_i2c_probe(struct i2c_client *client, return PTR_ERR(regmap); } - return bma400_probe(&client->dev, regmap, id->name); + return bma400_probe(&client->dev, regmap, client->irq, id->name); } static const struct i2c_device_id bma400_i2c_ids[] = { diff --git a/drivers/iio/accel/bma400_spi.c b/drivers/iio/accel/bma400_spi.c index 28e240400a3f..ec13c044b304 100644 --- a/drivers/iio/accel/bma400_spi.c +++ b/drivers/iio/accel/bma400_spi.c @@ -84,7 +84,7 @@ static int bma400_spi_probe(struct spi_device *spi) if (ret) dev_err(&spi->dev, "Failed to read chip id register\n"); - return bma400_probe(&spi->dev, regmap, id->name); + return bma400_probe(&spi->dev, regmap, spi->irq, id->name); } static const struct spi_device_id bma400_spi_ids[] = { From patchwork Mon Apr 11 20:31:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagath Jog J X-Patchwork-Id: 12809617 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F30EC433F5 for ; Mon, 11 Apr 2022 20:32:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349879AbiDKUeN (ORCPT ); Mon, 11 Apr 2022 16:34:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349872AbiDKUeF (ORCPT ); Mon, 11 Apr 2022 16:34:05 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B68EB35DD8; Mon, 11 Apr 2022 13:31:50 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id be5so8892116plb.13; Mon, 11 Apr 2022 13:31:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=835pUviTP5ppYn2Uev225f172MsZVkj8fAJp6g5nVbI=; b=XhPM9Xi4hI3zlMqpp9LPk3LS02QFPR2NAM7wG0m0iEvHU4D6z1teuac9/BCiuEWmLf T5mwJwanfwNd/iTQrKsEpaRy3SC0pZzOK9HdIDm5e+ata02srKGJLo8VN0biA0SUJ0iY V8hxRV93crh3RmX9H0364EpEa7J3BSjmYiMHhUFl3tAKFeDwkC//OBJqkGbY9qJ9zjFp ns7I9Md7bCPTiFHYr7pcG/bvil0cdjsrujzJ62CYM5AKD5QtKX8FR0ZXefbcn4o2/h73 XDF6GhiLgJv1fCPIo4k3P12qW3C1YdiafeQ4Vg6vpb+K1Ep2rNcuwmy/FDov5S360Z2H G3EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=835pUviTP5ppYn2Uev225f172MsZVkj8fAJp6g5nVbI=; b=hKEQOn2r/tyhHiKn2EuVsNEc5hMM8pOX35RsAKZmshmaQIhPK3IjZcqunkyZkIx2HF bTi2L+O3ZPneG4hB/RBba/aPbYcqKP0yHJTHZk11gugvcv5d2WEFxzPlk8HzShhnYO/J rvwEizrU9voVtcmWdQNji6GfPS5EkzyorQDWYUvPgXeu676+XHBaMAhj5WAixjsmbuhD UrUbZCM6VPU1fjiucOCbnIPC2WQAYK8U9eIKnyqJHqxO3rD8TSOWSVVkEmQJzeGph8iI ETirCrvZjuLeCayWLbiRGJEnzIN6qlHfLGxbtIg3mBJ3YEkKDI+HuBQpmfiwqEr84NHq FDqg== X-Gm-Message-State: AOAM533XIf5MLPQQXizp18pc4PVufpalVQP2jJOZhRqDc9HIP9wBrvKq dgVzgYiLu8fcP0ywk1VCl/Q= X-Google-Smtp-Source: ABdhPJynU3w14f8aoQPexTNCXrSK2rl3LVDMIRfan7vGLbnzrPwQestibKe5rO5e+naCZPyx6Xrp2Q== X-Received: by 2002:a17:902:e889:b0:151:a56d:eb8f with SMTP id w9-20020a170902e88900b00151a56deb8fmr33124044plg.142.1649709110223; Mon, 11 Apr 2022 13:31:50 -0700 (PDT) Received: from localhost.localdomain ([27.7.99.112]) by smtp.gmail.com with ESMTPSA id z15-20020a056a001d8f00b004fda37855ddsm34069828pfw.168.2022.04.11.13.31.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 13:31:49 -0700 (PDT) From: Jagath Jog J To: dan@dlrobertson.com, jic23@kernel.org, andy.shevchenko@gmail.com Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 5/9] iio: accel: bma400: Add separate channel for step counter Date: Tue, 12 Apr 2022 02:01:29 +0530 Message-Id: <20220411203133.19929-6-jagathjog1996@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220411203133.19929-1-jagathjog1996@gmail.com> References: <20220411203133.19929-1-jagathjog1996@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Added channel for step counter which can be enable or disable through the sysfs interface. Signed-off-by: Jagath Jog J --- drivers/iio/accel/bma400.h | 1 + drivers/iio/accel/bma400_core.c | 48 ++++++++++++++++++++++++++++++--- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/drivers/iio/accel/bma400.h b/drivers/iio/accel/bma400.h index a7482a66b36b..52f9ea95de81 100644 --- a/drivers/iio/accel/bma400.h +++ b/drivers/iio/accel/bma400.h @@ -53,6 +53,7 @@ #define BMA400_STEP_CNT1_REG 0x16 #define BMA400_STEP_CNT3_REG 0x17 #define BMA400_STEP_STAT_REG 0x18 +#define BMA400_STEP_INT_MSK BIT(0) /* * Read-write configuration registers diff --git a/drivers/iio/accel/bma400_core.c b/drivers/iio/accel/bma400_core.c index b7b2b67aef31..c8f147163d3c 100644 --- a/drivers/iio/accel/bma400_core.c +++ b/drivers/iio/accel/bma400_core.c @@ -20,6 +20,8 @@ #include #include +#include + #include #include #include @@ -67,6 +69,7 @@ struct bma400_data { int oversampling_ratio; int scale; struct iio_trigger *trig; + int steps_enabled; /* Correct time stamp alignment */ struct { __le16 buff[3]; @@ -201,6 +204,12 @@ static const struct iio_chan_spec bma400_channels[] = { .endianness = IIO_LE, }, }, + { + .type = IIO_STEPS, + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | + BIT(IIO_CHAN_INFO_ENABLE), + .scan_index = -1, /* No buffer support */ + }, IIO_CHAN_SOFT_TIMESTAMP(4), }; @@ -705,13 +714,28 @@ static int bma400_read_raw(struct iio_dev *indio_dev, { struct bma400_data *data = iio_priv(indio_dev); int ret; + u8 steps_raw[3]; switch (mask) { case IIO_CHAN_INFO_PROCESSED: - mutex_lock(&data->mutex); - ret = bma400_get_temp_reg(data, val, val2); - mutex_unlock(&data->mutex); - return ret; + switch (chan->type) { + case IIO_TEMP: + mutex_lock(&data->mutex); + ret = bma400_get_temp_reg(data, val, val2); + mutex_unlock(&data->mutex); + return ret; + case IIO_STEPS: + mutex_lock(&data->mutex); + ret = regmap_bulk_read(data->regmap, BMA400_STEP_CNT0_REG, + &steps_raw, sizeof(steps_raw)); + mutex_unlock(&data->mutex); + if (ret) + return ret; + *val = get_unaligned_le24(steps_raw); + return IIO_VAL_INT; + default: + return -EINVAL; + } case IIO_CHAN_INFO_RAW: mutex_lock(&data->mutex); ret = bma400_get_accel_reg(data, chan, val); @@ -752,6 +776,9 @@ static int bma400_read_raw(struct iio_dev *indio_dev, *val = data->oversampling_ratio; return IIO_VAL_INT; + case IIO_CHAN_INFO_ENABLE: + *val = data->steps_enabled; + return IIO_VAL_INT; default: return -EINVAL; } @@ -817,6 +844,17 @@ static int bma400_write_raw(struct iio_dev *indio_dev, ret = bma400_set_accel_oversampling_ratio(data, val); mutex_unlock(&data->mutex); return ret; + case IIO_CHAN_INFO_ENABLE: + if (data->steps_enabled == val) + return 0; + + mutex_lock(&data->mutex); + ret = regmap_update_bits(data->regmap, BMA400_INT_CONFIG1_REG, + BMA400_STEP_INT_MSK, + FIELD_PREP(BMA400_STEP_INT_MSK, !!val)); + mutex_unlock(&data->mutex); + data->steps_enabled = val; + return ret; default: return -EINVAL; } @@ -833,6 +871,8 @@ static int bma400_write_raw_get_fmt(struct iio_dev *indio_dev, return IIO_VAL_INT_PLUS_MICRO; case IIO_CHAN_INFO_OVERSAMPLING_RATIO: return IIO_VAL_INT; + case IIO_CHAN_INFO_ENABLE: + return IIO_VAL_INT; default: return -EINVAL; } From patchwork Mon Apr 11 20:31:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagath Jog J X-Patchwork-Id: 12809619 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14B09C4332F for ; Mon, 11 Apr 2022 20:32:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349883AbiDKUeO (ORCPT ); Mon, 11 Apr 2022 16:34:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349882AbiDKUeM (ORCPT ); Mon, 11 Apr 2022 16:34:12 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4064936142; Mon, 11 Apr 2022 13:31:53 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id n8so14875362plh.1; Mon, 11 Apr 2022 13:31:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Td+5xF2W6lM7nqApdBgxh2F8Fc6N+cKcoMhSCOA5VFg=; b=G1GXw3UPApwTJ2/wzpKAGhHm47/g1i/Fto/8j+jytX/w1M94iZzm6R31cSnzHmFIU6 t9WwH5Ts190+HN+9NxgQuErLDBHeXzo+qQgn4SQYoV08/iHflEa3cT1fk3xF6D8jERuY MyRMY02POFNJcmfYIjQxBm2HB242QQelTKVPwW52VsFbXOSjSu1kf5v38MnrSTWvHFTJ JA8Ij3MRDZIEpfO4w/nrIcn4DRLot6Jz6oU5OFSA8J4pZK5UNK9YdyABaw/BgFxXuqj0 emUH/SOtITtPktekLiv8UAbaNEIJJyXFX/Ok7tfrGa8dgWPeUEtP+vgSmqzayk+jkmw4 YL7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Td+5xF2W6lM7nqApdBgxh2F8Fc6N+cKcoMhSCOA5VFg=; b=el72UzhRpELNy4QAUsN8oYiug3IsyTb2NqJHeuQArSVrfO0AT3xNI0lfgPgbiey0+/ H7o9UJZm1ObsKbxRQQD7Eedz8gqOtdENKbX+3yt2CyOl8l9fe5yqaghfheN55Ebzk96d I3a0r8G7/qTIMcR8ulSKlfR74HbA7dqAwlblkAyPk3GHZo0uOpolgUEN2MW7dQXWzFMg ZzpGJGxBEWR7nATUW8muHIACnh0tkbtOxENW29zNcVmYdHmTpqt0wLV4c12OA2wvxHkQ XoYkvJOVNGFc6wP22a3WeKBBZ8Xy88Yq2Iwm+A0Y4zroZtOm4zrtgUf8gMlubF/FluWE 9tNw== X-Gm-Message-State: AOAM531AnE81EeWXUSCSyKbf1Ck3wSW0/w2UpULybEBI6YwelivjDarF r3XlK+rDOmVD4dH/Lk4/YIU= X-Google-Smtp-Source: ABdhPJzOVO+2Qnmg0jUXg+1t63JqijDn7fONYYDSPGczZbpUGooj1yDaZcJ8MzhYP7VNyFCfAjyZPg== X-Received: by 2002:a17:90b:1803:b0:1c7:24c4:ab52 with SMTP id lw3-20020a17090b180300b001c724c4ab52mr1011103pjb.240.1649709112575; Mon, 11 Apr 2022 13:31:52 -0700 (PDT) Received: from localhost.localdomain ([27.7.99.112]) by smtp.gmail.com with ESMTPSA id z15-20020a056a001d8f00b004fda37855ddsm34069828pfw.168.2022.04.11.13.31.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 13:31:52 -0700 (PDT) From: Jagath Jog J To: dan@dlrobertson.com, jic23@kernel.org, andy.shevchenko@gmail.com Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 6/9] iio: accel: bma400: Add step change event Date: Tue, 12 Apr 2022 02:01:30 +0530 Message-Id: <20220411203133.19929-7-jagathjog1996@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220411203133.19929-1-jagathjog1996@gmail.com> References: <20220411203133.19929-1-jagathjog1996@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Added support for event when there is a detection of step change. INT1 pin is used to interrupt and event is pushed to userspace. Signed-off-by: Jagath Jog J --- drivers/iio/accel/bma400.h | 2 + drivers/iio/accel/bma400_core.c | 76 +++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/drivers/iio/accel/bma400.h b/drivers/iio/accel/bma400.h index 52f9ea95de81..bc4641279be3 100644 --- a/drivers/iio/accel/bma400.h +++ b/drivers/iio/accel/bma400.h @@ -39,6 +39,7 @@ #define BMA400_INT_STAT0_REG 0x0e #define BMA400_INT_STAT1_REG 0x0f #define BMA400_INT_STAT2_REG 0x10 +#define BMA400_INT12_MAP_REG 0x23 /* Temperature register */ #define BMA400_TEMP_DATA_REG 0x11 @@ -54,6 +55,7 @@ #define BMA400_STEP_CNT3_REG 0x17 #define BMA400_STEP_STAT_REG 0x18 #define BMA400_STEP_INT_MSK BIT(0) +#define BMA400_STEP_STAT_MASK GENMASK(9, 8) /* * Read-write configuration registers diff --git a/drivers/iio/accel/bma400_core.c b/drivers/iio/accel/bma400_core.c index c8f147163d3c..37f38626a9aa 100644 --- a/drivers/iio/accel/bma400_core.c +++ b/drivers/iio/accel/bma400_core.c @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -70,6 +71,7 @@ struct bma400_data { int scale; struct iio_trigger *trig; int steps_enabled; + bool step_event_en; /* Correct time stamp alignment */ struct { __le16 buff[3]; @@ -167,6 +169,12 @@ static const struct iio_chan_spec_ext_info bma400_ext_info[] = { { } }; +static const struct iio_event_spec bma400_step_detect_event = { + .type = IIO_EV_TYPE_CHANGE, + .dir = IIO_EV_DIR_NONE, + .mask_separate = BIT(IIO_EV_INFO_ENABLE), +}; + #define BMA400_ACC_CHANNEL(_index, _axis) { \ .type = IIO_ACCEL, \ .modified = 1, \ @@ -209,6 +217,8 @@ static const struct iio_chan_spec bma400_channels[] = { .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | BIT(IIO_CHAN_INFO_ENABLE), .scan_index = -1, /* No buffer support */ + .event_spec = &bma400_step_detect_event, + .num_event_specs = 1, }, IIO_CHAN_SOFT_TIMESTAMP(4), }; @@ -878,6 +888,60 @@ static int bma400_write_raw_get_fmt(struct iio_dev *indio_dev, } } +static int bma400_read_event_config(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir) +{ + struct bma400_data *data = iio_priv(indio_dev); + + switch (chan->type) { + case IIO_STEPS: + return data->step_event_en; + default: + return -EINVAL; + } +} + +static int bma400_write_event_config(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, int state) +{ + int ret; + struct bma400_data *data = iio_priv(indio_dev); + + switch (chan->type) { + case IIO_STEPS: + mutex_lock(&data->mutex); + if (!data->steps_enabled) { + ret = regmap_update_bits(data->regmap, + BMA400_INT_CONFIG1_REG, + BMA400_STEP_INT_MSK, + FIELD_PREP(BMA400_STEP_INT_MSK, + 1)); + if (ret) { + mutex_unlock(&data->mutex); + return ret; + } + data->steps_enabled = 1; + } + + ret = regmap_update_bits(data->regmap, + BMA400_INT12_MAP_REG, + BMA400_STEP_INT_MSK, + FIELD_PREP(BMA400_STEP_INT_MSK, + state)); + mutex_unlock(&data->mutex); + if (ret) + return ret; + data->step_event_en = state; + return 0; + default: + return -EINVAL; + } +} + static int bma400_data_rdy_trigger_set_state(struct iio_trigger *trig, bool state) { @@ -906,6 +970,8 @@ static const struct iio_info bma400_info = { .read_avail = bma400_read_avail, .write_raw = bma400_write_raw, .write_raw_get_fmt = bma400_write_raw_get_fmt, + .read_event_config = bma400_read_event_config, + .write_event_config = bma400_write_event_config, }; static const struct iio_trigger_ops bma400_trigger_ops = { @@ -946,6 +1012,7 @@ static irqreturn_t bma400_interrupt(int irq, void *private) { struct iio_dev *indio_dev = private; struct bma400_data *data = iio_priv(indio_dev); + s64 timestamp = iio_get_time_ns(indio_dev); int ret; __le16 status; @@ -956,6 +1023,15 @@ static irqreturn_t bma400_interrupt(int irq, void *private) if (ret) return IRQ_NONE; + if (FIELD_GET(BMA400_STEP_STAT_MASK, le16_to_cpu(status))) { + iio_push_event(indio_dev, + IIO_EVENT_CODE(IIO_STEPS, 0, IIO_NO_MOD, + IIO_EV_DIR_NONE, + IIO_EV_TYPE_CHANGE, 0, 0, 0), + timestamp); + return IRQ_HANDLED; + } + if (FIELD_GET(BMA400_INT_DRDY_MSK, le16_to_cpu(status))) { iio_trigger_poll_chained(data->trig); return IRQ_HANDLED; From patchwork Mon Apr 11 20:31:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagath Jog J X-Patchwork-Id: 12809618 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DBBFEC43219 for ; Mon, 11 Apr 2022 20:32:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349840AbiDKUeO (ORCPT ); Mon, 11 Apr 2022 16:34:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349885AbiDKUeN (ORCPT ); Mon, 11 Apr 2022 16:34:13 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4884A36151; Mon, 11 Apr 2022 13:31:55 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id o5-20020a17090ad20500b001ca8a1dc47aso453060pju.1; Mon, 11 Apr 2022 13:31:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nVy+PdUdt3aYbmKl1De/O0IbA9jK9d4aWpuuU9JRDr0=; b=I0BOtu/NTUxum3tk1mDK4B4v9Tk/DOk/HjsgtA0CG0tELAoHcWuEID0q9kXAvPjvyY RTmxFA1WD68lC7h2hRvB+6kCo2D/Yu1/Z1jRmUIX+aexHC9ofI1nEFToFPMG/oW3LI5q q/D/Df0Z9xfri8lrhUBEnPaHWtK2IeEsn20NRI/zRhSTG3ZyZ+EnUpS5ipMt9aHfB5VU ZAg1mQuMOkAAg4dZTVMaj5qBR+n4/6WFRtmbd8Yc8zQidgWJXeglmvmuI+aMxi6gl1NG zX7zblPGjKEYlNlr4zj8XVsbxTx8n3VS1Ri4cOZbo4QW9/LLRARxYsdd6yUhKpVV257P Tamw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nVy+PdUdt3aYbmKl1De/O0IbA9jK9d4aWpuuU9JRDr0=; b=F8PxvsWGL/hKIYFnfYVtWRvKesp5OhuzO+CQN9/OZQPWjysWfD/TVWPRPBSzeu758r rhwriQYVyB7iMpalfAe5bGfIwcPWvXSDiKvzBhX51AWcmEI6lSw5Xk1Y/n7s7VpdL+Fs +Qg3a0J+WX8mmvvDMkxqQUEYSJ5P1S+yHpZt29o1dU/BuXBpYZPmq45yt18JZobmpOpp E/aFcP6BZlLo1oFBggOFcTp/44B82AqoWOmStWv1HpqrIYgVnXq0JiJOysECs+3mnkN7 sI+ZBJaldjNpxOx5PpkWU5l4e/ZAo4sKD0noGCwiPj3gPSX4/SQWGZ4kygpmAG48jsgf SgOQ== X-Gm-Message-State: AOAM530pY2ymPkQ0u5dgfp9a435ene+E6XwoPcazUbwdLV2n4iNtmmym PU1cEDgImGnHoRRSpGJVTP0= X-Google-Smtp-Source: ABdhPJyspJIGql9cAc4QJC3lhh50NSLTb/oRc3xE/Arap4dWYLja8tYgSWYEAKrReNGd3RaPGq24oQ== X-Received: by 2002:a17:902:ef46:b0:153:81f7:7fc2 with SMTP id e6-20020a170902ef4600b0015381f77fc2mr34343014plx.26.1649709114611; Mon, 11 Apr 2022 13:31:54 -0700 (PDT) Received: from localhost.localdomain ([27.7.99.112]) by smtp.gmail.com with ESMTPSA id z15-20020a056a001d8f00b004fda37855ddsm34069828pfw.168.2022.04.11.13.31.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 13:31:54 -0700 (PDT) From: Jagath Jog J To: dan@dlrobertson.com, jic23@kernel.org, andy.shevchenko@gmail.com Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 7/9] iio: accel: bma400: Add activity recognition support Date: Tue, 12 Apr 2022 02:01:31 +0530 Message-Id: <20220411203133.19929-8-jagathjog1996@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220411203133.19929-1-jagathjog1996@gmail.com> References: <20220411203133.19929-1-jagathjog1996@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add support for activity recognition like STILL, WALKING, RUNNING and these events are pushed to the userspace whenever the STEP interrupt occurs. Signed-off-by: Jagath Jog J --- drivers/iio/accel/bma400_core.c | 104 ++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/drivers/iio/accel/bma400_core.c b/drivers/iio/accel/bma400_core.c index 37f38626a9aa..69d2caa4ed18 100644 --- a/drivers/iio/accel/bma400_core.c +++ b/drivers/iio/accel/bma400_core.c @@ -59,6 +59,12 @@ struct bma400_sample_freq { int uhz; }; +enum bma400_activity { + BMA400_STILL, + BMA400_WALKING, + BMA400_RUNNING, +}; + struct bma400_data { struct device *dev; struct regmap *regmap; @@ -72,6 +78,7 @@ struct bma400_data { struct iio_trigger *trig; int steps_enabled; bool step_event_en; + bool activity_event_en; /* Correct time stamp alignment */ struct { __le16 buff[3]; @@ -175,6 +182,12 @@ static const struct iio_event_spec bma400_step_detect_event = { .mask_separate = BIT(IIO_EV_INFO_ENABLE), }; +static const struct iio_event_spec bma400_activity_event = { + .type = IIO_EV_TYPE_CHANGE, + .dir = IIO_EV_DIR_NONE, + .mask_shared_by_type = BIT(IIO_EV_INFO_ENABLE), +}; + #define BMA400_ACC_CHANNEL(_index, _axis) { \ .type = IIO_ACCEL, \ .modified = 1, \ @@ -196,6 +209,16 @@ static const struct iio_event_spec bma400_step_detect_event = { }, \ } +#define BMA400_ACTIVITY_CHANNEL(_chan2) { \ + .type = IIO_ACTIVITY, \ + .modified = 1, \ + .channel2 = _chan2, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \ + .scan_index = -1, /* No buffer support */ \ + .event_spec = &bma400_activity_event, \ + .num_event_specs = 1, \ +} + static const struct iio_chan_spec bma400_channels[] = { BMA400_ACC_CHANNEL(0, X), BMA400_ACC_CHANNEL(1, Y), @@ -220,6 +243,9 @@ static const struct iio_chan_spec bma400_channels[] = { .event_spec = &bma400_step_detect_event, .num_event_specs = 1, }, + BMA400_ACTIVITY_CHANNEL(IIO_MOD_STILL), + BMA400_ACTIVITY_CHANNEL(IIO_MOD_WALKING), + BMA400_ACTIVITY_CHANNEL(IIO_MOD_RUNNING), IIO_CHAN_SOFT_TIMESTAMP(4), }; @@ -626,6 +652,20 @@ static void bma400_power_disable(void *data_ptr) ERR_PTR(ret)); } +static enum iio_modifier bma400_act_to_mod(enum bma400_activity activity) +{ + switch (activity) { + case BMA400_STILL: + return IIO_MOD_STILL; + case BMA400_WALKING: + return IIO_MOD_WALKING; + case BMA400_RUNNING: + return IIO_MOD_RUNNING; + default: + return IIO_NO_MOD; + } +} + static int bma400_init(struct bma400_data *data) { unsigned int val; @@ -725,6 +765,7 @@ static int bma400_read_raw(struct iio_dev *indio_dev, struct bma400_data *data = iio_priv(indio_dev); int ret; u8 steps_raw[3]; + unsigned int activity; switch (mask) { case IIO_CHAN_INFO_PROCESSED: @@ -743,6 +784,23 @@ static int bma400_read_raw(struct iio_dev *indio_dev, return ret; *val = get_unaligned_le24(steps_raw); return IIO_VAL_INT; + case IIO_ACTIVITY: + mutex_lock(&data->mutex); + ret = regmap_read(data->regmap, BMA400_STEP_STAT_REG, + &activity); + mutex_unlock(&data->mutex); + if (ret) + return ret; + /* + * The device does not support confidence value levels, + * so we will always have 100% for current activity and + * 0% for the others. + */ + if (chan->channel2 == bma400_act_to_mod(activity)) + *val = 100; + else + *val = 0; + return IIO_VAL_INT; default: return -EINVAL; } @@ -898,6 +956,8 @@ static int bma400_read_event_config(struct iio_dev *indio_dev, switch (chan->type) { case IIO_STEPS: return data->step_event_en; + case IIO_ACTIVITY: + return data->activity_event_en; default: return -EINVAL; } @@ -937,6 +997,32 @@ static int bma400_write_event_config(struct iio_dev *indio_dev, return ret; data->step_event_en = state; return 0; + case IIO_ACTIVITY: + if (!data->step_event_en) { + mutex_lock(&data->mutex); + ret = regmap_update_bits(data->regmap, + BMA400_INT_CONFIG1_REG, + BMA400_STEP_INT_MSK, + FIELD_PREP(BMA400_STEP_INT_MSK, + 1)); + if (ret) { + mutex_unlock(&data->mutex); + return ret; + } + data->steps_enabled = 1; + + ret = regmap_update_bits(data->regmap, + BMA400_INT12_MAP_REG, + BMA400_STEP_INT_MSK, + FIELD_PREP(BMA400_STEP_INT_MSK, + 1)); + mutex_unlock(&data->mutex); + if (ret) + return ret; + data->step_event_en = 1; + } + data->activity_event_en = state; + return 0; default: return -EINVAL; } @@ -1015,6 +1101,7 @@ static irqreturn_t bma400_interrupt(int irq, void *private) s64 timestamp = iio_get_time_ns(indio_dev); int ret; __le16 status; + unsigned int act; mutex_lock(&data->mutex); ret = regmap_bulk_read(data->regmap, BMA400_INT_STAT0_REG, &status, @@ -1029,6 +1116,23 @@ static irqreturn_t bma400_interrupt(int irq, void *private) IIO_EV_DIR_NONE, IIO_EV_TYPE_CHANGE, 0, 0, 0), timestamp); + + if (data->activity_event_en) { + mutex_lock(&data->mutex); + ret = regmap_read(data->regmap, BMA400_STEP_STAT_REG, + &act); + mutex_unlock(&data->mutex); + if (ret) + return IRQ_NONE; + + iio_push_event(indio_dev, + IIO_EVENT_CODE(IIO_ACTIVITY, 0, + bma400_act_to_mod(act), + IIO_EV_DIR_NONE, + IIO_EV_TYPE_CHANGE, 0, + 0, 0), + timestamp); + } return IRQ_HANDLED; } From patchwork Mon Apr 11 20:31:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagath Jog J X-Patchwork-Id: 12809620 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2406C433EF for ; Mon, 11 Apr 2022 20:32:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233215AbiDKUeY (ORCPT ); Mon, 11 Apr 2022 16:34:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349903AbiDKUeU (ORCPT ); Mon, 11 Apr 2022 16:34:20 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 867863630A; Mon, 11 Apr 2022 13:31:57 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id 12so3067810pll.12; Mon, 11 Apr 2022 13:31:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cHf/BMrM4IDiFNkGBeStENyE+6vkeKtpmqEY0HT77/Y=; b=bjhBwoGvNFC2ffjYE/8W6ufUnPXB6zBcdL02HYrVqASINmgA1NgHBt8O1kXQ5Flkxk qY86BXxQLh6kw+oY5lEKlqxmA9AhukWPntUjLNOoFBur9B7fcNUnF+2GU5TaoHwsCA28 UuyKYkGRXuBaqGBmIqlOnFt59/w0XRwzgONvUOUuy9gefGi5w0b36XMa+4LdZ9lD50HL muV5BhYzx3MwjHYQP6//AAaoyuynrO+xHe9vkhtjz3lPFSAS9NKrzbdrYtPljhlKbkNJ XGCyih0XMOhQs4Pe2NxzMQ57jnbCYsrZAVIEoO2qW+nIIZtUMm6RJpoGSiP+ECnhnLc/ YChQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cHf/BMrM4IDiFNkGBeStENyE+6vkeKtpmqEY0HT77/Y=; b=DForRaELr7Ie/TvIF+VxsoMFR054dIL/D6WvJbXjVKAmIHVD4EnyvJq46HoZs7v5eT xO9kYAlWA2b6nZ8y6VqG9UTDWQSPcP7mwXQH4Ff/8Ys/nXXQ6djSt8xSBt+KSP1EtxKL sI6bOY6g7lL/0VLTKL9nQowSttZd05zCBG1P/3U8nobovG9Q0U08IH+cNYh9lQBCdaNE nZCFGE7lbzR3JGIcDwTJxRvbnXRY6sLcI1QKenEg5NFUUZVXy2j5q/Wcltwm8DV9vJmq 3Oa8XCsJpvKXzYxnPyIjJuA3LxgSsKhBFkSITHnXVUYC0o3lcvNUL4tgqqo+nPETtpPa /7Lw== X-Gm-Message-State: AOAM533Oe5/HWAIBhMdaDSKltxqkXpiS+kjrA3fQuJrN3Voex1GhlRO0 JGioMymy4aVsRcJeG8DGaaY= X-Google-Smtp-Source: ABdhPJwvED6ZmidCJkIUMw/pCTbM9oQ/KYGik9Nf2kyHDbPtCWCGDQF4oTj/79aQFNqOwr+9+Z2niQ== X-Received: by 2002:a17:902:ea0a:b0:157:31:e828 with SMTP id s10-20020a170902ea0a00b001570031e828mr24751037plg.19.1649709116623; Mon, 11 Apr 2022 13:31:56 -0700 (PDT) Received: from localhost.localdomain ([27.7.99.112]) by smtp.gmail.com with ESMTPSA id z15-20020a056a001d8f00b004fda37855ddsm34069828pfw.168.2022.04.11.13.31.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 13:31:56 -0700 (PDT) From: Jagath Jog J To: dan@dlrobertson.com, jic23@kernel.org, andy.shevchenko@gmail.com Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 8/9] iio: accel: bma400: Add debugfs register access support Date: Tue, 12 Apr 2022 02:01:32 +0530 Message-Id: <20220411203133.19929-9-jagathjog1996@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220411203133.19929-1-jagathjog1996@gmail.com> References: <20220411203133.19929-1-jagathjog1996@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add support to read/write byte from/to bma400 device from the userspace using debugfs interface. Signed-off-by: Jagath Jog J --- drivers/iio/accel/bma400_core.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/iio/accel/bma400_core.c b/drivers/iio/accel/bma400_core.c index 69d2caa4ed18..b6c79cfabaa4 100644 --- a/drivers/iio/accel/bma400_core.c +++ b/drivers/iio/accel/bma400_core.c @@ -1028,6 +1028,23 @@ static int bma400_write_event_config(struct iio_dev *indio_dev, } } +static int bma400_debugfs_reg_access(struct iio_dev *indio_dev, + unsigned int reg, + unsigned int writeval, + unsigned int *readval) +{ + struct bma400_data *data = iio_priv(indio_dev); + int ret; + + mutex_lock(&data->mutex); + if (readval) + ret = regmap_read(data->regmap, reg, readval); + else + ret = regmap_write(data->regmap, reg, writeval); + mutex_unlock(&data->mutex); + return ret; +} + static int bma400_data_rdy_trigger_set_state(struct iio_trigger *trig, bool state) { @@ -1058,6 +1075,7 @@ static const struct iio_info bma400_info = { .write_raw_get_fmt = bma400_write_raw_get_fmt, .read_event_config = bma400_read_event_config, .write_event_config = bma400_write_event_config, + .debugfs_reg_access = bma400_debugfs_reg_access, }; static const struct iio_trigger_ops bma400_trigger_ops = { From patchwork Mon Apr 11 20:31:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagath Jog J X-Patchwork-Id: 12809621 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D502DC433F5 for ; Mon, 11 Apr 2022 20:32:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349965AbiDKUec (ORCPT ); Mon, 11 Apr 2022 16:34:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349919AbiDKUeW (ORCPT ); Mon, 11 Apr 2022 16:34:22 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDDE535DF3; Mon, 11 Apr 2022 13:31:59 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id c23so14910560plo.0; Mon, 11 Apr 2022 13:31:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=TNR6m2F5BA/dkBi52W/20O0Hx4jKoOJlRkDptGmhUvM=; b=NIZObOZzcgdc5Sz2SVnkSusjvAjS/KQpT+CQsBfpemxwOKldl0+WhuXX1OOuc2XCOG r5ns5VGGt80MdeWs4I5GpbyYSjHJh3Fydbhb556BK6WSlY2phfuVZoWO3xEbgPZkXTcV OdTuXjOZjq9aeAGAYTn1SQ77kAhSJC1vul3xu1j4xJlsrXY3ncecnUy62BvT9FYyrOV9 V13CB58zxF3rEzJK67K6ifBnEOjaA7pStvwGB5xJlzb2QS+d3pcbvfGOCpZ3P3bDRa7n IclM9o1HqJ0Z0/yeVzjUyOc0OUx40Rp5HbsD2PjbDcfEF4eyqUrf9QzJ09hql470lz4/ AKVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=TNR6m2F5BA/dkBi52W/20O0Hx4jKoOJlRkDptGmhUvM=; b=kC8ApzIc/eHXQ7SA/7oAjQ8VfbMfosYay8YMbH6vJLHtCIyjNP/Lyng0WHAIPv6cxc WBcgxMyAgTTs5mSRbiW2t1g+8bVNJpcAqvE0LeTOIs8qZrN8KgwRj8OBmD4E1YeEtEaf Qw1A4nPPW+RqdCoNulXK5CyA66ilaswE1lKXO/hFbPQdmOM+khOPGYh252d4MCf6qp/w JmRcuXgTZU+WVNWf+ogeAXvDDkmub9KlYPySuvVhsr2HLApDPeqpik/YQiYec73k9Vby 0K28oSZP8XkPCh66l4693ILwaD0VS6jRYaXj08Fo3xGCVuPLe0KR0ax7hCnQgOtWQliD TVyg== X-Gm-Message-State: AOAM533zvlYls3M+RyYPqQkvLYvMs8XNKLs4o3sSjJKn5eOJ6mKN/ASv yyrRCXL6KHaSwIn8iltXIkwoCLH+ZHo= X-Google-Smtp-Source: ABdhPJyWwZMa6oNsQKkhJPysfDUiaKpCsh8QqxbGdOoN6U3QXGjQxdWaqSdtZWTyY4HoLYeigsWXLw== X-Received: by 2002:a17:90b:1b4e:b0:1c6:fff4:34dc with SMTP id nv14-20020a17090b1b4e00b001c6fff434dcmr1052267pjb.76.1649709119253; Mon, 11 Apr 2022 13:31:59 -0700 (PDT) Received: from localhost.localdomain ([27.7.99.112]) by smtp.gmail.com with ESMTPSA id z15-20020a056a001d8f00b004fda37855ddsm34069828pfw.168.2022.04.11.13.31.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 13:31:58 -0700 (PDT) From: Jagath Jog J To: dan@dlrobertson.com, jic23@kernel.org, andy.shevchenko@gmail.com Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 9/9] iio: accel: bma400: Add support for activity and inactivity events Date: Tue, 12 Apr 2022 02:01:33 +0530 Message-Id: <20220411203133.19929-10-jagathjog1996@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220411203133.19929-1-jagathjog1996@gmail.com> References: <20220411203133.19929-1-jagathjog1996@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add support for activity and inactivity events for all axis based on the threshold, duration and hysteresis value set from the userspace. INT1 pin is used to interrupt and event is pushed to userspace. Signed-off-by: Jagath Jog J Reported-by: kernel test robot Reported-by: kernel test robot Reported-by: Dan Carpenter Reported-by: kernel test robot --- drivers/iio/accel/bma400.h | 11 ++ drivers/iio/accel/bma400_core.c | 229 ++++++++++++++++++++++++++++++++ 2 files changed, 240 insertions(+) diff --git a/drivers/iio/accel/bma400.h b/drivers/iio/accel/bma400.h index bc4641279be3..cbf8035c817e 100644 --- a/drivers/iio/accel/bma400.h +++ b/drivers/iio/accel/bma400.h @@ -93,6 +93,17 @@ #define BMA400_ACC_ODR_MIN_WHOLE_HZ 25 #define BMA400_ACC_ODR_MIN_HZ 12 +/* Generic interrupts register */ +#define BMA400_GEN1INT_CONFIG0 0x3f +#define BMA400_GEN2INT_CONFIG0 0x4A +#define BMA400_GEN_CONFIG1_OFF 0x01 +#define BMA400_GEN_CONFIG2_OFF 0x02 +#define BMA400_GEN_CONFIG3_OFF 0x03 +#define BMA400_GEN_CONFIG31_OFF 0x04 +#define BMA400_INT_GEN1_MSK BIT(2) +#define BMA400_INT_GEN2_MSK BIT(3) +#define BMA400_GEN_HYST_MSK GENMASK(1, 0) + /* * BMA400_SCALE_MIN macro value represents m/s^2 for 1 LSB before * converting to micro values for +-2g range. diff --git a/drivers/iio/accel/bma400_core.c b/drivers/iio/accel/bma400_core.c index b6c79cfabaa4..226a5f63d1a6 100644 --- a/drivers/iio/accel/bma400_core.c +++ b/drivers/iio/accel/bma400_core.c @@ -79,6 +79,7 @@ struct bma400_data { int steps_enabled; bool step_event_en; bool activity_event_en; + u8 generic_event_en; /* Correct time stamp alignment */ struct { __le16 buff[3]; @@ -188,6 +189,25 @@ static const struct iio_event_spec bma400_activity_event = { .mask_shared_by_type = BIT(IIO_EV_INFO_ENABLE), }; +static const struct iio_event_spec bma400_accel_event[] = { + { + .type = IIO_EV_TYPE_MAG, + .dir = IIO_EV_DIR_FALLING, + .mask_shared_by_type = BIT(IIO_EV_INFO_VALUE) | + BIT(IIO_EV_INFO_PERIOD) | + BIT(IIO_EV_INFO_HYSTERESIS) | + BIT(IIO_EV_INFO_ENABLE), + }, + { + .type = IIO_EV_TYPE_MAG, + .dir = IIO_EV_DIR_RISING, + .mask_shared_by_type = BIT(IIO_EV_INFO_VALUE) | + BIT(IIO_EV_INFO_PERIOD) | + BIT(IIO_EV_INFO_HYSTERESIS) | + BIT(IIO_EV_INFO_ENABLE), + }, +}; + #define BMA400_ACC_CHANNEL(_index, _axis) { \ .type = IIO_ACCEL, \ .modified = 1, \ @@ -207,6 +227,8 @@ static const struct iio_event_spec bma400_activity_event = { .storagebits = 16, \ .endianness = IIO_LE, \ }, \ + .event_spec = bma400_accel_event, \ + .num_event_specs = ARRAY_SIZE(bma400_accel_event) \ } #define BMA400_ACTIVITY_CHANNEL(_chan2) { \ @@ -954,6 +976,17 @@ static int bma400_read_event_config(struct iio_dev *indio_dev, struct bma400_data *data = iio_priv(indio_dev); switch (chan->type) { + case IIO_ACCEL: + switch (dir) { + case IIO_EV_DIR_RISING: + return FIELD_GET(BMA400_INT_GEN1_MSK, + data->generic_event_en); + case IIO_EV_DIR_FALLING: + return FIELD_GET(BMA400_INT_GEN2_MSK, + data->generic_event_en); + default: + return -EINVAL; + } case IIO_STEPS: return data->step_event_en; case IIO_ACTIVITY: @@ -970,8 +1003,74 @@ static int bma400_write_event_config(struct iio_dev *indio_dev, { int ret; struct bma400_data *data = iio_priv(indio_dev); + int reg, msk, value, field_value; switch (chan->type) { + case IIO_ACCEL: + switch (dir) { + case IIO_EV_DIR_RISING: + reg = BMA400_GEN1INT_CONFIG0; + msk = BMA400_INT_GEN1_MSK; + value = 2; + field_value = FIELD_PREP(BMA400_INT_GEN1_MSK, state); + break; + case IIO_EV_DIR_FALLING: + reg = BMA400_GEN2INT_CONFIG0; + msk = BMA400_INT_GEN2_MSK; + value = 0; + field_value = FIELD_PREP(BMA400_INT_GEN2_MSK, state); + break; + default: + return -EINVAL; + } + + mutex_lock(&data->mutex); + /* Enabling all axis for interrupt evaluation */ + ret = regmap_write(data->regmap, reg, 0xF8); + if (ret) { + mutex_unlock(&data->mutex); + return ret; + } + + /* OR combination of all axis for interrupt evaluation */ + ret = regmap_write(data->regmap, reg + BMA400_GEN_CONFIG1_OFF, + value); + if (ret) { + mutex_unlock(&data->mutex); + return ret; + } + + /* Initial value to avoid interrupts while enabling*/ + ret = regmap_write(data->regmap, reg + BMA400_GEN_CONFIG2_OFF, + 0x0A); + if (ret) { + mutex_unlock(&data->mutex); + return ret; + } + + /* Initial duration value to avoid interrupts while enabling*/ + ret = regmap_write(data->regmap, reg + BMA400_GEN_CONFIG31_OFF, + 0x0F); + if (ret) { + mutex_unlock(&data->mutex); + return ret; + } + + ret = regmap_update_bits(data->regmap, BMA400_INT1_MAP_REG, + msk, field_value); + if (ret) { + mutex_unlock(&data->mutex); + return ret; + } + + ret = regmap_update_bits(data->regmap, BMA400_INT_CONFIG0_REG, + msk, field_value); + mutex_unlock(&data->mutex); + if (ret) + return ret; + + set_mask_bits(&data->generic_event_en, msk, field_value); + return 0; case IIO_STEPS: mutex_lock(&data->mutex); if (!data->steps_enabled) { @@ -1028,6 +1127,118 @@ static int bma400_write_event_config(struct iio_dev *indio_dev, } } +static int get_gen_config_reg(enum iio_event_direction dir) +{ + switch (dir) { + case IIO_EV_DIR_FALLING: + return BMA400_GEN2INT_CONFIG0; + case IIO_EV_DIR_RISING: + return BMA400_GEN1INT_CONFIG0; + default: + return -EINVAL; + } +} + +static int bma400_read_event_value(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + enum iio_event_info info, + int *val, int *val2) +{ + struct bma400_data *data = iio_priv(indio_dev); + int ret; + u8 reg, duration[2]; + + reg = get_gen_config_reg(dir); + if (reg < 0) + return -EINVAL; + + *val2 = 0; + switch (info) { + case IIO_EV_INFO_VALUE: + mutex_lock(&data->mutex); + ret = regmap_read(data->regmap, reg + BMA400_GEN_CONFIG2_OFF, + val); + mutex_unlock(&data->mutex); + if (ret) + return ret; + return IIO_VAL_INT; + case IIO_EV_INFO_PERIOD: + mutex_lock(&data->mutex); + ret = regmap_bulk_read(data->regmap, + reg + BMA400_GEN_CONFIG3_OFF, + duration, sizeof(duration)); + mutex_unlock(&data->mutex); + if (ret) + return ret; + *val = get_unaligned_be16(duration); + return IIO_VAL_INT; + case IIO_EV_INFO_HYSTERESIS: + mutex_lock(&data->mutex); + ret = regmap_read(data->regmap, reg, val); + mutex_unlock(&data->mutex); + if (ret) + return ret; + *val = FIELD_GET(BMA400_GEN_HYST_MSK, *val); + return IIO_VAL_INT; + default: + return -EINVAL; + } +} + +static int bma400_write_event_value(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + enum iio_event_info info, + int val, int val2) +{ + struct bma400_data *data = iio_priv(indio_dev); + int ret; + u8 reg, duration[2]; + + reg = get_gen_config_reg(dir); + if (reg < 0) + return -EINVAL; + + switch (info) { + case IIO_EV_INFO_VALUE: + if (val < 1 || val > 255) + return -EINVAL; + + mutex_lock(&data->mutex); + ret = regmap_write(data->regmap, reg + BMA400_GEN_CONFIG2_OFF, + val); + mutex_unlock(&data->mutex); + return ret; + case IIO_EV_INFO_PERIOD: + if (val < 1 || val > 65535) + return -EINVAL; + + put_unaligned_be16(val, duration); + + mutex_lock(&data->mutex); + ret = regmap_bulk_write(data->regmap, + reg + BMA400_GEN_CONFIG3_OFF, + duration, sizeof(duration)); + mutex_unlock(&data->mutex); + return ret; + case IIO_EV_INFO_HYSTERESIS: + if (val < 0 || val > 3) + return -EINVAL; + + mutex_lock(&data->mutex); + ret = regmap_update_bits(data->regmap, reg, + BMA400_GEN_HYST_MSK, + FIELD_PREP(BMA400_GEN_HYST_MSK, val)); + mutex_unlock(&data->mutex); + return ret; + default: + return -EINVAL; + } +} + static int bma400_debugfs_reg_access(struct iio_dev *indio_dev, unsigned int reg, unsigned int writeval, @@ -1076,6 +1287,8 @@ static const struct iio_info bma400_info = { .read_event_config = bma400_read_event_config, .write_event_config = bma400_write_event_config, .debugfs_reg_access = bma400_debugfs_reg_access, + .write_event_value = bma400_write_event_value, + .read_event_value = bma400_read_event_value, }; static const struct iio_trigger_ops bma400_trigger_ops = { @@ -1120,6 +1333,7 @@ static irqreturn_t bma400_interrupt(int irq, void *private) int ret; __le16 status; unsigned int act; + unsigned int ev_dir = IIO_EV_DIR_NONE; mutex_lock(&data->mutex); ret = regmap_bulk_read(data->regmap, BMA400_INT_STAT0_REG, &status, @@ -1128,6 +1342,21 @@ static irqreturn_t bma400_interrupt(int irq, void *private) if (ret) return IRQ_NONE; + if (FIELD_GET(BMA400_INT_GEN1_MSK, le16_to_cpu(status))) + ev_dir = IIO_EV_DIR_RISING; + + if (FIELD_GET(BMA400_INT_GEN2_MSK, le16_to_cpu(status))) + ev_dir = IIO_EV_DIR_FALLING; + + if (ev_dir != IIO_EV_DIR_NONE) { + iio_push_event(indio_dev, + IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, + IIO_MOD_X_OR_Y_OR_Z, + IIO_EV_TYPE_MAG, ev_dir), + timestamp); + return IRQ_HANDLED; + } + if (FIELD_GET(BMA400_STEP_STAT_MASK, le16_to_cpu(status))) { iio_push_event(indio_dev, IIO_EVENT_CODE(IIO_STEPS, 0, IIO_NO_MOD,