Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/proc_fs.h> |
| 2 | #include <linux/seq_file.h> |
| 3 | #include <linux/suspend.h> |
| 4 | #include <linux/bcd.h> |
| 5 | #include <asm/uaccess.h> |
| 6 | |
| 7 | #include <acpi/acpi_bus.h> |
| 8 | #include <acpi/acpi_drivers.h> |
| 9 | |
| 10 | #ifdef CONFIG_X86 |
| 11 | #include <linux/mc146818rtc.h> |
| 12 | #endif |
| 13 | |
| 14 | #include "sleep.h" |
| 15 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #define _COMPONENT ACPI_SYSTEM_COMPONENT |
Len Brown | 43532c8 | 2007-07-24 02:16:50 -0400 | [diff] [blame] | 17 | |
| 18 | /* |
| 19 | * this file provides support for: |
Len Brown | 43532c8 | 2007-07-24 02:16:50 -0400 | [diff] [blame] | 20 | * /proc/acpi/alarm |
| 21 | * /proc/acpi/wakeup |
| 22 | */ |
| 23 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 24 | ACPI_MODULE_NAME("sleep") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
Len Brown | 673d5b4 | 2007-07-28 03:33:16 -0400 | [diff] [blame] | 26 | #if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE) || !defined(CONFIG_X86) |
David Brownell | f5f72b4 | 2007-05-08 00:34:02 -0700 | [diff] [blame] | 27 | /* use /sys/class/rtc/rtcX/wakealarm instead; it's not ACPI-specific */ |
| 28 | #else |
| 29 | #define HAVE_ACPI_LEGACY_ALARM |
| 30 | #endif |
| 31 | |
| 32 | #ifdef HAVE_ACPI_LEGACY_ALARM |
| 33 | |
Len Brown | 2602a67 | 2009-01-09 02:10:16 -0500 | [diff] [blame] | 34 | static u32 cmos_bcd_read(int offset, int rtc_control); |
| 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset) |
| 37 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 38 | u32 sec, min, hr; |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 39 | u32 day, mo, yr, cent = 0; |
Mark Lord | 48452e5 | 2008-12-09 10:46:30 -0500 | [diff] [blame] | 40 | u32 today = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 41 | unsigned char rtc_control = 0; |
| 42 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | spin_lock_irqsave(&rtc_lock, flags); |
| 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | rtc_control = CMOS_READ(RTC_CONTROL); |
Mark Lord | 48452e5 | 2008-12-09 10:46:30 -0500 | [diff] [blame] | 47 | sec = cmos_bcd_read(RTC_SECONDS_ALARM, rtc_control); |
| 48 | min = cmos_bcd_read(RTC_MINUTES_ALARM, rtc_control); |
| 49 | hr = cmos_bcd_read(RTC_HOURS_ALARM, rtc_control); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | /* If we ever get an FACP with proper values... */ |
Mark Lord | 48452e5 | 2008-12-09 10:46:30 -0500 | [diff] [blame] | 52 | if (acpi_gbl_FADT.day_alarm) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | /* ACPI spec: only low 6 its should be cared */ |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 54 | day = CMOS_READ(acpi_gbl_FADT.day_alarm) & 0x3F; |
Mark Lord | 48452e5 | 2008-12-09 10:46:30 -0500 | [diff] [blame] | 55 | if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) |
| 56 | day = bcd2bin(day); |
| 57 | } else |
| 58 | day = cmos_bcd_read(RTC_DAY_OF_MONTH, rtc_control); |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 59 | if (acpi_gbl_FADT.month_alarm) |
Mark Lord | 48452e5 | 2008-12-09 10:46:30 -0500 | [diff] [blame] | 60 | mo = cmos_bcd_read(acpi_gbl_FADT.month_alarm, rtc_control); |
| 61 | else { |
| 62 | mo = cmos_bcd_read(RTC_MONTH, rtc_control); |
| 63 | today = cmos_bcd_read(RTC_DAY_OF_MONTH, rtc_control); |
| 64 | } |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 65 | if (acpi_gbl_FADT.century) |
Mark Lord | 48452e5 | 2008-12-09 10:46:30 -0500 | [diff] [blame] | 66 | cent = cmos_bcd_read(acpi_gbl_FADT.century, rtc_control); |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 67 | |
Mark Lord | 48452e5 | 2008-12-09 10:46:30 -0500 | [diff] [blame] | 68 | yr = cmos_bcd_read(RTC_YEAR, rtc_control); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
| 70 | spin_unlock_irqrestore(&rtc_lock, flags); |
| 71 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 72 | /* we're trusting the FADT (see above) */ |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 73 | if (!acpi_gbl_FADT.century) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 74 | /* If we're not trusting the FADT, we should at least make it |
| 75 | * right for _this_ century... ehm, what is _this_ century? |
| 76 | * |
| 77 | * TBD: |
| 78 | * ASAP: find piece of code in the kernel, e.g. star tracker driver, |
| 79 | * which we can trust to determine the century correctly. Atom |
| 80 | * watch driver would be nice, too... |
| 81 | * |
| 82 | * if that has not happened, change for first release in 2050: |
| 83 | * if (yr<50) |
| 84 | * yr += 2100; |
| 85 | * else |
| 86 | * yr += 2000; // current line of code |
| 87 | * |
| 88 | * if that has not happened either, please do on 2099/12/31:23:59:59 |
| 89 | * s/2000/2100 |
| 90 | * |
| 91 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | yr += 2000; |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 93 | else |
| 94 | yr += cent * 100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
Mark Lord | 48452e5 | 2008-12-09 10:46:30 -0500 | [diff] [blame] | 96 | /* |
| 97 | * Show correct dates for alarms up to a month into the future. |
| 98 | * This solves issues for nearly all situations with the common |
| 99 | * 30-day alarm clocks in PC hardware. |
| 100 | */ |
| 101 | if (day < today) { |
| 102 | if (mo < 12) { |
| 103 | mo += 1; |
| 104 | } else { |
| 105 | mo = 1; |
| 106 | yr += 1; |
| 107 | } |
| 108 | } |
| 109 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 110 | seq_printf(seq, "%4.4u-", yr); |
| 111 | (mo > 12) ? seq_puts(seq, "**-") : seq_printf(seq, "%2.2u-", mo); |
| 112 | (day > 31) ? seq_puts(seq, "** ") : seq_printf(seq, "%2.2u ", day); |
| 113 | (hr > 23) ? seq_puts(seq, "**:") : seq_printf(seq, "%2.2u:", hr); |
| 114 | (min > 59) ? seq_puts(seq, "**:") : seq_printf(seq, "%2.2u:", min); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | (sec > 59) ? seq_puts(seq, "**\n") : seq_printf(seq, "%2.2u\n", sec); |
| 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | static int acpi_system_alarm_open_fs(struct inode *inode, struct file *file) |
| 121 | { |
| 122 | return single_open(file, acpi_system_alarm_seq_show, PDE(inode)->data); |
| 123 | } |
| 124 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 125 | static int get_date_field(char **p, u32 * value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 127 | char *next = NULL; |
| 128 | char *string_end = NULL; |
| 129 | int result = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
| 131 | /* |
| 132 | * Try to find delimeter, only to insert null. The end of the |
| 133 | * string won't have one, but is still valid. |
| 134 | */ |
Signed-off by Yi Yang | 975c302 | 2007-12-27 21:50:42 -0500 | [diff] [blame] | 135 | if (*p == NULL) |
| 136 | return result; |
| 137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | next = strpbrk(*p, "- :"); |
| 139 | if (next) |
| 140 | *next++ = '\0'; |
| 141 | |
| 142 | *value = simple_strtoul(*p, &string_end, 10); |
| 143 | |
| 144 | /* Signal success if we got a good digit */ |
| 145 | if (string_end != *p) |
| 146 | result = 0; |
| 147 | |
| 148 | if (next) |
| 149 | *p = next; |
Signed-off by Yi Yang | 975c302 | 2007-12-27 21:50:42 -0500 | [diff] [blame] | 150 | else |
| 151 | *p = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
| 153 | return result; |
| 154 | } |
| 155 | |
Linus Torvalds | c67c36e | 2007-10-17 23:18:32 -0400 | [diff] [blame] | 156 | /* Read a possibly BCD register, always return binary */ |
| 157 | static u32 cmos_bcd_read(int offset, int rtc_control) |
| 158 | { |
| 159 | u32 val = CMOS_READ(offset); |
| 160 | if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) |
Adrian Bunk | ab527d7 | 2008-10-18 20:28:39 -0700 | [diff] [blame] | 161 | val = bcd2bin(val); |
Linus Torvalds | c67c36e | 2007-10-17 23:18:32 -0400 | [diff] [blame] | 162 | return val; |
| 163 | } |
| 164 | |
| 165 | /* Write binary value into possibly BCD register */ |
| 166 | static void cmos_bcd_write(u32 val, int offset, int rtc_control) |
| 167 | { |
| 168 | if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) |
Adrian Bunk | ab527d7 | 2008-10-18 20:28:39 -0700 | [diff] [blame] | 169 | val = bin2bcd(val); |
Linus Torvalds | c67c36e | 2007-10-17 23:18:32 -0400 | [diff] [blame] | 170 | CMOS_WRITE(val, offset); |
| 171 | } |
| 172 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | static ssize_t |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 174 | acpi_system_write_alarm(struct file *file, |
| 175 | const char __user * buffer, size_t count, loff_t * ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 177 | int result = 0; |
| 178 | char alarm_string[30] = { '\0' }; |
| 179 | char *p = alarm_string; |
| 180 | u32 sec, min, hr, day, mo, yr; |
| 181 | int adjust = 0; |
| 182 | unsigned char rtc_control = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | if (count > sizeof(alarm_string) - 1) |
Lin Ming | 95d9a7a | 2008-12-16 16:49:26 +0800 | [diff] [blame] | 185 | return -EINVAL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | if (copy_from_user(alarm_string, buffer, count)) |
Lin Ming | 95d9a7a | 2008-12-16 16:49:26 +0800 | [diff] [blame] | 188 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
| 190 | alarm_string[count] = '\0'; |
| 191 | |
| 192 | /* check for time adjustment */ |
| 193 | if (alarm_string[0] == '+') { |
| 194 | p++; |
| 195 | adjust = 1; |
| 196 | } |
| 197 | |
| 198 | if ((result = get_date_field(&p, &yr))) |
| 199 | goto end; |
| 200 | if ((result = get_date_field(&p, &mo))) |
| 201 | goto end; |
| 202 | if ((result = get_date_field(&p, &day))) |
| 203 | goto end; |
| 204 | if ((result = get_date_field(&p, &hr))) |
| 205 | goto end; |
| 206 | if ((result = get_date_field(&p, &min))) |
| 207 | goto end; |
| 208 | if ((result = get_date_field(&p, &sec))) |
| 209 | goto end; |
| 210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | spin_lock_irq(&rtc_lock); |
| 212 | |
| 213 | rtc_control = CMOS_READ(RTC_CONTROL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
| 215 | if (adjust) { |
Linus Torvalds | c67c36e | 2007-10-17 23:18:32 -0400 | [diff] [blame] | 216 | yr += cmos_bcd_read(RTC_YEAR, rtc_control); |
| 217 | mo += cmos_bcd_read(RTC_MONTH, rtc_control); |
| 218 | day += cmos_bcd_read(RTC_DAY_OF_MONTH, rtc_control); |
| 219 | hr += cmos_bcd_read(RTC_HOURS, rtc_control); |
| 220 | min += cmos_bcd_read(RTC_MINUTES, rtc_control); |
| 221 | sec += cmos_bcd_read(RTC_SECONDS, rtc_control); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | spin_unlock_irq(&rtc_lock); |
| 225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | if (sec > 59) { |
Yi Yang | 0879802 | 2007-12-27 22:04:26 -0500 | [diff] [blame] | 227 | min += sec/60; |
| 228 | sec = sec%60; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | } |
| 230 | if (min > 59) { |
Yi Yang | 0879802 | 2007-12-27 22:04:26 -0500 | [diff] [blame] | 231 | hr += min/60; |
| 232 | min = min%60; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | } |
| 234 | if (hr > 23) { |
Yi Yang | 0879802 | 2007-12-27 22:04:26 -0500 | [diff] [blame] | 235 | day += hr/24; |
| 236 | hr = hr%24; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | } |
| 238 | if (day > 31) { |
Yi Yang | 0879802 | 2007-12-27 22:04:26 -0500 | [diff] [blame] | 239 | mo += day/32; |
| 240 | day = day%32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | } |
| 242 | if (mo > 12) { |
Yi Yang | 0879802 | 2007-12-27 22:04:26 -0500 | [diff] [blame] | 243 | yr += mo/13; |
| 244 | mo = mo%13; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
| 247 | spin_lock_irq(&rtc_lock); |
| 248 | /* |
| 249 | * Disable alarm interrupt before setting alarm timer or else |
| 250 | * when ACPI_EVENT_RTC is enabled, a spurious ACPI interrupt occurs |
| 251 | */ |
| 252 | rtc_control &= ~RTC_AIE; |
| 253 | CMOS_WRITE(rtc_control, RTC_CONTROL); |
| 254 | CMOS_READ(RTC_INTR_FLAGS); |
| 255 | |
| 256 | /* write the fields the rtc knows about */ |
Linus Torvalds | c67c36e | 2007-10-17 23:18:32 -0400 | [diff] [blame] | 257 | cmos_bcd_write(hr, RTC_HOURS_ALARM, rtc_control); |
| 258 | cmos_bcd_write(min, RTC_MINUTES_ALARM, rtc_control); |
| 259 | cmos_bcd_write(sec, RTC_SECONDS_ALARM, rtc_control); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | |
| 261 | /* |
| 262 | * If the system supports an enhanced alarm it will have non-zero |
| 263 | * offsets into the CMOS RAM here -- which for some reason are pointing |
| 264 | * to the RTC area of memory. |
| 265 | */ |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 266 | if (acpi_gbl_FADT.day_alarm) |
Linus Torvalds | c67c36e | 2007-10-17 23:18:32 -0400 | [diff] [blame] | 267 | cmos_bcd_write(day, acpi_gbl_FADT.day_alarm, rtc_control); |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 268 | if (acpi_gbl_FADT.month_alarm) |
Linus Torvalds | c67c36e | 2007-10-17 23:18:32 -0400 | [diff] [blame] | 269 | cmos_bcd_write(mo, acpi_gbl_FADT.month_alarm, rtc_control); |
Huacai Chen | cce3ce8 | 2008-07-04 09:59:31 -0700 | [diff] [blame] | 270 | if (acpi_gbl_FADT.century) { |
| 271 | if (adjust) |
| 272 | yr += cmos_bcd_read(acpi_gbl_FADT.century, rtc_control) * 100; |
Linus Torvalds | c67c36e | 2007-10-17 23:18:32 -0400 | [diff] [blame] | 273 | cmos_bcd_write(yr / 100, acpi_gbl_FADT.century, rtc_control); |
Huacai Chen | cce3ce8 | 2008-07-04 09:59:31 -0700 | [diff] [blame] | 274 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | /* enable the rtc alarm interrupt */ |
| 276 | rtc_control |= RTC_AIE; |
| 277 | CMOS_WRITE(rtc_control, RTC_CONTROL); |
| 278 | CMOS_READ(RTC_INTR_FLAGS); |
| 279 | |
| 280 | spin_unlock_irq(&rtc_lock); |
| 281 | |
| 282 | acpi_clear_event(ACPI_EVENT_RTC); |
| 283 | acpi_enable_event(ACPI_EVENT_RTC, 0); |
| 284 | |
| 285 | *ppos += count; |
| 286 | |
| 287 | result = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 288 | end: |
Lin Ming | 95d9a7a | 2008-12-16 16:49:26 +0800 | [diff] [blame] | 289 | return result ? result : count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | } |
Len Brown | fd35094 | 2007-05-09 23:34:35 -0400 | [diff] [blame] | 291 | #endif /* HAVE_ACPI_LEGACY_ALARM */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | static int |
| 294 | acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset) |
| 295 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 296 | struct list_head *node, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
David Brownell | 8aa5559 | 2007-04-25 15:20:10 -0400 | [diff] [blame] | 298 | seq_printf(seq, "Device\tS-state\t Status Sysfs node\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
Shaohua Li | 9090589 | 2009-04-07 10:24:29 +0800 | [diff] [blame] | 300 | mutex_lock(&acpi_device_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 302 | struct acpi_device *dev = |
| 303 | container_of(node, struct acpi_device, wakeup_list); |
David Brownell | 8aa5559 | 2007-04-25 15:20:10 -0400 | [diff] [blame] | 304 | struct device *ldev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
| 306 | if (!dev->wakeup.flags.valid) |
| 307 | continue; |
David Brownell | 8aa5559 | 2007-04-25 15:20:10 -0400 | [diff] [blame] | 308 | |
| 309 | ldev = acpi_get_physical_device(dev->handle); |
| 310 | seq_printf(seq, "%s\t S%d\t%c%-8s ", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 311 | dev->pnp.bus_id, |
| 312 | (u32) dev->wakeup.sleep_state, |
David Brownell | 8aa5559 | 2007-04-25 15:20:10 -0400 | [diff] [blame] | 313 | dev->wakeup.flags.run_wake ? '*' : ' ', |
Pavel Machek | c65ade4 | 2005-08-05 00:37:45 -0400 | [diff] [blame] | 314 | dev->wakeup.state.enabled ? "enabled" : "disabled"); |
David Brownell | 8aa5559 | 2007-04-25 15:20:10 -0400 | [diff] [blame] | 315 | if (ldev) |
| 316 | seq_printf(seq, "%s:%s", |
Linus Torvalds | 77fb61a | 2008-11-16 10:09:34 -0800 | [diff] [blame] | 317 | ldev->bus ? ldev->bus->name : "no-bus", |
Kay Sievers | 0794469 | 2008-10-30 01:18:59 +0100 | [diff] [blame] | 318 | dev_name(ldev)); |
David Brownell | 8aa5559 | 2007-04-25 15:20:10 -0400 | [diff] [blame] | 319 | seq_printf(seq, "\n"); |
| 320 | put_device(ldev); |
| 321 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | } |
Shaohua Li | 9090589 | 2009-04-07 10:24:29 +0800 | [diff] [blame] | 323 | mutex_unlock(&acpi_device_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | return 0; |
| 325 | } |
| 326 | |
Rafael J. Wysocki | 76acae0 | 2008-10-03 15:23:49 -0700 | [diff] [blame] | 327 | static void physical_device_enable_wakeup(struct acpi_device *adev) |
| 328 | { |
| 329 | struct device *dev = acpi_get_physical_device(adev->handle); |
| 330 | |
| 331 | if (dev && device_can_wakeup(dev)) |
| 332 | device_set_wakeup_enable(dev, adev->wakeup.state.enabled); |
| 333 | } |
| 334 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | static ssize_t |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 336 | acpi_system_write_wakeup_device(struct file *file, |
| 337 | const char __user * buffer, |
| 338 | size_t count, loff_t * ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 340 | struct list_head *node, *next; |
| 341 | char strbuf[5]; |
| 342 | char str[5] = ""; |
Arjan van de Ven | 52a2b11 | 2009-10-01 15:48:40 -0700 | [diff] [blame] | 343 | unsigned int len = count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | struct acpi_device *found_dev = NULL; |
| 345 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 346 | if (len > 4) |
| 347 | len = 4; |
Arjan van de Ven | d9f6501 | 2009-09-26 20:50:25 +0200 | [diff] [blame] | 348 | if (len < 0) |
| 349 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | |
| 351 | if (copy_from_user(strbuf, buffer, len)) |
| 352 | return -EFAULT; |
| 353 | strbuf[len] = '\0'; |
| 354 | sscanf(strbuf, "%s", str); |
| 355 | |
Shaohua Li | 9090589 | 2009-04-07 10:24:29 +0800 | [diff] [blame] | 356 | mutex_lock(&acpi_device_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 358 | struct acpi_device *dev = |
| 359 | container_of(node, struct acpi_device, wakeup_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | if (!dev->wakeup.flags.valid) |
| 361 | continue; |
| 362 | |
| 363 | if (!strncmp(dev->pnp.bus_id, str, 4)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 364 | dev->wakeup.state.enabled = |
| 365 | dev->wakeup.state.enabled ? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | found_dev = dev; |
| 367 | break; |
| 368 | } |
| 369 | } |
| 370 | if (found_dev) { |
Rafael J. Wysocki | 76acae0 | 2008-10-03 15:23:49 -0700 | [diff] [blame] | 371 | physical_device_enable_wakeup(found_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 373 | struct acpi_device *dev = container_of(node, |
| 374 | struct |
| 375 | acpi_device, |
| 376 | wakeup_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | |
| 378 | if ((dev != found_dev) && |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 379 | (dev->wakeup.gpe_number == |
| 380 | found_dev->wakeup.gpe_number) |
| 381 | && (dev->wakeup.gpe_device == |
| 382 | found_dev->wakeup.gpe_device)) { |
| 383 | printk(KERN_WARNING |
| 384 | "ACPI: '%s' and '%s' have the same GPE, " |
Adam Buchbinder | edf86ba | 2009-12-11 16:35:41 -0500 | [diff] [blame] | 385 | "can't disable/enable one separately\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 386 | dev->pnp.bus_id, found_dev->pnp.bus_id); |
| 387 | dev->wakeup.state.enabled = |
| 388 | found_dev->wakeup.state.enabled; |
Rafael J. Wysocki | 76acae0 | 2008-10-03 15:23:49 -0700 | [diff] [blame] | 389 | physical_device_enable_wakeup(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | } |
| 391 | } |
| 392 | } |
Shaohua Li | 9090589 | 2009-04-07 10:24:29 +0800 | [diff] [blame] | 393 | mutex_unlock(&acpi_device_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | return count; |
| 395 | } |
| 396 | |
| 397 | static int |
| 398 | acpi_system_wakeup_device_open_fs(struct inode *inode, struct file *file) |
| 399 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 400 | return single_open(file, acpi_system_wakeup_device_seq_show, |
| 401 | PDE(inode)->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 404 | static const struct file_operations acpi_system_wakeup_device_fops = { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 405 | .owner = THIS_MODULE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 406 | .open = acpi_system_wakeup_device_open_fs, |
| 407 | .read = seq_read, |
| 408 | .write = acpi_system_write_wakeup_device, |
| 409 | .llseek = seq_lseek, |
| 410 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | }; |
| 412 | |
David Brownell | f5f72b4 | 2007-05-08 00:34:02 -0700 | [diff] [blame] | 413 | #ifdef HAVE_ACPI_LEGACY_ALARM |
Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 414 | static const struct file_operations acpi_system_alarm_fops = { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 415 | .owner = THIS_MODULE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 416 | .open = acpi_system_alarm_open_fs, |
| 417 | .read = seq_read, |
| 418 | .write = acpi_system_write_alarm, |
| 419 | .llseek = seq_lseek, |
| 420 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | }; |
| 422 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 423 | static u32 rtc_handler(void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | { |
| 425 | acpi_clear_event(ACPI_EVENT_RTC); |
| 426 | acpi_disable_event(ACPI_EVENT_RTC, 0); |
| 427 | |
| 428 | return ACPI_INTERRUPT_HANDLED; |
| 429 | } |
Len Brown | fd35094 | 2007-05-09 23:34:35 -0400 | [diff] [blame] | 430 | #endif /* HAVE_ACPI_LEGACY_ALARM */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
Bjorn Helgaas | 9cee43e | 2009-03-24 16:50:14 -0600 | [diff] [blame] | 432 | int __init acpi_sleep_proc_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | { |
David Brownell | f5f72b4 | 2007-05-08 00:34:02 -0700 | [diff] [blame] | 434 | #ifdef HAVE_ACPI_LEGACY_ALARM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | /* 'alarm' [R/W] */ |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 436 | proc_create("alarm", S_IFREG | S_IRUGO | S_IWUSR, |
| 437 | acpi_root_dir, &acpi_system_alarm_fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
David Brownell | f5f72b4 | 2007-05-08 00:34:02 -0700 | [diff] [blame] | 439 | acpi_install_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler, NULL); |
Zhao Yakui | e1094bf | 2008-05-14 11:32:59 +0800 | [diff] [blame] | 440 | /* |
| 441 | * Disable the RTC event after installing RTC handler. |
| 442 | * Only when RTC alarm is set will it be enabled. |
| 443 | */ |
| 444 | acpi_clear_event(ACPI_EVENT_RTC); |
| 445 | acpi_disable_event(ACPI_EVENT_RTC, 0); |
Len Brown | fd35094 | 2007-05-09 23:34:35 -0400 | [diff] [blame] | 446 | #endif /* HAVE_ACPI_LEGACY_ALARM */ |
David Brownell | f5f72b4 | 2007-05-08 00:34:02 -0700 | [diff] [blame] | 447 | |
Pavel Machek | c65ade4 | 2005-08-05 00:37:45 -0400 | [diff] [blame] | 448 | /* 'wakeup device' [R/W] */ |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 449 | proc_create("wakeup", S_IFREG | S_IRUGO | S_IWUSR, |
| 450 | acpi_root_dir, &acpi_system_wakeup_device_fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | return 0; |
| 453 | } |