CI: https://source.denx.de/u-boot/custodians/u-boot-mmc/-/pipelines/29066

- mmc: Fix sdhci-cadence6 license
- mmc: Fix sd_get_capabilities retry logic
- mmc: use max-frequency from device tree
- Clean up regulator and build fix
This commit is contained in:
Tom Rini
2026-01-22 08:36:35 -06:00
4 changed files with 73 additions and 66 deletions

View File

@@ -243,8 +243,12 @@ int mmc_of_parse(struct udevice *dev, struct mmc_config *cfg)
return -EINVAL; return -EINVAL;
} }
/* f_max is obtained from the optional "max-frequency" property */ /*
dev_read_u32(dev, "max-frequency", &cfg->f_max); * Maximum frequency is obtained from the optional "max-frequency" DT property.
* Use dev_read_u32_default() to preserve the driver-set f_max value when
* "max-frequency" is not present, ensuring the controller's default is used.
*/
cfg->f_max = dev_read_u32_default(dev, "max-frequency", cfg->f_max);
if (dev_read_bool(dev, "cap-sd-highspeed")) if (dev_read_bool(dev, "cap-sd-highspeed"))
cfg->host_caps |= MMC_CAP(SD_HS); cfg->host_caps |= MMC_CAP(SD_HS);

View File

@@ -1382,6 +1382,7 @@ static int sd_get_capabilities(struct mmc *mmc)
ALLOC_CACHE_ALIGN_BUFFER(__be32, switch_status, 16); ALLOC_CACHE_ALIGN_BUFFER(__be32, switch_status, 16);
struct mmc_data data; struct mmc_data data;
int timeout; int timeout;
uint retries = 3;
mmc->card_caps = MMC_MODE_1BIT | MMC_CAP(MMC_LEGACY); mmc->card_caps = MMC_MODE_1BIT | MMC_CAP(MMC_LEGACY);
@@ -1389,25 +1390,26 @@ static int sd_get_capabilities(struct mmc *mmc)
return 0; return 0;
/* Read the SCR to find out if this card supports higher speeds */ /* Read the SCR to find out if this card supports higher speeds */
cmd.cmdidx = MMC_CMD_APP_CMD; do {
cmd.resp_type = MMC_RSP_R1; cmd.cmdidx = MMC_CMD_APP_CMD;
cmd.cmdarg = mmc->rca << 16; cmd.resp_type = MMC_RSP_R1;
cmd.cmdarg = mmc->rca << 16;
err = mmc_send_cmd(mmc, &cmd, NULL); err = mmc_send_cmd(mmc, &cmd, NULL);
if (err)
continue;
if (err) cmd.cmdidx = SD_CMD_APP_SEND_SCR;
return err; cmd.resp_type = MMC_RSP_R1;
cmd.cmdarg = 0;
cmd.cmdidx = SD_CMD_APP_SEND_SCR; data.dest = (char *)scr;
cmd.resp_type = MMC_RSP_R1; data.blocksize = 8;
cmd.cmdarg = 0; data.blocks = 1;
data.flags = MMC_DATA_READ;
data.dest = (char *)scr; err = mmc_send_cmd(mmc, &cmd, &data);
data.blocksize = 8; } while (err && retries--);
data.blocks = 1;
data.flags = MMC_DATA_READ;
err = mmc_send_cmd_retry(mmc, &cmd, &data, 3);
if (err) if (err)
return err; return err;

View File

@@ -1,4 +1,4 @@
// SPDX-License-Identifier: GPL-2.0-or-platform_driver // SPDX-License-Identifier: GPL-2.0+
/* /*
* Copyright (C) 2023 Starfive. * Copyright (C) 2023 Starfive.
* Author: Kuan Lim Lee <kuanlim.lee@starfivetech.com> * Author: Kuan Lim Lee <kuanlim.lee@starfivetech.com>

View File

@@ -27,12 +27,14 @@ int regulator_common_of_to_plat(struct udevice *dev,
/* Get optional enable GPIO desc */ /* Get optional enable GPIO desc */
gpio = &plat->gpio; gpio = &plat->gpio;
ret = gpio_request_by_name(dev, enable_gpio_name, 0, gpio, flags); if (CONFIG_IS_ENABLED(DM_GPIO)) {
if (ret) { ret = gpio_request_by_name(dev, enable_gpio_name, 0, gpio, flags);
debug("Regulator '%s' optional enable GPIO - not found! Error: %d\n", if (ret) {
dev->name, ret); debug("Regulator '%s' optional enable GPIO - not found! Error: %d\n",
if (ret != -ENOENT) dev->name, ret);
return ret; if (ret != -ENOENT)
return ret;
}
} }
/* Get optional ramp up delay */ /* Get optional ramp up delay */
@@ -51,10 +53,10 @@ int regulator_common_get_enable(const struct udevice *dev,
struct regulator_common_plat *plat) struct regulator_common_plat *plat)
{ {
/* Enable GPIO is optional */ /* Enable GPIO is optional */
if (!plat->gpio.dev) if (CONFIG_IS_ENABLED(DM_GPIO) && dm_gpio_is_valid(&plat->gpio))
return true; return dm_gpio_get_value(&plat->gpio);
return dm_gpio_get_value(&plat->gpio); return true;
} }
int regulator_common_set_enable(const struct udevice *dev, int regulator_common_set_enable(const struct udevice *dev,
@@ -65,48 +67,47 @@ int regulator_common_set_enable(const struct udevice *dev,
debug("%s: dev='%s', enable=%d, delay=%d, has_gpio=%d\n", __func__, debug("%s: dev='%s', enable=%d, delay=%d, has_gpio=%d\n", __func__,
dev->name, enable, plat->startup_delay_us, dev->name, enable, plat->startup_delay_us,
dm_gpio_is_valid(&plat->gpio)); dm_gpio_is_valid(&plat->gpio));
/* Enable GPIO is optional */ /* Enable GPIO is optional */
if (!dm_gpio_is_valid(&plat->gpio)) { if (CONFIG_IS_ENABLED(DM_GPIO) && dm_gpio_is_valid(&plat->gpio)) {
if (!enable) /* If previously enabled, increase count */
return -ENOSYS; if (enable && plat->enable_count > 0) {
return 0; plat->enable_count++;
}
/* If previously enabled, increase count */
if (enable && plat->enable_count > 0) {
plat->enable_count++;
return -EALREADY;
}
if (!enable) {
if (plat->enable_count > 1) {
/* If enabled multiple times, decrease count */
plat->enable_count--;
return -EBUSY;
} else if (!plat->enable_count) {
/* If already disabled, do nothing */
return -EALREADY; return -EALREADY;
} }
if (!enable) {
if (plat->enable_count > 1) {
/* If enabled multiple times, decrease count */
plat->enable_count--;
return -EBUSY;
} else if (!plat->enable_count) {
/* If already disabled, do nothing */
return -EALREADY;
}
}
ret = dm_gpio_set_value(&plat->gpio, enable);
if (ret) {
pr_err("Can't set regulator : %s gpio to: %d\n", dev->name,
enable);
return ret;
}
if (enable && plat->startup_delay_us)
udelay(plat->startup_delay_us);
if (!enable && plat->off_on_delay_us)
udelay(plat->off_on_delay_us);
if (enable)
plat->enable_count++;
else
plat->enable_count--;
} else {
ret = enable ? 0 : -ENOSYS;
} }
ret = dm_gpio_set_value(&plat->gpio, enable); return ret;
if (ret) {
pr_err("Can't set regulator : %s gpio to: %d\n", dev->name,
enable);
return ret;
}
if (enable && plat->startup_delay_us)
udelay(plat->startup_delay_us);
debug("%s: done\n", __func__);
if (!enable && plat->off_on_delay_us)
udelay(plat->off_on_delay_us);
if (enable)
plat->enable_count++;
else
plat->enable_count--;
return 0;
} }