From patchwork Wed Jan 14 07:25:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nobuhiro Iwamatsu X-Patchwork-Id: 5629011 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@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 B76929F50F for ; Wed, 14 Jan 2015 08:45:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E45F1201FB for ; Wed, 14 Jan 2015 08:45:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 02399203A5 for ; Wed, 14 Jan 2015 08:45:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755963AbbANIpI (ORCPT ); Wed, 14 Jan 2015 03:45:08 -0500 Received: from mail-pa0-f44.google.com ([209.85.220.44]:45432 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753648AbbANHZz (ORCPT ); Wed, 14 Jan 2015 02:25:55 -0500 Received: by mail-pa0-f44.google.com with SMTP id et14so8824304pad.3 for ; Tue, 13 Jan 2015 23:25:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=3yz2+ScRu91bJI8QT8dSBHgE6xodQ0ChAZcesWx8Z9I=; b=fgtFhIZu1zHOWkHLl3P7dsvSPeBn/PlKhxAFSSBy08Bg2hxGi0oWV5VEttuwbJMuFG P3+eqtNpHKzTeLDjEpc+LmQE3d+yPi11bn+NEFlbD4WVXU0heKEjI8vBj5YmogC5k3lx W+NUAFOwX7xhDmrpwzO8fVySxwLlZ7m885pEF037oT9nPmxs1BWUNDLsc9INkzFNxcNu LrYnhan7hYWaOkghkhLSNilpbiMCTC2/8zr59w3lt2cQs5vGBAX4YDS6/BxuKOLcOGEk 263J2ulWkDxVod9C6cWIlTK7fYFkuasqasjEqHcs7Dyyj3yr30PlqUUFHMLVPCeoAi0a kJfQ== X-Gm-Message-State: ALoCoQnW24nKYt0vYbk32qu0qxWop/vZOfmiEI/L8+463VY41IMOA2OA2Dkzzxxl7hw49l1B5F55 X-Received: by 10.68.129.134 with SMTP id nw6mr3601262pbb.132.1421220355115; Tue, 13 Jan 2015 23:25:55 -0800 (PST) Received: from xps-iwamatsu.renesas.com (49.14.32.202.bf.2iij.net. [202.32.14.49]) by mx.google.com with ESMTPSA id ji5sm18814720pbd.22.2015.01.13.23.25.52 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Jan 2015 23:25:53 -0800 (PST) From: Nobuhiro Iwamatsu To: linux-spi@vger.kernel.org Cc: linux-sh@vger.kernel.org, geert@glider.be, yoshihiro.shimoda.uh@renesas.com, Nobuhiro Iwamatsu Subject: [PATCH] spi: sh-msiof: Update calculation of frequency dividing Date: Wed, 14 Jan 2015 16:25:35 +0900 Message-Id: <1421220335-22503-1-git-send-email-nobuhiro.iwamatsu.yj@renesas.com> X-Mailer: git-send-email 2.1.3 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@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=unavailable 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 sh-msiof of frequency dividing does not perform the calculation, driver have to manage setting value in the table. It is not possible to set frequency dividing value close to the actual data in this way. This changes from frequency dividing of table management to setting by calculation. This driver is able to set a value close to the actual data. Signed-off-by: Nobuhiro Iwamatsu --- drivers/spi/spi-sh-msiof.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c index 96a5fc0..58b1bfe 100644 --- a/drivers/spi/spi-sh-msiof.c +++ b/drivers/spi/spi-sh-msiof.c @@ -241,42 +241,37 @@ static irqreturn_t sh_msiof_spi_irq(int irq, void *data) static struct { unsigned short div; - unsigned short scr; -} const sh_msiof_spi_clk_table[] = { - { 1, SCR_BRPS( 1) | SCR_BRDV_DIV_1 }, - { 2, SCR_BRPS( 1) | SCR_BRDV_DIV_2 }, - { 4, SCR_BRPS( 1) | SCR_BRDV_DIV_4 }, - { 8, SCR_BRPS( 1) | SCR_BRDV_DIV_8 }, - { 16, SCR_BRPS( 1) | SCR_BRDV_DIV_16 }, - { 32, SCR_BRPS( 1) | SCR_BRDV_DIV_32 }, - { 64, SCR_BRPS(32) | SCR_BRDV_DIV_2 }, - { 128, SCR_BRPS(32) | SCR_BRDV_DIV_4 }, - { 256, SCR_BRPS(32) | SCR_BRDV_DIV_8 }, - { 512, SCR_BRPS(32) | SCR_BRDV_DIV_16 }, - { 1024, SCR_BRPS(32) | SCR_BRDV_DIV_32 }, + unsigned short brdv; +} const sh_msiof_spi_div_table[] = { + { 1, SCR_BRDV_DIV_1 }, + { 2, SCR_BRDV_DIV_2 }, + { 4, SCR_BRDV_DIV_4 }, + { 8, SCR_BRDV_DIV_8 }, + { 16, SCR_BRDV_DIV_16 }, + { 32, SCR_BRDV_DIV_32 }, }; static void sh_msiof_spi_set_clk_regs(struct sh_msiof_spi_priv *p, unsigned long parent_rate, u32 spi_hz) { unsigned long div = 1024; + unsigned long brps, scr; size_t k; if (!WARN_ON(!spi_hz || !parent_rate)) div = DIV_ROUND_UP(parent_rate, spi_hz); - /* TODO: make more fine grained */ - - for (k = 0; k < ARRAY_SIZE(sh_msiof_spi_clk_table); k++) { - if (sh_msiof_spi_clk_table[k].div >= div) - break; + for (k = 0; k < ARRAY_SIZE(sh_msiof_spi_div_table); k++) { + brps = DIV_ROUND_UP(div, sh_msiof_spi_div_table[k].div); + if (brps > 32) /* max of brsv is 32 */ + continue; + break; } - k = min_t(int, k, ARRAY_SIZE(sh_msiof_spi_clk_table) - 1); - - sh_msiof_write(p, TSCR, sh_msiof_spi_clk_table[k].scr); + scr = sh_msiof_spi_div_table[k].brdv | (brps -1) << 8; + sh_msiof_write(p, TSCR, scr); if (!(p->chipdata->master_flags & SPI_MASTER_MUST_TX)) - sh_msiof_write(p, RSCR, sh_msiof_spi_clk_table[k].scr); + sh_msiof_write(p, RSCR, scr); } static void sh_msiof_spi_set_pin_regs(struct sh_msiof_spi_priv *p,