2 * Copyright 2008 Analog Devices Inc.
4 * Licensed under the GPL-2 or later.
7 #include <linux/cdev.h>
8 #include <linux/device.h>
9 #include <linux/errno.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/platform_device.h>
14 #include <linux/types.h>
15 #include <linux/cpufreq.h>
17 #include <asm/delay.h>
20 #define DRIVER_NAME "bfin dpmc"
22 struct bfin_dpmc_platform_data
*pdata
;
25 * bfin_set_vlev - Update VLEV field in VR_CTL Reg.
26 * Avoid BYPASS sequence
28 static void bfin_set_vlev(unsigned int vlev
)
32 pll_lcnt
= bfin_read_PLL_LOCKCNT();
34 bfin_write_PLL_LOCKCNT(1);
35 bfin_write_VR_CTL((bfin_read_VR_CTL() & ~VLEV
) | vlev
);
36 bfin_write_PLL_LOCKCNT(pll_lcnt
);
40 * bfin_get_vlev - Get CPU specific VLEV from platform device data
42 static unsigned int bfin_get_vlev(unsigned int freq
)
51 for (i
= 0; i
< pdata
->tabsize
; i
++)
52 if (freq
<= (pdata
->tuple_tab
[i
] & 0xFFFF))
53 return pdata
->tuple_tab
[i
] >> 16;
56 printk(KERN_WARNING
"DPMC: No suitable CCLK VDDINT voltage pair found\n");
60 #ifdef CONFIG_CPU_FREQ
62 static void bfin_idle_this_cpu(void *info
)
64 unsigned long flags
= 0;
65 unsigned long iwr0
, iwr1
, iwr2
;
66 unsigned int cpu
= smp_processor_id();
68 local_irq_save_hw(flags
);
69 bfin_iwr_set_sup0(&iwr0
, &iwr1
, &iwr2
);
71 platform_clear_ipi(cpu
, IRQ_SUPPLE_0
);
74 bfin_iwr_restore(iwr0
, iwr1
, iwr2
);
76 local_irq_restore_hw(flags
);
79 static void bfin_idle_cpu(void)
81 smp_call_function(bfin_idle_this_cpu
, NULL
, 0);
84 static void bfin_wakeup_cpu(void)
87 unsigned int this_cpu
= smp_processor_id();
90 cpumask_copy(&mask
, cpu_online_mask
);
91 cpumask_clear_cpu(this_cpu
, &mask
);
92 for_each_cpu(cpu
, &mask
)
93 platform_send_ipi_cpu(cpu
, IRQ_SUPPLE_0
);
97 static void bfin_idle_cpu(void) {}
98 static void bfin_wakeup_cpu(void) {}
102 vreg_cpufreq_notifier(struct notifier_block
*nb
, unsigned long val
, void *data
)
104 struct cpufreq_freqs
*freq
= data
;
106 if (freq
->cpu
!= CPUFREQ_CPU
)
109 if (val
== CPUFREQ_PRECHANGE
&& freq
->old
< freq
->new) {
111 bfin_set_vlev(bfin_get_vlev(freq
->new));
112 udelay(pdata
->vr_settling_time
); /* Wait until Volatge settled */
114 } else if (val
== CPUFREQ_POSTCHANGE
&& freq
->old
> freq
->new) {
116 bfin_set_vlev(bfin_get_vlev(freq
->new));
123 static struct notifier_block vreg_cpufreq_notifier_block
= {
124 .notifier_call
= vreg_cpufreq_notifier
126 #endif /* CONFIG_CPU_FREQ */
132 static int __devinit
bfin_dpmc_probe(struct platform_device
*pdev
)
134 if (pdev
->dev
.platform_data
)
135 pdata
= pdev
->dev
.platform_data
;
139 return cpufreq_register_notifier(&vreg_cpufreq_notifier_block
,
140 CPUFREQ_TRANSITION_NOTIFIER
);
146 static int __devexit
bfin_dpmc_remove(struct platform_device
*pdev
)
149 return cpufreq_unregister_notifier(&vreg_cpufreq_notifier_block
,
150 CPUFREQ_TRANSITION_NOTIFIER
);
153 struct platform_driver bfin_dpmc_device_driver
= {
154 .probe
= bfin_dpmc_probe
,
155 .remove
= __devexit_p(bfin_dpmc_remove
),
162 * bfin_dpmc_init - Init driver
164 static int __init
bfin_dpmc_init(void)
166 return platform_driver_register(&bfin_dpmc_device_driver
);
168 module_init(bfin_dpmc_init
);
171 * bfin_dpmc_exit - break down driver
173 static void __exit
bfin_dpmc_exit(void)
175 platform_driver_unregister(&bfin_dpmc_device_driver
);
177 module_exit(bfin_dpmc_exit
);
179 MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
180 MODULE_DESCRIPTION("cpu power management driver for Blackfin");
181 MODULE_LICENSE("GPL");