Skip to content

Commit fa8f53a

Browse files
committed
Merge branch 'x86-olpc-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'x86-olpc-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: x86, olpc-xo15-sci: Enable EC wakeup capability x86, olpc: Fix dependency on POWER_SUPPLY x86, olpc: Add XO-1.5 SCI driver x86, olpc: Add XO-1 RTC driver x86, olpc-xo1-sci: Propagate power supply/battery events x86, olpc-xo1-sci: Add lid switch functionality x86, olpc-xo1-sci: Add GPE handler and ebook switch functionality x86, olpc: EC SCI wakeup mask functionality x86, olpc: Add XO-1 SCI driver and power button control x86, olpc: Add XO-1 suspend/resume support x86, olpc: Rename olpc-xo1 to olpc-xo1-pm x86, olpc: Move CS5536-related constants to cs5535.h x86, olpc: Add missing elements to device tree
2 parents 1d87c28 + 07d5b38 commit fa8f53a

13 files changed

Lines changed: 1547 additions & 163 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
OLPC XO-1 RTC
2+
~~~~~~~~~~~~~
3+
4+
Required properties:
5+
- compatible : "olpc,xo1-rtc"

‎arch/x86/Kconfig‎

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,11 +2024,44 @@ config OLPC
20242024
Add support for detecting the unique features of the OLPC
20252025
XO hardware.
20262026

2027-
config OLPC_XO1
2028-
tristate "OLPC XO-1 support"
2029-
depends on OLPC && MFD_CS5535
2030-
---help---
2031-
Add support for non-essential features of the OLPC XO-1 laptop.
2027+
config OLPC_XO1_PM
2028+
bool "OLPC XO-1 Power Management"
2029+
depends on OLPC && MFD_CS5535 && PM_SLEEP
2030+
select MFD_CORE
2031+
---help---
2032+
Add support for poweroff and suspend of the OLPC XO-1 laptop.
2033+
2034+
config OLPC_XO1_RTC
2035+
bool "OLPC XO-1 Real Time Clock"
2036+
depends on OLPC_XO1_PM && RTC_DRV_CMOS
2037+
---help---
2038+
Add support for the XO-1 real time clock, which can be used as a
2039+
programmable wakeup source.
2040+
2041+
config OLPC_XO1_SCI
2042+
bool "OLPC XO-1 SCI extras"
2043+
depends on OLPC && OLPC_XO1_PM
2044+
select POWER_SUPPLY
2045+
select GPIO_CS5535
2046+
select MFD_CORE
2047+
---help---
2048+
Add support for SCI-based features of the OLPC XO-1 laptop:
2049+
- EC-driven system wakeups
2050+
- Power button
2051+
- Ebook switch
2052+
- Lid switch
2053+
- AC adapter status updates
2054+
- Battery status updates
2055+
2056+
config OLPC_XO15_SCI
2057+
bool "OLPC XO-1.5 SCI extras"
2058+
depends on OLPC && ACPI
2059+
select POWER_SUPPLY
2060+
---help---
2061+
Add support for SCI-based features of the OLPC XO-1.5 laptop:
2062+
- EC-driven system wakeups
2063+
- AC adapter status updates
2064+
- Battery status updates
20322065

20332066
endif # X86_32
20342067

‎arch/x86/include/asm/olpc.h‎

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct olpc_platform_t {
1313

1414
#define OLPC_F_PRESENT 0x01
1515
#define OLPC_F_DCON 0x02
16+
#define OLPC_F_EC_WIDE_SCI 0x04
1617

1718
#ifdef CONFIG_OLPC
1819

@@ -62,6 +63,13 @@ static inline int olpc_board_at_least(uint32_t rev)
6263
return olpc_platform_info.boardrev >= rev;
6364
}
6465

66+
extern void olpc_ec_wakeup_set(u16 value);
67+
extern void olpc_ec_wakeup_clear(u16 value);
68+
extern bool olpc_ec_wakeup_available(void);
69+
70+
extern int olpc_ec_mask_write(u16 bits);
71+
extern int olpc_ec_sci_query(u16 *sci_value);
72+
6573
#else
6674

6775
static inline int machine_is_olpc(void)
@@ -74,6 +82,20 @@ static inline int olpc_has_dcon(void)
7482
return 0;
7583
}
7684

85+
static inline void olpc_ec_wakeup_set(u16 value) { }
86+
static inline void olpc_ec_wakeup_clear(u16 value) { }
87+
88+
static inline bool olpc_ec_wakeup_available(void)
89+
{
90+
return false;
91+
}
92+
93+
#endif
94+
95+
#ifdef CONFIG_OLPC_XO1_PM
96+
extern void do_olpc_suspend_lowlevel(void);
97+
extern void olpc_xo1_pm_wakeup_set(u16 value);
98+
extern void olpc_xo1_pm_wakeup_clear(u16 value);
7799
#endif
78100

79101
extern int pci_olpc_init(void);
@@ -83,14 +105,19 @@ extern int pci_olpc_init(void);
83105
extern int olpc_ec_cmd(unsigned char cmd, unsigned char *inbuf, size_t inlen,
84106
unsigned char *outbuf, size_t outlen);
85107

86-
extern int olpc_ec_mask_set(uint8_t bits);
87-
extern int olpc_ec_mask_unset(uint8_t bits);
88-
89108
/* EC commands */
90109

91-
#define EC_FIRMWARE_REV 0x08
92-
#define EC_WLAN_ENTER_RESET 0x35
93-
#define EC_WLAN_LEAVE_RESET 0x25
110+
#define EC_FIRMWARE_REV 0x08
111+
#define EC_WRITE_SCI_MASK 0x1b
112+
#define EC_WAKE_UP_WLAN 0x24
113+
#define EC_WLAN_LEAVE_RESET 0x25
114+
#define EC_READ_EB_MODE 0x2a
115+
#define EC_SET_SCI_INHIBIT 0x32
116+
#define EC_SET_SCI_INHIBIT_RELEASE 0x34
117+
#define EC_WLAN_ENTER_RESET 0x35
118+
#define EC_WRITE_EXT_SCI_MASK 0x38
119+
#define EC_SCI_QUERY 0x84
120+
#define EC_EXT_SCI_QUERY 0x85
94121

95122
/* SCI source values */
96123

@@ -99,10 +126,12 @@ extern int olpc_ec_mask_unset(uint8_t bits);
99126
#define EC_SCI_SRC_BATTERY 0x02
100127
#define EC_SCI_SRC_BATSOC 0x04
101128
#define EC_SCI_SRC_BATERR 0x08
102-
#define EC_SCI_SRC_EBOOK 0x10
103-
#define EC_SCI_SRC_WLAN 0x20
129+
#define EC_SCI_SRC_EBOOK 0x10 /* XO-1 only */
130+
#define EC_SCI_SRC_WLAN 0x20 /* XO-1 only */
104131
#define EC_SCI_SRC_ACPWR 0x40
105-
#define EC_SCI_SRC_ALL 0x7F
132+
#define EC_SCI_SRC_BATCRIT 0x80
133+
#define EC_SCI_SRC_GPWAKE 0x100 /* XO-1.5 only */
134+
#define EC_SCI_SRC_ALL 0x1FF
106135

107136
/* GPIO assignments */
108137

@@ -116,7 +145,7 @@ extern int olpc_ec_mask_unset(uint8_t bits);
116145
#define OLPC_GPIO_SMB_CLK 14
117146
#define OLPC_GPIO_SMB_DATA 15
118147
#define OLPC_GPIO_WORKAUX geode_gpio(24)
119-
#define OLPC_GPIO_LID geode_gpio(26)
120-
#define OLPC_GPIO_ECSCI geode_gpio(27)
148+
#define OLPC_GPIO_LID 26
149+
#define OLPC_GPIO_ECSCI 27
121150

122151
#endif /* _ASM_X86_OLPC_H */

‎arch/x86/platform/olpc/Makefile‎

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

0 commit comments

Comments
 (0)