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

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Apelete Seketeli <apelete@seketeli.net>
Files: arch/mips/include/asm/mach-jz4740/jz4740_mmc.h (1 diff)
arch/mips/jz4740/board-a320.c (3 diffs)
arch/mips/jz4740/board-qi_lb60.c (3 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
214214    PWM_LOOKUP("jz4740-pwm", 7, "pwm-backlight", 0),
215215};
216216
217static struct regulator_consumer_supply a320_mmc_regulator_consumer =
218    REGULATOR_SUPPLY("vmmc", "jz4740-mmc.0");
219
220static struct regulator_init_data a320_mmc_regulator_init_data = {
221    .num_consumer_supplies = 1,
222    .consumer_supplies = &a320_mmc_regulator_consumer,
223    .constraints = {
224        .name = "MMC power",
225        .min_uV = 3300000,
226        .max_uV = 3300000,
227        .valid_modes_mask = REGULATOR_MODE_NORMAL,
228        .valid_ops_mask = REGULATOR_CHANGE_STATUS,
229        .always_on = true,
230        .boot_on = 1,
231    },
232};
233
234static struct fixed_voltage_config a320_mmc_regulator_data = {
235    .supply_name = "MMC power",
236    .microvolts = 3300000,
237    .init_data = &a320_mmc_regulator_init_data,
238};
239
240static struct platform_device a320_mmc_regulator_device = {
241    .name = "reg-fixed-voltage",
242    .id = -1,
243    .dev = {
244        .platform_data = &a320_mmc_regulator_data,
245    }
246};
247
217248static struct jz4740_mmc_platform_data a320_mmc_pdata = {
218249    .gpio_card_detect = JZ_GPIO_PORTB(29),
219250    .gpio_read_only = -1,
220    .gpio_power = -1,
221    // TODO(MtH): I don't know which GPIO pin the SD power is connected to.
222    // Booboo left power alone, but I don't know why.
223    //.gpio_power = GPIO_SD_VCC_EN_N,
224    //.power_active_low = 1,
225251};
226252
227253/* Battery */
...... 
388414    &a320_backlight_device,
389415    &a320_gpio_keys_device,
390416    &a320_audio_device,
417    &a320_mmc_regulator_device,
391418};
392419
393420static void __init board_gpio_setup(void)
...... 
443470    panic_blink = a320_panic_blink_callback;
444471
445472    board_gpio_setup();
473    regulator_has_full_constraints();
446474
447475    if (a320_init_platform_devices())
448476        panic("Failed to initalize platform devices\n");
arch/mips/jz4740/board-qi_lb60.c
359359    }
360360};
361361
362static struct regulator_consumer_supply qi_lb60_mmc_regulator_consumer =
363    REGULATOR_SUPPLY("vmmc", "jz4740-mmc.0");
364
365static struct regulator_init_data qi_lb60_mmc_regulator_init_data = {
366    .num_consumer_supplies = 1,
367    .consumer_supplies = &qi_lb60_mmc_regulator_consumer,
368    .constraints = {
369        .name = "MMC power",
370        .min_uV = 3300000,
371        .max_uV = 3300000,
372        .valid_modes_mask = REGULATOR_MODE_NORMAL,
373        .valid_ops_mask = REGULATOR_CHANGE_STATUS,
374        .always_on = true,
375        .boot_on = 1,
376    },
377};
378
379static struct fixed_voltage_config qi_lb60_mmc_regulator_data = {
380    .supply_name = "MMC power",
381    .microvolts = 3300000,
382    .gpio = QI_LB60_GPIO_SD_VCC_EN_N,
383    .init_data = &qi_lb60_mmc_regulator_init_data,
384};
385
386static struct platform_device qi_lb60_mmc_regulator_device = {
387    .name = "reg-fixed-voltage",
388    .id = -1,
389    .dev = {
390        .platform_data = &qi_lb60_mmc_regulator_data,
391    }
392};
393
362394static struct jz4740_mmc_platform_data qi_lb60_mmc_pdata = {
363395    .gpio_card_detect = QI_LB60_GPIO_SD_CD,
364396    .gpio_read_only = -1,
365    .gpio_power = QI_LB60_GPIO_SD_VCC_EN_N,
366    .power_active_low = 1,
367397};
368398
369399/* OHCI */
...... 
461491    &qi_lb60_pwm_beeper,
462492    &qi_lb60_charger_device,
463493    &qi_lb60_audio_device,
494    &qi_lb60_mmc_regulator_device,
464495};
465496
466497static void __init board_gpio_setup(void)
...... 
516547        is_avt2 ? "AVT2" : "LB60");
517548
518549    board_gpio_setup();
550    regulator_has_full_constraints();
519551
520552    if (qi_lb60_init_platform_devices())
521553        panic("Failed to initialize platform devices");
drivers/mmc/host/jz4740_mmc.c
866866    switch (ios->power_mode) {
867867    case MMC_POWER_UP:
868868        jz4740_mmc_reset(host);
869        if (gpio_is_valid(host->pdata->gpio_power))
870            gpio_set_value(host->pdata->gpio_power,
871                    !host->pdata->power_active_low);
869        mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, ios->vdd);
872870        host->cmdat |= JZ_MMC_CMDAT_INIT;
873871        clk_prepare_enable(host->clk);
874872        break;
875873    case MMC_POWER_ON:
876874        break;
877875    default:
878        if (gpio_is_valid(host->pdata->gpio_power))
879            gpio_set_value(host->pdata->gpio_power,
880                    host->pdata->power_active_low);
876        mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
881877        clk_disable_unprepare(host->clk);
882878        break;
883879    }
...... 
973969    JZ_GPIO_BULK_PIN(MSC_DATA3),
974970};
975971
976static int jz4740_mmc_request_gpio(struct device *dev, int gpio,
977    const char *name, bool output, int value)
978{
979    int ret;
980
981    if (!gpio_is_valid(gpio))
982        return 0;
983
984    ret = gpio_request(gpio, name);
985    if (ret) {
986        dev_err(dev, "Failed to request %s gpio: %d\n", name, ret);
987        return ret;
988    }
989
990    if (output)
991        gpio_direction_output(gpio, value);
992    else
993        gpio_direction_input(gpio);
994
995    return 0;
996}
997
998972static int jz4740_mmc_request_gpios(struct mmc_host *mmc,
999973    struct platform_device *pdev)
1000974{
...... 
1015989            return ret;
1016990    }
1017991
1018    if (gpio_is_valid(pdata->gpio_read_only)) {
992    if (gpio_is_valid(pdata->gpio_read_only))
1019993        ret = mmc_gpio_request_ro(mmc, pdata->gpio_read_only);
1020        if (ret)
1021            return ret;
1022    }
1023
1024    return jz4740_mmc_request_gpio(&pdev->dev, pdata->gpio_power,
1025            "MMC read only", true, pdata->power_active_low);
1026}
1027994
1028static void jz4740_mmc_free_gpios(struct platform_device *pdev)
1029{
1030    struct jz4740_mmc_platform_data *pdata = pdev->dev.platform_data;
1031
1032    if (!pdata)
1033        return;
1034
1035    if (gpio_is_valid(pdata->gpio_power))
1036        gpio_free(pdata->gpio_power);
995    return ret;
1037996}
1038997
1039998static inline size_t jz4740_mmc_num_pins(struct jz4740_mmc_host *host)
...... 
11021061    if (ret)
11031062        goto err_gpio_bulk_free;
11041063
1064    ret = mmc_regulator_get_supply(mmc);
1065    if (ret)
1066        goto err_gpio_bulk_free;
1067
11051068    mmc->ops = &jz4740_mmc_ops;
11061069    mmc->f_min = JZ_MMC_CLK_RATE / 128;
11071070    mmc->f_max = JZ_MMC_CLK_RATE;
1108    mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
11091071    mmc->caps = (pdata && pdata->data_1bit) ? 0 : MMC_CAP_4_BIT_DATA;
11101072    mmc->caps |= MMC_CAP_SDIO_IRQ;
11111073
...... 
11251087            dev_name(&pdev->dev), host);
11261088    if (ret) {
11271089        dev_err(&pdev->dev, "Failed to request irq: %d\n", ret);
1128        goto err_free_gpios;
1090        goto err_gpio_bulk_free;
11291091    }
11301092
11311093    jz4740_mmc_reset(host);
...... 
11561118
11571119err_free_irq:
11581120    free_irq(host->irq, host);
1159err_free_gpios:
1160    jz4740_mmc_free_gpios(pdev);
11611121err_gpio_bulk_free:
11621122    if (host->use_dma)
11631123        jz4740_mmc_release_dma_channels(host);
...... 
11821142
11831143    free_irq(host->irq, host);
11841144
1185    jz4740_mmc_free_gpios(pdev);
11861145    jz_gpio_bulk_free(jz4740_mmc_pins, jz4740_mmc_num_pins(host));
11871146
11881147    if (host->use_dma)

Archive Download the corresponding diff file



interactive