]>
Commit | Line | Data |
---|---|---|
bf1ebf00 | 1 | /* |
a3128588 | 2 | * Support for power management features of the OLPC XO-1 laptop |
bf1ebf00 | 3 | * |
419cdc54 | 4 | * Copyright (C) 2010 Andres Salomon <dilinger@queued.net> |
bf1ebf00 DD |
5 | * Copyright (C) 2010 One Laptop per Child |
6 | * Copyright (C) 2006 Red Hat, Inc. | |
7 | * Copyright (C) 2006 Advanced Micro Devices, Inc. | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | */ | |
14 | ||
7a0d4fcf | 15 | #include <linux/cs5535.h> |
bf1ebf00 | 16 | #include <linux/platform_device.h> |
69c60c88 | 17 | #include <linux/export.h> |
bf1ebf00 | 18 | #include <linux/pm.h> |
1310e6d6 | 19 | #include <linux/mfd/core.h> |
97c4cb71 | 20 | #include <linux/suspend.h> |
3bf9428f | 21 | #include <linux/olpc-ec.h> |
bf1ebf00 DD |
22 | |
23 | #include <asm/io.h> | |
24 | #include <asm/olpc.h> | |
25 | ||
a3128588 | 26 | #define DRV_NAME "olpc-xo1-pm" |
bf1ebf00 | 27 | |
bf1ebf00 DD |
28 | static unsigned long acpi_base; |
29 | static unsigned long pms_base; | |
30 | ||
97c4cb71 DD |
31 | static u16 wakeup_mask = CS5536_PM_PWRBTN; |
32 | ||
33 | static struct { | |
34 | unsigned long address; | |
35 | unsigned short segment; | |
36 | } ofw_bios_entry = { 0xF0000 + PAGE_OFFSET, __KERNEL_CS }; | |
37 | ||
38 | /* Set bits in the wakeup mask */ | |
39 | void olpc_xo1_pm_wakeup_set(u16 value) | |
40 | { | |
41 | wakeup_mask |= value; | |
42 | } | |
43 | EXPORT_SYMBOL_GPL(olpc_xo1_pm_wakeup_set); | |
44 | ||
45 | /* Clear bits in the wakeup mask */ | |
46 | void olpc_xo1_pm_wakeup_clear(u16 value) | |
47 | { | |
48 | wakeup_mask &= ~value; | |
49 | } | |
50 | EXPORT_SYMBOL_GPL(olpc_xo1_pm_wakeup_clear); | |
51 | ||
52 | static int xo1_power_state_enter(suspend_state_t pm_state) | |
53 | { | |
54 | unsigned long saved_sci_mask; | |
55 | int r; | |
56 | ||
57 | /* Only STR is supported */ | |
58 | if (pm_state != PM_SUSPEND_MEM) | |
59 | return -EINVAL; | |
60 | ||
61 | r = olpc_ec_cmd(EC_SET_SCI_INHIBIT, NULL, 0, NULL, 0); | |
62 | if (r) | |
63 | return r; | |
64 | ||
65 | /* | |
66 | * Save SCI mask (this gets lost since PM1_EN is used as a mask for | |
67 | * wakeup events, which is not necessarily the same event set) | |
68 | */ | |
69 | saved_sci_mask = inl(acpi_base + CS5536_PM1_STS); | |
70 | saved_sci_mask &= 0xffff0000; | |
71 | ||
72 | /* Save CPU state */ | |
73 | do_olpc_suspend_lowlevel(); | |
74 | ||
75 | /* Resume path starts here */ | |
76 | ||
77 | /* Restore SCI mask (using dword access to CS5536_PM1_EN) */ | |
78 | outl(saved_sci_mask, acpi_base + CS5536_PM1_STS); | |
79 | ||
80 | /* Tell the EC to stop inhibiting SCIs */ | |
81 | olpc_ec_cmd(EC_SET_SCI_INHIBIT_RELEASE, NULL, 0, NULL, 0); | |
82 | ||
83 | /* | |
84 | * Tell the wireless module to restart USB communication. | |
85 | * Must be done twice. | |
86 | */ | |
87 | olpc_ec_cmd(EC_WAKE_UP_WLAN, NULL, 0, NULL, 0); | |
88 | olpc_ec_cmd(EC_WAKE_UP_WLAN, NULL, 0, NULL, 0); | |
89 | ||
90 | return 0; | |
91 | } | |
92 | ||
93 | asmlinkage int xo1_do_sleep(u8 sleep_state) | |
94 | { | |
95 | void *pgd_addr = __va(read_cr3()); | |
96 | ||
97 | /* Program wakeup mask (using dword access to CS5536_PM1_EN) */ | |
98 | outl(wakeup_mask << 16, acpi_base + CS5536_PM1_STS); | |
99 | ||
100 | __asm__("movl %0,%%eax" : : "r" (pgd_addr)); | |
101 | __asm__("call *(%%edi); cld" | |
102 | : : "D" (&ofw_bios_entry)); | |
103 | __asm__("movb $0x34, %al\n\t" | |
104 | "outb %al, $0x70\n\t" | |
105 | "movb $0x30, %al\n\t" | |
106 | "outb %al, $0x71\n\t"); | |
107 | return 0; | |
108 | } | |
109 | ||
bf1ebf00 DD |
110 | static void xo1_power_off(void) |
111 | { | |
112 | printk(KERN_INFO "OLPC XO-1 power off sequence...\n"); | |
113 | ||
114 | /* Enable all of these controls with 0 delay */ | |
7a0d4fcf DD |
115 | outl(0x40000000, pms_base + CS5536_PM_SCLK); |
116 | outl(0x40000000, pms_base + CS5536_PM_IN_SLPCTL); | |
117 | outl(0x40000000, pms_base + CS5536_PM_WKXD); | |
118 | outl(0x40000000, pms_base + CS5536_PM_WKD); | |
bf1ebf00 DD |
119 | |
120 | /* Clear status bits (possibly unnecessary) */ | |
7a0d4fcf DD |
121 | outl(0x0002ffff, pms_base + CS5536_PM_SSC); |
122 | outl(0xffffffff, acpi_base + CS5536_PM_GPE0_STS); | |
bf1ebf00 DD |
123 | |
124 | /* Write SLP_EN bit to start the machinery */ | |
7a0d4fcf | 125 | outl(0x00002000, acpi_base + CS5536_PM1_CNT); |
bf1ebf00 DD |
126 | } |
127 | ||
97c4cb71 DD |
128 | static int xo1_power_state_valid(suspend_state_t pm_state) |
129 | { | |
130 | /* suspend-to-RAM only */ | |
131 | return pm_state == PM_SUSPEND_MEM; | |
132 | } | |
133 | ||
134 | static const struct platform_suspend_ops xo1_suspend_ops = { | |
135 | .valid = xo1_power_state_valid, | |
136 | .enter = xo1_power_state_enter, | |
137 | }; | |
138 | ||
a3128588 | 139 | static int __devinit xo1_pm_probe(struct platform_device *pdev) |
bf1ebf00 | 140 | { |
419cdc54 | 141 | struct resource *res; |
1310e6d6 | 142 | int err; |
bf1ebf00 | 143 | |
419cdc54 AS |
144 | /* don't run on non-XOs */ |
145 | if (!machine_is_olpc()) | |
146 | return -ENODEV; | |
bf1ebf00 | 147 | |
f77289ac | 148 | err = mfd_cell_enable(pdev); |
1310e6d6 AS |
149 | if (err) |
150 | return err; | |
151 | ||
419cdc54 AS |
152 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
153 | if (!res) { | |
154 | dev_err(&pdev->dev, "can't fetch device resource info\n"); | |
155 | return -EIO; | |
bf1ebf00 | 156 | } |
adfa4bd4 | 157 | if (strcmp(pdev->name, "cs5535-pms") == 0) |
419cdc54 | 158 | pms_base = res->start; |
adfa4bd4 | 159 | else if (strcmp(pdev->name, "olpc-xo1-pm-acpi") == 0) |
419cdc54 AS |
160 | acpi_base = res->start; |
161 | ||
162 | /* If we have both addresses, we can override the poweroff hook */ | |
163 | if (pms_base && acpi_base) { | |
97c4cb71 | 164 | suspend_set_ops(&xo1_suspend_ops); |
419cdc54 AS |
165 | pm_power_off = xo1_power_off; |
166 | printk(KERN_INFO "OLPC XO-1 support registered\n"); | |
167 | } | |
bf1ebf00 DD |
168 | |
169 | return 0; | |
170 | } | |
171 | ||
a3128588 | 172 | static int __devexit xo1_pm_remove(struct platform_device *pdev) |
bf1ebf00 | 173 | { |
f77289ac | 174 | mfd_cell_disable(pdev); |
bf1ebf00 | 175 | |
adfa4bd4 | 176 | if (strcmp(pdev->name, "cs5535-pms") == 0) |
419cdc54 | 177 | pms_base = 0; |
adfa4bd4 | 178 | else if (strcmp(pdev->name, "olpc-xo1-pm-acpi") == 0) |
419cdc54 | 179 | acpi_base = 0; |
bf1ebf00 | 180 | |
bf1ebf00 DD |
181 | pm_power_off = NULL; |
182 | return 0; | |
183 | } | |
184 | ||
a3128588 | 185 | static struct platform_driver cs5535_pms_driver = { |
419cdc54 | 186 | .driver = { |
adfa4bd4 | 187 | .name = "cs5535-pms", |
419cdc54 AS |
188 | .owner = THIS_MODULE, |
189 | }, | |
a3128588 DD |
190 | .probe = xo1_pm_probe, |
191 | .remove = __devexit_p(xo1_pm_remove), | |
419cdc54 AS |
192 | }; |
193 | ||
a3128588 | 194 | static struct platform_driver cs5535_acpi_driver = { |
bf1ebf00 | 195 | .driver = { |
adfa4bd4 | 196 | .name = "olpc-xo1-pm-acpi", |
bf1ebf00 DD |
197 | .owner = THIS_MODULE, |
198 | }, | |
a3128588 DD |
199 | .probe = xo1_pm_probe, |
200 | .remove = __devexit_p(xo1_pm_remove), | |
bf1ebf00 DD |
201 | }; |
202 | ||
a3128588 | 203 | static int __init xo1_pm_init(void) |
bf1ebf00 | 204 | { |
419cdc54 AS |
205 | int r; |
206 | ||
a3128588 | 207 | r = platform_driver_register(&cs5535_pms_driver); |
419cdc54 AS |
208 | if (r) |
209 | return r; | |
210 | ||
a3128588 | 211 | r = platform_driver_register(&cs5535_acpi_driver); |
419cdc54 | 212 | if (r) |
a3128588 | 213 | platform_driver_unregister(&cs5535_pms_driver); |
419cdc54 AS |
214 | |
215 | return r; | |
bf1ebf00 | 216 | } |
a3128588 | 217 | arch_initcall(xo1_pm_init); |