2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2015-06-23 21:38:48 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Google, Inc
|
2020-06-17 10:08:58 +00:00
|
|
|
* Copyright 2020 NXP
|
2015-06-23 21:38:48 +00:00
|
|
|
* Written by Simon Glass <sjg@chromium.org>
|
|
|
|
*/
|
|
|
|
|
2021-04-27 09:02:19 +00:00
|
|
|
#define LOG_CATEGORY UCLASS_MMC
|
|
|
|
|
2015-06-23 21:38:48 +00:00
|
|
|
#include <common.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2015-06-23 21:38:48 +00:00
|
|
|
#include <mmc.h>
|
|
|
|
#include <dm.h>
|
2016-06-13 05:30:16 +00:00
|
|
|
#include <dm/device-internal.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <dm/device_compat.h>
|
2015-06-23 21:38:48 +00:00
|
|
|
#include <dm/lists.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <linux/compat.h>
|
2016-06-13 05:30:16 +00:00
|
|
|
#include "mmc_private.h"
|
2015-06-23 21:38:48 +00:00
|
|
|
|
2021-05-30 23:31:50 +00:00
|
|
|
static int dm_mmc_get_b_max(struct udevice *dev, void *dst, lbaint_t blkcnt)
|
2020-04-04 10:45:05 +00:00
|
|
|
{
|
|
|
|
struct dm_mmc_ops *ops = mmc_get_ops(dev);
|
|
|
|
struct mmc *mmc = mmc_get_mmc_dev(dev);
|
|
|
|
|
|
|
|
if (ops->get_b_max)
|
|
|
|
return ops->get_b_max(dev, dst, blkcnt);
|
|
|
|
else
|
|
|
|
return mmc->cfg->b_max;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mmc_get_b_max(struct mmc *mmc, void *dst, lbaint_t blkcnt)
|
|
|
|
{
|
|
|
|
return dm_mmc_get_b_max(mmc->dev, dst, blkcnt);
|
|
|
|
}
|
|
|
|
|
2021-05-30 23:31:50 +00:00
|
|
|
static int dm_mmc_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
|
2016-06-13 05:30:22 +00:00
|
|
|
struct mmc_data *data)
|
|
|
|
{
|
|
|
|
struct mmc *mmc = mmc_get_mmc_dev(dev);
|
|
|
|
struct dm_mmc_ops *ops = mmc_get_ops(dev);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mmmc_trace_before_send(mmc, cmd);
|
|
|
|
if (ops->send_cmd)
|
|
|
|
ret = ops->send_cmd(dev, cmd, data);
|
|
|
|
else
|
|
|
|
ret = -ENOSYS;
|
|
|
|
mmmc_trace_after_send(mmc, cmd, ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
|
|
|
|
{
|
|
|
|
return dm_mmc_send_cmd(mmc->dev, cmd, data);
|
|
|
|
}
|
|
|
|
|
2021-05-30 23:31:50 +00:00
|
|
|
static int dm_mmc_set_ios(struct udevice *dev)
|
2016-06-13 05:30:22 +00:00
|
|
|
{
|
|
|
|
struct dm_mmc_ops *ops = mmc_get_ops(dev);
|
|
|
|
|
|
|
|
if (!ops->set_ios)
|
|
|
|
return -ENOSYS;
|
|
|
|
return ops->set_ios(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
int mmc_set_ios(struct mmc *mmc)
|
|
|
|
{
|
|
|
|
return dm_mmc_set_ios(mmc->dev);
|
|
|
|
}
|
|
|
|
|
2021-05-30 23:31:50 +00:00
|
|
|
static int dm_mmc_wait_dat0(struct udevice *dev, int state, int timeout_us)
|
2017-09-21 14:30:07 +00:00
|
|
|
{
|
|
|
|
struct dm_mmc_ops *ops = mmc_get_ops(dev);
|
|
|
|
|
|
|
|
if (!ops->wait_dat0)
|
|
|
|
return -ENOSYS;
|
2019-08-14 19:52:51 +00:00
|
|
|
return ops->wait_dat0(dev, state, timeout_us);
|
2017-09-21 14:30:07 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 19:52:51 +00:00
|
|
|
int mmc_wait_dat0(struct mmc *mmc, int state, int timeout_us)
|
2017-09-21 14:30:07 +00:00
|
|
|
{
|
2019-08-14 19:52:51 +00:00
|
|
|
return dm_mmc_wait_dat0(mmc->dev, state, timeout_us);
|
2017-09-21 14:30:07 +00:00
|
|
|
}
|
|
|
|
|
2021-05-30 23:31:50 +00:00
|
|
|
static int dm_mmc_get_wp(struct udevice *dev)
|
2016-06-13 05:30:22 +00:00
|
|
|
{
|
|
|
|
struct dm_mmc_ops *ops = mmc_get_ops(dev);
|
|
|
|
|
|
|
|
if (!ops->get_wp)
|
|
|
|
return -ENOSYS;
|
|
|
|
return ops->get_wp(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
int mmc_getwp(struct mmc *mmc)
|
|
|
|
{
|
|
|
|
return dm_mmc_get_wp(mmc->dev);
|
|
|
|
}
|
|
|
|
|
2021-05-30 23:31:50 +00:00
|
|
|
static int dm_mmc_get_cd(struct udevice *dev)
|
2016-06-13 05:30:22 +00:00
|
|
|
{
|
|
|
|
struct dm_mmc_ops *ops = mmc_get_ops(dev);
|
|
|
|
|
|
|
|
if (!ops->get_cd)
|
|
|
|
return -ENOSYS;
|
|
|
|
return ops->get_cd(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
int mmc_getcd(struct mmc *mmc)
|
|
|
|
{
|
|
|
|
return dm_mmc_get_cd(mmc->dev);
|
|
|
|
}
|
|
|
|
|
2017-11-30 16:44:01 +00:00
|
|
|
#ifdef MMC_SUPPORTS_TUNING
|
2021-05-30 23:31:50 +00:00
|
|
|
static int dm_mmc_execute_tuning(struct udevice *dev, uint opcode)
|
2017-09-21 14:30:05 +00:00
|
|
|
{
|
|
|
|
struct dm_mmc_ops *ops = mmc_get_ops(dev);
|
|
|
|
|
|
|
|
if (!ops->execute_tuning)
|
|
|
|
return -ENOSYS;
|
|
|
|
return ops->execute_tuning(dev, opcode);
|
|
|
|
}
|
|
|
|
|
|
|
|
int mmc_execute_tuning(struct mmc *mmc, uint opcode)
|
|
|
|
{
|
|
|
|
return dm_mmc_execute_tuning(mmc->dev, opcode);
|
|
|
|
}
|
2017-11-30 16:44:01 +00:00
|
|
|
#endif
|
2017-09-21 14:30:05 +00:00
|
|
|
|
2019-07-10 06:43:07 +00:00
|
|
|
#if CONFIG_IS_ENABLED(MMC_HS400_ES_SUPPORT)
|
2021-05-30 23:31:50 +00:00
|
|
|
static int dm_mmc_set_enhanced_strobe(struct udevice *dev)
|
2019-07-10 06:43:07 +00:00
|
|
|
{
|
|
|
|
struct dm_mmc_ops *ops = mmc_get_ops(dev);
|
|
|
|
|
|
|
|
if (ops->set_enhanced_strobe)
|
|
|
|
return ops->set_enhanced_strobe(dev);
|
|
|
|
|
|
|
|
return -ENOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mmc_set_enhanced_strobe(struct mmc *mmc)
|
|
|
|
{
|
|
|
|
return dm_mmc_set_enhanced_strobe(mmc->dev);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-05-30 23:31:50 +00:00
|
|
|
static int dm_mmc_hs400_prepare_ddr(struct udevice *dev)
|
2020-09-01 08:58:04 +00:00
|
|
|
{
|
|
|
|
struct dm_mmc_ops *ops = mmc_get_ops(dev);
|
|
|
|
|
|
|
|
if (ops->hs400_prepare_ddr)
|
|
|
|
return ops->hs400_prepare_ddr(dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mmc_hs400_prepare_ddr(struct mmc *mmc)
|
|
|
|
{
|
|
|
|
return dm_mmc_hs400_prepare_ddr(mmc->dev);
|
|
|
|
}
|
|
|
|
|
2021-05-30 23:31:50 +00:00
|
|
|
static int dm_mmc_host_power_cycle(struct udevice *dev)
|
2019-09-19 15:56:12 +00:00
|
|
|
{
|
|
|
|
struct dm_mmc_ops *ops = mmc_get_ops(dev);
|
|
|
|
|
|
|
|
if (ops->host_power_cycle)
|
|
|
|
return ops->host_power_cycle(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mmc_host_power_cycle(struct mmc *mmc)
|
|
|
|
{
|
|
|
|
return dm_mmc_host_power_cycle(mmc->dev);
|
|
|
|
}
|
|
|
|
|
2021-05-30 23:31:50 +00:00
|
|
|
static int dm_mmc_deferred_probe(struct udevice *dev)
|
2020-02-26 08:14:30 +00:00
|
|
|
{
|
|
|
|
struct dm_mmc_ops *ops = mmc_get_ops(dev);
|
|
|
|
|
|
|
|
if (ops->deferred_probe)
|
|
|
|
return ops->deferred_probe(dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mmc_deferred_probe(struct mmc *mmc)
|
|
|
|
{
|
|
|
|
return dm_mmc_deferred_probe(mmc->dev);
|
|
|
|
}
|
|
|
|
|
2021-05-30 23:31:50 +00:00
|
|
|
static int dm_mmc_reinit(struct udevice *dev)
|
2020-09-01 08:57:59 +00:00
|
|
|
{
|
|
|
|
struct dm_mmc_ops *ops = mmc_get_ops(dev);
|
|
|
|
|
|
|
|
if (ops->reinit)
|
|
|
|
return ops->reinit(dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mmc_reinit(struct mmc *mmc)
|
|
|
|
{
|
|
|
|
return dm_mmc_reinit(mmc->dev);
|
|
|
|
}
|
|
|
|
|
2017-11-30 16:43:55 +00:00
|
|
|
int mmc_of_parse(struct udevice *dev, struct mmc_config *cfg)
|
2017-09-21 14:30:13 +00:00
|
|
|
{
|
|
|
|
int val;
|
|
|
|
|
2017-11-30 16:43:55 +00:00
|
|
|
val = dev_read_u32_default(dev, "bus-width", 1);
|
2017-09-21 14:30:13 +00:00
|
|
|
|
|
|
|
switch (val) {
|
|
|
|
case 0x8:
|
|
|
|
cfg->host_caps |= MMC_MODE_8BIT;
|
|
|
|
/* fall through */
|
|
|
|
case 0x4:
|
|
|
|
cfg->host_caps |= MMC_MODE_4BIT;
|
|
|
|
/* fall through */
|
|
|
|
case 0x1:
|
|
|
|
cfg->host_caps |= MMC_MODE_1BIT;
|
|
|
|
break;
|
|
|
|
default:
|
2017-12-29 17:00:07 +00:00
|
|
|
dev_err(dev, "Invalid \"bus-width\" value %u!\n", val);
|
|
|
|
return -EINVAL;
|
2017-09-21 14:30:13 +00:00
|
|
|
}
|
|
|
|
|
2017-12-29 17:00:06 +00:00
|
|
|
/* f_max is obtained from the optional "max-frequency" property */
|
|
|
|
dev_read_u32(dev, "max-frequency", &cfg->f_max);
|
2017-09-21 14:30:13 +00:00
|
|
|
|
2017-11-30 16:43:55 +00:00
|
|
|
if (dev_read_bool(dev, "cap-sd-highspeed"))
|
2017-09-21 14:30:13 +00:00
|
|
|
cfg->host_caps |= MMC_CAP(SD_HS);
|
2017-11-30 16:43:55 +00:00
|
|
|
if (dev_read_bool(dev, "cap-mmc-highspeed"))
|
2020-09-15 19:51:46 +00:00
|
|
|
cfg->host_caps |= MMC_CAP(MMC_HS) | MMC_CAP(MMC_HS_52);
|
2017-11-30 16:43:55 +00:00
|
|
|
if (dev_read_bool(dev, "sd-uhs-sdr12"))
|
2017-09-21 14:30:13 +00:00
|
|
|
cfg->host_caps |= MMC_CAP(UHS_SDR12);
|
2017-11-30 16:43:55 +00:00
|
|
|
if (dev_read_bool(dev, "sd-uhs-sdr25"))
|
2017-09-21 14:30:13 +00:00
|
|
|
cfg->host_caps |= MMC_CAP(UHS_SDR25);
|
2017-11-30 16:43:55 +00:00
|
|
|
if (dev_read_bool(dev, "sd-uhs-sdr50"))
|
2017-09-21 14:30:13 +00:00
|
|
|
cfg->host_caps |= MMC_CAP(UHS_SDR50);
|
2017-11-30 16:43:55 +00:00
|
|
|
if (dev_read_bool(dev, "sd-uhs-sdr104"))
|
2017-09-21 14:30:13 +00:00
|
|
|
cfg->host_caps |= MMC_CAP(UHS_SDR104);
|
2017-11-30 16:43:55 +00:00
|
|
|
if (dev_read_bool(dev, "sd-uhs-ddr50"))
|
2017-09-21 14:30:13 +00:00
|
|
|
cfg->host_caps |= MMC_CAP(UHS_DDR50);
|
2017-11-30 16:43:55 +00:00
|
|
|
if (dev_read_bool(dev, "mmc-ddr-1_8v"))
|
2017-09-21 14:30:13 +00:00
|
|
|
cfg->host_caps |= MMC_CAP(MMC_DDR_52);
|
2017-11-30 16:43:55 +00:00
|
|
|
if (dev_read_bool(dev, "mmc-ddr-1_2v"))
|
|
|
|
cfg->host_caps |= MMC_CAP(MMC_DDR_52);
|
|
|
|
if (dev_read_bool(dev, "mmc-hs200-1_8v"))
|
|
|
|
cfg->host_caps |= MMC_CAP(MMC_HS_200);
|
|
|
|
if (dev_read_bool(dev, "mmc-hs200-1_2v"))
|
2017-09-21 14:30:13 +00:00
|
|
|
cfg->host_caps |= MMC_CAP(MMC_HS_200);
|
2018-06-13 04:50:16 +00:00
|
|
|
if (dev_read_bool(dev, "mmc-hs400-1_8v"))
|
|
|
|
cfg->host_caps |= MMC_CAP(MMC_HS_400);
|
|
|
|
if (dev_read_bool(dev, "mmc-hs400-1_2v"))
|
|
|
|
cfg->host_caps |= MMC_CAP(MMC_HS_400);
|
2019-07-10 09:35:18 +00:00
|
|
|
if (dev_read_bool(dev, "mmc-hs400-enhanced-strobe"))
|
|
|
|
cfg->host_caps |= MMC_CAP(MMC_HS_400_ES);
|
2017-09-21 14:30:13 +00:00
|
|
|
|
2019-06-25 11:39:02 +00:00
|
|
|
if (dev_read_bool(dev, "non-removable")) {
|
|
|
|
cfg->host_caps |= MMC_CAP_NONREMOVABLE;
|
|
|
|
} else {
|
|
|
|
if (dev_read_bool(dev, "cd-inverted"))
|
|
|
|
cfg->host_caps |= MMC_CAP_CD_ACTIVE_HIGH;
|
|
|
|
if (dev_read_bool(dev, "broken-cd"))
|
|
|
|
cfg->host_caps |= MMC_CAP_NEEDS_POLL;
|
|
|
|
}
|
|
|
|
|
2019-07-10 09:35:20 +00:00
|
|
|
if (dev_read_bool(dev, "no-1-8-v")) {
|
|
|
|
cfg->host_caps &= ~(UHS_CAPS | MMC_MODE_HS200 |
|
|
|
|
MMC_MODE_HS400 | MMC_MODE_HS400_ES);
|
|
|
|
}
|
|
|
|
|
2017-09-21 14:30:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-08 14:33:00 +00:00
|
|
|
struct mmc *mmc_get_mmc_dev(const struct udevice *dev)
|
2015-06-23 21:38:48 +00:00
|
|
|
{
|
|
|
|
struct mmc_uclass_priv *upriv;
|
|
|
|
|
|
|
|
if (!device_active(dev))
|
|
|
|
return NULL;
|
|
|
|
upriv = dev_get_uclass_priv(dev);
|
|
|
|
return upriv->mmc;
|
|
|
|
}
|
|
|
|
|
2017-07-04 19:31:19 +00:00
|
|
|
#if CONFIG_IS_ENABLED(BLK)
|
2016-05-01 19:52:39 +00:00
|
|
|
struct mmc *find_mmc_device(int dev_num)
|
|
|
|
{
|
|
|
|
struct udevice *dev, *mmc_dev;
|
|
|
|
int ret;
|
|
|
|
|
2017-05-27 17:37:19 +00:00
|
|
|
ret = blk_find_device(IF_TYPE_MMC, dev_num, &dev);
|
2016-05-01 19:52:39 +00:00
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
#if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
|
|
|
|
printf("MMC Device %d not found\n", dev_num);
|
|
|
|
#endif
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
mmc_dev = dev_get_parent(dev);
|
|
|
|
|
2017-05-27 17:37:19 +00:00
|
|
|
struct mmc *mmc = mmc_get_mmc_dev(mmc_dev);
|
|
|
|
|
|
|
|
return mmc;
|
2016-05-01 19:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int get_mmc_num(void)
|
|
|
|
{
|
2016-07-22 09:22:50 +00:00
|
|
|
return max((blk_find_max_devnum(IF_TYPE_MMC) + 1), 0);
|
2016-05-01 19:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int mmc_get_next_devnum(void)
|
|
|
|
{
|
2016-10-13 15:13:18 +00:00
|
|
|
return blk_find_max_devnum(IF_TYPE_MMC);
|
2016-05-01 19:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct blk_desc *mmc_get_blk_desc(struct mmc *mmc)
|
|
|
|
{
|
|
|
|
struct blk_desc *desc;
|
|
|
|
struct udevice *dev;
|
|
|
|
|
|
|
|
device_find_first_child(mmc->dev, &dev);
|
|
|
|
if (!dev)
|
|
|
|
return NULL;
|
2020-12-03 23:55:18 +00:00
|
|
|
desc = dev_get_uclass_plat(dev);
|
2016-05-01 19:52:39 +00:00
|
|
|
|
|
|
|
return desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void mmc_do_preinit(void)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
struct uclass *uc;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = uclass_get(UCLASS_MMC, &uc);
|
|
|
|
if (ret)
|
|
|
|
return;
|
|
|
|
uclass_foreach_dev(dev, uc) {
|
|
|
|
struct mmc *m = mmc_get_mmc_dev(dev);
|
|
|
|
|
|
|
|
if (!m)
|
|
|
|
continue;
|
|
|
|
if (m->preinit)
|
|
|
|
mmc_start_init(m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
|
|
|
|
void print_mmc_devices(char separator)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
char *mmc_type;
|
|
|
|
bool first = true;
|
|
|
|
|
|
|
|
for (uclass_first_device(UCLASS_MMC, &dev);
|
|
|
|
dev;
|
2016-07-23 03:11:22 +00:00
|
|
|
uclass_next_device(&dev), first = false) {
|
2016-05-01 19:52:39 +00:00
|
|
|
struct mmc *m = mmc_get_mmc_dev(dev);
|
|
|
|
|
|
|
|
if (!first) {
|
|
|
|
printf("%c", separator);
|
|
|
|
if (separator != '\n')
|
|
|
|
puts(" ");
|
|
|
|
}
|
|
|
|
if (m->has_init)
|
|
|
|
mmc_type = IS_SD(m) ? "SD" : "eMMC";
|
|
|
|
else
|
|
|
|
mmc_type = NULL;
|
|
|
|
|
|
|
|
printf("%s: %d", m->cfg->name, mmc_get_blk_desc(m)->devnum);
|
|
|
|
if (mmc_type)
|
|
|
|
printf(" (%s)", mmc_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
void print_mmc_devices(char separator) { }
|
|
|
|
#endif
|
2016-06-13 05:30:16 +00:00
|
|
|
|
|
|
|
int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg)
|
|
|
|
{
|
|
|
|
struct blk_desc *bdesc;
|
|
|
|
struct udevice *bdev;
|
2021-03-25 07:18:48 +00:00
|
|
|
int ret;
|
2017-02-02 04:41:14 +00:00
|
|
|
|
2017-04-24 02:02:09 +00:00
|
|
|
if (!mmc_get_ops(dev))
|
|
|
|
return -ENOSYS;
|
2021-03-25 07:18:48 +00:00
|
|
|
|
|
|
|
/* Use the fixed index with aliases node's index */
|
|
|
|
debug("%s: alias devnum=%d\n", __func__, dev_seq(dev));
|
2016-06-13 05:30:16 +00:00
|
|
|
|
2017-02-02 04:41:14 +00:00
|
|
|
ret = blk_create_devicef(dev, "mmc_blk", "blk", IF_TYPE_MMC,
|
2021-03-25 07:18:48 +00:00
|
|
|
dev_seq(dev), 512, 0, &bdev);
|
2016-06-13 05:30:16 +00:00
|
|
|
if (ret) {
|
|
|
|
debug("Cannot create block device\n");
|
|
|
|
return ret;
|
|
|
|
}
|
2020-12-03 23:55:18 +00:00
|
|
|
bdesc = dev_get_uclass_plat(bdev);
|
2016-06-13 05:30:16 +00:00
|
|
|
mmc->cfg = cfg;
|
|
|
|
mmc->priv = dev;
|
|
|
|
|
|
|
|
/* the following chunk was from mmc_register() */
|
|
|
|
|
|
|
|
/* Setup dsr related values */
|
|
|
|
mmc->dsr_imp = 0;
|
|
|
|
mmc->dsr = 0xffffffff;
|
|
|
|
/* Setup the universal parts of the block interface just once */
|
|
|
|
bdesc->removable = 1;
|
|
|
|
|
|
|
|
/* setup initial part type */
|
|
|
|
bdesc->part_type = cfg->part_type;
|
|
|
|
mmc->dev = dev;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mmc_unbind(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct udevice *bdev;
|
|
|
|
|
|
|
|
device_find_first_child(dev, &bdev);
|
|
|
|
if (bdev) {
|
2017-03-20 11:51:48 +00:00
|
|
|
device_remove(bdev, DM_REMOVE_NORMAL);
|
2016-06-13 05:30:16 +00:00
|
|
|
device_unbind(bdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_select_hwpart(struct udevice *bdev, int hwpart)
|
|
|
|
{
|
|
|
|
struct udevice *mmc_dev = dev_get_parent(bdev);
|
|
|
|
struct mmc *mmc = mmc_get_mmc_dev(mmc_dev);
|
2020-12-03 23:55:18 +00:00
|
|
|
struct blk_desc *desc = dev_get_uclass_plat(bdev);
|
2019-08-27 07:32:19 +00:00
|
|
|
int ret;
|
2016-06-13 05:30:16 +00:00
|
|
|
|
|
|
|
if (desc->hwpart == hwpart)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (mmc->part_config == MMCPART_NOAVAILABLE)
|
|
|
|
return -EMEDIUMTYPE;
|
|
|
|
|
2019-08-27 07:32:19 +00:00
|
|
|
ret = mmc_switch_part(mmc, hwpart);
|
|
|
|
if (!ret)
|
|
|
|
blkcache_invalidate(desc->if_type, desc->devnum);
|
|
|
|
|
|
|
|
return ret;
|
2016-06-13 05:30:16 +00:00
|
|
|
}
|
|
|
|
|
2017-01-25 09:00:24 +00:00
|
|
|
static int mmc_blk_probe(struct udevice *dev)
|
|
|
|
{
|
2017-04-24 02:02:10 +00:00
|
|
|
struct udevice *mmc_dev = dev_get_parent(dev);
|
|
|
|
struct mmc_uclass_priv *upriv = dev_get_uclass_priv(mmc_dev);
|
|
|
|
struct mmc *mmc = upriv->mmc;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = mmc_init(mmc);
|
|
|
|
if (ret) {
|
|
|
|
debug("%s: mmc_init() failed (err=%d)\n", __func__, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2017-01-25 09:00:24 +00:00
|
|
|
|
2017-04-24 02:02:10 +00:00
|
|
|
return 0;
|
2017-01-25 09:00:24 +00:00
|
|
|
}
|
|
|
|
|
2019-01-29 03:45:51 +00:00
|
|
|
#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) || \
|
|
|
|
CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \
|
|
|
|
CONFIG_IS_ENABLED(MMC_HS400_SUPPORT)
|
|
|
|
static int mmc_blk_remove(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct udevice *mmc_dev = dev_get_parent(dev);
|
|
|
|
struct mmc_uclass_priv *upriv = dev_get_uclass_priv(mmc_dev);
|
|
|
|
struct mmc *mmc = upriv->mmc;
|
|
|
|
|
|
|
|
return mmc_deinit(mmc);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-06-13 05:30:16 +00:00
|
|
|
static const struct blk_ops mmc_blk_ops = {
|
|
|
|
.read = mmc_bread,
|
2018-01-04 14:23:32 +00:00
|
|
|
#if CONFIG_IS_ENABLED(MMC_WRITE)
|
2016-06-13 05:30:16 +00:00
|
|
|
.write = mmc_bwrite,
|
2016-10-01 20:43:17 +00:00
|
|
|
.erase = mmc_berase,
|
2016-06-13 05:30:16 +00:00
|
|
|
#endif
|
|
|
|
.select_hwpart = mmc_select_hwpart,
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(mmc_blk) = {
|
|
|
|
.name = "mmc_blk",
|
|
|
|
.id = UCLASS_BLK,
|
|
|
|
.ops = &mmc_blk_ops,
|
2017-01-25 09:00:24 +00:00
|
|
|
.probe = mmc_blk_probe,
|
2019-01-29 03:45:51 +00:00
|
|
|
#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) || \
|
|
|
|
CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \
|
|
|
|
CONFIG_IS_ENABLED(MMC_HS400_SUPPORT)
|
|
|
|
.remove = mmc_blk_remove,
|
|
|
|
.flags = DM_FLAG_OS_PREPARE,
|
|
|
|
#endif
|
2016-06-13 05:30:16 +00:00
|
|
|
};
|
2016-05-01 19:52:39 +00:00
|
|
|
#endif /* CONFIG_BLK */
|
|
|
|
|
2015-06-23 21:38:48 +00:00
|
|
|
|
|
|
|
UCLASS_DRIVER(mmc) = {
|
|
|
|
.id = UCLASS_MMC,
|
|
|
|
.name = "mmc",
|
|
|
|
.flags = DM_UC_FLAG_SEQ_ALIAS,
|
2020-12-03 23:55:17 +00:00
|
|
|
.per_device_auto = sizeof(struct mmc_uclass_priv),
|
2015-06-23 21:38:48 +00:00
|
|
|
};
|