Skip to content

Commit 075162d

Browse files
MaureenHelmcarlescufi
authored andcommitted
disk: Convert usdhc driver to new gpio api
Converts the usdhc driver to the new gpio api. Updates the device tree for the mimxrt1050_evk board to set appropriate active high/low polarity for the power and card detect pins. Note that the driver doesn't actually support interrupts yet. It initializes a gpio callback for the card detect pin, but never actually enables the gpio interrupt. This incomplete behavior is left as-is, since the purpose of this patch is only to convert the driver to the new gpio api, not to add new features. Signed-off-by: Maureen Helm <[email protected]>
1 parent ffba0ab commit 075162d

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

boards/arm/mimxrt1050_evk/mimxrt1050_evk.dts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,6 @@ arduino_serial: &uart3 {};
125125

126126
&usdhc1 {
127127
status = "okay";
128-
pwr-gpios = <&gpio1 5 0>;
129-
cd-gpios = <&gpio2 28 0>;
128+
pwr-gpios = <&gpio1 5 GPIO_ACTIVE_HIGH>;
129+
cd-gpios = <&gpio2 28 GPIO_ACTIVE_LOW>;
130130
};

dts/bindings/mmc/nxp,imx-usdhc.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@ properties:
1818
type: phandle-array
1919
required: false
2020
description: Power pin
21+
This pin defaults to active high when consumed by the SD card. The
22+
property value should ensure the flags properly describe the signal
23+
that is presented to the driver.
2124

2225
cd-gpios:
2326
type: phandle-array
2427
required: false
2528
description: Detect pin
29+
This pin defaults to active low when produced by the SD card. The
30+
property value should ensure the flags properly describe the signal
31+
that is presented to the driver.
2632

2733
label:
2834
required: true

subsys/disk/disk_access_usdhc.c

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,11 @@ struct usdhc_client_info {
439439
struct usdhc_board_config {
440440
struct device *pwr_gpio;
441441
u32_t pwr_pin;
442-
int pwr_flags;
442+
gpio_devicetree_flags_t pwr_flags;
443443

444444
struct device *detect_gpio;
445445
u32_t detect_pin;
446+
gpio_devicetree_flags_t detect_flags;
446447
struct gpio_callback detect_cb;
447448
};
448449

@@ -712,8 +713,6 @@ enum usdhc_reset {
712713
/*!< All reset types */
713714
};
714715

715-
#define HOST_CARD_INSERT_CD_LEVEL (0U)
716-
717716
static void usdhc_millsec_delay(unsigned int cycles_to_wait)
718717
{
719718
unsigned int start = z_timer_cycle_get_32();
@@ -2226,17 +2225,17 @@ static void usdhc_cd_gpio_cb(struct device *dev,
22262225
struct usdhc_board_config *board_cfg =
22272226
CONTAINER_OF(cb, struct usdhc_board_config, detect_cb);
22282227

2229-
gpio_pin_disable_callback(dev, board_cfg->detect_pin);
2230-
2228+
gpio_pin_interrupt_configure(dev, board_cfg->detect_pin,
2229+
GPIO_INT_DISABLE);
22312230
}
22322231

22332232
static int usdhc_cd_gpio_init(struct device *detect_gpio,
2234-
u32_t pin, struct gpio_callback *callback)
2233+
u32_t pin, gpio_devicetree_flags_t flags,
2234+
struct gpio_callback *callback)
22352235
{
22362236
int ret;
22372237

2238-
ret = gpio_pin_configure(detect_gpio, pin,
2239-
GPIO_DIR_IN | GPIO_INT_DOUBLE_EDGE);
2238+
ret = gpio_pin_configure(detect_gpio, pin, GPIO_INPUT | flags);
22402239
if (ret)
22412240
return ret;
22422241

@@ -2616,6 +2615,8 @@ static int usdhc_board_access_init(struct usdhc_priv *priv)
26162615
}
26172616
priv->board_cfg.detect_pin =
26182617
DT_INST_0_NXP_IMX_USDHC_CD_GPIOS_PIN;
2618+
priv->board_cfg.detect_flags =
2619+
DT_INST_0_NXP_IMX_USDHC_CD_GPIOS_FLAGS;
26192620
#endif
26202621

26212622
} else if (priv->nusdhc == 1) {
@@ -2641,6 +2642,8 @@ static int usdhc_board_access_init(struct usdhc_priv *priv)
26412642
}
26422643
priv->board_cfg.detect_pin =
26432644
DT_INST_1_NXP_IMX_USDHC_CD_GPIOS_PIN;
2645+
priv->board_cfg.detect_flags =
2646+
DT_INST_1_NXP_IMX_USDHC_CD_GPIOS_FLAGS;
26442647
#endif
26452648
} else {
26462649
return -ENODEV;
@@ -2649,6 +2652,7 @@ static int usdhc_board_access_init(struct usdhc_priv *priv)
26492652
if (priv->board_cfg.pwr_gpio) {
26502653
ret = gpio_pin_configure(priv->board_cfg.pwr_gpio,
26512654
priv->board_cfg.pwr_pin,
2655+
GPIO_OUTPUT_ACTIVE |
26522656
priv->board_cfg.pwr_flags);
26532657
if (ret) {
26542658
return ret;
@@ -2658,13 +2662,6 @@ static int usdhc_board_access_init(struct usdhc_priv *priv)
26582662
* maybe could be shorter
26592663
*/
26602664
k_busy_wait(100000);
2661-
if (priv->board_cfg.pwr_flags & (GPIO_DIR_OUT)) {
2662-
ret = gpio_pin_write(priv->board_cfg.pwr_gpio,
2663-
priv->board_cfg.pwr_pin, 1);
2664-
if (ret) {
2665-
return ret;
2666-
}
2667-
}
26682665
}
26692666

26702667
if (!priv->board_cfg.detect_gpio) {
@@ -2674,18 +2671,20 @@ static int usdhc_board_access_init(struct usdhc_priv *priv)
26742671

26752672
ret = usdhc_cd_gpio_init(priv->board_cfg.detect_gpio,
26762673
priv->board_cfg.detect_pin,
2674+
priv->board_cfg.detect_flags,
26772675
&priv->board_cfg.detect_cb);
26782676
if (ret) {
26792677
return ret;
26802678
}
2681-
ret = gpio_pin_read(priv->board_cfg.detect_gpio,
2682-
priv->board_cfg.detect_pin,
2683-
&gpio_level);
2684-
if (ret) {
2679+
ret = gpio_pin_get(priv->board_cfg.detect_gpio,
2680+
priv->board_cfg.detect_pin);
2681+
if (ret < 0) {
26852682
return ret;
26862683
}
26872684

2688-
if (gpio_level != HOST_CARD_INSERT_CD_LEVEL) {
2685+
gpio_level = ret;
2686+
2687+
if (gpio_level == 0) {
26892688
priv->inserted = false;
26902689
LOG_ERR("NO SD inserted!\r\n");
26912690

0 commit comments

Comments
 (0)