Subversion Repositories shark

Rev

Rev 597 | Go to most recent revision | Details | 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
 */
46
static struct cpufreq_driver    *cpufreq_driver;
47
static struct cpufreq_policy    *cpufreq_cpu_data;
48
static spinlock_t               cpufreq_driver_lock = SPIN_LOCK_UNLOCKED;
49
 
50
/*********************************************************************
51
 *                                USER                               *
52
 *********************************************************************/
53
 
54
int cpufreq_target(unsigned int target_freq, unsigned int relation)
55
{
56
        return cpufreq_driver_target(cpufreq_cpu_data, target_freq, relation);
57
}
58
 
59
/*********************************************************************
60
 *                              GOVERNOR                             *
61
 *********************************************************************/
62
 
63
int cpufreq_driver_target(struct cpufreq_policy *policy,
64
                          unsigned int target_freq,
65
                          unsigned int relation)
66
{
67
        unsigned int ret;
68
 
69
        if (!policy)
70
                return -EINVAL;
71
 
72
        ret = cpufreq_driver->target(policy, target_freq, relation);
73
 
74
        return ret;
75
}
76
 
77
/*********************************************************************
78
 *               REGISTER / UNREGISTER CPUFREQ DRIVER                *
79
 *********************************************************************/
80
 
81
/**
82
 * cpufreq_register_driver - register a CPU Frequency driver
83
 * @driver_data: A struct cpufreq_driver containing the values#
84
 * submitted by the CPU Frequency driver.
85
 *
86
 *   Registers a CPU Frequency driver to this core code. This code
87
 * returns zero on success, -EBUSY when another driver got here first
88
 * (and isn't unregistered in the meantime).
89
 *
90
 */
91
int cpufreq_register_driver(struct cpufreq_driver *driver_data)
92
{
93
        unsigned long flags;
94
 
95
        if (!driver_data || !driver_data->verify || !driver_data->init ||
96
            ((!driver_data->setpolicy) && (!driver_data->target)))
97
                return -EINVAL;
98
 
99
        spin_lock_irqsave(&cpufreq_driver_lock, flags);
100
        if (cpufreq_driver) {
101
                spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
102
                return -EBUSY;
103
        }
104
        cpufreq_driver = driver_data;
105
        spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
106
 
107
        /* Init & verify - TODO */
108
        cpufreq_driver->init(cpufreq_cpu_data);
109
        cpufreq_driver->verify(cpufreq_cpu_data);
110
 
111
        return 0; //sysdev_driver_register(&cpu_sysdev_class,&cpufreq_sysdev_driver);
112
}
113
 
114
/**
115
 * cpufreq_unregister_driver - unregister the current CPUFreq driver
116
 *
117
 *    Unregister the current CPUFreq driver. Only call this if you have
118
 * the right to do so, i.e. if you have succeeded in initialising before!
119
 * Returns zero if successful, and -EINVAL if the cpufreq_driver is
120
 * currently not initialised.
121
 */
122
int cpufreq_unregister_driver(struct cpufreq_driver *driver)
123
{
124
        unsigned long flags;
125
 
126
        if (!cpufreq_driver || (driver != cpufreq_driver))
127
                return -EINVAL;
128
 
129
        /* Exit */
130
        cpufreq_driver->exit(cpufreq_cpu_data);
131
 
132
        //sysdev_driver_unregister(&cpu_sysdev_class, &cpufreq_sysdev_driver);
133
 
134
        spin_lock_irqsave(&cpufreq_driver_lock, flags);
135
        cpufreq_driver = NULL;
136
        spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
137
 
138
        return 0;
139
}