Commit e7ecf7cb5a6b873daf2d88daf03034d51fad4acc

Authored by Simon Glass
1 parent fdfa39d3f2

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

Showing 6 changed files with 71 additions and 0 deletions Side-by-side Diff

1 1 menu "MMC Host controller Support"
2 2  
  3 +config DM_MMC
  4 + bool "Enable MMC controllers using Driver Model"
  5 + depends on DM
  6 + help
  7 + This enables the MultiMediaCard (MMC) uclass which suports MMC and
  8 + Secure Digital I/O (SDIO) cards. Both removable (SD, micro-SD, etc.)
  9 + and non-removable (e.g. eMMC chip) devices are supported. These
  10 + appear as block devices in U-Boot and can support filesystems such
  11 + as EXT4 and FAT.
  12 +
3 13 config SH_SDHI
4 14 bool "SuperH/Renesas ARM SoCs on-chip SDHI host controller support"
5 15 depends on RMOBILE
drivers/mmc/Makefile
... ... @@ -5,6 +5,8 @@
5 5 # SPDX-License-Identifier: GPL-2.0+
6 6 #
7 7  
  8 +obj-$(CONFIG_DM_MMC) += mmc-uclass.o
  9 +
8 10 obj-$(CONFIG_ARM_PL180_MMCI) += arm_pl180_mmci.o
9 11 obj-$(CONFIG_BCM2835_SDHCI) += bcm2835_sdhci.o
10 12 obj-$(CONFIG_BFIN_SDH) += bfin_sdh.o
drivers/mmc/mmc-uclass.c
  1 +/*
  2 + * Copyright (C) 2015 Google, Inc
  3 + * Written by Simon Glass <sjg@chromium.org>
  4 + *
  5 + * SPDX-License-Identifier: GPL-2.0+
  6 + */
  7 +
  8 +#include <common.h>
  9 +#include <mmc.h>
  10 +#include <dm.h>
  11 +#include <dm/lists.h>
  12 +#include <dm/root.h>
  13 +
  14 +struct mmc *mmc_get_mmc_dev(struct udevice *dev)
  15 +{
  16 + struct mmc_uclass_priv *upriv;
  17 +
  18 + if (!device_active(dev))
  19 + return NULL;
  20 + upriv = dev_get_uclass_priv(dev);
  21 + return upriv->mmc;
  22 +}
  23 +
  24 +U_BOOT_DRIVER(mmc) = {
  25 + .name = "mmc",
  26 + .id = UCLASS_MMC,
  27 +};
  28 +
  29 +UCLASS_DRIVER(mmc) = {
  30 + .id = UCLASS_MMC,
  31 + .name = "mmc",
  32 + .flags = DM_UC_FLAG_SEQ_ALIAS,
  33 + .per_device_auto_alloc_size = sizeof(struct mmc_uclass_priv),
  34 +};
... ... @@ -1761,8 +1761,10 @@
1761 1761 INIT_LIST_HEAD (&mmc_devices);
1762 1762 cur_dev_num = 0;
1763 1763  
  1764 +#ifndef CONFIG_DM_MMC
1764 1765 if (board_mmc_init(bis) < 0)
1765 1766 cpu_mmc_init(bis);
  1767 +#endif
1766 1768  
1767 1769 #ifndef CONFIG_SPL_BUILD
1768 1770 print_mmc_devices(',');
include/dm/uclass-id.h
... ... @@ -36,6 +36,7 @@
36 36 UCLASS_LED, /* Light-emitting diode (LED) */
37 37 UCLASS_LPC, /* x86 'low pin count' interface */
38 38 UCLASS_MASS_STORAGE, /* Mass storage device */
  39 + UCLASS_MMC, /* SD / MMC card or chip */
39 40 UCLASS_MOD_EXP, /* RSA Mod Exp device */
40 41 UCLASS_PCH, /* x86 platform controller hub */
41 42 UCLASS_PCI, /* PCI bus */
... ... @@ -266,6 +266,28 @@
266 266 #define MMC_NUM_BOOT_PARTITION 2
267 267 #define MMC_PART_RPMB 3 /* RPMB partition number */
268 268  
  269 +/* Driver model support */
  270 +
  271 +/**
  272 + * struct mmc_uclass_priv - Holds information about a device used by the uclass
  273 + */
  274 +struct mmc_uclass_priv {
  275 + struct mmc *mmc;
  276 +};
  277 +
  278 +/**
  279 + * mmc_get_mmc_dev() - get the MMC struct pointer for a device
  280 + *
  281 + * Provided that the device is already probed and ready for use, this value
  282 + * will be available.
  283 + *
  284 + * @dev: Device
  285 + * @return associated mmc struct pointer if available, else NULL
  286 + */
  287 +struct mmc *mmc_get_mmc_dev(struct udevice *dev);
  288 +
  289 +/* End of driver model support */
  290 +
269 291 struct mmc_cid {
270 292 unsigned long psn;
271 293 unsigned short oid;