From: Jagan Teki <jagan@openedev.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v9 01/21] dm: mtd: Add dm mtd core ops
Date: Sun, 30 Oct 2016 23:53:33 +0530 [thread overview]
Message-ID: <1477851833-23960-2-git-send-email-jagan@openedev.com> (raw)
In-Reply-To: <1477851833-23960-1-git-send-email-jagan@openedev.com>
- Add generic dm_mtd operations
- Add mtd_read|erase|write_dm
- Add add_mtd_device_dm
The respetive MTD_UCLASS drivers must install the hooks to these
dm_mtd_ops and other core ops are act as a interface b/w drivers
vs command code.
Signed-off-by: Jagan Teki <jagan@openedev.com>
---
drivers/mtd/mtd-uclass.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++
include/mtd.h | 54 ++++++++++++++++++++++++++++++++++++
2 files changed, 126 insertions(+)
diff --git a/drivers/mtd/mtd-uclass.c b/drivers/mtd/mtd-uclass.c
index 7b7c48e..acbd713 100644
--- a/drivers/mtd/mtd-uclass.c
+++ b/drivers/mtd/mtd-uclass.c
@@ -1,4 +1,5 @@
/*
+ * Copyright (C) 2016 Jagan Teki <jagan@openedev.com>
* Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
*
* SPDX-License-Identifier: GPL-2.0+
@@ -8,6 +9,77 @@
#include <dm.h>
#include <errno.h>
#include <mtd.h>
+#include <linux/log2.h>
+
+int dm_mtd_read(struct udevice *dev, loff_t from, size_t len, size_t *retlen,
+ u_char *buf)
+{
+ struct mtd_info *mtd = mtd_get_info(dev);
+
+ *retlen = 0;
+ if (from < 0 || from > mtd->size || len > mtd->size - from)
+ return -EINVAL;
+ if (!len)
+ return 0;
+
+ return mtd_get_ops(dev)->_read(dev, from, len, retlen, buf);
+}
+
+int dm_mtd_erase(struct udevice *dev, struct erase_info *instr)
+{
+ struct mtd_info *mtd = mtd_get_info(dev);
+
+ if (instr->addr > mtd->size || instr->len > mtd->size - instr->addr)
+ return -EINVAL;
+ if (!(mtd->flags & MTD_WRITEABLE))
+ return -EROFS;
+ instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN;
+ if (!instr->len) {
+ instr->state = MTD_ERASE_DONE;
+ return 0;
+ }
+
+ return mtd_get_ops(dev)->_erase(dev, instr);
+}
+
+int dm_mtd_write(struct udevice *dev, loff_t to, size_t len, size_t *retlen,
+ const u_char *buf)
+{
+ struct mtd_info *mtd = mtd_get_info(dev);
+
+ *retlen = 0;
+ if (to < 0 || to > mtd->size || len > mtd->size - to)
+ return -EINVAL;
+ if (!mtd_get_ops(dev)->_write || !(mtd->flags & MTD_WRITEABLE))
+ return -EROFS;
+ if (!len)
+ return 0;
+
+ return mtd_get_ops(dev)->_write(dev, to, len, retlen, buf);
+}
+
+int dm_add_mtd_device(struct udevice *dev)
+{
+ struct mtd_info *mtd = mtd_get_info(dev);
+
+ BUG_ON(mtd->writesize == 0);
+ mtd->usecount = 0;
+
+ if (is_power_of_2(mtd->erasesize))
+ mtd->erasesize_shift = ffs(mtd->erasesize) - 1;
+ else
+ mtd->erasesize_shift = 0;
+
+ if (is_power_of_2(mtd->writesize))
+ mtd->writesize_shift = ffs(mtd->writesize) - 1;
+ else
+ mtd->writesize_shift = 0;
+
+ mtd->erasesize_mask = (1 << mtd->erasesize_shift) - 1;
+ mtd->writesize_mask = (1 << mtd->writesize_shift) - 1;
+
+ return 0;
+}
/*
* Implement a MTD uclass which should include most flash drivers.
diff --git a/include/mtd.h b/include/mtd.h
index 3f8c293..93b5eaf 100644
--- a/include/mtd.h
+++ b/include/mtd.h
@@ -20,4 +20,58 @@ static inline struct mtd_info *mtd_get_info(struct udevice *dev)
return dev_get_uclass_priv(dev);
}
+struct dm_mtd_ops {
+ int (*_erase)(struct udevice *dev, struct erase_info *instr);
+ int (*_read)(struct udevice *dev, loff_t from, size_t len,
+ size_t *retlen, u_char *buf);
+ int (*_write)(struct udevice *dev, loff_t to, size_t len,
+ size_t *retlen, const u_char *buf);
+};
+
+/* Access the serial operations for a device */
+#define mtd_get_ops(dev) ((struct dm_mtd_ops *)(dev)->driver->ops)
+
+/**
+ * dm_mtd_read() - Read data from MTD device
+ *
+ * @dev: MTD device
+ * @from: Offset into device in bytes to read from
+ * @len: Length of bytes to read
+ * @retlen: Length of return bytes read to
+ * @buf: Buffer to put the data that is read
+ * @return 0 if OK, -ve on error
+ */
+int dm_mtd_read(struct udevice *dev, loff_t from, size_t len, size_t *retlen,
+ u_char *buf);
+
+/**
+ * dm_mtd_write() - Write data to MTD device
+ *
+ * @dev: MTD device
+ * @to: Offset into device in bytes to write to
+ * @len: Length of bytes to write
+ * @retlen: Length of return bytes to write to
+ * @buf: Buffer containing bytes to write
+ * @return 0 if OK, -ve on error
+ */
+int dm_mtd_write(struct udevice *dev, loff_t to, size_t len, size_t *retlen,
+ const u_char *buf);
+
+/**
+ * dm_mtd_erase() - Erase blocks of the MTD device
+ *
+ * @dev: MTD device
+ * @instr: Erase info details of MTD device
+ * @return 0 if OK, -ve on error
+ */
+int dm_mtd_erase(struct udevice *dev, struct erase_info *instr);
+
+/**
+ * dm_add_mtd_device() - Add MTD device
+ *
+ * @dev: MTD device
+ * @return 0 if OK, -ve on error
+ */
+int dm_add_mtd_device(struct udevice *dev);
+
#endif /* _MTD_H_ */
--
2.7.4
next prev parent reply other threads:[~2016-10-30 18:23 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-30 18:23 [U-Boot] [PATCH v9 00/21] dm: Generic MTD Subsystem/SPI-NOR Jagan Teki
2016-10-30 18:23 ` Jagan Teki [this message]
2016-11-05 16:07 ` [U-Boot] [PATCH v9 01/21] dm: mtd: Add dm mtd core ops Simon Glass
2016-10-30 18:23 ` [U-Boot] [PATCH v9 02/21] mtd: Add SPI-NOR core support Jagan Teki
2016-11-05 16:10 ` Simon Glass
2016-10-30 18:23 ` [U-Boot] [PATCH v9 03/21] mtd: spi-nor: Kconfig: Add MTD_SPI_NOR entry Jagan Teki
2016-11-05 16:09 ` Simon Glass
2016-10-30 18:23 ` [U-Boot] [PATCH v9 04/21] mtd: spi-nor: Kconfig: Add MTD_SPI_NOR_USE_4K_SECTORS Jagan Teki
2016-11-05 16:09 ` Simon Glass
2016-10-30 18:23 ` [U-Boot] [PATCH v9 05/21] mtd: spi-nor: Kconfig: Add SPI_NOR_MISC entry Jagan Teki
2016-11-05 16:09 ` Simon Glass
2016-10-30 18:23 ` [U-Boot] [PATCH v9 06/21] mtd: spi-nor: Kconfig: Add SPI_NOR_MACRONIX entry Jagan Teki
2016-11-05 16:09 ` Simon Glass
2016-10-30 18:23 ` [U-Boot] [PATCH v9 07/21] mtd: spi-nor: Kconfig: Add SPI_NOR_SPANSION entry Jagan Teki
2016-11-05 16:09 ` Simon Glass
2016-10-30 18:23 ` [U-Boot] [PATCH v9 08/21] mtd: spi-nor: Kconfig: Add SPI_NOR_STMICRO entry Jagan Teki
2016-11-05 16:09 ` Simon Glass
2016-10-30 18:23 ` [U-Boot] [PATCH v9 09/21] mtd: spi-nor: Kconfig: Add SPI_NOR_SST entry Jagan Teki
2016-11-05 16:09 ` Simon Glass
2016-10-30 18:23 ` [U-Boot] [PATCH v9 10/21] mtd: spi-nor: Kconfig: Add SPI_NOR_WINBOND entry Jagan Teki
2016-11-05 16:09 ` Simon Glass
2016-10-30 18:23 ` [U-Boot] [PATCH v9 11/21] spi: Add spi_write_then_read Jagan Teki
2016-11-05 16:09 ` Simon Glass
2016-10-30 18:23 ` [U-Boot] [PATCH v9 12/21] mtd: spi-nor: Add m25p80 driver Jagan Teki
2016-11-05 16:10 ` Simon Glass
2016-10-30 18:23 ` [U-Boot] [PATCH v9 13/21] mtd: spi-nor: Kconfig: Add MTD_M25P80 entry Jagan Teki
2016-11-05 16:09 ` Simon Glass
2016-10-30 18:23 ` [U-Boot] [PATCH v9 14/21] mtd: spi-nor: Add zynq qspinor driver Jagan Teki
2016-10-30 18:23 ` [U-Boot] [PATCH v9 15/21] mtd: spi-nor: zynq_qspi: Kconfig: Add MTD_ZYNQ Jagan Teki
2016-10-30 18:23 ` [U-Boot] [PATCH v9 16/21] mtd: spi-nor: Add 4-byte addresswidth support Jagan Teki
2016-10-30 18:23 ` [U-Boot] [PATCH v9 17/21] dm: mtd: Add uclass_driver.flags Jagan Teki
2016-11-05 16:10 ` Simon Glass
2016-10-30 18:23 ` [U-Boot] [PATCH v9 18/21] dm: mtd: Add post_bind Jagan Teki
2016-11-05 16:10 ` Simon Glass
2016-10-30 18:23 ` [U-Boot] [PATCH v9 19/21] cmd: Add mtd command support Jagan Teki
2016-11-05 16:10 ` Simon Glass
2016-10-30 18:23 ` [U-Boot] [PATCH v9 20/21] arm: dts: zynq: Add zynq-qspinor node Jagan Teki
2016-10-30 18:23 ` [U-Boot] [PATCH v9 21/21] dm: zynq: microzed: Enable MTD/SPI-NOR Jagan Teki
2016-11-05 16:07 ` [U-Boot] [PATCH v9 00/21] dm: Generic MTD Subsystem/SPI-NOR Simon Glass
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1477851833-23960-2-git-send-email-jagan@openedev.com \
--to=jagan@openedev.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox