From patchwork Thu Jan 16 13:52:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasiliy Doylov via B4 Relay X-Patchwork-Id: 13941688 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6029F1DE4EC; Thu, 16 Jan 2025 13:53:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737035613; cv=none; b=t02k7uDotbLFlg71wngVEDQe8U1cwP2fz2heybTTeG7wQZXVmbr6QtJ895elwr/K5asI5yLYDnZrWlXTJNc5OCXNYsDLr3VNyf/ieIbvi+uxGDFxLFuRSDHOJYFbGMpLjBxvg2gdrH6xBw2h3Po8q9YeWDTwCp7ZBVYMXgyxRy4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737035613; c=relaxed/simple; bh=y4ngFRv0AOBNbmFrZkhBTx2rszuk5J+ukbqnUzzOgZM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pcFDvUYgaHCXQsmnF3pk6klfGH5JisIA+n+dlk8SUAFM5D47zDKb+DpZGYD1th7loK1zNbh3jVogyHDTebBoWk5XZ0tJNIFwTtacUVvndWjKGzs9I+lN96QHKqx6E/2zuHUO5tSCRFslO96OW+gyZeaAVa8gw3+D863Rlfu0Fmc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RVwJRB1b; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RVwJRB1b" Received: by smtp.kernel.org (Postfix) with ESMTPS id 07A01C4CEE1; Thu, 16 Jan 2025 13:53:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737035613; bh=y4ngFRv0AOBNbmFrZkhBTx2rszuk5J+ukbqnUzzOgZM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=RVwJRB1bqkNop3aZ96xu0OCDb3Z8x0jcEgIs/37iySndhKPh/WeDbJObEliTgTfzT XPh3wKhbRecPTTC6vAjZampZO1TfqVl1AAlNBL/8gueBB0v+8oU0nRcRKZj9DTPx58 RyJqZjo76q5vpJvI7DDGCdkc3SaneIDhIH6aDnc9h9kLuukUIGRZnLqCtUH198ogpu rzow+dPqokytsEjpSkINQQPWlGTegL1Wzhz29fuIJXtPdVDmBNRlAIcDHsVwslexez 0hBbXQRzRLvHDhoMCEp4fmMmn7MOV5kndY/eAeXa/L53A/vdyBJloTy9kPdXZcrIZx wZSBzwh6VJSzg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E944DC02188; Thu, 16 Jan 2025 13:53:32 +0000 (UTC) From: Vasiliy Doylov via B4 Relay Date: Thu, 16 Jan 2025 16:52:42 +0300 Subject: [PATCH RESEND v4 1/5] dt-bindings: iio: accel: mc3230: document mc3510c Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250116-mainlining-mc3510c-v4-1-a41308b85ec2@gmail.com> References: <20250116-mainlining-mc3510c-v4-0-a41308b85ec2@gmail.com> In-Reply-To: <20250116-mainlining-mc3510c-v4-0-a41308b85ec2@gmail.com> To: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Vasiliy Doylov , Krzysztof Kozlowski X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1123; i=nekodevelopper@gmail.com; h=from:subject:message-id; bh=QPSsNqso95qPWrSIr5ihfDk9Bwjnpi3oQpu3J2o7Ics=; b=owGbwMvMwCW2fZ/SFZeSpU2Mp9WSGNI7+aPKls1232xRVLHyhqT5e94uFkMG/0zPy8eu9f89q PFoUm1oRykLgxgXg6yYIovNRo/ZYvnhkpOmPVWAmcPKBDKEgYtTACbi94mRYd/aIO2a01/azsjy XeEUO7TROfHrqWiTk3MV857c8Z7bMZvhf/D1GvU3xzOt/ktFfT95KsyvmiNdZPK34q79jU8/RXA 3cAEA X-Developer-Key: i=nekodevelopper@gmail.com; a=openpgp; fpr=3CB1489B166F57199296E520B7BE22D44474A582 X-Endpoint-Received: by B4 Relay for nekodevelopper@gmail.com/default with auth_id=314 X-Original-From: Vasiliy Doylov Reply-To: nekodevelopper@gmail.com From: Vasiliy Doylov The MC3510C is a 3 asix digital accelerometer. It handled by the same driver as MC3230. Document it as a trivial device. Acked-by: Krzysztof Kozlowski Signed-off-by: Vasiliy Doylov --- Documentation/devicetree/bindings/trivial-devices.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/trivial-devices.yaml b/Documentation/devicetree/bindings/trivial-devices.yaml index fadbd3c041c8c39faedfe62874d4eba25a0bf30e..6c34e4c0dcc6df5a4d8edc5effb80980de820db9 100644 --- a/Documentation/devicetree/bindings/trivial-devices.yaml +++ b/Documentation/devicetree/bindings/trivial-devices.yaml @@ -187,6 +187,8 @@ properties: - maxim,max6621 # mCube 3-axis 8-bit digital accelerometer - mcube,mc3230 + # mCube 3-axis 8-bit digital accelerometer + - mcube,mc3510c # Measurement Specialities I2C temperature and humidity sensor - meas,htu21 # Measurement Specialities I2C pressure and temperature sensor From patchwork Thu Jan 16 13:52:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasiliy Doylov via B4 Relay X-Patchwork-Id: 13941690 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 601B46DCE1; Thu, 16 Jan 2025 13:53:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737035613; cv=none; b=Pq0bjLPfJ/7OcFE4ssf0lghRAw2V0dL6r9r6yUmyKwJT2OZXvPcUkXJrSG5SX4XmQNOJ57siGWtxWv21zkOuELyvbgqq4hhdOQN5e7cL0jnqaRoIlOR5cVRG9G1vuEJ9SsH8QDRE27x6jZH90h/69QGbH5C9Lmg33ibqQD2YQCI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737035613; c=relaxed/simple; bh=2oIyvdA5lqjySX8l2Deg9R7DWN66uRbrlcnGgKpRqro=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KgLd7vDHwkY6pA8LXkKIWRFsOjNj6Bb/B4saROMrPhQUyQ/tALJd0QmcMLWftNa0CysxusQ0K2dzVqOscozbZXQuRJqIiG3RNiU90sqPR/1oRPNc87vnzwCArw/VQe1ZUfd3k07qmetM2LAD5uQ4WICHDKUDVZ2kEG/QjCWn3uM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FkQgmyX5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FkQgmyX5" Received: by smtp.kernel.org (Postfix) with ESMTPS id 13A82C4CEE3; Thu, 16 Jan 2025 13:53:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737035613; bh=2oIyvdA5lqjySX8l2Deg9R7DWN66uRbrlcnGgKpRqro=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=FkQgmyX5ItERGbpLd00fINs0tH6w1wNr1mT/AmUD6Wvjzo3laO0FVXVa4OEckqBpr A+F+oQngm/hTtvgYQpSLR7JkmuDYdh9yyIBpE8bGb9I0evu4WK9dvC3qkYwjLUoTtU oWrFyogu783E5UwIFt3JutTwOXGaBJenVDR9qnZtVQ9JavjtacH06Xp4TiBNzxYYkQ p9WIbEKWku0d19xBYEjlUVishBO5oeva68TdVIe1EryoAJNhf7IQpZsbQXjMgX9Kh4 POc7BP+Q2aYrUNGNA8JpzdwVF1mCY0mMCY/AeKeZVz+WJuX2VkK6YCurEk7Lrv4zhR eCU2OqWjjhoqQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0479DC0218A; Thu, 16 Jan 2025 13:53:33 +0000 (UTC) From: Vasiliy Doylov via B4 Relay Date: Thu, 16 Jan 2025 16:52:43 +0300 Subject: [PATCH RESEND v4 2/5] iio: accel: mc3230: add mount matrix support Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250116-mainlining-mc3510c-v4-2-a41308b85ec2@gmail.com> References: <20250116-mainlining-mc3510c-v4-0-a41308b85ec2@gmail.com> In-Reply-To: <20250116-mainlining-mc3510c-v4-0-a41308b85ec2@gmail.com> To: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Vasiliy Doylov X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1923; i=nekodevelopper@gmail.com; h=from:subject:message-id; bh=d1xov0qHxHQE7DYG5yJ4wuLkWhZ9BJAbb56t/my19Lo=; b=owGbwMvMwCW2fZ/SFZeSpU2Mp9WSGNI7+aNeRk6+etuiRaS3h7PIomXOnduf2J4b8shpmkeH3 4t4lrC/o5SFQYyLQVZMkcVmo8dssfxwyUnTnirAzGFlAhnCwMUpABN5k8Twv3jqYmetEJtHX/oU lnw9whdpHl1SpXV9rsKVWXx/fZrnfWX4p/pwycFwYYtZ13yuabqKHDrB/p7h2NEnDEKhm183KVt osgMA X-Developer-Key: i=nekodevelopper@gmail.com; a=openpgp; fpr=3CB1489B166F57199296E520B7BE22D44474A582 X-Endpoint-Received: by B4 Relay for nekodevelopper@gmail.com/default with auth_id=314 X-Original-From: Vasiliy Doylov Reply-To: nekodevelopper@gmail.com From: Vasiliy Doylov This patch allows to read a mount-matrix device tree property and report to user-space or in-kernel iio clients. Signed-off-by: Vasiliy Doylov --- drivers/iio/accel/mc3230.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/drivers/iio/accel/mc3230.c b/drivers/iio/accel/mc3230.c index caa40a14a6316acae3a972f0ebe0b325db96eb44..48787c0494ae6f0ef1d4d22bc5a4608035cbe123 100644 --- a/drivers/iio/accel/mc3230.c +++ b/drivers/iio/accel/mc3230.c @@ -44,18 +44,34 @@ static const int mc3230_nscale = 115411765; .channel2 = IIO_MOD_##axis, \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ + .ext_info = mc3230_ext_info, \ } +struct mc3230_data { + struct i2c_client *client; + struct iio_mount_matrix orientation; +}; + +static const struct iio_mount_matrix * +mc3230_get_mount_matrix(const struct iio_dev *indio_dev, + const struct iio_chan_spec *chan) +{ + struct mc3230_data *data = iio_priv(indio_dev); + + return &data->orientation; +} + +static const struct iio_chan_spec_ext_info mc3230_ext_info[] = { + IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, mc3230_get_mount_matrix), + { } +}; + static const struct iio_chan_spec mc3230_channels[] = { MC3230_CHANNEL(MC3230_REG_XOUT, X), MC3230_CHANNEL(MC3230_REG_YOUT, Y), MC3230_CHANNEL(MC3230_REG_ZOUT, Z), }; -struct mc3230_data { - struct i2c_client *client; -}; - static int mc3230_set_opcon(struct mc3230_data *data, int opcon) { int ret; @@ -141,6 +157,10 @@ static int mc3230_probe(struct i2c_client *client) if (ret < 0) return ret; + ret = iio_read_mount_matrix(&client->dev, &data->orientation); + if (ret) + return ret; + ret = iio_device_register(indio_dev); if (ret < 0) { dev_err(&client->dev, "device_register failed\n"); From patchwork Thu Jan 16 13:52:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasiliy Doylov via B4 Relay X-Patchwork-Id: 13941691 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 75FAE1DE8BC; Thu, 16 Jan 2025 13:53:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737035613; cv=none; b=nNmyczaq9C+H5GtRCVECQGgxNOjTKWV0CM8twPP4WR5dtsXBqCqh0cNKlZ2k3D4Rp+kuHePj6UNeHGdqu186RAUURKE42HAyPhQ0t9UlbrO9HiywpejM1+0hWExGvvxmlGmFCBMT+MvwdA1TWScYmFRdB+3kOlUFx0++eMqgEfI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737035613; c=relaxed/simple; bh=zTv1Z1EQPs9ebNg8jRjW1X2ohO4Uqa0O6o0M3vjRIZ4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qbTm8Y4YSq2vLUszFZXfrx36oy1j1N+9tgrxEjDFn7ka3XdMyEhq2dSjlkIO+BceQBT72zHwUqS2wrOMQvauna1wOTgIalDBDF547k2xSXRmdsOXSaBTojo2fL8wmuw01IVZM+I2Y4WNIk4Szt8hhmMh7S/OIaC2kWgnvj50NGA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=L4geFgHe; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="L4geFgHe" Received: by smtp.kernel.org (Postfix) with ESMTPS id 1F330C4CEE6; Thu, 16 Jan 2025 13:53:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737035613; bh=zTv1Z1EQPs9ebNg8jRjW1X2ohO4Uqa0O6o0M3vjRIZ4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=L4geFgHe58rK/tXhEJZEN+SH0V7eFPuMeYdsl/n495bzxey92sXuTQCmASo1Y8jBJ ww67smRIHdUmvwU5/KwqsqfAOhqWIx96UlVbACVrGZtCjmj6SxyZjee4RoN6hQsm+L FVwIe1KinpeS9oZFxCksN9Ft/9o3UZzKXC0hIKSOTvIFtIs/QtpMNq+p4SnefPCMSk Xfc+caWREDS639vmYjAwOM420surtsw3n9c9zTVVVf5FIeVw+7OjWS16lvQqNMn5c3 jV1Oc6Zck0wu3pK7oNHWxfOc/JFQIvy5GtHaMgGytHtd3chs68ug7H5NWtcrgpcm6K z6siVD1EQFybQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14E4BC02187; Thu, 16 Jan 2025 13:53:33 +0000 (UTC) From: Vasiliy Doylov via B4 Relay Date: Thu, 16 Jan 2025 16:52:44 +0300 Subject: [PATCH RESEND v4 3/5] iio: accel: mc3230: add OF match table Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250116-mainlining-mc3510c-v4-3-a41308b85ec2@gmail.com> References: <20250116-mainlining-mc3510c-v4-0-a41308b85ec2@gmail.com> In-Reply-To: <20250116-mainlining-mc3510c-v4-0-a41308b85ec2@gmail.com> To: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Vasiliy Doylov X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=922; i=nekodevelopper@gmail.com; h=from:subject:message-id; bh=Eg7uHGOE8j/UlALdyIln75Y0DBThMlnXhDZzImwRew8=; b=owGbwMvMwCW2fZ/SFZeSpU2Mp9WSGNI7+aNrtu8PdDjAGj3vxqWZ3yKLm320nptcZHpQ8nt/O OMpBWaujlIWBjEuBlkxRRabjR6zxfLDJSdNe6oAM4eVCWQIAxenAEzk8lJGhncfk978aZnKN/82 15xpP9pFNtwJm//22fezPaf2Sk1b187OyHDCZcKUOR8vX90QxlFzr1NyT6q91MKDx+3/an7gviK /cRkHAA== X-Developer-Key: i=nekodevelopper@gmail.com; a=openpgp; fpr=3CB1489B166F57199296E520B7BE22D44474A582 X-Endpoint-Received: by B4 Relay for nekodevelopper@gmail.com/default with auth_id=314 X-Original-From: Vasiliy Doylov Reply-To: nekodevelopper@gmail.com From: Vasiliy Doylov This will make the driver auto loaded via device-tree. Signed-off-by: Vasiliy Doylov --- drivers/iio/accel/mc3230.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/iio/accel/mc3230.c b/drivers/iio/accel/mc3230.c index 48787c0494ae6f0ef1d4d22bc5a4608035cbe123..443b5b30c83144478c27a86dbdc12e4e944a34df 100644 --- a/drivers/iio/accel/mc3230.c +++ b/drivers/iio/accel/mc3230.c @@ -205,9 +205,16 @@ static const struct i2c_device_id mc3230_i2c_id[] = { }; MODULE_DEVICE_TABLE(i2c, mc3230_i2c_id); +static const struct of_device_id mc3230_of_match[] = { + { .compatible = "mcube,mc3230" }, + { } +}; +MODULE_DEVICE_TABLE(of, mc3230_of_match); + static struct i2c_driver mc3230_driver = { .driver = { .name = "mc3230", + .of_match_table = mc3230_of_match, .pm = pm_sleep_ptr(&mc3230_pm_ops), }, .probe = mc3230_probe, From patchwork Thu Jan 16 13:52:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasiliy Doylov via B4 Relay X-Patchwork-Id: 13941692 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8BD4B22A81E; Thu, 16 Jan 2025 13:53:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737035613; cv=none; b=tWqxxyGj8JN5tvBL9/B4/F24iuAH6I75H3Z7qdtueXr+vdXLlDXqnjXszop6bzRxCz+u735Kv3X61GDuAyAGpTqXskkWoVZBn7O+HoUblpmmKwjgoUtIPHsQqLrRx/lz0BgkaYaPDGyIj3iRAV7qdXKt/YLAie5+IiEl4mGbXg4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737035613; c=relaxed/simple; bh=GHBGvpnYHAvgR5QdMdS42bx3vhlkuBWS2kC6em2zrsk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VXvlGee9tRF1ddvcteMQOwsNiSejq7BTtwV21EqKD6f1qQaxowI9U9fbFT/jxERY8iY6ZDXnVOyFqx0jHDLNFUt5M7oiBd4sA7igkU6Gi4hpwpke5gMyFd/HpDi/Ly/xFgOf9+GUfIid6tt32pmPt0X9wjlnVO2XXybMxhRWko0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OWisEzyN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OWisEzyN" Received: by smtp.kernel.org (Postfix) with ESMTPS id 33515C4CEE9; Thu, 16 Jan 2025 13:53:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737035613; bh=GHBGvpnYHAvgR5QdMdS42bx3vhlkuBWS2kC6em2zrsk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=OWisEzyNorzzryo4vVPv6UWHfVLZZyeHiWs1EIruBYqU08YQEYk0CV4EpFrWfNOIm gAXOVpsM+7b0T5dmNPYV7yGb3QmzV6LSXfbeK6HCCUWWHWEYGN3jdOLyUHzKNbQrQv l3v5rfcP1OgKnanXZJhf+r7FI8Rv8zLL4nOp4V5gK9pKZIPPYkp3TfqyufWdTA4TQG YxAwLws3FPy8e71zMbMOC22p6XZ3QgGvAriT0wVFAmHDy/DcJBphgCt6nplHlt+TYC atpr3FxuSbRi33m/JlhcM47EX5qdAbhCor9SibKKyUTsaDg5udZ0whKc8LI4KNvuDt 2K9xMmsDwmhdg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26471C0218B; Thu, 16 Jan 2025 13:53:33 +0000 (UTC) From: Vasiliy Doylov via B4 Relay Date: Thu, 16 Jan 2025 16:52:45 +0300 Subject: [PATCH RESEND v4 4/5] iio: accel: mc3230: add multiple devices support Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250116-mainlining-mc3510c-v4-4-a41308b85ec2@gmail.com> References: <20250116-mainlining-mc3510c-v4-0-a41308b85ec2@gmail.com> In-Reply-To: <20250116-mainlining-mc3510c-v4-0-a41308b85ec2@gmail.com> To: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Vasiliy Doylov X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3965; i=nekodevelopper@gmail.com; h=from:subject:message-id; bh=u0GLxDIqXOpHS5sTxKMtGQzMSlmbBkvPdn0nmTqe/ag=; b=owGbwMvMwCW2fZ/SFZeSpU2Mp9WSGNI7+aOL5z9d1jStdPX2v6v2LHAzXH8sMFpMZWVY5Z56D ya/I3/6O0pZGMS4GGTFFFlsNnrMFssPl5w07akCzBxWJpAhDFycAjARqZuMDIdO3+Q47x8u/3tX RNqOhUr5LOHC/IXPdqS4Hdtialca+52RYdcZgaQL3heOpPInKe+7Uhpgw7dD3f1xzmuRSXHP0sx u8QAA X-Developer-Key: i=nekodevelopper@gmail.com; a=openpgp; fpr=3CB1489B166F57199296E520B7BE22D44474A582 X-Endpoint-Received: by B4 Relay for nekodevelopper@gmail.com/default with auth_id=314 X-Original-From: Vasiliy Doylov Reply-To: nekodevelopper@gmail.com From: Vasiliy Doylov Refactor code to support multiple generations of MCUBE devices by defining name, chip id and product code in mc3230_chip_info struct. Signed-off-by: Vasiliy Doylov --- drivers/iio/accel/mc3230.c | 52 +++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/drivers/iio/accel/mc3230.c b/drivers/iio/accel/mc3230.c index 443b5b30c83144478c27a86dbdc12e4e944a34df..c8d394c3ecf08fad60f0f2ae7be6fd992327d843 100644 --- a/drivers/iio/accel/mc3230.c +++ b/drivers/iio/accel/mc3230.c @@ -22,20 +22,29 @@ #define MC3230_MODE_OPCON_STANDBY 0x03 #define MC3230_REG_CHIP_ID 0x18 -#define MC3230_CHIP_ID 0x01 - #define MC3230_REG_PRODUCT_CODE 0x3b -#define MC3230_PRODUCT_CODE 0x19 /* * The accelerometer has one measurement range: * * -1.5g - +1.5g (8-bit, signed) * - * scale = (1.5 + 1.5) * 9.81 / (2^8 - 1) = 0.115411765 */ -static const int mc3230_nscale = 115411765; +struct mc3230_chip_info { + const char *name; + const u8 chip_id; + const u8 product_code; + const int scale; +}; + +static const struct mc3230_chip_info mc3230_chip_info = { + .name = "mc3230", + .chip_id = 0x01, + .product_code = 0x19, + /* (1.5 + 1.5) * 9.81 / (2^8 - 1) = 0.115411765 */ + .scale = 115411765, +}; #define MC3230_CHANNEL(reg, axis) { \ .type = IIO_ACCEL, \ @@ -48,6 +57,7 @@ static const int mc3230_nscale = 115411765; } struct mc3230_data { + const struct mc3230_chip_info *chip_info; struct i2c_client *client; struct iio_mount_matrix orientation; }; @@ -111,7 +121,7 @@ static int mc3230_read_raw(struct iio_dev *indio_dev, return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: *val = 0; - *val2 = mc3230_nscale; + *val2 = data->chip_info->scale; return IIO_VAL_INT_PLUS_NANO; default: return -EINVAL; @@ -127,15 +137,28 @@ static int mc3230_probe(struct i2c_client *client) int ret; struct iio_dev *indio_dev; struct mc3230_data *data; + const struct mc3230_chip_info *chip_info; + + chip_info = i2c_get_match_data(client); + if (chip_info == NULL) { + dev_err(&client->dev, "failed to get match data"); + return -ENODATA; + } /* First check chip-id and product-id */ ret = i2c_smbus_read_byte_data(client, MC3230_REG_CHIP_ID); - if (ret != MC3230_CHIP_ID) - return (ret < 0) ? ret : -ENODEV; + if (ret != chip_info->chip_id) { + dev_info(&client->dev, + "chip id check fail: 0x%x != 0x%x !\n", + ret, chip_info->chip_id); + } ret = i2c_smbus_read_byte_data(client, MC3230_REG_PRODUCT_CODE); - if (ret != MC3230_PRODUCT_CODE) - return (ret < 0) ? ret : -ENODEV; + if (ret != chip_info->product_code) { + dev_info(&client->dev, + "product code check fail: 0x%x != 0x%x !\n", + ret, chip_info->product_code); + } indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); if (!indio_dev) { @@ -144,11 +167,12 @@ static int mc3230_probe(struct i2c_client *client) } data = iio_priv(indio_dev); + data->chip_info = chip_info; data->client = client; i2c_set_clientdata(client, indio_dev); indio_dev->info = &mc3230_info; - indio_dev->name = "mc3230"; + indio_dev->name = chip_info->name; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->channels = mc3230_channels; indio_dev->num_channels = ARRAY_SIZE(mc3230_channels); @@ -200,13 +224,13 @@ static int mc3230_resume(struct device *dev) static DEFINE_SIMPLE_DEV_PM_OPS(mc3230_pm_ops, mc3230_suspend, mc3230_resume); static const struct i2c_device_id mc3230_i2c_id[] = { - { "mc3230" }, - {} + { "mc3230", (kernel_ulong_t)&mc3230_chip_info }, + { } }; MODULE_DEVICE_TABLE(i2c, mc3230_i2c_id); static const struct of_device_id mc3230_of_match[] = { - { .compatible = "mcube,mc3230" }, + { .compatible = "mcube,mc3230", &mc3230_chip_info }, { } }; MODULE_DEVICE_TABLE(of, mc3230_of_match); From patchwork Thu Jan 16 13:52:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasiliy Doylov via B4 Relay X-Patchwork-Id: 13941693 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1E1022AE75; Thu, 16 Jan 2025 13:53:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737035613; cv=none; b=ApY3HhK6jIfWTcM2zi0gQMLnD1IsdQrCVbTJPomPZC4Jr5snERwjJHw3TLHeGUJjOWcvIwPOGFGMHwjFbbC5ne4J7qotVNMKL3oYh3hIPYHejS0p7UX8muMHtIPRH7bFAOlU9ZU20fZL9f4hCd8IJD2eO7BDSVE0Rr1u0WIFibA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737035613; c=relaxed/simple; bh=KZRoP5Cjgcq1f45YrvRYeCZ9m1rJx7lSPGLRnbbpDFo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uun6Pn4ZTJdoT++lM605mjsAVRTCXTQCc5yR7/fvJumMkmE0kNyFfobUzONEhAZ7ZP/qRVnA5Vo/P0yMub0JQV7A2BJOPFsjSbjfaRw3usQG43cUafMN9Ox3s1z80ZwvjwGKUPLYamBAJfeQs82uRxeC4XANfyWsHUzB4J49bWA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mblRpUOY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mblRpUOY" Received: by smtp.kernel.org (Postfix) with ESMTPS id 3DFBBC4CEE7; Thu, 16 Jan 2025 13:53:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737035613; bh=KZRoP5Cjgcq1f45YrvRYeCZ9m1rJx7lSPGLRnbbpDFo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=mblRpUOYEOqWYOSnuITNcxI4gut+S4GMtEBPsXPnnfU7UszxI0gowclFRYMXzgknm HXVy3pOaT0OZtr66SLZ5DUnupSVd5SeMouLxhd6GP6crmzHwppONRCK78WPRVi40OV UBOSow2mDH++s3WMM5w1mvkd1w+gsAuC9BzV6HU2moxPI5cWCjB6/u/38cnLK+zkPa eyvq+D5a9F0K2knvmWjEktkfnNF7ZkSlSypJlOJ1o4CtXtFOMtFOubXyPXquRSuU4o BaLCfjCcN3STT2FN5vUpgz4qF8247NRjMIGdqenzDTo6bTb8+YESnboViY1f+wHOE+ tS7i9oTRnwQ7g== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36004C02183; Thu, 16 Jan 2025 13:53:33 +0000 (UTC) From: Vasiliy Doylov via B4 Relay Date: Thu, 16 Jan 2025 16:52:46 +0300 Subject: [PATCH RESEND v4 5/5] iio: accel: mc3230: add mc3510c support Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250116-mainlining-mc3510c-v4-5-a41308b85ec2@gmail.com> References: <20250116-mainlining-mc3510c-v4-0-a41308b85ec2@gmail.com> In-Reply-To: <20250116-mainlining-mc3510c-v4-0-a41308b85ec2@gmail.com> To: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Vasiliy Doylov X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1524; i=nekodevelopper@gmail.com; h=from:subject:message-id; bh=9Z3q0OsDzL5ZwgOvYT7Efze32gsUcd3XbTfzqI4bFbA=; b=owGbwMvMwCW2fZ/SFZeSpU2Mp9WSGNI7+aOn5M9Vtetu2X/nb0/DoXDuDWe/3jxhnbnT3ODbK mOu+qupHaUsDGJcDLJiiiw2Gz1mi+WHS06a9lQBZg4rE8gQBi5OAZiIRinDH/6Q44tOh6uIhUkt f3//fn/Mc5tXJTbxkkXBf25F+B/SMWb476qVyJ6RcI8r68E9qY9tDJeire4d8/He2Hmo+O8z383 +jAA= X-Developer-Key: i=nekodevelopper@gmail.com; a=openpgp; fpr=3CB1489B166F57199296E520B7BE22D44474A582 X-Endpoint-Received: by B4 Relay for nekodevelopper@gmail.com/default with auth_id=314 X-Original-From: Vasiliy Doylov Reply-To: nekodevelopper@gmail.com From: Vasiliy Doylov This change integrates mc3510c support into the mc3230 driver. MC3510C uses the same registers as MC3230, but a different value scale. Tested on Huawei MediaPad T3 10 (huawei-agassi) Signed-off-by: Vasiliy Doylov --- drivers/iio/accel/mc3230.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/iio/accel/mc3230.c b/drivers/iio/accel/mc3230.c index c8d394c3ecf08fad60f0f2ae7be6fd992327d843..e2853090fa6e15f4dd74e996fae8520b30471d3b 100644 --- a/drivers/iio/accel/mc3230.c +++ b/drivers/iio/accel/mc3230.c @@ -46,6 +46,14 @@ static const struct mc3230_chip_info mc3230_chip_info = { .scale = 115411765, }; +static const struct mc3230_chip_info mc3510c_chip_info = { + .name = "mc3510c", + .chip_id = 0x23, + .product_code = 0x10, + /* Was obtained empirically */ + .scale = 625000000, +}; + #define MC3230_CHANNEL(reg, axis) { \ .type = IIO_ACCEL, \ .address = reg, \ @@ -225,12 +233,14 @@ static DEFINE_SIMPLE_DEV_PM_OPS(mc3230_pm_ops, mc3230_suspend, mc3230_resume); static const struct i2c_device_id mc3230_i2c_id[] = { { "mc3230", (kernel_ulong_t)&mc3230_chip_info }, + { "mc3510c", (kernel_ulong_t)&mc3510c_chip_info }, { } }; MODULE_DEVICE_TABLE(i2c, mc3230_i2c_id); static const struct of_device_id mc3230_of_match[] = { { .compatible = "mcube,mc3230", &mc3230_chip_info }, + { .compatible = "mcube,mc3510c", &mc3510c_chip_info }, { } }; MODULE_DEVICE_TABLE(of, mc3230_of_match);