Date:2013-04-23 21:49:58 (10 years 11 months ago)
Author:Lars C.
Commit:1be551a8eb58178b009ac645c537deb68ada70f9
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 */
...... 
443471    &qi_lb60_pwm_beeper,
444472    &qi_lb60_charger_device,
445473    &qi_lb60_audio_device,
474    &qi_lb60_mmc_regulator_device,
446475};
447476
448477static void __init board_gpio_setup(void)
drivers/mmc/host/jz4740_mmc.c
626626    switch (ios->power_mode) {
627627    case MMC_POWER_UP:
628628        jz4740_mmc_reset(host);
629        if (gpio_is_valid(host->pdata->gpio_power))
630            gpio_set_value(host->pdata->gpio_power,
631                    !host->pdata->power_active_low);
629        mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, ios->vdd);
632630        host->cmdat |= JZ_MMC_CMDAT_INIT;
633631        clk_prepare_enable(host->clk);
634632        break;
635633    case MMC_POWER_ON:
636634        break;
637635    default:
638        if (gpio_is_valid(host->pdata->gpio_power))
639            gpio_set_value(host->pdata->gpio_power,
640                    host->pdata->power_active_low);
636        mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
641637        clk_disable_unprepare(host->clk);
642638        break;
643639    }
...... 
731727    JZ_GPIO_BULK_PIN(MSC_DATA3),
732728};
733729
734static int jz4740_mmc_request_gpio(struct device *dev, int gpio,
735    const char *name, bool output, int value)
736{
737    int ret;
738
739    if (!gpio_is_valid(gpio))
740        return 0;
741
742    ret = gpio_request(gpio, name);
743    if (ret) {
744        dev_err(dev, "Failed to request %s gpio: %d\n", name, ret);
745        return ret;
746    }
747
748    if (output)
749        gpio_direction_output(gpio, value);
750    else
751        gpio_direction_input(gpio);
752
753    return 0;
754}
755
756730static int jz4740_mmc_request_gpios(struct mmc_host *mmc,
757731    struct platform_device *pdev)
758732{
...... 
773747            return ret;
774748    }
775749
776    if (gpio_is_valid(pdata->gpio_read_only)) {
750    if (gpio_is_valid(pdata->gpio_read_only))
777751        ret = mmc_gpio_request_ro(mmc, pdata->gpio_read_only);
778        if (ret)
779            return ret;
780    }
781
782    return jz4740_mmc_request_gpio(&pdev->dev, pdata->gpio_power,
783            "MMC read only", true, pdata->power_active_low);
784}
785
786static void jz4740_mmc_free_gpios(struct platform_device *pdev)
787{
788    struct jz4740_mmc_platform_data *pdata = pdev->dev.platform_data;
789
790    if (!pdata)
791        return;
792752
793    if (gpio_is_valid(pdata->gpio_power))
794        gpio_free(pdata->gpio_power);
753    return ret;
795754}
796755
797756static inline size_t jz4740_mmc_num_pins(struct jz4740_mmc_host *host)
...... 
861820    if (ret)
862821        goto err_gpio_bulk_free;
863822
823    ret = mmc_regulator_get_supply(mmc);
824    if (ret)
825        goto err_gpio_bulk_free;
826
864827    mmc->ops = &jz4740_mmc_ops;
865828    mmc->f_min = JZ_MMC_CLK_RATE / 128;
866829    mmc->f_max = JZ_MMC_CLK_RATE;
867    mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
868830    mmc->caps = (pdata && pdata->data_1bit) ? 0 : MMC_CAP_4_BIT_DATA;
869831    mmc->caps |= MMC_CAP_SDIO_IRQ;
870832
...... 
884846            dev_name(&pdev->dev), host);
885847    if (ret) {
886848        dev_err(&pdev->dev, "Failed to request irq: %d\n", ret);
887        goto err_free_gpios;
849        goto err_gpio_bulk_free;
888850    }
889851
890852    jz4740_mmc_reset(host);
...... 
907869
908870err_free_irq:
909871    free_irq(host->irq, host);
910err_free_gpios:
911    jz4740_mmc_free_gpios(pdev);
912872err_gpio_bulk_free:
913873    jz_gpio_bulk_free(jz4740_mmc_pins, jz4740_mmc_num_pins(host));
914874err_cpufreq_unreg:
...... 
931891
932892    free_irq(host->irq, host);
933893
934    jz4740_mmc_free_gpios(pdev);
935894    jz_gpio_bulk_free(jz4740_mmc_pins, jz4740_mmc_num_pins(host));
936895
937896    jz4740_mmc_cpufreq_unregister();

Archive Download the corresponding diff file



interactive