blob: a63e9488979fd23f99f4de9aa6654108582206fc [file] [log] [blame]
Daniel Drakebf1ebf02010-10-10 10:40:32 +01001/*
2 * Support for features of the OLPC XO-1 laptop
3 *
Andres Salomon419cdc52010-11-29 15:45:06 -08004 * Copyright (C) 2010 Andres Salomon <dilinger@queued.net>
Daniel Drakebf1ebf02010-10-10 10:40:32 +01005 * 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
Daniel Drake7a0d4fc2011-06-25 17:34:09 +010015#include <linux/cs5535.h>
Daniel Drakebf1ebf02010-10-10 10:40:32 +010016#include <linux/module.h>
Daniel Drakebf1ebf02010-10-10 10:40:32 +010017#include <linux/platform_device.h>
18#include <linux/pm.h>
Andres Salomon1310e6d2011-02-17 19:07:36 -080019#include <linux/mfd/core.h>
Daniel Drakebf1ebf02010-10-10 10:40:32 +010020
21#include <asm/io.h>
22#include <asm/olpc.h>
23
24#define DRV_NAME "olpc-xo1"
25
Daniel Drakebf1ebf02010-10-10 10:40:32 +010026static unsigned long acpi_base;
27static unsigned long pms_base;
28
29static void xo1_power_off(void)
30{
31 printk(KERN_INFO "OLPC XO-1 power off sequence...\n");
32
33 /* Enable all of these controls with 0 delay */
Daniel Drake7a0d4fc2011-06-25 17:34:09 +010034 outl(0x40000000, pms_base + CS5536_PM_SCLK);
35 outl(0x40000000, pms_base + CS5536_PM_IN_SLPCTL);
36 outl(0x40000000, pms_base + CS5536_PM_WKXD);
37 outl(0x40000000, pms_base + CS5536_PM_WKD);
Daniel Drakebf1ebf02010-10-10 10:40:32 +010038
39 /* Clear status bits (possibly unnecessary) */
Daniel Drake7a0d4fc2011-06-25 17:34:09 +010040 outl(0x0002ffff, pms_base + CS5536_PM_SSC);
41 outl(0xffffffff, acpi_base + CS5536_PM_GPE0_STS);
Daniel Drakebf1ebf02010-10-10 10:40:32 +010042
43 /* Write SLP_EN bit to start the machinery */
Daniel Drake7a0d4fc2011-06-25 17:34:09 +010044 outl(0x00002000, acpi_base + CS5536_PM1_CNT);
Daniel Drakebf1ebf02010-10-10 10:40:32 +010045}
46
Daniel Drakebf1ebf02010-10-10 10:40:32 +010047static int __devinit olpc_xo1_probe(struct platform_device *pdev)
48{
Andres Salomon419cdc52010-11-29 15:45:06 -080049 struct resource *res;
Andres Salomon1310e6d2011-02-17 19:07:36 -080050 int err;
Daniel Drakebf1ebf02010-10-10 10:40:32 +010051
Andres Salomon419cdc52010-11-29 15:45:06 -080052 /* don't run on non-XOs */
53 if (!machine_is_olpc())
Daniel Drakebf1ebf02010-10-10 10:40:32 +010054 return -ENODEV;
55
Andres Salomonf77289a2011-03-03 09:51:58 -080056 err = mfd_cell_enable(pdev);
Andres Salomon1310e6d2011-02-17 19:07:36 -080057 if (err)
58 return err;
59
Andres Salomon419cdc52010-11-29 15:45:06 -080060 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
61 if (!res) {
62 dev_err(&pdev->dev, "can't fetch device resource info\n");
63 return -EIO;
64 }
Daniel Drakeadfa4bd2011-03-22 13:50:39 -070065 if (strcmp(pdev->name, "cs5535-pms") == 0)
Andres Salomon419cdc52010-11-29 15:45:06 -080066 pms_base = res->start;
Daniel Drakeadfa4bd2011-03-22 13:50:39 -070067 else if (strcmp(pdev->name, "olpc-xo1-pm-acpi") == 0)
Andres Salomon419cdc52010-11-29 15:45:06 -080068 acpi_base = res->start;
69
70 /* If we have both addresses, we can override the poweroff hook */
71 if (pms_base && acpi_base) {
72 pm_power_off = xo1_power_off;
73 printk(KERN_INFO "OLPC XO-1 support registered\n");
74 }
75
Daniel Drakebf1ebf02010-10-10 10:40:32 +010076 return 0;
77}
78
79static int __devexit olpc_xo1_remove(struct platform_device *pdev)
80{
Andres Salomonf77289a2011-03-03 09:51:58 -080081 mfd_cell_disable(pdev);
Andres Salomon419cdc52010-11-29 15:45:06 -080082
Daniel Drakeadfa4bd2011-03-22 13:50:39 -070083 if (strcmp(pdev->name, "cs5535-pms") == 0)
Andres Salomon419cdc52010-11-29 15:45:06 -080084 pms_base = 0;
Daniel Drakeadfa4bd2011-03-22 13:50:39 -070085 else if (strcmp(pdev->name, "olpc-xo1-pm-acpi") == 0)
Andres Salomon419cdc52010-11-29 15:45:06 -080086 acpi_base = 0;
87
Daniel Drakebf1ebf02010-10-10 10:40:32 +010088 pm_power_off = NULL;
89 return 0;
90}
91
Andres Salomon419cdc52010-11-29 15:45:06 -080092static struct platform_driver cs5535_pms_drv = {
Daniel Drakebf1ebf02010-10-10 10:40:32 +010093 .driver = {
Daniel Drakeadfa4bd2011-03-22 13:50:39 -070094 .name = "cs5535-pms",
Andres Salomon419cdc52010-11-29 15:45:06 -080095 .owner = THIS_MODULE,
96 },
97 .probe = olpc_xo1_probe,
98 .remove = __devexit_p(olpc_xo1_remove),
99};
100
101static struct platform_driver cs5535_acpi_drv = {
102 .driver = {
Daniel Drakeadfa4bd2011-03-22 13:50:39 -0700103 .name = "olpc-xo1-pm-acpi",
Daniel Drakebf1ebf02010-10-10 10:40:32 +0100104 .owner = THIS_MODULE,
105 },
106 .probe = olpc_xo1_probe,
107 .remove = __devexit_p(olpc_xo1_remove),
108};
109
110static int __init olpc_xo1_init(void)
111{
Andres Salomon419cdc52010-11-29 15:45:06 -0800112 int r;
113
Andres Salomonfa1df692011-03-21 19:19:35 -0700114 r = platform_driver_register(&cs5535_pms_drv);
Andres Salomon419cdc52010-11-29 15:45:06 -0800115 if (r)
116 return r;
117
Andres Salomonfa1df692011-03-21 19:19:35 -0700118 r = platform_driver_register(&cs5535_acpi_drv);
Andres Salomon419cdc52010-11-29 15:45:06 -0800119 if (r)
Andres Salomonfa1df692011-03-21 19:19:35 -0700120 platform_driver_unregister(&cs5535_pms_drv);
Andres Salomon419cdc52010-11-29 15:45:06 -0800121
122 return r;
Daniel Drakebf1ebf02010-10-10 10:40:32 +0100123}
124
125static void __exit olpc_xo1_exit(void)
126{
Andres Salomonfa1df692011-03-21 19:19:35 -0700127 platform_driver_unregister(&cs5535_acpi_drv);
128 platform_driver_unregister(&cs5535_pms_drv);
Daniel Drakebf1ebf02010-10-10 10:40:32 +0100129}
130
131MODULE_AUTHOR("Daniel Drake <dsd@laptop.org>");
132MODULE_LICENSE("GPL");
Andres Salomon1310e6d2011-02-17 19:07:36 -0800133MODULE_ALIAS("platform:cs5535-pms");
Daniel Drakebf1ebf02010-10-10 10:40:32 +0100134
135module_init(olpc_xo1_init);
136module_exit(olpc_xo1_exit);