Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4629372yba; Mon, 20 May 2019 00:29:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqxvy3QyF0D2GcSDL3DMKGTlmty2xlEUV6/FclmFTqYMyMd2i+fKJX95KO+tQv5txVQ8rfuk X-Received: by 2002:aa7:9e9a:: with SMTP id p26mr46558822pfq.176.1558337386100; Mon, 20 May 2019 00:29:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558337386; cv=none; d=google.com; s=arc-20160816; b=oyK0UJ0q9LRTskU3Bg7rvJirwNXjfJvXrCmplYxXUpG2XPtFuLATVnynkBEEpuI5sx WkAWfjURrECUzxAF75pmw5UMIotHfhMkdGsi/RWvOcp+16zK/3hhtpnn3SNdcSZNQhFZ ubKO4auWgkm+DYm1U2f48xDmTdO60GhMlNGH0YRi7IVh/zpnMCiFAjEzFepnd8BjYa4B r3dphYCMIudD+Ciu5Q2Jln/NdpIX0fJKTeYa4mowLWYa1Gnc0fQQhjdUpro5Zj8Q9RWi 3Stji1eYF39qMN8qTVaOZDFAulkgtfEbKKGXimQC4rv0wnNGI6xnWKcKGSAHouETD0iE WQJA== 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=F5koHKFAyucAs2F5dFmSaONH3Uag13h/fplU0KLLcVo=; b=YTKUSwKgkTR+aR1T1vZiiYelRSLb+sVCM8lGEhV42QttwpvP06WKER+QPIdte6WwSQ KMTMPEGdkdcqBOIgGnffQHZBGHEFwx1ylcZqsRMRgNz3CRLUvNDT96Lh8Jvk8IGd22lb jVQzTk6VsGWofYgvHM3D//c+dJGFkjVBv/wzl88+HuzNl8PPxqqltC086brQxCvwjReE VYW+4g7R+iy9IK9II/ubA34huHnh6HJxpmzlG10ksiE7ZAtSVGsbeq3NBKP4+R6zqsok P23YRaphsABMMubuH1MvqHtF1OaXuz+//l37f9bhVIizmAOQCo7KuR3LET68OVXtl85t Ojag== 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 l96si17568043plb.115.2019.05.20.00.29.31; Mon, 20 May 2019 00:29:46 -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 S1730518AbfETHGP (ORCPT + 99 others); Mon, 20 May 2019 03:06:15 -0400 Received: from skyboo.net ([94.40.87.198]:51502 "EHLO skyboo.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730488AbfETHGO (ORCPT ); Mon, 20 May 2019 03:06:14 -0400 Received: from manio by skyboo.net with local (Exim 4.91) (envelope-from ) id 1hScN9-0005pU-GP; Mon, 20 May 2019 09:06:11 +0200 From: Mariusz Bialonczyk To: linux-kernel@vger.kernel.org, Greg Kroah-Hartman Cc: Mariusz Bialonczyk Date: Mon, 20 May 2019 09:05:57 +0200 Message-Id: <20190520070558.20142-3-manio@skyboo.net> X-Mailer: git-send-email 2.19.0.rc1 In-Reply-To: <20190520070558.20142-1-manio@skyboo.net> References: <20190520070558.20142-1-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, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.1 Subject: [PATCH 3/4] 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 --- drivers/w1/slaves/w1_ds2413.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/w1/slaves/w1_ds2413.c b/drivers/w1/slaves/w1_ds2413.c index d63778c70568..1854461d4d56 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,8 +54,13 @@ 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)) { + 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; + } else if ((*buf & 0x0F) == ((~*buf >> 4) & 0x0F)) { + /* complement is correct */ bytes_read = 1; goto out; } -- 2.19.0.rc1