From patchwork Sun Feb 15 14:43:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Kaneko X-Patchwork-Id: 5830141 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B34ADBF440 for ; Sun, 15 Feb 2015 14:44:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E8BAE20219 for ; Sun, 15 Feb 2015 14:44:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DE97F20220 for ; Sun, 15 Feb 2015 14:44:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754889AbbBOOoS (ORCPT ); Sun, 15 Feb 2015 09:44:18 -0500 Received: from mail-pa0-f50.google.com ([209.85.220.50]:37354 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754822AbbBOOoR (ORCPT ); Sun, 15 Feb 2015 09:44:17 -0500 Received: by mail-pa0-f50.google.com with SMTP id hz1so29445579pad.9; Sun, 15 Feb 2015 06:44:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=VZq9avYzePgvqhKZTfV18NFNvKWnFUZocu82IlPr4Y8=; b=NIT0xaRPjk0aNH7gU6UgkfDJmS0OHnQ1tloYmenu7QUg9K6XbW61gmfOPddCsOZvXP rev1ftGUcQ1KcQn2QuBVsLqnW9bL3FVMcdAiuF1ka1HDoUkC9XUSgQ+uK1a8ckxlpbU3 bEQK/bYblMxRK4V6LbHIX97Xo8Ld685F1aK7bRaHlLjG74tbLE8kXQXyBRGODq4buJtJ xgx86QwHbsnPwQFhPJ2MzjmtlPQk/PuX68GXAYWZysO7TPAqCFXNXWIVddCzpxidSR7y OvVWx32X/VHf2mI/4Fw0b21CIsVrrRaSMBGiQkrxL0Hg1E1KctBT+aKVUV7PdkGO5CLe Ux8w== X-Received: by 10.70.130.205 with SMTP id og13mr31589665pdb.72.1424011456969; Sun, 15 Feb 2015 06:44:16 -0800 (PST) Received: from localhost.localdomain (KD118152108246.ppp-bb.dion.ne.jp. [118.152.108.246]) by mx.google.com with ESMTPSA id z4sm11956894pdp.93.2015.02.15.06.44.14 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 15 Feb 2015 06:44:16 -0800 (PST) From: Yoshihiro Kaneko To: linux-i2c@vger.kernel.org Cc: Wolfram Sang , Simon Horman , Magnus Damm , linux-sh@vger.kernel.org Subject: [PATCH/RFC] i2c: rcar: Fix order of restart and clear status Date: Sun, 15 Feb 2015 23:43:15 +0900 Message-Id: <1424011396-3492-1-git-send-email-ykaneko0929@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ryo Kataoka In case of repeated START condition, the restart has to be kicked before clear status (MSR register). If it is kicked after clear status, R-Car I2C may transfer data (TXD register) or receive data (RXD register) instead of transferring slave address (MAR register). Signed-off-by: Ryo Kataoka Signed-off-by: Yoshihiro Kaneko --- This patch is based on i2c/for-next branch of Wolfram Sang's linux tree. drivers/i2c/busses/i2c-rcar.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c index 71a6e07..96c349f 100644 --- a/drivers/i2c/busses/i2c-rcar.c +++ b/drivers/i2c/busses/i2c-rcar.c @@ -2,6 +2,7 @@ * Driver for the Renesas RCar I2C unit * * Copyright (C) 2014 Wolfram Sang + * Copyright (C) 2013-2014 Renesas Electronics Corporation * * Copyright (C) 2012-14 Renesas Solutions Corp. * Kuninori Morimoto @@ -99,6 +100,7 @@ #define ID_DONE (1 << 2) #define ID_ARBLOST (1 << 3) #define ID_NACK (1 << 4) +#define ID_FIRST_MSG (1 << 5) enum rcar_i2c_type { I2C_RCAR_GEN1, @@ -125,6 +127,7 @@ struct rcar_i2c_priv { #define rcar_i2c_is_recv(p) ((p)->msg->flags & I2C_M_RD) #define rcar_i2c_flags_set(p, f) ((p)->flags |= (f)) +#define rcar_i2c_flags_clr(p, f) ((p)->flags &= ~(f)) #define rcar_i2c_flags_has(p, f) ((p)->flags & (f)) #define LOOP_TIMEOUT 1024 @@ -257,8 +260,14 @@ static void rcar_i2c_prepare_msg(struct rcar_i2c_priv *priv) int read = !!rcar_i2c_is_recv(priv); rcar_i2c_write(priv, ICMAR, (priv->msg->addr << 1) | read); - rcar_i2c_write(priv, ICMSR, 0); - rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_START); + if (rcar_i2c_flags_has(priv, ID_FIRST_MSG)) { /* start */ + rcar_i2c_write(priv, ICMSR, 0); + rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_START); + rcar_i2c_flags_clr(priv, ID_FIRST_MSG); + } else { /* restart */ + rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_START); + rcar_i2c_write(priv, ICMSR, 0); + } rcar_i2c_write(priv, ICMIER, read ? RCAR_IRQ_RECV : RCAR_IRQ_SEND); } @@ -524,6 +533,8 @@ static int rcar_i2c_master_xfer(struct i2c_adapter *adap, priv->msg = &msgs[i]; priv->pos = 0; priv->flags = 0; + if (i == 0) + rcar_i2c_flags_set(priv, ID_FIRST_MSG); if (i == num - 1) rcar_i2c_flags_set(priv, ID_LAST_MSG);