From patchwork Wed Sep 7 15:45:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Seidel X-Patchwork-Id: 9319591 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 E38D3601C0 for ; Wed, 7 Sep 2016 15:45:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF50C293E3 for ; Wed, 7 Sep 2016 15:45:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C4146293E5; Wed, 7 Sep 2016 15:45:46 +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 5A9CF293E3 for ; Wed, 7 Sep 2016 15:45:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753724AbcIGPpo (ORCPT ); Wed, 7 Sep 2016 11:45:44 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:33884 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751742AbcIGPpn (ORCPT ); Wed, 7 Sep 2016 11:45:43 -0400 Received: by mail-wm0-f65.google.com with SMTP id w12so3602185wmf.1 for ; Wed, 07 Sep 2016 08:45:43 -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=6Qsb/+m57ihPgw72oe3ICHOI7r6iXirYbY/Y6Zu7md0=; b=L6g/3/smNDLqt/JRran3l5fltWJ9PPB+j3FLWXJhsdSRO7sUSSe+cnxd0T4bOPu4jY GJygvM8PTyT2u48WuoSV1E0n8+ChTJVfU7XaHzO3eLqGjz59Y+ARgiv7aIMP1K9srUBh oJPDDr1Goetguyj+c8RELKe3MUXG9tbywVTJlT3qRUo2PLZmLEPQ/GTAbTcLUG5EVHwS wLxh+DRwhNh4LbgbVlIkiNXitGUaFvvcRJWVzGXcTDEOKyuPmm+xH9+8suEdVbGRwiQd aaJVqC8g7ju8U0AZvdTuh6BL3JOM8Ebf4gfdSgQBCa5nwBoIzLtfw5XEp2zTsShfYtir ORWA== 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=6Qsb/+m57ihPgw72oe3ICHOI7r6iXirYbY/Y6Zu7md0=; b=bEDD79Aet7xrCFirGjhjzj2blaJnKUswp56bPX/da0rgBTivglzfhPLQybnZNAbjMk HznmaKbN40kVJ6Wkqhn41pVcWEZvHkhnxDdT/0HG03NJTgOlNu1Q8+1kpPeoSVZE1oed ceTBm+J8ZOz2IuZ01G3o0e6dcVzNlgDqCtibN0evMU6C2MklH3UkKEWgHGANBGk5d9Fa /EIN9m/oDS9aeoMH94xKevjBo3LqQm255y81ao3Qe6gghGWYzFr/MKzk2IQWUDTYlf4b TQVvnWi+OlBWGkj56Wi2p2L8AHRN/mEnsBxBa4imCHX1t0BDT/KdKRHAJQEnj/tyw4Ix /AKA== X-Gm-Message-State: AE9vXwOBdB8wziXhdI3DOescTV79e8FKeQJwJBfcKbPBo++vKsllURQnXHDQEUS9UH1QQw== X-Received: by 10.28.4.23 with SMTP id 23mr4789366wme.96.1473263142088; Wed, 07 Sep 2016 08:45:42 -0700 (PDT) Received: from vm (ip-109-91-124-173.hsi12.unitymediagroup.de. [109.91.124.173]) by smtp.gmail.com with ESMTPSA id u64sm4893103wmd.20.2016.09.07.08.45.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Sep 2016 08:45:41 -0700 (PDT) Date: Wed, 7 Sep 2016 17:45:30 +0200 From: Matthias Seidel To: Mark Brown Cc: linux-spi@vger.kernel.org Subject: [PATCH v4] spi: dw: round up result of calculation for clock divider Message-ID: <20160907174530.1ada556f@vm> In-Reply-To: <20160906222131.GT3950@sirena.org.uk> References: <20160904020535.2bb2ab68@vm> <20160906105352.GK3950@sirena.org.uk> <20160906191652.01a11698@vm> <20160906222131.GT3950@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 --- v4: Corrected subject, thanks for your work! 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 | 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;