From patchwork Sun Aug 7 23:02:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12938399 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 128F2C19F2A for ; Sun, 7 Aug 2022 23:03:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232842AbiHGXDk (ORCPT ); Sun, 7 Aug 2022 19:03:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232816AbiHGXDj (ORCPT ); Sun, 7 Aug 2022 19:03:39 -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 642832AF3 for ; Sun, 7 Aug 2022 16:03:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1659913416; bh=RGArz7Zwo1YrpUAyYAm1grVSpdiCN8Oa/NeiK93F+nA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=DtAKcIiE8ZhVLHjOTGR/SraZcdQGMYxByzyFLwKn7TmoOAWm0E/z+swGaCfk/Oyp3z1TDKRdUanK9sTd1d5fodH8r+xzjTGA68sywsb4oR9/ftJH7RghOof0uxRaOX1HahH7SDfXyEDm5lJ3EtQ1hySbPmJ3G3iiI/9kD5HlaojW+W/PsxJv5n9VYwe8GRBGEnM9VBUM4/PUXTYbQbFSUH8u7bGtJjqID9ejglg6ypCaOIFHNa9bXBbbFfEA3PMn5AsqFVDWVGVBlAUaAalW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YSlIQap 7tU1i0GZ5B6q4Kt6AGoD8Lr1NkjbeltNpOuvb68sCJMPieM8wZHkm8u9EfXNFwhYA4WrMciyyN3E DsOJ2606KGfkpgs3Y2T3RTLwldbMdw21_.G20wbEuThpr4b7xTv8Cg4ogjYXUl2T6woUQUr0MYUE nMDx1XVTwJSoTv8Qj5UENgKcuD2AIfDT4ljrDKUiIpVFvE5UKr_5Qd5NZmlJx0BylY6uKjqeks2p ZB0uVIkDWShe.hURWpQIMKn2kUKA4xOtzVVWQTBKlLa_wnIwGGo9iZtPUpcpxprkqcHe33kWSvTA zV_r5.VvkoyQwtb23fkO5I1A4rUCxru_yMkd7Z1WZZfpQEVpj8bQzoVmM.kJoNjDNzDAphvP79jI 2YuGbatYDxU6fk0Urngq.jUXFo.iXdFcVw9fFoYfo2up6ehuqtGlTKVK5ZZWivOxwFEjgpiUefGz FdlZekW4.osuOATkfdmptFZ9WO3MgKXSZWthwd4ys1s81HzsNF_qoLqPAMLKAkJdhSt66qiG50Pc PR7M2AzTy8W_G_EMF2kGB9CPnW1Tbwqve.lHWgzpRqTrhJ.N4Zc74SgW22km8IFu5ZnsQWrW1DJX 1t4KAgeOA8JjXZ59tCwLQ_MApT1uMS8W9bVyL5DTokZ5kZG0q5kWGJgCO.bkIDTkMdjRGPstI7CT lkbBuzoDPzj7WyQTU8Wtg_v_OA6juXNSdR451RqYDmfuFRZWxMnfXr9CZ3na1kHvEOJoZT7in3lh SdSciYlEtjKpuaA-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.ir2.yahoo.com with HTTP; Sun, 7 Aug 2022 23:03:36 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-r76pr (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 12b0bfa600682cb6edf92800aaf76d46; Sun, 07 Aug 2022 23:03:34 +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 v5 01/14] iio: magnetometer: yas530: Change data type of hard_offsets to signed Date: Mon, 8 Aug 2022 01:02:06 +0200 Message-Id: <4293862b3deb526ee1163b6fc8d0786c3d9816fd.1659909060.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 Aug 7 23:02:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12938400 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 5CD0DC25B0C for ; Sun, 7 Aug 2022 23:03:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234303AbiHGXDs (ORCPT ); Sun, 7 Aug 2022 19:03:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233481AbiHGXDp (ORCPT ); Sun, 7 Aug 2022 19:03:45 -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 AC0DE2AFE for ; Sun, 7 Aug 2022 16:03:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1659913422; bh=F7BpDzS7greEJoS/tBb1EI2GHOq6sKTMQeOG/t4ARZY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=a6SNXd5cbkg/zmKadLwnfdwBQy0/zb4GnF9v8nkiJFDHozeHzfxRuaifX4+MXPGDfIskrvuB9kclMD5Q/LnGhgHSoyU8IG1orSrVBLNcmRpBi5yDNQLjD467Aj/0zBlpUUb9SO8Cm4zVwxTWY4+xpWJy8k1zB3pePE5QeH1+Jx5vpxwsd9LTVsm/WC7aw+MWNL7nbMUSvKW97s1Pz4dvCexQY/K4ie1oHFrf3rrZu2ScW5174AAvVJq1LaUQ8lMBKtgaW+wLtIkeVq6OnQnlZb9pUUTJfD7LJe0+viQJ6nkJYtnNirxTvrkGgrDrzmaUr8GiVhYVGfrTojH2FgZloQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1659913422; bh=tSmXNV+CCu/AUEvsX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oW cCfO5oV53wb36NRM08nLcTPd0C0vSsGujBxUU48ppVpif6FPU4rjWm3SnD90xUI9AHFb_vCJ46g1 31sGaOQWB64u5z_YgS69GUm5GwSVZB.6uxIC6UE4dSfHXrAak_O_ibGfPW_wYKfdgcpuObDy30Tx yXotxl4dIyNDnodbsRnVU5EbX1hyit27m3np30CtZ_uD9y3cgs0cvcXEFhKKcipMq.hnB7bXOgpO kKveuWA..RoVG5GmLA7nvMc1pYTngRKoyGIB2CP2bJNLWz08P_T6JRivcl72d.yUWDdz.MP.3wpK t7QYwrlUrvnpwr.YMrfOYA87KcqSJwXyXo22bswnsBJ3erFmyqypU2globvdRLkDlktZI52XhEYg 7y77X90TwUTV9Gpwy1tJ6E1k7ur_QUxYrcDFap5cpUmEQXyIX5H_facTdUUQloWrVOPoGQQk9me4 FzyKOQImqzCGbwYHP1le5JB.WWhoJr8IiqxIYzZgga8URC8eSp1r9G4kNqQim3oiz09BOlizvNao 9ATPoyh7AjiCTpAMeZWzFoGb0ac.1rukxn402EsbescU3vvBLlCgoLW67dpXQgwBBTjvBSxIs8di JGxVmEpy62QYigA-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic312.consmr.mail.ir2.yahoo.com with HTTP; Sun, 7 Aug 2022 23:03:42 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-r76pr (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 12b0bfa600682cb6edf92800aaf76d46; Sun, 07 Aug 2022 23:03:39 +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 v5 02/14] iio: magnetometer: yas530: Change range of data in volatile register Date: Mon, 8 Aug 2022 01:02:07 +0200 Message-Id: <1977ed81c06684cd08d90bce272c0256bed93cc6.1659909060.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 Aug 7 23:02:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12938401 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 46166C25B0D for ; Sun, 7 Aug 2022 23:03:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231964AbiHGXDu (ORCPT ); Sun, 7 Aug 2022 19:03:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234117AbiHGXDr (ORCPT ); Sun, 7 Aug 2022 19:03:47 -0400 Received: from sonic308-19.consmr.mail.ir2.yahoo.com (sonic308-19.consmr.mail.ir2.yahoo.com [77.238.178.147]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 937092BD1 for ; Sun, 7 Aug 2022 16:03:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1659913424; bh=EuFGkupLjx9zPeG1GfBnRcBvJL6CsBo11j9xvtKmu7w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=r10zRAa1E7+U+H3e+xn3yYVp/HhRH0Oq3RjXv6xENVoMJaLWVsCHEQrR0bZLvY8NTmQATq/Ky6psZI1xwD8WxM0oJd39Mmsek6tckiVCSlQZuuceYgtCT11zatrhVWDvSgTJr2EtXBK8eRDMtPvVoIXiUpUsk8dpk1jjeMpACVV6C7/44psaJiIEn1xz6jhpCVkmOrYJ3WYlUNBl9CzY7pDI/TMceyqQJXDWZbamrecaD5DArXC+kdpB0o90ZtFD97iFhPOcdlvwZZIJJRTLuG13dU/43iplMfa23B4w9qzJo+ATHUfLdQlJ7hLMS266mNTWxDYYyWnrxyVeJ7O+KQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1659913424; bh=MJx5cxsV7ELbkysUhaWazzJOoZLHteyrA68/h46TzPJ=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=jNZm0Ra9kwqEH4kjwXx60U6Z5tm6cFiv5ev3IqajKdee2w5unFzIgBUJCKaTuqWk3cj8K8Sind0PoFj1TcjkDgXXm0Ym2zF6Ow820KiuNRaK2rmqIWC9ahDs13VmFShUKIBfdGYqhIiv/xNplAIrRf+Ch7s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iBqMcXpm4wdFQj6MRG9v.x RhmTjML_bOZHEp5RivKciI1HOh8TRS05hwZbXvck1.skK4G7knSvZwXtLLaErncBCHAEqX569S45 k.IobEAkyb56NntLSa2puJHmd.ooAC8ffMwHUQrwlNdOuzft61HScMFlMyrYEh_RHn68LsWRjXtg vmp7K0TFTZymbZ6BUlpkTrc3h0rV7V01ypBUma2jrDxUWn2QhCzEWz0hCqAntSZFcxFae6rNnItc iIBPRpJas8EcpGw1mB_bE_jUGDOFK0OvQQf7B6npjSPwiP47YpS4qVFEQtTD6s7Qscgh66jvP_N9 2Z3Yyy.kg06AdFbZWYzCMsyXq7sCCT5zachsXWNR1kPjpmdJQ6Sh2q9pPu_QvcEueLpkhV_jX_AW 7EWpFVCqfMwU634VeFTg- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic308.consmr.mail.ir2.yahoo.com with HTTP; Sun, 7 Aug 2022 23:03:44 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-r76pr (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 12b0bfa600682cb6edf92800aaf76d46; Sun, 07 Aug 2022 23:03:42 +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 v5 03/14] iio: magnetometer: yas530: Correct scaling of magnetic axes Date: Mon, 8 Aug 2022 01:02:08 +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. 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 Aug 7 23:02:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12938402 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 67BDDC25B06 for ; Sun, 7 Aug 2022 23:04:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234913AbiHGXEC (ORCPT ); Sun, 7 Aug 2022 19:04:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234117AbiHGXDv (ORCPT ); Sun, 7 Aug 2022 19:03:51 -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 2D5A32BFF for ; Sun, 7 Aug 2022 16:03:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1659913428; bh=8VJGl0MuSHhL28Kf4k+uCd0Gflpcbk+QqcZEf6TEyHU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=nSgkCKPpBpgf34OQjXFnvRdv1OUWfDpTzc9uOZ8mw6hNQQIScQgJFH0HxfnOZCDXFHO1pRIXqo/W1WvuO8UzgMBYU4bLfRzDzmcmKO78Q5gHWsF+bC9ShL42Quy7FMGuYTkIBcKOdz8OR124vM3ZfXzpFFNE6VEXspG1sBR8g4d0mLdkIPZYpOmPt/SkkenPoWTPmqZJSF/kOiV+huSZPgHJP6j8e3rxG9+kQTpeVYJg/sH6px3qBEVPiNk+LBJHxGu5QzbMgVZTNMy9JcNWsxUm//dBTJn3+i8MYyqQj4m+m839MoQZnUzOK0lrlJmTM/rqPbWJLFdXOnSgSdsy4A== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1659913428; bh=vSNsIW/Z1x5kP9oYVwwRlTHWqIHJMt9L3CEO+4nMkI9=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=eqNc0kdfTrNrhqrNtBWIoJVuxcVeMZCbt1Ypl/6DIaF/5TI0RytQ2OqAID3OJKa7uZT8XkHIul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qOMn_XZd0GOJtAh387XQOGFDDx b54izxj4bglezhXk.ss4cnp3L_RftX5YuctZIYny0SrFC7wTowOQFJg3fihyCXNRt55hyUEM8hQe VyHSix9_LBxUEPEUGOh53SWWzqqNRlaoeZdHtSs5_jXj8ME30vfThp42RiMUeutd8HIR69OpGr1h NnXE.F0HgA_nRkeItfnuqLh.CQBISjd_1svOn65AEYOThuxxe2ySPUK2dUAtTCxKnyOVL03mESDo i8buxCFMUu3yumRogbdX9QkJArvU377iJ05sxt.Xukm2RMhDgOInn2OekbL98jcgAxx9Fr1k937f ZE.iUTvKVzdHvTAeL50R3BYcvzkWUrYqxdhTy8.xupaT1X6HL9zrQJoy2Mh0UTOPemuRQd02IfAs dP60gnr6hZ0JhIn1KnmY2S0JQINxslha_tAucdybAue8fa9KhLu0oSMD68bahBPUQFSuN.N6XSBN r.t04n9AH3ZKBTJOPo6tJ X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.ir2.yahoo.com with HTTP; Sun, 7 Aug 2022 23:03:48 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-r76pr (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 12b0bfa600682cb6edf92800aaf76d46; Sun, 07 Aug 2022 23:03:46 +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 v5 04/14] iio: magnetometer: yas530: Correct temperature handling Date: Mon, 8 Aug 2022 01:02: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 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 Aug 7 23:02: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: 12938403 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 55183C25B0C for ; Sun, 7 Aug 2022 23:04:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234180AbiHGXEF (ORCPT ); Sun, 7 Aug 2022 19:04:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234065AbiHGXD6 (ORCPT ); Sun, 7 Aug 2022 19:03:58 -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 F2EFD2DC0 for ; Sun, 7 Aug 2022 16:03:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1659913433; bh=GR8ksOaf4DkPasL6sXDaIM2/cMoDf6p7jL0ro40UYps=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=shZhKhkHvg5biL4xfYK8X47HXkyAJ9OQdvNLghXK1lTABpTehMQmpdr9+fZl2klhIUK2XFVE4LU3uiRWTt/2Ao3JHcQyovTQZ2hcz1ZTI9CT9EgDZrmwSE/0gtJGc9xoj9DJBXkHxwCXKM5FUJlCkpHPyGAkLPYsqYx6BrZs6PROfp8fhUnICnXAACsdyGSHBwNmHacnJMs4iK2ZeH6YAaY/mu2IA7eyvvQbOHjSvqn9u5V5iGkcZbTtFwD6kMcWQtrNbyo4B5woIyJ2C7TjpJMNULoCD8PzWBY1wwSos4+uiu8v5LzUrIqMyPQWArl98fjBXe56iHvP869GWNuXXQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1659913433; bh=aI04ScFbkx9RmSULteyPDYRJD4P3BP+k0dKwXtEDDBI=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=k+NJZ8VxyUujezjbBkpNlAT8AM9TIWuOWTVjWY1hhSCPmE61a5P8KiLA6XczBiCQoPlepDYgViozjuMw5flNX78D+sxTPx5sa9WSnCVlGSqaZyjn9dIJ4K5uJWkiFFqmm9DrL5C0DzgoPk3x7TA2oP35QNhVeKgNBUmltO7dHW409L1jwMKhGzM84+p2oi7VjBJq8gtwH9jeS/NYVv7cK316xxCTUKPdJhH3n9Ra2Cl6SLUDx74+Bd2BIu97szWQnZMt+qgVDcn3L/vDbXR1Z0EO8lE1ypFaIfKJn66SPVpBVFTV4DZJDrbBTwl357jroAFOR23ieyRC2vB5IsTkiQ== X-YMail-OSG: eKYLpq0VM1nP1Jz_pfTinRVHx7G1CD2TB_y5.k0zBzXVLq7Xbp74Uh0e_A2Dy6K a4nR7ByFOS5alZQVhSyco7e_ARiUo___3lSE_embKLLkwUpzic8emubw5paoTJJ4DEP7FQrSTOO0 y.7NXAvRHtkP.jpbXPONA3GPKdfXSZWo2iSv7DzXA1n36ibnbBE0BiMTUnSJBoI2R7gOP6so9Pbu KdH9ZY9lme6wwHU_kD6e9hpihQmSZyR3Jq8DUT_8LD.pboEXta8MPDvBNGkxnxU5nmPLAWs9aVwe D.LtJlEWyGVUS2KUz0IZuoTJ_5aUXdhI_K5Lw0xagnIYM0HZjiK.hwBycCxRbA92aER4__wuGJU8 Bru77YsQqZasvqLpe.cppYxcIcoeqVvwZfKI5.A5yVZGPglxoUi8dXEoqS2BEf76fmVPOOe5ZmOX XoDfLzXfu0T.wlA7fG4R_7QVNAeUq7qur7dJQprSM_m1tHR8o3WWeYoChqUDd1asvVa587JQll1t G1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l_j90XRkwuL4VcsHt_tiktXCJU66qfHB A_uX6JiSVYfzv.U0vkGGIVOUSo29cwMuU4qgPfRYq86VhQFVcL_BXuzcgEwJLfXcd.GSvx3oqFhz v2JvdYjDcO3s.J24dMG2a5MSmLDqj.n.WFoyXnwApt3x3KjTcji_QyKzqL.KiG_sDpE.iVYIkCNC JEudkdDCGCMFBj3cdnllSOMk4KbfLD.uB7Wb_Kbh8LICHg8HiT9H2_gJ67xhDFg92fFFufipw4Yo 9jSsVsLTqFUbh2cFZXb2EPv4GnGYjc2Q6bCCbfkuk.XE8Y_BQyZNIyOq9dgWXBQ4hcCJEPjFAHHJ P6Bxat4CXcdJ9VNKd_uuOG0CLH7TbF1_c_k1HS8r9rGUYsJbQCY6M95GfBk_E.wRvO3TuaV76eOa m4tXb3nYV7ROlsyoF8ylcu0Xf0zYR_kHdzsLqDdtmPwPDJykDW60S4L0lKukS1.gb76ZypbHqpFe 3ricSiwefBFqpZTvTy6r1AvlUtOLRYPXl2Ts5w09Pklf0YLnQPvqorgTu3TQc2PDi9f6c9F0wrEZ hKD9QW4e8SSvbhxtpmE5Z6O9qqYD6cbp4IFuedGj5URKNihlVpQNDsCPiga1x0uF5o9lY9e7xzUw qLHPueWnMt_BEPBMy_ZbX2pJEEpwL3SkAFui6bhn2.m3oaIu7g6FRRK2AGKlV5T7SAlNJ1t99xZn c9zORHyC2cMylUfXDK5l_7i6978dcV9uaV4Dk9nOby6CQxdgOG5ogklvJ1OcEkj.tlM5tMB4jNF8 Bq96FmutQHkNCXAlv91w- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic306.consmr.mail.ir2.yahoo.com with HTTP; Sun, 7 Aug 2022 23:03:53 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-r76pr (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 12b0bfa600682cb6edf92800aaf76d46; Sun, 07 Aug 2022 23:03:49 +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 v5 05/14] iio: magnetometer: yas530: Change data type of calibration coefficients Date: Mon, 8 Aug 2022 01:02:10 +0200 Message-Id: <9e95569cf94790b77d82dd29a230716717cef100.1659909060.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 Aug 7 23:02: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: 12938404 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 EF2F1C25B06 for ; Sun, 7 Aug 2022 23:04:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232816AbiHGXEJ (ORCPT ); Sun, 7 Aug 2022 19:04:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234900AbiHGXEB (ORCPT ); Sun, 7 Aug 2022 19:04:01 -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 AB0D42DE3 for ; Sun, 7 Aug 2022 16:03:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1659913437; bh=iSvqFPb7a8bm1SPtoNuwYDbtvuFTmw+0jFTTDM504tg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=ETu3hpw38EpJkJvW/7pOwAlQG1lHmFiZQ1ykW9hmSEVJ4W1v7D7cDtChiJwkLJmlx/yNCsng5mvqh9cLqmK3tjUdvQPapdGE2F4kNXOD1y7L/N2mt+WaDHYMy25BajCQDPo+xxnzBssUMVtkmA4AqFnZt4fXZINcEP3ixeEmdd9N3oZgSfB32kZtJ/rO2n6LnPOJdP2DzCVQOUHWhlANB0AqSmOrTl8DAC1/i7gvphNDc9IRuzLb+z0ARu5z2uFlu8QQddSw+e7R75IkzNR+SqaPvLKjLZPFQ678H4Ewtt1E5JRU2dthLb8/AOB39gnXP6bwy9IxI35FFgmgaT0hjg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1659913437; bh=mGEBgVZ/OPKapfrNjMII7zdpFcOF/HmdIzOrzupIRTl=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=AXf+lZNSCDBA6EXai02C34IG+quUIia1DKeOAFhsXOqMAjAl9cl0RA3/4N9a+9hEitRf724+kg+O5ikv8tzwF43LVzsVtrS8Oaz8OEL4hz+CPUWUvkjMHpsILd4Pb4FDQi029RCpQJqWaYszQEGXBQjLB+d1ZA1X6Yq5dOX2BNoLuCIRiz5k+aoakjYSUjECqsWd9tL3uAzKXDq6nWl7AitX+3VIiigg9TbvCfGG2rajnNzoulmZZSHdn2MQCP8W12uCOaTa91FCF8W5oBWYbzqisKaKRsGLLaq82vCopCe+s5A4IW8cx0+0LImKzMsTO9LyDmnOWUiMoGfzQo4NvQ== X-YMail-OSG: ZIpxIQAVM1na12q90iqZCaYnjjZ2fmpdzJNAeEoCNwK.cfKVujDtB1Ky9EOUIc9 5TUVjY2PmCi4ARkuH05A2P6g1i5j1yCwEMxjQDQqF0DTR3RWqy8wbQPKHjV4LvXCF1KbUBLm3AUT WCtfzH_x.IvAWJ4AkniGfKGShD58gOdXHicCFfyEawEBdxkYOb5iDk933fr5_VaJlN0J9grVFqdv vGc0vaNYr.uwzbRCwG1ccVVjlWUfwx1w8RFvHHMWBqZtp9pj2c7MNYhHVYLLg9LbeWlJuvo4nHA7 ZOHAlNedrNyg7B5_qweP59OosOXATaXfUo.11aZqJfkfV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L4XhjCWg5GHU0HyFzzgPDq8vAOmBy.6GLNFT.xf2gjbbi82c7w_G9p4hvinuEWix_YAwm9Q 43rC7RaP75q1TFgddBbcUkZB6AGoRPb_siVFPYC7atEGLoK20uMEE_lHQxFwTzeEchFJhKTrxruz QZdi0aws7zOKP5gNdO81AMdA4f5.etTVjKRKcg.KPZhhCDhSWSrOuRTt_WyFgJvnynLSH3yADG8R _gTJ9RWVL1iHRZVBHPizzzM6kAU5gWkhyUfy74F47YcuYR3N1gfMQYsWgtTwuTOtzBn3Ulr5jQf2 TdnOPNICHzU3leVensqgBfzM0LcYpRz4eLS87gU4a1xy2JgaGGIU1oH6LKkMvMhYuMn9xN2YQl5c UJnUn8Jt5PEeq3pjRTJnkCKiSMemL3z5vMw_PbHfrWHcFlF3xF5B.WPHynaayvLUuQqwrjy4Yyg6 r9xYBqL91NuBWF2Z1RN_J.iv_uTIg4rN2jhWPs9VP0Aqr.GNMyvwtWgFdI_Uv.v88FNLZQcfpSYf g2PWkk7L1gyv0_XsHH3B0pUd1Zbl8ULn3RcfJQDXT8H9puPYq1.tiu4NETXt0yZyS33guGt0AnyZ jRpsjSrHG1Olq8240NSQ.ZCb7_vhxMPc2K6VMOu2kAakUkxJ5AWUz5rcTn3d78KU_SeS6jnn1iFf W5OZMdbpnQXSj8uB5z5JWxrrTp0a228OjpQ0p8KnlxV99PoBo5I001NRA.witTHfGAd5gpDodghy M.1TXwpu9Qba_8nj1u7VG2ZlnUhoxL0STaydE56QNMybD7oRnoqIrejMLNY5kx.oaN_PD8tiTQgL YIqb6fdh31MjroJYIGqivdGct5cg5ZhL9XEeI8C0dBjTpRen3j1XhcwUm3K4CteaPbiXkebdR3k1 8ApRipS_jubECas7HOpycjg-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic312.consmr.mail.ir2.yahoo.com with HTTP; Sun, 7 Aug 2022 23:03:57 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-r76pr (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 12b0bfa600682cb6edf92800aaf76d46; Sun, 07 Aug 2022 23:03:55 +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 v5 06/14] iio: magnetometer: yas530: Rename functions and registers Date: Mon, 8 Aug 2022 01:02: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 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 Reviewed-by: Andy Shevchenko --- drivers/iio/magnetometer/yamaha-yas530.c | 126 +++++++++++++---------- 1 file changed, 70 insertions(+), 56 deletions(-) diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index 839baeca673a..b27cc2b432ee 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,15 +184,17 @@ 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 * @y1: the y1 axis measurement * @y2: the y2 axis measurement * @return: 0 on success or error code + * + * Used by YAS530, YAS532 and YAS533 */ -static int yas5xx_measure(struct yas5xx *yas5xx, u16 *t, u16 *x, u16 *y1, u16 *y2) +static int yas530_measure(struct yas5xx *yas5xx, u16 *t, u16 *x, u16 *y1, u16 *y2) { unsigned int busy; u8 data[8]; @@ -198,7 +202,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 +268,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,15 +311,17 @@ 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 * @yo: Y axis out * @zo: Z axis out * @return: 0 on success or error code + * + * Used by YAS530, YAS532 and YAS533 */ -static int yas5xx_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, s32 *zo) +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 +330,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) { @@ -446,7 +453,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 = yas530_get_measure(yas5xx, &t, &x, &y, &z); pm_runtime_mark_last_busy(yas5xx->dev); pm_runtime_put_autosuspend(yas5xx->dev); if (ret) @@ -505,7 +512,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 = yas530_get_measure(yas5xx, &t, &x, &y, &z); pm_runtime_mark_last_busy(yas5xx->dev); pm_runtime_put_autosuspend(yas5xx->dev); if (ret) { @@ -591,8 +598,8 @@ 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 || + return reg == YAS530_ACTUATE_INIT_COIL || + reg == YAS530_MEASURE || (reg >= YAS5XX_MEASURE_DATA && reg < YAS5XX_MEASURE_DATA + 8); } @@ -605,11 +612,13 @@ 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 + * + * Used by YAS530, YAS532 and YAS533 */ -static void yas53x_extract_calibration(u8 *data, struct yas5xx_calibration *c) +static void yas530_extract_calibration(u8 *data, struct yas5xx_calibration *c) { u64 val = get_unaligned_be64(data); @@ -647,12 +656,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 +673,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 +704,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 +727,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 +750,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 +774,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 +798,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 +808,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 +842,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 +870,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 +973,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; @@ -1062,7 +1076,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 = yas530_power_on(yas5xx); if (ret) { dev_err(dev, "cannot power on\n"); goto out_reset; From patchwork Sun Aug 7 23:06:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12938405 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 58E35C25B0C for ; Sun, 7 Aug 2022 23:07:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233233AbiHGXHc (ORCPT ); Sun, 7 Aug 2022 19:07:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229747AbiHGXHb (ORCPT ); Sun, 7 Aug 2022 19:07:31 -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 C513438AE for ; Sun, 7 Aug 2022 16:07:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1659913649; bh=8Fz3yYl1tXTkqaM9AF5KjSfyN7X7bxpP77X26Ox/V18=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=c2awqPB3lVcu1p1js3eYdX1sIU/mAcIjmBpuP+ajRlR8+YBD0xugj3RKvrgZ3mHYEvvQM+2vMXiZzmWlEPKSpLC1AY0Y4rSn3vTYG/bv7CGl9w+KmzuDmYkxQ4Ko4Y9ctxapZRXFKiQmALnPli/QinMJbWeyWaSd5Vfm1nh0TJqnc6iEVEtj9kss0gUEoPEga1npNR1x6YDHxcF/eRInI62yEbgPDbSCD/pdkKoBY7aZ3BtzcvUNkcPXG4amUoj/0crN0ehGMB4iHEOok+kA/eNZ693qKBzaQx2y0bzC1zuZUp823++BcAfIm+4i31S+0qcSTLTB/xUSWsASvvhzdg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1659913649; bh=eaIXbSnmtkld5YpzK3JxExnpNWrrqkz3QTnqpcqOLxV=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=FzxI1ICXIcO6p04JEJ5f8aHHE2cQoHPpvAQW2SNJAO0jhmW9hY+0RwjVAe31Z18XPoXJNQ2jLSWIec9OPiuNfm5cmnYBPK73hu3w1RDnaOF1TJYKQ6ETF9A23ZWt5CVW09EUksH9+BnKoRQmGYPj9965f6QN7NyXW1UfJLMN3WUM4/AOVZU4w2avlwdEAavoMwa7nfXpaq8SbOD2ifqKOQ0pIejDjhxtdcw+AC0z6YUGDHMYlwU/wFrbT9VEkrPO/iQmuE49l+rNfMLsfelhDVnsfl8h5xQmFcBhoJoZ8U0Pe4XTMtg2cO+5vn1KFLoewQDHAqL4G9gmfyEowYbWaA== X-YMail-OSG: Iem5lw8VM1nQZ6xhHtEYNYPqz0uhdlL7rn2x9SPv3RvMH9rTATGXIshVJJusODi 5ByUr66AaJjV3H.fzNjsP5irWm.J2XVbf7.xtmRv1ezMZVxL_LFXxROAAkWfNQoxRL7JiCUrm.H2 Kan_jGopDMid4yKTat8B2h4jumVtt4SpgbM35vQXV.iWucbyV2RDEGcOz69ezoAyY.hl5TxF3h3F yqciXDuibcPSXc22yqUGuBIyqkqKf_Rs3uwNzElds5.q0HGkv7DV9ovDyY7ldG5CB.Q_JPIryD_G Rc3GoVWr4EsC6SvLiOwbjYGuqZit48PH6IO4DrzUo6cZSMkutWlChlA2sDlEPv7guWxCvLB5.IEa tNVHUSSQa_PSqF9f41a248lxB93BirpEGUXvh3UUqBwmIGQbSV9afIzwc35iJ86Se0F8J.Tbt6.P Fr7OWmRrOF5xJtR_GokTNS8H7a4qo1wp2c89MRQvE5j98U_aTq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ml1PMTsPIvnTqp8gQ5WaYtgFoL8Wzzw Nu.BReTXnKvmTd9pL8D4BsDsDlWnsTgH9Hy2RYR2gOwQkE1fOlSZB5K7OJ7TZ5HjcxktkIEjNhzc bGVYeLCBshThiD74Q_bvJsqFD_v44iN6ivhrWbn0n_vchxv8H72Z7gXK.U5weVnlEdHHX8TOx8l1 Pt5sP.rki7_0NCNsT._.Qgnm1YR3hhBFifpxkP8jdRu2ER_.dFfhxpE.DRfYplHdkM5IX0EzmZzT 7ow6V4DisnJMjHj6Yv3XhYH1MawnL0L9fQji5rB8SqFCz8Bq.Ni9LChTiYM6VtPhx_XaB6qZc1c7 v0hHU9towOvM5cvw8UNLU_87P2is1z19S_g4zUh_kkMlFich0wbG759lLhRWKse_Z8a6ma3BH6oQ Vt.ycvTdCbu9Jvy0W936Ijy93GNjNIuikIZY9Z4JoDP1cIlItnBp07FkLO6_Ti7Wn5nMe.rLq_mw nYkKaenGPPw6oSPUvjpsxsUFRfOd8B3a4GAZUyQdG7yiWJozjvehBF8IlY7MxWV5xil5AS_fuMwu OVLAfQ4Pr5at.INSzrJM.k2dP0CXnNPt4roVk41TLjjNWKFqXaRRSqN3ZzfdgKEIyzC.VHX6Iymg qpYvnt.BwG1aifqbR73pzGUJaHp_5hqFgVHVeT7F1NrtVMIL12C3beNIWkgdzh87ezrdDDVFJ.lP SOxCL5eNFJT0FNuFLrE2FdxR_pu3OLzJy_a156xBGv746s7YAgR6Qh1cZdApM58IL3ieZ7QU6wlr DLelhkpMGWk6QfndVbXM- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ir2.yahoo.com with HTTP; Sun, 7 Aug 2022 23:07:29 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-2vqg6 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID dc92a55cf24372a35650a28a19dee6ae; Sun, 07 Aug 2022 23:07:24 +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 v5 07/14] iio: magnetometer: yas530: Move printk %*ph parameters out from stack Date: Mon, 8 Aug 2022 01:06:46 +0200 Message-Id: <0f80659d4a5865a267cf75eaf14a23b8319ddb92.1659909060.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 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 Suggested-by: Andy Shevchenko Reviewed-by: Andy Shevchenko --- 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 b27cc2b432ee..48995176fa39 100644 --- a/drivers/iio/magnetometer/yamaha-yas530.c +++ b/drivers/iio/magnetometer/yamaha-yas530.c @@ -664,7 +664,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); @@ -711,7 +711,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 Aug 7 23:06:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12938406 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 D09CCC3F6B0 for ; Sun, 7 Aug 2022 23:07:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234382AbiHGXHi (ORCPT ); Sun, 7 Aug 2022 19:07:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233481AbiHGXHh (ORCPT ); Sun, 7 Aug 2022 19:07:37 -0400 Received: from sonic308-19.consmr.mail.ir2.yahoo.com (sonic308-19.consmr.mail.ir2.yahoo.com [77.238.178.147]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B380538AE for ; Sun, 7 Aug 2022 16:07:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1659913654; bh=rYmtJgOdAlGhRoNXlxz5JKGNwmCEyFeKqqyMbfjetF8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=WyNrx+YEhjS7nCiOqsJz8PghheM/im8DnEo5okghCbIHkNUkaE8tpwmJexhGpea/PH7mgCjkInKBlVtyxg/KWVdkj1rIUxqLGkZvoXEE1chp+Q7mO6Jhit/9PWnuhcDqYSnCPxWSZk3j9Sjw4yLSEw84ADy1NFEF2BeRXXdje0iRDmrLT6dn/dcqkAkKTBumL5s4uYWt4wpw/5XqLzuWe8ah651bKUKm0gYy1BJuhP76/xmq6yqdGrxcdHfcgA6aOEDR7WrYBGibtkgeHTSerKNSD5jcUI9WMSU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rAlOYaN3c7_AY3qMiwQdGVJ733bLK32lK8rsaPQRuVDfjRxDyfwzVuhM9Unm HLsQFsXj1vlOi20r7mlwNefFIxKGagnFZuD.eri6F8TXtsXpSdtwT3VtJUEvIZ8tqXuieoTsNGtq Z9FyRjNvpXdkARC13bKphZaT2OByLQWOIu3VOM5wwNBwDSSm2x6zdfUikZR5B5SbyfQ_vKwa.gzf _MlKZKIhOGyO8T0VoUQ.O_iCZmOEvzojglXlEMaYZet2WgeGgEocm2zjVFlbo09FqF_FdXpi3hle A.DXmpZn55Z5K3dgtFG97tM3cwqnf0bPFE0X1ah8SAF0hqziiCCP5I0byrgrDvoVheRlU8lMuc.w ebgIKtseXH3jF6ifDUwvVHvJQzzLJTvlnI4HZ0GMtBfNYF6Cs3Q8.otusl_Xy0FUW2Sjy.niNTuo Bfr4KyTWBV8JFrUWMVJ0LbEDANlyfY86npVoP5VPWeANZZ.DUCbT6lm4EKjkMp3NEaeCiS1YSKTt vpgjUbfmf9.AqUy9.RiK6MCbA4gAYomucfTxrz2J_Jrk_HNxf2POiDEPVRKRIWstx3aKTHu7_ITN e9cVCIJ_5RXC2P5wHvtO6Tm3GGoBADrTwMM30R_Y1PRPkxQEwql9cZW_UhNLvWELusb97L5I28U_ 7U0DwwPnNoBN4XNZ2I6nswZbqdOWu9faN8e1qvaf1m8spV_YNPqdVG79OevOX7nVJL9jimEM.iT6 fviOYUzo89rxhpb4- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic308.consmr.mail.ir2.yahoo.com with HTTP; Sun, 7 Aug 2022 23:07:34 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-2vqg6 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID dc92a55cf24372a35650a28a19dee6ae; Sun, 07 Aug 2022 23:07:28 +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 v5 08/14] iio: magnetometer: yas530: Apply documentation and style fixes Date: Mon, 8 Aug 2022 01:06:47 +0200 Message-Id: <5a00a21e9414ad00117b67064eb585f589abfee1.1659909060.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 48995176fa39..bf0aa64ac1a2 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 @@ -325,7 +321,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; @@ -666,7 +662,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 */ @@ -693,6 +692,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; } @@ -714,12 +714,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); @@ -728,6 +728,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 Aug 7 23:06:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12938407 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 52C60C25B0F for ; Sun, 7 Aug 2022 23:07:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232816AbiHGXHk (ORCPT ); Sun, 7 Aug 2022 19:07:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233706AbiHGXHi (ORCPT ); Sun, 7 Aug 2022 19:07:38 -0400 Received: from sonic308-19.consmr.mail.ir2.yahoo.com (sonic308-19.consmr.mail.ir2.yahoo.com [77.238.178.147]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0F66558B for ; Sun, 7 Aug 2022 16:07:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1659913654; bh=CfOunXujCoN/8Uh5lR6rRFFlbyWsLrhKulkfgGP1eFc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=GKPhWw3T23SA6XDGPcWFswBsAqk2TsHNPmcGWwPvBRWswTqjXBe+TaEcdPqt5gIs2CPA6I+iILRmrA3XjPk/PRB5QxgyUAbJOBKp89whZ4yX08MPjScB6IxfeHIGRdX0dblRzXn7rLzm1qti6da3SkITchNlWNGOuEzgEp6+n6vQcloo2c2HFtkACtThiGutX3arjLm0N83M+6bACNCCYFhNWMyZSmvgQkowqQCTMOo+HUyTkRDzR5JT6xJl+ETLGjf5sylgb63JG7C7/O+TcnK9MDHVWMPr8cThMjt2aSo0gInX/pc/0EjkqnaGEQC6/9nXxuI1hPo3o8DqjdqrxQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1659913654; bh=Ll+xCr+Ozm0u7kdN8rzg4L5fezoAjHMBkHVYdfeiBRN=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=qUiTbbtPUUC62BYQoAcbJymajmVcD77UiOuTxfKgEvP7N52tGchASisejXF2cO7+1BfPaRWfOcwHlIrE61BO4ZDcUGolzAcMzymVd2rca6W1tFR9W7LF/duuu899T3Hc8bXPewJFWzFpihheF1+VPjZYowl8f+3mGVZJSpkhRKux+75DR+lG9fPYhDWzge55pZO69Pc+dDn5ptuEQKzD6eh7riAc3EAP5KF/WcCbnTvH/ABD2iVosti7rObRdH3JpT9KEj99XjA8UQgqH54lpR//Had/1EoOPFZvuir59P++KZQwTODz1fAg+Pu0CyTE1Lior1+v+azx/pXI+KJzrA== X-YMail-OSG: Sda1YSYVM1nbwDjoK6aVYi0UfInd_cyfvgRvCtpu_6qfSjl6PhdJfueo69RurEK 5M5glmcO3kldVJ3Iqa64AGmR2zgq5RbtrJzGfr.0Ry9LU0KnXRmCt5CKdYCvLIAB5_i406vjj9Rf J.NG1gnD_EhPuRGJccJ7f4f4SZeSzOj6KJi9sq9UZV7Qd16cZpxcp8.pqudjfXmXcyW66Q_V7QLg Z4I68KZ9Z9oGKWF2Gc9mtoq_xrYr7A1PTm.I7EUZPez0hJdDXBncqTGIV9C5u1Kop.5e49apen2d 4TSSaBMyUfD5.qgmoPof._pGMv7ZFLvR6J9zmKEJ.zFwk5e_Ymk1Du1E5WztWRfuCRKHfFHBqOzl cCkSkezHxSXiJaiaob5YAfe7_8gaeko0lKvjESRoMrUkOC2pcFnE0oI99EBfHmsuA64KI6ppZQFX HrLbhLd0GJsZm5cKwcujW05_0JqICvnhVjAEKq1M4lXu49FJB3yT49MEAwFiP5MM.PtnfQCF08DQ VN0dB3wY4SMwlOn0v95EOUIq3T5UshWt_th_zxj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CM1NclaJ8UxaQz33_sd8ud WPhL8lYiFKvSUhtiyqrW3v5OpWSIvlh7K7XaAKAg7L2Mw7tmI0OveIp8JDLS5JyROZS55DVFFhlw rGV7fl6tk1EEjc8W_K4GmVH_4xX1c7OZcGfEhRicacXkZHh1ou2dqSBSrku4eWxgHwbORDCYd.G2 uY_FlzcPDbbaU2IdhCZphlnGxS3vio7eHw9bT2oaadngPLMlvnVIqsZXyXFcucV5pCao6Y0Kd39Z Q8TJYCc9282DIFsKM0gIEV4h.jo6rtx9wPf4xMXMD_mEkPHQhS6XqnxaOJTOGXTFa0arwB8GOeJ1 1iiJh7ec5TYdtYpYhRttSdnZAOXSEh.rbmKlVf38b4uE6POCUfo1cGce9wht3fj3oN3GPr01uUQc GhqZoZyfBGf6Zeu6Z61xDVE9KtJsIcmc2WOLE8RBj3_vLXgkiNNYpeB9TiD8PQr9Yyao3ONRYJiP 1.C5RvbnFDRLiSgT0c8bNLSnciPhVHCBfR9ZPCjLwiTO8GRr.Fk4qMhpHxDfhoNfKimdDYCLnTj9 zsd4xycUATwlTwGy8E9Qly.njJ1ACPaGw.T0l2FAWDZ64ZcK_knVIf6nYFvv_39hw4wXJTYAY.lW e.XUaJZYGyRs6E4rnOHz0wveL2CeXTLbFgFXN473QMf2jZ6EvciAjYR0K7i.NhgC_thyFIEy0AuF u3q90X.D9Y.u9ekc- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic308.consmr.mail.ir2.yahoo.com with HTTP; Sun, 7 Aug 2022 23:07:34 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-2vqg6 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID dc92a55cf24372a35650a28a19dee6ae; Sun, 07 Aug 2022 23:07:31 +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 v5 09/14] iio: magnetometer: yas530: Introduce "chip_info" structure Date: Mon, 8 Aug 2022 01:06:48 +0200 Message-Id: <8f5f58c9bf0f4006fabd01b5564af071d20f2a2d.1659909060.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 Device Tree (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 Reported-by: kernel test robot --- drivers/iio/magnetometer/yamaha-yas530.c | 107 ++++++++++++++++++----- 1 file changed, 83 insertions(+), 24 deletions(-) diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index bf0aa64ac1a2..ecc2b61a5c4f 100644 --- a/drivers/iio/magnetometer/yamaha-yas530.c +++ b/drivers/iio/magnetometer/yamaha-yas530.c @@ -96,6 +96,24 @@ /* 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 * const yas5xx_product_name[] = { + "YAS530 MS-3E", + "YAS532 MS-3R", + "YAS533 MS-3F", +}; + +static const char * const yas5xx_version_names[][2] = { + [yas530] = { "A", "B" }, + [yas532] = { "AB", "AC" }, + [yas533] = { "AB", "AC" }, +}; + struct yas5xx_calibration { /* Linearization calibration x, y1, y2 */ s32 r[3]; @@ -110,12 +128,26 @@ struct yas5xx_calibration { u8 dck; }; +struct yas5xx; + +/** + * struct yas5xx_chip_info - device-specific data and function pointers + * @devid: device ID number + * @product_name: product name of the YAS variant + * @version_name: version letter or naming + */ +struct yas5xx_chip_info { + unsigned int devid; + const char *product_name; + const char * const *version_name; +}; + /** * 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 * @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 +161,9 @@ struct yas5xx_calibration { */ struct yas5xx { struct device *dev; - unsigned int devid; + enum chip_ids chip; + const 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; @@ -222,7 +254,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 @@ -276,7 +308,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; @@ -336,7 +368,7 @@ static int yas530_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, sy2 = yas530_linearize(yas5xx, y2, 2); /* Set the temperature reference value (unit: counts) */ - switch (yas5xx->devid) { + switch (yas5xx->chip_info->devid) { case YAS530_DEVICE_ID: t_ref = YAS530_20DEGREES; break; @@ -349,7 +381,7 @@ static int yas530_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, } /* Temperature compensation for x, y1, y2 respectively */ - if (yas5xx->devid == YAS532_DEVICE_ID && + if (yas5xx->chip_info->devid == YAS532_DEVICE_ID && yas5xx->version == YAS532_VERSION_AC) { /* * YAS532 version AC uses the temperature deviation as a @@ -384,7 +416,7 @@ static int yas530_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, sz = -sy1 - sy2; /* Process temperature readout */ - switch (yas5xx->devid) { + switch (yas5xx->chip_info->devid) { case YAS530_DEVICE_ID: /* * Raw temperature value t is the number of counts starting @@ -473,7 +505,7 @@ static int yas5xx_read_raw(struct iio_dev *indio_dev, } return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: - switch (yas5xx->devid) { + switch (yas5xx->chip_info->devid) { case YAS530_DEVICE_ID: /* * Raw values of YAS530 are in picotesla. Divide by @@ -814,7 +846,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; @@ -895,12 +927,31 @@ static int yas530_power_on(struct yas5xx *yas5xx) return regmap_write(yas5xx->map, YAS530_MEASURE_INTERVAL, 0); } +static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { + [yas530] = { + .devid = YAS530_DEVICE_ID, + .product_name = yas5xx_product_name[yas530], + .version_name = yas5xx_version_names[yas530], + }, + [yas532] = { + .devid = YAS532_DEVICE_ID, + .product_name = yas5xx_product_name[yas532], + .version_name = yas5xx_version_names[yas532], + }, + [yas533] = { + .devid = YAS532_DEVICE_ID, + .product_name = yas5xx_product_name[yas533], + .version_name = yas5xx_version_names[yas533], + }, +}; + 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 id_check; int ret; indio_dev = devm_iio_device_alloc(dev, sizeof(*yas5xx)); @@ -947,33 +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) { + if (id_check != yas5xx->chip_info->devid) { + ret = dev_err_probe(dev, -ENODEV, + "device ID %02x doesn't match %s\n", + id_check, id->name); + goto assert_reset; + } + + switch (yas5xx->chip_info->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: ret = -ENODEV; - dev_err(dev, "unhandled device ID %02x\n", yas5xx->devid); + dev_err(dev, "unhandled device ID %02x\n", + yas5xx->chip_info->devid); goto assert_reset; } + dev_info(dev, "detected %s %s\n", yas5xx->chip_info->product_name, + yas5xx->chip_info->version_name[yas5xx->version]); + yas530_dump_calibration(yas5xx); ret = yas530_power_on(yas5xx); if (ret) @@ -985,7 +1044,7 @@ static int yas5xx_probe(struct i2c_client *i2c, 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); @@ -1100,9 +1159,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 Aug 7 23:06:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12938408 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 735A1C19F2A for ; Sun, 7 Aug 2022 23:07:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233794AbiHGXHm (ORCPT ); Sun, 7 Aug 2022 19:07:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233517AbiHGXHi (ORCPT ); Sun, 7 Aug 2022 19:07:38 -0400 Received: from sonic311-32.consmr.mail.ir2.yahoo.com (sonic311-32.consmr.mail.ir2.yahoo.com [77.238.176.164]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD7672DF3 for ; Sun, 7 Aug 2022 16:07:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1659913655; bh=Opg3ThBOVGGnk1ZxUbIiwtDZRXpPBEgLU8xaQT4yBRQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=Mc6LjdlL6W2ZHQa3v560uX66WFIlInXmVnIuJ5hdl5okmDwWf7cru+zbCgqpxKCm7XsIFJpap3l16ZbQ3l+rZ/uzmB1ues3JbAY0JB0RBPHQxDcKGtuujZmsnolEsWcklPuoq3CiyKPQOF3xYjHK+XbWdXlbrT525J9AcUnr5Rj/m/c2yaGO4qOIscaLWuYz82o3Zv4epsiWN4sMx8H+JrxptweNh4tUt7nbVeprEjxK98HHoJ9yBRuI/dtOR8WNjc18t/deUyg0pS/RcucvYsVxGBmP9QvpDHPsCErG0aVU90349eb1158oOyBiziOaYUbo/DByuiBrgLhcpYRvnQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1659913655; bh=7UQfk7K66c7nWn29A8/87YBxGS+pHxn5N3JiGADxCn/=; h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o2GEv4PBJNb1zhXO.ujVvr9Fv8lidAV3RJ77rgbBn7PQIoEJR5.LY44vzowC8 HFmLdAAAD06l1DzC82RozPaVw4PV28N0oBZsQGNBzTR2L9H0B8cxR47T99bITz2QCgUhtf4h9dzr lDWyHrwpY2sbqGiHSpZ2zgGXQPtyhXFGRGSdklrP8KqVwH6AOkdDCKrlDkxh4EPst3wxlvZ4WH1U Bn8rOk4UjosXAKteeLaFGkUEdJn3caGmjcxVYVntAdcPDRlu_O5PznUxY2VG29A3sAE96tEvA2Ge XiXHfpAASj2khunTZKhnvkyuu1iCVDfF5MXU0VJe9VgpbFVuu8FxslBOZwizxzyet9umO.LyrV4J HKg.uScfKGLHqOVOGc9qLM3ji9NXBcTB8xDOy0yahCDKpRhq7Tlh6zEvvRgBwUYYG20T6oJ70u20 STUBZORaXKjAzgE2Ma7jsMSLilGJlUrq6YZ5FvZUARJNxm38WVpdwcB5MRqsP24_IgczpNqjl3ta t3svcYsXvUe4uE4nQ29tveZqc0tp8Fm_As8Ti8Sqdc6Ibve9CO9da2J5IV9L6_0VaLKYscw_ytS0 NDix2hH2vxbmGrJo- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.ir2.yahoo.com with HTTP; Sun, 7 Aug 2022 23:07:35 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-2vqg6 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID dc92a55cf24372a35650a28a19dee6ae; Sun, 07 Aug 2022 23:07:33 +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 v5 10/14] iio: magnetometer: yas530: Add volatile registers to "chip_info" Date: Mon, 8 Aug 2022 01:06:49 +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 Add volatile registers to the "chip_info" structure to ease the handling of different YAS variants. Signed-off-by: Jakob Hauser Reviewed-by: Andy Shevchenko --- drivers/iio/magnetometer/yamaha-yas530.c | 37 ++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index ecc2b61a5c4f..914f7f0a243e 100644 --- a/drivers/iio/magnetometer/yamaha-yas530.c +++ b/drivers/iio/magnetometer/yamaha-yas530.c @@ -114,6 +114,11 @@ static const char * const yas5xx_version_names[][2] = { [yas533] = { "AB", "AC" }, }; +static const int yas530_volatile_reg[] = { + YAS530_ACTUATE_INIT_COIL, + YAS530_MEASURE, +}; + struct yas5xx_calibration { /* Linearization calibration x, y1, y2 */ s32 r[3]; @@ -135,11 +140,15 @@ struct yas5xx; * @devid: device ID number * @product_name: product name of the YAS variant * @version_name: version letter or naming + * @volatile_reg: device-specific volatile registers + * @volatile_reg_qty: quantity of device-specific volatile registers */ struct yas5xx_chip_info { unsigned int devid; const char *product_name; const char * const *version_name; + const int *volatile_reg; + int volatile_reg_qty; }; /** @@ -626,9 +635,25 @@ static const struct iio_info yas5xx_info = { static bool yas5xx_volatile_reg(struct device *dev, unsigned int reg) { - return reg == YAS530_ACTUATE_INIT_COIL || - reg == YAS530_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 reg_qty; + int i; + + if (reg >= YAS5XX_MEASURE_DATA && reg < YAS5XX_MEASURE_DATA + 8) + return true; + + /* + * YAS versions share different registers on the same address, + * need to differentiate. + */ + reg_qty = yas5xx->chip_info->volatile_reg_qty; + for (i = 0; i < reg_qty; 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 */ @@ -932,16 +957,22 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { .devid = YAS530_DEVICE_ID, .product_name = yas5xx_product_name[yas530], .version_name = yas5xx_version_names[yas530], + .volatile_reg = yas530_volatile_reg, + .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), }, [yas532] = { .devid = YAS532_DEVICE_ID, .product_name = yas5xx_product_name[yas532], .version_name = yas5xx_version_names[yas532], + .volatile_reg = yas530_volatile_reg, + .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), }, [yas533] = { .devid = YAS532_DEVICE_ID, .product_name = yas5xx_product_name[yas533], .version_name = yas5xx_version_names[yas533], + .volatile_reg = yas530_volatile_reg, + .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), }, }; From patchwork Sun Aug 7 23:06:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12938409 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 4D4C7C25B06 for ; Sun, 7 Aug 2022 23:07:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234585AbiHGXHo (ORCPT ); Sun, 7 Aug 2022 19:07:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230376AbiHGXHn (ORCPT ); Sun, 7 Aug 2022 19:07:43 -0400 Received: from sonic307-7.consmr.mail.ir2.yahoo.com (sonic307-7.consmr.mail.ir2.yahoo.com [87.248.110.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4791338B2 for ; Sun, 7 Aug 2022 16:07:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1659913660; bh=aLBvqvlMffaphGatiwiH6+pKyFPvdxoXclSc3Df1NaY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=juifEGL53PssbMiauLN61yoQiz9A70TKlvnBuyhbdQ+M9dHA/zTUjwejrYlWcFZ8rdhrq03ri/ZB5xNSQUix7lQyVJnRlTLO6Op2Gk/BfwasxhwCr92O+XggI5T6PPpj9OsnIYaKVIEpz/9V/AflImlzZmWvaJByx/dSjns4mr2ZIuuZDn+ojEdiwgjF6YrE5w13kf/EBXrJQIhaUGg/n93Fwx2I8p6vh3KCuPjqvqqJe5y/K5Z3dFX0SGeRZAfwoFh77rGHtY20Y5hwS5Zna+XJu76hD8P+ZuQkDMLGgHAozl2YOiEUmTAoQ4LPrNRzsWidRQqnfz+5vPlX8zG/CQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1659913660; bh=OkHEtKKqK24JcXIavsLVFvhPNKEUl1HZmzXTGXcHOoR=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=YrrOaC0yDDT06mzu1dtopPfE0vvV61InhYOskbPWyW57MdetSwqsl6AihbWWrxRhznLGSZLrigf6E4cw9WTZBJ56ds4tggz+8vW2FdsbcPn2TL3sn/onj+FIczQOETknGVuo69xB9t+q+WntCEJxAd6gIKIvFpid39gmRrmeEguHXTuAYFnDn1WDZoKFQC2QMKpr1rRYIXiIEYVsn0i164gu483iQ7iPcXgHOorYXcbFBhc8MA203EWojDXK6bNKGFtqlI7m7KT8pmNOv4muk34scMW8up6uZMe55/SbfQDhW1rtbBqH29trodLr514SwQE2+L2ZvAwz8AQtUm2ZXw== X-YMail-OSG: Mc.6A9IVM1lzG8t3S1Gp3iyo22bHFSyzJ.ASmWPyDbsm4Hd6SDpLjx_sCF8wDP. 9lp7u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vhvw0RI6q4bQrwlGFOG.vQjQjrtzYXMw.t5jztqGbrrL0unbJbOel33Y_ YsGZqQwsrtJe5M5h0IoqavZI6s3NI7.B.fzWxyq9iTA2c7cKTp_CWO4cpV7gVfv0qbiZQmExnKII N_93TxacelwjP0wg- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic307.consmr.mail.ir2.yahoo.com with HTTP; Sun, 7 Aug 2022 23:07:40 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-2vqg6 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID dc92a55cf24372a35650a28a19dee6ae; Sun, 07 Aug 2022 23:07:35 +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 v5 11/14] iio: magnetometer: yas530: Add IIO scaling to "chip_info" Date: Mon, 8 Aug 2022 01:06:50 +0200 Message-Id: <1e1555dd2aee1636f4657899c20a9a92b4fe2d80.1659909060.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 Add IIO scaling to the "chip_info" structure to ease the handling to different YAS variants. Signed-off-by: Jakob Hauser Reviewed-by: Andy Shevchenko --- drivers/iio/magnetometer/yamaha-yas530.c | 28 ++++++------------------ 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index 914f7f0a243e..262a36c31616 100644 --- a/drivers/iio/magnetometer/yamaha-yas530.c +++ b/drivers/iio/magnetometer/yamaha-yas530.c @@ -142,6 +142,7 @@ struct yas5xx; * @version_name: version letter or naming * @volatile_reg: device-specific volatile registers * @volatile_reg_qty: quantity of device-specific volatile registers + * @scaling_val2: scaling value for IIO_CHAN_INFO_SCALE */ struct yas5xx_chip_info { unsigned int devid; @@ -149,6 +150,7 @@ struct yas5xx_chip_info { const char * const *version_name; const int *volatile_reg; int volatile_reg_qty; + u32 scaling_val2; }; /** @@ -514,27 +516,8 @@ static int yas5xx_read_raw(struct iio_dev *indio_dev, } return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: - switch (yas5xx->chip_info->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 */ @@ -959,6 +942,7 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { .version_name = yas5xx_version_names[yas530], .volatile_reg = yas530_volatile_reg, .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), + .scaling_val2 = 100000000, /* picotesla to Gauss */ }, [yas532] = { .devid = YAS532_DEVICE_ID, @@ -966,6 +950,7 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { .version_name = yas5xx_version_names[yas532], .volatile_reg = yas530_volatile_reg, .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), + .scaling_val2 = 100000, /* nanotesla to Gauss */ }, [yas533] = { .devid = YAS532_DEVICE_ID, @@ -973,6 +958,7 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { .version_name = yas5xx_version_names[yas533], .volatile_reg = yas530_volatile_reg, .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), + .scaling_val2 = 100000, /* nanotesla to Gauss */ }, }; From patchwork Sun Aug 7 23:06:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12938411 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 61FC8C25B0C for ; Sun, 7 Aug 2022 23:07:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234584AbiHGXHs (ORCPT ); Sun, 7 Aug 2022 19:07:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234138AbiHGXHr (ORCPT ); Sun, 7 Aug 2022 19:07:47 -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 CEF205589 for ; Sun, 7 Aug 2022 16:07:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1659913663; bh=/DR18V4fXYp9SrGrQSgOTOc2kOvov5DU33YvM1+CCoo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=CS7MZX8ZDF321tAEMSjizpMqWMOBY2T6dRnN/i6L2cvwTFdyYiB0n0t/ao5PTseLYgQoVlkjgOLpror8qHzAa/+Jv/uQ4y8E4aPgHLKDsQAeisKj97MPkJ3JIY/BxZF0rxu/zNM+57eljXhDT3icqbT7RSODBRp1SOHvhjStWZ3dmvP/oI31HYJpBXkD9XWMnsxCAzca7h70tN7WRPrRYTz4+sYIedVSR2VUzhcEsHU1WoQn9zJ/1KKIHnHoHU22AOcnjqpbY8EUajqsrfEBo6prLrLRAwG8HdaylGuJW3BJnVFADtaL3RQfVUG2SyrqwCNhlnmthCGTD+auvD+YOg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1659913663; bh=m/gwRuMdLvNfoPXJKAwMsQGiueKsxrcIi0vAQ8QLNw4=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=PQcXRGv56fXBLfeH3Iu8pw1j877DRbME8kUYibdsKa1HOsWIw8LFg/Myx0YCPfpdfYERMGQpJ97ljQQP4Y+cnKGEelSTpGjrBjwtypt90Yp55QroPwkwB4CNfWU7t9r+u0oL5+WuktCx3Rc7AOajqXM6KBWS5KelU+y9hNwjgYGIQZnDNrofoL8oRVf1GfBEtaz5yluJNJAm+gNEncAItgh60MufvzdDBVPezmTjtxiUco1kbHr7SM/Hs9lU9OeeaQGqOrNSzyez70WuHJya34ci6ew3yOnBlaewTFFFeNrbxAvbCyj3+Js0ojg+f8ohQGxFPfQbahL0ibkt2+6fLg== X-YMail-OSG: iAMRQFQVM1l0f5.dFLKZZjZdns9OXvqs9.MBksHwYSKyK5F6S2QAcor75.iZAqT JULC6IGZEIZMtia0RyGr9lioWk1nNWWHGZ4gqrkp5k8a3vwm1GTMKC8sHyy6jVwGFhqgXOdlRTd6 mgf8SkCm9F0GkNAjb6o1ubPq3r7W51gpi4f14NEpmyrLkmNAaPRzr2mLXJrguQkJGkujMNl4Dox4 wJmm1bo7m.hHHvz.smmWi.DGgY07yiKKXKGKjjzvDZVJllK6uguYSH5QhyHSQWPIuV7yumb87BZv XuqJKjaTt.qtp8xwt5YbLW4R1awU1PWJAXfNEvvZC7Rejkvvi5pbRMYXrUp0EIyYpPq66IelNugq SYbc_w4e2JOggv2RNYAgbk1u5_3V86QR6.XhgZA7AmOwSfqgxTJMijT5QAdHkJ195Y7_uCEeng6R EmDEYMaBzVaUkTab2KSFV5vohopkpPfXlF3NdVeHJ8qGL7GsoFmtSQLm9HM3zTtynKvCAfI8nRTx sHcl5qJH9f1K0d.WIfzqA9v3.KqDpEFfUFAFtUb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l1C__8GfeoiOwp1E.cw276Ncbl5laySpuxKfJPB7Hop.eQVP6a POWPSzRL1Tz6Keve1ChAigLXvDxB6fzbg325JCBLm.Ylltwr6lxKlsaXBtoyZwGubzUiNx7vh0M5 z3vq8III75WxipRQjNwkLfZIa7ImsWHMblBBHS9HvTGFTORZvqd6a0v9V1L5x2wW2G0818QP__IW Ur7DyEg.PzMIge.9I3vkIE4hBJ25QTrYVuFnqeWD7YmP6ET1dNHsln9an5DqdikpxJ6f4dkx95zK 8I1uDqlUu.JQR5CxLmZA.SU2jtSXTG6bZ50tA7jSCuuOyAuam.z8uYEcc5qfQ3bC5TOIo6tBJ3bE oIxoeLyMo5R05oG1Z.cHcZaXJ__MPiaDlbzcEejc19.y9U6DvKSHGL.nFdu2bcjSaAq7HzD0FWov rGfcM05qici4VYrQaVMbC1noKh8dTUgMBHXe7wZwXKdMbS0ETRkJbDAxPrF0WhiIEukYvMYcALpO v4WrvJIvHaTJUhjiyHYzA5VxHuWzMXo7.W7KqLNOuP5eZfpxyPxYyLwF_jh4d_99GyqsgMVQvulu PUhA6M.A7X6e4fTMeoa62llE06mphdctTbQYS.su9E64nBcBvK9vFUCH.avHyKG3PZxDhDegkHgx kUp63OSJUL8G2dwh9IIgATpqJ0tRkqK6j2njW2hGlV2KigkYHMGwA4xbm2BDOEocy_92zY_sN.So r_ZOyKdVG3khM9pB. X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.ir2.yahoo.com with HTTP; Sun, 7 Aug 2022 23:07:43 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-2vqg6 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID dc92a55cf24372a35650a28a19dee6ae; Sun, 07 Aug 2022 23:07:37 +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 v5 12/14] iio: magnetometer: yas530: Add temperature calculation to "chip_info" Date: Mon, 8 Aug 2022 01:06:51 +0200 Message-Id: <2a93df6f99913e438dd2d394c074cf79544ab692.1659909060.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 Add temperature calculation to the "chip_info" structure to ease the handling of different YAS variants. Signed-off-by: Jakob Hauser Reviewed-by: Andy Shevchenko --- drivers/iio/magnetometer/yamaha-yas530.c | 140 ++++++++++++----------- 1 file changed, 71 insertions(+), 69 deletions(-) diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index 262a36c31616..780c7f4d1eff 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,7 +90,6 @@ #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 @@ -119,6 +117,31 @@ static const int yas530_volatile_reg[] = { YAS530_MEASURE, }; +/* + * t_ref_counts is the number of counts at reference temperature. + * + * The temperature value at YAS magnetometers is a number of counts. The + * values in t_ref_counts[] are the counts at the reference temperature + * of 20 °C. + * + * For YAS532/533, this value is known from the Android driver. For YAS530, + * it was approximately measured. + */ +static const u16 t_ref_counts[] = { 182, 390, 390 }; + +/* + * min_temp_celsius_x10 is the starting point of temperature counting + * in 1/10:s degrees Celsius. + * + * The array min_temp_celsius_x10[] contains the temperatures where the + * temperature value count is 0. The values are in 1/10:s degrees Celsius + * to ease the further temperature calculation. + * + * These temperatures are derived from the temperature resolutions given + * in the data sheets. + */ +static const s16 min_temp_celsius_x10[] = { -620, -500, -500 }; + struct yas5xx_calibration { /* Linearization calibration x, y1, y2 */ s32 r[3]; @@ -143,6 +166,8 @@ struct yas5xx; * @volatile_reg: device-specific volatile registers * @volatile_reg_qty: quantity of device-specific volatile registers * @scaling_val2: scaling value for IIO_CHAN_INFO_SCALE + * @t_ref: number of counts at reference temperature + * @min_temp_x10: starting point of temperature counting in 1/10:s degrees Celsius */ struct yas5xx_chip_info { unsigned int devid; @@ -151,6 +176,8 @@ struct yas5xx_chip_info { const int *volatile_reg; int volatile_reg_qty; u32 scaling_val2; + u16 t_ref; + s16 min_temp_x10; }; /** @@ -349,6 +376,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 = yas5xx->chip_info->t_ref; + min_temp_x10 = yas5xx->chip_info->min_temp_x10; + 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 @@ -363,7 +404,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; @@ -378,47 +419,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->chip_info->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 */ + /* + * 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 = yas5xx->chip_info->t_ref; 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. @@ -426,36 +450,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->chip_info->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: @@ -943,6 +939,8 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { .volatile_reg = yas530_volatile_reg, .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), .scaling_val2 = 100000000, /* picotesla to Gauss */ + .t_ref = t_ref_counts[yas530], + .min_temp_x10 = min_temp_celsius_x10[yas530], }, [yas532] = { .devid = YAS532_DEVICE_ID, @@ -951,6 +949,8 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { .volatile_reg = yas530_volatile_reg, .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), .scaling_val2 = 100000, /* nanotesla to Gauss */ + .t_ref = t_ref_counts[yas532], + .min_temp_x10 = min_temp_celsius_x10[yas532], }, [yas533] = { .devid = YAS532_DEVICE_ID, @@ -959,6 +959,8 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { .volatile_reg = yas530_volatile_reg, .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), .scaling_val2 = 100000, /* nanotesla to Gauss */ + .t_ref = t_ref_counts[yas533], + .min_temp_x10 = min_temp_celsius_x10[yas533], }, }; From patchwork Sun Aug 7 23:06:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12938410 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 171F0C25B0E for ; Sun, 7 Aug 2022 23:07:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234498AbiHGXHr (ORCPT ); Sun, 7 Aug 2022 19:07:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234631AbiHGXHo (ORCPT ); Sun, 7 Aug 2022 19:07:44 -0400 Received: from sonic309-25.consmr.mail.ir2.yahoo.com (sonic309-25.consmr.mail.ir2.yahoo.com [77.238.179.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A913B55A1 for ; Sun, 7 Aug 2022 16:07:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1659913662; bh=s8hMp8JriMdWMFhNLLvIXtmbLU7UlvwcBiIrbiApJJg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=ry03yBWDSNbfLcAUaQIVkfs5q4GU3fjG+Y6yUHTL7d4cCJmeqi8FmujvHaje68VfKz3gtkbXbJclz1a74Qy3coIZEVo3RInqjJuHusaaDvVsUsGolcC2QQy0efIfJabLAZnTnQeIBq91H0P1mey2omP4N6TAfmFVItqlUYa6kv25YJNGoOhLJcwp3veZ810xuvUS/+u5YZWMStRII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KAUgv2tvCVj1uWKi70A5ASUgIMGkIvL4YqzLmVhjB.VuAYqbVceq3yQEQ4bqZhs9Hd5SDJXlPW 0Kwmohx1tm7a1OzE5llz3zt7w_mP5tbnh8Gl_BrXRkOT3RPdAfc6dlJVHD2SdE1G3VbfuY0NtuUB _IHjdjrWYyd9rkDmC2Cw.7LQO.USn63kck5ZnvSosiDJEVkgi_yFcv.jGPSZBHoKK7t05yTRJAaf DTKFrD.6vI90KX_1Dx3MksH4MlK65B1OUWxwX_4fJACjW5CcGve8wpuSwJRt77_0FEXYJVlMc7GS qtL3vMNGwL2suvhQYud9HLNLBVf0cXlWaymcApmH1OncZVDYMAd.I5QjvnnU.ERPKIWAm.tZESxs YuG8joLzmCaPrdtPpcZ9Bdzqty1Bpo0rFV8XIHcIJ.eXaKi3BEpqUdaUoLoEW9sTjO6ZpuVVLlKN RfDADw84oZMoSAEGWfqfRBjUdfGWadpB5K1LJSBDztJ6cp3rh_NataXEenC1NLxLzLMKxHd_oYd1 KP.j2.VPo6jXE8zsNuJ9mtPQIMiCwn5Ffv5Zl.5eezGc37XMdfkWUevdhHEQJ2s582QthpH3j3eL W4nycXhALFLxUgoGMo0WvlmZlfZ7BS5iRSeUA8qEjQnzWEkx2EY97MqBQjzrnZraIThthuFlJMw4 fvDrx6x3pOk2K2g.kK5bNPnkgM14t4QIajn23qGAYX5Mve7_.Rj30uO8Fu69pP9lQI7zEkXkyAvt 1L2UOnDK8NZByqEZT8w40bgDb0mNbphMvNkoORfIuPKZF8QA..lZj6TXpOl9eHRtW2MyHQsIJPO2 ISFvWFgFLDHN.q5oq X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.ir2.yahoo.com with HTTP; Sun, 7 Aug 2022 23:07:42 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-2vqg6 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID dc92a55cf24372a35650a28a19dee6ae; Sun, 07 Aug 2022 23:07:41 +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 v5 13/14] iio: magnetometer: yas530: Add function pointers to "chip_info" Date: Mon, 8 Aug 2022 01:06:52 +0200 Message-Id: <20ad0e793df229e71575c4e7d0bc4f6a5fb49f29.1659909060.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 Add funtion pointers to the "chip_info" structure to ease the handling of different YAS variants. In the function yas5xx_probe(), the function call for "measure_offsets" was added as a conditional "if (yas5xx->chip_info->measure_offsets)". This is a preparatory step for YAS537, as this variant doesn't need an offset measurement. Signed-off-by: Jakob Hauser Reviewed-by: Andy Shevchenko --- drivers/iio/magnetometer/yamaha-yas530.c | 65 +++++++++++++++--------- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index 780c7f4d1eff..62d5f23d8e08 100644 --- a/drivers/iio/magnetometer/yamaha-yas530.c +++ b/drivers/iio/magnetometer/yamaha-yas530.c @@ -168,6 +168,11 @@ struct yas5xx; * @scaling_val2: scaling value for IIO_CHAN_INFO_SCALE * @t_ref: number of counts at reference temperature * @min_temp_x10: starting point of temperature counting in 1/10:s degrees Celsius + * @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; @@ -178,13 +183,18 @@ struct yas5xx_chip_info { u32 scaling_val2; u16 t_ref; s16 min_temp_x10; + 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 * @chip: enumeration of the device variant - * @chip_info: device-specific data + * @chip_info: device-specific data and function pointers * @version: device version * @calibration: calibration settings from the OTP storage * @hard_offsets: offsets for each axis measured with initcoil actuated @@ -488,7 +498,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 = yas530_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) @@ -528,7 +538,7 @@ static void yas5xx_fill_buffer(struct iio_dev *indio_dev) int ret; pm_runtime_get_sync(yas5xx->dev); - ret = yas530_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) { @@ -941,6 +951,11 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { .scaling_val2 = 100000000, /* picotesla to Gauss */ .t_ref = t_ref_counts[yas530], .min_temp_x10 = min_temp_celsius_x10[yas530], + .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, @@ -951,6 +966,11 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { .scaling_val2 = 100000, /* nanotesla to Gauss */ .t_ref = t_ref_counts[yas532], .min_temp_x10 = min_temp_celsius_x10[yas532], + .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, @@ -961,6 +981,11 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { .scaling_val2 = 100000, /* nanotesla to Gauss */ .t_ref = t_ref_counts[yas533], .min_temp_x10 = min_temp_celsius_x10[yas533], + .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, }, }; @@ -1031,35 +1056,25 @@ static int yas5xx_probe(struct i2c_client *i2c, goto assert_reset; } - switch (yas5xx->chip_info->devid) { - case YAS530_DEVICE_ID: - ret = yas530_get_calibration_data(yas5xx); - if (ret) - goto assert_reset; - break; - case YAS532_DEVICE_ID: - ret = yas532_get_calibration_data(yas5xx); - if (ret) - goto assert_reset; - break; - default: - ret = -ENODEV; - dev_err(dev, "unhandled device ID %02x\n", - yas5xx->chip_info->devid); + ret = yas5xx->chip_info->get_calibration_data(yas5xx); + if (ret) goto assert_reset; - } dev_info(dev, "detected %s %s\n", yas5xx->chip_info->product_name, yas5xx->chip_info->version_name[yas5xx->version]); - yas530_dump_calibration(yas5xx); - ret = yas530_power_on(yas5xx); - if (ret) - goto assert_reset; - ret = yas530_measure_offsets(yas5xx); + yas5xx->chip_info->dump_calibration(yas5xx); + + ret = yas5xx->chip_info->power_on(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; indio_dev->modes = INDIO_DIRECT_MODE; @@ -1155,7 +1170,7 @@ static int __maybe_unused yas5xx_runtime_resume(struct device *dev) usleep_range(31000, 40000); gpiod_set_value_cansleep(yas5xx->reset, 0); - ret = yas530_power_on(yas5xx); + ret = yas5xx->chip_info->power_on(yas5xx); if (ret) { dev_err(dev, "cannot power on\n"); goto out_reset; From patchwork Sun Aug 7 23:12:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12938412 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 C063AC3F6B0 for ; Sun, 7 Aug 2022 23:12:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229560AbiHGXMf (ORCPT ); Sun, 7 Aug 2022 19:12:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229747AbiHGXMe (ORCPT ); Sun, 7 Aug 2022 19:12:34 -0400 Received: from sonic311-32.consmr.mail.ir2.yahoo.com (sonic311-32.consmr.mail.ir2.yahoo.com [77.238.176.164]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD78855BD for ; Sun, 7 Aug 2022 16:12:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1659913950; bh=r3IwpVFbKfVnnSifFYMeWHYasBCjnI7Hm/3mjO1Y/bA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=ZHM+fbYySPZsT099J0X2jaQbik9lli+iBHLeeXn6MZUFjtttkzzo5INnIygWDgVGCj/RFAApuT867Bw+n4wBlMUZ313yltFyID1/7RbI6lghSF8tTjwpJqRE9+5eMXy31Ba8GPJQyOfBAXv6sL13Wxv/v69AgWsMlhv/nKekBLpt56tjyMNAIgKSRPhN1iULs4O6VcsAGuqcDLgJnYKhclfkC+rYz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peUyDypCZuGNOw_t3mMw5QFv.R7unYK06eixUkj_8t_9pi2y_VScPpCIm. Rhg_V3c.ZCafxZE3Oad5ORbeCqITP29kXgt44rZ6lIoVCLVzXVpjGGkaEoN.R1ZDnY8dcOFERiBy Mk3BsEf0eHNbXGAxbSnK_JEEM3RkAUI3rt3CaP5dwlWWUtl1coZXiYJ62L_2KjeS49jQvedXfWV6 CMWTngns8uEG6K6awQEh7YJSHaLZvfwfjZnAHMgBWs1_5IFKw9StNHkH.1KzX4V9GNvqEILnJqSz oBQI6HbGeLFpneqwtVMHo44jTnkTP9fsjAbioU4JhIJxWLBuCptSLtP26CdG0wAHKjR6Xq6WcqAF 1kfZ5lD0a55CkdJIHV69xqUmtDnc5U.jSabGLGU4vhOQnX9f_2nUv6FsiZkdj6FrkSBA.aTuiLZC xiFkFfSa5GybWtg2dkz81ZaFdBUysfd3CxiHyN30UV1INsv29uqW9ChSDwfRTGMpgBvMiXX1oWzf lSSCSncoR.ra0G14UvwTOOLBxc3q76WAt3cmkT.a_kXQEdOW0qnko2YNNquGyxotMGN1w.HzqNIn 2AD919TEKc6fCBeKIOZZzUeZUJtsE2OYpc6AmhqvF1qVBrlAlU32VVlfZy8WX7HssX148TbAtLJE fEP1pNwoMuzrliy4Up7PkdGIsfjzO6zUDUYvCrO1uCc4UCUa4qrCudsnt9TtFZ5UgyW6TZF_R42M KlNYEcvJweUHA1gL1iFSGg1hADq4P3FrK35b2IVcPLo0qnZRIc0epXXCn45O.OIcPvXYT0cKaOx8 WoFqhKHDzdbjUOvP6 X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.ir2.yahoo.com with HTTP; Sun, 7 Aug 2022 23:12:30 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-r76pr (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 6fad4cda050acf3b4951eae0e5f75596; Sun, 07 Aug 2022 23:12:29 +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 v5 14/14] iio: magnetometer: yas530: Add YAS537 variant Date: Mon, 8 Aug 2022 01:12:04 +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 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 can be seen at: https://github.com/Jakko3/linux/blob/yas537_v5/drivers/iio/magnetometer/yamaha-yas530.c drivers/iio/magnetometer/Kconfig | 4 +- drivers/iio/magnetometer/yamaha-yas530.c | 436 ++++++++++++++++++++++- 2 files changed, 431 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 62d5f23d8e08..004bd6fcc6f3 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 @@ -32,6 +35,7 @@ #include #include #include +#include #include #include @@ -56,6 +60,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 +88,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 +113,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 +136,21 @@ enum chip_ids { yas530, yas532, yas533, + yas537, }; static const char * const yas5xx_product_name[] = { "YAS530 MS-3E", "YAS532 MS-3R", "YAS533 MS-3F", + "YAS537 MS-3T", }; static const char * const yas5xx_version_names[][2] = { [yas530] = { "A", "B" }, [yas532] = { "AB", "AC" }, [yas533] = { "AB", "AC" }, + [yas537] = { "v0", "v1" }, }; static const int yas530_volatile_reg[] = { @@ -117,6 +158,10 @@ static const int yas530_volatile_reg[] = { YAS530_MEASURE, }; +static const int yas537_volatile_reg[] = { + YAS537_MEASURE, +}; + /* * t_ref_counts is the number of counts at reference temperature. * @@ -124,23 +169,23 @@ static const int yas530_volatile_reg[] = { * values in t_ref_counts[] are the counts at the reference temperature * of 20 °C. * - * For YAS532/533, this value is known from the Android driver. For YAS530, - * it was approximately measured. + * For YAS532/533, this value is known from the Android driver. For YAS530 + * and YAS537, it was approximately measured. */ -static const u16 t_ref_counts[] = { 182, 390, 390 }; +static const u16 t_ref_counts[] = { 182, 390, 390, 8120 }; /* * min_temp_celsius_x10 is the starting point of temperature counting * in 1/10:s degrees Celsius. * - * The array min_temp_celsius_x10[] contains the temperatures where the - * temperature value count is 0. The values are in 1/10:s degrees Celsius - * to ease the further temperature calculation. + * The array min_temp_celsius_x10[] contains the theoretical temperatures + * where the temperature value count is 0. The values are in 1/10:s degrees + * Celsius to ease the further temperature calculation. * * These temperatures are derived from the temperature resolutions given * in the data sheets. */ -static const s16 min_temp_celsius_x10[] = { -620, -500, -500 }; +static const s16 min_temp_celsius_x10[] = { -620, -500, -500, -3860 }; struct yas5xx_calibration { /* Linearization calibration x, y1, y2 */ @@ -344,6 +389,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) { @@ -485,6 +601,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, @@ -797,6 +948,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) { @@ -821,6 +1168,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) { @@ -941,6 +1308,44 @@ 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) +{ + __be16 buf; + int ret; + u8 intrvl; + + /* Writing ADCCAL and TRM registers */ + buf = cpu_to_be16(GENMASK(9, 3)); + ret = regmap_bulk_write(yas5xx->map, YAS537_ADCCAL, &buf, sizeof(buf)); + 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 * MILLI + - 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 const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { [yas530] = { .devid = YAS530_DEVICE_ID, @@ -987,6 +1392,21 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { .measure_offsets = yas530_measure_offsets, .power_on = yas530_power_on, }, + [yas537] = { + .devid = YAS537_DEVICE_ID, + .product_name = yas5xx_product_name[yas537], + .version_name = yas5xx_version_names[yas537], + .volatile_reg = yas537_volatile_reg, + .volatile_reg_qty = ARRAY_SIZE(yas537_volatile_reg), + .scaling_val2 = 100000, /* nanotesla to Gauss */ + .t_ref = t_ref_counts[yas537], + .min_temp_x10 = min_temp_celsius_x10[yas537], + .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, + }, }; static int yas5xx_probe(struct i2c_client *i2c, @@ -1196,6 +1616,7 @@ static const struct i2c_device_id yas5xx_id[] = { {"yas530", yas530 }, {"yas532", yas532 }, {"yas533", yas533 }, + {"yas537", yas537 }, {} }; MODULE_DEVICE_TABLE(i2c, yas5xx_id); @@ -1204,6 +1625,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);