From patchwork Mon Jan 5 01:32:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Lin X-Patchwork-Id: 5564541 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CB9BA9F357 for ; Mon, 5 Jan 2015 01:33:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CEE9920166 for ; Mon, 5 Jan 2015 01:33:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DFD8920165 for ; Mon, 5 Jan 2015 01:33:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752868AbbAEBdC (ORCPT ); Sun, 4 Jan 2015 20:33:02 -0500 Received: from mail-pa0-f52.google.com ([209.85.220.52]:56358 "EHLO mail-pa0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751773AbbAEBdC (ORCPT ); Sun, 4 Jan 2015 20:33:02 -0500 Received: by mail-pa0-f52.google.com with SMTP id eu11so27659812pac.39 for ; Sun, 04 Jan 2015 17:33:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:subject:from:to:cc:date:content-type :mime-version:content-transfer-encoding; bh=vDK5yINMJ2EAC4nsrKhmRr0SHM16f7nE50JNJHxBPKg=; b=Xt+cyt4cf5AP/6dpRg/wrN7jA6mSvSB0iDvDBPwzogky2oyrfnNUDauwYJM+/FbdxG ekOifvuCbNYC1A4foRIM2pi9Bu1nH1zJJT8pXVOV53Itfrh65qaxWEO6GLV5UcveVDZ4 B202Zb5VNhRdgku4G4VEBuY15GfeaaVnV2QPrvsiARJLlYs2ZlzJTU7lWgBl4musxS0n PfNS5JxG0WvK+TFCu5UzsensASotk0hW6Dh6pQzceXGCv1FXou1srQha1w2ySwycaOV8 oLWqRSrUafL8LaOPwi+73XElCktZKsz4aJp/dkrAjc0u99eqd3Qz2E4FUkuDCqDN/dE7 uXTQ== X-Gm-Message-State: ALoCoQm+OHnrWmuzDqLK79ciF7HTveq0fCt/e52nFj1F+kEfvhyk2ZZvYpZLL5XdA8QcfLHQfEiH X-Received: by 10.68.211.161 with SMTP id nd1mr58415471pbc.92.1420421580893; Sun, 04 Jan 2015 17:33:00 -0800 (PST) Received: from [192.168.0.104] (36-239-212-135.dynamic-ip.hinet.net. [36.239.212.135]) by mx.google.com with ESMTPSA id j10sm52536826pdr.92.2015.01.04.17.32.58 (version=TLSv1.2 cipher=AES128-GCM-SHA256 bits=128/128); Sun, 04 Jan 2015 17:33:00 -0800 (PST) Message-ID: <1420421576.6968.1.camel@phoenix> Subject: [PATCH] spi: dw: Fix detecting FIFO depth From: Axel Lin To: Mark Brown Cc: Thor Thayer , Andy Shevchenko , Feng Tang , Stefan Roese , linux-spi Date: Mon, 05 Jan 2015 09:32:56 +0800 X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Current code tries to find the highest valid fifo depth by checking the value it wrote to DW_SPI_TXFLTR. There are a few problems in current code: 1) There is an off-by-one in dws->fifo_len setting because it assumes the latest register write fails so the latest valid value should be fifo - 1. 2) We know the depth could be from 2 to 256 from HW spec, so it is not necessary to test fifo == 257. In the case fifo is 257, it means the latest valid setting is fifo = 256. So after the for loop iteration, we should check fifo == 2 case instead of fifo == 257 if detecting the FIFO depth fails. This patch fixes above issues. Signed-off-by: Axel Lin Reviewed-and-tested-by: Andy Shevchenko --- drivers/spi/spi-dw.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c index d0d5542..1a0f266 100644 --- a/drivers/spi/spi-dw.c +++ b/drivers/spi/spi-dw.c @@ -621,13 +621,13 @@ static void spi_hw_init(struct dw_spi *dws) if (!dws->fifo_len) { u32 fifo; - for (fifo = 2; fifo <= 257; fifo++) { + for (fifo = 2; fifo <= 256; fifo++) { dw_writew(dws, DW_SPI_TXFLTR, fifo); if (fifo != dw_readw(dws, DW_SPI_TXFLTR)) break; } - dws->fifo_len = (fifo == 257) ? 0 : fifo; + dws->fifo_len = (fifo == 2) ? 0 : fifo - 1; dw_writew(dws, DW_SPI_TXFLTR, 0); } }