Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fa8f53ac authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge branch 'x86-olpc-for-linus' of...

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
parents 1d87c28e 07d5b38e
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
OLPC XO-1 RTC
~~~~~~~~~~~~~

Required properties:
 - compatible : "olpc,xo1-rtc"
+38 −5
Original line number Diff line number Diff line
@@ -2024,11 +2024,44 @@ config OLPC
	  Add support for detecting the unique features of the OLPC
	  XO hardware.

config OLPC_XO1
	tristate "OLPC XO-1 support"
	depends on OLPC && MFD_CS5535
	---help---
	  Add support for non-essential features of the OLPC XO-1 laptop.
config OLPC_XO1_PM
	bool "OLPC XO-1 Power Management"
	depends on OLPC && MFD_CS5535 && PM_SLEEP
	select MFD_CORE
	---help---
	  Add support for poweroff and suspend of the OLPC XO-1 laptop.

config OLPC_XO1_RTC
	bool "OLPC XO-1 Real Time Clock"
	depends on OLPC_XO1_PM && RTC_DRV_CMOS
	---help---
	  Add support for the XO-1 real time clock, which can be used as a
	  programmable wakeup source.

config OLPC_XO1_SCI
	bool "OLPC XO-1 SCI extras"
	depends on OLPC && OLPC_XO1_PM
	select POWER_SUPPLY
	select GPIO_CS5535
	select MFD_CORE
	---help---
	  Add support for SCI-based features of the OLPC XO-1 laptop:
	   - EC-driven system wakeups
	   - Power button
	   - Ebook switch
	   - Lid switch
	   - AC adapter status updates
	   - Battery status updates

config OLPC_XO15_SCI
	bool "OLPC XO-1.5 SCI extras"
	depends on OLPC && ACPI
	select POWER_SUPPLY
	---help---
	  Add support for SCI-based features of the OLPC XO-1.5 laptop:
	   - EC-driven system wakeups
	   - AC adapter status updates
	   - Battery status updates

endif # X86_32

+40 −11
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ struct olpc_platform_t {

#define OLPC_F_PRESENT		0x01
#define OLPC_F_DCON		0x02
#define OLPC_F_EC_WIDE_SCI	0x04

#ifdef CONFIG_OLPC

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

extern void olpc_ec_wakeup_set(u16 value);
extern void olpc_ec_wakeup_clear(u16 value);
extern bool olpc_ec_wakeup_available(void);

extern int olpc_ec_mask_write(u16 bits);
extern int olpc_ec_sci_query(u16 *sci_value);

#else

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

static inline void olpc_ec_wakeup_set(u16 value) { }
static inline void olpc_ec_wakeup_clear(u16 value) { }

static inline bool olpc_ec_wakeup_available(void)
{
	return false;
}

#endif

#ifdef CONFIG_OLPC_XO1_PM
extern void do_olpc_suspend_lowlevel(void);
extern void olpc_xo1_pm_wakeup_set(u16 value);
extern void olpc_xo1_pm_wakeup_clear(u16 value);
#endif

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

extern int olpc_ec_mask_set(uint8_t bits);
extern int olpc_ec_mask_unset(uint8_t bits);

/* EC commands */

#define EC_FIRMWARE_REV			0x08
#define EC_WLAN_ENTER_RESET	0x35
#define EC_WRITE_SCI_MASK		0x1b
#define EC_WAKE_UP_WLAN			0x24
#define EC_WLAN_LEAVE_RESET		0x25
#define EC_READ_EB_MODE			0x2a
#define EC_SET_SCI_INHIBIT		0x32
#define EC_SET_SCI_INHIBIT_RELEASE	0x34
#define EC_WLAN_ENTER_RESET		0x35
#define EC_WRITE_EXT_SCI_MASK		0x38
#define EC_SCI_QUERY			0x84
#define EC_EXT_SCI_QUERY		0x85

/* SCI source values */

@@ -99,10 +126,12 @@ extern int olpc_ec_mask_unset(uint8_t bits);
#define EC_SCI_SRC_BATTERY	0x02
#define EC_SCI_SRC_BATSOC	0x04
#define EC_SCI_SRC_BATERR	0x08
#define EC_SCI_SRC_EBOOK	0x10
#define EC_SCI_SRC_WLAN		0x20
#define EC_SCI_SRC_EBOOK	0x10	/* XO-1 only */
#define EC_SCI_SRC_WLAN		0x20	/* XO-1 only */
#define EC_SCI_SRC_ACPWR	0x40
#define EC_SCI_SRC_ALL		0x7F
#define EC_SCI_SRC_BATCRIT	0x80
#define EC_SCI_SRC_GPWAKE	0x100	/* XO-1.5 only */
#define EC_SCI_SRC_ALL		0x1FF

/* GPIO assignments */

@@ -116,7 +145,7 @@ extern int olpc_ec_mask_unset(uint8_t bits);
#define OLPC_GPIO_SMB_CLK      14
#define OLPC_GPIO_SMB_DATA     15
#define OLPC_GPIO_WORKAUX	geode_gpio(24)
#define OLPC_GPIO_LID		geode_gpio(26)
#define OLPC_GPIO_ECSCI		geode_gpio(27)
#define OLPC_GPIO_LID		26
#define OLPC_GPIO_ECSCI		27

#endif /* _ASM_X86_OLPC_H */
+4 −1
Original line number Diff line number Diff line
obj-$(CONFIG_OLPC)		+= olpc.o olpc_ofw.o olpc_dt.o
obj-$(CONFIG_OLPC_XO1)		+= olpc-xo1.o
obj-$(CONFIG_OLPC_XO1_PM)		+= olpc-xo1-pm.o xo1-wakeup.o
obj-$(CONFIG_OLPC_XO1_RTC)	+= olpc-xo1-rtc.o
obj-$(CONFIG_OLPC_XO1_SCI)	+= olpc-xo1-sci.o
obj-$(CONFIG_OLPC_XO15_SCI)	+= olpc-xo15-sci.o
+215 −0
Original line number Diff line number Diff line
/*
 * Support for features of the OLPC XO-1 laptop
 * Support for power management features of the OLPC XO-1 laptop
 *
 * Copyright (C) 2010 Andres Salomon <dilinger@queued.net>
 * Copyright (C) 2010 One Laptop per Child
@@ -12,49 +12,129 @@
 * (at your option) any later version.
 */

#include <linux/module.h>
#include <linux/cs5535.h>
#include <linux/platform_device.h>
#include <linux/pm.h>
#include <linux/mfd/core.h>
#include <linux/suspend.h>

#include <asm/io.h>
#include <asm/olpc.h>

#define DRV_NAME "olpc-xo1"

/* PMC registers (PMS block) */
#define PM_SCLK		0x10
#define PM_IN_SLPCTL	0x20
#define PM_WKXD		0x34
#define PM_WKD		0x30
#define PM_SSC		0x54

/* PM registers (ACPI block) */
#define PM1_CNT		0x08
#define PM_GPE0_STS	0x18
#define DRV_NAME "olpc-xo1-pm"

static unsigned long acpi_base;
static unsigned long pms_base;

static u16 wakeup_mask = CS5536_PM_PWRBTN;

static struct {
	unsigned long address;
	unsigned short segment;
} ofw_bios_entry = { 0xF0000 + PAGE_OFFSET, __KERNEL_CS };

/* Set bits in the wakeup mask */
void olpc_xo1_pm_wakeup_set(u16 value)
{
	wakeup_mask |= value;
}
EXPORT_SYMBOL_GPL(olpc_xo1_pm_wakeup_set);

/* Clear bits in the wakeup mask */
void olpc_xo1_pm_wakeup_clear(u16 value)
{
	wakeup_mask &= ~value;
}
EXPORT_SYMBOL_GPL(olpc_xo1_pm_wakeup_clear);

static int xo1_power_state_enter(suspend_state_t pm_state)
{
	unsigned long saved_sci_mask;
	int r;

	/* Only STR is supported */
	if (pm_state != PM_SUSPEND_MEM)
		return -EINVAL;

	r = olpc_ec_cmd(EC_SET_SCI_INHIBIT, NULL, 0, NULL, 0);
	if (r)
		return r;

	/*
	 * Save SCI mask (this gets lost since PM1_EN is used as a mask for
	 * wakeup events, which is not necessarily the same event set)
	 */
	saved_sci_mask = inl(acpi_base + CS5536_PM1_STS);
	saved_sci_mask &= 0xffff0000;

	/* Save CPU state */
	do_olpc_suspend_lowlevel();

	/* Resume path starts here */

	/* Restore SCI mask (using dword access to CS5536_PM1_EN) */
	outl(saved_sci_mask, acpi_base + CS5536_PM1_STS);

	/* Tell the EC to stop inhibiting SCIs */
	olpc_ec_cmd(EC_SET_SCI_INHIBIT_RELEASE, NULL, 0, NULL, 0);

	/*
	 * Tell the wireless module to restart USB communication.
	 * Must be done twice.
	 */
	olpc_ec_cmd(EC_WAKE_UP_WLAN, NULL, 0, NULL, 0);
	olpc_ec_cmd(EC_WAKE_UP_WLAN, NULL, 0, NULL, 0);

	return 0;
}

asmlinkage int xo1_do_sleep(u8 sleep_state)
{
	void *pgd_addr = __va(read_cr3());

	/* Program wakeup mask (using dword access to CS5536_PM1_EN) */
	outl(wakeup_mask << 16, acpi_base + CS5536_PM1_STS);

	__asm__("movl %0,%%eax" : : "r" (pgd_addr));
	__asm__("call *(%%edi); cld"
		: : "D" (&ofw_bios_entry));
	__asm__("movb $0x34, %al\n\t"
		"outb %al, $0x70\n\t"
		"movb $0x30, %al\n\t"
		"outb %al, $0x71\n\t");
	return 0;
}

static void xo1_power_off(void)
{
	printk(KERN_INFO "OLPC XO-1 power off sequence...\n");

	/* Enable all of these controls with 0 delay */
	outl(0x40000000, pms_base + PM_SCLK);
	outl(0x40000000, pms_base + PM_IN_SLPCTL);
	outl(0x40000000, pms_base + PM_WKXD);
	outl(0x40000000, pms_base + PM_WKD);
	outl(0x40000000, pms_base + CS5536_PM_SCLK);
	outl(0x40000000, pms_base + CS5536_PM_IN_SLPCTL);
	outl(0x40000000, pms_base + CS5536_PM_WKXD);
	outl(0x40000000, pms_base + CS5536_PM_WKD);

	/* Clear status bits (possibly unnecessary) */
	outl(0x0002ffff, pms_base  + PM_SSC);
	outl(0xffffffff, acpi_base + PM_GPE0_STS);
	outl(0x0002ffff, pms_base  + CS5536_PM_SSC);
	outl(0xffffffff, acpi_base + CS5536_PM_GPE0_STS);

	/* Write SLP_EN bit to start the machinery */
	outl(0x00002000, acpi_base + PM1_CNT);
	outl(0x00002000, acpi_base + CS5536_PM1_CNT);
}

static int xo1_power_state_valid(suspend_state_t pm_state)
{
	/* suspend-to-RAM only */
	return pm_state == PM_SUSPEND_MEM;
}

static int __devinit olpc_xo1_probe(struct platform_device *pdev)
static const struct platform_suspend_ops xo1_suspend_ops = {
	.valid = xo1_power_state_valid,
	.enter = xo1_power_state_enter,
};

static int __devinit xo1_pm_probe(struct platform_device *pdev)
{
	struct resource *res;
	int err;
@@ -79,6 +159,7 @@ static int __devinit olpc_xo1_probe(struct platform_device *pdev)

	/* If we have both addresses, we can override the poweroff hook */
	if (pms_base && acpi_base) {
		suspend_set_ops(&xo1_suspend_ops);
		pm_power_off = xo1_power_off;
		printk(KERN_INFO "OLPC XO-1 support registered\n");
	}
@@ -86,7 +167,7 @@ static int __devinit olpc_xo1_probe(struct platform_device *pdev)
	return 0;
}

static int __devexit olpc_xo1_remove(struct platform_device *pdev)
static int __devexit xo1_pm_remove(struct platform_device *pdev)
{
	mfd_cell_disable(pdev);

@@ -99,48 +180,36 @@ static int __devexit olpc_xo1_remove(struct platform_device *pdev)
	return 0;
}

static struct platform_driver cs5535_pms_drv = {
static struct platform_driver cs5535_pms_driver = {
	.driver = {
		.name = "cs5535-pms",
		.owner = THIS_MODULE,
	},
	.probe = olpc_xo1_probe,
	.remove = __devexit_p(olpc_xo1_remove),
	.probe = xo1_pm_probe,
	.remove = __devexit_p(xo1_pm_remove),
};

static struct platform_driver cs5535_acpi_drv = {
static struct platform_driver cs5535_acpi_driver = {
	.driver = {
		.name = "olpc-xo1-pm-acpi",
		.owner = THIS_MODULE,
	},
	.probe = olpc_xo1_probe,
	.remove = __devexit_p(olpc_xo1_remove),
	.probe = xo1_pm_probe,
	.remove = __devexit_p(xo1_pm_remove),
};

static int __init olpc_xo1_init(void)
static int __init xo1_pm_init(void)
{
	int r;

	r = platform_driver_register(&cs5535_pms_drv);
	r = platform_driver_register(&cs5535_pms_driver);
	if (r)
		return r;

	r = platform_driver_register(&cs5535_acpi_drv);
	r = platform_driver_register(&cs5535_acpi_driver);
	if (r)
		platform_driver_unregister(&cs5535_pms_drv);
		platform_driver_unregister(&cs5535_pms_driver);

	return r;
}

static void __exit olpc_xo1_exit(void)
{
	platform_driver_unregister(&cs5535_acpi_drv);
	platform_driver_unregister(&cs5535_pms_drv);
}

MODULE_AUTHOR("Daniel Drake <dsd@laptop.org>");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:cs5535-pms");

module_init(olpc_xo1_init);
module_exit(olpc_xo1_exit);
arch_initcall(xo1_pm_init);
Loading