[brcm63xx] resync kernel configuration
[openwrt.git] / target / linux / s3c24xx / patches-2.6.24 / 1199-fix-pcf50633-disable-irq-from-suspend-until-resume.p.patch
1 From eaa55efc0b559abebbcf2acea6ce267cea4c26f2 Mon Sep 17 00:00:00 2001
2 From: Andy Green <andy@openmoko.com>
3 Date: Wed, 2 Jul 2008 22:41:52 +0100
4 Subject: [PATCH] fix-pcf50633-disable-irq-from-suspend-until-resume.patch
5
6 Disable pcf interrupt (not for wake, just as interrupt) in
7 suspend, re-enable it again just before we force-call the
8 workqueue function at end of pcf resume, which leads to
9 pcf interrupt source registers getting cleared so it can
10 signal an interrupt normally again.
11
12 This change ends the uncontrolled appearance of pcf interrupts
13 during resume time which previously caused the work to attempt
14 to use the I2C stuff before i2c host device had itself resumed.
15 Now the isr work is only queued, and the isr work function called,
16 definitively after pcf resume completes.
17
18 In suspend time, the work function may have been queued some
19 time before and be pending, and it could still show up at a
20 bad time. Therefore if the work function sees that it is
21 coming since the start of pcf50633 suspend function, it
22 aborts without attempting to read the pcf interrupt regs,
23 leaving them for resume to take care of.
24
25 USB current limit and no battery work functions are also made
26 aware of suspend state and act accordingly.
27
28 Lastly I noticed that in early resume, i2c_get_clientdata(&pcf->client)
29 returns NULL, presumably because i2c device is still suspended. This
30 could easily make trouble for async events like interrupt work,
31 since pcf pointer is the client data. Disabling appearance of the
32 work until after pcf50633 resume will also avoid that.
33
34 Signed-off-by: Andy Green <andy@openmoko.com>
35 ---
36 drivers/i2c/chips/pcf50633.c | 93 +++++++++++++++++++++++++++++-------------
37 1 files changed, 65 insertions(+), 28 deletions(-)
38
39 diff --git a/drivers/i2c/chips/pcf50633.c b/drivers/i2c/chips/pcf50633.c
40 index c014384..120fdbc 100644
41 --- a/drivers/i2c/chips/pcf50633.c
42 +++ b/drivers/i2c/chips/pcf50633.c
43 @@ -632,6 +632,11 @@ static void pcf50633_work_usbcurlim(struct work_struct *work)
44
45 mutex_lock(&pcf->working_lock_usb_curlimit);
46
47 + /* just can't cope with it if we are suspending, don't reschedule */
48 + if ((pcf->suspend_state == PCF50633_SS_STARTING_SUSPEND) ||
49 + (pcf->suspend_state == PCF50633_SS_COMPLETED_SUSPEND))
50 + goto bail;
51 +
52 dev_info(&pcf->client.dev, "pcf50633_work_usbcurlim\n");
53
54 if (!pcf->probe_completed)
55 @@ -663,7 +668,8 @@ bail:
56 reschedule:
57 dev_info(&pcf->client.dev, "pcf50633_work_usbcurlim rescheduling\n");
58 if (!schedule_work(&pcf->work_usb_curlimit))
59 - dev_err(&pcf->client.dev, "work item may be lost\n");
60 + dev_err(&pcf->client.dev, "curlim reschedule work "
61 + "already queued\n");
62
63 mutex_unlock(&pcf->working_lock_usb_curlimit);
64 /* don't spew, delaying whatever else is happening */
65 @@ -700,7 +706,7 @@ int pcf50633_notify_usb_current_limit_change(struct pcf50633_data *pcf,
66 pcf->pending_curlimit = ma;
67
68 if (!schedule_work(&pcf->work_usb_curlimit))
69 - dev_err(&pcf->client.dev, "work item may be lost\n");
70 + dev_err(&pcf->client.dev, "curlim work item already queued\n");
71
72 return 0;
73 }
74 @@ -727,6 +733,9 @@ static void pcf50633_work_nobat(struct work_struct *work)
75 while (1) {
76 msleep(1000);
77
78 + if (pcf->suspend_state != PCF50633_SS_RUNNING)
79 + continue;
80 +
81 /* there's a battery in there now? */
82 if (reg_read(pcf, PCF50633_REG_MBCS3) & 0x40) {
83
84 @@ -761,6 +770,10 @@ static void pcf50633_work(struct work_struct *work)
85 mutex_lock(&pcf->working_lock);
86 pcf->working = 1;
87
88 + /* sanity */
89 + if (!&pcf->client.dev)
90 + goto bail;
91 +
92 /*
93 * if we are presently suspending, we are not in a position to deal
94 * with pcf50633 interrupts at all.
95 @@ -784,42 +797,55 @@ static void pcf50633_work(struct work_struct *work)
96 * reloaded with their pre-suspend states yet. Therefore we will
97 * defer our service if we are called like that until our resume has
98 * completed.
99 + *
100 + * This shouldn't happen any more because we disable servicing this
101 + * interrupt in suspend and don't re-enable it until resume is
102 + * completed.
103 */
104
105 - if (pcf->have_been_suspended && (pcf->have_been_suspended < 3))
106 + if (pcf->suspend_state &&
107 + (pcf->suspend_state != PCF50633_SS_COMPLETED_RESUME))
108 + goto reschedule;
109 +
110 + /* this is the case early in resume! Sanity check! */
111 + if (i2c_get_clientdata(&pcf->client) == NULL)
112 goto reschedule;
113
114 /*
115 - * datasheet says we have to read the five IRQ
116 - * status regs in one transaction
117 - */
118 - ret = i2c_smbus_read_i2c_block_data(&pcf->client, PCF50633_REG_INT1, 5,
119 - pcfirq);
120 - if (ret != 5) {
121 + * datasheet says we have to read the five IRQ
122 + * status regs in one transaction
123 + */
124 + ret = i2c_smbus_read_i2c_block_data(&pcf->client,
125 + PCF50633_REG_INT1,
126 + sizeof(pcfirq),
127 + pcfirq);
128 + if (ret != sizeof(pcfirq)) {
129 dev_info(&pcf->client.dev,
130 - "Oh crap PMU IRQ register read failed -- "
131 - "retrying later %d\n", ret);
132 + "Oh crap PMU IRQ register read failed -- "
133 + "retrying later %d\n", ret);
134 /*
135 - * it shouldn't fail, we no longer attempt to use I2C while
136 - * it can be suspended. But we don't have much option but to
137 - * retry if if it ever did fail, because if we don't service
138 - * the interrupt to clear it, we will never see another PMU
139 - * interrupt edge.
140 + * it shouldn't fail, we no longer attempt to use
141 + * I2C while it can be suspended. But we don't have
142 + * much option but to retry if if it ever did fail,
143 + * because if we don't service the interrupt to clear
144 + * it, we will never see another PMU interrupt edge.
145 */
146 goto reschedule;
147 }
148
149 - /* hey did we just resume? */
150 -
151 - if (pcf->have_been_suspended) {
152 - /* resume is officially over now then */
153 - pcf->have_been_suspended = 0;
154 + /* hey did we just resume? (because we don't get here unless we are
155 + * running normally or the first call after resumption)
156 + */
157
158 + if (pcf->suspend_state != PCF50633_SS_RUNNING) {
159 /*
160 - * grab a copy of resume interrupt reasons
161 - * from pcf50633 POV
162 - */
163 + * grab a copy of resume interrupt reasons
164 + * from pcf50633 POV
165 + */
166 memcpy(pcf->pcfirq_resume, pcfirq, sizeof(pcf->pcfirq_resume));
167 +
168 + /* pcf50633 resume is really really over now then */
169 + pcf->suspend_state = PCF50633_SS_RUNNING;
170 }
171
172 if (!pcf->coldplug_done) {
173 @@ -1169,6 +1195,7 @@ static void pcf50633_work(struct work_struct *work)
174
175 DEBUGPC("\n");
176
177 +bail:
178 pcf->working = 0;
179 input_sync(pcf->input_dev);
180 put_device(&pcf->client.dev);
181 @@ -1202,7 +1229,7 @@ static irqreturn_t pcf50633_irq(int irq, void *_pcf)
182
183 get_device(&pcf->client.dev);
184 if (!schedule_work(&pcf->work) && !pcf->working)
185 - dev_err(&pcf->client.dev, "work item may be lost\n");
186 + dev_err(&pcf->client.dev, "pcf irq work already queued\n");
187
188 return IRQ_HANDLED;
189 }
190 @@ -2310,7 +2337,7 @@ int pcf50633_report_resumers(struct pcf50633_data *pcf, char *buf)
191 char *end = buf;
192 int n;
193
194 - for (n = 0; n < 40; n++)
195 + for (n = 0; n < ARRAY_SIZE(int_names); n++)
196 if (int_names[n]) {
197 if (pcf->pcfirq_resume[n >> 3] & (1 >> (n & 7)))
198 end += sprintf(end, " * %s\n", int_names[n]);
199 @@ -2359,6 +2386,15 @@ static int pcf50633_suspend(struct device *dev, pm_message_t state)
200
201 mutex_lock(&pcf->lock);
202
203 + pcf->suspend_state = PCF50633_SS_STARTING_SUSPEND;
204 +
205 + /* we are not going to service any further interrupts until we
206 + * resume. If the IRQ workqueue is still pending in the background,
207 + * it will bail when it sees we set suspend state above
208 + */
209 +
210 + disable_irq(pcf->irq);
211 +
212 /* Save all registers that don't "survive" standby state */
213 pcf->standby_regs.ooctim2 = __reg_read(pcf, PCF50633_REG_OOCTIM2);
214
215 @@ -2502,6 +2538,8 @@ static int pcf50633_resume(struct device *dev)
216
217 pcf->suspend_state = PCF50633_SS_COMPLETED_RESUME;
218
219 + enable_irq(pcf->irq);
220 +
221 mutex_unlock(&pcf->lock);
222
223 /* gratuitous call to PCF work function, in the case that the PCF
224 @@ -2511,8 +2549,7 @@ static int pcf50633_resume(struct device *dev)
225 */
226
227 get_device(&pcf->client.dev);
228 - if (!schedule_work(&pcf->work) && !pcf->working)
229 - dev_err(&pcf->client.dev, "resume work item may be lost\n");
230 + pcf50633_work(&pcf->work);
231
232 callback_all_resume_dependencies(&pcf->resume_dependency);
233
234 --
235 1.5.6.5
236
This page took 0.054529 seconds and 5 git commands to generate.