Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
[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 One Laptop per Child
5  * Copyright (C) 2006 Red Hat, Inc.
6  * Copyright (C) 2006 Advanced Micro Devices, Inc.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  */
13
14 #include <linux/module.h>
15 #include <linux/pci.h>
16 #include <linux/pci_ids.h>
17 #include <linux/platform_device.h>
18 #include <linux/pm.h>
19
20 #include <asm/io.h>
21 #include <asm/olpc.h>
22
23 #define DRV_NAME "olpc-xo1"
24
25 #define PMS_BAR         4
26 #define ACPI_BAR        5
27
28 /* PMC registers (PMS block) */
29 #define PM_SCLK         0x10
30 #define PM_IN_SLPCTL    0x20
31 #define PM_WKXD         0x34
32 #define PM_WKD          0x30
33 #define PM_SSC          0x54
34
35 /* PM registers (ACPI block) */
36 #define PM1_CNT         0x08
37 #define PM_GPE0_STS     0x18
38
39 static unsigned long acpi_base;
40 static unsigned long pms_base;
41
42 static void xo1_power_off(void)
43 {
44         printk(KERN_INFO "OLPC XO-1 power off sequence...\n");
45
46         /* Enable all of these controls with 0 delay */
47         outl(0x40000000, pms_base + PM_SCLK);
48         outl(0x40000000, pms_base + PM_IN_SLPCTL);
49         outl(0x40000000, pms_base + PM_WKXD);
50         outl(0x40000000, pms_base + PM_WKD);
51
52         /* Clear status bits (possibly unnecessary) */
53         outl(0x0002ffff, pms_base  + PM_SSC);
54         outl(0xffffffff, acpi_base + PM_GPE0_STS);
55
56         /* Write SLP_EN bit to start the machinery */
57         outl(0x00002000, acpi_base + PM1_CNT);
58 }
59
60 /* Read the base addresses from the PCI BAR info */
61 static int __devinit setup_bases(struct pci_dev *pdev)
62 {
63         int r;
64
65         r = pci_enable_device_io(pdev);
66         if (r) {
67                 dev_err(&pdev->dev, "can't enable device IO\n");
68                 return r;
69         }
70
71         r = pci_request_region(pdev, ACPI_BAR, DRV_NAME);
72         if (r) {
73                 dev_err(&pdev->dev, "can't alloc PCI BAR #%d\n", ACPI_BAR);
74                 return r;
75         }
76
77         r = pci_request_region(pdev, PMS_BAR, DRV_NAME);
78         if (r) {
79                 dev_err(&pdev->dev, "can't alloc PCI BAR #%d\n", PMS_BAR);
80                 pci_release_region(pdev, ACPI_BAR);
81                 return r;
82         }
83
84         acpi_base = pci_resource_start(pdev, ACPI_BAR);
85         pms_base = pci_resource_start(pdev, PMS_BAR);
86
87         return 0;
88 }
89
90 static int __devinit olpc_xo1_probe(struct platform_device *pdev)
91 {
92         struct pci_dev *pcidev;
93         int r;
94
95         pcidev = pci_get_device(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA,
96                                 NULL);
97         if (!pdev)
98                 return -ENODEV;
99
100         r = setup_bases(pcidev);
101         if (r)
102                 return r;
103
104         pm_power_off = xo1_power_off;
105
106         printk(KERN_INFO "OLPC XO-1 support registered\n");
107         return 0;
108 }
109
110 static int __devexit olpc_xo1_remove(struct platform_device *pdev)
111 {
112         pm_power_off = NULL;
113         return 0;
114 }
115
116 static struct platform_driver olpc_xo1_driver = {
117         .driver = {
118                 .name = DRV_NAME,
119                 .owner = THIS_MODULE,
120         },
121         .probe = olpc_xo1_probe,
122         .remove = __devexit_p(olpc_xo1_remove),
123 };
124
125 static int __init olpc_xo1_init(void)
126 {
127         return platform_driver_register(&olpc_xo1_driver);
128 }
129
130 static void __exit olpc_xo1_exit(void)
131 {
132         platform_driver_unregister(&olpc_xo1_driver);
133 }
134
135 MODULE_AUTHOR("Daniel Drake <dsd@laptop.org>");
136 MODULE_LICENSE("GPL");
137 MODULE_ALIAS("platform:olpc-xo1");
138
139 module_init(olpc_xo1_init);
140 module_exit(olpc_xo1_exit);