From patchwork Mon Jan 30 21:11:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamal Dasu X-Patchwork-Id: 9546105 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 4C6CA604A0 for ; Mon, 30 Jan 2017 21:12:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 414CA28285 for ; Mon, 30 Jan 2017 21:12:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 358E028307; Mon, 30 Jan 2017 21:12:26 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 AD48728285 for ; Mon, 30 Jan 2017 21:12:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754379AbdA3VMY (ORCPT ); Mon, 30 Jan 2017 16:12:24 -0500 Received: from mail-qk0-f196.google.com ([209.85.220.196]:33195 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754363AbdA3VMX (ORCPT ); Mon, 30 Jan 2017 16:12:23 -0500 Received: by mail-qk0-f196.google.com with SMTP id 11so20794788qkl.0 for ; Mon, 30 Jan 2017 13:12:23 -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; bh=s0cUZDmD5KAdoyuqIkxDR69NoHTtlHYZUDbDvdWqrXg=; b=ptI40xOCeAGtvuJ8kgjGjwKBw8CeVl/izPmegfckffxGs4bxJCKD1C8+GZ9oNUAQcD CYITGqKxgb6TB/dlyjj3TI4W5a5ZYOhs0LfS29MQx6xb/3COxixJHbMaZn76ud9Z5NH/ 8REvCqr61ApGl+7yUqtfZ9NwoZEC3vpkpVmIUKbNUSMtt1fvth1LHCC0DXrI/ifkvm0D bh1U6G8G2Qg/n1efCL6MPR/AA2ewx1Rx4luwAf8iSTAaLEb96/f8+7XYWJYsNgKNMFH7 hVuWmJckp9LgPZpc+8/sgf0GXW/hWi1MJVlOGq2dh6DpnBoubnE6IMPuvK7jTQDGbdQl t75w== 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; bh=s0cUZDmD5KAdoyuqIkxDR69NoHTtlHYZUDbDvdWqrXg=; b=AQOAgxu5VCElCMwIgQ8Q7tVYObzx3VFBfcZ3Hcqf4C+77n9vXA+y2wYTwXGCW5MTbr luTB5AySAe4gDeFxXZ5pB8hQi70t8uGHA2MJUGOmiowslgqFELwsX+wsSEsIEkhVqZIA YbktyBuznFF0t2UZC1V09fCNCjNJAKRNqg/1aUURXAxO0+u77ijzY9RrQA5nHExbYRSP EwKViqycZbjORcu8y/NvEoIW1yfsb/KXldBORsXapKBH+f2ZsobWjF+7iz8XEUyC+uck XI4J6Fl4c7jR9hVR/KdaH+O3ziXyKUW7O/ccDgwLuF6UQ7dzjvYsKHlGGvUf9x+rdWir aZCA== X-Gm-Message-State: AIkVDXLhCIDJdNcNItSins8Sg7gqQGDFq10wjxmIIWUIftDGQm0KMjNIrnP4RkgcsplyUw== X-Received: by 10.55.110.6 with SMTP id j6mr8735388qkc.92.1485810742987; Mon, 30 Jan 2017 13:12:22 -0800 (PST) Received: from mail.broadcom.com ([192.19.218.250]) by smtp.gmail.com with ESMTPSA id r57sm13330274qtr.27.2017.01.30.13.12.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 30 Jan 2017 13:12:22 -0800 (PST) From: Kamal Dasu To: linux-spi@vger.kernel.org, cyrille.pitchen@atmel.com, marex@denx.de, broonie@kernel.org Cc: linux-mtd@lists.infradead.org, f.fainelli@gmail.com, bcm-kernel-feedback-list@broadcom.com, Kamal Dasu Subject: [PATCH 1/1] spi: bcm-qspi: Added mspi read fallback in bcm_qspi_flash_read() Date: Mon, 30 Jan 2017 16:11:16 -0500 Message-Id: <1485810676-19742-1-git-send-email-kdasu.kdev@gmail.com> X-Mailer: git-send-email 1.9.1 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 Added mspi read fallback under certain circumstances like unaligned buffer, address on short reads. Also takes care of version 3.0 spi controller where flash address crosses 4MB boundary on transfers the driver resorts to mspi reads. Signed-off-by: Kamal Dasu --- drivers/spi/spi-bcm-qspi.c | 116 +++++++++++++++++++++++++++++++++------------ 1 file changed, 85 insertions(+), 31 deletions(-) diff --git a/drivers/spi/spi-bcm-qspi.c b/drivers/spi/spi-bcm-qspi.c index 14f9dea..b50b6df 100644 --- a/drivers/spi/spi-bcm-qspi.c +++ b/drivers/spi/spi-bcm-qspi.c @@ -192,9 +192,11 @@ struct bcm_qspi_dev_id { void *dev; }; + struct qspi_trans { struct spi_transfer *trans; int byte; + bool mspi_last_trans; }; struct bcm_qspi { @@ -616,6 +618,16 @@ static int bcm_qspi_setup(struct spi_device *spi) return 0; } +static bool bcm_qspi_mspi_transfer_is_last(struct bcm_qspi *qspi, + struct qspi_trans *qt) +{ + if (qt->mspi_last_trans && + spi_transfer_is_last(qspi->master, qt->trans)) + return true; + else + return false; +} + static int update_qspi_trans_byte_count(struct bcm_qspi *qspi, struct qspi_trans *qt, int flags) { @@ -629,7 +641,6 @@ static int update_qspi_trans_byte_count(struct bcm_qspi *qspi, if (qt->byte >= qt->trans->len) { /* we're at the end of the spi_transfer */ - /* in TX mode, need to pause for a delay or CS change */ if (qt->trans->delay_usecs && (flags & TRANS_STATUS_BREAK_DELAY)) @@ -641,7 +652,7 @@ static int update_qspi_trans_byte_count(struct bcm_qspi *qspi, goto done; dev_dbg(&qspi->pdev->dev, "advance msg exit\n"); - if (spi_transfer_is_last(qspi->master, qt->trans)) + if (bcm_qspi_mspi_transfer_is_last(qspi, qt)) ret = TRANS_STATUS_BREAK_EOM; else ret = TRANS_STATUS_BREAK_NO_BYTES; @@ -885,6 +896,76 @@ static int bcm_qspi_bspi_flash_read(struct spi_device *spi, return ret; } +static int bcm_qspi_transfer_one(struct spi_master *master, + struct spi_device *spi, + struct spi_transfer *trans) +{ + struct bcm_qspi *qspi = spi_master_get_devdata(master); + int slots; + unsigned long timeo = msecs_to_jiffies(100); + + bcm_qspi_chip_select(qspi, spi->chip_select); + qspi->trans_pos.trans = trans; + qspi->trans_pos.byte = 0; + + while (qspi->trans_pos.byte < trans->len) { + reinit_completion(&qspi->mspi_done); + + slots = write_to_hw(qspi, spi); + if (!wait_for_completion_timeout(&qspi->mspi_done, timeo)) { + dev_err(&qspi->pdev->dev, "timeout waiting for MSPI\n"); + return -ETIMEDOUT; + } + + read_from_hw(qspi, slots); + } + + return 0; +} + +static int bcm_qspi_mspi_flash_read(struct spi_device *spi, + struct spi_flash_read_message *msg) +{ + struct bcm_qspi *qspi = spi_master_get_devdata(spi->master); + struct spi_transfer t[2]; + u8 cmd[6]; + int ret; + + memset(cmd, 0, sizeof(cmd)); + memset(t, 0, sizeof(t)); + + /* tx */ + /* opcode is in cmd[0] */ + cmd[0] = msg->read_opcode; + cmd[1] = msg->from >> (msg->addr_width * 8 - 8); + cmd[2] = msg->from >> (msg->addr_width * 8 - 16); + cmd[3] = msg->from >> (msg->addr_width * 8 - 24); + cmd[4] = msg->from >> (msg->addr_width * 8 - 32); + t[0].tx_buf = cmd; + t[0].len = msg->addr_width + msg->dummy_bytes + 1; + t[0].bits_per_word = spi->bits_per_word; + t[0].tx_nbits = msg->opcode_nbits; + /* lets mspi know that this is not last transfer */ + qspi->trans_pos.mspi_last_trans = false; + ret = bcm_qspi_transfer_one(spi->master, spi, &t[0]); + + /* rx */ + qspi->trans_pos.mspi_last_trans = true; + if (!ret) { + /* rx */ + t[1].rx_buf = msg->buf; + t[1].len = msg->len; + t[1].rx_nbits = msg->data_nbits; + t[1].bits_per_word = spi->bits_per_word; + ret = bcm_qspi_transfer_one(spi->master, spi, &t[1]); + } + + if (!ret) + msg->retlen = msg->len; + + return ret; +} + static int bcm_qspi_flash_read(struct spi_device *spi, struct spi_flash_read_message *msg) { @@ -918,8 +999,7 @@ static int bcm_qspi_flash_read(struct spi_device *spi, mspi_read = true; if (mspi_read) - /* this will make the m25p80 read to fallback to mspi read */ - return -EAGAIN; + return bcm_qspi_mspi_flash_read(spi, msg); io_width = msg->data_nbits ? msg->data_nbits : SPI_NBITS_SINGLE; addrlen = msg->addr_width; @@ -931,33 +1011,6 @@ static int bcm_qspi_flash_read(struct spi_device *spi, return ret; } -static int bcm_qspi_transfer_one(struct spi_master *master, - struct spi_device *spi, - struct spi_transfer *trans) -{ - struct bcm_qspi *qspi = spi_master_get_devdata(master); - int slots; - unsigned long timeo = msecs_to_jiffies(100); - - bcm_qspi_chip_select(qspi, spi->chip_select); - qspi->trans_pos.trans = trans; - qspi->trans_pos.byte = 0; - - while (qspi->trans_pos.byte < trans->len) { - reinit_completion(&qspi->mspi_done); - - slots = write_to_hw(qspi, spi); - if (!wait_for_completion_timeout(&qspi->mspi_done, timeo)) { - dev_err(&qspi->pdev->dev, "timeout waiting for MSPI\n"); - return -ETIMEDOUT; - } - - read_from_hw(qspi, slots); - } - - return 0; -} - static void bcm_qspi_cleanup(struct spi_device *spi) { struct bcm_qspi_parms *xp = spi_get_ctldata(spi); @@ -1187,6 +1240,7 @@ int bcm_qspi_probe(struct platform_device *pdev, qspi->pdev = pdev; qspi->trans_pos.trans = NULL; qspi->trans_pos.byte = 0; + qspi->trans_pos.mspi_last_trans = true; qspi->master = master; master->bus_num = -1;