From patchwork Fri Mar 27 21:51:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Brice X-Patchwork-Id: 6112441 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 300559F318 for ; Fri, 27 Mar 2015 21:59:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 60582203FB for ; Fri, 27 Mar 2015 21:59:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 767AA2041E for ; Fri, 27 Mar 2015 21:59:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752441AbbC0V7C (ORCPT ); Fri, 27 Mar 2015 17:59:02 -0400 Received: from p3plsmtpa11-09.prod.phx3.secureserver.net ([68.178.252.110]:57707 "EHLO p3plsmtpa11-09.prod.phx3.secureserver.ne" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752573AbbC0V7B (ORCPT ); Fri, 27 Mar 2015 17:59:01 -0400 X-Greylist: delayed 432 seconds by postgrey-1.27 at vger.kernel.org; Fri, 27 Mar 2015 17:59:01 EDT Received: from bricepc.corp.datasoft.com ([184.185.173.186]) by p3plsmtpa11-09.prod.phx3.secureserver.ne with id 8lrk1q00241flQ801lrpPk; Fri, 27 Mar 2015 14:51:49 -0700 From: Aaron Brice To: broonie@kernel.org Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, stefan@agner.ch Subject: [PATCH 1/2] spi: fsl-dspi: Fix clock rate scale values Date: Fri, 27 Mar 2015 14:51:42 -0700 Message-Id: <1427493103-7354-2-git-send-email-aaron.brice@datasoft.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1427493103-7354-1-git-send-email-aaron.brice@datasoft.com> References: <1427493103-7354-1-git-send-email-aaron.brice@datasoft.com> 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 Update baud rate scaling algorithm to get better scaling values. Signed-off-by: Aaron Brice --- drivers/spi/spi-fsl-dspi.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index d1a3924..96cac87 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c @@ -148,23 +148,30 @@ static void hz_to_spi_baud(char *pbr, char *br, int speed_hz, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 }; - int temp, i = 0, j = 0; - - temp = clkrate / 2 / speed_hz; - - for (i = 0; i < ARRAY_SIZE(pbr_tbl); i++) - for (j = 0; j < ARRAY_SIZE(brs); j++) { - if (pbr_tbl[i] * brs[j] >= temp) { - *pbr = i; - *br = j; - return; + int scale_needed, scale, minscale = INT_MAX; + int i, j; + + scale_needed = clkrate / speed_hz; + + for (i = 0; i < ARRAY_SIZE(brs); i++) + for (j = 0; j < ARRAY_SIZE(pbr_tbl); j++) { + scale = brs[i] * pbr_tbl[j]; + if (scale >= scale_needed) { + if (scale < minscale) { + minscale = scale; + *br = i; + *pbr = j; + } + break; } } - pr_warn("Can not find valid baud rate,speed_hz is %d,clkrate is %ld\ - ,we use the max prescaler value.\n", speed_hz, clkrate); - *pbr = ARRAY_SIZE(pbr_tbl) - 1; - *br = ARRAY_SIZE(brs) - 1; + if (minscale == INT_MAX) { + pr_warn("Can not find valid baud rate,speed_hz is %d,clkrate is %ld, we use the max prescaler value.\n", + speed_hz, clkrate); + *pbr = ARRAY_SIZE(pbr_tbl) - 1; + *br = ARRAY_SIZE(brs) - 1; + } } static int dspi_transfer_write(struct fsl_dspi *dspi)