From patchwork Wed Jan 18 21:51:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 643910 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 8038CC32793 for ; Wed, 18 Jan 2023 21:55:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229523AbjARVzx (ORCPT ); Wed, 18 Jan 2023 16:55:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229540AbjARVzn (ORCPT ); Wed, 18 Jan 2023 16:55:43 -0500 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20C7A654C3; Wed, 18 Jan 2023 13:55:42 -0800 (PST) Received: by mail-ed1-x532.google.com with SMTP id y19so608189edc.2; Wed, 18 Jan 2023 13:55:42 -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=GGp3fURHIN1KwNTqdNdjD2I+NMZ/HjTDkqRonIyKzP0=; b=Q7l9Y1KCwtVaG6F9kdtLyBSEuBe9Yq3gfImFqR7ha0I8Hs637R5+dp4JuFyFwqCLhO jdWNEGAN6CrCd4BgLoN5NV/kcE6BrjkevUpja9/Uzzaxq5qnVSOSnO1P9qlcUtjcjvr+ bJ/27XJtmktx8uUC3R5KeY3QtEr+UIkI3cls+blmzmNUOVKUwUd1OQ+WG2ob507W1GbH 7e7Phgr2uI3Hu2PLKsR3stHLwH1JuSPxWI6OY02cgdVE7zUfMjbDGEqYZW250KH2R5Jv WQhxCA6PcBEh1auAmWSlrmMHiw8XaJYZKI+Ff6iCVfyJh8GP9ERA+MFbx+c957OkLtMA kolw== 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=GGp3fURHIN1KwNTqdNdjD2I+NMZ/HjTDkqRonIyKzP0=; b=sbmZL0Y+ExiTLMAePWa3C5QDsR7XuPHHaZ0JL34G6cRY/gkYHIVl1EF4J4fNqdHnUq IO8dX1yibKFsglqPxaVr0R6X5IzbO3u3jszcN4h2jvc0KSq18jOeL8mbH0vsmIsT7hHT rIaD0jMl33djlUbYGVLdCz3UeoAvaEncO+DWSJmWwDmdoYdkNceVbXkZFa05CJUJgDaz txGo5n9nuqLwksW7DFkpsiSYEjoQ/JT1virF893aC7Wo4PfPs08XrtDluGv674tBtq9n RCOWFX86bTbwJ4N9wGTh+cwKoy8sXrr2r5hxcVWN0yDCbbGVxttzyxglwjmFj5QHDcFg agKA== X-Gm-Message-State: AFqh2ko3MIsmVqcdQ0q0NlUE4MBO1KxFpJA4BGnzTBpLdBPfeNq8g5JQ AogFotq0hqzmtIAF/NP4yOU= X-Google-Smtp-Source: AMrXdXuqflzAwGKvmroxu08+OTiyKxYQ7H5wD0vfImmUnbT33aaMzx7ga+j2/CIdWWMADLRXdwWodQ== X-Received: by 2002:aa7:c0d4:0:b0:48f:acd1:8da2 with SMTP id j20-20020aa7c0d4000000b0048facd18da2mr9071632edp.27.1674078940653; Wed, 18 Jan 2023 13:55:40 -0800 (PST) Received: from ?IPV6:2a02:3100:94be:5400:80c7:5ea4:ed2f:1a59? (dynamic-2a02-3100-94be-5400-80c7-5ea4-ed2f-1a59.310.pool.telefonica.de. [2a02:3100:94be:5400:80c7:5ea4:ed2f:1a59]) by smtp.googlemail.com with ESMTPSA id l4-20020a056402344400b004822681a671sm14775284edc.37.2023.01.18.13.55.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Jan 2023 13:55:40 -0800 (PST) Message-ID: <8eb4fb92-ea53-fb4e-4cdd-daed4ad96806@gmail.com> Date: Wed, 18 Jan 2023 22:51:58 +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 v5 1/3] dt-bindings: i2c-gpio: Add properties for dealing with write-only SDA/SCL w/o pullup Content-Language: en-US From: Heiner Kallweit To: Rob Herring , Krzysztof Kozlowski , Wolfram Sang , Peter Rosin Cc: "linux-i2c@vger.kernel.org" , "devicetree@vger.kernel.org" References: <6f4b54d9-ab6d-a4d4-5142-27c89e03c6d2@gmail.com> In-Reply-To: <6f4b54d9-ab6d-a4d4-5142-27c89e03c6d2@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 add properties for not using open-drain. For write-only SCL we have a property already, add one for write-only SDA. Signed-off-by: Heiner Kallweit Reviewed-by: Rob Herring --- v4: - add no-pullup properties v5: - add checking mutually-exclusive properties to schema --- .../devicetree/bindings/i2c/i2c-gpio.yaml | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Documentation/devicetree/bindings/i2c/i2c-gpio.yaml b/Documentation/devicetree/bindings/i2c/i2c-gpio.yaml index e0d76d5eb..afd4925c2 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 @@ -63,6 +67,28 @@ properties: GPIO line used for SCL into open drain mode, and that something is not the GPIO chip. It is essentially an inconsistency flag. + i2c-gpio,sda-has-no-pullup: + type: boolean + description: sda is used in a non-compliant way and has no pull-up. + Therefore disable open-drain. This property is mutually-exclusive + with i2c-gpio,sda-open-drain. + + i2c-gpio,scl-has-no-pullup: + type: boolean + description: scl is used in a non-compliant way and has no pull-up. + Therefore disable open-drain. This property is mutually-exclusive + with i2c-gpio,scl-open-drain. + +dependencies: + i2c-gpio,sda-has-no-pullup: + not: + required: + - i2c-gpio,sda-open-drain + i2c-gpio,scl-has-no-pullup: + not: + required: + - i2c-gpio,scl-open-drain + required: - compatible - sda-gpios From patchwork Wed Jan 18 21:54:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 643909 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 64A55C38159 for ; Wed, 18 Jan 2023 21:55:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229620AbjARVzy (ORCPT ); Wed, 18 Jan 2023 16:55:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229883AbjARVzo (ORCPT ); Wed, 18 Jan 2023 16:55:44 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FFF7654DA; Wed, 18 Jan 2023 13:55:43 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id mp20so785928ejc.7; Wed, 18 Jan 2023 13:55:43 -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=1jWUcSxNgYzoZDSCAYfnIccXHRmHbJtKyjM0QyMRP9U=; b=a6DpNQy/Nue9NvVoK9sWIoGFZHS601a0NvJtTiWJCBw0V0eEOkvxxCjW9Uy8pxf2ma AP8Wl99VMGiLIMy8uGp37awcG/JzzQKALMQwv0K6G3KgrDWK+JdG2E4IkBgHqgCFQj98 CkYync2Nc7N1XAomaDfea46SZE4ojEGpt99WfUEyTpQnBI4rmhiKECW6R6BXgEl0tZbd Tf+eCYjaKP+n5yj8NTp0K3bgydczY64k5vRF6slpAEeTeyksSKGhtv+UbQEEYab9gXPW OB+hLGXmBoBuMkN0uKj2pqFJmHKxvgdM6Bv70TLH7DlljBD0PebThPK0BaICabvGPriU Yj/A== 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=1jWUcSxNgYzoZDSCAYfnIccXHRmHbJtKyjM0QyMRP9U=; b=q6XLGsckhHDVtaSgQJrppbbj2QlKbrXkIRie0uFs9bTRhlb04ZAUEvPlRC97Wywxuf RV93xbpDmyK1RceF1c+xbsOWBOMJYHFKge+XABD3gnvxNX7516s1KaQB2OEKrtz/3JOl c/ngfd+gr6ZYUjnk1eAOK3ed+1GfKX1LL6vBcxkOjZN1qSX6hYeHSGm887yp++s0Le4g K82rBKOvm5DmgK32485+ELgaIEd9JhG81qxO9dbe2C8q2Mjy3jEDJmLzs2GTY93SiBOD AmyxpDEy2iUNEnCyUXHT+Naa0iGzqFKCkOxqi34bxsd1ngp4azUBnRj7bXchvJALvzK7 o+vw== X-Gm-Message-State: AFqh2kqG8sgw+pMd5NTUU3dueCl8ZH0dYnicyr+Zw3YAnt8G3DW5MuNu YYZBlMjNV9QBm3AobCpWzcA= X-Google-Smtp-Source: AMrXdXuBInZTTUba2Gd8fQSU6zasqD+20MrIr2ZTzauJ/mkSsj0La6ClGk0DvRyOHHRQ/qLxIEyk0A== X-Received: by 2002:a17:906:5da8:b0:7b2:c227:126d with SMTP id n8-20020a1709065da800b007b2c227126dmr5350704ejv.20.1674078941956; Wed, 18 Jan 2023 13:55:41 -0800 (PST) Received: from ?IPV6:2a02:3100:94be:5400:80c7:5ea4:ed2f:1a59? (dynamic-2a02-3100-94be-5400-80c7-5ea4-ed2f-1a59.310.pool.telefonica.de. [2a02:3100:94be:5400:80c7:5ea4:ed2f:1a59]) by smtp.googlemail.com with ESMTPSA id b1-20020a1709063ca100b007af0f0d2249sm15252848ejh.52.2023.01.18.13.55.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Jan 2023 13:55:41 -0800 (PST) Message-ID: <83ab7926-2db3-ef60-8356-53bc517a22a8@gmail.com> Date: Wed, 18 Jan 2023 22:54:03 +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 v5 2/3] i2c: algo: bit: allow getsda to be NULL Content-Language: en-US From: Heiner Kallweit To: Rob Herring , Krzysztof Kozlowski , Wolfram Sang , Peter Rosin Cc: "linux-i2c@vger.kernel.org" , "devicetree@vger.kernel.org" References: <6f4b54d9-ab6d-a4d4-5142-27c89e03c6d2@gmail.com> In-Reply-To: <6f4b54d9-ab6d-a4d4-5142-27c89e03c6d2@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 v4: - handle SDA and SCL independently - properly handle case that SDA is NULL but SCL not --- drivers/i2c/algos/i2c-algo-bit.c | 77 +++++++++++++++----------------- 1 file changed, 35 insertions(+), 42 deletions(-) diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c index fc90293af..eddf25b90 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"); @@ -238,71 +239,55 @@ static int test_bus(struct i2c_adapter *i2c_adap) return -ENODEV; } + if (adap->getsda == NULL) + pr_info("%s: SDA is write-only, testing not possible\n", name); if (adap->getscl == NULL) - pr_info("%s: Testing SDA only, SCL is not readable\n", name); + pr_info("%s: SCL is write-only, testing not possible\n", name); - sda = getsda(adap); - scl = (adap->getscl == NULL) ? 1 : getscl(adap); + sda = adap->getsda ? getsda(adap) : 1; + scl = adap->getscl ? getscl(adap) : 1; if (!scl || !sda) { - printk(KERN_WARNING - "%s: bus seems to be busy (scl=%d, sda=%d)\n", - name, scl, sda); + pr_warn("%s: bus seems to be busy (scl=%d, sda=%d)\n", name, scl, sda); goto bailout; } sdalo(adap); - sda = getsda(adap); - scl = (adap->getscl == NULL) ? 1 : getscl(adap); - if (sda) { - printk(KERN_WARNING "%s: SDA stuck high!\n", name); + if (adap->getsda && getsda(adap)) { + pr_warn("%s: SDA stuck high!\n", name); goto bailout; } - if (!scl) { - printk(KERN_WARNING - "%s: SCL unexpected low while pulling SDA low!\n", - name); + if (adap->getscl && !getscl(adap)) { + pr_warn("%s: SCL unexpected low while pulling SDA low!\n", name); goto bailout; } sdahi(adap); - sda = getsda(adap); - scl = (adap->getscl == NULL) ? 1 : getscl(adap); - if (!sda) { - printk(KERN_WARNING "%s: SDA stuck low!\n", name); + if (adap->getsda && !getsda(adap)) { + pr_warn("%s: SDA stuck low!\n", name); goto bailout; } - if (!scl) { - printk(KERN_WARNING - "%s: SCL unexpected low while pulling SDA high!\n", - name); + if (adap->getscl && !getscl(adap)) { + pr_warn("%s: SCL unexpected low while pulling SDA high!\n", name); goto bailout; } scllo(adap); - sda = getsda(adap); - scl = (adap->getscl == NULL) ? 0 : getscl(adap); - if (scl) { - printk(KERN_WARNING "%s: SCL stuck high!\n", name); + if (adap->getscl && getscl(adap)) { + pr_warn("%s: SCL stuck high!\n", name); goto bailout; } - if (!sda) { - printk(KERN_WARNING - "%s: SDA unexpected low while pulling SCL low!\n", - name); + if (adap->getsda && !getsda(adap)) { + pr_warn("%s: SDA unexpected low while pulling SCL low!\n", name); goto bailout; } sclhi(adap); - sda = getsda(adap); - scl = (adap->getscl == NULL) ? 1 : getscl(adap); - if (!scl) { - printk(KERN_WARNING "%s: SCL stuck low!\n", name); + if (adap->getscl && !getscl(adap)) { + pr_warn("%s: SCL stuck low!\n", name); goto bailout; } - if (!sda) { - printk(KERN_WARNING - "%s: SDA unexpected low while pulling SCL high!\n", - name); + if (adap->getsda && !getsda(adap)) { + pr_warn("%s: SDA unexpected low while pulling SCL high!\n", name); goto bailout; } @@ -420,6 +405,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,11 +659,15 @@ 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->getscl == NULL) { + if (bit_adap->getsda == NULL) + dev_warn(&adap->dev, "Not I2C compliant: can't read SDA\n"); + + if (bit_adap->getscl == NULL) dev_warn(&adap->dev, "Not I2C compliant: can't read SCL\n"); + + if (bit_adap->getsda == NULL || bit_adap->getscl == NULL) dev_warn(&adap->dev, "Bus may be unreliable\n"); - } + return 0; } From patchwork Wed Jan 18 21:55:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 644835 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 5115CC46467 for ; Wed, 18 Jan 2023 21:55:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229766AbjARVzy (ORCPT ); Wed, 18 Jan 2023 16:55:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229886AbjARVzp (ORCPT ); Wed, 18 Jan 2023 16:55:45 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1C8B654E6; Wed, 18 Jan 2023 13:55:44 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id ud5so819889ejc.4; Wed, 18 Jan 2023 13:55:44 -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=Qhuunm12DEUADeX8dZ1+bPKvTYYCnKP/G5wxRkVG32M=; b=LcElQn9P1CW+7ADiCD8xLqPt5LHhfMwa70qarg6E0Wqr2HWQHtW+4v/6OIQGMpuxB2 lRFAFdVAEKCOpbyV0OFgCTk9LBtYkHiLVADUeDKluHQb2KM5BHg1CRdsN3NkI7rtS3o5 l6EJ5EreHncxlG1HWskT5TIqlM/j9HeXLxB9hBx9VtwXL0Fe9pH2ctygfw1RFsMGBJ0Y sPlXbNEbBMQ2doJwBVXhRfIdD7aqX4IcA4xXHdZNHdosYNnsT5rywT3S79pwgEHjAvQy Ho+oOCPl3buhkueBTQVe2lbptKGveW4hnghvxNqEkTsx2E4RLLBrqeOozPnXBefwH0lq QyLw== 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=Qhuunm12DEUADeX8dZ1+bPKvTYYCnKP/G5wxRkVG32M=; b=qN3G2k8XStCCciG8hk86Vtr93L2HK9QNn5Ujp+3fa5yd/KE+adNO8XH0b3BQVXKQmE MeXSfcZm6NKFUcTb16Sx5+m2p78mmvsxD9OfH75j+EDLK9zH0dNG6h+ZaTcfyr5BceO7 AVk5wVKLLH79k2nx8lB2yifmU/4Qutz5S+umdUckkMHmd/6dYV7JeheeAdsbIZ8q/Av5 Q8IVADa6XwX/PMJcB6y4jCRW1ukIoALEBxqMqTE7nCsb2eLZPeoCdeZqPFStCPaJz7Pw BjIK8GORbmZd2nCeDtkga9fziV9jqF1mU4gsPt2EQzAoPit9yhkf86yTng1kCYmv8C1W 11PQ== X-Gm-Message-State: AFqh2kotx+PivQjmpKwNw66/TJ+FgX0ehWh/W1gV/rV1tbb55pBPVG8Y ofgzlbSqm/VtnjW4yB04j+U= X-Google-Smtp-Source: AMrXdXvXesO0DESwI62c2ayyyHVtZxgk0ZwMlinh+TTr3Qw5aQROnFmrkTeJZSzw+qSj9XGUhKY8AA== X-Received: by 2002:a17:906:af14:b0:844:de87:8684 with SMTP id lx20-20020a170906af1400b00844de878684mr8899504ejb.46.1674078943224; Wed, 18 Jan 2023 13:55:43 -0800 (PST) Received: from ?IPV6:2a02:3100:94be:5400:80c7:5ea4:ed2f:1a59? (dynamic-2a02-3100-94be-5400-80c7-5ea4-ed2f-1a59.310.pool.telefonica.de. [2a02:3100:94be:5400:80c7:5ea4:ed2f:1a59]) by smtp.googlemail.com with ESMTPSA id y11-20020aa7c24b000000b004954c90c94bsm14835385edo.6.2023.01.18.13.55.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Jan 2023 13:55:42 -0800 (PST) Message-ID: <7eea145d-d5a7-052c-e458-18f3b842c2ec@gmail.com> Date: Wed, 18 Jan 2023 22:55:12 +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 v5 3/3] i2c: gpio: support write-only sda/scl w/o pull-up Content-Language: en-US From: Heiner Kallweit To: Rob Herring , Krzysztof Kozlowski , Wolfram Sang , Peter Rosin Cc: "linux-i2c@vger.kernel.org" , "devicetree@vger.kernel.org" References: <6f4b54d9-ab6d-a4d4-5142-27c89e03c6d2@gmail.com> In-Reply-To: <6f4b54d9-ab6d-a4d4-5142-27c89e03c6d2@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. Handle the new attributes for write-only SDA and missing pull-up on SDA/SCL. For either pin the open-drain and has-no-pullup properties are mutually-exclusive, what is documented in the DT property documentation. We don't add an extra warning here because the open-drain properties are marked deprecated anyway. Signed-off-by: Heiner Kallweit --- v3: - improve description of attribute sda_is_output_only v4: - handle new no-pullup attributes --- drivers/i2c/busses/i2c-gpio.c | 13 ++++++++++--- include/linux/platform_data/i2c-gpio.h | 9 +++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c index 0e4385a9b..85b3beb20 100644 --- a/drivers/i2c/busses/i2c-gpio.c +++ b/drivers/i2c/busses/i2c-gpio.c @@ -316,6 +316,12 @@ 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"); + pdata->sda_has_no_pullup = + of_property_read_bool(np, "i2c-gpio,sda-has-no-pullup"); + pdata->scl_has_no_pullup = + of_property_read_bool(np, "i2c-gpio,scl-has-no-pullup"); } static struct gpio_desc *i2c_gpio_get_desc(struct device *dev, @@ -392,7 +398,7 @@ static int i2c_gpio_probe(struct platform_device *pdev) * handle them as we handle any other output. Else we enforce open * drain as this is required for an I2C bus. */ - if (pdata->sda_is_open_drain) + if (pdata->sda_is_open_drain || pdata->sda_has_no_pullup) gflags = GPIOD_OUT_HIGH; else gflags = GPIOD_OUT_HIGH_OPEN_DRAIN; @@ -400,7 +406,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 || pdata->scl_has_no_pullup) gflags = GPIOD_OUT_HIGH; else gflags = GPIOD_OUT_HIGH_OPEN_DRAIN; @@ -418,7 +424,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..545639bcc 100644 --- a/include/linux/platform_data/i2c-gpio.h +++ b/include/linux/platform_data/i2c-gpio.h @@ -16,16 +16,25 @@ * 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. + * @sda_has_no_pullup: SDA is used in a non-compliant way and has no pull-up. + * Therefore disable open-drain. * @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. + * @scl_has_no_pullup: SCL is used in a non-compliant way and has no pull-up. + * Therefore disable open-drain. */ 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 sda_has_no_pullup:1; unsigned int scl_is_open_drain:1; unsigned int scl_is_output_only:1; + unsigned int scl_has_no_pullup:1; }; #endif /* _LINUX_I2C_GPIO_H */