From patchwork Tue Sep 6 17:16:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Seidel X-Patchwork-Id: 9317705 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 AB21960760 for ; Tue, 6 Sep 2016 17:17:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A107D28DC3 for ; Tue, 6 Sep 2016 17:17:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9594B28E29; Tue, 6 Sep 2016 17:17:35 +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=-4.4 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 CBC3028DC3 for ; Tue, 6 Sep 2016 17:17:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964840AbcIFRRe (ORCPT ); Tue, 6 Sep 2016 13:17:34 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:36746 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964800AbcIFRRd (ORCPT ); Tue, 6 Sep 2016 13:17:33 -0400 Received: by mail-wm0-f67.google.com with SMTP id l65so11776170wmf.3 for ; Tue, 06 Sep 2016 10:17:32 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=HdKtTUfTiMfXv1Gd1TmqQTU51DyuTtrldCPL5NE4t9g=; b=BWBcLQlk5oIg55Sh+ExHtJwi2aSKSEWlh5Cg2wIsBC384uZ1cadQ+tvAsLQWnFftPj ywWbbMN7SPeukbx4peW0MQTYNo5Hy69WxzwknuMIRHVWLi+Se/4vrVApguJ2Q9vMeoq0 W+5SxRQUzctq+Fh6zR6gWRCAYoYBdK6v4/nVZB2/Ku4Wws+Syn/nso1AbQlwp7tpTEDo Nd5t0AJ8kg8MUNuS7wCBDoAGBobaRyGdqhiICv4zijoSzYaBHcZZY2FekaQ6mRRVfgjL BBfvuy2awKDF81BjiNt8B/4fEQ2WZguDs19o1Z69EU7BnDGyLTg4nv7K09SbL1Ldub8Z hRTQ== 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 :in-reply-to:references:mime-version:content-transfer-encoding; bh=HdKtTUfTiMfXv1Gd1TmqQTU51DyuTtrldCPL5NE4t9g=; b=Dmi/cviGNcDHiE+LdZPnWd14ww0vML7HmiU6CKNd4CDSLmVXxlwOSyLEvOGIwfduJJ nzDGLK4DW7XQQM+u5Fa2qY1QJRIT4MsThavXHrnxhLQHsA+F3neqHiBV9ekr/1/bUzw6 dr0bR96O/1dMGosowExlJ8GCTr8IigmVA2VCuTxDOM+6vBFD7tWUOYx6WeI8XnzpxuZi Fa8jEYVpsAUC8zaCdrJpF4GDWBt4Q/UVYrOMgXAzjw0kJxcIQOr93driaYylY6eg4o7x VJKgNMhs1tNZzSvdFIJlQiSyBS4LvJmS7MNb8DcBAdN/NyvY0YCOQZKWo/Kx0dD86P2Z LeOA== X-Gm-Message-State: AE9vXwOkF122kp56qdYSZgQ50zYDPvkT8mNkkelkvQrFlh88ixmbEZFFAbKRfkCAvPJvnA== X-Received: by 10.28.206.197 with SMTP id e188mr17297619wmg.65.1473182251847; Tue, 06 Sep 2016 10:17:31 -0700 (PDT) Received: from vm (ip-109-91-124-173.hsi12.unitymediagroup.de. [109.91.124.173]) by smtp.gmail.com with ESMTPSA id pm1sm34317956wjb.40.2016.09.06.10.17.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Sep 2016 10:17:31 -0700 (PDT) Date: Tue, 6 Sep 2016 19:16:52 +0200 From: Matthias Seidel To: Mark Brown Cc: linux-spi@vger.kernel.org Subject: [PATCH v3 2/2] spi: dw: round up result of calculation for clock divider Message-ID: <20160906191652.01a11698@vm> In-Reply-To: <20160906105352.GK3950@sirena.org.uk> References: <20160904020535.2bb2ab68@vm> <20160906105352.GK3950@sirena.org.uk> 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 v3: I wasn't aware of this macro, better readability. --- drivers/spi/spi-dw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c index c85e4b3..27960e4 100644 --- a/drivers/spi/spi-dw.c +++ b/drivers/spi/spi-dw.c @@ -300,7 +300,7 @@ 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 = (DIV_ROUND_UP(dws->max_freq, transfer->speed_hz) + 1) & 0xfffe; chip->speed_hz = transfer->speed_hz; } dws->current_freq = transfer->speed_hz;