From patchwork Sat Dec 20 02:17:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Lin X-Patchwork-Id: 5521851 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4DEBABEEA8 for ; Sat, 20 Dec 2014 02:18:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 76DA72013A for ; Sat, 20 Dec 2014 02:18:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A0EA420115 for ; Sat, 20 Dec 2014 02:18:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752659AbaLTCSB (ORCPT ); Fri, 19 Dec 2014 21:18:01 -0500 Received: from mail-qc0-f170.google.com ([209.85.216.170]:34681 "EHLO mail-qc0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751626AbaLTCSA (ORCPT ); Fri, 19 Dec 2014 21:18:00 -0500 Received: by mail-qc0-f170.google.com with SMTP id x3so1510712qcv.29 for ; Fri, 19 Dec 2014 18:17:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=J6SqbVk0EaZpXJmzxwHXuJ3iO8UWg0S1/laQnAJK448=; b=ZYbozyoqnAptf4RjVIrQX4iXrpYt5iJbI/ul5JQWGCbhiNFO/11v1K62CaXQLTAPcq BiMrGVvgLx29RnSBW3iteeGh5UkKZzRtqZCYPr0FGiHhmM3doaX7dR1Lbhp7KO+wn1Fk 6w1lnm1WoiERsyk5mO+72tABjkXHb9HNe0u4YB0dwl4vxGNZhJMrcqxif3A0MZ421Gdt 4lrLVEaXXcy/P7FIplOrzZ0FcDrOU9m2100TyWKtfuteyx5zrHmu1FEMn/3InjdccX+s 2OBMPERdO1wa7LRQsIshyh4vCgTGEPk7J54upPPbrD7/VYSO5MVao4NPt88zGpQHqJ+O eKeA== X-Gm-Message-State: ALoCoQnVD8YLjfUWHrD3S5+HQYkm6HpmMHS5FRJvx0QCHrbxwuBBXPaXltjsRT5atzGr+u9kkR7d MIME-Version: 1.0 X-Received: by 10.224.14.66 with SMTP id f2mr8329974qaa.81.1419041879864; Fri, 19 Dec 2014 18:17:59 -0800 (PST) Received: by 10.140.106.38 with HTTP; Fri, 19 Dec 2014 18:17:59 -0800 (PST) X-Originating-IP: [218.164.131.128] In-Reply-To: <1418989567.17201.71.camel@linux.intel.com> References: <1418976099.23257.4.camel@phoenix> <1418989567.17201.71.camel@linux.intel.com> Date: Sat, 20 Dec 2014 10:17:59 +0800 Message-ID: Subject: Re: [PATCH RFT] spi: dw: Fix off-by-one for checking fifo depth From: Axel Lin To: Andy Shevchenko Cc: Mark Brown , Thor Thayer , Feng Tang , Stefan Roese , linux-spi 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 2014-12-19 19:46 GMT+08:00 Andy Shevchenko : > On Fri, 2014-12-19 at 16:01 +0800, Axel Lin wrote: >> The fifo depth could be from 2 to 256 from HW spec, so fix off-by-one for >> checking fifo depth. >> Without this patch, fifo is 258 after for loop iteration for the "no-match" >> case. So below line does not catch the "no-match" case. >> dws->fifo_len = (fifo == 257) ? 0 : fifo; > > Seems reasonable, but never tried because in case of Medfield device we > have fifo size defined. > > I would try this in January. hi Andy, I check the code again and I think what current code does is: It tries to find the highest valid fifo depth so it checks the value it wrote to DW_SPI_TXFLTR. I think the valid value range is 2 ~ 256. So it will break out when writing 257 to DW_SPI_TXFLTR. There is an off-by-one in dws->fifo_len setting because it assumes the latest register write fails so the latest valid value is fifo - 1. So I think you can set dws->fifo_len to 0 to test current behavior first. I guess below change should work, please test this instead my previous patch. Regards, Axel --- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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); } }