2 drivers/rtc/rtc-pcf8563.c | 109 +++++++++++++---------------------------------
3 1 file changed, 32 insertions(+), 77 deletions(-)
5 --- a/drivers/rtc/rtc-pcf8563.c
6 +++ b/drivers/rtc/rtc-pcf8563.c
11 -#define DRV_VERSION "0.4.2"
13 -/* Addresses to scan: none
14 - * This chip cannot be reliably autodetected. An empty eeprom
15 - * located at 0x51 will pass the validation routine due to
16 - * the way the registers are implemented.
18 -static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
20 -/* Module parameters */
22 +#define DRV_VERSION "0.4.3"
24 #define PCF8563_REG_ST1 0x00 /* status */
25 #define PCF8563_REG_ST2 0x01
27 #define PCF8563_SC_LV 0x80 /* low voltage */
28 #define PCF8563_MO_C 0x80 /* century */
30 +static struct i2c_driver pcf8563_driver;
33 - struct i2c_client client;
34 + struct rtc_device *rtc;
36 * The meaning of MO_C bit varies by the chip type.
37 * From PCF8563 datasheet: this bit is toggled when the years
39 int c_polarity; /* 0: MO_C=1 means 19xx, otherwise MO_C=1 means 20xx */
42 -static int pcf8563_probe(struct i2c_adapter *adapter, int address, int kind);
43 -static int pcf8563_detach(struct i2c_client *client);
46 * In the routines that deal directly with the pcf8563 hardware, we use
47 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
49 static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
51 - struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client);
52 + struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
53 unsigned char buf[13] = { PCF8563_REG_ST1 };
55 struct i2c_msg msgs[] = {
58 static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm)
60 - struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client);
61 + struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
65 @@ -257,100 +246,66 @@
66 .set_time = pcf8563_rtc_set_time,
69 -static int pcf8563_attach(struct i2c_adapter *adapter)
71 - return i2c_probe(adapter, &addr_data, pcf8563_probe);
74 -static struct i2c_driver pcf8563_driver = {
78 - .id = I2C_DRIVERID_PCF8563,
79 - .attach_adapter = &pcf8563_attach,
80 - .detach_client = &pcf8563_detach,
83 -static int pcf8563_probe(struct i2c_adapter *adapter, int address, int kind)
84 +static int pcf8563_probe(struct i2c_client *client)
86 struct pcf8563 *pcf8563;
87 - struct i2c_client *client;
88 - struct rtc_device *rtc;
92 - dev_dbg(&adapter->dev, "%s\n", __FUNCTION__);
93 + dev_dbg(&client->dev, "%s\n", __FUNCTION__);
95 - if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
99 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
102 - if (!(pcf8563 = kzalloc(sizeof(struct pcf8563), GFP_KERNEL))) {
107 - client = &pcf8563->client;
108 - client->addr = address;
109 - client->driver = &pcf8563_driver;
110 - client->adapter = adapter;
112 - strlcpy(client->name, pcf8563_driver.driver.name, I2C_NAME_SIZE);
113 + if (!(pcf8563 = kzalloc(sizeof(struct pcf8563), GFP_KERNEL)))
116 /* Verify the chip is really an PCF8563 */
118 - if (pcf8563_validate_client(client) < 0) {
124 - /* Inform the i2c layer */
125 - if ((err = i2c_attach_client(client)))
126 + if (pcf8563_validate_client(client) < 0) {
131 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
133 - rtc = rtc_device_register(pcf8563_driver.driver.name, &client->dev,
134 + pcf8563->rtc = rtc_device_register(pcf8563_driver.driver.name, &client->dev,
135 &pcf8563_rtc_ops, THIS_MODULE);
138 - err = PTR_ERR(rtc);
140 + if (IS_ERR(pcf8563->rtc)) {
141 + err = PTR_ERR(pcf8563->rtc);
145 - i2c_set_clientdata(client, rtc);
146 + i2c_set_clientdata(client, pcf8563);
151 - i2c_detach_client(client);
160 -static int pcf8563_detach(struct i2c_client *client)
161 +static int pcf8563_remove(struct i2c_client *client)
163 - struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client);
165 - struct rtc_device *rtc = i2c_get_clientdata(client);
166 + struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
169 - rtc_device_unregister(rtc);
171 - if ((err = i2c_detach_client(client)))
174 + rtc_device_unregister(pcf8563->rtc);
181 +static struct i2c_driver pcf8563_driver = {
183 + .name = "rtc-pcf8563",
185 + .probe = pcf8563_probe,
186 + .remove = pcf8563_remove,
189 static int __init pcf8563_init(void)
191 return i2c_add_driver(&pcf8563_driver);