From patchwork Thu Apr 20 20:22:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mehdi Djait X-Patchwork-Id: 675699 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 8A42EC77B73 for ; Thu, 20 Apr 2023 20:22:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232302AbjDTUWm (ORCPT ); Thu, 20 Apr 2023 16:22:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232140AbjDTUWk (ORCPT ); Thu, 20 Apr 2023 16:22:40 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87CE740CE; Thu, 20 Apr 2023 13:22:34 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-94a34a14a54so119062866b.1; Thu, 20 Apr 2023 13:22:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682022153; x=1684614153; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oiDtdcy06XCyhFDJKdSPPZSHud6d0q/+1DEyo40929M=; b=ExFVgNHV5faxTvk8ocYZh8K3qEo6Yz4wp82sGRqTyyP8Yj6pIvGNYbQNq38AaweiqB PxIi9d9YXgnbLyu8HvzPq6MuAmcm5GM1k6/8er5/Gcrag96tKLz+5L87T67QqbGm8lhL 9IE4IbcWB4Cse3eAwT8IAAn0KRfQjxuk8ewpjFk7+zrSlx3l4uXkLAmnuLaxca7UWDc8 Jg0f1UkUS82WhfCnhpyAfVZsC4tdv/e5r90LSI3J3+SlbPxcwEQqYHEvqaoGa7cP06kq Ic3qVcEZGeggYmaUcAt5zhJyY1pwKMHNKLMUABqRDftdxXh2KNutP/J960SszxX6d0ve BI/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682022153; x=1684614153; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oiDtdcy06XCyhFDJKdSPPZSHud6d0q/+1DEyo40929M=; b=G3b99dkTpA3PTy6eA0+BZEo6PmIJ80Ch3m80tUp4FQJxMdvDTrrf1VgstHYwjwiJvL BbqOPh0UV2tYhLyaIlQbsx0x0mYOzSeVf87TsfDTyHKDyZVEhWF96gZ1jAJuDlHCjTPa qsVx2CIOJILW/07sudL07so/sc2gF1mOGbRutDOS7xMMmfl9IScPAhaaRAYcbSMEsrsQ I6dl2CVVjmLe/IsWAAMIPHwoVNkXbq+1OmfQPzPbwQ9cF7LqOIQd9PEUFJXt3wgOgkl8 uWIYZm3RMFyE/VLhk4oNx/wvsNOJCgWf7Yd/Iq6DMgz+wrCPdEr/xscqG5dbKNteQvzo Vp1g== X-Gm-Message-State: AAQBX9fb0yBha6Gw93hebae5m0uSzcl1xpU0g3TdwmSImc888EyQLQjl GmD5FpGFAqqgFbqsguBjAaY= X-Google-Smtp-Source: AKy350bul3Kr3GYKA7stV5VpNwADdmTA/BaTRbnjC9WHwGXk1GJRCpw4CPYawcUqH2R6pI4fej1UBQ== X-Received: by 2002:a17:907:94d1:b0:94f:1c90:cb70 with SMTP id dn17-20020a17090794d100b0094f1c90cb70mr166307ejc.66.1682022152608; Thu, 20 Apr 2023 13:22:32 -0700 (PDT) Received: from carbian.fritz.box ([2a02:8109:aa3f:ead8::d7e8]) by smtp.gmail.com with ESMTPSA id q14-20020a17090676ce00b00932ba722482sm1136881ejn.149.2023.04.20.13.22.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 13:22:32 -0700 (PDT) From: Mehdi Djait To: jic23@kernel.org, mazziesaccount@gmail.com Cc: krzysztof.kozlowski+dt@linaro.org, andriy.shevchenko@linux.intel.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Mehdi Djait Subject: [PATCH v2 1/5] dt-bindings: iio: Add KX132-1211 accelerometer Date: Thu, 20 Apr 2023 22:22:01 +0200 Message-Id: <68466b01b967efbdd1bf2de0747d35f28f94fddb.1682019544.git.mehdi.djait.k@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Extend the kionix,kx022a.yaml file to support the kx132-1211 device Signed-off-by: Mehdi Djait --- v2: - made the device name more specific from "kx132" to "kx132-1211" - removed the output data-rates mentioned and replaced them with "variable output data-rates" .../devicetree/bindings/iio/accel/kionix,kx022a.yaml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/accel/kionix,kx022a.yaml b/Documentation/devicetree/bindings/iio/accel/kionix,kx022a.yaml index 986df1a6ff0a..034b69614416 100644 --- a/Documentation/devicetree/bindings/iio/accel/kionix,kx022a.yaml +++ b/Documentation/devicetree/bindings/iio/accel/kionix,kx022a.yaml @@ -4,19 +4,21 @@ $id: http://devicetree.org/schemas/iio/accel/kionix,kx022a.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: ROHM/Kionix KX022A Accelerometer +title: ROHM/Kionix KX022A and KX132-1211 Accelerometers maintainers: - Matti Vaittinen description: | - KX022A is a 3-axis accelerometer supporting +/- 2G, 4G, 8G and 16G ranges, - output data-rates from 0.78Hz to 1600Hz and a hardware-fifo buffering. - KX022A can be accessed either via I2C or SPI. + KX022A and KX132-1211 are 3-axis accelerometers supporting +/- 2G, 4G, 8G and + 16G ranges, variable output data-rates and a hardware-fifo buffering. + KX022A and KX132-1211 can be accessed either via I2C or SPI. properties: compatible: - const: kionix,kx022a + enum: + - kionix,kx022a + - kionix,kx132-1211 reg: maxItems: 1 From patchwork Thu Apr 20 20:22:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mehdi Djait X-Patchwork-Id: 675698 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 75C8FC7618E for ; Thu, 20 Apr 2023 20:23:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232391AbjDTUXU (ORCPT ); Thu, 20 Apr 2023 16:23:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232341AbjDTUWz (ORCPT ); Thu, 20 Apr 2023 16:22:55 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3105249C7; Thu, 20 Apr 2023 13:22:37 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-5066ce4f490so1229768a12.2; Thu, 20 Apr 2023 13:22:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682022155; x=1684614155; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1CydptxKkm22NUNjkNivJRkww6tHUqJf95wdwrAx7jU=; b=qeZdazHXe++2TOz6hvvgwzCsDzhhk45FRYs2NVtXMhGJ4HQz3A+AAdQuLlhfx+ek0Q zEMT2iZhflT0Q4z/sJUxzhEsmcUF9BzftQGVPF4n4v3pZMZ//P1UnjtOWTdOJB9khQqX Hn9Q500M1/alx6dfRks6T16p5Q/O81egJtUc/YIdkJ67rVvA4Tezoh42D/0FJHxwMBLC RIUjbBuvPhNJxJ3JWUypcla+jkJ+KFZW1x1HzNFi59O/p/5SICqJY2uhnf/0H+DxsAOq gibIKpIXRuXoDfXZaFrekhy+SLs6UMsmPIVhY6+cnMsx3wDB7xl68wdfUGXfuVTucZio Wdrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682022155; x=1684614155; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1CydptxKkm22NUNjkNivJRkww6tHUqJf95wdwrAx7jU=; b=TWW+EQOzdZVLj007/Z/JLi1K6wHoDvzfH2aZd97o9qniiifWJLeOzlHwJhwu5Bv9Pj O18CfLGtozTzl1E6o1TjI5VzXO+oI5K2MmlwCIDyDvq6zTwslaQeLGACLaelmTkd9Txo y35QGPWYhUCJ+66NlCSm3Za0zZEj6XoGnnXJ7/7uL4u31h/vg5DFd+Tj+0PcB5N1xaCi cij7V8XxdjfHHUexaUQiDympweXe3R3ywsxwGOdv8ZGds3Bgg7yOalIjRO20X/tfvh51 uLCFndBqX74hdlpNIjdr+d59BBcP7QQQuREApzOwvg75rYQn1abmq45099PnWNGKdKmj xJfA== X-Gm-Message-State: AAQBX9dG/AOXxmevSP4cP2hfewLuzojxnwRNaib15qVIkuJCCDVjc18h QggSkfaqxJ0GpWoACyf9NP6cD3r88UQ= X-Google-Smtp-Source: AKy350YT5VdPyi9/69jD0KFM51ldl/psBXlTJGPTE7c+rEfzMkolJTUpTUrwk7dvGHI/sHlM4HQz1A== X-Received: by 2002:a05:6402:53:b0:506:be49:243a with SMTP id f19-20020a056402005300b00506be49243amr2931571edu.15.1682022155559; Thu, 20 Apr 2023 13:22:35 -0700 (PDT) Received: from carbian.fritz.box ([2a02:8109:aa3f:ead8::d7e8]) by smtp.gmail.com with ESMTPSA id q14-20020a17090676ce00b00932ba722482sm1136881ejn.149.2023.04.20.13.22.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 13:22:35 -0700 (PDT) From: Mehdi Djait To: jic23@kernel.org, mazziesaccount@gmail.com Cc: krzysztof.kozlowski+dt@linaro.org, andriy.shevchenko@linux.intel.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Mehdi Djait Subject: [PATCH v2 2/5] iio: accel: kionix-kx022a: Warn on failed matches and assume compatibility Date: Thu, 20 Apr 2023 22:22:02 +0200 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Avoid error returns on a failure to match and instead just warn with assumption that we have a correct dt-binding telling us that some new device with a different ID is backwards compatible. Signed-off-by: Mehdi Djait --- v2: - no changes, this patch is introduced in the v2 drivers/iio/accel/kionix-kx022a.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c index f98393d74666..70530005cad3 100644 --- a/drivers/iio/accel/kionix-kx022a.c +++ b/drivers/iio/accel/kionix-kx022a.c @@ -1038,9 +1038,7 @@ int kx022a_probe_internal(struct device *dev) return dev_err_probe(dev, ret, "Failed to access sensor\n"); if (chip_id != KX022A_ID) { - dev_err(dev, "unsupported device 0x%x\n", chip_id); - return -EINVAL; - } + dev_warn(dev, "unsupported device 0x%x\n", chip_id); irq = fwnode_irq_get_byname(fwnode, "INT1"); if (irq > 0) { From patchwork Thu Apr 20 20:22:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mehdi Djait X-Patchwork-Id: 675697 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 13A78C77B73 for ; Thu, 20 Apr 2023 20:24:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232464AbjDTUYX (ORCPT ); Thu, 20 Apr 2023 16:24:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232389AbjDTUYA (ORCPT ); Thu, 20 Apr 2023 16:24:00 -0400 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E23E6A5A; Thu, 20 Apr 2023 13:22:55 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-504fce3d7fbso1227893a12.2; Thu, 20 Apr 2023 13:22:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682022174; x=1684614174; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ToW9WThq3gLLkyGYDWNM0Zjw078yICy28mQ0vlGolbc=; b=kekTDG5zu5+LQUfyi5YaXVoJcTUmGezCgKPoLb1Yc//Buh1Xnomhold4ilgf9Ri+PQ GmgUAb1+a7rOirzyaWB3iW3V3UIbzsfoooes47E2pOcCbpVewwOBFk57eAgaqN6MUJQD pwxn8UHVL6SmmMvrHgI6w+juOOkNHblyDMzHFcpNRb6wTu0PpEF3Qi2u+BvkNAN2A0dC +NfpRDPl1Kx+SCjbThTdSNnsNc4NFa1303Cbvs8sbeG+jZrLQEe2B40GC706ecNVFiUi 1ekixAZiyLsWmoQIuOHw3BApnD1K9nFWSXvQLhkl9JlsrwGipaIYCo+X8NkxKTsfwVYw 1BLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682022174; x=1684614174; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ToW9WThq3gLLkyGYDWNM0Zjw078yICy28mQ0vlGolbc=; b=X2SH0OkcWtRfVzVfPft1aktVfqcUC6tXW/V14EYFIaxWPk1jfsdL3N1HgPl6GIAQO7 nx6q4HmeICCWWtiRprJzVfhPLxjA5zIaQ9RfwcosKYd4UYJdYTUxzrJGHSjntocMgfHl AGPkGakPP5Qm77gF7GGZiOpbHrrGJziIoemsDc20Htqw13MOoCVnaodL05vv2nvFIz20 ohcTLhhRneGfrvMFkTxYPiwLk6q2ys8cI5pw8KbLHCyBukG3qtVoiA0/mgMK3cLiytqK ob8XWcKMMUKji//h4OjOePFwC6QaiNfVe5p5MVhHABhx+Qc9UKrBa768me3BMay/trlJ SuYQ== X-Gm-Message-State: AAQBX9ezx2Eu3NJAot4aiSdqYqi6qfsVa92a2XmOPebTU6HLFzEQICSb 9moFA6vg+4X8V+pZo6utnZE= X-Google-Smtp-Source: AKy350ZyHfdQLTBeCHtNOVW5xKm3ksc5nbZN4FT57eA0ImqLCLzhQQYOMc7cvCdFC1Jy7+eX4hi2wg== X-Received: by 2002:a17:907:2ad1:b0:94a:937a:58f1 with SMTP id fm17-20020a1709072ad100b0094a937a58f1mr216807ejc.1.1682022173921; Thu, 20 Apr 2023 13:22:53 -0700 (PDT) Received: from carbian.fritz.box ([2a02:8109:aa3f:ead8::d7e8]) by smtp.gmail.com with ESMTPSA id q14-20020a17090676ce00b00932ba722482sm1136881ejn.149.2023.04.20.13.22.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 13:22:53 -0700 (PDT) From: Mehdi Djait To: jic23@kernel.org, mazziesaccount@gmail.com Cc: krzysztof.kozlowski+dt@linaro.org, andriy.shevchenko@linux.intel.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Mehdi Djait Subject: [PATCH v2 5/5] iio: accel: Add support for Kionix/ROHM KX132-1211 accelerometer Date: Thu, 20 Apr 2023 22:22:05 +0200 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Kionix KX132-1211 is a tri-axis 16-bit accelerometer that can support ranges from ±2G to ±16G, digital output through I²C/SPI. Add support for basic accelerometer features such as reading acceleration via IIO using raw reads, triggered buffer (data-ready), or the WMI IRQ. Signed-off-by: Mehdi Djait --- v2: - mentioned the kx132-1211 in the Kconfig - added a kx132-specific get_fifo_bytes function - changed the device name from "kx132" to "kx132-1211" drivers/iio/accel/Kconfig | 8 +- drivers/iio/accel/kionix-kx022a-i2c.c | 2 + drivers/iio/accel/kionix-kx022a-spi.c | 2 + drivers/iio/accel/kionix-kx022a.c | 145 ++++++++++++++++++++++++++ drivers/iio/accel/kionix-kx022a.h | 52 +++++++++ 5 files changed, 205 insertions(+), 4 deletions(-) diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig index b6b45d359f28..d8cc6e6f2bb9 100644 --- a/drivers/iio/accel/Kconfig +++ b/drivers/iio/accel/Kconfig @@ -418,8 +418,8 @@ config IIO_KX022A_SPI select IIO_KX022A select REGMAP_SPI help - Enable support for the Kionix KX022A digital tri-axis - accelerometer connected to I2C interface. + Enable support for the Kionix KX022A, KX132-1211 digital tri-axis + accelerometers connected to SPI interface. config IIO_KX022A_I2C tristate "Kionix KX022A tri-axis digital accelerometer I2C interface" @@ -427,8 +427,8 @@ config IIO_KX022A_I2C select IIO_KX022A select REGMAP_I2C help - Enable support for the Kionix KX022A digital tri-axis - accelerometer connected to I2C interface. + Enable support for the Kionix KX022A, KX132-1211 digital tri-axis + accelerometers connected to I2C interface. config KXSD9 tristate "Kionix KXSD9 Accelerometer Driver" diff --git a/drivers/iio/accel/kionix-kx022a-i2c.c b/drivers/iio/accel/kionix-kx022a-i2c.c index ce299d0446f7..4ea28d2482ec 100644 --- a/drivers/iio/accel/kionix-kx022a-i2c.c +++ b/drivers/iio/accel/kionix-kx022a-i2c.c @@ -39,12 +39,14 @@ static int kx022a_i2c_probe(struct i2c_client *i2c) static const struct i2c_device_id kx022a_i2c_id[] = { { .name = "kx022a", .driver_data = (kernel_ulong_t)&kx022a_chip_info }, + { .name = "kx132-1211", .driver_data = (kernel_ulong_t)&kx132_chip_info }, { } }; MODULE_DEVICE_TABLE(i2c, kx022a_i2c_id); static const struct of_device_id kx022a_of_match[] = { { .compatible = "kionix,kx022a", .data = &kx022a_chip_info }, + { .compatible = "kionix,kx132-1211", .data = &kx132_chip_info }, { } }; MODULE_DEVICE_TABLE(of, kx022a_of_match); diff --git a/drivers/iio/accel/kionix-kx022a-spi.c b/drivers/iio/accel/kionix-kx022a-spi.c index 7bc81588e40e..8441d1444b9d 100644 --- a/drivers/iio/accel/kionix-kx022a-spi.c +++ b/drivers/iio/accel/kionix-kx022a-spi.c @@ -39,12 +39,14 @@ static int kx022a_spi_probe(struct spi_device *spi) static const struct spi_device_id kx022a_spi_id[] = { { .name = "kx022a", .driver_data = (kernel_ulong_t)&kx022a_chip_info }, + { .name = "kx132-1211", .driver_data = (kernel_ulong_t)&kx132_chip_info }, { } }; MODULE_DEVICE_TABLE(spi, kx022a_spi_id); static const struct of_device_id kx022a_of_match[] = { { .compatible = "kionix,kx022a", .data = &kx022a_chip_info }, + { .compatible = "kionix,kx132-1211", .data = &kx132_chip_info }, { } }; MODULE_DEVICE_TABLE(of, kx022a_of_match); diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c index 1c81ea1657b9..f058e266d189 100644 --- a/drivers/iio/accel/kionix-kx022a.c +++ b/drivers/iio/accel/kionix-kx022a.c @@ -150,6 +150,99 @@ static const struct regmap_config kx022a_regmap_config = { .cache_type = REGCACHE_RBTREE, }; +/* Regmap configs kx132 */ +static const struct regmap_range kx132_volatile_ranges[] = { + { + .range_min = KX132_REG_XADP_L, + .range_max = KX132_REG_COTR, + }, { + .range_min = KX132_REG_TSCP, + .range_max = KX132_REG_INT_REL, + }, { + /* The reset bit will be cleared by sensor */ + .range_min = KX132_REG_CNTL2, + .range_max = KX132_REG_CNTL2, + }, { + .range_min = KX132_REG_BUF_STATUS_1, + .range_max = KX132_REG_BUF_READ, + }, +}; + +static const struct regmap_access_table kx132_volatile_regs = { + .yes_ranges = &kx132_volatile_ranges[0], + .n_yes_ranges = ARRAY_SIZE(kx132_volatile_ranges), +}; + +static const struct regmap_range kx132_precious_ranges[] = { + { + .range_min = KX132_REG_INT_REL, + .range_max = KX132_REG_INT_REL, + }, +}; + +static const struct regmap_access_table kx132_precious_regs = { + .yes_ranges = &kx132_precious_ranges[0], + .n_yes_ranges = ARRAY_SIZE(kx132_precious_ranges), +}; + +static const struct regmap_range kx132_read_only_ranges[] = { + { + .range_min = KX132_REG_XADP_L, + .range_max = KX132_REG_INT_REL, + }, { + .range_min = KX132_REG_BUF_STATUS_1, + .range_max = KX132_REG_BUF_STATUS_2, + }, { + .range_min = KX132_REG_BUF_READ, + .range_max = KX132_REG_BUF_READ, + }, +}; + +static const struct regmap_access_table kx132_ro_regs = { + .no_ranges = &kx132_read_only_ranges[0], + .n_no_ranges = ARRAY_SIZE(kx132_read_only_ranges), +}; + +static const struct regmap_range kx132_write_only_ranges[] = { + { + .range_min = KX132_REG_MAN_WAKE, + .range_max = KX132_REG_MAN_WAKE, + }, { + .range_min = KX132_REG_SELF_TEST, + .range_max = KX132_REG_SELF_TEST, + }, { + .range_min = KX132_REG_BUF_CLEAR, + .range_max = KX132_REG_BUF_CLEAR, + }, +}; + +static const struct regmap_access_table kx132_wo_regs = { + .no_ranges = &kx132_write_only_ranges[0], + .n_no_ranges = ARRAY_SIZE(kx132_write_only_ranges), +}; + +static const struct regmap_range kx132_noinc_read_ranges[] = { + { + .range_min = KX132_REG_BUF_READ, + .range_max = KX132_REG_BUF_READ, + }, +}; + +static const struct regmap_access_table kx132_nir_regs = { + .yes_ranges = &kx132_noinc_read_ranges[0], + .n_yes_ranges = ARRAY_SIZE(kx132_noinc_read_ranges), +}; + +static const struct regmap_config kx132_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .volatile_table = &kx132_volatile_regs, + .rd_table = &kx132_wo_regs, + .wr_table = &kx132_ro_regs, + .rd_noinc_table = &kx132_nir_regs, + .precious_table = &kx132_precious_regs, + .max_register = KX132_MAX_REGISTER, + .cache_type = REGCACHE_RBTREE, }; static const struct iio_mount_matrix * @@ -206,6 +299,13 @@ static const struct iio_chan_spec kx022a_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(3), }; +static const struct iio_chan_spec kx132_channels[] = { + KX022A_ACCEL_CHAN(X, KX132_REG_XOUT_L, 0), + KX022A_ACCEL_CHAN(Y, KX132_REG_YOUT_L, 1), + KX022A_ACCEL_CHAN(Z, KX132_REG_ZOUT_L, 2), + IIO_CHAN_SOFT_TIMESTAMP(3), +}; + /* * The sensor HW can support ODR up to 1600 Hz, which is beyond what most of the * Linux CPUs can handle without dropping samples. Also, the low power mode is @@ -582,6 +682,25 @@ static int kx022a_get_fifo_bytes(struct kx022a_data *data) return fifo_bytes; } +static int kx132_get_fifo_bytes(struct kx022a_data *data) +{ + struct device *dev = regmap_get_device(data->regmap); + __le16 buf_status; + int ret, fifo_bytes; + + ret = regmap_bulk_read(data->regmap, data->chip_info->buf_status1, + &buf_status, sizeof(buf_status)); + if (ret) { + dev_err(dev, "Error reading buffer status\n"); + return ret; + } + + buf_status &= data->chip_info->buf_smp_lvl_mask; + fifo_bytes = le16_to_cpu(buf_status); + + return fifo_bytes; +} + static int __kx022a_fifo_flush(struct iio_dev *idev, unsigned int samples, bool irq) { @@ -1006,6 +1125,32 @@ const struct kx022a_chip_info kx022a_chip_info = { }; EXPORT_SYMBOL_NS_GPL(kx022a_chip_info, IIO_KX022A); +const struct kx022a_chip_info kx132_chip_info = { + .name = "kx132-1211", + .regmap_config = &kx132_regmap_config, + .channels = kx132_channels, + .num_channels = ARRAY_SIZE(kx132_channels), + .fifo_length = KX132_FIFO_LENGTH, + .who = KX132_REG_WHO, + .id = KX132_ID, + .cntl = KX132_REG_CNTL, + .cntl2 = KX132_REG_CNTL2, + .odcntl = KX132_REG_ODCNTL, + .buf_cntl1 = KX132_REG_BUF_CNTL1, + .buf_cntl2 = KX132_REG_BUF_CNTL2, + .buf_clear = KX132_REG_BUF_CLEAR, + .buf_status1 = KX132_REG_BUF_STATUS_1, + .buf_smp_lvl_mask = KX132_MASK_BUF_SMP_LVL, + .buf_read = KX132_REG_BUF_READ, + .inc1 = KX132_REG_INC1, + .inc4 = KX132_REG_INC4, + .inc5 = KX132_REG_INC5, + .inc6 = KX132_REG_INC6, + .xout_l = KX132_REG_XOUT_L, + .get_fifo_bytes = kx132_get_fifo_bytes, +}; +EXPORT_SYMBOL_NS_GPL(kx132_chip_info, IIO_KX022A); + int kx022a_probe_internal(struct device *dev, const struct kx022a_chip_info *chip_info) { static const char * const regulator_names[] = {"io-vdd", "vdd"}; diff --git a/drivers/iio/accel/kionix-kx022a.h b/drivers/iio/accel/kionix-kx022a.h index 43e32e688258..c79d9895921e 100644 --- a/drivers/iio/accel/kionix-kx022a.h +++ b/drivers/iio/accel/kionix-kx022a.h @@ -76,6 +76,57 @@ #define KX022A_REG_SELF_TEST 0x60 #define KX022A_MAX_REGISTER 0x60 +#define KX132_REG_WHO 0x13 +#define KX132_ID 0x3d + +#define KX132_FIFO_LENGTH 86 + +#define KX132_REG_CNTL 0x1b +#define KX132_REG_CNTL2 0x1c +#define KX132_MASK_RES BIT(6) +#define KX132_GSEL_2 0x0 +#define KX132_GSEL_4 BIT(3) +#define KX132_GSEL_8 BIT(4) +#define KX132_GSEL_16 GENMASK(4, 3) + +#define KX132_REG_INS2 0x17 +#define KX132_MASK_INS2_WMI BIT(5) + +#define KX132_REG_XADP_L 0x02 +#define KX132_REG_XOUT_L 0x08 +#define KX132_REG_YOUT_L 0x0a +#define KX132_REG_ZOUT_L 0x0c +#define KX132_REG_COTR 0x12 +#define KX132_REG_TSCP 0x14 +#define KX132_REG_INT_REL 0x1a + +#define KX132_REG_ODCNTL 0x21 + +#define KX132_REG_BTS_WUF_TH 0x4a +#define KX132_REG_MAN_WAKE 0x4d + +#define KX132_REG_BUF_CNTL1 0x5e +#define KX132_REG_BUF_CNTL2 0x5f +#define KX132_REG_BUF_STATUS_1 0x60 +#define KX132_REG_BUF_STATUS_2 0x61 +#define KX132_MASK_BUF_SMP_LVL GENMASK(9, 0) +#define KX132_REG_BUF_CLEAR 0x62 +#define KX132_REG_BUF_READ 0x63 +#define KX132_ODR_SHIFT 3 +#define KX132_FIFO_MAX_WMI_TH 86 + +#define KX132_REG_INC1 0x22 +#define KX132_REG_INC5 0x26 +#define KX132_REG_INC6 0x27 +#define KX132_IPOL_LOW 0 +#define KX132_IPOL_HIGH KX022A_MASK_IPOL +#define KX132_ITYP_PULSE KX022A_MASK_ITYP + +#define KX132_REG_INC4 0x25 + +#define KX132_REG_SELF_TEST 0x5d +#define KX132_MAX_REGISTER 0x76 + struct device; struct kx022a_data { @@ -165,5 +216,6 @@ struct kx022a_chip_info { int kx022a_probe_internal(struct device *dev, const struct kx022a_chip_info *chip_info); extern const struct kx022a_chip_info kx022a_chip_info; +extern const struct kx022a_chip_info kx132_chip_info; #endif