Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2044635pxu; Sun, 13 Dec 2020 11:39:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJzNx4nUGqLQZj8nwsfe83zNaE2YmHQO0caQSf3DExbFRaZZ2yp0WgC0biMLHQhK4K1rzne+ X-Received: by 2002:a05:6402:16c8:: with SMTP id r8mr21415958edx.59.1607888372306; Sun, 13 Dec 2020 11:39:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607888372; cv=none; d=google.com; s=arc-20160816; b=EycQQ98A0ZQdQtkfEWzSskwxq3uF8qEVfD6DcZlPKxIkKLj5v3FcpccwR8nHrbc61r yXoFxnLagac0gKMb2ZFux1P2P9CIgNtiLufCraNrzFcDka39rxzk+jyzVGhp1ptz8ynV FWINFzmEVvDPMzTJZQ8nngpZFWCBRSde9xlgephkFavjz1oM+MdtzLOgr/QODcRouNEl Lom4gyhFZ02QQB/+fPoZWAFZWhS1aEx8aDwlUhRasJpQ7LzpFvbnQpK6O5fb/RbeRVmF 1kdgNXIHY+99lIPiVuUgOYWRMoaUSzFUh0Co+HpI03VRKbuIpe1yiM5RhPHlW0GcSIGj t1Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=8lCqSgcwOcGgKvSkJSt6n3lIpZBGbPV130IBgN+7OUA=; b=NpQfB8tbV43quebcGpKicwVqEPOcPQqmunz9X1AMsi6k1dPUl+tdunzs6Hp9MiVeIk 1CIUd/XSgX38KDWLoeZBWdkefAmc3K//ZQmtSO5dps5bKLX+ck5Bdm4W7ffCVcIp7U4s vIiGHjGin3ntc/3a9+8j6MaTtz2uyBazVOaF+pmDkVECQRZKr6Y6I6Bbzgv7kTYcUWar We+GYDViM/G811sh7dPZXcVRp1p8IKAgBWL6JpgjVkxE8ZOvZ1bCw8M+B4jjS8fQVDEW PYx/q1YcaaoVuORuL8xGK/zVy0jXnakSV3yW77NWNk2ffpjNl2ep/wzsvyKLr4R2I9gk IVhg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l89si10719405ede.577.2020.12.13.11.39.08; Sun, 13 Dec 2020 11:39:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728853AbgLMTfU (ORCPT + 99 others); Sun, 13 Dec 2020 14:35:20 -0500 Received: from relay12.mail.gandi.net ([217.70.178.232]:37243 "EHLO relay12.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727909AbgLMTfU (ORCPT ); Sun, 13 Dec 2020 14:35:20 -0500 Received: from localhost (lfbn-lyo-1-997-19.w86-194.abo.wanadoo.fr [86.194.74.19]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay12.mail.gandi.net (Postfix) with ESMTPSA id B61F8200003; Sun, 13 Dec 2020 19:34:36 +0000 (UTC) Date: Sun, 13 Dec 2020 20:34:36 +0100 From: Alexandre Belloni To: Jonathan Cameron Cc: Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 5/6] iio:common:ms_sensors:ms_sensors_i2c: add support for alternative PROM layout Message-ID: <20201213193436.GM1781038@piout.net> References: <20201209234857.1521453-1-alexandre.belloni@bootlin.com> <20201209234857.1521453-6-alexandre.belloni@bootlin.com> <20201213172042.76b2e028@archlinux> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201213172042.76b2e028@archlinux> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 13/12/2020 17:20:42+0000, Jonathan Cameron wrote: > > +/** > > + * ms_sensors_tp_crc_valid_112() - CRC check function for > > + * Temperature and pressure devices for 112bit PROM. > > + * This function is only used when reading PROM coefficients > > + * > > + * @prom: pointer to PROM coefficients array > > + * > > + * Return: CRC. > > That's a bit confusing. Perhaps return if CRC correct > Sometimes CRC is used to refer to particular bits and sometimes > to the check (i.e. whether it is right). > Roght, this should have been "Return: True if CRC is ok." > > + */ > > +static bool ms_sensors_tp_crc_valid_112(u16 *prom) > > +{ > > + u16 w0 = prom[0], crc_read = (w0 & 0xF000) >> 12; > > + u8 crc; > > + > > + prom[0] &= 0x0FFF; /* Clear the CRC computation part */ > > + prom[MS_SENSORS_TP_PROM_WORDS_NB - 1] = 0; > > + > > + crc = ms_sensors_tp_crc4(prom); > > + > > + prom[0] = w0; > > + > > + return crc == crc_read; > > +} > > + > > +/** > > + * ms_sensors_tp_crc_valid_128() - CRC check function for > > + * Temperature and pressure devices for 128bit PROM. > > + * This function is only used when reading PROM coefficients > > + * > > + * @prom: pointer to PROM coefficients array > > + * > > + * Return: CRC. > > + */ > > +static bool ms_sensors_tp_crc_valid_128(u16 *prom) > > +{ > > + u16 w7 = prom[7], crc_read = w7 & 0x000F; > > + u8 crc; > > + > > + prom[7] &= 0xFF00; /* Clear the CRC and LSB part */ > > + > > + crc = ms_sensors_tp_crc4(prom); > > + > > + prom[7] = w7; > > + > > + return crc == crc_read; > > } > > > > /** > > @@ -535,6 +577,7 @@ static bool ms_sensors_tp_crc_valid(u16 *prom) > > int ms_sensors_tp_read_prom(struct ms_tp_dev *dev_data) > > { > > int i, ret; > > + bool valid; > > > > for (i = 0; i < dev_data->hw->prom_len; i++) { > > ret = ms_sensors_read_prom_word( > > @@ -546,7 +589,12 @@ int ms_sensors_tp_read_prom(struct ms_tp_dev *dev_data) > > return ret; > > } > > > > - if (!ms_sensors_tp_crc_valid(dev_data->prom)) { > > + if (dev_data->hw->prom_len == 8) > > + valid = ms_sensors_tp_crc_valid_128(dev_data->prom); > > + else > > + valid = ms_sensors_tp_crc_valid_112(dev_data->prom); > > + > > + if (!valid) { > > dev_err(&dev_data->client->dev, > > "Calibration coefficients crc check error\n"); > > return -ENODEV; > -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com