@@ -1223,6 +1223,7 @@ EXPORT_SYMBOL_GPL(sdhci_set_clock);
12231223static void sdhci_set_power (struct sdhci_host * host , unsigned char mode ,
12241224 unsigned short vdd )
12251225{
1226+ struct mmc_host * mmc = host -> mmc ;
12261227 u8 pwr = 0 ;
12271228
12281229 if (mode != MMC_POWER_OFF ) {
@@ -1284,9 +1285,9 @@ static void sdhci_set_power(struct sdhci_host *host, unsigned char mode,
12841285 mdelay (10 );
12851286 }
12861287
1287- if (host -> vmmc ) {
1288+ if (! IS_ERR ( mmc -> supply . vmmc ) ) {
12881289 spin_unlock_irq (& host -> lock );
1289- mmc_regulator_set_ocr (host -> mmc , host -> vmmc , vdd );
1290+ mmc_regulator_set_ocr (host -> mmc , mmc -> supply . vmmc , vdd );
12901291 spin_lock_irq (& host -> lock );
12911292 }
12921293}
@@ -1440,13 +1441,15 @@ static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios)
14401441{
14411442 unsigned long flags ;
14421443 u8 ctrl ;
1444+ struct mmc_host * mmc = host -> mmc ;
14431445
14441446 spin_lock_irqsave (& host -> lock , flags );
14451447
14461448 if (host -> flags & SDHCI_DEVICE_DEAD ) {
14471449 spin_unlock_irqrestore (& host -> lock , flags );
1448- if (host -> vmmc && ios -> power_mode == MMC_POWER_OFF )
1449- mmc_regulator_set_ocr (host -> mmc , host -> vmmc , 0 );
1450+ if (!IS_ERR (mmc -> supply .vmmc ) &&
1451+ ios -> power_mode == MMC_POWER_OFF )
1452+ mmc_regulator_set_ocr (host -> mmc , mmc -> supply .vmmc , 0 );
14501453 return ;
14511454 }
14521455
@@ -1707,6 +1710,7 @@ static void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable)
17071710static int sdhci_do_start_signal_voltage_switch (struct sdhci_host * host ,
17081711 struct mmc_ios * ios )
17091712{
1713+ struct mmc_host * mmc = host -> mmc ;
17101714 u16 ctrl ;
17111715 int ret ;
17121716
@@ -1725,8 +1729,9 @@ static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host,
17251729 ctrl &= ~SDHCI_CTRL_VDD_180 ;
17261730 sdhci_writew (host , ctrl , SDHCI_HOST_CONTROL2 );
17271731
1728- if (host -> vqmmc ) {
1729- ret = regulator_set_voltage (host -> vqmmc , 2700000 , 3600000 );
1732+ if (!IS_ERR (mmc -> supply .vqmmc )) {
1733+ ret = regulator_set_voltage (mmc -> supply .vqmmc , 2700000 ,
1734+ 3600000 );
17301735 if (ret ) {
17311736 pr_warning ("%s: Switching to 3.3V signalling voltage "
17321737 " failed\n" , mmc_hostname (host -> mmc ));
@@ -1746,8 +1751,8 @@ static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host,
17461751
17471752 return - EAGAIN ;
17481753 case MMC_SIGNAL_VOLTAGE_180 :
1749- if (host -> vqmmc ) {
1750- ret = regulator_set_voltage (host -> vqmmc ,
1754+ if (! IS_ERR ( mmc -> supply . vqmmc ) ) {
1755+ ret = regulator_set_voltage (mmc -> supply . vqmmc ,
17511756 1700000 , 1950000 );
17521757 if (ret ) {
17531758 pr_warning ("%s: Switching to 1.8V signalling voltage "
@@ -1776,8 +1781,9 @@ static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host,
17761781
17771782 return - EAGAIN ;
17781783 case MMC_SIGNAL_VOLTAGE_120 :
1779- if (host -> vqmmc ) {
1780- ret = regulator_set_voltage (host -> vqmmc , 1100000 , 1300000 );
1784+ if (!IS_ERR (mmc -> supply .vqmmc )) {
1785+ ret = regulator_set_voltage (mmc -> supply .vqmmc , 1100000 ,
1786+ 1300000 );
17811787 if (ret ) {
17821788 pr_warning ("%s: Switching to 1.2V signalling voltage "
17831789 " failed\n" , mmc_hostname (host -> mmc ));
@@ -2962,25 +2968,22 @@ int sdhci_add_host(struct sdhci_host *host)
29622968 !(host -> mmc -> caps & MMC_CAP_NONREMOVABLE ))
29632969 mmc -> caps |= MMC_CAP_NEEDS_POLL ;
29642970
2971+ /* If there are external regulators, get them */
2972+ if (mmc_regulator_get_supply (mmc ) == - EPROBE_DEFER )
2973+ return - EPROBE_DEFER ;
2974+
29652975 /* If vqmmc regulator and no 1.8V signalling, then there's no UHS */
2966- host -> vqmmc = regulator_get_optional (mmc_dev (mmc ), "vqmmc" );
2967- if (IS_ERR_OR_NULL (host -> vqmmc )) {
2968- if (PTR_ERR (host -> vqmmc ) < 0 ) {
2969- pr_info ("%s: no vqmmc regulator found\n" ,
2970- mmc_hostname (mmc ));
2971- host -> vqmmc = NULL ;
2972- }
2973- } else {
2974- ret = regulator_enable (host -> vqmmc );
2975- if (!regulator_is_supported_voltage (host -> vqmmc , 1700000 ,
2976- 1950000 ))
2976+ if (!IS_ERR (mmc -> supply .vqmmc )) {
2977+ ret = regulator_enable (mmc -> supply .vqmmc );
2978+ if (!regulator_is_supported_voltage (mmc -> supply .vqmmc , 1700000 ,
2979+ 1950000 ))
29772980 caps [1 ] &= ~(SDHCI_SUPPORT_SDR104 |
29782981 SDHCI_SUPPORT_SDR50 |
29792982 SDHCI_SUPPORT_DDR50 );
29802983 if (ret ) {
29812984 pr_warn ("%s: Failed to enable vqmmc regulator: %d\n" ,
29822985 mmc_hostname (mmc ), ret );
2983- host -> vqmmc = NULL ;
2986+ mmc -> supply . vqmmc = NULL ;
29842987 }
29852988 }
29862989
@@ -3041,34 +3044,6 @@ int sdhci_add_host(struct sdhci_host *host)
30413044
30423045 ocr_avail = 0 ;
30433046
3044- host -> vmmc = regulator_get_optional (mmc_dev (mmc ), "vmmc" );
3045- if (IS_ERR_OR_NULL (host -> vmmc )) {
3046- if (PTR_ERR (host -> vmmc ) < 0 ) {
3047- pr_info ("%s: no vmmc regulator found\n" ,
3048- mmc_hostname (mmc ));
3049- host -> vmmc = NULL ;
3050- }
3051- }
3052-
3053- #ifdef CONFIG_REGULATOR
3054- /*
3055- * Voltage range check makes sense only if regulator reports
3056- * any voltage value.
3057- */
3058- if (host -> vmmc && regulator_get_voltage (host -> vmmc ) > 0 ) {
3059- ret = regulator_is_supported_voltage (host -> vmmc , 2700000 ,
3060- 3600000 );
3061- if ((ret <= 0 ) || (!(caps [0 ] & SDHCI_CAN_VDD_330 )))
3062- caps [0 ] &= ~SDHCI_CAN_VDD_330 ;
3063- if ((ret <= 0 ) || (!(caps [0 ] & SDHCI_CAN_VDD_300 )))
3064- caps [0 ] &= ~SDHCI_CAN_VDD_300 ;
3065- ret = regulator_is_supported_voltage (host -> vmmc , 1700000 ,
3066- 1950000 );
3067- if ((ret <= 0 ) || (!(caps [0 ] & SDHCI_CAN_VDD_180 )))
3068- caps [0 ] &= ~SDHCI_CAN_VDD_180 ;
3069- }
3070- #endif /* CONFIG_REGULATOR */
3071-
30723047 /*
30733048 * According to SD Host Controller spec v3.00, if the Host System
30743049 * can afford more than 150mA, Host Driver should set XPC to 1. Also
@@ -3077,8 +3052,8 @@ int sdhci_add_host(struct sdhci_host *host)
30773052 * value.
30783053 */
30793054 max_current_caps = sdhci_readl (host , SDHCI_MAX_CURRENT );
3080- if (!max_current_caps && host -> vmmc ) {
3081- u32 curr = regulator_get_current_limit (host -> vmmc );
3055+ if (!max_current_caps && ! IS_ERR ( mmc -> supply . vmmc ) ) {
3056+ u32 curr = regulator_get_current_limit (mmc -> supply . vmmc );
30823057 if (curr > 0 ) {
30833058
30843059 /* convert to SDHCI_MAX_CURRENT format */
@@ -3118,8 +3093,11 @@ int sdhci_add_host(struct sdhci_host *host)
31183093 SDHCI_MAX_CURRENT_MULTIPLIER ;
31193094 }
31203095
3096+ if (mmc -> ocr_avail )
3097+ ocr_avail &= mmc -> ocr_avail ;
3098+
31213099 if (host -> ocr_mask )
3122- ocr_avail = host -> ocr_mask ;
3100+ ocr_avail & = host -> ocr_mask ;
31233101
31243102 mmc -> ocr_avail = ocr_avail ;
31253103 mmc -> ocr_avail_sdio = ocr_avail ;
@@ -3273,6 +3251,7 @@ EXPORT_SYMBOL_GPL(sdhci_add_host);
32733251
32743252void sdhci_remove_host (struct sdhci_host * host , int dead )
32753253{
3254+ struct mmc_host * mmc = host -> mmc ;
32763255 unsigned long flags ;
32773256
32783257 if (dead ) {
@@ -3310,15 +3289,11 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)
33103289
33113290 tasklet_kill (& host -> finish_tasklet );
33123291
3313- if (host -> vmmc ) {
3314- regulator_disable (host -> vmmc );
3315- regulator_put (host -> vmmc );
3316- }
3292+ if (!IS_ERR (mmc -> supply .vmmc ))
3293+ regulator_disable (mmc -> supply .vmmc );
33173294
3318- if (host -> vqmmc ) {
3319- regulator_disable (host -> vqmmc );
3320- regulator_put (host -> vqmmc );
3321- }
3295+ if (!IS_ERR (mmc -> supply .vqmmc ))
3296+ regulator_disable (mmc -> supply .vqmmc );
33223297
33233298 if (host -> adma_desc )
33243299 dma_free_coherent (mmc_dev (host -> mmc ), ADMA_SIZE ,
0 commit comments