Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2568774rwb; Mon, 15 Aug 2022 07:34:02 -0700 (PDT) X-Google-Smtp-Source: AA6agR5mxUHKW6W+JupyQwwlqyR/FbkEE06CLNF/iJOTW3nAsUouoSQeo3EHR0WBkqqlGiW4Gwib X-Received: by 2002:a05:6402:d05:b0:425:b7ab:776e with SMTP id eb5-20020a0564020d0500b00425b7ab776emr15539396edb.142.1660574042408; Mon, 15 Aug 2022 07:34:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660574042; cv=none; d=google.com; s=arc-20160816; b=NW6nmtxSSmgu+qS0jiL7DKxN3/VVo2uxK/9S4m0t0Y/cPiq64ASD9Qoq4bZbU71tWp guTs22fhFIq+4Q6LK7C58VORHLrKprbGxl/3S/ts6rwer8ocuXL33A5SJJaar+bJ+blb MnbEI5on0vL8MgNeU9JDLCFagfnU0o3hQA584DLi9xYQgyUCDyahpNluOJ1VoDVxyPmJ 71JFG2c1Xb3d+i/QYhQprstvuzIGeYN1wgBXet2sJ6t4enlFp+eemIC4KGqKn8qFF5J/ x/7N0lQQw7EPipcC5H03Ml5AhrmJ+DAeyXs3bS/GkLu92/8wOhqLcAkDGpTifvh0e8kM v4tQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=oyXLuDwoqKoBqtixFcLUxvAdEJpipLRmAoin7itaNu4=; b=KF0pKwdGqiSo8IhS0cHwc/l0afAStNWPqetFpJ4XfYyPSIcdJua6l5V8qDvdr0hAxM zuZ6EhUphpZr+oUnrDF/NkAEREuH/spm7kVGdu5HzY4CnZ0kuiOD+PtUEiYN70oNRzrO /jjrGA13p2QjK0k8zy3TcO+MT/hBHieLhDMaVP/if81OxzA631hK/DsHK0njTrB2W56z OT2PQCQn+G3HHMC/Uqug/3zVhRWk+xys5+D8UPOPaV4FstgJkBPGZcJIBhvwhhkH59Qr 6VomivXXGoIWZApMt/SEaTnE3/yjwKve1jcmxlTD3LJNu+zuz+Ht/gVznDkpGdhHsmGj WR6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=kHdRad97; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f14-20020a0564021e8e00b0043d4a5ee1a8si8760528edf.577.2022.08.15.07.33.30; Mon, 15 Aug 2022 07:34:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=kHdRad97; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233268AbiHON7a (ORCPT + 99 others); Mon, 15 Aug 2022 09:59:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231778AbiHON72 (ORCPT ); Mon, 15 Aug 2022 09:59:28 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC30922B23; Mon, 15 Aug 2022 06:59:26 -0700 (PDT) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27FDhZRC010502; Mon, 15 Aug 2022 13:59:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=oyXLuDwoqKoBqtixFcLUxvAdEJpipLRmAoin7itaNu4=; b=kHdRad97OBPdppFHAtUUKwazvszb+Ed1qRuHDoWeVXFbB8H3VTeEmpyZT9de4fxpzcDH VS/Egyka1MzYlZmojnbxayWa2p0xrc3/zilxgejklkbVVMJXFbLl4n9LSnR1wepvVIfG 0IpiwS17q4GFDlR5ZAAINXrUHeaLo0guvqGLE9hOUg3n3SD1q1+SXtiW9Okzdezro8bL QOoXCe+fS6u0Kqhk8lfaqbeUMwP5OyQRvp/KlKqzy2sS5Nnce2hz/gI9fTYGJOo4uzSA /1eufCnGlSJKkrbdfdydWY0FLnMDc//pDcXl219DKSr4ehjK2T2eyZMCBFJjDKIk1Phi iQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hyq9h0cxg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 15 Aug 2022 13:59:06 +0000 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 27FDiK5v014684; Mon, 15 Aug 2022 13:59:06 GMT Received: from ppma02wdc.us.ibm.com (aa.5b.37a9.ip4.static.sl-reverse.com [169.55.91.170]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hyq9h0cw1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 15 Aug 2022 13:59:06 +0000 Received: from pps.filterd (ppma02wdc.us.ibm.com [127.0.0.1]) by ppma02wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 27FDnjqM014593; Mon, 15 Aug 2022 13:59:04 GMT Received: from b01cxnp23032.gho.pok.ibm.com (b01cxnp23032.gho.pok.ibm.com [9.57.198.27]) by ppma02wdc.us.ibm.com with ESMTP id 3hx3k9m91d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 15 Aug 2022 13:59:04 +0000 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 27FDx4RK1507942 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 15 Aug 2022 13:59:04 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F2B14B205F; Mon, 15 Aug 2022 13:59:03 +0000 (GMT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 80DCAB2064; Mon, 15 Aug 2022 13:59:03 +0000 (GMT) Received: from [9.77.146.160] (unknown [9.77.146.160]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP; Mon, 15 Aug 2022 13:59:03 +0000 (GMT) Message-ID: Date: Mon, 15 Aug 2022 08:59:03 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v4 2/2] iio: pressure: dps310: Reset chip if MEAS_CFG is corrupt Content-Language: en-US To: Andy Shevchenko Cc: linux-iio , Jonathan Cameron , Lars-Peter Clausen , Linux Kernel Mailing List , Joel Stanley References: <20220809211246.251006-1-eajames@linux.ibm.com> <20220809211246.251006-3-eajames@linux.ibm.com> From: Eddie James In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: eFzUiPUmn3NZt_6_sBugfKfki2IlSf4G X-Proofpoint-GUID: vYziDs7p1oPGlA5fHTRZq0IjfzH4MXk- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-15_08,2022-08-15_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 lowpriorityscore=0 malwarescore=0 clxscore=1015 bulkscore=0 spamscore=0 mlxlogscore=999 phishscore=0 mlxscore=0 impostorscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208150053 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/12/22 17:13, Andy Shevchenko wrote: > On Wed, Aug 10, 2022 at 12:12 AM Eddie James wrote: >> Corruption of the MEAS_CFG register has been observed soon after >> system boot. In order to recover this scenario, check MEAS_CFG if >> measurement isn't ready, and if it's incorrect, reset the DPS310 >> and execute the startup procedure. > Looks like both patches miss the Fixes tag. Can you add them? Well this isn't really a software fix - there's no identifiable bug in the driver. Just trying to recover the chip in this observed mystery scenario. > > ... > >> +/* >> + * Called with lock held. Returns a negative value on error, a positive value >> + * when the device is not ready, and zero when the device is ready. >> + */ >> +static int dps310_check_reset_meas_cfg(struct dps310_data *data, int ready_bit) >> +{ >> + int meas_cfg; >> + int rc = regmap_read(data->regmap, DPS310_MEAS_CFG, &meas_cfg); >> + >> + if (rc < 0) >> + return rc; > Please, split definition and assignment. Ack. > >> + /* Device is ready, proceed to measurement */ >> + if (meas_cfg & ready_bit) >> + return 0; >> + >> + /* Device is OK, just not ready */ >> + if (meas_cfg & (DPS310_PRS_EN | DPS310_TEMP_EN | DPS310_BACKGROUND)) >> + return 1; >> + >> + /* DPS310 register state corrupt, better start from scratch */ >> + rc = regmap_write(data->regmap, DPS310_RESET, DPS310_RESET_MAGIC); >> + if (rc < 0) >> + return rc; >> + >> + /* Wait for device chip access: 2.5ms in specification */ >> + usleep_range(2500, 12000); >> + >> + /* Reinitialize the chip */ >> + rc = dps310_startup(data); >> + if (rc) >> + return rc; >> + >> + dev_info(&data->client->dev, >> + "recovered from corrupted MEAS_CFG=%02x\n", meas_cfg); >> + return 1; >> +} >> + >> static int dps310_read_pres_raw(struct dps310_data *data) >> { >> int rc; >> @@ -405,16 +443,26 @@ static int dps310_read_pres_raw(struct dps310_data *data) >> if (mutex_lock_interruptible(&data->lock)) >> return -EINTR; >> >> - rate = dps310_get_pres_samp_freq(data); >> - timeout = DPS310_POLL_TIMEOUT_US(rate); >> - >> - /* Poll for sensor readiness; base the timeout upon the sample rate. */ >> - rc = regmap_read_poll_timeout(data->regmap, DPS310_MEAS_CFG, ready, >> - ready & DPS310_PRS_RDY, >> - DPS310_POLL_SLEEP_US(timeout), timeout); >> - if (rc) >> + rc = dps310_check_reset_meas_cfg(data, DPS310_PRS_RDY); >> + if (rc < 0) >> goto done; >> >> + if (rc > 0) { >> + rate = dps310_get_pres_samp_freq(data); >> + timeout = DPS310_POLL_TIMEOUT_US(rate); >> + >> + /* >> + * Poll for sensor readiness; base the timeout upon the sample >> + * rate. >> + */ >> + rc = regmap_read_poll_timeout(data->regmap, DPS310_MEAS_CFG, >> + ready, ready & DPS310_PRS_RDY, >> + DPS310_POLL_SLEEP_US(timeout), >> + timeout); >> + if (rc) >> + goto done; >> + } > If you split the condition body to a helper, it can be rewritten like > (also note special definition for positive returned numbers): > > rc = ..._reset_meas_cfg(...); > if (rc == DPS310_MEAS_NOT_READY) > rc = ..._new_helper_func(...); > if (rc) > goto done; > > and looking at this it might be worth considering calling that > conditional in the middle in the _reset_meas_cfg(), so the latter will > return either 0 or negative error code. To be honest that looks more complicated than the way it is now? And I don't think I can make it common between the temp and pressure without some complicated macro business. > >> + rc = dps310_check_reset_meas_cfg(data, DPS310_TMP_RDY); >> if (rc < 0) >> goto done; >> >> + if (rc > 0) { >> + rate = dps310_get_temp_samp_freq(data); > Okay, I see this function is different, but still you may realize a > helper from below and something like above suggestion can still be > achieved. > >> + timeout = DPS310_POLL_TIMEOUT_US(rate); >> + >> + /* >> + * Poll for sensor readiness; base the timeout upon the sample >> + * rate. >> + */ >> + rc = regmap_read_poll_timeout(data->regmap, DPS310_MEAS_CFG, >> + ready, ready & DPS310_TMP_RDY, >> + DPS310_POLL_SLEEP_US(timeout), >> + timeout); >> + if (rc < 0) > Why out of a sudden ' < 0'? Good point, I'll fix that. > >> + goto done; >> + } > As per above. > >> rc = dps310_read_temp_ready(data); >