aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/devices/m25p80.c
diff options
context:
space:
mode:
authorDavid Brownell <david-b@pacbell.net>2007-06-24 18:09:13 -0400
committerDavid Woodhouse <dwmw2@infradead.org>2007-06-28 17:34:32 -0400
commit7d5230ea3987ea3eaa03601fe429cb69f87de3e3 (patch)
treea268ad16b63c90fa55cc53a737441a5a05676a77 /drivers/mtd/devices/m25p80.c
parent02d929187414f2095b30ebf4acee1ce6617add45 (diff)
[MTD] m25p80 converted to mutex
Convert semaphore usage in m25p80 driver to mutex; mention another kind of SPI flash chip that should be able to use this driver (given minor tweaks). Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Diffstat (limited to 'drivers/mtd/devices/m25p80.c')
-rw-r--r--drivers/mtd/devices/m25p80.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 78c2511ae9e0..7eaa61862a00 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -19,16 +19,17 @@
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/device.h> 20#include <linux/device.h>
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <linux/interrupt.h> 22#include <linux/mutex.h>
23
23#include <linux/mtd/mtd.h> 24#include <linux/mtd/mtd.h>
24#include <linux/mtd/partitions.h> 25#include <linux/mtd/partitions.h>
26
25#include <linux/spi/spi.h> 27#include <linux/spi/spi.h>
26#include <linux/spi/flash.h> 28#include <linux/spi/flash.h>
27 29
28#include <asm/semaphore.h>
29
30 30
31/* NOTE: AT 25F and SST 25LF series are very similar, 31/* NOTE: AT 25F and SST 25LF series are very similar,
32 * as are other newer Atmel dataflash chips (AT26),
32 * but commands for sector erase and chip id differ... 33 * but commands for sector erase and chip id differ...
33 */ 34 */
34 35
@@ -65,7 +66,7 @@
65 66
66struct m25p { 67struct m25p {
67 struct spi_device *spi; 68 struct spi_device *spi;
68 struct semaphore lock; 69 struct mutex lock;
69 struct mtd_info mtd; 70 struct mtd_info mtd;
70 unsigned partitioned; 71 unsigned partitioned;
71 u8 command[4]; 72 u8 command[4];
@@ -201,13 +202,13 @@ static int m25p80_erase(struct mtd_info *mtd, struct erase_info *instr)
201 addr = instr->addr; 202 addr = instr->addr;
202 len = instr->len; 203 len = instr->len;
203 204
204 down(&flash->lock); 205 mutex_lock(&flash->lock);
205 206
206 /* now erase those sectors */ 207 /* now erase those sectors */
207 while (len) { 208 while (len) {
208 if (erase_sector(flash, addr)) { 209 if (erase_sector(flash, addr)) {
209 instr->state = MTD_ERASE_FAILED; 210 instr->state = MTD_ERASE_FAILED;
210 up(&flash->lock); 211 mutex_unlock(&flash->lock);
211 return -EIO; 212 return -EIO;
212 } 213 }
213 214
@@ -215,7 +216,7 @@ static int m25p80_erase(struct mtd_info *mtd, struct erase_info *instr)
215 len -= mtd->erasesize; 216 len -= mtd->erasesize;
216 } 217 }
217 218
218 up(&flash->lock); 219 mutex_unlock(&flash->lock);
219 220
220 instr->state = MTD_ERASE_DONE; 221 instr->state = MTD_ERASE_DONE;
221 mtd_erase_callback(instr); 222 mtd_erase_callback(instr);
@@ -260,12 +261,12 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len,
260 if (retlen) 261 if (retlen)
261 *retlen = 0; 262 *retlen = 0;
262 263
263 down(&flash->lock); 264 mutex_lock(&flash->lock);
264 265
265 /* Wait till previous write/erase is done. */ 266 /* Wait till previous write/erase is done. */
266 if (wait_till_ready(flash)) { 267 if (wait_till_ready(flash)) {
267 /* REVISIT status return?? */ 268 /* REVISIT status return?? */
268 up(&flash->lock); 269 mutex_unlock(&flash->lock);
269 return 1; 270 return 1;
270 } 271 }
271 272
@@ -281,7 +282,7 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len,
281 282
282 *retlen = m.actual_length - sizeof(flash->command); 283 *retlen = m.actual_length - sizeof(flash->command);
283 284
284 up(&flash->lock); 285 mutex_unlock(&flash->lock);
285 286
286 return 0; 287 return 0;
287} 288}
@@ -323,7 +324,7 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len,
323 t[1].tx_buf = buf; 324 t[1].tx_buf = buf;
324 spi_message_add_tail(&t[1], &m); 325 spi_message_add_tail(&t[1], &m);
325 326
326 down(&flash->lock); 327 mutex_lock(&flash->lock);
327 328
328 /* Wait until finished previous write command. */ 329 /* Wait until finished previous write command. */
329 if (wait_till_ready(flash)) 330 if (wait_till_ready(flash))
@@ -381,10 +382,10 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len,
381 if (retlen) 382 if (retlen)
382 *retlen += m.actual_length 383 *retlen += m.actual_length
383 - sizeof(flash->command); 384 - sizeof(flash->command);
384 } 385 }
385 } 386 }
386 387
387 up(&flash->lock); 388 mutex_unlock(&flash->lock);
388 389
389 return 0; 390 return 0;
390} 391}
@@ -405,7 +406,7 @@ struct flash_info {
405}; 406};
406 407
407static struct flash_info __devinitdata m25p_data [] = { 408static struct flash_info __devinitdata m25p_data [] = {
408 /* REVISIT: fill in JEDEC ids, for parts that have them */ 409 /* JEDEC id zero means "has no ID" */
409 { "m25p05", 0x05, 0x2010, 32 * 1024, 2 }, 410 { "m25p05", 0x05, 0x2010, 32 * 1024, 2 },
410 { "m25p10", 0x10, 0x2011, 32 * 1024, 4 }, 411 { "m25p10", 0x10, 0x2011, 32 * 1024, 4 },
411 { "m25p20", 0x11, 0x2012, 64 * 1024, 4 }, 412 { "m25p20", 0x11, 0x2012, 64 * 1024, 4 },
@@ -456,7 +457,7 @@ static int __devinit m25p_probe(struct spi_device *spi)
456 return -ENOMEM; 457 return -ENOMEM;
457 458
458 flash->spi = spi; 459 flash->spi = spi;
459 init_MUTEX(&flash->lock); 460 mutex_init(&flash->lock);
460 dev_set_drvdata(&spi->dev, flash); 461 dev_set_drvdata(&spi->dev, flash);
461 462
462 if (data->name) 463 if (data->name)