From patchwork Mon Dec 12 08:36:50 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: 9470171 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 C893A60476 for ; Mon, 12 Dec 2016 08:37:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF554282DC for ; Mon, 12 Dec 2016 08:37:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B38F328427; Mon, 12 Dec 2016 08:37:21 +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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 54AA3282DC for ; Mon, 12 Dec 2016 08:37:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753571AbcLLIhD (ORCPT ); Mon, 12 Dec 2016 03:37:03 -0500 Received: from mail-pg0-f53.google.com ([74.125.83.53]:33993 "EHLO mail-pg0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751983AbcLLIhC (ORCPT ); Mon, 12 Dec 2016 03:37:02 -0500 Received: by mail-pg0-f53.google.com with SMTP id x23so33196770pgx.1 for ; Mon, 12 Dec 2016 00:37:02 -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=55fmSqHdesJMeDiB3WsQzLgDRvFjh2Fu8enuYyN51iY=; b=PyR8QaB3GxYhZNN6iDMpTcNOcmDm5Vrod0kHfUDA6zLIOYeVE770FnSjP54zSC4pNq j+LESHnFs3DykiImVIbQeqdCeC032eRGWJqHu8mom3uNIg1y6XXH3BJOrXmEqp+rEGNY tzwTF3U3uV8ieQNPbVLCsxCaCUdFIrkcodut0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=55fmSqHdesJMeDiB3WsQzLgDRvFjh2Fu8enuYyN51iY=; b=H2BrknfzSciGEE2EFdbxuTT+ZO62Y1UZlie95uUbtE1D7nbWyYo3w2cVW7kxy4z6cp Dih4rxsyJ2lVD4lE8deafSwzFH2ZhQJCd32Bskx6GKzIDE5/eapnG0lWVo/Dl3ooa9e3 PFQJTDpeANaECYZ2wU0vkzB6rx1uqjV+9RNTDTSuLO8vKSeroH4+w/xmRe8sRXdew3Nd DJ3vejqrz3JNeXpRiP4Pb3iO+1GpOPI1+1mxfgJFcuEEVEvxhMRcr3QAios8ZmMvkt6L 7nbAniGFFFAUP/GMdQAfxmRrV0OQ92p88DPAtZoyn3QCHCILWmlmILDX+fFjMXiFgfQX 3kgQ== X-Gm-Message-State: AKaTC00XiGES+K6Oao3iBbcf2mwFLY41n1YCmoXnyi+MylHXB6EdFzpZ3RTvVuxzF7BVPGsT X-Received: by 10.84.173.4 with SMTP id o4mr186164227plb.123.1481531822129; Mon, 12 Dec 2016 00:37:02 -0800 (PST) Received: from localhost.localdomain ([118.69.219.197]) by smtp.gmail.com with ESMTPSA id w5sm74444049pfl.31.2016.12.12.00.36.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Dec 2016 00:37:00 -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 V3] i2c: designware: fix wrong tx/rx fifo for ACPI Date: Mon, 12 Dec 2016 15:36:50 +0700 Message-Id: <1481531810-31695-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 txfifo and rxfifo 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 --- drivers/i2c/busses/i2c-designware-platdrv.c | 26 ++++++++++++++++++++------ 1 files changed, 20 insertions(+), 6 deletions(-) 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..665f491 100644 --- a/drivers/i2c/busses/i2c-designware-platdrv.c +++ b/drivers/i2c/busses/i2c-designware-platdrv.c @@ -150,6 +150,24 @@ 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) +{ + u32 param1, tx_fifo_depth, rx_fifo_depth; + + param1 = i2c_dw_read_comp_param(dev); + tx_fifo_depth = ((param1 >> 16) & 0xff) + 1; + rx_fifo_depth = ((param1 >> 8) & 0xff) + 1; + if (!dev->tx_fifo_depth) { + dev->tx_fifo_depth = tx_fifo_depth; + dev->rx_fifo_depth = rx_fifo_depth; + } else if (tx_fifo_depth) { + 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 +264,9 @@ 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; + if (!dev->tx_fifo_depth) dev->adapter.nr = pdev->id; - } + dw_i2c_set_fifo_size(dev); adap = &dev->adapter; adap->owner = THIS_MODULE;