Subversion Repositories shark

Rev

Rev 582 | Rev 647 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
582 mauro 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Mauro Marinoni      <mauro.marinoni@unipv.it>
10
 *
11
 *
12
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
13
 *
14
 * http://www.sssup.it
15
 * http://retis.sssup.it
16
 * http://shark.sssup.it
17
 */
18
 
19
/*
20
 *  This file was based upon code in Powertweak Linux (http://powertweak.sf.net)
21
 *  (C) 2000-2003  Dave Jones, Arjan van de Ven, Janne P�k�� Dominik Brodowski.
22
 *
23
 *  Licensed under the terms of the GNU GPL License version 2.
24
 *
25
 *  BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous*
26
 */
27
 
28
#include <linuxcomp.h>
29
 
30
#include <linux/config.h>
31
#include <linux/kernel.h>
32
#include <linux/module.h>
33
#include <linux/init.h>
34
#include <linux/cpufreq.h>
35
#include <linux/delay.h>
36
#include <linux/interrupt.h>
37
#include <linux/spinlock.h>
38
#include <linux/slab.h>
39
#include <linux/cpu.h>
40
 
41
/**
42
 * The "cpufreq driver" - the arch- or hardware-dependend low
43
 * level driver of CPUFreq support, and its spinlock. This lock
44
 * also protects the cpufreq_cpu_data array.
45
 */
597 mauro 46
static struct cpufreq_policy    cpufreq_cpu_policy;
47
static struct cpufreq_policy    *cpufreq_cpu_data = &cpufreq_cpu_policy;
582 mauro 48
static struct cpufreq_driver    *cpufreq_driver;
49
static spinlock_t               cpufreq_driver_lock = SPIN_LOCK_UNLOCKED;
50
 
51
/*********************************************************************
52
 *                                USER                               *
53
 *********************************************************************/
54
 
55
int cpufreq_target(unsigned int target_freq, unsigned int relation)
56
{
57
        return cpufreq_driver_target(cpufreq_cpu_data, target_freq, relation);
58
}
59
 
597 mauro 60
int cpufreq_get_cur_freq(void)
61
{
62
        return cpufreq_cpu_data->cur;
63
}
64
 
65
int cpufreq_get_min_freq(void)
66
{
67
        return cpufreq_cpu_data->min;
68
}
69
 
70
int cpufreq_get_max_freq(void)
71
{
72
        return cpufreq_cpu_data->max;
73
}
74
 
75
int cpufreq_get_latency(void)
76
{
77
        return cpufreq_cpu_data->cpuinfo.transition_latency;
78
}
79
 
582 mauro 80
/*********************************************************************
81
 *                              GOVERNOR                             *
82
 *********************************************************************/
83
 
84
int cpufreq_driver_target(struct cpufreq_policy *policy,
85
                          unsigned int target_freq,
86
                          unsigned int relation)
87
{
88
        unsigned int ret;
89
 
90
        if (!policy)
91
                return -EINVAL;
92
 
93
        ret = cpufreq_driver->target(policy, target_freq, relation);
94
 
95
        return ret;
96
}
97
 
98
/*********************************************************************
597 mauro 99
 *                              NOTIFIER                             *
100
 *********************************************************************/
101
void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state)
102
{
103
        switch (state) {
104
        case CPUFREQ_PRECHANGE:
105
                //adjust_jiffies(CPUFREQ_PRECHANGE, freqs);
106
                break;
107
        case CPUFREQ_POSTCHANGE:
108
                //adjust_jiffies(CPUFREQ_POSTCHANGE, freqs);
109
                cpufreq_cpu_data->cur = freqs->new;
110
                break;
111
        }
112
}
113
 
114
/*********************************************************************
582 mauro 115
 *               REGISTER / UNREGISTER CPUFREQ DRIVER                *
116
 *********************************************************************/
117
 
118
/**
119
 * cpufreq_register_driver - register a CPU Frequency driver
120
 * @driver_data: A struct cpufreq_driver containing the values#
121
 * submitted by the CPU Frequency driver.
122
 *
123
 *   Registers a CPU Frequency driver to this core code. This code
124
 * returns zero on success, -EBUSY when another driver got here first
125
 * (and isn't unregistered in the meantime).
126
 *
127
 */
128
int cpufreq_register_driver(struct cpufreq_driver *driver_data)
129
{
130
        unsigned long flags;
131
 
132
        if (!driver_data || !driver_data->verify || !driver_data->init ||
133
            ((!driver_data->setpolicy) && (!driver_data->target)))
134
                return -EINVAL;
135
 
136
        spin_lock_irqsave(&cpufreq_driver_lock, flags);
137
        if (cpufreq_driver) {
138
                spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
139
                return -EBUSY;
140
        }
141
        cpufreq_driver = driver_data;
142
        spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
143
 
144
        /* Init & verify - TODO */
145
        cpufreq_driver->init(cpufreq_cpu_data);
146
        cpufreq_driver->verify(cpufreq_cpu_data);
147
 
148
        return 0; //sysdev_driver_register(&cpu_sysdev_class,&cpufreq_sysdev_driver);
149
}
150
 
151
/**
152
 * cpufreq_unregister_driver - unregister the current CPUFreq driver
153
 *
154
 *    Unregister the current CPUFreq driver. Only call this if you have
155
 * the right to do so, i.e. if you have succeeded in initialising before!
156
 * Returns zero if successful, and -EINVAL if the cpufreq_driver is
157
 * currently not initialised.
158
 */
159
int cpufreq_unregister_driver(struct cpufreq_driver *driver)
160
{
161
        unsigned long flags;
162
 
163
        if (!cpufreq_driver || (driver != cpufreq_driver))
164
                return -EINVAL;
165
 
166
        /* Exit */
167
        cpufreq_driver->exit(cpufreq_cpu_data);
168
 
169
        //sysdev_driver_unregister(&cpu_sysdev_class, &cpufreq_sysdev_driver);
170
 
171
        spin_lock_irqsave(&cpufreq_driver_lock, flags);
172
        cpufreq_driver = NULL;
173
        spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
174
 
175
        return 0;
176
}