From patchwork Fri Dec 29 13:48:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 10137127 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D82DB60318 for ; Fri, 29 Dec 2017 13:48:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C574F2D9E6 for ; Fri, 29 Dec 2017 13:48:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B78152DE57; Fri, 29 Dec 2017 13:48:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87B2F2D9E6 for ; Fri, 29 Dec 2017 13:48:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751202AbdL2Nsc (ORCPT ); Fri, 29 Dec 2017 08:48:32 -0500 Received: from mail-lf0-f68.google.com ([209.85.215.68]:35623 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751194AbdL2Nsb (ORCPT ); Fri, 29 Dec 2017 08:48:31 -0500 Received: by mail-lf0-f68.google.com with SMTP id h5so4526265lfj.2 for ; Fri, 29 Dec 2017 05:48:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8VBkFbEqHMeCviZG7jhha8jD4EpiWmDWOWJ+r3A3fEk=; b=Asrqr7+w33Mmq8Ye52AjMZGGoT2kjNLkOtu3pnMRrK1Q1/qjr8XN/UbmTdM/kgVm3P jD5f3518yrGVmOtzGjkE+D8WUoDSOoZHtG9w/tJ3KeeAd7PxePzMMQoweKuYk9sd/S6I EO9BnjAzsjSVhFlrqW8QYUOHP7G0fd8buzAX/z/arcYfOrRjFZ8iEIJjkCvtcI5GakbI DorFQHLUHDCXLaqPskOvPG/iCCytTNFjvYeURsh53WH4qwwmD1rTqX2SQnfFtIkq9D94 F8LEY5xEhfaOVK6TPreQNDonGKaxahUwXfol+AHUjSxP/nNnUvLL+yCMYdnlVc568RFC g4ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8VBkFbEqHMeCviZG7jhha8jD4EpiWmDWOWJ+r3A3fEk=; b=QzHvpuGyp2uIyAnz+2hSnEVnwROw7jvoBQ6J7cLYUx+uAokYweB/CmSYPd0gaqjBIT TSdCEAEhmVLOp6U9GLDXw3dpRXSZxA99W0t5lW3Y5rcW6KjmZGkLWLa+DXvaADkuCcWo H/wnieIOL0lunmudq3Z0hJw9xTT05agwXQAftQqGNCYXm0T0eLS8aqgoVdELpMJ+d5xO MyNLsu25xD8nGAX0jRvolghO6VYr7/LGprYJ9wfY9PIKmXw/nob9PFD8zuNWqCsUS4qy 7ZOqDuS3yd86nifEHv/MbBny1/nONiJqJpU1AGU0FwFK75BpjL4MP3Vp4VxsmOx6cXFB rjSg== X-Gm-Message-State: AKGB3mIwdCbNWPrm3GtW3g5FuAV15jevM3x+vEtfcHQDJ1BVgqziARXH DY77Bfxq1ogRh01NmFFNcvk/Ew== X-Google-Smtp-Source: ACJfBosqf6rJHPmyglqyb3RX5mGzNwRULyS7XTnSa1aYp4Ae7jdp7UuioVni9jjVLnQcwAflGEhD0w== X-Received: by 10.25.196.212 with SMTP id u203mr16018798lff.126.1514555309764; Fri, 29 Dec 2017 05:48:29 -0800 (PST) Received: from linux-samsung.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id q28sm6140862lfd.14.2017.12.29.05.48.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Dec 2017 05:48:28 -0800 (PST) From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= To: Mark Brown , linux-spi@vger.kernel.org Cc: Hauke Mehrtens , =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= Subject: [PATCH] spi: bcm53xx: simplify reading SPI data Date: Fri, 29 Dec 2017 14:48:02 +0100 Message-Id: <20171229134802.7551-1-zajec5@gmail.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Rafał Miłecki This commit makes transfer function use spi_transfer_is_last to determine if currently processed transfer is the last one. Thanks to that we finally set hardware registers properly and it makes controller behave the way it's expected to. This allows simplifying read function which can now simply start reading from the slot 0 instead of the last saved offset. It has been successfully tested using spi_write_then_read. Moreover this change fixes handling messages with two writing transfers. It's important for SPI flash devices as their drivers commonly use one transfer for a command and another one for data. Signed-off-by: Rafał Miłecki --- drivers/spi/spi-bcm53xx.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/drivers/spi/spi-bcm53xx.c b/drivers/spi/spi-bcm53xx.c index 6e409eabe1c9..d02ceb7a29d1 100644 --- a/drivers/spi/spi-bcm53xx.c +++ b/drivers/spi/spi-bcm53xx.c @@ -27,8 +27,6 @@ struct bcm53xxspi { struct bcma_device *core; struct spi_master *master; void __iomem *mmio_base; - - size_t read_offset; bool bspi; /* Boot SPI mode with memory mapping */ }; @@ -172,8 +170,6 @@ static void bcm53xxspi_buf_write(struct bcm53xxspi *b53spi, u8 *w_buf, if (!cont) bcm53xxspi_write(b53spi, B53SPI_MSPI_WRITE_LOCK, 0); - - b53spi->read_offset = len; } static void bcm53xxspi_buf_read(struct bcm53xxspi *b53spi, u8 *r_buf, @@ -182,10 +178,10 @@ static void bcm53xxspi_buf_read(struct bcm53xxspi *b53spi, u8 *r_buf, u32 tmp; int i; - for (i = 0; i < b53spi->read_offset + len; i++) { + for (i = 0; i < len; i++) { tmp = B53SPI_CDRAM_CONT | B53SPI_CDRAM_PCS_DISABLE_ALL | B53SPI_CDRAM_PCS_DSCK; - if (!cont && i == b53spi->read_offset + len - 1) + if (!cont && i == len - 1) tmp &= ~B53SPI_CDRAM_CONT; tmp &= ~0x1; /* Command Register File */ @@ -194,8 +190,7 @@ static void bcm53xxspi_buf_read(struct bcm53xxspi *b53spi, u8 *r_buf, /* Set queue pointers */ bcm53xxspi_write(b53spi, B53SPI_MSPI_NEWQP, 0); - bcm53xxspi_write(b53spi, B53SPI_MSPI_ENDQP, - b53spi->read_offset + len - 1); + bcm53xxspi_write(b53spi, B53SPI_MSPI_ENDQP, len - 1); if (cont) bcm53xxspi_write(b53spi, B53SPI_MSPI_WRITE_LOCK, 1); @@ -214,13 +209,11 @@ static void bcm53xxspi_buf_read(struct bcm53xxspi *b53spi, u8 *r_buf, bcm53xxspi_write(b53spi, B53SPI_MSPI_WRITE_LOCK, 0); for (i = 0; i < len; ++i) { - int offset = b53spi->read_offset + i; + u16 reg = B53SPI_MSPI_RXRAM + 4 * (1 + i * 2); /* Data stored in the transmit register file LSB */ - r_buf[i] = (u8)bcm53xxspi_read(b53spi, B53SPI_MSPI_RXRAM + 4 * (1 + offset * 2)); + r_buf[i] = (u8)bcm53xxspi_read(b53spi, reg); } - - b53spi->read_offset = 0; } static int bcm53xxspi_transfer_one(struct spi_master *master, @@ -238,7 +231,8 @@ static int bcm53xxspi_transfer_one(struct spi_master *master, left = t->len; while (left) { size_t to_write = min_t(size_t, 16, left); - bool cont = left - to_write > 0; + bool cont = !spi_transfer_is_last(master, t) || + left - to_write > 0; bcm53xxspi_buf_write(b53spi, buf, to_write, cont); left -= to_write; @@ -250,9 +244,9 @@ static int bcm53xxspi_transfer_one(struct spi_master *master, buf = (u8 *)t->rx_buf; left = t->len; while (left) { - size_t to_read = min_t(size_t, 16 - b53spi->read_offset, - left); - bool cont = left - to_read > 0; + size_t to_read = min_t(size_t, 16, left); + bool cont = !spi_transfer_is_last(master, t) || + left - to_read > 0; bcm53xxspi_buf_read(b53spi, buf, to_read, cont); left -= to_read;