aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArjan van de Ven <arjan@infradead.org>2006-01-11 04:50:26 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2006-03-23 17:21:49 -0500
commitb3585e4f5b3e4ddb4d82ae50d0b844f619c6d821 (patch)
tree5375363cc6087d74196efc0ded6dae9a8a4c2ad5
parent2488a39d233a758d41ab7de70a220bc956f3c96c (diff)
[PATCH] I2C: Convert i2c to mutexes
The patch below converts a few i2c semaphores to mutexes Signed-off-by: Arjan van de Ven <arjan@infradead.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--drivers/i2c/busses/i2c-ali1535.c7
-rw-r--r--drivers/i2c/chips/ds1374.c11
-rw-r--r--drivers/i2c/chips/m41t00.c11
-rw-r--r--drivers/i2c/i2c-core.c23
4 files changed, 28 insertions, 24 deletions
diff --git a/drivers/i2c/busses/i2c-ali1535.c b/drivers/i2c/busses/i2c-ali1535.c
index 3eb47890db40..26cf891762b8 100644
--- a/drivers/i2c/busses/i2c-ali1535.c
+++ b/drivers/i2c/busses/i2c-ali1535.c
@@ -62,6 +62,7 @@
62#include <linux/ioport.h> 62#include <linux/ioport.h>
63#include <linux/i2c.h> 63#include <linux/i2c.h>
64#include <linux/init.h> 64#include <linux/init.h>
65#include <linux/mutex.h>
65#include <asm/io.h> 66#include <asm/io.h>
66#include <asm/semaphore.h> 67#include <asm/semaphore.h>
67 68
@@ -136,7 +137,7 @@
136 137
137static struct pci_driver ali1535_driver; 138static struct pci_driver ali1535_driver;
138static unsigned short ali1535_smba; 139static unsigned short ali1535_smba;
139static DECLARE_MUTEX(i2c_ali1535_sem); 140static DEFINE_MUTEX(i2c_ali1535_mutex);
140 141
141/* Detect whether a ALI1535 can be found, and initialize it, where necessary. 142/* Detect whether a ALI1535 can be found, and initialize it, where necessary.
142 Note the differences between kernels with the old PCI BIOS interface and 143 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 int timeout; 346 int timeout;
346 s32 result = 0; 347 s32 result = 0;
347 348
348 down(&i2c_ali1535_sem); 349 mutex_lock(&i2c_ali1535_mutex);
349 /* make sure SMBus is idle */ 350 /* make sure SMBus is idle */
350 temp = inb_p(SMBHSTSTS); 351 temp = inb_p(SMBHSTSTS);
351 for (timeout = 0; 352 for (timeout = 0;
@@ -460,7 +461,7 @@ static s32 ali1535_access(struct i2c_adapter *adap, u16 addr,
460 break; 461 break;
461 } 462 }
462EXIT: 463EXIT:
463 up(&i2c_ali1535_sem); 464 mutex_unlock(&i2c_ali1535_mutex);
464 return result; 465 return result;
465} 466}
466 467
diff --git a/drivers/i2c/chips/ds1374.c b/drivers/i2c/chips/ds1374.c
index 0710b9da9d54..03d09ed5ec2c 100644
--- a/drivers/i2c/chips/ds1374.c
+++ b/drivers/i2c/chips/ds1374.c
@@ -26,6 +26,7 @@
26#include <linux/i2c.h> 26#include <linux/i2c.h>
27#include <linux/rtc.h> 27#include <linux/rtc.h>
28#include <linux/bcd.h> 28#include <linux/bcd.h>
29#include <linux/mutex.h>
29 30
30#define DS1374_REG_TOD0 0x00 31#define DS1374_REG_TOD0 0x00
31#define DS1374_REG_TOD1 0x01 32#define DS1374_REG_TOD1 0x01
@@ -41,7 +42,7 @@
41 42
42#define DS1374_DRV_NAME "ds1374" 43#define DS1374_DRV_NAME "ds1374"
43 44
44static DECLARE_MUTEX(ds1374_mutex); 45static DEFINE_MUTEX(ds1374_mutex);
45 46
46static struct i2c_driver ds1374_driver; 47static struct i2c_driver ds1374_driver;
47static struct i2c_client *save_client; 48static struct i2c_client *save_client;
@@ -114,7 +115,7 @@ ulong ds1374_get_rtc_time(void)
114 ulong t1, t2; 115 ulong t1, t2;
115 int limit = 10; /* arbitrary retry limit */ 116 int limit = 10; /* arbitrary retry limit */
116 117
117 down(&ds1374_mutex); 118 mutex_lock(&ds1374_mutex);
118 119
119 /* 120 /*
120 * Since the reads are being performed one byte at a time using 121 * Since the reads are being performed one byte at a time using
@@ -127,7 +128,7 @@ ulong ds1374_get_rtc_time(void)
127 t2 = ds1374_read_rtc(); 128 t2 = ds1374_read_rtc();
128 } while (t1 != t2 && limit--); 129 } while (t1 != t2 && limit--);
129 130
130 up(&ds1374_mutex); 131 mutex_unlock(&ds1374_mutex);
131 132
132 if (t1 != t2) { 133 if (t1 != t2) {
133 dev_warn(&save_client->dev, 134 dev_warn(&save_client->dev,
@@ -145,7 +146,7 @@ static void ds1374_set_tlet(ulong arg)
145 146
146 t1 = *(ulong *) arg; 147 t1 = *(ulong *) arg;
147 148
148 down(&ds1374_mutex); 149 mutex_lock(&ds1374_mutex);
149 150
150 /* 151 /*
151 * Since the writes are being performed one byte at a time using 152 * Since the writes are being performed one byte at a time using
@@ -158,7 +159,7 @@ static void ds1374_set_tlet(ulong arg)
158 t2 = ds1374_read_rtc(); 159 t2 = ds1374_read_rtc();
159 } while (t1 != t2 && limit--); 160 } while (t1 != t2 && limit--);
160 161
161 up(&ds1374_mutex); 162 mutex_unlock(&ds1374_mutex);
162 163
163 if (t1 != t2) 164 if (t1 != t2)
164 dev_warn(&save_client->dev, 165 dev_warn(&save_client->dev,
diff --git a/drivers/i2c/chips/m41t00.c b/drivers/i2c/chips/m41t00.c
index 2dc3d48375fc..b5aabe7cf792 100644
--- a/drivers/i2c/chips/m41t00.c
+++ b/drivers/i2c/chips/m41t00.c
@@ -24,13 +24,14 @@
24#include <linux/i2c.h> 24#include <linux/i2c.h>
25#include <linux/rtc.h> 25#include <linux/rtc.h>
26#include <linux/bcd.h> 26#include <linux/bcd.h>
27#include <linux/mutex.h>
27 28
28#include <asm/time.h> 29#include <asm/time.h>
29#include <asm/rtc.h> 30#include <asm/rtc.h>
30 31
31#define M41T00_DRV_NAME "m41t00" 32#define M41T00_DRV_NAME "m41t00"
32 33
33static DECLARE_MUTEX(m41t00_mutex); 34static DEFINE_MUTEX(m41t00_mutex);
34 35
35static struct i2c_driver m41t00_driver; 36static struct i2c_driver m41t00_driver;
36static struct i2c_client *save_client; 37static struct i2c_client *save_client;
@@ -54,7 +55,7 @@ m41t00_get_rtc_time(void)
54 sec = min = hour = day = mon = year = 0; 55 sec = min = hour = day = mon = year = 0;
55 sec1 = min1 = hour1 = day1 = mon1 = year1 = 0; 56 sec1 = min1 = hour1 = day1 = mon1 = year1 = 0;
56 57
57 down(&m41t00_mutex); 58 mutex_lock(&m41t00_mutex);
58 do { 59 do {
59 if (((sec = i2c_smbus_read_byte_data(save_client, 0)) >= 0) 60 if (((sec = i2c_smbus_read_byte_data(save_client, 0)) >= 0)
60 && ((min = i2c_smbus_read_byte_data(save_client, 1)) 61 && ((min = i2c_smbus_read_byte_data(save_client, 1))
@@ -80,7 +81,7 @@ m41t00_get_rtc_time(void)
80 mon1 = mon; 81 mon1 = mon;
81 year1 = year; 82 year1 = year;
82 } while (--limit > 0); 83 } while (--limit > 0);
83 up(&m41t00_mutex); 84 mutex_unlock(&m41t00_mutex);
84 85
85 if (limit == 0) { 86 if (limit == 0) {
86 dev_warn(&save_client->dev, 87 dev_warn(&save_client->dev,
@@ -125,7 +126,7 @@ m41t00_set_tlet(ulong arg)
125 BIN_TO_BCD(tm.tm_mday); 126 BIN_TO_BCD(tm.tm_mday);
126 BIN_TO_BCD(tm.tm_year); 127 BIN_TO_BCD(tm.tm_year);
127 128
128 down(&m41t00_mutex); 129 mutex_lock(&m41t00_mutex);
129 if ((i2c_smbus_write_byte_data(save_client, 0, tm.tm_sec & 0x7f) < 0) 130 if ((i2c_smbus_write_byte_data(save_client, 0, tm.tm_sec & 0x7f) < 0)
130 || (i2c_smbus_write_byte_data(save_client, 1, tm.tm_min & 0x7f) 131 || (i2c_smbus_write_byte_data(save_client, 1, tm.tm_min & 0x7f)
131 < 0) 132 < 0)
@@ -140,7 +141,7 @@ m41t00_set_tlet(ulong arg)
140 141
141 dev_warn(&save_client->dev,"m41t00: can't write to rtc chip\n"); 142 dev_warn(&save_client->dev,"m41t00: can't write to rtc chip\n");
142 143
143 up(&m41t00_mutex); 144 mutex_unlock(&m41t00_mutex);
144 return; 145 return;
145} 146}
146 147
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 1a2c9ab5d9e3..97334433e534 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -31,12 +31,13 @@
31#include <linux/idr.h> 31#include <linux/idr.h>
32#include <linux/seq_file.h> 32#include <linux/seq_file.h>
33#include <linux/platform_device.h> 33#include <linux/platform_device.h>
34#include <linux/mutex.h>
34#include <asm/uaccess.h> 35#include <asm/uaccess.h>
35 36
36 37
37static LIST_HEAD(adapters); 38static LIST_HEAD(adapters);
38static LIST_HEAD(drivers); 39static LIST_HEAD(drivers);
39static DECLARE_MUTEX(core_lists); 40static DEFINE_MUTEX(core_lists);
40static DEFINE_IDR(i2c_adapter_idr); 41static DEFINE_IDR(i2c_adapter_idr);
41 42
42/* match always succeeds, as we want the probe() to tell if we really accept this match */ 43/* 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 struct list_head *item; 154 struct list_head *item;
154 struct i2c_driver *driver; 155 struct i2c_driver *driver;
155 156
156 down(&core_lists); 157 mutex_lock(&core_lists);
157 158
158 if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0) { 159 if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0) {
159 res = -ENOMEM; 160 res = -ENOMEM;
@@ -203,7 +204,7 @@ int i2c_add_adapter(struct i2c_adapter *adap)
203 } 204 }
204 205
205out_unlock: 206out_unlock:
206 up(&core_lists); 207 mutex_unlock(&core_lists);
207 return res; 208 return res;
208} 209}
209 210
@@ -216,7 +217,7 @@ int i2c_del_adapter(struct i2c_adapter *adap)
216 struct i2c_client *client; 217 struct i2c_client *client;
217 int res = 0; 218 int res = 0;
218 219
219 down(&core_lists); 220 mutex_lock(&core_lists);
220 221
221 /* First make sure that this adapter was ever added */ 222 /* First make sure that this adapter was ever added */
222 list_for_each_entry(adap_from_list, &adapters, list) { 223 list_for_each_entry(adap_from_list, &adapters, list) {
@@ -272,7 +273,7 @@ int i2c_del_adapter(struct i2c_adapter *adap)
272 dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name); 273 dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name);
273 274
274 out_unlock: 275 out_unlock:
275 up(&core_lists); 276 mutex_unlock(&core_lists);
276 return res; 277 return res;
277} 278}
278 279
@@ -289,7 +290,7 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
289 struct i2c_adapter *adapter; 290 struct i2c_adapter *adapter;
290 int res = 0; 291 int res = 0;
291 292
292 down(&core_lists); 293 mutex_lock(&core_lists);
293 294
294 /* add the driver to the list of i2c drivers in the driver core */ 295 /* add the driver to the list of i2c drivers in the driver core */
295 driver->driver.owner = owner; 296 driver->driver.owner = owner;
@@ -311,7 +312,7 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
311 } 312 }
312 313
313 out_unlock: 314 out_unlock:
314 up(&core_lists); 315 mutex_unlock(&core_lists);
315 return res; 316 return res;
316} 317}
317EXPORT_SYMBOL(i2c_register_driver); 318EXPORT_SYMBOL(i2c_register_driver);
@@ -324,7 +325,7 @@ int i2c_del_driver(struct i2c_driver *driver)
324 325
325 int res = 0; 326 int res = 0;
326 327
327 down(&core_lists); 328 mutex_lock(&core_lists);
328 329
329 /* Have a look at each adapter, if clients of this driver are still 330 /* Have a look at each adapter, if clients of this driver are still
330 * attached. If so, detach them to be able to kill the driver 331 * 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 pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name); 364 pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name);
364 365
365 out_unlock: 366 out_unlock:
366 up(&core_lists); 367 mutex_unlock(&core_lists);
367 return 0; 368 return 0;
368} 369}
369 370
@@ -779,12 +780,12 @@ struct i2c_adapter* i2c_get_adapter(int id)
779{ 780{
780 struct i2c_adapter *adapter; 781 struct i2c_adapter *adapter;
781 782
782 down(&core_lists); 783 mutex_lock(&core_lists);
783 adapter = (struct i2c_adapter *)idr_find(&i2c_adapter_idr, id); 784 adapter = (struct i2c_adapter *)idr_find(&i2c_adapter_idr, id);
784 if (adapter && !try_module_get(adapter->owner)) 785 if (adapter && !try_module_get(adapter->owner))
785 adapter = NULL; 786 adapter = NULL;
786 787
787 up(&core_lists); 788 mutex_unlock(&core_lists);
788 return adapter; 789 return adapter;
789} 790}
790 791