Commit 3ea07279 authored by Madhusudhan Chikkature's avatar Madhusudhan Chikkature Committed by Tony Lindgren

HDQ driver:protect the shared flag

This patch moves the shared variable into the local structure and
protects its updation.
Signed-off-by: default avatarMadhusudhan Chikkature <madhu.cr@ti.com>
Acked-by: default avatarEvgeniy Polyakov <johnpol@2ka.mipt.ru>
Acked-by: default avatarFelipe Balbi <felipe.balbi@nokia.com>
Signed-off-by: default avatarTony Lindgren <tony@atomide.com>
parent a6774aaf
...@@ -61,6 +61,12 @@ struct hdq_data { ...@@ -61,6 +61,12 @@ struct hdq_data {
struct clk *hdq_fck; struct clk *hdq_fck;
u8 hdq_irqstatus; u8 hdq_irqstatus;
spinlock_t hdq_spinlock; spinlock_t hdq_spinlock;
/*
* Used to control the call to omap_hdq_get and omap_hdq_put.
* HDQ Protocol: Write the CMD|REG_address first, followed by
* the data wrire or read.
*/
int init_trans;
}; };
static int omap_hdq_get(struct hdq_data *hdq_data); static int omap_hdq_get(struct hdq_data *hdq_data);
...@@ -504,13 +510,6 @@ omap_hdq_put(struct hdq_data *hdq_data) ...@@ -504,13 +510,6 @@ omap_hdq_put(struct hdq_data *hdq_data)
return ret; return ret;
} }
/*
* Used to control the call to omap_hdq_get and omap_hdq_put.
* HDQ Protocol: Write the CMD|REG_address first, followed by
* the data wrire or read.
*/
static int init_trans;
/* /*
* Read a byte of data from the device. * Read a byte of data from the device.
*/ */
...@@ -522,14 +521,26 @@ static u8 omap_w1_read_byte(void *_hdq) ...@@ -522,14 +521,26 @@ static u8 omap_w1_read_byte(void *_hdq)
ret = hdq_read_byte(hdq_data, &val); ret = hdq_read_byte(hdq_data, &val);
if (ret) { if (ret) {
init_trans = 0; ret = mutex_lock_interruptible(&hdq_data->hdq_mutex);
if (ret < 0) {
dev_dbg(hdq_data->dev, "Could not acquire mutex\n");
return -EINTR;
}
hdq_data->init_trans = 0;
mutex_unlock(&hdq_data->hdq_mutex);
omap_hdq_put(hdq_data); omap_hdq_put(hdq_data);
return -1; return -1;
} }
/* Write followed by a read, release the module */ /* Write followed by a read, release the module */
if (init_trans) { if (hdq_data->init_trans) {
init_trans = 0; ret = mutex_lock_interruptible(&hdq_data->hdq_mutex);
if (ret < 0) {
dev_dbg(hdq_data->dev, "Could not acquire mutex\n");
return -EINTR;
}
hdq_data->init_trans = 0;
mutex_unlock(&hdq_data->hdq_mutex);
omap_hdq_put(hdq_data); omap_hdq_put(hdq_data);
} }
...@@ -542,21 +553,34 @@ static u8 omap_w1_read_byte(void *_hdq) ...@@ -542,21 +553,34 @@ static u8 omap_w1_read_byte(void *_hdq)
static void omap_w1_write_byte(void *_hdq, u8 byte) static void omap_w1_write_byte(void *_hdq, u8 byte)
{ {
struct hdq_data *hdq_data = _hdq; struct hdq_data *hdq_data = _hdq;
int ret;
u8 status; u8 status;
/* First write to initialize the transfer */ /* First write to initialize the transfer */
if (init_trans == 0) if (hdq_data->init_trans == 0)
omap_hdq_get(hdq_data); omap_hdq_get(hdq_data);
init_trans++; ret = mutex_lock_interruptible(&hdq_data->hdq_mutex);
if (ret < 0) {
dev_dbg(hdq_data->dev, "Could not acquire mutex\n");
return;
}
hdq_data->init_trans++;
mutex_unlock(&hdq_data->hdq_mutex);
hdq_write_byte(hdq_data, byte, &status); hdq_write_byte(hdq_data, byte, &status);
dev_dbg(hdq_data->dev, "Ctrl status %x\n", status); dev_dbg(hdq_data->dev, "Ctrl status %x\n", status);
/* Second write, data transfered. Release the module */ /* Second write, data transfered. Release the module */
if (init_trans > 1) { if (hdq_data->init_trans > 1) {
omap_hdq_put(hdq_data); omap_hdq_put(hdq_data);
init_trans = 0; ret = mutex_lock_interruptible(&hdq_data->hdq_mutex);
if (ret < 0) {
dev_dbg(hdq_data->dev, "Could not acquire mutex\n");
return;
}
hdq_data->init_trans = 0;
mutex_unlock(&hdq_data->hdq_mutex);
} }
return; return;
......
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