From patchwork Sat Sep 16 12:38:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mehdi Djait X-Patchwork-Id: 13388359 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 9C176C46CA1 for ; Sat, 16 Sep 2023 12:39:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239190AbjIPMjR (ORCPT ); Sat, 16 Sep 2023 08:39:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239097AbjIPMjJ (ORCPT ); Sat, 16 Sep 2023 08:39:09 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EF21CED; Sat, 16 Sep 2023 05:39:04 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-502defbb0c3so5005488e87.0; Sat, 16 Sep 2023 05:39:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694867942; x=1695472742; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nieLmXIKnfkthdI8h0lUoH7VKVpFKo/h00FyBK08R40=; b=RgZRIzAuQ4s6Xgali18E5fanTzIhz4xRh+yxU+V7xV1TjIIbsvOm8JfqHffcUmnAUH Rzrz9878DpKNex4p4Z0uU2Fg6KmX3n340tPYJHQmuDrYdegzB2/pi62+45dUofpnTjGF qvPJWdYvdNoy/enuKwLpk4FWVzNRSt9vdRnnXZwfjst3XvVqXxhO9N2EnQDtX58QMcFx 9MroYpz7xZftxZvNFXqzX8IxD1y6pEWc6202dVDUx76wABnX3cyyMiVbjM/OLjJ4wj5P bbUSte9tmnQ23D3Ni0ABsIMzdosWO/47dA6xmhw5smwN2/FHpvncl5ClYH0Wou9TlOAZ 6KvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694867942; x=1695472742; 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=nieLmXIKnfkthdI8h0lUoH7VKVpFKo/h00FyBK08R40=; b=NqWPMCp1zUQ0HzMKnf488NxPyLfXvIUhJJmsj1lWS9Wyb1XJURsKZ6TnXPGDXp1OkM TPIetcwR/SzfjtpiLR162p7pL8g4pTeOgXr2IKUu4lPafDEEAwnopDpIGx5lCEbIGX8m sAdG/pTkTHE2VqXIWmh1yrYLqTER9PLy2GVpGM/ts1hvS9auDEQ5D2Vv1esDipKAjSKn k0+4BymhRgs/F+ZWH25i9mMsXMemP52FMfWWc/pgZyYnPrpxeASWUI0QDASsqyyiD9kp MzTOuO3jZ7owiapSrkuUsET05hCpOBK2ab45ZuU4bGdMFFCllFQzEHUDqaHscKm2QArG Kraw== X-Gm-Message-State: AOJu0Yz4KGvaadPCZCGt++MO82o2yjYfHsxENQCgQQG3T/2R04XX3HWT zwd2RsBHA/rBf1wA6djZtPU= X-Google-Smtp-Source: AGHT+IH/qxwqx8+EhczONsEZzFXbPcYDeP3F71DAK4QPw1NoWKyfQ+3paOogF1UI8wcNqMcQmmbhmw== X-Received: by 2002:a05:6512:3e05:b0:503:3b5:a65 with SMTP id i5-20020a0565123e0500b0050303b50a65mr1457882lfv.31.1694867942097; Sat, 16 Sep 2023 05:39:02 -0700 (PDT) Received: from localhost.localdomain ([77.134.181.150]) by smtp.gmail.com with ESMTPSA id bo6-20020a0564020b2600b0052284228e3bsm3474064edb.8.2023.09.16.05.39.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 05:39:01 -0700 (PDT) From: Mehdi Djait To: jic23@kernel.org, mazziesaccount@gmail.com Cc: krzysztof.kozlowski+dt@linaro.org, andriy.shevchenko@linux.intel.com, robh+dt@kernel.org, lars@metafoo.de, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Mehdi Djait , Krzysztof Kozlowski Subject: [PATCH v9 1/7] dt-bindings: iio: Add KX132-1211 accelerometer Date: Sat, 16 Sep 2023 14:38:47 +0200 Message-Id: <735004c624082aead6e08ae37ea4fc086b11cf86.1694867379.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: linux-iio@vger.kernel.org Extend the kionix,kx022a.yaml file to support the kx132-1211 device Acked-by: Krzysztof Kozlowski Acked-by: Matti Vaittinen Signed-off-by: Mehdi Djait --- .../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 Sat Sep 16 12:38:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mehdi Djait X-Patchwork-Id: 13388356 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 8673ACD37BB for ; Sat, 16 Sep 2023 12:39:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238935AbjIPMjR (ORCPT ); Sat, 16 Sep 2023 08:39:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239111AbjIPMjK (ORCPT ); Sat, 16 Sep 2023 08:39:10 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1534CEF; Sat, 16 Sep 2023 05:39:05 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-500913779f5so4898977e87.2; Sat, 16 Sep 2023 05:39:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694867944; x=1695472744; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q79fUZZbSUv3woTyk6fuaOdxQDm7PBUultk07mBos+4=; b=mgRIJ0a+yRHvOk2MXIASEWi4SCoaqfvBsezrBUFB9gWl7u7Z6V28ewtN7RAuCEyDYn BJzdZUNncLqQfa+3dvFRE2bjt3+WldIZ40pL05QJn+spnGjocV6K26gW428mN93f+Kw8 n/m0edWr1fwvDX+hupI+zeiFVMtAIcg6WZDzB88SX9GFHLBl6ObHzDQV3qEEdiCZD7xy UreoWrLfnuhHr0WfDR5KpS7iLoVAqY9pqntz81ERpZqguP2UmTEVQPCYBl+oekqnxDzB tbSFdQrbK9EIY1zunZnLV4Kza1O2wAIbf1nHPh+lw/GJ0sWcR7CxcgAQfrnQwca9U6g8 r3zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694867944; x=1695472744; 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=Q79fUZZbSUv3woTyk6fuaOdxQDm7PBUultk07mBos+4=; b=VxK+WTygJgRbrSVn7e6qOqisETscPzMTFrKVqYgoOYFzX5sDElXLFFD0NUW9yIJ55u NUXd0gEOX5/s8I5ev1IPwdXBAyn2n0NXWU5XQcBXGb53+jFFCY4odPAdnLAJ3je6FVY4 keaCtNTT2sKaAhk8SKAydbKuPGzW9Vr6ftL8tw8KRDTftUi7ceQXcAM7TzR1V/HOC9rz TQn8uFOBkBeoQHzzD5QjU2l1iTqQp2jNv/z62INwGFFrydfQJSnCO5febav08VxcAWZo kbQpOf96mdLmkWTVe8MRiO3N+L0oBQrs8TgTHj8qvQ6i1IWTNKvlFiBJ4WTu0/hEr1Kr v8+A== X-Gm-Message-State: AOJu0YwGch3BJWEENOTD7x6QFqK8MVejZ/6kdJA6f4Xa5OG6qNlbbliy Wbd8tZDBih0LZaTwLOl7DS0= X-Google-Smtp-Source: AGHT+IGG6yNDr1u/yJrve6emYBkyCfBo5rXmedyP3fAucUQrIqExiENN7gWRJp/OitCxwnERHwWuTw== X-Received: by 2002:a05:6512:e96:b0:4f8:71cc:2b6e with SMTP id bi22-20020a0565120e9600b004f871cc2b6emr4423713lfb.33.1694867943947; Sat, 16 Sep 2023 05:39:03 -0700 (PDT) Received: from localhost.localdomain ([77.134.181.150]) by smtp.gmail.com with ESMTPSA id bo6-20020a0564020b2600b0052284228e3bsm3474064edb.8.2023.09.16.05.39.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 05:39:03 -0700 (PDT) From: Mehdi Djait To: jic23@kernel.org, mazziesaccount@gmail.com Cc: krzysztof.kozlowski+dt@linaro.org, andriy.shevchenko@linux.intel.com, robh+dt@kernel.org, lars@metafoo.de, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Mehdi Djait Subject: [PATCH v9 2/7] iio: accel: kionix-kx022a: Remove blank lines Date: Sat, 16 Sep 2023 14:38:48 +0200 Message-Id: <3489099f653491e97b13b8f19fe86635b03020c8.1694867379.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: linux-iio@vger.kernel.org Remove blank lines pointed out by the checkpatch script Reviewed-by: Andy Shevchenko Reviewed-by: Matti Vaittinen Signed-off-by: Mehdi Djait --- drivers/iio/accel/kionix-kx022a.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c index f164b09520c9..2f1e7da25460 100644 --- a/drivers/iio/accel/kionix-kx022a.c +++ b/drivers/iio/accel/kionix-kx022a.c @@ -341,7 +341,6 @@ static int kx022a_turn_on_off_unlocked(struct kx022a_data *data, bool on) dev_err(data->dev, "Turn %s fail %d\n", str_on_off(on), ret); return ret; - } static int kx022a_turn_off_lock(struct kx022a_data *data) @@ -1110,7 +1109,6 @@ int kx022a_probe_internal(struct device *dev) if (ret) return dev_err_probe(data->dev, ret, "Could not request IRQ\n"); - ret = devm_iio_trigger_register(dev, indio_trig); if (ret) return dev_err_probe(data->dev, ret, From patchwork Sat Sep 16 12:38:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mehdi Djait X-Patchwork-Id: 13388360 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 D26F6CD37BE for ; Sat, 16 Sep 2023 12:39:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239197AbjIPMjS (ORCPT ); Sat, 16 Sep 2023 08:39:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239160AbjIPMjM (ORCPT ); Sat, 16 Sep 2023 08:39:12 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EEA419A; Sat, 16 Sep 2023 05:39:07 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-5280ef23593so3446581a12.3; Sat, 16 Sep 2023 05:39:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694867946; x=1695472746; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rbUZvYmQNv8XlHrBCEW1i93lPke7LBgt2Bqs3H5wtAk=; b=F6iGH7t1axChCJBQ4Uaxbg98Y4TGX5MxKr8LsU3k6OXTPdBIyGRbYuMceFsEXU4ldk 3ZHwMC6cSS6RctFKY4UaI3kdyYbS1ZakgohUvNulvlSvt3MsHJZkrPhDIxqyrSzeIHPc xHzyliViJ1HpDFqHvXBtf36UuTQtmA55r8+cJ127ZA227YBomiKH5yRANEABzXi4lW7L hsm9S90QBhmnCIWjHIRndbG24g0bRFad1g7xyPZqtuYCfETtaIJ1fuoMt8kGbYYRqz3c Sq7weyQj171yAco72DNj0n3s0aWRHGFHFqOlM1GcwX8XkXhYMcfUj1Os4fKppxauMGXC pt6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694867946; x=1695472746; 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=rbUZvYmQNv8XlHrBCEW1i93lPke7LBgt2Bqs3H5wtAk=; b=QQ3yd+tYyLW2vthZMsYSi9r00NkiJZebTGo08g/B6obVQmuxC3yg+aE7cig9kNUFUB pqE5wM9lroOE2hG29p5jnzYqgK7SOCqf+dLjlskXw1EpPHSuzyqQYE8zbYolT3b61mm+ NAxCmHA6XDCxj8n5nW4poX75U4f9e4TSMI/ASTIUY9qLdNhNE9Bb3zv2Big5chqXCAeE rwkP5UnaiaA14fHh/0HppbUsIGz93oOuiqPQCWSRjZQxEjh4CXl0OYy7rhny/s1VNzL6 94GOZLi2LZHVvsiPZs+aqZoEM6lp2PIOH9jcGesFJOdVAHTMpfSlCv+I+65qcXG00B7G GB6Q== X-Gm-Message-State: AOJu0YwOj54vqisrBxGQee9NBLZKX4rnMt316curU1/8twljBa0VlxW7 2SpcDVb66xRmSGT/vVXAkxs= X-Google-Smtp-Source: AGHT+IEW9exOYt9cVJju2hIT4N6DQ0wSOJuXq361U1FWB9/G6uY7vFibOZIXUkdPPmEq6pa9zXc1Gg== X-Received: by 2002:a05:6402:14c4:b0:530:4fc4:50f8 with SMTP id f4-20020a05640214c400b005304fc450f8mr3350537edx.29.1694867945641; Sat, 16 Sep 2023 05:39:05 -0700 (PDT) Received: from localhost.localdomain ([77.134.181.150]) by smtp.gmail.com with ESMTPSA id bo6-20020a0564020b2600b0052284228e3bsm3474064edb.8.2023.09.16.05.39.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 05:39:05 -0700 (PDT) From: Mehdi Djait To: jic23@kernel.org, mazziesaccount@gmail.com Cc: krzysztof.kozlowski+dt@linaro.org, andriy.shevchenko@linux.intel.com, robh+dt@kernel.org, lars@metafoo.de, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Mehdi Djait Subject: [PATCH v9 3/7] iio: accel: kionix-kx022a: Warn on failed matches and assume compatibility Date: Sat, 16 Sep 2023 14:38:49 +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: linux-iio@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. Acked-by: Matti Vaittinen Signed-off-by: Mehdi Djait --- drivers/iio/accel/kionix-kx022a.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c index 2f1e7da25460..5a144f86c634 100644 --- a/drivers/iio/accel/kionix-kx022a.c +++ b/drivers/iio/accel/kionix-kx022a.c @@ -1025,10 +1025,8 @@ int kx022a_probe_internal(struct device *dev) if (ret) 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; - } + if (chip_id != KX022A_ID) + dev_warn(dev, "unknown device 0x%x\n", chip_id); irq = fwnode_irq_get_byname(fwnode, "INT1"); if (irq > 0) { From patchwork Sat Sep 16 12:38:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mehdi Djait X-Patchwork-Id: 13388358 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 ACC6ACD37BD for ; Sat, 16 Sep 2023 12:39:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239076AbjIPMjS (ORCPT ); Sat, 16 Sep 2023 08:39:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239172AbjIPMjO (ORCPT ); Sat, 16 Sep 2023 08:39:14 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68FCCCEF; Sat, 16 Sep 2023 05:39:09 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-502fd1e1dd8so1166168e87.1; Sat, 16 Sep 2023 05:39:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694867947; x=1695472747; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fYNQU7FPTvydILSwaK5s6AQY8aSIkTxjQ7ZIxHmCX18=; b=U80BwZbCz5EV1V9Vf6yjraZPBoQCrty40RaH1ZfCj0PxEginJT2U74Ss4+yb21eSgT Z5BR27haIXf4BeQiJUHSk6T+bAMT4LW/WC0XKqwzgvAOTMAH41NrFbIFvbMpX3KTsYfk imFTCUVNEQL3mXVbQ84owb7Kkhb+p4e5x6dPdfy8btIk44wkVjIm4gnqjPvEPLy2awVn 87jom8j/UwXxQWmSGbJc0mo1zR3jBPMGZfqxsZCrustfU/zqKHWe5mtOP9a8eKY9NZ5c Kff3l5Azz77Q0qzcicUPDhRfzXY/PqtlXa8eTG+cRxRuZsx08SgFe5lTT2Sns9AgKdsD QJ0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694867947; x=1695472747; 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=fYNQU7FPTvydILSwaK5s6AQY8aSIkTxjQ7ZIxHmCX18=; b=BbsT7kAKBVQp4klRbBR7JCGenDcK6WNuOLJP0aczMUwHzKsnr0lbZuvwcTzKhsBpAa Wz/odZ1ykhIMvBp/O7e5wowhvpjcmPlz1+Oj4BDJiTzwYClxb3l2CYl2KNOqmKMh4QJt 5MaBUrhr845sLT+lzZJzytSevaNYSo4senPoDD852f2NoFfBybJLEvBgb5RZenzuzTtC R7SSVmkGMh3mAtbkcrQKz6YjwlFnnj9E4NUqBqiWrcv+mXHhRIt8yzpRI7gL4wkMwMQy LtDQTrHPOJM8pL4yt2qfCmhNjijEepJdjfx6f5V7nv0ar9YeF/eqj8WE9YOmYUoZW8Xv AOjg== X-Gm-Message-State: AOJu0YzkhZk5sS7yBrObu2vckia/upXMpdilDp0J6eSJ+U4+EG9Fmedd N3n23LJF031SjCT4jiANG3o= X-Google-Smtp-Source: AGHT+IGJ6r1XVtdmzsBBFUnIUyW7I4dm3Ai02tPH6LrH/oRvJKGpCOaHvoH8GnNDrSR1/tw4IXZwmg== X-Received: by 2002:a05:6512:3b27:b0:502:ff3b:766f with SMTP id f39-20020a0565123b2700b00502ff3b766fmr2027243lfv.6.1694867947453; Sat, 16 Sep 2023 05:39:07 -0700 (PDT) Received: from localhost.localdomain ([77.134.181.150]) by smtp.gmail.com with ESMTPSA id bo6-20020a0564020b2600b0052284228e3bsm3474064edb.8.2023.09.16.05.39.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 05:39:07 -0700 (PDT) From: Mehdi Djait To: jic23@kernel.org, mazziesaccount@gmail.com Cc: krzysztof.kozlowski+dt@linaro.org, andriy.shevchenko@linux.intel.com, robh+dt@kernel.org, lars@metafoo.de, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Mehdi Djait Subject: [PATCH v9 4/7] iio: accel: kionix-kx022a: Add an i2c_device_id table Date: Sat, 16 Sep 2023 14:38:50 +0200 Message-Id: <61b43bbf35d602eac34b6d81b4d1b2d7ba39786f.1694867379.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: linux-iio@vger.kernel.org Add the missing i2c device id. Acked-by: Matti Vaittinen Signed-off-by: Mehdi Djait --- drivers/iio/accel/kionix-kx022a-i2c.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/iio/accel/kionix-kx022a-i2c.c b/drivers/iio/accel/kionix-kx022a-i2c.c index b0ac78e85dad..c0d0b69680f9 100644 --- a/drivers/iio/accel/kionix-kx022a-i2c.c +++ b/drivers/iio/accel/kionix-kx022a-i2c.c @@ -30,6 +30,12 @@ static int kx022a_i2c_probe(struct i2c_client *i2c) return kx022a_probe_internal(dev); } +static const struct i2c_device_id kx022a_i2c_id[] = { + { .name = "kx022a" }, + { } +}; +MODULE_DEVICE_TABLE(i2c, kx022a_i2c_id); + static const struct of_device_id kx022a_of_match[] = { { .compatible = "kionix,kx022a", }, { } @@ -43,6 +49,7 @@ static struct i2c_driver kx022a_i2c_driver = { .probe_type = PROBE_PREFER_ASYNCHRONOUS, }, .probe = kx022a_i2c_probe, + .id_table = kx022a_i2c_id, }; module_i2c_driver(kx022a_i2c_driver); From patchwork Sat Sep 16 12:38:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mehdi Djait X-Patchwork-Id: 13388362 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 7338FCD37BB for ; Sat, 16 Sep 2023 12:40:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239130AbjIPMjt (ORCPT ); Sat, 16 Sep 2023 08:39:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239228AbjIPMjT (ORCPT ); Sat, 16 Sep 2023 08:39:19 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B6F0CED; Sat, 16 Sep 2023 05:39:13 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-52e5900cf77so3621636a12.2; Sat, 16 Sep 2023 05:39:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694867951; x=1695472751; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wYYjh9GMEQV4bQzg1yrZBAuN1ssy5a2YTx5yaZl725w=; b=WHJMFxtdghFQ5NPDrXWh22aq8vJd+i8bobyAkuV+HbgxXheTgCvO7fQ9xuuhKP9Y24 F3GneP3csRqX8Qm4BtoFakTMHArrte336g3ikkI3VnyREvDzjGGIkLVR7VL2PMBNONtp os+v3FjIq1tM1pWh3xE2AVpVAtxFDcuLVGpa/RQfMAnGLTrhdLTPn0kUqAywEm86z0Ab 4Xczy0U+xFlEzgGNWY0M6uq10jsohgJlMvIO67KOk09Wd0uiak2KWWOjg2zUAh3NwDyD KcstrXsOCpaqTcHCFbWou3uOIxJCZvGjNia8u60AOoQrxUkPtdkVyLnicjCoyHvONcVy dXng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694867951; x=1695472751; 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=wYYjh9GMEQV4bQzg1yrZBAuN1ssy5a2YTx5yaZl725w=; b=EKCZgPEPvNNvPyW/4t085WUY2y8mqSu0MZXqgwHgmU4ufwbau8Brn9V6+OZRzTflxi 3LbO2yrQMPXUBhE4IscLHgWoNO62iZWouXxBGbzSc21t0lWHE3iPR7iA4kozlPxbzXgI WgeNE/rmWKqQ2bd4MPY+6Ne9mj9T8nqYZEcAW43fGqpWVbAjzrWqiUwLh2p/3pESnak9 iqJZiA34n9Wwu078RRPifMD74Mgx3BRneD2p8u8/0uAqaeqiWE+oitEo/qBkqlx1Fpih ax+7Qdnorc6oLtAzkZSyQrApJ8Cmpbv7OWaTjEpuDDkGv4A042ZA+JwjoeokxpMvYvSo TGwQ== X-Gm-Message-State: AOJu0YwMXnbK2AabyJKdZij97AH+6oMvEbwtVk2CKAu2whv4/yHSrXvi na1Ok3O8BMfGBKbG2tFZpn6Q9V462vbpnA== X-Google-Smtp-Source: AGHT+IF3pdlrF9KDFCXXOMdGR7KeMs4q60AuU50UeaoWvlHbEvMsBvGAqR5u0DVzm2xSEk6SN989mA== X-Received: by 2002:a50:fc0e:0:b0:527:3a95:5bea with SMTP id i14-20020a50fc0e000000b005273a955beamr3616471edr.32.1694867951371; Sat, 16 Sep 2023 05:39:11 -0700 (PDT) Received: from localhost.localdomain ([77.134.181.150]) by smtp.gmail.com with ESMTPSA id bo6-20020a0564020b2600b0052284228e3bsm3474064edb.8.2023.09.16.05.39.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 05:39:10 -0700 (PDT) From: Mehdi Djait To: jic23@kernel.org, mazziesaccount@gmail.com Cc: krzysztof.kozlowski+dt@linaro.org, andriy.shevchenko@linux.intel.com, robh+dt@kernel.org, lars@metafoo.de, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Mehdi Djait Subject: [PATCH v9 5/7] iio: accel: kionix-kx022a: Refactor driver and add chip_info structure Date: Sat, 16 Sep 2023 14:38:51 +0200 Message-Id: <7a31d0cdefba15d7c791252ec8bc5db553b3996b.1694867379.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: linux-iio@vger.kernel.org Add the chip_info structure to the driver's private data to hold all the device specific infos. Refactor the kx022a driver implementation to make it more generic and extensible. Acked-by: Matti Vaittinen Signed-off-by: Mehdi Djait --- drivers/iio/accel/kionix-kx022a-i2c.c | 13 ++- drivers/iio/accel/kionix-kx022a-spi.c | 13 ++- drivers/iio/accel/kionix-kx022a.c | 117 +++++++++++++++++--------- drivers/iio/accel/kionix-kx022a.h | 52 +++++++++++- 4 files changed, 143 insertions(+), 52 deletions(-) diff --git a/drivers/iio/accel/kionix-kx022a-i2c.c b/drivers/iio/accel/kionix-kx022a-i2c.c index c0d0b69680f9..2fdc4c1ab93f 100644 --- a/drivers/iio/accel/kionix-kx022a-i2c.c +++ b/drivers/iio/accel/kionix-kx022a-i2c.c @@ -15,6 +15,7 @@ static int kx022a_i2c_probe(struct i2c_client *i2c) { struct device *dev = &i2c->dev; + const struct kx022a_chip_info *chip_info; struct regmap *regmap; if (!i2c->irq) { @@ -22,22 +23,26 @@ static int kx022a_i2c_probe(struct i2c_client *i2c) return -EINVAL; } - regmap = devm_regmap_init_i2c(i2c, &kx022a_regmap); + chip_info = i2c_get_match_data(i2c); + if (!chip_info) + return -EINVAL; + + regmap = devm_regmap_init_i2c(i2c, chip_info->regmap_config); if (IS_ERR(regmap)) return dev_err_probe(dev, PTR_ERR(regmap), "Failed to initialize Regmap\n"); - return kx022a_probe_internal(dev); + return kx022a_probe_internal(dev, chip_info); } static const struct i2c_device_id kx022a_i2c_id[] = { - { .name = "kx022a" }, + { .name = "kx022a", .driver_data = (kernel_ulong_t)&kx022a_chip_info }, { } }; MODULE_DEVICE_TABLE(i2c, kx022a_i2c_id); static const struct of_device_id kx022a_of_match[] = { - { .compatible = "kionix,kx022a", }, + { .compatible = "kionix,kx022a", .data = &kx022a_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 f45a46899a5f..c21494ade157 100644 --- a/drivers/iio/accel/kionix-kx022a-spi.c +++ b/drivers/iio/accel/kionix-kx022a-spi.c @@ -15,6 +15,7 @@ static int kx022a_spi_probe(struct spi_device *spi) { struct device *dev = &spi->dev; + const struct kx022a_chip_info *chip_info; struct regmap *regmap; if (!spi->irq) { @@ -22,22 +23,26 @@ static int kx022a_spi_probe(struct spi_device *spi) return -EINVAL; } - regmap = devm_regmap_init_spi(spi, &kx022a_regmap); + chip_info = spi_get_device_match_data(spi); + if (!chip_info) + return -EINVAL; + + regmap = devm_regmap_init_spi(spi, chip_info->regmap_config); if (IS_ERR(regmap)) return dev_err_probe(dev, PTR_ERR(regmap), "Failed to initialize Regmap\n"); - return kx022a_probe_internal(dev); + return kx022a_probe_internal(dev, chip_info); } static const struct spi_device_id kx022a_id[] = { - { "kx022a" }, + { .name = "kx022a", .driver_data = (kernel_ulong_t)&kx022a_chip_info }, { } }; MODULE_DEVICE_TABLE(spi, kx022a_id); static const struct of_device_id kx022a_of_match[] = { - { .compatible = "kionix,kx022a", }, + { .compatible = "kionix,kx022a", .data = &kx022a_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 5a144f86c634..ab3e5c8a19df 100644 --- a/drivers/iio/accel/kionix-kx022a.c +++ b/drivers/iio/accel/kionix-kx022a.c @@ -48,7 +48,7 @@ enum { KX022A_STATE_FIFO, }; -/* Regmap configs */ +/* kx022a Regmap configs */ static const struct regmap_range kx022a_volatile_ranges[] = { { .range_min = KX022A_REG_XHP_L, @@ -138,7 +138,7 @@ static const struct regmap_access_table kx022a_nir_regs = { .n_yes_ranges = ARRAY_SIZE(kx022a_noinc_read_ranges), }; -const struct regmap_config kx022a_regmap = { +static const struct regmap_config kx022a_regmap_config = { .reg_bits = 8, .val_bits = 8, .volatile_table = &kx022a_volatile_regs, @@ -149,10 +149,10 @@ const struct regmap_config kx022a_regmap = { .max_register = KX022A_MAX_REGISTER, .cache_type = REGCACHE_RBTREE, }; -EXPORT_SYMBOL_NS_GPL(kx022a_regmap, IIO_KX022A); struct kx022a_data { struct regmap *regmap; + const struct kx022a_chip_info *chip_info; struct iio_trigger *trig; struct device *dev; struct iio_mount_matrix orientation; @@ -175,6 +175,8 @@ struct kx022a_data { struct mutex mutex; u8 watermark; + __le16 *fifo_buffer; + /* 3 x 16bit accel data + timestamp */ __le16 buffer[8] __aligned(IIO_DMA_MINALIGN); struct { @@ -208,7 +210,7 @@ static const struct iio_chan_spec_ext_info kx022a_ext_info[] = { { } }; -#define KX022A_ACCEL_CHAN(axis, index) \ +#define KX022A_ACCEL_CHAN(axis, reg, index) \ { \ .type = IIO_ACCEL, \ .modified = 1, \ @@ -220,7 +222,7 @@ static const struct iio_chan_spec_ext_info kx022a_ext_info[] = { BIT(IIO_CHAN_INFO_SCALE) | \ BIT(IIO_CHAN_INFO_SAMP_FREQ), \ .ext_info = kx022a_ext_info, \ - .address = KX022A_REG_##axis##OUT_L, \ + .address = reg, \ .scan_index = index, \ .scan_type = { \ .sign = 's', \ @@ -231,9 +233,9 @@ static const struct iio_chan_spec_ext_info kx022a_ext_info[] = { } static const struct iio_chan_spec kx022a_channels[] = { - KX022A_ACCEL_CHAN(X, 0), - KX022A_ACCEL_CHAN(Y, 1), - KX022A_ACCEL_CHAN(Z, 2), + KX022A_ACCEL_CHAN(X, KX022A_REG_XOUT_L, 0), + KX022A_ACCEL_CHAN(Y, KX022A_REG_YOUT_L, 1), + KX022A_ACCEL_CHAN(Z, KX022A_REG_ZOUT_L, 2), IIO_CHAN_SOFT_TIMESTAMP(3), }; @@ -332,10 +334,10 @@ static int kx022a_turn_on_off_unlocked(struct kx022a_data *data, bool on) int ret; if (on) - ret = regmap_set_bits(data->regmap, KX022A_REG_CNTL, + ret = regmap_set_bits(data->regmap, data->chip_info->cntl, KX022A_MASK_PC1); else - ret = regmap_clear_bits(data->regmap, KX022A_REG_CNTL, + ret = regmap_clear_bits(data->regmap, data->chip_info->cntl, KX022A_MASK_PC1); if (ret) dev_err(data->dev, "Turn %s fail %d\n", str_on_off(on), ret); @@ -402,7 +404,7 @@ static int kx022a_write_raw(struct iio_dev *idev, break; ret = regmap_update_bits(data->regmap, - KX022A_REG_ODCNTL, + data->chip_info->odcntl, KX022A_MASK_ODR, n); data->odr_ns = kx022a_odrs[n]; kx022a_turn_on_unlock(data); @@ -423,7 +425,7 @@ static int kx022a_write_raw(struct iio_dev *idev, if (ret) break; - ret = regmap_update_bits(data->regmap, KX022A_REG_CNTL, + ret = regmap_update_bits(data->regmap, data->chip_info->cntl, KX022A_MASK_GSEL, n << KX022A_GSEL_SHIFT); kx022a_turn_on_unlock(data); @@ -445,7 +447,7 @@ static int kx022a_fifo_set_wmi(struct kx022a_data *data) threshold = data->watermark; - return regmap_update_bits(data->regmap, KX022A_REG_BUF_CNTL1, + return regmap_update_bits(data->regmap, data->chip_info->buf_cntl1, KX022A_MASK_WM_TH, threshold); } @@ -488,7 +490,7 @@ static int kx022a_read_raw(struct iio_dev *idev, return ret; case IIO_CHAN_INFO_SAMP_FREQ: - ret = regmap_read(data->regmap, KX022A_REG_ODCNTL, ®val); + ret = regmap_read(data->regmap, data->chip_info->odcntl, ®val); if (ret) return ret; @@ -503,7 +505,7 @@ static int kx022a_read_raw(struct iio_dev *idev, return IIO_VAL_INT_PLUS_MICRO; case IIO_CHAN_INFO_SCALE: - ret = regmap_read(data->regmap, KX022A_REG_CNTL, ®val); + ret = regmap_read(data->regmap, data->chip_info->cntl, ®val); if (ret < 0) return ret; @@ -519,8 +521,7 @@ static int kx022a_set_watermark(struct iio_dev *idev, unsigned int val) { struct kx022a_data *data = iio_priv(idev); - if (val > KX022A_FIFO_LENGTH) - val = KX022A_FIFO_LENGTH; + val = min(data->chip_info->fifo_length, val); mutex_lock(&data->mutex); data->watermark = val; @@ -581,7 +582,7 @@ static int kx022a_drop_fifo_contents(struct kx022a_data *data) */ data->timestamp = 0; - return regmap_write(data->regmap, KX022A_REG_BUF_CLEAR, 0x0); + return regmap_write(data->regmap, data->chip_info->buf_clear, 0x0); } static int __kx022a_fifo_flush(struct iio_dev *idev, unsigned int samples, @@ -589,7 +590,6 @@ static int __kx022a_fifo_flush(struct iio_dev *idev, unsigned int samples, { struct kx022a_data *data = iio_priv(idev); struct device *dev = regmap_get_device(data->regmap); - __le16 buffer[KX022A_FIFO_LENGTH * 3]; uint64_t sample_period; int count, fifo_bytes; bool renable = false; @@ -668,13 +668,13 @@ static int __kx022a_fifo_flush(struct iio_dev *idev, unsigned int samples, } fifo_bytes = count * KX022A_FIFO_SAMPLES_SIZE_BYTES; - ret = regmap_noinc_read(data->regmap, KX022A_REG_BUF_READ, - &buffer[0], fifo_bytes); + ret = regmap_noinc_read(data->regmap, data->chip_info->buf_read, + data->fifo_buffer, fifo_bytes); if (ret) goto renable_out; for (i = 0; i < count; i++) { - __le16 *sam = &buffer[i * 3]; + __le16 *sam = &data->fifo_buffer[i * 3]; __le16 *chs; int bit; @@ -721,10 +721,10 @@ static const struct iio_info kx022a_info = { static int kx022a_set_drdy_irq(struct kx022a_data *data, bool en) { if (en) - return regmap_set_bits(data->regmap, KX022A_REG_CNTL, + return regmap_set_bits(data->regmap, data->chip_info->cntl, KX022A_MASK_DRDY); - return regmap_clear_bits(data->regmap, KX022A_REG_CNTL, + return regmap_clear_bits(data->regmap, data->chip_info->cntl, KX022A_MASK_DRDY); } @@ -759,7 +759,7 @@ static int kx022a_fifo_disable(struct kx022a_data *data) if (ret) goto unlock_out; - ret = regmap_clear_bits(data->regmap, KX022A_REG_BUF_CNTL2, + ret = regmap_clear_bits(data->regmap, data->chip_info->buf_cntl2, KX022A_MASK_BUF_EN); if (ret) goto unlock_out; @@ -768,6 +768,8 @@ static int kx022a_fifo_disable(struct kx022a_data *data) kx022a_drop_fifo_contents(data); + kfree(data->fifo_buffer); + return kx022a_turn_on_unlock(data); unlock_out: @@ -790,6 +792,12 @@ static int kx022a_fifo_enable(struct kx022a_data *data) { int ret; + data->fifo_buffer = kmalloc_array(data->chip_info->fifo_length, + KX022A_FIFO_SAMPLES_SIZE_BYTES, + GFP_KERNEL); + if (!data->fifo_buffer) + return -ENOMEM; + ret = kx022a_turn_off_lock(data); if (ret) return ret; @@ -800,7 +808,7 @@ static int kx022a_fifo_enable(struct kx022a_data *data) goto unlock_out; /* Enable buffer */ - ret = regmap_set_bits(data->regmap, KX022A_REG_BUF_CNTL2, + ret = regmap_set_bits(data->regmap, data->chip_info->buf_cntl2, KX022A_MASK_BUF_EN); if (ret) goto unlock_out; @@ -846,7 +854,7 @@ static irqreturn_t kx022a_trigger_handler(int irq, void *p) struct kx022a_data *data = iio_priv(idev); int ret; - ret = regmap_bulk_read(data->regmap, KX022A_REG_XOUT_L, data->buffer, + ret = regmap_bulk_read(data->regmap, data->chip_info->xout_l, data->buffer, KX022A_FIFO_SAMPLES_SIZE_BYTES); if (ret < 0) goto err_read; @@ -894,7 +902,7 @@ static irqreturn_t kx022a_irq_thread_handler(int irq, void *private) if (data->state & KX022A_STATE_FIFO) { int ok; - ok = __kx022a_fifo_flush(idev, KX022A_FIFO_LENGTH, true); + ok = __kx022a_fifo_flush(idev, data->chip_info->fifo_length, true); if (ok > 0) ret = IRQ_HANDLED; } @@ -947,7 +955,7 @@ static int kx022a_chip_init(struct kx022a_data *data) int ret, val; /* Reset the senor */ - ret = regmap_write(data->regmap, KX022A_REG_CNTL2, KX022A_MASK_SRST); + ret = regmap_write(data->regmap, data->chip_info->cntl2, KX022A_MASK_SRST); if (ret) return ret; @@ -957,7 +965,7 @@ static int kx022a_chip_init(struct kx022a_data *data) */ msleep(1); - ret = regmap_read_poll_timeout(data->regmap, KX022A_REG_CNTL2, val, + ret = regmap_read_poll_timeout(data->regmap, data->chip_info->cntl2, val, !(val & KX022A_MASK_SRST), KX022A_SOFT_RESET_WAIT_TIME_US, KX022A_SOFT_RESET_TOTAL_WAIT_TIME_US); @@ -967,14 +975,14 @@ static int kx022a_chip_init(struct kx022a_data *data) return ret; } - ret = regmap_reinit_cache(data->regmap, &kx022a_regmap); + ret = regmap_reinit_cache(data->regmap, data->chip_info->regmap_config); if (ret) { dev_err(data->dev, "Failed to reinit reg cache\n"); return ret; } /* set data res 16bit */ - ret = regmap_set_bits(data->regmap, KX022A_REG_BUF_CNTL2, + ret = regmap_set_bits(data->regmap, data->chip_info->buf_cntl2, KX022A_MASK_BRES16); if (ret) { dev_err(data->dev, "Failed to set data resolution\n"); @@ -984,7 +992,31 @@ static int kx022a_chip_init(struct kx022a_data *data) return kx022a_prepare_irq_pin(data); } -int kx022a_probe_internal(struct device *dev) +const struct kx022a_chip_info kx022a_chip_info = { + .name = "kx022-accel", + .regmap_config = &kx022a_regmap_config, + .channels = kx022a_channels, + .num_channels = ARRAY_SIZE(kx022a_channels), + .fifo_length = KX022A_FIFO_LENGTH, + .who = KX022A_REG_WHO, + .id = KX022A_ID, + .cntl = KX022A_REG_CNTL, + .cntl2 = KX022A_REG_CNTL2, + .odcntl = KX022A_REG_ODCNTL, + .buf_cntl1 = KX022A_REG_BUF_CNTL1, + .buf_cntl2 = KX022A_REG_BUF_CNTL2, + .buf_clear = KX022A_REG_BUF_CLEAR, + .buf_status1 = KX022A_REG_BUF_STATUS_1, + .buf_read = KX022A_REG_BUF_READ, + .inc1 = KX022A_REG_INC1, + .inc4 = KX022A_REG_INC4, + .inc5 = KX022A_REG_INC5, + .inc6 = KX022A_REG_INC6, + .xout_l = KX022A_REG_XOUT_L, +}; +EXPORT_SYMBOL_NS_GPL(kx022a_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"}; struct iio_trigger *indio_trig; @@ -1011,6 +1043,7 @@ int kx022a_probe_internal(struct device *dev) return -ENOMEM; data = iio_priv(idev); + data->chip_info = chip_info; /* * VDD is the analog and digital domain voltage supply and @@ -1021,24 +1054,24 @@ int kx022a_probe_internal(struct device *dev) if (ret && ret != -ENODEV) return dev_err_probe(dev, ret, "failed to enable regulator\n"); - ret = regmap_read(regmap, KX022A_REG_WHO, &chip_id); + ret = regmap_read(regmap, chip_info->who, &chip_id); if (ret) return dev_err_probe(dev, ret, "Failed to access sensor\n"); - if (chip_id != KX022A_ID) + if (chip_id != chip_info->id) dev_warn(dev, "unknown device 0x%x\n", chip_id); irq = fwnode_irq_get_byname(fwnode, "INT1"); if (irq > 0) { - data->inc_reg = KX022A_REG_INC1; - data->ien_reg = KX022A_REG_INC4; + data->inc_reg = chip_info->inc1; + data->ien_reg = chip_info->inc4; } else { irq = fwnode_irq_get_byname(fwnode, "INT2"); if (irq < 0) return dev_err_probe(dev, irq, "No suitable IRQ\n"); - data->inc_reg = KX022A_REG_INC5; - data->ien_reg = KX022A_REG_INC6; + data->inc_reg = chip_info->inc5; + data->ien_reg = chip_info->inc6; } data->regmap = regmap; @@ -1047,9 +1080,9 @@ int kx022a_probe_internal(struct device *dev) data->odr_ns = KX022A_DEFAULT_PERIOD_NS; mutex_init(&data->mutex); - idev->channels = kx022a_channels; - idev->num_channels = ARRAY_SIZE(kx022a_channels); - idev->name = "kx022-accel"; + idev->channels = chip_info->channels; + idev->num_channels = chip_info->num_channels; + idev->name = chip_info->name; idev->info = &kx022a_info; idev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE; idev->available_scan_masks = kx022a_scan_masks; diff --git a/drivers/iio/accel/kionix-kx022a.h b/drivers/iio/accel/kionix-kx022a.h index 12424649d438..0e5026019213 100644 --- a/drivers/iio/accel/kionix-kx022a.h +++ b/drivers/iio/accel/kionix-kx022a.h @@ -76,7 +76,55 @@ struct device; -int kx022a_probe_internal(struct device *dev); -extern const struct regmap_config kx022a_regmap; +/** + * struct kx022a_chip_info - Kionix accelerometer chip specific information + * + * @name: name of the device + * @regmap_config: pointer to register map configuration + * @channels: pointer to iio_chan_spec array + * @num_channels: number of iio_chan_spec channels + * @fifo_length: number of 16-bit samples in a full buffer + * @who: WHO_AM_I register + * @id: WHO_AM_I register value + * @cntl: control register 1 + * @cntl2: control register 2 + * @odcntl: output data control register + * @buf_cntl1: buffer control register 1 + * @buf_cntl2: buffer control register 2 + * @buf_clear: buffer clear register + * @buf_status1: buffer status register 1 + * @buf_read: buffer read register + * @inc1: interrupt control register 1 + * @inc4: interrupt control register 4 + * @inc5: interrupt control register 5 + * @inc6: interrupt control register 6 + * @xout_l: x-axis output least significant byte + */ +struct kx022a_chip_info { + const char *name; + const struct regmap_config *regmap_config; + const struct iio_chan_spec *channels; + unsigned int num_channels; + unsigned int fifo_length; + u8 who; + u8 id; + u8 cntl; + u8 cntl2; + u8 odcntl; + u8 buf_cntl1; + u8 buf_cntl2; + u8 buf_clear; + u8 buf_status1; + u8 buf_read; + u8 inc1; + u8 inc4; + u8 inc5; + u8 inc6; + u8 xout_l; +}; + +int kx022a_probe_internal(struct device *dev, const struct kx022a_chip_info *chip_info); + +extern const struct kx022a_chip_info kx022a_chip_info; #endif From patchwork Sat Sep 16 12:38:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mehdi Djait X-Patchwork-Id: 13388361 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 A59D8CD37BD for ; Sat, 16 Sep 2023 12:40:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239172AbjIPMjv (ORCPT ); Sat, 16 Sep 2023 08:39:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239241AbjIPMjW (ORCPT ); Sat, 16 Sep 2023 08:39:22 -0400 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3CA1CF1; Sat, 16 Sep 2023 05:39:15 -0700 (PDT) Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2b703a0453fso50225871fa.3; Sat, 16 Sep 2023 05:39:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694867954; x=1695472754; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mj0S4IUhwKpm57k81UJh3FEAAmf45N8dx0cUdOy0h84=; b=SwQymvz72+L7um8VS20JF407Sg+WMxmAVOf97V9rkOzNVmu7a+gY382gVoCtYyy71H LnMm8xZ45zoc43fwDrWgiIc/egMzVTtO5oOzrnEXz9hDGyX6GJgiIQ4fl6V/cs6DW3Mc 2ay/QTJe+JAEW2C3IIGX8w7gJoqwK9RCu7gE/tZxqQVj6n3gQQ+MksUICK8YRIADdYgi hM1DeX9ICb/ymtDhby2mKQNcqzvsAcCJSdO610dP2MgNBkYEAEWk+OHr/1ubB25pn/NF seSO2OmkP1bZXQkJiAOZ4LP3TOJc4FLws1JtzqbdfJi8/16FteQJX9siLlEAjls4Gzld PoZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694867954; x=1695472754; 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=mj0S4IUhwKpm57k81UJh3FEAAmf45N8dx0cUdOy0h84=; b=LalrCoosV/xEMiDU74XujkgVNKTSwLBDleisnfZEonGinMrsfQspWv4ovnD8/gRVEn 5bXcIY8WfyFHU4+/s3uCsyNII3CQRgGfmrJs3Pm8km5LP5u+9VUDvJ/J3rhj0S38v98A n8SP8h90NrCvvEX5YV+KgaPoJu95uG6mxBW4RKpExyMSU+4MWHkFNws3X8AoXYsjKyJO RtIxKrqrZKfiyjtADHTTEOkr670iIPrwceBWP736ecPpSuEIwmHGzfiMCNouGtPTu474 5aY9pRuwEnX1VlWNNxe4LGSzaYH1iJrZsx92rSQnNngNNRStfXxUDjabaXkCa0bUJKqQ EQyw== X-Gm-Message-State: AOJu0YwRO6W98RDC/xnIBDGN9C2z43XOLywdhgUBFoPd/ee/9n77thw6 7/Yi+Rs+JDFJ00Mw/sLzI0ZO9xoWxskC8Q== X-Google-Smtp-Source: AGHT+IGj462tn+kYa6mnbmyhKe/vs8cE9HX/9bQ8DzXGvyzB7fNvA3hHUFOWswr9WHzVW3MwU/9tMg== X-Received: by 2002:ac2:58e2:0:b0:4fe:8c07:98eb with SMTP id v2-20020ac258e2000000b004fe8c0798ebmr3479948lfo.51.1694867953910; Sat, 16 Sep 2023 05:39:13 -0700 (PDT) Received: from localhost.localdomain ([77.134.181.150]) by smtp.gmail.com with ESMTPSA id bo6-20020a0564020b2600b0052284228e3bsm3474064edb.8.2023.09.16.05.39.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 05:39:13 -0700 (PDT) From: Mehdi Djait To: jic23@kernel.org, mazziesaccount@gmail.com Cc: krzysztof.kozlowski+dt@linaro.org, andriy.shevchenko@linux.intel.com, robh+dt@kernel.org, lars@metafoo.de, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Mehdi Djait Subject: [PATCH v9 6/7] iio: accel: kionix-kx022a: Add a function to retrieve number of bytes in buffer Date: Sat, 16 Sep 2023 14:38:52 +0200 Message-Id: <9c550fb28e34915d473e379f812c7753f7643bae.1694867379.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: linux-iio@vger.kernel.org Since Kionix accelerometers use various numbers of bits to report data, a device-specific function is required. Implement the function as a callback in the device-specific chip_info structure Reviewed-by: Matti Vaittinen Signed-off-by: Mehdi Djait --- drivers/iio/accel/kionix-kx022a.c | 68 +++++++++++++++++-------------- drivers/iio/accel/kionix-kx022a.h | 46 ++++++++++++--------- 2 files changed, 64 insertions(+), 50 deletions(-) diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c index ab3e5c8a19df..cc7134b1183b 100644 --- a/drivers/iio/accel/kionix-kx022a.c +++ b/drivers/iio/accel/kionix-kx022a.c @@ -585,26 +585,33 @@ static int kx022a_drop_fifo_contents(struct kx022a_data *data) return regmap_write(data->regmap, data->chip_info->buf_clear, 0x0); } +static int kx022a_get_fifo_bytes_available(struct kx022a_data *data) +{ + int ret, fifo_bytes; + + ret = regmap_read(data->regmap, KX022A_REG_BUF_STATUS_1, &fifo_bytes); + if (ret) { + dev_err(data->dev, "Error reading buffer status\n"); + return ret; + } + + if (fifo_bytes == KX022A_FIFO_FULL_VALUE) + return KX022A_FIFO_MAX_BYTES; + + return fifo_bytes; +} + static int __kx022a_fifo_flush(struct iio_dev *idev, unsigned int samples, bool irq) { struct kx022a_data *data = iio_priv(idev); - struct device *dev = regmap_get_device(data->regmap); uint64_t sample_period; int count, fifo_bytes; bool renable = false; int64_t tstamp; int ret, i; - ret = regmap_read(data->regmap, KX022A_REG_BUF_STATUS_1, &fifo_bytes); - if (ret) { - dev_err(dev, "Error reading buffer status\n"); - return ret; - } - - /* Let's not overflow if we for some reason get bogus value from i2c */ - if (fifo_bytes == KX022A_FIFO_FULL_VALUE) - fifo_bytes = KX022A_FIFO_MAX_BYTES; + fifo_bytes = data->chip_info->get_fifo_bytes_available(data); if (fifo_bytes % KX022A_FIFO_SAMPLES_SIZE_BYTES) dev_warn(data->dev, "Bad FIFO alignment. Data may be corrupt\n"); @@ -993,26 +1000,27 @@ static int kx022a_chip_init(struct kx022a_data *data) } const struct kx022a_chip_info kx022a_chip_info = { - .name = "kx022-accel", - .regmap_config = &kx022a_regmap_config, - .channels = kx022a_channels, - .num_channels = ARRAY_SIZE(kx022a_channels), - .fifo_length = KX022A_FIFO_LENGTH, - .who = KX022A_REG_WHO, - .id = KX022A_ID, - .cntl = KX022A_REG_CNTL, - .cntl2 = KX022A_REG_CNTL2, - .odcntl = KX022A_REG_ODCNTL, - .buf_cntl1 = KX022A_REG_BUF_CNTL1, - .buf_cntl2 = KX022A_REG_BUF_CNTL2, - .buf_clear = KX022A_REG_BUF_CLEAR, - .buf_status1 = KX022A_REG_BUF_STATUS_1, - .buf_read = KX022A_REG_BUF_READ, - .inc1 = KX022A_REG_INC1, - .inc4 = KX022A_REG_INC4, - .inc5 = KX022A_REG_INC5, - .inc6 = KX022A_REG_INC6, - .xout_l = KX022A_REG_XOUT_L, + .name = "kx022-accel", + .regmap_config = &kx022a_regmap_config, + .channels = kx022a_channels, + .num_channels = ARRAY_SIZE(kx022a_channels), + .fifo_length = KX022A_FIFO_LENGTH, + .who = KX022A_REG_WHO, + .id = KX022A_ID, + .cntl = KX022A_REG_CNTL, + .cntl2 = KX022A_REG_CNTL2, + .odcntl = KX022A_REG_ODCNTL, + .buf_cntl1 = KX022A_REG_BUF_CNTL1, + .buf_cntl2 = KX022A_REG_BUF_CNTL2, + .buf_clear = KX022A_REG_BUF_CLEAR, + .buf_status1 = KX022A_REG_BUF_STATUS_1, + .buf_read = KX022A_REG_BUF_READ, + .inc1 = KX022A_REG_INC1, + .inc4 = KX022A_REG_INC4, + .inc5 = KX022A_REG_INC5, + .inc6 = KX022A_REG_INC6, + .xout_l = KX022A_REG_XOUT_L, + .get_fifo_bytes_available = kx022a_get_fifo_bytes_available, }; EXPORT_SYMBOL_NS_GPL(kx022a_chip_info, IIO_KX022A); diff --git a/drivers/iio/accel/kionix-kx022a.h b/drivers/iio/accel/kionix-kx022a.h index 0e5026019213..7ca48e6f2c49 100644 --- a/drivers/iio/accel/kionix-kx022a.h +++ b/drivers/iio/accel/kionix-kx022a.h @@ -76,29 +76,34 @@ struct device; +struct kx022a_data; + /** * struct kx022a_chip_info - Kionix accelerometer chip specific information * - * @name: name of the device - * @regmap_config: pointer to register map configuration - * @channels: pointer to iio_chan_spec array - * @num_channels: number of iio_chan_spec channels - * @fifo_length: number of 16-bit samples in a full buffer - * @who: WHO_AM_I register - * @id: WHO_AM_I register value - * @cntl: control register 1 - * @cntl2: control register 2 - * @odcntl: output data control register - * @buf_cntl1: buffer control register 1 - * @buf_cntl2: buffer control register 2 - * @buf_clear: buffer clear register - * @buf_status1: buffer status register 1 - * @buf_read: buffer read register - * @inc1: interrupt control register 1 - * @inc4: interrupt control register 4 - * @inc5: interrupt control register 5 - * @inc6: interrupt control register 6 - * @xout_l: x-axis output least significant byte + * @name: name of the device + * @regmap_config: pointer to register map configuration + * @channels: pointer to iio_chan_spec array + * @num_channels: number of iio_chan_spec channels + * @fifo_length: number of 16-bit samples in a full buffer + * @who: WHO_AM_I register + * @id: WHO_AM_I register value + * @cntl: control register 1 + * @cntl2: control register 2 + * @odcntl: output data control register + * @buf_cntl1: buffer control register 1 + * @buf_cntl2: buffer control register 2 + * @buf_clear: buffer clear register + * @buf_status1: buffer status register 1 + * @buf_read: buffer read register + * @inc1: interrupt control register 1 + * @inc4: interrupt control register 4 + * @inc5: interrupt control register 5 + * @inc6: interrupt control register 6 + * @xout_l: x-axis output least significant byte + * @get_fifo_bytes_available: function pointer to get amount of acceleration + * data bytes currently stored in the sensor's FIFO + * buffer */ struct kx022a_chip_info { const char *name; @@ -121,6 +126,7 @@ struct kx022a_chip_info { u8 inc5; u8 inc6; u8 xout_l; + int (*get_fifo_bytes_available)(struct kx022a_data *); }; int kx022a_probe_internal(struct device *dev, const struct kx022a_chip_info *chip_info); From patchwork Sat Sep 16 12:38:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mehdi Djait X-Patchwork-Id: 13388363 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 C2428CD37BC for ; Sat, 16 Sep 2023 12:40:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239265AbjIPMjw (ORCPT ); Sat, 16 Sep 2023 08:39:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239249AbjIPMjY (ORCPT ); Sat, 16 Sep 2023 08:39:24 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C598CED; Sat, 16 Sep 2023 05:39:18 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-50300e9e75bso814641e87.1; Sat, 16 Sep 2023 05:39:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694867957; x=1695472757; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aIvTR78Gg1PPgLqvHiZjf3eT74tJdHxgcaMgCqHD5ZQ=; b=LUqzYOP7iWo4jQaexwNhai/82mCOjX3eaaT7F7aWMPWMKcnXPU5IWYGjr9SkQsQeOm Au0cuppgS99E2/Gd1LKfDVdwW2I6gSabeDWtRPu2zZdbULh2eymqiv8EOFhyCEc6AQnQ qNErfbq1exUHV2g0C6w2YAoj/eoGmnkUx/LBujPsV+vwIAt+NiTafoteDh4uW1djZKKH J3PHDlUv1aS1T+w/fVEGcmX1D4BQzM/K43tXP+8Il1hz5PjpPsAe6Rerv26F8ykS/Rmb /BhA5G2VfD5cq5Gxwd526ustAeCtOlM5pr+q9qvQ5LiKA0nnWFiYkzpKPpqmURUcgLLS 1Xiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694867957; x=1695472757; 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=aIvTR78Gg1PPgLqvHiZjf3eT74tJdHxgcaMgCqHD5ZQ=; b=exkclOyk2GyeBBR+MYKKAOn3CyLnNp0QfBqJrIAmzK0faRmWfG1BfUk1jWcHUkC0z1 U0y/JDDdf6JUoBD29A9d1ZF1onbAxyU9W/g117OJfI3TVcURM9nf1bQFe2t2E32ZwGZS qcZHtH8kQHxpc6wEnJFfAY2T3o1mmv5FttCzg8MbQBmbxz/QdSFpO/Q5KOVHnv804Mi2 8fa9i4kXH3H/NDqA7uCIWJiN+dri29zfLOg9XXSPSmazv/m7NPtIhscBa114hDlbP/nS 5GX/zFOSxYf+mNjuKntXUC1u1Uh3TCMIcbiTlui+p+riAdKNJrFcY5Fpp62esEvVD40O RmIQ== X-Gm-Message-State: AOJu0YzUHiUzH5IBkHFJwWgcsPolHPT0ot0uk8/I4UbDV5c6cvEzzR+p 6E7VND73i9qDULrZpD6c80c= X-Google-Smtp-Source: AGHT+IEOrN+Mdy8FrNcz0c64QEmsn51oPhGTtsO4HS+iNdvWM4WM2gQA7tgvINN8ADEQMaCh1kNz/A== X-Received: by 2002:a19:6714:0:b0:500:b8a3:1bf1 with SMTP id b20-20020a196714000000b00500b8a31bf1mr3521460lfc.43.1694867956622; Sat, 16 Sep 2023 05:39:16 -0700 (PDT) Received: from localhost.localdomain ([77.134.181.150]) by smtp.gmail.com with ESMTPSA id bo6-20020a0564020b2600b0052284228e3bsm3474064edb.8.2023.09.16.05.39.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 05:39:16 -0700 (PDT) From: Mehdi Djait To: jic23@kernel.org, mazziesaccount@gmail.com Cc: krzysztof.kozlowski+dt@linaro.org, andriy.shevchenko@linux.intel.com, robh+dt@kernel.org, lars@metafoo.de, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Mehdi Djait Subject: [PATCH v9 7/7] iio: accel: Add support for Kionix/ROHM KX132-1211 accelerometer Date: Sat, 16 Sep 2023 14:38:53 +0200 Message-Id: <389a7d6100ff2e71b1c5d60bebe662d09435996a.1694867379.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: linux-iio@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. Datasheet: https://kionixfs.azureedge.net/en/document/KX132-1211-Technical-Reference-Manual-Rev-5.0.pdf Acked-by: Matti Vaittinen Reviewed-by: Andy Shevchenko Signed-off-by: Mehdi Djait --- drivers/iio/accel/Kconfig | 10 +- drivers/iio/accel/kionix-kx022a-i2c.c | 2 + drivers/iio/accel/kionix-kx022a-spi.c | 2 + drivers/iio/accel/kionix-kx022a.c | 164 ++++++++++++++++++++++++++ drivers/iio/accel/kionix-kx022a.h | 54 +++++++++ 5 files changed, 228 insertions(+), 4 deletions(-) diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig index b6b45d359f28..373257d64a7e 100644 --- a/drivers/iio/accel/Kconfig +++ b/drivers/iio/accel/Kconfig @@ -418,8 +418,9 @@ 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 digital tri-axis accelerometers + connected to SPI interface. Supported devices are: + KX022A, KX132-1211 config IIO_KX022A_I2C tristate "Kionix KX022A tri-axis digital accelerometer I2C interface" @@ -427,8 +428,9 @@ 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 digital tri-axis accelerometers + connected to I2C interface. Supported devices are: + KX022A, KX132-1211 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 2fdc4c1ab93f..fc53e527cae0 100644 --- a/drivers/iio/accel/kionix-kx022a-i2c.c +++ b/drivers/iio/accel/kionix-kx022a-i2c.c @@ -37,12 +37,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 c21494ade157..e7878ba67827 100644 --- a/drivers/iio/accel/kionix-kx022a-spi.c +++ b/drivers/iio/accel/kionix-kx022a-spi.c @@ -37,12 +37,14 @@ static int kx022a_spi_probe(struct spi_device *spi) static const struct spi_device_id kx022a_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_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 cc7134b1183b..c5b555094e60 100644 --- a/drivers/iio/accel/kionix-kx022a.c +++ b/drivers/iio/accel/kionix-kx022a.c @@ -150,6 +150,117 @@ 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_CNTL5, + .range_max = KX132_REG_CNTL5, + }, { + .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, + }, { + /* Kionix reserved registers: should not be written */ + .range_min = 0x28, + .range_max = 0x28, + }, { + .range_min = 0x35, + .range_max = 0x36, + }, { + .range_min = 0x3c, + .range_max = 0x48, + }, { + .range_min = 0x4e, + .range_max = 0x5c, + }, { + .range_min = 0x77, + .range_max = 0x7f, + }, +}; + +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_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, +}; + struct kx022a_data { struct regmap *regmap; const struct kx022a_chip_info *chip_info; @@ -239,6 +350,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 @@ -601,6 +719,26 @@ static int kx022a_get_fifo_bytes_available(struct kx022a_data *data) return fifo_bytes; } +static int kx132_get_fifo_bytes_available(struct kx022a_data *data) +{ + __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(data->dev, "Error reading buffer status\n"); + return ret; + } + + fifo_bytes = le16_to_cpu(buf_status); + fifo_bytes &= data->chip_info->buf_smp_lvl_mask; + fifo_bytes = min((unsigned int)fifo_bytes, data->chip_info->fifo_length * + KX022A_FIFO_SAMPLES_SIZE_BYTES); + + return fifo_bytes; +} + static int __kx022a_fifo_flush(struct iio_dev *idev, unsigned int samples, bool irq) { @@ -1024,6 +1162,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_available = kx132_get_fifo_bytes_available, +}; +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 7ca48e6f2c49..35c548ae7eff 100644 --- a/drivers/iio/accel/kionix-kx022a.h +++ b/drivers/iio/accel/kionix-kx022a.h @@ -74,6 +74,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_REG_CNTL5 0x1f +#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_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; @@ -86,6 +137,7 @@ struct kx022a_data; * @channels: pointer to iio_chan_spec array * @num_channels: number of iio_chan_spec channels * @fifo_length: number of 16-bit samples in a full buffer + * @buf_smp_lvl_mask: buffer sample level mask * @who: WHO_AM_I register * @id: WHO_AM_I register value * @cntl: control register 1 @@ -111,6 +163,7 @@ struct kx022a_chip_info { const struct iio_chan_spec *channels; unsigned int num_channels; unsigned int fifo_length; + u16 buf_smp_lvl_mask; u8 who; u8 id; u8 cntl; @@ -132,5 +185,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