Skip to content

Commit

Permalink
drivers: sdhc: imx_usdhc: assume card is present if no detection method
Browse files Browse the repository at this point in the history
The imx USDHC driver previously queried the peripheral's internal card
detect signal to check card presence if no card detect method was
configured. However, some boards do not route the card detect signal and
do not work correctly with the DAT3 detection method supported by this
peripheral. As a fallback, assume the card is present in the slot but
log a warning to the user.

Fixes zephyrproject-rtos#42227

(cherry picked from commit 17f71e1)

Original-Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
GitOrigin-RevId: 17f71e1
Cr-Build-Id: 8738819815572775377
Cr-Build-Url: https://cr-buildbucket.appspot.com/build/8738819815572775377
Copybot-Job-Name: zephyr-main-copybot-downstream
Change-Id: I2205284a9c94d4f9b6b0592ab17417686b4ead19
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5807813
Reviewed-by: Eric Yilun Lin <yllin@google.com>
Tested-by: Eric Yilun Lin <yllin@google.com>
Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Commit-Queue: Eric Yilun Lin <yllin@google.com>
  • Loading branch information
danieldegrasse authored and Chromeos LUCI committed Aug 23, 2024
1 parent 1689893 commit ca6adec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
12 changes: 11 additions & 1 deletion drivers/sdhc/imx_usdhc.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct usdhc_config {
const struct gpio_dt_spec pwr_gpio;
const struct gpio_dt_spec detect_gpio;
bool detect_dat3;
bool detect_cd;
bool no_180_vol;
uint32_t data_timeout;
uint32_t read_watermark;
Expand Down Expand Up @@ -809,10 +810,18 @@ static int imx_usdhc_get_card_present(const struct device *dev)
imx_usdhc_dat3_pull(cfg, true);
USDHC_CardDetectByData3(cfg->base, false);
}
} else if (cfg->detect_cd) {
/*
* Detect the card via the USDHC_CD signal internal to
* the peripheral
*/
data->card_present = USDHC_DetectCardInsert(cfg->base);
} else if (cfg->detect_gpio.port) {
data->card_present = gpio_pin_get_dt(&cfg->detect_gpio) > 0;
} else {
data->card_present = USDHC_DetectCardInsert(cfg->base);
LOG_WRN("No card detection method configured, assuming card "
"is present");
data->card_present = true;
}
return ((int)data->card_present);
}
Expand Down Expand Up @@ -1090,6 +1099,7 @@ static const struct sdhc_driver_api usdhc_api = {
.detect_gpio = GPIO_DT_SPEC_INST_GET_OR(n, cd_gpios, {0}), \
.data_timeout = DT_INST_PROP(n, data_timeout), \
.detect_dat3 = DT_INST_PROP(n, detect_dat3), \
.detect_cd = DT_INST_PROP(n, detect_cd), \
.no_180_vol = DT_INST_PROP(n, no_1_8_v), \
.read_watermark = DT_INST_PROP(n, read_watermark), \
.write_watermark = DT_INST_PROP(n, write_watermark), \
Expand Down
7 changes: 7 additions & 0 deletions dts/bindings/sdhc/nxp,imx-usdhc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,10 @@ properties:
Enable the host to detect an SD card via the DAT3 line of the SD card
connection. Requires the board to define a function to pull DAT3 low or
high using pullup/pulldown resistors.
detect-cd:
type: boolean
description: |
Use the host's internal card detect signal (USDHC_CD) to detect the SD
card. This signal is available as an alternative to card detect via GPIO,
and should be connected to the SD slot's detect pin if used.

0 comments on commit ca6adec

Please sign in to comment.