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>
24 #define OSIRIS_GPIO_DVS S3C2410_GPB(5)
28 static void osiris_dvs_tps_setdvs(bool on)
30 unsigned vregs1 = 0, vdcdc2 = 0;
33 vdcdc2 = TPS_VCORE_DISCH | TPS_LP_COREOFF;
34 vregs1 = TPS_LDO1_OFF; /* turn off in low-power mode */
38 vdcdc2 |= TPS_VCORE_1_3V | TPS_VCORE_LP_1_0V;
39 vregs1 |= TPS_LDO2_ENABLE | TPS_LDO1_ENABLE;
41 tps65010_config_vregs1(vregs1);
42 tps65010_config_vdcdc2(vdcdc2);
45 static bool is_dvs(struct s3c_freq *f)
47 /* at the moment, we assume ARMCLK = HCLK => DVS */
48 return f->armclk == f->hclk;
51 /* keep track of current state */
52 static bool cur_dvs = false;
54 static int osiris_dvs_notify(struct notifier_block *nb,
55 unsigned long val, void *data)
57 struct cpufreq_freqs *cf = data;
58 struct s3c_cpufreq_freqs *freqs = to_s3c_cpufreq(cf);
59 bool old_dvs = is_dvs(&freqs->old);
60 bool new_dvs = is_dvs(&freqs->new);
66 printk(KERN_DEBUG "%s: old %ld,%ld new %ld,%ld\n", __func__,
67 freqs->old.armclk, freqs->old.hclk,
68 freqs->new.armclk, freqs->new.hclk);
71 case CPUFREQ_PRECHANGE:
72 if (old_dvs & !new_dvs ||
74 pr_debug("%s: exiting dvs\n", __func__);
76 gpio_set_value(OSIRIS_GPIO_DVS, 1);
79 case CPUFREQ_POSTCHANGE:
80 if (!old_dvs & new_dvs ||
82 pr_debug("entering dvs\n");
84 gpio_set_value(OSIRIS_GPIO_DVS, 0);
92 static struct notifier_block osiris_dvs_nb = {
93 .notifier_call = osiris_dvs_notify,
96 static int osiris_dvs_probe(struct platform_device *pdev)
100 dev_info(&pdev->dev, "initialising\n");
102 ret = gpio_request(OSIRIS_GPIO_DVS, "osiris-dvs");
104 dev_err(&pdev->dev, "cannot claim gpio\n");
108 /* start with dvs disabled */
109 gpio_direction_output(OSIRIS_GPIO_DVS, 1);
111 ret = cpufreq_register_notifier(&osiris_dvs_nb,
112 CPUFREQ_TRANSITION_NOTIFIER);
114 dev_err(&pdev->dev, "failed to register with cpufreq\n");
118 osiris_dvs_tps_setdvs(true);
123 gpio_free(OSIRIS_GPIO_DVS);
129 static int osiris_dvs_remove(struct platform_device *pdev)
131 dev_info(&pdev->dev, "exiting\n");
133 /* disable any current dvs */
134 gpio_set_value(OSIRIS_GPIO_DVS, 1);
135 osiris_dvs_tps_setdvs(false);
137 cpufreq_unregister_notifier(&osiris_dvs_nb,
138 CPUFREQ_TRANSITION_NOTIFIER);
140 gpio_free(OSIRIS_GPIO_DVS);
145 /* the CONFIG_PM block is so small, it isn't worth actaully compiling it
146 * out if the configuration isn't set. */
148 static int osiris_dvs_suspend(struct device *dev)
150 gpio_set_value(OSIRIS_GPIO_DVS, 1);
151 osiris_dvs_tps_setdvs(false);
157 static int osiris_dvs_resume(struct device *dev)
159 osiris_dvs_tps_setdvs(true);
163 static const struct dev_pm_ops osiris_dvs_pm = {
164 .suspend = osiris_dvs_suspend,
165 .resume = osiris_dvs_resume,
168 static struct platform_driver osiris_dvs_driver = {
169 .probe = osiris_dvs_probe,
170 .remove = osiris_dvs_remove,
172 .name = "osiris-dvs",
173 .owner = THIS_MODULE,
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");