From patchwork Wed Dec 14 09:23:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tnhuynh@apm.com X-Patchwork-Id: 9473899 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 662B960571 for ; Wed, 14 Dec 2016 09:24:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5304328704 for ; Wed, 14 Dec 2016 09:24:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 47A4C28709; Wed, 14 Dec 2016 09:24:28 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 A14DA28708 for ; Wed, 14 Dec 2016 09:24:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755154AbcLNJYO (ORCPT ); Wed, 14 Dec 2016 04:24:14 -0500 Received: from mail-pg0-f50.google.com ([74.125.83.50]:33289 "EHLO mail-pg0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754951AbcLNJYN (ORCPT ); Wed, 14 Dec 2016 04:24:13 -0500 Received: by mail-pg0-f50.google.com with SMTP id 3so6383265pgd.0 for ; Wed, 14 Dec 2016 01:24:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apm.com; s=apm; h=from:to:cc:subject:date:message-id; bh=plc+DXmgDc5bbbSpQDx5qBlPv5Y8M2RjklET07e1ziA=; b=qXSEKEzNHsuYoakSUcGTvQN/iIM4QLO3hvwDoycXFmwIEbRO2zDXJNH4wEzON3vTgx r79ZGz47W5iJkqUg+EalMvxUVSAOwSydKQYYuMwIeMJVGp8O65A/VRWjHm90w7PY7u1o sDVrzwQ7wcg3bZWs5EcJrl2agxdeo9nz5ZRyE= 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; bh=plc+DXmgDc5bbbSpQDx5qBlPv5Y8M2RjklET07e1ziA=; b=LmZfWKZEU8laU6jV4JJKSCI14mt16yQnnjJ+SS049qTp5EoPRHLZa77jMbP5FzMfOm qMfTWMy4FAtzZEGLnOY0Uali2a4J9lZ92riqfc476Wp58oJWwytUbC+1p33ODrAV8xNe DAnu6TXniSJqaxCshryaKo8L8HddAldcAHKdledIzfza8D2gvVB2K7n7qrJ8WFi/SRyr zk7pkMwkCptxIKdPg+tMFCTfL+s/u93eanqxyolKvbnd79n06b8bG9Plf3TRlNVHzMju 9DS+FPwHnIsbQeO9Y+wdo/ld0gWero8renDfGX8Qu/eKTeJphDSUfV6vbtrH6ljCKBCg /GpQ== X-Gm-Message-State: AKaTC03S4IN+RbiwvuwzK20IXzhYAuh2NPEI9l4LX5xilZG6T8mj6Yw9e1NB4DRX+ri5EyR7 X-Received: by 10.99.207.17 with SMTP id j17mr178509449pgg.57.1481707452529; Wed, 14 Dec 2016 01:24:12 -0800 (PST) Received: from localhost.localdomain ([118.69.219.197]) by smtp.gmail.com with ESMTPSA id e5sm15581975pfd.77.2016.12.14.01.24.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Dec 2016 01:24:10 -0800 (PST) From: Tin Huynh To: Jarkko Nikula , Andy Shevchenko , Mika Westerberg , Wolfram Sang Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Loc Ho , Thang Nguyen , Phong Vo , patches@apm.com, Tin Huynh Subject: [PATCH V5] i2c: designware: fix wrong Tx/Rx FIFO for ACPI Date: Wed, 14 Dec 2016 16:23:58 +0700 Message-Id: <1481707438-32240-1-git-send-email-tnhuynh@apm.com> X-Mailer: git-send-email 1.7.1 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP ACPI always sets Tx/Rx FIFO to 32. This configuration will cause problem if the IP core supports a FIFO size of less than 32. The driver should read the FIFO size from the IP and select the smaller one of the two. Signed-off-by: Tin Huynh Acked-by: Jarkko Nikula Reviewed-by: Mika Westerberg Reviewed-by: Andy Shevchenko --- drivers/i2c/busses/i2c-designware-platdrv.c | 31 ++++++++++++++++++++------ 1 files changed, 24 insertions(+), 7 deletions(-) Change from V4: -Change else condition and add some comments to clarify new approach. Change from V3: -Use uppercase of FIFO instead of lowercase. -Correct else condition when IP core return 0 of FIFO. Change from V2: -Add a helper function to set FIFO size. Change from V1: -Revert the default 32 for FIFO, read parameter from IP core and pick the smaller one of the two. -Correct the title to describe new approach. diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c index 0b42a12..682adc3 100644 --- a/drivers/i2c/busses/i2c-designware-platdrv.c +++ b/drivers/i2c/busses/i2c-designware-platdrv.c @@ -150,6 +150,29 @@ static int i2c_dw_plat_prepare_clk(struct dw_i2c_dev *i_dev, bool prepare) return 0; } +static void dw_i2c_set_fifo_size(struct dw_i2c_dev *dev, int id) +{ + u32 param, tx_fifo_depth, rx_fifo_depth; + + /* + * Try to detect the FIFO depth if not set by interface driver, + * the depth could be from 2 to 256 from HW spec. + */ + param = i2c_dw_read_comp_param(dev); + tx_fifo_depth = ((param >> 16) & 0xff) + 1; + rx_fifo_depth = ((param >> 8) & 0xff) + 1; + if (!dev->tx_fifo_depth) { + dev->tx_fifo_depth = tx_fifo_depth; + dev->rx_fifo_depth = rx_fifo_depth; + dev->adapter.nr = id; + } else if (tx_fifo_depth >= 2) { + dev->tx_fifo_depth = min_t(u32, dev->tx_fifo_depth, + tx_fifo_depth); + dev->rx_fifo_depth = min_t(u32, dev->rx_fifo_depth, + rx_fifo_depth); + } +} + static int dw_i2c_plat_probe(struct platform_device *pdev) { struct dw_i2c_platform_data *pdata = dev_get_platdata(&pdev->dev); @@ -246,13 +269,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) 1000000); } - if (!dev->tx_fifo_depth) { - u32 param1 = i2c_dw_read_comp_param(dev); - - dev->tx_fifo_depth = ((param1 >> 16) & 0xff) + 1; - dev->rx_fifo_depth = ((param1 >> 8) & 0xff) + 1; - dev->adapter.nr = pdev->id; - } + dw_i2c_set_fifo_size(dev, pdev->id); adap = &dev->adapter; adap->owner = THIS_MODULE;