From patchwork Sat Nov 7 22:41:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcus Weseloh X-Patchwork-Id: 7576381 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D982EC05C6 for ; Sat, 7 Nov 2015 22:41:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0B95E2062E for ; Sat, 7 Nov 2015 22:41:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2989F2060A for ; Sat, 7 Nov 2015 22:41:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932987AbbKGWlh (ORCPT ); Sat, 7 Nov 2015 17:41:37 -0500 Received: from mail-wm0-f52.google.com ([74.125.82.52]:34569 "EHLO mail-wm0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932202AbbKGWlh (ORCPT ); Sat, 7 Nov 2015 17:41:37 -0500 Received: by wmnn186 with SMTP id n186so69093888wmn.1 for ; Sat, 07 Nov 2015 14:41:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=6ILRCByIkV0PNe0l5O2t/QXsso1Ui4GmxW9iQuXTg1g=; b=KlRkRFbE3nv90GXr4dkE6BA19Y3FuJBpkSCYalrgkPvfh0FaZNRIqxIcMEiPUkHsSS PRDh6HyLKOb2rPmCY3bMBFK4BWOEEgW8vIc1wWaNM3WFR6aP7xMyu03VW/wiCHnkGHbt 4oflmxIWEkHz8ExlK/v/mah3MRGsq5CEuwotvgVMTnjzzcHw5qMTRg8DW33ITyA+FXuT cSMge4VeMbNhZlnoV5zZxp4mqENrK5qbQEPnY1EJNoJQuu0FeB9DPB2bhtZxO6YVAo4L CaPSn30xjROcRmTs528ZKuMd+S/JxonolZM/SFmb+hwlLaRuCm2ajY8BpfhpUj4LggZy jV+g== X-Received: by 10.28.215.205 with SMTP id o196mr18246811wmg.95.1446936096045; Sat, 07 Nov 2015 14:41:36 -0800 (PST) Received: from speedy.fritz.box (p578E8236.dip0.t-ipconnect.de. [87.142.130.54]) by smtp.gmail.com with ESMTPSA id cr5sm7128229wjb.16.2015.11.07.14.41.34 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 07 Nov 2015 14:41:35 -0800 (PST) From: Marcus Weseloh To: Maxime Ripard Cc: Mark Brown , linux-spi@vger.kernel.org, linux-sunxi@googlegroups.com, Marcus Weseloh Subject: [PATCH] spi: sun4i: allow transfers to set transmission speed Date: Sat, 7 Nov 2015 23:41:05 +0100 Message-Id: <1446936065-15868-1-git-send-email-mweseloh42@gmail.com> X-Mailer: git-send-email 1.9.1 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.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, 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 Allow transfers to set the transmission speed, only fall back to board max_speed_hz if requested speed is not set or invalid. Signed-off-by: Marcus Weseloh --- drivers/spi/spi-sun4i.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi-sun4i.c b/drivers/spi/spi-sun4i.c index fbb0a4d..0630691 100644 --- a/drivers/spi/spi-sun4i.c +++ b/drivers/spi/spi-sun4i.c @@ -173,6 +173,7 @@ static int sun4i_spi_transfer_one(struct spi_master *master, unsigned int tx_len = 0; int ret = 0; u32 reg; + u32 speed; /* We don't support transfer larger than the FIFO */ if (tfr->len > SUN4I_FIFO_DEPTH) @@ -227,10 +228,16 @@ static int sun4i_spi_transfer_one(struct spi_master *master, sun4i_spi_write(sspi, SUN4I_CTL_REG, reg); + /* Transfer speed setup with fallback to board max_speed_hz */ + if (tfr->speed_hz > 0 && tfr->speed_hz <= spi->max_speed_hz) + speed = tfr->speed_hz; + else + speed = spi->max_speed_hz; + /* Ensure that we have a parent clock fast enough */ mclk_rate = clk_get_rate(sspi->mclk); - if (mclk_rate < (2 * spi->max_speed_hz)) { - clk_set_rate(sspi->mclk, 2 * spi->max_speed_hz); + if (mclk_rate < (2 * speed)) { + clk_set_rate(sspi->mclk, 2 * speed); mclk_rate = clk_get_rate(sspi->mclk); } @@ -248,14 +255,14 @@ static int sun4i_spi_transfer_one(struct spi_master *master, * First try CDR2, and if we can't reach the expected * frequency, fall back to CDR1. */ - div = mclk_rate / (2 * spi->max_speed_hz); + div = mclk_rate / (2 * speed); if (div <= (SUN4I_CLK_CTL_CDR2_MASK + 1)) { if (div > 0) div--; reg = SUN4I_CLK_CTL_CDR2(div) | SUN4I_CLK_CTL_DRS; } else { - div = ilog2(mclk_rate) - ilog2(spi->max_speed_hz); + div = ilog2(mclk_rate) - ilog2(speed); reg = SUN4I_CLK_CTL_CDR1(div); }