1 /* linux/arch/arm/mach-s3c2440/mach-osiris-dvs.c
3 * Copyright (c) 2009 Simtec Electronics
4 * http://armlinux.simtec.co.uk/
5 * Ben Dooks <ben@simtec.co.uk>
7 * Simtec Osiris Dynamic Voltage Scaling support.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/platform_device.h>
17 #include <linux/cpufreq.h>
18 #include <linux/gpio.h>
20 #include <linux/i2c/tps65010.h>
22 #include <plat/cpu-freq.h>
23 #include <mach/gpio-samsung.h>
25 #define OSIRIS_GPIO_DVS S3C2410_GPB(5)
29 static void osiris_dvs_tps_setdvs(bool on
)
31 unsigned vregs1
= 0, vdcdc2
= 0;
34 vdcdc2
= TPS_VCORE_DISCH
| TPS_LP_COREOFF
;
35 vregs1
= TPS_LDO1_OFF
; /* turn off in low-power mode */
39 vdcdc2
|= TPS_VCORE_1_3V
| TPS_VCORE_LP_1_0V
;
40 vregs1
|= TPS_LDO2_ENABLE
| TPS_LDO1_ENABLE
;
42 tps65010_config_vregs1(vregs1
);
43 tps65010_config_vdcdc2(vdcdc2
);
46 static bool is_dvs(struct s3c_freq
*f
)
48 /* at the moment, we assume ARMCLK = HCLK => DVS */
49 return f
->armclk
== f
->hclk
;
52 /* keep track of current state */
53 static bool cur_dvs
= false;
55 static int osiris_dvs_notify(struct notifier_block
*nb
,
56 unsigned long val
, void *data
)
58 struct cpufreq_freqs
*cf
= data
;
59 struct s3c_cpufreq_freqs
*freqs
= to_s3c_cpufreq(cf
);
60 bool old_dvs
= is_dvs(&freqs
->old
);
61 bool new_dvs
= is_dvs(&freqs
->new);
67 printk(KERN_DEBUG
"%s: old %ld,%ld new %ld,%ld\n", __func__
,
68 freqs
->old
.armclk
, freqs
->old
.hclk
,
69 freqs
->new.armclk
, freqs
->new.hclk
);
72 case CPUFREQ_PRECHANGE
:
73 if (old_dvs
& !new_dvs
||
75 pr_debug("%s: exiting dvs\n", __func__
);
77 gpio_set_value(OSIRIS_GPIO_DVS
, 1);
80 case CPUFREQ_POSTCHANGE
:
81 if (!old_dvs
& new_dvs
||
83 pr_debug("entering dvs\n");
85 gpio_set_value(OSIRIS_GPIO_DVS
, 0);
93 static struct notifier_block osiris_dvs_nb
= {
94 .notifier_call
= osiris_dvs_notify
,
97 static int osiris_dvs_probe(struct platform_device
*pdev
)
101 dev_info(&pdev
->dev
, "initialising\n");
103 ret
= gpio_request(OSIRIS_GPIO_DVS
, "osiris-dvs");
105 dev_err(&pdev
->dev
, "cannot claim gpio\n");
109 /* start with dvs disabled */
110 gpio_direction_output(OSIRIS_GPIO_DVS
, 1);
112 ret
= cpufreq_register_notifier(&osiris_dvs_nb
,
113 CPUFREQ_TRANSITION_NOTIFIER
);
115 dev_err(&pdev
->dev
, "failed to register with cpufreq\n");
119 osiris_dvs_tps_setdvs(true);
124 gpio_free(OSIRIS_GPIO_DVS
);
130 static int osiris_dvs_remove(struct platform_device
*pdev
)
132 dev_info(&pdev
->dev
, "exiting\n");
134 /* disable any current dvs */
135 gpio_set_value(OSIRIS_GPIO_DVS
, 1);
136 osiris_dvs_tps_setdvs(false);
138 cpufreq_unregister_notifier(&osiris_dvs_nb
,
139 CPUFREQ_TRANSITION_NOTIFIER
);
141 gpio_free(OSIRIS_GPIO_DVS
);
146 /* the CONFIG_PM block is so small, it isn't worth actaully compiling it
147 * out if the configuration isn't set. */
149 static int osiris_dvs_suspend(struct device
*dev
)
151 gpio_set_value(OSIRIS_GPIO_DVS
, 1);
152 osiris_dvs_tps_setdvs(false);
158 static int osiris_dvs_resume(struct device
*dev
)
160 osiris_dvs_tps_setdvs(true);
164 static const struct dev_pm_ops osiris_dvs_pm
= {
165 .suspend
= osiris_dvs_suspend
,
166 .resume
= osiris_dvs_resume
,
169 static struct platform_driver osiris_dvs_driver
= {
170 .probe
= osiris_dvs_probe
,
171 .remove
= osiris_dvs_remove
,
173 .name
= "osiris-dvs",
174 .pm
= &osiris_dvs_pm
,
178 module_platform_driver(osiris_dvs_driver
);
180 MODULE_DESCRIPTION("Simtec OSIRIS DVS support");
181 MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
182 MODULE_LICENSE("GPL");
183 MODULE_ALIAS("platform:osiris-dvs");