From patchwork Mon May 23 09:22:43 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jamie Iles X-Patchwork-Id: 96848 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 CD84CB6FC4 for ; Mon, 23 May 2011 19:25:52 +1000 (EST) Received: from canuck.infradead.org ([2001:4978:20e::1]) by bombadil.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QORN4-0002oW-Ks; Mon, 23 May 2011 09:24:18 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QORN2-0002WZ-OT; Mon, 23 May 2011 09:24:16 +0000 Received: from mail-ww0-f49.google.com ([74.125.82.49]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QORMl-0002Tm-K3 for linux-mtd@lists.infradead.org; Mon, 23 May 2011 09:24:01 +0000 Received: by wwb39 with SMTP id 39so4359562wwb.18 for ; Mon, 23 May 2011 02:23:57 -0700 (PDT) Received: by 10.227.199.80 with SMTP id er16mr1953156wbb.78.1306142637435; Mon, 23 May 2011 02:23:57 -0700 (PDT) Received: from localhost (gw-ba1.picochip.com [94.175.234.108]) by mx.google.com with ESMTPS id o23sm3957533wbc.10.2011.05.23.02.23.56 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 23 May 2011 02:23:56 -0700 (PDT) From: Jamie Iles To: linux-mtd@lists.infradead.org Subject: [PATCH 02/62] mtd: introduce mtd_device_(un)register() Date: Mon, 23 May 2011 10:22:43 +0100 Message-Id: <1306142623-24952-3-git-send-email-jamie@jamieiles.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1306142623-24952-1-git-send-email-jamie@jamieiles.com> References: <1306142623-24952-1-git-send-email-jamie@jamieiles.com> X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110523_052359_930075_AD1D77FA X-CRM114-Status: GOOD ( 20.74 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.49 listed in list.dnswl.org] Cc: Jamie Iles , dwmw2@infradead.org, dedekind1@gmail.com 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: , MIME-Version: 1.0 Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org To prepare for the removal of add_mtd_device and add_mtd_partitions(), introduce mtd_device_register(). This will create partitions if they are supplied or register the whole device if there are no partitions. Once all drivers are converted to use mtd_device_register(), add_mtd_device() and add_mtd_partitions() will be made internal only. Cc: David Woodhouse Cc: Artem Bityutskiy Signed-off-by: Jamie Iles --- drivers/mtd/mtdcore.c | 25 +++++++++++++++++++++++++ include/linux/mtd/mtd.h | 28 ++++++++++++++++++++++++++++ include/linux/mtd/partitions.h | 2 +- 3 files changed, 54 insertions(+), 1 deletions(-) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index da69bc8..6af7ad9 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -37,6 +37,7 @@ #include #include +#include #include "mtdcore.h" /* @@ -426,6 +427,30 @@ out_error: return ret; } +int mtd_device_register(struct mtd_info *master, + const struct mtd_partition *parts, + int nr_parts) +{ + return parts ? add_mtd_partitions(master, parts, nr_parts) : + add_mtd_device(master); +} +EXPORT_SYMBOL_GPL(mtd_device_register); + +int mtd_device_unregister(struct mtd_info *master) +{ + int err; + + err = del_mtd_partitions(master); + if (err) + return err; + + if (!device_is_registered(&master->dev)) + return 0; + + return del_mtd_device(master); +} +EXPORT_SYMBOL_GPL(mtd_device_unregister); + /** * register_mtd_user - register a 'user' of MTD devices. * @new: pointer to notifier info structure diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 9d5306b..fcb6e62 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -325,6 +325,34 @@ static inline uint32_t mtd_mod_by_ws(uint64_t sz, struct mtd_info *mtd) extern int add_mtd_device(struct mtd_info *mtd); extern int del_mtd_device (struct mtd_info *mtd); +struct mtd_partition; + +/** + * mtd_device_register() - register an MTD device + * + * Register an MTD device with the system and optionally, a number of + * partitions. If nr_parts is 0 then the whole device is registered, + * otherwise only the partitions are registered. To register both the full + * device *and* the partitions, call mtd_device_register() twice, once with + * nr_parts == 0 and once equal to the number of partitions. + * + * @master The MTD device to register. + * @parts The partitions to register - only valid if nr_parts > 0. + * @nr_parts The number of partitions in parts. If zero then the full + * MTD device is registered. + */ +extern int mtd_device_register(struct mtd_info *master, + const struct mtd_partition *parts, + int nr_parts); + +/** + * mtd_device_unregister() - unregister an existing MTD device. + * + * @master The MTD device to unregister. This will unregister both the + * master and any partitions if registered. + */ +extern int mtd_device_unregister(struct mtd_info *master); + extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num); extern int __get_mtd_device(struct mtd_info *mtd); extern void __put_mtd_device(struct mtd_info *mtd); diff --git a/include/linux/mtd/partitions.h b/include/linux/mtd/partitions.h index 4a0a8ba..998a6cf 100644 --- a/include/linux/mtd/partitions.h +++ b/include/linux/mtd/partitions.h @@ -16,7 +16,7 @@ * Partition definition structure: * * An array of struct partition is passed along with a MTD object to - * add_mtd_partitions() to create them. + * mtd_device_register() to create them. * * For each partition, these fields are available: * name: string that will be used to label the partition's MTD device.