From patchwork Mon Mar 17 02:08:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Lin X-Patchwork-Id: 3840951 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A1A2EBF549 for ; Mon, 17 Mar 2014 02:08:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C9E5D201B9 for ; Mon, 17 Mar 2014 02:08:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F2E5F201DD for ; Mon, 17 Mar 2014 02:08:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932302AbaCQCIS (ORCPT ); Sun, 16 Mar 2014 22:08:18 -0400 Received: from mail-pd0-f174.google.com ([209.85.192.174]:60898 "EHLO mail-pd0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932129AbaCQCIR (ORCPT ); Sun, 16 Mar 2014 22:08:17 -0400 Received: by mail-pd0-f174.google.com with SMTP id y13so4959226pdi.33 for ; Sun, 16 Mar 2014 19:08:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:subject:from:to:cc:date:content-type :mime-version:content-transfer-encoding; bh=MXFAh/pVEUDaVGvQyzCydDzSVI0324Ozg81jLru61L4=; b=UyH320ppWtAcyfEnZGF0c+3KU3d/Ys73Z0uIbqjVxUK323nG+bepjPZ/VeS9FmOfhG Oy+k8lnRZVKh8d8H6ZM0ubRMiA+VYPuE3AuWy3ip4oJ+DJ7y3UPkmcgakrkl2P5xRcOs V1Ew9BB5/Z123IhhA/9/Qtr4tqY3lxlyEL5DNa7vrFkT0yaMZztl0otvvJuOe95owIYS yWhgI7EgMWDh/h+lbp8A0bzRrnJ5z441Q15TkfvPPHAYPoAG24ZN4kTePpuNp+Iwt7T1 7TRbU5NvGyIUA3djv9GjKu7sZGvURlFUtt/bSY/52/rrudUReuCXiNNdYKE4jEbuOyAX uYaA== X-Gm-Message-State: ALoCoQlzGquZ7VL5TrZdcmzEQOAZ933HBs3CFyRtysvgY1UzyBZrjGxdjljrsh4HGY9LUPNhKSNo X-Received: by 10.68.171.229 with SMTP id ax5mr23029811pbc.125.1395022096308; Sun, 16 Mar 2014 19:08:16 -0700 (PDT) Received: from [192.168.0.102] (218-164-129-85.dynamic.hinet.net. [218.164.129.85]) by mx.google.com with ESMTPSA id y9sm64132429pas.10.2014.03.16.19.08.14 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 16 Mar 2014 19:08:15 -0700 (PDT) Message-ID: <1395022092.30299.1.camel@phoenix> Subject: [PATCH RFC] spi: core: Use master->max_speed_hz as transfer speed when xfer->speed_hz > master->max_speed_hz From: Axel Lin To: Mark Brown Cc: Guenter Roeck , linux-spi@vger.kernel.org Date: Mon, 17 Mar 2014 10:08:12 +0800 X-Mailer: Evolution 3.8.4-0ubuntu1 Mime-Version: 1.0 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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 When xfer->speed_hz is greater than master->max_speed_hz, it's generally safe to use master->max_speed_hz as transfer speed. Thus use master->max_speed_hz as transfer speed rather than return error when xfer->speed_hz > master->max_speed_hz. Signed-off-by: Axel Lin Tested-by: Guenter Roeck Reviewed-by: Guenter Roeck --- Hi Guenter, Does this patch fix the issue you encounter? Regards, Axel drivers/spi/spi.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 454a523..26b331d 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1844,12 +1844,13 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message) message->frame_length += xfer->len; if (!xfer->bits_per_word) xfer->bits_per_word = spi->bits_per_word; - if (!xfer->speed_hz) { + + if (!xfer->speed_hz) xfer->speed_hz = spi->max_speed_hz; - if (master->max_speed_hz && - xfer->speed_hz > master->max_speed_hz) - xfer->speed_hz = master->max_speed_hz; - } + + if (master->max_speed_hz && + xfer->speed_hz > master->max_speed_hz) + xfer->speed_hz = master->max_speed_hz; if (master->bits_per_word_mask) { /* Only 32 bits fit in the mask */ @@ -1878,9 +1879,6 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message) if (xfer->speed_hz && master->min_speed_hz && xfer->speed_hz < master->min_speed_hz) return -EINVAL; - if (xfer->speed_hz && master->max_speed_hz && - xfer->speed_hz > master->max_speed_hz) - return -EINVAL; if (xfer->tx_buf && !xfer->tx_nbits) xfer->tx_nbits = SPI_NBITS_SINGLE;