LCOV - code coverage report
Current view: top level - drivers/acpi - wakeup.c (source / functions) Hit Total Coverage
Test: combined.info Lines: 6 39 15.4 %
Date: 2022-04-01 13:59:58 Functions: 1 3 33.3 %
Branches: 1 32 3.1 %

           Branch data     Line data    Source code
       1                 :            : // SPDX-License-Identifier: GPL-2.0
       2                 :            : /*
       3                 :            :  * wakeup.c - support wakeup devices
       4                 :            :  * Copyright (C) 2004 Li Shaohua <shaohua.li@intel.com>
       5                 :            :  */
       6                 :            : 
       7                 :            : #include <linux/init.h>
       8                 :            : #include <linux/acpi.h>
       9                 :            : #include <linux/kernel.h>
      10                 :            : #include <linux/types.h>
      11                 :            : 
      12                 :            : #include "internal.h"
      13                 :            : #include "sleep.h"
      14                 :            : 
      15                 :            : /*
      16                 :            :  * We didn't lock acpi_device_lock in the file, because it invokes oops in
      17                 :            :  * suspend/resume and isn't really required as this is called in S-state. At
      18                 :            :  * that time, there is no device hotplug
      19                 :            :  **/
      20                 :            : #define _COMPONENT              ACPI_SYSTEM_COMPONENT
      21                 :            : ACPI_MODULE_NAME("wakeup_devices")
      22                 :            : 
      23                 :            : /**
      24                 :            :  * acpi_enable_wakeup_devices - Enable wake-up device GPEs.
      25                 :            :  * @sleep_state: ACPI system sleep state.
      26                 :            :  *
      27                 :            :  * Enable wakeup device power of devices with the state.enable flag set and set
      28                 :            :  * the wakeup enable mask bits in the GPE registers that correspond to wakeup
      29                 :            :  * devices.
      30                 :            :  */
      31                 :          0 : void acpi_enable_wakeup_devices(u8 sleep_state)
      32                 :            : {
      33                 :          0 :         struct list_head *node, *next;
      34                 :            : 
      35         [ #  # ]:          0 :         list_for_each_safe(node, next, &acpi_wakeup_device_list) {
      36                 :          0 :                 struct acpi_device *dev =
      37                 :          0 :                         container_of(node, struct acpi_device, wakeup_list);
      38                 :            : 
      39         [ #  # ]:          0 :                 if (!dev->wakeup.flags.valid
      40         [ #  # ]:          0 :                     || sleep_state > (u32) dev->wakeup.sleep_state
      41         [ #  # ]:          0 :                     || !(device_may_wakeup(&dev->dev)
      42         [ #  # ]:          0 :                         || dev->wakeup.prepare_count))
      43                 :          0 :                         continue;
      44                 :            : 
      45   [ #  #  #  # ]:          0 :                 if (device_may_wakeup(&dev->dev))
      46                 :          0 :                         acpi_enable_wakeup_device_power(dev, sleep_state);
      47                 :            : 
      48                 :            :                 /* The wake-up power should have been enabled already. */
      49                 :          0 :                 acpi_set_gpe_wake_mask(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
      50                 :            :                                 ACPI_GPE_ENABLE);
      51                 :            :         }
      52                 :          0 : }
      53                 :            : 
      54                 :            : /**
      55                 :            :  * acpi_disable_wakeup_devices - Disable devices' wakeup capability.
      56                 :            :  * @sleep_state: ACPI system sleep state.
      57                 :            :  */
      58                 :          0 : void acpi_disable_wakeup_devices(u8 sleep_state)
      59                 :            : {
      60                 :          0 :         struct list_head *node, *next;
      61                 :            : 
      62         [ #  # ]:          0 :         list_for_each_safe(node, next, &acpi_wakeup_device_list) {
      63                 :          0 :                 struct acpi_device *dev =
      64                 :          0 :                         container_of(node, struct acpi_device, wakeup_list);
      65                 :            : 
      66         [ #  # ]:          0 :                 if (!dev->wakeup.flags.valid
      67         [ #  # ]:          0 :                     || sleep_state > (u32) dev->wakeup.sleep_state
      68         [ #  # ]:          0 :                     || !(device_may_wakeup(&dev->dev)
      69         [ #  # ]:          0 :                         || dev->wakeup.prepare_count))
      70                 :          0 :                         continue;
      71                 :            : 
      72                 :          0 :                 acpi_set_gpe_wake_mask(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
      73                 :            :                                 ACPI_GPE_DISABLE);
      74                 :            : 
      75   [ #  #  #  # ]:          0 :                 if (device_may_wakeup(&dev->dev))
      76                 :          0 :                         acpi_disable_wakeup_device_power(dev);
      77                 :            :         }
      78                 :          0 : }
      79                 :            : 
      80                 :         78 : int __init acpi_wakeup_device_init(void)
      81                 :            : {
      82                 :         78 :         struct list_head *node, *next;
      83                 :            : 
      84                 :         78 :         mutex_lock(&acpi_device_lock);
      85         [ -  + ]:         78 :         list_for_each_safe(node, next, &acpi_wakeup_device_list) {
      86                 :          0 :                 struct acpi_device *dev = container_of(node,
      87                 :            :                                                        struct acpi_device,
      88                 :            :                                                        wakeup_list);
      89         [ #  # ]:          0 :                 if (device_can_wakeup(&dev->dev)) {
      90                 :            :                         /* Button GPEs are supposed to be always enabled. */
      91                 :          0 :                         acpi_enable_gpe(dev->wakeup.gpe_device,
      92                 :          0 :                                         dev->wakeup.gpe_number);
      93                 :          0 :                         device_set_wakeup_enable(&dev->dev, true);
      94                 :            :                 }
      95                 :            :         }
      96                 :         78 :         mutex_unlock(&acpi_device_lock);
      97                 :         78 :         return 0;
      98                 :            : }

Generated by: LCOV version 1.14