From patchwork Wed Jan 28 12:23:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda Delgado X-Patchwork-Id: 5734441 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C34309F38B for ; Thu, 29 Jan 2015 02:06:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 018B9201DD for ; Thu, 29 Jan 2015 02:06:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 15E15201BB for ; Thu, 29 Jan 2015 02:06:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761104AbbA2CGc (ORCPT ); Wed, 28 Jan 2015 21:06:32 -0500 Received: from mail-lb0-f180.google.com ([209.85.217.180]:59905 "EHLO mail-lb0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754389AbbA2CGa (ORCPT ); Wed, 28 Jan 2015 21:06:30 -0500 Received: by mail-lb0-f180.google.com with SMTP id b6so23247904lbj.11; Wed, 28 Jan 2015 18:06:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SR5KZ+P8Jg1FBSd3gI58z5df+ZP8K6oat4I3KreUeHA=; b=Z3UGUMirKVKMmOslO+laE8+Ek5tdw9l2ULGuOLo06N2VKA5iCxHnj+Hgt9Z0V5ZaPt HBMmMypx/6iJ3nkST9AOL6o5pRZKA24NEIQ2bNxN0+nlyvPWT1Bm3usmGLCEtVCowKOM lkcaFF9MvdatXon03DkYpWZhTJWp6wWSNfWpNNgyY+fGn2xt4OFzDS+GSDyGQuHVfYB0 cdWfXidgMDcSm5s3UCzzRGsTqKTMhl/jOjOzWgWdVbbvnwnMxrfW0eYSLVN/xHp/3a2W NYT5rdWvHGbewfRMyhcQYEjww2o0K2rMqgo1GtKbhxenGkb7lL3A3LDQnIqNVp4gRQxD bFxw== X-Received: by 10.112.17.197 with SMTP id q5mr7678448lbd.30.1422447839424; Wed, 28 Jan 2015 04:23:59 -0800 (PST) Received: from neopili.qtec.com (cpe.xe-3-0-1-778.vbrnqe10.dk.customer.tdc.net. [80.197.57.18]) by mx.google.com with ESMTPSA id xh7sm1293741lbb.17.2015.01.28.04.23.58 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Jan 2015 04:23:58 -0800 (PST) From: Ricardo Ribalda Delgado To: Mark Brown , Michal Simek , =?UTF-8?q?S=C3=B6ren=20Brinkmann?= , linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Ricardo Ribalda Delgado Subject: [PATCH v2 01/15] spi/xilinx: Simplify spi_fill_tx_fifo Date: Wed, 28 Jan 2015 13:23:40 +0100 Message-Id: <1422447834-23116-2-git-send-email-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1422447834-23116-1-git-send-email-ricardo.ribalda@gmail.com> References: <1422447834-23116-1-git-send-email-ricardo.ribalda@gmail.com> 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.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_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 Instead of checking the TX_FULL flag for every transaction, find out the size of the buffer at probe time and use it. To avoid situations where the core had some data on the buffer before initialization, the core is reseted before the buffer size is detected Signed-off-by: Ricardo Ribalda Delgado --- v2: Changes Requested by Mark Brown Before discovering the buffer size, reset the core. drivers/spi/spi-xilinx.c | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/drivers/spi/spi-xilinx.c b/drivers/spi/spi-xilinx.c index 416b227..1890af8 100644 --- a/drivers/spi/spi-xilinx.c +++ b/drivers/spi/spi-xilinx.c @@ -88,6 +88,7 @@ struct xilinx_spi { const u8 *tx_ptr; /* pointer in the Rx buffer */ int remaining_bytes; /* the number of bytes left to transfer */ u8 bits_per_word; + int buffer_size; /* buffer size in words */ unsigned int (*read_fn)(void __iomem *); void (*write_fn)(u32, void __iomem *); void (*tx_fn)(struct xilinx_spi *); @@ -221,24 +222,16 @@ static int xilinx_spi_setup_transfer(struct spi_device *spi, return 0; } -static int xilinx_spi_fill_tx_fifo(struct xilinx_spi *xspi) +static void xilinx_spi_fill_tx_fifo(struct xilinx_spi *xspi, int n_words) { - u8 sr; - int n_words = 0; + xspi->remaining_bytes -= n_words * xspi->bits_per_word / 8; - /* Fill the Tx FIFO with as many bytes as possible */ - sr = xspi->read_fn(xspi->regs + XSPI_SR_OFFSET); - while ((sr & XSPI_SR_TX_FULL_MASK) == 0 && xspi->remaining_bytes > 0) { + while (n_words--) if (xspi->tx_ptr) xspi->tx_fn(xspi); else xspi->write_fn(0, xspi->regs + XSPI_TXD_OFFSET); - xspi->remaining_bytes -= xspi->bits_per_word / 8; - sr = xspi->read_fn(xspi->regs + XSPI_SR_OFFSET); - n_words++; - } - - return n_words; + return; } static int xilinx_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t) @@ -265,7 +258,10 @@ static int xilinx_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t) u16 cr; int n_words; - n_words = xilinx_spi_fill_tx_fifo(xspi); + n_words = (xspi->remaining_bytes * 8) / xspi->bits_per_word; + n_words = min(n_words, xspi->buffer_size); + + xilinx_spi_fill_tx_fifo(xspi, n_words); /* Start the transfer by not inhibiting the transmitter any * longer @@ -322,6 +318,28 @@ static irqreturn_t xilinx_spi_irq(int irq, void *dev_id) return IRQ_HANDLED; } +static int xilinx_spi_find_buffer_size(struct xilinx_spi *xspi) +{ + u8 sr; + int n_words = 0; + + /* + * Before the buffer_size detection we reset the core + * to make sure we start with a clean state. + */ + xspi->write_fn(XIPIF_V123B_RESET_MASK, + xspi->regs + XIPIF_V123B_RESETR_OFFSET); + + /* Fill the Tx FIFO with as many words as possible */ + do { + xspi->write_fn(0, xspi->regs + XSPI_TXD_OFFSET); + sr = xspi->read_fn(xspi->regs + XSPI_SR_OFFSET); + n_words++; + } while (!(sr & XSPI_SR_TX_FULL_MASK)); + + return n_words; +} + static const struct of_device_id xilinx_spi_of_match[] = { { .compatible = "xlnx,xps-spi-2.00.a", }, { .compatible = "xlnx,xps-spi-2.00.b", }, @@ -413,6 +431,8 @@ static int xilinx_spi_probe(struct platform_device *pdev) goto put_master; } + xspi->buffer_size = xilinx_spi_find_buffer_size(xspi); + /* SPI controller initializations */ xspi_init_hw(xspi);