From 02bb584f3b1cfc8188522a4d2c8881b65073a4f1 Mon Sep 17 00:00:00 2001 From: Wolfram Sang Date: Wed, 23 Jul 2008 21:30:39 -0700 Subject: 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 Signed-off-by: Wolfram Sang Signed-off-by: Alessandro Zummo Cc: David Brownell Acked-by: Jean Delvare Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/rtc/rtc-pcf8583.c | 129 ++++++++++++++-------------------------------- 1 file changed, 39 insertions(+), 90 deletions(-) (limited to 'drivers/rtc') diff --git a/drivers/rtc/rtc-pcf8583.c b/drivers/rtc/rtc-pcf8583.c index 3d09d8f0b1f..d388c662bf4 100644 --- a/drivers/rtc/rtc-pcf8583.c +++ b/drivers/rtc/rtc-pcf8583.c @@ -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 #include #include -#include #include #include #include @@ -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) { -- cgit v1.2.3