From patchwork Sun Jul 3 22:02:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12904497 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 79ADACCA47F for ; Sun, 3 Jul 2022 22:03:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231458AbiGCWDP (ORCPT ); Sun, 3 Jul 2022 18:03:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229871AbiGCWDP (ORCPT ); Sun, 3 Jul 2022 18:03:15 -0400 Received: from sonic314-20.consmr.mail.ir2.yahoo.com (sonic314-20.consmr.mail.ir2.yahoo.com [77.238.177.146]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CADF460C7 for ; Sun, 3 Jul 2022 15:03:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1656885792; bh=RGArz7Zwo1YrpUAyYAm1grVSpdiCN8Oa/NeiK93F+nA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=E8rEHxxNPATRrPOhCb7TC/Ds7C1fI8MqX3LHhe+4Rcoh6bCIPtb/ILIfPztNp5mttb5PSG+Qw7w14I63hp2Hd1IBN0XVRfrlGitdC3sv+KdZD0lpAo23dDKJoTjmMN2ZIwMu+bytSgUxDWGVsCBXPHw39oth92nqa4C5p6f/P/5MRoUsV9O7gd/JBkJWHvzXtlzmgvwtNVwUwbR63ltsvbHlGFAQc0rJGghWGWW0zu0j2EMPpr4+j3C+K+TaaYK70o3megPKbnEWm3VcgsO/LOGCYsC2c76C9I4yHYgRe9jDY1PNhqD54BITUsKUInFsShl9mK0hd2rIU9+VWl/lcQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1656885792; bh=ddrCvG9hXzO2nfSrDplf4wDuBnp22zvX5IqF/0PG6dT=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=WZce+XB9xNHAG2I8ox+IdKoSH9b8ZMgHbzxCd1lo1buEkmUDXDphcM2ma1PIA0xfz3aJ3P+73Pfcbyql4+lKXYhTobJHiwu1Kkraom9siTTf4wN0VnLTksq5kj0tdEUBCobyTOcHqCN5RsMF6fDnEpdfrX8qlekXe5InqdO8fCtrAjuCRehJzigQCTRAmJoxJqUfBw2ArtEo2YP4eq8MRy5l4Rpay0nRULySRv/TUB3FLdN8GgDWjoRM743MssGbxUqmT1vV3Ni88b0myrm2PhpveFwvQuOu7kj/P0sWXjM38B51u1ooQmffBvDscs0Ip95A/hQxw/kJ+utPZ37wSg== X-YMail-OSG: iXGguFMVM1nOcucGXjiWKWpZSxDLiWJF3HzeAuW0sbyp.3HjxrmBtlyIbwbeOVh GX7oMZR65ioNCrspauxAAoFnRl.mbLN6a2Z_QMID1pj6C.YRQemT2fC0kP.6tRk_5XpTzu2Vbi8L rSrVfrtf9i8GGG2J85iTTqpMwe0mW.TEiNjejOjBwHMdQ3u5Ql0WSA2aMnBqp5ztie3g3Izz8XE7 eA8aZ0_gieSf8EcNpLeuRrGJ3SAjIgLszlqt1Yo.eDaIdMjkN_aaQMauRmqEjxksC89ayYuJDs.x WCo2hlcY..SxlBLICsd8WSCZpJ71fA2yTyheCWJQeXQRVPPd.oMTN9WvfmR.AQCvL1_pifQ8xPIS T0MSKn.J8nmJG_z..ZINkR3XU0IrHK0TL3jvYOR64xlyI1ZX3zd0YgGQLPfyZsxYmg9xUfBWzYrb rmLyA2aLKHsyG5K5MxTiAgDaryY0b.vzUHZF4rUOrO7z8blpJymTrO7a5EIg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tuByQ54A uM0JwnUMDSAWiSCMTdbpyU.UCFf5T6WnjhzX..zKTpDia4jJUTZktv3l0wcLyzCAkqRZDNKd8OWD Gj8DAdNCXqiuMFZn_b_caV2lCOOYnQD3aiBWUIsG6JEK.N6P1.sBA_7EE_t8TXFvxm5aqdAxTgXC uOKHuDpsPYZ33.ZetiFmS3cz6GFhxlak1uI9y7PN1Q4GGFI7krcOWlKkNFdAXv1DuBiZTjRZr7Cl Ykv8.vSkUEblQHlaPmoButrPDNPjBrP7eqYWIfeBX13tZFSy6xPTUtymOwKeQOzODRxEkKAu6u6P tygVl01x7gMv.3BinxsDutMioDaC4sEnjXnaBBBdC.TzzmLCyyKv_nInvdS1o.nUnH_UMyisSlpR rrG9jyfex9h4rOSv3ataiXO6VMZoIWcnhlshUIHy4c.b3wZyO4Nq7KMqox5Uag81XJuB0nvRc.wE xPaQOmFQHkuK_AjKRuwMSU5zlvv7Sg5or37ZQxS9oaRAMC0e4l8Agkttynjx6.ow6zr0TCtoqKtA yzS4LIPq56I.A5w.ZaiaKB0ei_cUHKrQE_Q1xNwapjfxJYfqhw90Ep3TpzmslUt32nnk02hbvAK0 1BXOABLcY1HV_yyemWSwI2EUhxBZ28UG_XlkNadnlc23rLsBOt4Q_tW_yt2O8AADPjmm3DkL6K2Z fTXRWn99r9eVrFI1s8hAmVC_v1ZtjfwozpDay9KkLdkCtETQej6OtirQTmhIlkhIiQaWQFU872X8 CwyXPFMafrsm6ivZ2 X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic314.consmr.mail.ir2.yahoo.com with HTTP; Sun, 3 Jul 2022 22:03:12 +0000 Received: by hermes--canary-production-ir2-74b4d6d794-tv8mb (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 0849bd8970b52a790a5a1bb96f2e336c; Sun, 03 Jul 2022 22:03:06 +0000 (UTC) From: Jakob Hauser To: Jonathan Cameron Cc: Lars-Peter Clausen , Linus Walleij , Andy Shevchenko , Hans de Goede , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH v4 01/10] iio: magnetometer: yas530: Change data type of hard_offsets to signed Date: Mon, 4 Jul 2022 00:02:35 +0200 Message-Id: <84be5d9fc769d6f90270e025872b771f2a4c86fc.1656883851.git.jahau@rocketmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org The "hard_offsets" are currently unsigned u8 but they should be signed as they can get negative. They are signed in function yas5xx_meaure_offsets() and in the Yamaha drivers [1][2]. [1] https://github.com/NovaFusion/android_kernel_samsung_golden/blob/cm-12.1/drivers/sensor/compass/yas.h#L156 [2] https://github.com/msm8916-mainline/android_kernel_qcom_msm8916/blob/GT-I9195I/drivers/iio/magnetometer/yas_mag_drv-yas532.c#L91 Fixes: de8860b1ed47 ("iio: magnetometer: Add driver for Yamaha YAS530") Signed-off-by: Jakob Hauser Reviewed-by: Linus Walleij Reviewed-by: Andy Shevchenko --- drivers/iio/magnetometer/yamaha-yas530.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index b2bc637150bf..40192aa46b04 100644 --- a/drivers/iio/magnetometer/yamaha-yas530.c +++ b/drivers/iio/magnetometer/yamaha-yas530.c @@ -132,7 +132,7 @@ struct yas5xx { unsigned int version; char name[16]; struct yas5xx_calibration calibration; - u8 hard_offsets[3]; + s8 hard_offsets[3]; struct iio_mount_matrix orientation; struct regmap *map; struct regulator_bulk_data regs[2]; From patchwork Sun Jul 3 22:02:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12904498 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 2F3C3CCA483 for ; Sun, 3 Jul 2022 22:03:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230273AbiGCWDQ (ORCPT ); Sun, 3 Jul 2022 18:03:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231403AbiGCWDP (ORCPT ); Sun, 3 Jul 2022 18:03:15 -0400 Received: from sonic312-26.consmr.mail.ir2.yahoo.com (sonic312-26.consmr.mail.ir2.yahoo.com [77.238.178.97]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11F1460CB for ; Sun, 3 Jul 2022 15:03:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1656885792; bh=F7BpDzS7greEJoS/tBb1EI2GHOq6sKTMQeOG/t4ARZY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=l8dkI/TfMWmEa0I7KlCM0I7L578SVHgGPiZ8SPElLJHrwSHbsmGJxbZrzVfIZhO8hp5hakNfMEwS+ZqhAybHiE9xxr9pLJwuoY5VNFl5MpWO30am4cMLAhMJZ/FclVES4lcv/m8thuFBit3VJZFf0mqZAC4eejE5IoxETJyaBIUnZ5tDl6zVTvuRNl2nmCtFDQP9DswTpSvykmrkQW61qXiQij6OVikOT08fzfNgQ3KjTN9p5EI809g63UIRtLcj0Pvi42T6rBVIzsdP+l7l5eCz7WaPEP+jGBGHlzXUeC5SnrVnKuq5dk7ovTUtw88CwtjI6jX5NIHWbSLnFxjU/w== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1656885792; bh=GkGt8PIVaSnG/jRWiPnzaS4fMTR82/sLY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BkkMVtUDdZUmC_fkIjGgs937Ol0V2KBkphd3ItF7LEffSCj7DYggyJ3Qs7_7Zg8jI NiuIHF4lzDJx8SOWjMplB0KZLs22tn98MwtOCnlBEGe3XAi9ZChDe5sG8fMCPCbpJNsp12FIE4h4 GEJ6JcD_2Kxl7R1ftWWmUPDJabZDHCfFlPhozPwixAK_nENLzfl2PuwiruqnHCQXrO1QOvaxH9TX z9RYsCVwjLGTHCyFlyqvgeVnsXDD6ZbL1iuWjK5cEER_OmxE31eTrEzIazFYg8Y1rOcEhvuUEwvt Okx8nXZi7Mm.dv4PCDzE4guC2qQQ8Ml6R7rpDSVJYlpkb1jkEFFYt4LKkCHKQgHySJoQi2pwIwHA DeGHeWOQ5cM1WDH5cfLnPxxcrGbSbEGBEGsZlNsTQ8b792VHdD_Zg2kbx3lB5GKM_ggSinDLRkHQ Ky1NZzzHD2AQwfajM5KDhNY.zEE.uC6L4TXqv.fpCr7zNpgrITHM73jmYCMmbL7Z.g01.vSdQ4Ob lFOlIrbLBnTMw94sj3SGRDHvVgH5ApVJKQQjMllw629LtRkRerTMP_qjr3DMpCcipRUGJhrc5N2D LVU.xuzweyg50laV1Bg-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic312.consmr.mail.ir2.yahoo.com with HTTP; Sun, 3 Jul 2022 22:03:12 +0000 Received: by hermes--canary-production-ir2-74b4d6d794-tv8mb (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 0849bd8970b52a790a5a1bb96f2e336c; Sun, 03 Jul 2022 22:03:09 +0000 (UTC) From: Jakob Hauser To: Jonathan Cameron Cc: Lars-Peter Clausen , Linus Walleij , Andy Shevchenko , Hans de Goede , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH v4 02/10] iio: magnetometer: yas530: Change range of data in volatile register Date: Mon, 4 Jul 2022 00:02:36 +0200 Message-Id: <5fbc8e114e4940569559edec3a85a1044c823f52.1656883851.git.jahau@rocketmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org In function yas5xx_volatile_reg(), register "YAS5XX_MEASURE_DATA + 8" shouldn't be volatile as we count from 0 to 7 here. Instead of lowering the number from 8 to 7, the operator "<=" is replaced by "<". The size of the measure data array is 8, therefore it's more natural to use 8 as a constant. This change is of low importance as the "+ 8" register isn't called. Signed-off-by: Jakob Hauser Reviewed-by: Linus Walleij Reviewed-by: Andy Shevchenko --- drivers/iio/magnetometer/yamaha-yas530.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index 40192aa46b04..6fa29b96c013 100644 --- a/drivers/iio/magnetometer/yamaha-yas530.c +++ b/drivers/iio/magnetometer/yamaha-yas530.c @@ -527,7 +527,7 @@ static bool yas5xx_volatile_reg(struct device *dev, unsigned int reg) { return reg == YAS5XX_ACTUATE_INIT_COIL || reg == YAS5XX_MEASURE || - (reg >= YAS5XX_MEASURE_DATA && reg <= YAS5XX_MEASURE_DATA + 8); + (reg >= YAS5XX_MEASURE_DATA && reg < YAS5XX_MEASURE_DATA + 8); } /* TODO: enable regmap cache, using mark dirty and sync at runtime resume */ From patchwork Sun Jul 3 22:02:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12904499 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 E064EC433EF for ; Sun, 3 Jul 2022 22:03:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229673AbiGCWDS (ORCPT ); Sun, 3 Jul 2022 18:03:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230420AbiGCWDR (ORCPT ); Sun, 3 Jul 2022 18:03:17 -0400 Received: from sonic305-21.consmr.mail.ir2.yahoo.com (sonic305-21.consmr.mail.ir2.yahoo.com [77.238.177.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E075060C7 for ; Sun, 3 Jul 2022 15:03:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1656885794; bh=EuFGkupLjx9zPeG1GfBnRcBvJL6CsBo11j9xvtKmu7w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=odlyzq1zKjKmhZiNRTJzvGdsVVz41Qywa4VK40KFymFdk9cjehizd6JoOXIIZaVTWgmPU5ZVFEPS4ho4GoDFAX2zfXxPcRgwte/VnAqaUJ+aKehC1lsk0yyX9mmtiswMQ9mTL9alTeIXwPM22V4nYXS6+U5n16vogt9llchhu3jl976RxfjnPPFKpO3tZ8QO5dQ9M2YP+zsz6g3+zpNNzwqjXet8s8rQKX0xm1l8aBY6XRoVKpSmqE2Q178FYcL8iFPt2JnTjfGWS4i00k4MGkzHXmbisIJu0WV7SzAKs/bcKcw0loeu/Hvs004hmm3itcEAkxLiH2a7FY6gvNi5VQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1656885794; bh=NjqdnLHQWyVeQvaUbsqOeVzNc1MvOT6xjm/rrD2B7vz=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=oXW6pq3RE78tozBOCl92yedajgULz6Ok1RMfAJjfGaFB8M1fG2u13T3d8r5H1EHSrSZQNWNDB+14vYa7BzqON58CUnCmnBXRzp+4zn0nS1vvQpSlynuATDU0KplRTOYowR46BO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K4cRU3YviTu9BoyP.oUjKjYZUDAy1.YIC.IPv9gGVldCmbQAersANLF jzkuOdYH0BePKMwox8iZrfYkdjyO9ghu1FgHx03rLbH8LkxzF4CV7N5bXINmZU0CDB.9.wjGaa8Q 2FUqp5Qm01CVzD9wuqz1fzwzaflWlYIhr.sK2wg40vxLY9XB8IKpdOzRiR.NOKO2IXAbdYKCM.kA 0xJhJAQfEktVp_VcoB.QXOawoDF7HFBD41ZFu4DH23VpBtWe5kP7MnPwi6wjCxmeeXioZlzG5xdp ZbIA2pWJFWdO3IL8xwyXsZxDfiEoACQqkillKB.8LzK3EkFXjXElOZDuiSuL_KsMSVBsgoUUA.w3 ws5cdr2ibB3eHQElPkAfKblNNidZFBQt8PFY95AVkTmXLAuxIUrf1LhHQdpOAew9DVN2uPecxHWH VpsGhgMd27BxvQ21f X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic305.consmr.mail.ir2.yahoo.com with HTTP; Sun, 3 Jul 2022 22:03:14 +0000 Received: by hermes--canary-production-ir2-74b4d6d794-tv8mb (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 0849bd8970b52a790a5a1bb96f2e336c; Sun, 03 Jul 2022 22:03:12 +0000 (UTC) From: Jakob Hauser To: Jonathan Cameron Cc: Lars-Peter Clausen , Linus Walleij , Andy Shevchenko , Hans de Goede , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH v4 03/10] iio: magnetometer: yas530: Correct scaling of magnetic axes Date: Mon, 4 Jul 2022 00:02:37 +0200 Message-Id: <3e43975412539f6af6b6a479bcd222741f9f8b28.1656883851.git.jahau@rocketmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Looks like YAS530 raw values return picotesla and YAS532 nanotesla. Adapt comments and scaling. Signed-off-by: Jakob Hauser Reviewed-by: Linus Walleij Reviewed-by: Andy Shevchenko --- drivers/iio/magnetometer/yamaha-yas530.c | 31 ++++++++++++++++-------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index 6fa29b96c013..8cad724fb328 100644 --- a/drivers/iio/magnetometer/yamaha-yas530.c +++ b/drivers/iio/magnetometer/yamaha-yas530.c @@ -310,8 +310,6 @@ static s32 yas5xx_linearize(struct yas5xx *yas5xx, u16 val, int axis) * @yo: Y axis out * @zo: Z axis out * @return: 0 on success or error code - * - * Returned values are in nanotesla according to some code. */ static int yas5xx_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, s32 *zo) { @@ -417,14 +415,27 @@ static int yas5xx_read_raw(struct iio_dev *indio_dev, *val = 1; return IIO_VAL_INT; } - /* - * The axis values are in nanotesla according to the vendor - * drivers, but is clearly in microtesla according to - * experiments. Since 1 uT = 0.01 Gauss, we need to divide - * by 100000000 (10^8) to get to Gauss from the raw value. - */ - *val = 1; - *val2 = 100000000; + switch (yas5xx->devid) { + case YAS530_DEVICE_ID: + /* + * Raw values of YAS530 are in picotesla. Divide by + * 100000000 (10^8) to get Gauss. + */ + *val = 1; + *val2 = 100000000; + break; + case YAS532_DEVICE_ID: + /* + * Raw values of YAS532 are in nanotesla. Divide by + * 100000 (10^5) to get Gauss. + */ + *val = 1; + *val2 = 100000; + break; + default: + dev_err(yas5xx->dev, "unknown device type\n"); + return -EINVAL; + } return IIO_VAL_FRACTIONAL; default: /* Unknown request */ From patchwork Sun Jul 3 22:02:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12904500 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 9AD8DC43334 for ; Sun, 3 Jul 2022 22:03:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232068AbiGCWDY (ORCPT ); Sun, 3 Jul 2022 18:03:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231403AbiGCWDU (ORCPT ); Sun, 3 Jul 2022 18:03:20 -0400 Received: from sonic312-26.consmr.mail.ir2.yahoo.com (sonic312-26.consmr.mail.ir2.yahoo.com [77.238.178.97]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 170E0B3E for ; Sun, 3 Jul 2022 15:03:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1656885797; bh=8VJGl0MuSHhL28Kf4k+uCd0Gflpcbk+QqcZEf6TEyHU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=jN4B2HjoNpceXb+Z9R7fBxCBwj19JcvD07XYVVzF01lk3QHOuPtOw/Pk4vW7XRIrsLwjyfbDDgDrg25XRFY6WwR3XCYsasVPO+66ZFZbSN1sbGJb+oSkXsd9IEiKPEjtENFHDAX7v79kcvl/ZJAyBf+eay0HTK8G+CFgAskXVQaavTKWSyay/KjIYFc1jrwXSna1yXj6rrW4qEekbDSoSUKkod1u+Uor4K5BTQHzl72T28aMLrCBLLG4WLZWSvb0B8s93GYHJJW51wfMXm/uXl+6Q7qe4xHMO7aWiIDh796gNIGvfMEiEhOUKWyQxh047eH1AuYR+9vy+rQsyGIREA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1656885797; bh=Agd1qJ2LKU88Y+fcOLxP4nOnN6Tbk47qHo1w0O0YfYa=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=s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5ayEiywmkMcK3zAfymnFOxaLU2fGSbG f0WVYqr81Gw74_XHnXbFHZFhZ0Su_G0mTH_Y4yOTGHWv.zxcIYCU61GjXzHJP0T50rvfuPgj3x.0 Yt6bzKDbA234YQvEQwCX39E9IotoCghEvmVSe_HtSoFyQzt.yWoZ058gFJAEnebyFbBFa8Ow2Rg3 zU4MLN_oizFPE463YhYfzuexd7sHwVLlYgrSI3HWnoPQLDKYom67tMld32RqFwuR7Ig_NQlvAswE 8H7EifjokGoS0J7mzdib0xbadYVviNCrDomYpVlFF120mCksjdFJb1hIMqSIuJx4NOaNIf4GdC.4 giHKm2xO9_LkMuD98OXIuHgfpgwjqo21sMGXANckkrXnByAv_NcxGRxWF0EBv3Pt3amRJXUwCyIR P9044tbsipzlGp2KtvBYiImcIxxK4Cj_NvAb5kZS8k1.j6BjSTXdMUeBxS2r7RQcoa7QhcRlTc7y eVubjVHIhUL_b5MxkYTJKeChwx6VPEQZitVaoxL_av8MIXHWmJsKjkqzoL5PrhpYXfSfKy4PISot cBGh9qdBhIX0hi5iBuw-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic312.consmr.mail.ir2.yahoo.com with HTTP; Sun, 3 Jul 2022 22:03:17 +0000 Received: by hermes--canary-production-ir2-74b4d6d794-tv8mb (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 0849bd8970b52a790a5a1bb96f2e336c; Sun, 03 Jul 2022 22:03:14 +0000 (UTC) From: Jakob Hauser To: Jonathan Cameron Cc: Lars-Peter Clausen , Linus Walleij , Andy Shevchenko , Hans de Goede , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH v4 04/10] iio: magnetometer: yas530: Correct temperature handling Date: Mon, 4 Jul 2022 00:02:38 +0200 Message-Id: <61e778798703b53a5e4870a5d1e12c6c56a1ae4a.1656883851.git.jahau@rocketmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org The raw temperature value is a number of counts from a certain starting point. The resolution of the temperature counts is different for the YAS variants. Temperature compensation for YAS532 version AC seems to be handled differently. It uses the deviation from 20 degree Celsius [1] whereas YAS530 and older versions of YAS532 apply solely the t value as a multiplier [2][3]. In funtion yas5xx_read_raw(), add case IIO_CHAN_INFO_PROCESSED. Remove scale of temperature as this isn't applied. Additionally correct sign of temperature channel in iio_chan_spec. It's already defined that way in the yas5xx_get_measure() function. [1] https://github.com/msm8916-mainline/android_kernel_qcom_msm8916/blob/GT-I9195I/drivers/iio/magnetometer/yas_mag_drv-yas532.c#L442 [2] https://github.com/NovaFusion/android_kernel_samsung_golden/blob/cm-12.1/drivers/sensor/compass/yas_mag_driver-yas530.c#L881-L883 [3] https://github.com/LineageOS/android_kernel_samsung_msm8930-common/blob/lineage-18.1/drivers/sensors/geomagnetic/yas_mag_driver-yas53x.c#L856-L858 Signed-off-by: Jakob Hauser Reviewed-by: Linus Walleij Reviewed-by: Andy Shevchenko --- drivers/iio/magnetometer/yamaha-yas530.c | 99 ++++++++++++++++++------ 1 file changed, 76 insertions(+), 23 deletions(-) diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index 8cad724fb328..c6889a30a1b5 100644 --- a/drivers/iio/magnetometer/yamaha-yas530.c +++ b/drivers/iio/magnetometer/yamaha-yas530.c @@ -77,6 +77,7 @@ #define YAS530_DATA_BITS 12 #define YAS530_DATA_CENTER BIT(YAS530_DATA_BITS - 1) #define YAS530_DATA_OVERFLOW (BIT(YAS530_DATA_BITS) - 1) +#define YAS530_20DEGREES 182 /* Counts starting at -62 °C */ #define YAS532_DEVICE_ID 0x02 /* YAS532/YAS533 (MS-3R/F) */ #define YAS532_VERSION_AB 0 /* YAS532/533 AB (MS-3R/F AB) */ @@ -88,7 +89,7 @@ #define YAS532_DATA_BITS 13 #define YAS532_DATA_CENTER BIT(YAS532_DATA_BITS - 1) #define YAS532_DATA_OVERFLOW (BIT(YAS532_DATA_BITS) - 1) -#define YAS532_20DEGREES 390 /* Looks like Kelvin */ +#define YAS532_20DEGREES 390 /* Counts starting at -50 °C */ /* These variant IDs are known from code dumps */ #define YAS537_DEVICE_ID 0x07 /* YAS537 (MS-3T) */ @@ -314,7 +315,7 @@ static s32 yas5xx_linearize(struct yas5xx *yas5xx, u16 val, int axis) static int yas5xx_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, s32 *zo) { struct yas5xx_calibration *c = &yas5xx->calibration; - u16 t, x, y1, y2; + u16 t_ref, t, x, y1, y2; /* These are "signed x, signed y1 etc */ s32 sx, sy1, sy2, sy, sz; int ret; @@ -329,16 +330,46 @@ static int yas5xx_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, sy1 = yas5xx_linearize(yas5xx, y1, 1); sy2 = yas5xx_linearize(yas5xx, y2, 2); - /* - * Temperature compensation for x, y1, y2 respectively: - * - * Cx * t - * x' = x - ------ - * 100 - */ - sx = sx - (c->Cx * t) / 100; - sy1 = sy1 - (c->Cy1 * t) / 100; - sy2 = sy2 - (c->Cy2 * t) / 100; + /* Set the temperature reference value (unit: counts) */ + switch (yas5xx->devid) { + case YAS530_DEVICE_ID: + t_ref = YAS530_20DEGREES; + break; + case YAS532_DEVICE_ID: + t_ref = YAS532_20DEGREES; + break; + default: + dev_err(yas5xx->dev, "unknown device type\n"); + return -EINVAL; + } + + /* Temperature compensation for x, y1, y2 respectively */ + if (yas5xx->devid == YAS532_DEVICE_ID && + yas5xx->version == YAS532_VERSION_AC) { + /* + * YAS532 version AC uses the temperature deviation as a + * multiplier. + * + * Cx * (t - t_ref) + * x' = x - ---------------- + * 100 + */ + sx = sx - (c->Cx * (t - t_ref)) / 100; + sy1 = sy1 - (c->Cy1 * (t - t_ref)) / 100; + sy2 = sy2 - (c->Cy2 * (t - t_ref)) / 100; + } else { + /* + * YAS530 and YAS532 version AB use solely the t value as a + * multiplier. + * + * Cx * t + * x' = x - ------ + * 100 + */ + sx = sx - (c->Cx * t) / 100; + sy1 = sy1 - (c->Cy1 * t) / 100; + sy2 = sy2 - (c->Cy2 * t) / 100; + } /* * Break y1 and y2 into y and z, y1 and y2 are apparently encoding @@ -347,11 +378,37 @@ static int yas5xx_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, sy = sy1 - sy2; sz = -sy1 - sy2; - /* - * FIXME: convert to Celsius? Just guessing this is given - * as 1/10:s of degrees so multiply by 100 to get millicentigrades. - */ - *to = t * 100; + /* Process temperature readout */ + switch (yas5xx->devid) { + case YAS530_DEVICE_ID: + /* + * Raw temperature value t is the number of counts starting + * at -62 °C. Reference value t_ref is the number of counts + * between -62 °C and 20 °C (82 °C range). + * + * Temperature in °C would be (82 / t_ref * t) - 62. + * + * Contrary to this, perform multiplication first and division + * second due to calculating with integers. + * + * To get a nicer result, calculate with 1/10:s degrees Celsius + * and finally multiply by 100 to return millidegrees Celsius. + */ + *to = ((820 * t / t_ref) - 620) * 100; + break; + case YAS532_DEVICE_ID: + /* + * Actually same procedure for YAS532 but the starting point is + * at -50 °C. Reference value t_ref is the number of counts + * between -50 °C and 20 °C (70 °C range). + */ + *to = ((700 * t / t_ref) - 500) * 100; + break; + default: + dev_err(yas5xx->dev, "unknown device type\n"); + return -EINVAL; + } + /* * Calibrate [x,y,z] with some formulas like this: * @@ -384,6 +441,7 @@ static int yas5xx_read_raw(struct iio_dev *indio_dev, int ret; switch (mask) { + case IIO_CHAN_INFO_PROCESSED: case IIO_CHAN_INFO_RAW: pm_runtime_get_sync(yas5xx->dev); ret = yas5xx_get_measure(yas5xx, &t, &x, &y, &z); @@ -410,11 +468,6 @@ static int yas5xx_read_raw(struct iio_dev *indio_dev, } return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: - if (chan->address == 0) { - /* Temperature is unscaled */ - *val = 1; - return IIO_VAL_INT; - } switch (yas5xx->devid) { case YAS530_DEVICE_ID: /* @@ -516,7 +569,7 @@ static const struct iio_chan_spec yas5xx_channels[] = { .address = 0, .scan_index = 0, .scan_type = { - .sign = 'u', + .sign = 's', .realbits = 32, .storagebits = 32, .endianness = IIO_CPU, From patchwork Sun Jul 3 22:02:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12904501 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 ADE1EC433EF for ; Sun, 3 Jul 2022 22:03:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232313AbiGCWD1 (ORCPT ); Sun, 3 Jul 2022 18:03:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232354AbiGCWDZ (ORCPT ); Sun, 3 Jul 2022 18:03:25 -0400 Received: from sonic310-12.consmr.mail.ir2.yahoo.com (sonic310-12.consmr.mail.ir2.yahoo.com [77.238.177.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 432DE2AD4 for ; Sun, 3 Jul 2022 15:03:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1656885800; bh=GR8ksOaf4DkPasL6sXDaIM2/cMoDf6p7jL0ro40UYps=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=QcxjmgEmKbifpS+q5qYZ1YFmYVtcKoh8osHXMh799LO+2qqczgyECl37e8GQlNMwddw+8Ye3yuml8q82CEQJzHLVvys6oAABqdycWvb2ZyU/XZeKffcjH5EZ9zZOfQzJkkyK3LXD/1QwFGrXl5KHLmnV/nlQa5H5GQHabgyqw0PkabkaVlAyOR5sfkhoHhIZ8nQ0UAKIWW7olYKYXV0BIWfm3r/G+QxluXdbhoEs0/j24Kt/wAy1OhY4EGh2ezleEzIBB31WbvwSNZxIKtX7aLB6UXsZri6W3dietSu2N8ZkSMGJBjvfu9GNg6qB8yFk+GxXbOWnyPImdgCfbmowDQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1656885800; bh=GXq8UhEZp6WTWu3YrUwCUOAJg6BORGMf779gHVoSqQb=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=kzA1FjG5KvFyAvLDWvacoyYfUppa1FTyY9wbZQE1NaffafduPN+iXzRDj3Hw89t1OXRJZxwAwu2K2ToP0GVyjDQzUB1rzaYXsIQ+xdCiwhXnh4cQDJO2EuFeAlTOvRqcl58l1i3Re6POAOTj2DxIJ5gnWPW0POZnqSxh9jnkuNMau522ouARxNOR/S5TslOdbserOZTnOsNda5Tyk56EE6UujzIg3vnqWpAySdIK4mqCWABKJ8gmFKj5jf8UvzbRitT7NRe+13aw1gGqdUcMozxBkEU8NtLMmbCeYuhqibiBey36atSMHSv2hjTbZOGWWrsQXV56oDDi0HO+00jEeg== X-YMail-OSG: fmZSPZIVM1m4UsPp2Z6HJntg8k5AUw1ySzkrwvClhGy3unqI.OcI5O4kO0IMVp0 utki4VN91B2nF21rr8abi0sYz2GkiOXcvOWNV_tGqLF_O6gLHkKnudd7.xByPnh0eMQ0XCjLnStS xufMRQqZR.UIzeyESUL2.Xw6YzdbXNdIp6YroQAe_1tdMT8HNYhNATLC1U5WnJ8BOWT1YXqApLS4 8T6ZLk.whRe6xE57SlSWoY30KFy998lV_tmPycEnmTstvnNx7V3O2g3Hiqc5He2WItvXmMEMOgex z.RjGratdc.uP_6D2GF4pim_H1EAB_YCy6sDOddxU4bS8VrlR0No7a7JzlUIFu9IpMNb1gnPeKOO VuqEQUmKuE1lSqEDXHhbrhEi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ib_mChC0oav9b4eGQt.JWsRxOElCCgsBE2fCDyacJDNvNeHdK KOsvWZShKMJ10zX76NTAVfq.c.CAMepkZiZBTwN.pENDgJWhxraaeo2FO9CB5LEwd1yxtIq91UQe yK9sB6k3mZTFMzA_PZhPOMzFwiHJNe5cRvi.LMIy8R.rZzMPKzRipCKgSqza6Suozg_mD7n7FKtI Np8ELamAMgSYa3ZTbQw7l5LBB.grfD2h9bNCfudybAraDp3a3U4qFw7IdXNK_2wPzIDc3ZHgj0IP YRgMcCo78Mma9fRvC9M94.y5qgAvHFD77OtMCX3Ao4o98BJi3DrILdr8vEVQN8vNeN0z32Iykrhy nkPBNa7kLEKyTy9kNG47emR9LhpkD.jbZUHs07.pT2JhosYrtb7Vos3WWrzKoEPZ_3E8d7PydbLi YqJPnC7lZ5YuDVPiFgLroMXT_Ecfn24mYgzLPth4DQU_tk8QYZG4G70vMXeyhsCHFyD6KQZmbLsp s6CDi7VIRcienHuNNJ05AkgoyaQg4TTK8z1S5rj68e6D1CF35.NBwaozT.mc3CtyZzsy6fUC7BUg czzDpFT9DZxYybYBfKvc0WgftqQbmgrgSpSwH7D5wUB13VZJScGvbINvMzaaTpWiVLv_I.0t4BCY FLJZ4sryGuydDRaukZd9xiQoI4KR6G2JYtvxzT1SYQQiUBuUBT_P25XRsyQT1sxVeKmbiRnM_MlI LupuIiT9Hcd3IuGgV0kjKbDcHpYeGp61FqZ0ZNatkYwFbQ9miYzyKhK1yq3FEOocB4eZGpqIsXIV jpYmaJZly7uw6HvRWGY7ZEQjAzceoQlpXNVq5oejZ9PCYcpvIfjYfNSJX5korCoVZLczrKILQx3S 2q6o4IwOPSPNN_QKKtw-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.ir2.yahoo.com with HTTP; Sun, 3 Jul 2022 22:03:20 +0000 Received: by hermes--canary-production-ir2-74b4d6d794-tv8mb (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 0849bd8970b52a790a5a1bb96f2e336c; Sun, 03 Jul 2022 22:03:16 +0000 (UTC) From: Jakob Hauser To: Jonathan Cameron Cc: Lars-Peter Clausen , Linus Walleij , Andy Shevchenko , Hans de Goede , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH v4 05/10] iio: magnetometer: yas530: Change data type of calibration coefficients Date: Mon, 4 Jul 2022 00:02:39 +0200 Message-Id: <502f2d4425af785efe49c9e3841cbfe90fd1b713.1656883851.git.jahau@rocketmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This is a preparation for adding YAS537 variant. YAS537 uses other data types on the calibration coefficients [1] than YAS530 [2] and YAS532 [3]. On YAS537, at least for a4 and a7 this could matter because 8-bit unsigned data from the register gets stored into a signed data type, therefore this should be 8-bit as well. For YAS530/532, on the other hand, it doesn't seem to matter. The size of a2-a9 and k is smaller than 8-bit at extraction, also the applied math is low. And Cx/Cy1/Cy2, now being defined as signed 16-bit, are extracted as unsigned 8-bit and undergo only minor math. [1] https://github.com/msm8916-mainline/android_kernel_qcom_msm8916/blob/GT-I9195I/drivers/iio/magnetometer/yas_mag_drv-yas537.c#L76-L78 [2] https://github.com/NovaFusion/android_kernel_samsung_golden/blob/cm-12.1/drivers/sensor/compass/yas_mag_driver-yas530.c#L526-L527 [3] https://github.com/msm8916-mainline/android_kernel_qcom_msm8916/blob/GT-I9195I/drivers/iio/magnetometer/yas_mag_drv-yas532.c#L76-L77 Signed-off-by: Jakob Hauser Reviewed-by: Linus Walleij Reviewed-by: Andy Shevchenko --- drivers/iio/magnetometer/yamaha-yas530.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index c6889a30a1b5..839baeca673a 100644 --- a/drivers/iio/magnetometer/yamaha-yas530.c +++ b/drivers/iio/magnetometer/yamaha-yas530.c @@ -103,9 +103,11 @@ struct yas5xx_calibration { s32 r[3]; u32 f[3]; /* Temperature compensation calibration */ - s32 Cx, Cy1, Cy2; + s16 Cx, Cy1, Cy2; /* Misc calibration coefficients */ - s32 a2, a3, a4, a5, a6, a7, a8, a9, k; + s8 a2, a3, a4, a6, a7, a8; + s16 a5, a9; + u8 k; /* clock divider */ u8 dck; }; From patchwork Sun Jul 3 22:02:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12904502 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 0B552CCA47F for ; Sun, 3 Jul 2022 22:03:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231956AbiGCWD2 (ORCPT ); Sun, 3 Jul 2022 18:03:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230420AbiGCWD0 (ORCPT ); Sun, 3 Jul 2022 18:03:26 -0400 Received: from sonic301-22.consmr.mail.ir2.yahoo.com (sonic301-22.consmr.mail.ir2.yahoo.com [77.238.176.99]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95EB72BEC for ; Sun, 3 Jul 2022 15:03:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1656885801; bh=3q+WLnoTc6L3URW0sHdvF2JD+anBhYh2Gfku7wYwxQo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=D4evdxNCE8sZEdnjULQlbWzD98aQfqq+6Zvd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5YwJLZG53Ayppdb2adomn2D eNcuecREF2uTZV0uCyx1riJMbKbVPAnsPBTBf003.Yg9x06J11nUSFs0awwtcka2R5eYop1fdw0M Bf4qzJOwP9qSpCLE1u9.VASClPtH.r5kV31t4oHM5p.acZ4OxTvai1yEvXBNMyeabJyGSH0KlolR xEahCXdrNCXAyaMl8a16Lt4e60tgBWrK0rqtH1ZmMAUSivFP2DGBO3YgKUZ6a8sTRQ23aZ.UHckN d2iAPRRLqobY8FJsr8u_6HFym0WwsadLxtveVRvJxBfLV.FqW1T3yPHm6LOhb5jirdXg2LKUGy6S EOIb6LSj0G7VtLpaK2s2Iy7zDV_739wRcnw.pSvogiRddT.VZRxuEmAgCVmn5GQySvy1V4a4fs6w BHRbsffTbUtcn5Yqf.tV8RoixN9u7GoSJ.dwCLeV6Ls9rCKDHZ3wKxA5R8WylDNvccoe6vEifk1o Wkc9Sw4wXv7h65P9aDfsOJYNKAQa49dYGAWigUF21m1aCCzha17cuTTDcr3JDnQd8A30Hv5cePbY 4qdBdy3UTdJLLokmpBunhfZKnHPz0yGlKDBRXqqzPqCKABpB1GSp2_e8STPgOnLth4lziV3sH78n svW9n9ZBZz6sIRSDZkn.yfu.2wzuYIMw8DKvtMMfHIRq25DW3jqrk6JppGNN1UknKnvbMrmwiSp4 cASyTdzNb_qVqHwofYm_hqbEKXQC9vUZuhGgXzG3kOy5SScXDQiLPjz3Nu2sE3G_oBHhw4cez1a1 cRAuNLS2DbEDim.ikyDllvRi3e_M91gyE3ZyBoUQRnSEffSR8s3ayehaZMnl48YgeYo17MZnJXHF 90diKb.UHQJJLWak9fUyt1V9JRxq1i.Bmdf_g2AtIbleRerjjFsn2e4JlkwzWEHBbRQRUXjjvwCx ujFIKUXcv2EsW8DygnyHE6STUkpHPCypd.2Uwx_62dFjmd4GiI._i6_6TKUcQDefKD5beVKy19Pu UFuWstPGPt6Lnzpq.DA-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ir2.yahoo.com with HTTP; Sun, 3 Jul 2022 22:03:21 +0000 Received: by hermes--canary-production-ir2-74b4d6d794-tv8mb (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 0849bd8970b52a790a5a1bb96f2e336c; Sun, 03 Jul 2022 22:03:18 +0000 (UTC) From: Jakob Hauser To: Jonathan Cameron Cc: Lars-Peter Clausen , Linus Walleij , Andy Shevchenko , Hans de Goede , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH v4 06/10] iio: magnetometer: yas530: Rename functions and registers Date: Mon, 4 Jul 2022 00:02:40 +0200 Message-Id: <24d0ed13b317de4209cfd0b7ecd258af87b1b952.1656883851.git.jahau@rocketmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This is a preparation for adding YAS537 variant. Functions that are used only by YAS530, YAS532 and YAS533 are renamed from yas5xx to yas530. Same for the registers. To avoid part listing in function and registers names, the name of the first variant is used. Where appropriate, comments were added that these functions are used by more than one variant. Functions that will be used by all variants including YAS537 remain in the naming scheme yas5xx. Or YAS5XX for registers, respectively. Signed-off-by: Jakob Hauser Reviewed-by: Linus Walleij --- drivers/iio/magnetometer/yamaha-yas530.c | 113 +++++++++++++---------- 1 file changed, 62 insertions(+), 51 deletions(-) diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index 839baeca673a..c250909df8f4 100644 --- a/drivers/iio/magnetometer/yamaha-yas530.c +++ b/drivers/iio/magnetometer/yamaha-yas530.c @@ -40,20 +40,22 @@ #include -/* This register map covers YAS530 and YAS532 but differs in YAS 537 and YAS539 */ +/* Commonly used registers */ #define YAS5XX_DEVICE_ID 0x80 -#define YAS5XX_ACTUATE_INIT_COIL 0x81 -#define YAS5XX_MEASURE 0x82 -#define YAS5XX_CONFIG 0x83 -#define YAS5XX_MEASURE_INTERVAL 0x84 -#define YAS5XX_OFFSET_X 0x85 /* [-31 .. 31] */ -#define YAS5XX_OFFSET_Y1 0x86 /* [-31 .. 31] */ -#define YAS5XX_OFFSET_Y2 0x87 /* [-31 .. 31] */ -#define YAS5XX_TEST1 0x88 -#define YAS5XX_TEST2 0x89 -#define YAS5XX_CAL 0x90 #define YAS5XX_MEASURE_DATA 0xB0 +/* These registers are used by YAS530, YAS532 and YAS533 */ +#define YAS530_ACTUATE_INIT_COIL 0x81 +#define YAS530_MEASURE 0x82 +#define YAS530_CONFIG 0x83 +#define YAS530_MEASURE_INTERVAL 0x84 +#define YAS530_OFFSET_X 0x85 /* [-31 .. 31] */ +#define YAS530_OFFSET_Y1 0x86 /* [-31 .. 31] */ +#define YAS530_OFFSET_Y2 0x87 /* [-31 .. 31] */ +#define YAS530_TEST1 0x88 +#define YAS530_TEST2 0x89 +#define YAS530_CAL 0x90 + /* Bits in the YAS5xx config register */ #define YAS5XX_CONFIG_INTON BIT(0) /* Interrupt on? */ #define YAS5XX_CONFIG_INTHACT BIT(1) /* Interrupt active high? */ @@ -182,7 +184,7 @@ static u16 yas532_extract_axis(u8 *data) } /** - * yas5xx_measure() - Make a measure from the hardware + * yas530_measure() - Make a measure from the hardware * @yas5xx: The device state * @t: the raw temperature measurement * @x: the raw x axis measurement @@ -190,7 +192,8 @@ static u16 yas532_extract_axis(u8 *data) * @y2: the y2 axis measurement * @return: 0 on success or error code */ -static int yas5xx_measure(struct yas5xx *yas5xx, u16 *t, u16 *x, u16 *y1, u16 *y2) +/* Used by YAS530, YAS532 and YAS533 */ +static int yas530_measure(struct yas5xx *yas5xx, u16 *t, u16 *x, u16 *y1, u16 *y2) { unsigned int busy; u8 data[8]; @@ -198,7 +201,7 @@ static int yas5xx_measure(struct yas5xx *yas5xx, u16 *t, u16 *x, u16 *y1, u16 *y u16 val; mutex_lock(&yas5xx->lock); - ret = regmap_write(yas5xx->map, YAS5XX_MEASURE, YAS5XX_MEASURE_START); + ret = regmap_write(yas5xx->map, YAS530_MEASURE, YAS5XX_MEASURE_START); if (ret < 0) goto out_unlock; @@ -264,7 +267,8 @@ static int yas5xx_measure(struct yas5xx *yas5xx, u16 *t, u16 *x, u16 *y1, u16 *y return ret; } -static s32 yas5xx_linearize(struct yas5xx *yas5xx, u16 val, int axis) +/* Used by YAS530, YAS532 and YAS533 */ +static s32 yas530_linearize(struct yas5xx *yas5xx, u16 val, int axis) { struct yas5xx_calibration *c = &yas5xx->calibration; static const s32 yas532ac_coef[] = { @@ -306,7 +310,7 @@ static s32 yas5xx_linearize(struct yas5xx *yas5xx, u16 val, int axis) } /** - * yas5xx_get_measure() - Measure a sample of all axis and process + * yas530_get_measure() - Measure a sample of all axis and process * @yas5xx: The device state * @to: Temperature out * @xo: X axis out @@ -314,7 +318,8 @@ static s32 yas5xx_linearize(struct yas5xx *yas5xx, u16 val, int axis) * @zo: Z axis out * @return: 0 on success or error code */ -static int yas5xx_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, s32 *zo) +/* Used by YAS530, YAS532 and YAS533 */ +static int yas530_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, s32 *zo) { struct yas5xx_calibration *c = &yas5xx->calibration; u16 t_ref, t, x, y1, y2; @@ -323,14 +328,14 @@ static int yas5xx_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, int ret; /* We first get raw data that needs to be translated to [x,y,z] */ - ret = yas5xx_measure(yas5xx, &t, &x, &y1, &y2); + ret = yas530_measure(yas5xx, &t, &x, &y1, &y2); if (ret) return ret; /* Do some linearization if available */ - sx = yas5xx_linearize(yas5xx, x, 0); - sy1 = yas5xx_linearize(yas5xx, y1, 1); - sy2 = yas5xx_linearize(yas5xx, y2, 2); + sx = yas530_linearize(yas5xx, x, 0); + sy1 = yas530_linearize(yas5xx, y1, 1); + sy2 = yas530_linearize(yas5xx, y2, 2); /* Set the temperature reference value (unit: counts) */ switch (yas5xx->devid) { @@ -605,11 +610,12 @@ static const struct regmap_config yas5xx_regmap_config = { }; /** - * yas53x_extract_calibration() - extracts the a2-a9 and k calibration + * yas530_extract_calibration() - extracts the a2-a9 and k calibration * @data: the bitfield to use * @c: the calibration to populate */ -static void yas53x_extract_calibration(u8 *data, struct yas5xx_calibration *c) +/* Used by YAS530, YAS532 and YAS533 */ +static void yas530_extract_calibration(u8 *data, struct yas5xx_calibration *c) { u64 val = get_unaligned_be64(data); @@ -647,12 +653,12 @@ static int yas530_get_calibration_data(struct yas5xx *yas5xx) int ret; /* Dummy read, first read is ALWAYS wrong */ - ret = regmap_bulk_read(yas5xx->map, YAS5XX_CAL, data, sizeof(data)); + ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data)); if (ret) return ret; /* Actual calibration readout */ - ret = regmap_bulk_read(yas5xx->map, YAS5XX_CAL, data, sizeof(data)); + ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data)); if (ret) return ret; dev_dbg(yas5xx->dev, "calibration data: %*ph\n", 14, data); @@ -664,7 +670,7 @@ static int yas530_get_calibration_data(struct yas5xx *yas5xx) c->Cx = data[0] * 6 - 768; c->Cy1 = data[1] * 6 - 768; c->Cy2 = data[2] * 6 - 768; - yas53x_extract_calibration(&data[3], c); + yas530_extract_calibration(&data[3], c); /* * Extract linearization: @@ -695,11 +701,11 @@ static int yas532_get_calibration_data(struct yas5xx *yas5xx) int ret; /* Dummy read, first read is ALWAYS wrong */ - ret = regmap_bulk_read(yas5xx->map, YAS5XX_CAL, data, sizeof(data)); + ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data)); if (ret) return ret; /* Actual calibration readout */ - ret = regmap_bulk_read(yas5xx->map, YAS5XX_CAL, data, sizeof(data)); + ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data)); if (ret) return ret; dev_dbg(yas5xx->dev, "calibration data: %*ph\n", 14, data); @@ -718,7 +724,7 @@ static int yas532_get_calibration_data(struct yas5xx *yas5xx) c->Cx = data[0] * 10 - 1280; c->Cy1 = data[1] * 10 - 1280; c->Cy2 = data[2] * 10 - 1280; - yas53x_extract_calibration(&data[3], c); + yas530_extract_calibration(&data[3], c); /* * Extract linearization: * Linearization layout in the 32 bits at byte 10: @@ -741,7 +747,8 @@ static int yas532_get_calibration_data(struct yas5xx *yas5xx) return 0; } -static void yas5xx_dump_calibration(struct yas5xx *yas5xx) +/* Used by YAS530, YAS532 and YAS533 */ +static void yas530_dump_calibration(struct yas5xx *yas5xx) { struct yas5xx_calibration *c = &yas5xx->calibration; @@ -764,20 +771,22 @@ static void yas5xx_dump_calibration(struct yas5xx *yas5xx) dev_dbg(yas5xx->dev, "dck = %d\n", c->dck); } -static int yas5xx_set_offsets(struct yas5xx *yas5xx, s8 ox, s8 oy1, s8 oy2) +/* Used by YAS530, YAS532 and YAS533 */ +static int yas530_set_offsets(struct yas5xx *yas5xx, s8 ox, s8 oy1, s8 oy2) { int ret; - ret = regmap_write(yas5xx->map, YAS5XX_OFFSET_X, ox); + ret = regmap_write(yas5xx->map, YAS530_OFFSET_X, ox); if (ret) return ret; - ret = regmap_write(yas5xx->map, YAS5XX_OFFSET_Y1, oy1); + ret = regmap_write(yas5xx->map, YAS530_OFFSET_Y1, oy1); if (ret) return ret; - return regmap_write(yas5xx->map, YAS5XX_OFFSET_Y2, oy2); + return regmap_write(yas5xx->map, YAS530_OFFSET_Y2, oy2); } -static s8 yas5xx_adjust_offset(s8 old, int bit, u16 center, u16 measure) +/* Used by YAS530, YAS532 and YAS533 */ +static s8 yas530_adjust_offset(s8 old, int bit, u16 center, u16 measure) { if (measure > center) return old + BIT(bit); @@ -786,7 +795,8 @@ static s8 yas5xx_adjust_offset(s8 old, int bit, u16 center, u16 measure) return old; } -static int yas5xx_meaure_offsets(struct yas5xx *yas5xx) +/* Used by YAS530, YAS532 and YAS533 */ +static int yas530_measure_offsets(struct yas5xx *yas5xx) { int ret; u16 center; @@ -795,7 +805,7 @@ static int yas5xx_meaure_offsets(struct yas5xx *yas5xx) int i; /* Actuate the init coil and measure offsets */ - ret = regmap_write(yas5xx->map, YAS5XX_ACTUATE_INIT_COIL, 0); + ret = regmap_write(yas5xx->map, YAS530_ACTUATE_INIT_COIL, 0); if (ret) return ret; @@ -829,26 +839,26 @@ static int yas5xx_meaure_offsets(struct yas5xx *yas5xx) oy2 = 0; for (i = 4; i >= 0; i--) { - ret = yas5xx_set_offsets(yas5xx, ox, oy1, oy2); + ret = yas530_set_offsets(yas5xx, ox, oy1, oy2); if (ret) return ret; - ret = yas5xx_measure(yas5xx, &t, &x, &y1, &y2); + ret = yas530_measure(yas5xx, &t, &x, &y1, &y2); if (ret) return ret; dev_dbg(yas5xx->dev, "measurement %d: x=%d, y1=%d, y2=%d\n", 5-i, x, y1, y2); - ox = yas5xx_adjust_offset(ox, i, center, x); - oy1 = yas5xx_adjust_offset(oy1, i, center, y1); - oy2 = yas5xx_adjust_offset(oy2, i, center, y2); + ox = yas530_adjust_offset(ox, i, center, x); + oy1 = yas530_adjust_offset(oy1, i, center, y1); + oy2 = yas530_adjust_offset(oy2, i, center, y2); } /* Needed for calibration algorithm */ yas5xx->hard_offsets[0] = ox; yas5xx->hard_offsets[1] = oy1; yas5xx->hard_offsets[2] = oy2; - ret = yas5xx_set_offsets(yas5xx, ox, oy1, oy2); + ret = yas530_set_offsets(yas5xx, ox, oy1, oy2); if (ret) return ret; @@ -857,27 +867,28 @@ static int yas5xx_meaure_offsets(struct yas5xx *yas5xx) return 0; } -static int yas5xx_power_on(struct yas5xx *yas5xx) +/* Used by YAS530, YAS532 and YAS533 */ +static int yas530_power_on(struct yas5xx *yas5xx) { unsigned int val; int ret; /* Zero the test registers */ - ret = regmap_write(yas5xx->map, YAS5XX_TEST1, 0); + ret = regmap_write(yas5xx->map, YAS530_TEST1, 0); if (ret) return ret; - ret = regmap_write(yas5xx->map, YAS5XX_TEST2, 0); + ret = regmap_write(yas5xx->map, YAS530_TEST2, 0); if (ret) return ret; /* Set up for no interrupts, calibrated clock divider */ val = FIELD_PREP(YAS5XX_CONFIG_CCK_MASK, yas5xx->calibration.dck); - ret = regmap_write(yas5xx->map, YAS5XX_CONFIG, val); + ret = regmap_write(yas5xx->map, YAS530_CONFIG, val); if (ret) return ret; /* Measure interval 0 (back-to-back?) */ - return regmap_write(yas5xx->map, YAS5XX_MEASURE_INTERVAL, 0); + return regmap_write(yas5xx->map, YAS530_MEASURE_INTERVAL, 0); } static int yas5xx_probe(struct i2c_client *i2c, @@ -959,11 +970,11 @@ static int yas5xx_probe(struct i2c_client *i2c, goto assert_reset; } - yas5xx_dump_calibration(yas5xx); - ret = yas5xx_power_on(yas5xx); + yas530_dump_calibration(yas5xx); + ret = yas530_power_on(yas5xx); if (ret) goto assert_reset; - ret = yas5xx_meaure_offsets(yas5xx); + ret = yas530_measure_offsets(yas5xx); if (ret) goto assert_reset; From patchwork Sun Jul 3 22:02:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12904503 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 078E8CCA483 for ; Sun, 3 Jul 2022 22:03:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232277AbiGCWDa (ORCPT ); Sun, 3 Jul 2022 18:03:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232425AbiGCWD2 (ORCPT ); Sun, 3 Jul 2022 18:03:28 -0400 Received: from sonic312-26.consmr.mail.ir2.yahoo.com (sonic312-26.consmr.mail.ir2.yahoo.com [77.238.178.97]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BEFB2DE2 for ; Sun, 3 Jul 2022 15:03:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1656885802; bh=06ZbKj/O4G/euSZD9awuYJpka4OzYY+PQp4ku8CMgmQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=VTjDKusmbE02aK9POjVKUDrEC5I4ZIGFE3sIKrhcmxXegw59xksRqoCToLxs5XUe3kwS96oAfHiiVhUcYNHZn4URm7Ap4bdC9OwAJo9r/O1GpFOw42+yJqTuuN2QlwjbJlrjEzh74TZlVHfTGxSzpsmQfHF9jVUhnx/nJiGMqcd/Q7o/1596Gj3iE+KbbomLwOGoefXK8pHVWZxrx+CBe4lBh6IgTl1i+GZXd937Y56cBKG9lYy766WT42JeKXuvFKpUXsWSBXJ6CL0k8C4ENJjULTyvwqcWB77Ny0WCFlE8/nKjgTpgnvMs1IDTpq8vuxcTmUUcDbFyp+KbvAJteQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1656885802; bh=lTQ94aS5OZ7nfyRM+YnALrl2PnpTbe3/pEq6ipE9ij+=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=C8HJCFUJuLc+dpaeX6FX77AD77phZ7iRTHaM9ZG/bwGHfrR5nzFJYwFu77EOUqh4U1+QmM2V1McHu9aQoIihEl+FJQe82BqOwGY3CPvfjtNmjNqdPvJ+btc762NJVousljaiLOQMHLKJ0y3VIZMOuikTsPJFWe0nqze/jL5GBrg7KtYOUQPtu0EdU3eXSFXl3zwzqszgYpjFtzCg+WIAefbcr9aOQVakwy74LcKz4ZiU2vYzsjZfR5o0zy/bH2AGDVxMGxfcpAx9HF6mA87kR8AAK5v387/FXKm6BHd2/b9byZ/SzxHuddHnuoI+mCuF//VGsolR+v/GvFjvdlgYPg== X-YMail-OSG: b5S8CAkVM1nYj4_978Yb7K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B5Dp6nTGuZTW2sQuqdXAi1mN_1VfWHGIZTyo6T RvKH0ouibkymiedTG2Vrep4ekvRdc5mzX72EvFIZAQD0NTRrm2ZoRYKQkDi2xadkABkgEz6K5hFJ n7sFEQ4YvfMKl1vteN9kC5Gk8xB2k9XifsLN9nT.UCbVkwAaBUAfiGe96wYqnJowTRhWCRXpqTJO xZ.hfKtoqzc8ERuti X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic312.consmr.mail.ir2.yahoo.com with HTTP; Sun, 3 Jul 2022 22:03:22 +0000 Received: by hermes--canary-production-ir2-74b4d6d794-tv8mb (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 0849bd8970b52a790a5a1bb96f2e336c; Sun, 03 Jul 2022 22:03:20 +0000 (UTC) From: Jakob Hauser To: Jonathan Cameron Cc: Lars-Peter Clausen , Linus Walleij , Andy Shevchenko , Hans de Goede , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH v4 07/10] iio: magnetometer: yas530: Move printk %*ph parameters out from stack Date: Mon, 4 Jul 2022 00:02:41 +0200 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Use less stack by modifying %*ph parameters. Additionally, in the function yas530_get_calibration_data(), the debug dump was extended to 16 elements as this is the size of the calibration data array of YAS530. Signed-off-by: Jakob Hauser --- drivers/iio/magnetometer/yamaha-yas530.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index c250909df8f4..8358d4b3d1e2 100644 --- a/drivers/iio/magnetometer/yamaha-yas530.c +++ b/drivers/iio/magnetometer/yamaha-yas530.c @@ -661,7 +661,7 @@ static int yas530_get_calibration_data(struct yas5xx *yas5xx) ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data)); if (ret) return ret; - dev_dbg(yas5xx->dev, "calibration data: %*ph\n", 14, data); + dev_dbg(yas5xx->dev, "calibration data: %16ph\n", data); add_device_randomness(data, sizeof(data)); yas5xx->version = data[15] & GENMASK(1, 0); @@ -708,7 +708,7 @@ static int yas532_get_calibration_data(struct yas5xx *yas5xx) ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data)); if (ret) return ret; - dev_dbg(yas5xx->dev, "calibration data: %*ph\n", 14, data); + dev_dbg(yas5xx->dev, "calibration data: %14ph\n", data); /* Sanity check, is this all zeroes? */ if (memchr_inv(data, 0x00, 13) == NULL) { From patchwork Sun Jul 3 22:02:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12904504 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 5615DCCA473 for ; Sun, 3 Jul 2022 22:03:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232425AbiGCWDc (ORCPT ); Sun, 3 Jul 2022 18:03:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231905AbiGCWDb (ORCPT ); Sun, 3 Jul 2022 18:03:31 -0400 Received: from sonic314-20.consmr.mail.ir2.yahoo.com (sonic314-20.consmr.mail.ir2.yahoo.com [77.238.177.146]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B013E2BDB for ; Sun, 3 Jul 2022 15:03:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1656885807; bh=OfDSYQwQvZKC/QF+iVLWNzwkWD6d9XWRERzlXTFUHKQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=MWDDQCuJX8kKggLex6fS5SyrjfvgGJxFYqz5t6tQhXycdDtMmDhrBeiro43HFCiB2ahxO7gYQo9O5UawzxvlcULTFDEVyT4uwOZhU6oyGO2lx+FsZaTpvcHAvTx6YmNgB/uyeZ0wjg6UQ8Su8Q/FdF9723eCkDujcfbjXrila/KlXxll0K0DwjDRA7EHJ3OF+X9DK0ZxPOPE92qqfl8lsQrxG3Aj9KbjLUq9x+9e8vRB4oscylwe6RgEn3LsHdmcPjJsGwbMmH0RIfqJPUmeiqeNTKn/l/y3prEFYSiqLkQpOKS5ZEsOMvL9N+UwQdEPSSsNoSirfqQJn3Z8FCXO/g== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1656885807; bh=/2V4NheHlXOBXV3OKEUEe5Arrqzf1oIHGnUD9ZYW2yR=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=qUnEQMBD1I6KiZAVKuNwp22YmMpW/I8ZCQ3pSuxTFX4/eUCysCmRVQN8nDoLmIl0jT1+/CTvTHQXj34B/G9067pJJBVPO0ivRqfmevIXFyMsbG4ai53qMFyOtyjFV1D8l0RvgVB373y4KJTCeXLM5N0kXANorQ5SMLBF+OeWYYUvozv8+1qmTgmqKwLxrHobFAvNfgpBGL+Z4yXcenUXW5NktEVVqgxlW6pgKK6aQoeA7DxgwBDXEYCaYfOzTlu3Y4U9k+qcvlia0fJOo97tLo0OJ8qTr0aHPFuggQOLwXJ81Xpyy1lxuiR+4/UDQMaAlOK24Mxk3gF9WXo2ddQ6NA== X-YMail-OSG: zDoUJ_EVM1mOYs.fkoXbSAXtv1OQJwx_4CXaegpzQ_Um3hw2ZPwaILfVSe.HxAA jbqWs426im_rjJBjIqzAKz8mAS4FNilSq5xU4preM1ix9YffDYmoXceKKAlDkx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0PQIvnESfvfLu5jxvyj3.WkYA0xAj3MoY.HP1QmorlBLPb5ikwM7FTaEm.Lp qNmWEGkAp7Hkrdh2ALg-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic314.consmr.mail.ir2.yahoo.com with HTTP; Sun, 3 Jul 2022 22:03:27 +0000 Received: by hermes--canary-production-ir2-74b4d6d794-tv8mb (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 0849bd8970b52a790a5a1bb96f2e336c; Sun, 03 Jul 2022 22:03:22 +0000 (UTC) From: Jakob Hauser To: Jonathan Cameron Cc: Lars-Peter Clausen , Linus Walleij , Andy Shevchenko , Hans de Goede , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH v4 08/10] iio: magnetometer: yas530: Apply documentation and style fixes Date: Mon, 4 Jul 2022 00:02:42 +0200 Message-Id: <8a1fb0faedc25aa2fbf9852cf4e1d9d085675ad6.1656883851.git.jahau@rocketmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This commit gathers several minor changes. In the device examples, "Xiaomi" is too generic, specific devices should be listed here. E.g. Xiaomi Redmi 2 seems to have YAS537 but it's not fully clear if this applies to all its variants. Samsung Galaxy S7 is often quoted in conjunction with YAS537. Removed defines for device IDs of YAS537 and YAS539, they are not needed so far. Signed-off-by: Jakob Hauser Reviewed-by: Andy Shevchenko Reviewed-by: Linus Walleij --- drivers/iio/magnetometer/yamaha-yas530.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index 8358d4b3d1e2..4e2f460a4efd 100644 --- a/drivers/iio/magnetometer/yamaha-yas530.c +++ b/drivers/iio/magnetometer/yamaha-yas530.c @@ -10,7 +10,7 @@ * (YAS534 is a magnetic switch, not handled) * YAS535 MS-6C * YAS536 MS-3W - * YAS537 MS-3T (2015 Samsung Galaxy S6, Note 5, Xiaomi) + * YAS537 MS-3T (2015 Samsung Galaxy S6, Note 5, Galaxy S7) * YAS539 MS-3S (2018 Samsung Galaxy A7 SM-A750FN) * * Code functions found in the MPU3050 YAS530 and YAS532 drivers @@ -93,10 +93,6 @@ #define YAS532_DATA_OVERFLOW (BIT(YAS532_DATA_BITS) - 1) #define YAS532_20DEGREES 390 /* Counts starting at -50 °C */ -/* These variant IDs are known from code dumps */ -#define YAS537_DEVICE_ID 0x07 /* YAS537 (MS-3T) */ -#define YAS539_DEVICE_ID 0x08 /* YAS539 (MS-3S) */ - /* Turn off device regulators etc after 5 seconds of inactivity */ #define YAS5XX_AUTOSUSPEND_DELAY_MS 5000 @@ -323,7 +319,7 @@ static int yas530_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, { struct yas5xx_calibration *c = &yas5xx->calibration; u16 t_ref, t, x, y1, y2; - /* These are "signed x, signed y1 etc */ + /* These are signed x, signed y1 etc */ s32 sx, sy1, sy2, sy, sz; int ret; @@ -663,7 +659,10 @@ static int yas530_get_calibration_data(struct yas5xx *yas5xx) return ret; dev_dbg(yas5xx->dev, "calibration data: %16ph\n", data); + /* Contribute calibration data to the input pool for kernel entropy */ add_device_randomness(data, sizeof(data)); + + /* Extract version */ yas5xx->version = data[15] & GENMASK(1, 0); /* Extract the calibration from the bitfield */ @@ -690,6 +689,7 @@ static int yas530_get_calibration_data(struct yas5xx *yas5xx) c->r[0] = sign_extend32(FIELD_GET(GENMASK(28, 23), val), 5); c->r[1] = sign_extend32(FIELD_GET(GENMASK(20, 15), val), 5); c->r[2] = sign_extend32(FIELD_GET(GENMASK(12, 7), val), 5); + return 0; } @@ -711,12 +711,12 @@ static int yas532_get_calibration_data(struct yas5xx *yas5xx) dev_dbg(yas5xx->dev, "calibration data: %14ph\n", data); /* Sanity check, is this all zeroes? */ - if (memchr_inv(data, 0x00, 13) == NULL) { - if (!(data[13] & BIT(7))) - dev_warn(yas5xx->dev, "calibration is blank!\n"); - } + if (!memchr_inv(data, 0x00, 13) && !(data[13] & BIT(7))) + dev_warn(yas5xx->dev, "calibration is blank!\n"); + /* Contribute calibration data to the input pool for kernel entropy */ add_device_randomness(data, sizeof(data)); + /* Only one bit of version info reserved here as far as we know */ yas5xx->version = data[13] & BIT(0); @@ -725,6 +725,7 @@ static int yas532_get_calibration_data(struct yas5xx *yas5xx) c->Cy1 = data[1] * 10 - 1280; c->Cy2 = data[2] * 10 - 1280; yas530_extract_calibration(&data[3], c); + /* * Extract linearization: * Linearization layout in the 32 bits at byte 10: From patchwork Sun Jul 3 22:04:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12904505 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 C4EC1C43334 for ; Sun, 3 Jul 2022 22:04:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230353AbiGCWEm (ORCPT ); Sun, 3 Jul 2022 18:04:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230174AbiGCWEm (ORCPT ); Sun, 3 Jul 2022 18:04:42 -0400 Received: from sonic311-31.consmr.mail.ir2.yahoo.com (sonic311-31.consmr.mail.ir2.yahoo.com [77.238.176.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 184D52AC5 for ; Sun, 3 Jul 2022 15:04:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1656885878; bh=zhV4kNJHQ91AOiE3U+WxaLMR79nF0FGx7CXAYspbze0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=aVkuSHkVRC3e15Dgu4DrU3vm5j8H7u+GslK/jY5eaH2vQI8x0Hzh/CTrwWN3PWM2il43H5d/dHYddYlLraFdX1BNoMkRRv4HSnSALHapL56zut8vBseMIFryN/FEe614nGkErrkWj80l0QUmQBGYfcdc7PQ3N4qVvk/aegdPKQN6J0fz2GG/MFKxsuATz80VK3S9ZgcAb+PgrblhAdd83UW0IUFN4ypQalTsmyH6xENJfWF/rKkhFqKD8cZhFVaI6Yo3C/Jr05m7Pwqz5kczAurhsJPqDeagU2+zkQ1YELAcVazheKY1lG1gkY28mUE/Ot9ZZDByNfeAaWy2VQARJg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1656885878; bh=tjfRZoKcJyn5uosTvxCJYVRbtC5sb9+/1SWTnI4GGDP=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=icTxwsIcCdMX5OYdEou/0CWs4WzEX3iz16gIImEDdOcaKXgQM9dxGtt4qhXhfeMxcL6wUy/10MCgYH7iE+sI1je7OmYGyirie63jXed1F59/Fu/tZBsJL61HuLpPksnEf6sxATur0D8N6+CgaS/3GOKN67SV1CilUnOzlpzLac+iAtPAb8Wv15Zu+M3t14oM5MLulm4W/69kva4+m5hoy+0l6dnVfiNMW61FbnzehcoxaS/4mQ9oTZKQTbAkF9wdfGZ5CCRiBKjNFzcpvcg+he3vexqFAryKMKzaXXQP/Z5bnuLnIMyUqvJG4gKZLGWZBvRAy2IlZ6IzaBKx906OVw== X-YMail-OSG: DPGLBKMVM1nElwBL7_g9ZpYy00wPQTPFhhulvoMfC9OZHvaq7.psm5xj8GBZiqM QsJpQYfsylOIUpSo7Yxi4W88tAdOWJ1tbtsiUDrujgv5tMvwHI6bWSr4li78x.nYF57ISuu82_bZ Y8507sMfekIoJR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xyVMQG2SVQQvZvXX.tC22vTg4Mxl7LcvCIfllSTSjPWx_ws0crQByG LHqXsfABhO45EKIYV11Hkb8na X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.ir2.yahoo.com with HTTP; Sun, 3 Jul 2022 22:04:38 +0000 Received: by hermes--canary-production-ir2-74b4d6d794-rsm7w (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 0750169e44cb0b4394403fc70acb325a; Sun, 03 Jul 2022 22:04:36 +0000 (UTC) From: Jakob Hauser To: Jonathan Cameron Cc: Lars-Peter Clausen , Linus Walleij , Andy Shevchenko , Hans de Goede , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH v4 09/10] iio: magnetometer: yas530: Introduce "chip_info" structure Date: Mon, 4 Jul 2022 00:04:17 +0200 Message-Id: <28a2a9ec27c6fb4073149b897415475a8f04e3f7.1656883851.git.jahau@rocketmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This commit introduces the "chip_info" structure approach for better variant handling. The variant to be used is now chosen by the devicetree (enum "chip_ids"), not by the chip ID in the register. However, there is a check to make sure they match (using integer "id_check"). Signed-off-by: Jakob Hauser --- Result of the patch can be seen at: https://github.com/Jakko3/linux/blob/28a2a9ec27c6fb4073149b897415475a8f04e3f7/drivers/iio/magnetometer/yamaha-yas530.c drivers/iio/magnetometer/yamaha-yas530.c | 314 +++++++++++++---------- 1 file changed, 182 insertions(+), 132 deletions(-) diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index 4e2f460a4efd..ce9c1077c121 100644 --- a/drivers/iio/magnetometer/yamaha-yas530.c +++ b/drivers/iio/magnetometer/yamaha-yas530.c @@ -79,7 +79,6 @@ #define YAS530_DATA_BITS 12 #define YAS530_DATA_CENTER BIT(YAS530_DATA_BITS - 1) #define YAS530_DATA_OVERFLOW (BIT(YAS530_DATA_BITS) - 1) -#define YAS530_20DEGREES 182 /* Counts starting at -62 °C */ #define YAS532_DEVICE_ID 0x02 /* YAS532/YAS533 (MS-3R/F) */ #define YAS532_VERSION_AB 0 /* YAS532/533 AB (MS-3R/F AB) */ @@ -91,11 +90,39 @@ #define YAS532_DATA_BITS 13 #define YAS532_DATA_CENTER BIT(YAS532_DATA_BITS - 1) #define YAS532_DATA_OVERFLOW (BIT(YAS532_DATA_BITS) - 1) -#define YAS532_20DEGREES 390 /* Counts starting at -50 °C */ /* Turn off device regulators etc after 5 seconds of inactivity */ #define YAS5XX_AUTOSUSPEND_DELAY_MS 5000 +enum chip_ids { + yas530, + yas532, + yas533, +}; + +static const char yas5xx_product_name[][13] = { + "YAS530 MS-3E", + "YAS532 MS-3R", + "YAS533 MS-3F" +}; + +static const char yas5xx_version_name[][2][3] = { + { "A", "B" }, + { "AB", "AC" }, + { "AB", "AC" } +}; + +static const int yas530_volatile_reg[] = { + YAS530_ACTUATE_INIT_COIL, + YAS530_MEASURE +}; + +/* Number of counts between minimum and reference temperature */ +const u16 t_ref_counts[] = { 182, 390, 390 }; + +/* Starting point of temperature counting in 1/10:s degrees Celsius */ +const s16 min_temp_celcius_x10[] = { -620, -500, -500 }; + struct yas5xx_calibration { /* Linearization calibration x, y1, y2 */ s32 r[3]; @@ -110,12 +137,38 @@ struct yas5xx_calibration { u8 dck; }; +struct yas5xx; + +/** + * struct yas5xx_chip_info - device-specific data and function pointers + * @devid: device ID number + * @volatile_reg: device-specific volatile registers + * @volatile_reg_qty: quantity of device-specific volatile registers + * @scaling_val2: scaling value for IIO_CHAN_INFO_SCALE + * @get_measure: function pointer to get a measurement + * @get_calibration_data: function pointer to get calibration data + * @dump_calibration: function pointer to dump calibration for debugging + * @measure_offsets: function pointer to measure the offsets + * @power_on: function pointer to power-on procedure + */ +struct yas5xx_chip_info { + unsigned int devid; + const int *volatile_reg; + const int volatile_reg_qty; + const u32 scaling_val2; + int (*get_measure)(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, s32 *zo); + int (*get_calibration_data)(struct yas5xx *yas5xx); + void (*dump_calibration)(struct yas5xx *yas5xx); + int (*measure_offsets)(struct yas5xx *yas5xx); + int (*power_on)(struct yas5xx *yas5xx); +}; + /** * struct yas5xx - state container for the YAS5xx driver * @dev: parent device pointer - * @devid: device ID number + * @chip: enumeration of the device variant + * @chip_info: device-specific data and function pointers * @version: device version - * @name: device name * @calibration: calibration settings from the OTP storage * @hard_offsets: offsets for each axis measured with initcoil actuated * @orientation: mounting matrix, flipped axis etc @@ -129,9 +182,9 @@ struct yas5xx_calibration { */ struct yas5xx { struct device *dev; - unsigned int devid; + enum chip_ids chip; + struct yas5xx_chip_info *chip_info; unsigned int version; - char name[16]; struct yas5xx_calibration calibration; s8 hard_offsets[3]; struct iio_mount_matrix orientation; @@ -221,7 +274,7 @@ static int yas530_measure(struct yas5xx *yas5xx, u16 *t, u16 *x, u16 *y1, u16 *y mutex_unlock(&yas5xx->lock); - switch (yas5xx->devid) { + switch (yas5xx->chip_info->devid) { case YAS530_DEVICE_ID: /* * The t value is 9 bits in big endian format @@ -275,7 +328,7 @@ static s32 yas530_linearize(struct yas5xx *yas5xx, u16 val, int axis) s32 coef; /* Select coefficients */ - switch (yas5xx->devid) { + switch (yas5xx->chip_info->devid) { case YAS530_DEVICE_ID: if (yas5xx->version == YAS530_VERSION_A) coef = YAS530_VERSION_A_COEF; @@ -305,6 +358,20 @@ static s32 yas530_linearize(struct yas5xx *yas5xx, u16 val, int axis) (yas5xx->hard_offsets[axis] - c->r[axis]) * coef; } +static s32 yas5xx_calc_temperature(struct yas5xx *yas5xx, u16 t) +{ + s32 to; + u16 t_ref; + int min_temp_x10, ref_temp_x10; + + t_ref = t_ref_counts[yas5xx->chip]; + min_temp_x10 = min_temp_celcius_x10[yas5xx->chip]; + ref_temp_x10 = 200; + + to = (min_temp_x10 + ((ref_temp_x10 - min_temp_x10) * t / t_ref)) * 100; + return to; +} + /** * yas530_get_measure() - Measure a sample of all axis and process * @yas5xx: The device state @@ -318,7 +385,7 @@ static s32 yas530_linearize(struct yas5xx *yas5xx, u16 val, int axis) static int yas530_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, s32 *zo) { struct yas5xx_calibration *c = &yas5xx->calibration; - u16 t_ref, t, x, y1, y2; + u16 t_ref, t_comp, t, x, y1, y2; /* These are signed x, signed y1 etc */ s32 sx, sy1, sy2, sy, sz; int ret; @@ -333,47 +400,30 @@ static int yas530_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, sy1 = yas530_linearize(yas5xx, y1, 1); sy2 = yas530_linearize(yas5xx, y2, 2); - /* Set the temperature reference value (unit: counts) */ - switch (yas5xx->devid) { - case YAS530_DEVICE_ID: - t_ref = YAS530_20DEGREES; - break; - case YAS532_DEVICE_ID: - t_ref = YAS532_20DEGREES; - break; - default: - dev_err(yas5xx->dev, "unknown device type\n"); - return -EINVAL; - } - - /* Temperature compensation for x, y1, y2 respectively */ - if (yas5xx->devid == YAS532_DEVICE_ID && + /* + * Set the temperature for compensation (unit: counts): + * YAS532/YAS533 version AC uses the temperature deviation as a + * multiplier. YAS530 and YAS532 version AB use solely the t value. + */ + t_ref = t_ref_counts[yas5xx->chip]; + if (yas5xx->chip_info->devid == YAS532_DEVICE_ID && yas5xx->version == YAS532_VERSION_AC) { - /* - * YAS532 version AC uses the temperature deviation as a - * multiplier. - * - * Cx * (t - t_ref) - * x' = x - ---------------- - * 100 - */ - sx = sx - (c->Cx * (t - t_ref)) / 100; - sy1 = sy1 - (c->Cy1 * (t - t_ref)) / 100; - sy2 = sy2 - (c->Cy2 * (t - t_ref)) / 100; + t_comp = t - t_ref; } else { - /* - * YAS530 and YAS532 version AB use solely the t value as a - * multiplier. - * - * Cx * t - * x' = x - ------ - * 100 - */ - sx = sx - (c->Cx * t) / 100; - sy1 = sy1 - (c->Cy1 * t) / 100; - sy2 = sy2 - (c->Cy2 * t) / 100; + t_comp = t; } + /* + * Temperature compensation for x, y1, y2 respectively: + * + * Cx * t_comp + * x' = x - ----------- + * 100 + */ + sx = sx - (c->Cx * t_comp) / 100; + sy1 = sy1 - (c->Cy1 * t_comp) / 100; + sy2 = sy2 - (c->Cy2 * t_comp) / 100; + /* * Break y1 and y2 into y and z, y1 and y2 are apparently encoding * y and z. @@ -381,36 +431,8 @@ static int yas530_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, sy = sy1 - sy2; sz = -sy1 - sy2; - /* Process temperature readout */ - switch (yas5xx->devid) { - case YAS530_DEVICE_ID: - /* - * Raw temperature value t is the number of counts starting - * at -62 °C. Reference value t_ref is the number of counts - * between -62 °C and 20 °C (82 °C range). - * - * Temperature in °C would be (82 / t_ref * t) - 62. - * - * Contrary to this, perform multiplication first and division - * second due to calculating with integers. - * - * To get a nicer result, calculate with 1/10:s degrees Celsius - * and finally multiply by 100 to return millidegrees Celsius. - */ - *to = ((820 * t / t_ref) - 620) * 100; - break; - case YAS532_DEVICE_ID: - /* - * Actually same procedure for YAS532 but the starting point is - * at -50 °C. Reference value t_ref is the number of counts - * between -50 °C and 20 °C (70 °C range). - */ - *to = ((700 * t / t_ref) - 500) * 100; - break; - default: - dev_err(yas5xx->dev, "unknown device type\n"); - return -EINVAL; - } + /* Calculate temperature readout */ + *to = yas5xx_calc_temperature(yas5xx, t); /* * Calibrate [x,y,z] with some formulas like this: @@ -447,7 +469,7 @@ static int yas5xx_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_PROCESSED: case IIO_CHAN_INFO_RAW: pm_runtime_get_sync(yas5xx->dev); - ret = yas5xx_get_measure(yas5xx, &t, &x, &y, &z); + ret = yas5xx->chip_info->get_measure(yas5xx, &t, &x, &y, &z); pm_runtime_mark_last_busy(yas5xx->dev); pm_runtime_put_autosuspend(yas5xx->dev); if (ret) @@ -471,27 +493,8 @@ static int yas5xx_read_raw(struct iio_dev *indio_dev, } return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: - switch (yas5xx->devid) { - case YAS530_DEVICE_ID: - /* - * Raw values of YAS530 are in picotesla. Divide by - * 100000000 (10^8) to get Gauss. - */ - *val = 1; - *val2 = 100000000; - break; - case YAS532_DEVICE_ID: - /* - * Raw values of YAS532 are in nanotesla. Divide by - * 100000 (10^5) to get Gauss. - */ - *val = 1; - *val2 = 100000; - break; - default: - dev_err(yas5xx->dev, "unknown device type\n"); - return -EINVAL; - } + *val = 1; + *val2 = yas5xx->chip_info->scaling_val2; return IIO_VAL_FRACTIONAL; default: /* Unknown request */ @@ -506,7 +509,7 @@ static void yas5xx_fill_buffer(struct iio_dev *indio_dev) int ret; pm_runtime_get_sync(yas5xx->dev); - ret = yas5xx_get_measure(yas5xx, &t, &x, &y, &z); + ret = yas5xx->chip_info->get_measure(yas5xx, &t, &x, &y, &z); pm_runtime_mark_last_busy(yas5xx->dev); pm_runtime_put_autosuspend(yas5xx->dev); if (ret) { @@ -592,9 +595,24 @@ static const struct iio_info yas5xx_info = { static bool yas5xx_volatile_reg(struct device *dev, unsigned int reg) { - return reg == YAS5XX_ACTUATE_INIT_COIL || - reg == YAS5XX_MEASURE || - (reg >= YAS5XX_MEASURE_DATA && reg < YAS5XX_MEASURE_DATA + 8); + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct yas5xx *yas5xx = iio_priv(indio_dev); + int i, j; + + if (reg >= YAS5XX_MEASURE_DATA && reg < YAS5XX_MEASURE_DATA + 8) + return true; + + /* + * YAS versions share different registers on the same address, + * need to differentiate. + */ + j = yas5xx->chip_info->volatile_reg_qty; + for (i = 0; i < j; i++) { + if (reg == yas5xx->chip_info->volatile_reg[i]) + return true; + } + + return false; } /* TODO: enable regmap cache, using mark dirty and sync at runtime resume */ @@ -811,7 +829,7 @@ static int yas530_measure_offsets(struct yas5xx *yas5xx) return ret; /* When the initcoil is active this should be around the center */ - switch (yas5xx->devid) { + switch (yas5xx->chip_info->devid) { case YAS530_DEVICE_ID: center = YAS530_DATA_CENTER; break; @@ -892,13 +910,49 @@ static int yas530_power_on(struct yas5xx *yas5xx) return regmap_write(yas5xx->map, YAS530_MEASURE_INTERVAL, 0); } +static struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { + [yas530] = { + .devid = YAS530_DEVICE_ID, + .volatile_reg = yas530_volatile_reg, + .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), + .scaling_val2 = 100000000, /* picotesla to Gauss */ + .get_measure = yas530_get_measure, + .get_calibration_data = yas530_get_calibration_data, + .dump_calibration = yas530_dump_calibration, + .measure_offsets = yas530_measure_offsets, + .power_on = yas530_power_on, + }, + [yas532] = { + .devid = YAS532_DEVICE_ID, + .volatile_reg = yas530_volatile_reg, + .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), + .scaling_val2 = 100000, /* nanotesla to Gauss */ + .get_measure = yas530_get_measure, + .get_calibration_data = yas532_get_calibration_data, + .dump_calibration = yas530_dump_calibration, + .measure_offsets = yas530_measure_offsets, + .power_on = yas530_power_on, + }, + [yas533] = { + .devid = YAS532_DEVICE_ID, + .volatile_reg = yas530_volatile_reg, + .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), + .scaling_val2 = 100000, /* nanotesla to Gauss */ + .get_measure = yas530_get_measure, + .get_calibration_data = yas532_get_calibration_data, + .dump_calibration = yas530_dump_calibration, + .measure_offsets = yas530_measure_offsets, + .power_on = yas530_power_on, + } +}; + static int yas5xx_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct iio_dev *indio_dev; struct device *dev = &i2c->dev; struct yas5xx *yas5xx; - int ret; + int id_check, ret; indio_dev = devm_iio_device_alloc(dev, sizeof(*yas5xx)); if (!indio_dev) @@ -944,45 +998,41 @@ static int yas5xx_probe(struct i2c_client *i2c, goto assert_reset; } - ret = regmap_read(yas5xx->map, YAS5XX_DEVICE_ID, &yas5xx->devid); + yas5xx->chip = id->driver_data; + yas5xx->chip_info = &yas5xx_chip_info_tbl[yas5xx->chip]; + + ret = regmap_read(yas5xx->map, YAS5XX_DEVICE_ID, &id_check); if (ret) goto assert_reset; - switch (yas5xx->devid) { - case YAS530_DEVICE_ID: - ret = yas530_get_calibration_data(yas5xx); - if (ret) - goto assert_reset; - dev_info(dev, "detected YAS530 MS-3E %s", - yas5xx->version ? "B" : "A"); - strncpy(yas5xx->name, "yas530", sizeof(yas5xx->name)); - break; - case YAS532_DEVICE_ID: - ret = yas532_get_calibration_data(yas5xx); - if (ret) - goto assert_reset; - dev_info(dev, "detected YAS532/YAS533 MS-3R/F %s", - yas5xx->version ? "AC" : "AB"); - strncpy(yas5xx->name, "yas532", sizeof(yas5xx->name)); - break; - default: + if (id_check != yas5xx->chip_info->devid) { ret = -ENODEV; - dev_err(dev, "unhandled device ID %02x\n", yas5xx->devid); + dev_err(dev, "device ID %02x doesn't match %s\n", + id_check, id->name); goto assert_reset; } - yas530_dump_calibration(yas5xx); - ret = yas530_power_on(yas5xx); + ret = yas5xx->chip_info->get_calibration_data(yas5xx); if (ret) goto assert_reset; - ret = yas530_measure_offsets(yas5xx); + + dev_info(dev, "detected %s %s\n", yas5xx_product_name[yas5xx->chip], + yas5xx_version_name[yas5xx->chip][yas5xx->version]); + + yas5xx->chip_info->dump_calibration(yas5xx); + + ret = yas5xx->chip_info->power_on(yas5xx); + if (ret) + goto assert_reset; + + ret = yas5xx->chip_info->measure_offsets(yas5xx); if (ret) goto assert_reset; indio_dev->info = &yas5xx_info; indio_dev->available_scan_masks = yas5xx_scan_masks; indio_dev->modes = INDIO_DIRECT_MODE; - indio_dev->name = yas5xx->name; + indio_dev->name = id->name; indio_dev->channels = yas5xx_channels; indio_dev->num_channels = ARRAY_SIZE(yas5xx_channels); @@ -1074,7 +1124,7 @@ static int __maybe_unused yas5xx_runtime_resume(struct device *dev) usleep_range(31000, 40000); gpiod_set_value_cansleep(yas5xx->reset, 0); - ret = yas5xx_power_on(yas5xx); + ret = yas5xx->chip_info->power_on(yas5xx); if (ret) { dev_err(dev, "cannot power on\n"); goto out_reset; @@ -1097,9 +1147,9 @@ static const struct dev_pm_ops yas5xx_dev_pm_ops = { }; static const struct i2c_device_id yas5xx_id[] = { - {"yas530", }, - {"yas532", }, - {"yas533", }, + {"yas530", yas530 }, + {"yas532", yas532 }, + {"yas533", yas533 }, {} }; MODULE_DEVICE_TABLE(i2c, yas5xx_id); From patchwork Sun Jul 3 22:05:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12904506 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 0013FC43334 for ; Sun, 3 Jul 2022 22:05:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232486AbiGCWF2 (ORCPT ); Sun, 3 Jul 2022 18:05:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231928AbiGCWF1 (ORCPT ); Sun, 3 Jul 2022 18:05:27 -0400 Received: from sonic311-31.consmr.mail.ir2.yahoo.com (sonic311-31.consmr.mail.ir2.yahoo.com [77.238.176.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A6012AC5 for ; Sun, 3 Jul 2022 15:05:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1656885923; bh=xeaQAtSYen5im4d0xYT+4mLQA+4xdErIBXh0BuTWz/8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=Hpxp6jghvgIRXdkrk6G3rOhiFaqMrHT1p8aph44uT/YhZYQVTXaWNh5LPbnZL6N/YGb+KBGtZNJFvzlSX7/PhWYFH3uG7M8su+uuX42I+ypXWial8JIBSMHUSj20VDSpitqfCVj85vj/VeB82Dq/9WKJAbof485kgdUg+i0o/i2s9DCtPtFrbamqwjkKXkXRKCThW9Rk8PoWd0A3h21a2pmbkAXS+/YzTENes/+oelnHYCuCTkT/Eae6XxrDN5fayAeoQw5kK+R/+J42dV/AOKDP0cQee2amH4Deadtdx4deQEj+23RIVV2/GGBP/tAhBYw/Yerzs9rmZFq/udB3rg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1656885923; bh=LuRBcq+8+gqtqU7QQL089C+goOdKz4wk8nKubSoWJZT=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=VjiUFbOqVdTeBGn/FeQoAi8FbcBCg98iUsboxFM51qK0Ba9di+rIzFwyeZNIOkXz/6A5JOVkcg/mAzBEX+oN5FLeRpoBcXPkuzQWhhahqcvXLieJ0FCXW5aGG9kiZK80MkYGQg6eHBHLt6I7XlxsnyJWivCfFZSn7j1opBCKEEcfsmaXyL2+2MIXTx+LLEDhrZ/1EN//5hGeU/CZh3s2KI2alxsnA8fVrbq964/87daq4n2FI+xyhYxvXzWuo/Vbmqz2kNMKX19joEWgc50dsLqd/VBVctuvO9SDtxhcGbJRu8P4iAPLv+LXwByXCc/uNSvr6jqd1x5CFcRRsC8ckw== X-YMail-OSG: YYsTbkoVM1k0z9gw9zZCX4HdWVWdatL0_7oxiU8DmR.qeuRq6YVVsxgEioB1YJs RsFrs_Wd1fpzigeUpaENvw_mGhBzbz0N9PoItixS_nWsXAi3Mgq1FamP1bL.pcCkmEDSeI9H587U GwgbrWnOnoSAz57j68WXcXdAKmAYPtX5dUz7eqrSwOn.23_u45POQmKmUI4TpDqI3PNGEFCt9vsJ pidxx5AMD4KhrqB.cKiBiAR118qgTCDczR525PZiOmTav9ecX2P_yGlxlm5jI3sxb9kPuEpXjUg_ UvIuWv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Jul 2022 22:05:23 +0000 Received: by hermes--canary-production-ir2-74b4d6d794-ddpc4 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID a35f6751a6c4fcd8e9399f6f92d75bcb; Sun, 03 Jul 2022 22:05:22 +0000 (UTC) From: Jakob Hauser To: Jonathan Cameron Cc: Lars-Peter Clausen , Linus Walleij , Andy Shevchenko , Hans de Goede , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH v4 10/10] iio: magnetometer: yas530: Add YAS537 variant Date: Mon, 4 Jul 2022 00:05:01 +0200 Message-Id: <69a512cf5b62b34415d5983a6406c3d5ba438a1d.1656883851.git.jahau@rocketmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This adds support for the magnetometer Yamaha YAS537. The additions are based on comparison of Yamaha Android kernel drivers for YAS532 [1] and YAS537 [2]. In the Yamaha YAS537 Android driver, there is an overflow/underflow control implemented. For regular usage, this seems not necessary. A similar overflow/ underflow control of Yamaha YAS530/532 Android driver isn't integrated in the mainline driver. It is therefore skipped for YAS537 in mainline too. Also in the Yamaha YAS537 Android driver, at the end of the reset_yas537() function, a measurement is saved in "last_after_rcoil". Later on, this is compared to current measurements. If the difference gets too big, a new reset is initialized. The difference in measurements needs to be quite big, it's hard to say if this is necessary for regular operation. Therefore this isn't integrated in the mainline driver either. [1] https://github.com/msm8916-mainline/android_kernel_qcom_msm8916/blob/GT-I9195I/drivers/iio/magnetometer/yas_mag_drv-yas532.c [2] https://github.com/msm8916-mainline/android_kernel_qcom_msm8916/blob/GT-I9195I/drivers/iio/magnetometer/yas_mag_drv-yas537.c Signed-off-by: Jakob Hauser Reviewed-by: Linus Walleij --- Result of the patch can be seen at: https://github.com/Jakko3/linux/blob/yas537_v4/drivers/iio/magnetometer/yamaha-yas530.c drivers/iio/magnetometer/Kconfig | 4 +- drivers/iio/magnetometer/yamaha-yas530.c | 434 ++++++++++++++++++++++- 2 files changed, 429 insertions(+), 9 deletions(-) diff --git a/drivers/iio/magnetometer/Kconfig b/drivers/iio/magnetometer/Kconfig index 07eb619bcfe8..b91fc5e6a26e 100644 --- a/drivers/iio/magnetometer/Kconfig +++ b/drivers/iio/magnetometer/Kconfig @@ -216,8 +216,8 @@ config YAMAHA_YAS530 select IIO_TRIGGERED_BUFFER help Say Y here to add support for the Yamaha YAS530 series of - 3-Axis Magnetometers. Right now YAS530, YAS532 and YAS533 are - fully supported. + 3-Axis Magnetometers. YAS530, YAS532, YAS533 and YAS537 are + supported. This driver can also be compiled as a module. To compile this driver as a module, choose M here: the module diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index ce9c1077c121..4692e8bd4de3 100644 --- a/drivers/iio/magnetometer/yamaha-yas530.c +++ b/drivers/iio/magnetometer/yamaha-yas530.c @@ -17,6 +17,9 @@ * named "inv_compass" in the Tegra Android kernel tree. * Copyright (C) 2012 InvenSense Corporation * + * Code functions for YAS537 based on Yamaha Android kernel driver. + * Copyright (c) 2014 Yamaha Corporation + * * Author: Linus Walleij */ #include @@ -56,6 +59,23 @@ #define YAS530_TEST2 0x89 #define YAS530_CAL 0x90 +/* Registers used by YAS537 */ +#define YAS537_MEASURE 0x81 /* Originally YAS537_REG_CMDR */ +#define YAS537_CONFIG 0x82 /* Originally YAS537_REG_CONFR */ +#define YAS537_MEASURE_INTERVAL 0x83 /* Originally YAS537_REG_INTRVLR */ +#define YAS537_OFFSET_X 0x84 /* Originally YAS537_REG_OXR */ +#define YAS537_OFFSET_Y1 0x85 /* Originally YAS537_REG_OY1R */ +#define YAS537_OFFSET_Y2 0x86 /* Originally YAS537_REG_OY2R */ +#define YAS537_AVR 0x87 +#define YAS537_HCK 0x88 +#define YAS537_LCK 0x89 +#define YAS537_SRST 0x90 +#define YAS537_ADCCAL 0x91 +#define YAS537_MTC 0x93 +#define YAS537_OC 0x9E +#define YAS537_TRM 0x9F +#define YAS537_CAL 0xC0 + /* Bits in the YAS5xx config register */ #define YAS5XX_CONFIG_INTON BIT(0) /* Interrupt on? */ #define YAS5XX_CONFIG_INTHACT BIT(1) /* Interrupt active high? */ @@ -67,6 +87,7 @@ #define YAS5XX_MEASURE_LDTC BIT(1) #define YAS5XX_MEASURE_FORS BIT(2) #define YAS5XX_MEASURE_DLYMES BIT(4) +#define YAS5XX_MEASURE_CONT BIT(5) /* Bits in the measure data register */ #define YAS5XX_MEASURE_DATA_BUSY BIT(7) @@ -91,6 +112,22 @@ #define YAS532_DATA_CENTER BIT(YAS532_DATA_BITS - 1) #define YAS532_DATA_OVERFLOW (BIT(YAS532_DATA_BITS) - 1) +#define YAS537_DEVICE_ID 0x07 /* YAS537 (MS-3T) */ +#define YAS537_VERSION_0 0 /* Version naming unknown */ +#define YAS537_VERSION_1 1 /* Version naming unknown */ +#define YAS537_MAG_AVERAGE_32_MASK GENMASK(6, 4) +#define YAS537_MEASURE_TIME_WORST_US 1500 +#define YAS537_DEFAULT_SENSOR_DELAY_MS 50 +#define YAS537_MAG_RCOIL_TIME_US 65 +#define YAS537_MTC3_MASK_PREP GENMASK(7, 0) +#define YAS537_MTC3_MASK_GET GENMASK(7, 5) +#define YAS537_MTC3_ADD_BIT BIT(4) +#define YAS537_HCK_MASK_PREP GENMASK(4, 0) +#define YAS537_HCK_MASK_GET GENMASK(7, 4) +#define YAS537_LCK_MASK_PREP GENMASK(4, 0) +#define YAS537_LCK_MASK_GET GENMASK(3, 0) +#define YAS537_OC_MASK_GET GENMASK(5, 0) + /* Turn off device regulators etc after 5 seconds of inactivity */ #define YAS5XX_AUTOSUSPEND_DELAY_MS 5000 @@ -98,18 +135,21 @@ enum chip_ids { yas530, yas532, yas533, + yas537, }; static const char yas5xx_product_name[][13] = { "YAS530 MS-3E", "YAS532 MS-3R", - "YAS533 MS-3F" + "YAS533 MS-3F", + "YAS537 MS-3T" }; static const char yas5xx_version_name[][2][3] = { { "A", "B" }, { "AB", "AC" }, - { "AB", "AC" } + { "AB", "AC" }, + { "v0", "v1" } }; static const int yas530_volatile_reg[] = { @@ -117,11 +157,15 @@ static const int yas530_volatile_reg[] = { YAS530_MEASURE }; +static const int yas537_volatile_reg[] = { + YAS537_MEASURE +}; + /* Number of counts between minimum and reference temperature */ -const u16 t_ref_counts[] = { 182, 390, 390 }; +const u16 t_ref_counts[] = { 182, 390, 390, 8120 }; /* Starting point of temperature counting in 1/10:s degrees Celsius */ -const s16 min_temp_celcius_x10[] = { -620, -500, -500 }; +const s16 min_temp_celcius_x10[] = { -620, -500, -500, -3860 }; struct yas5xx_calibration { /* Linearization calibration x, y1, y2 */ @@ -316,6 +360,77 @@ static int yas530_measure(struct yas5xx *yas5xx, u16 *t, u16 *x, u16 *y1, u16 *y return ret; } +/** + * yas537_measure() - Make a measure from the hardware + * @yas5xx: The device state + * @t: the raw temperature measurement + * @x: the raw x axis measurement + * @y1: the y1 axis measurement + * @y2: the y2 axis measurement + * @return: 0 on success or error code + */ +static int yas537_measure(struct yas5xx *yas5xx, u16 *t, u16 *x, u16 *y1, u16 *y2) +{ + struct yas5xx_calibration *c = &yas5xx->calibration; + unsigned int busy; + u8 data[8]; + u16 xy1y2[3]; + s32 h[3], s[3]; + int i, ret; + + mutex_lock(&yas5xx->lock); + + /* Contrary to YAS530/532, also a "cont" bit is set, meaning unknown */ + ret = regmap_write(yas5xx->map, YAS537_MEASURE, YAS5XX_MEASURE_START | + YAS5XX_MEASURE_CONT); + if (ret < 0) + goto out_unlock; + + /* Use same timeout like YAS530/532 but the bit is in data row 2 */ + ret = regmap_read_poll_timeout(yas5xx->map, YAS5XX_MEASURE_DATA + 2, busy, + !(busy & YAS5XX_MEASURE_DATA_BUSY), + 500, 20000); + if (ret) { + dev_err(yas5xx->dev, "timeout waiting for measurement\n"); + goto out_unlock; + } + + ret = regmap_bulk_read(yas5xx->map, YAS5XX_MEASURE_DATA, + data, sizeof(data)); + if (ret) + goto out_unlock; + + mutex_unlock(&yas5xx->lock); + + *t = get_unaligned_be16(&data[0]); + xy1y2[0] = FIELD_GET(GENMASK(13, 0), get_unaligned_be16(&data[2])); + xy1y2[1] = get_unaligned_be16(&data[4]); + xy1y2[2] = get_unaligned_be16(&data[6]); + + /* The second version of YAS537 needs to include calibration coefficients */ + if (yas5xx->version == YAS537_VERSION_1) { + for (i = 0; i < 3; i++) + s[i] = xy1y2[i] - BIT(13); + h[0] = (c->k * (128 * s[0] + c->a2 * s[1] + c->a3 * s[2])) / BIT(13); + h[1] = (c->k * (c->a4 * s[0] + c->a5 * s[1] + c->a6 * s[2])) / BIT(13); + h[2] = (c->k * (c->a7 * s[0] + c->a8 * s[1] + c->a9 * s[2])) / BIT(13); + for (i = 0; i < 3; i++) { + clamp_val(h[i], -BIT(13), BIT(13) - 1); + xy1y2[i] = h[i] + BIT(13); + } + } + + *x = xy1y2[0]; + *y1 = xy1y2[1]; + *y2 = xy1y2[2]; + + return 0; + +out_unlock: + mutex_unlock(&yas5xx->lock); + return ret; +} + /* Used by YAS530, YAS532 and YAS533 */ static s32 yas530_linearize(struct yas5xx *yas5xx, u16 val, int axis) { @@ -456,6 +571,41 @@ static int yas530_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, return 0; } +/** + * yas537_get_measure() - Measure a sample of all axis and process + * @yas5xx: The device state + * @to: Temperature out + * @xo: X axis out + * @yo: Y axis out + * @zo: Z axis out + * @return: 0 on success or error code + */ +static int yas537_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, s32 *zo) +{ + u16 t, x, y1, y2; + int ret; + + /* We first get raw data that needs to be translated to [x,y,z] */ + ret = yas537_measure(yas5xx, &t, &x, &y1, &y2); + if (ret) + return ret; + + /* Calculate temperature readout */ + *to = yas5xx_calc_temperature(yas5xx, t); + + /* + * Unfortunately, no linearization or temperature compensation formulas + * are known for YAS537. + */ + + /* Calculate x, y, z from x, y1, y2 */ + *xo = (x - BIT(13)) * 300; + *yo = (y1 - y2) * 1732 / 10; + *zo = (-y1 - y2 + BIT(14)) * 300; + + return 0; +} + static int yas5xx_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, @@ -766,6 +916,202 @@ static int yas532_get_calibration_data(struct yas5xx *yas5xx) return 0; } +static int yas537_get_calibration_data(struct yas5xx *yas5xx) +{ + struct yas5xx_calibration *c = &yas5xx->calibration; + u8 data[17]; + u32 val1, val2, val3, val4; + int i, ret; + + /* Writing SRST register */ + ret = regmap_write(yas5xx->map, YAS537_SRST, BIT(1)); + if (ret) + return ret; + + /* Calibration readout, YAS537 needs one readout only */ + ret = regmap_bulk_read(yas5xx->map, YAS537_CAL, data, sizeof(data)); + if (ret) + return ret; + dev_dbg(yas5xx->dev, "calibration data: %17ph\n", data); + + /* Sanity check, is this all zeroes? */ + if (!memchr_inv(data, 0x00, 16) && !FIELD_GET(GENMASK(5, 0), data[16])) + dev_warn(yas5xx->dev, "calibration is blank!\n"); + + /* Contribute calibration data to the input pool for kernel entropy */ + add_device_randomness(data, sizeof(data)); + + /* Extract version information */ + yas5xx->version = FIELD_GET(GENMASK(7, 6), data[16]); + + /* There are two versions of YAS537 behaving differently */ + switch (yas5xx->version) { + case YAS537_VERSION_0: + /* + * The first version simply writes data back into registers: + * + * data[0] YAS537_MTC 0x93 + * data[1] 0x94 + * data[2] 0x95 + * data[3] 0x96 + * data[4] 0x97 + * data[5] 0x98 + * data[6] 0x99 + * data[7] 0x9a + * data[8] 0x9b + * data[9] 0x9c + * data[10] 0x9d + * data[11] YAS537_OC 0x9e + * + * data[12] YAS537_OFFSET_X 0x84 + * data[13] YAS537_OFFSET_Y1 0x85 + * data[14] YAS537_OFFSET_Y2 0x86 + * + * data[15] YAS537_HCK 0x88 + * data[16] YAS537_LCK 0x89 + */ + for (i = 0; i < 12; i++) { + ret = regmap_write(yas5xx->map, YAS537_MTC + i, + data[i]); + if (ret) + return ret; + } + for (i = 0; i < 3; i++) { + ret = regmap_write(yas5xx->map, YAS537_OFFSET_X + i, + data[i + 12]); + if (ret) + return ret; + yas5xx->hard_offsets[i] = data[i + 12]; + } + for (i = 0; i < 2; i++) { + ret = regmap_write(yas5xx->map, YAS537_HCK + i, + data[i + 15]); + if (ret) + return ret; + } + break; + case YAS537_VERSION_1: + /* + * The second version writes some data into registers but also + * extracts calibration coefficients. + * + * Registers being written: + * + * data[0] YAS537_MTC 0x93 + * data[1] YAS537_MTC+1 0x94 + * data[2] YAS537_MTC+2 0x95 + * data[3] YAS537_MTC+3 (partially) 0x96 + * + * data[12] YAS537_OFFSET_X 0x84 + * data[13] YAS537_OFFSET_Y1 0x85 + * data[14] YAS537_OFFSET_Y2 0x86 + * + * data[15] YAS537_HCK (partially) 0x88 + * YAS537_LCK (partially) 0x89 + * data[16] YAS537_OC (partially) 0x9e + */ + for (i = 0; i < 3; i++) { + ret = regmap_write(yas5xx->map, YAS537_MTC + i, + data[i]); + if (ret) + return ret; + } + for (i = 0; i < 3; i++) { + ret = regmap_write(yas5xx->map, YAS537_OFFSET_X + i, + data[i + 12]); + if (ret) + return ret; + yas5xx->hard_offsets[i] = data[i + 12]; + } + /* + * Visualization of partially taken data: + * + * data[3] n 7 6 5 4 3 2 1 0 + * YAS537_MTC+3 x x x 1 0 0 0 0 + * + * data[15] n 7 6 5 4 3 2 1 0 + * YAS537_HCK x x x x 0 + * + * data[15] n 7 6 5 4 3 2 1 0 + * YAS537_LCK x x x x 0 + * + * data[16] n 7 6 5 4 3 2 1 0 + * YAS537_OC x x x x x x + */ + ret = regmap_write(yas5xx->map, YAS537_MTC + 3, + FIELD_PREP(YAS537_MTC3_MASK_PREP, + FIELD_GET(YAS537_MTC3_MASK_GET, data[3])) | + YAS537_MTC3_ADD_BIT); + if (ret) + return ret; + ret = regmap_write(yas5xx->map, YAS537_HCK, + FIELD_PREP(YAS537_HCK_MASK_PREP, + FIELD_GET(YAS537_HCK_MASK_GET, data[15]))); + if (ret) + return ret; + ret = regmap_write(yas5xx->map, YAS537_LCK, + FIELD_PREP(YAS537_LCK_MASK_PREP, + FIELD_GET(YAS537_LCK_MASK_GET, data[15]))); + if (ret) + return ret; + ret = regmap_write(yas5xx->map, YAS537_OC, + FIELD_GET(YAS537_OC_MASK_GET, data[16])); + if (ret) + return ret; + /* + * For data extraction, build some blocks. Four 32-bit blocks + * look appropriate. + * + * n 7 6 5 4 3 2 1 0 + * data[0] 0 [ Cx Cx Cx Cx Cx Cx Cx Cx ] bits 31 .. 24 + * data[1] 1 [ Cx C1 C1 C1 C1 C1 C1 C1 ] bits 23 .. 16 + * data[2] 2 [ C1 C1 C2 C2 C2 C2 C2 C2 ] bits 15 .. 8 + * data[3] 3 [ C2 C2 C2 ] bits 7 .. 0 + * + * n 7 6 5 4 3 2 1 0 + * data[3] 0 [ a2 a2 a2 a2 a2 ] bits 31 .. 24 + * data[4] 1 [ a2 a2 a3 a3 a3 a3 a3 a3 ] bits 23 .. 16 + * data[5] 2 [ a3 a4 a4 a4 a4 a4 a4 a4 ] bits 15 .. 8 + * data[6] 3 [ a4 ] bits 7 .. 0 + * + * n 7 6 5 4 3 2 1 0 + * data[6] 0 [ a5 a5 a5 a5 a5 a5 a5 ] bits 31 .. 24 + * data[7] 1 [ a5 a5 a6 a6 a6 a6 a6 a6 ] bits 23 .. 16 + * data[8] 2 [ a6 a7 a7 a7 a7 a7 a7 a7 ] bits 15 .. 8 + * data[9] 3 [ a7 ] bits 7 .. 0 + * + * n 7 6 5 4 3 2 1 0 + * data[9] 0 [ a8 a8 a8 a8 a8 a8 a8 ] bits 31 .. 24 + * data[10] 1 [ a9 a9 a9 a9 a9 a9 a9 a9 ] bits 23 .. 16 + * data[11] 2 [ a9 k k k k k k k ] bits 15 .. 8 + * data[12] 3 [ ] bits 7 .. 0 + */ + val1 = get_unaligned_be32(&data[0]); + val2 = get_unaligned_be32(&data[3]); + val3 = get_unaligned_be32(&data[6]); + val4 = get_unaligned_be32(&data[9]); + /* Extract calibration coefficients and modify */ + c->Cx = FIELD_GET(GENMASK(31, 23), val1) - 256; + c->Cy1 = FIELD_GET(GENMASK(22, 14), val1) - 256; + c->Cy2 = FIELD_GET(GENMASK(13, 5), val1) - 256; + c->a2 = FIELD_GET(GENMASK(28, 22), val2) - 64; + c->a3 = FIELD_GET(GENMASK(21, 15), val2) - 64; + c->a4 = FIELD_GET(GENMASK(14, 7), val2) - 128; + c->a5 = FIELD_GET(GENMASK(30, 22), val3) - 112; + c->a6 = FIELD_GET(GENMASK(21, 15), val3) - 64; + c->a7 = FIELD_GET(GENMASK(14, 7), val3) - 128; + c->a8 = FIELD_GET(GENMASK(30, 24), val4) - 64; + c->a9 = FIELD_GET(GENMASK(23, 15), val4) - 112; + c->k = FIELD_GET(GENMASK(14, 8), val4); + break; + default: + dev_err(yas5xx->dev, "unknown version of YAS537\n"); + return -EINVAL; + } + + return 0; +} + /* Used by YAS530, YAS532 and YAS533 */ static void yas530_dump_calibration(struct yas5xx *yas5xx) { @@ -790,6 +1136,26 @@ static void yas530_dump_calibration(struct yas5xx *yas5xx) dev_dbg(yas5xx->dev, "dck = %d\n", c->dck); } +static void yas537_dump_calibration(struct yas5xx *yas5xx) +{ + struct yas5xx_calibration *c = &yas5xx->calibration; + + if (yas5xx->version == YAS537_VERSION_1) { + dev_dbg(yas5xx->dev, "Cx = %d\n", c->Cx); + dev_dbg(yas5xx->dev, "Cy1 = %d\n", c->Cy1); + dev_dbg(yas5xx->dev, "Cy2 = %d\n", c->Cy2); + dev_dbg(yas5xx->dev, "a2 = %d\n", c->a2); + dev_dbg(yas5xx->dev, "a3 = %d\n", c->a3); + dev_dbg(yas5xx->dev, "a4 = %d\n", c->a4); + dev_dbg(yas5xx->dev, "a5 = %d\n", c->a5); + dev_dbg(yas5xx->dev, "a6 = %d\n", c->a6); + dev_dbg(yas5xx->dev, "a7 = %d\n", c->a7); + dev_dbg(yas5xx->dev, "a8 = %d\n", c->a8); + dev_dbg(yas5xx->dev, "a9 = %d\n", c->a9); + dev_dbg(yas5xx->dev, "k = %d\n", c->k); + } +} + /* Used by YAS530, YAS532 and YAS533 */ static int yas530_set_offsets(struct yas5xx *yas5xx, s8 ox, s8 oy1, s8 oy2) { @@ -910,6 +1276,45 @@ static int yas530_power_on(struct yas5xx *yas5xx) return regmap_write(yas5xx->map, YAS530_MEASURE_INTERVAL, 0); } +static int yas537_power_on(struct yas5xx *yas5xx) +{ + int ret; + u8 intrvl; + + /* Write registers according to Android driver */ + ret = regmap_write(yas5xx->map, YAS537_ADCCAL, GENMASK(1, 0)); + if (ret) + return ret; + ret = regmap_write(yas5xx->map, YAS537_ADCCAL + 1, GENMASK(7, 3)); + if (ret) + return ret; + ret = regmap_write(yas5xx->map, YAS537_TRM, GENMASK(7, 0)); + if (ret) + return ret; + + /* The interval value is static in regular operation */ + intrvl = (YAS537_DEFAULT_SENSOR_DELAY_MS * 1000 + - YAS537_MEASURE_TIME_WORST_US) / 4100; + ret = regmap_write(yas5xx->map, YAS537_MEASURE_INTERVAL, intrvl); + if (ret) + return ret; + + /* The average value is also static in regular operation */ + ret = regmap_write(yas5xx->map, YAS537_AVR, YAS537_MAG_AVERAGE_32_MASK); + if (ret) + return ret; + + /* Perform the "rcoil" part but skip the "last_after_rcoil" read */ + ret = regmap_write(yas5xx->map, YAS537_CONFIG, BIT(3)); + if (ret) + return ret; + + /* Wait until the coil has ramped up */ + usleep_range(YAS537_MAG_RCOIL_TIME_US, YAS537_MAG_RCOIL_TIME_US + 100); + + return 0; +} + static struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { [yas530] = { .devid = YAS530_DEVICE_ID, @@ -943,6 +1348,17 @@ static struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { .dump_calibration = yas530_dump_calibration, .measure_offsets = yas530_measure_offsets, .power_on = yas530_power_on, + }, + [yas537] = { + .devid = YAS537_DEVICE_ID, + .volatile_reg = yas537_volatile_reg, + .volatile_reg_qty = ARRAY_SIZE(yas537_volatile_reg), + .scaling_val2 = 100000, /* nanotesla to Gauss */ + .get_measure = yas537_get_measure, + .get_calibration_data = yas537_get_calibration_data, + .dump_calibration = yas537_dump_calibration, + /* .measure_offets is not needed for yas537 */ + .power_on = yas537_power_on, } }; @@ -1025,9 +1441,11 @@ static int yas5xx_probe(struct i2c_client *i2c, if (ret) goto assert_reset; - ret = yas5xx->chip_info->measure_offsets(yas5xx); - if (ret) - goto assert_reset; + if (yas5xx->chip_info->measure_offsets) { + ret = yas5xx->chip_info->measure_offsets(yas5xx); + if (ret) + goto assert_reset; + } indio_dev->info = &yas5xx_info; indio_dev->available_scan_masks = yas5xx_scan_masks; @@ -1150,6 +1568,7 @@ static const struct i2c_device_id yas5xx_id[] = { {"yas530", yas530 }, {"yas532", yas532 }, {"yas533", yas533 }, + {"yas537", yas537 }, {} }; MODULE_DEVICE_TABLE(i2c, yas5xx_id); @@ -1158,6 +1577,7 @@ static const struct of_device_id yas5xx_of_match[] = { { .compatible = "yamaha,yas530", }, { .compatible = "yamaha,yas532", }, { .compatible = "yamaha,yas533", }, + { .compatible = "yamaha,yas537", }, {} }; MODULE_DEVICE_TABLE(of, yas5xx_of_match);