From patchwork Fri Aug 12 21:54: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: 12942553 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 E30C4C3F6B0 for ; Fri, 12 Aug 2022 21:55:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235252AbiHLVzA (ORCPT ); Fri, 12 Aug 2022 17:55:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233859AbiHLVyp (ORCPT ); Fri, 12 Aug 2022 17:54:45 -0400 Received: from sonic301-22.consmr.mail.ir2.yahoo.com (sonic301-22.consmr.mail.ir2.yahoo.com [77.238.176.99]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F231B4439 for ; Fri, 12 Aug 2022 14:54:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1660341281; bh=caI5YrEKF79TQRJda739FwKXTDN05RVs3N/XMdhJsGs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=r2Fm2xJQnkVGpvH/FjrMzJEJc1H7QKcgCcj0RZmt40/DcFbLI+jibx+usznmZAbKeltHkH0wwM0OUmH9usjoDz1VXeWHBOk5+aN0nA+DmKEbzqfgE9L6oa3zney2bsMcHxmZUeF6bqf6pFFYT6HV0ABR5YPDw+IlI7fcMj0G4DbzQQjdo+BpyR3gmfg9Um1wISP8+ihhHRoOW3EQEA+PFTWz4I7OYil6vl2mIrH27lyw8+8WmiFk1K17QUNJp6VGupLNdoobQqlgdlxlIKlqiXBdkljLUJHGqYmAkIqbNRI/TG3THVMHEuF+w3RX/4KGnBjXYf7hMdMh9Qo5OzNV0Q== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1660341281; bh=S7M/3Krv3JLZ3bEmLx87WstdU5m7uqTHXZIt/gzEkW8=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=GhRdBoFa2FM+OORdp73Drd0b2PMiX70bgnHaPrFYIoCwRPyXUlbGo1mwOMQVFMCVV80btXwOY13Ojkuk6pODGtF6xo5OLaM9z8UlJl9rW+p6+AAwYMWbj120n+5Kaa5tgV3E521wZwKP3xFUVM+we7KiORAIXyTK+Ef+DbYExddVZSoVaswvD42dZQ9y0S+R3MlLfH2lAgNaXFeL63ud8anzao0fS9oPOD3zQyuAQg9pU98bF0WOqrCQBawPfZ9zTcQD7lp7GFJ7mjN1bD488sATPNL7LBoGMNwQiqATzqCMwfpYaVZNA2wDvq2WS+DpcjvSVQ+YJd7iCtM2j5EQNw== X-YMail-OSG: Hr8.rPEVM1kASFQEjhCM2Ih4RibK4e5J9IaDxHsRYsXBLOK83AnSmQsAth136tK jewwh9H8JocPixayvEJzxgyGbHngWoo50yBi02Cc8fJFO__Xl9N1uZku2VVNTjqezCSWQw.Z5Tt5 .huzejembKgmNCb20NJPphj7T4nJmRA4IRuP.Venii5VhxlAaWarh2X6mJOhhxW0Qd2.M5VrZHNM e2PFU7h.b.ht7B8U9LXu_eXpaX3aDjoOhsj7Nu5hn7j3WffpVUSKKiz6BEuAawICTZJ5hkjfkeJ7 rbagcJeLYu72VmIR_W0o2NnKQY_ZG4Gx4iRhwh3QjADETZIFrrvfMylraoIe7SYPB5J4HMdneOz2 sG7ZZLSabOFWgFsuT7DKMOSCWnlepzRT1CwW0R8O4EimNUNFsYhe5vaWVOgl8ZNb52O8D4R05oHN 525fsneOMVZsDGRokaKaz8284ts4tomwIo7U_PC8PIO0wZaz4FUS.uIGC.msXnZ54ow2wkzQ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F4eLS8 C6yvUV4GGSiYazYwbr4mvigSWdpJJ3SRo2kJgtRIZjeXm7MJf.jX6TQemDqHxVXP033iHBSlc69w kkBotfjrBwXQNEp7OOHsbUUY64o_4ucewQuqmRGvGVzqT5qQaIqzieO0c.PYNb6WDHy3iRMPScGK nmCOb3S1ElFzoQLbZBTdc05VCI_c8zIPLhClXjsp0.wdHwpuDSr.YUNRR8xUDVLpHNYXA8OQmPtv ArQ4NF9FrD06x02D92C7ixhrIWAKwNgf2Cm6oOIcTBlyKtY9EfQwUR0_x5z9g2mInyU30EEwFeYm XZ2ZQr8klHv3p4.HfYB0uCFdmWaIRXJyE65VGu1EMoIbnjM8AzMz9dV0b.gvmyCmcWMNY07GM3Mv xQoGAvFFvutqqckUavUA1ECMTdNr.twQQRgM9dlhqsyYk0j0cUC9AbhUzNUBTRF.fa31ketZNUSN dKyGu3sYh9dj7E.3SBiP_TssAKnS.fu3W8lIhdeIMKHI_N5QoNKfIOk7tvSFK9ZcZuHmf3r8vdKy DafyV_yjmDy5ovlzRXMB00ZsZ88iBKXjLAxfhypaqIUsNKdSJmWfJJiZ6iMrjKpgOJc0T8OFw0g1 hXEDifhSKjA0.jqe3js1N81SYBpY4a4usZQq9YPTww05.RdSz3utFEq7ac00Hs_d2hnH0DZj6W9O XHzbDP_WMESy9n9C3x39bDc0cAaY8KRsuZFf7lGdpPCSnJNd5vaMnkQGLSzRIFUf8H0VzlGQZ15o g9DAo3rLacffZUg-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ir2.yahoo.com with HTTP; Fri, 12 Aug 2022 21:54:41 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-sqjll (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 4374eb8c565a32f837f1ffd0e5de4e7d; Fri, 12 Aug 2022 21:54:38 +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 v6 01/14] iio: magnetometer: yas530: Change data type of hard_offsets to signed Date: Fri, 12 Aug 2022 23:54:06 +0200 Message-Id: <40f052bf6491457d0c5c0ed4c3534dc6fa251c3c.1660337264.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 aeaa4da6923b..d1f16729c60e 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 Fri Aug 12 21:54: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: 12942555 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 4AD18C2BB43 for ; Fri, 12 Aug 2022 21:55:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233859AbiHLVzB (ORCPT ); Fri, 12 Aug 2022 17:55:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234291AbiHLVyq (ORCPT ); Fri, 12 Aug 2022 17:54:46 -0400 Received: from sonic305-21.consmr.mail.ir2.yahoo.com (sonic305-21.consmr.mail.ir2.yahoo.com [77.238.177.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AD4BB443D for ; Fri, 12 Aug 2022 14:54:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1660341281; bh=TOc5+fd/W86tPI2FR+KwSdGnTCcDbKSyaiaUexNx5+8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=RB1mTijGMA+9zR1SMeH7s4VoC/ZAFCceKi8VAyfI5oeaQaRiQWbTGrZLhcN7Z4ZMctxp1nozTHhVdMmqNJ1UFEK/9YB5jIoF9QAQdeMkUMJFCCU0Z6dpmPbDYGQYf0mVCXTsAxREXOKeG0cAi9qzYq+gk8BDd5yc6QvNMW6qWT4Wd3NlflpL4CyPNu64A+aGtTP8jzc1U/+xcemWr0VZv5gaWdufwbvRY1KAJbMTLZRmgZQD75sHCVjkC2jOBFRGUaIlY+7NXGwZkDeDhFPmN+Yvv+kknkioJZ9mLc1AcxZJ9bJ6c0HHuGkgQ18PvLq+g01mbuxI9pIcjuS+HvSCOw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1660341282; bh=ugsI39zsbx5B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qZiH8xRTiC_Q1rcxB X1TIIRJRUuERPmzvqgUd.vuYY8_mjUFjkKjLYn8OCueR.d34jZua6zVO_kMWCo6hOs8D.VgrWdxY CHe533avsIk8xGYWi1efSjAPhd8rBM460yhNzU7jWQHyCgDroJjtLv2xRfmahGilgQ8lPH_f5fAs 42NJtIrWHDqYqn99RzXa2Kna0O4YsH_6ApL.Q2B.4SwHDDfCc8QJJ_mOemejCbMJajXFHMM98_vq 6RJJtQaD60HMm7IzlfjPxfmPMViEiU14IEBAeSdxnqcyzBZs73tY9NEJ0e2s7PQEFoUyAwKK47.9 v7tuWX6dO5JI5tJ.UUZBzng5JVxjsG6et_L5XYTNmFk_gIsXoqbsipBUPL6XQNgTyIFmLFLeFFbN e3LXKzzuASL9U4h8S02tdtDgmBrf9fzvm3xGodvHoZGJm3TZ.s.htQkpem.vqCxztivDH6q.YuEA mEFO3AE_MyypJzljp2BINS6GYM.by_m2DncS75HdgJo.EXwlwUHBzqhnJAUbT8fyQQh2M9xiE6qz 0CJPuMJ070bUDKC2mifsopkV4xzXYk.2.5LUzYxHb8F0VJ4x3ery2dyTpm85kp5wf4x6oAqqeD9Z r0hM38CBtQnmYv1k- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic305.consmr.mail.ir2.yahoo.com with HTTP; Fri, 12 Aug 2022 21:54:41 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-sqjll (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 4374eb8c565a32f837f1ffd0e5de4e7d; Fri, 12 Aug 2022 21:54: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 v6 02/14] iio: magnetometer: yas530: Change range of data in volatile register Date: Fri, 12 Aug 2022 23:54:07 +0200 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org In function yas5xx_volatile_reg(), 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 d1f16729c60e..76bff4818461 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 Fri Aug 12 21:54: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: 12942556 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 CAFDFC32757 for ; Fri, 12 Aug 2022 21:55:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234291AbiHLVzB (ORCPT ); Fri, 12 Aug 2022 17:55:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234827AbiHLVyq (ORCPT ); Fri, 12 Aug 2022 17:54:46 -0400 Received: from sonic311-31.consmr.mail.ir2.yahoo.com (sonic311-31.consmr.mail.ir2.yahoo.com [77.238.176.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E507B5143 for ; Fri, 12 Aug 2022 14:54:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1660341284; bh=znEE+x4/fs8ErVXvNtdEaKwQbVEdxjLwO/9+DaBezGM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=OZEC0TXwd/FgiPQ96ZTR/uEXRzCc2W6L0oAMxrJEGdZUcfFbcz8u7GHxjNnRl9HGwX6jDg4qtdKXwleMNHltG09McQAwFup4Qh5NuZTFU0q/iixIuK5yd/9mW+7v4BkE2KziO4jm2eSNF6VLtsGukFlt5oTl94iDxj3LaXNeopR3oBd7jlH+DtSTQZMdNMsWrKiuDwI4Uq356pIEiVUqf8A/m3pz440rO2AFOUX1kZBp7uEC95qogBhng1IqWGyi9A6/4yyv7OOSKalnmAPnAOx7iwKpvWbRbrihf7/lxS6I3OIyTWfC3Pu8hV0CFbYnbut+1GhgULpoSB+xEQCSew== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1660341284; bh=YiQ5izLVCi5X5plK+UxqefN164ywxzhPcImpky0vVl3=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=PeMjo2cp4wXnbwhaLVcR8pqSTHhKiaLkPnZG/ALmbMSPzXsqd2em4e6qkMdMSgl6BXcSsIq3Wd0zNRLOwW5GsnHb2tuipPVJHa+Y7Ung8+tYEiRsBrRPE0PL1MA9NT+EBCq3QwZfbFTy7PBgVnzEicEbwboGk+00mFgjhU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wMz07_LrVDSa.CRgIAmd6ZsfYZcruCzuny25guupRBQw0CqRd4bbPHSNSq8dyAOulRCKPtOS8 AJrbIxjfdmRPKbyJ3emrfnypJGiYx_UWXW.ffPh00Jm5pIlMA5yKyO7N.tuFagkGZbfkM6ReTLrH MJc6jYdlI.wl4IU8pJeKF1HvI0t0YJHwfqOpwDPb0qUI4bC16ipf2xlxh8tlphqkepVF.twMu_5R mlMTSrElgrZ.ANOI2h3CVAH8LCNdiR9Ey2CsxQviRElqEppPZIAKNUCTocq4eB3okSG.Cwu0PUZI B1W4TX8SifNF8qDeVnBZS8o_0T6AEfQWx2M5ONCkpSDa26lzzn53YYQAoOozH97lU9HuSrilThx3 B6G90EvWrDmVRGD4- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.ir2.yahoo.com with HTTP; Fri, 12 Aug 2022 21:54:44 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-sqjll (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 4374eb8c565a32f837f1ffd0e5de4e7d; Fri, 12 Aug 2022 21:54:40 +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 v6 03/14] iio: magnetometer: yas530: Correct scaling of magnetic axes Date: Fri, 12 Aug 2022 23:54:08 +0200 Message-Id: <053ab05cb9a0f6b0536ab5e0de57009f513c6f81.1660337264.git.jahau@rocketmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Looks like YAS530 raw values return picotesla and YAS532 nanotesla. Adapt comments and scaling. Signed-off-by: Jakob Hauser Reviewed-by: Linus Walleij Reviewed-by: Andy Shevchenko --- drivers/iio/magnetometer/yamaha-yas530.c | 31 ++++++++++++++++-------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index 76bff4818461..199d83013e6f 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 Fri Aug 12 21:54: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: 12942568 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 65F73C25B0F for ; Fri, 12 Aug 2022 21:56:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230114AbiHLV46 (ORCPT ); Fri, 12 Aug 2022 17:56:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231386AbiHLV45 (ORCPT ); Fri, 12 Aug 2022 17:56:57 -0400 Received: from sonic311-31.consmr.mail.ir2.yahoo.com (sonic311-31.consmr.mail.ir2.yahoo.com [77.238.176.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97DF5B443D for ; Fri, 12 Aug 2022 14:56:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1660341414; bh=6EErivruwsgZKC+fXIpLXsbvYq9f75MRwEyexn+OXd0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=g4g304DONim6/WSBdq6apSzI0ADyDIuIyBY0pKHXJL4doqcMesrl8hdEL/mgksJwcGzYmRD5scvTDpq62jeOUhefrYlFsecQkyssRAdMmkfdXgVuCRtQgNNwnX7uFK0ajsfEP3hqdk29Q4wfKxigjKq9wrjb9X+a49LLzuAGyu+jlx9JshH7d9pj7Tt2H/dMTJ1sOTzI8ty7NMfUXy7wnx6G6/2Q2s35aL54i7YrvlTB/4kJHBmvgcv4mEdRJHjBo7TPHumWdgl4pzR9BAniGuhKwwcvKyQW5wL3+0cpjHWEs/RBHndxFoD79843fkDG59CF8ZryY5V+rTIcJ78Fkg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1660341414; bh=rpR8H/53ymVa+HXLXn/dDnxmnoH8soakZl+H2+loy/c=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=SC0WiAzIVJgQKEneYwMJ/SBNuzM9mgKSiv8NrdJTXK7sUH0vBbuAsfKeQIUcPewxdUMszc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EK5.XLEsD zxE6MwFBfqlHEf8xml7qKYCnTTON1w8obl8__LdzPSdPNb1tO_Nuo6Gno5mRPNjTiS7LuvOw7oAS h_VzFddWIMYD4gcQYlVli_IpJLKu0jAyW7XWbSgX9TBZdHFiqE7LwgC_uZyjn2PiEk.QvnqtKH7F W5_PS4u7muOI_ppDH36cOs1KSUtAYszYrCZJiuIf7ak3CXizDu4ScfouylkGGuGT5a7QHSquBhSH edbuZZfpS_J4diOqwEJ1VaOuXpsVIhBDte_uf0Te9oZQMrAsiNp9lG51c8oPT6XKpiEHHauLRDbF cjcE40o05W9N4kQ3wPOf_cl_H75o6NytXVUEukg4qczEouRwZudRx6S.HIubSKgELL6gH.SW6Ccb eS_25lM.XRXLSV6s2g.O14NfhzsIYeoGKZnF7ea_oesns4yBMc96A7nH3HtVSiwRv_TchP9ylyNK XPjjxvifOKbGCxdU- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.ir2.yahoo.com with HTTP; Fri, 12 Aug 2022 21:56:54 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-2vqg6 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 15f5a750f82727a3561822ee8056ab25; Fri, 12 Aug 2022 21:56:52 +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 v6 04/14] iio: magnetometer: yas530: Correct temperature handling Date: Fri, 12 Aug 2022 23:54: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 199d83013e6f..6296ea3140ef 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 Fri Aug 12 21:54: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: 12942569 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 E5DAEC3F6B0 for ; Fri, 12 Aug 2022 21:57:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233820AbiHLV5C (ORCPT ); Fri, 12 Aug 2022 17:57:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231698AbiHLV5A (ORCPT ); Fri, 12 Aug 2022 17:57:00 -0400 Received: from sonic305-21.consmr.mail.ir2.yahoo.com (sonic305-21.consmr.mail.ir2.yahoo.com [77.238.177.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 880F899259 for ; Fri, 12 Aug 2022 14:56:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1660341417; bh=nuMoHzZRdeYccWIDIyDSTJ5ryNgtfIJF3s4M09Vr0oU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=Ge9a8lac4zAhLE4Son5FO/CXCn5kc/dPGgAmtDa1eslF83nMlJOj2zsFABmMukogxqOmb9kawtGsI4F2sD0pvkjS2Dm6IXcFJY03WGfk3bBqXW62KaNQT0rkf9+v7Fov82s+QpbNhw5wyY9Bj4EOBTrnPBXlineiqH/0aX3K83xQRnyMwGwz6tAApTRVmWCx4RS6Xj1oCHwiXxqNDHoQ1+9y4yPgtZrky9l1WKutqMCNYYudz+eTgl6xnDhM2wBfuviiQNpjQD0C+HSxpuEIQLsHTJbMVixaZhVctC9S7lrIqQkDFs4rR9qRTCrkGV0RMO7DW3ivqnaBy/ta3HCYVA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1660341417; bh=zqqrR3UrpbrRMJ+HiDCFCWJ9rnoFujiaifHyhdHHE7p=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=pPoE9OE+gHzY4EWbA++xNxoenUueMWFD15d4ZRUJOzW2xZplchO20uA6JyVIBZfSDapANnDVNqxQdpRXa2SZyEmnZ36TgF53luuwYTwMrxP6Ll9tbhoSHiDX8CuuznPM8dpguxtN0BxYVrh41zyzge3jgmA+Z0ncwsXpAWElTzRmzq5YjmNgd4Ges1Z8LwvreLz9eem208kwWj2HOUlU59rq+G5S8al8/g8O5DMsKXbnxAj5N4i1rZWt7XpcGZCSdDEjyC30Ck7gncrxkixKZk5MHojBrDuB9HkyEYuk0vE8uHGRD5Zy3NVfx4XQI618wJtF0U65Ao33kVVxypQdaw== X-YMail-OSG: uahWN0oVM1lwyiDRffZTeqLsZUZsqWqUZcQdgfiCH2GyTj4dTIa.BaD9_yZHHNH uxi01oLrPiDjpS.mjt0dlx8otNuVwecG4cKhynPEFduY_ZnD26URYMndC_N.JSgHzDFQ8PnQA1Fr r8TfGHRLnwya_6VZ.zd_F_YEwtkhzXFf0Go41k_Wvlh52WRTKXhyRdapIEprgxLvrOhqyVTJDw.Y YFwY5p8qL0obzU.BcfyNNf5AFhieVxAnoeJ87z.5Hr_CnZDN5ONU9zaxRXnUFb7i3aNmuidRz2LY Qy98wwbX75tmYLeh9jlzVwJpkW.ZP7cwBCM0EWE_1BWqFUMHfN_PtvcQ4hVj0tpuVZPX8_83XcPC iqnysAnD4y..5kJUB6jdKmPuTSvVjc.j3lBLVISuXF4bbhHZEZLIqPECKY6_vzrDVoNzgHrzpd4y I57gJ5mYyqeYTEmWMCRap4S4z6cHL3VXH6BrGFGW.0qyUGeGgd2NI_DBcW69gVFglHKOVka4dheF l_kMGtBq9q0hD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KCuDgO5G6bXWWsOhjHwjmcu.jxYspLvV2d2zVTVae_oSqLGHT8MWd8FEzb RRAIug3GgqtwXHEaH7xlL1_VZEhduib6bwpytPJ3BFtzJWjkbc57A5_jarSY8SqmvxC3g.x2zIym o_FWBhRw2_05aSXolDmZQZSW3D1RSFHGUeRjAu6Dm0M_WJxJ6oLaEG8fINONxXh8KbFwY3wccVKu .zvKOVSNCpgz9tbYJ70SGv96QFgDSGSSTUIMCqNx2iBWTiPVCzUWmaHs5F954PoSOONQF2kli1Ka 6tNfDQPBXA4KpzPDK_s0PGHgqiSXumGuXioeY_kLPOonk3hF25tcnaobJ1KGWHMIKXfQxj34E8X5 wgurRG.ZUyCYLpYMJMFQtFZLJHy0HqXxyCZC6aZh.w_bPHpVLcPxX3zg0Q_OH83kd_4JOiIWIZ_j CHnF1snDTQpKuxOKwIU5zy4.r77Gar7ad2WJtvqyYOPbUZGqvMIdd0Zr9d3YFCJM27A.zVmIy9ky nVNSHZSv8LSPu6u3IV_X99VvIiy41wApSLCIYrLjUrXbiYXmCDG_5nlR85.2KeGuzVt7ySV0ZXhB hLtUclcrH3TW4vnSuMeFk_hC.FT.PwWeak4hmvHyAkA2AknX3EHl_A04T1xXvFS90W2l7O1eRlBr H7RdSR4Iq9IHGNl9asnaPh6Z20uvdr1.4Y31rLjRJjN3SQZFakGAYI_VXBM0BtjiTfTY2Pkq_i3D dHDLaeKnIwZygOw-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic305.consmr.mail.ir2.yahoo.com with HTTP; Fri, 12 Aug 2022 21:56:57 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-2vqg6 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 15f5a750f82727a3561822ee8056ab25; Fri, 12 Aug 2022 21:56:53 +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 v6 05/14] iio: magnetometer: yas530: Change data type of calibration coefficients Date: Fri, 12 Aug 2022 23:54:10 +0200 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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 6296ea3140ef..a9d7cf3ad77f 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 Fri Aug 12 21:54: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: 12942570 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 8EB18C282E7 for ; Fri, 12 Aug 2022 21:57:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231698AbiHLV5D (ORCPT ); Fri, 12 Aug 2022 17:57:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229646AbiHLV5A (ORCPT ); Fri, 12 Aug 2022 17:57:00 -0400 Received: from sonic308-18.consmr.mail.ir2.yahoo.com (sonic308-18.consmr.mail.ir2.yahoo.com [77.238.178.146]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89722B443D for ; Fri, 12 Aug 2022 14:56:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1660341417; bh=NHYENK3/2zrXtIKxNQM0pVoNCqaTCcdUoYVQRHxdJwQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=tN4RUISAr6O8OHTNmwebzcrXbHaqVhfrYtcy8bmUeuaw/gWXSd7MJNvsd1P+l5xaMw4ZyyXQVNAr+Nx92tXOI95VKfE60qW71ir7Vv8C9tzA2JmHMTvDwIhKf8P2V1Nlmoj9UJvZ2Y/yW0hs21pkZ3n8C9hX+zSbYB5y9uaGPKmmO9JWJrlX36Nq0txvWQi5scSCOQGe+JumcuPx2I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CBz_efuCGAYl7 k5.gy46ssBirxWiQfhPugBVJWXa.NI99c5Mw88rFsG67_SveKfNL2mBxy2o1h.E2A8c4xmgTf0N3 ymLXHpwa82YTRrjlcJw_bFy_zqj03YwH2PX0lQW4iGExWf3S5unBWMQwQSOpDnbLh978eHqqZGTQ 2bSgnlYsdGG3WJYMG3s__MO5FxOXgz_JrDqFLsiYDp92_WiHABNMZHo39RYaaAI8VCQzk0J4Hm97 MQJ1H1jher3ofEdcy21KngLt1u.3R7J.y1N3sfhSjKI1XjFjNeGHYc2T5Wd1h9yLEaZrL.PXeSSn A6xJmvLpv.k7hsnDLkmIXTP3Y8FjE7L_2mpE_PHDZPbOWf9ZvFHG_fvReLutnddCLcRt1PIvW6CH MLyszIRkxhWzs6uzmMFJsX70iWnsT4G2.d4Y9lP70vmEuHDEyYaztLj1F7DPEJJquWJ.2Sno2sqe SwJaUt6p_._D3M94_2qlrDJ_4UeNoHxZlr2bq55Ern6G9G2eu1Y92Jy.LF9YnH2hTkowLRWL2IYi hnFv1ZvCsOQuGJcNn7IDs6CAbmdoVdtoVK8yD33AMTWQri7h42WNFjp0kOb4Xmfb1.OR89X.AH5Y KwtI5Hjxe4S6tNLl7f4cBjgZmG_dpYrCEXcFseALJ7B2m2EvwTpiNkxw5LRJ0vxbwdJnNZsjA.IP SFFkQzOR9.Pyb0lmOZ9ZuhPW361qhg0PvUoXCI6BoO1W2GpJGDWj.sU552NFkJjYDC4zJbYkXZao _veMoiYqUhuBWd8J9vz_njW94V5OlvQzdSlUNozFkMPDnY4bEcsLoEpFCXULGaw5EjrRFYI8DJ8u LYPafjTuieDB6jcQXDPwU X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic308.consmr.mail.ir2.yahoo.com with HTTP; Fri, 12 Aug 2022 21:56:57 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-2vqg6 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 15f5a750f82727a3561822ee8056ab25; Fri, 12 Aug 2022 21:56:54 +0000 (UTC) From: Jakob Hauser To: Jonathan Cameron Cc: Lars-Peter Clausen , Linus Walleij , Andy Shevchenko , Hans de Goede , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH v6 06/14] iio: magnetometer: yas530: Rename functions and registers Date: Fri, 12 Aug 2022 23:54:11 +0200 Message-Id: <344d3b2f5e050eab79ce9962c24781486774d9fb.1660337264.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 the 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 a9d7cf3ad77f..40cd6bbc9952 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 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 Fri Aug 12 21:54:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12942571 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 32BDCC28B2C for ; Fri, 12 Aug 2022 21:57:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230445AbiHLV5E (ORCPT ); Fri, 12 Aug 2022 17:57:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233859AbiHLV5D (ORCPT ); Fri, 12 Aug 2022 17:57:03 -0400 Received: from sonic307-54.consmr.mail.ir2.yahoo.com (sonic307-54.consmr.mail.ir2.yahoo.com [87.248.110.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B893FB5146 for ; Fri, 12 Aug 2022 14:57:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1660341418; bh=mIUQiLcLvAOL7SpGV1ZiJOCq32eACtPmZycCkGSkGCw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=ZkkY7AQPKhvfe4i864U6aqnEEsxHEwS+MZUseCUOsR5gc1CWZHevptoBA6Ogygs7eSq3PGLAYjZKZHNmVF9LAwSd5J0YZVynUcCXN57MpAqgmusxQD8XxzERxoh2rcR3EImvnBK+mM0Lu1IYhp+rJqwv3nHJi2YLeuozxfX9LZ8MRUHoFhXmL6ZJcowcM3RMR/aRHkEddZf8sT5+wRGEpvpzCNfpEwbFNQ219WlQ9ZiRcwZt8RviumPAAeV3duOqusO0MYgIg+hhcu1DhVrS8zZn7H34s9P77hG/Ly2agPgNL0/cU3I3cEOoL8/OfsnGHexCOMGY3YO8sEq34ewgiQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1660341418; bh=VZVsB9Et19YPn6aP1OmcH+W3+7xLDoKoO/1qWgfgq9f=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=EWcC543b3COPx+Bi8+LnwFnjR9lvyWaDSAl7itdKRc/Z3H+tAhCdwPcX5cd+NkUh9iUa47BnZEdaxSwDaE2cNlnNv7azlUIMJpPGXzV4DP+9uBBtykMOVkVHsK7Sm0Y7n+y8FqoQSPiIhfSPznmSzQwuI541Oe12pcgG+joKV3tQ0M1vJa1P3i4A6AlgvGRDpfiCULWIWcKFQ5mq3nI/8HwW2/6mL4bpAQ1SkHIk6b1vOZAfvwpKGTERoIioWBuZVKMWlsbMXcbjQ2n1gNPBGl40SDIroI7a1ifAKcY2EzQ1vQO8Jejw47wm0aQZOPjKiPsUZzp+9g444IhUPjr8jQ== X-YMail-OSG: ewzIJlMVM1kOlJ_bAKj1.AVeRZVgSHvO6rPkScVgDcfo3eim27b46pwL11Gp.nS UTwY2DZvYZZ08lr776B6OE6Wn3btgxN6BsdNfQZdzMB2s3Ks.8PsYg7qGin3wobR0FCGlEfqgm1A sRENjDVNolIjQrjqdP9cEasIfGJr7rCRqbP0F0ZyMpucYwgfsaed1OvGSwuaBmAKdxJ.AiA8g23U YEA2Uo4zJ4NQe3SJmfjDtFVuTbMgLIBNDmZI3l.QnDQGPYsFYvgmWKXmGRzLpcQOR_vbKQcspJlF ihsqQyyn7h9b35wnNap_ucqUTpHlf3K5isydrDb9wFGnO80U.BinZT_P99TylApP2KpleiIz449h gR3vmjy0.sSZvj4Lnx8Mhl20NTCMcwRsU23ZONUh5UXIYgEEhxErZ657I1d8sm73dlStewAPkYkN v05OE_b7B3EjX2itI7VPNAnGTAhJHTZTwvgYkEKSC94Anypyi7ZIX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1Rg7VJTNavpwLjRKqXpSqBDD9 l9OCpw7X7a6fjEPuIUBpDFHoPehW8yXJr2ETJ4xqRB3bVlN_aKDmwNt24R9Bt_En8nfNLpaXJM0D LwH_pBl2iq7npkA6Bl1876b7LK2JZcH_3I6RcKXNpqt6Q5x6q9Azn.r9mfNmIqQuRCiv_glkkGZZ A84InWJJmo9szF_FIeOzPda.wViVQeDkPd3PekH0oC_F6Lzk7b9hjUe.JQrzGp.Tuc4ULO96bA5w ELyHaAHRPYyX5f4pZvfgUq1OgPEVLaqrAShSIldoIpetLrZl2OT_gMhRv0xm1iSlrcIzIj0YGNEm In2DtOWDKD1R2BijlUWMTmsmu5jApyZgpeDX8bI42x3tRm4kJGAxyE6P5CLQa7MIJwp3EXbuulCh eexyUQ84d2j.Xd5rh_7mKx1s2j5xJY.UKhjZENbOh0LzmjqqRnSFUa0Qb0QaLVHhkvDO930HTo6F bwTOt9C_yCH.MW4M1t3EnlH0aYl_fcY8xUkK2qm8NrOgdQt9pBl7x5W0EhkVqVfTb.pRryT6KHxG nHcmbCYJCxI3jf1fxONQnn9jF4QacQyUHvZfLQtaKlUxheUiR2PR.ESWy6GrClM3kcq3C.Xcn7me qPPsIFZYNdaLHiGcHeyEpAvzrwlbRk6pPdq9Pg0vA2p7__A_fyq5qZBCUJ5ZekuUkUua3MQ70Wys 7lYa68sWFMKXWgh.5pUsS6JXEHCiqP184WqS0mh5oFnQqFB_eq3Upv9xkeBZ5Y0LV8da3MaxQXM0 yfqmmxkDTkBEDjlWJLt4- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic307.consmr.mail.ir2.yahoo.com with HTTP; Fri, 12 Aug 2022 21:56:58 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-2vqg6 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 15f5a750f82727a3561822ee8056ab25; Fri, 12 Aug 2022 21:56: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 v6 07/14] iio: magnetometer: yas530: Move printk %*ph parameters out from stack Date: Fri, 12 Aug 2022 23:54:12 +0200 Message-Id: <93b50c20adb1b2acb4cddb1ab25755070edd7c07.1660337264.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. While at it, 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. Suggested-by: Andy Shevchenko Signed-off-by: Jakob Hauser Reviewed-by: Andy Shevchenko Reviewed-by: Linus Walleij --- 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 40cd6bbc9952..beb48f3a959c 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 Fri Aug 12 21:54:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12942572 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 CF2C3C3F6B0 for ; Fri, 12 Aug 2022 21:59:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232950AbiHLV7P (ORCPT ); Fri, 12 Aug 2022 17:59:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230118AbiHLV7N (ORCPT ); Fri, 12 Aug 2022 17:59:13 -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 94566B443F for ; Fri, 12 Aug 2022 14:59:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1660341551; bh=PuAzVUYJCPGAi2dhIABGwnKhY1GAm8cD88e7vvhikLU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=OltVJ0tmxCiDnGoMhiaZ3qPmI43swIgcOVWvlrRA/vhkEaOJ/neLM5vAimL/7/MviSbzfX4+XLFWon18M0umJCmurT7zu8cDqk+DIo9wN3OSa3h6bxHdNddh+oDPsIUHzHGQqAnOT4am58eEpUps2RwPpskN+n0uptMdOLqXWmojli+aN3qLfJ6LZ9Rg/YskZ4xrlOac4SECX28rs0m7xadaIihl1AHarH0/cq57fW97nvvlIEIhKBEuApvumMMd15pmvkhyj++sU9eDRQnK/4wOgl+lISMuquO6WU6RqMZk7Ymj1qw7X37gU2BeWQpn9x1O69jb+31P4Tyj7ckZhg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1660341551; bh=9cN/+z3JU59JYRqm84u99sfrH9t1C3/eaSCtTsUXhAP=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=PtlvbMwlBF5BU4hOQ5z+JWSz8zIp92vYrzLPIUPwoZ3aU5vBxdV/7O7FbFYKPADuur6o3rmZ3tAI3yOkJOjEbVkqlw6Os76N6h+AFj32e2FJOXpYPNlKEsbqMKuGbIf+/6pVvapld9ebKsHI6h7ByKg9L2WaDnREkrmMuDgiLhyi3ZowQDqeF2IWZLB6Mnzwxd+2NOKajTfx6dNsodRItQAVLblctmYJ+vSSwtnGdvRQf1QmKdix/5Ga+6vrhiMrdrIT3KdgOLP+C756rJNDks4twxpwf0VcJv0S1FksUX9r5Xt5LR4xEhw+nmn4UiJ5+SKuXvkKrD77jHs3B1FgVQ== X-YMail-OSG: tR7TvtEVM1mBr52ZL30JJNjTpDZSO7qgd1eTSJolFpvLQl0K42TikJHHeL3_ZJQ shX09qTYFBb44JCuqchLrW.OSo6nN4to2O5iebb5rpIy67HhwPLTcWBsZ.ZJnjXWVm0eGDImJQJy TrSPj9E4wppScAeJAovsxfMzo9scpCJCpQweIjmCDPE1WtVeCx3lQPwqMivfUcXXHn7Vj3lS7VC9 bYIHWHN.QlPGnkANBe7oiPxZYr.7MET4KXQfuC7N27LSSUx0SenJvupQZC4UydOarfHTbczRnRMK 6nj3ERvOCM.ZlTsRfoa1pgu6GilJaRPpA_qY7r9si6MkdBStO8hVRwbMo8fwMnnLaX7k2MVKS7SK 7iHofOQf_CQT5Lbxug1p__yUm5PJEgS.E3AbTev5pMIBGw6CPGV1VEO93GPstiFiCpyo2kHcV7MV qkD21WyfPbZnRxIqLlDZmgAXWI2DNXc3Rm0tjqDXSss6OngK7kA7dGYvZVb0rzrIFjEylUE4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R5Gk_SwxyOa.89U7SyXiQw1lwCRwhSMb.jiQVg93Y42462oKXfpJD1H6 _RNSrOozG6B82DZtA2uHqEYR0s9J4KShHmhCQACT1Md7NoGXEghsJRlGu3_3hkcTS2.O9AYxnHWt 2hbBPWNTY5mTpZTkuHH_sQExScBhD5SBH7x.7A6.FOYouYDL8X9GGgJLdWpjEGsWZCed_OVwIaVb b_XYEQ3wPXA791cnALukAFYaxfQiK8XIv1JwNz4WY6QlE3pD1wsgRZiXxdsolvTVe7XDJAxUOAj1 C_8yT3POt.8xnkTJ5fVedPt_15kiYNTYdBncfXMMI6_Szhd1hLoBecIRY_9StSKgtWo2921UGagu 1j88vf7JRfBjckPaFqLaW4_NB0TTFGrJHM.pSzd8cAvHMbr6iXK0q6J9JFKYZmABA.4EbKXpdCMX WGpMbvne4f8lLn2Zg4m4gixoryD.RvUWDRfHoVFEvzdhTAa3QIYc3yUWYFX3fkx5HjjIoy6IksgG SFUPO2UAYhBLd_KwSsWLx4XMTbGbQWoco4VAepNyIUCdCWr.cpmSSHkvpwTWu4ShDW5JTuKYtqSL 8IcJ_wIxJktsPjMGq030yrmaCfqio1Yx6.1bPka5tysG9cuTSoNVA2bVKXDNR8nJN71v2uw2GQCI vpedZn8m4kjKzr6EfDc2z0qkblnvTaRQwfU_5unUQMDQ.19pwz93GJaEOXegMx.Sjhj0wfRrPv7d hps2MsV.chxrTBkms_A0- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.ir2.yahoo.com with HTTP; Fri, 12 Aug 2022 21:59:11 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-5bdfc (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID da2640015b5c2c3b63bd3f8312c2da46; Fri, 12 Aug 2022 21:59:07 +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 v6 08/14] iio: magnetometer: yas530: Apply documentation and style fixes Date: Fri, 12 Aug 2022 23:54:13 +0200 Message-Id: <300e394a76eb30fa031ecb69b594e9f9a70dac42.1660337264.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 beb48f3a959c..f81868de5995 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 Fri Aug 12 21:54:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12942573 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 0B4C8C282E7 for ; Fri, 12 Aug 2022 21:59:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231424AbiHLV7Q (ORCPT ); Fri, 12 Aug 2022 17:59:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232433AbiHLV7P (ORCPT ); Fri, 12 Aug 2022 17:59:15 -0400 Received: from sonic312-26.consmr.mail.ir2.yahoo.com (sonic312-26.consmr.mail.ir2.yahoo.com [77.238.178.97]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B401AB5143 for ; Fri, 12 Aug 2022 14:59:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1660341552; bh=4DWIioWw8aydWG5RN5ZpQ4gaiQLP6WsFfJYNUaD+nn8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=IgRjUE5MNyR7mUxCe3bWnXnhld2hiw19hntRj89g/jo8h7eTJ03sdChxct1Okxo+gHmvPuVDoaA9U5c0kdsBjZYncKmfc/7RXW91Q1+NRv7gqryOQCttr2fdfgpWy2gW3R0OYzTPIRKWg2VSD7fNp1RYaOdIGN8rNB97rVWNiSOdMLRp7WO681QoyEYY0n4YzqcXumP1x5iBhrFkNUv5aHtfMPyr4/E/rDdB3ojZip1KmbBvosA8bhUl/Gr0/2OGJgV3l9D/SHTHJBQtUBJTxuXUTSNWFk7ddl60WSO7vgQbDAEoof/SdEeQvbnREtMNjl+xnotAVww0QJZzplPYiQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1660341552; bh=PKYX4hJwVuKR0KfCQNwkwHYsds34GG1jsl/faTVldP6=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=MNDCklcFKxGn24RfDTVbt9OYa8qytI8n5s+uEKwgtvlPirmgY2MKD6spxzKXsErHtz/+KNzNKUjmqmge/v0s3wOXxkfRgoD+6g1QVSvKNojGqWiafx3mm5sOIjEbYJYn0ca6wk0B6qj1awU+aZlPKhqN/j9phmOCHU7ziEvtV8/01EDOv7dN1ZDe4eYoFBopV3gWBZiO7tcZItDOw3ERxeOn5R/EODsuGLSFlLukX4V7qE1w4zTtyCmVK+SOvUcgttDZJQADqw0M9IWZbMvoyJUnrfyVE0xSZ6TpNthizSBjpyLaXtXsXBVJkIBg5h7hA1gwgW7nIekCtNv/ogJTVg== X-YMail-OSG: SnTEAUwVM1lSiu6qevHKEbSIoq4DxsygTjzTohOADqu0jlsBcqPSruSYkypsFLs jlCeXfiNcrpixoatxP6wBcip8nPA4vCkXm_8ai.y67ofrfTAarLjQBbnc9KAawkT.lrnqRGj3ZLL cT6Xkyn61tvtNHfsmcO2BNqQO4GM6tUX_jgb0dlrPpIJjqzJvQlXKglsvHTzZNRsLKY02n6m5aHo 40VcWRPeW8sANrvTRVq1lzg6tmERbfjSsgHnP9cK_hbUCeIJ30jk8dr_qv2Ew0rr86ZNdJqYsn4m VI1Top2wG1HUO2wBUR.muKZhXyhwCTAr4zqqN6tEOI8iiFM.u7CuezGAzt6JlBIbH1vqAZsZ1lox 91lh_RVjv9cgPiWPTqM6TZyuO4Y2qRSTEH.CJqOWYlKxxZ8rjJM6C05zfGrKSxwsJ1Skc0oO6588 elEuvOVEHS3F5P7wUA0L7H26qFs.yWCQJ_orB_dny9BeH3hbu8x0epSOr55UPOvvYaWZ6BMT2xuh W9lr1OLhN7lHapY4f7iBvNLn6NJsXpR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VUcdN1E2n4IjUjd4nQJmgbgGKjIwe4uFtq8MBqLT0VIMq6KI6I S4epI00n4nff_UmRSj3DVxQgT1Y3M8_yo.W3eVIR.RJxi24eB.jLwhH5l4z_CQY69I9mOLOUyD8o qt3ivtXm4e_cVk.lVpv6D.oaGgHdVupo_KqF_mPYzY3u.v9OTz0RBbPPw0qydbJAxcWgO.r_NxxJ D9zJx0Ne8ViwmvZOvq6lSoxNYWrTe97fZaljnDihoEJPteNxibB05JexC1NccondqqMzIFKySMtN Md0fouluQNHhNe6Jy9HRB23AQ8Gm9qNmhro3l8JQlxylnpPBzBlgjFCe6p2oGiFO1Lqj_wG3ujbD ZdF9VOB5R0JHojvNYVWFlDz1gZERkwiahJFCOuqfW1SvbbgcrV92mzsWhoO.rgGlidQLGYeGAvU. kFyY_MUpK8.abCxBfyO2XB5sKVivsKL9csdXBNkrtEHabR3yEGaRXZ_XYrwULdNmviCPmvHJgshW qwnPGDoyu.DgE6RY0pnKi5k9uEETsOHH3aADn3PH1ABT4iHuJQstYTtd1xMJc0ICe_B1s01SNIDu cAhTprRXSQwsNDuGhIRm5sY_CKmgXHPnMNO_P2Lz_x3lX.GDAddok6jwXYOQS7IRC4kbvgdefdy1 KCN2xrXC3umCaEyywnqbpPJ4qkdKAm12x.cTNoUDWDbCZKNQ9vijX_N.fkOwRMNeEoidumsciQqR sAGsVA.dMxvkCmiU7HWTt X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic312.consmr.mail.ir2.yahoo.com with HTTP; Fri, 12 Aug 2022 21:59:12 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-5bdfc (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID da2640015b5c2c3b63bd3f8312c2da46; Fri, 12 Aug 2022 21:59:08 +0000 (UTC) From: Jakob Hauser To: Jonathan Cameron Cc: Lars-Peter Clausen , Linus Walleij , Andy Shevchenko , Hans de Goede , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH v6 09/14] iio: magnetometer: yas530: Introduce "chip_info" structure Date: Fri, 12 Aug 2022 23:54:14 +0200 Message-Id: <57236545107286771d351b95091bf56815d3717d.1660337264.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 Introduce 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 Reviewed-by: Linus Walleij --- drivers/iio/magnetometer/yamaha-yas530.c | 98 ++++++++++++++++++------ 1 file changed, 74 insertions(+), 24 deletions(-) diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index f81868de5995..4fe7e8c820c3 100644 --- a/drivers/iio/magnetometer/yamaha-yas530.c +++ b/drivers/iio/magnetometer/yamaha-yas530.c @@ -96,6 +96,12 @@ /* Turn off device regulators etc after 5 seconds of inactivity */ #define YAS5XX_AUTOSUSPEND_DELAY_MS 5000 +enum chip_ids { + yas530, + yas532, + yas533, +}; + struct yas5xx_calibration { /* Linearization calibration x, y1, y2 */ s32 r[3]; @@ -110,12 +116,25 @@ 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_names: version letters or namings + */ +struct yas5xx_chip_info { + unsigned int devid; + char *product_name; + char *version_names[2]; +}; + /** * struct yas5xx - state container for the YAS5xx driver * @dev: parent device pointer - * @devid: device ID number + * @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 +148,8 @@ struct yas5xx_calibration { */ struct yas5xx { struct device *dev; - unsigned int devid; + 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; @@ -192,6 +210,7 @@ static u16 yas532_extract_axis(u8 *data) */ static int yas530_measure(struct yas5xx *yas5xx, u16 *t, u16 *x, u16 *y1, u16 *y2) { + const struct yas5xx_chip_info *ci = yas5xx->chip_info; unsigned int busy; u8 data[8]; int ret; @@ -222,7 +241,7 @@ static int yas530_measure(struct yas5xx *yas5xx, u16 *t, u16 *x, u16 *y1, u16 *y mutex_unlock(&yas5xx->lock); - switch (yas5xx->devid) { + switch (ci->devid) { case YAS530_DEVICE_ID: /* * The t value is 9 bits in big endian format @@ -267,6 +286,7 @@ static int yas530_measure(struct yas5xx *yas5xx, u16 *t, u16 *x, u16 *y1, u16 *y /* Used by YAS530, YAS532 and YAS533 */ static s32 yas530_linearize(struct yas5xx *yas5xx, u16 val, int axis) { + const struct yas5xx_chip_info *ci = yas5xx->chip_info; struct yas5xx_calibration *c = &yas5xx->calibration; static const s32 yas532ac_coef[] = { YAS532_VERSION_AC_COEF_X, @@ -276,7 +296,7 @@ static s32 yas530_linearize(struct yas5xx *yas5xx, u16 val, int axis) s32 coef; /* Select coefficients */ - switch (yas5xx->devid) { + switch (ci->devid) { case YAS530_DEVICE_ID: if (yas5xx->version == YAS530_VERSION_A) coef = YAS530_VERSION_A_COEF; @@ -319,6 +339,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) { + const struct yas5xx_chip_info *ci = yas5xx->chip_info; struct yas5xx_calibration *c = &yas5xx->calibration; u16 t_ref, t, x, y1, y2; /* These are signed x, signed y1 etc */ @@ -336,7 +357,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 (ci->devid) { case YAS530_DEVICE_ID: t_ref = YAS530_20DEGREES; break; @@ -349,7 +370,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 (ci->devid == YAS532_DEVICE_ID && yas5xx->version == YAS532_VERSION_AC) { /* * YAS532 version AC uses the temperature deviation as a @@ -384,7 +405,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 (ci->devid) { case YAS530_DEVICE_ID: /* * Raw temperature value t is the number of counts starting @@ -442,6 +463,7 @@ static int yas5xx_read_raw(struct iio_dev *indio_dev, long mask) { struct yas5xx *yas5xx = iio_priv(indio_dev); + const struct yas5xx_chip_info *ci = yas5xx->chip_info; s32 t, x, y, z; int ret; @@ -473,7 +495,7 @@ static int yas5xx_read_raw(struct iio_dev *indio_dev, } return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: - switch (yas5xx->devid) { + switch (ci->devid) { case YAS530_DEVICE_ID: /* * Raw values of YAS530 are in picotesla. Divide by @@ -802,6 +824,7 @@ static s8 yas530_adjust_offset(s8 old, int bit, u16 center, u16 measure) /* Used by YAS530, YAS532 and YAS533 */ static int yas530_measure_offsets(struct yas5xx *yas5xx) { + const struct yas5xx_chip_info *ci = yas5xx->chip_info; int ret; u16 center; u16 t, x, y1, y2; @@ -814,7 +837,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 (ci->devid) { case YAS530_DEVICE_ID: center = YAS530_DATA_CENTER; break; @@ -895,12 +918,32 @@ 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 = "YAS530 MS-3E", + .version_names = { "A", "B" }, + }, + [yas532] = { + .devid = YAS532_DEVICE_ID, + .product_name = "YAS532 MS-3R", + .version_names = { "AB", "AC" }, + }, + [yas533] = { + .devid = YAS532_DEVICE_ID, + .product_name = "YAS533 MS-3F", + .version_names = { "AB", "AC" }, + }, +}; + 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; + const struct yas5xx_chip_info *ci; + int id_check; int ret; indio_dev = devm_iio_device_alloc(dev, sizeof(*yas5xx)); @@ -947,33 +990,40 @@ static int yas5xx_probe(struct i2c_client *i2c, goto assert_reset; } - ret = regmap_read(yas5xx->map, YAS5XX_DEVICE_ID, &yas5xx->devid); + yas5xx->chip_info = &yas5xx_chip_info_tbl[id->driver_data]; + ci = yas5xx->chip_info; + + ret = regmap_read(yas5xx->map, YAS5XX_DEVICE_ID, &id_check); if (ret) goto assert_reset; - switch (yas5xx->devid) { + if (id_check != ci->devid) { + ret = dev_err_probe(dev, -ENODEV, + "device ID %02x doesn't match %s\n", + id_check, id->name); + goto assert_reset; + } + + switch (ci->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", ci->devid); goto assert_reset; } + dev_info(dev, "detected %s %s\n", ci->product_name, + ci->version_names[yas5xx->version]); + yas530_dump_calibration(yas5xx); ret = yas530_power_on(yas5xx); if (ret) @@ -985,7 +1035,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); @@ -1096,9 +1146,9 @@ static DEFINE_RUNTIME_DEV_PM_OPS(yas5xx_dev_pm_ops, yas5xx_runtime_suspend, yas5xx_runtime_resume, NULL); 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 Fri Aug 12 21:54:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12942574 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 836C2C2BB45 for ; Fri, 12 Aug 2022 21:59:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233151AbiHLV7S (ORCPT ); Fri, 12 Aug 2022 17:59:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233615AbiHLV7P (ORCPT ); Fri, 12 Aug 2022 17:59:15 -0400 Received: from sonic314-19.consmr.mail.ir2.yahoo.com (sonic314-19.consmr.mail.ir2.yahoo.com [77.238.177.145]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85FF5B514B for ; Fri, 12 Aug 2022 14:59:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1660341553; bh=soju2w1mmQ5qFukSEwLFpYSnFgCDfNKRtq3CDVaWa6I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=OrAlXbF6zndCrfQfQE8if0ulr1zFO28G38BmLvAuMtO18CDz3OgRvJerRnT9tRP9f0CCA6A/UydmFcMeAndLjz4WLz8dvdJKWbNjjnijmM3JZ2vIQ2F9jUwNzmq21wWJcTYKwLwVTFb2qKFcHfbQinZvRVH5XJzNb9xNU/f06udk0jDcAD3fJy7YHfhQH7MUD1f6x1qxb/bjYPsx+zl12ImzdjEue/wEH+P1Kr9xMaWHcU7KxAmccm9gFohf2HN74k9w12zCw7yHH1KRejaM+12N3tJ+EeO68XCeQ0QDIYiqWG4WZsNqrDSatPZXqkzu7+7z6jtZWRH99rMkOdIAPw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1660341553; bh=+sto39i1nGejNxdTEUzPOb32s1RoiXL/XKdYP0Bvqma=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=azEXT55hu4ZV9XiOzNoF4EnZse10bdKsH28O4wNKZraBR7BrEZJ/8lUttNsRG4Agbth4UL248Q0kLtcP2UlyYXo+0TloODinx96QdyiuIVOt0yWNQDKIlwGZ2ZBSntzDYeW16jqfMKkrOUrAItCfK4pGKysC5SlRrOJqaKdmiX+5rRLvvYxwCFB4j9ikDVAjVG6Dzvowt7V9vwklQCkkaMgQl5Az5Fe67ty/MHPIMv9TIwTPOh5FiqEZ+5w8E7DFsxbf7hSte4CIxq7iE+Wov/DSrhTbtkcFePbzPhdd+djG429FUbLgKe6PAyZmvIwPT4x3eNOBRxGtJVMoE8kuug== X-YMail-OSG: 3LhErrsVM1nvezyH2rTRju6bSrQYq5oSFOIIF2g9DBA_GlPsus8DmVaOsD7_1H2 13APOwMRjCO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p0a5Xfbhjze9aGHvttfml6kgi6ltgwVrBKI 6n6nNBb_wCj1DgLO2Tvgi5bBEUKqCjDjzI8MiEJju94XoG_Ab_JZED0FAC1KKm.6x4KTUGvAodiz KQ03Ow1oQetvvBDjFO6o- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic314.consmr.mail.ir2.yahoo.com with HTTP; Fri, 12 Aug 2022 21:59:13 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-5bdfc (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID da2640015b5c2c3b63bd3f8312c2da46; Fri, 12 Aug 2022 21:59:09 +0000 (UTC) From: Jakob Hauser To: Jonathan Cameron Cc: Lars-Peter Clausen , Linus Walleij , Andy Shevchenko , Hans de Goede , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH v6 10/14] iio: magnetometer: yas530: Add volatile registers to "chip_info" Date: Fri, 12 Aug 2022 23:54:15 +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 Reviewed-by: Linus Walleij --- drivers/iio/magnetometer/yamaha-yas530.c | 38 ++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index 4fe7e8c820c3..fa317b975f8f 100644 --- a/drivers/iio/magnetometer/yamaha-yas530.c +++ b/drivers/iio/magnetometer/yamaha-yas530.c @@ -102,6 +102,11 @@ enum chip_ids { yas533, }; +static const int yas530_volatile_reg[] = { + YAS530_ACTUATE_INIT_COIL, + YAS530_MEASURE, +}; + struct yas5xx_calibration { /* Linearization calibration x, y1, y2 */ s32 r[3]; @@ -123,11 +128,15 @@ struct yas5xx; * @devid: device ID number * @product_name: product name of the YAS variant * @version_names: version letters or namings + * @volatile_reg: device-specific volatile registers + * @volatile_reg_qty: quantity of device-specific volatile registers */ struct yas5xx_chip_info { unsigned int devid; char *product_name; char *version_names[2]; + const int *volatile_reg; + int volatile_reg_qty; }; /** @@ -616,9 +625,26 @@ 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); + const struct yas5xx_chip_info *ci = yas5xx->chip_info; + 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 = ci->volatile_reg_qty; + for (i = 0; i < reg_qty; i++) { + if (reg == ci->volatile_reg[i]) + return true; + } + + return false; } /* TODO: enable regmap cache, using mark dirty and sync at runtime resume */ @@ -923,16 +949,22 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { .devid = YAS530_DEVICE_ID, .product_name = "YAS530 MS-3E", .version_names = { "A", "B" }, + .volatile_reg = yas530_volatile_reg, + .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), }, [yas532] = { .devid = YAS532_DEVICE_ID, .product_name = "YAS532 MS-3R", .version_names = { "AB", "AC" }, + .volatile_reg = yas530_volatile_reg, + .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), }, [yas533] = { .devid = YAS532_DEVICE_ID, .product_name = "YAS533 MS-3F", .version_names = { "AB", "AC" }, + .volatile_reg = yas530_volatile_reg, + .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), }, }; From patchwork Fri Aug 12 22:05:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12942575 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 8059BC25B0F for ; Fri, 12 Aug 2022 22:05:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235912AbiHLWFY (ORCPT ); Fri, 12 Aug 2022 18:05:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231698AbiHLWFX (ORCPT ); Fri, 12 Aug 2022 18:05:23 -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 76BF94C622 for ; Fri, 12 Aug 2022 15:05:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1660341921; bh=PYe43HwPKQzTRJjNn52n7gP1CuESppOZLfs+lpCD3KA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=IFKaUkFGeLCvYPu5vzbCjjmgJvWVbzr9LdJez8xdsIHD2Y/DVzHpX4LN30ww3Gop+kt+1d5RUoyxfarDV2Qm4yK2o6IjjH88rHVrRwUUBGOE89jOrGlZnuQywsKal+Dey78Z7cqbKIlspkLBAi3gDrZOyCcKhkyoCdQtuC4rzk5S2nRfb6Xu7qmf3s6dJNFAfnD88Uu9MGwyRI7nWa5Z0Y86oTuSpUof6bPz3+e0xAuBExyzrLh2jgib27ikCN14iyyjYAav7r+nDLJfnZhFLF56UwdwaOh9p6/7J1ALZKYSc0V0pFsz15Qq7M3pm8VaXb4wcmkZXnKA66r5EdfR2w== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1660341921; bh=Ug3RcSye99YjCtsKm5jteuI8mquFfcXpY+z9mqeyYQX=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=cp0auMe4gpq92spQpKoXOLGvN/RjgknZCZ/cztBlUzk1OJGrOqip3y8HfTB09iQP8vw+QR9NLJq+fw1Fy9mKvTPkdHRvAhl4vGi3z59UI8NSa95C4oH68UhOgNikDnFzMXW8qO2lwVOkYFOqP/ne7YRLVksGvJN/vjRuJO/RBtcF1g7oz2wqKmiyanIUCtZBW1bcSM5JPtvmX+6nUW6BQi3MQxd6k7zHPYtOkfG8JcrJsvmPVc2rgfPMEx9Q78+4/iym/jtxQMNkYr9s5zy84KDPw2FaofBZgzDvMDdCk9xfNR9vJu5RibLMqNt4WW6npswvKNzK04zLs4IhxtzEzA== X-YMail-OSG: FNUoAkYVM1laBS01NJCKE7M5jf69qU6ciT04GnBpN6Y4sos2CGzl7ZFgdDd0vwI Ga7ogzm20DgTkIyAcL3vS3iQJ7nb2W3PsuaJl8eh0ojkNu8Ibe2GLuEJKYaEp90W.lef8GGGd2j1 xdLVaxrzcdQq4H0FrNXlFTb.EIQt3PfDBynWZmIOmRDuC4u65oeT7eso5_gnM5Pw2GAx4FTNjhzM tCvjjnOKilFm1On8LMtZLsp6B.XwWjdM5iNLuSsUWHYClY9RP.qFoxHdqV5c3Zi.mLj5w.7OmGkM E4tz6JvmVqc_qm7y73NAGXwS0SxUwul1D0__2SraTVHXdtYPxYT8wheI3oIONmBkN90dksH17NMj S7vWRDKbZpnc5dkZPpj1fHFI_MpcO2Xeobu3g_0.UPvtZ_NLMUB_PZMoC6pjBXjWFzJPzPzyCCFa U90LD4wpJbH4ZhU8okvZzwoLeORSH8GZuceCEmS7oL5DLunNwuzQESNP.nGFcpeRqHR6tJKZzqwo 6zLJscI47tQA9crtUylXPVPctcH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nmyO7Ei8DAH4ixq6d8grmdI3Kp1nXh65a.KsuZyI5xP E6mBotIwNCCStil5_ITklkQcWRZ8wHllZiAs27aPEOy_BXJu1I3g5YHz_FMpLeT6RGhrfJ443hXg p.nXSBLROUiSm_pPUyrCuAJOXJVceERw1Ll7aoc5eM6eGEptQamO3.3BQoas3KAkZzCdU7yTCbSs 36gWYNdu0bKb57VfZCBD0rWMkf49dhalx4FU0Ktu6JVD.g_ssfQ4eEELzmh4nStGePf9a8iaLB21 eiRk_tl7AdCQnFkFX7D1TuKy5c8g6dRYJnGD6NjJOI6j8K_oOxk23Xfx7Gu1Oc8zf6lGVr_e7dLn G9.tQxNposF73syoZz8YssbVYr4.FczRIFZXIxqkIYcjy.JthVT1pzSomrvTnLsgY4OxEenr1qcv Ki5fDHSzy_Z_2vMSOlJ.o3bIbCwrCgL0.UDXlhv3Y4FoiGR_uThmA5t.TWvAy7qeVffuMrI11lYG KTgjbKpyEx4Hrr9ROIqaqm_vsvBhbN8BEyYqKljSuxhvuSL8CE8uk6abpnEH4P8GE9CXiQpyGrTI IQm.IrBwXeig7Luplj2gu0u_5b810CJRAA8aXOUMUQM5aUnm8UmXhC0fEzsrH0yhqdyULOBzR8_N 8iO_421DSNQXzucxTy2ptqeUL.ERdz22cmtBi_vKynAIVh5NylJJs6zXymhVOeQS7s..y8OKC7Ta 1ObcENuV0MRZca6pHXSLc X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic306.consmr.mail.ir2.yahoo.com with HTTP; Fri, 12 Aug 2022 22:05:21 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-48gl8 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID c89c964524cd385a78dd9672c65b4e57; Fri, 12 Aug 2022 22:05:16 +0000 (UTC) From: Jakob Hauser To: Jonathan Cameron Cc: Lars-Peter Clausen , Linus Walleij , Andy Shevchenko , Hans de Goede , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH v6 11/14] iio: magnetometer: yas530: Add IIO scaling to "chip_info" Date: Sat, 13 Aug 2022 00:05:00 +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 IIO scaling to the "chip_info" structure to ease the handling to different YAS variants. Signed-off-by: Jakob Hauser Reviewed-by: Andy Shevchenko Reviewed-by: Linus Walleij --- 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 fa317b975f8f..af5c090098fb 100644 --- a/drivers/iio/magnetometer/yamaha-yas530.c +++ b/drivers/iio/magnetometer/yamaha-yas530.c @@ -130,6 +130,7 @@ struct yas5xx; * @version_names: version letters or namings * @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; @@ -137,6 +138,7 @@ struct yas5xx_chip_info { char *version_names[2]; const int *volatile_reg; int volatile_reg_qty; + u32 scaling_val2; }; /** @@ -504,27 +506,8 @@ static int yas5xx_read_raw(struct iio_dev *indio_dev, } return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: - switch (ci->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 = ci->scaling_val2; return IIO_VAL_FRACTIONAL; default: /* Unknown request */ @@ -951,6 +934,7 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { .version_names = { "A", "B" }, .volatile_reg = yas530_volatile_reg, .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), + .scaling_val2 = 100000000, /* picotesla to Gauss */ }, [yas532] = { .devid = YAS532_DEVICE_ID, @@ -958,6 +942,7 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { .version_names = { "AB", "AC" }, .volatile_reg = yas530_volatile_reg, .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), + .scaling_val2 = 100000, /* nanotesla to Gauss */ }, [yas533] = { .devid = YAS532_DEVICE_ID, @@ -965,6 +950,7 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { .version_names = { "AB", "AC" }, .volatile_reg = yas530_volatile_reg, .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), + .scaling_val2 = 100000, /* nanotesla to Gauss */ }, }; From patchwork Fri Aug 12 22:05:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12942576 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 12269C28B2C for ; Fri, 12 Aug 2022 22:05:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236062AbiHLWF1 (ORCPT ); Fri, 12 Aug 2022 18:05:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235643AbiHLWF0 (ORCPT ); Fri, 12 Aug 2022 18:05:26 -0400 Received: from sonic301-22.consmr.mail.ir2.yahoo.com (sonic301-22.consmr.mail.ir2.yahoo.com [77.238.176.99]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F9C45FACE for ; Fri, 12 Aug 2022 15:05:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1660341922; bh=jr2xytb/J/2n6Kd3wfYldek1d2bL7GKUO3ekuqQrFmw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=e7sTNEN7W6FMqKzxcT+x1SoTF9UjXmYSY0P/2R4sTjxP8wE9zAFgKdC6oLvCi0C2AxZfAAAdc2WprPKHO1DDtRgrxOAtB39cYCUVuCnHTv/DdWYaJjGxOv2SNEmdAXFu6skpy8LKy+IMujMCHbK1E4fjAXIbKoKfrvtaDpZBuVKIg0B2G/UWpCQlhV0BezJzU3pNp2bjSE8QEmtUD+rOLyacZ6jkmqinyRm/cr1d3RVgV0YYuGrGWXZ488Xuu2C4Bf/ZvpTXdMZdTqVEYZf8vA1JBdj6zzhuXpSZRrw0b4wQSDgtlLthJzGQlwifSUR7zaJwAlUE8nCW3rJV56NIJw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1660341922; bh=88yQBi06fqvxFRvHA8z5fmgPw6cYF6LDK4uthjBdXlk=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=FkO5/IZ8qckWqpqp1/ymXo1+dUIVFYb+mb9IFyDYQhsbPJj3C26p1YK2iGViwDyhs6pbj0Btm7Ky95NbAX+C04qwebZVn+kYyyfSI4DRBn2JUzO+WfKgByOYFCsWbrq6W+xuMLS8LFWKR7bKb6OgymGUV0yTaviZwSUcVmrOcZM38cS6RTPi6RFSZEfmepSiCwKr1lSn4pJMGoCpIyRSYkyaBKfZ0otczEPS9o2n/EX9ubwIvtHGniyp4F00He6tZGqmbf/56bQ+YjhqL9EBRr3BSB3QCu8x0l3VOxbvB8N46qmxsenX6gXwpJ9bA2s3UadhmgH6aQfft2LFyDPVDA== X-YMail-OSG: LlMz71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sWJ.7rB5bIwkVh7r89NIFePbZNIAQOV4Vgofq2icUE_Uot7C0FGb zgwLM3wO812GuL6LvarEX0fVH_k876PtLdzeHKkrAUT82mrK5F55fte8eUpoH3KfFFElK6RX1zqU VePGSDwpvwnVEwyw2hM02MbQSyo.rDHESww6_GbK1DnOuHsBPd5iNVb7C.76_MrLXwztbZMl_Ty. UZCV4T43HsgWQJqU- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ir2.yahoo.com with HTTP; Fri, 12 Aug 2022 22:05:22 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-48gl8 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID c89c964524cd385a78dd9672c65b4e57; Fri, 12 Aug 2022 22:05:21 +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 v6 12/14] iio: magnetometer: yas530: Add temperature calculation to "chip_info" Date: Sat, 13 Aug 2022 00:05:01 +0200 Message-Id: <1a8bffdb7e807455620a73f2d61981e7f9aab8d5.1660337264.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: Linus Walleij --- drivers/iio/magnetometer/yamaha-yas530.c | 123 ++++++++++------------- 1 file changed, 54 insertions(+), 69 deletions(-) diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index af5c090098fb..a5d3f0bff024 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 @@ -131,6 +129,14 @@ 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 20 °C + * @min_temp_x10: starting point of temperature counting in 1/10:s degrees Celsius + * + * The "t_ref" value for YAS532/533 is known from the Android driver. + * For YAS530 it was approximately measured. + * + * The temperatures "min_temp_x10" are derived from the temperature resolutions + * given in the data sheets. */ struct yas5xx_chip_info { unsigned int devid; @@ -139,6 +145,8 @@ struct yas5xx_chip_info { const int *volatile_reg; int volatile_reg_qty; u32 scaling_val2; + u16 t_ref; + s16 min_temp_x10; }; /** @@ -337,6 +345,22 @@ 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) +{ + const struct yas5xx_chip_info *ci = yas5xx->chip_info; + s32 to; + u16 t_ref; + s16 min_temp_x10; + int ref_temp_x10; + + t_ref = ci->t_ref; + min_temp_x10 = ci->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 @@ -352,7 +376,7 @@ static int yas530_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, { const struct yas5xx_chip_info *ci = yas5xx->chip_info; 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; @@ -367,47 +391,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 (ci->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 = ci->t_ref; if (ci->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. @@ -415,36 +422,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 (ci->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: @@ -935,6 +914,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 = 182, /* counts */ + .min_temp_x10 = -620, /* 1/10:s degrees Celsius */ }, [yas532] = { .devid = YAS532_DEVICE_ID, @@ -943,6 +924,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 = 390, /* counts */ + .min_temp_x10 = -500, /* 1/10:s degrees Celsius */ }, [yas533] = { .devid = YAS532_DEVICE_ID, @@ -951,6 +934,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 = 390, /* counts */ + .min_temp_x10 = -500, /* 1/10:s degrees Celsius */ }, }; From patchwork Fri Aug 12 22:05:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12942577 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 8B688C3F6B0 for ; Fri, 12 Aug 2022 22:05:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236078AbiHLWFb (ORCPT ); Fri, 12 Aug 2022 18:05:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231698AbiHLWF3 (ORCPT ); Fri, 12 Aug 2022 18:05:29 -0400 Received: from sonic301-22.consmr.mail.ir2.yahoo.com (sonic301-22.consmr.mail.ir2.yahoo.com [77.238.176.99]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 793FF6DF98 for ; Fri, 12 Aug 2022 15:05:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1660341927; bh=/EKCQ/W045XC71mexb1JnxWPWaTRucbF1YIpPiGxLEM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=r52xUdFMBB07M2RWC62kxXQJzKfv7hifkAWfFD5G9CwTPHTFUu5suZaYe0vUgpEoW2LAX8kc29stD8r7+TFoEzpwk8K8oc7HZX3KZftcIWrRXuRgFbJyJKmvLVWRtHd9Ug+Z5swyhmiMnBnCaz0TMV4FuV4ClrVwuBrMf4mUU9Jz4uaYq36zpftJUmk2fUZ7OGtUHIHlnX9SkBS2+BCOs9qBRewJ4jB6IpKWKEz5lLFo99IHb88JKkitYNyTQidHzBQwzIDnkauuZZnxqtmwQDqWqWRu7qVw1FyjhSN5+T1gej0Hh6cuv8i8ted+I9nVZj8nnnIdEiIbxB/QIO2vwA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1660341927; bh=2fJcbDTsHGUEL4EZYoczl7RhJ/eVs0DPjLnUn9lpd+m=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=G8bbmUVDCdFJRj4GQheLBhf7jaPhXT/qKqYy2y6C67ex0MYMnhcyFbbiBPqzJnHSUvgYXUSHP3ah5arO/QozEzuTpJcHMP8z6s0ehFuQxiUOBMVvAJ+/FCHj4gitR/IfFng7UyA+XyQUBpgf/INkWa6xqix3ZQj0+/ZUfAP0/WHYjKF/cUvLuQz6JS1JWxl5atey/iPI/6xzu98NQ/MH97wqPY108abjMrmH0yA57mHaA6Wo/gOgaEcRW9AVELRUV0fLmpSajv7dlJg9xSdUjghdJee5hYVShC0nrdZxyc7OjOo6I9ODi7Z5R5/LSDMkR4id4q6/ksB8tgsdWFtm7g== X-YMail-OSG: ErQ2Z2EVM1maSiISpRV7IafJutUO5L8E24It31QNYvHtw2ucFNC30SWcRl.ifml yHkp8L.gqGrL49h2TfxuS9DPLHqCfAiUkrNRHylFtfaaMEMP3WqjRU5hj.10RfFuw1DVN8KphGbr P0kQ8.yPAtYvy_xkK1Tyys38y9.3.980yawAuxNeKzXH6yn25tPx5FI65jp0snVXqWX5q3BoReX8 iB8TgYhiBB2J9IS8sBABNqB8vhIwrUQciI.KS0FLOn.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consmr.mail.ir2.yahoo.com with HTTP; Fri, 12 Aug 2022 22:05:27 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-48gl8 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID c89c964524cd385a78dd9672c65b4e57; Fri, 12 Aug 2022 22:05:23 +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 v6 13/14] iio: magnetometer: yas530: Add function pointers to "chip_info" Date: Sat, 13 Aug 2022 00:05:02 +0200 Message-Id: <4bd3f96262e0132b7f9720521a801da3c18abd95.1660337264.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 function 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 (ci->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 Reviewed-by: Linus Walleij --- drivers/iio/magnetometer/yamaha-yas530.c | 66 +++++++++++++++--------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index a5d3f0bff024..18933d8937ae 100644 --- a/drivers/iio/magnetometer/yamaha-yas530.c +++ b/drivers/iio/magnetometer/yamaha-yas530.c @@ -131,6 +131,11 @@ struct yas5xx; * @scaling_val2: scaling value for IIO_CHAN_INFO_SCALE * @t_ref: number of counts at reference temperature 20 °C * @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 * * The "t_ref" value for YAS532/533 is known from the Android driver. * For YAS530 it was approximately measured. @@ -147,12 +152,17 @@ 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_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 @@ -461,7 +471,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 = ci->get_measure(yas5xx, &t, &x, &y, &z); pm_runtime_mark_last_busy(yas5xx->dev); pm_runtime_put_autosuspend(yas5xx->dev); if (ret) @@ -497,11 +507,12 @@ static int yas5xx_read_raw(struct iio_dev *indio_dev, static void yas5xx_fill_buffer(struct iio_dev *indio_dev) { struct yas5xx *yas5xx = iio_priv(indio_dev); + const struct yas5xx_chip_info *ci = yas5xx->chip_info; s32 t, x, y, z; int ret; pm_runtime_get_sync(yas5xx->dev); - ret = yas530_get_measure(yas5xx, &t, &x, &y, &z); + ret = ci->get_measure(yas5xx, &t, &x, &y, &z); pm_runtime_mark_last_busy(yas5xx->dev); pm_runtime_put_autosuspend(yas5xx->dev); if (ret) { @@ -916,6 +927,11 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { .scaling_val2 = 100000000, /* picotesla to Gauss */ .t_ref = 182, /* counts */ .min_temp_x10 = -620, /* 1/10:s degrees Celsius */ + .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, @@ -926,6 +942,11 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { .scaling_val2 = 100000, /* nanotesla to Gauss */ .t_ref = 390, /* counts */ .min_temp_x10 = -500, /* 1/10:s degrees Celsius */ + .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, @@ -936,6 +957,11 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { .scaling_val2 = 100000, /* nanotesla to Gauss */ .t_ref = 390, /* counts */ .min_temp_x10 = -500, /* 1/10:s degrees Celsius */ + .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, }, }; @@ -1007,34 +1033,25 @@ static int yas5xx_probe(struct i2c_client *i2c, goto assert_reset; } - switch (ci->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", ci->devid); + ret = ci->get_calibration_data(yas5xx); + if (ret) goto assert_reset; - } dev_info(dev, "detected %s %s\n", ci->product_name, ci->version_names[yas5xx->version]); - yas530_dump_calibration(yas5xx); - ret = yas530_power_on(yas5xx); - if (ret) - goto assert_reset; - ret = yas530_measure_offsets(yas5xx); + ci->dump_calibration(yas5xx); + + ret = ci->power_on(yas5xx); if (ret) goto assert_reset; + if (ci->measure_offsets) { + ret = ci->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; @@ -1114,6 +1131,7 @@ static int yas5xx_runtime_resume(struct device *dev) { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct yas5xx *yas5xx = iio_priv(indio_dev); + const struct yas5xx_chip_info *ci = yas5xx->chip_info; int ret; ret = regulator_bulk_enable(ARRAY_SIZE(yas5xx->regs), yas5xx->regs); @@ -1130,7 +1148,7 @@ static int yas5xx_runtime_resume(struct device *dev) usleep_range(31000, 40000); gpiod_set_value_cansleep(yas5xx->reset, 0); - ret = yas530_power_on(yas5xx); + ret = ci->power_on(yas5xx); if (ret) { dev_err(dev, "cannot power on\n"); goto out_reset; From patchwork Fri Aug 12 22:05:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12942578 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 AE163C282E7 for ; Fri, 12 Aug 2022 22:05:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236232AbiHLWFd (ORCPT ); Fri, 12 Aug 2022 18:05:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235626AbiHLWFc (ORCPT ); Fri, 12 Aug 2022 18:05:32 -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 6A89073935 for ; Fri, 12 Aug 2022 15:05:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1660341927; bh=rwrJBC1EN3No5MvFpujm/uDVSFGv9ifS8IkWpNzBRm8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=hcMETl6gu8yCjmlgnTY8Nza1aKfJCC4/Sq0EYl6Apyf+c7beA95fRAIS234Eir5XVBTjyqboH2yFD7iCYO7fNRdrNbQWohxxqtsn/uLMtwh5rAumSbV1d/TYUNfy1VBUILEb6XitvjxtVtWZDeBhrFBgqlzrXMxPcf9C5TOQdc2zPEIbEEU5mUuCJW5JNb5NnZyjlEar3itG35BchN0HUkMwWQ0h1gyQ6PenkIKV7oit3NBhHJiBkPdUInd1JEhrV/FN9ePE36DhWn1/gMf1EvS8tZmXe4L4UGQJdgq4Np0QsxHRhIAuwJSYZznbsc6BpJx3ryKpu4MlQbgx88hlsw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1660341927; bh=5kSy/aRPj1svObuf6SHFS4ytNbVyVxOyXpAE7DWAFj9=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=q60QeanD0NaFj6c/QeNsvqQxTSgjhs/VFjJTVDHnL+96XiWb8l/OI1nCk5PEp1pSVcgmeJi+ZzxJALZOmE8kn/fGocLtyOFYJNniCOTlRb5cfHC9J7PuBbqpyin4ibjeKphVS/mqadXwK1qa4HuS9bzBvXyo7HEyinGkmVWHz8wHSdO40AUdtWgNcP87PTr/gDrjq+HB+YqRv/4ZlUacE+lPFYr2hjnzijMDD4c/2yNd7AjeGEcgcms7hi/cR4VxHHB8kW9tv3GYXZnCZ7tDDCuY58irF3HbY4K8/QzBtL+hzrUWw4PMvohKMG1AGRybQ22T7/n3fNQ35Nw+xpvBQA== X-YMail-OSG: wM.pzMEVM1lwchGJ1R3Es.8apy8nDf8QQGcXJgNaJO3fY7k208SYv5TmEMrWacm qQJbX6kU3S9IwsE7q7xeEPwNmel50sU.4lNjxs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o k1e5Lak.gdeGUEO36gHS9cxO01vS5TVr8Kk9Y1Ay6q7c2qKJL.Li0q.2E4AI7pMnFhKES2Qvwe20 U3fdtgQVvsW51zA-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ir2.yahoo.com with HTTP; Fri, 12 Aug 2022 22:05:27 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-48gl8 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID c89c964524cd385a78dd9672c65b4e57; Fri, 12 Aug 2022 22:05:26 +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 v6 14/14] iio: magnetometer: yas530: Add YAS537 variant Date: Sat, 13 Aug 2022 00:05:03 +0200 Message-Id: <264c6488733a5c32089c9ab406a5bcb808c48fef.1660337264.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 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 the 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_v6/drivers/iio/magnetometer/yamaha-yas530.c drivers/iio/magnetometer/Kconfig | 4 +- drivers/iio/magnetometer/yamaha-yas530.c | 422 ++++++++++++++++++++++- 2 files changed, 423 insertions(+), 3 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 18933d8937ae..65bb34c24810 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,6 +136,7 @@ enum chip_ids { yas530, yas532, yas533, + yas537, }; static const int yas530_volatile_reg[] = { @@ -105,6 +144,10 @@ static const int yas530_volatile_reg[] = { YAS530_MEASURE, }; +static const int yas537_volatile_reg[] = { + YAS537_MEASURE, +}; + struct yas5xx_calibration { /* Linearization calibration x, y1, y2 */ s32 r[3]; @@ -138,7 +181,7 @@ struct yas5xx; * @power_on: function pointer to power-on procedure * * The "t_ref" value for YAS532/533 is known from the Android driver. - * For YAS530 it was approximately measured. + * For YAS530 and YAS537 it was approximately measured. * * The temperatures "min_temp_x10" are derived from the temperature resolutions * given in the data sheets. @@ -312,6 +355,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) { @@ -457,6 +571,41 @@ static int yas530_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, return 0; } +/** + * yas537_get_measure() - Measure a sample of all axis and process + * @yas5xx: The device state + * @to: Temperature out + * @xo: X axis out + * @yo: Y axis out + * @zo: Z axis out + * @return: 0 on success or error code + */ +static int yas537_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, s32 *zo) +{ + u16 t, x, y1, y2; + int ret; + + /* We first get raw data that needs to be translated to [x,y,z] */ + ret = yas537_measure(yas5xx, &t, &x, &y1, &y2); + if (ret) + return ret; + + /* Calculate temperature readout */ + *to = yas5xx_calc_temperature(yas5xx, t); + + /* + * Unfortunately, no linearization or temperature compensation formulas + * are known for YAS537. + */ + + /* Calculate x, y, z from x, y1, y2 */ + *xo = (x - BIT(13)) * 300; + *yo = (y1 - y2) * 1732 / 10; + *zo = (-y1 - y2 + BIT(14)) * 300; + + return 0; +} + static int yas5xx_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, @@ -772,6 +921,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) { @@ -796,6 +1141,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) { @@ -917,6 +1282,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, @@ -963,6 +1366,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 = "YAS537 MS-3T", + .version_names = { "v0", "v1" }, /* version naming unknown */ + .volatile_reg = yas537_volatile_reg, + .volatile_reg_qty = ARRAY_SIZE(yas537_volatile_reg), + .scaling_val2 = 100000, /* nanotesla to Gauss */ + .t_ref = 8120, /* counts */ + .min_temp_x10 = -3860, /* 1/10:s degrees Celsius */ + .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, @@ -1170,6 +1588,7 @@ static const struct i2c_device_id yas5xx_id[] = { {"yas530", yas530 }, {"yas532", yas532 }, {"yas533", yas533 }, + {"yas537", yas537 }, {} }; MODULE_DEVICE_TABLE(i2c, yas5xx_id); @@ -1178,6 +1597,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);