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.
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.
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
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.
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.
23 There is no performance regression since the mutex is normally not
27 06.03.2010 First release
28 26.03.2010 Fix mutex[1] issue and tested it for compile failure
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>
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(-)
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);
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))
60 - spin_unlock(chip->mutex);
61 + mutex_unlock(&chip->mutex);
63 - spin_lock(chip->mutex);
64 + mutex_lock(&chip->mutex);
65 /* Someone else might have been playing with it. */
68 @@ -791,9 +790,9 @@ static int chip_ready (struct map_info *map, struct flchip *chip, unsigned long
72 - spin_unlock(chip->mutex);
73 + mutex_unlock(&chip->mutex);
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. */
80 @@ -820,10 +819,10 @@ static int chip_ready (struct map_info *map, struct flchip *chip, unsigned long
82 set_current_state(TASK_UNINTERRUPTIBLE);
83 add_wait_queue(&chip->wq, &wait);
84 - spin_unlock(chip->mutex);
85 + mutex_unlock(&chip->mutex);
87 remove_wait_queue(&chip->wq, &wait);
88 - spin_lock(chip->mutex);
89 + mutex_lock(&chip->mutex);
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.
97 - ret = spin_trylock(contender->mutex);
98 + ret = mutex_trylock(&contender->mutex);
99 spin_unlock(&shared->lock);
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);
108 if (ret == -EAGAIN) {
109 - spin_unlock(contender->mutex);
110 + mutex_unlock(&contender->mutex);
114 - spin_unlock(contender->mutex);
115 + mutex_unlock(&contender->mutex);
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);
127 - spin_unlock(contender->mutex);
128 + mutex_unlock(&contender->mutex);
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);
139 remove_wait_queue(&chip->wq, &wait);
140 - spin_lock(chip->mutex);
141 + mutex_lock(&chip->mutex);
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);
162 @@ -1112,7 +1111,7 @@ static int __xipram xip_wait_for_operation(
163 (void) map_read(map, adr);
166 - spin_unlock(chip->mutex);
167 + mutex_unlock(&chip->mutex);
171 @@ -1122,15 +1121,15 @@ static int __xipram xip_wait_for_operation(
172 * a suspended erase state. If so let's wait
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);
184 remove_wait_queue(&chip->wq, &wait);
185 - spin_lock(chip->mutex);
186 + mutex_lock(&chip->mutex);
188 /* Disallow XIP again */
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;
194 - spin_unlock(chip->mutex);
195 + mutex_unlock(&chip->mutex);
197 INVALIDATE_CACHED_RANGE(map, inval_adr, inval_len);
198 - spin_lock(chip->mutex);
199 + mutex_lock(&chip->mutex);
201 timeo = chip_op_time_max;
203 @@ -1209,7 +1208,7 @@ static int inval_cache_and_wait_for_operation(
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) {
211 * Half of the normal delay still remaining
212 @@ -1224,17 +1223,17 @@ static int inval_cache_and_wait_for_operation(
216 - spin_lock(chip->mutex);
217 + mutex_lock(&chip->mutex);
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);
227 remove_wait_queue(&chip->wq, &wait);
228 - spin_lock(chip->mutex);
229 + mutex_lock(&chip->mutex);
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);
237 - spin_lock(chip->mutex);
238 + mutex_lock(&chip->mutex);
240 ret = get_chip(map, chip, cmd_addr, FL_POINT);
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++;
246 - spin_unlock(chip->mutex);
247 + mutex_unlock(&chip->mutex);
251 @@ -1362,7 +1361,7 @@ static void cfi_intelext_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
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? */
263 put_chip(map, chip, chip->start);
264 - spin_unlock(chip->mutex);
265 + mutex_unlock(&chip->mutex);
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);
273 - spin_lock(chip->mutex);
274 + mutex_lock(&chip->mutex);
275 ret = get_chip(map, chip, cmd_addr, FL_READY);
277 - spin_unlock(chip->mutex);
278 + mutex_unlock(&chip->mutex);
282 @@ -1407,7 +1406,7 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
284 put_chip(map, chip, cmd_addr);
286 - spin_unlock(chip->mutex);
287 + mutex_unlock(&chip->mutex);
291 @@ -1470,10 +1469,10 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
295 - spin_lock(chip->mutex);
296 + mutex_lock(&chip->mutex);
297 ret = get_chip(map, chip, adr, mode);
299 - spin_unlock(chip->mutex);
300 + mutex_unlock(&chip->mutex);
304 @@ -1519,7 +1518,7 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
306 xip_enable(map, chip, adr);
307 out: put_chip(map, chip, adr);
308 - spin_unlock(chip->mutex);
309 + mutex_unlock(&chip->mutex);
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);
317 - spin_lock(chip->mutex);
318 + mutex_lock(&chip->mutex);
319 ret = get_chip(map, chip, cmd_adr, FL_WRITING);
321 - spin_unlock(chip->mutex);
322 + mutex_unlock(&chip->mutex);
326 @@ -1762,7 +1761,7 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
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);
335 @@ -1841,10 +1840,10 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
339 - spin_lock(chip->mutex);
340 + mutex_lock(&chip->mutex);
341 ret = get_chip(map, chip, adr, FL_ERASING);
343 - spin_unlock(chip->mutex);
344 + mutex_unlock(&chip->mutex);
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);
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,
359 xip_enable(map, chip, adr);
360 out: put_chip(map, chip, adr);
361 - spin_unlock(chip->mutex);
362 + mutex_unlock(&chip->mutex);
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];
370 - spin_lock(chip->mutex);
371 + mutex_lock(&chip->mutex);
372 ret = get_chip(map, chip, chip->start, FL_SYNCING);
375 @@ -1956,7 +1955,7 @@ static void cfi_intelext_sync (struct mtd_info *mtd)
376 * with the chip now anyway.
379 - spin_unlock(chip->mutex);
380 + mutex_unlock(&chip->mutex);
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];
388 - spin_lock(chip->mutex);
389 + mutex_lock(&chip->mutex);
391 if (chip->state == FL_SYNCING) {
392 chip->state = chip->oldstate;
393 chip->oldstate = FL_READY;
396 - spin_unlock(chip->mutex);
397 + mutex_unlock(&chip->mutex);
401 @@ -2017,10 +2016,10 @@ static int __xipram do_xxlock_oneblock(struct map_info *map, struct flchip *chip
405 - spin_lock(chip->mutex);
406 + mutex_lock(&chip->mutex);
407 ret = get_chip(map, chip, adr, FL_LOCKING);
409 - spin_unlock(chip->mutex);
410 + mutex_unlock(&chip->mutex);
414 @@ -2054,7 +2053,7 @@ static int __xipram do_xxlock_oneblock(struct map_info *map, struct flchip *chip
416 xip_enable(map, chip, adr);
417 out: put_chip(map, chip, adr);
418 - spin_unlock(chip->mutex);
419 + mutex_unlock(&chip->mutex);
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;
427 - spin_lock(chip->mutex);
428 + mutex_lock(&chip->mutex);
429 ret = get_chip(map, chip, chip->start, FL_JEDEC_QUERY);
431 - spin_unlock(chip->mutex);
432 + mutex_unlock(&chip->mutex);
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);
439 put_chip(map, chip, chip->start);
440 - spin_unlock(chip->mutex);
441 + mutex_unlock(&chip->mutex);
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];
449 - spin_lock(chip->mutex);
450 + mutex_lock(&chip->mutex);
452 switch (chip->state) {
454 @@ -2448,7 +2447,7 @@ static int cfi_intelext_suspend(struct mtd_info *mtd)
455 case FL_PM_SUSPENDED:
458 - spin_unlock(chip->mutex);
459 + mutex_unlock(&chip->mutex);
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];
467 - spin_lock(chip->mutex);
468 + mutex_lock(&chip->mutex);
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;
476 - spin_unlock(chip->mutex);
477 + mutex_unlock(&chip->mutex);
481 @@ -2508,7 +2507,7 @@ static void cfi_intelext_resume(struct mtd_info *mtd)
483 chip = &cfi->chips[i];
485 - spin_lock(chip->mutex);
486 + mutex_lock(&chip->mutex);
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)
494 - spin_unlock(chip->mutex);
495 + mutex_unlock(&chip->mutex);
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);
507 map_write(map, CMD(0xff), chip->start);
508 chip->state = FL_SHUTDOWN;
510 - spin_unlock(chip->mutex);
511 + mutex_unlock(&chip->mutex);
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
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);
527 - spin_unlock(chip->mutex);
528 + mutex_unlock(&chip->mutex);
530 - spin_lock(chip->mutex);
531 + mutex_lock(&chip->mutex);
532 /* Someone else might have been playing with it. */
535 @@ -618,9 +618,9 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
539 - spin_unlock(chip->mutex);
540 + mutex_unlock(&chip->mutex);
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. */
547 @@ -644,10 +644,10 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
549 set_current_state(TASK_UNINTERRUPTIBLE);
550 add_wait_queue(&chip->wq, &wait);
551 - spin_unlock(chip->mutex);
552 + mutex_unlock(&chip->mutex);
554 remove_wait_queue(&chip->wq, &wait);
555 - spin_lock(chip->mutex);
556 + mutex_lock(&chip->mutex);
560 @@ -779,7 +779,7 @@ static void __xipram xip_udelay(struct map_info *map, struct flchip *chip,
561 (void) map_read(map, adr);
564 - spin_unlock(chip->mutex);
565 + mutex_unlock(&chip->mutex);
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
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);
582 remove_wait_queue(&chip->wq, &wait);
583 - spin_lock(chip->mutex);
584 + mutex_lock(&chip->mutex);
586 /* Disallow XIP again */
588 @@ -859,17 +859,17 @@ static void __xipram xip_udelay(struct map_info *map, struct flchip *chip,
590 #define UDELAY(map, chip, adr, usec) \
592 - spin_unlock(chip->mutex); \
593 + mutex_unlock(&chip->mutex); \
595 - spin_lock(chip->mutex); \
596 + mutex_lock(&chip->mutex); \
599 #define INVALIDATE_CACHE_UDELAY(map, chip, adr, len, usec) \
601 - spin_unlock(chip->mutex); \
602 + mutex_unlock(&chip->mutex); \
603 INVALIDATE_CACHED_RANGE(map, adr, len); \
605 - spin_lock(chip->mutex); \
606 + mutex_lock(&chip->mutex); \
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);
614 - spin_lock(chip->mutex);
615 + mutex_lock(&chip->mutex);
616 ret = get_chip(map, chip, cmd_addr, FL_READY);
618 - spin_unlock(chip->mutex);
619 + mutex_unlock(&chip->mutex);
623 @@ -901,7 +901,7 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
625 put_chip(map, chip, cmd_addr);
627 - spin_unlock(chip->mutex);
628 + mutex_unlock(&chip->mutex);
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;
636 - spin_lock(chip->mutex);
637 + mutex_lock(&chip->mutex);
639 if (chip->state != FL_READY){
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);
645 - spin_unlock(chip->mutex);
646 + mutex_unlock(&chip->mutex);
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);
654 - spin_unlock(chip->mutex);
655 + mutex_unlock(&chip->mutex);
659 @@ -1062,10 +1062,10 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
663 - spin_lock(chip->mutex);
664 + mutex_lock(&chip->mutex);
665 ret = get_chip(map, chip, adr, FL_WRITING);
667 - spin_unlock(chip->mutex);
668 + mutex_unlock(&chip->mutex);
672 @@ -1108,11 +1108,11 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
674 set_current_state(TASK_UNINTERRUPTIBLE);
675 add_wait_queue(&chip->wq, &wait);
676 - spin_unlock(chip->mutex);
677 + mutex_unlock(&chip->mutex);
679 remove_wait_queue(&chip->wq, &wait);
680 timeo = jiffies + (HZ / 2); /* FIXME */
681 - spin_lock(chip->mutex);
682 + mutex_lock(&chip->mutex);
686 @@ -1144,7 +1144,7 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
688 chip->state = FL_READY;
689 put_chip(map, chip, adr);
690 - spin_unlock(chip->mutex);
691 + mutex_unlock(&chip->mutex);
695 @@ -1176,7 +1176,7 @@ static int cfi_amdstd_write_words(struct mtd_info *mtd, loff_t to, size_t len,
699 - spin_lock(cfi->chips[chipnum].mutex);
700 + mutex_lock(&cfi->chips[chipnum].mutex);
702 if (cfi->chips[chipnum].state != FL_READY) {
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);
708 - spin_unlock(cfi->chips[chipnum].mutex);
709 + mutex_unlock(&cfi->chips[chipnum].mutex);
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);
717 - spin_unlock(cfi->chips[chipnum].mutex);
718 + mutex_unlock(&cfi->chips[chipnum].mutex);
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,
726 - spin_lock(cfi->chips[chipnum].mutex);
727 + mutex_lock(&cfi->chips[chipnum].mutex);
729 if (cfi->chips[chipnum].state != FL_READY) {
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);
735 - spin_unlock(cfi->chips[chipnum].mutex);
736 + mutex_unlock(&cfi->chips[chipnum].mutex);
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,
742 tmp_buf = map_read(map, ofs + chipstart);
744 - spin_unlock(cfi->chips[chipnum].mutex);
745 + mutex_unlock(&cfi->chips[chipnum].mutex);
747 tmp_buf = map_word_load_partial(map, tmp_buf, buf, 0, len);
749 @@ -1311,10 +1311,10 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
753 - spin_lock(chip->mutex);
754 + mutex_lock(&chip->mutex);
755 ret = get_chip(map, chip, adr, FL_WRITING);
757 - spin_unlock(chip->mutex);
758 + mutex_unlock(&chip->mutex);
762 @@ -1369,11 +1369,11 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
764 set_current_state(TASK_UNINTERRUPTIBLE);
765 add_wait_queue(&chip->wq, &wait);
766 - spin_unlock(chip->mutex);
767 + mutex_unlock(&chip->mutex);
769 remove_wait_queue(&chip->wq, &wait);
770 timeo = jiffies + (HZ / 2); /* FIXME */
771 - spin_lock(chip->mutex);
772 + mutex_lock(&chip->mutex);
776 @@ -1401,7 +1401,7 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
778 chip->state = FL_READY;
779 put_chip(map, chip, adr);
780 - spin_unlock(chip->mutex);
781 + mutex_unlock(&chip->mutex);
785 @@ -1501,10 +1501,10 @@ static int __xipram do_erase_chip(struct map_info *map, struct flchip *chip)
787 adr = cfi->addr_unlock1;
789 - spin_lock(chip->mutex);
790 + mutex_lock(&chip->mutex);
791 ret = get_chip(map, chip, adr, FL_WRITING);
793 - spin_unlock(chip->mutex);
794 + mutex_unlock(&chip->mutex);
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);
805 remove_wait_queue(&chip->wq, &wait);
806 - spin_lock(chip->mutex);
807 + mutex_lock(&chip->mutex);
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);
820 @@ -1589,10 +1589,10 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
824 - spin_lock(chip->mutex);
825 + mutex_lock(&chip->mutex);
826 ret = get_chip(map, chip, adr, FL_ERASING);
828 - spin_unlock(chip->mutex);
829 + mutex_unlock(&chip->mutex);
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);
840 remove_wait_queue(&chip->wq, &wait);
841 - spin_lock(chip->mutex);
842 + mutex_lock(&chip->mutex);
845 if (chip->erase_suspended) {
846 @@ -1664,7 +1664,7 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
848 chip->state = FL_READY;
849 put_chip(map, chip, adr);
850 - spin_unlock(chip->mutex);
851 + mutex_unlock(&chip->mutex);
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;
859 - spin_lock(chip->mutex);
860 + mutex_lock(&chip->mutex);
861 ret = get_chip(map, chip, adr + chip->start, FL_LOCKING);
864 @@ -1742,7 +1742,7 @@ static int do_atmel_lock(struct map_info *map, struct flchip *chip,
868 - spin_unlock(chip->mutex);
869 + mutex_unlock(&chip->mutex);
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;
877 - spin_lock(chip->mutex);
878 + mutex_lock(&chip->mutex);
879 ret = get_chip(map, chip, adr + chip->start, FL_UNLOCKING);
882 @@ -1770,7 +1770,7 @@ static int do_atmel_unlock(struct map_info *map, struct flchip *chip,
886 - spin_unlock(chip->mutex);
887 + mutex_unlock(&chip->mutex);
891 @@ -1798,7 +1798,7 @@ static void cfi_amdstd_sync (struct mtd_info *mtd)
892 chip = &cfi->chips[i];
895 - spin_lock(chip->mutex);
896 + mutex_lock(&chip->mutex);
898 switch(chip->state) {
900 @@ -1812,7 +1812,7 @@ static void cfi_amdstd_sync (struct mtd_info *mtd)
901 * with the chip now anyway.
904 - spin_unlock(chip->mutex);
905 + mutex_unlock(&chip->mutex);
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);
913 - spin_unlock(chip->mutex);
914 + mutex_unlock(&chip->mutex);
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];
922 - spin_lock(chip->mutex);
923 + mutex_lock(&chip->mutex);
925 if (chip->state == FL_SYNCING) {
926 chip->state = chip->oldstate;
929 - spin_unlock(chip->mutex);
930 + mutex_unlock(&chip->mutex);
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];
938 - spin_lock(chip->mutex);
939 + mutex_lock(&chip->mutex);
941 switch(chip->state) {
943 @@ -1877,7 +1877,7 @@ static int cfi_amdstd_suspend(struct mtd_info *mtd)
947 - spin_unlock(chip->mutex);
948 + mutex_unlock(&chip->mutex);
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];
956 - spin_lock(chip->mutex);
957 + mutex_lock(&chip->mutex);
959 if (chip->state == FL_PM_SUSPENDED) {
960 chip->state = chip->oldstate;
963 - spin_unlock(chip->mutex);
964 + mutex_unlock(&chip->mutex);
968 @@ -1911,7 +1911,7 @@ static void cfi_amdstd_resume(struct mtd_info *mtd)
970 chip = &cfi->chips[i];
972 - spin_lock(chip->mutex);
973 + mutex_lock(&chip->mutex);
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)
979 printk(KERN_ERR "Argh. Chip not in PM_SUSPENDED state upon resume()\n");
981 - spin_unlock(chip->mutex);
982 + mutex_unlock(&chip->mutex);
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
992 timeo = jiffies + HZ;
994 - spin_lock_bh(chip->mutex);
995 + mutex_lock(&chip->mutex);
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]);
1010 - spin_unlock_bh(chip->mutex);
1011 + mutex_unlock(&chip->mutex);
1013 - spin_lock_bh(chip->mutex);
1014 + mutex_lock(&chip->mutex);
1018 @@ -335,13 +335,13 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
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]);
1028 /* Latency issues. Drop the lock, wait a while and retry */
1029 - spin_unlock_bh(chip->mutex);
1030 + mutex_unlock(&chip->mutex);
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);
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
1047 - spin_unlock_bh(chip->mutex);
1048 + mutex_unlock(&chip->mutex);
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);
1056 - spin_lock_bh(chip->mutex);
1057 + mutex_lock(&chip->mutex);
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,
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]);
1072 /* Latency issues. Drop the lock, wait a while and retry */
1073 - spin_unlock_bh(chip->mutex);
1074 + mutex_unlock(&chip->mutex);
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);
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))
1091 - spin_unlock_bh(chip->mutex);
1092 + mutex_unlock(&chip->mutex);
1094 - spin_lock_bh(chip->mutex);
1095 + mutex_lock(&chip->mutex);
1098 /* Argh. Not ready for write to buffer */
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]);
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;
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);
1117 timeo = jiffies + (HZ/2);
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);
1126 remove_wait_queue(&chip->wq, &wait);
1127 timeo = jiffies + (HZ / 2); /* FIXME */
1128 - spin_lock_bh(chip->mutex);
1129 + mutex_lock(&chip->mutex);
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;
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");
1143 /* Latency issues. Drop the lock, wait a while and retry */
1144 - spin_unlock_bh(chip->mutex);
1145 + mutex_unlock(&chip->mutex);
1148 - spin_lock_bh(chip->mutex);
1149 + mutex_lock(&chip->mutex);
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);
1157 - spin_unlock_bh(chip->mutex);
1158 + mutex_unlock(&chip->mutex);
1159 return map_word_bitsset(map, status, CMD(0x02)) ? -EROFS : -EIO;
1162 - spin_unlock_bh(chip->mutex);
1163 + mutex_unlock(&chip->mutex);
1167 @@ -749,7 +749,7 @@ static inline int do_erase_oneblock(struct map_info *map, struct flchip *chip, u
1169 timeo = jiffies + HZ;
1171 - spin_lock_bh(chip->mutex);
1172 + mutex_lock(&chip->mutex);
1174 /* Check that the chip's ready to talk to us. */
1175 switch (chip->state) {
1176 @@ -766,13 +766,13 @@ retry:
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");
1186 /* Latency issues. Drop the lock, wait a while and retry */
1187 - spin_unlock_bh(chip->mutex);
1188 + mutex_unlock(&chip->mutex);
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);
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;
1205 - spin_unlock_bh(chip->mutex);
1206 + mutex_unlock(&chip->mutex);
1208 - spin_lock_bh(chip->mutex);
1209 + mutex_lock(&chip->mutex);
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);
1220 remove_wait_queue(&chip->wq, &wait);
1221 timeo = jiffies + (HZ*20); /* FIXME */
1222 - spin_lock_bh(chip->mutex);
1223 + mutex_lock(&chip->mutex);
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]);
1231 - spin_unlock_bh(chip->mutex);
1232 + mutex_unlock(&chip->mutex);
1236 /* Latency issues. Drop the lock, wait a while and retry */
1237 - spin_unlock_bh(chip->mutex);
1238 + mutex_unlock(&chip->mutex);
1240 - spin_lock_bh(chip->mutex);
1241 + mutex_lock(&chip->mutex);
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);
1253 printk(KERN_DEBUG "Chip erase failed at 0x%08lx: status 0x%x\n", adr, chipstatus);
1254 @@ -887,7 +887,7 @@ retry:
1258 - spin_unlock_bh(chip->mutex);
1259 + mutex_unlock(&chip->mutex);
1263 @@ -995,7 +995,7 @@ static void cfi_staa_sync (struct mtd_info *mtd)
1264 chip = &cfi->chips[i];
1267 - spin_lock_bh(chip->mutex);
1268 + mutex_lock(&chip->mutex);
1270 switch(chip->state) {
1272 @@ -1009,7 +1009,7 @@ static void cfi_staa_sync (struct mtd_info *mtd)
1273 * with the chip now anyway.
1276 - spin_unlock_bh(chip->mutex);
1277 + mutex_unlock(&chip->mutex);
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);
1285 - spin_unlock_bh(chip->mutex);
1286 + mutex_unlock(&chip->mutex);
1288 remove_wait_queue(&chip->wq, &wait);
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];
1294 - spin_lock_bh(chip->mutex);
1295 + mutex_lock(&chip->mutex);
1297 if (chip->state == FL_SYNCING) {
1298 chip->state = chip->oldstate;
1301 - spin_unlock_bh(chip->mutex);
1302 + mutex_unlock(&chip->mutex);
1306 @@ -1054,7 +1054,7 @@ static inline int do_lock_oneblock(struct map_info *map, struct flchip *chip, un
1308 timeo = jiffies + HZ;
1310 - spin_lock_bh(chip->mutex);
1311 + mutex_lock(&chip->mutex);
1313 /* Check that the chip's ready to talk to us. */
1314 switch (chip->state) {
1315 @@ -1071,13 +1071,13 @@ retry:
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");
1325 /* Latency issues. Drop the lock, wait a while and retry */
1326 - spin_unlock_bh(chip->mutex);
1327 + mutex_unlock(&chip->mutex);
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);
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;
1344 - spin_unlock_bh(chip->mutex);
1345 + mutex_unlock(&chip->mutex);
1347 - spin_lock_bh(chip->mutex);
1348 + mutex_lock(&chip->mutex);
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]);
1356 - spin_unlock_bh(chip->mutex);
1357 + mutex_unlock(&chip->mutex);
1361 /* Latency issues. Drop the lock, wait a while and retry */
1362 - spin_unlock_bh(chip->mutex);
1363 + mutex_unlock(&chip->mutex);
1365 - spin_lock_bh(chip->mutex);
1366 + mutex_lock(&chip->mutex);
1369 /* Done and happy. */
1370 chip->state = FL_STATUS;
1373 - spin_unlock_bh(chip->mutex);
1374 + mutex_unlock(&chip->mutex);
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,
1380 timeo = jiffies + HZ;
1382 - spin_lock_bh(chip->mutex);
1383 + mutex_lock(&chip->mutex);
1385 /* Check that the chip's ready to talk to us. */
1386 switch (chip->state) {
1387 @@ -1220,13 +1220,13 @@ retry:
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");
1397 /* Latency issues. Drop the lock, wait a while and retry */
1398 - spin_unlock_bh(chip->mutex);
1399 + mutex_unlock(&chip->mutex);
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);
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;
1416 - spin_unlock_bh(chip->mutex);
1417 + mutex_unlock(&chip->mutex);
1419 - spin_lock_bh(chip->mutex);
1420 + mutex_lock(&chip->mutex);
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]);
1428 - spin_unlock_bh(chip->mutex);
1429 + mutex_unlock(&chip->mutex);
1433 /* Latency issues. Drop the unlock, wait a while and retry */
1434 - spin_unlock_bh(chip->mutex);
1435 + mutex_unlock(&chip->mutex);
1437 - spin_lock_bh(chip->mutex);
1438 + mutex_lock(&chip->mutex);
1441 /* Done and happy. */
1442 chip->state = FL_STATUS;
1445 - spin_unlock_bh(chip->mutex);
1446 + mutex_unlock(&chip->mutex);
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];
1454 - spin_lock_bh(chip->mutex);
1455 + mutex_lock(&chip->mutex);
1457 switch(chip->state) {
1459 @@ -1354,7 +1354,7 @@ static int cfi_staa_suspend(struct mtd_info *mtd)
1463 - spin_unlock_bh(chip->mutex);
1464 + mutex_unlock(&chip->mutex);
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];
1472 - spin_lock_bh(chip->mutex);
1473 + mutex_lock(&chip->mutex);
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;
1481 - spin_unlock_bh(chip->mutex);
1482 + mutex_unlock(&chip->mutex);
1486 @@ -1390,7 +1390,7 @@ static void cfi_staa_resume(struct mtd_info *mtd)
1488 chip = &cfi->chips[i];
1490 - spin_lock_bh(chip->mutex);
1491 + mutex_lock(&chip->mutex);
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)
1499 - spin_unlock_bh(chip->mutex);
1500 + mutex_unlock(&chip->mutex);
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
1512 - spin_lock(chip->mutex);
1513 + mutex_lock(&chip->mutex);
1514 ret = get_chip(map, chip, adr, FL_LOCKING);
1516 - spin_unlock(chip->mutex);
1517 + mutex_unlock(&chip->mutex);
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);
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);
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
1549 * has asm/spinlock.h, or 2.4, which has linux/spinlock.h
1551 #include <linux/sched.h>
1552 +#include <linux/mutex.h>
1556 @@ -65,8 +66,7 @@ struct flchip {
1557 unsigned int erase_suspended:1;
1558 unsigned long in_progress_block_addr;
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
1565 int word_write_time;