Revert "tty: hvc: Fix data abort due to race in hvc_open"
[linux/fpc-iii.git] / arch / x86 / platform / olpc / olpc-xo1-pm.c
blobf067ac780ba7aa269d4f366d4f396131e8b7cea8
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Support for power management features of the OLPC XO-1 laptop
5 * Copyright (C) 2010 Andres Salomon <dilinger@queued.net>
6 * Copyright (C) 2010 One Laptop per Child
7 * Copyright (C) 2006 Red Hat, Inc.
8 * Copyright (C) 2006 Advanced Micro Devices, Inc.
9 */
11 #include <linux/cs5535.h>
12 #include <linux/platform_device.h>
13 #include <linux/export.h>
14 #include <linux/pm.h>
15 #include <linux/suspend.h>
16 #include <linux/olpc-ec.h>
18 #include <asm/io.h>
19 #include <asm/olpc.h>
21 #define DRV_NAME "olpc-xo1-pm"
23 static unsigned long acpi_base;
24 static unsigned long pms_base;
26 static u16 wakeup_mask = CS5536_PM_PWRBTN;
28 static struct {
29 unsigned long address;
30 unsigned short segment;
31 } ofw_bios_entry = { 0xF0000 + PAGE_OFFSET, __KERNEL_CS };
33 /* Set bits in the wakeup mask */
34 void olpc_xo1_pm_wakeup_set(u16 value)
36 wakeup_mask |= value;
38 EXPORT_SYMBOL_GPL(olpc_xo1_pm_wakeup_set);
40 /* Clear bits in the wakeup mask */
41 void olpc_xo1_pm_wakeup_clear(u16 value)
43 wakeup_mask &= ~value;
45 EXPORT_SYMBOL_GPL(olpc_xo1_pm_wakeup_clear);
47 static int xo1_power_state_enter(suspend_state_t pm_state)
49 unsigned long saved_sci_mask;
51 /* Only STR is supported */
52 if (pm_state != PM_SUSPEND_MEM)
53 return -EINVAL;
56 * Save SCI mask (this gets lost since PM1_EN is used as a mask for
57 * wakeup events, which is not necessarily the same event set)
59 saved_sci_mask = inl(acpi_base + CS5536_PM1_STS);
60 saved_sci_mask &= 0xffff0000;
62 /* Save CPU state */
63 do_olpc_suspend_lowlevel();
65 /* Resume path starts here */
67 /* Restore SCI mask (using dword access to CS5536_PM1_EN) */
68 outl(saved_sci_mask, acpi_base + CS5536_PM1_STS);
70 return 0;
73 asmlinkage __visible int xo1_do_sleep(u8 sleep_state)
75 void *pgd_addr = __va(read_cr3_pa());
77 /* Program wakeup mask (using dword access to CS5536_PM1_EN) */
78 outl(wakeup_mask << 16, acpi_base + CS5536_PM1_STS);
80 __asm__("movl %0,%%eax" : : "r" (pgd_addr));
81 __asm__("call *(%%edi); cld"
82 : : "D" (&ofw_bios_entry));
83 __asm__("movb $0x34, %al\n\t"
84 "outb %al, $0x70\n\t"
85 "movb $0x30, %al\n\t"
86 "outb %al, $0x71\n\t");
87 return 0;
90 static void xo1_power_off(void)
92 printk(KERN_INFO "OLPC XO-1 power off sequence...\n");
94 /* Enable all of these controls with 0 delay */
95 outl(0x40000000, pms_base + CS5536_PM_SCLK);
96 outl(0x40000000, pms_base + CS5536_PM_IN_SLPCTL);
97 outl(0x40000000, pms_base + CS5536_PM_WKXD);
98 outl(0x40000000, pms_base + CS5536_PM_WKD);
100 /* Clear status bits (possibly unnecessary) */
101 outl(0x0002ffff, pms_base + CS5536_PM_SSC);
102 outl(0xffffffff, acpi_base + CS5536_PM_GPE0_STS);
104 /* Write SLP_EN bit to start the machinery */
105 outl(0x00002000, acpi_base + CS5536_PM1_CNT);
108 static int xo1_power_state_valid(suspend_state_t pm_state)
110 /* suspend-to-RAM only */
111 return pm_state == PM_SUSPEND_MEM;
114 static const struct platform_suspend_ops xo1_suspend_ops = {
115 .valid = xo1_power_state_valid,
116 .enter = xo1_power_state_enter,
119 static int xo1_pm_probe(struct platform_device *pdev)
121 struct resource *res;
123 /* don't run on non-XOs */
124 if (!machine_is_olpc())
125 return -ENODEV;
127 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
128 if (!res) {
129 dev_err(&pdev->dev, "can't fetch device resource info\n");
130 return -EIO;
132 if (strcmp(pdev->name, "cs5535-pms") == 0)
133 pms_base = res->start;
134 else if (strcmp(pdev->name, "olpc-xo1-pm-acpi") == 0)
135 acpi_base = res->start;
137 /* If we have both addresses, we can override the poweroff hook */
138 if (pms_base && acpi_base) {
139 suspend_set_ops(&xo1_suspend_ops);
140 pm_power_off = xo1_power_off;
141 printk(KERN_INFO "OLPC XO-1 support registered\n");
144 return 0;
147 static int xo1_pm_remove(struct platform_device *pdev)
149 if (strcmp(pdev->name, "cs5535-pms") == 0)
150 pms_base = 0;
151 else if (strcmp(pdev->name, "olpc-xo1-pm-acpi") == 0)
152 acpi_base = 0;
154 pm_power_off = NULL;
155 return 0;
158 static struct platform_driver cs5535_pms_driver = {
159 .driver = {
160 .name = "cs5535-pms",
162 .probe = xo1_pm_probe,
163 .remove = xo1_pm_remove,
166 static struct platform_driver cs5535_acpi_driver = {
167 .driver = {
168 .name = "olpc-xo1-pm-acpi",
170 .probe = xo1_pm_probe,
171 .remove = xo1_pm_remove,
174 static int __init xo1_pm_init(void)
176 int r;
178 r = platform_driver_register(&cs5535_pms_driver);
179 if (r)
180 return r;
182 r = platform_driver_register(&cs5535_acpi_driver);
183 if (r)
184 platform_driver_unregister(&cs5535_pms_driver);
186 return r;
188 arch_initcall(xo1_pm_init);