1 From de64d8449b10dc39eebdee6bc01409cd0197e38a Mon Sep 17 00:00:00 2001
2 From: Andy Green <andy@openmoko.com>
3 Date: Wed, 2 Jul 2008 22:38:15 +0100
4 Subject: [PATCH] add-use-pcf50633-resume-callback-jbt6k74.patch
6 Adds the resume callback stuff to glamo, then changes
7 jbt6k74 to no longer use a sleeping workqueue, but to
8 make its resume actions dependent on pcf50633 and
9 glamo resume (for backlight and communication to LCM
12 Signed-off-by: Andy Green <andy@openmoko.com>
14 arch/arm/mach-s3c2440/mach-gta02.c | 39 ++++++++++++++++++++-
15 drivers/i2c/chips/pcf50633.c | 17 +++------
16 drivers/mfd/glamo/glamo-core.c | 16 ++++++++
17 drivers/mfd/glamo/glamo-core.h | 3 +-
18 drivers/video/display/jbt6k74.c | 67 +++++++++++++++++++-----------------
19 include/linux/glamofb.h | 3 ++
20 include/linux/jbt6k74.h | 4 ++
21 include/linux/pcf50633.h | 2 +-
22 include/linux/resume-dependency.h | 10 +++---
23 9 files changed, 108 insertions(+), 53 deletions(-)
25 diff --git a/arch/arm/mach-s3c2440/mach-gta02.c b/arch/arm/mach-s3c2440/mach-gta02.c
26 index d7882ea..9ba1036 100644
27 --- a/arch/arm/mach-s3c2440/mach-gta02.c
28 +++ b/arch/arm/mach-s3c2440/mach-gta02.c
30 /* arbitrates which sensor IRQ owns the shared SPI bus */
31 static spinlock_t motion_irq_lock;
33 +/* the dependency of jbt / LCM on pcf50633 resume */
34 +struct resume_dependency resume_dep_jbt_pcf;
35 +/* the dependency of jbt / LCM on glamo resume */
36 +struct resume_dependency resume_dep_jbt_glamo;
39 /* define FIQ IPC struct */
41 * contains stuff FIQ ISR modifies and normal kernel code can see and use
42 @@ -857,21 +863,50 @@ static struct s3c2410_ts_mach_info gta02_ts_cfg = {
44 /* SPI: LCM control interface attached to Glamo3362 */
46 -void gta02_jbt6k74_reset(int devidx, int level)
47 +static void gta02_jbt6k74_reset(int devidx, int level)
49 glamo_lcm_reset(level);
52 /* finally bring up deferred backlight resume now LCM is resumed itself */
54 -void gta02_jbt6k74_resuming(int devidx)
55 +static void gta02_jbt6k74_resuming(int devidx)
57 pcf50633_backlight_resume(pcf50633_global);
60 +static int gta02_jbt6k74_all_dependencies_resumed(int devidx)
62 + if (!resume_dep_jbt_pcf.called_flag)
65 + if (!resume_dep_jbt_glamo.called_flag)
71 +/* register jbt resume action to be dependent on pcf50633 and glamo resume */
73 +static void gta02_jbt6k74_suspending(int devindex, struct spi_device *spi)
75 + void jbt6k74_resume(void *spi); /* little white lies about types */
77 + resume_dep_jbt_pcf.callback = jbt6k74_resume;
78 + resume_dep_jbt_pcf.context = (void *)spi;
79 + pcf50633_register_resume_dependency(pcf50633_global,
80 + &resume_dep_jbt_pcf);
81 + resume_dep_jbt_glamo.callback = jbt6k74_resume;
82 + resume_dep_jbt_glamo.context = (void *)spi;
83 + glamo_register_resume_dependency(&resume_dep_jbt_glamo);
87 const struct jbt6k74_platform_data jbt6k74_pdata = {
88 .reset = gta02_jbt6k74_reset,
89 .resuming = gta02_jbt6k74_resuming,
90 + .suspending = gta02_jbt6k74_suspending,
91 + .all_dependencies_resumed = gta02_jbt6k74_all_dependencies_resumed,
94 static struct spi_board_info gta02_spi_board_info[] = {
95 diff --git a/drivers/i2c/chips/pcf50633.c b/drivers/i2c/chips/pcf50633.c
96 index ec6b9f1..2f9b9e1 100644
97 --- a/drivers/i2c/chips/pcf50633.c
98 +++ b/drivers/i2c/chips/pcf50633.c
99 @@ -1937,7 +1937,7 @@ static int pcf50633_detect(struct i2c_adapter *adapter, int address, int kind)
101 pcf50633_global = data;
103 - init_resume_dependency_list(data->resume_dependency);
104 + init_resume_dependency_list(&data->resume_dependency);
106 populate_sysfs_group(data);
108 @@ -2153,11 +2153,11 @@ int pcf50633_report_resumers(struct pcf50633_data *pcf, char *buf)
111 void pcf50633_register_resume_dependency(struct pcf50633_data *pcf,
112 - struct pcf50633_resume_dependency *dep)
113 + struct resume_dependency *dep)
115 - register_resume_dependency(pcf->resume_dependency, dep);
116 + register_resume_dependency(&pcf->resume_dependency, dep);
118 -EXPORT_SYMBOL_GPL(pcf50633_register_resume_dep);
119 +EXPORT_SYMBOL_GPL(pcf50633_register_resume_dependency);
122 static int pcf50633_suspend(struct device *dev, pm_message_t state)
123 @@ -2251,9 +2251,6 @@ static int pcf50633_resume(struct device *dev)
124 struct i2c_client *client = to_i2c_client(dev);
125 struct pcf50633_data *pcf = i2c_get_clientdata(client);
127 - struct list_head *pos, *q;
128 - struct pcf50633_resume_dependency *dep;
131 mutex_lock(&pcf->lock);
133 @@ -2281,10 +2278,6 @@ static int pcf50633_resume(struct device *dev)
134 __reg_write(pcf, PCF50633_REG_LEDOUT, pcf->standby_regs.ledout);
135 __reg_write(pcf, PCF50633_REG_LEDENA, pcf->standby_regs.ledena);
136 __reg_write(pcf, PCF50633_REG_LEDDIM, pcf->standby_regs.leddim);
137 - } else { /* force backlight down, platform will restore later */
138 - __reg_write(pcf, PCF50633_REG_LEDOUT, 2);
139 - __reg_write(pcf, PCF50633_REG_LEDENA, 0x20);
140 - __reg_write(pcf, PCF50633_REG_LEDDIM, 1);
143 /* FIXME: one big read? */
144 @@ -2298,7 +2291,7 @@ static int pcf50633_resume(struct device *dev)
146 pcf50633_irq(pcf->irq, pcf);
148 - callback_all_resume_dependencies(pcf->resume_dependency);
149 + callback_all_resume_dependencies(&pcf->resume_dependency);
153 diff --git a/drivers/mfd/glamo/glamo-core.c b/drivers/mfd/glamo/glamo-core.c
154 index 34b2a01..4925e62 100644
155 --- a/drivers/mfd/glamo/glamo-core.c
156 +++ b/drivers/mfd/glamo/glamo-core.c
157 @@ -1087,6 +1087,8 @@ static int __init glamo_probe(struct platform_device *pdev)
161 + init_resume_dependency_list(&glamo->resume_dependency);
163 /* register a number of sibling devices whoise IOMEM resources
164 * are siblings of pdev's IOMEM resource */
166 @@ -1225,6 +1227,18 @@ static int glamo_remove(struct platform_device *pdev)
171 +/* have to export this because struct glamo_core is opaque */
173 +void glamo_register_resume_dependency(struct resume_dependency *
176 + register_resume_dependency(&glamo_handle->resume_dependency,
177 + resume_dependency);
179 +EXPORT_SYMBOL_GPL(glamo_register_resume_dependency);
182 static int glamo_suspend(struct platform_device *pdev, pm_message_t state)
184 glamo_power(glamo_handle, GLAMO_POWER_SUSPEND);
185 @@ -1234,6 +1248,8 @@ static int glamo_suspend(struct platform_device *pdev, pm_message_t state)
186 static int glamo_resume(struct platform_device *pdev)
188 glamo_power(glamo_handle, GLAMO_POWER_ON);
189 + callback_all_resume_dependencies(&glamo_handle->resume_dependency);
194 diff --git a/drivers/mfd/glamo/glamo-core.h b/drivers/mfd/glamo/glamo-core.h
195 index cf89f03..1fee059 100644
196 --- a/drivers/mfd/glamo/glamo-core.h
197 +++ b/drivers/mfd/glamo/glamo-core.h
199 #define __GLAMO_CORE_H
201 #include <asm/system.h>
203 +#include <linux/resume-dependency.h>
205 /* for the time being, we put the on-screen framebuffer into the lowest
206 * VRAM space. This should make the code easily compatible with the various
207 @@ -29,6 +29,7 @@ struct glamo_core {
211 + struct resume_dependency resume_dependency;
214 struct glamo_script {
215 diff --git a/drivers/video/display/jbt6k74.c b/drivers/video/display/jbt6k74.c
216 index 178e2da..8e7bf36 100644
217 --- a/drivers/video/display/jbt6k74.c
218 +++ b/drivers/video/display/jbt6k74.c
220 #include <linux/device.h>
221 #include <linux/platform_device.h>
222 #include <linux/delay.h>
223 -#include <linux/workqueue.h>
224 #include <linux/jbt6k74.h>
226 -#include <linux/spi/spi.h>
229 JBT_REG_SLEEP_IN = 0x10,
230 JBT_REG_SLEEP_OUT = 0x11,
231 @@ -116,14 +113,12 @@ struct jbt_info {
232 struct mutex lock; /* protects tx_buf and reg_cache */
235 - struct work_struct work;
239 #define JBT_COMMAND 0x000
240 #define JBT_DATA 0x100
242 -static void jbt_resume_work(struct work_struct *work);
245 static int jbt_reg_write_nodata(struct jbt_info *jbt, u8 reg)
247 @@ -576,8 +571,6 @@ static int __devinit jbt_probe(struct spi_device *spi)
251 - INIT_WORK(&jbt->work, jbt_resume_work);
254 jbt->state = JBT_STATE_DEEP_STANDBY;
255 mutex_init(&jbt->lock);
256 @@ -635,27 +628,48 @@ static int jbt_suspend(struct spi_device *spi, pm_message_t state)
257 struct jbt_info *jbt = dev_get_drvdata(&spi->dev);
258 struct jbt6k74_platform_data *jbt6k74_pdata = spi->dev.platform_data;
260 + /* platform needs to register resume dependencies here */
261 + if (jbt6k74_pdata->suspending)
262 + (jbt6k74_pdata->suspending)(0, spi);
264 /* Save mode for resume */
265 jbt->last_state = jbt->state;
266 jbt6k74_enter_state(jbt, JBT_STATE_DEEP_STANDBY);
268 - (jbt6k74_pdata->reset)(0, 0);
269 + jbt->have_resumed = 0;
271 +// (jbt6k74_pdata->reset)(0, 0);
276 -static void jbt_resume_work(struct work_struct *work)
277 +int jbt6k74_resume(struct spi_device *spi)
279 - struct jbt_info *jbt = container_of(work, struct jbt_info, work);
280 - struct jbt6k74_platform_data *jbt6k74_pdata =
281 - jbt->spi_dev->dev.platform_data;
282 + struct jbt_info *jbt = dev_get_drvdata(&spi->dev);
283 + struct jbt6k74_platform_data *jbt6k74_pdata = spi->dev.platform_data;
285 + /* if we still wait on dependencies, exit because we will get called
286 + * again. This guy will get called once by core resume action, and
287 + * should be set as resume_dependency callback for any dependencies
288 + * set by platform code.
291 - printk(KERN_INFO"jbt_resume_work waiting...\n");
292 - /* 100ms is not enough here 2008-05-08 andy@openmoko.com
293 - * if CONFIG_PM_DEBUG is enabled 2000ms is required
294 + if (jbt6k74_pdata->all_dependencies_resumed)
295 + if (!(jbt6k74_pdata->all_dependencies_resumed)(0))
298 + /* we can get called twice with all dependencies resumed if our core
299 + * resume callback is last of all. Protect against going twice
302 - printk(KERN_INFO"jbt_resume_work GO...\n");
303 + if (jbt->have_resumed)
306 + jbt->have_resumed = 1;
308 + /* OK we are sure all devices we depend on for operation are up now */
310 + /* even this needs glamo up on GTA02 :-/ */
311 + (jbt6k74_pdata->reset)(0, 1);
313 jbt6k74_enter_state(jbt, JBT_STATE_DEEP_STANDBY);
315 @@ -675,21 +689,10 @@ static void jbt_resume_work(struct work_struct *work)
316 if (jbt6k74_pdata->resuming)
317 (jbt6k74_pdata->resuming)(0);
319 - printk(KERN_INFO"jbt_resume_work done...\n");
322 -static int jbt_resume(struct spi_device *spi)
324 - struct jbt_info *jbt = dev_get_drvdata(&spi->dev);
325 - struct jbt6k74_platform_data *jbt6k74_pdata = spi->dev.platform_data;
327 - (jbt6k74_pdata->reset)(0, 1);
329 - if (!schedule_work(&jbt->work))
330 - dev_err(&spi->dev, "Unable to schedule LCM wakeup work\n");
334 +EXPORT_SYMBOL_GPL(jbt6k74_resume);
337 #define jbt_suspend NULL
338 #define jbt_resume NULL
339 @@ -704,7 +707,7 @@ static struct spi_driver jbt6k74_driver = {
341 .remove = __devexit_p(jbt_remove),
342 .suspend = jbt_suspend,
343 - .resume = jbt_resume,
344 + .resume = jbt6k74_resume,
347 static int __init jbt_init(void)
348 diff --git a/include/linux/glamofb.h b/include/linux/glamofb.h
349 index 51bf593..bb4ed0a 100644
350 --- a/include/linux/glamofb.h
351 +++ b/include/linux/glamofb.h
353 #define _LINUX_GLAMOFB_H
355 #include <linux/spi/glamo.h>
356 +#include <linux/resume-dependency.h>
360 @@ -36,5 +37,7 @@ struct glamofb_platform_data {
361 int glamofb_cmd_mode(struct glamofb_handle *gfb, int on);
362 int glamofb_cmd_write(struct glamofb_handle *gfb, u_int16_t val);
363 void glamo_lcm_reset(int level);
365 +glamo_register_resume_dependency(struct resume_dependency * resume_dependency);
368 diff --git a/include/linux/jbt6k74.h b/include/linux/jbt6k74.h
369 index 0ac9124..f0eaf39 100644
370 --- a/include/linux/jbt6k74.h
371 +++ b/include/linux/jbt6k74.h
373 #ifndef __JBT6K74_H__
374 #define __JBT6K74_H__
376 +#include <linux/spi/spi.h>
378 struct jbt6k74_platform_data {
379 void (*reset)(int devindex, int level);
380 void (*resuming)(int devindex); /* called when LCM is resumed */
381 + void (*suspending)(int devindex, struct spi_device *spi);
382 + int (*all_dependencies_resumed)(int devindex);
386 diff --git a/include/linux/pcf50633.h b/include/linux/pcf50633.h
387 index 2bef616..8a75b28 100644
388 --- a/include/linux/pcf50633.h
389 +++ b/include/linux/pcf50633.h
390 @@ -127,7 +127,7 @@ pcf50633_report_resumers(struct pcf50633_data *pcf, char *buf);
393 pcf50633_register_resume_dependency(struct pcf50633_data *pcf,
394 - struct pcf50633_resume_dependency *dep);
395 + struct resume_dependency *dep);
398 #define PCF50633_FEAT_EXTON 0x00000001 /* not yet supported */
399 diff --git a/include/linux/resume-dependency.h b/include/linux/resume-dependency.h
400 index b13aa3e..e0c0f33 100644
401 --- a/include/linux/resume-dependency.h
402 +++ b/include/linux/resume-dependency.h
403 @@ -38,7 +38,7 @@ struct resume_dependency {
406 #define init_resume_dependency_list(_head) \
407 - INIT_LIST_HEAD(&_head.list);
408 + INIT_LIST_HEAD(&(_head)->list);
411 /* if your resume function depends on something else being resumed first, you
412 @@ -48,8 +48,8 @@ struct resume_dependency {
415 #define register_resume_dependency(_head, _dep) { \
416 - _dep->called_flag = 0; \
417 - list_add(&_dep->list, &_head->list); \
418 + (_dep)->called_flag = 0; \
419 + list_add(&(_dep)->list, &(_head)->list); \
422 /* In the resume function that things can be dependent on, at the end you
423 @@ -61,10 +61,10 @@ struct resume_dependency {
424 struct list_head *_pos, *_q; \
425 struct resume_dependency *_dep; \
427 - list_for_each_safe(pos, _q, &_head.list) { \
428 + list_for_each_safe(_pos, _q, &((_head)->list)) { \
429 _dep = list_entry(_pos, struct resume_dependency, list); \
430 _dep->called_flag = 1; \
431 - (_dep->callback)(dep->context); \
432 + (_dep->callback)(_dep->context); \