From patchwork Tue Nov 15 20:56:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9430493 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 EDC1B60469 for ; Tue, 15 Nov 2016 20:56:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAC3F28C57 for ; Tue, 15 Nov 2016 20:56:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFA5028C98; Tue, 15 Nov 2016 20:56: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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 7BA5B28C57 for ; Tue, 15 Nov 2016 20:56:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753823AbcKOU4q (ORCPT ); Tue, 15 Nov 2016 15:56:46 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:35394 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753761AbcKOU4p (ORCPT ); Tue, 15 Nov 2016 15:56:45 -0500 Received: by mail-wm0-f66.google.com with SMTP id a20so4095979wme.2 for ; Tue, 15 Nov 2016 12:56:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:subject:to:cc:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=6BsQ0qR5fgmlIJeiockx+7X1LLkqe4BPp3EWNSSDsho=; b=HZSjryJCZPj6VwxbEfC77IVqEqtqd3PEY7RhZeVZS+vaCEH8czeiVoDVsKFmaTCRCR gxGdmmvYL4zL4qWvFdK+SUBQdLiy/49a0GCAbRcQwTQ1TH5g07DTPUg9uUy09MWshQlB s2N/MzC/fWB7uwOWDAkoXuBnK9gKjV/n5/Ct9VNlbA7XrzK/5knrTJaseAnHfmYAW/IU XK9a9bmDT7i4bFnhYNa0yHrPEIahYmtAObBIgYzuJNXA4Q+qH+Sd2BLlzY+lkNCGQRAw ohSVG/eAuRxr6XhBTy2eDeaTdzpF5FsrwENT8nn0s0WtGUYyxHZTM3H/13E/5KzoGWZ0 j76g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:cc:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=6BsQ0qR5fgmlIJeiockx+7X1LLkqe4BPp3EWNSSDsho=; b=mEViSuPwTP0/Xl32oQf70OK8JShfbwGznqup/bguugG4OPG+cs8HmXkp28uXaPovZE I+V6Fh2ByqdgR3tBzEn6JsMHkA2bmXNF15ZAfOXwmS+Cr/VKAYlZ7xfzYnj4GQ/7FNAq Bp0m/anLINrIRkd/+ERELxcggBYxc4McnBR35V+vUc3gWTiJKZepTrxYq4xaI37XIFXG EnC3rFYACoXGZx4B3kGzC4FILKUlmLuAe+O7QOO/V8iPtuE5RB+Q94uJ1QVpMi/aD+Dv JCVZMCP7FcMVe+JzQbgYyj2i0aYFX0OVpYeuOqr9BcKWaw9sTPfmx4KIu2cZqx7/F8JS rxiA== X-Gm-Message-State: ABUngvcEpFJtGIW5g+22o933g+lZU/ZF/ATHkSIJKfDxLN2gF9mSlSmKFF7pzeA3PKTaQw== X-Received: by 10.28.187.67 with SMTP id l64mr5610521wmf.114.1479243403887; Tue, 15 Nov 2016 12:56:43 -0800 (PST) Received: from ?IPv6:2003:62:5f58:9d00:51c7:39a5:8281:db0c? (p200300625F589D0051C739A58281DB0C.dip0.t-ipconnect.de. [2003:62:5f58:9d00:51c7:39a5:8281:db0c]) by smtp.googlemail.com with ESMTPSA id g197sm6191700wmd.15.2016.11.15.12.56.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Nov 2016 12:56:41 -0800 (PST) From: Heiner Kallweit Subject: [PATCH] spi: fsl-espi: set spi_master members min_speed_hz and max_speed_hz To: Mark Brown Cc: "linux-spi@vger.kernel.org" Message-ID: Date: Tue, 15 Nov 2016 21:56:33 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 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 ESPI has a max and min supported SPI frequency, determined by the clock divider range. Set master->min_speed_hz/max_speed_hz to inform the SPI core about these limits. Then the SPI core handles cases where a transfer requests a frequency outside the supported range. So far the driver simply set the lowest supported frequency if the requested frequency was below the supported range. This is not necessarily an appropriate action as the device might not support frequencies greater than the requested one. With this patch the SPI core will reject transfers requesting a too low frequency. The check in fsl_espi_setup can be removed because the SPI core sets spi->max_speed_hz to master->max_speed_hz if it's not set already. Signed-off-by: Heiner Kallweit --- drivers/spi/spi-fsl-espi.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c index b5feae3..28b6e7f 100644 --- a/drivers/spi/spi-fsl-espi.c +++ b/drivers/spi/spi-fsl-espi.c @@ -314,13 +314,6 @@ static void fsl_espi_setup_transfer(struct spi_device *spi, if (pm > 15) { cs->hw_mode |= CSMODE_DIV16; pm = DIV_ROUND_UP(espi->spibrg, hz * 16 * 4) - 1; - - WARN_ONCE(pm > 15, - "%s: Requested speed is too low: %u Hz. Will use %u Hz instead.\n", - dev_name(&spi->dev), hz, - espi->spibrg / (4 * 16 * (15 + 1))); - if (pm > 15) - pm = 15; } cs->hw_mode |= CSMODE_PM(pm); @@ -460,9 +453,6 @@ static int fsl_espi_setup(struct spi_device *spi) u32 loop_mode; struct fsl_espi_cs *cs = spi_get_ctldata(spi); - if (!spi->max_speed_hz) - return -EINVAL; - if (!cs) { cs = kzalloc(sizeof(*cs), GFP_KERNEL); if (!cs) @@ -673,6 +663,9 @@ static int fsl_espi_probe(struct device *dev, struct resource *mem, ret = -EINVAL; goto err_probe; } + /* determined by clock divider fields DIV16/PM in register SPMODEx */ + master->min_speed_hz = DIV_ROUND_UP(espi->spibrg, 4 * 16 * 16); + master->max_speed_hz = DIV_ROUND_UP(espi->spibrg, 4); init_completion(&espi->done);