Commit bfa5ecda authored by Sudhakar Rajashekhara's avatar Sudhakar Rajashekhara Committed by Kevin Hilman

mtdpart: memory accessor interface for MTD layer

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: default avatarSudhakar Rajashekhara <sudhakar.raj@ti.com>
Cc: David Brownell <david-b@pacbell.net>
Cc: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: default avatarKevin Hilman <khilman@deeprootsystems.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent e40152ee
...@@ -26,6 +26,7 @@ static LIST_HEAD(mtd_partitions); ...@@ -26,6 +26,7 @@ static LIST_HEAD(mtd_partitions);
struct mtd_part { struct mtd_part {
struct mtd_info mtd; struct mtd_info mtd;
struct mtd_info *master; struct mtd_info *master;
struct memory_accessor macc;
uint64_t offset; uint64_t offset;
struct list_head list; struct list_head list;
}; };
...@@ -327,6 +328,39 @@ int del_mtd_partitions(struct mtd_info *master) ...@@ -327,6 +328,39 @@ int del_mtd_partitions(struct mtd_info *master)
} }
EXPORT_SYMBOL(del_mtd_partitions); 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, static struct mtd_part *add_one_partition(struct mtd_info *master,
const struct mtd_partition *part, int partno, const struct mtd_partition *part, int partno,
uint64_t cur_offset) uint64_t cur_offset)
...@@ -364,6 +398,9 @@ static struct mtd_part *add_one_partition(struct mtd_info *master, ...@@ -364,6 +398,9 @@ static struct mtd_part *add_one_partition(struct mtd_info *master,
slave->mtd.read = part_read; slave->mtd.read = part_read;
slave->mtd.write = part_write; slave->mtd.write = part_write;
slave->macc.read = mtd_macc_read;
slave->macc.write = mtd_macc_write;
if (master->panic_write) if (master->panic_write)
slave->mtd.panic_write = part_panic_write; slave->mtd.panic_write = part_panic_write;
...@@ -428,6 +465,9 @@ static struct mtd_part *add_one_partition(struct mtd_info *master, ...@@ -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, 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); (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 */ /* let's do some sanity checks */
if (slave->offset >= master->size) { if (slave->offset >= master->size) {
/* let's register it anyway to preserve ordering */ /* let's register it anyway to preserve ordering */
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#define MTD_PARTITIONS_H #define MTD_PARTITIONS_H
#include <linux/types.h> #include <linux/types.h>
#include <linux/memory.h>
/* /*
...@@ -40,6 +41,8 @@ struct mtd_partition { ...@@ -40,6 +41,8 @@ struct mtd_partition {
uint64_t offset; /* offset within the master MTD space */ uint64_t offset; /* offset within the master MTD space */
uint32_t mask_flags; /* master MTD flags to mask out for this partition */ 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)*/ 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) #define MTDPART_OFS_NXTBLK (-2)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment