summaryrefslogtreecommitdiffstats
path: root/drivers/nor
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/nor')
-rw-r--r--drivers/nor/cfi_flash.c41
-rw-r--r--drivers/nor/cfi_flash.h6
-rw-r--r--drivers/nor/m25p80.c76
-rw-r--r--drivers/nor/m25p80.h2
4 files changed, 102 insertions, 23 deletions
diff --git a/drivers/nor/cfi_flash.c b/drivers/nor/cfi_flash.c
index 16885c0af9..f65763a6e6 100644
--- a/drivers/nor/cfi_flash.c
+++ b/drivers/nor/cfi_flash.c
@@ -24,10 +24,6 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
*
*/
@@ -917,7 +913,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,11 +972,11 @@ 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)
{
struct flash_info *info = xzalloc(sizeof(*info));
+ int cfinum;
dev->priv = (void *)info;
@@ -1000,30 +995,46 @@ static int cfi_probe (struct device_d *dev)
dev_info(dev, "found cfi flash at %p, size %ld\n",
info->base, info->size);
- info->cdev.name = asprintf("nor%d", dev->id);
+ if (dev->id < 0)
+ cfinum = cdev_find_free_index("nor");
+ else
+ cfinum = dev->id;
+
+ info->cdev.name = asprintf("nor%d", cfinum);
info->cdev.size = info->size;
info->cdev.dev = 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);
+ if (dev->device_node)
+ of_parse_partitions(info->cdev.name, dev->device_node);
+
return 0;
}
+static __maybe_unused struct of_device_id cfi_dt_ids[] = {
+ {
+ .compatible = "cfi-flash",
+ }, {
+ /* sentinel */
+ }
+};
+
static struct driver_d cfi_driver = {
- .name = "cfi_flash",
- .probe = cfi_probe,
- .info = cfi_info,
+ .name = "cfi_flash",
+ .probe = cfi_probe,
+ .info = cfi_info,
+ .of_compatible = DRV_OF_COMPAT(cfi_dt_ids),
};
static int cfi_init(void)
{
- return register_driver(&cfi_driver);
+ return register_driver(&cfi_driver);
}
device_initcall(cfi_init);
-
diff --git a/drivers/nor/cfi_flash.h b/drivers/nor/cfi_flash.h
index fec08940ab..8f818ba4aa 100644
--- a/drivers/nor/cfi_flash.h
+++ b/drivers/nor/cfi_flash.h
@@ -18,10 +18,6 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
*/
#include <driver.h>
@@ -75,9 +71,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;
diff --git a/drivers/nor/m25p80.c b/drivers/nor/m25p80.c
index 5713ad58fe..e3b5b95443 100644
--- a/drivers/nor/m25p80.c
+++ b/drivers/nor/m25p80.c
@@ -648,6 +648,9 @@ static const struct spi_device_id m25p_ids[] = {
{ "cat25c09", CAT25_INFO( 128, 8, 32, 2) },
{ "cat25c17", CAT25_INFO( 256, 8, 32, 2) },
{ "cat25128", CAT25_INFO(2048, 8, 64, 2) },
+
+ /* Micron */
+ { "n25q128", INFO(0x20ba18, 0, 64 * 1024, 256, 0) },
{ },
};
@@ -694,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
@@ -825,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;
@@ -838,7 +912,7 @@ static struct driver_d epcs_flash_driver = {
static int epcs_init(void)
{
- register_driver(&epcs_flash_driver);
+ spi_register_driver(&epcs_flash_driver);
return 0;
}
diff --git a/drivers/nor/m25p80.h b/drivers/nor/m25p80.h
index 34bf2e259a..957900e3a2 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;