Date:2011-06-19 10:57:18 (8 years 11 months ago)
Author:Maarten ter Huurne
Commit:aff1fc8f3617d93f5588c4671bacfa553fb7e1f5
Message:MMC: JZ4740: Added support for CPU frequency changing

The MSC device clock is stopped before the frequency change.
After the change a new divider is computed and the clock is restarted.
Also the frequency change is postponed if an I/O operation is in progress.
Files: drivers/mmc/host/jz4740_mmc.c (5 diffs)

Change Details

drivers/mmc/host/jz4740_mmc.c
2424#include <linux/delay.h>
2525#include <linux/scatterlist.h>
2626#include <linux/clk.h>
27#include <linux/cpufreq.h>
2728
2829#include <linux/bitops.h>
2930#include <linux/gpio.h>
...... 
659660    jz4740_mmc_set_irq_enabled(host, JZ_MMC_IRQ_SDIO, enable);
660661}
661662
663#ifdef CONFIG_CPU_FREQ
664
665static struct jz4740_mmc_host *cpufreq_host;
666
667static int jz4740_mmc_cpufreq_transition(struct notifier_block *nb,
668                     unsigned long val, void *data)
669{
670    /* TODO: We only have to take action when the PLL freq changes:
671             the main dividers have no influence on the MSC device clock. */
672
673    if (val == CPUFREQ_PRECHANGE) {
674        mmc_claim_host(cpufreq_host->mmc);
675        clk_disable(cpufreq_host->clk);
676    } else if (val == CPUFREQ_POSTCHANGE) {
677        struct mmc_ios *ios = &cpufreq_host->mmc->ios;
678        if (ios->clock)
679            jz4740_mmc_set_clock_rate(cpufreq_host, ios->clock);
680        if (ios->power_mode != MMC_POWER_OFF)
681            clk_enable(cpufreq_host->clk);
682        mmc_release_host(cpufreq_host->mmc);
683    }
684    return 0;
685}
686
687static struct notifier_block jz4740_mmc_cpufreq_nb = {
688    .notifier_call = jz4740_mmc_cpufreq_transition,
689};
690
691static inline int jz4740_mmc_cpufreq_register(struct jz4740_mmc_host *host)
692{
693    cpufreq_host = host;
694    return cpufreq_register_notifier(&jz4740_mmc_cpufreq_nb,
695                     CPUFREQ_TRANSITION_NOTIFIER);
696}
697
698static inline void jz4740_mmc_cpufreq_unregister(void)
699{
700    cpufreq_unregister_notifier(&jz4740_mmc_cpufreq_nb,
701                    CPUFREQ_TRANSITION_NOTIFIER);
702}
703
704#else
705
706static inline int jz4740_mmc_cpufreq_register(struct jz4740_mmc_host *host)
707{
708    return 0;
709}
710
711static inline void jz4740_mmc_cpufreq_unregister(void)
712{
713}
714
715#endif
716
662717static const struct mmc_host_ops jz4740_mmc_ops = {
663718    .request = jz4740_mmc_request,
664719    .set_ios = jz4740_mmc_set_ios,
...... 
781836        goto err_free_host;
782837    }
783838
839    ret = jz4740_mmc_cpufreq_register(host);
840    if (ret) {
841        dev_err(&pdev->dev,
842            "Failed to register cpufreq transition notifier\n");
843        goto err_free_host;
844    }
845
784846    res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
785847    host->base = devm_ioremap_resource(&pdev->dev, res);
786848    if (IS_ERR(host->base)) {
787849        ret = PTR_ERR(host->base);
788        goto err_free_host;
850        dev_err(&pdev->dev, "Failed to ioremap base memory\n");
851        goto err_cpufreq_unreg;
789852    }
790853
791854    ret = jz_gpio_bulk_request(jz4740_mmc_pins, jz4740_mmc_num_pins(host));
792855    if (ret) {
793856        dev_err(&pdev->dev, "Failed to request mmc pins: %d\n", ret);
794        goto err_free_host;
857        goto err_cpufreq_unreg;
795858    }
796859
797860    ret = jz4740_mmc_request_gpios(mmc, pdev);
...... 
848911    jz4740_mmc_free_gpios(pdev);
849912err_gpio_bulk_free:
850913    jz_gpio_bulk_free(jz4740_mmc_pins, jz4740_mmc_num_pins(host));
914err_cpufreq_unreg:
915    jz4740_mmc_cpufreq_unregister();
851916err_free_host:
852917    mmc_free_host(mmc);
853918
...... 
869934    jz4740_mmc_free_gpios(pdev);
870935    jz_gpio_bulk_free(jz4740_mmc_pins, jz4740_mmc_num_pins(host));
871936
937    jz4740_mmc_cpufreq_unregister();
872938    mmc_free_host(host->mmc);
873939
874940    return 0;

Archive Download the corresponding diff file



interactive