From patchwork Wed Dec 9 23:48:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Belloni X-Patchwork-Id: 11962859 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DBBD3C433FE for ; Wed, 9 Dec 2020 23:50:51 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A095A23B51 for ; Wed, 9 Dec 2020 23:50:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A095A23B51 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bootlin.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=MWTPmgyEbWUFT6XZN7Wh1evV/1KSSVPaGCJaRwxvRyM=; b=ON5J6ZuiQmMn8VRenva9Qd4vC bm18GM+7QfQaqUB06igyN9eXKoYg9zsLpfm1uqFwgcdi3AYbJBAgqhqx8fwl/oKEtzd8sjLUNJPgo FlPqOgB52vIArjoqYfgW0CCgafpt3cfjceHe5Nu3DPYNgZGCqArkM6JMC8R8DrLq25b2ruEEVu8Br Kfz9fm/OHzcSk9Qnele3kBuplp7QYIg0DzLbJWVKCvWn9mBFe0Hcm+s/WFL2nZaeMrTcBaz2CXsO0 oCEziLn6nifC9O5NQ6E9BYE9HpW26nPkp3y/+TeFbnHMJOcs8N2I7hEBJ35YnZjgc7O7s4uw18Evz g2tSl0G7Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kn9Cw-0000Nf-Cl; Wed, 09 Dec 2020 23:49:18 +0000 Received: from relay1-d.mail.gandi.net ([217.70.183.193]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kn9Cm-0000LA-RY for linux-arm-kernel@lists.infradead.org; Wed, 09 Dec 2020 23:49:10 +0000 X-Originating-IP: 86.194.74.19 Received: from localhost (lfbn-lyo-1-997-19.w86-194.abo.wanadoo.fr [86.194.74.19]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 797F3240007; Wed, 9 Dec 2020 23:49:07 +0000 (UTC) From: Alexandre Belloni To: Jonathan Cameron Subject: [PATCH 4/6] iio:common:ms_sensors:ms_sensors_i2c: rework CRC calculation helper Date: Thu, 10 Dec 2020 00:48:55 +0100 Message-Id: <20201209234857.1521453-5-alexandre.belloni@bootlin.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201209234857.1521453-1-alexandre.belloni@bootlin.com> References: <20201209234857.1521453-1-alexandre.belloni@bootlin.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201209_184909_130620_5095C34D X-CRM114-Status: GOOD ( 15.91 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Alexandre Belloni , Lars-Peter Clausen , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Meerwald-Stadler , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The CRC calculation always happens on 8 words which is why there is an extra element in the prom array of struct ms_tp_dev. However, on ms5637 and similar, only 7 words are readable. Then, set MS_SENSORS_TP_PROM_WORDS_NB to 8 and stop passing a len parameter to ms_sensors_tp_crc_valid as this simply hide the fact that it is hardcoded. Finally, use the newly introduced hw->prom_len to know how many words can be read. Signed-off-by: Alexandre Belloni --- drivers/iio/common/ms_sensors/ms_sensors_i2c.c | 12 +++++------- drivers/iio/common/ms_sensors/ms_sensors_i2c.h | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/iio/common/ms_sensors/ms_sensors_i2c.c b/drivers/iio/common/ms_sensors/ms_sensors_i2c.c index b9e2038d05ef..872f90459e2e 100644 --- a/drivers/iio/common/ms_sensors/ms_sensors_i2c.c +++ b/drivers/iio/common/ms_sensors/ms_sensors_i2c.c @@ -493,19 +493,18 @@ EXPORT_SYMBOL(ms_sensors_ht_read_humidity); * This function is only used when reading PROM coefficients * * @prom: pointer to PROM coefficients array - * @len: length of PROM coefficients array * * Return: True if CRC is ok. */ -static bool ms_sensors_tp_crc_valid(u16 *prom, u8 len) +static bool ms_sensors_tp_crc_valid(u16 *prom) { unsigned int cnt, n_bit; u16 n_rem = 0x0000, crc_read = prom[0], crc = (*prom & 0xF000) >> 12; - prom[len - 1] = 0; + prom[MS_SENSORS_TP_PROM_WORDS_NB - 1] = 0; prom[0] &= 0x0FFF; /* Clear the CRC computation part */ - for (cnt = 0; cnt < len * 2; cnt++) { + for (cnt = 0; cnt < MS_SENSORS_TP_PROM_WORDS_NB * 2; cnt++) { if (cnt % 2 == 1) n_rem ^= prom[cnt >> 1] & 0x00FF; else @@ -537,7 +536,7 @@ int ms_sensors_tp_read_prom(struct ms_tp_dev *dev_data) { int i, ret; - for (i = 0; i < MS_SENSORS_TP_PROM_WORDS_NB; i++) { + for (i = 0; i < dev_data->hw->prom_len; i++) { ret = ms_sensors_read_prom_word( dev_data->client, MS_SENSORS_TP_PROM_READ + (i << 1), @@ -547,8 +546,7 @@ int ms_sensors_tp_read_prom(struct ms_tp_dev *dev_data) return ret; } - if (!ms_sensors_tp_crc_valid(dev_data->prom, - MS_SENSORS_TP_PROM_WORDS_NB + 1)) { + if (!ms_sensors_tp_crc_valid(dev_data->prom)) { dev_err(&dev_data->client->dev, "Calibration coefficients crc check error\n"); return -ENODEV; diff --git a/drivers/iio/common/ms_sensors/ms_sensors_i2c.h b/drivers/iio/common/ms_sensors/ms_sensors_i2c.h index f4a88148c113..f15b973f27c6 100644 --- a/drivers/iio/common/ms_sensors/ms_sensors_i2c.h +++ b/drivers/iio/common/ms_sensors/ms_sensors_i2c.h @@ -11,7 +11,7 @@ #include #include -#define MS_SENSORS_TP_PROM_WORDS_NB 7 +#define MS_SENSORS_TP_PROM_WORDS_NB 8 /** * struct ms_ht_dev - Humidity/Temperature sensor device structure @@ -47,7 +47,7 @@ struct ms_tp_dev { struct i2c_client *client; struct mutex lock; const struct ms_tp_hw_data *hw; - u16 prom[MS_SENSORS_TP_PROM_WORDS_NB + 1]; + u16 prom[MS_SENSORS_TP_PROM_WORDS_NB]; u8 res_index; };