* [PATCH 1/2] drivers/nor/m25p80: add MTD support
@ 2012-09-10 8:55 Jan Luebbe
2012-09-10 8:55 ` [PATCH 2/2] drivers/nor/cfi_flash: use IS_ENABLED instead of an ifdef Jan Luebbe
2012-09-10 16:04 ` [PATCH 1/2] drivers/nor/m25p80: add MTD support Sascha Hauer
0 siblings, 2 replies; 3+ messages in thread
From: Jan Luebbe @ 2012-09-10 8:55 UTC (permalink / raw)
To: barebox
This has been tested by using UBI with a N25Q128 connected to
a TI McSPI controller.
Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
---
drivers/nor/m25p80.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++
drivers/nor/m25p80.h | 2 +-
2 files changed, 72 insertions(+), 1 deletion(-)
diff --git a/drivers/nor/m25p80.c b/drivers/nor/m25p80.c
index 61f2195..8775fa9 100644
--- a/drivers/nor/m25p80.c
+++ b/drivers/nor/m25p80.c
@@ -697,6 +697,74 @@ static struct file_operations m25p80_ops = {
.lseek = dev_lseek_default,
};
+static int m25p_mtd_read(struct mtd_info *mtd, loff_t from, size_t len,
+ size_t *retlen, u_char *buf)
+{
+ struct m25p *flash = container_of(mtd, struct m25p, mtd);
+ ssize_t ret;
+
+ ret = flash->cdev.ops->read(&flash->cdev, buf, len, from, 0);
+ if (ret < 0) {
+ *retlen = 0;
+ return ret;
+ }
+
+ *retlen = ret;
+ return 0;
+}
+
+static int m25p_mtd_write(struct mtd_info *mtd, loff_t to, size_t len,
+ size_t *retlen, const u_char *buf)
+{
+ struct m25p *flash = container_of(mtd, struct m25p, mtd);
+ ssize_t ret;
+
+ ret = flash->cdev.ops->write(&flash->cdev, buf, len, to, 0);
+ if (ret < 0) {
+ *retlen = 0;
+ return ret;
+ }
+
+ *retlen = ret;
+ return 0;
+}
+
+static int m25p_mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
+{
+ struct m25p *flash = container_of(mtd, struct m25p, mtd);
+ ssize_t ret;
+
+ ret = flash->cdev.ops->erase(&flash->cdev, instr->len, instr->addr);
+
+ if (ret) {
+ instr->state = MTD_ERASE_FAILED;
+ return -EIO;
+ }
+
+ instr->state = MTD_ERASE_DONE;
+ mtd_erase_callback(instr);
+
+ return 0;
+}
+
+static void m25p_init_mtd(struct m25p *flash)
+{
+ struct mtd_info *mtd = &flash->mtd;
+
+ mtd->read = m25p_mtd_read;
+ mtd->write = m25p_mtd_write;
+ mtd->erase = m25p_mtd_erase;
+ mtd->size = flash->size;
+ mtd->name = flash->cdev.name;
+ mtd->erasesize = flash->erasesize;
+ mtd->writesize = 1;
+ mtd->subpage_sft = 0;
+ mtd->eraseregions = NULL;
+ mtd->numeraseregions = 0;
+ mtd->flags = MTD_CAP_NORFLASH;
+ flash->cdev.mtd = mtd;
+}
+
/*
* board specific setup should have ensured the SPI clock used here
* matches what the READ command supports, at least until this driver
@@ -828,6 +896,9 @@ static int m25p_probe(struct device_d *dev)
dev_info(dev, "%s (%lld Kbytes)\n", id->name, (long long)flash->size >> 10);
+ if (IS_ENABLED(CONFIG_PARTITION_NEED_MTD))
+ m25p_init_mtd(flash);
+
devfs_create(&flash->cdev);
return 0;
diff --git a/drivers/nor/m25p80.h b/drivers/nor/m25p80.h
index 34bf2e2..957900e 100644
--- a/drivers/nor/m25p80.h
+++ b/drivers/nor/m25p80.h
@@ -46,7 +46,7 @@ struct spi_device_id {
struct m25p {
struct spi_device *spi;
struct flash_info *info;
- struct mtd_info mtd;
+ struct mtd_info mtd;
struct cdev cdev;
char *name;
u32 erasesize;
--
1.7.10.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] drivers/nor/cfi_flash: use IS_ENABLED instead of an ifdef
2012-09-10 8:55 [PATCH 1/2] drivers/nor/m25p80: add MTD support Jan Luebbe
@ 2012-09-10 8:55 ` Jan Luebbe
2012-09-10 16:04 ` [PATCH 1/2] drivers/nor/m25p80: add MTD support Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Jan Luebbe @ 2012-09-10 8:55 UTC (permalink / raw)
To: barebox
Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
---
drivers/nor/cfi_flash.c | 8 +++-----
drivers/nor/cfi_flash.h | 2 --
2 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/drivers/nor/cfi_flash.c b/drivers/nor/cfi_flash.c
index 16885c0..d9347b2 100644
--- a/drivers/nor/cfi_flash.c
+++ b/drivers/nor/cfi_flash.c
@@ -917,7 +917,6 @@ struct file_operations cfi_ops = {
.memmap = generic_memmap_ro,
};
-#ifdef CONFIG_PARTITION_NEED_MTD
static int cfi_mtd_read(struct mtd_info *mtd, loff_t from, size_t len,
size_t *retlen, u_char *buf)
{
@@ -977,7 +976,6 @@ static void cfi_init_mtd(struct flash_info *info)
mtd->flags = MTD_CAP_NORFLASH;
info->cdev.mtd = mtd;
}
-#endif
static int cfi_probe (struct device_d *dev)
{
@@ -1006,9 +1004,9 @@ static int cfi_probe (struct device_d *dev)
info->cdev.ops = &cfi_ops;
info->cdev.priv = info;
-#ifdef CONFIG_PARTITION_NEED_MTD
- cfi_init_mtd(info);
-#endif
+ if (IS_ENABLED(CONFIG_PARTITION_NEED_MTD))
+ cfi_init_mtd(info);
+
devfs_create(&info->cdev);
return 0;
diff --git a/drivers/nor/cfi_flash.h b/drivers/nor/cfi_flash.h
index fec0894..1bfe81c 100644
--- a/drivers/nor/cfi_flash.h
+++ b/drivers/nor/cfi_flash.h
@@ -75,9 +75,7 @@ struct flash_info {
ulong addr_unlock2; /* unlock address 2 for AMD flash roms */
struct cfi_cmd_set *cfi_cmd_set;
struct cdev cdev;
-#ifdef CONFIG_PARTITION_NEED_MTD
struct mtd_info mtd;
-#endif
int numeraseregions;
struct mtd_erase_region_info *eraseregions;
void *base;
--
1.7.10.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] drivers/nor/m25p80: add MTD support
2012-09-10 8:55 [PATCH 1/2] drivers/nor/m25p80: add MTD support Jan Luebbe
2012-09-10 8:55 ` [PATCH 2/2] drivers/nor/cfi_flash: use IS_ENABLED instead of an ifdef Jan Luebbe
@ 2012-09-10 16:04 ` Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2012-09-10 16:04 UTC (permalink / raw)
To: Jan Luebbe; +Cc: barebox
On Mon, Sep 10, 2012 at 10:55:46AM +0200, Jan Luebbe wrote:
> This has been tested by using UBI with a N25Q128 connected to
> a TI McSPI controller.
>
> Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
Applied, thanks
Sascha
> ---
> drivers/nor/m25p80.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++
> drivers/nor/m25p80.h | 2 +-
> 2 files changed, 72 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/nor/m25p80.c b/drivers/nor/m25p80.c
> index 61f2195..8775fa9 100644
> --- a/drivers/nor/m25p80.c
> +++ b/drivers/nor/m25p80.c
> @@ -697,6 +697,74 @@ static struct file_operations m25p80_ops = {
> .lseek = dev_lseek_default,
> };
>
> +static int m25p_mtd_read(struct mtd_info *mtd, loff_t from, size_t len,
> + size_t *retlen, u_char *buf)
> +{
> + struct m25p *flash = container_of(mtd, struct m25p, mtd);
> + ssize_t ret;
> +
> + ret = flash->cdev.ops->read(&flash->cdev, buf, len, from, 0);
> + if (ret < 0) {
> + *retlen = 0;
> + return ret;
> + }
> +
> + *retlen = ret;
> + return 0;
> +}
> +
> +static int m25p_mtd_write(struct mtd_info *mtd, loff_t to, size_t len,
> + size_t *retlen, const u_char *buf)
> +{
> + struct m25p *flash = container_of(mtd, struct m25p, mtd);
> + ssize_t ret;
> +
> + ret = flash->cdev.ops->write(&flash->cdev, buf, len, to, 0);
> + if (ret < 0) {
> + *retlen = 0;
> + return ret;
> + }
> +
> + *retlen = ret;
> + return 0;
> +}
> +
> +static int m25p_mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
> +{
> + struct m25p *flash = container_of(mtd, struct m25p, mtd);
> + ssize_t ret;
> +
> + ret = flash->cdev.ops->erase(&flash->cdev, instr->len, instr->addr);
> +
> + if (ret) {
> + instr->state = MTD_ERASE_FAILED;
> + return -EIO;
> + }
> +
> + instr->state = MTD_ERASE_DONE;
> + mtd_erase_callback(instr);
> +
> + return 0;
> +}
> +
> +static void m25p_init_mtd(struct m25p *flash)
> +{
> + struct mtd_info *mtd = &flash->mtd;
> +
> + mtd->read = m25p_mtd_read;
> + mtd->write = m25p_mtd_write;
> + mtd->erase = m25p_mtd_erase;
> + mtd->size = flash->size;
> + mtd->name = flash->cdev.name;
> + mtd->erasesize = flash->erasesize;
> + mtd->writesize = 1;
> + mtd->subpage_sft = 0;
> + mtd->eraseregions = NULL;
> + mtd->numeraseregions = 0;
> + mtd->flags = MTD_CAP_NORFLASH;
> + flash->cdev.mtd = mtd;
> +}
> +
> /*
> * board specific setup should have ensured the SPI clock used here
> * matches what the READ command supports, at least until this driver
> @@ -828,6 +896,9 @@ static int m25p_probe(struct device_d *dev)
>
> dev_info(dev, "%s (%lld Kbytes)\n", id->name, (long long)flash->size >> 10);
>
> + if (IS_ENABLED(CONFIG_PARTITION_NEED_MTD))
> + m25p_init_mtd(flash);
> +
> devfs_create(&flash->cdev);
>
> return 0;
> diff --git a/drivers/nor/m25p80.h b/drivers/nor/m25p80.h
> index 34bf2e2..957900e 100644
> --- a/drivers/nor/m25p80.h
> +++ b/drivers/nor/m25p80.h
> @@ -46,7 +46,7 @@ struct spi_device_id {
> struct m25p {
> struct spi_device *spi;
> struct flash_info *info;
> - struct mtd_info mtd;
> + struct mtd_info mtd;
> struct cdev cdev;
> char *name;
> u32 erasesize;
> --
> 1.7.10.4
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
>
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-09-10 16:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-10 8:55 [PATCH 1/2] drivers/nor/m25p80: add MTD support Jan Luebbe
2012-09-10 8:55 ` [PATCH 2/2] drivers/nor/cfi_flash: use IS_ENABLED instead of an ifdef Jan Luebbe
2012-09-10 16:04 ` [PATCH 1/2] drivers/nor/m25p80: add MTD support Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox