From patchwork Sun Aug 7 19:49:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9266547 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 3F8D860754 for ; Sun, 7 Aug 2016 19:49:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2FB8725D99 for ; Sun, 7 Aug 2016 19:49:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 24CDC27D0E; Sun, 7 Aug 2016 19:49:46 +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 B273C25D99 for ; Sun, 7 Aug 2016 19:49:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751981AbcHGTtp (ORCPT ); Sun, 7 Aug 2016 15:49:45 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:34680 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751947AbcHGTto (ORCPT ); Sun, 7 Aug 2016 15:49:44 -0400 Received: by mail-wm0-f65.google.com with SMTP id q128so11988973wma.1 for ; Sun, 07 Aug 2016 12:49:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:subject:to:cc:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=/m/MWCOA/MJ5UdLqsIyj9cAu2q2AvFzxaj/HIneIg90=; b=egxRJA7VGwxVcVqOnR2uwMM5/ODU9GMyWN2WmACiIRUaAZFbg/Ann3XU9umYhZQiVu sHg22c+DxTTArjmZiF5z4Z7sXVec/tpLRqgMi0bgCNceZYNIU5HfInescOygZd3PMY+a yGqbhvtp8Kb+ZiHQTrHzJHkg2gsnjswMeLZTQimSR3sIEb6eMDWQjptN0zn0Nbj97P3O kA8JQB3H/rngGPJu41gYhthc44IpXzZZMJhUG32ORChNGbwVDP0CA2KH1UMsEEfEwOTJ JMevfy4RwVL+IxFz4I6xF3O3CwP2MsEkAj/dbCkliD6y88+jdoU9W6hyitR57ee8CZ4i t7Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:cc:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=/m/MWCOA/MJ5UdLqsIyj9cAu2q2AvFzxaj/HIneIg90=; b=g59imeTQLZqG7Ru87+B/YzPedHQCV0l1tAx/oSt03lFwH4qsDtHgnxO00V+pCDWs3q S7gCgSEg0fr0aHUT75myxW27PEIZa1jmSyE7HSRMANOlcQysxmNB5hvHbWxIDRDD94qG vVbkWK8xKaIUJnG9r7RGg0T0Bevkxipi3fC7MBHTXk5aEFhi/n4w73C5MFZ9sbeM2ksA I/hITLnsYZAwuoF6HzYttVlpCJZUU+Ly7Rh2HgLSddo7bTH3n4HtTpy4XiNmw++wRJ20 zci8dIpgkk/Y1NtMKJ1DdzvIbAMIIJsbbyzYq32x+yoEVBZKVuhuseMdTfc7nuRbJO8X s0Ug== X-Gm-Message-State: AEkoous8PubuuTMkFeeqoJ2lXZs4Bcy3GRaTUfLLCdkGMo7kRUSmHYQ7JqIJoPg4Ic/c6g== X-Received: by 10.194.235.229 with SMTP id up5mr88294475wjc.69.1470599383270; Sun, 07 Aug 2016 12:49:43 -0700 (PDT) Received: from ?IPv6:2003:62:5f01:4400:19c4:bee6:ba17:e190? (p200300625F01440019C4BEE6BA17E190.dip0.t-ipconnect.de. [2003:62:5f01:4400:19c4:bee6:ba17:e190]) by smtp.googlemail.com with ESMTPSA id b203sm19918140wmh.20.2016.08.07.12.49.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Aug 2016 12:49:42 -0700 (PDT) From: Heiner Kallweit Subject: [PATCH 3/3] spi: fsl-espi: eliminate spi nor flash read loop To: Mark Brown , Brian Norris Cc: "linux-spi@vger.kernel.org" , MTD Maling List Message-ID: <64289061-b779-1dcf-abd7-274a23e91b49@gmail.com> Date: Sun, 7 Aug 2016 21:49:30 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.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 The fsl-espi driver contains a read loop that implicitely assumes that the device to read from is a m25p80 SPI NOR flash (bytes 2 - 4 of the first write transfer are interpreted as 3 byte flash address). Now that we have such a read loop in the spi-nor driver and are able to correctly indicate the message size limit of the controller, the read loop can be removed from the fsl-espi driver. Signed-off-by: Heiner Kallweit --- drivers/spi/spi-fsl-espi.c | 88 +++++++++++----------------------------------- 1 file changed, 20 insertions(+), 68 deletions(-) diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c index 8d85a3c..f3ff65f 100644 --- a/drivers/spi/spi-fsl-espi.c +++ b/drivers/spi/spi-fsl-espi.c @@ -258,23 +258,6 @@ static int fsl_espi_bufs(struct spi_device *spi, struct spi_transfer *t) return mpc8xxx_spi->count; } -static inline void fsl_espi_addr2cmd(unsigned int addr, u8 *cmd) -{ - if (cmd) { - cmd[1] = (u8)(addr >> 16); - cmd[2] = (u8)(addr >> 8); - cmd[3] = (u8)(addr >> 0); - } -} - -static inline unsigned int fsl_espi_cmd2addr(u8 *cmd) -{ - if (cmd) - return cmd[1] << 16 | cmd[2] << 8 | cmd[3] << 0; - - return 0; -} - static void fsl_espi_do_trans(struct spi_message *m, struct fsl_espi_transfer *tr) { @@ -366,68 +349,36 @@ static void fsl_espi_cmd_trans(struct spi_message *m, static void fsl_espi_rw_trans(struct spi_message *m, struct fsl_espi_transfer *trans, u8 *rx_buff) { - struct fsl_espi_transfer *espi_trans = trans; - unsigned int total_len = espi_trans->len; struct spi_transfer *t; u8 *local_buf; - u8 *rx_buf = rx_buff; - unsigned int trans_len; - unsigned int addr; - unsigned int tx_only; - unsigned int rx_pos = 0; - unsigned int pos; - int i, loop; + unsigned int tx_only = 0; + int i = 0; local_buf = kzalloc(SPCOM_TRANLEN_MAX, GFP_KERNEL); if (!local_buf) { - espi_trans->status = -ENOMEM; + trans->status = -ENOMEM; return; } - for (pos = 0, loop = 0; pos < total_len; pos += trans_len, loop++) { - trans_len = total_len - pos; - - i = 0; - tx_only = 0; - list_for_each_entry(t, &m->transfers, transfer_list) { - if (t->tx_buf) { - memcpy(local_buf + i, t->tx_buf, t->len); - i += t->len; - if (!t->rx_buf) - tx_only += t->len; - } - } - - /* Add additional TX bytes to compensate SPCOM_TRANLEN_MAX */ - if (loop > 0) - trans_len += tx_only; - - if (trans_len > SPCOM_TRANLEN_MAX) - trans_len = SPCOM_TRANLEN_MAX; - - /* Update device offset */ - if (pos > 0) { - addr = fsl_espi_cmd2addr(local_buf); - addr += rx_pos; - fsl_espi_addr2cmd(addr, local_buf); + list_for_each_entry(t, &m->transfers, transfer_list) { + if (t->tx_buf) { + memcpy(local_buf + i, t->tx_buf, t->len); + i += t->len; + if (!t->rx_buf) + tx_only += t->len; } + } - espi_trans->len = trans_len; - espi_trans->tx_buf = local_buf; - espi_trans->rx_buf = local_buf; - fsl_espi_do_trans(m, espi_trans); - - /* If there is at least one RX byte then copy it to rx_buf */ - if (tx_only < SPCOM_TRANLEN_MAX) - memcpy(rx_buf + rx_pos, espi_trans->rx_buf + tx_only, - trans_len - tx_only); - - rx_pos += trans_len - tx_only; + trans->tx_buf = local_buf; + trans->rx_buf = local_buf; + fsl_espi_do_trans(m, trans); - if (loop > 0) - espi_trans->actual_length += espi_trans->len - tx_only; - else - espi_trans->actual_length += espi_trans->len; + if (!trans->status) { + /* If there is at least one RX byte then copy it to rx_buff */ + if (trans->len > tx_only) + memcpy(rx_buff, trans->rx_buf + tx_only, + trans->len - tx_only); + trans->actual_length += trans->len; } kfree(local_buf); @@ -696,6 +647,7 @@ static struct spi_master * fsl_espi_probe(struct device *dev, master->transfer_one_message = fsl_espi_do_one_msg; master->auto_runtime_pm = true; master->max_transfer_size = fsl_espi_max_transfer_size; + master->max_message_size_flag = true; mpc8xxx_spi = spi_master_get_devdata(master);