From patchwork Wed May 24 07:07:01 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: 766335 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 3wXjwr4QB0z9sNp for ; Wed, 24 May 2017 17:01:16 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Up88V2S/"; 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=I89t7rfWZzVauMqPy0ZxvM+avpGiR7Biwi/SJqNCWss=; b=Up88V2S//bdeOz IqpwRL4m3NsfH+/G4jfskE8pHzdNcpdFRXgE6UZ+WhigETC4eusVCvqHqTrUlkqzFE1mDirBNNbGJ /PJoFNf4+UvVJ+VW+vvHpR9v3V6iibiVd0YJg76OGZpUkYG8DkflNGofKoJMDZGikcEg8HoH3M89D DXF+lolg1oYpzGsU9e44McDVEf/Tg8GcDrjmW8I3XPwQrtSfV4NJPlP8IL23xsN+enlLF0QSGBMYX U6YKCDZkYGnSuMQr1gSvYNb8PHCbXzx6VA9njJF6So9k41D6MaLHUuFqcrXMckrgAQ0CQkk11ZqNq 2dzwBoizWCfls747z1xA==; 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 1dDQID-000110-Gq; Wed, 24 May 2017 07:01:13 +0000 Received: from mailout.micron.com ([137.201.242.129]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dDQHe-00009c-FT for linux-mtd@lists.infradead.org; Wed, 24 May 2017 07:00:47 +0000 Received: from mail.micron.com (bowex36h.micron.com [137.201.84.179]) by mailout.micron.com (8.14.4/8.14.6) with ESMTP id v4O70ECX026259; Wed, 24 May 2017 01:00:14 -0600 Received: from SIWEX5A.sing.micron.com (10.160.29.59) by BOWEX36H.micron.com (137.201.84.179) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Wed, 24 May 2017 01:00:13 -0600 Received: from BOWEX36G.micron.com (137.201.84.120) by SIWEX5A.sing.micron.com (10.160.29.59) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Wed, 24 May 2017 15:00:05 +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:01 -0600 From: Peter Pan To: , , , , , , , Subject: [PATCH v6 05/15] mtd: nand: raw: create struct rawnand_device Date: Wed, 24 May 2017 15:07:01 +0800 Message-ID: <1495609631-18880-6-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--5.501700-0.000000-31 X-TM-AS-MatchedID: 105630-708712-704425-860493-705461-121367-188121-702865-7 01927-700057-121119-702791-863432-700648-862883-188019-706290-701384-700200 -824651-700251-703788-700287-702931-702171-707066-700264-709859-188221-7047 74-700901-701143-708804-700398-148004-148036-42000-42003 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_000038_908799_AE5FB832 X-CRM114-Status: GOOD ( 14.82 ) X-Spam-Score: -4.2 (----) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-4.2 points) 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 From: Boris Brezillon Create the rawnand_device struct inheriting from nand_device and make nand_chip inherit from this struct. The rawnand_device object should be used for the new rawnand-device/rawnand-controller model, and fields inside nand_chip should progressively move to the future rawnand_controller or the existing rawnand_device struct. In the meantime, we make sure nand_device fields are properly initialized by converting information stored in mtd_info and nand_chip into the nand_memory_organization format. Signed-off-by: Boris Brezillon Signed-off-by: Peter Pan --- drivers/mtd/nand/raw/nand_base.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/linux/mtd/rawnand.h | 26 ++++++++++++++++++++------ 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index a113cfb..8f8df15 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -3957,6 +3957,43 @@ static bool find_full_id_nand(struct nand_chip *chip, return false; } +static int rawnand_erase(struct nand_device *nand, struct erase_info *einfo) +{ + struct mtd_info *mtd = nand_to_mtd(nand); + + return nand_erase_nand(mtd, einfo, 1); +} + +static int rawnand_markbad(struct nand_device *nand, int block) +{ + struct mtd_info *mtd = nand_to_mtd(nand); + struct nand_chip *chip = mtd_to_nandchip(mtd); + loff_t offs = nand_eraseblock_to_offs(nand, block); + + return chip->block_markbad(mtd, offs); +} + +static const struct nand_ops rawnand_ops = { + .erase = rawnand_erase, + .markbad = rawnand_markbad, +}; + +static void nandc_fill_nandd(struct nand_chip *chip) +{ + struct mtd_info *mtd = nandchip_to_mtd(chip); + struct nand_device *nand = mtd_to_nand(mtd); + struct nand_memory_organization *memorg = &nand->memorg; + + memorg->pagesize = mtd->writesize; + memorg->oobsize = mtd->oobsize; + memorg->eraseblocksize = mtd->erasesize; + memorg->ndies = chip->numchips; + memorg->diesize = chip->chipsize; + /* TODO: fill ->planesize and ->nplanes */ + + nand->ops = &rawnand_ops; +} + /* * Manufacturer detection. Only used when the NAND is not ONFI or JEDEC * compliant and does not have a full-id or legacy-id entry in the nand_ids @@ -4409,6 +4446,9 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips, chip->numchips = i; mtd->size = i * chip->chipsize; + /* Fill nand_device info */ + nandc_fill_nandd(chip); + return 0; } EXPORT_SYMBOL(nand_scan_ident); diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index aa43ec4..750fac2 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -20,6 +20,7 @@ #include #include #include +#include #include struct mtd_info; @@ -727,8 +728,21 @@ struct nand_manufacturer_ops { }; /** + * struct rawnand_device - raw NAND device structure + * @base: NAND device instance (inheritance) + * + * This structure describes a raw NAND device and should progressively + * replace the nand_chip struct. + * + * Note: do not blindly move nand_chip fields into rawnand_device. + */ +struct rawnand_device { + struct nand_device base; +}; + +/** * struct nand_chip - NAND Private Flash Chip Data - * @mtd: MTD device registered to the MTD framework + * @base: raw NAND device instance (inheritance) * @IO_ADDR_R: [BOARDSPECIFIC] address to read the 8 I/O lines of the * flash device * @IO_ADDR_W: [BOARDSPECIFIC] address to write the 8 I/O lines of the @@ -834,7 +848,7 @@ struct nand_manufacturer_ops { */ struct nand_chip { - struct mtd_info mtd; + struct rawnand_device base; void __iomem *IO_ADDR_R; void __iomem *IO_ADDR_W; @@ -930,22 +944,22 @@ struct nand_chip { static inline void nand_set_flash_node(struct nand_chip *chip, struct device_node *np) { - mtd_set_of_node(&chip->mtd, np); + nand_set_of_node(&chip->base.base, np); } static inline struct device_node *nand_get_flash_node(struct nand_chip *chip) { - return mtd_get_of_node(&chip->mtd); + return nand_get_of_node(&chip->base.base); } static inline struct nand_chip *mtd_to_nandchip(struct mtd_info *mtd) { - return container_of(mtd, struct nand_chip, mtd); + return container_of(mtd_to_nand(mtd), struct nand_chip, base.base); } static inline struct mtd_info *nandchip_to_mtd(struct nand_chip *chip) { - return &chip->mtd; + return nand_to_mtd(&chip->base.base); } static inline void *nand_get_controller_data(struct nand_chip *chip)