From patchwork Sat Mar 19 18:10:19 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: 12786296 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 136FCC433F5 for ; Sat, 19 Mar 2022 18:10:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242378AbiCSSLx (ORCPT ); Sat, 19 Mar 2022 14:11:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231363AbiCSSLw (ORCPT ); Sat, 19 Mar 2022 14:11:52 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 609DE8FE5F; Sat, 19 Mar 2022 11:10:31 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id d18so9508436plr.6; Sat, 19 Mar 2022 11:10:31 -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=tuna39nHlj/vJbNH47sbVQP5PReNvCKKw5S8gfoddFQ=; b=CXBwCDALT/4bOPF2ycOxpMaoA+ppe7kuzXRrYGD9Cg+/F8Vl/Z7aKCFxg97202Igxs guDoBAVL7qA8hT2ExSsWHtbgfxUHF6SJpseXy//XBV3/FLLV3N9tZwhBMHu81y4SOqRi z1LsOz1cX+iyuAWEAq4v8PDgPxFxpk70hsYNkO95V0FmzeXhy/wJ693Id5pURjkLtfcU KukLZrXthvRcRqgBxrCtoG19foXxSgPZPCDJu4b+OL8AKPVNO/zMhfqIB53lf1dxHWf/ AKRekOzRDudw6650Ytx6LHuKFHUqvcRT2mxeNASonzQ/ft3bnfc3jJqHrLkcka6nqO3F 5O/g== 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=tuna39nHlj/vJbNH47sbVQP5PReNvCKKw5S8gfoddFQ=; b=I/3iO/9sehzojuNDH39daOph2oF7z5QJPWD1KzzpyAeTPKUlNhdXoBIZEatImVOBcK X5rgl3ZVTmEbdMYD7DPmTOrCCv3k1Zrpj6/7pP2KpVjxQ5HDkJoBDQUpSJ+fkF+SvD1P qHE+/pDieDc4jcU0383VBIhAOYvnsb8nN4vqjzLgzl1BIKz0w/6BKbLjSeq/GKJtfZ2r uUV1LpF+qH8gouBWyoM6KAQNbjFvOaqaw8dvei/1FkW4BajIawKBbZZz3gvSd+3xlimn h50pJRQ86Oqed+qBp5I72Ciexi45H2ZHxfvGDoWlKF5QV7ku3muLlzFV4ZzZ90116oG4 ie+g== X-Gm-Message-State: AOAM5300KzLnc/3T05BqVOHlw/3JvFYh64xJ1KPScJUrV2AyVSMqIWGX vykWQbGFaQciX+kQij18uFeyra/O+tlcmg== X-Google-Smtp-Source: ABdhPJxjpOMPrMpN5FtjjYqgRINehth2c6JNWOGrZb2VQgv4To35+dtG4NT0yjvwWjTB9nTkWTJudw== X-Received: by 2002:a17:90a:4604:b0:1bc:8bdd:4a63 with SMTP id w4-20020a17090a460400b001bc8bdd4a63mr28315285pjg.147.1647713430840; Sat, 19 Mar 2022 11:10:30 -0700 (PDT) Received: from localhost.localdomain ([115.99.145.231]) by smtp.gmail.com with ESMTPSA id nu4-20020a17090b1b0400b001bf497a9324sm16413981pjb.31.2022.03.19.11.10.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Mar 2022 11:10:30 -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 v1 1/5] iio: accel: bma400: conversion to device-managed function Date: Sat, 19 Mar 2022 23:40:19 +0530 Message-Id: <20220319181023.8090-2-jagathjog1996@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220319181023.8090-1-jagathjog1996@gmail.com> References: <20220319181023.8090-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, now disabling the regulator and putting bma400 to power down via a devm_add_action_or_reset() hook. 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 --- drivers/iio/accel/bma400.h | 2 -- drivers/iio/accel/bma400_core.c | 39 ++++++++++++++------------------- drivers/iio/accel/bma400_i2c.c | 8 ------- drivers/iio/accel/bma400_spi.c | 8 ------- 4 files changed, 17 insertions(+), 40 deletions(-) diff --git a/drivers/iio/accel/bma400.h b/drivers/iio/accel/bma400.h index c4c8d74155c2..e938da5a57b4 100644 --- a/drivers/iio/accel/bma400.h +++ b/drivers/iio/accel/bma400.h @@ -94,6 +94,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 fd2647b728d3..dcc7549c7a0e 100644 --- a/drivers/iio/accel/bma400_core.c +++ b/drivers/iio/accel/bma400_core.c @@ -793,6 +793,19 @@ static const struct iio_info bma400_info = { .write_raw_get_fmt = bma400_write_raw_get_fmt, }; +static void bma400_disable(void *data_ptr) +{ + struct bma400_data *data = data_ptr; + int ret; + + ret = bma400_set_power_mode(data, POWER_MODE_SLEEP); + if (ret) + dev_warn(data->dev, "Failed to put device into sleep mode (%pe)\n", + ERR_PTR(ret)); + + regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators); +} + int bma400_probe(struct device *dev, struct regmap *regmap, const char *name) { struct iio_dev *indio_dev; @@ -822,31 +835,13 @@ 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); -} -EXPORT_SYMBOL(bma400_probe); - -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); - + ret = devm_add_action_or_reset(dev, bma400_disable, data); 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); + return ret; - iio_device_unregister(indio_dev); + return devm_iio_device_register(dev, indio_dev); } -EXPORT_SYMBOL(bma400_remove); +EXPORT_SYMBOL(bma400_probe); MODULE_AUTHOR("Dan Robertson "); MODULE_DESCRIPTION("Bosch BMA400 triaxial acceleration sensor core"); diff --git a/drivers/iio/accel/bma400_i2c.c b/drivers/iio/accel/bma400_i2c.c index f50df5310beb..56da06537562 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 9f622e37477b..96dc9c215401 100644 --- a/drivers/iio/accel/bma400_spi.c +++ b/drivers/iio/accel/bma400_spi.c @@ -87,13 +87,6 @@ static int bma400_spi_probe(struct spi_device *spi) return bma400_probe(&spi->dev, regmap, id->name); } -static int bma400_spi_remove(struct spi_device *spi) -{ - bma400_remove(&spi->dev); - - return 0; -} - static const struct spi_device_id bma400_spi_ids[] = { { "bma400", 0 }, { } @@ -112,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 Sat Mar 19 18:10:20 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: 12786297 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 24D7DC433EF for ; Sat, 19 Mar 2022 18:10:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231363AbiCSSLz (ORCPT ); Sat, 19 Mar 2022 14:11:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243768AbiCSSLy (ORCPT ); Sat, 19 Mar 2022 14:11:54 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B84E8FE60; Sat, 19 Mar 2022 11:10:33 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id gb19so9933036pjb.1; Sat, 19 Mar 2022 11:10:33 -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=4eyuItiM/A2/gLReN5fqpzJcJZBVqcz5QpX+I81RvDQ=; b=ITbEe0spxcop3l4lw8f2wpC83b6CpC/c3HCA2ypD6PvqkKpXl1wnaGJ1EmBSk8Py/D udHlBKrBmHneKEIPQQweHCVDaUtOIFR3EnjaGZ5qXMPvMVLG6hGuzM/GHbBXFZosnYb0 2xe9Mh73bEN5AwPZNZJYQrAb3ryrNG0IRtuDU9W2T8Qq80fosOytRN46rDxtKt8uFErN W5qCFYbDnXNcyACG0UFpmTWtH2zroHLvpYF+lVmrk7qngNZ/Zn0tUi+hFgN5+K44SF1G LkpezG8ZVBj5Y5xi/lXqck5ZcsJSxtQcoGevlLLFzhWpRBwltOj33qKYpy2yOf6cSmat R4VA== 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=4eyuItiM/A2/gLReN5fqpzJcJZBVqcz5QpX+I81RvDQ=; b=fkAEYzpVYdtP4RVa594qG/CbxY1zf49dFbnKQj/aU8RVlfSX0XyGI07g24+8VhIqvJ hcZRVVJI2bpxYL7cGXgGNDRHmHoMJUTIbV0WTc9FrO7NiRyJCcE8DJfBumm+yDcUhOku cx7jkHRjmvICtBdXhmGJO7gK5EVczemlYW1IKj9L2RpASw1MeSWq2BR9AC332Zp6e8Ko IBxdAn36e6XmistfWL7Toe6AFRmn0SwU/KNDd3K6aP3VnCwXk0WCA6+MQJvFmC9UsKi4 ogyc2pcNIzNIrpAz39CaBlZo/hQKIEagk5XlvJY1DAPd+1pMqMLhdrSzOCVR01+y+5N8 +uWw== X-Gm-Message-State: AOAM532V4papImBSfjHLmz2BTOTOB5B49/Om3+m1JLtOofVsKZOL0rYj TOokwPCpc76y1B22aC+otks= X-Google-Smtp-Source: ABdhPJwMDVrPFtyiIIxYdx1qIJwb064CN2ndi0y6LLkfa6zzQB1QDr1FPevzboMZYjw+4eotQcuzcA== X-Received: by 2002:a17:902:e78f:b0:153:29c8:5395 with SMTP id cp15-20020a170902e78f00b0015329c85395mr5285082plb.55.1647713433068; Sat, 19 Mar 2022 11:10:33 -0700 (PDT) Received: from localhost.localdomain ([115.99.145.231]) by smtp.gmail.com with ESMTPSA id nu4-20020a17090b1b0400b001bf497a9324sm16413981pjb.31.2022.03.19.11.10.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Mar 2022 11:10:32 -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 v1 2/5] iio: accel: bma400: changing scale min and max macro values Date: Sat, 19 Mar 2022 23:40:20 +0530 Message-Id: <20220319181023.8090-3-jagathjog1996@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220319181023.8090-1-jagathjog1996@gmail.com> References: <20220319181023.8090-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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iio/accel/bma400.h b/drivers/iio/accel/bma400.h index e938da5a57b4..cfc2c9bacec8 100644 --- a/drivers/iio/accel/bma400.h +++ b/drivers/iio/accel/bma400.h @@ -83,8 +83,8 @@ #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 +#define BMA400_SCALE_MIN 9583 +#define BMA400_SCALE_MAX 76669 #define BMA400_NUM_REGULATORS 2 #define BMA400_VDD_REGULATOR 0 From patchwork Sat Mar 19 18:10:21 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: 12786298 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 CE55AC433EF for ; Sat, 19 Mar 2022 18:10:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243768AbiCSSL7 (ORCPT ); Sat, 19 Mar 2022 14:11:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243809AbiCSSL5 (ORCPT ); Sat, 19 Mar 2022 14:11:57 -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 089D590243; Sat, 19 Mar 2022 11:10:35 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id b8so9899185pjb.4; Sat, 19 Mar 2022 11:10:35 -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=EIsVtfI4oxwH1Tgw3dc0Q57CPWfQ9tcC+DLmFSdruZg=; b=RIu5Rv7Yi0vYiuQBc4LK/sidMrC7aUGzby9B53autqXQxjIPJo4seAY8ch3Vi883Gd 9PIcWVriLE9IYLV8P10HabG73m+FEXPeoq/tHP7NMOY9LmGg5X8hv6tC2a4R/UtZbBPI KFtHZq2416vPdFQ9M9ma7Lw8mHy6KLfGSN0H1WWzfI6TaQee/a4nmNqcmLNTeT4KYzb9 4tkev0FmYpxQ8rFfKVioPu36bBu1OWdJCYrJhvQm1CV/kBRlLB5XsSDQOjR5X1XkZDhV 4o8krHqLTSLlLkfRyE9yc5aNC7fo98ToPRpG9oyPT5c76q1tqeAaBOET7AeIyvAWyiuD YFIA== 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=EIsVtfI4oxwH1Tgw3dc0Q57CPWfQ9tcC+DLmFSdruZg=; b=00PntLjgK5Xiv8rjluLkyE4z3FsnJO3a9/JNOrSNlqk4K03OzBkD5hpvXvzpgHZ6uk 3TQLK+LS8+6Ak5nhwZJgr2VPfAnjQ1/KyQDfx5hkfwTc1rQHpuuzFugzElbnPAT9mfv3 8wnOmlEsLnIBttIxNaJAIRSBsjMWyIQVieBwBUPUIoT9rmXJujNwwyaUitbCMJ0qOcvC HSzqKloaq/UkWa2utkkGlAHOEyiPv/7mPUvXA/zQyE8ioMd7t9Jn54CP8IYdwB/pLFa5 HUWdmQ82Dc+asv3+DymKXKFRbcFc5jOCgfQleRXlU6LdbRjXDp+4xm+qDcUONbyyFZhW eU4Q== X-Gm-Message-State: AOAM5308Px+cgWbYsjNNTeHX6pMKsRM0X9Z9WsKhh9dTStOL1Q86TDcc TKck6XShJexsV489iY2shWs= X-Google-Smtp-Source: ABdhPJyMdNT1ygXJW2dvdFmfNZagT1Hj53j1ktVnWwz83K3VzsFDeRH+SDO+r8CUEd/pQDH/FkvLsw== X-Received: by 2002:a17:90b:1b51:b0:1c6:f880:166d with SMTP id nv17-20020a17090b1b5100b001c6f880166dmr557555pjb.185.1647713435312; Sat, 19 Mar 2022 11:10:35 -0700 (PDT) Received: from localhost.localdomain ([115.99.145.231]) by smtp.gmail.com with ESMTPSA id nu4-20020a17090b1b0400b001bf497a9324sm16413981pjb.31.2022.03.19.11.10.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Mar 2022 11:10:35 -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 v1 3/5] iio: accel: bma400: Add triggered buffer support Date: Sat, 19 Mar 2022 23:40:21 +0530 Message-Id: <20220319181023.8090-4-jagathjog1996@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220319181023.8090-1-jagathjog1996@gmail.com> References: <20220319181023.8090-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 Reported-by: kernel test robot --- drivers/iio/accel/Kconfig | 2 + drivers/iio/accel/bma400.h | 10 +- drivers/iio/accel/bma400_core.c | 161 +++++++++++++++++++++++++++++++- drivers/iio/accel/bma400_i2c.c | 2 +- drivers/iio/accel/bma400_spi.c | 2 +- 5 files changed, 169 insertions(+), 8 deletions(-) diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig index 49587c992a6d..0eb379578e00 100644 --- a/drivers/iio/accel/Kconfig +++ b/drivers/iio/accel/Kconfig @@ -177,6 +177,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 cfc2c9bacec8..b306a5ad513a 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 @@ -92,6 +99,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 dcc7549c7a0e..797403c7dd85 100644 --- a/drivers/iio/accel/bma400_core.c +++ b/drivers/iio/accel/bma400_core.c @@ -20,6 +20,12 @@ #include #include #include +#include +#include +#include +#include +#include +#include #include "bma400.h" @@ -61,6 +67,13 @@ struct bma400_data { struct bma400_sample_freq sample_freq; int oversampling_ratio; int scale; + struct iio_trigger *trig; + /* Correct time stamp alignment */ + struct { + __be16 buff[3]; + u8 temperature; + s64 ts __aligned(8); + } buffer; }; static bool bma400_is_writable_reg(struct device *dev, unsigned int reg) @@ -152,7 +165,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 +177,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) @@ -632,6 +660,11 @@ static int bma400_init(struct bma400_data *data) if (ret) goto err_reg_disable; + /* Configure INT-1 pin to push pull */ + ret = regmap_write(data->regmap, BMA400_INT_IO_CTRL_REG, 0x02); + if (ret) + goto err_reg_disable; + /* * Once the interrupt engine is supported we might use the * data_src_reg, but for now ensure this is set to the @@ -786,6 +819,33 @@ 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; + + ret = regmap_update_bits(data->regmap, BMA400_INT1_MAP_REG, + BMA400_INT_DRDY_MSK, + FIELD_PREP(BMA400_INT_DRDY_MSK, state)); + if (ret) + return ret; + + return 0; +} + +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, @@ -793,6 +853,63 @@ static const struct iio_info bma400_info = { .write_raw_get_fmt = bma400_write_raw_get_fmt, }; +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, 3 * sizeof(__be16)); + mutex_unlock(&data->mutex); + if (ret) + goto out; + + ret = regmap_read(data->regmap, BMA400_TEMP_DATA_REG, &temp); + if (ret) + goto out; + + data->buffer.temperature = temp; + + iio_push_to_buffers_with_timestamp(indio_dev, &data->buffer, + iio_get_time_ns(indio_dev)); + +out: + 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) + goto out; + + if (status & BMA400_INT_DRDY_MSK) + iio_trigger_poll_chained(data->trig); + +out: + return IRQ_HANDLED; +} + static void bma400_disable(void *data_ptr) { struct bma400_data *data = data_ptr; @@ -806,7 +923,8 @@ static void bma400_disable(void *data_ptr) regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators); } -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) { struct iio_dev *indio_dev; struct bma400_data *data; @@ -833,12 +951,45 @@ 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; ret = devm_add_action_or_reset(dev, bma400_disable, data); if (ret) return ret; + 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) { + dev_err(dev, "iio trigger register failed\n"); + return ret; + } + 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) { + dev_err(dev, "request irq %d failed\n", irq); + return ret; + } + } + + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL, + &bma400_trigger_handler, NULL); + if (ret) { + dev_err(dev, "iio triggered buffer setup failed\n"); + return ret; + } return devm_iio_device_register(dev, indio_dev); } EXPORT_SYMBOL(bma400_probe); diff --git a/drivers/iio/accel/bma400_i2c.c b/drivers/iio/accel/bma400_i2c.c index 56da06537562..49b0ae13fdc8 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 96dc9c215401..2957ebc51543 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 Sat Mar 19 18:10:22 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: 12786299 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 CD69FC433F5 for ; Sat, 19 Mar 2022 18:10:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243809AbiCSSMC (ORCPT ); Sat, 19 Mar 2022 14:12:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243791AbiCSSL7 (ORCPT ); Sat, 19 Mar 2022 14:11:59 -0400 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 937978FE60; Sat, 19 Mar 2022 11:10:38 -0700 (PDT) Received: by mail-pg1-x533.google.com with SMTP id o13so7384430pgc.12; Sat, 19 Mar 2022 11:10:38 -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=xAshbbCBTuYOBwYQ431+MMdTrkfc3vce11+ie44orN0=; b=JnMentE4eJhOuVigDnrFALlsPP8Hou2yOZKShv4MPkV3GXbl83FJRE33TV/ywaIzrj mmVUXJ2vPz+KPP1iSxyVGNMUZWmBboPg/zSA4Un++uv6jQIZbUuL39eyxVY+X7wsOX/e EyNC1xhCV7PKjGxvfTPZHnk2KsuqMORYsfjv6rYXB2qHbpMNYE8Ufrsqm6cHSkLNfx54 A4k6eaDtvqN+AP52pLPsQRyRaiG4L8RE7odJE6gh860W1Edo1Z0bfra6cy1AaSWrxvSd uKfJ31zbGm3dZ34jcwfLzpuNHeUFS+khOA5ihicUwnLDXDbGKm+deUcvNOkYWVKuTtTw /a9Q== 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=xAshbbCBTuYOBwYQ431+MMdTrkfc3vce11+ie44orN0=; b=3h0Do/xLmKhq4Gq4xPnWyVwMbAjfZLYWWUXxvliKi8X20YtsrA5Dg0Ir8lsvXV2onL QyyRf4Ch+4IkFkS5KrXrMj2tWgKPS7hHUrBSezMUq+Dt9ccVwvWF19d7wiJzrMX/jm/H ARXUEhA32IrD+kUil1RCVF6Zj/aQ2twfZQYcDuVrG/EAlSLI+5mGd2zGOyqgwmd0l4JG wGBBuwHJCPIUMgDWcmvItUi2LngjjU6MLkwDVVOZwYPvDFhpQ/ckNXzo72WzDA2zbuQc O807bJCFACk4+8FJ5VQVzkGSSGCJf3k0yCNVCNoS6lkkC+My/4USFpgZaIFZ7D0BXMgm XyrQ== X-Gm-Message-State: AOAM532ebVxiY6ABzk7hSnn/yucHzu9+zUBn03U/d1lg1inHKL3qWQ2h wBUJ+xK7RY6ef+a6XzESiX3IcuwtU5wknw== X-Google-Smtp-Source: ABdhPJxuG8XtKSOpvdZ+GqckD15RBfeXvPQ4EcpqjJsNHvcvMX3u+jb16/CMEhgE30lagYb6AXvdJw== X-Received: by 2002:aa7:82d9:0:b0:4fa:2c7f:41e with SMTP id f25-20020aa782d9000000b004fa2c7f041emr15866562pfn.1.1647713438015; Sat, 19 Mar 2022 11:10:38 -0700 (PDT) Received: from localhost.localdomain ([115.99.145.231]) by smtp.gmail.com with ESMTPSA id nu4-20020a17090b1b0400b001bf497a9324sm16413981pjb.31.2022.03.19.11.10.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Mar 2022 11:10:37 -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 v1 4/5] iio: accel: bma400: Add separate channel for step counter Date: Sat, 19 Mar 2022 23:40:22 +0530 Message-Id: <20220319181023.8090-5-jagathjog1996@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220319181023.8090-1-jagathjog1996@gmail.com> References: <20220319181023.8090-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 | 47 ++++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/drivers/iio/accel/bma400.h b/drivers/iio/accel/bma400.h index b306a5ad513a..65bbc80cbb7f 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 797403c7dd85..305643e99eb5 100644 --- a/drivers/iio/accel/bma400_core.c +++ b/drivers/iio/accel/bma400_core.c @@ -68,6 +68,7 @@ struct bma400_data { int oversampling_ratio; int scale; struct iio_trigger *trig; + int steps_enabled; /* Correct time stamp alignment */ struct { __be16 buff[3]; @@ -202,6 +203,13 @@ 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), }; @@ -686,13 +694,28 @@ static int bma400_read_raw(struct iio_dev *indio_dev, { struct bma400_data *data = iio_priv(indio_dev); int ret; + u32 steps_raw; 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_STEPS: + mutex_lock(&data->mutex); + ret = regmap_bulk_read(data->regmap, BMA400_STEP_CNT0_REG, + &steps_raw, 3 * sizeof(u8)); + mutex_unlock(&data->mutex); + if (ret) + return ret; + *val = steps_raw & 0x00FFFFFF; + return IIO_VAL_INT; + case IIO_TEMP: + mutex_lock(&data->mutex); + ret = bma400_get_temp_reg(data, val, val2); + mutex_unlock(&data->mutex); + return ret; + default: + return -EINVAL; + } case IIO_CHAN_INFO_RAW: mutex_lock(&data->mutex); ret = bma400_get_accel_reg(data, chan, val); @@ -733,6 +756,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; } @@ -798,6 +824,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; } @@ -814,6 +851,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 Sat Mar 19 18:10:23 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: 12786300 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 949DAC4332F for ; Sat, 19 Mar 2022 18:10:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243829AbiCSSMC (ORCPT ); Sat, 19 Mar 2022 14:12:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243839AbiCSSMB (ORCPT ); Sat, 19 Mar 2022 14:12:01 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92FE891370; Sat, 19 Mar 2022 11:10:40 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id q5so284402plg.3; Sat, 19 Mar 2022 11:10:40 -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=JwC7vhtQbQObnQh1/kjr7PyY5SjPha1pc6pp5W08Wzc=; b=f8X9UI5vPpI5KvEnKtInL9ihdzjDL/TKiV+XaaUynfbej3n+Ep9wvdwkAZp9r80B6d NBYI+MGJ9nfNlCEe+xK2yhKn0x8zaEnlsDWRzT9pHClrVXHV359KC3U99HGA1G5QacVb qyAdT+t6f43tO/+bCChrO/3h3VS5GQPr9pYMj4wqTMZw/z9H4E1Uy0yVc2f/YxarcdtB r/Z69wrQLySRmyX53rtMRc1E+klIZL3VrPkYLH1zNj4tLTPEBLLIldL/bNICMxzCm+dH G+BM+NXk9YnOCRbl+WbompKhGHDAXxj17mYo9llhQYdL6yyotqufQJCb647v6UZCjPLu ic4w== 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=JwC7vhtQbQObnQh1/kjr7PyY5SjPha1pc6pp5W08Wzc=; b=1uhc3kXsdBs9v3w7c5VwWkDQKDKWundpyeW8PzysXNdKWH7J6/lQF6eht+l6tIzziu 0wrl+p32nivFEZf5HtFuqFwnnQiR/qMkglcQYg07Mp8yr01DaRNMu4Fnxq95CuAWehrS FWUzQ9mTHT7yQ2GNJ3Xc6r0u4dm+TkSq2nIPCZc8cuWRsAs5s16b1Lu5DdDrUtoxjhVM TgzWHxCB8ZHyq7MZXNfoYB1qrt91zPLimuKGq1TX2RrK/URaq8lP7XcW/zLf3ucs6p8n Ucy5kFVkfyMzUWZrfkt5j8BDBR1En+CdjApu78QwCKppLH9rEKkYBDRZNlSGytOD8R2z Yc4w== X-Gm-Message-State: AOAM5300D/WPH7sWgfwPicB9Cgb5Ko4IynNNJx8KoZQsbzbB4ZtFhy5O r+GMlmjrfTeLaMTqTZmRgf8= X-Google-Smtp-Source: ABdhPJz6dHl3t4bQ8bYv8ZaZRf9mtLo7QrIeDaZ/MxGeuGi1Q5Lnb4Aikd04XGALFuQoZR7Hl4CjtA== X-Received: by 2002:a17:902:c745:b0:151:e8fa:629b with SMTP id q5-20020a170902c74500b00151e8fa629bmr5443495plq.90.1647713440059; Sat, 19 Mar 2022 11:10:40 -0700 (PDT) Received: from localhost.localdomain ([115.99.145.231]) by smtp.gmail.com with ESMTPSA id nu4-20020a17090b1b0400b001bf497a9324sm16413981pjb.31.2022.03.19.11.10.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Mar 2022 11:10:39 -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 v1 5/5] iio: accel: bma400: Add step change event Date: Sat, 19 Mar 2022 23:40:23 +0530 Message-Id: <20220319181023.8090-6-jagathjog1996@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220319181023.8090-1-jagathjog1996@gmail.com> References: <20220319181023.8090-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 single step or double 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 | 72 +++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/drivers/iio/accel/bma400.h b/drivers/iio/accel/bma400.h index 65bbc80cbb7f..c833119bb42e 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(1, 0) /* * Read-write configuration registers diff --git a/drivers/iio/accel/bma400_core.c b/drivers/iio/accel/bma400_core.c index 305643e99eb5..79321e41df51 100644 --- a/drivers/iio/accel/bma400_core.c +++ b/drivers/iio/accel/bma400_core.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "bma400.h" @@ -69,6 +70,7 @@ struct bma400_data { int scale; struct iio_trigger *trig; int steps_enabled; + bool step_event_en; /* Correct time stamp alignment */ struct { __be16 buff[3]; @@ -166,6 +168,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, \ @@ -208,6 +216,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), @@ -858,6 +868,59 @@ 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: + switch (type) { + case IIO_EV_TYPE_CHANGE: + return data->steps_enabled; + default: + return -EINVAL; + } + default: + return -EINVAL; + } + return 0; +} + +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: + switch (type) { + case IIO_EV_TYPE_CHANGE: + mutex_lock(&data->mutex); + 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->steps_enabled = state; + return 0; + default: + return -EINVAL; + } + default: + return -EINVAL; + } + return 0; +} + static int bma400_data_rdy_trigger_set_state(struct iio_trigger *trig, bool state) { @@ -890,6 +953,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 = { @@ -945,6 +1010,13 @@ static irqreturn_t bma400_interrupt(int irq, void *private) if (status & BMA400_INT_DRDY_MSK) iio_trigger_poll_chained(data->trig); + if (status & (BMA400_STEP_STAT_MASK << 8)) { + 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), + iio_get_time_ns(indio_dev)); + } out: return IRQ_HANDLED; }