Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: sdhc: imx_usdhc: assume card is present if no detection method #77301

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/releases/migration-guide-4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ Interrupt Controller
LED Strip
=========

SDHC
====

* The NXP USDHC driver now assumes a card is present if no card detect method
is configured, instead of using the peripheral's internal card detect signal
to check for card presence. To use the internal card detect signal, the
devicetree property ``detect-cd`` should be added to the USDHC node in use.

Sensors
=======

Expand Down
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 @@
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 @@
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 @@
.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 Expand Up @@ -1119,6 +1129,6 @@
&usdhc_##n##_config, \
POST_KERNEL, \
CONFIG_SDHC_INIT_PRIORITY, \
&usdhc_api);

Check notice on line 1132 in drivers/sdhc/imx_usdhc.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

drivers/sdhc/imx_usdhc.c:1132 - - -#define IMX_USDHC_INIT(n) \ - static void usdhc_##n##_irq_config_func(const struct device *dev) \ - { \ - IRQ_CONNECT(DT_INST_IRQN(n), DT_INST_IRQ(n, priority), \ - imx_usdhc_isr, DEVICE_DT_INST_GET(n), 0); \ - irq_enable(DT_INST_IRQN(n)); \ - } \ - \ - PINCTRL_DT_INST_DEFINE(n); \ - \ - static const struct usdhc_config usdhc_##n##_config = { \ - .base = (USDHC_Type *) DT_INST_REG_ADDR(n), \ - .clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(n)), \ - .clock_subsys = \ - (clock_control_subsys_t)DT_INST_CLOCKS_CELL(n, name), \ - .nusdhc = n, \ - .pwr_gpio = GPIO_DT_SPEC_INST_GET_OR(n, pwr_gpios, {0}), \ - .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), \ - .max_current_330 = DT_INST_PROP(n, max_current_330), \ - .max_current_180 = DT_INST_PROP(n, max_current_180), \ - .min_bus_freq = DT_INST_PROP(n, min_bus_freq), \ - .max_bus_freq = DT_INST_PROP(n, max_bus_freq), \ - .power_delay_ms = DT_INST_PROP(n, power_delay_ms), \ - .mmc_hs200_1_8v = DT_INST_PROP(n, mmc_hs200_1_8v), \ - .mmc_hs400_1_8v = DT_INST_PROP(n, mmc_hs400_1_8v), \ - .irq_config_func = usdhc_##n##_irq_config_func, \ - .pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \ - }; \ - \ - \ - IMX_USDHC_DMA_BUFFER_DEFINE(n) \ - \ - static struct usdhc_data usdhc_##n##_data = { \ - .card_present = false, \ - IMX_USDHC_DMA_BUFFER_INIT(n) \ - }; \ - \ - DEVICE_DT_INST_DEFINE(n, \ - &imx_usdhc_init, \ - NULL, \ - &usdhc_##n##_data, \ - &usdhc_##n##_config, \ - POST_KERNEL, \ - CONFIG_SDHC_INIT_PRIORITY, \ - &usdhc_api); +#define IMX_USDHC_INIT(n) \ + static void usdhc_##n##_irq_config_func(const struct device *dev) \ + { \ + IRQ_CONNECT(DT_INST_IRQN(n), DT_INST_IRQ(n, priority), imx_usdhc_isr, \ + DEVICE_DT_INST_GET(n), 0); \ + irq_enable(DT_INST_IRQN(n)); \ + } \ + \ + PINCTRL_DT_INST_DEFINE(n); \ + \ + static const struct usdhc_config usdhc_##n##_config = { \ + .base = (USDHC_Type *)DT_INST_REG_ADDR(n), \ + .clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(n)), \ + .clock_subsys = (clock_control_subsys_t)DT_INST_CLOCKS_CELL(n, name), \ + .nusdhc = n, \ + .pwr_gpio = GPIO_DT_SPEC_INST_GET_OR(n, pwr_gpios, {0}), \ + .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), \ + .wri

DT_INST_FOREACH_STATUS_OKAY(IMX_USDHC_INIT)
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.
Loading