@@ -113,16 +113,52 @@ static struct acpi_device *lid_device;
113
113
static struct proc_dir_entry * acpi_button_dir ;
114
114
static struct proc_dir_entry * acpi_lid_dir ;
115
115
116
+ static int acpi_lid_evaluate_state (struct acpi_device * device )
117
+ {
118
+ unsigned long long lid_state ;
119
+ acpi_status status ;
120
+
121
+ status = acpi_evaluate_integer (device -> handle , "_LID" , NULL , & lid_state );
122
+ if (ACPI_FAILURE (status ))
123
+ return - ENODEV ;
124
+
125
+ return lid_state ? 1 : 0 ;
126
+ }
127
+
128
+ static int acpi_lid_notify_state (struct acpi_device * device , int state )
129
+ {
130
+ struct acpi_button * button = acpi_driver_data (device );
131
+ int ret ;
132
+
133
+ /* input layer checks if event is redundant */
134
+ input_report_switch (button -> input , SW_LID , !state );
135
+ input_sync (button -> input );
136
+
137
+ if (state )
138
+ pm_wakeup_event (& device -> dev , 0 );
139
+
140
+ ret = blocking_notifier_call_chain (& acpi_lid_notifier , state , device );
141
+ if (ret == NOTIFY_DONE )
142
+ ret = blocking_notifier_call_chain (& acpi_lid_notifier , state ,
143
+ device );
144
+ if (ret == NOTIFY_DONE || ret == NOTIFY_OK ) {
145
+ /*
146
+ * It is also regarded as success if the notifier_chain
147
+ * returns NOTIFY_OK or NOTIFY_DONE.
148
+ */
149
+ ret = 0 ;
150
+ }
151
+ return ret ;
152
+ }
153
+
116
154
static int acpi_button_state_seq_show (struct seq_file * seq , void * offset )
117
155
{
118
156
struct acpi_device * device = seq -> private ;
119
- acpi_status status ;
120
- unsigned long long state ;
157
+ int state ;
121
158
122
- status = acpi_evaluate_integer (device -> handle , "_LID" , NULL , & state );
159
+ state = acpi_lid_evaluate_state (device );
123
160
seq_printf (seq , "state: %s\n" ,
124
- ACPI_FAILURE (status ) ? "unsupported" :
125
- (state ? "open" : "closed" ));
161
+ state < 0 ? "unsupported" : (state ? "open" : "closed" ));
126
162
return 0 ;
127
163
}
128
164
@@ -231,51 +267,22 @@ EXPORT_SYMBOL(acpi_lid_notifier_unregister);
231
267
232
268
int acpi_lid_open (void )
233
269
{
234
- acpi_status status ;
235
- unsigned long long state ;
236
-
237
270
if (!lid_device )
238
271
return - ENODEV ;
239
272
240
- status = acpi_evaluate_integer (lid_device -> handle , "_LID" , NULL ,
241
- & state );
242
- if (ACPI_FAILURE (status ))
243
- return - ENODEV ;
244
-
245
- return !!state ;
273
+ return acpi_lid_evaluate_state (lid_device );
246
274
}
247
275
EXPORT_SYMBOL (acpi_lid_open );
248
276
249
- static int acpi_lid_send_state (struct acpi_device * device )
277
+ static int acpi_lid_update_state (struct acpi_device * device )
250
278
{
251
- struct acpi_button * button = acpi_driver_data (device );
252
- unsigned long long state ;
253
- acpi_status status ;
254
- int ret ;
255
-
256
- status = acpi_evaluate_integer (device -> handle , "_LID" , NULL , & state );
257
- if (ACPI_FAILURE (status ))
258
- return - ENODEV ;
279
+ int state ;
259
280
260
- /* input layer checks if event is redundant */
261
- input_report_switch ( button -> input , SW_LID , ! state );
262
- input_sync ( button -> input ) ;
281
+ state = acpi_lid_evaluate_state ( device );
282
+ if ( state < 0 )
283
+ return state ;
263
284
264
- if (state )
265
- pm_wakeup_event (& device -> dev , 0 );
266
-
267
- ret = blocking_notifier_call_chain (& acpi_lid_notifier , state , device );
268
- if (ret == NOTIFY_DONE )
269
- ret = blocking_notifier_call_chain (& acpi_lid_notifier , state ,
270
- device );
271
- if (ret == NOTIFY_DONE || ret == NOTIFY_OK ) {
272
- /*
273
- * It is also regarded as success if the notifier_chain
274
- * returns NOTIFY_OK or NOTIFY_DONE.
275
- */
276
- ret = 0 ;
277
- }
278
- return ret ;
285
+ return acpi_lid_notify_state (device , state );
279
286
}
280
287
281
288
static void acpi_button_notify (struct acpi_device * device , u32 event )
@@ -290,7 +297,7 @@ static void acpi_button_notify(struct acpi_device *device, u32 event)
290
297
case ACPI_BUTTON_NOTIFY_STATUS :
291
298
input = button -> input ;
292
299
if (button -> type == ACPI_BUTTON_TYPE_LID ) {
293
- acpi_lid_send_state (device );
300
+ acpi_lid_update_state (device );
294
301
} else {
295
302
int keycode ;
296
303
0 commit comments