From patchwork Tue Aug 18 16:34:27 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rajashekhara, Sudhakar" X-Patchwork-Id: 31549 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 63902B7B69 for ; Tue, 18 Aug 2009 17:09:12 +1000 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1MdIn0-0000d8-Rc; Tue, 18 Aug 2009 07:07:26 +0000 Received: from comal.ext.ti.com ([198.47.26.152]) by bombadil.infradead.org with esmtps (Exim 4.69 #1 (Red Hat Linux)) id 1MdImv-0000Ux-7B; Tue, 18 Aug 2009 07:07:25 +0000 Received: from dflp53.itg.ti.com ([128.247.5.6]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id n7I77EvX027751; Tue, 18 Aug 2009 02:07:19 -0500 Received: from tidmzi-ftp.india.ext.ti.com (localhost [127.0.0.1]) by dflp53.itg.ti.com (8.13.8/8.13.8) with SMTP id n7I77BkQ023241; Tue, 18 Aug 2009 02:07:12 -0500 (CDT) Received: from symphonyindia.ti.com (symphony-ftp [192.168.247.11]) by tidmzi-ftp.india.ext.ti.com (Postfix) with SMTP id BE2C93886B; Tue, 18 Aug 2009 12:34:17 +0530 (IST) Received: from localhost.localdomain ([192.168.247.76]) by symphonyindia.ti.com (8.13.1/8.12.10) with ESMTP id n7I70flq009522; Tue, 18 Aug 2009 12:30:41 +0530 From: Sudhakar Rajashekhara To: linux-mtd@lists.infradead.org Subject: [PATCH] [MTD] mtdpart: memory accessor interface for MTD layer Date: Tue, 18 Aug 2009 12:34:27 -0400 Message-Id: <1250613267-25485-1-git-send-email-sudhakar.raj@ti.com> X-Mailer: git-send-email 1.5.6 X-Spam-Score: 3.1 (+++) X-Spam-Report: SpamAssassin version 3.2.5 on bombadil.infradead.org summary: Content analysis details: (3.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- 3.1 DATE_IN_FUTURE_06_12 Date: is 6 to 12 hours after Received: date Cc: david-b@pacbell.net, davinci-linux-open-source@linux.davincidsp.com, Sudhakar Rajashekhara , dwmw2@infradead.org, linux-kernel@vger.kernel.org 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 This patch implements memory accessor interface in the MTD layer which enables the kernel to access flash data. This patch adds two new members to the mtd_partition structure, a function handler which will be called during setup of the partition and an argument to be passed to this setup function. Example: +static struct mtd_partition spi_flash_partitions[] = { + [0] = { + .name = "U-Boot", + .offset = 0, + .size = SZ_256K, + .mask_flags = MTD_WRITEABLE, + }, + [1] = { + .name = "U-Boot Environment", + .offset = MTDPART_OFS_NXTBLK, + .size = SZ_64K, + .mask_flags = MTD_WRITEABLE, + }, + [2] = { + .name = "Linux", + .offset = MTDPART_OFS_NXTBLK, + .size = SZ_7M, + .mask_flags = 0, + }, + [3] = { + .name = "MAC Address", + .offset = MTDPART_OFS_NXTBLK, + .size = SZ_64K, + .mask_flags = 0, + .setup = davinci_get_mac_addr, + .context = (void *)0, + }, +}; The davinci_get_mac_addr function reads the MAC address from offset ZERO of last MTD partition. Signed-off-by: Sudhakar Rajashekhara --- drivers/mtd/mtdpart.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/linux/mtd/partitions.h | 3 +++ 2 files changed, 43 insertions(+), 0 deletions(-) diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index 349fcbe..8f14653 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -26,6 +26,7 @@ static LIST_HEAD(mtd_partitions); struct mtd_part { struct mtd_info mtd; struct mtd_info *master; + struct memory_accessor macc; uint64_t offset; struct list_head list; }; @@ -327,6 +328,39 @@ int del_mtd_partitions(struct mtd_info *master) } EXPORT_SYMBOL(del_mtd_partitions); +/* + * This lets other kernel code access the flash data. For example, it + * might hold a board's Ethernet address, or board-specific calibration + * data generated on the manufacturing floor. + */ +static ssize_t mtd_macc_read(struct memory_accessor *macc, char *buf, + off_t offset, size_t count) +{ + struct mtd_part *part = container_of(macc, struct mtd_part, macc); + ssize_t ret = -EIO; + size_t retlen; + + if (part_read((struct mtd_info *)part, offset, count, + &retlen, buf) == 0) + ret = retlen; + + return ret; +} + +static ssize_t mtd_macc_write(struct memory_accessor *macc, const char *buf, + off_t offset, size_t count) +{ + struct mtd_part *part = container_of(macc, struct mtd_part, macc); + ssize_t ret = -EIO; + size_t retlen; + + if (part_write((struct mtd_info *)part, offset, count, + &retlen, buf) == 0) + ret = retlen; + + return ret; +} + static struct mtd_part *add_one_partition(struct mtd_info *master, const struct mtd_partition *part, int partno, uint64_t cur_offset) @@ -364,6 +398,9 @@ static struct mtd_part *add_one_partition(struct mtd_info *master, slave->mtd.read = part_read; slave->mtd.write = part_write; + slave->macc.read = mtd_macc_read; + slave->macc.write = mtd_macc_write; + if (master->panic_write) slave->mtd.panic_write = part_panic_write; @@ -428,6 +465,9 @@ static struct mtd_part *add_one_partition(struct mtd_info *master, printk(KERN_NOTICE "0x%012llx-0x%012llx : \"%s\"\n", (unsigned long long)slave->offset, (unsigned long long)(slave->offset + slave->mtd.size), slave->mtd.name); + if (part->setup) + part->setup(&slave->macc, (void *)part->context); + /* let's do some sanity checks */ if (slave->offset >= master->size) { /* let's register it anyway to preserve ordering */ diff --git a/include/linux/mtd/partitions.h b/include/linux/mtd/partitions.h index af6dcb9..cc76779 100644 --- a/include/linux/mtd/partitions.h +++ b/include/linux/mtd/partitions.h @@ -10,6 +10,7 @@ #define MTD_PARTITIONS_H #include +#include /* @@ -40,6 +41,8 @@ struct mtd_partition { uint64_t offset; /* offset within the master MTD space */ uint32_t mask_flags; /* master MTD flags to mask out for this partition */ struct nand_ecclayout *ecclayout; /* out of band layout for this partition (NAND only)*/ + void (*setup)(struct memory_accessor *, void *context); + void *context; }; #define MTDPART_OFS_NXTBLK (-2)