From patchwork Thu Sep 27 11:55:45 2012 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: 187334 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (unknown [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B1E712C00D0 for ; Thu, 27 Sep 2012 21:57:23 +1000 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1THChY-0008E6-0H; Thu, 27 Sep 2012 11:56:20 +0000 Received: from mail-wi0-f177.google.com ([209.85.212.177]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1THChG-0008AU-CP for linux-mtd@lists.infradead.org; Thu, 27 Sep 2012 11:56:04 +0000 Received: by mail-wi0-f177.google.com with SMTP id hj13so103484wib.0 for ; Thu, 27 Sep 2012 04:56:02 -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:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=KwApXnJUcMIaCimWMI+EKv0bRUhX1HhA5oP7pGNMSWE=; b=G2p4D9IQ/S276X1gybvu0a97zEL/PNa8OX7tiVrf5gpSoq1BfSPXzHljik6ZpcJ8ZF g1lIY7aZFPLM5RmqnrnZwStWi2gs51B+5A7YB1qaIbhJhjPaG1XdO0TtYdKeDENyS2iJ Otz43XzfqeX4YZDx23VT6TLiIH3i4V03YRyKH852nLm08eFZahOZ4Wy7//AVYR2YMXfO MRLiUfFIqRkSU1I+lH5KXkxs8ETL0UlOO7xybo+0/sZAsiTBqb7DszaWMKOUyhzGGygI +bT2KDNnyQCYIW5sleKmNhRrwdnN4G67INTzYEfnqSjCM3z0dFPnxEoZ2kcj4F5iGGcJ Lduw== Received: by 10.180.108.45 with SMTP id hh13mr36226029wib.15.1348746962076; Thu, 27 Sep 2012 04:56:02 -0700 (PDT) Received: from localhost.localdomain (gw.bas.roche.com. [196.3.50.254]) by mx.google.com with ESMTPS id cn6sm3591360wib.9.2012.09.27.04.56.00 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 27 Sep 2012 04:56:01 -0700 (PDT) From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= To: linux-mtd@lists.infradead.org, Artem Bityutskiy Subject: [PATCH 4/6] mtd: bcm47xxnflash: support for NAND_CMD_READID command Date: Thu, 27 Sep 2012 13:55:45 +0200 Message-Id: <1348746947-2349-4-git-send-email-zajec5@gmail.com> X-Mailer: git-send-email 1.7.7 In-Reply-To: <1348746947-2349-1-git-send-email-zajec5@gmail.com> References: <1348746947-2349-1-git-send-email-zajec5@gmail.com> MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.212.177 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (zajec5[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (zajec5[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Signed-off-by: Rafał Miłecki --- 0004-mtd-bcm47xxnflash-support-for-NAND_CMD_READID-comman.patch Successfully built configuration "mips-bcm47xx_defconfig,mips,mips-linux-", no issues WARNING:LONG_LINE: line over 80 characters #120: FILE: drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c:106: + b47n->id_data[i] = bcma_cc_read32(b47n->cc, BCMA_CC_NFLASH_DATA) & 0xFF; I avoid lines over 80 chars, but in this single case I left it to make it easier to read the code (don't like having that code in 3 lines) --- drivers/mtd/nand/bcm47xxnflash/bcm47xxnflash.h | 5 + drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c | 99 ++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 0 deletions(-) diff --git a/drivers/mtd/nand/bcm47xxnflash/bcm47xxnflash.h b/drivers/mtd/nand/bcm47xxnflash/bcm47xxnflash.h index 2e8864a..cc71400 100644 --- a/drivers/mtd/nand/bcm47xxnflash/bcm47xxnflash.h +++ b/drivers/mtd/nand/bcm47xxnflash/bcm47xxnflash.h @@ -9,6 +9,11 @@ struct bcm47xxnflash { struct nand_chip nand_chip; struct mtd_info mtd; + + unsigned curr_command; + int curr_column; + + u8 id_data[8]; }; #endif /* BCM47XXNFLASH */ diff --git a/drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c b/drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c index 2f0ad1d..9ca6882 100644 --- a/drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c +++ b/drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c @@ -16,6 +16,10 @@ #include "bcm47xxnflash.h" +/* Broadcom uses 1'000'000 but it seems to be too many. Tests on WNDR4500 has + * shown 164 retries as maxiumum. */ +#define NFLASH_READY_RETRIES 1000 + /************************************************** * Various helpers **************************************************/ @@ -25,6 +29,24 @@ static inline u8 bcm47xxnflash_ops_bcm4706_ns_to_cycle(u16 ns, u16 clock) return ((ns * 1000 * clock) / 1000000) + 1; } +static int bcm47xxnflash_ops_bcm4706_ctl_cmd(struct bcma_drv_cc *cc, u32 code) +{ + int i = 0; + + bcma_cc_write32(cc, BCMA_CC_NFLASH_CTL, 0x80000000 | code); + for (i = 0; i < NFLASH_READY_RETRIES; i++) { + if (!(bcma_cc_read32(cc, BCMA_CC_NFLASH_CTL) & 0x80000000)) { + i = 0; + break; + } + } + if (i) { + pr_err("NFLASH control command not ready!\n"); + return -EBUSY; + } + return 0; +} + /************************************************** * NAND chip ops **************************************************/ @@ -36,6 +58,81 @@ static void bcm47xxnflash_ops_bcm4706_select_chip(struct mtd_info *mtd, return; } +/* + * Default nand_command and nand_command_lp don't match BCM4706 hardware layout. + * For example, reading chip id is performed in a non-standard way. + * Setting column and page is also handled differently, we use a special + * registers of ChipCommon core. Hacking cmd_ctrl to understand and convert + * standard commands would be much more complicated. + */ +static void bcm47xxnflash_ops_bcm4706_cmdfunc(struct mtd_info *mtd, + unsigned command, int column, + int page_addr) +{ + struct nand_chip *nand_chip = (struct nand_chip *)mtd->priv; + struct bcm47xxnflash *b47n = (struct bcm47xxnflash *)nand_chip->priv; + u32 ctlcode; + int i; + + if (column != -1) + b47n->curr_column = column; + + switch (command) { + case NAND_CMD_RESET: + pr_warn("Chip reset not implemented yet\n"); + break; + case NAND_CMD_READID: + ctlcode = 0x40000000 | 0x01000000 | 0x00080000 | 0x00010000; + ctlcode |= NAND_CMD_READID; + if (bcm47xxnflash_ops_bcm4706_ctl_cmd(b47n->cc, ctlcode)) { + pr_err("READID error\n"); + break; + } + + /* + * Reading is specific, last one has to go without 0x40000000 + * bit. We don't know how many reads NAND subsystem is going + * to perform, so cache everything. + */ + for (i = 0; i < ARRAY_SIZE(b47n->id_data); i++) { + ctlcode = 0x40000000 | 0x00100000; + if (i == ARRAY_SIZE(b47n->id_data) - 1) + ctlcode &= ~0x40000000; + if (bcm47xxnflash_ops_bcm4706_ctl_cmd(b47n->cc, + ctlcode)) { + pr_err("READID error\n"); + break; + } + b47n->id_data[i] = bcma_cc_read32(b47n->cc, BCMA_CC_NFLASH_DATA) & 0xFF; + } + + break; + default: + pr_err("Command 0x%X unsupported\n", command); + break; + } + b47n->curr_command = command; +} + +static u8 bcm47xxnflash_ops_bcm4706_read_byte(struct mtd_info *mtd) +{ + struct nand_chip *nand_chip = (struct nand_chip *)mtd->priv; + struct bcm47xxnflash *b47n = (struct bcm47xxnflash *)nand_chip->priv; + + switch (b47n->curr_command) { + case NAND_CMD_READID: + if (b47n->curr_column >= ARRAY_SIZE(b47n->id_data)) { + pr_err("Requested invalid id_data: %d\n", + b47n->curr_column); + return 0; + } + return b47n->id_data[b47n->curr_column++]; + } + + pr_err("Invalid command for byte read: 0x%X\n", b47n->curr_command); + return 0; +} + /************************************************** * Init **************************************************/ @@ -53,6 +150,8 @@ int bcm47xxnflash_ops_bcm4706_init(struct bcm47xxnflash *b47n) u32 val; b47n->nand_chip.select_chip = bcm47xxnflash_ops_bcm4706_select_chip; + b47n->nand_chip.cmdfunc = bcm47xxnflash_ops_bcm4706_cmdfunc; + b47n->nand_chip.read_byte = bcm47xxnflash_ops_bcm4706_read_byte; b47n->nand_chip.ecc.mode = NAND_ECC_NONE; /* TODO: implement ECC */ /* Enable NAND flash access */