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: 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>
This commit is contained in:
committed by
Linus Torvalds
parent
71fc822455
commit
02bb584f3b
@@ -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 @@
|
|||||||
#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 {
|
|||||||
};
|
};
|
||||||
|
|
||||||
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 {
|
|||||||
#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,107 +264,61 @@ 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);
|
struct pcf8583 *pcf8583;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
|
||||||
|
return -ENODEV;
|
||||||
|
|
||||||
|
pcf8583 = kzalloc(sizeof(struct pcf8583), GFP_KERNEL);
|
||||||
|
if (!pcf8583)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
pcf8583->rtc = rtc_device_register(pcf8583_driver.driver.name,
|
||||||
|
&client->dev, &pcf8583_rtc_ops, THIS_MODULE);
|
||||||
|
|
||||||
|
if (IS_ERR(pcf8583->rtc)) {
|
||||||
|
err = PTR_ERR(pcf8583->rtc);
|
||||||
|
goto exit_kfree;
|
||||||
|
}
|
||||||
|
|
||||||
|
i2c_set_clientdata(client, pcf8583);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
exit_kfree:
|
||||||
|
kfree(pcf8583);
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pcf8583_detach(struct i2c_client *client)
|
static int __devexit pcf8583_remove(struct i2c_client *client)
|
||||||
{
|
{
|
||||||
int err;
|
struct pcf8583 *pcf8583 = i2c_get_clientdata(client);
|
||||||
struct pcf8583 *pcf = i2c_get_clientdata(client);
|
|
||||||
struct rtc_device *rtc = pcf->rtc;
|
|
||||||
|
|
||||||
if (rtc)
|
if (pcf8583->rtc)
|
||||||
rtc_device_unregister(rtc);
|
rtc_device_unregister(pcf8583->rtc);
|
||||||
|
kfree(pcf8583);
|
||||||
if ((err = i2c_detach_client(client)))
|
|
||||||
return err;
|
|
||||||
|
|
||||||
kfree(pcf);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct i2c_device_id pcf8583_id[] = {
|
||||||
|
{ "pcf8583", 0 },
|
||||||
|
{ }
|
||||||
|
};
|
||||||
|
MODULE_DEVICE_TABLE(i2c, pcf8583_id);
|
||||||
|
|
||||||
static struct i2c_driver pcf8583_driver = {
|
static struct i2c_driver pcf8583_driver = {
|
||||||
.driver = {
|
.driver = {
|
||||||
.name = "pcf8583",
|
.name = "pcf8583",
|
||||||
|
.owner = THIS_MODULE,
|
||||||
},
|
},
|
||||||
.id = I2C_DRIVERID_PCF8583,
|
.probe = pcf8583_probe,
|
||||||
.attach_adapter = pcf8583_attach,
|
.remove = __devexit_p(pcf8583_remove),
|
||||||
.detach_client = pcf8583_detach,
|
.id_table = pcf8583_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int pcf8583_probe(struct i2c_adapter *adap, int addr, int kind)
|
|
||||||
{
|
|
||||||
struct pcf8583 *pcf;
|
|
||||||
struct i2c_client *client;
|
|
||||||
struct rtc_device *rtc;
|
|
||||||
unsigned char buf[1], ad[1] = { 0 };
|
|
||||||
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;
|
|
||||||
|
|
||||||
pcf = kzalloc(sizeof(*pcf), GFP_KERNEL);
|
|
||||||
if (!pcf)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
client = &pcf->client;
|
|
||||||
|
|
||||||
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;
|
|
||||||
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);
|
|
||||||
|
|
||||||
if (IS_ERR(rtc)) {
|
|
||||||
err = PTR_ERR(rtc);
|
|
||||||
goto exit_detach;
|
|
||||||
}
|
|
||||||
|
|
||||||
pcf->rtc = rtc;
|
|
||||||
i2c_set_clientdata(client, pcf);
|
|
||||||
set_ctrl(client, buf[0]);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
exit_detach:
|
|
||||||
i2c_detach_client(client);
|
|
||||||
|
|
||||||
exit_kfree:
|
|
||||||
kfree(pcf);
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
static __init int pcf8583_init(void)
|
static __init int pcf8583_init(void)
|
||||||
{
|
{
|
||||||
return i2c_add_driver(&pcf8583_driver);
|
return i2c_add_driver(&pcf8583_driver);
|
||||||
|
Reference in New Issue
Block a user