From patchwork Fri Jul 26 08:53:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hsin-Yi Wang X-Patchwork-Id: 11060583 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DB16E13AC for ; Fri, 26 Jul 2019 08:54:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8CA3289D6 for ; Fri, 26 Jul 2019 08:54:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC48C28A59; Fri, 26 Jul 2019 08:54:15 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 67053289D6 for ; Fri, 26 Jul 2019 08:54:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=EwWJLq8N5sMi8X4ihB9uCkfkDb17l6yhbECIFmUsgvE=; b=drB8ecLmfNbLgm DnfwzHw7ymjSVHnrCRtshGgb2T7Jr8OJco+55EmwSr7Z+8o9iTBKCWAXjnKTN5C8+PRfpehjRA4mU p7JSLK4fEzfnXEAj8j5xQpWwjHPlqQKwCezLvNkv5GDoF37qr6hEfj/IF7j/8UjSeSZusNPhxk5y5 qDZ/bLzZtCm4a7YNJedC4BdL3Cp0Q0lc9TCCyZFpS+2M3RCbE9JHFkvXym14sPON3K06o4Ph3rugm F+/HaGFzMvq4OoX6DdzXV4mMDNMxalGII5Phobgrne78+trJI19UgRdZrlCLQzZGqd/ud3SaC8DO/ ueReZeTdLkvdDoTbaMOg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hqvzS-0001CR-7f; Fri, 26 Jul 2019 08:54:14 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hqvzC-00010t-RQ for linux-mediatek@lists.infradead.org; Fri, 26 Jul 2019 08:54:00 +0000 Received: by mail-pg1-x542.google.com with SMTP id f5so15631879pgu.5 for ; Fri, 26 Jul 2019 01:53:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Kn51c4iVY6vEKLBAUEgNeUWaRLfBi8NFzSwtDO3qJPo=; b=ZrwXgOysV4Nm38G/Jd5hjo4ESfSee36UHEVzuju2NmMPD0fUC94XqOIjPS/vdAra91 GePNmRjhbOHDSzgaRjaMUMHG2ycRlVIjQlvGTHCJ6xkeIKiWZn0uDU1XyD51GtXPWUIZ 1aTRStwb5PMDv7h+ojMqDKzg/9hv/j4m2tbSs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Kn51c4iVY6vEKLBAUEgNeUWaRLfBi8NFzSwtDO3qJPo=; b=p9fFx1H51wzQ2CwtW1Y15L/q9l7G4kALY5WedBJVieukhD2EqCHqFfEt1qwLbY/MpB f8B2hKei6JB/Xa0whYBYQfJvFiwSVCR3U7P+rOUGeff7Ga1oAkJNo6jenxwVIJ9zPjSt IJYmu9sl+7X31Ne1ENTJ0+ahz2C4fX/V32mG6wZyv18tFpVEvd1rXfKl2LYd0Yfc8b0M jtR5cbqPDe0nXYCJ2WR8J5JJfq5dEM2UG1yUiVx8QAa934193wdY65n9DYwEBULxAPEk AicdopRJHQbvSwoP+e1fwCsBLULN/b9kOj8d1SitZOTTuaG90jm5aFbOVucl9oz86uOm yhWQ== X-Gm-Message-State: APjAAAUQ4qPvWV5oNrnZvDiw20pQEH5f6+tDFdMFcXtjNZtp4mLE5WVx lgKOjCmeZKKlo5YziuQ19E2Jpg== X-Google-Smtp-Source: APXvYqwEl1k8U3GLoPPwct03h2YHbh18gkXJVzJDcKZV2mmsK3QGn7e5o8uX6/Q7RDC9oULrHaYOvA== X-Received: by 2002:a63:c03:: with SMTP id b3mr26309020pgl.23.1564131237150; Fri, 26 Jul 2019 01:53:57 -0700 (PDT) Received: from hsinyi-z840.tpe.corp.google.com ([2401:fa00:1:10:b852:bd51:9305:4261]) by smtp.gmail.com with ESMTPSA id p15sm49438737pjf.27.2019.07.26.01.53.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jul 2019 01:53:56 -0700 (PDT) From: Hsin-Yi Wang To: linux-arm-kernel@lists.infradead.org Subject: [PATCH] i2c: mediatek: disable zero-length transfers for mt8183 Date: Fri, 26 Jul 2019 16:53:06 +0800 Message-Id: <20190726085305.163306-1-hsinyi@chromium.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190726_015358_916508_3DBF7A7F X-CRM114-Status: GOOD ( 11.12 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicolas Boichat , Alexandru M Stan , Wolfram Sang , Jun Gao , linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-i2c@vger.kernel.org, Hsin-Yi Wang , Matthias Brugger , Thomas Gleixner , Qii Wang Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP When doing i2cdetect quick write mode, we would get transfer error ENOMEM, and i2cdetect shows there's no device at the address. Quoting from mt8183 datasheet, the number of transfers to be transferred in one transaction should be set to bigger than 1, so we should forbid zero-length transfer and update functionality. Incorrect return: localhost ~ # i2cdetect -q -y 0 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- -- After this patch: localhost ~ # i2cdetect -q -y 0 Error: Can't use SMBus Quick Write command on this bus localhost ~ # i2cdetect -y 0 Warning: Can't use SMBus Quick Write command, will skip some addresses 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: 10: 20: 30: -- -- -- -- -- -- -- -- 40: 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: 70: Reported-by: Alexandru M Stan Signed-off-by: Hsin-Yi Wang --- Previous patch and discussion: http://patchwork.ozlabs.org/patch/1042684/ --- drivers/i2c/busses/i2c-mt65xx.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c index 252edb433fdf..2842ca4b8c3b 100644 --- a/drivers/i2c/busses/i2c-mt65xx.c +++ b/drivers/i2c/busses/i2c-mt65xx.c @@ -234,6 +234,10 @@ static const struct i2c_adapter_quirks mt7622_i2c_quirks = { .max_num_msgs = 255, }; +static const struct i2c_adapter_quirks mt8183_i2c_quirks = { + .flags = I2C_AQ_NO_ZERO_LEN, +}; + static const struct mtk_i2c_compatible mt2712_compat = { .regs = mt_i2c_regs_v1, .pmic_i2c = 0, @@ -298,6 +302,7 @@ static const struct mtk_i2c_compatible mt8173_compat = { }; static const struct mtk_i2c_compatible mt8183_compat = { + .quirks = &mt8183_i2c_quirks, .regs = mt_i2c_regs_v2, .pmic_i2c = 0, .dcm = 0, @@ -870,7 +875,11 @@ static irqreturn_t mtk_i2c_irq(int irqno, void *dev_id) static u32 mtk_i2c_functionality(struct i2c_adapter *adap) { - return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; + if (adap->quirks->flags & I2C_AQ_NO_ZERO_LEN) + return I2C_FUNC_I2C | + (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK); + else + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; } static const struct i2c_algorithm mtk_i2c_algorithm = { @@ -933,8 +942,8 @@ static int mtk_i2c_probe(struct platform_device *pdev) i2c->dev = &pdev->dev; i2c->adap.dev.parent = &pdev->dev; i2c->adap.owner = THIS_MODULE; - i2c->adap.algo = &mtk_i2c_algorithm; i2c->adap.quirks = i2c->dev_comp->quirks; + i2c->adap.algo = &mtk_i2c_algorithm; i2c->adap.timeout = 2 * HZ; i2c->adap.retries = 1;