]> err.no Git - linux-2.6/commitdiff
rtc: convert the PCF8583 driver to the new I2C style framework with device_ids
authorWolfram Sang <w.sang@pengutronix.de>
Thu, 24 Jul 2008 04:30:39 +0000 (21:30 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 24 Jul 2008 17:47:34 +0000 (10:47 -0700)
Convert the PCF8583 driver to the new I2C style framework with device_ids

Signed-off-by: Juergen Beisert <j.beisert@pengutronix.de>
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Signed-off-by: Alessandro Zummo <a.zummo@towertech.it>
Cc: David Brownell <david-b@pacbell.net>
Acked-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/rtc/rtc-pcf8583.c

index 3d09d8f0b1f0244220bcd1562d109664fa87f266..d388c662bf4b6b630909187a9fbc5370e3c97c7f 100644 (file)
@@ -2,6 +2,7 @@
  *  drivers/rtc/rtc-pcf8583.c
  *
  *  Copyright (C) 2000 Russell King
+ *  Copyright (C) 2008 Wolfram Sang & Juergen Beisert, Pengutronix
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -14,7 +15,6 @@
 #include <linux/module.h>
 #include <linux/i2c.h>
 #include <linux/slab.h>
-#include <linux/string.h>
 #include <linux/rtc.h>
 #include <linux/init.h>
 #include <linux/errno.h>
@@ -27,7 +27,6 @@ struct rtc_mem {
 };
 
 struct pcf8583 {
-       struct i2c_client client;
        struct rtc_device *rtc;
        unsigned char ctrl;
 };
@@ -40,10 +39,6 @@ struct pcf8583 {
 #define CTRL_ALARM     0x02
 #define CTRL_TIMER     0x01
 
-static const unsigned short normal_i2c[] = { 0x50, I2C_CLIENT_END };
-
-/* Module parameters */
-I2C_CLIENT_INSMOD;
 
 static struct i2c_driver pcf8583_driver;
 
@@ -269,106 +264,60 @@ static const struct rtc_class_ops pcf8583_rtc_ops = {
        .set_time       = pcf8583_rtc_set_time,
 };
 
-static int pcf8583_probe(struct i2c_adapter *adap, int addr, int kind);
-
-static int pcf8583_attach(struct i2c_adapter *adap)
-{
-       return i2c_probe(adap, &addr_data, pcf8583_probe);
-}
-
-static int pcf8583_detach(struct i2c_client *client)
-{
-       int err;
-       struct pcf8583 *pcf = i2c_get_clientdata(client);
-       struct rtc_device *rtc = pcf->rtc;
-
-       if (rtc)
-               rtc_device_unregister(rtc);
-
-       if ((err = i2c_detach_client(client)))
-               return err;
-
-       kfree(pcf);
-       return 0;
-}
-
-static struct i2c_driver pcf8583_driver = {
-       .driver = {
-               .name   = "pcf8583",
-       },
-       .id             = I2C_DRIVERID_PCF8583,
-       .attach_adapter = pcf8583_attach,
-       .detach_client  = pcf8583_detach,
-};
-
-static int pcf8583_probe(struct i2c_adapter *adap, int addr, int kind)
+static int pcf8583_probe(struct i2c_client *client,
+                               const struct i2c_device_id *id)
 {
-       struct pcf8583 *pcf;
-       struct i2c_client *client;
-       struct rtc_device *rtc;
-       unsigned char buf[1], ad[1] = { 0 };
+       struct pcf8583 *pcf8583;
        int err;
-       struct i2c_msg msgs[2] = {
-               {
-                       .addr = addr,
-                       .flags = 0,
-                       .len = 1,
-                       .buf = ad,
-               }, {
-                       .addr = addr,
-                       .flags = I2C_M_RD,
-                       .len = 1,
-                       .buf = buf,
-               }
-       };
 
-       if (!i2c_check_functionality(adap, I2C_FUNC_I2C))
-               return 0;
+       if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
+               return -ENODEV;
 
-       pcf = kzalloc(sizeof(*pcf), GFP_KERNEL);
-       if (!pcf)
+       pcf8583 = kzalloc(sizeof(struct pcf8583), GFP_KERNEL);
+       if (!pcf8583)
                return -ENOMEM;
 
-       client = &pcf->client;
+       pcf8583->rtc = rtc_device_register(pcf8583_driver.driver.name,
+                       &client->dev, &pcf8583_rtc_ops, THIS_MODULE);
 
-       client->addr            = addr;
-       client->adapter = adap;
-       client->driver  = &pcf8583_driver;
-
-       strlcpy(client->name, pcf8583_driver.driver.name, I2C_NAME_SIZE);
-
-       if (i2c_transfer(client->adapter, msgs, 2) != 2) {
-               err = -EIO;
+       if (IS_ERR(pcf8583->rtc)) {
+               err = PTR_ERR(pcf8583->rtc);
                goto exit_kfree;
        }
 
-       err = i2c_attach_client(client);
-
-       if (err)
-               goto exit_kfree;
-
-       rtc = rtc_device_register(pcf8583_driver.driver.name, &client->dev,
-                                 &pcf8583_rtc_ops, THIS_MODULE);
+       i2c_set_clientdata(client, pcf8583);
+       return 0;
 
-       if (IS_ERR(rtc)) {
-               err = PTR_ERR(rtc);
-               goto exit_detach;
-       }
+exit_kfree:
+       kfree(pcf8583);
+       return err;
+}
 
-       pcf->rtc = rtc;
-       i2c_set_clientdata(client, pcf);
-       set_ctrl(client, buf[0]);
+static int __devexit pcf8583_remove(struct i2c_client *client)
+{
+       struct pcf8583 *pcf8583 = i2c_get_clientdata(client);
 
+       if (pcf8583->rtc)
+               rtc_device_unregister(pcf8583->rtc);
+       kfree(pcf8583);
        return 0;
+}
 
-exit_detach:
-       i2c_detach_client(client);
-
-exit_kfree:
-       kfree(pcf);
+static const struct i2c_device_id pcf8583_id[] = {
+       { "pcf8583", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, pcf8583_id);
 
-       return err;
-}
+static struct i2c_driver pcf8583_driver = {
+       .driver = {
+               .name   = "pcf8583",
+               .owner  = THIS_MODULE,
+       },
+       .probe          = pcf8583_probe,
+       .remove         = __devexit_p(pcf8583_remove),
+       .id_table       = pcf8583_id,
+};
 
 static __init int pcf8583_init(void)
 {