olpc-xo1-pm.c 2.9 KB
Newer Older
1
/*
2
 * Support for power management features of the OLPC XO-1 laptop
3
 *
4
 * Copyright (C) 2010 Andres Salomon <dilinger@queued.net>
5 6 7 8 9 10 11 12 13 14
 * Copyright (C) 2010 One Laptop per Child
 * Copyright (C) 2006 Red Hat, Inc.
 * Copyright (C) 2006 Advanced Micro Devices, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

15
#include <linux/cs5535.h>
16 17
#include <linux/platform_device.h>
#include <linux/pm.h>
18
#include <linux/mfd/core.h>
19 20 21 22

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

23
#define DRV_NAME "olpc-xo1-pm"
24 25 26 27 28 29 30 31 32

static unsigned long acpi_base;
static unsigned long pms_base;

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

	/* Enable all of these controls with 0 delay */
33 34 35 36
	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);
37 38

	/* Clear status bits (possibly unnecessary) */
39 40
	outl(0x0002ffff, pms_base  + CS5536_PM_SSC);
	outl(0xffffffff, acpi_base + CS5536_PM_GPE0_STS);
41 42

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

46
static int __devinit xo1_pm_probe(struct platform_device *pdev)
47
{
48
	struct resource *res;
49
	int err;
50

51 52 53
	/* don't run on non-XOs */
	if (!machine_is_olpc())
		return -ENODEV;
54

55
	err = mfd_cell_enable(pdev);
56 57 58
	if (err)
		return err;

59 60 61 62
	res = platform_get_resource(pdev, IORESOURCE_IO, 0);
	if (!res) {
		dev_err(&pdev->dev, "can't fetch device resource info\n");
		return -EIO;
63
	}
64
	if (strcmp(pdev->name, "cs5535-pms") == 0)
65
		pms_base = res->start;
66
	else if (strcmp(pdev->name, "olpc-xo1-pm-acpi") == 0)
67 68 69 70 71 72 73
		acpi_base = res->start;

	/* If we have both addresses, we can override the poweroff hook */
	if (pms_base && acpi_base) {
		pm_power_off = xo1_power_off;
		printk(KERN_INFO "OLPC XO-1 support registered\n");
	}
74 75 76 77

	return 0;
}

78
static int __devexit xo1_pm_remove(struct platform_device *pdev)
79
{
80
	mfd_cell_disable(pdev);
81

82
	if (strcmp(pdev->name, "cs5535-pms") == 0)
83
		pms_base = 0;
84
	else if (strcmp(pdev->name, "olpc-xo1-pm-acpi") == 0)
85
		acpi_base = 0;
86 87 88 89 90

	pm_power_off = NULL;
	return 0;
}

91
static struct platform_driver cs5535_pms_driver = {
92
	.driver = {
93
		.name = "cs5535-pms",
94 95
		.owner = THIS_MODULE,
	},
96 97
	.probe = xo1_pm_probe,
	.remove = __devexit_p(xo1_pm_remove),
98 99
};

100
static struct platform_driver cs5535_acpi_driver = {
101
	.driver = {
102
		.name = "olpc-xo1-pm-acpi",
103 104
		.owner = THIS_MODULE,
	},
105 106
	.probe = xo1_pm_probe,
	.remove = __devexit_p(xo1_pm_remove),
107 108
};

109
static int __init xo1_pm_init(void)
110
{
111 112
	int r;

113
	r = platform_driver_register(&cs5535_pms_driver);
114 115 116
	if (r)
		return r;

117
	r = platform_driver_register(&cs5535_acpi_driver);
118
	if (r)
119
		platform_driver_unregister(&cs5535_pms_driver);
120 121

	return r;
122
}
123
arch_initcall(xo1_pm_init);