Date:2013-04-23 21:49:58 (10 years 1 month ago)
Author:Lars C.
Commit:b6d180b87fbaabb5f78ed9105895a4589ea44380
Message:mmc: jz4740: Use a regulator for power control

Files: arch/mips/include/asm/mach-jz4740/jz4740_mmc.h (1 diff)
arch/mips/jz4740/board-a320.c (2 diffs)
arch/mips/jz4740/board-qi_lb60.c (2 diffs)
drivers/mmc/host/jz4740_mmc.c (7 diffs)

Change Details

arch/mips/include/asm/mach-jz4740/jz4740_mmc.h
22#define __LINUX_MMC_JZ4740_MMC
33
44struct jz4740_mmc_platform_data {
5    int gpio_power;
65    int gpio_card_detect;
76    int gpio_read_only;
87    unsigned card_detect_active_low:1;
98    unsigned read_only_active_low:1;
10    unsigned power_active_low:1;
119
1210    unsigned data_1bit:1;
1311};
arch/mips/jz4740/board-a320.c
207207    PWM_LOOKUP("jz4740-pwm", 7, "pwm-backlight", 0),
208208};
209209
210static struct regulator_consumer_supply a320_mmc_regulator_consumer =
211    REGULATOR_SUPPLY("vmmc", "jz4740-mmc.0");
212
213static struct regulator_init_data a320_mmc_regulator_init_data = {
214    .num_consumer_supplies = 1,
215    .consumer_supplies = &a320_mmc_regulator_consumer,
216    .constraints = {
217        .name = "MMC power",
218        .min_uV = 3300000,
219        .max_uV = 3300000,
220        .valid_modes_mask = REGULATOR_MODE_NORMAL,
221        .valid_ops_mask = REGULATOR_CHANGE_STATUS,
222    },
223};
224
225static struct fixed_voltage_config a320_mmc_regulator_data = {
226    .supply_name = "MMC power",
227    .microvolts = 3300000,
228    .init_data = &a320_mmc_regulator_init_data,
229};
230
231static struct platform_device a320_mmc_regulator_device = {
232    .name = "reg-fixed-voltage",
233    .id = -1,
234    .dev = {
235        .platform_data = &a320_mmc_regulator_data,
236    }
237};
238
210239static struct jz4740_mmc_platform_data a320_mmc_pdata = {
211240    .gpio_card_detect = JZ_GPIO_PORTB(29),
212241    .gpio_read_only = -1,
213    .gpio_power = -1,
214    // TODO(MtH): I don't know which GPIO pin the SD power is connected to.
215    // Booboo left power alone, but I don't know why.
216    //.gpio_power = GPIO_SD_VCC_EN_N,
217    //.power_active_low = 1,
218242};
219243
220244/* Battery */
...... 
381405    &a320_backlight_device,
382406    &a320_gpio_keys_device,
383407    &a320_audio_device,
408    &a320_mmc_regulator_device,
384409};
385410
386411static void __init board_gpio_setup(void)
arch/mips/jz4740/board-qi_lb60.c
350350    }
351351};
352352
353static struct regulator_consumer_supply qi_lb60_mmc_regulator_consumer =
354    REGULATOR_SUPPLY("vmmc", "jz4740-mmc.0");
355
356static struct regulator_init_data qi_lb60_mmc_regulator_init_data = {
357    .num_consumer_supplies = 1,
358    .consumer_supplies = &qi_lb60_mmc_regulator_consumer,
359    .constraints = {
360        .name = "MMC power",
361        .min_uV = 3300000,
362        .max_uV = 3300000,
363        .valid_modes_mask = REGULATOR_MODE_NORMAL,
364        .valid_ops_mask = REGULATOR_CHANGE_STATUS,
365    },
366};
367
368static struct fixed_voltage_config qi_lb60_mmc_regulator_data = {
369    .supply_name = "MMC power",
370    .microvolts = 3300000,
371    .gpio = QI_LB60_GPIO_SD_VCC_EN_N,
372    .init_data = &qi_lb60_mmc_regulator_init_data,
373};
374
375static struct platform_device qi_lb60_mmc_regulator_device = {
376    .name = "reg-fixed-voltage",
377    .id = -1,
378    .dev = {
379        .platform_data = &qi_lb60_mmc_regulator_data,
380    }
381};
382
353383static struct jz4740_mmc_platform_data qi_lb60_mmc_pdata = {
354384    .gpio_card_detect = QI_LB60_GPIO_SD_CD,
355385    .gpio_read_only = -1,
356    .gpio_power = QI_LB60_GPIO_SD_VCC_EN_N,
357    .power_active_low = 1,
358386};
359387
360388/* OHCI */
...... 
442470    &qi_lb60_pwm_beeper,
443471    &qi_lb60_charger_device,
444472    &qi_lb60_audio_device,
473    &qi_lb60_mmc_regulator_device,
445474};
446475
447476static void __init board_gpio_setup(void)
drivers/mmc/host/jz4740_mmc.c
634634    switch (ios->power_mode) {
635635    case MMC_POWER_UP:
636636        jz4740_mmc_reset(host);
637        if (gpio_is_valid(host->pdata->gpio_power))
638            gpio_set_value(host->pdata->gpio_power,
639                    !host->pdata->power_active_low);
637        mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, ios->vdd);
640638        host->cmdat |= JZ_MMC_CMDAT_INIT;
641639        clk_prepare_enable(host->clk);
642640        break;
643641    case MMC_POWER_ON:
644642        break;
645643    default:
646        if (gpio_is_valid(host->pdata->gpio_power))
647            gpio_set_value(host->pdata->gpio_power,
648                    host->pdata->power_active_low);
644        mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
649645        clk_disable_unprepare(host->clk);
650646        break;
651647    }
...... 
739735    JZ_GPIO_BULK_PIN(MSC_DATA3),
740736};
741737
742static int jz4740_mmc_request_gpio(struct device *dev, int gpio,
743    const char *name, bool output, int value)
744{
745    int ret;
746
747    if (!gpio_is_valid(gpio))
748        return 0;
749
750    ret = gpio_request(gpio, name);
751    if (ret) {
752        dev_err(dev, "Failed to request %s gpio: %d\n", name, ret);
753        return ret;
754    }
755
756    if (output)
757        gpio_direction_output(gpio, value);
758    else
759        gpio_direction_input(gpio);
760
761    return 0;
762}
763
764738static int jz4740_mmc_request_gpios(struct mmc_host *mmc,
765739    struct platform_device *pdev)
766740{
...... 
781755            return ret;
782756    }
783757
784    if (gpio_is_valid(pdata->gpio_read_only)) {
758    if (gpio_is_valid(pdata->gpio_read_only))
785759        ret = mmc_gpio_request_ro(mmc, pdata->gpio_read_only);
786        if (ret)
787            return ret;
788    }
789
790    return jz4740_mmc_request_gpio(&pdev->dev, pdata->gpio_power,
791            "MMC read only", true, pdata->power_active_low);
792}
793
794static void jz4740_mmc_free_gpios(struct platform_device *pdev)
795{
796    struct jz4740_mmc_platform_data *pdata = pdev->dev.platform_data;
797
798    if (!pdata)
799        return;
800760
801    if (gpio_is_valid(pdata->gpio_power))
802        gpio_free(pdata->gpio_power);
761    return ret;
803762}
804763
805764static inline size_t jz4740_mmc_num_pins(struct jz4740_mmc_host *host)
...... 
869828    if (ret)
870829        goto err_gpio_bulk_free;
871830
831    ret = mmc_regulator_get_supply(mmc);
832    if (ret)
833        goto err_gpio_bulk_free;
834
872835    mmc->ops = &jz4740_mmc_ops;
873836    mmc->f_min = JZ_MMC_CLK_RATE / 128;
874837    mmc->f_max = JZ_MMC_CLK_RATE;
875    mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
876838    mmc->caps = (pdata && pdata->data_1bit) ? 0 : MMC_CAP_4_BIT_DATA;
877839    mmc->caps |= MMC_CAP_SDIO_IRQ;
878840
...... 
892854            dev_name(&pdev->dev), host);
893855    if (ret) {
894856        dev_err(&pdev->dev, "Failed to request irq: %d\n", ret);
895        goto err_free_gpios;
857        goto err_gpio_bulk_free;
896858    }
897859
898860    jz4740_mmc_reset(host);
...... 
915877
916878err_free_irq:
917879    free_irq(host->irq, host);
918err_free_gpios:
919    jz4740_mmc_free_gpios(pdev);
920880err_gpio_bulk_free:
921881    jz_gpio_bulk_free(jz4740_mmc_pins, jz4740_mmc_num_pins(host));
922882err_cpufreq_unreg:
...... 
939899
940900    free_irq(host->irq, host);
941901
942    jz4740_mmc_free_gpios(pdev);
943902    jz_gpio_bulk_free(jz4740_mmc_pins, jz4740_mmc_num_pins(host));
944903
945904    jz4740_mmc_cpufreq_unregister();

Archive Download the corresponding diff file



interactive