From patchwork Tue Feb 18 01:31:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Lin X-Patchwork-Id: 3666481 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 4E1499F38B for ; Tue, 18 Feb 2014 01:31:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5B39D201F7 for ; Tue, 18 Feb 2014 01:31:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 502C02020F for ; Tue, 18 Feb 2014 01:31:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751547AbaBRBbf (ORCPT ); Mon, 17 Feb 2014 20:31:35 -0500 Received: from mail-pb0-f52.google.com ([209.85.160.52]:45282 "EHLO mail-pb0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751137AbaBRBbf (ORCPT ); Mon, 17 Feb 2014 20:31:35 -0500 Received: by mail-pb0-f52.google.com with SMTP id jt11so15973965pbb.25 for ; Mon, 17 Feb 2014 17:31:34 -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=umSYmOqEVQNLH7L7jISrUq2J4UQR/VkwLDN7QcGG0nc=; b=fHu6rrAKYB6qmmFAEWWYKWwVx+7gKmBhMbcIvikC55YRrTFpwohIurWUBvaFfP+gkx tVceMVa16YxMPBZ3JYEj0cOWOgByfPBT9oxZqcOm9zVb01rMDroazx6LKPkA8Tv0/1as 3n9HlEwpiGnMmHDuHU6GbRGH9fJBVnWS/ZEG926GW5d6ybHZLcqgyYVnqp9ySvg2QNoB CVuiWrk+kyTa8gWnZW2KwmOGeCQFtfo45RhqM52ZDJM5EVxgHHQYH0CEYQjQvHU8y81g ojm2aHK4BOAMMR5mlU+HT8k0OCiDEOjC7OvoxQCwQBpKtxOCY2MRaugnYWyOvDokKPdP Rnvg== X-Gm-Message-State: ALoCoQm5Vc9XN3kWY89v31PpfJCMEulvtS3WYVmedg5Wtx+5/K2MxPg2L5XBzrvpzRt39J7hWH0S X-Received: by 10.68.130.169 with SMTP id of9mr29752558pbb.79.1392687094742; Mon, 17 Feb 2014 17:31:34 -0800 (PST) Received: from [192.168.0.102] (218-164-138-164.dynamic.hinet.net. [218.164.138.164]) by mx.google.com with ESMTPSA id yz5sm129328484pac.9.2014.02.17.17.31.32 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 17 Feb 2014 17:31:33 -0800 (PST) Message-ID: <1392687089.5047.1.camel@phoenix> Subject: [RFT][PATCH v2] spi: clps711x: refactor to use core message parsing From: Axel Lin To: Mark Brown Cc: Alexander Shiyan , linux-spi@vger.kernel.org Date: Tue, 18 Feb 2014 09:31:29 +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=unavailable 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 Convert to use default implementation of transfer_one_message() which provides standard handling of delays and chip select management. Signed-off-by: Axel Lin --- v2: Remove spi_clps711x_set_cs() as it is done by spi core drivers/spi/spi-clps711x.c | 82 +++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 52 deletions(-) diff --git a/drivers/spi/spi-clps711x.c b/drivers/spi/spi-clps711x.c index f973e97..e07d1b0 100644 --- a/drivers/spi/spi-clps711x.c +++ b/drivers/spi/spi-clps711x.c @@ -24,8 +24,6 @@ #define DRIVER_NAME "spi-clps711x" struct spi_clps711x_data { - struct completion done; - struct clk *spi_clk; u32 max_speed_hz; @@ -43,15 +41,6 @@ static int spi_clps711x_setup(struct spi_device *spi) return 0; } -static void spi_clps711x_setup_mode(struct spi_device *spi) -{ - /* Setup edge for transfer */ - if (spi->mode & SPI_CPHA) - clps_writew(clps_readw(SYSCON3) | SYSCON3_ADCCKNSEN, SYSCON3); - else - clps_writew(clps_readw(SYSCON3) & ~SYSCON3_ADCCKNSEN, SYSCON3); -} - static void spi_clps711x_setup_xfer(struct spi_device *spi, struct spi_transfer *xfer) { @@ -73,55 +62,44 @@ static void spi_clps711x_setup_xfer(struct spi_device *spi, SYSCON1_ADCKSEL(0), SYSCON1); } -static int spi_clps711x_transfer_one_message(struct spi_master *master, - struct spi_message *msg) +static int spi_clps711x_prepare_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; - - spi_clps711x_setup_mode(spi); - - list_for_each_entry(xfer, &msg->transfers, transfer_list) { - u8 data; - - spi_clps711x_setup_xfer(spi, xfer); - gpio_set_value(spi->cs_gpio, !!(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(hw->bpw) | SYNCIO_TXFRMEN, - SYNCIO); - - wait_for_completion(&hw->done); + /* Setup edge for transfer */ + if (spi->mode & SPI_CPHA) + clps_writew(clps_readw(SYSCON3) | SYSCON3_ADCCKNSEN, SYSCON3); + else + clps_writew(clps_readw(SYSCON3) & ~SYSCON3_ADCCKNSEN, SYSCON3); - if (xfer->delay_usecs) - udelay(xfer->delay_usecs); + return 0; +} - if (xfer->cs_change || - list_is_last(&xfer->transfer_list, &msg->transfers)) - gpio_set_value(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH)); +static int spi_clps711x_transfer_one(struct spi_master *master, + struct spi_device *spi, + struct spi_transfer *xfer) +{ + struct spi_clps711x_data *hw = spi_master_get_devdata(master); + u8 data; - msg->actual_length += xfer->len; - } + spi_clps711x_setup_xfer(spi, xfer); - msg->status = 0; - spi_finalize_current_message(master); + 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; - return 0; + /* Initiate transfer */ + data = hw->tx_buf ? *hw->tx_buf++ : 0; + clps_writel(data | SYNCIO_FRMLEN(hw->bpw) | SYNCIO_TXFRMEN, SYNCIO); + return 1; } static irqreturn_t spi_clps711x_isr(int irq, void *dev_id) { - struct spi_clps711x_data *hw = (struct spi_clps711x_data *)dev_id; + struct spi_master *master = dev_id; + struct spi_clps711x_data *hw = spi_master_get_devdata(master); u8 data; /* Handle RX */ @@ -135,7 +113,7 @@ static irqreturn_t spi_clps711x_isr(int irq, void *dev_id) clps_writel(data | SYNCIO_FRMLEN(hw->bpw) | SYNCIO_TXFRMEN, SYNCIO); } else - complete(&hw->done); + complete(&master->xfer_completion); return IRQ_HANDLED; } @@ -173,7 +151,8 @@ static int spi_clps711x_probe(struct platform_device *pdev) 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; + master->prepare_message = spi_clps711x_prepare_message; + master->transfer_one = spi_clps711x_transfer_one; hw = spi_master_get_devdata(master); @@ -199,7 +178,6 @@ static int spi_clps711x_probe(struct platform_device *pdev) } hw->max_speed_hz = clk_get_rate(hw->spi_clk); - init_completion(&hw->done); platform_set_drvdata(pdev, master); /* Disable extended mode due hardware problems */ @@ -209,7 +187,7 @@ static int spi_clps711x_probe(struct platform_device *pdev) clps_readl(SYNCIO); ret = devm_request_irq(&pdev->dev, IRQ_SSEOTI, spi_clps711x_isr, 0, - dev_name(&pdev->dev), hw); + dev_name(&pdev->dev), master); if (ret) { dev_err(&pdev->dev, "Can't request IRQ\n"); goto err_out;