From patchwork Mon Apr 6 12:38:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Grygorii.Strashko@linaro.org" X-Patchwork-Id: 46782 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 97946214B1 for ; Mon, 6 Apr 2015 12:39:07 +0000 (UTC) Received: by lbbqq2 with SMTP id qq2sf5216511lbb.0 for ; Mon, 06 Apr 2015 05:39:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-type :content-transfer-encoding:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=VqRbZxA8mDLU9sF6lvaNdZH0ogg+ICSr0GK6+GMaFnA=; b=iCZ/zRaQjGZHhk9m1dknnC2MbSkxEaN+XbtbkrpeKgYkI/zuKwMfxUq61CVh8dNGmk 6GgM6mKrdpQiRfCtNIy6mu3CbMqn2NIzE4f0V8cE/YaXyYhB7x1mlzU0hu592GXHsPus y0VyHtcDO1Rb5Zm/RygMgjOr/Yz5a6ta626x9uE7R6z9SxQQwn0q5KHic3DjcUrbUljr 8ggbXRSHJALySPjk9XalMSIQpZJkpmaouwp3a5kojGTBYMmqTWaKyF1zoLBsDxg/VMXC j54NP+JTh+MgBm0H9JFPDR9xCuv+La9rbeTwqfUaqnhA6/U6y7ydkylfSkNarazYS8EN eE4A== X-Gm-Message-State: ALoCoQmKsROW52nCom8Ps2khUTTNLCXApTkIX4ftQdI1RU9bKW+qgG4FILMz+HY+jUBEOJ0JtgTM X-Received: by 10.152.37.101 with SMTP id x5mr766078laj.5.1428323946364; Mon, 06 Apr 2015 05:39:06 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.22.134 with SMTP id d6ls515556laf.95.gmail; Mon, 06 Apr 2015 05:39:06 -0700 (PDT) X-Received: by 10.152.45.101 with SMTP id l5mr12951688lam.95.1428323946014; Mon, 06 Apr 2015 05:39:06 -0700 (PDT) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id py2si3472025lbb.33.2015.04.06.05.39.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Apr 2015 05:39:06 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by laat2 with SMTP id t2so11747736laa.1 for ; Mon, 06 Apr 2015 05:39:05 -0700 (PDT) X-Received: by 10.112.212.106 with SMTP id nj10mr13437385lbc.36.1428323945867; Mon, 06 Apr 2015 05:39:05 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.57.201 with SMTP id k9csp3329954lbq; Mon, 6 Apr 2015 05:39:05 -0700 (PDT) X-Received: by 10.70.131.15 with SMTP id oi15mr26933748pdb.161.1428323942538; Mon, 06 Apr 2015 05:39:02 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fh5si6509881pdb.24.2015.04.06.05.39.01 for ; Mon, 06 Apr 2015 05:39:02 -0700 (PDT) Received-SPF: none (google.com: linux-i2c-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753152AbbDFMit (ORCPT ); Mon, 6 Apr 2015 08:38:49 -0400 Received: from mail-lb0-f181.google.com ([209.85.217.181]:33986 "EHLO mail-lb0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752853AbbDFMiq (ORCPT ); Mon, 6 Apr 2015 08:38:46 -0400 Received: by lboc7 with SMTP id c7so18774611lbo.1 for ; Mon, 06 Apr 2015 05:38:44 -0700 (PDT) X-Received: by 10.152.121.72 with SMTP id li8mr12999646lab.11.1428323924364; Mon, 06 Apr 2015 05:38:44 -0700 (PDT) Received: from localhost ([195.238.92.128]) by mx.google.com with ESMTPSA id ky7sm958229lab.37.2015.04.06.05.38.43 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 06 Apr 2015 05:38:43 -0700 (PDT) From: To: Wolfram Sang , Sekhar Nori , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Cc: grygorii.strashko@ti.com, linux-i2c@vger.kernel.org, , , Kevin Hilman , Santosh Shilimkar , Murali Karicheri , Alexander Sverdlin Subject: [PATCH v4 2/3] i2c: davinci: use bus recovery infrastructure Date: Mon, 6 Apr 2015 15:38:40 +0300 Message-Id: <1428323921-25832-3-git-send-email-grygorii.strashko@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1428323921-25832-1-git-send-email-grygorii.strashko@linaro.org> References: <1428323921-25832-1-git-send-email-grygorii.strashko@linaro.org> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-i2c@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: grygorii.strashko@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Grygorii Strashko This patch converts Davinci I2C driver to use I2C bus recovery infrastructure, introduced by commit 5f9296ba21b3 ("i2c: Add bus recovery infrastructure"). The i2c_bus_recovery_info is configured for Davinci I2C adapter only in case scl_pin is provided in platform data. As the controller must be held in reset while doing so, the recovery routine must re-init the controller. Since this was already being done after each call to i2c_recover_bus, move those calls into the recovery_prepare/unprepare routines and as well. CC: Sekhar Nori CC: Kevin Hilman CC: Santosh Shilimkar CC: Murali Karicheri CC: Alexander Sverdlin Acked-by: Uwe Kleine-König Signed-off-by: Grygorii Strashko --- drivers/i2c/busses/i2c-davinci.c | 77 +++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 41 deletions(-) diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c index 120a4ef..54819fb 100644 --- a/drivers/i2c/busses/i2c-davinci.c +++ b/drivers/i2c/busses/i2c-davinci.c @@ -129,43 +129,6 @@ static inline u16 davinci_i2c_read_reg(struct davinci_i2c_dev *i2c_dev, int reg) return readw_relaxed(i2c_dev->base + reg); } -/* Generate a pulse on the i2c clock pin. */ -static void davinci_i2c_clock_pulse(unsigned int scl_pin) -{ - u16 i; - - if (scl_pin) { - /* Send high and low on the SCL line */ - for (i = 0; i < 9; i++) { - gpio_set_value(scl_pin, 0); - udelay(20); - gpio_set_value(scl_pin, 1); - udelay(20); - } - } -} - -/* This routine does i2c bus recovery as specified in the - * i2c protocol Rev. 03 section 3.16 titled "Bus clear" - */ -static void davinci_i2c_recover_bus(struct davinci_i2c_dev *dev) -{ - u32 flag = 0; - struct davinci_i2c_platform_data *pdata = dev->pdata; - - dev_err(dev->dev, "initiating i2c bus recovery\n"); - /* Send NACK to the slave */ - flag = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG); - flag |= DAVINCI_I2C_MDR_NACK; - /* write the data into mode register */ - davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag); - davinci_i2c_clock_pulse(pdata->scl_pin); - /* Send STOP */ - flag = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG); - flag |= DAVINCI_I2C_MDR_STP; - davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag); -} - static inline void davinci_i2c_reset_ctrl(struct davinci_i2c_dev *i2c_dev, int val) { @@ -263,6 +226,34 @@ static int i2c_davinci_init(struct davinci_i2c_dev *dev) } /* + * This routine does i2c bus recovery by using i2c_generic_gpio_recovery + * which is provided by I2C Bus recovery infrastructure. + */ +static void davinci_i2c_prepare_recovery(struct i2c_adapter *adap) +{ + struct davinci_i2c_dev *dev = i2c_get_adapdata(adap); + + /* Disable interrupts */ + davinci_i2c_write_reg(dev, DAVINCI_I2C_IMR_REG, 0); + + /* put I2C into reset */ + davinci_i2c_reset_ctrl(dev, 0); +} + +static void davinci_i2c_unprepare_recovery(struct i2c_adapter *adap) +{ + struct davinci_i2c_dev *dev = i2c_get_adapdata(adap); + + i2c_davinci_init(dev); +} + +static struct i2c_bus_recovery_info davinci_i2c_gpio_recovery_info = { + .recover_bus = i2c_generic_gpio_recovery, + .prepare_recovery = davinci_i2c_prepare_recovery, + .unprepare_recovery = davinci_i2c_unprepare_recovery, +}; + +/* * Waiting for bus not busy */ static int i2c_davinci_wait_bus_not_busy(struct davinci_i2c_dev *dev, @@ -282,8 +273,7 @@ static int i2c_davinci_wait_bus_not_busy(struct davinci_i2c_dev *dev, return -ETIMEDOUT; } else { to_cnt = 0; - davinci_i2c_recover_bus(dev); - i2c_davinci_init(dev); + i2c_recover_bus(&dev->adapter); } } if (allow_sleep) @@ -372,8 +362,7 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop) dev->adapter.timeout); if (!time_left) { dev_err(dev->dev, "controller timed out\n"); - davinci_i2c_recover_bus(dev); - i2c_davinci_init(dev); + i2c_recover_bus(adap); dev->buf_len = 0; return -ETIMEDOUT; } @@ -712,6 +701,12 @@ static int davinci_i2c_probe(struct platform_device *pdev) adap->timeout = DAVINCI_I2C_TIMEOUT; adap->dev.of_node = pdev->dev.of_node; + if (dev->pdata->scl_pin) { + adap->bus_recovery_info = &davinci_i2c_gpio_recovery_info; + adap->bus_recovery_info->scl_gpio = dev->pdata->scl_pin; + adap->bus_recovery_info->sda_gpio = dev->pdata->sda_pin; + } + adap->nr = pdev->id; r = i2c_add_numbered_adapter(adap); if (r) {