1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
/*
* Copyright (C) ST-Ericsson SA 2010
*
* License Terms: GNU General Public License v2
* Authors: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson
* Bengt Jonsson <bengt.g.jonsson@stericsson.com> for ST-Ericsson
*
* UX500 common part of Power domain regulators (atomic regulators)
*/
#include <linux/kernel.h>
#include <linux/err.h>
#include <linux/regulator/driver.h>
/*
* power state reference count
*/
static int power_state_active_cnt; /* will initialize to zero */
static DEFINE_SPINLOCK(power_state_active_lock);
void power_state_active_enable(void)
{
unsigned long flags;
spin_lock_irqsave(&power_state_active_lock, flags);
power_state_active_cnt++;
spin_unlock_irqrestore(&power_state_active_lock, flags);
}
EXPORT_SYMBOL_GPL(power_state_active_enable);
int power_state_active_disable(void)
{
int ret = 0;
unsigned long flags;
spin_lock_irqsave(&power_state_active_lock, flags);
if (power_state_active_cnt <= 0) {
pr_err("power state: unbalanced enable/disable calls\n");
ret = -EINVAL;
goto out;
}
power_state_active_cnt--;
out:
spin_unlock_irqrestore(&power_state_active_lock, flags);
return ret;
}
EXPORT_SYMBOL_GPL(power_state_active_disable);
/*
* Exported interface for CPUIdle only. This function is called when interrupts
* are turned off. Hence, no locking.
*/
int power_state_active_is_enabled(void)
{
return (power_state_active_cnt > 0);
}
EXPORT_SYMBOL_GPL(power_state_active_is_enabled);
struct ux500_regulator {
char *name;
void (*enable)(void);
int (*disable)(void);
};
/*
* Don't add any clients to this struct without checking with regulator
* responsible!
*/
static struct ux500_regulator ux500_atomic_regulators[] = {
{
.name = "dma40.0",
.enable = power_state_active_enable,
.disable = power_state_active_disable,
},
{
.name = "ssp0",
.enable = power_state_active_enable,
.disable = power_state_active_disable,
},
{
.name = "ssp1",
.enable = power_state_active_enable,
.disable = power_state_active_disable,
},
{
.name = "spi0",
.enable = power_state_active_enable,
.disable = power_state_active_disable,
},
{
.name = "spi1",
.enable = power_state_active_enable,
.disable = power_state_active_disable,
},
{
.name = "spi2",
.enable = power_state_active_enable,
.disable = power_state_active_disable,
},
{
.name = "spi3",
.enable = power_state_active_enable,
.disable = power_state_active_disable,
},
{
.name = "cryp1",
.enable = power_state_active_enable,
.disable = power_state_active_disable,
},
{
.name = "hash1",
.enable = power_state_active_enable,
.disable = power_state_active_disable,
},
};
struct ux500_regulator *__must_check ux500_regulator_get(struct device *dev)
{
int i;
for (i = 0; i < ARRAY_SIZE(ux500_atomic_regulators); i++) {
if (!strcmp(dev_name(dev), ux500_atomic_regulators[i].name))
return &ux500_atomic_regulators[i];
}
return ERR_PTR(-EINVAL);
}
EXPORT_SYMBOL_GPL(ux500_regulator_get);
int ux500_regulator_atomic_enable(struct ux500_regulator *regulator)
{
if (regulator) {
regulator->enable();
return 0;
}
return -EINVAL;
}
EXPORT_SYMBOL_GPL(ux500_regulator_atomic_enable);
int ux500_regulator_atomic_disable(struct ux500_regulator *regulator)
{
if (regulator)
return regulator->disable();
else
return -EINVAL;
}
EXPORT_SYMBOL_GPL(ux500_regulator_atomic_disable);
void ux500_regulator_put(struct ux500_regulator *regulator)
{
/* Here for symetric reasons and for possible future use */
}
EXPORT_SYMBOL_GPL(ux500_regulator_put);
|