MMC: davinici_mmc: Enable CD and WP with DM and OF_CONTROL
PATCH 1/1 MMC: davinici_mmc: Enable CD and WP with DM and OF_CONTROL
When used with a device tree, this will extract the card detect and write protect pins from the device tree and configure them accordingly. This assumes the GPIO_ACTIVE_LOW/HIGH is supported byt da8xx_gpio.
drivers/mmc/davinci_mmc.c +38 -0
@@ -15,6 +15,7 @@#include <malloc.h> #include <asm/io.h> #include <asm/arch/sdmmc_defs.h> +#include <asm-generic/gpio.h> #define DAVINCI_MAX_BLOCKS (32)#define WATCHDOG_COUNT (100000)
@@ -35,6 +36,8 @@ struct davinci_mmc_priv {struct davinci_mmc_regs *reg_base;/* Register base address */ uint input_clk;/* Input clock to MMC controller */ uint version;/* MMC Controller version */ +struct gpio_desc cd_gpio;/* Card Detect GPIO */ +struct gpio_desc wp_gpio;/* Write Protect GPIO */ };struct davinci_mmc_plat
@@ -425,9 +428,38 @@ static const struct mmc_ops dmmc_ops = { .init = dmmc_init, };#else + +static int davinci_mmc_getcd (struct udevice *dev) +{ +struct davinci_mmc_priv *priv =dev_get_priv (dev); +int value; + + value =dm_gpio_get_value (&priv->cd_gpio); +/* if no CD return as 1 */ +if (value <0 ) +return 1 ; + +return value; +} + +static int davinci_mmc_getwp (struct udevice *dev) +{ +struct davinci_mmc_priv *priv =dev_get_priv (dev); +int value; + + value =dm_gpio_get_value (&priv->wp_gpio); +/* if no WP return as 0 */ +if (value <0 ) +return 0 ; + +return value; +} +static const struct dm_mmc_ops davinci_mmc_ops = { .send_cmd = davinci_mmc_send_cmd, .set_ios = davinci_mmc_set_ios, + .get_cd = davinci_mmc_getcd, + .get_wp = davinci_mmc_getwp, };#endif
@@ -475,6 +507,12 @@ static int davinci_mmc_probe(struct udevice *dev) priv->reg_base = (struct davinci_mmc_regs *)dev_read_addr (dev); priv->input_clk =clk_get (DAVINCI_MMCSD_CLKID ); +#if CONFIG_IS_ENABLED (DM_GPIO ) +/* These GPIOs are optional */ +gpio_request_by_name (dev,"cd-gpios" ,0 , &priv->cd_gpio,GPIOD_IS_IN ); +gpio_request_by_name (dev,"wp-gpios" ,0 , &priv->wp_gpio,GPIOD_IS_IN ); +#endif + upriv->mmc = &plat->mmc;return davinci_dm_mmc_init (dev);
Signature · 1 line
2.17.1
PATCH 1/1 MMC: davinici_mmc: Enable CD and WP with DM and OF_CONTROL
Quoted 31 lines · Adam Ford
When used with a device tree, this will extract the card detect and write protect pins from the device tree and configure them accordingly. This assumes the GPIO_ACTIVE_LOW/HIGH is supported byt
da8xx_gpio.Signed-off-by Adam Ford <[email protected]>drivers/mmc/davinci_mmc.c +1
-0@@ -15,6 +15,7 @@#include <malloc.h> #include <asm/io.h> #include <asm/arch/sdmmc_defs.h> +#include <asm-generic/gpio.h> #define DAVINCI_MAX_BLOCKS (32)#define WATCHDOG_COUNT (100000)@@ -35,6 +36,8 @@ struct davinci_mmc_priv {struct davinci_mmc_regs *reg_base;/* Register base address */
uintinput_clk; /* Input clock to MMC
controller */drivers/mmc/davinci_mmc.c +2
-0uint version;/* MMC Controller version */ +struct gpio_desc cd_gpio;/* Card Detect GPIO */ +struct gpio_desc wp_gpio;/* Write Protect GPIO */ };struct davinci_mmc_plat
drivers/mmc/davinci_mmc.c static const struct mmc_ops dmmc_ops = { · line 431
Quoted 4 lines
drivers/mmc/davinci_mmc.c +1
-0@@ -425,9 +428,38 @@ static const struct mmc_ops dmmc_ops = { .init = dmmc_init, };#else +
The two new functions here - davinci_mmc_getcd() and davinci_mmc_getwp() - also need to be wrapped in a check for DM_GPIO being enabled, otherwise dm_gpio_get_value() isn't built.
Quoted 21 lines
drivers/mmc/davinci_mmc.c +21
-0+static int davinci_mmc_getcd (struct udevice *dev) +{ +struct davinci_mmc_priv *priv =dev_get_priv (dev); +int value; + + value =dm_gpio_get_value (&priv->cd_gpio); +/* if no CD return as 1 */ +if (value <0 ) +return 1 ; + +return value; +} + +static int davinci_mmc_getwp (struct udevice *dev) +{ +struct davinci_mmc_priv *priv =dev_get_priv (dev); +int value; + + value =dm_gpio_get_value (&priv->wp_gpio); +/* if no WP return as 0 */ +if (value <0 )
drivers/mmc/davinci_mmc.c static const struct mmc_ops dmmc_ops = { · line 462
Quoted 10 lines
drivers/mmc/davinci_mmc.c +7
-0+return 0 ; + +return value; +} +static const struct dm_mmc_ops davinci_mmc_ops = { .send_cmd = davinci_mmc_send_cmd, .set_ios = davinci_mmc_set_ios, + .get_cd = davinci_mmc_getcd, + .get_wp = davinci_mmc_getwp,
Again the assignment of .get_cd and .get_wp need to be wrapped in a check for DM_GPIO.
Quoted 15 lines
drivers/mmc/davinci_mmc.c +4
-0};#endif @@ -475,6 +507,12 @@ static int davinci_mmc_probe(struct udevice *dev) priv->reg_base = (struct davinci_mmc_regs *)dev_read_addr (dev); priv->input_clk =clk_get (DAVINCI_MMCSD_CLKID ); +#if CONFIG_IS_ENABLED (DM_GPIO ) +/* These GPIOs are optional */ +gpio_request_by_name (dev,"cd-gpios" ,0 , &priv->cd_gpio,GPIOD_IS_IN ); + gpio_request_by_name(dev, "wp-gpios", 0, &priv->wp_gpio,
GPIOD_IS_IN);
drivers/mmc/davinci_mmc.c static int davinci_mmc_probe(struct udevice *dev) · line 518
Quoted 5 lines
drivers/mmc/davinci_mmc.c +2
-0+#endif + upriv->mmc = &plat->mmc;return davinci_dm_mmc_init (dev);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: This is a digitally signed message part
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180823/b22ab938/attachment.sig>
PATCH 1/1 MMC: davinici_mmc: Enable CD and WP with DM and OF_CONTROL
Quoted 31 lines · Peter Howard
Quoted 29 lines · Adam Ford
When used with a device tree, this will extract the card detect and write protect pins from the device tree and configure them accordingly. This assumes the GPIO_ACTIVE_LOW/HIGH is supported byt
da8xx_gpio.Signed-off-by Adam Ford <[email protected]>drivers/mmc/davinci_mmc.c +1
-0@@ -15,6 +15,7 @@#include <malloc.h> #include <asm/io.h> #include <asm/arch/sdmmc_defs.h> +#include <asm-generic/gpio.h> #define DAVINCI_MAX_BLOCKS (32)#define WATCHDOG_COUNT (100000)@@ -35,6 +36,8 @@ struct davinci_mmc_priv {struct davinci_mmc_regs *reg_base;/* Register base address */
uintinput_clk; /* Input clock to MMC
controller */
uint version; /* MMC Controller version */drivers/mmc/davinci_mmc.c +2
-0+struct gpio_desc cd_gpio;/* Card Detect GPIO */ +struct gpio_desc wp_gpio;/* Write Protect GPIO */ };
Quoted 10 lines
drivers/mmc/davinci_mmc.c static const struct mmc_ops dmmc_ops = { · line 431
Quoted 6 lines
struct
davinci_mmc_platdrivers/mmc/davinci_mmc.c +1
-0@@ -425,9 +428,38 @@ static const struct mmc_ops dmmc_ops = { .init = dmmc_init, };#else +The two new functions here -
davinci_mmc_getcd()anddavinci_mmc_getwp()- also need to be wrapped in a check forDM_GPIObeing enabled, otherwisedm_gpio_get_value()isn't built.
Good catch. I'm on vacation now in London, but I'll be home Sept 4. I should be able to post a V2 around then.
adam
Quoted 57 lines
Quoted 23 lines
drivers/mmc/davinci_mmc.c +21
-0+static int davinci_mmc_getcd (struct udevice *dev) +{ +struct davinci_mmc_priv *priv =dev_get_priv (dev); +int value; + + value =dm_gpio_get_value (&priv->cd_gpio); +/* if no CD return as 1 */ +if (value <0 ) +return 1 ; + +return value; +} + +static int davinci_mmc_getwp (struct udevice *dev) +{ +struct davinci_mmc_priv *priv =dev_get_priv (dev); +int value; + + value =dm_gpio_get_value (&priv->wp_gpio); +/* if no WP return as 0 */ +if (value <0 )drivers/mmc/davinci_mmc.c static const struct mmc_ops dmmc_ops = { · line 462
Quoted 10 lines
drivers/mmc/davinci_mmc.c +7
-0+return 0 ; + +return value; +} +static const struct dm_mmc_ops davinci_mmc_ops = { .send_cmd = davinci_mmc_send_cmd, .set_ios = davinci_mmc_set_ios, + .get_cd = davinci_mmc_getcd, + .get_wp = davinci_mmc_getwp,Again the assignment of .get_cd and .get_wp need to be wrapped in a check for
DM_GPIO.Quoted 20 lines
drivers/mmc/davinci_mmc.c +4
-0};#endif @@ -475,6 +507,12 @@ static int davinci_mmc_probe(struct udevice *dev) priv->reg_base = (struct davinci_mmc_regs *)dev_read_addr (dev); priv->input_clk =clk_get (DAVINCI_MMCSD_CLKID ); +#if CONFIG_IS_ENABLED (DM_GPIO ) +/* These GPIOs are optional */ +gpio_request_by_name (dev,"cd-gpios" ,0 , &priv->cd_gpio,GPIOD_IS_IN ); + gpio_request_by_name(dev, "wp-gpios", 0, &priv->wp_gpio,
GPIOD_IS_IN);drivers/mmc/davinci_mmc.c +2
-0+#endif + upriv->mmc = &plat->mmc;return davinci_dm_mmc_init (dev);