Commit ec9ce52e authored by Matthias Kaehlcke's avatar Matthias Kaehlcke Committed by David Woodhouse

[MTD] Use mutex instead of semaphore in dataflash driver

The MTD DataFlash driver uses a semaphore as mutex.  Use the mutex API instead
of the (binary) semaphore.
Signed-off-by: default avatarMatthias Kaehlcke <matthias.kaehlcke@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarDavid Woodhouse <dwmw2@infradead.org>
parent 02d087db
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/mutex.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <linux/spi/flash.h> #include <linux/spi/flash.h>
...@@ -89,7 +90,7 @@ struct dataflash { ...@@ -89,7 +90,7 @@ struct dataflash {
unsigned short page_offset; /* offset in flash address */ unsigned short page_offset; /* offset in flash address */
unsigned int page_size; /* of bytes per page */ unsigned int page_size; /* of bytes per page */
struct semaphore lock; struct mutex lock;
struct spi_device *spi; struct spi_device *spi;
struct mtd_info mtd; struct mtd_info mtd;
...@@ -167,7 +168,7 @@ static int dataflash_erase(struct mtd_info *mtd, struct erase_info *instr) ...@@ -167,7 +168,7 @@ static int dataflash_erase(struct mtd_info *mtd, struct erase_info *instr)
x.len = 4; x.len = 4;
spi_message_add_tail(&x, &msg); spi_message_add_tail(&x, &msg);
down(&priv->lock); mutex_lock(&priv->lock);
while (instr->len > 0) { while (instr->len > 0) {
unsigned int pageaddr; unsigned int pageaddr;
int status; int status;
...@@ -210,7 +211,7 @@ static int dataflash_erase(struct mtd_info *mtd, struct erase_info *instr) ...@@ -210,7 +211,7 @@ static int dataflash_erase(struct mtd_info *mtd, struct erase_info *instr)
instr->len -= priv->page_size; instr->len -= priv->page_size;
} }
} }
up(&priv->lock); mutex_unlock(&priv->lock);
/* Inform MTD subsystem that erase is complete */ /* Inform MTD subsystem that erase is complete */
instr->state = MTD_ERASE_DONE; instr->state = MTD_ERASE_DONE;
...@@ -266,7 +267,7 @@ static int dataflash_read(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -266,7 +267,7 @@ static int dataflash_read(struct mtd_info *mtd, loff_t from, size_t len,
x[1].len = len; x[1].len = len;
spi_message_add_tail(&x[1], &msg); spi_message_add_tail(&x[1], &msg);
down(&priv->lock); mutex_lock(&priv->lock);
/* Continuous read, max clock = f(car) which may be less than /* Continuous read, max clock = f(car) which may be less than
* the peak rate available. Some chips support commands with * the peak rate available. Some chips support commands with
...@@ -279,7 +280,7 @@ static int dataflash_read(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -279,7 +280,7 @@ static int dataflash_read(struct mtd_info *mtd, loff_t from, size_t len,
/* plus 4 "don't care" bytes */ /* plus 4 "don't care" bytes */
status = spi_sync(priv->spi, &msg); status = spi_sync(priv->spi, &msg);
up(&priv->lock); mutex_unlock(&priv->lock);
if (status >= 0) { if (status >= 0) {
*retlen = msg.actual_length - 8; *retlen = msg.actual_length - 8;
...@@ -336,7 +337,7 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -336,7 +337,7 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,
else else
writelen = len; writelen = len;
down(&priv->lock); mutex_lock(&priv->lock);
while (remaining > 0) { while (remaining > 0) {
DEBUG(MTD_DEBUG_LEVEL3, "write @ %i:%i len=%i\n", DEBUG(MTD_DEBUG_LEVEL3, "write @ %i:%i len=%i\n",
pageaddr, offset, writelen); pageaddr, offset, writelen);
...@@ -441,7 +442,7 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -441,7 +442,7 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,
else else
writelen = remaining; writelen = remaining;
} }
up(&priv->lock); mutex_unlock(&priv->lock);
return status; return status;
} }
...@@ -463,7 +464,7 @@ add_dataflash(struct spi_device *spi, char *name, ...@@ -463,7 +464,7 @@ add_dataflash(struct spi_device *spi, char *name,
if (!priv) if (!priv)
return -ENOMEM; return -ENOMEM;
init_MUTEX(&priv->lock); mutex_init(&priv->lock);
priv->spi = spi; priv->spi = spi;
priv->page_size = pagesize; priv->page_size = pagesize;
priv->page_offset = pageoffset; priv->page_offset = pageoffset;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment