From patchwork Sun Jan 15 10:12:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 643012 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76E9FC3DA78 for ; Sun, 15 Jan 2023 10:18:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230333AbjAOKSd (ORCPT ); Sun, 15 Jan 2023 05:18:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230137AbjAOKSa (ORCPT ); Sun, 15 Jan 2023 05:18:30 -0500 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5777DCDE1; Sun, 15 Jan 2023 02:18:29 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id l41-20020a05600c1d2900b003daf986faaeso272628wms.3; Sun, 15 Jan 2023 02:18:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=zNZMQn185TG+Tx8tewhmSx+Qg1QuTVS0EFy/ikAT8rs=; b=HSn5ULbp18jNbEDsW2780oWNWY+ZUmSoShdVMmeX7zuQ41YBfpTXEqV6YaHd9OcUBi 0AC6r68uaeOefJil7Q30wCVATb1c0zyiL87uXKvj4v+gVek/t9zZ+Wc/xEry9VsmIrNt YAJyqdNQnHHTs62U5/agkQMLWpfLlCZ5Axm1cnSJoXYvH46ad4Xtg5FGLJGiUe5qrXto sCgbDRWtEoqadsVotQqhRrS1RwCHw563kJr8C22Eqaj34z+2LYNzblfoHvaiWSjYYG6d fRwtZdNXmjNFhTBeFDoBRoZiRUVTOJtzyNuCPtRGKeipL1q65gJ7CQigJVMMpVGdVXzJ jDjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zNZMQn185TG+Tx8tewhmSx+Qg1QuTVS0EFy/ikAT8rs=; b=qlRm+J/azpFOt8ypXODXECRUyxMj8/FNSvoeGBq/+dVaynDPLrFWf6XReAHMnLJMuE zkiYdKt4+qzzEYDXJfmvH/CvURXjEYnk0zhwX3W6djaC7yXf2fYLyYwbwHtv2XpgUMRT VntlsvL45reoxi8y6dMgIf5TSRBJ6uUuhrRl9cvoS2Keb0aCTgm9XmY8hh2DkfMmsL1u GSjmDsArCEjl2xG+ywdoYly67NrNEjgtvOvOZNKmskVrC6ZJFFUmVbp2ZA+9qet0piDs jikrCHeHk1DG62zTq742IY3lBIMmm6wAtIRJiPFGweoQ0G4Kl17YhoHWwm8KVvgGUyaG 1mJQ== X-Gm-Message-State: AFqh2kp064AAv6T4V5S241/d41SSimOaaFXzKGiFidhbTgn0XivDofAz bpH40sg749FY58rddouffdUYBhp1qqE= X-Google-Smtp-Source: AMrXdXuSX+U2cpCqO/uF7u+5F7m0/2cXk7pk8tLHcjNPlFW800Yny+G9d9TqkKnNQapyyuoZ/X89Qw== X-Received: by 2002:a05:600c:4f96:b0:3d9:ed3b:5b3e with SMTP id n22-20020a05600c4f9600b003d9ed3b5b3emr20979706wmq.19.1673777907222; Sun, 15 Jan 2023 02:18:27 -0800 (PST) Received: from ?IPV6:2a01:c22:6e61:8c00:154f:326e:8d45:8ce7? (dynamic-2a01-0c22-6e61-8c00-154f-326e-8d45-8ce7.c22.pool.telefonica.de. [2a01:c22:6e61:8c00:154f:326e:8d45:8ce7]) by smtp.googlemail.com with ESMTPSA id h10-20020a1ccc0a000000b003d237d60318sm30545648wmb.2.2023.01.15.02.18.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 15 Jan 2023 02:18:26 -0800 (PST) Message-ID: <60e3b33b-360e-94f0-5065-08589cb1cab6@gmail.com> Date: Sun, 15 Jan 2023 11:12:30 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: [PATCH v3 1/3] dt-bindings: i2c-gpio: Add property i2c-gpio,sda-output-only Content-Language: en-US From: Heiner Kallweit To: Rob Herring , Krzysztof Kozlowski , Wolfram Sang Cc: "linux-i2c@vger.kernel.org" , "devicetree@vger.kernel.org" References: <3a5545f3-f858-2c80-8bd4-2e0d401a1dc0@gmail.com> In-Reply-To: <3a5545f3-f858-2c80-8bd4-2e0d401a1dc0@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org There are slave devices that understand I2C but have read-only SDA and SCL. Examples are FD650 7-segment LED controller and its derivatives. Typical board designs don't even have a pull-up for both pins. Therefore don't enforce open-drain if SDA and SCL both are unidirectional. This patch makes i2c-gpio usable with such devices, based on new DT property i2c-gpio,sda-output-only. Reviewed-by: Rob Herring Signed-off-by: Heiner Kallweit --- Documentation/devicetree/bindings/i2c/i2c-gpio.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/devicetree/bindings/i2c/i2c-gpio.yaml b/Documentation/devicetree/bindings/i2c/i2c-gpio.yaml index e0d76d5eb..fd84a60d9 100644 --- a/Documentation/devicetree/bindings/i2c/i2c-gpio.yaml +++ b/Documentation/devicetree/bindings/i2c/i2c-gpio.yaml @@ -33,6 +33,10 @@ properties: open drain. maxItems: 1 + i2c-gpio,sda-output-only: + description: sda as output only + type: boolean + i2c-gpio,scl-output-only: description: scl as output only type: boolean From patchwork Sun Jan 15 10:15:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 643268 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D92D9C46467 for ; Sun, 15 Jan 2023 10:18:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230462AbjAOKSq (ORCPT ); Sun, 15 Jan 2023 05:18:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230145AbjAOKSa (ORCPT ); Sun, 15 Jan 2023 05:18:30 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2794CDE3; Sun, 15 Jan 2023 02:18:29 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id k8so10365544wrc.9; Sun, 15 Jan 2023 02:18:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=/D0U6ZSa9ufXqRencjxkQFzJOdEXcs/cpW2jU/kZH/M=; b=K9pasKsSYWaBapGarM+zzgGQVplz5o57CJb32ZxlQ14rAfHqBMOGMYSVFnHsx7qJ9G VXRpCU0JQqDhgNsOWFInXfYDxCrZc+FcBOCUqbQ6WmqmrdTyjNHh/tCx13x89CZR6EAE IGuhsdjtoLjWxubUnetxlEI1071gXYO2zqwhyhofHnHDKXpIiedt9xi5t5jztD+Z/ZU8 Q0BBcMrGrEAK9LnEqEKd2B+AAJfNjOQ3s7gvmnUoL2sOVkFvGYLYPCNggVdGrk7TXpLu VOjtLJP03FWAtC1lTm3mlBibXHdS7GDOXvJuS+CqumZWGTFudkRvMmqMPIENZGd6THHV rXQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/D0U6ZSa9ufXqRencjxkQFzJOdEXcs/cpW2jU/kZH/M=; b=NQy97VrQR8yabPuPMQ7cnmdD0Hy4bB2baOUeFFX11BFm4TutbDjSK7XvjH+e+7xOBd Mk9OjhCyGIi5P8PgrTfFOg31j5KbO89GfEgh7EAO20YYdfz/bUzyEzIKWlILCr0VcaPL PdhsLcAjl/pwV1sMfv/IdgSblefN3EohOlDwvgm/kpmEmrN7KQM9+TENZnMlAqZz1JfO MCpld3rbx+2MbX3o9Uu8Q+xha3SPqY7G4kWOjGMH6oXmqHKd+NpW9wAe2CMbfyrP1bZp dP52sXCFo9fIr3C+fI5T9gKd4MwUz65PhIzRCgFjxi9B25BxctSsJyjHq5pYlnL7k8fl rCxQ== X-Gm-Message-State: AFqh2kqUeQZ8F/g+4wt3wUEu68wov5InN54Z5GzozVrAn1wQPkXTCR+C yFy4Pb5I6VtZJ325q1w1TUYlKFjt9uk= X-Google-Smtp-Source: AMrXdXv48t+zyOW+TLe3yWdXReBPlpJ/rytYi71Z/PeQUGAPaIFkFLeYZzO7pVES7BjHKIz5LCALiw== X-Received: by 2002:a5d:4b0f:0:b0:2bd:c4ea:3b59 with SMTP id v15-20020a5d4b0f000000b002bdc4ea3b59mr10674279wrq.0.1673777908265; Sun, 15 Jan 2023 02:18:28 -0800 (PST) Received: from ?IPV6:2a01:c22:6e61:8c00:154f:326e:8d45:8ce7? (dynamic-2a01-0c22-6e61-8c00-154f-326e-8d45-8ce7.c22.pool.telefonica.de. [2a01:c22:6e61:8c00:154f:326e:8d45:8ce7]) by smtp.googlemail.com with ESMTPSA id l4-20020a05600012c400b002bbb2d43f65sm20419613wrx.14.2023.01.15.02.18.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 15 Jan 2023 02:18:27 -0800 (PST) Message-ID: Date: Sun, 15 Jan 2023 11:15:48 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: [PATCH v3 2/3] i2c: algo: bit: allow getsda to be NULL Content-Language: en-US From: Heiner Kallweit To: Rob Herring , Krzysztof Kozlowski , Wolfram Sang Cc: "linux-i2c@vger.kernel.org" , "devicetree@vger.kernel.org" References: <3a5545f3-f858-2c80-8bd4-2e0d401a1dc0@gmail.com> In-Reply-To: <3a5545f3-f858-2c80-8bd4-2e0d401a1dc0@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org This is in preparation of supporting write-only SDA in i2c-gpio. Signed-off-by: Heiner Kallweit --- v3: - check for adap->getsda in readbytes() - align warning message level for info on missing getscl/getsda --- drivers/i2c/algos/i2c-algo-bit.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c index fc90293af..a1b822723 100644 --- a/drivers/i2c/algos/i2c-algo-bit.c +++ b/drivers/i2c/algos/i2c-algo-bit.c @@ -184,8 +184,9 @@ static int i2c_outb(struct i2c_adapter *i2c_adap, unsigned char c) /* read ack: SDA should be pulled down by slave, or it may * NAK (usually to report problems with the data we wrote). + * Always report ACK if SDA is write-only. */ - ack = !getsda(adap); /* ack: sda is pulled low -> success */ + ack = !adap->getsda || !getsda(adap); /* ack: sda is pulled low -> success */ bit_dbg(2, &i2c_adap->dev, "i2c_outb: 0x%02x %s\n", (int)c, ack ? "A" : "NA"); @@ -232,6 +233,10 @@ static int test_bus(struct i2c_adapter *i2c_adap) const char *name = i2c_adap->name; int scl, sda, ret; + /* Testing not possible if both pins are write-only. */ + if (adap->getscl == NULL && adap->getsda == NULL) + return 0; + if (adap->pre_xfer) { ret = adap->pre_xfer(i2c_adap); if (ret < 0) @@ -420,6 +425,10 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) unsigned char *temp = msg->buf; int count = msg->len; const unsigned flags = msg->flags; + struct i2c_algo_bit_data *adap = i2c_adap->algo_data; + + if (!adap->getsda) + return -EOPNOTSUPP; while (count > 0) { inval = i2c_inb(i2c_adap); @@ -670,8 +679,11 @@ static int __i2c_bit_add_bus(struct i2c_adapter *adap, if (ret < 0) return ret; - /* Complain if SCL can't be read */ + if (bit_adap->getsda == NULL) + dev_warn(&adap->dev, "Not I2C compliant: can't read SDA\n"); + if (bit_adap->getscl == NULL) { + /* Complain if SCL can't be read */ dev_warn(&adap->dev, "Not I2C compliant: can't read SCL\n"); dev_warn(&adap->dev, "Bus may be unreliable\n"); } From patchwork Sun Jan 15 10:18:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 643011 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F3DEC3DA78 for ; Sun, 15 Jan 2023 10:18:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229545AbjAOKSt (ORCPT ); Sun, 15 Jan 2023 05:18:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230269AbjAOKSc (ORCPT ); Sun, 15 Jan 2023 05:18:32 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D73DDCDEB; Sun, 15 Jan 2023 02:18:30 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id az7so24866604wrb.5; Sun, 15 Jan 2023 02:18:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:subject:references:cc:to:from :content-language:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=QjLp6QWv6hG/L4se1xznm41jj/SIL/KV5mwnUzjGRjg=; b=V2haQMHoal0fFvcaeMRlztSg2HXfsgfRLiGj14vaZT4Ay7nVwHyBixyGeyHxMz8qjz DV4yB2W6Yw2epyhx4BGcpQ7ot3UL6S2apbO8J1dVU+kIWLs/4t40NmK7FrEQn0dUWjsH 9TZ7sMsj90TKmhqd/wNg0+XYFkBTpPEDYWuSN/GeOS62YMVzCTTtRzrD8KH0W6kUpRdz l+B5SlP4btvH00FCClBAvO0b93iuFFhMZKzwKY5HVp3MW4FgujxsYtaUc04UnZpjjMKP e7Ih3pCOXlVZgyqVwDvApeUlKJsgUMZwRxzWmDSBfRaQfe9LV54cv0Q4KWvirSvfCZNh NT8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:subject:references:cc:to:from :content-language:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QjLp6QWv6hG/L4se1xznm41jj/SIL/KV5mwnUzjGRjg=; b=pWnAYvBmSAFmxqHDfAj/UAvjyNIOQ1iXff3/0Y7lKlWhnPRXDSfnrVOkNYPA8u+N7K EEdMtV4HAI1nqGj947UmTSB0uRLQ7rmPMe9nYKqVxhUlM8AlTcjrEei3SPcODzAUDGzz a3te9cw+bn+PEU8/EN7SZVbm8I0Y3oQTgOnqW5m02iAXagmCAfa48I6fYAlO24ZG3ftS 3eaG1zcibVFcgWjkMrMYBktfYK5vNule3mk0lzexIBClyIx3NwdlW8D9DHpOepZOgUNu MlvMgQZCsOe70lDFr/0xVjg5drnQl3gT1FIFeAVFeOkPXUBCde/VqgFZJ9TJYfSpIz7O T1PQ== X-Gm-Message-State: AFqh2kprZwurQYyD/OsQcHrZ5VnCrpWwG0xTRXo6+EBq8YajnCv/dJMv btNAsfx5SdRvGTqrz8PyDSg= X-Google-Smtp-Source: AMrXdXsdMKp8fN+naOGWSJXrvWof5ui/BkPM/JpwR76wJirFQ3AUkLZilNLJUS+/q0RO9JN+yMc3NA== X-Received: by 2002:a5d:4a45:0:b0:2bb:62bf:f5ce with SMTP id v5-20020a5d4a45000000b002bb62bff5cemr19755850wrs.35.1673777909335; Sun, 15 Jan 2023 02:18:29 -0800 (PST) Received: from ?IPV6:2a01:c22:6e61:8c00:154f:326e:8d45:8ce7? (dynamic-2a01-0c22-6e61-8c00-154f-326e-8d45-8ce7.c22.pool.telefonica.de. [2a01:c22:6e61:8c00:154f:326e:8d45:8ce7]) by smtp.googlemail.com with ESMTPSA id k2-20020a5d5182000000b00236545edc91sm23789073wrv.76.2023.01.15.02.18.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 15 Jan 2023 02:18:29 -0800 (PST) Message-ID: Date: Sun, 15 Jan 2023 11:18:05 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Content-Language: en-US From: Heiner Kallweit To: Rob Herring , Krzysztof Kozlowski , Wolfram Sang Cc: "linux-i2c@vger.kernel.org" , "devicetree@vger.kernel.org" References: <3a5545f3-f858-2c80-8bd4-2e0d401a1dc0@gmail.com> Subject: [PATCH v3 3/3] i2c: gpio: support write-only sda In-Reply-To: <3a5545f3-f858-2c80-8bd4-2e0d401a1dc0@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org There are slave devices that understand I2C but have read-only SDA and SCL. Examples are FD650 7-segment LED controller and its derivatives. Typical board designs don't even have a pull-up for both pins. Therefore don't enforce open-drain if SDA and SCL both are unidirectional. This patch makes i2c-gpio usable with such devices, based on new DT property i2c-gpio,sda-output-only. Signed-off-by: Heiner Kallweit --- v3: - improve description of attribute sda_is_output_only --- drivers/i2c/busses/i2c-gpio.c | 14 +++++++++++--- include/linux/platform_data/i2c-gpio.h | 3 +++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c index 0e4385a9b..ea108d7e4 100644 --- a/drivers/i2c/busses/i2c-gpio.c +++ b/drivers/i2c/busses/i2c-gpio.c @@ -316,6 +316,8 @@ static void of_i2c_gpio_get_props(struct device_node *np, of_property_read_bool(np, "i2c-gpio,scl-open-drain"); pdata->scl_is_output_only = of_property_read_bool(np, "i2c-gpio,scl-output-only"); + pdata->sda_is_output_only = + of_property_read_bool(np, "i2c-gpio,sda-output-only"); } static struct gpio_desc *i2c_gpio_get_desc(struct device *dev, @@ -363,6 +365,7 @@ static int i2c_gpio_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct device_node *np = dev->of_node; enum gpiod_flags gflags; + bool sda_scl_output_only; int ret; priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); @@ -391,8 +394,12 @@ static int i2c_gpio_probe(struct platform_device *pdev) * marking these lines to be handled as open drain, and we should just * handle them as we handle any other output. Else we enforce open * drain as this is required for an I2C bus. + * If SCL/SDA both are write-only, then this indicates I2C-like slaves + * with read-only SCL/SDA. Such slaves don't need open-drain, and partially + * don't even work with open-drain. */ - if (pdata->sda_is_open_drain) + sda_scl_output_only = pdata->sda_is_output_only && pdata->scl_is_output_only; + if (pdata->sda_is_open_drain || sda_scl_output_only) gflags = GPIOD_OUT_HIGH; else gflags = GPIOD_OUT_HIGH_OPEN_DRAIN; @@ -400,7 +407,7 @@ static int i2c_gpio_probe(struct platform_device *pdev) if (IS_ERR(priv->sda)) return PTR_ERR(priv->sda); - if (pdata->scl_is_open_drain) + if (pdata->scl_is_open_drain || sda_scl_output_only) gflags = GPIOD_OUT_HIGH; else gflags = GPIOD_OUT_HIGH_OPEN_DRAIN; @@ -418,7 +425,8 @@ static int i2c_gpio_probe(struct platform_device *pdev) if (!pdata->scl_is_output_only) bit_data->getscl = i2c_gpio_getscl; - bit_data->getsda = i2c_gpio_getsda; + if (!pdata->sda_is_output_only) + bit_data->getsda = i2c_gpio_getsda; if (pdata->udelay) bit_data->udelay = pdata->udelay; diff --git a/include/linux/platform_data/i2c-gpio.h b/include/linux/platform_data/i2c-gpio.h index a907774fd..e9536c078 100644 --- a/include/linux/platform_data/i2c-gpio.h +++ b/include/linux/platform_data/i2c-gpio.h @@ -16,6 +16,8 @@ * isn't actively driven high when setting the output value high. * gpio_get_value() must return the actual pin state even if the * pin is configured as an output. + * @sda_is_output_only: SDA output drivers can't be turned off. + * This is for clients that can only read SDA/SCL. * @scl_is_open_drain: SCL is set up as open drain. Same requirements * as for sda_is_open_drain apply. * @scl_is_output_only: SCL output drivers cannot be turned off. @@ -24,6 +26,7 @@ struct i2c_gpio_platform_data { int udelay; int timeout; unsigned int sda_is_open_drain:1; + unsigned int sda_is_output_only:1; unsigned int scl_is_open_drain:1; unsigned int scl_is_output_only:1; };