From patchwork Wed Mar 7 13:38:14 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laxman Dewangan X-Patchwork-Id: 145273 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 64CDEB6EEA for ; Thu, 8 Mar 2012 00:41:01 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756680Ab2CGNko (ORCPT ); Wed, 7 Mar 2012 08:40:44 -0500 Received: from hqemgate04.nvidia.com ([216.228.121.35]:12968 "EHLO hqemgate04.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756204Ab2CGNkn (ORCPT ); Wed, 7 Mar 2012 08:40:43 -0500 Received: from hqnvupgp05.nvidia.com (Not Verified[216.228.121.13]) by hqemgate04.nvidia.com id ; Wed, 07 Mar 2012 05:39:40 -0800 Received: from hqnvemgw01.nvidia.com ([172.17.108.22]) by hqnvupgp05.nvidia.com (PGP Universal service); Wed, 07 Mar 2012 05:40:42 -0800 X-PGP-Universal: processed; by hqnvupgp05.nvidia.com on Wed, 07 Mar 2012 05:40:42 -0800 Received: from daphne.nvidia.com (Not Verified[172.16.212.96]) by hqnvemgw01.nvidia.com with MailMarshal (v6, 7, 2, 8378) id ; Wed, 07 Mar 2012 05:40:42 -0800 Received: from ldewangan-ubuntu.nvidia.com ([10.19.65.30]) by daphne.nvidia.com (8.13.8+Sun/8.8.8) with ESMTP id q27Deaf9006913; Wed, 7 Mar 2012 05:40:38 -0800 (PST) From: Laxman Dewangan To: khali@linux-fr.org, ben-linux@fluff.org, w.sang@pengutronix.de, grant.likely@secretlab.ca, broonie@opensource.wolfsonmicro.com, linus.walleij@linaro.org Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, ldewangan@nvidia.com Subject: [PATCH V1] i2c: gpio: Use open drain support from gpio driver Date: Wed, 7 Mar 2012 19:08:14 +0530 Message-Id: <1331127494-6913-1-git-send-email-ldewangan@nvidia.com> X-Mailer: git-send-email 1.7.1.1 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The gpio core driver (gpio library) supports the open drain pin handling. Therefore, it is not require it to handle in the i2c-gpio driver, just require to pass the OPEN_DRAIN type flag when requesting the gpio. Remove the handling of open drain pin in the i2c-gpio driver. Signed-off-by: Laxman Dewangan Acked-by: Linus Walleij --- drivers/i2c/busses/i2c-gpio.c | 78 ++++++++++++++-------------------------- 1 files changed, 27 insertions(+), 51 deletions(-) diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c index 69fbfae..662a747 100644 --- a/drivers/i2c/busses/i2c-gpio.c +++ b/drivers/i2c/busses/i2c-gpio.c @@ -16,22 +16,7 @@ #include #include -/* Toggle SDA by changing the direction of the pin */ -static void i2c_gpio_setsda_dir(void *data, int state) -{ - struct i2c_gpio_platform_data *pdata = data; - - if (state) - gpio_direction_input(pdata->sda_pin); - else - gpio_direction_output(pdata->sda_pin, 0); -} - -/* - * Toggle SDA by changing the output value of the pin. This is only - * valid for pins configured as open drain (i.e. setting the value - * high effectively turns off the output driver.) - */ +/* Toggle SDA by setting value, gpio library take care of open drain pins.*/ static void i2c_gpio_setsda_val(void *data, int state) { struct i2c_gpio_platform_data *pdata = data; @@ -39,23 +24,7 @@ static void i2c_gpio_setsda_val(void *data, int state) gpio_set_value(pdata->sda_pin, state); } -/* Toggle SCL by changing the direction of the pin. */ -static void i2c_gpio_setscl_dir(void *data, int state) -{ - struct i2c_gpio_platform_data *pdata = data; - - if (state) - gpio_direction_input(pdata->scl_pin); - else - gpio_direction_output(pdata->scl_pin, 0); -} - -/* - * Toggle SCL by changing the output value of the pin. This is used - * for pins that are configured as open drain and for output-only - * pins. The latter case will break the i2c protocol, but it will - * often work in practice. - */ + /* Toggle SCL by setting value, gpio library take care of open drain pins.*/ static void i2c_gpio_setscl_val(void *data, int state) { struct i2c_gpio_platform_data *pdata = data; @@ -83,6 +52,8 @@ static int __devinit i2c_gpio_probe(struct platform_device *pdev) struct i2c_algo_bit_data *bit_data; struct i2c_adapter *adap; int ret; + unsigned long sda_gpio_flags; + unsigned long scl_gpio_flags; pdata = pdev->dev.platform_data; if (!pdata) @@ -96,28 +67,33 @@ static int __devinit i2c_gpio_probe(struct platform_device *pdev) if (!bit_data) goto err_alloc_bit_data; - ret = gpio_request(pdata->sda_pin, "sda"); - if (ret) + /* Initially, SCL and SDA pin should be HIGH */ + sda_gpio_flags = GPIOF_OUT_INIT_HIGH; + scl_gpio_flags = GPIOF_OUT_INIT_HIGH; + + if (pdata->sda_is_open_drain) + sda_gpio_flags |= GPIOF_OPEN_DRAIN; + + if (pdata->scl_is_open_drain && !pdata->scl_is_output_only) + scl_gpio_flags |= GPIOF_OPEN_DRAIN; + + + + ret = gpio_request_one(pdata->sda_pin, sda_gpio_flags, "sda"); + if (ret) { + pr_err("%s(): Error in requesting sda gpio%d, ret %d\n", + __func__, pdata->sda_pin, ret); goto err_request_sda; - ret = gpio_request(pdata->scl_pin, "scl"); - if (ret) + } + ret = gpio_request_one(pdata->scl_pin, scl_gpio_flags, "scl"); + if (ret) { + pr_err("%s(): Error in requesting scl gpio%d, ret %d\n", + __func__, pdata->scl_pin, ret); goto err_request_scl; - - if (pdata->sda_is_open_drain) { - gpio_direction_output(pdata->sda_pin, 1); - bit_data->setsda = i2c_gpio_setsda_val; - } else { - gpio_direction_input(pdata->sda_pin); - bit_data->setsda = i2c_gpio_setsda_dir; } - if (pdata->scl_is_open_drain || pdata->scl_is_output_only) { - gpio_direction_output(pdata->scl_pin, 1); - bit_data->setscl = i2c_gpio_setscl_val; - } else { - gpio_direction_input(pdata->scl_pin); - bit_data->setscl = i2c_gpio_setscl_dir; - } + bit_data->setsda = i2c_gpio_setsda_val; + bit_data->setscl = i2c_gpio_setscl_val; if (!pdata->scl_is_output_only) bit_data->getscl = i2c_gpio_getscl;