Update bq2415x_charger patch:
[kernel-power] / kernel-power-2.6.28 / debian / patches / 0001-mtd-fix-a-huge-latency-problem-in-the-MTD-CFI-flash-.diff
1 From 5a2ef8426802c6c76df555b83cab4522f5bdf1bc Mon Sep 17 00:00:00 2001
2 From: Stefani Seibold <stefani@seibold.net>
3 Date: Sun, 18 Apr 2010 22:46:44 +0200
4 Subject: [PATCH 1/2] mtd: fix a huge latency problem in the MTD CFI flash driver.
5
6 The use of a memcpy() during a spinlock operation will cause very long
7 thread context switch delays if the flash chip bandwidth is low and the
8 data to be copied large, because a spinlock will disable preemption.
9
10 For example: A flash with 6,5 MB/s bandwidth will cause under ubifs,
11 which request sometimes 128 KiB (the flash erase size), a preemption delay of
12 20 milliseconds. High priority threads will not be served during this
13 time, regardless whether this threads access the flash or not. This behavior
14 breaks real time.
15
16 The patch changes all the use of spin_lock operations for xxxx->mutex
17 into mutex operations, which is exact what the name says and means.
18
19 I have checked the code of the drivers and there is no use of atomic
20 pathes like interrupt or timers. The mtdoops facility will also not be used
21 by this drivers. So it is dave to replace the spin_lock against mutex.
22
23 There is no performance regression since the mutex is normally not
24 acquired.
25
26 Changelog:
27  06.03.2010 First release
28  26.03.2010 Fix mutex[1] issue and tested it for compile failure
29
30 Signed-off-by: Stefani Seibold <stefani@seibold.net>
31 Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
32 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
33 ---
34  drivers/mtd/chips/cfi_cmdset_0001.c |  131 +++++++++++++++++-----------------
35  drivers/mtd/chips/cfi_cmdset_0002.c |  124 ++++++++++++++++----------------
36  drivers/mtd/chips/cfi_cmdset_0020.c |  136 +++++++++++++++++-----------------
37  drivers/mtd/chips/fwh_lock.h        |    6 +-
38  drivers/mtd/chips/gen_probe.c       |    3 +-
39  include/linux/mtd/flashchip.h       |    4 +-
40  6 files changed, 201 insertions(+), 203 deletions(-)
41
42 diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
43 index c93a8be..c9c3517 100644
44 --- a/drivers/mtd/chips/cfi_cmdset_0001.c
45 +++ b/drivers/mtd/chips/cfi_cmdset_0001.c
46 @@ -695,8 +695,7 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
47                                 /* those should be reset too since
48                                    they create memory references. */
49                                 init_waitqueue_head(&chip->wq);
50 -                               spin_lock_init(&chip->_spinlock);
51 -                               chip->mutex = &chip->_spinlock;
52 +                               mutex_init(&chip->mutex);
53                                 chip++;
54                         }
55                 }
56 @@ -742,9 +741,9 @@ static int chip_ready (struct map_info *map, struct flchip *chip, unsigned long
57                         if (chip->priv && map_word_andequal(map, status, status_PWS, status_PWS))
58                                 break;
59  
60 -                       spin_unlock(chip->mutex);
61 +                       mutex_unlock(&chip->mutex);
62                         cfi_udelay(1);
63 -                       spin_lock(chip->mutex);
64 +                       mutex_lock(&chip->mutex);
65                         /* Someone else might have been playing with it. */
66                         return -EAGAIN;
67                 }
68 @@ -791,9 +790,9 @@ static int chip_ready (struct map_info *map, struct flchip *chip, unsigned long
69                                 return -EIO;
70                         }
71  
72 -                       spin_unlock(chip->mutex);
73 +                       mutex_unlock(&chip->mutex);
74                         cfi_udelay(1);
75 -                       spin_lock(chip->mutex);
76 +                       mutex_lock(&chip->mutex);
77                         /* Nobody will touch it while it's in state FL_ERASE_SUSPENDING.
78                            So we can just loop here. */
79                 }
80 @@ -820,10 +819,10 @@ static int chip_ready (struct map_info *map, struct flchip *chip, unsigned long
81         sleep:
82                 set_current_state(TASK_UNINTERRUPTIBLE);
83                 add_wait_queue(&chip->wq, &wait);
84 -               spin_unlock(chip->mutex);
85 +               mutex_unlock(&chip->mutex);
86                 schedule();
87                 remove_wait_queue(&chip->wq, &wait);
88 -               spin_lock(chip->mutex);
89 +               mutex_lock(&chip->mutex);
90                 return -EAGAIN;
91         }
92  }
93 @@ -869,20 +868,20 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
94                          * it'll happily send us to sleep.  In any case, when
95                          * get_chip returns success we're clear to go ahead.
96                          */
97 -                       ret = spin_trylock(contender->mutex);
98 +                       ret = mutex_trylock(&contender->mutex);
99                         spin_unlock(&shared->lock);
100                         if (!ret)
101                                 goto retry;
102 -                       spin_unlock(chip->mutex);
103 +                       mutex_unlock(&chip->mutex);
104                         ret = chip_ready(map, contender, contender->start, mode);
105 -                       spin_lock(chip->mutex);
106 +                       mutex_lock(&chip->mutex);
107  
108                         if (ret == -EAGAIN) {
109 -                               spin_unlock(contender->mutex);
110 +                               mutex_unlock(&contender->mutex);
111                                 goto retry;
112                         }
113                         if (ret) {
114 -                               spin_unlock(contender->mutex);
115 +                               mutex_unlock(&contender->mutex);
116                                 return ret;
117                         }
118                         spin_lock(&shared->lock);
119 @@ -891,10 +890,10 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
120                          * in FL_SYNCING state. Put contender and retry. */
121                         if (chip->state == FL_SYNCING) {
122                                 put_chip(map, contender, contender->start);
123 -                               spin_unlock(contender->mutex);
124 +                               mutex_unlock(&contender->mutex);
125                                 goto retry;
126                         }
127 -                       spin_unlock(contender->mutex);
128 +                       mutex_unlock(&contender->mutex);
129                 }
130  
131                 /* Check if we already have suspended erase
132 @@ -904,10 +903,10 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
133                         spin_unlock(&shared->lock);
134                         set_current_state(TASK_UNINTERRUPTIBLE);
135                         add_wait_queue(&chip->wq, &wait);
136 -                       spin_unlock(chip->mutex);
137 +                       mutex_unlock(&chip->mutex);
138                         schedule();
139                         remove_wait_queue(&chip->wq, &wait);
140 -                       spin_lock(chip->mutex);
141 +                       mutex_lock(&chip->mutex);
142                         goto retry;
143                 }
144  
145 @@ -937,12 +936,12 @@ static void put_chip(struct map_info *map, struct flchip *chip, unsigned long ad
146                         if (shared->writing && shared->writing != chip) {
147                                 /* give back ownership to who we loaned it from */
148                                 struct flchip *loaner = shared->writing;
149 -                               spin_lock(loaner->mutex);
150 +                               mutex_lock(&loaner->mutex);
151                                 spin_unlock(&shared->lock);
152 -                               spin_unlock(chip->mutex);
153 +                               mutex_unlock(&chip->mutex);
154                                 put_chip(map, loaner, loaner->start);
155 -                               spin_lock(chip->mutex);
156 -                               spin_unlock(loaner->mutex);
157 +                               mutex_lock(&chip->mutex);
158 +                               mutex_unlock(&loaner->mutex);
159                                 wake_up(&chip->wq);
160                                 return;
161                         }
162 @@ -1112,7 +1111,7 @@ static int __xipram xip_wait_for_operation(
163                         (void) map_read(map, adr);
164                         xip_iprefetch();
165                         local_irq_enable();
166 -                       spin_unlock(chip->mutex);
167 +                       mutex_unlock(&chip->mutex);
168                         xip_iprefetch();
169                         cond_resched();
170  
171 @@ -1122,15 +1121,15 @@ static int __xipram xip_wait_for_operation(
172                          * a suspended erase state.  If so let's wait
173                          * until it's done.
174                          */
175 -                       spin_lock(chip->mutex);
176 +                       mutex_lock(&chip->mutex);
177                         while (chip->state != newstate) {
178                                 DECLARE_WAITQUEUE(wait, current);
179                                 set_current_state(TASK_UNINTERRUPTIBLE);
180                                 add_wait_queue(&chip->wq, &wait);
181 -                               spin_unlock(chip->mutex);
182 +                               mutex_unlock(&chip->mutex);
183                                 schedule();
184                                 remove_wait_queue(&chip->wq, &wait);
185 -                               spin_lock(chip->mutex);
186 +                               mutex_lock(&chip->mutex);
187                         }
188                         /* Disallow XIP again */
189                         local_irq_disable();
190 @@ -1186,10 +1185,10 @@ static int inval_cache_and_wait_for_operation(
191         int chip_state = chip->state;
192         unsigned int timeo, sleep_time, reset_timeo;
193  
194 -       spin_unlock(chip->mutex);
195 +       mutex_unlock(&chip->mutex);
196         if (inval_len)
197                 INVALIDATE_CACHED_RANGE(map, inval_adr, inval_len);
198 -       spin_lock(chip->mutex);
199 +       mutex_lock(&chip->mutex);
200  
201         timeo = chip_op_time_max;
202         if (!timeo)
203 @@ -1209,7 +1208,7 @@ static int inval_cache_and_wait_for_operation(
204                 }
205  
206                 /* OK Still waiting. Drop the lock, wait a while and retry. */
207 -               spin_unlock(chip->mutex);
208 +               mutex_unlock(&chip->mutex);
209                 if (sleep_time >= 1000000/HZ) {
210                         /*
211                          * Half of the normal delay still remaining
212 @@ -1224,17 +1223,17 @@ static int inval_cache_and_wait_for_operation(
213                         cond_resched();
214                         timeo--;
215                 }
216 -               spin_lock(chip->mutex);
217 +               mutex_lock(&chip->mutex);
218  
219                 while (chip->state != chip_state) {
220                         /* Someone's suspended the operation: sleep */
221                         DECLARE_WAITQUEUE(wait, current);
222                         set_current_state(TASK_UNINTERRUPTIBLE);
223                         add_wait_queue(&chip->wq, &wait);
224 -                       spin_unlock(chip->mutex);
225 +                       mutex_unlock(&chip->mutex);
226                         schedule();
227                         remove_wait_queue(&chip->wq, &wait);
228 -                       spin_lock(chip->mutex);
229 +                       mutex_lock(&chip->mutex);
230                 }
231                 if (chip->erase_suspended || chip->write_suspended)  {
232                         /* Suspend has occured while sleep: reset timeout */
233 @@ -1266,7 +1265,7 @@ static int do_point_onechip (struct map_info *map, struct flchip *chip, loff_t a
234         /* Ensure cmd read/writes are aligned. */
235         cmd_addr = adr & ~(map_bankwidth(map)-1);
236  
237 -       spin_lock(chip->mutex);
238 +       mutex_lock(&chip->mutex);
239  
240         ret = get_chip(map, chip, cmd_addr, FL_POINT);
241  
242 @@ -1277,7 +1276,7 @@ static int do_point_onechip (struct map_info *map, struct flchip *chip, loff_t a
243                 chip->state = FL_POINT;
244                 chip->ref_point_counter++;
245         }
246 -       spin_unlock(chip->mutex);
247 +       mutex_unlock(&chip->mutex);
248  
249         return ret;
250  }
251 @@ -1362,7 +1361,7 @@ static void cfi_intelext_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
252                 else
253                         thislen = len;
254  
255 -               spin_lock(chip->mutex);
256 +               mutex_lock(&chip->mutex);
257                 if (chip->state == FL_POINT) {
258                         chip->ref_point_counter--;
259                         if(chip->ref_point_counter == 0)
260 @@ -1371,7 +1370,7 @@ static void cfi_intelext_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
261                         printk(KERN_ERR "%s: Warning: unpoint called on non pointed region\n", map->name); /* Should this give an error? */
262  
263                 put_chip(map, chip, chip->start);
264 -               spin_unlock(chip->mutex);
265 +               mutex_unlock(&chip->mutex);
266  
267                 len -= thislen;
268                 ofs = 0;
269 @@ -1390,10 +1389,10 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
270         /* Ensure cmd read/writes are aligned. */
271         cmd_addr = adr & ~(map_bankwidth(map)-1);
272  
273 -       spin_lock(chip->mutex);
274 +       mutex_lock(&chip->mutex);
275         ret = get_chip(map, chip, cmd_addr, FL_READY);
276         if (ret) {
277 -               spin_unlock(chip->mutex);
278 +               mutex_unlock(&chip->mutex);
279                 return ret;
280         }
281  
282 @@ -1407,7 +1406,7 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
283  
284         put_chip(map, chip, cmd_addr);
285  
286 -       spin_unlock(chip->mutex);
287 +       mutex_unlock(&chip->mutex);
288         return 0;
289  }
290  
291 @@ -1470,10 +1469,10 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
292                 return -EINVAL;
293         }
294  
295 -       spin_lock(chip->mutex);
296 +       mutex_lock(&chip->mutex);
297         ret = get_chip(map, chip, adr, mode);
298         if (ret) {
299 -               spin_unlock(chip->mutex);
300 +               mutex_unlock(&chip->mutex);
301                 return ret;
302         }
303  
304 @@ -1519,7 +1518,7 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
305  
306         xip_enable(map, chip, adr);
307   out:  put_chip(map, chip, adr);
308 -       spin_unlock(chip->mutex);
309 +       mutex_unlock(&chip->mutex);
310         return ret;
311  }
312  
313 @@ -1628,10 +1627,10 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
314         /* Let's determine this according to the interleave only once */
315         write_cmd = (cfi->cfiq->P_ID != 0x0200) ? CMD(0xe8) : CMD(0xe9);
316  
317 -       spin_lock(chip->mutex);
318 +       mutex_lock(&chip->mutex);
319         ret = get_chip(map, chip, cmd_adr, FL_WRITING);
320         if (ret) {
321 -               spin_unlock(chip->mutex);
322 +               mutex_unlock(&chip->mutex);
323                 return ret;
324         }
325  
326 @@ -1762,7 +1761,7 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
327  
328         xip_enable(map, chip, cmd_adr);
329   out:  put_chip(map, chip, cmd_adr);
330 -       spin_unlock(chip->mutex);
331 +       mutex_unlock(&chip->mutex);
332         return ret;
333  }
334  
335 @@ -1841,10 +1840,10 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
336         adr += chip->start;
337  
338   retry:
339 -       spin_lock(chip->mutex);
340 +       mutex_lock(&chip->mutex);
341         ret = get_chip(map, chip, adr, FL_ERASING);
342         if (ret) {
343 -               spin_unlock(chip->mutex);
344 +               mutex_unlock(&chip->mutex);
345                 return ret;
346         }
347  
348 @@ -1900,7 +1899,7 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
349                 } else if (chipstatus & 0x20 && retries--) {
350                         printk(KERN_DEBUG "block erase failed at 0x%08lx: status 0x%lx. Retrying...\n", adr, chipstatus);
351                         put_chip(map, chip, adr);
352 -                       spin_unlock(chip->mutex);
353 +                       mutex_unlock(&chip->mutex);
354                         goto retry;
355                 } else {
356                         printk(KERN_ERR "%s: block erase failed at 0x%08lx (status 0x%lx)\n", map->name, adr, chipstatus);
357 @@ -1912,7 +1911,7 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
358  
359         xip_enable(map, chip, adr);
360   out:  put_chip(map, chip, adr);
361 -       spin_unlock(chip->mutex);
362 +       mutex_unlock(&chip->mutex);
363         return ret;
364  }
365  
366 @@ -1945,7 +1944,7 @@ static void cfi_intelext_sync (struct mtd_info *mtd)
367         for (i=0; !ret && i<cfi->numchips; i++) {
368                 chip = &cfi->chips[i];
369  
370 -               spin_lock(chip->mutex);
371 +               mutex_lock(&chip->mutex);
372                 ret = get_chip(map, chip, chip->start, FL_SYNCING);
373  
374                 if (!ret) {
375 @@ -1956,7 +1955,7 @@ static void cfi_intelext_sync (struct mtd_info *mtd)
376                          * with the chip now anyway.
377                          */
378                 }
379 -               spin_unlock(chip->mutex);
380 +               mutex_unlock(&chip->mutex);
381         }
382  
383         /* Unlock the chips again */
384 @@ -1964,14 +1963,14 @@ static void cfi_intelext_sync (struct mtd_info *mtd)
385         for (i--; i >=0; i--) {
386                 chip = &cfi->chips[i];
387  
388 -               spin_lock(chip->mutex);
389 +               mutex_lock(&chip->mutex);
390  
391                 if (chip->state == FL_SYNCING) {
392                         chip->state = chip->oldstate;
393                         chip->oldstate = FL_READY;
394                         wake_up(&chip->wq);
395                 }
396 -               spin_unlock(chip->mutex);
397 +               mutex_unlock(&chip->mutex);
398         }
399  }
400  
401 @@ -2017,10 +2016,10 @@ static int __xipram do_xxlock_oneblock(struct map_info *map, struct flchip *chip
402  
403         adr += chip->start;
404  
405 -       spin_lock(chip->mutex);
406 +       mutex_lock(&chip->mutex);
407         ret = get_chip(map, chip, adr, FL_LOCKING);
408         if (ret) {
409 -               spin_unlock(chip->mutex);
410 +               mutex_unlock(&chip->mutex);
411                 return ret;
412         }
413  
414 @@ -2054,7 +2053,7 @@ static int __xipram do_xxlock_oneblock(struct map_info *map, struct flchip *chip
415  
416         xip_enable(map, chip, adr);
417  out:   put_chip(map, chip, adr);
418 -       spin_unlock(chip->mutex);
419 +       mutex_unlock(&chip->mutex);
420         return ret;
421  }
422  
423 @@ -2119,10 +2118,10 @@ do_otp_read(struct map_info *map, struct flchip *chip, u_long offset,
424         struct cfi_private *cfi = map->fldrv_priv;
425         int ret;
426  
427 -       spin_lock(chip->mutex);
428 +       mutex_lock(&chip->mutex);
429         ret = get_chip(map, chip, chip->start, FL_JEDEC_QUERY);
430         if (ret) {
431 -               spin_unlock(chip->mutex);
432 +               mutex_unlock(&chip->mutex);
433                 return ret;
434         }
435  
436 @@ -2141,7 +2140,7 @@ do_otp_read(struct map_info *map, struct flchip *chip, u_long offset,
437         INVALIDATE_CACHED_RANGE(map, chip->start + offset, size);
438  
439         put_chip(map, chip, chip->start);
440 -       spin_unlock(chip->mutex);
441 +       mutex_unlock(&chip->mutex);
442         return 0;
443  }
444  
445 @@ -2416,7 +2415,7 @@ static int cfi_intelext_suspend(struct mtd_info *mtd)
446         for (i=0; !ret && i<cfi->numchips; i++) {
447                 chip = &cfi->chips[i];
448  
449 -               spin_lock(chip->mutex);
450 +               mutex_lock(&chip->mutex);
451  
452                 switch (chip->state) {
453                 case FL_READY:
454 @@ -2448,7 +2447,7 @@ static int cfi_intelext_suspend(struct mtd_info *mtd)
455                 case FL_PM_SUSPENDED:
456                         break;
457                 }
458 -               spin_unlock(chip->mutex);
459 +               mutex_unlock(&chip->mutex);
460         }
461  
462         /* Unlock the chips again */
463 @@ -2457,7 +2456,7 @@ static int cfi_intelext_suspend(struct mtd_info *mtd)
464                 for (i--; i >=0; i--) {
465                         chip = &cfi->chips[i];
466  
467 -                       spin_lock(chip->mutex);
468 +                       mutex_lock(&chip->mutex);
469  
470                         if (chip->state == FL_PM_SUSPENDED) {
471                                 /* No need to force it into a known state here,
472 @@ -2467,7 +2466,7 @@ static int cfi_intelext_suspend(struct mtd_info *mtd)
473                                 chip->oldstate = FL_READY;
474                                 wake_up(&chip->wq);
475                         }
476 -                       spin_unlock(chip->mutex);
477 +                       mutex_unlock(&chip->mutex);
478                 }
479         }
480  
481 @@ -2508,7 +2507,7 @@ static void cfi_intelext_resume(struct mtd_info *mtd)
482  
483                 chip = &cfi->chips[i];
484  
485 -               spin_lock(chip->mutex);
486 +               mutex_lock(&chip->mutex);
487  
488                 /* Go to known state. Chip may have been power cycled */
489                 if (chip->state == FL_PM_SUSPENDED) {
490 @@ -2517,7 +2516,7 @@ static void cfi_intelext_resume(struct mtd_info *mtd)
491                         wake_up(&chip->wq);
492                 }
493  
494 -               spin_unlock(chip->mutex);
495 +               mutex_unlock(&chip->mutex);
496         }
497  
498         if ((mtd->flags & MTD_POWERUP_LOCK)
499 @@ -2537,13 +2536,13 @@ static int cfi_intelext_reset(struct mtd_info *mtd)
500                 /* force the completion of any ongoing operation
501                    and switch to array mode so any bootloader in
502                    flash is accessible for soft reboot. */
503 -               spin_lock(chip->mutex);
504 +               mutex_lock(&chip->mutex);
505                 ret = get_chip(map, chip, chip->start, FL_SHUTDOWN);
506                 if (!ret) {
507                         map_write(map, CMD(0xff), chip->start);
508                         chip->state = FL_SHUTDOWN;
509                 }
510 -               spin_unlock(chip->mutex);
511 +               mutex_unlock(&chip->mutex);
512         }
513  
514         return 0;
515 diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
516 index d74ec46..090c394 100644
517 --- a/drivers/mtd/chips/cfi_cmdset_0002.c
518 +++ b/drivers/mtd/chips/cfi_cmdset_0002.c
519 @@ -563,12 +563,12 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
520  
521                         if (time_after(jiffies, timeo)) {
522                                 printk(KERN_ERR "Waiting for chip to be ready timed out.\n");
523 -                               spin_unlock(chip->mutex);
524 +                               mutex_unlock(chip->mutex);
525                                 return -EIO;
526                         }
527 -                       spin_unlock(chip->mutex);
528 +                       mutex_unlock(&chip->mutex);
529                         cfi_udelay(1);
530 -                       spin_lock(chip->mutex);
531 +                       mutex_lock(&chip->mutex);
532                         /* Someone else might have been playing with it. */
533                         goto retry;
534                 }
535 @@ -618,9 +618,9 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
536                                 return -EIO;
537                         }
538  
539 -                       spin_unlock(chip->mutex);
540 +                       mutex_unlock(&chip->mutex);
541                         cfi_udelay(1);
542 -                       spin_lock(chip->mutex);
543 +                       mutex_lock(&chip->mutex);
544                         /* Nobody will touch it while it's in state FL_ERASE_SUSPENDING.
545                            So we can just loop here. */
546                 }
547 @@ -644,10 +644,10 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
548         sleep:
549                 set_current_state(TASK_UNINTERRUPTIBLE);
550                 add_wait_queue(&chip->wq, &wait);
551 -               spin_unlock(chip->mutex);
552 +               mutex_unlock(&chip->mutex);
553                 schedule();
554                 remove_wait_queue(&chip->wq, &wait);
555 -               spin_lock(chip->mutex);
556 +               mutex_lock(&chip->mutex);
557                 goto resettime;
558         }
559  }
560 @@ -779,7 +779,7 @@ static void __xipram xip_udelay(struct map_info *map, struct flchip *chip,
561                         (void) map_read(map, adr);
562                         xip_iprefetch();
563                         local_irq_enable();
564 -                       spin_unlock(chip->mutex);
565 +                       mutex_unlock(&chip->mutex);
566                         xip_iprefetch();
567                         cond_resched();
568  
569 @@ -789,15 +789,15 @@ static void __xipram xip_udelay(struct map_info *map, struct flchip *chip,
570                          * a suspended erase state.  If so let's wait
571                          * until it's done.
572                          */
573 -                       spin_lock(chip->mutex);
574 +                       mutex_lock(&chip->mutex);
575                         while (chip->state != FL_XIP_WHILE_ERASING) {
576                                 DECLARE_WAITQUEUE(wait, current);
577                                 set_current_state(TASK_UNINTERRUPTIBLE);
578                                 add_wait_queue(&chip->wq, &wait);
579 -                               spin_unlock(chip->mutex);
580 +                               mutex_unlock(&chip->mutex);
581                                 schedule();
582                                 remove_wait_queue(&chip->wq, &wait);
583 -                               spin_lock(chip->mutex);
584 +                               mutex_lock(&chip->mutex);
585                         }
586                         /* Disallow XIP again */
587                         local_irq_disable();
588 @@ -859,17 +859,17 @@ static void __xipram xip_udelay(struct map_info *map, struct flchip *chip,
589  
590  #define UDELAY(map, chip, adr, usec)  \
591  do {  \
592 -       spin_unlock(chip->mutex);  \
593 +       mutex_unlock(&chip->mutex);  \
594         cfi_udelay(usec);  \
595 -       spin_lock(chip->mutex);  \
596 +       mutex_lock(&chip->mutex);  \
597  } while (0)
598  
599  #define INVALIDATE_CACHE_UDELAY(map, chip, adr, len, usec)  \
600  do {  \
601 -       spin_unlock(chip->mutex);  \
602 +       mutex_unlock(&chip->mutex);  \
603         INVALIDATE_CACHED_RANGE(map, adr, len);  \
604         cfi_udelay(usec);  \
605 -       spin_lock(chip->mutex);  \
606 +       mutex_lock(&chip->mutex);  \
607  } while (0)
608  
609  #endif
610 @@ -885,10 +885,10 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
611         /* Ensure cmd read/writes are aligned. */
612         cmd_addr = adr & ~(map_bankwidth(map)-1);
613  
614 -       spin_lock(chip->mutex);
615 +       mutex_lock(&chip->mutex);
616         ret = get_chip(map, chip, cmd_addr, FL_READY);
617         if (ret) {
618 -               spin_unlock(chip->mutex);
619 +               mutex_unlock(&chip->mutex);
620                 return ret;
621         }
622  
623 @@ -901,7 +901,7 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
624  
625         put_chip(map, chip, cmd_addr);
626  
627 -       spin_unlock(chip->mutex);
628 +       mutex_unlock(&chip->mutex);
629         return 0;
630  }
631  
632 @@ -955,7 +955,7 @@ static inline int do_read_secsi_onechip(struct map_info *map, struct flchip *chi
633         struct cfi_private *cfi = map->fldrv_priv;
634  
635   retry:
636 -       spin_lock(chip->mutex);
637 +       mutex_lock(&chip->mutex);
638  
639         if (chip->state != FL_READY){
640  #if 0
641 @@ -964,7 +964,7 @@ static inline int do_read_secsi_onechip(struct map_info *map, struct flchip *chi
642                 set_current_state(TASK_UNINTERRUPTIBLE);
643                 add_wait_queue(&chip->wq, &wait);
644  
645 -               spin_unlock(chip->mutex);
646 +               mutex_unlock(&chip->mutex);
647  
648                 schedule();
649                 remove_wait_queue(&chip->wq, &wait);
650 @@ -993,7 +993,7 @@ static inline int do_read_secsi_onechip(struct map_info *map, struct flchip *chi
651         cfi_send_gen_cmd(0x00, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
652  
653         wake_up(&chip->wq);
654 -       spin_unlock(chip->mutex);
655 +       mutex_unlock(&chip->mutex);
656  
657         return 0;
658  }
659 @@ -1062,10 +1062,10 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
660  
661         adr += chip->start;
662  
663 -       spin_lock(chip->mutex);
664 +       mutex_lock(&chip->mutex);
665         ret = get_chip(map, chip, adr, FL_WRITING);
666         if (ret) {
667 -               spin_unlock(chip->mutex);
668 +               mutex_unlock(&chip->mutex);
669                 return ret;
670         }
671  
672 @@ -1108,11 +1108,11 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
673  
674                         set_current_state(TASK_UNINTERRUPTIBLE);
675                         add_wait_queue(&chip->wq, &wait);
676 -                       spin_unlock(chip->mutex);
677 +                       mutex_unlock(&chip->mutex);
678                         schedule();
679                         remove_wait_queue(&chip->wq, &wait);
680                         timeo = jiffies + (HZ / 2); /* FIXME */
681 -                       spin_lock(chip->mutex);
682 +                       mutex_lock(&chip->mutex);
683                         continue;
684                 }
685  
686 @@ -1144,7 +1144,7 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
687   op_done:
688         chip->state = FL_READY;
689         put_chip(map, chip, adr);
690 -       spin_unlock(chip->mutex);
691 +       mutex_unlock(&chip->mutex);
692  
693         return ret;
694  }
695 @@ -1176,7 +1176,7 @@ static int cfi_amdstd_write_words(struct mtd_info *mtd, loff_t to, size_t len,
696                 map_word tmp_buf;
697  
698   retry:
699 -               spin_lock(cfi->chips[chipnum].mutex);
700 +               mutex_lock(&cfi->chips[chipnum].mutex);
701  
702                 if (cfi->chips[chipnum].state != FL_READY) {
703  #if 0
704 @@ -1185,7 +1185,7 @@ static int cfi_amdstd_write_words(struct mtd_info *mtd, loff_t to, size_t len,
705                         set_current_state(TASK_UNINTERRUPTIBLE);
706                         add_wait_queue(&cfi->chips[chipnum].wq, &wait);
707  
708 -                       spin_unlock(cfi->chips[chipnum].mutex);
709 +                       mutex_unlock(&cfi->chips[chipnum].mutex);
710  
711                         schedule();
712                         remove_wait_queue(&cfi->chips[chipnum].wq, &wait);
713 @@ -1199,7 +1199,7 @@ static int cfi_amdstd_write_words(struct mtd_info *mtd, loff_t to, size_t len,
714                 /* Load 'tmp_buf' with old contents of flash */
715                 tmp_buf = map_read(map, bus_ofs+chipstart);
716  
717 -               spin_unlock(cfi->chips[chipnum].mutex);
718 +               mutex_unlock(&cfi->chips[chipnum].mutex);
719  
720                 /* Number of bytes to copy from buffer */
721                 n = min_t(int, len, map_bankwidth(map)-i);
722 @@ -1254,7 +1254,7 @@ static int cfi_amdstd_write_words(struct mtd_info *mtd, loff_t to, size_t len,
723                 map_word tmp_buf;
724  
725   retry1:
726 -               spin_lock(cfi->chips[chipnum].mutex);
727 +               mutex_lock(&cfi->chips[chipnum].mutex);
728  
729                 if (cfi->chips[chipnum].state != FL_READY) {
730  #if 0
731 @@ -1263,7 +1263,7 @@ static int cfi_amdstd_write_words(struct mtd_info *mtd, loff_t to, size_t len,
732                         set_current_state(TASK_UNINTERRUPTIBLE);
733                         add_wait_queue(&cfi->chips[chipnum].wq, &wait);
734  
735 -                       spin_unlock(cfi->chips[chipnum].mutex);
736 +                       mutex_unlock(&cfi->chips[chipnum].mutex);
737  
738                         schedule();
739                         remove_wait_queue(&cfi->chips[chipnum].wq, &wait);
740 @@ -1276,7 +1276,7 @@ static int cfi_amdstd_write_words(struct mtd_info *mtd, loff_t to, size_t len,
741  
742                 tmp_buf = map_read(map, ofs + chipstart);
743  
744 -               spin_unlock(cfi->chips[chipnum].mutex);
745 +               mutex_unlock(&cfi->chips[chipnum].mutex);
746  
747                 tmp_buf = map_word_load_partial(map, tmp_buf, buf, 0, len);
748  
749 @@ -1311,10 +1311,10 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
750         adr += chip->start;
751         cmd_adr = adr;
752  
753 -       spin_lock(chip->mutex);
754 +       mutex_lock(&chip->mutex);
755         ret = get_chip(map, chip, adr, FL_WRITING);
756         if (ret) {
757 -               spin_unlock(chip->mutex);
758 +               mutex_unlock(&chip->mutex);
759                 return ret;
760         }
761  
762 @@ -1369,11 +1369,11 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
763  
764                         set_current_state(TASK_UNINTERRUPTIBLE);
765                         add_wait_queue(&chip->wq, &wait);
766 -                       spin_unlock(chip->mutex);
767 +                       mutex_unlock(&chip->mutex);
768                         schedule();
769                         remove_wait_queue(&chip->wq, &wait);
770                         timeo = jiffies + (HZ / 2); /* FIXME */
771 -                       spin_lock(chip->mutex);
772 +                       mutex_lock(&chip->mutex);
773                         continue;
774                 }
775  
776 @@ -1401,7 +1401,7 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
777   op_done:
778         chip->state = FL_READY;
779         put_chip(map, chip, adr);
780 -       spin_unlock(chip->mutex);
781 +       mutex_unlock(&chip->mutex);
782  
783         return ret;
784  }
785 @@ -1501,10 +1501,10 @@ static int __xipram do_erase_chip(struct map_info *map, struct flchip *chip)
786  
787         adr = cfi->addr_unlock1;
788  
789 -       spin_lock(chip->mutex);
790 +       mutex_lock(&chip->mutex);
791         ret = get_chip(map, chip, adr, FL_WRITING);
792         if (ret) {
793 -               spin_unlock(chip->mutex);
794 +               mutex_unlock(&chip->mutex);
795                 return ret;
796         }
797  
798 @@ -1537,10 +1537,10 @@ static int __xipram do_erase_chip(struct map_info *map, struct flchip *chip)
799                         /* Someone's suspended the erase. Sleep */
800                         set_current_state(TASK_UNINTERRUPTIBLE);
801                         add_wait_queue(&chip->wq, &wait);
802 -                       spin_unlock(chip->mutex);
803 +                       mutex_unlock(&chip->mutex);
804                         schedule();
805                         remove_wait_queue(&chip->wq, &wait);
806 -                       spin_lock(chip->mutex);
807 +                       mutex_lock(&chip->mutex);
808                         continue;
809                 }
810                 if (chip->erase_suspended) {
811 @@ -1574,7 +1574,7 @@ static int __xipram do_erase_chip(struct map_info *map, struct flchip *chip)
812         chip->state = FL_READY;
813         xip_enable(map, chip, adr);
814         put_chip(map, chip, adr);
815 -       spin_unlock(chip->mutex);
816 +       mutex_unlock(&chip->mutex);
817  
818         return ret;
819  }
820 @@ -1589,10 +1589,10 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
821  
822         adr += chip->start;
823  
824 -       spin_lock(chip->mutex);
825 +       mutex_lock(&chip->mutex);
826         ret = get_chip(map, chip, adr, FL_ERASING);
827         if (ret) {
828 -               spin_unlock(chip->mutex);
829 +               mutex_unlock(&chip->mutex);
830                 return ret;
831         }
832  
833 @@ -1625,10 +1625,10 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
834                         /* Someone's suspended the erase. Sleep */
835                         set_current_state(TASK_UNINTERRUPTIBLE);
836                         add_wait_queue(&chip->wq, &wait);
837 -                       spin_unlock(chip->mutex);
838 +                       mutex_unlock(&chip->mutex);
839                         schedule();
840                         remove_wait_queue(&chip->wq, &wait);
841 -                       spin_lock(chip->mutex);
842 +                       mutex_lock(&chip->mutex);
843                         continue;
844                 }
845                 if (chip->erase_suspended) {
846 @@ -1664,7 +1664,7 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
847  
848         chip->state = FL_READY;
849         put_chip(map, chip, adr);
850 -       spin_unlock(chip->mutex);
851 +       mutex_unlock(&chip->mutex);
852         return ret;
853  }
854  
855 @@ -1716,7 +1716,7 @@ static int do_atmel_lock(struct map_info *map, struct flchip *chip,
856         struct cfi_private *cfi = map->fldrv_priv;
857         int ret;
858  
859 -       spin_lock(chip->mutex);
860 +       mutex_lock(&chip->mutex);
861         ret = get_chip(map, chip, adr + chip->start, FL_LOCKING);
862         if (ret)
863                 goto out_unlock;
864 @@ -1742,7 +1742,7 @@ static int do_atmel_lock(struct map_info *map, struct flchip *chip,
865         ret = 0;
866  
867  out_unlock:
868 -       spin_unlock(chip->mutex);
869 +       mutex_unlock(&chip->mutex);
870         return ret;
871  }
872  
873 @@ -1752,7 +1752,7 @@ static int do_atmel_unlock(struct map_info *map, struct flchip *chip,
874         struct cfi_private *cfi = map->fldrv_priv;
875         int ret;
876  
877 -       spin_lock(chip->mutex);
878 +       mutex_lock(&chip->mutex);
879         ret = get_chip(map, chip, adr + chip->start, FL_UNLOCKING);
880         if (ret)
881                 goto out_unlock;
882 @@ -1770,7 +1770,7 @@ static int do_atmel_unlock(struct map_info *map, struct flchip *chip,
883         ret = 0;
884  
885  out_unlock:
886 -       spin_unlock(chip->mutex);
887 +       mutex_unlock(&chip->mutex);
888         return ret;
889  }
890  
891 @@ -1798,7 +1798,7 @@ static void cfi_amdstd_sync (struct mtd_info *mtd)
892                 chip = &cfi->chips[i];
893  
894         retry:
895 -               spin_lock(chip->mutex);
896 +               mutex_lock(&chip->mutex);
897  
898                 switch(chip->state) {
899                 case FL_READY:
900 @@ -1812,7 +1812,7 @@ static void cfi_amdstd_sync (struct mtd_info *mtd)
901                          * with the chip now anyway.
902                          */
903                 case FL_SYNCING:
904 -                       spin_unlock(chip->mutex);
905 +                       mutex_unlock(&chip->mutex);
906                         break;
907  
908                 default:
909 @@ -1820,7 +1820,7 @@ static void cfi_amdstd_sync (struct mtd_info *mtd)
910                         set_current_state(TASK_UNINTERRUPTIBLE);
911                         add_wait_queue(&chip->wq, &wait);
912  
913 -                       spin_unlock(chip->mutex);
914 +                       mutex_unlock(&chip->mutex);
915  
916                         schedule();
917  
918 @@ -1835,13 +1835,13 @@ static void cfi_amdstd_sync (struct mtd_info *mtd)
919         for (i--; i >=0; i--) {
920                 chip = &cfi->chips[i];
921  
922 -               spin_lock(chip->mutex);
923 +               mutex_lock(&chip->mutex);
924  
925                 if (chip->state == FL_SYNCING) {
926                         chip->state = chip->oldstate;
927                         wake_up(&chip->wq);
928                 }
929 -               spin_unlock(chip->mutex);
930 +               mutex_unlock(&chip->mutex);
931         }
932  }
933  
934 @@ -1857,7 +1857,7 @@ static int cfi_amdstd_suspend(struct mtd_info *mtd)
935         for (i=0; !ret && i<cfi->numchips; i++) {
936                 chip = &cfi->chips[i];
937  
938 -               spin_lock(chip->mutex);
939 +               mutex_lock(&chip->mutex);
940  
941                 switch(chip->state) {
942                 case FL_READY:
943 @@ -1877,7 +1877,7 @@ static int cfi_amdstd_suspend(struct mtd_info *mtd)
944                         ret = -EAGAIN;
945                         break;
946                 }
947 -               spin_unlock(chip->mutex);
948 +               mutex_unlock(&chip->mutex);
949         }
950  
951         /* Unlock the chips again */
952 @@ -1886,13 +1886,13 @@ static int cfi_amdstd_suspend(struct mtd_info *mtd)
953                 for (i--; i >=0; i--) {
954                         chip = &cfi->chips[i];
955  
956 -                       spin_lock(chip->mutex);
957 +                       mutex_lock(&chip->mutex);
958  
959                         if (chip->state == FL_PM_SUSPENDED) {
960                                 chip->state = chip->oldstate;
961                                 wake_up(&chip->wq);
962                         }
963 -                       spin_unlock(chip->mutex);
964 +                       mutex_unlock(&chip->mutex);
965                 }
966         }
967  
968 @@ -1911,7 +1911,7 @@ static void cfi_amdstd_resume(struct mtd_info *mtd)
969  
970                 chip = &cfi->chips[i];
971  
972 -               spin_lock(chip->mutex);
973 +               mutex_lock(&chip->mutex);
974  
975                 if (chip->state == FL_PM_SUSPENDED) {
976                         chip->state = FL_READY;
977 @@ -1921,7 +1921,7 @@ static void cfi_amdstd_resume(struct mtd_info *mtd)
978                 else
979                         printk(KERN_ERR "Argh. Chip not in PM_SUSPENDED state upon resume()\n");
980  
981 -               spin_unlock(chip->mutex);
982 +               mutex_unlock(&chip->mutex);
983         }
984  }
985  
986 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
987 index d4714dd..0322c64 100644
988 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
989 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
990 @@ -265,7 +265,7 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
991  
992         timeo = jiffies + HZ;
993   retry:
994 -       spin_lock_bh(chip->mutex);
995 +       mutex_lock(&chip->mutex);
996  
997         /* Check that the chip's ready to talk to us.
998          * If it's in FL_ERASING state, suspend it and make it talk now.
999 @@ -296,15 +296,15 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
1000                                 /* make sure we're in 'read status' mode */
1001                                 map_write(map, CMD(0x70), cmd_addr);
1002                                 chip->state = FL_ERASING;
1003 -                               spin_unlock_bh(chip->mutex);
1004 +                               mutex_unlock(&chip->mutex);
1005                                 printk(KERN_ERR "Chip not ready after erase "
1006                                        "suspended: status = 0x%lx\n", status.x[0]);
1007                                 return -EIO;
1008                         }
1009  
1010 -                       spin_unlock_bh(chip->mutex);
1011 +                       mutex_unlock(&chip->mutex);
1012                         cfi_udelay(1);
1013 -                       spin_lock_bh(chip->mutex);
1014 +                       mutex_lock(&chip->mutex);
1015                 }
1016  
1017                 suspended = 1;
1018 @@ -335,13 +335,13 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
1019  
1020                 /* Urgh. Chip not yet ready to talk to us. */
1021                 if (time_after(jiffies, timeo)) {
1022 -                       spin_unlock_bh(chip->mutex);
1023 +                       mutex_unlock(&chip->mutex);
1024                         printk(KERN_ERR "waiting for chip to be ready timed out in read. WSM status = %lx\n", status.x[0]);
1025                         return -EIO;
1026                 }
1027  
1028                 /* Latency issues. Drop the lock, wait a while and retry */
1029 -               spin_unlock_bh(chip->mutex);
1030 +               mutex_unlock(&chip->mutex);
1031                 cfi_udelay(1);
1032                 goto retry;
1033  
1034 @@ -351,7 +351,7 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
1035                    someone changes the status */
1036                 set_current_state(TASK_UNINTERRUPTIBLE);
1037                 add_wait_queue(&chip->wq, &wait);
1038 -               spin_unlock_bh(chip->mutex);
1039 +               mutex_unlock(&chip->mutex);
1040                 schedule();
1041                 remove_wait_queue(&chip->wq, &wait);
1042                 timeo = jiffies + HZ;
1043 @@ -376,7 +376,7 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
1044         }
1045  
1046         wake_up(&chip->wq);
1047 -       spin_unlock_bh(chip->mutex);
1048 +       mutex_unlock(&chip->mutex);
1049         return 0;
1050  }
1051  
1052 @@ -445,7 +445,7 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
1053  #ifdef DEBUG_CFI_FEATURES
1054         printk("%s: chip->state[%d]\n", __func__, chip->state);
1055  #endif
1056 -       spin_lock_bh(chip->mutex);
1057 +       mutex_lock(&chip->mutex);
1058  
1059         /* Check that the chip's ready to talk to us.
1060          * Later, we can actually think about interrupting it
1061 @@ -470,14 +470,14 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
1062                         break;
1063                 /* Urgh. Chip not yet ready to talk to us. */
1064                 if (time_after(jiffies, timeo)) {
1065 -                       spin_unlock_bh(chip->mutex);
1066 +                       mutex_unlock(&chip->mutex);
1067                          printk(KERN_ERR "waiting for chip to be ready timed out in buffer write Xstatus = %lx, status = %lx\n",
1068                                 status.x[0], map_read(map, cmd_adr).x[0]);
1069                         return -EIO;
1070                 }
1071  
1072                 /* Latency issues. Drop the lock, wait a while and retry */
1073 -               spin_unlock_bh(chip->mutex);
1074 +               mutex_unlock(&chip->mutex);
1075                 cfi_udelay(1);
1076                 goto retry;
1077  
1078 @@ -486,7 +486,7 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
1079                    someone changes the status */
1080                 set_current_state(TASK_UNINTERRUPTIBLE);
1081                 add_wait_queue(&chip->wq, &wait);
1082 -               spin_unlock_bh(chip->mutex);
1083 +               mutex_unlock(&chip->mutex);
1084                 schedule();
1085                 remove_wait_queue(&chip->wq, &wait);
1086                 timeo = jiffies + HZ;
1087 @@ -503,16 +503,16 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
1088                 if (map_word_andequal(map, status, status_OK, status_OK))
1089                         break;
1090  
1091 -               spin_unlock_bh(chip->mutex);
1092 +               mutex_unlock(&chip->mutex);
1093                 cfi_udelay(1);
1094 -               spin_lock_bh(chip->mutex);
1095 +               mutex_lock(&chip->mutex);
1096  
1097                 if (++z > 100) {
1098                         /* Argh. Not ready for write to buffer */
1099                         DISABLE_VPP(map);
1100                          map_write(map, CMD(0x70), cmd_adr);
1101                         chip->state = FL_STATUS;
1102 -                       spin_unlock_bh(chip->mutex);
1103 +                       mutex_unlock(&chip->mutex);
1104                         printk(KERN_ERR "Chip not ready for buffer write. Xstatus = %lx\n", status.x[0]);
1105                         return -EIO;
1106                 }
1107 @@ -532,9 +532,9 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
1108         map_write(map, CMD(0xd0), cmd_adr);
1109         chip->state = FL_WRITING;
1110  
1111 -       spin_unlock_bh(chip->mutex);
1112 +       mutex_unlock(&chip->mutex);
1113         cfi_udelay(chip->buffer_write_time);
1114 -       spin_lock_bh(chip->mutex);
1115 +       mutex_lock(&chip->mutex);
1116  
1117         timeo = jiffies + (HZ/2);
1118         z = 0;
1119 @@ -543,11 +543,11 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
1120                         /* Someone's suspended the write. Sleep */
1121                         set_current_state(TASK_UNINTERRUPTIBLE);
1122                         add_wait_queue(&chip->wq, &wait);
1123 -                       spin_unlock_bh(chip->mutex);
1124 +                       mutex_unlock(&chip->mutex);
1125                         schedule();
1126                         remove_wait_queue(&chip->wq, &wait);
1127                         timeo = jiffies + (HZ / 2); /* FIXME */
1128 -                       spin_lock_bh(chip->mutex);
1129 +                       mutex_lock(&chip->mutex);
1130                         continue;
1131                 }
1132  
1133 @@ -563,16 +563,16 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
1134                          map_write(map, CMD(0x70), adr);
1135                         chip->state = FL_STATUS;
1136                         DISABLE_VPP(map);
1137 -                       spin_unlock_bh(chip->mutex);
1138 +                       mutex_unlock(&chip->mutex);
1139                         printk(KERN_ERR "waiting for chip to be ready timed out in bufwrite\n");
1140                         return -EIO;
1141                 }
1142  
1143                 /* Latency issues. Drop the lock, wait a while and retry */
1144 -               spin_unlock_bh(chip->mutex);
1145 +               mutex_unlock(&chip->mutex);
1146                 cfi_udelay(1);
1147                 z++;
1148 -               spin_lock_bh(chip->mutex);
1149 +               mutex_lock(&chip->mutex);
1150         }
1151         if (!z) {
1152                 chip->buffer_write_time--;
1153 @@ -596,11 +596,11 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
1154                 /* put back into read status register mode */
1155                 map_write(map, CMD(0x70), adr);
1156                 wake_up(&chip->wq);
1157 -               spin_unlock_bh(chip->mutex);
1158 +               mutex_unlock(&chip->mutex);
1159                 return map_word_bitsset(map, status, CMD(0x02)) ? -EROFS : -EIO;
1160         }
1161         wake_up(&chip->wq);
1162 -       spin_unlock_bh(chip->mutex);
1163 +       mutex_unlock(&chip->mutex);
1164  
1165          return 0;
1166  }
1167 @@ -749,7 +749,7 @@ static inline int do_erase_oneblock(struct map_info *map, struct flchip *chip, u
1168  
1169         timeo = jiffies + HZ;
1170  retry:
1171 -       spin_lock_bh(chip->mutex);
1172 +       mutex_lock(&chip->mutex);
1173  
1174         /* Check that the chip's ready to talk to us. */
1175         switch (chip->state) {
1176 @@ -766,13 +766,13 @@ retry:
1177  
1178                 /* Urgh. Chip not yet ready to talk to us. */
1179                 if (time_after(jiffies, timeo)) {
1180 -                       spin_unlock_bh(chip->mutex);
1181 +                       mutex_unlock(&chip->mutex);
1182                         printk(KERN_ERR "waiting for chip to be ready timed out in erase\n");
1183                         return -EIO;
1184                 }
1185  
1186                 /* Latency issues. Drop the lock, wait a while and retry */
1187 -               spin_unlock_bh(chip->mutex);
1188 +               mutex_unlock(&chip->mutex);
1189                 cfi_udelay(1);
1190                 goto retry;
1191  
1192 @@ -781,7 +781,7 @@ retry:
1193                    someone changes the status */
1194                 set_current_state(TASK_UNINTERRUPTIBLE);
1195                 add_wait_queue(&chip->wq, &wait);
1196 -               spin_unlock_bh(chip->mutex);
1197 +               mutex_unlock(&chip->mutex);
1198                 schedule();
1199                 remove_wait_queue(&chip->wq, &wait);
1200                 timeo = jiffies + HZ;
1201 @@ -797,9 +797,9 @@ retry:
1202         map_write(map, CMD(0xD0), adr);
1203         chip->state = FL_ERASING;
1204  
1205 -       spin_unlock_bh(chip->mutex);
1206 +       mutex_unlock(&chip->mutex);
1207         msleep(1000);
1208 -       spin_lock_bh(chip->mutex);
1209 +       mutex_lock(&chip->mutex);
1210  
1211         /* FIXME. Use a timer to check this, and return immediately. */
1212         /* Once the state machine's known to be working I'll do that */
1213 @@ -810,11 +810,11 @@ retry:
1214                         /* Someone's suspended the erase. Sleep */
1215                         set_current_state(TASK_UNINTERRUPTIBLE);
1216                         add_wait_queue(&chip->wq, &wait);
1217 -                       spin_unlock_bh(chip->mutex);
1218 +                       mutex_unlock(&chip->mutex);
1219                         schedule();
1220                         remove_wait_queue(&chip->wq, &wait);
1221                         timeo = jiffies + (HZ*20); /* FIXME */
1222 -                       spin_lock_bh(chip->mutex);
1223 +                       mutex_lock(&chip->mutex);
1224                         continue;
1225                 }
1226  
1227 @@ -828,14 +828,14 @@ retry:
1228                         chip->state = FL_STATUS;
1229                         printk(KERN_ERR "waiting for erase to complete timed out. Xstatus = %lx, status = %lx.\n", status.x[0], map_read(map, adr).x[0]);
1230                         DISABLE_VPP(map);
1231 -                       spin_unlock_bh(chip->mutex);
1232 +                       mutex_unlock(&chip->mutex);
1233                         return -EIO;
1234                 }
1235  
1236                 /* Latency issues. Drop the lock, wait a while and retry */
1237 -               spin_unlock_bh(chip->mutex);
1238 +               mutex_unlock(&chip->mutex);
1239                 cfi_udelay(1);
1240 -               spin_lock_bh(chip->mutex);
1241 +               mutex_lock(&chip->mutex);
1242         }
1243  
1244         DISABLE_VPP(map);
1245 @@ -878,7 +878,7 @@ retry:
1246                                 printk(KERN_DEBUG "Chip erase failed at 0x%08lx: status 0x%x. Retrying...\n", adr, chipstatus);
1247                                 timeo = jiffies + HZ;
1248                                 chip->state = FL_STATUS;
1249 -                               spin_unlock_bh(chip->mutex);
1250 +                               mutex_unlock(&chip->mutex);
1251                                 goto retry;
1252                         }
1253                         printk(KERN_DEBUG "Chip erase failed at 0x%08lx: status 0x%x\n", adr, chipstatus);
1254 @@ -887,7 +887,7 @@ retry:
1255         }
1256  
1257         wake_up(&chip->wq);
1258 -       spin_unlock_bh(chip->mutex);
1259 +       mutex_unlock(&chip->mutex);
1260         return ret;
1261  }
1262  
1263 @@ -995,7 +995,7 @@ static void cfi_staa_sync (struct mtd_info *mtd)
1264                 chip = &cfi->chips[i];
1265  
1266         retry:
1267 -               spin_lock_bh(chip->mutex);
1268 +               mutex_lock(&chip->mutex);
1269  
1270                 switch(chip->state) {
1271                 case FL_READY:
1272 @@ -1009,7 +1009,7 @@ static void cfi_staa_sync (struct mtd_info *mtd)
1273                          * with the chip now anyway.
1274                          */
1275                 case FL_SYNCING:
1276 -                       spin_unlock_bh(chip->mutex);
1277 +                       mutex_unlock(&chip->mutex);
1278                         break;
1279  
1280                 default:
1281 @@ -1017,7 +1017,7 @@ static void cfi_staa_sync (struct mtd_info *mtd)
1282                         set_current_state(TASK_UNINTERRUPTIBLE);
1283                         add_wait_queue(&chip->wq, &wait);
1284  
1285 -                       spin_unlock_bh(chip->mutex);
1286 +                       mutex_unlock(&chip->mutex);
1287                         schedule();
1288                         remove_wait_queue(&chip->wq, &wait);
1289  
1290 @@ -1030,13 +1030,13 @@ static void cfi_staa_sync (struct mtd_info *mtd)
1291         for (i--; i >=0; i--) {
1292                 chip = &cfi->chips[i];
1293  
1294 -               spin_lock_bh(chip->mutex);
1295 +               mutex_lock(&chip->mutex);
1296  
1297                 if (chip->state == FL_SYNCING) {
1298                         chip->state = chip->oldstate;
1299                         wake_up(&chip->wq);
1300                 }
1301 -               spin_unlock_bh(chip->mutex);
1302 +               mutex_unlock(&chip->mutex);
1303         }
1304  }
1305  
1306 @@ -1054,7 +1054,7 @@ static inline int do_lock_oneblock(struct map_info *map, struct flchip *chip, un
1307  
1308         timeo = jiffies + HZ;
1309  retry:
1310 -       spin_lock_bh(chip->mutex);
1311 +       mutex_lock(&chip->mutex);
1312  
1313         /* Check that the chip's ready to talk to us. */
1314         switch (chip->state) {
1315 @@ -1071,13 +1071,13 @@ retry:
1316  
1317                 /* Urgh. Chip not yet ready to talk to us. */
1318                 if (time_after(jiffies, timeo)) {
1319 -                       spin_unlock_bh(chip->mutex);
1320 +                       mutex_unlock(&chip->mutex);
1321                         printk(KERN_ERR "waiting for chip to be ready timed out in lock\n");
1322                         return -EIO;
1323                 }
1324  
1325                 /* Latency issues. Drop the lock, wait a while and retry */
1326 -               spin_unlock_bh(chip->mutex);
1327 +               mutex_unlock(&chip->mutex);
1328                 cfi_udelay(1);
1329                 goto retry;
1330  
1331 @@ -1086,7 +1086,7 @@ retry:
1332                    someone changes the status */
1333                 set_current_state(TASK_UNINTERRUPTIBLE);
1334                 add_wait_queue(&chip->wq, &wait);
1335 -               spin_unlock_bh(chip->mutex);
1336 +               mutex_unlock(&chip->mutex);
1337                 schedule();
1338                 remove_wait_queue(&chip->wq, &wait);
1339                 timeo = jiffies + HZ;
1340 @@ -1098,9 +1098,9 @@ retry:
1341         map_write(map, CMD(0x01), adr);
1342         chip->state = FL_LOCKING;
1343  
1344 -       spin_unlock_bh(chip->mutex);
1345 +       mutex_unlock(&chip->mutex);
1346         msleep(1000);
1347 -       spin_lock_bh(chip->mutex);
1348 +       mutex_lock(&chip->mutex);
1349  
1350         /* FIXME. Use a timer to check this, and return immediately. */
1351         /* Once the state machine's known to be working I'll do that */
1352 @@ -1118,21 +1118,21 @@ retry:
1353                         chip->state = FL_STATUS;
1354                         printk(KERN_ERR "waiting for lock to complete timed out. Xstatus = %lx, status = %lx.\n", status.x[0], map_read(map, adr).x[0]);
1355                         DISABLE_VPP(map);
1356 -                       spin_unlock_bh(chip->mutex);
1357 +                       mutex_unlock(&chip->mutex);
1358                         return -EIO;
1359                 }
1360  
1361                 /* Latency issues. Drop the lock, wait a while and retry */
1362 -               spin_unlock_bh(chip->mutex);
1363 +               mutex_unlock(&chip->mutex);
1364                 cfi_udelay(1);
1365 -               spin_lock_bh(chip->mutex);
1366 +               mutex_lock(&chip->mutex);
1367         }
1368  
1369         /* Done and happy. */
1370         chip->state = FL_STATUS;
1371         DISABLE_VPP(map);
1372         wake_up(&chip->wq);
1373 -       spin_unlock_bh(chip->mutex);
1374 +       mutex_unlock(&chip->mutex);
1375         return 0;
1376  }
1377  static int cfi_staa_lock(struct mtd_info *mtd, loff_t ofs, size_t len)
1378 @@ -1203,7 +1203,7 @@ static inline int do_unlock_oneblock(struct map_info *map, struct flchip *chip,
1379  
1380         timeo = jiffies + HZ;
1381  retry:
1382 -       spin_lock_bh(chip->mutex);
1383 +       mutex_lock(&chip->mutex);
1384  
1385         /* Check that the chip's ready to talk to us. */
1386         switch (chip->state) {
1387 @@ -1220,13 +1220,13 @@ retry:
1388  
1389                 /* Urgh. Chip not yet ready to talk to us. */
1390                 if (time_after(jiffies, timeo)) {
1391 -                       spin_unlock_bh(chip->mutex);
1392 +                       mutex_unlock(&chip->mutex);
1393                         printk(KERN_ERR "waiting for chip to be ready timed out in unlock\n");
1394                         return -EIO;
1395                 }
1396  
1397                 /* Latency issues. Drop the lock, wait a while and retry */
1398 -               spin_unlock_bh(chip->mutex);
1399 +               mutex_unlock(&chip->mutex);
1400                 cfi_udelay(1);
1401                 goto retry;
1402  
1403 @@ -1235,7 +1235,7 @@ retry:
1404                    someone changes the status */
1405                 set_current_state(TASK_UNINTERRUPTIBLE);
1406                 add_wait_queue(&chip->wq, &wait);
1407 -               spin_unlock_bh(chip->mutex);
1408 +               mutex_unlock(&chip->mutex);
1409                 schedule();
1410                 remove_wait_queue(&chip->wq, &wait);
1411                 timeo = jiffies + HZ;
1412 @@ -1247,9 +1247,9 @@ retry:
1413         map_write(map, CMD(0xD0), adr);
1414         chip->state = FL_UNLOCKING;
1415  
1416 -       spin_unlock_bh(chip->mutex);
1417 +       mutex_unlock(&chip->mutex);
1418         msleep(1000);
1419 -       spin_lock_bh(chip->mutex);
1420 +       mutex_lock(&chip->mutex);
1421  
1422         /* FIXME. Use a timer to check this, and return immediately. */
1423         /* Once the state machine's known to be working I'll do that */
1424 @@ -1267,21 +1267,21 @@ retry:
1425                         chip->state = FL_STATUS;
1426                         printk(KERN_ERR "waiting for unlock to complete timed out. Xstatus = %lx, status = %lx.\n", status.x[0], map_read(map, adr).x[0]);
1427                         DISABLE_VPP(map);
1428 -                       spin_unlock_bh(chip->mutex);
1429 +                       mutex_unlock(&chip->mutex);
1430                         return -EIO;
1431                 }
1432  
1433                 /* Latency issues. Drop the unlock, wait a while and retry */
1434 -               spin_unlock_bh(chip->mutex);
1435 +               mutex_unlock(&chip->mutex);
1436                 cfi_udelay(1);
1437 -               spin_lock_bh(chip->mutex);
1438 +               mutex_lock(&chip->mutex);
1439         }
1440  
1441         /* Done and happy. */
1442         chip->state = FL_STATUS;
1443         DISABLE_VPP(map);
1444         wake_up(&chip->wq);
1445 -       spin_unlock_bh(chip->mutex);
1446 +       mutex_unlock(&chip->mutex);
1447         return 0;
1448  }
1449  static int cfi_staa_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
1450 @@ -1334,7 +1334,7 @@ static int cfi_staa_suspend(struct mtd_info *mtd)
1451         for (i=0; !ret && i<cfi->numchips; i++) {
1452                 chip = &cfi->chips[i];
1453  
1454 -               spin_lock_bh(chip->mutex);
1455 +               mutex_lock(&chip->mutex);
1456  
1457                 switch(chip->state) {
1458                 case FL_READY:
1459 @@ -1354,7 +1354,7 @@ static int cfi_staa_suspend(struct mtd_info *mtd)
1460                         ret = -EAGAIN;
1461                         break;
1462                 }
1463 -               spin_unlock_bh(chip->mutex);
1464 +               mutex_unlock(&chip->mutex);
1465         }
1466  
1467         /* Unlock the chips again */
1468 @@ -1363,7 +1363,7 @@ static int cfi_staa_suspend(struct mtd_info *mtd)
1469                 for (i--; i >=0; i--) {
1470                         chip = &cfi->chips[i];
1471  
1472 -                       spin_lock_bh(chip->mutex);
1473 +                       mutex_lock(&chip->mutex);
1474  
1475                         if (chip->state == FL_PM_SUSPENDED) {
1476                                 /* No need to force it into a known state here,
1477 @@ -1372,7 +1372,7 @@ static int cfi_staa_suspend(struct mtd_info *mtd)
1478                                 chip->state = chip->oldstate;
1479                                 wake_up(&chip->wq);
1480                         }
1481 -                       spin_unlock_bh(chip->mutex);
1482 +                       mutex_unlock(&chip->mutex);
1483                 }
1484         }
1485  
1486 @@ -1390,7 +1390,7 @@ static void cfi_staa_resume(struct mtd_info *mtd)
1487  
1488                 chip = &cfi->chips[i];
1489  
1490 -               spin_lock_bh(chip->mutex);
1491 +               mutex_lock(&chip->mutex);
1492  
1493                 /* Go to known state. Chip may have been power cycled */
1494                 if (chip->state == FL_PM_SUSPENDED) {
1495 @@ -1399,7 +1399,7 @@ static void cfi_staa_resume(struct mtd_info *mtd)
1496                         wake_up(&chip->wq);
1497                 }
1498  
1499 -               spin_unlock_bh(chip->mutex);
1500 +               mutex_unlock(&chip->mutex);
1501         }
1502  }
1503  
1504 diff --git a/drivers/mtd/chips/fwh_lock.h b/drivers/mtd/chips/fwh_lock.h
1505 index ab44f2b..329906b 100644
1506 --- a/drivers/mtd/chips/fwh_lock.h
1507 +++ b/drivers/mtd/chips/fwh_lock.h
1508 @@ -58,10 +58,10 @@ static int fwh_xxlock_oneblock(struct map_info *map, struct flchip *chip,
1509          * to flash memory - that means that we don't have to check status
1510          * and timeout.
1511          */
1512 -       spin_lock(chip->mutex);
1513 +       mutex_lock(&chip->mutex);
1514         ret = get_chip(map, chip, adr, FL_LOCKING);
1515         if (ret) {
1516 -               spin_unlock(chip->mutex);
1517 +               mutex_unlock(&chip->mutex);
1518                 return ret;
1519         }
1520  
1521 @@ -72,7 +72,7 @@ static int fwh_xxlock_oneblock(struct map_info *map, struct flchip *chip,
1522         /* Done and happy. */
1523         chip->state = chip->oldstate;
1524         put_chip(map, chip, adr);
1525 -       spin_unlock(chip->mutex);
1526 +       mutex_unlock(&chip->mutex);
1527         return 0;
1528  }
1529  
1530 diff --git a/drivers/mtd/chips/gen_probe.c b/drivers/mtd/chips/gen_probe.c
1531 index e2dc964..fcc1bc0 100644
1532 --- a/drivers/mtd/chips/gen_probe.c
1533 +++ b/drivers/mtd/chips/gen_probe.c
1534 @@ -155,8 +155,7 @@ static struct cfi_private *genprobe_ident_chips(struct map_info *map, struct chi
1535                         pchip->start = (i << cfi.chipshift);
1536                         pchip->state = FL_READY;
1537                         init_waitqueue_head(&pchip->wq);
1538 -                       spin_lock_init(&pchip->_spinlock);
1539 -                       pchip->mutex = &pchip->_spinlock;
1540 +                       mutex_init(&pchip->mutex);
1541                 }
1542         }
1543  
1544 diff --git a/include/linux/mtd/flashchip.h b/include/linux/mtd/flashchip.h
1545 index d4f38c5..bfc2f1a 100644
1546 --- a/include/linux/mtd/flashchip.h
1547 +++ b/include/linux/mtd/flashchip.h
1548 @@ -15,6 +15,7 @@
1549   * has asm/spinlock.h, or 2.4, which has linux/spinlock.h
1550   */
1551  #include <linux/sched.h>
1552 +#include <linux/mutex.h>
1553  
1554  typedef enum {
1555         FL_READY,
1556 @@ -65,8 +66,7 @@ struct flchip {
1557         unsigned int erase_suspended:1;
1558         unsigned long in_progress_block_addr;
1559  
1560 -       spinlock_t *mutex;
1561 -       spinlock_t _spinlock; /* We do it like this because sometimes they'll be shared. */
1562 +       struct mutex mutex;
1563         wait_queue_head_t wq; /* Wait on here when we're waiting for the chip
1564                              to be ready */
1565         int word_write_time;
1566 -- 
1567 1.7.3.4
1568