x86, olpc: Move CS5536-related constants to cs5535.h
[pandora-kernel.git] / arch / x86 / platform / olpc / olpc-xo1.c
1 /*
2  * Support for 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/module.h>
17 #include <linux/platform_device.h>
18 #include <linux/pm.h>
19 #include <linux/mfd/core.h>
20
21 #include <asm/io.h>
22 #include <asm/olpc.h>
23
24 #define DRV_NAME "olpc-xo1"
25
26 static unsigned long acpi_base;
27 static unsigned long pms_base;
28
29 static 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 */
34         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);
38
39         /* Clear status bits (possibly unnecessary) */
40         outl(0x0002ffff, pms_base  + CS5536_PM_SSC);
41         outl(0xffffffff, acpi_base + CS5536_PM_GPE0_STS);
42
43         /* Write SLP_EN bit to start the machinery */
44         outl(0x00002000, acpi_base + CS5536_PM1_CNT);
45 }
46
47 static int __devinit olpc_xo1_probe(struct platform_device *pdev)
48 {
49         struct resource *res;
50         int err;
51
52         /* don't run on non-XOs */
53         if (!machine_is_olpc())
54                 return -ENODEV;
55
56         err = mfd_cell_enable(pdev);
57         if (err)
58                 return err;
59
60         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         }
65         if (strcmp(pdev->name, "cs5535-pms") == 0)
66                 pms_base = res->start;
67         else if (strcmp(pdev->name, "olpc-xo1-pm-acpi") == 0)
68                 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
76         return 0;
77 }
78
79 static int __devexit olpc_xo1_remove(struct platform_device *pdev)
80 {
81         mfd_cell_disable(pdev);
82
83         if (strcmp(pdev->name, "cs5535-pms") == 0)
84                 pms_base = 0;
85         else if (strcmp(pdev->name, "olpc-xo1-pm-acpi") == 0)
86                 acpi_base = 0;
87
88         pm_power_off = NULL;
89         return 0;
90 }
91
92 static struct platform_driver cs5535_pms_drv = {
93         .driver = {
94                 .name = "cs5535-pms",
95                 .owner = THIS_MODULE,
96         },
97         .probe = olpc_xo1_probe,
98         .remove = __devexit_p(olpc_xo1_remove),
99 };
100
101 static struct platform_driver cs5535_acpi_drv = {
102         .driver = {
103                 .name = "olpc-xo1-pm-acpi",
104                 .owner = THIS_MODULE,
105         },
106         .probe = olpc_xo1_probe,
107         .remove = __devexit_p(olpc_xo1_remove),
108 };
109
110 static int __init olpc_xo1_init(void)
111 {
112         int r;
113
114         r = platform_driver_register(&cs5535_pms_drv);
115         if (r)
116                 return r;
117
118         r = platform_driver_register(&cs5535_acpi_drv);
119         if (r)
120                 platform_driver_unregister(&cs5535_pms_drv);
121
122         return r;
123 }
124
125 static void __exit olpc_xo1_exit(void)
126 {
127         platform_driver_unregister(&cs5535_acpi_drv);
128         platform_driver_unregister(&cs5535_pms_drv);
129 }
130
131 MODULE_AUTHOR("Daniel Drake <dsd@laptop.org>");
132 MODULE_LICENSE("GPL");
133 MODULE_ALIAS("platform:cs5535-pms");
134
135 module_init(olpc_xo1_init);
136 module_exit(olpc_xo1_exit);