From mboxrd@z Thu Jan 1 00:00:00 1970 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 5A920C678D4 for ; Fri, 3 Mar 2023 12:10:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229905AbjCCMKH (ORCPT ); Fri, 3 Mar 2023 07:10:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229676AbjCCMKG (ORCPT ); Fri, 3 Mar 2023 07:10:06 -0500 X-Greylist: delayed 3601 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 03 Mar 2023 04:10:05 PST Received: from mail.gfz-potsdam.de (rz-vm483.gfz-potsdam.de [139.17.229.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 062C1126D0 for ; Fri, 3 Mar 2023 04:10:04 -0800 (PST) Received: from [84.186.206.190] (account andres@gfz-potsdam.de) by gfz-potsdam.de (CommuniGate Pro WEBUSER 7.1.3) with HTTP id 1200298; Fri, 03 Mar 2023 12:10:00 +0100 From: "Andres Heinloo" Subject: Bugs in dps310 Linux driver To: "Jonathan Cameron" Cc: "Eddie James" , linux-iio@vger.kernel.org X-Mailer: CommuniGate Pro WebUser v7.1.3 Date: Fri, 03 Mar 2023 12:10:00 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain;charset=utf-8; format="flowed" Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Hello, I've been struggling with the dps310 driver, which gives incorrect pressure values and in particular different values than manufacturers code (https://github.com/Infineon/RaspberryPi_DPS). I think I've found where the problem is. Firstly, there is a mistake in bit numbering at https://github.com/torvalds/linux/blob/857f1268a591147f7be7509f249dbb3aba6fc65c/drivers/iio/pressure/dps310.c#L51 According to datasheet, correct is: #define DPS310_INT_HL BIT(7) #define DPS310_TMP_SHIFT_EN BIT(3) #define DPS310_PRS_SHIFT_EN BIT(2) #define DPS310_FIFO_EN BIT(1) #define DPS310_SPI_EN BIT(0) Eg., the current code is using wrong bit (4) for DPS310_PRS_SHIFT_EN, which means that pressure shift is never enabled. Secondly, there is a problem with overflows starting at https://github.com/torvalds/linux/blob/857f1268a591147f7be7509f249dbb3aba6fc65c/drivers/iio/pressure/dps310.c#L654 Since p is a 24-bit value, nums[3] = p * p * p * (s64)data->c30; can and does overflow. Second overflow problem is at https://github.com/torvalds/linux/blob/857f1268a591147f7be7509f249dbb3aba6fc65c/drivers/iio/pressure/dps310.c#L684 In fact, I don't understand why 1000000000LL is needed. Since only 7 values are summed, using 10LL should give the same precision. Best regards, Andres