tracking-2.6.27-rc2-include-path-changes.patch
[kernel.git] / arch / arm / plat-s3c24xx / neo1973_pm_resume_reason.c
1 /*
2  * Resume reason sysfs for the FIC Neo1973 GSM Phone
3  *
4  * (C) 2008 by Openmoko Inc.
5  * Author: Andy Green <andy@openmoko.com>
6  * All rights reserved.
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 resume_reason 2 as
10  * published by the Free Software Foundation
11  *
12  */
13
14 #include <linux/module.h>
15 #include <linux/init.h>
16 #include <linux/kernel.h>
17 #include <linux/platform_device.h>
18 #include <linux/io.h>
19
20 #include <mach/hardware.h>
21 #include <asm/mach-types.h>
22
23 #ifdef CONFIG_MACH_NEO1973_GTA02
24 #include <asm/arch/gta02.h>
25 #include <linux/pcf50633.h>
26 #endif
27
28 static unsigned int *gstatus4_mapped;
29 static char *resume_reasons[][17] = { { /* GTA01 */
30         "EINT00_NULL",
31         "EINT01_GSM",
32         "EINT02_NULL",
33         "EINT03_NULL",
34         "EINT04_JACK",
35         "EINT05_SDCARD",
36         "EINT06_AUXKEY",
37         "EINT07_HOLDKEY",
38         "EINT08_NULL",
39         "EINT09_NULL",
40         "EINT10_NULL",
41         "EINT11_NULL",
42         "EINT12_NULL",
43         "EINT13_NULL",
44         "EINT14_NULL",
45         "EINT15_NULL",
46         NULL
47 }, { /* GTA02 */
48         "EINT00_ACCEL1",
49         "EINT01_GSM",
50         "EINT02_BLUETOOTH",
51         "EINT03_DEBUGBRD",
52         "EINT04_JACK",
53         "EINT05_WLAN",
54         "EINT06_AUXKEY",
55         "EINT07_HOLDKEY",
56         "EINT08_ACCEL2",
57         "EINT09_PMU",
58         "EINT10_NULL",
59         "EINT11_NULL",
60         "EINT12_GLAMO",
61         "EINT13_NULL",
62         "EINT14_NULL",
63         "EINT15_NULL",
64         NULL
65 } };
66
67 static ssize_t resume_reason_read(struct device *dev,
68                                   struct device_attribute *attr,
69                                   char *buf)
70 {
71         int bit = 0;
72         char *end = buf;
73         int gta = !!machine_is_neo1973_gta02();
74
75         for (bit = 0; resume_reasons[gta][bit]; bit++) {
76                 if ((*gstatus4_mapped) & (1 << bit))
77                         end += sprintf(end, "* %s\n", resume_reasons[gta][bit]);
78                 else
79                         end += sprintf(end, "  %s\n", resume_reasons[gta][bit]);
80
81 #ifdef CONFIG_MACH_NEO1973_GTA02
82                 if ((gta) && (bit == 9)) /* PMU */
83                         end += pcf50633_report_resumers(pcf50633_global, end);
84 #endif
85         }
86
87         return end - buf;
88 }
89
90
91 static DEVICE_ATTR(resume_reason, 0644, resume_reason_read, NULL);
92
93 static struct attribute *neo1973_resume_reason_sysfs_entries[] = {
94         &dev_attr_resume_reason.attr,
95         NULL
96 };
97
98 static struct attribute_group neo1973_resume_reason_attr_group = {
99         .name   = NULL,
100         .attrs  = neo1973_resume_reason_sysfs_entries,
101 };
102
103 static int __init neo1973_resume_reason_probe(struct platform_device *pdev)
104 {
105         dev_info(&pdev->dev, "starting\n");
106
107         gstatus4_mapped = ioremap(0x560000BC /* GSTATUS4 */, 0x4);
108         if (!gstatus4_mapped) {
109                 dev_err(&pdev->dev, "failed to ioremap() memory region\n");
110                 return -EINVAL;
111         }
112
113         return sysfs_create_group(&pdev->dev.kobj,
114                                             &neo1973_resume_reason_attr_group);
115 }
116
117 static int neo1973_resume_reason_remove(struct platform_device *pdev)
118 {
119         sysfs_remove_group(&pdev->dev.kobj, &neo1973_resume_reason_attr_group);
120         iounmap(gstatus4_mapped);
121         return 0;
122 }
123
124 static struct platform_driver neo1973_resume_reason_driver = {
125         .probe          = neo1973_resume_reason_probe,
126         .remove         = neo1973_resume_reason_remove,
127         .driver         = {
128                 .name           = "neo1973-resume",
129         },
130 };
131
132 static int __devinit neo1973_resume_reason_init(void)
133 {
134         return platform_driver_register(&neo1973_resume_reason_driver);
135 }
136
137 static void neo1973_resume_reason_exit(void)
138 {
139         platform_driver_unregister(&neo1973_resume_reason_driver);
140 }
141
142 module_init(neo1973_resume_reason_init);
143 module_exit(neo1973_resume_reason_exit);
144
145 MODULE_LICENSE("GPL");
146 MODULE_AUTHOR("Andy Green <andy@openmoko.com>");
147 MODULE_DESCRIPTION("Neo1973 resume_reason");