From patchwork Tue Dec 13 10:03:34 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: 9471979 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 BD89060760 for ; Tue, 13 Dec 2016 10:03:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A46F284E0 for ; Tue, 13 Dec 2016 10:03:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8ECFA284EB; Tue, 13 Dec 2016 10:03:53 +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=ham 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 D69A2284E0 for ; Tue, 13 Dec 2016 10:03:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932859AbcLMKDv (ORCPT ); Tue, 13 Dec 2016 05:03:51 -0500 Received: from mail-pf0-f173.google.com ([209.85.192.173]:33161 "EHLO mail-pf0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932446AbcLMKDu (ORCPT ); Tue, 13 Dec 2016 05:03:50 -0500 Received: by mail-pf0-f173.google.com with SMTP id d2so18104473pfd.0 for ; Tue, 13 Dec 2016 02:03:49 -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=6+tjkU9juoppp/f7/Y6cRc08nrlczH86+ivmSBIF9gE=; b=C0TNTrPYLuNWpReKs0vkvEd3/PKDN7O2y0loLDI0YuLMSSrDxuAytm05DOSbYOR7zk 3w8GKb8/1dnlSZj1du14nlQw7DNM7/32399xsfCXiu9uULhP2RwQlvehnx0a8avQi3dA BG/hmUwEoXBXrfY3EQ8B3T75KJlj+I6/NIUtU= 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=6+tjkU9juoppp/f7/Y6cRc08nrlczH86+ivmSBIF9gE=; b=eOB/kQPbawBbiGy2eySUhbrML75X7teAvdspVorX2kqYUx3wADIYhnJMwzg9fQ4YaI muLflyorHyUJrNG2u8HFy1HhBqZ/qyxb6JvREtlda1L0cXl+lUSNYxqHJy5n3qYqIMSH xWczV9nOXMg1mfeQa1jQDvJz+JSl3v051Qmz0N2faSm0hUlIXneVXDhG8ZhzVNAU3Ws0 U9+pKSXBbAtpQwMHS3MZYX9XC36HlZWVSSdPqNfNjBZDVgWWghQDrVtJ/J+SsR4T5uk0 cRX7Yos0RH/ZZTK8nomrnCPwve7uyi69IDKVMFelVmo6OQbUo/Y8Ij4p6tY7BBaQafCw sVxQ== X-Gm-Message-State: AKaTC01F2GaCXAtKo0/irPxihTfKmPZVrH6Ty8iV4RDaEekYILd4IFdxuH6CjvSPtBuMlPjq X-Received: by 10.84.210.73 with SMTP id z67mr194815446plh.171.1481623429253; Tue, 13 Dec 2016 02:03:49 -0800 (PST) Received: from localhost.localdomain ([118.69.219.197]) by smtp.gmail.com with ESMTPSA id a22sm79836147pfg.7.2016.12.13.02.03.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Dec 2016 02:03:48 -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 V4] i2c: designware: fix wrong Tx/Rx FIFO for ACPI Date: Tue, 13 Dec 2016 17:03:34 +0700 Message-Id: <1481623414-19220-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 Reviewed-by: Andy Shevchenko Acked-by: Jarkko Nikula --- drivers/i2c/busses/i2c-designware-platdrv.c | 27 ++++++++++++++++++++------- 1 files changed, 20 insertions(+), 7 deletions(-) Change from V3: -Use uppercase of FIFO instead of lowercase. -Fix the problem 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..24032d6 100644 --- a/drivers/i2c/busses/i2c-designware-platdrv.c +++ b/drivers/i2c/busses/i2c-designware-platdrv.c @@ -150,6 +150,25 @@ 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; + + 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 > 1) { + 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 +265,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;