From patchwork Sat Jun 18 00:13:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12886137 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 CFD2BCCA479 for ; Sat, 18 Jun 2022 00:14:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237824AbiFRAOz (ORCPT ); Fri, 17 Jun 2022 20:14:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237773AbiFRAOz (ORCPT ); Fri, 17 Jun 2022 20:14:55 -0400 Received: from sonic306-21.consmr.mail.ir2.yahoo.com (sonic306-21.consmr.mail.ir2.yahoo.com [77.238.176.207]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E55214D37 for ; Fri, 17 Jun 2022 17:14:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1655511292; bh=QafQc4ZMyctCnOKdCtBnq0f/dxsC+4Cf+E3CVMEn2HA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=NtmOtP/KVm1GfNsLn+TzLvUBLC9OIsXqyNmFQg2S17T6pjM2kpAyJAnrOF+CqSAE43Lq+CE1lqnfAI/CZ+5VNw6iHEbz1dS4q0SJat6GWA6HyfYREW+0yKda8EbI3LHEiq5a8lCIddROXhjfviwt6mKbbbLz+YqKyXUCuz9UrOiSMSYephZOYMrOxC6llQ99tuwt6MBToRXHbcsP++Af7yHdVsjEp4XyfeQ7XBu3DBuHkBzwN6/7xdzjq+lEVqW2GxOSTxURCOKfaUnR+6X09edwiivLFwus7xiFaSh6b6DLr1eqV285Jemt1tbyYAbUzE+ndnprO1Y1OuDcPV5NHA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1655511292; bh=q4KF4LnLCgGczavQeg4kZbz0UBI8FlurD6Ewv0UfQpp=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=mU8ML18TUvIcEbxLeg6lhWilNAMh4IilsuluRLt0mV6NHnvOy3d+w0Chrohgy2Gv3GqMZaznOr6ZNnuS7r8rGATITX/6CHKIfyuB/s4K4YKCdN32Fe1z/BpJMeEnVvranVM6C+N4FX/aXfeMTmH+h9bwgP4Vo0W3OWKWUqxZeAZeT/bYWqjAq3mmwEYshz83wxl0XdW/LfRFgbGRuLzYvfmjGyND/2XhAolR+UNjSs6HH7QLlnCE8aPA416uzXulsHN4roJAMor74P4X5CQdr7cZPScU4cxH+UOsWzd/DcHdt6f7FDp/uLC5ZdjqaXoCEhbCxl7HVE1DSZdmI88xSw== X-YMail-OSG: QXckt8AVM1k5Tq_SBboGxY9z6NuiwLc2mrsX0ttdu8DV6_DMtVzI73JSwDy4wmB oEkvbFQtdNqdZy3gRA.2F3JdvXKGvUSTmKtub7_LNL54xfBtUhZ0b0OCh5t0Smkq9cktMIkvFpan 6t5gj61EvPo2yM9wwkxiT4HJ5kNO_avwN15LXxp_IgP_6XC6XNmLel_9g41nT4mzDLxn4wyj9kT2 rj7STNnhz_E5CJ7f6DuKA4zf4a5es9gwFtpyQs0OCNVPrC0GPIDMoqQjqKKSc2vKlLCedw_hWGHC GWK6NlpndxH01403VclPg2r5j6zG0rNJEZY3axFLQfuSdXqrV14gLHVRZm01UCLsdOX8gYqNg32b _bWwdAlMVPm_OLyUs7bjc5z3eIulVGBDCpRJqnjTjHwNOS5HWBCoP6WyyGbvr6RKRDxZbYiHyGNf hMWNaNPkEKKx.JLN36hnaftCrYnH5TOh0vuvuzZF0C5Uv6Jeo8C_4YzpQVsId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jO4BtiKIyjhGet4TFkK 6kSiDYIwZpAZv5.6R3v3jURSssls.X2PoaHjcIuV5Rfti92pFK.Ma4SgCxXb0TqIDCYuHtnMcILg h4SvYa.tALvfKm0FsUdIn.KgteGQYBLmePlP1Wt418WpZ8rQH8g4JmOqJ6fOk4Y71ibgDRNLPLVA czjqyd0.OZ5b6mWfZ4lJCXmFQ6n71D4W4V6SVfp1TU0lsHc47bTkHx8A5D0tunyiU6mLY4oBkkXF KY1cFdhVEqzp4lewN5w6p4HGslAvgUsAPuEB7h8nKj_tcSrcjpBvv9CGZ7vxNB2VxEQ5pj39z.aR sriOWrInitQSNpgoxjWthxyCWFJ9EZrKjS.OKBtyViAuCGd_vz2EvVsSMx7zWL.53z5MuIwKyCTD yNXnMhTevGYvUb3UGtShpsLg83GZXfITAl54Fwis.fOJ.c69sbnU2eLrmdqZHRRhtJATSNzja0Tj E8yLvXCJgc8XvyHfnrCJKK_Irkto9az9FYABdNNrW.vBn14QWOtH_eAWPoQRtsJm.L6zEGn68muP Ul15Nz0L0wreeAFOQXNJwUVqXQ_geS0BSeApIRx_LV_qn0ywaZPnbMsSMRDyosjxp5mv6Xu0deUZ RqNTnOxZWJB7dLr9qFqW2rKt69ijafUxtp145BIW3SSc8k4OzKR.SIcQqoM.om8HPsMipAK3iTxk FOs8i3DpslxCgTSVV96XRLX5oZCWzELqMAapr9E46jvXAr_zrG90zuc8IOXZdPAimPtTpIprUmyk yUW.5bsvLa.XQIftnYA-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic306.consmr.mail.ir2.yahoo.com with HTTP; Sat, 18 Jun 2022 00:14:52 +0000 Received: by hermes--canary-production-ir2-c9bf9d9bc-74fwm (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 8b08f14069c990c2ed22165f3e3da032; Sat, 18 Jun 2022 00:14:50 +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 v3 1/8] iio: magnetometer: yas530: Change data type of hard_offsets to signed Date: Sat, 18 Jun 2022 02:13:09 +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 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") Cc: Linus Walleij 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 Sat Jun 18 00:13:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12886138 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 5F03ECCA47E for ; Sat, 18 Jun 2022 00:15:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237595AbiFRAPB (ORCPT ); Fri, 17 Jun 2022 20:15:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234393AbiFRAPA (ORCPT ); Fri, 17 Jun 2022 20:15:00 -0400 Received: from sonic303-21.consmr.mail.ir2.yahoo.com (sonic303-21.consmr.mail.ir2.yahoo.com [77.238.178.202]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54B6F15732 for ; Fri, 17 Jun 2022 17:14:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1655511297; bh=HUA420pLmyXbBKlHXL/2plBKjp8N9OY9zJWWnglHYrg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=JJFJb6LsgMg6E4qV7SCMDvNJt8VGY55NJqtntTrmhAbZU1LtOIi7S9JQ7ZDk4LpmyPlbGlAz8MgTks35SZBqPG1Np9awZqz1EoT9pxQjeBDbv/5mbYNhebV5nq6bK3ETWY59KTJjSubhWwOPdR+jV5ngsXXWPy4ks/ip2GG84c7NlwPNJdgJX+C/SoV98z67jPYXatT+tbTY1jL9gXrCZklJBK66+qe0w4+lBuL/scymFh83XRcC9NazC39MGt917ks6yJYjgZgwmCU84R1sMOVNf/SnWSu0YgJiWrCCHEM7Vw+TXnW8k4bR5QrJ/YU5j1bLVP6ZIcy1GHuECmeUiQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1655511297; bh=YaGF0cIQKihlDoH6A3DcT9BuQOWhEK++9dOOYbKsocJ=; h=X-Sonic-MF:From:To:Subject:Date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iqnNs7b0brlE 8gv2u0c.1aLSiEUL7gFJFh0YnSfnJemb1332nf4o.BSBHrdRcJ.O0e0zBo_oO_4Sx7BFbxCg1iBs VJgG9EKlat7LoGDySI3uewhok9GJnJcS9lhnPwnuz9m9n0PzDgTARqD5XCilWt3DG0NDD7SYvmrt fgV2jS9qpJ7tI0elL4TMb5m10novM4MyM0EeMwUdfwdDZrPoKMGhwYIrkYzFEFil.HJlGPyw2zIi 5CnHdi4ifcuV0qbHgQUL02rji4LOUiGtQ6sY.qGNVMU_8iMIP0.9Ek8tWnt_YLiUD9zTOsIjkQS_ WI5JBxTJLxY.GYKYBVr1mgAksK6pwiYDc5tIRICGg930rYVTTNJRQUHfm2f7q6DfmseSqshp9ajl AFWr1wlIj1fO0kEVnf.g0WuBPeJG.fh2dtl.8POxmo9Dnk_U42ePoRmLMwaByiRLtWU_uk2yB45B saYapEaG2Stl0Ung_YavZdmcaofZhP37ulTPekI7giaLp9J98ZBBC2KO_Zqe3UnvyzxNasrMiP6p XmU17uMOJTvUqkLnZlQ-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.ir2.yahoo.com with HTTP; Sat, 18 Jun 2022 00:14:57 +0000 Received: by hermes--canary-production-ir2-c9bf9d9bc-74fwm (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 8b08f14069c990c2ed22165f3e3da032; Sat, 18 Jun 2022 00:14:54 +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 v3 2/8] iio: magnetometer: yas530: Change range of data in volatile register Date: Sat, 18 Jun 2022 02:13:10 +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 In function yas5xx_volatile_reg(), the range for measure data should end at "YAS5XX_MEASURE_DATA + 7" instead of "+ 8" as we count from 0 to 7 here. This change is of low importance as the "+ 8" register isn't called. Cc: Linus Walleij 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..2799ae0784fd 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 + 7); } /* TODO: enable regmap cache, using mark dirty and sync at runtime resume */ From patchwork Sat Jun 18 00:13:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12886139 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 CE92BC433EF for ; Sat, 18 Jun 2022 00:15:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237928AbiFRAPD (ORCPT ); Fri, 17 Jun 2022 20:15:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237736AbiFRAPD (ORCPT ); Fri, 17 Jun 2022 20:15:03 -0400 Received: from sonic304-23.consmr.mail.ir2.yahoo.com (sonic304-23.consmr.mail.ir2.yahoo.com [77.238.179.148]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 022DB15829 for ; Fri, 17 Jun 2022 17:15:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1655511300; bh=pWKwob//oMrCGdu8osqOK8fSSKjG7fXLFNCSSjKHJOY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=RLkbMJFCN4DTt1mf1AcvyEjPUEE/4fko1m/nWuyrBEXICb/DHAA26olHEA1r1/U+5+y3ZLZAePUXHutOJpAD3bNYs/dTV6sj76NG0GjJePxSbBejhcfYA84I/3H4LzA201iRdGg/sNBgqBWURAub8GHBm0Oj2jtpQXHqcphr0w4BDPN9W5Pva4khsUghRvH1diLL2UDdhwLaXlFjirI67X5JmNB1eecsLcrC3m4OYI3pOoviV7j6MA0Kg8HuBkVNH5RT3lnNo7HhxPx7AYiLrDDW/7IPQ/59Ku0MTzJJfTFAVK3DAqoDXvMjbKXygKbLJKkkjHI0ql+YRM3qUPJ1hA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1655511300; bh=wWBUCkaGkSwAwYDl83FbXZkCbxpmT4wi9iRMF104Xc6=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=Mo9X6pbCI7zBX/l+Ip4skO3+MbWQGIV1nNUcQp3TKVLhGeuobXs71mlpniRHSU/VCKcuA03feKvtrtwQFOiyQ8hyBRixAc43kvHpsQxcfPncem2YY6PmZSil/46Vi5LKWkV29KZLkq8ZSyo2z2bAv0kXMtk9x2ibaI2kVOK24gSXdjKdHaZu+yS2Njqtqzf74CDgjAsJwZARTe7UesiBM7lfHQ/Ofiqerb+S8jJR5UkgNPEoy6s3D+VOxFte9IQWvX5ei33FvTNKFFtQG9WcCkIvN6sYCH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s ta7mpKylSDzfMSOK5IGBuy8Rl4XTjhv2GcazZw.ZGlA.f5HwL6xQgw5apDxIgsudjpNygzGkZ3SA nhDfPw1zH9w_9FacPcuDvDK6Cr7sT6Q2ihHMCbzLmywAgfAqaQm6yzX9VHh8QGru4o_G.531sSUy uatQuY2iA2iuTl7yDANEiZWdeFvpT.EqckENlnQsfmkakVdLgZQusuR2lqDutV7O.IgUabqVbfQH Jvt4cn4_IiK8hXKSUwc7uKLH_hVf8Ajc1hdmUKN7VGXVBS6RLCCY4HAMGUDkRhJItyn1NuxkkUj4 ODdJESHe6fDnCTILcuQ-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ir2.yahoo.com with HTTP; Sat, 18 Jun 2022 00:15:00 +0000 Received: by hermes--canary-production-ir2-c9bf9d9bc-74fwm (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 8b08f14069c990c2ed22165f3e3da032; Sat, 18 Jun 2022 00:14:57 +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 v3 3/8] iio: magnetometer: yas530: Correct scaling of magnetic axes Date: Sat, 18 Jun 2022 02:13:11 +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 Looks like YAS530 raw values return picotesla and YAS532 nanotesla. Adapt comments and scaling. Cc: Linus Walleij Signed-off-by: Jakob Hauser Reviewed-by: Linus Walleij Reviewed-by: Andy Shevchenko --- drivers/iio/magnetometer/yamaha-yas530.c | 28 +++++++++++++++--------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index 2799ae0784fd..bd43b2555b73 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,24 @@ 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; + } return IIO_VAL_FRACTIONAL; default: /* Unknown request */ From patchwork Sat Jun 18 00:13:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12886140 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 A497ACCA483 for ; Sat, 18 Jun 2022 00:15:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234451AbiFRAPE (ORCPT ); Fri, 17 Jun 2022 20:15:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237818AbiFRAPD (ORCPT ); Fri, 17 Jun 2022 20:15:03 -0400 Received: from sonic302-21.consmr.mail.ir2.yahoo.com (sonic302-21.consmr.mail.ir2.yahoo.com [87.248.110.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E82D1ADB8 for ; Fri, 17 Jun 2022 17:15:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1655511300; bh=gn54fJeWT1i1GAWZ2VjHhSE1vulAvEE7gdAL7I29ZjQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=lZxWVKTjzgqsc+S25/rgkZgHDl7W6NrU3T5B4eL8JPP0L1q6HJYydvUB+s7aQcZFYgtLh9MuW+rDv8Vzc4u+n6NBim8t1yPkF+1Yh4o7VH59S++iTl2e8s+lkjHtHG7HM+s8Gc0uVoveH8vSJz1OALAmVsdhPUrWdZZYgB4tSLklGEKNL3b3SwV/grn+8x09hJaoyhMU6aEbx3CO/Icmn4Ky9RYXWI+6KDx9/QDBZv7Ff7aSnweCvLwwsrUXm7I5qfMxvhpxm2k4tOuOHW5WPuu99XO+2fQePzHcf+3Z/rkAu8mV7AsgFV68XPsL3aD8Y9WnoguFyQx8k2PIu9m9ZQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1655511300; bh=b0b6wVP9pLIjBtic3csdPYA3fzeQ91iT64trBwhn5Bs=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=Y8YLCKO1IRDRKazzn7iuMCUOzUNL/W0Pwe8YW7h/mal6hag8Xb3v+6C72W+Z5tUhDSF0qW7GNhT9JYsrfCt63t0flg+O0mw3XPPN1Zf5sjtKJQFANu71nggg/vzhD3blMG+rotk8e6xrQfqdtlN6Z0LscqiAm48zG4r5aQO++9IDZTQLfgcmdEfXuAh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7UGz3sU81Cb_4zaf84Cc8NSCRLBMEoyoWc8ZaCN5dRaNLmDYB9tpFey18x 104Z8uWbNnoUi0oUcpRuOpBsNb9aFkg0aYc.r_0yJMgXUX40LfoFNSk5XgvFeFWCD8YKfndLoMPx NkhdcKQ1ji8QzDUF78miJfstAvdZ6zjv0neUypz4KOuOuWFsUQpLvUUzR2c4rxekWUm2WlQEIElA F4DdHMydKJsjPHLXAYRaSt4f0iLcxwJ.DpPwkCEvf23PKab_eaOCUDp.RYt.dUvHexzNQ4y1DVza ZSe1ig5GLOFKflB8Yzj3lknRGlN7KxS6shMi.S6VTMBIJvElLK15FLJKoL6he0ViTadv56yQRAqH F.y29..D01O5Z0Fn9q7E- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.ir2.yahoo.com with HTTP; Sat, 18 Jun 2022 00:15:00 +0000 Received: by hermes--canary-production-ir2-c9bf9d9bc-74fwm (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 8b08f14069c990c2ed22165f3e3da032; Sat, 18 Jun 2022 00:14:59 +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 v3 4/8] iio: magnetometer: yas530: Correct temperature handling Date: Sat, 18 Jun 2022 02:13:12 +0200 Message-Id: <076e87f66378be8c729723cb9be5bc9151c081ab.1655509425.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 Cc: Linus Walleij 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 bd43b2555b73..9b45a550f31e 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 milli degrees 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: /* @@ -513,7 +566,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 Sat Jun 18 00:13:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12886141 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 09FE9C433EF for ; Sat, 18 Jun 2022 00:15:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356130AbiFRAPJ (ORCPT ); Fri, 17 Jun 2022 20:15:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236835AbiFRAPI (ORCPT ); Fri, 17 Jun 2022 20:15:08 -0400 Received: from sonic302-21.consmr.mail.ir2.yahoo.com (sonic302-21.consmr.mail.ir2.yahoo.com [87.248.110.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F94E1ADB8 for ; Fri, 17 Jun 2022 17:15:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1655511305; bh=s8wR7NVG2hJ7U7KQaWy5POGWhS7BSCCGW2GyzhwYZk4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=jU3cNvkxptia1+tDmB3Wlo0JtPEWo4Kbchs7m5dXYGIf8RqNNVsYkWb8tAwBJYXiyporta8cGCY/Hlq1h/PiyEZmACmSM3WpJNBsocmifzfMrPgRh9qidEYniA4HrzzXOMM0vEMryix+KvRPnBZOZ5J5GbLEyLwhcuqH7eAXdGf/mlv2rDB1AWCdEHpCCiKu9d8ZvwXsovSAhOwovE8YYEC36nyblpHBs5w4AqabPYDDs2psw/mVgKmJFPuXcjnnq64FR1Z3SA5jRLQv99yL8ao29XUXeb3mrjjG0EotnzUNBfrLbuFIut+Eg8lxgoed28+hfa3oo90mso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sXQ2TJv3fOOGFKiH_4Hh.Q5F3zij5HE nddjeTrFbVbr1AgXfnC6pwxz6jyIFEcOhgrTpqwo1bnEbyyyFVwfjr1Eesce0pSK_Y1OsUFPCYBm VBUFv7in8E9g8xIu_N4AgHvyIL2KUpMsxdKm2IVPv2Du_A86B32x0VExUxWS6znU1YVq2OSdBxp2 tIhsayHY1xOy8jWVW.UFqLcSUby8zRJ2YD5hUO8bVsDMPjbtSBAD.smC5GvlbOf8E2hVHvMQ.zxZ bYpsOnVvqixXsXNn9T6btdkumLQWT6jPiJSxpcWApyL44BRL.xYQv09._uPvpjO1H_nNzIzwRdFj iEjAGXSMxjrnqIlP08.FkDzIEUlOubABOO8hXF_YmbFeUKMpcPHZknqdLT9QAwzdz9HH0HinOqeA i_FXmqJ9DbPrUkiCVO0upbFAN8NDLeT3hO_25G9F_7fDAc.7JmZkwMwzFn3EyV_yLOoULs1kB5mw SPSKGs0.EFucpIvmZ198cPGqnexdR2cJfMuC8rXl9eRerNOlJnCN9JbF_FBoAqxwSilU_UuZj_2H IPUJ3d2c8lxqj2jSQMid_fmoDs2DIu0VvcourHJFOD4.iHwYFP5wHQbKT3aFALzyj5nG5BCldXHA 5HJ.k4qwHkWNhfhE8qJgsKBEIabZ9CA8vmyjJiWSVAOSnBldZt437S6zAhT62laBoX6m9eBfbjHh gvGLscYSu.zK.A.Ql X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.ir2.yahoo.com with HTTP; Sat, 18 Jun 2022 00:15:05 +0000 Received: by hermes--canary-production-ir2-c9bf9d9bc-74fwm (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 8b08f14069c990c2ed22165f3e3da032; Sat, 18 Jun 2022 00:15:01 +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 v3 5/8] iio: magnetometer: yas530: Change data type of calibration coefficients Date: Sat, 18 Jun 2022 02:13:13 +0200 Message-Id: <18f223776f6942d52af2e41dd10160e220a23311.1655509425.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 Cc: Linus Walleij 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 9b45a550f31e..c6f5f25793c4 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 Sat Jun 18 00:13:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12886142 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 2F808C43334 for ; Sat, 18 Jun 2022 00:15:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245202AbiFRAPM (ORCPT ); Fri, 17 Jun 2022 20:15:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348242AbiFRAPL (ORCPT ); Fri, 17 Jun 2022 20:15:11 -0400 Received: from sonic306-21.consmr.mail.ir2.yahoo.com (sonic306-21.consmr.mail.ir2.yahoo.com [77.238.176.207]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44AB81ADB8 for ; Fri, 17 Jun 2022 17:15:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1655511307; bh=sGHa/AM5SkKKVfdyjAJJqV4wePUji04k+kdekMfkmzo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=tss8RT3EYkuy7JrG2MIEiis5L2FA9RcH0MkqJPn6X0rwujw53HiGspLlxrw9MtOjS+p9+0Gg/OA5Oz3s1q7dsHlyOmpTpjaR7eDxVdY6xP9VrKyFgT/HgnC+yWf8Bj4V3CYzB8eRKV7Q0smaMrwFdYeimyXFVEFrIrgqPvG9iwJ2fNgntUmbkuwWoniWDkYOziMkFRuXJRpQHZRIc/k5GAomi7IH8UxhhFu4Y6DAeDExf8da/IunMS5AxpWPHnWZb4GKtLzJkF0Ahx57+ukCxzrvpMVvSvSaFVG5BSmc3moKb+AWaeIaViTDzOH5GQkrqykxJws/zSxMoG6uTCD3ew== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1655511307; bh=v/5euCm9wK27F2Yqo6Qttn3KnhZz3EBVJKGagpzW6fP=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=spW9Y0xO1SvsgPj4QHbua3VcSDc1dkOzdfvy8UJCQWS9mzYIES7YYzddUfe8pBNFUx0qihsvbaUUfO80q4bZiwxK+io7YUYhlp3gL60Dwscd7y7lwkcKuf9chQUs4Bot32AE2BA9xahytvOjkSpZhAGEHKP8jiRvayzXG0zXVCTUKQixlAW4F/bnNnkMfbttfcUrq5/ENvTRzZAgD4n/XkLLp4Ex8QQY/uUqoLeUYz+vGuxQavQAoglWfS59wirAxnV5Z2clhzplhUj8kEpV530utik4oVA0mGA/n40E3HJlceSGTrBkxaErK706sQHr8HiXW+QkHZMBdVS/w4KTKw== X-YMail-OSG: GkZdy4kVM1nqojiH6zXwT1QZdZ7J2UzovN28miqs0m_WzUpRyFM.wuCBqEPQYPA _b7ZIm9GeLgjmWuOkIQD3sWxO.9opZt4I2DOQjcqm4ty9e04b4gn90Hz6QoQS2t30jvTJ5KQweW4 tEe0qeBLeARTcoTYUVCR4_at1avK9iNmvxmy3.p4wV2.aBmmqjV32OxCi59jVbM3w8DcN5SRVbFq CELcQh.YZKpdyOJUHijyX4x59MN.4t1eTIZZUa.JtWUP.Oy1Met7Zyprd63dpmyZFEVgDvWxyln5 QbQMHw0xfSRpiMVXJbkUxCeZcsMBVRqmeepwIvu8tn8.pGAOxYnC.DBPvRZlt4002VemPQS0vYDG TRx53GINtDqQ9sV_tg9sNGyUTaQ6CSGEDxzhMDzdn8FfuWG88rCsBkBE269AJ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Nt.G eqSZ1bcxP081ZmRIp3l0gZ8BnuseaJ5vnYtDoapPVDhDFAWXhQiDikKezH18Ce10irFMU8yGU_ib 0uSOu6iY9nb4Fc2IISS0T9bMGBH8zG04iGrYSfi4TMMOTclVOd7F_16CU62zWH2BEfJnugW2Jx1O 1J9suAiInGAVNqhraijet_vYXA7sTV8TYYvIWOcW4TCS7VAnPsOPSL8aVQf2TUPkaG25i9R0JSdD _HITAKDLmU1ngZNaBTqMfANsciMUUV1HlhKWNLLTjGqPbnaSeszH0G4wyQdoZHRQoS42mzG0wdtG cNmtMWYh6cQMBm3wkdY.nErtoDy02yz3Y2LEtkj3uqLOkceH7gshllsZQtSftJbeoxP5eH9DXebU RsYKqiJn6A2WhL8GHiBhGG4yIfRjXWfJDnGdZAEtrFRw5RfDbW0wAxmChfQ.He2xvokGzOif717s OHygUIlhdxZN2O1etKIiKlXp4DJ17sWr6uM03MVDBJ5fJOCrkMVvOjGJO7k4DGMvGj.etSq0hfDz z0j_MwcoUdcPdexj5G3XTeyX3jxRxB.0qlbgHXHgL6I9G6n_QUL6LTHSzf7ETlB2EmLN5EVXMyBe 6_sRxlGc7IJLh9YE1JeWUlxtqtZb.DlUqaiFabhD37bHRE.5o7k4d38zrBHwvK3MzXyU9qZ.CP9Q doXKIQYEyZsRzUQXExOSM9dsO0qscZjrbQj80jrcu47.V7I5JBXHVj7MiPwbbXAC4zgF8FRRqLX3 9iStj9VG8N6A2VLZqMpVMI0.6j_2eyn92HYHZuWeGEWdZMZu4Wm8m7hR.f5CRqAAe50TWP27RhvI osbJnvLqKnlZrFYDJUQ0- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic306.consmr.mail.ir2.yahoo.com with HTTP; Sat, 18 Jun 2022 00:15:07 +0000 Received: by hermes--canary-production-ir2-c9bf9d9bc-74fwm (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 8b08f14069c990c2ed22165f3e3da032; Sat, 18 Jun 2022 00:15:04 +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 v3 6/8] iio: magnetometer: yas530: Rename functions and registers Date: Sat, 18 Jun 2022 02:13:14 +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 This is a preparation for adding YAS537 variant. Rename functions used only by YAS530 & YAS532 from yas5xx to yas530_532. Same for the registers. Cc: Linus Walleij Signed-off-by: Jakob Hauser Reviewed-by: Linus Walleij Reviewed-by: Andy Shevchenko --- drivers/iio/magnetometer/yamaha-yas530.c | 106 ++++++++++++----------- 1 file changed, 55 insertions(+), 51 deletions(-) diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index c6f5f25793c4..98c8d365fab7 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 +/* Registers used by YAS530 and YAS532 */ +#define YAS530_532_ACTUATE_INIT_COIL 0x81 +#define YAS530_532_MEASURE 0x82 +#define YAS530_532_CONFIG 0x83 +#define YAS530_532_MEASURE_INTERVAL 0x84 +#define YAS530_532_OFFSET_X 0x85 /* [-31 .. 31] */ +#define YAS530_532_OFFSET_Y1 0x86 /* [-31 .. 31] */ +#define YAS530_532_OFFSET_Y2 0x87 /* [-31 .. 31] */ +#define YAS530_532_TEST1 0x88 +#define YAS530_532_TEST2 0x89 +#define YAS530_532_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_532_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) +static int yas530_532_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_532_MEASURE, YAS5XX_MEASURE_START); if (ret < 0) goto out_unlock; @@ -264,7 +267,7 @@ 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) +static s32 yas530_532_linearize(struct yas5xx *yas5xx, u16 val, int axis) { struct yas5xx_calibration *c = &yas5xx->calibration; static const s32 yas532ac_coef[] = { @@ -306,7 +309,7 @@ static s32 yas5xx_linearize(struct yas5xx *yas5xx, u16 val, int axis) } /** - * yas5xx_get_measure() - Measure a sample of all axis and process + * yas530_532_get_measure() - Measure a sample of all axis and process * @yas5xx: The device state * @to: Temperature out * @xo: X axis out @@ -314,7 +317,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) +static int yas530_532_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 +327,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_532_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_532_linearize(yas5xx, x, 0); + sy1 = yas530_532_linearize(yas5xx, y1, 1); + sy2 = yas530_532_linearize(yas5xx, y2, 2); /* Set the temperature reference value (unit: counts) */ switch (yas5xx->devid) { @@ -602,11 +606,11 @@ static const struct regmap_config yas5xx_regmap_config = { }; /** - * yas53x_extract_calibration() - extracts the a2-a9 and k calibration + * yas530_532_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) +static void yas530_532_extract_calibration(u8 *data, struct yas5xx_calibration *c) { u64 val = get_unaligned_be64(data); @@ -644,12 +648,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_532_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_532_CAL, data, sizeof(data)); if (ret) return ret; dev_dbg(yas5xx->dev, "calibration data: %*ph\n", 14, data); @@ -661,7 +665,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_532_extract_calibration(&data[3], c); /* * Extract linearization: @@ -692,11 +696,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_532_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_532_CAL, data, sizeof(data)); if (ret) return ret; dev_dbg(yas5xx->dev, "calibration data: %*ph\n", 14, data); @@ -715,7 +719,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_532_extract_calibration(&data[3], c); /* * Extract linearization: * Linearization layout in the 32 bits at byte 10: @@ -738,7 +742,7 @@ static int yas532_get_calibration_data(struct yas5xx *yas5xx) return 0; } -static void yas5xx_dump_calibration(struct yas5xx *yas5xx) +static void yas530_532_dump_calibration(struct yas5xx *yas5xx) { struct yas5xx_calibration *c = &yas5xx->calibration; @@ -761,20 +765,20 @@ 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) +static int yas530_532_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_532_OFFSET_X, ox); if (ret) return ret; - ret = regmap_write(yas5xx->map, YAS5XX_OFFSET_Y1, oy1); + ret = regmap_write(yas5xx->map, YAS530_532_OFFSET_Y1, oy1); if (ret) return ret; - return regmap_write(yas5xx->map, YAS5XX_OFFSET_Y2, oy2); + return regmap_write(yas5xx->map, YAS530_532_OFFSET_Y2, oy2); } -static s8 yas5xx_adjust_offset(s8 old, int bit, u16 center, u16 measure) +static s8 yas530_532_adjust_offset(s8 old, int bit, u16 center, u16 measure) { if (measure > center) return old + BIT(bit); @@ -783,7 +787,7 @@ static s8 yas5xx_adjust_offset(s8 old, int bit, u16 center, u16 measure) return old; } -static int yas5xx_meaure_offsets(struct yas5xx *yas5xx) +static int yas530_532_measure_offsets(struct yas5xx *yas5xx) { int ret; u16 center; @@ -792,7 +796,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_532_ACTUATE_INIT_COIL, 0); if (ret) return ret; @@ -826,26 +830,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_532_set_offsets(yas5xx, ox, oy1, oy2); if (ret) return ret; - ret = yas5xx_measure(yas5xx, &t, &x, &y1, &y2); + ret = yas530_532_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_532_adjust_offset(ox, i, center, x); + oy1 = yas530_532_adjust_offset(oy1, i, center, y1); + oy2 = yas530_532_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_532_set_offsets(yas5xx, ox, oy1, oy2); if (ret) return ret; @@ -854,27 +858,27 @@ static int yas5xx_meaure_offsets(struct yas5xx *yas5xx) return 0; } -static int yas5xx_power_on(struct yas5xx *yas5xx) +static int yas530_532_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_532_TEST1, 0); if (ret) return ret; - ret = regmap_write(yas5xx->map, YAS5XX_TEST2, 0); + ret = regmap_write(yas5xx->map, YAS530_532_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_532_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_532_MEASURE_INTERVAL, 0); } static int yas5xx_probe(struct i2c_client *i2c, @@ -956,11 +960,11 @@ static int yas5xx_probe(struct i2c_client *i2c, goto assert_reset; } - yas5xx_dump_calibration(yas5xx); - ret = yas5xx_power_on(yas5xx); + yas530_532_dump_calibration(yas5xx); + ret = yas530_532_power_on(yas5xx); if (ret) goto assert_reset; - ret = yas5xx_meaure_offsets(yas5xx); + ret = yas530_532_measure_offsets(yas5xx); if (ret) goto assert_reset; From patchwork Sat Jun 18 00:13:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12886143 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 887E8CCA479 for ; Sat, 18 Jun 2022 00:15:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380215AbiFRAPQ (ORCPT ); Fri, 17 Jun 2022 20:15:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348242AbiFRAPP (ORCPT ); Fri, 17 Jun 2022 20:15: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 1E97E21259 for ; Fri, 17 Jun 2022 17:15:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1655511311; bh=jJGcjXdRFHjvy2vr53L1DCuPWMWBd4P6XV8ec+te0zA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=Jki6R99TZeoRckSDEAevrRi4J1HWPZ2F9xjYI5nU21BUMqyK+IzVtUbzaQSqUDMoWB37n4hMcM8aDFK8adAecJgxkfDewGkogTZ7gaYb6FdFzsuUc7OnCCndPfwE0asK4c0rMJ9DfLKPbUnrY5+Dt9V2GkhSGW6a3c0NMsYgwks+VDEFGzjUNhB9Ou5r41j0Wz7bmjNTwO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G_SYpEN2i 3J3FgPBysYEzna2eK7nYKeDkWC3dyt0lB_ETjK8hqKoHepDF7lpvwiWYYJBOnRP7YAYsvsyRnpe1 7NuhFs99uO5I_vHuDDNVZVaujcPS86yd6IcGCWlAv55DmGfz2X06VTqEYI6jLAkd0BPTMntT_W9r xWCpNOFQTlBAgI1Bnq6wamTVKaIVnU1iiJJUrL2.9G7qfKIcg5TTLJImqUOz26A2kXuabaPXTUYJ 1R6lEm8TpwD4huxpQ8m.1P.DDj8JWk8UpQG3kIWqszsSewAhuISoGomEdVcoP9bvmuVbZL2Ls_PV MAo4vntPyvp4kCdyL6g4XTE1kaCzpkL6ji9A2y6nry1_.JkBK2pWC5yolWsnd06N9wXPsvY57Wej AXORKc75tujuaQFhhtSWSKyE.OBeV0XbOAjEba6fHBaK7Zxrv.tafAQ44wgzYedaAjqzNJ2N4JNy w5cTJrOiVQbPG4HTfBm9PXynf6rVyMsoTb2AlEkZ56ovlyl1gzUkuezUz76LdjVXrtAHFYb_dHpX ZY1N7L0vPk8_tKD16KkLULAVcbrvDNi3xJvk9j4CrfjZ8CyfNCpv9qpYv1G.o1JfZSsLGu_AYMcS J3pbod2gT8MstdRdoN._HhpplzijiPvZbNdJLr3CcTDwSW6qIYUnqoMiRuedEDYaN13uivFp30T0 .Bm1PUaC_BNfdZWdW0eccIXjTNsV.lcp_nGiv7YV8abex42riUtnpTuACRYf7mL.Xl6LgS_ksF_g AbgLz9qybxB0IdryerwmlLNuDcErOoVqYB3TfEfB1d2oGUv4Uc_1T.g3SjP4yBEvI7auAhYY3hB4 q3bFVlD6u4n_D_oIvqQ-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic314.consmr.mail.ir2.yahoo.com with HTTP; Sat, 18 Jun 2022 00:15:11 +0000 Received: by hermes--canary-production-ir2-c9bf9d9bc-74fwm (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 8b08f14069c990c2ed22165f3e3da032; Sat, 18 Jun 2022 00:15: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 v3 7/8] iio: magnetometer: yas530: Apply minor cleanups Date: Sat, 18 Jun 2022 02:13:15 +0200 Message-Id: <362744427c87bfcfa8c885b1bb174dacc4861ec3.1655509425.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 minor cleanups in the current driver. 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. 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. --- drivers/iio/magnetometer/yamaha-yas530.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index 98c8d365fab7..72a75dc57e11 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 @@ -322,7 +322,7 @@ static int yas530_532_get_measure(struct yas5xx *yas5xx, s32 *to, { 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; @@ -656,9 +656,12 @@ static int yas530_get_calibration_data(struct yas5xx *yas5xx) ret = regmap_bulk_read(yas5xx->map, YAS530_532_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); + /* 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 */ @@ -685,6 +688,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; } @@ -703,15 +707,17 @@ static int yas532_get_calibration_data(struct yas5xx *yas5xx) ret = regmap_bulk_read(yas5xx->map, YAS530_532_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) { + if (!memchr_inv(data, 0x00, 13)) { if (!(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); @@ -720,6 +726,7 @@ static int yas532_get_calibration_data(struct yas5xx *yas5xx) c->Cy1 = data[1] * 10 - 1280; c->Cy2 = data[2] * 10 - 1280; yas530_532_extract_calibration(&data[3], c); + /* * Extract linearization: * Linearization layout in the 32 bits at byte 10: From patchwork Sat Jun 18 00:13:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12886144 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 6B80CCCA47E for ; Sat, 18 Jun 2022 00:15:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236528AbiFRAPS (ORCPT ); Fri, 17 Jun 2022 20:15:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381999AbiFRAPS (ORCPT ); Fri, 17 Jun 2022 20:15:18 -0400 Received: from sonic303-21.consmr.mail.ir2.yahoo.com (sonic303-21.consmr.mail.ir2.yahoo.com [77.238.178.202]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8822E28990 for ; Fri, 17 Jun 2022 17:15:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1655511312; bh=FUCFiv/rH7deJKomtcQ5oy/kYcRcwMHqiUcoKWdEu24=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=UFWdND6Xp/4jJC8pX6XjmWqA2K53ag/EinpHvnOB9jnp2kGbcLYXVm0J6UASKJ9aTK5bLMdC7phdBH/P/PopKtyM0Cz+Q41gCxZ/VvdTdQdOvZ84VG3Qsp92/YdINXiOsqUdgCkgCVDLq8Tf2XreUjWVEdJ52d4mpku5wZQ51GsF+6xnc2w2+SGvcHYT3E5e1dc1QyJbmCc/8jyExJf9gaJqKITpeMtPbj7eHD9ydMfmqf0y390nEZuomSpmc3JxrSARXqFLiXqCE/aNO193m1JSpD0TxNmO+5S3ZXAfGIC1u+z3ZtnPQkII/DIYSqf2ZUf/kdXsLyE9UR0z7tST1A== X-SONIC-DKIM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2g4U2fZLq7nfMmJA7 VILGGUfcYwT0f9MxbDZLwF1ZhYmzxtFvv99Gp5HkkvyOC.8bz.uDeYSgh0YZuvp9bBwwG868x6R7 4OGNZWk._hbSddGlnHBQkrhCO3F8dOE0Ouo5gZc_qQ7238qu9GoTQ7O3LkoVcDUanjY1jF1SLPeC _czTUx.Dy1q8Yff1dmIwbOlqzH06VBqesYglR.m063vRUaJbOKKskGS9Nli8K3Pq3fBhar8j61U5 eWg5vbv71Vw_17j1UTGuVnxT1tX0T_Xsu7kgveuV6CxM_g_lTIOovgXm_aHo.CvKmQDArPDMb60B Lhq_Bppz9.BYYvy1l4afsCz2MzzOMvdvu08cHVlrOyq6Nxysl7INtoRKj7LB4Ng4jAbeUgkgd2lv pDtpAPxOtRfmMnnXth2mw6qRAJ1ilhTrztjGyrVxosnzrxI19UhiUNC1yLaODaE0wP2Cp1clS1K2 5G1amOXqd_9SKVpfHDOyU.8QmbdiOaEJzcTafSEwik85pB0oEwKKjXUoGbH5DFDiiMjwD5iioeh_ _5WBn0.a8jKPYvghZ4ikT5hbSfV75yuhOz6uR.ip8gboM6YVOE94G1qE5EFpuJjwjaLY2LN5k63g kJliM_rBIX3Pw_cblaYCAHY6VNK.dgX4dHgMWrDFz779Pn0BIiq1araQklEPrMKxO2qRyDsqZUcx sf2XjdLXhoOZeeLLqkgA- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.ir2.yahoo.com with HTTP; Sat, 18 Jun 2022 00:15:12 +0000 Received: by hermes--canary-production-ir2-c9bf9d9bc-74fwm (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 8b08f14069c990c2ed22165f3e3da032; Sat, 18 Jun 2022 00:15:08 +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 v3 8/8] iio: magnetometer: yas530: Add YAS537 variant Date: Sat, 18 Jun 2022 02:13:16 +0200 Message-Id: <3bdb392bb75073bdfe10aab1739fee2d6c64f10c.1655509425.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 Cc: Linus Walleij Signed-off-by: Jakob Hauser Reviewed-by: Linus Walleij --- The diff on function yas5xx_probe() is a bit confusing. Maybe better to understand when comparing before and after code. before: https://github.com/torvalds/linux/blob/v5.19-rc2/drivers/iio/magnetometer/yamaha-yas530.c#L873-L902 after: https://github.com/Jakko3/linux/blob/yas537_v3/drivers/iio/magnetometer/yamaha-yas530.c#L1416-L1463 drivers/iio/magnetometer/Kconfig | 4 +- drivers/iio/magnetometer/yamaha-yas530.c | 553 +++++++++++++++++++++-- 2 files changed, 529 insertions(+), 28 deletions(-) diff --git a/drivers/iio/magnetometer/Kconfig b/drivers/iio/magnetometer/Kconfig index 07eb619bcfe8..868128cee835 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. Right now YAS530, YAS532, YAS533 and + YAS537 are fully 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 72a75dc57e11..e6123d1d9383 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_532_TEST2 0x89 #define YAS530_532_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) @@ -93,8 +114,15 @@ #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 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_20DEGREES 8120 /* Counts starting at -386 °C */ + #define YAS539_DEVICE_ID 0x08 /* YAS539 (MS-3S) */ /* Turn off device regulators etc after 5 seconds of inactivity */ @@ -267,6 +295,78 @@ static int yas530_532_measure(struct yas5xx *yas5xx, u16 *t, 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; +} + static s32 yas530_532_linearize(struct yas5xx *yas5xx, u16 val, int axis) { struct yas5xx_calibration *c = &yas5xx->calibration; @@ -437,6 +537,58 @@ static int yas530_532_get_measure(struct yas5xx *yas5xx, s32 *to, 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_ref, 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; + + /* Set the temperature reference value (unit: counts) */ + t_ref = YAS537_20DEGREES; + + /* + * Raw temperature value t is the number of counts. YAS537 product + * description No. PBAS537A-000-01-e mentions a temperature resolution + * of 0.05 °C/count. A readout of the t value at ca. 20 °C returns + * approx. 8120 counts. + * + * 8120 counts x 0.05 °C/count corresponds to a range of 406 °C. + * 0 counts would be at theoretical -386 °C. + * + * The formula used for YAS530/532 needs to be adapted to this + * theoretical starting temperature, again calculating with 1/10:s + * of degrees Celsius and finally multiplying by 100 to get milli + * degrees Celsius. + */ + *to = ((4060 * t / t_ref) - 3860) * 100; + + /* + * 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, @@ -450,7 +602,18 @@ 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); + switch (yas5xx->devid) { + case YAS530_DEVICE_ID: + case YAS532_DEVICE_ID: + ret = yas530_532_get_measure(yas5xx, &t, &x, &y, &z); + break; + case YAS537_DEVICE_ID: + ret = yas537_get_measure(yas5xx, &t, &x, &y, &z); + break; + default: + dev_err(yas5xx->dev, "unknown device type\n"); + return -EINVAL; + } pm_runtime_mark_last_busy(yas5xx->dev); pm_runtime_put_autosuspend(yas5xx->dev); if (ret) @@ -484,9 +647,10 @@ static int yas5xx_read_raw(struct iio_dev *indio_dev, *val2 = 100000000; break; case YAS532_DEVICE_ID: + case YAS537_DEVICE_ID: /* - * Raw values of YAS532 are in nanotesla. Divide by - * 100000 (10^5) to get Gauss. + * Raw values of YAS532 and YAS537 are in nanotesla. + * Divide by 100000 (10^5) to get Gauss. */ *val = 1; *val2 = 100000; @@ -506,7 +670,18 @@ 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); + switch (yas5xx->devid) { + case YAS530_DEVICE_ID: + case YAS532_DEVICE_ID: + ret = yas530_532_get_measure(yas5xx, &t, &x, &y, &z); + break; + case YAS537_DEVICE_ID: + ret = yas537_get_measure(yas5xx, &t, &x, &y, &z); + break; + default: + dev_err(yas5xx->dev, "unknown device type\n"); + return; + } pm_runtime_mark_last_busy(yas5xx->dev); pm_runtime_put_autosuspend(yas5xx->dev); if (ret) { @@ -592,9 +767,34 @@ 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 + 7); + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct yas5xx *yas5xx = iio_priv(indio_dev); + + if (reg >= YAS5XX_MEASURE_DATA && reg <= YAS5XX_MEASURE_DATA + 7) + return true; + + /* + * YAS versions share different registers on the same address, + * need to differentiate. + */ + switch (yas5xx->devid) { + case YAS530_DEVICE_ID: + case YAS532_DEVICE_ID: + if (reg == YAS530_532_ACTUATE_INIT_COIL || + reg == YAS530_532_MEASURE) + return true; + break; + case YAS537_DEVICE_ID: + if (reg == YAS537_MEASURE) + return true; + break; + default: + dev_err(yas5xx->dev, "unknown device type\n"); + break; + /* fall through */ + } + + return false; } /* TODO: enable regmap cache, using mark dirty and sync at runtime resume */ @@ -749,6 +949,216 @@ 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, the exact meaning is unknown */ + 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)) { + if (FIELD_GET(GENMASK(5, 0), data[16]) == 0) + 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 < 17; i++) { + if (i < 12) { + ret = regmap_write(yas5xx->map, + YAS537_MTC + i, + data[i]); + if (ret) + return ret; + } else if (i < 15) { + ret = regmap_write(yas5xx->map, + YAS537_OFFSET_X + i - 12, + data[i]); + if (ret) + return ret; + yas5xx->hard_offsets[i - 12] = data[i]; + } else { + ret = regmap_write(yas5xx->map, + YAS537_HCK + i - 15, + data[i]); + 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; + 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, + (data[3] & GENMASK(7, 5)) | BIT(4)); + if (ret) + return ret; + ret = regmap_write(yas5xx->map, YAS537_HCK, + FIELD_GET(GENMASK(7, 4), data[15]) << 1); + if (ret) + return ret; + ret = regmap_write(yas5xx->map, YAS537_LCK, + FIELD_GET(GENMASK(3, 0), data[15]) << 1); + if (ret) + return ret; + ret = regmap_write(yas5xx->map, YAS537_OC, + FIELD_GET(GENMASK(5, 0), 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 + */ + + /* Get data into these four blocks val1 to val4 */ + 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; +} + static void yas530_532_dump_calibration(struct yas5xx *yas5xx) { struct yas5xx_calibration *c = &yas5xx->calibration; @@ -772,6 +1182,26 @@ static void yas530_532_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); + } +} + static int yas530_532_set_offsets(struct yas5xx *yas5xx, s8 ox, s8 oy1, s8 oy2) { int ret; @@ -888,6 +1318,45 @@ static int yas530_532_power_on(struct yas5xx *yas5xx) return regmap_write(yas5xx->map, YAS530_532_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 int yas5xx_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { @@ -946,35 +1415,53 @@ static int yas5xx_probe(struct i2c_client *i2c, switch (yas5xx->devid) { case YAS530_DEVICE_ID: - ret = yas530_get_calibration_data(yas5xx); + case YAS532_DEVICE_ID: + + if (yas5xx->devid == 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)); + } else { + 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)); + } + + yas530_532_dump_calibration(yas5xx); + ret = yas530_532_power_on(yas5xx); + if (ret) + goto assert_reset; + ret = yas530_532_measure_offsets(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); + + case YAS537_DEVICE_ID: + ret = yas537_get_calibration_data(yas5xx); + if (ret) + goto assert_reset; + dev_info(dev, "detected YAS537 MS-3T version %s", + yas5xx->version ? "1" : "0"); + strncpy(yas5xx->name, "yas537", sizeof(yas5xx->name)); + + yas537_dump_calibration(yas5xx); + ret = yas537_power_on(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: ret = -ENODEV; dev_err(dev, "unhandled device ID %02x\n", yas5xx->devid); goto assert_reset; } - yas530_532_dump_calibration(yas5xx); - ret = yas530_532_power_on(yas5xx); - if (ret) - goto assert_reset; - ret = yas530_532_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; @@ -1070,7 +1557,19 @@ 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); + switch (yas5xx->devid) { + case YAS530_DEVICE_ID: + case YAS532_DEVICE_ID: + ret = yas530_532_power_on(yas5xx); + break; + case YAS537_DEVICE_ID: + ret = yas537_power_on(yas5xx); + break; + default: + dev_err(yas5xx->dev, "unknown device type\n"); + ret = -EINVAL; + break; + } if (ret) { dev_err(dev, "cannot power on\n"); goto out_reset; @@ -1096,6 +1595,7 @@ static const struct i2c_device_id yas5xx_id[] = { {"yas530", }, {"yas532", }, {"yas533", }, + {"yas537", }, {} }; MODULE_DEVICE_TABLE(i2c, yas5xx_id); @@ -1104,6 +1604,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);