Commit b3585e4f authored by Arjan van de Ven's avatar Arjan van de Ven Committed by Greg Kroah-Hartman

[PATCH] I2C: Convert i2c to mutexes

The patch below converts a few i2c semaphores to mutexes
Signed-off-by: default avatarArjan van de Ven <arjan@infradead.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 2488a39d
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
#include <linux/ioport.h> #include <linux/ioport.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/mutex.h>
#include <asm/io.h> #include <asm/io.h>
#include <asm/semaphore.h> #include <asm/semaphore.h>
...@@ -136,7 +137,7 @@ ...@@ -136,7 +137,7 @@
static struct pci_driver ali1535_driver; static struct pci_driver ali1535_driver;
static unsigned short ali1535_smba; static unsigned short ali1535_smba;
static DECLARE_MUTEX(i2c_ali1535_sem); static DEFINE_MUTEX(i2c_ali1535_mutex);
/* Detect whether a ALI1535 can be found, and initialize it, where necessary. /* Detect whether a ALI1535 can be found, and initialize it, where necessary.
Note the differences between kernels with the old PCI BIOS interface and Note the differences between kernels with the old PCI BIOS interface and
...@@ -345,7 +346,7 @@ static s32 ali1535_access(struct i2c_adapter *adap, u16 addr, ...@@ -345,7 +346,7 @@ static s32 ali1535_access(struct i2c_adapter *adap, u16 addr,
int timeout; int timeout;
s32 result = 0; s32 result = 0;
down(&i2c_ali1535_sem); mutex_lock(&i2c_ali1535_mutex);
/* make sure SMBus is idle */ /* make sure SMBus is idle */
temp = inb_p(SMBHSTSTS); temp = inb_p(SMBHSTSTS);
for (timeout = 0; for (timeout = 0;
...@@ -460,7 +461,7 @@ static s32 ali1535_access(struct i2c_adapter *adap, u16 addr, ...@@ -460,7 +461,7 @@ static s32 ali1535_access(struct i2c_adapter *adap, u16 addr,
break; break;
} }
EXIT: EXIT:
up(&i2c_ali1535_sem); mutex_unlock(&i2c_ali1535_mutex);
return result; return result;
} }
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/rtc.h> #include <linux/rtc.h>
#include <linux/bcd.h> #include <linux/bcd.h>
#include <linux/mutex.h>
#define DS1374_REG_TOD0 0x00 #define DS1374_REG_TOD0 0x00
#define DS1374_REG_TOD1 0x01 #define DS1374_REG_TOD1 0x01
...@@ -41,7 +42,7 @@ ...@@ -41,7 +42,7 @@
#define DS1374_DRV_NAME "ds1374" #define DS1374_DRV_NAME "ds1374"
static DECLARE_MUTEX(ds1374_mutex); static DEFINE_MUTEX(ds1374_mutex);
static struct i2c_driver ds1374_driver; static struct i2c_driver ds1374_driver;
static struct i2c_client *save_client; static struct i2c_client *save_client;
...@@ -114,7 +115,7 @@ ulong ds1374_get_rtc_time(void) ...@@ -114,7 +115,7 @@ ulong ds1374_get_rtc_time(void)
ulong t1, t2; ulong t1, t2;
int limit = 10; /* arbitrary retry limit */ int limit = 10; /* arbitrary retry limit */
down(&ds1374_mutex); mutex_lock(&ds1374_mutex);
/* /*
* Since the reads are being performed one byte at a time using * Since the reads are being performed one byte at a time using
...@@ -127,7 +128,7 @@ ulong ds1374_get_rtc_time(void) ...@@ -127,7 +128,7 @@ ulong ds1374_get_rtc_time(void)
t2 = ds1374_read_rtc(); t2 = ds1374_read_rtc();
} while (t1 != t2 && limit--); } while (t1 != t2 && limit--);
up(&ds1374_mutex); mutex_unlock(&ds1374_mutex);
if (t1 != t2) { if (t1 != t2) {
dev_warn(&save_client->dev, dev_warn(&save_client->dev,
...@@ -145,7 +146,7 @@ static void ds1374_set_tlet(ulong arg) ...@@ -145,7 +146,7 @@ static void ds1374_set_tlet(ulong arg)
t1 = *(ulong *) arg; t1 = *(ulong *) arg;
down(&ds1374_mutex); mutex_lock(&ds1374_mutex);
/* /*
* Since the writes are being performed one byte at a time using * Since the writes are being performed one byte at a time using
...@@ -158,7 +159,7 @@ static void ds1374_set_tlet(ulong arg) ...@@ -158,7 +159,7 @@ static void ds1374_set_tlet(ulong arg)
t2 = ds1374_read_rtc(); t2 = ds1374_read_rtc();
} while (t1 != t2 && limit--); } while (t1 != t2 && limit--);
up(&ds1374_mutex); mutex_unlock(&ds1374_mutex);
if (t1 != t2) if (t1 != t2)
dev_warn(&save_client->dev, dev_warn(&save_client->dev,
......
...@@ -24,13 +24,14 @@ ...@@ -24,13 +24,14 @@
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/rtc.h> #include <linux/rtc.h>
#include <linux/bcd.h> #include <linux/bcd.h>
#include <linux/mutex.h>
#include <asm/time.h> #include <asm/time.h>
#include <asm/rtc.h> #include <asm/rtc.h>
#define M41T00_DRV_NAME "m41t00" #define M41T00_DRV_NAME "m41t00"
static DECLARE_MUTEX(m41t00_mutex); static DEFINE_MUTEX(m41t00_mutex);
static struct i2c_driver m41t00_driver; static struct i2c_driver m41t00_driver;
static struct i2c_client *save_client; static struct i2c_client *save_client;
...@@ -54,7 +55,7 @@ m41t00_get_rtc_time(void) ...@@ -54,7 +55,7 @@ m41t00_get_rtc_time(void)
sec = min = hour = day = mon = year = 0; sec = min = hour = day = mon = year = 0;
sec1 = min1 = hour1 = day1 = mon1 = year1 = 0; sec1 = min1 = hour1 = day1 = mon1 = year1 = 0;
down(&m41t00_mutex); mutex_lock(&m41t00_mutex);
do { do {
if (((sec = i2c_smbus_read_byte_data(save_client, 0)) >= 0) if (((sec = i2c_smbus_read_byte_data(save_client, 0)) >= 0)
&& ((min = i2c_smbus_read_byte_data(save_client, 1)) && ((min = i2c_smbus_read_byte_data(save_client, 1))
...@@ -80,7 +81,7 @@ m41t00_get_rtc_time(void) ...@@ -80,7 +81,7 @@ m41t00_get_rtc_time(void)
mon1 = mon; mon1 = mon;
year1 = year; year1 = year;
} while (--limit > 0); } while (--limit > 0);
up(&m41t00_mutex); mutex_unlock(&m41t00_mutex);
if (limit == 0) { if (limit == 0) {
dev_warn(&save_client->dev, dev_warn(&save_client->dev,
...@@ -125,7 +126,7 @@ m41t00_set_tlet(ulong arg) ...@@ -125,7 +126,7 @@ m41t00_set_tlet(ulong arg)
BIN_TO_BCD(tm.tm_mday); BIN_TO_BCD(tm.tm_mday);
BIN_TO_BCD(tm.tm_year); BIN_TO_BCD(tm.tm_year);
down(&m41t00_mutex); mutex_lock(&m41t00_mutex);
if ((i2c_smbus_write_byte_data(save_client, 0, tm.tm_sec & 0x7f) < 0) if ((i2c_smbus_write_byte_data(save_client, 0, tm.tm_sec & 0x7f) < 0)
|| (i2c_smbus_write_byte_data(save_client, 1, tm.tm_min & 0x7f) || (i2c_smbus_write_byte_data(save_client, 1, tm.tm_min & 0x7f)
< 0) < 0)
...@@ -140,7 +141,7 @@ m41t00_set_tlet(ulong arg) ...@@ -140,7 +141,7 @@ m41t00_set_tlet(ulong arg)
dev_warn(&save_client->dev,"m41t00: can't write to rtc chip\n"); dev_warn(&save_client->dev,"m41t00: can't write to rtc chip\n");
up(&m41t00_mutex); mutex_unlock(&m41t00_mutex);
return; return;
} }
......
...@@ -31,12 +31,13 @@ ...@@ -31,12 +31,13 @@
#include <linux/idr.h> #include <linux/idr.h>
#include <linux/seq_file.h> #include <linux/seq_file.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/mutex.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
static LIST_HEAD(adapters); static LIST_HEAD(adapters);
static LIST_HEAD(drivers); static LIST_HEAD(drivers);
static DECLARE_MUTEX(core_lists); static DEFINE_MUTEX(core_lists);
static DEFINE_IDR(i2c_adapter_idr); static DEFINE_IDR(i2c_adapter_idr);
/* match always succeeds, as we want the probe() to tell if we really accept this match */ /* match always succeeds, as we want the probe() to tell if we really accept this match */
...@@ -153,7 +154,7 @@ int i2c_add_adapter(struct i2c_adapter *adap) ...@@ -153,7 +154,7 @@ int i2c_add_adapter(struct i2c_adapter *adap)
struct list_head *item; struct list_head *item;
struct i2c_driver *driver; struct i2c_driver *driver;
down(&core_lists); mutex_lock(&core_lists);
if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0) { if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0) {
res = -ENOMEM; res = -ENOMEM;
...@@ -203,7 +204,7 @@ int i2c_add_adapter(struct i2c_adapter *adap) ...@@ -203,7 +204,7 @@ int i2c_add_adapter(struct i2c_adapter *adap)
} }
out_unlock: out_unlock:
up(&core_lists); mutex_unlock(&core_lists);
return res; return res;
} }
...@@ -216,7 +217,7 @@ int i2c_del_adapter(struct i2c_adapter *adap) ...@@ -216,7 +217,7 @@ int i2c_del_adapter(struct i2c_adapter *adap)
struct i2c_client *client; struct i2c_client *client;
int res = 0; int res = 0;
down(&core_lists); mutex_lock(&core_lists);
/* First make sure that this adapter was ever added */ /* First make sure that this adapter was ever added */
list_for_each_entry(adap_from_list, &adapters, list) { list_for_each_entry(adap_from_list, &adapters, list) {
...@@ -272,7 +273,7 @@ int i2c_del_adapter(struct i2c_adapter *adap) ...@@ -272,7 +273,7 @@ int i2c_del_adapter(struct i2c_adapter *adap)
dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name); dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name);
out_unlock: out_unlock:
up(&core_lists); mutex_unlock(&core_lists);
return res; return res;
} }
...@@ -289,7 +290,7 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver) ...@@ -289,7 +290,7 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
struct i2c_adapter *adapter; struct i2c_adapter *adapter;
int res = 0; int res = 0;
down(&core_lists); mutex_lock(&core_lists);
/* add the driver to the list of i2c drivers in the driver core */ /* add the driver to the list of i2c drivers in the driver core */
driver->driver.owner = owner; driver->driver.owner = owner;
...@@ -311,7 +312,7 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver) ...@@ -311,7 +312,7 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
} }
out_unlock: out_unlock:
up(&core_lists); mutex_unlock(&core_lists);
return res; return res;
} }
EXPORT_SYMBOL(i2c_register_driver); EXPORT_SYMBOL(i2c_register_driver);
...@@ -324,7 +325,7 @@ int i2c_del_driver(struct i2c_driver *driver) ...@@ -324,7 +325,7 @@ int i2c_del_driver(struct i2c_driver *driver)
int res = 0; int res = 0;
down(&core_lists); mutex_lock(&core_lists);
/* Have a look at each adapter, if clients of this driver are still /* Have a look at each adapter, if clients of this driver are still
* attached. If so, detach them to be able to kill the driver * attached. If so, detach them to be able to kill the driver
...@@ -363,7 +364,7 @@ int i2c_del_driver(struct i2c_driver *driver) ...@@ -363,7 +364,7 @@ int i2c_del_driver(struct i2c_driver *driver)
pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name); pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name);
out_unlock: out_unlock:
up(&core_lists); mutex_unlock(&core_lists);
return 0; return 0;
} }
...@@ -779,12 +780,12 @@ struct i2c_adapter* i2c_get_adapter(int id) ...@@ -779,12 +780,12 @@ struct i2c_adapter* i2c_get_adapter(int id)
{ {
struct i2c_adapter *adapter; struct i2c_adapter *adapter;
down(&core_lists); mutex_lock(&core_lists);
adapter = (struct i2c_adapter *)idr_find(&i2c_adapter_idr, id); adapter = (struct i2c_adapter *)idr_find(&i2c_adapter_idr, id);
if (adapter && !try_module_get(adapter->owner)) if (adapter && !try_module_get(adapter->owner))
adapter = NULL; adapter = NULL;
up(&core_lists); mutex_unlock(&core_lists);
return adapter; return adapter;
} }
......
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