From patchwork Sun Aug 7 23:02:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 12938401 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46166C25B0D for ; Sun, 7 Aug 2022 23:03:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231964AbiHGXDu (ORCPT ); Sun, 7 Aug 2022 19:03:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234117AbiHGXDr (ORCPT ); Sun, 7 Aug 2022 19:03:47 -0400 Received: from sonic308-19.consmr.mail.ir2.yahoo.com (sonic308-19.consmr.mail.ir2.yahoo.com [77.238.178.147]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 937092BD1 for ; Sun, 7 Aug 2022 16:03:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1659913424; bh=EuFGkupLjx9zPeG1GfBnRcBvJL6CsBo11j9xvtKmu7w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=r10zRAa1E7+U+H3e+xn3yYVp/HhRH0Oq3RjXv6xENVoMJaLWVsCHEQrR0bZLvY8NTmQATq/Ky6psZI1xwD8WxM0oJd39Mmsek6tckiVCSlQZuuceYgtCT11zatrhVWDvSgTJr2EtXBK8eRDMtPvVoIXiUpUsk8dpk1jjeMpACVV6C7/44psaJiIEn1xz6jhpCVkmOrYJ3WYlUNBl9CzY7pDI/TMceyqQJXDWZbamrecaD5DArXC+kdpB0o90ZtFD97iFhPOcdlvwZZIJJRTLuG13dU/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HhSur0 U37gGv.HcVYZSW12lYKXQ1RAuIOL_fLz.LvSw38p.cGLyBBzKnb0j3vh5xYC_x87kQnYShOpQMRK Yjrtk67IUhjYVpda.e4QNy38uodFNIwVv.gdlVXVdgp7ajSQbtrAzLtMDITJqSibW3mvnJ5kpfRl IMEWqqixtk6Pu0xEpzdXXjvRRh0IL_4lOsIlg8E7KYQ.8M2OXTL4A_iRVq_JVHFVkqP6tDdR9y52 Y7uEHk2MYNLQ2KcayqzbtFDae0KYxP9RrryFkOetjgHkhnVYTcpFBBh4outpR_xiRW8vdziIdsMk vPHA1paRlOnqlhVeb2TgSCfQ183obTuXbV7wC54Zl.tE3BecsKQIaCiBqMcXpm4wdFQj6MRG9v.x RhmTjML_bOZHEp5RivKciI1HOh8TRS05hwZbXvck1.skK4G7knSvZwXtLLaErncBCHAEqX569S45 k.IobEAkyb56NntLSa2puJHmd.ooAC8ffMwHUQrwlNdOuzft61HScMFlMyrYEh_RHn68LsWRjXtg vmp7K0TFTZymbZ6BUlpkTrc3h0rV7V01ypBUma2jrDxUWn2QhCzEWz0hCqAntSZFcxFae6rNnItc iIBPRpJas8EcpGw1mB_bE_jUGDOFK0OvQQf7B6npjSPwiP47YpS4qVFEQtTD6s7Qscgh66jvP_N9 2Z3Yyy.kg06AdFbZWYzCMsyXq7sCCT5zachsXWNR1kPjpmdJQ6Sh2q9pPu_QvcEueLpkhV_jX_AW 7EWpFVCqfMwU634VeFTg- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic308.consmr.mail.ir2.yahoo.com with HTTP; Sun, 7 Aug 2022 23:03:44 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-r76pr (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 12b0bfa600682cb6edf92800aaf76d46; Sun, 07 Aug 2022 23:03:42 +0000 (UTC) From: Jakob Hauser To: Jonathan Cameron Cc: Lars-Peter Clausen , Linus Walleij , Andy Shevchenko , Hans de Goede , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH v5 03/14] iio: magnetometer: yas530: Correct scaling of magnetic axes Date: Mon, 8 Aug 2022 01:02:08 +0200 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Looks like YAS530 raw values return picotesla and YAS532 nanotesla. Adapt comments and scaling. Signed-off-by: Jakob Hauser Reviewed-by: Linus Walleij Reviewed-by: Andy Shevchenko --- drivers/iio/magnetometer/yamaha-yas530.c | 31 ++++++++++++++++-------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index 6fa29b96c013..8cad724fb328 100644 --- a/drivers/iio/magnetometer/yamaha-yas530.c +++ b/drivers/iio/magnetometer/yamaha-yas530.c @@ -310,8 +310,6 @@ static s32 yas5xx_linearize(struct yas5xx *yas5xx, u16 val, int axis) * @yo: Y axis out * @zo: Z axis out * @return: 0 on success or error code - * - * Returned values are in nanotesla according to some code. */ static int yas5xx_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, s32 *zo) { @@ -417,14 +415,27 @@ static int yas5xx_read_raw(struct iio_dev *indio_dev, *val = 1; return IIO_VAL_INT; } - /* - * The axis values are in nanotesla according to the vendor - * drivers, but is clearly in microtesla according to - * experiments. Since 1 uT = 0.01 Gauss, we need to divide - * by 100000000 (10^8) to get to Gauss from the raw value. - */ - *val = 1; - *val2 = 100000000; + switch (yas5xx->devid) { + case YAS530_DEVICE_ID: + /* + * Raw values of YAS530 are in picotesla. Divide by + * 100000000 (10^8) to get Gauss. + */ + *val = 1; + *val2 = 100000000; + break; + case YAS532_DEVICE_ID: + /* + * Raw values of YAS532 are in nanotesla. Divide by + * 100000 (10^5) to get Gauss. + */ + *val = 1; + *val2 = 100000; + break; + default: + dev_err(yas5xx->dev, "unknown device type\n"); + return -EINVAL; + } return IIO_VAL_FRACTIONAL; default: /* Unknown request */