From patchwork Tue Jan 9 13:58:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 10152117 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CC38C602CA for ; Tue, 9 Jan 2018 13:59:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE3AD289D3 for ; Tue, 9 Jan 2018 13:59:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B3238289EC; Tue, 9 Jan 2018 13:59:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35D96289D3 for ; Tue, 9 Jan 2018 13:59:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755751AbeAIN7g (ORCPT ); Tue, 9 Jan 2018 08:59:36 -0500 Received: from sauhun.de ([88.99.104.3]:41835 "EHLO pokefinder.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758433AbeAIN7J (ORCPT ); Tue, 9 Jan 2018 08:59:09 -0500 Received: from localhost (p54B33354.dip0.t-ipconnect.de [84.179.51.84]) by pokefinder.org (Postfix) with ESMTPSA id 15DD22C5EBD; Tue, 9 Jan 2018 14:59:08 +0100 (CET) From: Wolfram Sang To: linux-i2c@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Phil Reid , Wolfram Sang Subject: [PATCH v2 3/6] i2c: add 'set_sda' to bus_recovery_info Date: Tue, 9 Jan 2018 14:58:56 +0100 Message-Id: <20180109135859.20771-4-wsa@the-dreams.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180109135859.20771-1-wsa@the-dreams.de> References: <20180109135859.20771-1-wsa@the-dreams.de> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wolfram Sang This will be needed when we want to create STOP conditions, too, later. Create the needed fields and populate them for the GPIO case if the GPIO is set to output. Tested-by: Phil Reid Signed-off-by: Wolfram Sang Reviewed-by: Linus Walleij --- Changes since V1: * don't use GPIOF_* flags but hardocded '0' drivers/i2c/i2c-core-base.c | 11 ++++++++++- include/linux/i2c.h | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index bb34a5d4113331..a8b3fbe16fa08c 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -147,6 +147,11 @@ static int get_sda_gpio_value(struct i2c_adapter *adap) return gpiod_get_value_cansleep(adap->bus_recovery_info->sda_gpiod); } +static void set_sda_gpio_value(struct i2c_adapter *adap, int val) +{ + gpiod_set_value_cansleep(adap->bus_recovery_info->sda_gpiod, val); +} + /* * We are generating clock pulses. ndelay() determines durating of clk pulses. * We will generate clock with rate 100 KHz and so duration of both clock levels @@ -225,8 +230,12 @@ static void i2c_init_recovery(struct i2c_adapter *adap) if (bri->scl_gpiod && bri->recover_bus == i2c_generic_scl_recovery) { bri->get_scl = get_scl_gpio_value; bri->set_scl = set_scl_gpio_value; - if (bri->sda_gpiod) + if (bri->sda_gpiod) { bri->get_sda = get_sda_gpio_value; + /* FIXME: add proper flag instead of '0' once available */ + if (gpiod_get_direction(bri->sda_gpiod) == 0) + bri->set_sda = set_sda_gpio_value; + } return; } diff --git a/include/linux/i2c.h b/include/linux/i2c.h index fd87b806b5f165..419a38e7c315f1 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -551,6 +551,9 @@ struct i2c_timings { * @get_sda: This gets current value of SDA line. Optional for generic SCL * recovery. Populated internally, if sda_gpio is a valid GPIO, for generic * GPIO recovery. + * @set_sda: This sets/clears the SDA line. Optional for generic SCL recovery. + * Populated internally, if sda_gpio is a valid GPIO, for generic GPIO + * recovery. * @prepare_recovery: This will be called before starting recovery. Platform may * configure padmux here for SDA/SCL line or something else they want. * @unprepare_recovery: This will be called after completing recovery. Platform @@ -564,6 +567,7 @@ struct i2c_bus_recovery_info { int (*get_scl)(struct i2c_adapter *adap); void (*set_scl)(struct i2c_adapter *adap, int val); int (*get_sda)(struct i2c_adapter *adap); + void (*set_sda)(struct i2c_adapter *adap, int val); void (*prepare_recovery)(struct i2c_adapter *adap); void (*unprepare_recovery)(struct i2c_adapter *adap);