Commit d85879938d3fc3557f6ff74a60f95e0975a314ce

Authored by Thomas Chou
1 parent b375219e73

dm: implement a MTD uclass

Implement a Memory Technology Device (MTD) uclass. It should
include most flash drivers in the future. Though no uclass ops
are defined yet, the MTD ops could be used.

The NAND flash driver is based on MTD. The CFI flash and SPI
flash support MTD, too. It should make sense to convert them
to MTD uclass.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

Showing 7 changed files with 63 additions and 0 deletions Side-by-side Diff

  1 +menu "MTD Support"
  2 +
  3 +config MTD
  4 + bool "Enable Driver Model for MTD drivers"
  5 + depends on DM
  6 + help
  7 + Enable driver model for Memory Technology Devices (MTD), such as
  8 + flash, RAM and similar chips, often used for solid state file
  9 + systems on embedded devices.
  10 +
  11 +endmenu
  12 +
1 13 source "drivers/mtd/nand/Kconfig"
2 14  
3 15 source "drivers/mtd/spi/Kconfig"
drivers/mtd/Makefile
... ... @@ -8,6 +8,7 @@
8 8 ifneq (,$(findstring y,$(CONFIG_MTD_DEVICE)$(CONFIG_CMD_NAND)$(CONFIG_CMD_ONENAND)$(CONFIG_CMD_SF)))
9 9 obj-y += mtdcore.o mtd_uboot.o
10 10 endif
  11 +obj-$(CONFIG_MTD) += mtd-uclass.o
11 12 obj-$(CONFIG_MTD_PARTITIONS) += mtdpart.o
12 13 obj-$(CONFIG_MTD_CONCAT) += mtdconcat.o
13 14 obj-$(CONFIG_HAS_DATAFLASH) += at45.o
drivers/mtd/mtd-uclass.c
  1 +/*
  2 + * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
  3 + *
  4 + * SPDX-License-Identifier: GPL-2.0+
  5 + */
  6 +
  7 +#include <common.h>
  8 +#include <dm.h>
  9 +#include <errno.h>
  10 +#include <mtd.h>
  11 +
  12 +/*
  13 + * Implement a MTD uclass which should include most flash drivers.
  14 + * The uclass private is pointed to mtd_info.
  15 + */
  16 +
  17 +UCLASS_DRIVER(mtd) = {
  18 + .id = UCLASS_MTD,
  19 + .name = "mtd",
  20 + .per_device_auto_alloc_size = sizeof(struct mtd_info),
  21 +};
include/dm/uclass-id.h
... ... @@ -43,6 +43,7 @@
43 43 UCLASS_MISC, /* Miscellaneous device */
44 44 UCLASS_MMC, /* SD / MMC card or chip */
45 45 UCLASS_MOD_EXP, /* RSA Mod Exp device */
  46 + UCLASS_MTD, /* Memory Technology Device (MTD) device */
46 47 UCLASS_PCH, /* x86 platform controller hub */
47 48 UCLASS_PCI, /* PCI bus */
48 49 UCLASS_PCI_GENERIC, /* Generic PCI bus device */
... ... @@ -41,6 +41,9 @@
41 41 ulong addr_unlock2; /* unlock address 2 for AMD flash roms */
42 42 const char *name; /* human-readable name */
43 43 #endif
  44 +#ifdef CONFIG_MTD
  45 + struct mtd_info *mtd;
  46 +#endif
44 47 } flash_info_t;
45 48  
46 49 extern flash_info_t flash_info[]; /* info for FLASH chips */
include/linux/mtd/mtd.h
... ... @@ -272,6 +272,8 @@
272 272 struct module *owner;
273 273 #ifndef __UBOOT__
274 274 struct device dev;
  275 +#else
  276 + struct udevice *dev;
275 277 #endif
276 278 int usecount;
277 279 };
  1 +/*
  2 + * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
  3 + *
  4 + * SPDX-License-Identifier: GPL-2.0+
  5 + */
  6 +
  7 +#ifndef _MTD_H_
  8 +#define _MTD_H_
  9 +
  10 +#include <linux/mtd/mtd.h>
  11 +
  12 +/*
  13 + * Get mtd_info structure of the dev, which is stored as uclass private.
  14 + *
  15 + * @dev: The MTD device
  16 + * @return: pointer to mtd_info, NULL on error
  17 + */
  18 +static inline struct mtd_info *mtd_get_info(struct udevice *dev)
  19 +{
  20 + return dev_get_uclass_priv(dev);
  21 +}
  22 +
  23 +#endif /* _MTD_H_ */