From patchwork Tue Feb 11 12:51:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Lin X-Patchwork-Id: 3626891 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 C36609F382 for ; Tue, 11 Feb 2014 12:51:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B6860201EF for ; Tue, 11 Feb 2014 12:51:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E700F201F2 for ; Tue, 11 Feb 2014 12:51:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750934AbaBKMvu (ORCPT ); Tue, 11 Feb 2014 07:51:50 -0500 Received: from mail-pb0-f51.google.com ([209.85.160.51]:62276 "EHLO mail-pb0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750788AbaBKMvu (ORCPT ); Tue, 11 Feb 2014 07:51:50 -0500 Received: by mail-pb0-f51.google.com with SMTP id un15so7676389pbc.38 for ; Tue, 11 Feb 2014 04:51:47 -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=myNE7P7ORxDd0Rb4J5haWykXV6NNWGS3mvS2+9eHsm4=; b=WfwtsYw0/YXpc3FVgJRUdb0b/HNd7tI9LvJfAAzAJJJBwadvIzs5pDDem0mQ3SyF+n TZoeUhf+7DlN2BA5gBHgabkLDm8WV2xtcMMZQ8V93y10YD83ZLPxGQGoBRGvYjNOjp49 iOgcfgmxvrer1iyibywwgDNqRJp81TCmzJxJTaX/Qm4YlBBD3YMytaIpSeZbfu/YD6Os nY544q3mxJtFMClCUCr1EgyG3H368w6O3Z1+MIeuIwvxPslEYfM33VUwyclX8t9vtVpe 2gDfRqD2qWYoj+yG9ERBnUiba9ucBGHgp/95FUc3ohnuGeGaAjaTMcqGlu7uSmRcVB3c r2qg== X-Gm-Message-State: ALoCoQkcP3uihxVb4y82owux523dcvoXx1hnG15QMNA50zQ/RLe/ZKRn8Nrc7psknQ2+xYQM6WPH X-Received: by 10.67.2.106 with SMTP id bn10mr32173119pad.38.1392123106658; Tue, 11 Feb 2014 04:51:46 -0800 (PST) Received: from [10.145.55.56] ([60.245.65.194]) by mx.google.com with ESMTPSA id os1sm135463366pac.20.2014.02.11.04.51.44 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 11 Feb 2014 04:51:46 -0800 (PST) Message-ID: <1392123096.1351.6.camel@phoenix> Subject: [PATCH] spi: orion: Convert to let spi core validate xfer->bits_per_word From: Axel Lin To: Mark Brown Cc: Shadi Ammouri , linux-spi@vger.kernel.org Date: Tue, 11 Feb 2014 20:51:36 +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. Signed-off-by: Axel Lin --- drivers/spi/spi-orion.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/drivers/spi/spi-orion.c b/drivers/spi/spi-orion.c index 95e29b6..2deddb3 100644 --- a/drivers/spi/spi-orion.c +++ b/drivers/spi/spi-orion.c @@ -74,23 +74,6 @@ orion_spi_clrbits(struct orion_spi *orion_spi, u32 reg, u32 mask) writel(val, reg_addr); } -static int orion_spi_set_transfer_size(struct orion_spi *orion_spi, int size) -{ - if (size == 16) { - orion_spi_setbits(orion_spi, ORION_SPI_IF_CONFIG_REG, - ORION_SPI_IF_8_16_BIT_MODE); - } else if (size == 8) { - orion_spi_clrbits(orion_spi, ORION_SPI_IF_CONFIG_REG, - ORION_SPI_IF_8_16_BIT_MODE); - } else { - pr_debug("Bad bits per word value %d (only 8 or 16 are allowed).\n", - size); - return -EINVAL; - } - - return 0; -} - static int orion_spi_baudrate_set(struct spi_device *spi, unsigned int speed) { u32 tclk_hz; @@ -169,7 +152,14 @@ orion_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t) if (rc) return rc; - return orion_spi_set_transfer_size(orion_spi, bits_per_word); + if (bits_per_word == 16) + orion_spi_setbits(orion_spi, ORION_SPI_IF_CONFIG_REG, + ORION_SPI_IF_8_16_BIT_MODE); + else + orion_spi_clrbits(orion_spi, ORION_SPI_IF_CONFIG_REG, + ORION_SPI_IF_8_16_BIT_MODE); + + return 0; } static void orion_spi_set_cs(struct orion_spi *orion_spi, int enable) @@ -425,6 +415,7 @@ static int orion_spi_probe(struct platform_device *pdev) master->setup = orion_spi_setup; master->transfer_one_message = orion_spi_transfer_one_message; master->num_chipselect = ORION_NUM_CHIPSELECTS; + master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16); platform_set_drvdata(pdev, master);