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: 6163201 Return-Path: X-Original-To: patchwork-linux-arm@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 2C1B5BF4A6 for ; Mon, 6 Apr 2015 12:43:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 209652041E for ; Mon, 6 Apr 2015 12:43:46 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D0E7D203E9 for ; Mon, 6 Apr 2015 12:43:43 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Yf6JI-0008Qm-Nw; Mon, 06 Apr 2015 12:39:24 +0000 Received: from mail-lb0-f170.google.com ([209.85.217.170]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Yf6J3-0008LW-Mh for linux-arm-kernel@lists.infradead.org; Mon, 06 Apr 2015 12:39:11 +0000 Received: by lbbzk7 with SMTP id zk7so18854390lbb.0 for ; Mon, 06 Apr 2015 05:38:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=0ZNf4H32gwPJd4ZiVZBVmH1l6Bq3zSZ9isWWIx012Io=; b=atQ+XflF6NDf5jlpUZGZBpdDT5+9ee6a2U/2nwG9rlyt1NVJGguV9YQtG7R+8HlDpJ C+eGOPqu53XzSAeVWQNKglKaoq3n/QSUSOT6BmyDvIuGjJtgYIIAPuXB5F/iDBHaT2D0 miHHl58u+HD9nUiYm7g5xx1KYQqXVHq/cqc3NkIbBYNUV3cWyAoAxvhujAk2wyyDpRPz 6gl884UBP0lPdtddaPpXwYvbdOJZeDVLGfGqTXf3G2yw2IWSf7G/OGutcn51s4Dr+Yl3 34f14SIwX2oiEO0xHTsFAzbyW5tweo6hZNg8P6PCeox3w/96CsdSLCotUoOuRmpDkoqw sHLQ== X-Gm-Message-State: ALoCoQn0w9PPsHJuoHI3aKKIDbBUg7IRdX+OiL6rVciqHCc2o+FDeI8Dvj7wUBVN8e3IG3X3aUzb 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?= 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150406_053910_128050_29F6AABB X-CRM114-Status: GOOD ( 17.60 ) X-Spam-Score: -0.7 (/) Cc: grygorii.strashko@ti.com, Kevin Hilman , linux-kernel@vger.kernel.org, Murali Karicheri , Alexander Sverdlin , linux-i2c@vger.kernel.org, Santosh Shilimkar , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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: 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) {