From patchwork Mon Jul 9 18:53:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Kshevetskiy X-Patchwork-Id: 169933 X-Patchwork-Delegate: jagannadh.teki@gmail.com 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 5A38D2C0083 for ; Tue, 10 Jul 2012 05:22:59 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 861A22813A; Mon, 9 Jul 2012 21:22:45 +0200 (CEST) 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 5P5kb38r4LOL; Mon, 9 Jul 2012 21:22:45 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 831712813C; Mon, 9 Jul 2012 21:22:23 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EDEBD28125 for ; Mon, 9 Jul 2012 20:53:31 +0200 (CEST) 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 F9SFlCBuGixJ for ; Mon, 9 Jul 2012 20:53:30 +0200 (CEST) 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 mail-lb0-f172.google.com (mail-lb0-f172.google.com [209.85.217.172]) by theia.denx.de (Postfix) with ESMTPS id 7701A28113 for ; Mon, 9 Jul 2012 20:53:27 +0200 (CEST) Received: by lbbgo11 with SMTP id go11so16086579lbb.3 for ; Mon, 09 Jul 2012 11:53:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=pH0joEdxYzIIp5ozfV/mw606AdOuKll0RqSSGgumnEU=; b=vrgn0rj3I8BALV76WRc1gxpi2+Xk872YXwzrFPkqlrBuRNicecqDyEHN1qBPNT4TzF gb/Ysgd4BZUK2LD/aKRy1xOaa2YLrl1YwRhPzHOekQVnmpfHZNR/1FIEqQglyqtkTJ99 KCPvdQrGIv4Px8aVQR09++IaqcInnXOODHvHfUPgYPW/kcWrW7r2s4H44LvZMIgxMBZY PC4sXEFPQ5XhLn4+ry8+4tGafSROAwWb77RwfLr1kOnCqO3g72NL2So9pXondY07u+sw FuxI8zkv63l+9kEpURSzgQ4yDll1lT0lg3wItnxwL8DLezMZncwltrikF9rIdSh14IVl gsRw== Received: by 10.152.108.144 with SMTP id hk16mr41573725lab.2.1341860007446; Mon, 09 Jul 2012 11:53:27 -0700 (PDT) Received: from weasel.lan ([217.71.235.199]) by mx.google.com with ESMTPS id h9sm16781858lbi.9.2012.07.09.11.53.26 (version=SSLv3 cipher=OTHER); Mon, 09 Jul 2012 11:53:26 -0700 (PDT) From: Mikhail Kshevetskiy To: u-boot@lists.denx.de Date: Mon, 9 Jul 2012 22:53:20 +0400 Message-Id: <1341860001-11466-1-git-send-email-mikhail.kshevetskiy@gmail.com> X-Mailer: git-send-email 1.7.10.4 X-Mailman-Approved-At: Mon, 09 Jul 2012 21:22:17 +0200 Cc: Tom Rini , Christian Riesch Subject: [U-Boot] [PATCH V3 1/2] mtd/spi/spi_flash: support CMD_READ_ID=0x90 case X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de current code does not support spi flashes that have 0x90 read_id command, so fix this Signed-off-by: Mikhail Kshevetskiy --- Change for v3: * split SPI flash fixes to separate patch series (series 2/3) Change for v2: * fix checkpatch warnings --- drivers/mtd/spi/spi_flash.c | 66 +++++++++++++++++++++++----------- drivers/mtd/spi/spi_flash_internal.h | 1 + 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index f689cc4..530b7b3 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -306,13 +306,44 @@ static const struct { }; #define IDCODE_LEN (IDCODE_CONT_LEN + IDCODE_PART_LEN) +struct spi_flash *spi_analize_flash_probe(struct spi_slave *spi, + u8 *idcode, size_t idcode_len, u8 *id) +{ + struct spi_flash *flash = NULL; + int i, shift; + u8 *idp; + +#ifdef DEBUG + printf("SF: Got idcodes\n"); + print_buffer(0, idcode, 1, idcode_len, 0); +#endif + + /* count the number of continuation bytes */ + for (shift = 0, idp = idcode; + shift < idcode_len && *idp == 0x7f; + ++shift, ++idp) + continue; + + *id = *idp; + /* search the table for matches in shift and id */ + for (i = 0; i < ARRAY_SIZE(flashes); ++i) + if (flashes[i].shift == shift && flashes[i].idcode == *idp) { + /* we have a match, call probe */ + flash = flashes[i].probe(spi, idp); + if (flash) + break; + } + + return flash; +} + struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs, unsigned int max_hz, unsigned int spi_mode) { struct spi_slave *spi; struct spi_flash *flash = NULL; - int ret, i, shift; - u8 idcode[IDCODE_LEN], *idp; + u8 cmd[4], idcode[IDCODE_LEN], id; + int ret; spi = spi_setup_slave(bus, cs, max_hz, spi_mode); if (!spi) { @@ -331,28 +362,23 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs, if (ret) goto err_read_id; -#ifdef DEBUG - printf("SF: Got idcodes\n"); - print_buffer(0, idcode, 1, sizeof(idcode), 0); -#endif + flash = spi_analize_flash_probe(spi, idcode, sizeof(idcode), &id); + if (id == 0xff) { + /* try CMD_READ_ID_NEW command */ + cmd[0] = CMD_READ_ID_NEW; + spi_flash_addr(0x000000, cmd); - /* count the number of continuation bytes */ - for (shift = 0, idp = idcode; - shift < IDCODE_CONT_LEN && *idp == 0x7f; - ++shift, ++idp) - continue; + ret = spi_flash_cmd_read(spi, cmd, sizeof(cmd), + idcode, sizeof(idcode)); + if (ret) + goto err_read_id; - /* search the table for matches in shift and id */ - for (i = 0; i < ARRAY_SIZE(flashes); ++i) - if (flashes[i].shift == shift && flashes[i].idcode == *idp) { - /* we have a match, call probe */ - flash = flashes[i].probe(spi, idp); - if (flash) - break; - } + flash = spi_analize_flash_probe(spi, + idcode, sizeof(idcode), &id); + } if (!flash) { - printf("SF: Unsupported manufacturer %02x\n", *idp); + printf("SF: Unsupported manufacturer %02x\n", id); goto err_manufacturer_probe; } diff --git a/drivers/mtd/spi/spi_flash_internal.h b/drivers/mtd/spi/spi_flash_internal.h index 91e036a..b8bd5d5 100644 --- a/drivers/mtd/spi/spi_flash_internal.h +++ b/drivers/mtd/spi/spi_flash_internal.h @@ -14,6 +14,7 @@ /* Common commands */ #define CMD_READ_ID 0x9f +#define CMD_READ_ID_NEW 0x90 #define CMD_READ_ARRAY_SLOW 0x03 #define CMD_READ_ARRAY_FAST 0x0b