Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp313865ybm; Wed, 22 May 2019 03:43:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqwEGYoPzyhNvx+Z3uV70Atb8ZD4npFs4TVqjkOJdHYFLpTJDQz4g2EdPc5d6//Arxd9xPLx X-Received: by 2002:a62:4118:: with SMTP id o24mr64148360pfa.17.1558521802194; Wed, 22 May 2019 03:43:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558521802; cv=none; d=google.com; s=arc-20160816; b=LnTrUQPWXR7R/8wGf36hcoJHKfZW29+JVVh51kSX3TGw8yJnVdXDPhKv3pFU+lhCwf xLcMQU5/JWROl1fDgtYWJscf1lOYQdteyD7X4+hBCM+m2f8E6EIyw6NiJF3VYgnpXT7i 4uCqGKK0JMtdB0FazOsuOWGNVl8NxBpdiXrtoV3QS/Pap2vPK82qumQn1fHoELTej1eS E/rLwG0LeD+9w0fPNdBB6o+gSeqDnXxpXyiwZCwe/Q1sMKhi5uZb4tFYlohaiY9GtSKo /YSRfgvNQROHhCHayCx+FVYjba5UgLZHdyeajMfsBgG1vHb0eh/M4akfrKf5h9LR71Jh WDNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:cc:to:from; bh=Myw0PB/PSPc6zohGIlgDqlF+LDVeS7aIPUxOHwVzJWU=; b=s+DD8JjNELxZDfufTOSrL17qiTI2LHnegb5S0hrQnZxfJE8QCdkXq1g0L3czf63D/D j1BWcf2HaHbJ9cY1zlI8pSxyWPvsuMmtPLfjTvudq4RzPSG3wHDUwOeOPbhIhaOIm5FW pUUw0U5B5jj7tyBB1H9le8K4zCoXRJZUM7e//tW5vzCxC17tevtOVokpVOUU/q6pX0OB xI3woAVkmIPjK4n6oD1+tncjXBzvbMJWVTgeLuGcfmKbhSl4ejCyAcrugD196Z7fnlxZ PJRcucTFDHVhKvjZ2SAh81DArjTX0EToZhr9ErnJKKU/oq7bJTFOBcqyK5LspdI7m7pQ 7ESw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=REJECT dis=NONE) header.from=skyboo.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y63si20054392pgd.567.2019.05.22.03.43.07; Wed, 22 May 2019 03:43:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=REJECT dis=NONE) header.from=skyboo.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729155AbfEVKk7 (ORCPT + 99 others); Wed, 22 May 2019 06:40:59 -0400 Received: from skyboo.net ([94.40.87.198]:47838 "EHLO skyboo.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728690AbfEVKk6 (ORCPT ); Wed, 22 May 2019 06:40:58 -0400 Received: from manio by skyboo.net with local (Exim 4.91) (envelope-from ) id 1hTOg3-0003zI-Ln; Wed, 22 May 2019 12:40:56 +0200 From: Mariusz Bialonczyk To: linux-kernel@vger.kernel.org, Greg Kroah-Hartman Cc: Mariusz Bialonczyk Date: Wed, 22 May 2019 12:40:53 +0200 Message-Id: <20190522104053.14577-1-manio@skyboo.net> X-Mailer: git-send-email 2.19.0.rc1 In-Reply-To: <20190520070558.20142-3-manio@skyboo.net> References: <20190520070558.20142-3-manio@skyboo.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: X-SA-Exim-Rcpt-To: linux-kernel@vger.kernel.org, greg@kroah.com, manio@skyboo.net X-SA-Exim-Mail-From: manio@skyboo.net X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on nemesis.skyboo.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NO_RELAYS autolearn=ham autolearn_force=no version=3.4.1 Subject: [PATCH 3/4 v2] w1: ds2413: when the slave is not responding during read, select it again X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on skyboo.net) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The protocol is not allowing to obtain a byte of 0xff for PIO_ACCESS_READ call. It is very likely that the slave was not addressed properly and it is just not respoding (leaving the bus in logic high state) during the read of sampled PIO value. We cannot just call w1_reset_resume_command() because the problem will persist, instead try selecting (addressing) the slave again. Signed-off-by: Mariusz Bialonczyk --- Changes in v2: Optimize the if statement so the most common is checked first. drivers/w1/slaves/w1_ds2413.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/w1/slaves/w1_ds2413.c b/drivers/w1/slaves/w1_ds2413.c index d63778c70568..21f08ac8a4e0 100644 --- a/drivers/w1/slaves/w1_ds2413.c +++ b/drivers/w1/slaves/w1_ds2413.c @@ -24,6 +24,7 @@ #define W1_F3A_FUNC_PIO_ACCESS_READ 0xF5 #define W1_F3A_FUNC_PIO_ACCESS_WRITE 0x5A #define W1_F3A_SUCCESS_CONFIRM_BYTE 0xAA +#define W1_F3A_INVALID_PIO_STATE 0xFF static ssize_t state_read(struct file *filp, struct kobject *kobj, struct bin_attribute *bin_attr, char *buf, loff_t off, @@ -45,6 +46,7 @@ static ssize_t state_read(struct file *filp, struct kobject *kobj, mutex_lock(&sl->master->bus_mutex); dev_dbg(&sl->dev, "mutex locked"); +next: if (w1_reset_select_slave(sl)) goto out; @@ -52,10 +54,15 @@ static ssize_t state_read(struct file *filp, struct kobject *kobj, w1_write_8(sl->master, W1_F3A_FUNC_PIO_ACCESS_READ); *buf = w1_read_8(sl->master); - /* check for correct complement */ if ((*buf & 0x0F) == ((~*buf >> 4) & 0x0F)) { + /* complement is correct */ bytes_read = 1; goto out; + } else if (*buf == W1_F3A_INVALID_PIO_STATE) { + /* slave didn't respond, try to select it again */ + dev_warn(&sl->dev, "slave device did not respond to PIO_ACCESS_READ, " \ + "reselecting, retries left: %d\n", retries); + goto next; } if (w1_reset_resume_command(sl->master)) -- 2.19.0.rc1