From patchwork Sun Feb 2 06:59:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Shiyan X-Patchwork-Id: 3566521 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 EF9A89F2E9 for ; Sun, 2 Feb 2014 07:00:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E255720251 for ; Sun, 2 Feb 2014 07:00:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C9B782017A for ; Sun, 2 Feb 2014 07:00:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750900AbaBBHAc (ORCPT ); Sun, 2 Feb 2014 02:00:32 -0500 Received: from fallback6.mail.ru ([94.100.176.134]:36101 "EHLO fallback6.mail.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750770AbaBBHAc (ORCPT ); Sun, 2 Feb 2014 02:00:32 -0500 Received: from smtp40.i.mail.ru (smtp40.i.mail.ru [94.100.177.100]) by fallback6.mail.ru (mPOP.Fallback_MX) with ESMTP id 996452FD6F46 for ; Sun, 2 Feb 2014 11:00:20 +0400 (MSK) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.ru; s=mail2; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=MiI4K/Pjq77IY9fVyHZMsFfn20Ok/I+4axeXgSjZlf0=; b=eWDBxeahv+u2X2yzcN+/pGLRxUO39F1jxTxBSC8zFHHlxEq0ukDeiueOrQFm7CC9g+IGAMTeigbp0RK1Kd9GR+H80kYfTuMLQkZm+LHDIKTJ8sudxpaemExle+24Jb2XFYkB00h0fc5sJcOlRSMa6niKSqRFUS205aUuG929tcs=; Received: from [188.134.40.128] (port=62912 helo=shc.zet) by smtp40.i.mail.ru with esmtpa (envelope-from ) id 1W9r2G-0001vA-UE; Sun, 02 Feb 2014 11:00:09 +0400 From: Alexander Shiyan To: linux-spi@vger.kernel.org Cc: Mark Brown , Alexander Shiyan Subject: [PATCH 2/3] spi: clps711x: Add support for 1-8 BPW transfers Date: Sun, 2 Feb 2014 10:59:49 +0400 Message-Id: <1391324390-17547-2-git-send-email-shc_work@mail.ru> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1391324390-17547-1-git-send-email-shc_work@mail.ru> References: <1391324390-17547-1-git-send-email-shc_work@mail.ru> X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Mras: Ok Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RDNS_NONE, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no 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 This patch adds support for 1 to 8 BPW to driver and removes excess BPW validation since this is already checked by SPI core. Signed-off-by: Alexander Shiyan --- drivers/spi/spi-clps711x.c | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/drivers/spi/spi-clps711x.c b/drivers/spi/spi-clps711x.c index 0b80624..d9fa933 100644 --- a/drivers/spi/spi-clps711x.c +++ b/drivers/spi/spi-clps711x.c @@ -31,6 +31,7 @@ struct spi_clps711x_data { u8 *tx_buf; u8 *rx_buf; + unsigned int bpw; int len; int chipselect[0]; @@ -56,18 +57,12 @@ static void spi_clps711x_setup_mode(struct spi_device *spi) clps_writew(clps_readw(SYSCON3) & ~SYSCON3_ADCCKNSEN, SYSCON3); } -static int spi_clps711x_setup_xfer(struct spi_device *spi, - struct spi_transfer *xfer) +static void spi_clps711x_setup_xfer(struct spi_device *spi, + struct spi_transfer *xfer) { u32 speed = xfer->speed_hz ? : spi->max_speed_hz; - u8 bpw = xfer->bits_per_word; struct spi_clps711x_data *hw = spi_master_get_devdata(spi->master); - if (bpw != 8) { - dev_err(&spi->dev, "Unsupported master bus width %i\n", bpw); - return -EINVAL; - } - /* Setup SPI frequency divider */ if (!speed || (speed >= hw->max_speed_hz)) clps_writel((clps_readl(SYSCON1) & ~SYSCON1_ADCKSEL_MASK) | @@ -81,38 +76,36 @@ static int spi_clps711x_setup_xfer(struct spi_device *spi, else clps_writel((clps_readl(SYSCON1) & ~SYSCON1_ADCKSEL_MASK) | SYSCON1_ADCKSEL(0), SYSCON1); - - return 0; } static int spi_clps711x_transfer_one_message(struct spi_master *master, struct spi_message *msg) { struct spi_clps711x_data *hw = spi_master_get_devdata(master); + struct spi_device *spi = msg->spi; struct spi_transfer *xfer; - int status = 0, cs = hw->chipselect[msg->spi->chip_select]; + int cs = hw->chipselect[spi->chip_select]; - spi_clps711x_setup_mode(msg->spi); + spi_clps711x_setup_mode(spi); list_for_each_entry(xfer, &msg->transfers, transfer_list) { u8 data; - if (spi_clps711x_setup_xfer(msg->spi, xfer)) { - status = -EINVAL; - goto out_xfr; - } + spi_clps711x_setup_xfer(spi, xfer); - gpio_set_value(cs, !!(msg->spi->mode & SPI_CS_HIGH)); + gpio_set_value(cs, !!(spi->mode & SPI_CS_HIGH)); reinit_completion(&hw->done); hw->len = xfer->len; + hw->bpw = xfer->bits_per_word ? : spi->bits_per_word; hw->tx_buf = (u8 *)xfer->tx_buf; hw->rx_buf = (u8 *)xfer->rx_buf; /* Initiate transfer */ data = hw->tx_buf ? *hw->tx_buf++ : 0; - clps_writel(data | SYNCIO_FRMLEN(8) | SYNCIO_TXFRMEN, SYNCIO); + clps_writel(data | SYNCIO_FRMLEN(hw->bpw) | SYNCIO_TXFRMEN, + SYNCIO); wait_for_completion(&hw->done); @@ -121,13 +114,12 @@ static int spi_clps711x_transfer_one_message(struct spi_master *master, if (xfer->cs_change || list_is_last(&xfer->transfer_list, &msg->transfers)) - gpio_set_value(cs, !(msg->spi->mode & SPI_CS_HIGH)); + gpio_set_value(cs, !(spi->mode & SPI_CS_HIGH)); msg->actual_length += xfer->len; } -out_xfr: - msg->status = status; + msg->status = 0; spi_finalize_current_message(master); return 0; @@ -146,7 +138,8 @@ static irqreturn_t spi_clps711x_isr(int irq, void *dev_id) /* Handle TX */ if (--hw->len > 0) { data = hw->tx_buf ? *hw->tx_buf++ : 0; - clps_writel(data | SYNCIO_FRMLEN(8) | SYNCIO_TXFRMEN, SYNCIO); + clps_writel(data | SYNCIO_FRMLEN(hw->bpw) | SYNCIO_TXFRMEN, + SYNCIO); } else complete(&hw->done); @@ -180,7 +173,7 @@ static int spi_clps711x_probe(struct platform_device *pdev) master->bus_num = pdev->id; master->mode_bits = SPI_CPHA | SPI_CS_HIGH; - master->bits_per_word_mask = SPI_BPW_MASK(8); + master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 8); master->num_chipselect = pdata->num_chipselect; master->setup = spi_clps711x_setup; master->transfer_one_message = spi_clps711x_transfer_one_message;