1 From 95b8e195427ce0c6b495925813d7e10949af8ce3 Mon Sep 17 00:00:00 2001
2 From: Andy Green <andy@openmoko.com>
3 Date: Fri, 25 Jul 2008 23:06:10 +0100
4 Subject: [PATCH] add-resume-reason-sysfs.patch
6 If you have U-Boot with uboot-add-find-wake-reason.patch, this
7 patch will get you a wake reason report from
9 cat /sys/devices/platform/neo1973-resume.0/resume_reason
68 This shows a problem, false wake from suspend due to battery full
70 Signed-off-by: Andy Green <andy@openmoko.com>
72 arch/arm/mach-s3c2440/mach-gta02.c | 5 +
73 arch/arm/plat-s3c24xx/Makefile | 4 +-
74 arch/arm/plat-s3c24xx/neo1973_pm_resume_reason.c | 134 ++++++++++++++++++++++
75 drivers/i2c/chips/pcf50633.c | 80 +++++++++++++
76 include/linux/pcf50633.h | 6 +
77 5 files changed, 227 insertions(+), 2 deletions(-)
78 create mode 100644 arch/arm/plat-s3c24xx/neo1973_pm_resume_reason.c
80 diff --git a/arch/arm/mach-s3c2440/mach-gta02.c b/arch/arm/mach-s3c2440/mach-gta02.c
81 index 9e8fae7..90b62c1 100644
82 --- a/arch/arm/mach-s3c2440/mach-gta02.c
83 +++ b/arch/arm/mach-s3c2440/mach-gta02.c
84 @@ -378,6 +378,10 @@ struct platform_device gta02_version_device = {
88 +struct platform_device gta02_resume_reason_device = {
89 + .name = "neo1973-resume",
93 static struct map_desc gta02_iodesc[] __initdata = {
95 @@ -737,6 +741,7 @@ static struct platform_device *gta02_devices[] __initdata = {
98 >a02_version_device,
99 + >a02_resume_reason_device,
103 diff --git a/arch/arm/plat-s3c24xx/Makefile b/arch/arm/plat-s3c24xx/Makefile
104 index c173f7b..f60dc5f 100644
105 --- a/arch/arm/plat-s3c24xx/Makefile
106 +++ b/arch/arm/plat-s3c24xx/Makefile
107 @@ -34,5 +34,5 @@ obj-$(CONFIG_MACH_NEO1973) += neo1973_version.o \
114 + neo1973_pm_resume_reason.o
115 diff --git a/arch/arm/plat-s3c24xx/neo1973_pm_resume_reason.c b/arch/arm/plat-s3c24xx/neo1973_pm_resume_reason.c
117 index 0000000..cca42dc
119 +++ b/arch/arm/plat-s3c24xx/neo1973_pm_resume_reason.c
122 + * Resume reason sysfs for the FIC Neo1973 GSM Phone
124 + * (C) 2008 by Openmoko Inc.
125 + * Author: Andy Green <andy@openmoko.com>
126 + * All rights reserved.
128 + * This program is free software; you can redistribute it and/or modify
129 + * it under the terms of the GNU General Public License resume_reason 2 as
130 + * published by the Free Software Foundation
134 +#include <linux/module.h>
135 +#include <linux/init.h>
136 +#include <linux/kernel.h>
137 +#include <linux/platform_device.h>
138 +#include <linux/io.h>
140 +#include <asm/hardware.h>
141 +#include <asm/mach-types.h>
143 +#ifdef CONFIG_MACH_NEO1973_GTA02
144 +#include <asm/arch/gta02.h>
145 +#include <linux/pcf50633.h>
148 +static unsigned int *gstatus4_mapped;
149 +static char *resume_reasons[] = {
152 + "EINT02_BLUETOOTH",
169 +static ssize_t resume_reason_read(struct device *dev,
170 + struct device_attribute *attr,
176 + for (bit = 0; resume_reasons[bit]; bit++) {
177 + if ((*gstatus4_mapped) & (1 << bit))
178 + end += sprintf(end, "* %s\n", resume_reasons[bit]);
180 + end += sprintf(end, " %s\n", resume_reasons[bit]);
182 + if (bit == 9) /* PMU */
183 + end += pcf50633_report_resumers(pcf50633_global, end);
190 +static DEVICE_ATTR(resume_reason, 0644, resume_reason_read, NULL);
192 +static struct attribute *neo1973_resume_reason_sysfs_entries[] = {
193 + &dev_attr_resume_reason.attr,
197 +static struct attribute_group neo1973_resume_reason_attr_group = {
199 + .attrs = neo1973_resume_reason_sysfs_entries,
202 +static int __init neo1973_resume_reason_probe(struct platform_device *pdev)
204 + dev_info(&pdev->dev, "starting\n");
206 + switch (machine_arch_type) {
207 +#ifdef CONFIG_MACH_NEO1973_GTA01
208 + case MACH_TYPE_NEO1973_GTA01:
210 +#endif /* CONFIG_MACH_NEO1973_GTA01 */
212 + gstatus4_mapped = ioremap(0x560000BC, 0x4);
213 + if (!gstatus4_mapped) {
214 + dev_err(&pdev->dev, "failed to ioremap() memory region\n");
220 + return sysfs_create_group(&pdev->dev.kobj, &neo1973_resume_reason_attr_group);
223 +static int neo1973_resume_reason_remove(struct platform_device *pdev)
225 + sysfs_remove_group(&pdev->dev.kobj, &neo1973_resume_reason_attr_group);
226 + iounmap(gstatus4_mapped);
230 +static struct platform_driver neo1973_resume_reason_driver = {
231 + .probe = neo1973_resume_reason_probe,
232 + .remove = neo1973_resume_reason_remove,
234 + .name = "neo1973-resume",
238 +static int __devinit neo1973_resume_reason_init(void)
240 + return platform_driver_register(&neo1973_resume_reason_driver);
243 +static void neo1973_resume_reason_exit(void)
245 + platform_driver_unregister(&neo1973_resume_reason_driver);
248 +module_init(neo1973_resume_reason_init);
249 +module_exit(neo1973_resume_reason_exit);
251 +MODULE_LICENSE("GPL");
252 +MODULE_AUTHOR("Andy Green <andy@openmoko.com>");
253 +MODULE_DESCRIPTION("Neo1973 resume_reason");
255 diff --git a/drivers/i2c/chips/pcf50633.c b/drivers/i2c/chips/pcf50633.c
256 index da58aa3..d2ff2c1 100644
257 --- a/drivers/i2c/chips/pcf50633.c
258 +++ b/drivers/i2c/chips/pcf50633.c
259 @@ -120,6 +120,8 @@ struct pcf50633_data {
263 + int have_been_suspended;
264 + unsigned char pcfirq_resume[5];
266 int coldplug_done; /* cleared by probe, set by first work service */
267 int flag_bat_voltage_read; /* ipc to /sys batt voltage read func */
268 @@ -597,6 +599,17 @@ static void pcf50633_work(struct work_struct *work)
272 + /* hey did we just resume? */
274 + if (pcf->have_been_suspended) {
275 + pcf->have_been_suspended = 0;
277 + * grab a copy of resume interrupt reasons
278 + * from pcf50633 POV
280 + memcpy(pcf->pcfirq_resume, pcfirq, sizeof(pcf->pcfirq_resume));
283 if (!pcf->coldplug_done) {
284 DEBUGP("PMU Coldplug init\n");
286 @@ -1856,6 +1869,71 @@ static int pcf50633_detach_client(struct i2c_client *client)
290 +/* you're going to need >300 bytes in buf */
292 +int pcf50633_report_resumers(struct pcf50633_data *pcf, char *buf)
294 + static char *int_names[] = {
343 + for (n = 0; n < 40; n++)
344 + if (int_names[n]) {
345 + if (pcf->pcfirq_resume[n >> 3] & (1 >> (n & 7)))
346 + end += sprintf(end, " * %s\n", int_names[n]);
348 + end += sprintf(end, " %s\n", int_names[n]);
356 #define INT1M_RESUMERS (PCF50633_INT1_ADPINS | \
357 PCF50633_INT1_ADPREM | \
358 @@ -1938,6 +2016,8 @@ static int pcf50633_suspend(struct device *dev, pm_message_t state)
359 __reg_write(pcf, PCF50633_REG_INT4M, ~INT4M_RESUMERS & 0xff);
360 __reg_write(pcf, PCF50633_REG_INT5M, ~INT5M_RESUMERS & 0xff);
362 + pcf->have_been_suspended = 1;
364 mutex_unlock(&pcf->lock);
367 diff --git a/include/linux/pcf50633.h b/include/linux/pcf50633.h
368 index f427985..39d919d 100644
369 --- a/include/linux/pcf50633.h
370 +++ b/include/linux/pcf50633.h
371 @@ -64,6 +64,12 @@ pcf50633_charge_enable(struct pcf50633_data *pcf, int on);
373 pcf50633_backlight_resume(struct pcf50633_data *pcf);
376 +pcf50633_battvolt(struct pcf50633_data *pcf);
379 +pcf50633_report_resumers(struct pcf50633_data *pcf, char *buf);
381 #define PCF50633_FEAT_EXTON 0x00000001 /* not yet supported */
382 #define PCF50633_FEAT_MBC 0x00000002
383 #define PCF50633_FEAT_BBC 0x00000004 /* not yet supported */