From patchwork Thu Feb 13 11:05:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Lin X-Patchwork-Id: 3644851 X-Patchwork-Delegate: broonie@sirena.org.uk Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DD53A9F390 for ; Thu, 13 Feb 2014 11:05:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1B56F2018E for ; Thu, 13 Feb 2014 11:05:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4AACB201B4 for ; Thu, 13 Feb 2014 11:05:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753114AbaBMLFp (ORCPT ); Thu, 13 Feb 2014 06:05:45 -0500 Received: from mail-pb0-f51.google.com ([209.85.160.51]:38391 "EHLO mail-pb0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753494AbaBMLFp (ORCPT ); Thu, 13 Feb 2014 06:05:45 -0500 Received: by mail-pb0-f51.google.com with SMTP id un15so10692201pbc.10 for ; Thu, 13 Feb 2014 03:05:44 -0800 (PST) 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=69LDG8nM4d9OvcEj8lkvcTrKKhghZ/BDwfhhhzbn6RE=; b=BNNiv/pSUotUkJLxIpvJqfxczz/uicRPICjYj2owEQKSSb7aH3v28HcyC4qvP19ZyJ 1R8cppK9cdncXk5INbeGVQ98GfhX6uuu6YKtZCvCpF2WwPLOXynVy/WhuoOszARcnQfa pDuYOgXoaDuVQ8FQMcszJolPWpO4Qbk2AL2sGTywH+jAPMwZx76zIFyUQjgWj0rsHP1J XXyGhYQCnUUJKjFS/T3SjE5u2ujdBgXgpJg5uT8oczLJyho8KKnCWv4pbt91lrDusbRF quvlO1gbf0JLFTGvL1Hoz6ojgqE68PjdB9c1Dfje0vwzaNEfj6qwXwQWm09Up/8kqKUZ w8qA== X-Gm-Message-State: ALoCoQmUp+jlcLJFQ3l/9+wJ9MjMacTPCm7ev5mM2QTS1P415De6lVCO7moKomkqbxdddsJQzpce X-Received: by 10.66.254.3 with SMTP id ae3mr911228pad.107.1392289544441; Thu, 13 Feb 2014 03:05:44 -0800 (PST) Received: from [192.168.1.107] (111-249-179-2.dynamic.hinet.net. [111.249.179.2]) by mx.google.com with ESMTPSA id nz11sm12172511pab.6.2014.02.13.03.05.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 13 Feb 2014 03:05:43 -0800 (PST) Message-ID: <1392289538.20787.1.camel@phoenix> Subject: [PATCH v3] spi: fsl-spi: Convert to let spi core validate xfer->bits_per_word From: Axel Lin To: Mark Brown Cc: Stefan Roese , Andreas Larsson , linux-spi@vger.kernel.org Date: Thu, 13 Feb 2014 19:05:38 +0800 X-Mailer: Evolution 3.6.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=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 Set bits_per_word_mask so spi core will reject transfers that attempt to use an unsupported bits_per_word value. fsl_spi_grlib_probe() may update mpc8xxx_spi->max_bits_per_word setting. So set master->bits_per_word_mask after fsl_spi_grlib_probe(). Signed-off-by: Axel Lin --- v3: revise based on Andreas' suggestion. v2: Make sure bits_per_word can not be greater than mpc8xxx_spi->max_bits_per_word. drivers/spi/spi-fsl-spi.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/spi/spi-fsl-spi.c b/drivers/spi/spi-fsl-spi.c index 4dcb292..f35488e 100644 --- a/drivers/spi/spi-fsl-spi.c +++ b/drivers/spi/spi-fsl-spi.c @@ -239,12 +239,6 @@ static int fsl_spi_setup_transfer(struct spi_device *spi, if (!bits_per_word) bits_per_word = spi->bits_per_word; - /* Make sure its a bit width we support [4..16, 32] */ - if ((bits_per_word < 4) - || ((bits_per_word > 16) && (bits_per_word != 32)) - || (bits_per_word > mpc8xxx_spi->max_bits_per_word)) - return -EINVAL; - if (!hz) hz = spi->max_speed_hz; @@ -651,6 +645,10 @@ static struct spi_master * fsl_spi_probe(struct device *dev, if (mpc8xxx_spi->type == TYPE_GRLIB) fsl_spi_grlib_probe(dev); + master->bits_per_word_mask = + (SPI_BPW_RANGE_MASK(4, 16) | SPI_BPW_MASK(32)) & + SPI_BPW_RANGE_MASK(1, mpc8xxx_spi->max_bits_per_word); + if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE) mpc8xxx_spi->set_shifts = fsl_spi_qe_cpu_set_shifts;