From patchwork Fri Mar 18 06:18:55 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shaohui xie X-Patchwork-Id: 87488 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 756AEB6EEC for ; Fri, 18 Mar 2011 17:56:31 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9B1C728110; Fri, 18 Mar 2011 07:56:29 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id b52pNBm8s3HU; Fri, 18 Mar 2011 07:56:29 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CED5A28114; Fri, 18 Mar 2011 07:56:26 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CFC4C28114 for ; Fri, 18 Mar 2011 07:56:24 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WxCkW-l9TnbB for ; Fri, 18 Mar 2011 07:56:23 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from VA3EHSOBE001.bigfish.com (va3ehsobe001.messaging.microsoft.com [216.32.180.11]) by theia.denx.de (Postfix) with ESMTPS id 0BF6D28110 for ; Fri, 18 Mar 2011 07:56:21 +0100 (CET) Received: from mail23-va3-R.bigfish.com (10.7.14.248) by VA3EHSOBE001.bigfish.com (10.7.40.21) with Microsoft SMTP Server id 14.1.225.22; Fri, 18 Mar 2011 06:56:17 +0000 Received: from mail23-va3 (localhost.localdomain [127.0.0.1]) by mail23-va3-R.bigfish.com (Postfix) with ESMTP id 253DD192807F; Fri, 18 Mar 2011 06:56:17 +0000 (UTC) X-SpamScore: -3 X-BigFish: VS-3(zzbb2cKzz1202hzz8275bh8275dhz2dh2a8h668h62h) X-Spam-TCS-SCL: 1:0 X-Forefront-Antispam-Report: KIP:(null); UIP:(null); IPVD:NLI; H:mail.freescale.net; RD:none; EFVD:NLI Received: from mail23-va3 (localhost.localdomain [127.0.0.1]) by mail23-va3 (MessageSwitch) id 1300431376887367_22830; Fri, 18 Mar 2011 06:56:16 +0000 (UTC) Received: from VA3EHSMHS015.bigfish.com (unknown [10.7.14.242]) by mail23-va3.bigfish.com (Postfix) with ESMTP id C8CF01AD004D; Fri, 18 Mar 2011 06:56:16 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by VA3EHSMHS015.bigfish.com (10.7.99.25) with Microsoft SMTP Server (TLS) id 14.1.225.8; Fri, 18 Mar 2011 06:56:16 +0000 Received: from az33smr01.freescale.net (10.64.34.199) by 039-SN1MMR1-001.039d.mgd.msft.net (10.84.1.13) with Microsoft SMTP Server id 14.1.270.2; Fri, 18 Mar 2011 01:56:15 -0500 Received: from localhost.localdomain (rock.ap.freescale.net [10.193.20.106]) by az33smr01.freescale.net (8.13.1/8.13.0) with ESMTP id p2I6uCxx029451; Fri, 18 Mar 2011 01:56:13 -0500 (CDT) From: Shaohui Xie To: Date: Fri, 18 Mar 2011 14:18:55 +0800 Message-ID: <1300429135-6884-1-git-send-email-b21989@freescale.com> X-Mailer: git-send-email 1.6.4 MIME-Version: 1.0 X-OriginatorOrg: freescale.com Cc: kumar.gala@freescale.com Subject: [U-Boot] [PATCH 2/2] powerpc: make espi can read more than 0xFFFA bytes X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de espi flash read returns invalid data if the read length is more than 0xFFFA bytes, it supports maximum transaction of 2^16 bytes at a time, resister spcom[TRANLEN] is 16 bits. If the transaction length is greater than 0xFFFF, it need to be split into multiple transactions. Signed-off-by: Shaohui Xie Cc: Mike Frysinger --- this patch is rebased on Mike's sf unify patches. drivers/mtd/spi/spi_flash.c | 30 ++++++++++++++++++++++++++++++ drivers/spi/fsl_espi.c | 6 ++++++ include/spi.h | 2 ++ 3 files changed, 38 insertions(+), 0 deletions(-) diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index f745def..f50ca63 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -127,11 +127,41 @@ int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset, { u8 cmd[5]; +#ifndef CONFIG_FSL_ESPI cmd[0] = CMD_READ_ARRAY_FAST; spi_flash_addr(offset, cmd); cmd[4] = 0x00; return spi_flash_read_common(flash, cmd, sizeof(cmd), data, len); +#else + int max_tran_len, num_chunks, tran_len, ret; + + max_tran_len = flash->spi->max_transfer_length; + num_chunks = len / max_tran_len + (len % max_tran_len ? 1 : 0); + + while (num_chunks--) { + tran_len = min(len , max_tran_len); + + cmd[0] = CMD_READ_ARRAY_FAST; + spi_flash_addr(offset, cmd); + cmd[4] = 0x00; + + debug("READ: 0x%x => cmd = + { 0x%02x 0x%02x%02x%02x%02x } tran_len = 0x%x\n", + offset, cmd[0], cmd[1], cmd[2], cmd[3], cmd[4], tran_len); + + ret = spi_flash_read_common( + flash, cmd, sizeof(cmd), data, tran_len); + if (ret < 0) + return ret; + + offset += max_tran_len; + data += max_tran_len; + len -= max_tran_len; + } + + return ret; +#endif } int spi_flash_cmd_poll_bit(struct spi_flash *flash, unsigned long timeout, diff --git a/drivers/spi/fsl_espi.c b/drivers/spi/fsl_espi.c index f4ff884..66ae1a8 100644 --- a/drivers/spi/fsl_espi.c +++ b/drivers/spi/fsl_espi.c @@ -53,6 +53,8 @@ ESPI_CSMODE_CSBEF(0) | ESPI_CSMODE_CSAFT(0) | \ ESPI_CSMODE_CSCG(1)) +#define ESPI_MAX_DATA_TRANSFER_LEN 0xFFF0 + struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, unsigned int max_hz, unsigned int mode) { @@ -72,6 +74,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, slave->bus = bus; slave->cs = cs; + slave->max_transfer_length = ESPI_MAX_DATA_TRANSFER_LEN; /* Enable eSPI interface */ espi->mode = ESPI_MODE_RXTHR(3) | ESPI_MODE_TXTHR(4) | ESPI_MODE_EN; @@ -153,6 +156,9 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *data_out, unsigned char *ch; int num_bytes = len % 4; + if (t->data_len > ESPI_MAX_DATA_TRANSFER_LEN) + return -1; + debug("spi_xfer: slave %u:%u dout %08X(%08x) din %08X(%08x) len %u\n", slave->bus, slave->cs, *(uint *) dout, dout, *(uint *) din, din, len); diff --git a/include/spi.h b/include/spi.h index 423899f..b0e13d5 100644 --- a/include/spi.h +++ b/include/spi.h @@ -77,12 +77,14 @@ struct espi_transfer { * * bus: ID of the bus that the slave is attached to. * cs: ID of the chip select connected to the slave. + * max_txn_length: maximum data transfer length supported by the slave. * transfer: Represent an eSPI transaction. */ struct spi_slave { unsigned int bus; unsigned int cs; + unsigned int max_transfer_length; struct espi_transfer *transfer; };