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