3131
3232/* Uncomment next line to get verbose printout */
3333/* #define DEBUG */
34- #define DEBUG_REF 0
3534#define pr_fmt (fmt ) "ACPI : EC: " fmt
3635
3736#include <linux/kernel.h>
@@ -77,9 +76,7 @@ enum ec_command {
7776 * when trying to clear the EC */
7877
7978enum {
80- EC_FLAGS_EVENT_ENABLED , /* Event is enabled */
81- EC_FLAGS_EVENT_PENDING , /* Event is pending */
82- EC_FLAGS_EVENT_DETECTED , /* Event is detected */
79+ EC_FLAGS_QUERY_PENDING , /* Query is pending */
8380 EC_FLAGS_HANDLERS_INSTALLED , /* Handlers for GPE and
8481 * OpReg are installed */
8582 EC_FLAGS_STARTED , /* Driver is started */
@@ -91,13 +88,6 @@ enum {
9188#define ACPI_EC_COMMAND_POLL 0x01 /* Available for command byte */
9289#define ACPI_EC_COMMAND_COMPLETE 0x02 /* Completed last byte */
9390
94- #define ec_debug_ref (ec , fmt , ...) \
95- do { \
96- if (DEBUG_REF) \
97- pr_debug("%lu: " fmt, ec->reference_count, \
98- ## __VA_ARGS__); \
99- } while (0)
100-
10191/* ec.c is compiled in acpi namespace so this shows up as acpi.ec_delay param */
10292static unsigned int ec_delay __read_mostly = ACPI_EC_DELAY ;
10393module_param (ec_delay , uint , 0644 );
@@ -161,12 +151,6 @@ static bool acpi_ec_flushed(struct acpi_ec *ec)
161151 return ec -> reference_count == 1 ;
162152}
163153
164- static bool acpi_ec_has_pending_event (struct acpi_ec * ec )
165- {
166- return test_bit (EC_FLAGS_EVENT_DETECTED , & ec -> flags ) ||
167- test_bit (EC_FLAGS_EVENT_PENDING , & ec -> flags );
168- }
169-
170154/* --------------------------------------------------------------------------
171155 * EC Registers
172156 * -------------------------------------------------------------------------- */
@@ -334,97 +318,34 @@ static void acpi_ec_clear_storm(struct acpi_ec *ec, u8 flag)
334318 * the flush operation is not in
335319 * progress
336320 * @ec: the EC device
337- * @allow_event: whether event should be handled
338321 *
339322 * This function must be used before taking a new action that should hold
340323 * the reference count. If this function returns false, then the action
341324 * must be discarded or it will prevent the flush operation from being
342325 * completed.
343- *
344- * During flushing, QR_EC command need to pass this check when there is a
345- * pending event, so that the reference count held for the pending event
346- * can be decreased by the completion of the QR_EC command.
347326 */
348- static bool acpi_ec_submit_flushable_request (struct acpi_ec * ec ,
349- bool allow_event )
327+ static bool acpi_ec_submit_flushable_request (struct acpi_ec * ec )
350328{
351- if (!acpi_ec_started (ec )) {
352- if (!allow_event || !acpi_ec_has_pending_event (ec ))
353- return false;
354- }
329+ if (!acpi_ec_started (ec ))
330+ return false;
355331 acpi_ec_submit_request (ec );
356332 return true;
357333}
358334
359- static void acpi_ec_submit_event (struct acpi_ec * ec )
335+ static void acpi_ec_submit_query (struct acpi_ec * ec )
360336{
361- if (!test_bit (EC_FLAGS_EVENT_DETECTED , & ec -> flags ) ||
362- !test_bit (EC_FLAGS_EVENT_ENABLED , & ec -> flags ))
363- return ;
364- /* Hold reference for pending event */
365- if (!acpi_ec_submit_flushable_request (ec , true))
366- return ;
367- ec_debug_ref (ec , "Increase event\n" );
368- if (!test_and_set_bit (EC_FLAGS_EVENT_PENDING , & ec -> flags )) {
369- pr_debug ("***** Event query started *****\n" );
337+ if (!test_and_set_bit (EC_FLAGS_QUERY_PENDING , & ec -> flags )) {
338+ pr_debug ("***** Event started *****\n" );
370339 schedule_work (& ec -> work );
371- return ;
372340 }
373- acpi_ec_complete_request (ec );
374- ec_debug_ref (ec , "Decrease event\n" );
375341}
376342
377- static void acpi_ec_complete_event (struct acpi_ec * ec )
343+ static void acpi_ec_complete_query (struct acpi_ec * ec )
378344{
379345 if (ec -> curr -> command == ACPI_EC_COMMAND_QUERY ) {
380- clear_bit (EC_FLAGS_EVENT_PENDING , & ec -> flags );
381- pr_debug ("***** Event query stopped *****\n" );
382- /* Unhold reference for pending event */
383- acpi_ec_complete_request (ec );
384- ec_debug_ref (ec , "Decrease event\n" );
385- /* Check if there is another SCI_EVT detected */
386- acpi_ec_submit_event (ec );
387- }
388- }
389-
390- static void acpi_ec_submit_detection (struct acpi_ec * ec )
391- {
392- /* Hold reference for query submission */
393- if (!acpi_ec_submit_flushable_request (ec , false))
394- return ;
395- ec_debug_ref (ec , "Increase query\n" );
396- if (!test_and_set_bit (EC_FLAGS_EVENT_DETECTED , & ec -> flags )) {
397- pr_debug ("***** Event detection blocked *****\n" );
398- acpi_ec_submit_event (ec );
399- return ;
346+ clear_bit (EC_FLAGS_QUERY_PENDING , & ec -> flags );
347+ pr_debug ("***** Event stopped *****\n" );
400348 }
401- acpi_ec_complete_request (ec );
402- ec_debug_ref (ec , "Decrease query\n" );
403- }
404-
405- static void acpi_ec_complete_detection (struct acpi_ec * ec )
406- {
407- if (ec -> curr -> command == ACPI_EC_COMMAND_QUERY ) {
408- clear_bit (EC_FLAGS_EVENT_DETECTED , & ec -> flags );
409- pr_debug ("***** Event detetion unblocked *****\n" );
410- /* Unhold reference for query submission */
411- acpi_ec_complete_request (ec );
412- ec_debug_ref (ec , "Decrease query\n" );
413- }
414- }
415-
416- static void acpi_ec_enable_event (struct acpi_ec * ec )
417- {
418- unsigned long flags ;
419-
420- spin_lock_irqsave (& ec -> lock , flags );
421- set_bit (EC_FLAGS_EVENT_ENABLED , & ec -> flags );
422- /*
423- * An event may be pending even with SCI_EVT=0, so QR_EC should
424- * always be issued right after started.
425- */
426- acpi_ec_submit_detection (ec );
427- spin_unlock_irqrestore (& ec -> lock , flags );
428349}
429350
430351static int ec_transaction_completed (struct acpi_ec * ec )
@@ -468,7 +389,6 @@ static void advance_transaction(struct acpi_ec *ec)
468389 t -> rdata [t -> ri ++ ] = acpi_ec_read_data (ec );
469390 if (t -> rlen == t -> ri ) {
470391 t -> flags |= ACPI_EC_COMMAND_COMPLETE ;
471- acpi_ec_complete_event (ec );
472392 if (t -> command == ACPI_EC_COMMAND_QUERY )
473393 pr_debug ("***** Command(%s) hardware completion *****\n" ,
474394 acpi_ec_cmd_string (t -> command ));
@@ -479,7 +399,6 @@ static void advance_transaction(struct acpi_ec *ec)
479399 } else if (t -> wlen == t -> wi &&
480400 (status & ACPI_EC_FLAG_IBF ) == 0 ) {
481401 t -> flags |= ACPI_EC_COMMAND_COMPLETE ;
482- acpi_ec_complete_event (ec );
483402 wakeup = true;
484403 }
485404 goto out ;
@@ -488,17 +407,16 @@ static void advance_transaction(struct acpi_ec *ec)
488407 !(status & ACPI_EC_FLAG_SCI ) &&
489408 (t -> command == ACPI_EC_COMMAND_QUERY )) {
490409 t -> flags |= ACPI_EC_COMMAND_POLL ;
491- acpi_ec_complete_detection (ec );
410+ acpi_ec_complete_query (ec );
492411 t -> rdata [t -> ri ++ ] = 0x00 ;
493412 t -> flags |= ACPI_EC_COMMAND_COMPLETE ;
494- acpi_ec_complete_event (ec );
495413 pr_debug ("***** Command(%s) software completion *****\n" ,
496414 acpi_ec_cmd_string (t -> command ));
497415 wakeup = true;
498416 } else if ((status & ACPI_EC_FLAG_IBF ) == 0 ) {
499417 acpi_ec_write_cmd (ec , t -> command );
500418 t -> flags |= ACPI_EC_COMMAND_POLL ;
501- acpi_ec_complete_detection (ec );
419+ acpi_ec_complete_query (ec );
502420 } else
503421 goto err ;
504422 goto out ;
@@ -519,7 +437,7 @@ static void advance_transaction(struct acpi_ec *ec)
519437 }
520438out :
521439 if (status & ACPI_EC_FLAG_SCI )
522- acpi_ec_submit_detection (ec );
440+ acpi_ec_submit_query (ec );
523441 if (wakeup && in_interrupt ())
524442 wake_up (& ec -> wait );
525443}
@@ -580,11 +498,10 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec,
580498 /* start transaction */
581499 spin_lock_irqsave (& ec -> lock , tmp );
582500 /* Enable GPE for command processing (IBF=0/OBF=1) */
583- if (!acpi_ec_submit_flushable_request (ec , true )) {
501+ if (!acpi_ec_submit_flushable_request (ec )) {
584502 ret = - EINVAL ;
585503 goto unlock ;
586504 }
587- ec_debug_ref (ec , "Increase command\n" );
588505 /* following two actions should be kept atomic */
589506 ec -> curr = t ;
590507 pr_debug ("***** Command(%s) started *****\n" ,
@@ -600,7 +517,6 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec,
600517 ec -> curr = NULL ;
601518 /* Disable GPE for command processing (IBF=0/OBF=1) */
602519 acpi_ec_complete_request (ec );
603- ec_debug_ref (ec , "Decrease command\n" );
604520unlock :
605521 spin_unlock_irqrestore (& ec -> lock , tmp );
606522 return ret ;
@@ -762,10 +678,8 @@ static void acpi_ec_start(struct acpi_ec *ec, bool resuming)
762678 if (!test_and_set_bit (EC_FLAGS_STARTED , & ec -> flags )) {
763679 pr_debug ("+++++ Starting EC +++++\n" );
764680 /* Enable GPE for event processing (SCI_EVT=1) */
765- if (!resuming ) {
681+ if (!resuming )
766682 acpi_ec_submit_request (ec );
767- ec_debug_ref (ec , "Increase driver\n" );
768- }
769683 pr_info ("+++++ EC started +++++\n" );
770684 }
771685 spin_unlock_irqrestore (& ec -> lock , flags );
@@ -794,10 +708,8 @@ static void acpi_ec_stop(struct acpi_ec *ec, bool suspending)
794708 wait_event (ec -> wait , acpi_ec_stopped (ec ));
795709 spin_lock_irqsave (& ec -> lock , flags );
796710 /* Disable GPE for event processing (SCI_EVT=1) */
797- if (!suspending ) {
711+ if (!suspending )
798712 acpi_ec_complete_request (ec );
799- ec_debug_ref (ec , "Decrease driver\n" );
800- }
801713 clear_bit (EC_FLAGS_STARTED , & ec -> flags );
802714 clear_bit (EC_FLAGS_STOPPED , & ec -> flags );
803715 pr_info ("+++++ EC stopped +++++\n" );
@@ -967,9 +879,7 @@ static void acpi_ec_gpe_poller(struct work_struct *work)
967879{
968880 struct acpi_ec * ec = container_of (work , struct acpi_ec , work );
969881
970- pr_debug ("***** Event poller started *****\n" );
971882 acpi_ec_query (ec , NULL );
972- pr_debug ("***** Event poller stopped *****\n" );
973883}
974884
975885static u32 acpi_ec_gpe_handler (acpi_handle gpe_device ,
@@ -1039,6 +949,7 @@ static struct acpi_ec *make_acpi_ec(void)
1039949
1040950 if (!ec )
1041951 return NULL ;
952+ ec -> flags = 1 << EC_FLAGS_QUERY_PENDING ;
1042953 mutex_init (& ec -> mutex );
1043954 init_waitqueue_head (& ec -> wait );
1044955 INIT_LIST_HEAD (& ec -> list );
@@ -1189,7 +1100,7 @@ static int acpi_ec_add(struct acpi_device *device)
11891100 ret = ec_install_handlers (ec );
11901101
11911102 /* EC is fully operational, allow queries */
1192- acpi_ec_enable_event ( ec );
1103+ clear_bit ( EC_FLAGS_QUERY_PENDING , & ec -> flags );
11931104
11941105 /* Clear stale _Q events if hardware might require that */
11951106 if (EC_FLAGS_CLEAR_ON_RESUME )
0 commit comments