Commit 02bb584f authored by Wolfram Sang's avatar Wolfram Sang Committed by Linus Torvalds

rtc: convert the PCF8583 driver to the new I2C style framework with device_ids

Convert the PCF8583 driver to the new I2C style framework with device_ids
Signed-off-by: default avatarJuergen Beisert <j.beisert@pengutronix.de>
Signed-off-by: default avatarWolfram Sang <w.sang@pengutronix.de>
Signed-off-by: default avatarAlessandro Zummo <a.zummo@towertech.it>
Cc: David Brownell <david-b@pacbell.net>
Acked-by: default avatarJean Delvare <khali@linux-fr.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 71fc8224
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* drivers/rtc/rtc-pcf8583.c * drivers/rtc/rtc-pcf8583.c
* *
* Copyright (C) 2000 Russell King * 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 * 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 * it under the terms of the GNU General Public License version 2 as
...@@ -14,7 +15,6 @@ ...@@ -14,7 +15,6 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/string.h>
#include <linux/rtc.h> #include <linux/rtc.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/errno.h> #include <linux/errno.h>
...@@ -27,7 +27,6 @@ struct rtc_mem { ...@@ -27,7 +27,6 @@ struct rtc_mem {
}; };
struct pcf8583 { struct pcf8583 {
struct i2c_client client;
struct rtc_device *rtc; struct rtc_device *rtc;
unsigned char ctrl; unsigned char ctrl;
}; };
...@@ -40,10 +39,6 @@ struct pcf8583 { ...@@ -40,10 +39,6 @@ struct pcf8583 {
#define CTRL_ALARM 0x02 #define CTRL_ALARM 0x02
#define CTRL_TIMER 0x01 #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; static struct i2c_driver pcf8583_driver;
...@@ -269,106 +264,60 @@ static const struct rtc_class_ops pcf8583_rtc_ops = { ...@@ -269,106 +264,60 @@ static const struct rtc_class_ops pcf8583_rtc_ops = {
.set_time = pcf8583_rtc_set_time, .set_time = pcf8583_rtc_set_time,
}; };
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)
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)
{ {
struct pcf8583 *pcf; struct pcf8583 *pcf8583;
struct i2c_client *client;
struct rtc_device *rtc;
unsigned char buf[1], ad[1] = { 0 };
int err; 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)) if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
return 0; return -ENODEV;
pcf = kzalloc(sizeof(*pcf), GFP_KERNEL); pcf8583 = kzalloc(sizeof(struct pcf8583), GFP_KERNEL);
if (!pcf) if (!pcf8583)
return -ENOMEM; return -ENOMEM;
client = &pcf->client; pcf8583->rtc = rtc_device_register(pcf8583_driver.driver.name,
&client->dev, &pcf8583_rtc_ops, THIS_MODULE);
client->addr = addr; if (IS_ERR(pcf8583->rtc)) {
client->adapter = adap; err = PTR_ERR(pcf8583->rtc);
client->driver = &pcf8583_driver;
strlcpy(client->name, pcf8583_driver.driver.name, I2C_NAME_SIZE);
if (i2c_transfer(client->adapter, msgs, 2) != 2) {
err = -EIO;
goto exit_kfree; goto exit_kfree;
} }
err = i2c_attach_client(client); i2c_set_clientdata(client, pcf8583);
return 0;
if (err)
goto exit_kfree;
rtc = rtc_device_register(pcf8583_driver.driver.name, &client->dev,
&pcf8583_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc)) { exit_kfree:
err = PTR_ERR(rtc); kfree(pcf8583);
goto exit_detach; return err;
} }
pcf->rtc = rtc; static int __devexit pcf8583_remove(struct i2c_client *client)
i2c_set_clientdata(client, pcf); {
set_ctrl(client, buf[0]); struct pcf8583 *pcf8583 = i2c_get_clientdata(client);
if (pcf8583->rtc)
rtc_device_unregister(pcf8583->rtc);
kfree(pcf8583);
return 0; return 0;
}
exit_detach: static const struct i2c_device_id pcf8583_id[] = {
i2c_detach_client(client); { "pcf8583", 0 },
{ }
exit_kfree: };
kfree(pcf); 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) static __init int pcf8583_init(void)
{ {
......
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