Pull bugzilla-5452 into release branch
[pandora-kernel.git] / drivers / i2c / chips / ds1374.c
index 0936327..4630f19 100644 (file)
@@ -26,6 +26,8 @@
 #include <linux/i2c.h>
 #include <linux/rtc.h>
 #include <linux/bcd.h>
+#include <linux/mutex.h>
+#include <linux/workqueue.h>
 
 #define DS1374_REG_TOD0                0x00
 #define DS1374_REG_TOD1                0x01
@@ -41,7 +43,7 @@
 
 #define        DS1374_DRV_NAME         "ds1374"
 
-static DECLARE_MUTEX(ds1374_mutex);
+static DEFINE_MUTEX(ds1374_mutex);
 
 static struct i2c_driver ds1374_driver;
 static struct i2c_client *save_client;
@@ -114,7 +116,7 @@ ulong ds1374_get_rtc_time(void)
        ulong t1, t2;
        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
@@ -127,7 +129,7 @@ ulong ds1374_get_rtc_time(void)
                t2 = ds1374_read_rtc();
        } while (t1 != t2 && limit--);
 
-       up(&ds1374_mutex);
+       mutex_unlock(&ds1374_mutex);
 
        if (t1 != t2) {
                dev_warn(&save_client->dev,
@@ -138,14 +140,14 @@ ulong ds1374_get_rtc_time(void)
        return t1;
 }
 
-static void ds1374_set_tlet(ulong arg)
+static void ds1374_set_work(void *arg)
 {
        ulong t1, t2;
        int limit = 10;         /* arbitrary retry limit */
 
        t1 = *(ulong *) arg;
 
-       down(&ds1374_mutex);
+       mutex_lock(&ds1374_mutex);
 
        /*
         * Since the writes are being performed one byte at a time using
@@ -158,7 +160,7 @@ static void ds1374_set_tlet(ulong arg)
                t2 = ds1374_read_rtc();
        } while (t1 != t2 && limit--);
 
-       up(&ds1374_mutex);
+       mutex_unlock(&ds1374_mutex);
 
        if (t1 != t2)
                dev_warn(&save_client->dev,
@@ -167,16 +169,18 @@ static void ds1374_set_tlet(ulong arg)
 
 static ulong new_time;
 
-DECLARE_TASKLET_DISABLED(ds1374_tasklet, ds1374_set_tlet, (ulong) & new_time);
+static struct workqueue_struct *ds1374_workqueue;
+
+static DECLARE_WORK(ds1374_work, ds1374_set_work, &new_time);
 
 int ds1374_set_rtc_time(ulong nowtime)
 {
        new_time = nowtime;
 
        if (in_interrupt())
-               tasklet_schedule(&ds1374_tasklet);
+               queue_work(ds1374_workqueue, &ds1374_work);
        else
-               ds1374_set_tlet((ulong) & new_time);
+               ds1374_set_work(&new_time);
 
        return 0;
 }
@@ -193,17 +197,17 @@ static int ds1374_probe(struct i2c_adapter *adap, int addr, int kind)
        struct i2c_client *client;
        int rc;
 
-       client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
+       client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
        if (!client)
                return -ENOMEM;
 
-       memset(client, 0, sizeof(struct i2c_client));
        strncpy(client->name, DS1374_DRV_NAME, I2C_NAME_SIZE);
-       client->flags = I2C_DF_NOTIFY;
        client->addr = addr;
        client->adapter = adap;
        client->driver = &ds1374_driver;
 
+       ds1374_workqueue = create_singlethread_workqueue("ds1374");
+
        if ((rc = i2c_attach_client(client)) != 0) {
                kfree(client);
                return rc;
@@ -227,16 +231,16 @@ static int ds1374_detach(struct i2c_client *client)
 
        if ((rc = i2c_detach_client(client)) == 0) {
                kfree(i2c_get_clientdata(client));
-               tasklet_kill(&ds1374_tasklet);
+               destroy_workqueue(ds1374_workqueue);
        }
        return rc;
 }
 
 static struct i2c_driver ds1374_driver = {
-       .owner = THIS_MODULE,
-       .name = DS1374_DRV_NAME,
+       .driver = {
+               .name   = DS1374_DRV_NAME,
+       },
        .id = I2C_DRIVERID_DS1374,
-       .flags = I2C_DF_NOTIFY,
        .attach_adapter = ds1374_attach,
        .detach_client = ds1374_detach,
 };