diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/acpi/sleep |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/acpi/sleep')
-rw-r--r-- | drivers/acpi/sleep/Makefile | 5 | ||||
-rw-r--r-- | drivers/acpi/sleep/main.c | 234 | ||||
-rw-r--r-- | drivers/acpi/sleep/poweroff.c | 39 | ||||
-rw-r--r-- | drivers/acpi/sleep/proc.c | 509 | ||||
-rw-r--r-- | drivers/acpi/sleep/sleep.h | 8 | ||||
-rw-r--r-- | drivers/acpi/sleep/wakeup.c | 209 |
6 files changed, 1004 insertions, 0 deletions
diff --git a/drivers/acpi/sleep/Makefile b/drivers/acpi/sleep/Makefile new file mode 100644 index 000000000000..d6c017709c85 --- /dev/null +++ b/drivers/acpi/sleep/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | obj-y := poweroff.o wakeup.o | ||
2 | obj-$(CONFIG_ACPI_SLEEP) += main.o | ||
3 | obj-$(CONFIG_ACPI_SLEEP_PROC_FS) += proc.o | ||
4 | |||
5 | EXTRA_CFLAGS += $(ACPI_CFLAGS) | ||
diff --git a/drivers/acpi/sleep/main.c b/drivers/acpi/sleep/main.c new file mode 100644 index 000000000000..0a5d2a94131e --- /dev/null +++ b/drivers/acpi/sleep/main.c | |||
@@ -0,0 +1,234 @@ | |||
1 | /* | ||
2 | * sleep.c - ACPI sleep support. | ||
3 | * | ||
4 | * Copyright (c) 2004 David Shaohua Li <shaohua.li@intel.com> | ||
5 | * Copyright (c) 2000-2003 Patrick Mochel | ||
6 | * Copyright (c) 2003 Open Source Development Lab | ||
7 | * | ||
8 | * This file is released under the GPLv2. | ||
9 | * | ||
10 | */ | ||
11 | |||
12 | #include <linux/delay.h> | ||
13 | #include <linux/irq.h> | ||
14 | #include <linux/dmi.h> | ||
15 | #include <linux/device.h> | ||
16 | #include <linux/suspend.h> | ||
17 | #include <asm/io.h> | ||
18 | #include <acpi/acpi_bus.h> | ||
19 | #include <acpi/acpi_drivers.h> | ||
20 | #include "sleep.h" | ||
21 | |||
22 | u8 sleep_states[ACPI_S_STATE_COUNT]; | ||
23 | |||
24 | static struct pm_ops acpi_pm_ops; | ||
25 | |||
26 | extern void do_suspend_lowlevel_s4bios(void); | ||
27 | extern void do_suspend_lowlevel(void); | ||
28 | |||
29 | static u32 acpi_suspend_states[] = { | ||
30 | [PM_SUSPEND_ON] = ACPI_STATE_S0, | ||
31 | [PM_SUSPEND_STANDBY] = ACPI_STATE_S1, | ||
32 | [PM_SUSPEND_MEM] = ACPI_STATE_S3, | ||
33 | [PM_SUSPEND_DISK] = ACPI_STATE_S4, | ||
34 | }; | ||
35 | |||
36 | static int init_8259A_after_S1; | ||
37 | |||
38 | /** | ||
39 | * acpi_pm_prepare - Do preliminary suspend work. | ||
40 | * @pm_state: suspend state we're entering. | ||
41 | * | ||
42 | * Make sure we support the state. If we do, and we need it, set the | ||
43 | * firmware waking vector and do arch-specific nastiness to get the | ||
44 | * wakeup code to the waking vector. | ||
45 | */ | ||
46 | |||
47 | static int acpi_pm_prepare(suspend_state_t pm_state) | ||
48 | { | ||
49 | u32 acpi_state = acpi_suspend_states[pm_state]; | ||
50 | |||
51 | if (!sleep_states[acpi_state]) | ||
52 | return -EPERM; | ||
53 | |||
54 | /* do we have a wakeup address for S2 and S3? */ | ||
55 | /* Here, we support only S4BIOS, those we set the wakeup address */ | ||
56 | /* S4OS is only supported for now via swsusp.. */ | ||
57 | if (pm_state == PM_SUSPEND_MEM || pm_state == PM_SUSPEND_DISK) { | ||
58 | if (!acpi_wakeup_address) | ||
59 | return -EFAULT; | ||
60 | acpi_set_firmware_waking_vector( | ||
61 | (acpi_physical_address) virt_to_phys( | ||
62 | (void *)acpi_wakeup_address)); | ||
63 | } | ||
64 | ACPI_FLUSH_CPU_CACHE(); | ||
65 | acpi_enable_wakeup_device_prep(acpi_state); | ||
66 | acpi_enter_sleep_state_prep(acpi_state); | ||
67 | return 0; | ||
68 | } | ||
69 | |||
70 | |||
71 | /** | ||
72 | * acpi_pm_enter - Actually enter a sleep state. | ||
73 | * @pm_state: State we're entering. | ||
74 | * | ||
75 | * Flush caches and go to sleep. For STR or STD, we have to call | ||
76 | * arch-specific assembly, which in turn call acpi_enter_sleep_state(). | ||
77 | * It's unfortunate, but it works. Please fix if you're feeling frisky. | ||
78 | */ | ||
79 | |||
80 | static int acpi_pm_enter(suspend_state_t pm_state) | ||
81 | { | ||
82 | acpi_status status = AE_OK; | ||
83 | unsigned long flags = 0; | ||
84 | u32 acpi_state = acpi_suspend_states[pm_state]; | ||
85 | |||
86 | ACPI_FLUSH_CPU_CACHE(); | ||
87 | |||
88 | /* Do arch specific saving of state. */ | ||
89 | if (pm_state > PM_SUSPEND_STANDBY) { | ||
90 | int error = acpi_save_state_mem(); | ||
91 | if (error) | ||
92 | return error; | ||
93 | } | ||
94 | |||
95 | |||
96 | local_irq_save(flags); | ||
97 | acpi_enable_wakeup_device(acpi_state); | ||
98 | switch (pm_state) | ||
99 | { | ||
100 | case PM_SUSPEND_STANDBY: | ||
101 | barrier(); | ||
102 | status = acpi_enter_sleep_state(acpi_state); | ||
103 | break; | ||
104 | |||
105 | case PM_SUSPEND_MEM: | ||
106 | do_suspend_lowlevel(); | ||
107 | break; | ||
108 | |||
109 | case PM_SUSPEND_DISK: | ||
110 | if (acpi_pm_ops.pm_disk_mode == PM_DISK_PLATFORM) | ||
111 | status = acpi_enter_sleep_state(acpi_state); | ||
112 | else | ||
113 | do_suspend_lowlevel_s4bios(); | ||
114 | break; | ||
115 | default: | ||
116 | return -EINVAL; | ||
117 | } | ||
118 | local_irq_restore(flags); | ||
119 | printk(KERN_DEBUG "Back to C!\n"); | ||
120 | |||
121 | /* restore processor state | ||
122 | * We should only be here if we're coming back from STR or STD. | ||
123 | * And, in the case of the latter, the memory image should have already | ||
124 | * been loaded from disk. | ||
125 | */ | ||
126 | if (pm_state > PM_SUSPEND_STANDBY) | ||
127 | acpi_restore_state_mem(); | ||
128 | |||
129 | |||
130 | return ACPI_SUCCESS(status) ? 0 : -EFAULT; | ||
131 | } | ||
132 | |||
133 | |||
134 | /** | ||
135 | * acpi_pm_finish - Finish up suspend sequence. | ||
136 | * @pm_state: State we're coming out of. | ||
137 | * | ||
138 | * This is called after we wake back up (or if entering the sleep state | ||
139 | * failed). | ||
140 | */ | ||
141 | |||
142 | static int acpi_pm_finish(suspend_state_t pm_state) | ||
143 | { | ||
144 | u32 acpi_state = acpi_suspend_states[pm_state]; | ||
145 | |||
146 | acpi_leave_sleep_state(acpi_state); | ||
147 | acpi_disable_wakeup_device(acpi_state); | ||
148 | |||
149 | /* reset firmware waking vector */ | ||
150 | acpi_set_firmware_waking_vector((acpi_physical_address) 0); | ||
151 | |||
152 | if (init_8259A_after_S1) { | ||
153 | printk("Broken toshiba laptop -> kicking interrupts\n"); | ||
154 | init_8259A(0); | ||
155 | } | ||
156 | return 0; | ||
157 | } | ||
158 | |||
159 | |||
160 | int acpi_suspend(u32 acpi_state) | ||
161 | { | ||
162 | suspend_state_t states[] = { | ||
163 | [1] = PM_SUSPEND_STANDBY, | ||
164 | [3] = PM_SUSPEND_MEM, | ||
165 | [4] = PM_SUSPEND_DISK, | ||
166 | }; | ||
167 | |||
168 | if (acpi_state <= 4 && states[acpi_state]) | ||
169 | return pm_suspend(states[acpi_state]); | ||
170 | return -EINVAL; | ||
171 | } | ||
172 | |||
173 | static struct pm_ops acpi_pm_ops = { | ||
174 | .prepare = acpi_pm_prepare, | ||
175 | .enter = acpi_pm_enter, | ||
176 | .finish = acpi_pm_finish, | ||
177 | }; | ||
178 | |||
179 | |||
180 | /* | ||
181 | * Toshiba fails to preserve interrupts over S1, reinitialization | ||
182 | * of 8259 is needed after S1 resume. | ||
183 | */ | ||
184 | static int __init init_ints_after_s1(struct dmi_system_id *d) | ||
185 | { | ||
186 | printk(KERN_WARNING "%s with broken S1 detected.\n", d->ident); | ||
187 | init_8259A_after_S1 = 1; | ||
188 | return 0; | ||
189 | } | ||
190 | |||
191 | static struct dmi_system_id __initdata acpisleep_dmi_table[] = { | ||
192 | { | ||
193 | .callback = init_ints_after_s1, | ||
194 | .ident = "Toshiba Satellite 4030cdt", | ||
195 | .matches = { DMI_MATCH(DMI_PRODUCT_NAME, "S4030CDT/4.3"), }, | ||
196 | }, | ||
197 | { }, | ||
198 | }; | ||
199 | |||
200 | static int __init acpi_sleep_init(void) | ||
201 | { | ||
202 | int i = 0; | ||
203 | |||
204 | dmi_check_system(acpisleep_dmi_table); | ||
205 | |||
206 | if (acpi_disabled) | ||
207 | return 0; | ||
208 | |||
209 | printk(KERN_INFO PREFIX "(supports"); | ||
210 | for (i=0; i < ACPI_S_STATE_COUNT; i++) { | ||
211 | acpi_status status; | ||
212 | u8 type_a, type_b; | ||
213 | status = acpi_get_sleep_type_data(i, &type_a, &type_b); | ||
214 | if (ACPI_SUCCESS(status)) { | ||
215 | sleep_states[i] = 1; | ||
216 | printk(" S%d", i); | ||
217 | } | ||
218 | if (i == ACPI_STATE_S4) { | ||
219 | if (acpi_gbl_FACS->S4bios_f) { | ||
220 | sleep_states[i] = 1; | ||
221 | printk(" S4bios"); | ||
222 | acpi_pm_ops.pm_disk_mode = PM_DISK_FIRMWARE; | ||
223 | } | ||
224 | if (sleep_states[i]) | ||
225 | acpi_pm_ops.pm_disk_mode = PM_DISK_PLATFORM; | ||
226 | } | ||
227 | } | ||
228 | printk(")\n"); | ||
229 | |||
230 | pm_set_ops(&acpi_pm_ops); | ||
231 | return 0; | ||
232 | } | ||
233 | |||
234 | late_initcall(acpi_sleep_init); | ||
diff --git a/drivers/acpi/sleep/poweroff.c b/drivers/acpi/sleep/poweroff.c new file mode 100644 index 000000000000..da237754ded9 --- /dev/null +++ b/drivers/acpi/sleep/poweroff.c | |||
@@ -0,0 +1,39 @@ | |||
1 | /* | ||
2 | * poweroff.c - ACPI handler for powering off the system. | ||
3 | * | ||
4 | * AKA S5, but it is independent of whether or not the kernel supports | ||
5 | * any other sleep support in the system. | ||
6 | */ | ||
7 | |||
8 | #include <linux/pm.h> | ||
9 | #include <linux/init.h> | ||
10 | #include <acpi/acpi_bus.h> | ||
11 | #include <linux/sched.h> | ||
12 | #include "sleep.h" | ||
13 | |||
14 | static void | ||
15 | acpi_power_off (void) | ||
16 | { | ||
17 | printk("%s called\n",__FUNCTION__); | ||
18 | /* Some SMP machines only can poweroff in boot CPU */ | ||
19 | set_cpus_allowed(current, cpumask_of_cpu(0)); | ||
20 | acpi_wakeup_gpe_poweroff_prepare(); | ||
21 | acpi_enter_sleep_state_prep(ACPI_STATE_S5); | ||
22 | ACPI_DISABLE_IRQS(); | ||
23 | acpi_enter_sleep_state(ACPI_STATE_S5); | ||
24 | } | ||
25 | |||
26 | static int acpi_poweroff_init(void) | ||
27 | { | ||
28 | if (!acpi_disabled) { | ||
29 | u8 type_a, type_b; | ||
30 | acpi_status status; | ||
31 | |||
32 | status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b); | ||
33 | if (ACPI_SUCCESS(status)) | ||
34 | pm_power_off = acpi_power_off; | ||
35 | } | ||
36 | return 0; | ||
37 | } | ||
38 | |||
39 | late_initcall(acpi_poweroff_init); | ||
diff --git a/drivers/acpi/sleep/proc.c b/drivers/acpi/sleep/proc.c new file mode 100644 index 000000000000..fd7c5a0649af --- /dev/null +++ b/drivers/acpi/sleep/proc.c | |||
@@ -0,0 +1,509 @@ | |||
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 | |||
16 | #define ACPI_SYSTEM_FILE_SLEEP "sleep" | ||
17 | #define ACPI_SYSTEM_FILE_ALARM "alarm" | ||
18 | #define ACPI_SYSTEM_FILE_WAKEUP_DEVICE "wakeup" | ||
19 | |||
20 | #define _COMPONENT ACPI_SYSTEM_COMPONENT | ||
21 | ACPI_MODULE_NAME ("sleep") | ||
22 | |||
23 | |||
24 | static int acpi_system_sleep_seq_show(struct seq_file *seq, void *offset) | ||
25 | { | ||
26 | int i; | ||
27 | |||
28 | ACPI_FUNCTION_TRACE("acpi_system_sleep_seq_show"); | ||
29 | |||
30 | for (i = 0; i <= ACPI_STATE_S5; i++) { | ||
31 | if (sleep_states[i]) { | ||
32 | seq_printf(seq,"S%d ", i); | ||
33 | if (i == ACPI_STATE_S4 && acpi_gbl_FACS->S4bios_f) | ||
34 | seq_printf(seq, "S4bios "); | ||
35 | } | ||
36 | } | ||
37 | |||
38 | seq_puts(seq, "\n"); | ||
39 | |||
40 | return 0; | ||
41 | } | ||
42 | |||
43 | static int acpi_system_sleep_open_fs(struct inode *inode, struct file *file) | ||
44 | { | ||
45 | return single_open(file, acpi_system_sleep_seq_show, PDE(inode)->data); | ||
46 | } | ||
47 | |||
48 | static ssize_t | ||
49 | acpi_system_write_sleep ( | ||
50 | struct file *file, | ||
51 | const char __user *buffer, | ||
52 | size_t count, | ||
53 | loff_t *ppos) | ||
54 | { | ||
55 | char str[12]; | ||
56 | u32 state = 0; | ||
57 | int error = 0; | ||
58 | |||
59 | if (count > sizeof(str) - 1) | ||
60 | goto Done; | ||
61 | memset(str,0,sizeof(str)); | ||
62 | if (copy_from_user(str, buffer, count)) | ||
63 | return -EFAULT; | ||
64 | |||
65 | /* Check for S4 bios request */ | ||
66 | if (!strcmp(str,"4b")) { | ||
67 | error = acpi_suspend(4); | ||
68 | goto Done; | ||
69 | } | ||
70 | state = simple_strtoul(str, NULL, 0); | ||
71 | #ifdef CONFIG_SOFTWARE_SUSPEND | ||
72 | if (state == 4) { | ||
73 | error = software_suspend(); | ||
74 | goto Done; | ||
75 | } | ||
76 | #endif | ||
77 | error = acpi_suspend(state); | ||
78 | Done: | ||
79 | return error ? error : count; | ||
80 | } | ||
81 | |||
82 | static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset) | ||
83 | { | ||
84 | u32 sec, min, hr; | ||
85 | u32 day, mo, yr; | ||
86 | unsigned char rtc_control = 0; | ||
87 | unsigned long flags; | ||
88 | |||
89 | ACPI_FUNCTION_TRACE("acpi_system_alarm_seq_show"); | ||
90 | |||
91 | spin_lock_irqsave(&rtc_lock, flags); | ||
92 | |||
93 | sec = CMOS_READ(RTC_SECONDS_ALARM); | ||
94 | min = CMOS_READ(RTC_MINUTES_ALARM); | ||
95 | hr = CMOS_READ(RTC_HOURS_ALARM); | ||
96 | rtc_control = CMOS_READ(RTC_CONTROL); | ||
97 | |||
98 | /* If we ever get an FACP with proper values... */ | ||
99 | if (acpi_gbl_FADT->day_alrm) | ||
100 | /* ACPI spec: only low 6 its should be cared */ | ||
101 | day = CMOS_READ(acpi_gbl_FADT->day_alrm) & 0x3F; | ||
102 | else | ||
103 | day = CMOS_READ(RTC_DAY_OF_MONTH); | ||
104 | if (acpi_gbl_FADT->mon_alrm) | ||
105 | mo = CMOS_READ(acpi_gbl_FADT->mon_alrm); | ||
106 | else | ||
107 | mo = CMOS_READ(RTC_MONTH); | ||
108 | if (acpi_gbl_FADT->century) | ||
109 | yr = CMOS_READ(acpi_gbl_FADT->century) * 100 + CMOS_READ(RTC_YEAR); | ||
110 | else | ||
111 | yr = CMOS_READ(RTC_YEAR); | ||
112 | |||
113 | spin_unlock_irqrestore(&rtc_lock, flags); | ||
114 | |||
115 | if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { | ||
116 | BCD_TO_BIN(sec); | ||
117 | BCD_TO_BIN(min); | ||
118 | BCD_TO_BIN(hr); | ||
119 | BCD_TO_BIN(day); | ||
120 | BCD_TO_BIN(mo); | ||
121 | BCD_TO_BIN(yr); | ||
122 | } | ||
123 | |||
124 | /* we're trusting the FADT (see above)*/ | ||
125 | if (!acpi_gbl_FADT->century) | ||
126 | /* If we're not trusting the FADT, we should at least make it | ||
127 | * right for _this_ century... ehm, what is _this_ century? | ||
128 | * | ||
129 | * TBD: | ||
130 | * ASAP: find piece of code in the kernel, e.g. star tracker driver, | ||
131 | * which we can trust to determine the century correctly. Atom | ||
132 | * watch driver would be nice, too... | ||
133 | * | ||
134 | * if that has not happened, change for first release in 2050: | ||
135 | * if (yr<50) | ||
136 | * yr += 2100; | ||
137 | * else | ||
138 | * yr += 2000; // current line of code | ||
139 | * | ||
140 | * if that has not happened either, please do on 2099/12/31:23:59:59 | ||
141 | * s/2000/2100 | ||
142 | * | ||
143 | */ | ||
144 | yr += 2000; | ||
145 | |||
146 | seq_printf(seq,"%4.4u-", yr); | ||
147 | (mo > 12) ? seq_puts(seq, "**-") : seq_printf(seq, "%2.2u-", mo); | ||
148 | (day > 31) ? seq_puts(seq, "** ") : seq_printf(seq, "%2.2u ", day); | ||
149 | (hr > 23) ? seq_puts(seq, "**:") : seq_printf(seq, "%2.2u:", hr); | ||
150 | (min > 59) ? seq_puts(seq, "**:") : seq_printf(seq, "%2.2u:", min); | ||
151 | (sec > 59) ? seq_puts(seq, "**\n") : seq_printf(seq, "%2.2u\n", sec); | ||
152 | |||
153 | return 0; | ||
154 | } | ||
155 | |||
156 | static int acpi_system_alarm_open_fs(struct inode *inode, struct file *file) | ||
157 | { | ||
158 | return single_open(file, acpi_system_alarm_seq_show, PDE(inode)->data); | ||
159 | } | ||
160 | |||
161 | |||
162 | static int | ||
163 | get_date_field ( | ||
164 | char **p, | ||
165 | u32 *value) | ||
166 | { | ||
167 | char *next = NULL; | ||
168 | char *string_end = NULL; | ||
169 | int result = -EINVAL; | ||
170 | |||
171 | /* | ||
172 | * Try to find delimeter, only to insert null. The end of the | ||
173 | * string won't have one, but is still valid. | ||
174 | */ | ||
175 | next = strpbrk(*p, "- :"); | ||
176 | if (next) | ||
177 | *next++ = '\0'; | ||
178 | |||
179 | *value = simple_strtoul(*p, &string_end, 10); | ||
180 | |||
181 | /* Signal success if we got a good digit */ | ||
182 | if (string_end != *p) | ||
183 | result = 0; | ||
184 | |||
185 | if (next) | ||
186 | *p = next; | ||
187 | |||
188 | return result; | ||
189 | } | ||
190 | |||
191 | |||
192 | static ssize_t | ||
193 | acpi_system_write_alarm ( | ||
194 | struct file *file, | ||
195 | const char __user *buffer, | ||
196 | size_t count, | ||
197 | loff_t *ppos) | ||
198 | { | ||
199 | int result = 0; | ||
200 | char alarm_string[30] = {'\0'}; | ||
201 | char *p = alarm_string; | ||
202 | u32 sec, min, hr, day, mo, yr; | ||
203 | int adjust = 0; | ||
204 | unsigned char rtc_control = 0; | ||
205 | |||
206 | ACPI_FUNCTION_TRACE("acpi_system_write_alarm"); | ||
207 | |||
208 | if (count > sizeof(alarm_string) - 1) | ||
209 | return_VALUE(-EINVAL); | ||
210 | |||
211 | if (copy_from_user(alarm_string, buffer, count)) | ||
212 | return_VALUE(-EFAULT); | ||
213 | |||
214 | alarm_string[count] = '\0'; | ||
215 | |||
216 | /* check for time adjustment */ | ||
217 | if (alarm_string[0] == '+') { | ||
218 | p++; | ||
219 | adjust = 1; | ||
220 | } | ||
221 | |||
222 | if ((result = get_date_field(&p, &yr))) | ||
223 | goto end; | ||
224 | if ((result = get_date_field(&p, &mo))) | ||
225 | goto end; | ||
226 | if ((result = get_date_field(&p, &day))) | ||
227 | goto end; | ||
228 | if ((result = get_date_field(&p, &hr))) | ||
229 | goto end; | ||
230 | if ((result = get_date_field(&p, &min))) | ||
231 | goto end; | ||
232 | if ((result = get_date_field(&p, &sec))) | ||
233 | goto end; | ||
234 | |||
235 | if (sec > 59) { | ||
236 | min += 1; | ||
237 | sec -= 60; | ||
238 | } | ||
239 | if (min > 59) { | ||
240 | hr += 1; | ||
241 | min -= 60; | ||
242 | } | ||
243 | if (hr > 23) { | ||
244 | day += 1; | ||
245 | hr -= 24; | ||
246 | } | ||
247 | if (day > 31) { | ||
248 | mo += 1; | ||
249 | day -= 31; | ||
250 | } | ||
251 | if (mo > 12) { | ||
252 | yr += 1; | ||
253 | mo -= 12; | ||
254 | } | ||
255 | |||
256 | spin_lock_irq(&rtc_lock); | ||
257 | |||
258 | rtc_control = CMOS_READ(RTC_CONTROL); | ||
259 | if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { | ||
260 | BIN_TO_BCD(yr); | ||
261 | BIN_TO_BCD(mo); | ||
262 | BIN_TO_BCD(day); | ||
263 | BIN_TO_BCD(hr); | ||
264 | BIN_TO_BCD(min); | ||
265 | BIN_TO_BCD(sec); | ||
266 | } | ||
267 | |||
268 | if (adjust) { | ||
269 | yr += CMOS_READ(RTC_YEAR); | ||
270 | mo += CMOS_READ(RTC_MONTH); | ||
271 | day += CMOS_READ(RTC_DAY_OF_MONTH); | ||
272 | hr += CMOS_READ(RTC_HOURS); | ||
273 | min += CMOS_READ(RTC_MINUTES); | ||
274 | sec += CMOS_READ(RTC_SECONDS); | ||
275 | } | ||
276 | |||
277 | spin_unlock_irq(&rtc_lock); | ||
278 | |||
279 | if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { | ||
280 | BCD_TO_BIN(yr); | ||
281 | BCD_TO_BIN(mo); | ||
282 | BCD_TO_BIN(day); | ||
283 | BCD_TO_BIN(hr); | ||
284 | BCD_TO_BIN(min); | ||
285 | BCD_TO_BIN(sec); | ||
286 | } | ||
287 | |||
288 | if (sec > 59) { | ||
289 | min++; | ||
290 | sec -= 60; | ||
291 | } | ||
292 | if (min > 59) { | ||
293 | hr++; | ||
294 | min -= 60; | ||
295 | } | ||
296 | if (hr > 23) { | ||
297 | day++; | ||
298 | hr -= 24; | ||
299 | } | ||
300 | if (day > 31) { | ||
301 | mo++; | ||
302 | day -= 31; | ||
303 | } | ||
304 | if (mo > 12) { | ||
305 | yr++; | ||
306 | mo -= 12; | ||
307 | } | ||
308 | if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { | ||
309 | BIN_TO_BCD(yr); | ||
310 | BIN_TO_BCD(mo); | ||
311 | BIN_TO_BCD(day); | ||
312 | BIN_TO_BCD(hr); | ||
313 | BIN_TO_BCD(min); | ||
314 | BIN_TO_BCD(sec); | ||
315 | } | ||
316 | |||
317 | spin_lock_irq(&rtc_lock); | ||
318 | /* | ||
319 | * Disable alarm interrupt before setting alarm timer or else | ||
320 | * when ACPI_EVENT_RTC is enabled, a spurious ACPI interrupt occurs | ||
321 | */ | ||
322 | rtc_control &= ~RTC_AIE; | ||
323 | CMOS_WRITE(rtc_control, RTC_CONTROL); | ||
324 | CMOS_READ(RTC_INTR_FLAGS); | ||
325 | |||
326 | /* write the fields the rtc knows about */ | ||
327 | CMOS_WRITE(hr, RTC_HOURS_ALARM); | ||
328 | CMOS_WRITE(min, RTC_MINUTES_ALARM); | ||
329 | CMOS_WRITE(sec, RTC_SECONDS_ALARM); | ||
330 | |||
331 | /* | ||
332 | * If the system supports an enhanced alarm it will have non-zero | ||
333 | * offsets into the CMOS RAM here -- which for some reason are pointing | ||
334 | * to the RTC area of memory. | ||
335 | */ | ||
336 | if (acpi_gbl_FADT->day_alrm) | ||
337 | CMOS_WRITE(day, acpi_gbl_FADT->day_alrm); | ||
338 | if (acpi_gbl_FADT->mon_alrm) | ||
339 | CMOS_WRITE(mo, acpi_gbl_FADT->mon_alrm); | ||
340 | if (acpi_gbl_FADT->century) | ||
341 | CMOS_WRITE(yr/100, acpi_gbl_FADT->century); | ||
342 | /* enable the rtc alarm interrupt */ | ||
343 | rtc_control |= RTC_AIE; | ||
344 | CMOS_WRITE(rtc_control, RTC_CONTROL); | ||
345 | CMOS_READ(RTC_INTR_FLAGS); | ||
346 | |||
347 | spin_unlock_irq(&rtc_lock); | ||
348 | |||
349 | acpi_clear_event(ACPI_EVENT_RTC); | ||
350 | acpi_enable_event(ACPI_EVENT_RTC, 0); | ||
351 | |||
352 | *ppos += count; | ||
353 | |||
354 | result = 0; | ||
355 | end: | ||
356 | return_VALUE(result ? result : count); | ||
357 | } | ||
358 | |||
359 | extern struct list_head acpi_wakeup_device_list; | ||
360 | extern spinlock_t acpi_device_lock; | ||
361 | |||
362 | static int | ||
363 | acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset) | ||
364 | { | ||
365 | struct list_head * node, * next; | ||
366 | |||
367 | seq_printf(seq, "Device Sleep state Status\n"); | ||
368 | |||
369 | spin_lock(&acpi_device_lock); | ||
370 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { | ||
371 | struct acpi_device * dev = container_of(node, struct acpi_device, wakeup_list); | ||
372 | |||
373 | if (!dev->wakeup.flags.valid) | ||
374 | continue; | ||
375 | spin_unlock(&acpi_device_lock); | ||
376 | if (dev->wakeup.flags.run_wake) | ||
377 | seq_printf(seq, "%4s %4d %8s\n", | ||
378 | dev->pnp.bus_id, (u32) dev->wakeup.sleep_state, | ||
379 | dev->wakeup.state.enabled ? "*enabled" : "*disabled"); | ||
380 | else | ||
381 | seq_printf(seq, "%4s %4d %8s\n", | ||
382 | dev->pnp.bus_id, (u32) dev->wakeup.sleep_state, | ||
383 | dev->wakeup.state.enabled ? "enabled" : "disabled"); | ||
384 | spin_lock(&acpi_device_lock); | ||
385 | } | ||
386 | spin_unlock(&acpi_device_lock); | ||
387 | return 0; | ||
388 | } | ||
389 | |||
390 | static ssize_t | ||
391 | acpi_system_write_wakeup_device ( | ||
392 | struct file *file, | ||
393 | const char __user *buffer, | ||
394 | size_t count, | ||
395 | loff_t *ppos) | ||
396 | { | ||
397 | struct list_head * node, * next; | ||
398 | char strbuf[5]; | ||
399 | char str[5] = ""; | ||
400 | int len = count; | ||
401 | struct acpi_device *found_dev = NULL; | ||
402 | |||
403 | if (len > 4) len = 4; | ||
404 | |||
405 | if (copy_from_user(strbuf, buffer, len)) | ||
406 | return -EFAULT; | ||
407 | strbuf[len] = '\0'; | ||
408 | sscanf(strbuf, "%s", str); | ||
409 | |||
410 | spin_lock(&acpi_device_lock); | ||
411 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { | ||
412 | struct acpi_device * dev = container_of(node, struct acpi_device, wakeup_list); | ||
413 | if (!dev->wakeup.flags.valid) | ||
414 | continue; | ||
415 | |||
416 | if (!strncmp(dev->pnp.bus_id, str, 4)) { | ||
417 | dev->wakeup.state.enabled = dev->wakeup.state.enabled ? 0:1; | ||
418 | found_dev = dev; | ||
419 | break; | ||
420 | } | ||
421 | } | ||
422 | if (found_dev) { | ||
423 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { | ||
424 | struct acpi_device * dev = container_of(node, | ||
425 | struct acpi_device, wakeup_list); | ||
426 | |||
427 | if ((dev != found_dev) && | ||
428 | (dev->wakeup.gpe_number == found_dev->wakeup.gpe_number) && | ||
429 | (dev->wakeup.gpe_device == found_dev->wakeup.gpe_device)) { | ||
430 | printk(KERN_WARNING "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 = found_dev->wakeup.state.enabled; | ||
434 | } | ||
435 | } | ||
436 | } | ||
437 | spin_unlock(&acpi_device_lock); | ||
438 | return count; | ||
439 | } | ||
440 | |||
441 | static int | ||
442 | acpi_system_wakeup_device_open_fs(struct inode *inode, struct file *file) | ||
443 | { | ||
444 | return single_open(file, acpi_system_wakeup_device_seq_show, PDE(inode)->data); | ||
445 | } | ||
446 | |||
447 | static struct file_operations acpi_system_wakeup_device_fops = { | ||
448 | .open = acpi_system_wakeup_device_open_fs, | ||
449 | .read = seq_read, | ||
450 | .write = acpi_system_write_wakeup_device, | ||
451 | .llseek = seq_lseek, | ||
452 | .release = single_release, | ||
453 | }; | ||
454 | |||
455 | static struct file_operations acpi_system_sleep_fops = { | ||
456 | .open = acpi_system_sleep_open_fs, | ||
457 | .read = seq_read, | ||
458 | .write = acpi_system_write_sleep, | ||
459 | .llseek = seq_lseek, | ||
460 | .release = single_release, | ||
461 | }; | ||
462 | |||
463 | static struct file_operations acpi_system_alarm_fops = { | ||
464 | .open = acpi_system_alarm_open_fs, | ||
465 | .read = seq_read, | ||
466 | .write = acpi_system_write_alarm, | ||
467 | .llseek = seq_lseek, | ||
468 | .release = single_release, | ||
469 | }; | ||
470 | |||
471 | |||
472 | static u32 rtc_handler(void * context) | ||
473 | { | ||
474 | acpi_clear_event(ACPI_EVENT_RTC); | ||
475 | acpi_disable_event(ACPI_EVENT_RTC, 0); | ||
476 | |||
477 | return ACPI_INTERRUPT_HANDLED; | ||
478 | } | ||
479 | |||
480 | static int acpi_sleep_proc_init(void) | ||
481 | { | ||
482 | struct proc_dir_entry *entry = NULL; | ||
483 | |||
484 | if (acpi_disabled) | ||
485 | return 0; | ||
486 | |||
487 | /* 'sleep' [R/W]*/ | ||
488 | entry = create_proc_entry(ACPI_SYSTEM_FILE_SLEEP, | ||
489 | S_IFREG|S_IRUGO|S_IWUSR, acpi_root_dir); | ||
490 | if (entry) | ||
491 | entry->proc_fops = &acpi_system_sleep_fops; | ||
492 | |||
493 | /* 'alarm' [R/W] */ | ||
494 | entry = create_proc_entry(ACPI_SYSTEM_FILE_ALARM, | ||
495 | S_IFREG|S_IRUGO|S_IWUSR, acpi_root_dir); | ||
496 | if (entry) | ||
497 | entry->proc_fops = &acpi_system_alarm_fops; | ||
498 | |||
499 | /* 'wakeup device' [R/W]*/ | ||
500 | entry = create_proc_entry(ACPI_SYSTEM_FILE_WAKEUP_DEVICE, | ||
501 | S_IFREG|S_IRUGO|S_IWUSR, acpi_root_dir); | ||
502 | if (entry) | ||
503 | entry->proc_fops = &acpi_system_wakeup_device_fops; | ||
504 | |||
505 | acpi_install_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler, NULL); | ||
506 | return 0; | ||
507 | } | ||
508 | |||
509 | late_initcall(acpi_sleep_proc_init); | ||
diff --git a/drivers/acpi/sleep/sleep.h b/drivers/acpi/sleep/sleep.h new file mode 100644 index 000000000000..efd0001c6f05 --- /dev/null +++ b/drivers/acpi/sleep/sleep.h | |||
@@ -0,0 +1,8 @@ | |||
1 | |||
2 | extern u8 sleep_states[]; | ||
3 | extern int acpi_suspend (u32 state); | ||
4 | |||
5 | extern void acpi_enable_wakeup_device_prep(u8 sleep_state); | ||
6 | extern void acpi_enable_wakeup_device(u8 sleep_state); | ||
7 | extern void acpi_disable_wakeup_device(u8 sleep_state); | ||
8 | extern void acpi_wakeup_gpe_poweroff_prepare(void); | ||
diff --git a/drivers/acpi/sleep/wakeup.c b/drivers/acpi/sleep/wakeup.c new file mode 100644 index 000000000000..d9b199969d5d --- /dev/null +++ b/drivers/acpi/sleep/wakeup.c | |||
@@ -0,0 +1,209 @@ | |||
1 | /* | ||
2 | * wakeup.c - support wakeup devices | ||
3 | * Copyright (C) 2004 Li Shaohua <shaohua.li@intel.com> | ||
4 | */ | ||
5 | |||
6 | #include <linux/init.h> | ||
7 | #include <linux/acpi.h> | ||
8 | #include <acpi/acpi_drivers.h> | ||
9 | #include <linux/kernel.h> | ||
10 | #include <linux/types.h> | ||
11 | #include <acpi/acevents.h> | ||
12 | #include "sleep.h" | ||
13 | |||
14 | #define _COMPONENT ACPI_SYSTEM_COMPONENT | ||
15 | ACPI_MODULE_NAME ("wakeup_devices") | ||
16 | |||
17 | extern struct list_head acpi_wakeup_device_list; | ||
18 | extern spinlock_t acpi_device_lock; | ||
19 | |||
20 | #ifdef CONFIG_ACPI_SLEEP | ||
21 | /** | ||
22 | * acpi_enable_wakeup_device_prep - prepare wakeup devices | ||
23 | * @sleep_state: ACPI state | ||
24 | * Enable all wakup devices power if the devices' wakeup level | ||
25 | * is higher than requested sleep level | ||
26 | */ | ||
27 | |||
28 | void | ||
29 | acpi_enable_wakeup_device_prep( | ||
30 | u8 sleep_state) | ||
31 | { | ||
32 | struct list_head * node, * next; | ||
33 | |||
34 | ACPI_FUNCTION_TRACE("acpi_enable_wakeup_device_prep"); | ||
35 | |||
36 | spin_lock(&acpi_device_lock); | ||
37 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { | ||
38 | struct acpi_device * dev = container_of(node, | ||
39 | struct acpi_device, wakeup_list); | ||
40 | |||
41 | if (!dev->wakeup.flags.valid || | ||
42 | !dev->wakeup.state.enabled || | ||
43 | (sleep_state > (u32) dev->wakeup.sleep_state)) | ||
44 | continue; | ||
45 | |||
46 | spin_unlock(&acpi_device_lock); | ||
47 | acpi_enable_wakeup_device_power(dev); | ||
48 | spin_lock(&acpi_device_lock); | ||
49 | } | ||
50 | spin_unlock(&acpi_device_lock); | ||
51 | } | ||
52 | |||
53 | /** | ||
54 | * acpi_enable_wakeup_device - enable wakeup devices | ||
55 | * @sleep_state: ACPI state | ||
56 | * Enable all wakup devices's GPE | ||
57 | */ | ||
58 | void | ||
59 | acpi_enable_wakeup_device( | ||
60 | u8 sleep_state) | ||
61 | { | ||
62 | struct list_head * node, * next; | ||
63 | |||
64 | /* | ||
65 | * Caution: this routine must be invoked when interrupt is disabled | ||
66 | * Refer ACPI2.0: P212 | ||
67 | */ | ||
68 | ACPI_FUNCTION_TRACE("acpi_enable_wakeup_device"); | ||
69 | spin_lock(&acpi_device_lock); | ||
70 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { | ||
71 | struct acpi_device * dev = container_of(node, | ||
72 | struct acpi_device, wakeup_list); | ||
73 | |||
74 | /* If users want to disable run-wake GPE, | ||
75 | * we only disable it for wake and leave it for runtime | ||
76 | */ | ||
77 | if (dev->wakeup.flags.run_wake && !dev->wakeup.state.enabled) { | ||
78 | spin_unlock(&acpi_device_lock); | ||
79 | acpi_set_gpe_type(dev->wakeup.gpe_device, | ||
80 | dev->wakeup.gpe_number, ACPI_GPE_TYPE_RUNTIME); | ||
81 | /* Re-enable it, since set_gpe_type will disable it */ | ||
82 | acpi_enable_gpe(dev->wakeup.gpe_device, | ||
83 | dev->wakeup.gpe_number, ACPI_ISR); | ||
84 | spin_lock(&acpi_device_lock); | ||
85 | continue; | ||
86 | } | ||
87 | |||
88 | if (!dev->wakeup.flags.valid || | ||
89 | !dev->wakeup.state.enabled || | ||
90 | (sleep_state > (u32) dev->wakeup.sleep_state)) | ||
91 | continue; | ||
92 | |||
93 | spin_unlock(&acpi_device_lock); | ||
94 | /* run-wake GPE has been enabled */ | ||
95 | if (!dev->wakeup.flags.run_wake) | ||
96 | acpi_enable_gpe(dev->wakeup.gpe_device, | ||
97 | dev->wakeup.gpe_number, ACPI_ISR); | ||
98 | dev->wakeup.state.active = 1; | ||
99 | spin_lock(&acpi_device_lock); | ||
100 | } | ||
101 | spin_unlock(&acpi_device_lock); | ||
102 | } | ||
103 | |||
104 | /** | ||
105 | * acpi_disable_wakeup_device - disable devices' wakeup capability | ||
106 | * @sleep_state: ACPI state | ||
107 | * Disable all wakup devices's GPE and wakeup capability | ||
108 | */ | ||
109 | void | ||
110 | acpi_disable_wakeup_device ( | ||
111 | u8 sleep_state) | ||
112 | { | ||
113 | struct list_head * node, * next; | ||
114 | |||
115 | ACPI_FUNCTION_TRACE("acpi_disable_wakeup_device"); | ||
116 | |||
117 | spin_lock(&acpi_device_lock); | ||
118 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { | ||
119 | struct acpi_device * dev = container_of(node, | ||
120 | struct acpi_device, wakeup_list); | ||
121 | |||
122 | if (dev->wakeup.flags.run_wake && !dev->wakeup.state.enabled) { | ||
123 | spin_unlock(&acpi_device_lock); | ||
124 | acpi_set_gpe_type(dev->wakeup.gpe_device, | ||
125 | dev->wakeup.gpe_number, ACPI_GPE_TYPE_WAKE_RUN); | ||
126 | /* Re-enable it, since set_gpe_type will disable it */ | ||
127 | acpi_enable_gpe(dev->wakeup.gpe_device, | ||
128 | dev->wakeup.gpe_number, ACPI_NOT_ISR); | ||
129 | spin_lock(&acpi_device_lock); | ||
130 | continue; | ||
131 | } | ||
132 | |||
133 | if (!dev->wakeup.flags.valid || | ||
134 | !dev->wakeup.state.active || | ||
135 | (sleep_state > (u32) dev->wakeup.sleep_state)) | ||
136 | continue; | ||
137 | |||
138 | spin_unlock(&acpi_device_lock); | ||
139 | acpi_disable_wakeup_device_power(dev); | ||
140 | /* Never disable run-wake GPE */ | ||
141 | if (!dev->wakeup.flags.run_wake) { | ||
142 | acpi_disable_gpe(dev->wakeup.gpe_device, | ||
143 | dev->wakeup.gpe_number, ACPI_NOT_ISR); | ||
144 | acpi_clear_gpe(dev->wakeup.gpe_device, | ||
145 | dev->wakeup.gpe_number, ACPI_NOT_ISR); | ||
146 | } | ||
147 | dev->wakeup.state.active = 0; | ||
148 | spin_lock(&acpi_device_lock); | ||
149 | } | ||
150 | spin_unlock(&acpi_device_lock); | ||
151 | } | ||
152 | |||
153 | static int __init acpi_wakeup_device_init(void) | ||
154 | { | ||
155 | struct list_head * node, * next; | ||
156 | |||
157 | if (acpi_disabled) | ||
158 | return 0; | ||
159 | printk("ACPI wakeup devices: \n"); | ||
160 | |||
161 | spin_lock(&acpi_device_lock); | ||
162 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { | ||
163 | struct acpi_device * dev = container_of(node, | ||
164 | struct acpi_device, wakeup_list); | ||
165 | |||
166 | /* In case user doesn't load button driver */ | ||
167 | if (dev->wakeup.flags.run_wake && !dev->wakeup.state.enabled) { | ||
168 | spin_unlock(&acpi_device_lock); | ||
169 | acpi_set_gpe_type(dev->wakeup.gpe_device, | ||
170 | dev->wakeup.gpe_number, ACPI_GPE_TYPE_WAKE_RUN); | ||
171 | acpi_enable_gpe(dev->wakeup.gpe_device, | ||
172 | dev->wakeup.gpe_number, ACPI_NOT_ISR); | ||
173 | dev->wakeup.state.enabled = 1; | ||
174 | spin_lock(&acpi_device_lock); | ||
175 | } | ||
176 | printk("%4s ", dev->pnp.bus_id); | ||
177 | } | ||
178 | spin_unlock(&acpi_device_lock); | ||
179 | printk("\n"); | ||
180 | |||
181 | return 0; | ||
182 | } | ||
183 | |||
184 | late_initcall(acpi_wakeup_device_init); | ||
185 | #endif | ||
186 | |||
187 | /* | ||
188 | * Disable all wakeup GPEs before power off. | ||
189 | * | ||
190 | * Since acpi_enter_sleep_state() will disable all | ||
191 | * RUNTIME GPEs, we simply mark all GPES that | ||
192 | * are not enabled for wakeup from S5 as RUNTIME. | ||
193 | */ | ||
194 | void acpi_wakeup_gpe_poweroff_prepare(void) | ||
195 | { | ||
196 | struct list_head * node, * next; | ||
197 | |||
198 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { | ||
199 | struct acpi_device * dev = container_of(node, | ||
200 | struct acpi_device, wakeup_list); | ||
201 | |||
202 | /* The GPE can wakeup system from S5, don't touch it */ | ||
203 | if ((u32)dev->wakeup.sleep_state == ACPI_STATE_S5) | ||
204 | continue; | ||
205 | /* acpi_set_gpe_type will automatically disable GPE */ | ||
206 | acpi_set_gpe_type(dev->wakeup.gpe_device, | ||
207 | dev->wakeup.gpe_number, ACPI_GPE_TYPE_RUNTIME); | ||
208 | } | ||
209 | } | ||