x86, olpc: Move CS5536-related constants to cs5535.h
[linux-2.6.git] / arch / x86 / platform / olpc / olpc-xo1.c
bloba63e9488979fd23f99f4de9aa6654108582206fc
1 /*
2 * Support for features of the OLPC XO-1 laptop
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.
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.
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>
21 #include <asm/io.h>
22 #include <asm/olpc.h>
24 #define DRV_NAME "olpc-xo1"
26 static unsigned long acpi_base;
27 static unsigned long pms_base;
29 static void xo1_power_off(void)
31 printk(KERN_INFO "OLPC XO-1 power off sequence...\n");
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);
39 /* Clear status bits (possibly unnecessary) */
40 outl(0x0002ffff, pms_base + CS5536_PM_SSC);
41 outl(0xffffffff, acpi_base + CS5536_PM_GPE0_STS);
43 /* Write SLP_EN bit to start the machinery */
44 outl(0x00002000, acpi_base + CS5536_PM1_CNT);
47 static int __devinit olpc_xo1_probe(struct platform_device *pdev)
49 struct resource *res;
50 int err;
52 /* don't run on non-XOs */
53 if (!machine_is_olpc())
54 return -ENODEV;
56 err = mfd_cell_enable(pdev);
57 if (err)
58 return err;
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;
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;
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");
76 return 0;
79 static int __devexit olpc_xo1_remove(struct platform_device *pdev)
81 mfd_cell_disable(pdev);
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;
88 pm_power_off = NULL;
89 return 0;
92 static struct platform_driver cs5535_pms_drv = {
93 .driver = {
94 .name = "cs5535-pms",
95 .owner = THIS_MODULE,
97 .probe = olpc_xo1_probe,
98 .remove = __devexit_p(olpc_xo1_remove),
101 static struct platform_driver cs5535_acpi_drv = {
102 .driver = {
103 .name = "olpc-xo1-pm-acpi",
104 .owner = THIS_MODULE,
106 .probe = olpc_xo1_probe,
107 .remove = __devexit_p(olpc_xo1_remove),
110 static int __init olpc_xo1_init(void)
112 int r;
114 r = platform_driver_register(&cs5535_pms_drv);
115 if (r)
116 return r;
118 r = platform_driver_register(&cs5535_acpi_drv);
119 if (r)
120 platform_driver_unregister(&cs5535_pms_drv);
122 return r;
125 static void __exit olpc_xo1_exit(void)
127 platform_driver_unregister(&cs5535_acpi_drv);
128 platform_driver_unregister(&cs5535_pms_drv);
131 MODULE_AUTHOR("Daniel Drake <dsd@laptop.org>");
132 MODULE_LICENSE("GPL");
133 MODULE_ALIAS("platform:cs5535-pms");
135 module_init(olpc_xo1_init);
136 module_exit(olpc_xo1_exit);