From patchwork Sun Sep 4 00:05:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Seidel X-Patchwork-Id: 9312313 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A767160865 for ; Sun, 4 Sep 2016 00:24:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 99F03288E7 for ; Sun, 4 Sep 2016 00:24:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E8F52891D; Sun, 4 Sep 2016 00:24:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4FC928917 for ; Sun, 4 Sep 2016 00:24:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753372AbcIDAYN (ORCPT ); Sat, 3 Sep 2016 20:24:13 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:34572 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752219AbcIDAYL (ORCPT ); Sat, 3 Sep 2016 20:24:11 -0400 Received: by mail-wm0-f67.google.com with SMTP id v143so7903484wmv.1 for ; Sat, 03 Sep 2016 17:24:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mseidel-net.20150623.gappssmtp.com; s=20150623; h=sender:date:from:to:cc:subject:message-id:mime-version :content-transfer-encoding; bh=6TwY7fhGz1ha+Tv/qYigQtBZLD8q8whhXZA0LC6E6xM=; b=vISuMSt0qHye9mEN8zjVLNc9tMa3Qp3LDIa/FOC1pQxxXQg9+FhnGm9ixVuGIQYsvl mXjLM8PwuBeekIOrA3z+ov/TMF4DvLcflouifbg/e5QXZkU/+fIIGCOb0PNtpaV5qL8F BHIfugxyOxxaYK1BB20WlJ2tDAp/lMnQ5njIOOLkqK5zdLtOZHn31o2YrJLUq4mSW9J/ Jkbq9hVXD+z0tqj2DwINTIp1hFwwmDI4ob24UC7FLzWrVk/scFyxoiJDVMMIcEjAA8Pq r5zgIgBTLmxZBxSUuC50pgA7Esnkx/K86IE9nQ1mQjzVBm2C46wEfqBWOb9dBxngcWEp X/3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :mime-version:content-transfer-encoding; bh=6TwY7fhGz1ha+Tv/qYigQtBZLD8q8whhXZA0LC6E6xM=; b=eG2+pZ8AfDHLPlR/67wvBbUW5+WCVoDgKVsn1KhljOruDWn8wWi5N4J5B2ZOS2zUoI 52E0TahWpiGOQssUYkCuIkjMLlgJywvGFHmbIQT21/OI6VYUwz0o1xArGjHHy4CzQ7xJ p+n7xI1rnLjZ6B/4cuqhdRw1FcVZzhcVL8vNHPR+HmfpTd3xc7xXSNYFmp+oKi/VT5tJ RmLeA5/QqEco/1YEF462ARIPTka+gNOjVCXAGNdsCeg1JjSVgMEC0OHuA7G7N49Sz05z ARHl26Q+KHYoom3pPt1fMyBBpxJ57xDtyNd5+KbNXpkYYIcIiDiIIpqKF/w6DaCgVfyO C+dg== X-Gm-Message-State: AE9vXwNPWkTw0k7y2ZeCI6ynwc2Ua8CypFkWFCFAlj5u/vgmz9hkBp2xd5tgOc0SJ12VyA== X-Received: by 10.194.88.41 with SMTP id bd9mr27366023wjb.75.1472947538181; Sat, 03 Sep 2016 17:05:38 -0700 (PDT) Received: from vm (ip-109-91-124-173.hsi12.unitymediagroup.de. [109.91.124.173]) by smtp.gmail.com with ESMTPSA id n7sm5636854wjs.34.2016.09.03.17.05.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Sep 2016 17:05:37 -0700 (PDT) Date: Sun, 4 Sep 2016 02:05:35 +0200 From: Matthias Seidel To: Mark Brown Cc: linux-spi@vger.kernel.org Subject: [PATCH v2 2/2] spi: dw: round up result of calculation for clock divider Message-ID: <20160904020535.2bb2ab68@vm> X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Avoid ending up with a higher frequency than requested Signed-off-by: Matthias Seidel --- Previously failing example: requested transfer freq: 16MHz max_freq = 200MHz calculated clk_div = 12 actual frequency = 200/12 = 16.6666MHz --- drivers/spi/spi-dw.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c index c85e4b3..2fd517d 100644 --- a/drivers/spi/spi-dw.c +++ b/drivers/spi/spi-dw.c @@ -300,7 +300,8 @@ static int dw_spi_transfer_one(struct spi_master *master, if (transfer->speed_hz != dws->current_freq) { if (transfer->speed_hz != chip->speed_hz) { /* clk_div doesn't support odd number */ - chip->clk_div = (dws->max_freq / transfer->speed_hz + 1) & 0xfffe; + chip->clk_div = ((dws->max_freq + transfer->speed_hz) / + transfer->speed_hz + 1) & 0xfffe; chip->speed_hz = transfer->speed_hz; } dws->current_freq = transfer->speed_hz;