Skip to content

Commit 0cb22df

Browse files
committed
drivers: disk: sdmmc_stm32: Update driver to use gpio_dt_spec
Move driver to use gpio_dt_spec for GPIO access. Signed-off-by: Kumar Gala <[email protected]>
1 parent 213eaee commit 0cb22df

File tree

1 file changed

+19
-43
lines changed

1 file changed

+19
-43
lines changed

drivers/disk/sdmmc_stm32.c

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,8 @@ struct stm32_sdmmc_priv {
4444
int status;
4545
struct k_work work;
4646
struct gpio_callback cd_cb;
47-
struct {
48-
const char *name;
49-
const struct device *port;
50-
int pin;
51-
int flags;
52-
} cd;
53-
struct {
54-
const char *name;
55-
const struct device *port;
56-
int pin;
57-
int flags;
58-
} pe;
47+
struct gpio_dt_spec cd;
48+
struct gpio_dt_spec pe;
5949
struct stm32_pclken pclken;
6050
const struct pinctrl_dev_config *pcfg;
6151
};
@@ -318,11 +308,11 @@ static bool stm32_sdmmc_card_present(struct stm32_sdmmc_priv *priv)
318308
{
319309
int err;
320310

321-
if (!priv->cd.name) {
311+
if (!priv->cd.port) {
322312
return true;
323313
}
324314

325-
err = gpio_pin_get(priv->cd.port, priv->cd.pin);
315+
err = gpio_pin_get_dt(&priv->cd);
326316
if (err < 0) {
327317
LOG_WRN("reading card detect failed %d", err);
328318
return true;
@@ -361,12 +351,11 @@ static int stm32_sdmmc_card_detect_init(struct stm32_sdmmc_priv *priv)
361351
{
362352
int err;
363353

364-
if (!priv->cd.name) {
354+
if (!priv->cd.port) {
365355
return 0;
366356
}
367357

368-
priv->cd.port = device_get_binding(priv->cd.name);
369-
if (!priv->cd.port) {
358+
if (!device_is_ready(priv->cd.port)) {
370359
return -ENODEV;
371360
}
372361

@@ -378,35 +367,32 @@ static int stm32_sdmmc_card_detect_init(struct stm32_sdmmc_priv *priv)
378367
return err;
379368
}
380369

381-
err = gpio_pin_configure(priv->cd.port, priv->cd.pin,
382-
priv->cd.flags | GPIO_INPUT);
370+
err = gpio_pin_configure_dt(&priv->cd, GPIO_INPUT);
383371
if (err) {
384372
goto remove_callback;
385373
}
386374

387-
err = gpio_pin_interrupt_configure(priv->cd.port, priv->cd.pin,
388-
GPIO_INT_EDGE_BOTH);
375+
err = gpio_pin_interrupt_configure_dt(&priv->cd, GPIO_INT_EDGE_BOTH);
389376
if (err) {
390377
goto unconfigure_pin;
391378
}
392379
return 0;
393380

394381
unconfigure_pin:
395-
gpio_pin_configure(priv->cd.port, priv->cd.pin, GPIO_DISCONNECTED);
382+
gpio_pin_configure_dt(&priv->cd, GPIO_DISCONNECTED);
396383
remove_callback:
397384
gpio_remove_callback(priv->cd.port, &priv->cd_cb);
398385
return err;
399386
}
400387

401388
static int stm32_sdmmc_card_detect_uninit(struct stm32_sdmmc_priv *priv)
402389
{
403-
if (!priv->cd.name) {
390+
if (!priv->cd.port) {
404391
return 0;
405392
}
406393

407-
gpio_pin_interrupt_configure(priv->cd.port, priv->cd.pin,
408-
GPIO_INT_MODE_DISABLED);
409-
gpio_pin_configure(priv->cd.port, priv->cd.pin, GPIO_DISCONNECTED);
394+
gpio_pin_interrupt_configure_dt(&priv->cd, GPIO_INT_MODE_DISABLED);
395+
gpio_pin_configure_dt(&priv->cd, GPIO_DISCONNECTED);
410396
gpio_remove_callback(priv->cd.port, &priv->cd_cb);
411397
return 0;
412398
}
@@ -415,17 +401,15 @@ static int stm32_sdmmc_pwr_init(struct stm32_sdmmc_priv *priv)
415401
{
416402
int err;
417403

418-
if (!priv->pe.name) {
404+
if (!priv->pe.port) {
419405
return 0;
420406
}
421407

422-
priv->pe.port = device_get_binding(priv->pe.name);
423-
if (!priv->pe.port) {
408+
if (!device_is_ready(priv->pe.port)) {
424409
return -ENODEV;
425410
}
426411

427-
err = gpio_pin_configure(priv->pe.port, priv->pe.pin,
428-
priv->pe.flags | GPIO_OUTPUT_ACTIVE);
412+
err = gpio_pin_configure_dt(&priv->pe, GPIO_OUTPUT_ACTIVE);
429413
if (err) {
430414
return err;
431415
}
@@ -437,11 +421,11 @@ static int stm32_sdmmc_pwr_init(struct stm32_sdmmc_priv *priv)
437421

438422
static int stm32_sdmmc_pwr_uninit(struct stm32_sdmmc_priv *priv)
439423
{
440-
if (!priv->pe.name) {
424+
if (!priv->pe.port) {
441425
return 0;
442426
}
443427

444-
gpio_pin_configure(priv->pe.port, priv->pe.pin, GPIO_DISCONNECTED);
428+
gpio_pin_configure_dt(&priv->pe, GPIO_DISCONNECTED);
445429
return 0;
446430
}
447431

@@ -522,18 +506,10 @@ static struct stm32_sdmmc_priv stm32_sdmmc_priv_1 = {
522506
.Init.BusWide = SDMMC_BUS_WIDTH,
523507
},
524508
#if DT_INST_NODE_HAS_PROP(0, cd_gpios)
525-
.cd = {
526-
.name = DT_INST_GPIO_LABEL(0, cd_gpios),
527-
.pin = DT_INST_GPIO_PIN(0, cd_gpios),
528-
.flags = DT_INST_GPIO_FLAGS(0, cd_gpios),
529-
},
509+
.cd = GPIO_DT_SPEC_INST_GET(0, cd_gpios),
530510
#endif
531511
#if DT_INST_NODE_HAS_PROP(0, pwr_gpios)
532-
.pe = {
533-
.name = DT_INST_GPIO_LABEL(0, pwr_gpios),
534-
.pin = DT_INST_GPIO_PIN(0, pwr_gpios),
535-
.flags = DT_INST_GPIO_FLAGS(0, pwr_gpios),
536-
},
512+
.pe = GPIO_DT_SPEC_INST_GET(0, pwr_gpios),
537513
#endif
538514
.pclken = {
539515
.bus = DT_INST_CLOCKS_CELL(0, bus),

0 commit comments

Comments
 (0)