From patchwork Tue Aug 17 12:30:16 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haojian Zhuang X-Patchwork-Id: 61889 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0FDCAB6EFF for ; Tue, 17 Aug 2010 22:31:39 +1000 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.72 #1 (Red Hat Linux)) id 1OlLJR-0002h7-0S; Tue, 17 Aug 2010 12:30:41 +0000 Received: from mail-wy0-f177.google.com ([74.125.82.177]) by bombadil.infradead.org with esmtp (Exim 4.72 #1 (Red Hat Linux)) id 1OlLJK-0002Zf-GE; Tue, 17 Aug 2010 12:30:37 +0000 Received: by wyb34 with SMTP id 34so7926862wyb.36 for ; Tue, 17 Aug 2010 05:30:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=4lp5lWfOLdE0x4CDiGEGdzLXi20IZIWXDiKO5x+qg5I=; b=ItT0CXnrYRNdzlBCmn3MaK8k6nH3opxILLG9EEspA/GRMOkzC4i3FVQJncKUZX22Vl 7RMBWxVkguo76POG9W8AzFWPTAzd0jo6EdPJPhj87TWjOl3gE0iPUfuJQ7cgHV793WXk ts9Tbj7zm/hLyM4p0MDGL3dSBlSXODVS+wsc4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=n6Kctsk4gouFCX/k5zbQ6V10mcgq7umsYhImgOH6D9r0QMLVM09NglGQ1qtWG03mm9 dEjQFMrM/MuSlxt4cger8Il74TsKpUy8cXiV5o5VokafaJZm2Cx2CoDZwkicXPB0SWns Qr1w/XhMCM69gvTnZ1xJypy0hx78upk0DiS6w= MIME-Version: 1.0 Received: by 10.216.185.4 with SMTP id t4mr5619568wem.87.1282048216335; Tue, 17 Aug 2010 05:30:16 -0700 (PDT) Received: by 10.216.46.73 with HTTP; Tue, 17 Aug 2010 05:30:16 -0700 (PDT) Date: Tue, 17 Aug 2010 20:30:16 +0800 Message-ID: Subject: [PATCH 06/06] pxa3xx_nand: set oob length in the runtime From: Haojian Zhuang To: Eric Miao , David Woodhouse , linux-mtd@lists.infradead.org, linux-arm-kernel X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20100817_083036_728304_5F17502B X-CRM114-Status: GOOD ( 19.06 ) X-Spam-Score: -0.1 (/) X-Spam-Report: SpamAssassin version 3.3.1 on bombadil.infradead.org summary: Content analysis details: (-0.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is freemail (haojian.zhuang[at]gmail.com) -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 X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 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 From 1054e6ca4f60139af1915f5d41d6e9887052862e Mon Sep 17 00:00:00 2001 From: Lei Wen Date: Tue, 17 Aug 2010 14:09:30 +0800 Subject: [PATCH 06/06] pxa3xx_nand: set oob length in the runtime For different command need different oob requirement, set the proper oob length by different cmd. Signed-off-by: Lei Wen --- drivers/mtd/nand/pxa3xx_nand.c | 25 ++++++++++++++++++------- 1 files changed, 18 insertions(+), 7 deletions(-) } @@ -333,6 +340,7 @@ static int prepare_other_cmd(struct pxa3xx_nand_info *info, uint16_t cmd) info->ndcb1 = 0; info->ndcb2 = 0; + info->oob_size = 0; if (cmd == cmdset->read_id) { info->ndcb0 |= NDCB0_CMD_TYPE(3); info->data_size = 8; @@ -401,6 +409,9 @@ static int handle_data_pio(struct pxa3xx_nand_info *info) case STATE_PIO_WRITING: __raw_writesl(info->mmio_base + NDDB, info->data_buff, DIV_ROUND_UP(info->data_size, 4)); + if (info->oob_size > 0) + __raw_writesl(info->mmio_base + NDDB, info->oob_buff, + DIV_ROUND_UP(info->oob_size, 4)); enable_int(info, NDSR_CS0_BBD | NDSR_CS0_CMDD); @@ -413,6 +424,9 @@ static int handle_data_pio(struct pxa3xx_nand_info *info) case STATE_PIO_READING: __raw_readsl(info->mmio_base + NDDB, info->data_buff, DIV_ROUND_UP(info->data_size, 4)); + if (info->oob_size > 0) + __raw_readsl(info->mmio_base + NDDB, info->oob_buff, + DIV_ROUND_UP(info->oob_size, 4)); break; default: printk(KERN_ERR "%s: invalid state %d\n", __func__, @@ -427,7 +441,7 @@ static int handle_data_pio(struct pxa3xx_nand_info *info) static void start_data_dma(struct pxa3xx_nand_info *info, int dir_out) { struct pxa_dma_desc *desc = info->data_desc; - int dma_len = ALIGN(info->data_size, 32); + int dma_len = ALIGN(info->data_size + info->oob_size, 32); desc->ddadr = DDADR_STOP; desc->dcmd = DCMD_ENDIRQEN | DCMD_WIDTH4 | DCMD_BURST32 | dma_len; @@ -833,7 +847,6 @@ static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info, info->cmdset = f->cmdset; info->page_size = f->page_size; info->oob_buff = info->data_buff + f->page_size; - info->oob_size = (f->page_size == 2048) ? 64 : 16; info->read_id_bytes = (f->page_size == 2048) ? 4 : 2; /* calculate addressing information */ @@ -892,8 +905,6 @@ static int pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info) i = __ffs(page_per_block * info->page_size); num_blocks = type->chipsize << (20 - i); - info->oob_size = (info->page_size == 2048) ? 64 : 16; - /* calculate addressing information */ info->col_addr_cycles = (info->page_size == 2048) ? 2 : 1; From 1054e6ca4f60139af1915f5d41d6e9887052862e Mon Sep 17 00:00:00 2001 From: Lei Wen Date: Tue, 17 Aug 2010 14:09:30 +0800 Subject: [PATCH 06/12] pxa3xx_nand: set oob length in the runtime For different command need different oob requirement, set the proper oob length by different cmd. Signed-off-by: Lei Wen --- drivers/mtd/nand/pxa3xx_nand.c | 25 ++++++++++++++++++------- 1 files changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c index 27ed63f..70f2be0 100644 --- a/drivers/mtd/nand/pxa3xx_nand.c +++ b/drivers/mtd/nand/pxa3xx_nand.c @@ -273,13 +273,20 @@ static int wait_for_event(struct pxa3xx_nand_info *info, uint32_t event) static void pxa3xx_set_datasize(struct pxa3xx_nand_info *info) { - /* calculate data size */ + int oob_enable = info->reg_ndcr & NDCR_SPARE_EN; + + info->data_size = info->page_size; + if (!oob_enable) { + info->oob_size = 0; + return; + } + switch (info->page_size) { case 2048: - info->data_size = (info->use_ecc) ? 2088 : 2112; + info->oob_size = (info->use_ecc) ? 40 : 64; break; case 512: - info->data_size = (info->use_ecc) ? 520 : 528; + info->oob_size = (info->use_ecc) ? 8 : 16; break; } } @@ -333,6 +340,7 @@ static int prepare_other_cmd(struct pxa3xx_nand_info *info, uint16_t cmd) info->ndcb1 = 0; info->ndcb2 = 0; + info->oob_size = 0; if (cmd == cmdset->read_id) { info->ndcb0 |= NDCB0_CMD_TYPE(3); info->data_size = 8; @@ -401,6 +409,9 @@ static int handle_data_pio(struct pxa3xx_nand_info *info) case STATE_PIO_WRITING: __raw_writesl(info->mmio_base + NDDB, info->data_buff, DIV_ROUND_UP(info->data_size, 4)); + if (info->oob_size > 0) + __raw_writesl(info->mmio_base + NDDB, info->oob_buff, + DIV_ROUND_UP(info->oob_size, 4)); enable_int(info, NDSR_CS0_BBD | NDSR_CS0_CMDD); @@ -413,6 +424,9 @@ static int handle_data_pio(struct pxa3xx_nand_info *info) case STATE_PIO_READING: __raw_readsl(info->mmio_base + NDDB, info->data_buff, DIV_ROUND_UP(info->data_size, 4)); + if (info->oob_size > 0) + __raw_readsl(info->mmio_base + NDDB, info->oob_buff, + DIV_ROUND_UP(info->oob_size, 4)); break; default: printk(KERN_ERR "%s: invalid state %d\n", __func__, @@ -427,7 +441,7 @@ static int handle_data_pio(struct pxa3xx_nand_info *info) static void start_data_dma(struct pxa3xx_nand_info *info, int dir_out) { struct pxa_dma_desc *desc = info->data_desc; - int dma_len = ALIGN(info->data_size, 32); + int dma_len = ALIGN(info->data_size + info->oob_size, 32); desc->ddadr = DDADR_STOP; desc->dcmd = DCMD_ENDIRQEN | DCMD_WIDTH4 | DCMD_BURST32 | dma_len; @@ -833,7 +847,6 @@ static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info, info->cmdset = f->cmdset; info->page_size = f->page_size; info->oob_buff = info->data_buff + f->page_size; - info->oob_size = (f->page_size == 2048) ? 64 : 16; info->read_id_bytes = (f->page_size == 2048) ? 4 : 2; /* calculate addressing information */ @@ -892,8 +905,6 @@ static int pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info) i = __ffs(page_per_block * info->page_size); num_blocks = type->chipsize << (20 - i); - info->oob_size = (info->page_size == 2048) ? 64 : 16; - /* calculate addressing information */ info->col_addr_cycles = (info->page_size == 2048) ? 2 : 1; -- 1.7.0.4