50
50
51
51
#define domain_to_gdsc (domain ) container_of(domain, struct gdsc, pd)
52
52
53
- static int gdsc_is_enabled (struct gdsc * sc , bool en )
53
+ enum gdsc_status {
54
+ GDSC_OFF ,
55
+ GDSC_ON
56
+ };
57
+
58
+ /* Returns 1 if GDSC status is status, 0 if not, and < 0 on error */
59
+ static int gdsc_check_status (struct gdsc * sc , enum gdsc_status status )
54
60
{
55
61
unsigned int reg ;
56
62
u32 val ;
57
63
int ret ;
58
64
59
65
if (sc -> flags & POLL_CFG_GDSCR )
60
66
reg = sc -> gdscr + CFG_GDSCR_OFFSET ;
67
+ else if (sc -> gds_hw_ctrl )
68
+ reg = sc -> gds_hw_ctrl ;
61
69
else
62
- reg = sc -> gds_hw_ctrl ? sc -> gds_hw_ctrl : sc -> gdscr ;
70
+ reg = sc -> gdscr ;
63
71
64
72
ret = regmap_read (sc -> regmap , reg , & val );
65
73
if (ret )
66
74
return ret ;
67
75
68
76
if (sc -> flags & POLL_CFG_GDSCR ) {
69
- if (en )
77
+ switch (status ) {
78
+ case GDSC_ON :
70
79
return !!(val & GDSC_POWER_UP_COMPLETE );
71
- else
72
- return !(val & GDSC_POWER_DOWN_COMPLETE );
80
+ case GDSC_OFF :
81
+ return !!(val & GDSC_POWER_DOWN_COMPLETE );
82
+ }
83
+ }
84
+
85
+ switch (status ) {
86
+ case GDSC_ON :
87
+ return !!(val & PWR_ON_MASK );
88
+ case GDSC_OFF :
89
+ return !(val & PWR_ON_MASK );
73
90
}
74
91
75
- return !!( val & PWR_ON_MASK ) ;
92
+ return - EINVAL ;
76
93
}
77
94
78
95
static int gdsc_hwctrl (struct gdsc * sc , bool en )
@@ -82,33 +99,33 @@ static int gdsc_hwctrl(struct gdsc *sc, bool en)
82
99
return regmap_update_bits (sc -> regmap , sc -> gdscr , HW_CONTROL_MASK , val );
83
100
}
84
101
85
- static int gdsc_poll_status (struct gdsc * sc , bool en )
102
+ static int gdsc_poll_status (struct gdsc * sc , enum gdsc_status status )
86
103
{
87
104
ktime_t start ;
88
105
89
106
start = ktime_get ();
90
107
do {
91
- if (gdsc_is_enabled (sc , en ) == en )
108
+ if (gdsc_check_status (sc , status ) )
92
109
return 0 ;
93
110
} while (ktime_us_delta (ktime_get (), start ) < TIMEOUT_US );
94
111
95
- if (gdsc_is_enabled (sc , en ) == en )
112
+ if (gdsc_check_status (sc , status ) )
96
113
return 0 ;
97
114
98
115
return - ETIMEDOUT ;
99
116
}
100
117
101
- static int gdsc_toggle_logic (struct gdsc * sc , bool en )
118
+ static int gdsc_toggle_logic (struct gdsc * sc , enum gdsc_status status )
102
119
{
103
120
int ret ;
104
- u32 val = en ? 0 : SW_COLLAPSE_MASK ;
121
+ u32 val = ( status == GDSC_ON ) ? 0 : SW_COLLAPSE_MASK ;
105
122
106
123
ret = regmap_update_bits (sc -> regmap , sc -> gdscr , SW_COLLAPSE_MASK , val );
107
124
if (ret )
108
125
return ret ;
109
126
110
127
/* If disabling votable gdscs, don't poll on status */
111
- if ((sc -> flags & VOTABLE ) && ! en ) {
128
+ if ((sc -> flags & VOTABLE ) && status == GDSC_OFF ) {
112
129
/*
113
130
* Add a short delay here to ensure that an enable
114
131
* right after it was disabled does not put it in an
@@ -118,7 +135,7 @@ static int gdsc_toggle_logic(struct gdsc *sc, bool en)
118
135
return 0 ;
119
136
}
120
137
121
- if (sc -> gds_hw_ctrl )
138
+ if (sc -> gds_hw_ctrl ) {
122
139
/*
123
140
* The gds hw controller asserts/de-asserts the status bit soon
124
141
* after it receives a power on/off request from a master.
@@ -130,8 +147,9 @@ static int gdsc_toggle_logic(struct gdsc *sc, bool en)
130
147
* and polling the status bit.
131
148
*/
132
149
udelay (1 );
150
+ }
133
151
134
- return gdsc_poll_status (sc , en );
152
+ return gdsc_poll_status (sc , status );
135
153
}
136
154
137
155
static inline int gdsc_deassert_reset (struct gdsc * sc )
@@ -210,7 +228,7 @@ static int gdsc_enable(struct generic_pm_domain *domain)
210
228
gdsc_deassert_clamp_io (sc );
211
229
}
212
230
213
- ret = gdsc_toggle_logic (sc , true );
231
+ ret = gdsc_toggle_logic (sc , GDSC_ON );
214
232
if (ret )
215
233
return ret ;
216
234
@@ -266,15 +284,15 @@ static int gdsc_disable(struct generic_pm_domain *domain)
266
284
*/
267
285
udelay (1 );
268
286
269
- ret = gdsc_poll_status (sc , true );
287
+ ret = gdsc_poll_status (sc , GDSC_ON );
270
288
if (ret )
271
289
return ret ;
272
290
}
273
291
274
292
if (sc -> pwrsts & PWRSTS_OFF )
275
293
gdsc_clear_mem_on (sc );
276
294
277
- ret = gdsc_toggle_logic (sc , false );
295
+ ret = gdsc_toggle_logic (sc , GDSC_OFF );
278
296
if (ret )
279
297
return ret ;
280
298
@@ -303,12 +321,12 @@ static int gdsc_init(struct gdsc *sc)
303
321
304
322
/* Force gdsc ON if only ON state is supported */
305
323
if (sc -> pwrsts == PWRSTS_ON ) {
306
- ret = gdsc_toggle_logic (sc , true );
324
+ ret = gdsc_toggle_logic (sc , GDSC_ON );
307
325
if (ret )
308
326
return ret ;
309
327
}
310
328
311
- on = gdsc_is_enabled (sc , true );
329
+ on = gdsc_check_status (sc , GDSC_ON );
312
330
if (on < 0 )
313
331
return on ;
314
332
0 commit comments