Skip to content

Commit 3ef0e1f

Browse files
dilingertorvalds
authored andcommitted
x86: olpc: add One Laptop Per Child architecture support
This adds support for OLPC XO hardware. Open Firmware on XOs don't contain the VSA, so it is necessary to emulate the PCI BARs in the kernel. This also adds functionality for running EC commands, and a CONFIG_OLPC. A number of OLPC drivers depend upon CONFIG_OLPC. olpc_ec_timeout is a hack to work around Embedded Controller bugs. [akpm@linux-foundation.org: build fix] [akpm@linux-foundation.org: geode_has_vsa build fix] [akpm@linux-foundation.org: olpc_register_battery_callback doesn't exist] Signed-off-by: Andres Salomon <dilinger@debian.org> Acked-by: Ingo Molnar <mingo@elte.hu> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Andi Kleen <ak@suse.de> Cc: Jordan Crouse <jordan.crouse@amd.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 2f9b12a commit 3ef0e1f

File tree

10 files changed

+736
-3
lines changed

10 files changed

+736
-3
lines changed

Documentation/kernel-parameters.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,13 @@ and is between 256 and 4096 characters. It is defined in the file
13891389

13901390
nr_uarts= [SERIAL] maximum number of UARTs to be registered.
13911391

1392+
olpc_ec_timeout= [OLPC] ms delay when issuing EC commands
1393+
Rather than timing out after 20 ms if an EC
1394+
command is not properly ACKed, override the length
1395+
of the timeout. We have interrupts disabled while
1396+
waiting for the ACK, so if this is set too high
1397+
interrupts *may* be lost!
1398+
13921399
opl3= [HW,OSS]
13931400
Format: <io>
13941401

arch/x86/Kconfig

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,10 @@ config PCI_GODIRECT
15041504
config PCI_GOANY
15051505
bool "Any"
15061506

1507+
config PCI_GOOLPC
1508+
bool "OLPC"
1509+
depends on OLPC
1510+
15071511
endchoice
15081512

15091513
config PCI_BIOS
@@ -1513,12 +1517,17 @@ config PCI_BIOS
15131517
# x86-64 doesn't support PCI BIOS access from long mode so always go direct.
15141518
config PCI_DIRECT
15151519
def_bool y
1516-
depends on PCI && (X86_64 || (PCI_GODIRECT || PCI_GOANY) || X86_VISWS)
1520+
depends on PCI && (X86_64 || (PCI_GODIRECT || PCI_GOANY || PCI_GOOLPC) || X86_VISWS)
15171521

15181522
config PCI_MMCONFIG
15191523
def_bool y
15201524
depends on X86_32 && PCI && ACPI && (PCI_GOMMCONFIG || PCI_GOANY)
15211525

1526+
config PCI_OLPC
1527+
bool
1528+
depends on PCI && PCI_GOOLPC
1529+
default y
1530+
15221531
config PCI_DOMAINS
15231532
def_bool y
15241533
depends on PCI
@@ -1638,6 +1647,13 @@ config GEODE_MFGPT_TIMER
16381647
MFGPTs have a better resolution and max interval than the
16391648
generic PIT, and are suitable for use as high-res timers.
16401649

1650+
config OLPC
1651+
bool "One Laptop Per Child support"
1652+
default n
1653+
help
1654+
Add support for detecting the unique features of the OLPC
1655+
XO hardware.
1656+
16411657
endif # X86_32
16421658

16431659
config K8_NB

arch/x86/kernel/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ endif
9191
obj-$(CONFIG_SCx200) += scx200.o
9292
scx200-y += scx200_32.o
9393

94+
obj-$(CONFIG_OLPC) += olpc.o
95+
9496
###
9597
# 64 bit specific files
9698
ifeq ($(CONFIG_X86_64),y)

arch/x86/kernel/olpc.c

Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
/*
2+
* Support for the OLPC DCON and OLPC EC access
3+
*
4+
* Copyright © 2006 Advanced Micro Devices, Inc.
5+
* Copyright © 2007-2008 Andres Salomon <dilinger@debian.org>
6+
*
7+
* This program is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 2 of the License, or
10+
* (at your option) any later version.
11+
*/
12+
13+
#include <linux/kernel.h>
14+
#include <linux/init.h>
15+
#include <linux/module.h>
16+
#include <linux/delay.h>
17+
#include <linux/spinlock.h>
18+
#include <linux/io.h>
19+
#include <linux/string.h>
20+
#include <asm/geode.h>
21+
#include <asm/olpc.h>
22+
23+
#ifdef CONFIG_OPEN_FIRMWARE
24+
#include <asm/ofw.h>
25+
#endif
26+
27+
struct olpc_platform_t olpc_platform_info;
28+
EXPORT_SYMBOL_GPL(olpc_platform_info);
29+
30+
static DEFINE_SPINLOCK(ec_lock);
31+
32+
/* what the timeout *should* be (in ms) */
33+
#define EC_BASE_TIMEOUT 20
34+
35+
/* the timeout that bugs in the EC might force us to actually use */
36+
static int ec_timeout = EC_BASE_TIMEOUT;
37+
38+
static int __init olpc_ec_timeout_set(char *str)
39+
{
40+
if (get_option(&str, &ec_timeout) != 1) {
41+
ec_timeout = EC_BASE_TIMEOUT;
42+
printk(KERN_ERR "olpc-ec: invalid argument to "
43+
"'olpc_ec_timeout=', ignoring!\n");
44+
}
45+
printk(KERN_DEBUG "olpc-ec: using %d ms delay for EC commands.\n",
46+
ec_timeout);
47+
return 1;
48+
}
49+
__setup("olpc_ec_timeout=", olpc_ec_timeout_set);
50+
51+
/*
52+
* These {i,o}bf_status functions return whether the buffers are full or not.
53+
*/
54+
55+
static inline unsigned int ibf_status(unsigned int port)
56+
{
57+
return !!(inb(port) & 0x02);
58+
}
59+
60+
static inline unsigned int obf_status(unsigned int port)
61+
{
62+
return inb(port) & 0x01;
63+
}
64+
65+
#define wait_on_ibf(p, d) __wait_on_ibf(__LINE__, (p), (d))
66+
static int __wait_on_ibf(unsigned int line, unsigned int port, int desired)
67+
{
68+
unsigned int timeo;
69+
int state = ibf_status(port);
70+
71+
for (timeo = ec_timeout; state != desired && timeo; timeo--) {
72+
mdelay(1);
73+
state = ibf_status(port);
74+
}
75+
76+
if ((state == desired) && (ec_timeout > EC_BASE_TIMEOUT) &&
77+
timeo < (ec_timeout - EC_BASE_TIMEOUT)) {
78+
printk(KERN_WARNING "olpc-ec: %d: waited %u ms for IBF!\n",
79+
line, ec_timeout - timeo);
80+
}
81+
82+
return !(state == desired);
83+
}
84+
85+
#define wait_on_obf(p, d) __wait_on_obf(__LINE__, (p), (d))
86+
static int __wait_on_obf(unsigned int line, unsigned int port, int desired)
87+
{
88+
unsigned int timeo;
89+
int state = obf_status(port);
90+
91+
for (timeo = ec_timeout; state != desired && timeo; timeo--) {
92+
mdelay(1);
93+
state = obf_status(port);
94+
}
95+
96+
if ((state == desired) && (ec_timeout > EC_BASE_TIMEOUT) &&
97+
timeo < (ec_timeout - EC_BASE_TIMEOUT)) {
98+
printk(KERN_WARNING "olpc-ec: %d: waited %u ms for OBF!\n",
99+
line, ec_timeout - timeo);
100+
}
101+
102+
return !(state == desired);
103+
}
104+
105+
/*
106+
* This allows the kernel to run Embedded Controller commands. The EC is
107+
* documented at <http://wiki.laptop.org/go/Embedded_controller>, and the
108+
* available EC commands are here:
109+
* <http://wiki.laptop.org/go/Ec_specification>. Unfortunately, while
110+
* OpenFirmware's source is available, the EC's is not.
111+
*/
112+
int olpc_ec_cmd(unsigned char cmd, unsigned char *inbuf, size_t inlen,
113+
unsigned char *outbuf, size_t outlen)
114+
{
115+
unsigned long flags;
116+
int ret = -EIO;
117+
int i;
118+
119+
spin_lock_irqsave(&ec_lock, flags);
120+
121+
/* Clear OBF */
122+
for (i = 0; i < 10 && (obf_status(0x6c) == 1); i++)
123+
inb(0x68);
124+
if (i == 10) {
125+
printk(KERN_ERR "olpc-ec: timeout while attempting to "
126+
"clear OBF flag!\n");
127+
goto err;
128+
}
129+
130+
if (wait_on_ibf(0x6c, 0)) {
131+
printk(KERN_ERR "olpc-ec: timeout waiting for EC to "
132+
"quiesce!\n");
133+
goto err;
134+
}
135+
136+
restart:
137+
/*
138+
* Note that if we time out during any IBF checks, that's a failure;
139+
* we have to return. There's no way for the kernel to clear that.
140+
*
141+
* If we time out during an OBF check, we can restart the command;
142+
* reissuing it will clear the OBF flag, and we should be alright.
143+
* The OBF flag will sometimes misbehave due to what we believe
144+
* is a hardware quirk..
145+
*/
146+
printk(KERN_DEBUG "olpc-ec: running cmd 0x%x\n", cmd);
147+
outb(cmd, 0x6c);
148+
149+
if (wait_on_ibf(0x6c, 0)) {
150+
printk(KERN_ERR "olpc-ec: timeout waiting for EC to read "
151+
"command!\n");
152+
goto err;
153+
}
154+
155+
if (inbuf && inlen) {
156+
/* write data to EC */
157+
for (i = 0; i < inlen; i++) {
158+
if (wait_on_ibf(0x6c, 0)) {
159+
printk(KERN_ERR "olpc-ec: timeout waiting for"
160+
" EC accept data!\n");
161+
goto err;
162+
}
163+
printk(KERN_DEBUG "olpc-ec: sending cmd arg 0x%x\n",
164+
inbuf[i]);
165+
outb(inbuf[i], 0x68);
166+
}
167+
}
168+
if (outbuf && outlen) {
169+
/* read data from EC */
170+
for (i = 0; i < outlen; i++) {
171+
if (wait_on_obf(0x6c, 1)) {
172+
printk(KERN_ERR "olpc-ec: timeout waiting for"
173+
" EC to provide data!\n");
174+
goto restart;
175+
}
176+
outbuf[i] = inb(0x68);
177+
printk(KERN_DEBUG "olpc-ec: received 0x%x\n",
178+
outbuf[i]);
179+
}
180+
}
181+
182+
ret = 0;
183+
err:
184+
spin_unlock_irqrestore(&ec_lock, flags);
185+
return ret;
186+
}
187+
EXPORT_SYMBOL_GPL(olpc_ec_cmd);
188+
189+
#ifdef CONFIG_OPEN_FIRMWARE
190+
static void __init platform_detect(void)
191+
{
192+
size_t propsize;
193+
u32 rev;
194+
195+
if (ofw("getprop", 4, 1, NULL, "board-revision-int", &rev, 4,
196+
&propsize) || propsize != 4) {
197+
printk(KERN_ERR "ofw: getprop call failed!\n");
198+
rev = 0;
199+
}
200+
olpc_platform_info.boardrev = be32_to_cpu(rev);
201+
}
202+
#else
203+
static void __init platform_detect(void)
204+
{
205+
/* stopgap until OFW support is added to the kernel */
206+
olpc_platform_info.boardrev = be32_to_cpu(0xc2);
207+
}
208+
#endif
209+
210+
static int __init olpc_init(void)
211+
{
212+
unsigned char *romsig;
213+
214+
/* The ioremap check is dangerous; limit what we run it on */
215+
if (!is_geode() || geode_has_vsa2())
216+
return 0;
217+
218+
spin_lock_init(&ec_lock);
219+
220+
romsig = ioremap(0xffffffc0, 16);
221+
if (!romsig)
222+
return 0;
223+
224+
if (strncmp(romsig, "CL1 Q", 7))
225+
goto unmap;
226+
if (strncmp(romsig+6, romsig+13, 3)) {
227+
printk(KERN_INFO "OLPC BIOS signature looks invalid. "
228+
"Assuming not OLPC\n");
229+
goto unmap;
230+
}
231+
232+
printk(KERN_INFO "OLPC board with OpenFirmware %.16s\n", romsig);
233+
olpc_platform_info.flags |= OLPC_F_PRESENT;
234+
235+
/* get the platform revision */
236+
platform_detect();
237+
238+
/* assume B1 and above models always have a DCON */
239+
if (olpc_board_at_least(olpc_board(0xb1)))
240+
olpc_platform_info.flags |= OLPC_F_DCON;
241+
242+
/* get the EC revision */
243+
olpc_ec_cmd(EC_FIRMWARE_REV, NULL, 0,
244+
(unsigned char *) &olpc_platform_info.ecver, 1);
245+
246+
/* check to see if the VSA exists */
247+
if (geode_has_vsa2())
248+
olpc_platform_info.flags |= OLPC_F_VSA;
249+
250+
printk(KERN_INFO "OLPC board revision %s%X (EC=%x)\n",
251+
((olpc_platform_info.boardrev & 0xf) < 8) ? "pre" : "",
252+
olpc_platform_info.boardrev >> 4,
253+
olpc_platform_info.ecver);
254+
255+
unmap:
256+
iounmap(romsig);
257+
return 0;
258+
}
259+
260+
postcore_initcall(olpc_init);

arch/x86/pci/Makefile_32

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ obj-y := i386.o init.o
33
obj-$(CONFIG_PCI_BIOS) += pcbios.o
44
obj-$(CONFIG_PCI_MMCONFIG) += mmconfig_32.o direct.o mmconfig-shared.o
55
obj-$(CONFIG_PCI_DIRECT) += direct.o
6+
obj-$(CONFIG_PCI_OLPC) += olpc.o
67

78
pci-y := fixup.o
89
pci-$(CONFIG_ACPI) += acpi.o

arch/x86/pci/init.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ static __init int pci_access_init(void)
1313
#endif
1414
#ifdef CONFIG_PCI_MMCONFIG
1515
pci_mmcfg_init(type);
16+
#endif
17+
#ifdef CONFIG_PCI_OLPC
18+
pci_olpc_init();
1619
#endif
1720
if (raw_pci_ops)
1821
return 0;

0 commit comments

Comments
 (0)