1 // SPDX-License-Identifier: GPL-2.0-or-later
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.
11 #include <linux/cs5535.h>
12 #include <linux/platform_device.h>
13 #include <linux/export.h>
15 #include <linux/suspend.h>
16 #include <linux/olpc-ec.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
;
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
)
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
)
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;
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
);
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"
86 "outb %al, $0x71\n\t");
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())
127 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
129 dev_err(&pdev
->dev
, "can't fetch device resource info\n");
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");
147 static int xo1_pm_remove(struct platform_device
*pdev
)
149 if (strcmp(pdev
->name
, "cs5535-pms") == 0)
151 else if (strcmp(pdev
->name
, "olpc-xo1-pm-acpi") == 0)
158 static struct platform_driver cs5535_pms_driver
= {
160 .name
= "cs5535-pms",
162 .probe
= xo1_pm_probe
,
163 .remove
= xo1_pm_remove
,
166 static struct platform_driver cs5535_acpi_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)
178 r
= platform_driver_register(&cs5535_pms_driver
);
182 r
= platform_driver_register(&cs5535_acpi_driver
);
184 platform_driver_unregister(&cs5535_pms_driver
);
188 arch_initcall(xo1_pm_init
);