From patchwork Wed May 24 07:07:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?UGV0ZXIgUGFuIOa9mOagiyAocGV0ZXJwYW5kb25nKQ==?= X-Patchwork-Id: 766344 X-Patchwork-Delegate: boris.brezillon@free-electrons.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wXjz55xBNz9sNp for ; Wed, 24 May 2017 17:03:13 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="t5XBkqjh"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="iZDjHfJS"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=qJcnPkW66FDZP6T0CW85haTOpIyYuVBiI8PTiX44uyc=; b=t5XBkqjhUaw5Mt MgwIVut1LNFxdpC+zjvEU9zzL4OmSB1vXdQwb98zvLekxgKd75TBwTX/GIWr0G3R94E5C5/FvFKSm 4dSQ1PTubfMdskraxkqodQatOVInCLlm5758QEIO8nEyEKzseMN3WqT90IJPweWA1rXpD9smaMj/y Zo8dKMuk6WnBU4cCzT/LMwmbXfxLSFYEqoNw4jJVvuDz5BiVDOhu/OEJWf1FtrU+lruEWrgboGLos 7b7c3bkC1v8WxopD6buoQcpjT4mjNl8CR8JlMjggk7Fr1oRgiYDztPHEFgirda5q/pspXaasrIFkO K3MnThyJhxrtiyebIZoA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dDQK8-00033r-6z; Wed, 24 May 2017 07:03:12 +0000 Received: from casper.infradead.org ([85.118.1.10]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dDQIO-0001F5-Vp for linux-mtd@bombadil.infradead.org; Wed, 24 May 2017 07:01:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=NoZaqNtoGSXdBbvi8ju27TkLaTFoBAlmieEDKaoh/sE=; b=iZDjHfJS3EkHG2F+Zp7s1JW9w I6Ee1b+FxQSbAFzkiaM8C9tSfg5s4q6HHLGCXpM9ij+8ZP1nCPlSuCfi1GYTogNOzBvUuCFLWpwSo gdzWqtW0kCPfjo3fRj+dc1VCzraZSyLunRRVASI+DGEP6x494TrqWLTT7MTd3w5YJOhVKnAslws/Z TDBeIyRtG/PbUBptLZlsgZlXKWwymmTxmRA798l5ZASGuMlpKTXYSBiX/U07hN13pF1i0V8CumeM3 XexpCCDrYXVxmO0bIeEZap5crAK7eqT/FvR5GQ10ps6kRvbjYnH493bvUNdOL74PuO10H/8TdQUFf Qf4Ep7dFQ==; Received: from mailout.micron.com ([137.201.242.129]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dDQIG-0004zO-Ag for linux-mtd@lists.infradead.org; Wed, 24 May 2017 07:01:23 +0000 Received: from mail.micron.com (bowex17c.micron.com [137.201.21.211]) by mailout.micron.com (8.14.4/8.14.6) with ESMTP id v4O70f7O027658; Wed, 24 May 2017 01:00:41 -0600 Received: from SIWEX4H.sing.micron.com (10.160.29.19) by bowex17c.micron.com (137.201.21.211) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Wed, 24 May 2017 01:00:40 -0600 Received: from BOWEX36G.micron.com (137.201.84.120) by SIWEX4H.sing.micron.com (10.160.29.19) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Wed, 24 May 2017 15:00:37 +0800 Received: from peterpan-Linux-Desktop.micron.com (10.66.12.56) by BOWEX36G.micron.com (137.201.84.120) with Microsoft SMTP Server id 15.0.1263.5 via Frontend Transport; Wed, 24 May 2017 01:00:34 -0600 From: Peter Pan To: , , , , , , , Subject: [PATCH v6 13/15] nand: spi: add Micron spi nand support Date: Wed, 24 May 2017 15:07:09 +0800 Message-ID: <1495609631-18880-14-git-send-email-peterpandong@micron.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1495609631-18880-1-git-send-email-peterpandong@micron.com> References: <1495609631-18880-1-git-send-email-peterpandong@micron.com> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-12.0.0.1464-8.100.1062-23088.005 X-TM-AS-Result: No-0.824200-0.000000-31 X-TM-AS-MatchedID: 704421-863432-700648-862883-700270-703529-188019-706290-7 02171-708712-700251-704425-700324-702796-113670-703786-703352-711219-702020 -705102-702067-703275-703468-114012-703523-700057-700264-703399-704473-7037 12-847298-702474-705753-704713-702609-705901-702919-704568-121119-188199-70 1384-121367-300010-705178-702098-148004-148036-42000-42003-52000 X-TM-AS-User-Approved-Sender: Yes X-TM-AS-User-Blocked-Sender: No X-MT-CheckInternalSenderRule: True X-Scanned-By: MIMEDefang 2.78 on 137.201.130.65 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170524_080116_874053_1E3F2C8F X-CRM114-Status: GOOD ( 22.85 ) X-Spam-Score: -4.2 (----) X-Spam-Report: SpamAssassin version 3.4.1 on casper.infradead.org summary: Content analysis details: (-4.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [137.201.242.129 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peterpansjtu@gmail.com, linshunquan1@hisilicon.com, peterpandong@micron.com Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This commit is to add support for Micron MT29F2G01ABAGD spi nand chip. Signed-off-by: Peter Pan --- drivers/mtd/nand/spi/Makefile | 1 + drivers/mtd/nand/spi/core.c | 4 +- drivers/mtd/nand/spi/micron.c | 157 ++++++++++++++++++++++++++++++++++++++++++ include/linux/mtd/spinand.h | 2 + 4 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 drivers/mtd/nand/spi/micron.c diff --git a/drivers/mtd/nand/spi/Makefile b/drivers/mtd/nand/spi/Makefile index a677a4d..df6c2ea 100644 --- a/drivers/mtd/nand/spi/Makefile +++ b/drivers/mtd/nand/spi/Makefile @@ -1 +1,2 @@ obj-$(CONFIG_MTD_SPI_NAND) += core.o +obj-$(CONFIG_MTD_SPI_NAND) += micron.o diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c index 345d04f..05610c6 100644 --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c @@ -1129,7 +1129,9 @@ static int spinand_scan_bbt(struct spinand_device *spinand) return nand_scan_bbt(nand); } -static const struct spinand_manufacturer *spinand_manufacturers[] = {}; +static const struct spinand_manufacturer *spinand_manufacturers[] = { + µn_spinand_manufacturer +}; /** * spinand_manufacturer_detect - detect SPI NAND device by each manufacturer diff --git a/drivers/mtd/nand/spi/micron.c b/drivers/mtd/nand/spi/micron.c new file mode 100644 index 0000000..43784db --- /dev/null +++ b/drivers/mtd/nand/spi/micron.c @@ -0,0 +1,157 @@ +/* + * + * Copyright (c) 2016-2017 Micron Technology, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include + +#define SPINAND_MFR_MICRON 0x2C + +struct micron_spinand_info { + char *name; + u8 dev_id; + u32 page_size; + u32 oob_size; + u32 pages_per_blk; + u32 blks_per_lun; + u32 luns_per_chip; + u32 ecc_strength; + u32 ecc_steps; + u32 rw_mode; +}; + +#define MICRON_SPI_NAND_INFO(nm, did, pagesz, oobsz, pg_per_blk, \ + blk_per_lun, lun_per_chip, ecc_stren, \ + ecc_stps, rwmode) \ + { \ + .name = (nm), \ + .dev_id = (did), \ + .page_size = (pagesz), \ + .oob_size = (oobsz), \ + .pages_per_blk = (pg_per_blk), \ + .blks_per_lun = (blk_per_lun), \ + .luns_per_chip = (lun_per_chip),\ + .ecc_strength = (ecc_stren), \ + .ecc_steps = (ecc_stps), \ + .rw_mode = (rwmode) \ + } + +static const struct micron_spinand_info micron_spinand_table[] = { + MICRON_SPI_NAND_INFO("MT29F2G01ABAGD", 0x24, 2048, 128, 64, 2048, 1, + 8, 512, SPINAND_OP_COMMON), +}; + +static int micron_spinand_get_dummy(struct spinand_device *spinand, + struct spinand_op *op) +{ + u8 opcode = op->cmd; + + switch (opcode) { + case SPINAND_CMD_READ_FROM_CACHE: + case SPINAND_CMD_READ_FROM_CACHE_FAST: + case SPINAND_CMD_READ_FROM_CACHE_X2: + case SPINAND_CMD_READ_FROM_CACHE_DUAL_IO: + case SPINAND_CMD_READ_FROM_CACHE_X4: + case SPINAND_CMD_READ_ID: + return 1; + + case SPINAND_CMD_READ_FROM_CACHE_QUAD_IO: + return 2; + + default: + return 0; + } +} + +/** + * micron_spinand_scan_id_table - scan SPI NAND info in id table + * @spinand: SPI NAND device structure + * @id: point to manufacture id and device id + * Description: + * If found in id table, config device with table information. + */ +static bool micron_spinand_scan_id_table(struct spinand_device *spinand, + u8 dev_id) +{ + struct mtd_info *mtd = spinand_to_mtd(spinand); + struct nand_device *nand = mtd_to_nand(mtd); + struct micron_spinand_info *item = NULL; + struct nand_memory_organization *memorg = &nand->memorg; + int i = 0; + + for (; i < ARRAY_SIZE(micron_spinand_table); i++) { + item = (struct micron_spinand_info *)micron_spinand_table + i; + if (dev_id != item->dev_id) + continue; + + spinand->name = item->name; + memorg->eraseblocksize = item->page_size * item->pages_per_blk; + memorg->pagesize = item->page_size; + memorg->oobsize = item->oob_size; + memorg->diesize = memorg->eraseblocksize * item->blks_per_lun; + memorg->ndies = item->luns_per_chip; + spinand->rw_mode = item->rw_mode; + + return true; + } + + return false; +} + +/** + * micron_spinand_detect - initialize device related part in spinand_device + * struct if it is Micron device. + * @spinand: SPI NAND device structure + */ +static bool micron_spinand_detect(struct spinand_device *spinand) +{ + u8 *id = spinand->id.data; + + /* + * Micron SPI NAND read ID need a dummy byte, + * so the first byte in raw_id is dummy. + */ + if (id[1] != SPINAND_MFR_MICRON) + return false; + + return micron_spinand_scan_id_table(spinand, id[2]); +} + +/** + * micron_spinand_prepare_op - Fix address for cache operation. + * @spinand: SPI NAND device structure + * @op: pointer to spinand_op struct + * @page: page address + * @column: column address + */ +static void micron_spinand_prepare_op(struct spinand_device *spinand, + struct spinand_op *op, u32 page, + u32 column) +{ + op->addr[0] |= (u8)((nand_page_to_eraseblock(&spinand->base, page) + & 0x1) << 4); + op->n_addr += micron_spinand_get_dummy(spinand, op); +} + +static const struct spinand_manufacturer_ops micron_spinand_manuf_ops = { + .detect = micron_spinand_detect, + .prepare_op = micron_spinand_prepare_op, +}; + +const struct spinand_manufacturer micron_spinand_manufacturer = { + .id = SPINAND_MFR_MICRON, + .name = "Micron", + .ops = µn_spinand_manuf_ops, +}; diff --git a/include/linux/mtd/spinand.h b/include/linux/mtd/spinand.h index 04ad1dd..8ef2c69 100644 --- a/include/linux/mtd/spinand.h +++ b/include/linux/mtd/spinand.h @@ -125,6 +125,8 @@ struct spinand_manufacturer { const struct spinand_manufacturer_ops *ops; }; +extern const struct spinand_manufacturer micron_spinand_manufacturer; + #define SPINAND_CAP_RD_X1 BIT(0) #define SPINAND_CAP_RD_X2 BIT(1) #define SPINAND_CAP_RD_X4 BIT(2)