From patchwork Mon Mar 21 14:58:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexandre Belloni X-Patchwork-Id: 600162 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-lb0-x23d.google.com (mail-lb0-x23d.google.com [IPv6:2a00:1450:4010:c04::23d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qTJr40gyhz9s2Q for ; Tue, 22 Mar 2016 01:58:59 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b=l12NLZ+X; dkim-atps=neutral Received: by mail-lb0-x23d.google.com with SMTP id wn5sf41411577lbb.0 for ; Mon, 21 Mar 2016 07:58:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=mK8Fs4t+awF0tlfsdFXfC/PB1eGJZD8CyGXuzcpvXK4=; b=l12NLZ+XH6k0UwyudHGH7gh2ydUT3ebW4dRYkcO791fkT8uQphqcuXXZe3QlkEG6PY LG9tZ9yTaass+4Zu4ZpBD/Y9DqVRoxZjyLIkaYlQwfB/j3n7DIv0+oEDlMb9+PwpQ3t9 MIqckMPFlUveng2w6rY3/plnkjCfvYwYAVzTal19ter28yfxcyp/X1duxBJdVU13Ofh+ /WdJnBTAKVr/3GouHEVVl30cygyq5ofpaj59macz0Zmaf7qA5uUegAygveHIF0/3Fxou duzNI/huiLrMw6UQ8zSgus1as5Z3S7YY9vdNUcxdynTc/fTYdS6Oq36qO18QY6g1efBY xlTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=mK8Fs4t+awF0tlfsdFXfC/PB1eGJZD8CyGXuzcpvXK4=; b=GuZpQ4KEwA7BKd91W7WAs2SS3PA/uYBpnuW6k/VRhNxxculE+uzpxrdK9kwVD26eb1 Mg6B8c/SyyIaL3OQBssrUC5cM9Y0GOxLo/4j27r8jaHpYSkNUsBqG++HkXDCeCcFW88O IdZnx/m4N8N0+CSmYi1s7QzF38kkdrEzied8vzYi+CbURWPCrfAbzsHt2WhtA5BsrNTz OpacdvjksiO+yuMlpqcyChAY41zj26KmXkiiO9RXOfLPRr1e8DioK/eaTvnga2k/AVe+ GNsB70JhHBfkaQaS/NgUn4CrIq7J1eXwyBgxiiUaHQIwVuXdd9jPR178JxW45AJE2fbG ewOg== Sender: rtc-linux@googlegroups.com X-Gm-Message-State: AD7BkJJ8lHYqtcOdGm2ABLxt0ZWQo5HMUE3cR0MX6v7l14hdN30K7X0OaZ8UrJxTEBd5rQ== X-Received: by 10.25.149.195 with SMTP id x186mr399504lfd.5.1458572336044; Mon, 21 Mar 2016 07:58:56 -0700 (PDT) X-BeenThere: rtc-linux@googlegroups.com Received: by 10.25.147.1 with SMTP id v1ls723401lfd.37.gmail; Mon, 21 Mar 2016 07:58:55 -0700 (PDT) X-Received: by 10.112.170.42 with SMTP id aj10mr3697622lbc.1.1458572335078; Mon, 21 Mar 2016 07:58:55 -0700 (PDT) Received: from mail.free-electrons.com (down.free-electrons.com. [37.187.137.238]) by gmr-mx.google.com with ESMTP id s141si468433wmd.1.2016.03.21.07.58.55 for ; Mon, 21 Mar 2016 07:58:55 -0700 (PDT) Received-SPF: pass (google.com: domain of alexandre.belloni@free-electrons.com designates 37.187.137.238 as permitted sender) client-ip=37.187.137.238; Received: by mail.free-electrons.com (Postfix, from userid 110) id 4FCE8227; Mon, 21 Mar 2016 15:58:54 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost (unknown [88.191.26.124]) by mail.free-electrons.com (Postfix) with ESMTPSA id 0707511D; Mon, 21 Mar 2016 15:58:44 +0100 (CET) From: Alexandre Belloni To: rtc-linux@googlegroups.com Cc: Alessandro Zummo , linux-kernel@vger.kernel.org, Alexandre Belloni Subject: [rtc-linux] [PATCH] rv8803: workaround i2c HW issue Date: Mon, 21 Mar 2016 15:58:38 +0100 Message-Id: <1458572318-13184-1-git-send-email-alexandre.belloni@free-electrons.com> X-Mailer: git-send-email 2.7.0 MIME-Version: 1.0 X-Original-Sender: alexandre.belloni@free-electrons.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of alexandre.belloni@free-electrons.com designates 37.187.137.238 as permitted sender) smtp.mailfrom=alexandre.belloni@free-electrons.com Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: rtc-linux@googlegroups.com X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , The rv8803 has a 60µs window where it will not answer on the i2c bus. It also means there will be no ack for the communication. Make sure communication is tried multiple times when this happens (the i2c subsystem mandates -ENXIO is that case but the number of retries is host specific). The critical parts are the probe function and the alarm callback so make sure we handle the failure there. Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-rv8803.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/drivers/rtc/rtc-rv8803.c b/drivers/rtc/rtc-rv8803.c index 7155c0816aa6..82ab41074156 100644 --- a/drivers/rtc/rtc-rv8803.c +++ b/drivers/rtc/rtc-rv8803.c @@ -61,11 +61,14 @@ static irqreturn_t rv8803_handle_irq(int irq, void *dev_id) struct i2c_client *client = dev_id; struct rv8803_data *rv8803 = i2c_get_clientdata(client); unsigned long events = 0; - int flags; + int flags, try = 0; spin_lock(&rv8803->flags_lock); - flags = i2c_smbus_read_byte_data(client, RV8803_FLAG); + do { + flags = i2c_smbus_read_byte_data(client, RV8803_FLAG); + try++; + } while ((flags == -ENXIO) && (try < 3)); if (flags <= 0) { spin_unlock(&rv8803->flags_lock); return IRQ_NONE; @@ -428,7 +431,7 @@ static int rv8803_probe(struct i2c_client *client, { struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); struct rv8803_data *rv8803; - int err, flags; + int err, flags, try = 0; if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_I2C_BLOCK)) { @@ -444,7 +447,16 @@ static int rv8803_probe(struct i2c_client *client, rv8803->client = client; i2c_set_clientdata(client, rv8803); - flags = i2c_smbus_read_byte_data(client, RV8803_FLAG); + /* + * There is a 60µs window where the RTC may not reply on the i2c bus in + * that case, the transfer is not ACKed. In that case, ensure there are + * multiple attempts. + */ + do { + flags = i2c_smbus_read_byte_data(client, RV8803_FLAG); + try++; + } while ((flags == -ENXIO) && (try < 3)); + if (flags < 0) return flags; @@ -479,8 +491,12 @@ static int rv8803_probe(struct i2c_client *client, return PTR_ERR(rv8803->rtc); } - err = i2c_smbus_write_byte_data(rv8803->client, RV8803_EXT, - RV8803_EXT_WADA); + try = 0; + do { + err = i2c_smbus_write_byte_data(rv8803->client, RV8803_EXT, + RV8803_EXT_WADA); + try++; + } while ((err == -ENXIO) && (try < 3)); if (err) return err;