From patchwork Thu Mar 26 23:30:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julius Werner X-Patchwork-Id: 6102711 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 18955BF90F for ; Thu, 26 Mar 2015 23:30:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2FF73203A1 for ; Thu, 26 Mar 2015 23:30:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5C6AE20435 for ; Thu, 26 Mar 2015 23:30:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932163AbbCZXap (ORCPT ); Thu, 26 Mar 2015 19:30:45 -0400 Received: from mail-ig0-f177.google.com ([209.85.213.177]:35447 "EHLO mail-ig0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932140AbbCZXao (ORCPT ); Thu, 26 Mar 2015 19:30:44 -0400 Received: by igcau2 with SMTP id au2so6472785igc.0 for ; Thu, 26 Mar 2015 16:30:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=7ePn9oHbIvnk14njWpENR8wNJw6WTHIVVWi3dPVQy8o=; b=bVWTM2K1CckKElL6ahy6C40jx6fgrBplSo3H988y79imHDrvT/RGqvsla9X7yf5jic JLohG0tQQp9mykf4S8YrhPLiA6FdZwBW/fyY5RrlcnoA496Sq5KG7FoBzu1pkuQGrH0X C/WAy5oKNvCxDXIbEEb8omYy1MbSqXrFPGzMI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=7ePn9oHbIvnk14njWpENR8wNJw6WTHIVVWi3dPVQy8o=; b=Ae0t9YElJ4CRWa501W/NofuExSkHBNaq3VaGSHioggH2rGr5KBA/EFyNpBIfEfb195 /vd88iBHd27nor7YEoVAl4dBxKmcLaIebJPYA42zOUjB8Orgc4McGrfum/+Y4rv5F8TF u838rxi4KfoS5Y4QWLsmUmw201ODb25QyFJpH7ImArkoLXXiV1K1izYi1yZ1pKC+PPQP W8BQyUNtV6iXXXaXI9Dfe+JMkHIU7jlkrDK6q5+p+IVi6xSVEnDGX/sL5GUSjvHOg4sw cez6g2G7Saa2d+4mtk3sojtxxgTJpiDTa2aYjfEPJD89nzQFeXgjsPaAhi5+1WQ+C/I3 fiBA== X-Gm-Message-State: ALoCoQn9dBxUAh5tn2nBXdw4t+CUwcFFS36Ry4TiSLfOs5cGgNtYJq29dLE3weuzrl2gYtXn+BGG X-Received: by 10.107.39.72 with SMTP id n69mr9922837ion.8.1427412644285; Thu, 26 Mar 2015 16:30:44 -0700 (PDT) Received: from jwerner-linux.mtv.corp.google.com ([172.22.64.164]) by mx.google.com with ESMTPSA id l197sm208191iol.1.2015.03.26.16.30.42 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 Mar 2015 16:30:43 -0700 (PDT) From: Julius Werner To: Mark Brown Cc: Mark Rutland , Heiko Stuebner , addy ke , Doug Anderson , devicetree@vger.kernel.org, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Julius Werner Subject: [PATCH 1/2] spi/rockchip: Round up clock rate divisor to err on the safe side Date: Thu, 26 Mar 2015 16:30:24 -0700 Message-Id: <1427412625-12377-1-git-send-email-jwerner@chromium.org> X-Mailer: git-send-email 2.2.0.rc0.207.ga3a616c 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_SIGNED, 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 The Rockchip SPI driver currently calculates its clock rate divisor by integer dividing the parent rate by the target rate, and then rounding the result up to the next even number (since the divisor must be even). Clock rate divisors should always be rounded up, so that the resulting frequency is lower or equal to the target. This is correctly done in the second step here but not in the first, so we still have a risk of exceeding the desired target frequency (e.g. setting spi-max-frequency to 40000000 with a parent clock of 99000000 could lead to a divisor of 99000000 / 40000000 == 2 (which is even) that then results in an effective frequency of 99000000 / 2 == 49500000 (potentially exceeding the flash chip's specifications). This patch changes the division to round up to fix this problem. Signed-off-by: Julius Werner Reviewed-by: Doug Anderson --- drivers/spi/spi-rockchip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/spi/spi-rockchip.c b/drivers/spi/spi-rockchip.c index 1a777dc..5e4e52c 100644 --- a/drivers/spi/spi-rockchip.c +++ b/drivers/spi/spi-rockchip.c @@ -519,7 +519,7 @@ static void rockchip_spi_config(struct rockchip_spi *rs) } /* div doesn't support odd number */ - div = max_t(u32, rs->max_freq / rs->speed, 1); + div = DIV_ROUND_UP(rs->max_freq, rs->speed); div = (div + 1) & 0xfffe; writel_relaxed(cr0, rs->regs + ROCKCHIP_SPI_CTRLR0);