Skip to content

Commit e23350b

Browse files
ahunter6storulf
authored andcommitted
mmc: core: Factor out common code in drive strength selection
Make a new function out of common code used for drive strength selection. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent f168359 commit e23350b

File tree

4 files changed

+46
-46
lines changed

4 files changed

+46
-46
lines changed

drivers/mmc/core/core.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,44 @@ void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type)
16391639
mmc_host_clk_release(host);
16401640
}
16411641

1642+
int mmc_select_drive_strength(struct mmc_card *card, unsigned int max_dtr,
1643+
int card_drv_type, int *drv_type)
1644+
{
1645+
struct mmc_host *host = card->host;
1646+
int host_drv_type = SD_DRIVER_TYPE_B;
1647+
int drive_strength;
1648+
1649+
*drv_type = 0;
1650+
1651+
if (!host->ops->select_drive_strength)
1652+
return 0;
1653+
1654+
/* Use SD definition of driver strength for hosts */
1655+
if (host->caps & MMC_CAP_DRIVER_TYPE_A)
1656+
host_drv_type |= SD_DRIVER_TYPE_A;
1657+
1658+
if (host->caps & MMC_CAP_DRIVER_TYPE_C)
1659+
host_drv_type |= SD_DRIVER_TYPE_C;
1660+
1661+
if (host->caps & MMC_CAP_DRIVER_TYPE_D)
1662+
host_drv_type |= SD_DRIVER_TYPE_D;
1663+
1664+
/*
1665+
* The drive strength that the hardware can support
1666+
* depends on the board design. Pass the appropriate
1667+
* information and let the hardware specific code
1668+
* return what is possible given the options
1669+
*/
1670+
mmc_host_clk_hold(host);
1671+
drive_strength = host->ops->select_drive_strength(card, max_dtr,
1672+
host_drv_type,
1673+
card_drv_type,
1674+
drv_type);
1675+
mmc_host_clk_release(host);
1676+
1677+
return drive_strength;
1678+
}
1679+
16421680
/*
16431681
* Apply power to the MMC stack. This is a two-stage process.
16441682
* First, we enable power to the card without the clock running.

drivers/mmc/core/core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage, u32 ocr);
5050
int __mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage);
5151
void mmc_set_timing(struct mmc_host *host, unsigned int timing);
5252
void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type);
53+
int mmc_select_drive_strength(struct mmc_card *card, unsigned int max_dtr,
54+
int card_drv_type, int *drv_type);
5355
void mmc_power_up(struct mmc_host *host, u32 ocr);
5456
void mmc_power_off(struct mmc_host *host);
5557
void mmc_power_cycle(struct mmc_host *host, u32 ocr);

drivers/mmc/core/sd.c

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -386,35 +386,14 @@ int mmc_sd_switch_hs(struct mmc_card *card)
386386

387387
static int sd_select_driver_type(struct mmc_card *card, u8 *status)
388388
{
389-
int host_drv_type = SD_DRIVER_TYPE_B;
390389
int card_drv_type, drive_strength, drv_type;
391390
int err;
392391

393-
if (!card->host->ops->select_drive_strength)
394-
return 0;
395-
396-
if (card->host->caps & MMC_CAP_DRIVER_TYPE_A)
397-
host_drv_type |= SD_DRIVER_TYPE_A;
398-
399-
if (card->host->caps & MMC_CAP_DRIVER_TYPE_C)
400-
host_drv_type |= SD_DRIVER_TYPE_C;
401-
402-
if (card->host->caps & MMC_CAP_DRIVER_TYPE_D)
403-
host_drv_type |= SD_DRIVER_TYPE_D;
404-
405392
card_drv_type = card->sw_caps.sd3_drv_type | SD_DRIVER_TYPE_B;
406393

407-
/*
408-
* The drive strength that the hardware can support
409-
* depends on the board design. Pass the appropriate
410-
* information and let the hardware specific code
411-
* return what is possible given the options
412-
*/
413-
mmc_host_clk_hold(card->host);
414-
drive_strength = card->host->ops->select_drive_strength(card,
415-
card->sw_caps.uhs_max_dtr,
416-
host_drv_type, card_drv_type, &drv_type);
417-
mmc_host_clk_release(card->host);
394+
drive_strength = mmc_select_drive_strength(card,
395+
card->sw_caps.uhs_max_dtr,
396+
card_drv_type, &drv_type);
418397

419398
if (drive_strength) {
420399
err = mmc_sd_switch(card, 1, 2, drive_strength, status);

drivers/mmc/core/sdio.c

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -402,34 +402,15 @@ static unsigned char host_drive_to_sdio_drive(int host_strength)
402402

403403
static void sdio_select_driver_type(struct mmc_card *card)
404404
{
405-
int host_drv_type = SD_DRIVER_TYPE_B;
406405
int card_drv_type, drive_strength, drv_type;
407406
unsigned char card_strength;
408407
int err;
409408

410-
if (!card->host->ops->select_drive_strength)
411-
return;
412-
413-
if (card->host->caps & MMC_CAP_DRIVER_TYPE_A)
414-
host_drv_type |= SD_DRIVER_TYPE_A;
415-
416-
if (card->host->caps & MMC_CAP_DRIVER_TYPE_C)
417-
host_drv_type |= SD_DRIVER_TYPE_C;
418-
419-
if (card->host->caps & MMC_CAP_DRIVER_TYPE_D)
420-
host_drv_type |= SD_DRIVER_TYPE_D;
421-
422409
card_drv_type = card->sw_caps.sd3_drv_type | SD_DRIVER_TYPE_B;
423410

424-
/*
425-
* The drive strength that the hardware can support
426-
* depends on the board design. Pass the appropriate
427-
* information and let the hardware specific code
428-
* return what is possible given the options
429-
*/
430-
drive_strength = card->host->ops->select_drive_strength(card,
431-
card->sw_caps.uhs_max_dtr,
432-
host_drv_type, card_drv_type, &drv_type);
411+
drive_strength = mmc_select_drive_strength(card,
412+
card->sw_caps.uhs_max_dtr,
413+
card_drv_type, &drv_type);
433414

434415
if (drive_strength) {
435416
/* if error just use default for drive strength B */

0 commit comments

Comments
 (0)