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: |
| 20 | * /proc/acpi/sleep |
| 21 | * /proc/acpi/alarm |
| 22 | * /proc/acpi/wakeup |
| 23 | */ |
| 24 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 25 | ACPI_MODULE_NAME("sleep") |
Christian Borntraeger | 134c217 | 2007-08-28 14:58:56 -0400 | [diff] [blame] | 26 | #ifdef CONFIG_ACPI_PROCFS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | static int acpi_system_sleep_seq_show(struct seq_file *seq, void *offset) |
| 28 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 29 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | ACPI_FUNCTION_TRACE("acpi_system_sleep_seq_show"); |
| 32 | |
| 33 | for (i = 0; i <= ACPI_STATE_S5; i++) { |
| 34 | if (sleep_states[i]) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 35 | seq_printf(seq, "S%d ", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | } |
| 37 | } |
| 38 | |
| 39 | seq_puts(seq, "\n"); |
| 40 | |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | static int acpi_system_sleep_open_fs(struct inode *inode, struct file *file) |
| 45 | { |
| 46 | return single_open(file, acpi_system_sleep_seq_show, PDE(inode)->data); |
| 47 | } |
| 48 | |
| 49 | static ssize_t |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 50 | acpi_system_write_sleep(struct file *file, |
| 51 | const char __user * buffer, size_t count, loff_t * ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 53 | char str[12]; |
| 54 | u32 state = 0; |
| 55 | int error = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | if (count > sizeof(str) - 1) |
| 58 | goto Done; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 59 | memset(str, 0, sizeof(str)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | if (copy_from_user(str, buffer, count)) |
| 61 | return -EFAULT; |
| 62 | |
| 63 | /* Check for S4 bios request */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 64 | if (!strcmp(str, "4b")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | error = acpi_suspend(4); |
| 66 | goto Done; |
| 67 | } |
| 68 | state = simple_strtoul(str, NULL, 0); |
Rafael J. Wysocki | b0cb1a1 | 2007-07-29 23:24:36 +0200 | [diff] [blame] | 69 | #ifdef CONFIG_HIBERNATION |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | if (state == 4) { |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 71 | error = hibernate(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | goto Done; |
| 73 | } |
| 74 | #endif |
| 75 | error = acpi_suspend(state); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 76 | Done: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | return error ? error : count; |
| 78 | } |
Christian Borntraeger | 134c217 | 2007-08-28 14:58:56 -0400 | [diff] [blame] | 79 | #endif /* CONFIG_ACPI_PROCFS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Len Brown | 673d5b4 | 2007-07-28 03:33:16 -0400 | [diff] [blame] | 81 | #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] | 82 | /* use /sys/class/rtc/rtcX/wakealarm instead; it's not ACPI-specific */ |
| 83 | #else |
| 84 | #define HAVE_ACPI_LEGACY_ALARM |
| 85 | #endif |
| 86 | |
| 87 | #ifdef HAVE_ACPI_LEGACY_ALARM |
| 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset) |
| 90 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 91 | u32 sec, min, hr; |
Alexey Starikovskiy | ad71860 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 92 | u32 day, mo, yr, cent = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 93 | unsigned char rtc_control = 0; |
| 94 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | ACPI_FUNCTION_TRACE("acpi_system_alarm_seq_show"); |
| 97 | |
| 98 | spin_lock_irqsave(&rtc_lock, flags); |
| 99 | |
| 100 | sec = CMOS_READ(RTC_SECONDS_ALARM); |
| 101 | min = CMOS_READ(RTC_MINUTES_ALARM); |
| 102 | hr = CMOS_READ(RTC_HOURS_ALARM); |
| 103 | rtc_control = CMOS_READ(RTC_CONTROL); |
| 104 | |
| 105 | /* If we ever get an FACP with proper values... */ |
Alexey Starikovskiy | ad71860 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 106 | if (acpi_gbl_FADT.day_alarm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | /* ACPI spec: only low 6 its should be cared */ |
Alexey Starikovskiy | ad71860 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 108 | day = CMOS_READ(acpi_gbl_FADT.day_alarm) & 0x3F; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | else |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 110 | day = CMOS_READ(RTC_DAY_OF_MONTH); |
Alexey Starikovskiy | ad71860 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 111 | if (acpi_gbl_FADT.month_alarm) |
| 112 | mo = CMOS_READ(acpi_gbl_FADT.month_alarm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | else |
| 114 | mo = CMOS_READ(RTC_MONTH); |
Alexey Starikovskiy | ad71860 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 115 | if (acpi_gbl_FADT.century) |
| 116 | cent = CMOS_READ(acpi_gbl_FADT.century); |
| 117 | |
| 118 | yr = CMOS_READ(RTC_YEAR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
| 120 | spin_unlock_irqrestore(&rtc_lock, flags); |
| 121 | |
| 122 | if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { |
| 123 | BCD_TO_BIN(sec); |
| 124 | BCD_TO_BIN(min); |
| 125 | BCD_TO_BIN(hr); |
| 126 | BCD_TO_BIN(day); |
| 127 | BCD_TO_BIN(mo); |
| 128 | BCD_TO_BIN(yr); |
Alexey Starikovskiy | ad71860 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 129 | BCD_TO_BIN(cent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 132 | /* we're trusting the FADT (see above) */ |
Alexey Starikovskiy | ad71860 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 133 | if (!acpi_gbl_FADT.century) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 134 | /* If we're not trusting the FADT, we should at least make it |
| 135 | * right for _this_ century... ehm, what is _this_ century? |
| 136 | * |
| 137 | * TBD: |
| 138 | * ASAP: find piece of code in the kernel, e.g. star tracker driver, |
| 139 | * which we can trust to determine the century correctly. Atom |
| 140 | * watch driver would be nice, too... |
| 141 | * |
| 142 | * if that has not happened, change for first release in 2050: |
| 143 | * if (yr<50) |
| 144 | * yr += 2100; |
| 145 | * else |
| 146 | * yr += 2000; // current line of code |
| 147 | * |
| 148 | * if that has not happened either, please do on 2099/12/31:23:59:59 |
| 149 | * s/2000/2100 |
| 150 | * |
| 151 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | yr += 2000; |
Alexey Starikovskiy | ad71860 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 153 | else |
| 154 | yr += cent * 100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 156 | seq_printf(seq, "%4.4u-", yr); |
| 157 | (mo > 12) ? seq_puts(seq, "**-") : seq_printf(seq, "%2.2u-", mo); |
| 158 | (day > 31) ? seq_puts(seq, "** ") : seq_printf(seq, "%2.2u ", day); |
| 159 | (hr > 23) ? seq_puts(seq, "**:") : seq_printf(seq, "%2.2u:", hr); |
| 160 | (min > 59) ? seq_puts(seq, "**:") : seq_printf(seq, "%2.2u:", min); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | (sec > 59) ? seq_puts(seq, "**\n") : seq_printf(seq, "%2.2u\n", sec); |
| 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | static int acpi_system_alarm_open_fs(struct inode *inode, struct file *file) |
| 167 | { |
| 168 | return single_open(file, acpi_system_alarm_seq_show, PDE(inode)->data); |
| 169 | } |
| 170 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 171 | static int get_date_field(char **p, u32 * value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 173 | char *next = NULL; |
| 174 | char *string_end = NULL; |
| 175 | int result = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
| 177 | /* |
| 178 | * Try to find delimeter, only to insert null. The end of the |
| 179 | * string won't have one, but is still valid. |
| 180 | */ |
| 181 | next = strpbrk(*p, "- :"); |
| 182 | if (next) |
| 183 | *next++ = '\0'; |
| 184 | |
| 185 | *value = simple_strtoul(*p, &string_end, 10); |
| 186 | |
| 187 | /* Signal success if we got a good digit */ |
| 188 | if (string_end != *p) |
| 189 | result = 0; |
| 190 | |
| 191 | if (next) |
| 192 | *p = next; |
| 193 | |
| 194 | return result; |
| 195 | } |
| 196 | |
Linus Torvalds | c67c36e | 2007-10-17 23:18:32 -0400 | [diff] [blame] | 197 | /* Read a possibly BCD register, always return binary */ |
| 198 | static u32 cmos_bcd_read(int offset, int rtc_control) |
| 199 | { |
| 200 | u32 val = CMOS_READ(offset); |
| 201 | if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) |
| 202 | BCD_TO_BIN(val); |
| 203 | return val; |
| 204 | } |
| 205 | |
| 206 | /* Write binary value into possibly BCD register */ |
| 207 | static void cmos_bcd_write(u32 val, int offset, int rtc_control) |
| 208 | { |
| 209 | if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) |
| 210 | BIN_TO_BCD(val); |
| 211 | CMOS_WRITE(val, offset); |
| 212 | } |
| 213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | static ssize_t |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 215 | acpi_system_write_alarm(struct file *file, |
| 216 | const char __user * buffer, size_t count, loff_t * ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 218 | int result = 0; |
| 219 | char alarm_string[30] = { '\0' }; |
| 220 | char *p = alarm_string; |
| 221 | u32 sec, min, hr, day, mo, yr; |
| 222 | int adjust = 0; |
| 223 | unsigned char rtc_control = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
| 225 | ACPI_FUNCTION_TRACE("acpi_system_write_alarm"); |
| 226 | |
| 227 | if (count > sizeof(alarm_string) - 1) |
| 228 | return_VALUE(-EINVAL); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 229 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | if (copy_from_user(alarm_string, buffer, count)) |
| 231 | return_VALUE(-EFAULT); |
| 232 | |
| 233 | alarm_string[count] = '\0'; |
| 234 | |
| 235 | /* check for time adjustment */ |
| 236 | if (alarm_string[0] == '+') { |
| 237 | p++; |
| 238 | adjust = 1; |
| 239 | } |
| 240 | |
| 241 | if ((result = get_date_field(&p, &yr))) |
| 242 | goto end; |
| 243 | if ((result = get_date_field(&p, &mo))) |
| 244 | goto end; |
| 245 | if ((result = get_date_field(&p, &day))) |
| 246 | goto end; |
| 247 | if ((result = get_date_field(&p, &hr))) |
| 248 | goto end; |
| 249 | if ((result = get_date_field(&p, &min))) |
| 250 | goto end; |
| 251 | if ((result = get_date_field(&p, &sec))) |
| 252 | goto end; |
| 253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | spin_lock_irq(&rtc_lock); |
| 255 | |
| 256 | rtc_control = CMOS_READ(RTC_CONTROL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
| 258 | if (adjust) { |
Linus Torvalds | c67c36e | 2007-10-17 23:18:32 -0400 | [diff] [blame] | 259 | yr += cmos_bcd_read(RTC_YEAR, rtc_control); |
| 260 | mo += cmos_bcd_read(RTC_MONTH, rtc_control); |
| 261 | day += cmos_bcd_read(RTC_DAY_OF_MONTH, rtc_control); |
| 262 | hr += cmos_bcd_read(RTC_HOURS, rtc_control); |
| 263 | min += cmos_bcd_read(RTC_MINUTES, rtc_control); |
| 264 | sec += cmos_bcd_read(RTC_SECONDS, rtc_control); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | spin_unlock_irq(&rtc_lock); |
| 268 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | if (sec > 59) { |
Yi Yang | 0879802 | 2007-12-27 22:04:26 -0500 | [diff] [blame^] | 270 | min += sec/60; |
| 271 | sec = sec%60; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | } |
| 273 | if (min > 59) { |
Yi Yang | 0879802 | 2007-12-27 22:04:26 -0500 | [diff] [blame^] | 274 | hr += min/60; |
| 275 | min = min%60; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | } |
| 277 | if (hr > 23) { |
Yi Yang | 0879802 | 2007-12-27 22:04:26 -0500 | [diff] [blame^] | 278 | day += hr/24; |
| 279 | hr = hr%24; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | } |
| 281 | if (day > 31) { |
Yi Yang | 0879802 | 2007-12-27 22:04:26 -0500 | [diff] [blame^] | 282 | mo += day/32; |
| 283 | day = day%32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | } |
| 285 | if (mo > 12) { |
Yi Yang | 0879802 | 2007-12-27 22:04:26 -0500 | [diff] [blame^] | 286 | yr += mo/13; |
| 287 | mo = mo%13; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | |
| 290 | spin_lock_irq(&rtc_lock); |
| 291 | /* |
| 292 | * Disable alarm interrupt before setting alarm timer or else |
| 293 | * when ACPI_EVENT_RTC is enabled, a spurious ACPI interrupt occurs |
| 294 | */ |
| 295 | rtc_control &= ~RTC_AIE; |
| 296 | CMOS_WRITE(rtc_control, RTC_CONTROL); |
| 297 | CMOS_READ(RTC_INTR_FLAGS); |
| 298 | |
| 299 | /* write the fields the rtc knows about */ |
Linus Torvalds | c67c36e | 2007-10-17 23:18:32 -0400 | [diff] [blame] | 300 | cmos_bcd_write(hr, RTC_HOURS_ALARM, rtc_control); |
| 301 | cmos_bcd_write(min, RTC_MINUTES_ALARM, rtc_control); |
| 302 | cmos_bcd_write(sec, RTC_SECONDS_ALARM, rtc_control); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
| 304 | /* |
| 305 | * If the system supports an enhanced alarm it will have non-zero |
| 306 | * offsets into the CMOS RAM here -- which for some reason are pointing |
| 307 | * to the RTC area of memory. |
| 308 | */ |
Alexey Starikovskiy | ad71860 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 309 | if (acpi_gbl_FADT.day_alarm) |
Linus Torvalds | c67c36e | 2007-10-17 23:18:32 -0400 | [diff] [blame] | 310 | cmos_bcd_write(day, acpi_gbl_FADT.day_alarm, rtc_control); |
Alexey Starikovskiy | ad71860 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 311 | if (acpi_gbl_FADT.month_alarm) |
Linus Torvalds | c67c36e | 2007-10-17 23:18:32 -0400 | [diff] [blame] | 312 | cmos_bcd_write(mo, acpi_gbl_FADT.month_alarm, rtc_control); |
Alexey Starikovskiy | ad71860 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 313 | if (acpi_gbl_FADT.century) |
Linus Torvalds | c67c36e | 2007-10-17 23:18:32 -0400 | [diff] [blame] | 314 | cmos_bcd_write(yr / 100, acpi_gbl_FADT.century, rtc_control); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | /* enable the rtc alarm interrupt */ |
| 316 | rtc_control |= RTC_AIE; |
| 317 | CMOS_WRITE(rtc_control, RTC_CONTROL); |
| 318 | CMOS_READ(RTC_INTR_FLAGS); |
| 319 | |
| 320 | spin_unlock_irq(&rtc_lock); |
| 321 | |
| 322 | acpi_clear_event(ACPI_EVENT_RTC); |
| 323 | acpi_enable_event(ACPI_EVENT_RTC, 0); |
| 324 | |
| 325 | *ppos += count; |
| 326 | |
| 327 | result = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 328 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | return_VALUE(result ? result : count); |
| 330 | } |
Len Brown | fd35094 | 2007-05-09 23:34:35 -0400 | [diff] [blame] | 331 | #endif /* HAVE_ACPI_LEGACY_ALARM */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 333 | extern struct list_head acpi_wakeup_device_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | extern spinlock_t acpi_device_lock; |
| 335 | |
| 336 | static int |
| 337 | acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset) |
| 338 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 339 | struct list_head *node, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
David Brownell | 8aa5559 | 2007-04-25 15:20:10 -0400 | [diff] [blame] | 341 | seq_printf(seq, "Device\tS-state\t Status Sysfs node\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
| 343 | spin_lock(&acpi_device_lock); |
| 344 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 345 | struct acpi_device *dev = |
| 346 | container_of(node, struct acpi_device, wakeup_list); |
David Brownell | 8aa5559 | 2007-04-25 15:20:10 -0400 | [diff] [blame] | 347 | struct device *ldev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
| 349 | if (!dev->wakeup.flags.valid) |
| 350 | continue; |
| 351 | spin_unlock(&acpi_device_lock); |
David Brownell | 8aa5559 | 2007-04-25 15:20:10 -0400 | [diff] [blame] | 352 | |
| 353 | ldev = acpi_get_physical_device(dev->handle); |
| 354 | seq_printf(seq, "%s\t S%d\t%c%-8s ", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 355 | dev->pnp.bus_id, |
| 356 | (u32) dev->wakeup.sleep_state, |
David Brownell | 8aa5559 | 2007-04-25 15:20:10 -0400 | [diff] [blame] | 357 | dev->wakeup.flags.run_wake ? '*' : ' ', |
Pavel Machek | c65ade4 | 2005-08-05 00:37:45 -0400 | [diff] [blame] | 358 | dev->wakeup.state.enabled ? "enabled" : "disabled"); |
David Brownell | 8aa5559 | 2007-04-25 15:20:10 -0400 | [diff] [blame] | 359 | if (ldev) |
| 360 | seq_printf(seq, "%s:%s", |
Len Brown | fd35094 | 2007-05-09 23:34:35 -0400 | [diff] [blame] | 361 | ldev->bus ? ldev->bus->name : "no-bus", |
| 362 | ldev->bus_id); |
David Brownell | 8aa5559 | 2007-04-25 15:20:10 -0400 | [diff] [blame] | 363 | seq_printf(seq, "\n"); |
| 364 | put_device(ldev); |
| 365 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | spin_lock(&acpi_device_lock); |
| 367 | } |
| 368 | spin_unlock(&acpi_device_lock); |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | static ssize_t |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 373 | acpi_system_write_wakeup_device(struct file *file, |
| 374 | const char __user * buffer, |
| 375 | size_t count, loff_t * ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 377 | struct list_head *node, *next; |
| 378 | char strbuf[5]; |
| 379 | char str[5] = ""; |
| 380 | int len = count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | struct acpi_device *found_dev = NULL; |
| 382 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 383 | if (len > 4) |
| 384 | len = 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | |
| 386 | if (copy_from_user(strbuf, buffer, len)) |
| 387 | return -EFAULT; |
| 388 | strbuf[len] = '\0'; |
| 389 | sscanf(strbuf, "%s", str); |
| 390 | |
| 391 | spin_lock(&acpi_device_lock); |
| 392 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 393 | struct acpi_device *dev = |
| 394 | container_of(node, struct acpi_device, wakeup_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | if (!dev->wakeup.flags.valid) |
| 396 | continue; |
| 397 | |
| 398 | if (!strncmp(dev->pnp.bus_id, str, 4)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 399 | dev->wakeup.state.enabled = |
| 400 | dev->wakeup.state.enabled ? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | found_dev = dev; |
| 402 | break; |
| 403 | } |
| 404 | } |
| 405 | if (found_dev) { |
| 406 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 407 | struct acpi_device *dev = container_of(node, |
| 408 | struct |
| 409 | acpi_device, |
| 410 | wakeup_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
| 412 | if ((dev != found_dev) && |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 413 | (dev->wakeup.gpe_number == |
| 414 | found_dev->wakeup.gpe_number) |
| 415 | && (dev->wakeup.gpe_device == |
| 416 | found_dev->wakeup.gpe_device)) { |
| 417 | printk(KERN_WARNING |
| 418 | "ACPI: '%s' and '%s' have the same GPE, " |
| 419 | "can't disable/enable one seperately\n", |
| 420 | dev->pnp.bus_id, found_dev->pnp.bus_id); |
| 421 | dev->wakeup.state.enabled = |
| 422 | found_dev->wakeup.state.enabled; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | } |
| 424 | } |
| 425 | } |
| 426 | spin_unlock(&acpi_device_lock); |
| 427 | return count; |
| 428 | } |
| 429 | |
| 430 | static int |
| 431 | acpi_system_wakeup_device_open_fs(struct inode *inode, struct file *file) |
| 432 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 433 | return single_open(file, acpi_system_wakeup_device_seq_show, |
| 434 | PDE(inode)->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 437 | static const struct file_operations acpi_system_wakeup_device_fops = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 438 | .open = acpi_system_wakeup_device_open_fs, |
| 439 | .read = seq_read, |
| 440 | .write = acpi_system_write_wakeup_device, |
| 441 | .llseek = seq_lseek, |
| 442 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | }; |
| 444 | |
Christian Borntraeger | 134c217 | 2007-08-28 14:58:56 -0400 | [diff] [blame] | 445 | #ifdef CONFIG_ACPI_PROCFS |
Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 446 | static const struct file_operations acpi_system_sleep_fops = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 447 | .open = acpi_system_sleep_open_fs, |
| 448 | .read = seq_read, |
| 449 | .write = acpi_system_write_sleep, |
| 450 | .llseek = seq_lseek, |
| 451 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | }; |
Christian Borntraeger | 134c217 | 2007-08-28 14:58:56 -0400 | [diff] [blame] | 453 | #endif /* CONFIG_ACPI_PROCFS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | |
David Brownell | f5f72b4 | 2007-05-08 00:34:02 -0700 | [diff] [blame] | 455 | #ifdef HAVE_ACPI_LEGACY_ALARM |
Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 456 | static const struct file_operations acpi_system_alarm_fops = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 457 | .open = acpi_system_alarm_open_fs, |
| 458 | .read = seq_read, |
| 459 | .write = acpi_system_write_alarm, |
| 460 | .llseek = seq_lseek, |
| 461 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | }; |
| 463 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 464 | static u32 rtc_handler(void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | { |
| 466 | acpi_clear_event(ACPI_EVENT_RTC); |
| 467 | acpi_disable_event(ACPI_EVENT_RTC, 0); |
| 468 | |
| 469 | return ACPI_INTERRUPT_HANDLED; |
| 470 | } |
Len Brown | fd35094 | 2007-05-09 23:34:35 -0400 | [diff] [blame] | 471 | #endif /* HAVE_ACPI_LEGACY_ALARM */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | |
David Brownell | f5f72b4 | 2007-05-08 00:34:02 -0700 | [diff] [blame] | 473 | static int __init acpi_sleep_proc_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | { |
Pavel Machek | c65ade4 | 2005-08-05 00:37:45 -0400 | [diff] [blame] | 475 | struct proc_dir_entry *entry = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | |
| 477 | if (acpi_disabled) |
| 478 | return 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 479 | |
Christian Borntraeger | 134c217 | 2007-08-28 14:58:56 -0400 | [diff] [blame] | 480 | #ifdef CONFIG_ACPI_PROCFS |
Pavel Machek | c65ade4 | 2005-08-05 00:37:45 -0400 | [diff] [blame] | 481 | /* 'sleep' [R/W] */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 482 | entry = |
| 483 | create_proc_entry("sleep", S_IFREG | S_IRUGO | S_IWUSR, |
| 484 | acpi_root_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | if (entry) |
| 486 | entry->proc_fops = &acpi_system_sleep_fops; |
Len Brown | 43532c8 | 2007-07-24 02:16:50 -0400 | [diff] [blame] | 487 | #endif /* CONFIG_ACPI_PROCFS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | |
David Brownell | f5f72b4 | 2007-05-08 00:34:02 -0700 | [diff] [blame] | 489 | #ifdef HAVE_ACPI_LEGACY_ALARM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | /* 'alarm' [R/W] */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 491 | entry = |
| 492 | create_proc_entry("alarm", S_IFREG | S_IRUGO | S_IWUSR, |
| 493 | acpi_root_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | if (entry) |
| 495 | entry->proc_fops = &acpi_system_alarm_fops; |
| 496 | |
David Brownell | f5f72b4 | 2007-05-08 00:34:02 -0700 | [diff] [blame] | 497 | acpi_install_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler, NULL); |
Len Brown | fd35094 | 2007-05-09 23:34:35 -0400 | [diff] [blame] | 498 | #endif /* HAVE_ACPI_LEGACY_ALARM */ |
David Brownell | f5f72b4 | 2007-05-08 00:34:02 -0700 | [diff] [blame] | 499 | |
Pavel Machek | c65ade4 | 2005-08-05 00:37:45 -0400 | [diff] [blame] | 500 | /* 'wakeup device' [R/W] */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 501 | entry = |
| 502 | create_proc_entry("wakeup", S_IFREG | S_IRUGO | S_IWUSR, |
| 503 | acpi_root_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | if (entry) |
| 505 | entry->proc_fops = &acpi_system_wakeup_device_fops; |
| 506 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | return 0; |
| 508 | } |
| 509 | |
| 510 | late_initcall(acpi_sleep_proc_init); |