diff options
author | Jeff Garzik <jgarzik@pobox.com> | 2005-10-28 18:48:57 -0400 |
---|---|---|
committer | Jeff Garzik <jgarzik@pobox.com> | 2005-10-28 18:48:57 -0400 |
commit | 596c96ba06e5d56e72451e02f93f4e15e17458df (patch) | |
tree | 78bc640acacb8faeb621c51296e99dbb0533a147 /drivers/i2c/chips | |
parent | ad18b0ea089928367185e13d11424aea91d4b41f (diff) | |
parent | 20731945ae743034353a88c307920d1f16cf8ac8 (diff) |
Merge branch 'master'
Diffstat (limited to 'drivers/i2c/chips')
-rw-r--r-- | drivers/i2c/chips/Kconfig | 9 | ||||
-rw-r--r-- | drivers/i2c/chips/Makefile | 1 | ||||
-rw-r--r-- | drivers/i2c/chips/ds1337.c | 3 | ||||
-rw-r--r-- | drivers/i2c/chips/ds1374.c | 7 | ||||
-rw-r--r-- | drivers/i2c/chips/eeprom.c | 9 | ||||
-rw-r--r-- | drivers/i2c/chips/isp1301_omap.c | 1 | ||||
-rw-r--r-- | drivers/i2c/chips/m41t00.c | 4 | ||||
-rw-r--r-- | drivers/i2c/chips/max6875.c | 6 | ||||
-rw-r--r-- | drivers/i2c/chips/pca9539.c | 3 | ||||
-rw-r--r-- | drivers/i2c/chips/pcf8574.c | 5 | ||||
-rw-r--r-- | drivers/i2c/chips/pcf8591.c | 5 | ||||
-rw-r--r-- | drivers/i2c/chips/rtc8564.c | 5 | ||||
-rw-r--r-- | drivers/i2c/chips/tps65010.c | 3 | ||||
-rw-r--r-- | drivers/i2c/chips/x1205.c | 698 |
14 files changed, 728 insertions, 31 deletions
diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig index 6bd44a44cd28..f9fae28f5612 100644 --- a/drivers/i2c/chips/Kconfig +++ b/drivers/i2c/chips/Kconfig | |||
@@ -126,4 +126,13 @@ config SENSORS_MAX6875 | |||
126 | This driver can also be built as a module. If so, the module | 126 | This driver can also be built as a module. If so, the module |
127 | will be called max6875. | 127 | will be called max6875. |
128 | 128 | ||
129 | config RTC_X1205_I2C | ||
130 | tristate "Xicor X1205 RTC chip" | ||
131 | depends on I2C && EXPERIMENTAL | ||
132 | help | ||
133 | If you say yes here you get support for the Xicor X1205 RTC chip. | ||
134 | |||
135 | This driver can also be built as a module. If so, the module | ||
136 | will be called x1205. | ||
137 | |||
129 | endmenu | 138 | endmenu |
diff --git a/drivers/i2c/chips/Makefile b/drivers/i2c/chips/Makefile index a876dd42b860..46178b57b1f1 100644 --- a/drivers/i2c/chips/Makefile +++ b/drivers/i2c/chips/Makefile | |||
@@ -13,6 +13,7 @@ obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o | |||
13 | obj-$(CONFIG_SENSORS_RTC8564) += rtc8564.o | 13 | obj-$(CONFIG_SENSORS_RTC8564) += rtc8564.o |
14 | obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o | 14 | obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o |
15 | obj-$(CONFIG_TPS65010) += tps65010.o | 15 | obj-$(CONFIG_TPS65010) += tps65010.o |
16 | obj-$(CONFIG_RTC_X1205_I2C) += x1205.o | ||
16 | 17 | ||
17 | ifeq ($(CONFIG_I2C_DEBUG_CHIP),y) | 18 | ifeq ($(CONFIG_I2C_DEBUG_CHIP),y) |
18 | EXTRA_CFLAGS += -DDEBUG | 19 | EXTRA_CFLAGS += -DDEBUG |
diff --git a/drivers/i2c/chips/ds1337.c b/drivers/i2c/chips/ds1337.c index 9d3175c03395..01b037007410 100644 --- a/drivers/i2c/chips/ds1337.c +++ b/drivers/i2c/chips/ds1337.c | |||
@@ -243,11 +243,10 @@ static int ds1337_detect(struct i2c_adapter *adapter, int address, int kind) | |||
243 | I2C_FUNC_I2C)) | 243 | I2C_FUNC_I2C)) |
244 | goto exit; | 244 | goto exit; |
245 | 245 | ||
246 | if (!(data = kmalloc(sizeof(struct ds1337_data), GFP_KERNEL))) { | 246 | if (!(data = kzalloc(sizeof(struct ds1337_data), GFP_KERNEL))) { |
247 | err = -ENOMEM; | 247 | err = -ENOMEM; |
248 | goto exit; | 248 | goto exit; |
249 | } | 249 | } |
250 | memset(data, 0, sizeof(struct ds1337_data)); | ||
251 | INIT_LIST_HEAD(&data->list); | 250 | INIT_LIST_HEAD(&data->list); |
252 | 251 | ||
253 | /* The common I2C client data is placed right before the | 252 | /* The common I2C client data is placed right before the |
diff --git a/drivers/i2c/chips/ds1374.c b/drivers/i2c/chips/ds1374.c index 0936327a946d..da488b735abf 100644 --- a/drivers/i2c/chips/ds1374.c +++ b/drivers/i2c/chips/ds1374.c | |||
@@ -167,7 +167,8 @@ static void ds1374_set_tlet(ulong arg) | |||
167 | 167 | ||
168 | static ulong new_time; | 168 | static ulong new_time; |
169 | 169 | ||
170 | DECLARE_TASKLET_DISABLED(ds1374_tasklet, ds1374_set_tlet, (ulong) & new_time); | 170 | static DECLARE_TASKLET_DISABLED(ds1374_tasklet, ds1374_set_tlet, |
171 | (ulong) & new_time); | ||
171 | 172 | ||
172 | int ds1374_set_rtc_time(ulong nowtime) | 173 | int ds1374_set_rtc_time(ulong nowtime) |
173 | { | 174 | { |
@@ -193,13 +194,11 @@ static int ds1374_probe(struct i2c_adapter *adap, int addr, int kind) | |||
193 | struct i2c_client *client; | 194 | struct i2c_client *client; |
194 | int rc; | 195 | int rc; |
195 | 196 | ||
196 | client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL); | 197 | client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); |
197 | if (!client) | 198 | if (!client) |
198 | return -ENOMEM; | 199 | return -ENOMEM; |
199 | 200 | ||
200 | memset(client, 0, sizeof(struct i2c_client)); | ||
201 | strncpy(client->name, DS1374_DRV_NAME, I2C_NAME_SIZE); | 201 | strncpy(client->name, DS1374_DRV_NAME, I2C_NAME_SIZE); |
202 | client->flags = I2C_DF_NOTIFY; | ||
203 | client->addr = addr; | 202 | client->addr = addr; |
204 | client->adapter = adap; | 203 | client->adapter = adap; |
205 | client->driver = &ds1374_driver; | 204 | client->driver = &ds1374_driver; |
diff --git a/drivers/i2c/chips/eeprom.c b/drivers/i2c/chips/eeprom.c index d58403a47908..4baf573fa04f 100644 --- a/drivers/i2c/chips/eeprom.c +++ b/drivers/i2c/chips/eeprom.c | |||
@@ -88,8 +88,8 @@ static void eeprom_update_client(struct i2c_client *client, u8 slice) | |||
88 | dev_dbg(&client->dev, "Starting eeprom update, slice %u\n", slice); | 88 | dev_dbg(&client->dev, "Starting eeprom update, slice %u\n", slice); |
89 | 89 | ||
90 | if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { | 90 | if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { |
91 | for (i = slice << 5; i < (slice + 1) << 5; i += I2C_SMBUS_I2C_BLOCK_MAX) | 91 | for (i = slice << 5; i < (slice + 1) << 5; i += I2C_SMBUS_BLOCK_MAX) |
92 | if (i2c_smbus_read_i2c_block_data(client, i, data->data + i) != I2C_SMBUS_I2C_BLOCK_MAX) | 92 | if (i2c_smbus_read_i2c_block_data(client, i, data->data + i) != I2C_SMBUS_BLOCK_MAX) |
93 | goto exit; | 93 | goto exit; |
94 | } else { | 94 | } else { |
95 | if (i2c_smbus_write_byte(client, slice << 5)) { | 95 | if (i2c_smbus_write_byte(client, slice << 5)) { |
@@ -155,7 +155,7 @@ static int eeprom_attach_adapter(struct i2c_adapter *adapter) | |||
155 | } | 155 | } |
156 | 156 | ||
157 | /* This function is called by i2c_probe */ | 157 | /* This function is called by i2c_probe */ |
158 | int eeprom_detect(struct i2c_adapter *adapter, int address, int kind) | 158 | static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind) |
159 | { | 159 | { |
160 | struct i2c_client *new_client; | 160 | struct i2c_client *new_client; |
161 | struct eeprom_data *data; | 161 | struct eeprom_data *data; |
@@ -171,11 +171,10 @@ int eeprom_detect(struct i2c_adapter *adapter, int address, int kind) | |||
171 | | I2C_FUNC_SMBUS_BYTE)) | 171 | | I2C_FUNC_SMBUS_BYTE)) |
172 | goto exit; | 172 | goto exit; |
173 | 173 | ||
174 | if (!(data = kmalloc(sizeof(struct eeprom_data), GFP_KERNEL))) { | 174 | if (!(data = kzalloc(sizeof(struct eeprom_data), GFP_KERNEL))) { |
175 | err = -ENOMEM; | 175 | err = -ENOMEM; |
176 | goto exit; | 176 | goto exit; |
177 | } | 177 | } |
178 | memset(data, 0, sizeof(struct eeprom_data)); | ||
179 | 178 | ||
180 | new_client = &data->client; | 179 | new_client = &data->client; |
181 | memset(data->data, 0xff, EEPROM_SIZE); | 180 | memset(data->data, 0xff, EEPROM_SIZE); |
diff --git a/drivers/i2c/chips/isp1301_omap.c b/drivers/i2c/chips/isp1301_omap.c index 8ee56d4b3891..eaa4742e04fa 100644 --- a/drivers/i2c/chips/isp1301_omap.c +++ b/drivers/i2c/chips/isp1301_omap.c | |||
@@ -888,6 +888,7 @@ static int otg_remove(struct device *dev) | |||
888 | } | 888 | } |
889 | 889 | ||
890 | struct device_driver omap_otg_driver = { | 890 | struct device_driver omap_otg_driver = { |
891 | .owner = THIS_MODULE, | ||
891 | .name = "omap_otg", | 892 | .name = "omap_otg", |
892 | .bus = &platform_bus_type, | 893 | .bus = &platform_bus_type, |
893 | .probe = otg_probe, | 894 | .probe = otg_probe, |
diff --git a/drivers/i2c/chips/m41t00.c b/drivers/i2c/chips/m41t00.c index 3f14528a52a9..3df309ae44a6 100644 --- a/drivers/i2c/chips/m41t00.c +++ b/drivers/i2c/chips/m41t00.c | |||
@@ -174,13 +174,11 @@ m41t00_probe(struct i2c_adapter *adap, int addr, int kind) | |||
174 | struct i2c_client *client; | 174 | struct i2c_client *client; |
175 | int rc; | 175 | int rc; |
176 | 176 | ||
177 | client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL); | 177 | client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); |
178 | if (!client) | 178 | if (!client) |
179 | return -ENOMEM; | 179 | return -ENOMEM; |
180 | 180 | ||
181 | memset(client, 0, sizeof(struct i2c_client)); | ||
182 | strncpy(client->name, M41T00_DRV_NAME, I2C_NAME_SIZE); | 181 | strncpy(client->name, M41T00_DRV_NAME, I2C_NAME_SIZE); |
183 | client->flags = I2C_DF_NOTIFY; | ||
184 | client->addr = addr; | 182 | client->addr = addr; |
185 | client->adapter = adap; | 183 | client->adapter = adap; |
186 | client->driver = &m41t00_driver; | 184 | client->driver = &m41t00_driver; |
diff --git a/drivers/i2c/chips/max6875.c b/drivers/i2c/chips/max6875.c index 9e1aeb69abf9..b376a006883c 100644 --- a/drivers/i2c/chips/max6875.c +++ b/drivers/i2c/chips/max6875.c | |||
@@ -179,16 +179,14 @@ static int max6875_detect(struct i2c_adapter *adapter, int address, int kind) | |||
179 | if (address & 1) | 179 | if (address & 1) |
180 | return 0; | 180 | return 0; |
181 | 181 | ||
182 | if (!(data = kmalloc(sizeof(struct max6875_data), GFP_KERNEL))) | 182 | if (!(data = kzalloc(sizeof(struct max6875_data), GFP_KERNEL))) |
183 | return -ENOMEM; | 183 | return -ENOMEM; |
184 | memset(data, 0, sizeof(struct max6875_data)); | ||
185 | 184 | ||
186 | /* A fake client is created on the odd address */ | 185 | /* A fake client is created on the odd address */ |
187 | if (!(fake_client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL))) { | 186 | if (!(fake_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL))) { |
188 | err = -ENOMEM; | 187 | err = -ENOMEM; |
189 | goto exit_kfree1; | 188 | goto exit_kfree1; |
190 | } | 189 | } |
191 | memset(fake_client, 0, sizeof(struct i2c_client)); | ||
192 | 190 | ||
193 | /* Init real i2c_client */ | 191 | /* Init real i2c_client */ |
194 | real_client = &data->client; | 192 | real_client = &data->client; |
diff --git a/drivers/i2c/chips/pca9539.c b/drivers/i2c/chips/pca9539.c index 225577fdda4d..59a930346229 100644 --- a/drivers/i2c/chips/pca9539.c +++ b/drivers/i2c/chips/pca9539.c | |||
@@ -122,11 +122,10 @@ static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind) | |||
122 | 122 | ||
123 | /* OK. For now, we presume we have a valid client. We now create the | 123 | /* OK. For now, we presume we have a valid client. We now create the |
124 | client structure, even though we cannot fill it completely yet. */ | 124 | client structure, even though we cannot fill it completely yet. */ |
125 | if (!(data = kmalloc(sizeof(struct pca9539_data), GFP_KERNEL))) { | 125 | if (!(data = kzalloc(sizeof(struct pca9539_data), GFP_KERNEL))) { |
126 | err = -ENOMEM; | 126 | err = -ENOMEM; |
127 | goto exit; | 127 | goto exit; |
128 | } | 128 | } |
129 | memset(data, 0, sizeof(struct pca9539_data)); | ||
130 | 129 | ||
131 | new_client = &data->client; | 130 | new_client = &data->client; |
132 | i2c_set_clientdata(new_client, data); | 131 | i2c_set_clientdata(new_client, data); |
diff --git a/drivers/i2c/chips/pcf8574.c b/drivers/i2c/chips/pcf8574.c index 6525743ff9fd..c323c2de236c 100644 --- a/drivers/i2c/chips/pcf8574.c +++ b/drivers/i2c/chips/pcf8574.c | |||
@@ -115,7 +115,7 @@ static int pcf8574_attach_adapter(struct i2c_adapter *adapter) | |||
115 | } | 115 | } |
116 | 116 | ||
117 | /* This function is called by i2c_probe */ | 117 | /* This function is called by i2c_probe */ |
118 | int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind) | 118 | static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind) |
119 | { | 119 | { |
120 | struct i2c_client *new_client; | 120 | struct i2c_client *new_client; |
121 | struct pcf8574_data *data; | 121 | struct pcf8574_data *data; |
@@ -127,11 +127,10 @@ int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind) | |||
127 | 127 | ||
128 | /* OK. For now, we presume we have a valid client. We now create the | 128 | /* OK. For now, we presume we have a valid client. We now create the |
129 | client structure, even though we cannot fill it completely yet. */ | 129 | client structure, even though we cannot fill it completely yet. */ |
130 | if (!(data = kmalloc(sizeof(struct pcf8574_data), GFP_KERNEL))) { | 130 | if (!(data = kzalloc(sizeof(struct pcf8574_data), GFP_KERNEL))) { |
131 | err = -ENOMEM; | 131 | err = -ENOMEM; |
132 | goto exit; | 132 | goto exit; |
133 | } | 133 | } |
134 | memset(data, 0, sizeof(struct pcf8574_data)); | ||
135 | 134 | ||
136 | new_client = &data->client; | 135 | new_client = &data->client; |
137 | i2c_set_clientdata(new_client, data); | 136 | i2c_set_clientdata(new_client, data); |
diff --git a/drivers/i2c/chips/pcf8591.c b/drivers/i2c/chips/pcf8591.c index 80f1df9a4500..ce420a67560b 100644 --- a/drivers/i2c/chips/pcf8591.c +++ b/drivers/i2c/chips/pcf8591.c | |||
@@ -166,7 +166,7 @@ static int pcf8591_attach_adapter(struct i2c_adapter *adapter) | |||
166 | } | 166 | } |
167 | 167 | ||
168 | /* This function is called by i2c_probe */ | 168 | /* This function is called by i2c_probe */ |
169 | int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind) | 169 | static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind) |
170 | { | 170 | { |
171 | struct i2c_client *new_client; | 171 | struct i2c_client *new_client; |
172 | struct pcf8591_data *data; | 172 | struct pcf8591_data *data; |
@@ -178,11 +178,10 @@ int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind) | |||
178 | 178 | ||
179 | /* OK. For now, we presume we have a valid client. We now create the | 179 | /* OK. For now, we presume we have a valid client. We now create the |
180 | client structure, even though we cannot fill it completely yet. */ | 180 | client structure, even though we cannot fill it completely yet. */ |
181 | if (!(data = kmalloc(sizeof(struct pcf8591_data), GFP_KERNEL))) { | 181 | if (!(data = kzalloc(sizeof(struct pcf8591_data), GFP_KERNEL))) { |
182 | err = -ENOMEM; | 182 | err = -ENOMEM; |
183 | goto exit; | 183 | goto exit; |
184 | } | 184 | } |
185 | memset(data, 0, sizeof(struct pcf8591_data)); | ||
186 | 185 | ||
187 | new_client = &data->client; | 186 | new_client = &data->client; |
188 | i2c_set_clientdata(new_client, data); | 187 | i2c_set_clientdata(new_client, data); |
diff --git a/drivers/i2c/chips/rtc8564.c b/drivers/i2c/chips/rtc8564.c index 0b5385c892b1..916cdc1af23c 100644 --- a/drivers/i2c/chips/rtc8564.c +++ b/drivers/i2c/chips/rtc8564.c | |||
@@ -148,17 +148,16 @@ static int rtc8564_attach(struct i2c_adapter *adap, int addr, int kind) | |||
148 | {addr, I2C_M_RD, 2, data} | 148 | {addr, I2C_M_RD, 2, data} |
149 | }; | 149 | }; |
150 | 150 | ||
151 | d = kmalloc(sizeof(struct rtc8564_data), GFP_KERNEL); | 151 | d = kzalloc(sizeof(struct rtc8564_data), GFP_KERNEL); |
152 | if (!d) { | 152 | if (!d) { |
153 | ret = -ENOMEM; | 153 | ret = -ENOMEM; |
154 | goto done; | 154 | goto done; |
155 | } | 155 | } |
156 | memset(d, 0, sizeof(struct rtc8564_data)); | ||
157 | new_client = &d->client; | 156 | new_client = &d->client; |
158 | 157 | ||
159 | strlcpy(new_client->name, "RTC8564", I2C_NAME_SIZE); | 158 | strlcpy(new_client->name, "RTC8564", I2C_NAME_SIZE); |
160 | i2c_set_clientdata(new_client, d); | 159 | i2c_set_clientdata(new_client, d); |
161 | new_client->flags = I2C_CLIENT_ALLOW_USE | I2C_DF_NOTIFY; | 160 | new_client->flags = I2C_CLIENT_ALLOW_USE; |
162 | new_client->addr = addr; | 161 | new_client->addr = addr; |
163 | new_client->adapter = adap; | 162 | new_client->adapter = adap; |
164 | new_client->driver = &rtc8564_driver; | 163 | new_client->driver = &rtc8564_driver; |
diff --git a/drivers/i2c/chips/tps65010.c b/drivers/i2c/chips/tps65010.c index 280e9638c0f8..280dd7a45db6 100644 --- a/drivers/i2c/chips/tps65010.c +++ b/drivers/i2c/chips/tps65010.c | |||
@@ -500,11 +500,10 @@ tps65010_probe(struct i2c_adapter *bus, int address, int kind) | |||
500 | return 0; | 500 | return 0; |
501 | } | 501 | } |
502 | 502 | ||
503 | tps = kmalloc(sizeof *tps, GFP_KERNEL); | 503 | tps = kzalloc(sizeof *tps, GFP_KERNEL); |
504 | if (!tps) | 504 | if (!tps) |
505 | return 0; | 505 | return 0; |
506 | 506 | ||
507 | memset(tps, 0, sizeof *tps); | ||
508 | init_MUTEX(&tps->lock); | 507 | init_MUTEX(&tps->lock); |
509 | INIT_WORK(&tps->work, tps65010_work, tps); | 508 | INIT_WORK(&tps->work, tps65010_work, tps); |
510 | tps->irq = -1; | 509 | tps->irq = -1; |
diff --git a/drivers/i2c/chips/x1205.c b/drivers/i2c/chips/x1205.c new file mode 100644 index 000000000000..7da366cdc18c --- /dev/null +++ b/drivers/i2c/chips/x1205.c | |||
@@ -0,0 +1,698 @@ | |||
1 | /* | ||
2 | * x1205.c - An i2c driver for the Xicor X1205 RTC | ||
3 | * Copyright 2004 Karen Spearel | ||
4 | * Copyright 2005 Alessandro Zummo | ||
5 | * | ||
6 | * please send all reports to: | ||
7 | * kas11 at tampabay dot rr dot com | ||
8 | * a dot zummo at towertech dot it | ||
9 | * | ||
10 | * based on the other drivers in this same directory. | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or modify | ||
13 | * it under the terms of the GNU General Public License as published by | ||
14 | * the Free Software Foundation; either version 2 of the License, or | ||
15 | * (at your option) any later version. | ||
16 | */ | ||
17 | |||
18 | #include <linux/module.h> | ||
19 | #include <linux/init.h> | ||
20 | #include <linux/slab.h> | ||
21 | #include <linux/i2c.h> | ||
22 | #include <linux/string.h> | ||
23 | #include <linux/bcd.h> | ||
24 | #include <linux/rtc.h> | ||
25 | #include <linux/list.h> | ||
26 | |||
27 | #include <linux/x1205.h> | ||
28 | |||
29 | #define DRV_VERSION "0.9.9" | ||
30 | |||
31 | /* Addresses to scan: none. This chip is located at | ||
32 | * 0x6f and uses a two bytes register addressing. | ||
33 | * Two bytes need to be written to read a single register, | ||
34 | * while most other chips just require one and take the second | ||
35 | * one as the data to be written. To prevent corrupting | ||
36 | * unknown chips, the user must explicitely set the probe parameter. | ||
37 | */ | ||
38 | |||
39 | static unsigned short normal_i2c[] = { I2C_CLIENT_END }; | ||
40 | |||
41 | /* Insmod parameters */ | ||
42 | I2C_CLIENT_INSMOD; | ||
43 | I2C_CLIENT_MODULE_PARM(hctosys, | ||
44 | "Set the system time from the hardware clock upon initialization"); | ||
45 | |||
46 | /* offsets into CCR area */ | ||
47 | |||
48 | #define CCR_SEC 0 | ||
49 | #define CCR_MIN 1 | ||
50 | #define CCR_HOUR 2 | ||
51 | #define CCR_MDAY 3 | ||
52 | #define CCR_MONTH 4 | ||
53 | #define CCR_YEAR 5 | ||
54 | #define CCR_WDAY 6 | ||
55 | #define CCR_Y2K 7 | ||
56 | |||
57 | #define X1205_REG_SR 0x3F /* status register */ | ||
58 | #define X1205_REG_Y2K 0x37 | ||
59 | #define X1205_REG_DW 0x36 | ||
60 | #define X1205_REG_YR 0x35 | ||
61 | #define X1205_REG_MO 0x34 | ||
62 | #define X1205_REG_DT 0x33 | ||
63 | #define X1205_REG_HR 0x32 | ||
64 | #define X1205_REG_MN 0x31 | ||
65 | #define X1205_REG_SC 0x30 | ||
66 | #define X1205_REG_DTR 0x13 | ||
67 | #define X1205_REG_ATR 0x12 | ||
68 | #define X1205_REG_INT 0x11 | ||
69 | #define X1205_REG_0 0x10 | ||
70 | #define X1205_REG_Y2K1 0x0F | ||
71 | #define X1205_REG_DWA1 0x0E | ||
72 | #define X1205_REG_YRA1 0x0D | ||
73 | #define X1205_REG_MOA1 0x0C | ||
74 | #define X1205_REG_DTA1 0x0B | ||
75 | #define X1205_REG_HRA1 0x0A | ||
76 | #define X1205_REG_MNA1 0x09 | ||
77 | #define X1205_REG_SCA1 0x08 | ||
78 | #define X1205_REG_Y2K0 0x07 | ||
79 | #define X1205_REG_DWA0 0x06 | ||
80 | #define X1205_REG_YRA0 0x05 | ||
81 | #define X1205_REG_MOA0 0x04 | ||
82 | #define X1205_REG_DTA0 0x03 | ||
83 | #define X1205_REG_HRA0 0x02 | ||
84 | #define X1205_REG_MNA0 0x01 | ||
85 | #define X1205_REG_SCA0 0x00 | ||
86 | |||
87 | #define X1205_CCR_BASE 0x30 /* Base address of CCR */ | ||
88 | #define X1205_ALM0_BASE 0x00 /* Base address of ALARM0 */ | ||
89 | |||
90 | #define X1205_SR_RTCF 0x01 /* Clock failure */ | ||
91 | #define X1205_SR_WEL 0x02 /* Write Enable Latch */ | ||
92 | #define X1205_SR_RWEL 0x04 /* Register Write Enable */ | ||
93 | |||
94 | #define X1205_DTR_DTR0 0x01 | ||
95 | #define X1205_DTR_DTR1 0x02 | ||
96 | #define X1205_DTR_DTR2 0x04 | ||
97 | |||
98 | #define X1205_HR_MIL 0x80 /* Set in ccr.hour for 24 hr mode */ | ||
99 | |||
100 | /* Prototypes */ | ||
101 | static int x1205_attach(struct i2c_adapter *adapter); | ||
102 | static int x1205_detach(struct i2c_client *client); | ||
103 | static int x1205_probe(struct i2c_adapter *adapter, int address, int kind); | ||
104 | static int x1205_command(struct i2c_client *client, unsigned int cmd, | ||
105 | void *arg); | ||
106 | |||
107 | static struct i2c_driver x1205_driver = { | ||
108 | .owner = THIS_MODULE, | ||
109 | .name = "x1205", | ||
110 | .flags = I2C_DF_NOTIFY, | ||
111 | .attach_adapter = &x1205_attach, | ||
112 | .detach_client = &x1205_detach, | ||
113 | }; | ||
114 | |||
115 | struct x1205_data { | ||
116 | struct i2c_client client; | ||
117 | struct list_head list; | ||
118 | unsigned int epoch; | ||
119 | }; | ||
120 | |||
121 | static const unsigned char days_in_mo[] = | ||
122 | { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; | ||
123 | |||
124 | static LIST_HEAD(x1205_clients); | ||
125 | |||
126 | /* Workaround until the I2C subsytem will allow to send | ||
127 | * commands to a specific client. This function will send the command | ||
128 | * to the first client. | ||
129 | */ | ||
130 | int x1205_do_command(unsigned int cmd, void *arg) | ||
131 | { | ||
132 | struct list_head *walk; | ||
133 | struct list_head *tmp; | ||
134 | struct x1205_data *data; | ||
135 | |||
136 | list_for_each_safe(walk, tmp, &x1205_clients) { | ||
137 | data = list_entry(walk, struct x1205_data, list); | ||
138 | return x1205_command(&data->client, cmd, arg); | ||
139 | } | ||
140 | |||
141 | return -ENODEV; | ||
142 | } | ||
143 | |||
144 | #define is_leap(year) \ | ||
145 | ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0)) | ||
146 | |||
147 | /* make sure the rtc_time values are in bounds */ | ||
148 | static int x1205_validate_tm(struct rtc_time *tm) | ||
149 | { | ||
150 | int year = tm->tm_year + 1900; | ||
151 | |||
152 | if ((tm->tm_year < 70) || (tm->tm_year > 255)) | ||
153 | return -EINVAL; | ||
154 | |||
155 | if ((tm->tm_mon > 11) || (tm->tm_mday == 0)) | ||
156 | return -EINVAL; | ||
157 | |||
158 | if (tm->tm_mday > days_in_mo[tm->tm_mon] | ||
159 | + ((tm->tm_mon == 1) && is_leap(year))) | ||
160 | return -EINVAL; | ||
161 | |||
162 | if ((tm->tm_hour >= 24) || (tm->tm_min >= 60) || (tm->tm_sec >= 60)) | ||
163 | return -EINVAL; | ||
164 | |||
165 | return 0; | ||
166 | } | ||
167 | |||
168 | /* | ||
169 | * In the routines that deal directly with the x1205 hardware, we use | ||
170 | * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch | ||
171 | * Epoch is initialized as 2000. Time is set to UTC. | ||
172 | */ | ||
173 | static int x1205_get_datetime(struct i2c_client *client, struct rtc_time *tm, | ||
174 | u8 reg_base) | ||
175 | { | ||
176 | unsigned char dt_addr[2] = { 0, reg_base }; | ||
177 | static unsigned char sr_addr[2] = { 0, X1205_REG_SR }; | ||
178 | |||
179 | unsigned char buf[8], sr; | ||
180 | |||
181 | struct i2c_msg msgs[] = { | ||
182 | { client->addr, 0, 2, sr_addr }, /* setup read ptr */ | ||
183 | { client->addr, I2C_M_RD, 1, &sr }, /* read status */ | ||
184 | { client->addr, 0, 2, dt_addr }, /* setup read ptr */ | ||
185 | { client->addr, I2C_M_RD, 8, buf }, /* read date */ | ||
186 | }; | ||
187 | |||
188 | struct x1205_data *data = i2c_get_clientdata(client); | ||
189 | |||
190 | /* read status register */ | ||
191 | if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { | ||
192 | dev_err(&client->dev, "%s: read error\n", __FUNCTION__); | ||
193 | return -EIO; | ||
194 | } | ||
195 | |||
196 | /* check for battery failure */ | ||
197 | if (sr & X1205_SR_RTCF) { | ||
198 | dev_warn(&client->dev, | ||
199 | "Clock had a power failure, you must set the date.\n"); | ||
200 | return -EINVAL; | ||
201 | } | ||
202 | |||
203 | /* read date registers */ | ||
204 | if ((i2c_transfer(client->adapter, &msgs[2], 2)) != 2) { | ||
205 | dev_err(&client->dev, "%s: read error\n", __FUNCTION__); | ||
206 | return -EIO; | ||
207 | } | ||
208 | |||
209 | dev_dbg(&client->dev, | ||
210 | "%s: raw read data - sec=%02x, min=%02x, hr=%02x, " | ||
211 | "mday=%02x, mon=%02x, year=%02x, wday=%02x, y2k=%02x\n", | ||
212 | __FUNCTION__, | ||
213 | buf[0], buf[1], buf[2], buf[3], | ||
214 | buf[4], buf[5], buf[6], buf[7]); | ||
215 | |||
216 | tm->tm_sec = BCD2BIN(buf[CCR_SEC]); | ||
217 | tm->tm_min = BCD2BIN(buf[CCR_MIN]); | ||
218 | tm->tm_hour = BCD2BIN(buf[CCR_HOUR] & 0x3F); /* hr is 0-23 */ | ||
219 | tm->tm_mday = BCD2BIN(buf[CCR_MDAY]); | ||
220 | tm->tm_mon = BCD2BIN(buf[CCR_MONTH]); | ||
221 | data->epoch = BCD2BIN(buf[CCR_Y2K]) * 100; | ||
222 | tm->tm_year = BCD2BIN(buf[CCR_YEAR]) + data->epoch - 1900; | ||
223 | tm->tm_wday = buf[CCR_WDAY]; | ||
224 | |||
225 | dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " | ||
226 | "mday=%d, mon=%d, year=%d, wday=%d\n", | ||
227 | __FUNCTION__, | ||
228 | tm->tm_sec, tm->tm_min, tm->tm_hour, | ||
229 | tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); | ||
230 | |||
231 | return 0; | ||
232 | } | ||
233 | |||
234 | static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm, | ||
235 | int datetoo, u8 reg_base) | ||
236 | { | ||
237 | int i, err, xfer; | ||
238 | |||
239 | unsigned char buf[8]; | ||
240 | |||
241 | static const unsigned char wel[3] = { 0, X1205_REG_SR, | ||
242 | X1205_SR_WEL }; | ||
243 | |||
244 | static const unsigned char rwel[3] = { 0, X1205_REG_SR, | ||
245 | X1205_SR_WEL | X1205_SR_RWEL }; | ||
246 | |||
247 | static const unsigned char diswe[3] = { 0, X1205_REG_SR, 0 }; | ||
248 | |||
249 | struct x1205_data *data = i2c_get_clientdata(client); | ||
250 | |||
251 | /* check if all values in the tm struct are correct */ | ||
252 | if ((err = x1205_validate_tm(tm)) < 0) | ||
253 | return err; | ||
254 | |||
255 | dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, " | ||
256 | "mday=%d, mon=%d, year=%d, wday=%d\n", | ||
257 | __FUNCTION__, | ||
258 | tm->tm_sec, tm->tm_min, tm->tm_hour, | ||
259 | tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); | ||
260 | |||
261 | buf[CCR_SEC] = BIN2BCD(tm->tm_sec); | ||
262 | buf[CCR_MIN] = BIN2BCD(tm->tm_min); | ||
263 | |||
264 | /* set hour and 24hr bit */ | ||
265 | buf[CCR_HOUR] = BIN2BCD(tm->tm_hour) | X1205_HR_MIL; | ||
266 | |||
267 | /* should we also set the date? */ | ||
268 | if (datetoo) { | ||
269 | buf[CCR_MDAY] = BIN2BCD(tm->tm_mday); | ||
270 | |||
271 | /* month, 0 - 11 */ | ||
272 | buf[CCR_MONTH] = BIN2BCD(tm->tm_mon); | ||
273 | |||
274 | /* year, since 1900 */ | ||
275 | buf[CCR_YEAR] = BIN2BCD(tm->tm_year + 1900 - data->epoch); | ||
276 | buf[CCR_WDAY] = tm->tm_wday & 0x07; | ||
277 | buf[CCR_Y2K] = BIN2BCD(data->epoch / 100); | ||
278 | } | ||
279 | |||
280 | /* this sequence is required to unlock the chip */ | ||
281 | xfer = i2c_master_send(client, wel, 3); | ||
282 | if (xfer != 3) { | ||
283 | dev_err(&client->dev, "%s: wel - %d\n", __FUNCTION__, xfer); | ||
284 | return -EIO; | ||
285 | } | ||
286 | |||
287 | xfer = i2c_master_send(client, rwel, 3); | ||
288 | if (xfer != 3) { | ||
289 | dev_err(&client->dev, "%s: rwel - %d\n", __FUNCTION__, xfer); | ||
290 | return -EIO; | ||
291 | } | ||
292 | |||
293 | /* write register's data */ | ||
294 | for (i = 0; i < (datetoo ? 8 : 3); i++) { | ||
295 | unsigned char rdata[3] = { 0, reg_base + i, buf[i] }; | ||
296 | |||
297 | xfer = i2c_master_send(client, rdata, 3); | ||
298 | if (xfer != 3) { | ||
299 | dev_err(&client->dev, | ||
300 | "%s: xfer=%d addr=%02x, data=%02x\n", | ||
301 | __FUNCTION__, | ||
302 | xfer, rdata[1], rdata[2]); | ||
303 | return -EIO; | ||
304 | } | ||
305 | }; | ||
306 | |||
307 | /* disable further writes */ | ||
308 | xfer = i2c_master_send(client, diswe, 3); | ||
309 | if (xfer != 3) { | ||
310 | dev_err(&client->dev, "%s: diswe - %d\n", __FUNCTION__, xfer); | ||
311 | return -EIO; | ||
312 | } | ||
313 | |||
314 | return 0; | ||
315 | } | ||
316 | |||
317 | static int x1205_get_dtrim(struct i2c_client *client, int *trim) | ||
318 | { | ||
319 | unsigned char dtr; | ||
320 | static unsigned char dtr_addr[2] = { 0, X1205_REG_DTR }; | ||
321 | |||
322 | struct i2c_msg msgs[] = { | ||
323 | { client->addr, 0, 2, dtr_addr }, /* setup read ptr */ | ||
324 | { client->addr, I2C_M_RD, 1, &dtr }, /* read dtr */ | ||
325 | }; | ||
326 | |||
327 | /* read dtr register */ | ||
328 | if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { | ||
329 | dev_err(&client->dev, "%s: read error\n", __FUNCTION__); | ||
330 | return -EIO; | ||
331 | } | ||
332 | |||
333 | dev_dbg(&client->dev, "%s: raw dtr=%x\n", __FUNCTION__, dtr); | ||
334 | |||
335 | *trim = 0; | ||
336 | |||
337 | if (dtr & X1205_DTR_DTR0) | ||
338 | *trim += 20; | ||
339 | |||
340 | if (dtr & X1205_DTR_DTR1) | ||
341 | *trim += 10; | ||
342 | |||
343 | if (dtr & X1205_DTR_DTR2) | ||
344 | *trim = -*trim; | ||
345 | |||
346 | return 0; | ||
347 | } | ||
348 | |||
349 | static int x1205_get_atrim(struct i2c_client *client, int *trim) | ||
350 | { | ||
351 | s8 atr; | ||
352 | static unsigned char atr_addr[2] = { 0, X1205_REG_ATR }; | ||
353 | |||
354 | struct i2c_msg msgs[] = { | ||
355 | { client->addr, 0, 2, atr_addr }, /* setup read ptr */ | ||
356 | { client->addr, I2C_M_RD, 1, &atr }, /* read atr */ | ||
357 | }; | ||
358 | |||
359 | /* read atr register */ | ||
360 | if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { | ||
361 | dev_err(&client->dev, "%s: read error\n", __FUNCTION__); | ||
362 | return -EIO; | ||
363 | } | ||
364 | |||
365 | dev_dbg(&client->dev, "%s: raw atr=%x\n", __FUNCTION__, atr); | ||
366 | |||
367 | /* atr is a two's complement value on 6 bits, | ||
368 | * perform sign extension. The formula is | ||
369 | * Catr = (atr * 0.25pF) + 11.00pF. | ||
370 | */ | ||
371 | if (atr & 0x20) | ||
372 | atr |= 0xC0; | ||
373 | |||
374 | dev_dbg(&client->dev, "%s: raw atr=%x (%d)\n", __FUNCTION__, atr, atr); | ||
375 | |||
376 | *trim = (atr * 250) + 11000; | ||
377 | |||
378 | dev_dbg(&client->dev, "%s: real=%d\n", __FUNCTION__, *trim); | ||
379 | |||
380 | return 0; | ||
381 | } | ||
382 | |||
383 | static int x1205_hctosys(struct i2c_client *client) | ||
384 | { | ||
385 | int err; | ||
386 | |||
387 | struct rtc_time tm; | ||
388 | struct timespec tv; | ||
389 | |||
390 | err = x1205_command(client, X1205_CMD_GETDATETIME, &tm); | ||
391 | |||
392 | if (err) { | ||
393 | dev_err(&client->dev, | ||
394 | "Unable to set the system clock\n"); | ||
395 | return err; | ||
396 | } | ||
397 | |||
398 | /* IMPORTANT: the RTC only stores whole seconds. It is arbitrary | ||
399 | * whether it stores the most close value or the value with partial | ||
400 | * seconds truncated. However, it is important that we use it to store | ||
401 | * the truncated value. This is because otherwise it is necessary, | ||
402 | * in an rtc sync function, to read both xtime.tv_sec and | ||
403 | * xtime.tv_nsec. On some processors (i.e. ARM), an atomic read | ||
404 | * of >32bits is not possible. So storing the most close value would | ||
405 | * slow down the sync API. So here we have the truncated value and | ||
406 | * the best guess is to add 0.5s. | ||
407 | */ | ||
408 | |||
409 | tv.tv_nsec = NSEC_PER_SEC >> 1; | ||
410 | |||
411 | /* WARNING: this is not the C library 'mktime' call, it is a built in | ||
412 | * inline function from include/linux/time.h. It expects (requires) | ||
413 | * the month to be in the range 1-12 | ||
414 | */ | ||
415 | |||
416 | tv.tv_sec = mktime(tm.tm_year + 1900, tm.tm_mon + 1, | ||
417 | tm.tm_mday, tm.tm_hour, | ||
418 | tm.tm_min, tm.tm_sec); | ||
419 | |||
420 | do_settimeofday(&tv); | ||
421 | |||
422 | dev_info(&client->dev, | ||
423 | "setting the system clock to %d-%d-%d %d:%d:%d\n", | ||
424 | tm.tm_year + 1900, tm.tm_mon + 1, | ||
425 | tm.tm_mday, tm.tm_hour, tm.tm_min, | ||
426 | tm.tm_sec); | ||
427 | |||
428 | return 0; | ||
429 | } | ||
430 | |||
431 | struct x1205_limit | ||
432 | { | ||
433 | unsigned char reg; | ||
434 | unsigned char mask; | ||
435 | unsigned char min; | ||
436 | unsigned char max; | ||
437 | }; | ||
438 | |||
439 | static int x1205_validate_client(struct i2c_client *client) | ||
440 | { | ||
441 | int i, xfer; | ||
442 | |||
443 | /* Probe array. We will read the register at the specified | ||
444 | * address and check if the given bits are zero. | ||
445 | */ | ||
446 | static const unsigned char probe_zero_pattern[] = { | ||
447 | /* register, mask */ | ||
448 | X1205_REG_SR, 0x18, | ||
449 | X1205_REG_DTR, 0xF8, | ||
450 | X1205_REG_ATR, 0xC0, | ||
451 | X1205_REG_INT, 0x18, | ||
452 | X1205_REG_0, 0xFF, | ||
453 | }; | ||
454 | |||
455 | static const struct x1205_limit probe_limits_pattern[] = { | ||
456 | /* register, mask, min, max */ | ||
457 | { X1205_REG_Y2K, 0xFF, 19, 20 }, | ||
458 | { X1205_REG_DW, 0xFF, 0, 6 }, | ||
459 | { X1205_REG_YR, 0xFF, 0, 99 }, | ||
460 | { X1205_REG_MO, 0xFF, 0, 12 }, | ||
461 | { X1205_REG_DT, 0xFF, 0, 31 }, | ||
462 | { X1205_REG_HR, 0x7F, 0, 23 }, | ||
463 | { X1205_REG_MN, 0xFF, 0, 59 }, | ||
464 | { X1205_REG_SC, 0xFF, 0, 59 }, | ||
465 | { X1205_REG_Y2K1, 0xFF, 19, 20 }, | ||
466 | { X1205_REG_Y2K0, 0xFF, 19, 20 }, | ||
467 | }; | ||
468 | |||
469 | /* check that registers have bits a 0 where expected */ | ||
470 | for (i = 0; i < ARRAY_SIZE(probe_zero_pattern); i += 2) { | ||
471 | unsigned char buf; | ||
472 | |||
473 | unsigned char addr[2] = { 0, probe_zero_pattern[i] }; | ||
474 | |||
475 | struct i2c_msg msgs[2] = { | ||
476 | { client->addr, 0, 2, addr }, | ||
477 | { client->addr, I2C_M_RD, 1, &buf }, | ||
478 | }; | ||
479 | |||
480 | xfer = i2c_transfer(client->adapter, msgs, 2); | ||
481 | if (xfer != 2) { | ||
482 | dev_err(&client->adapter->dev, | ||
483 | "%s: could not read register %x\n", | ||
484 | __FUNCTION__, addr[1]); | ||
485 | |||
486 | return -EIO; | ||
487 | } | ||
488 | |||
489 | if ((buf & probe_zero_pattern[i+1]) != 0) { | ||
490 | dev_err(&client->adapter->dev, | ||
491 | "%s: register=%02x, zero pattern=%d, value=%x\n", | ||
492 | __FUNCTION__, addr[1], i, buf); | ||
493 | |||
494 | return -ENODEV; | ||
495 | } | ||
496 | } | ||
497 | |||
498 | /* check limits (only registers with bcd values) */ | ||
499 | for (i = 0; i < ARRAY_SIZE(probe_limits_pattern); i++) { | ||
500 | unsigned char reg, value; | ||
501 | |||
502 | unsigned char addr[2] = { 0, probe_limits_pattern[i].reg }; | ||
503 | |||
504 | struct i2c_msg msgs[2] = { | ||
505 | { client->addr, 0, 2, addr }, | ||
506 | { client->addr, I2C_M_RD, 1, ® }, | ||
507 | }; | ||
508 | |||
509 | xfer = i2c_transfer(client->adapter, msgs, 2); | ||
510 | |||
511 | if (xfer != 2) { | ||
512 | dev_err(&client->adapter->dev, | ||
513 | "%s: could not read register %x\n", | ||
514 | __FUNCTION__, addr[1]); | ||
515 | |||
516 | return -EIO; | ||
517 | } | ||
518 | |||
519 | value = BCD2BIN(reg & probe_limits_pattern[i].mask); | ||
520 | |||
521 | if (value > probe_limits_pattern[i].max || | ||
522 | value < probe_limits_pattern[i].min) { | ||
523 | dev_dbg(&client->adapter->dev, | ||
524 | "%s: register=%x, lim pattern=%d, value=%d\n", | ||
525 | __FUNCTION__, addr[1], i, value); | ||
526 | |||
527 | return -ENODEV; | ||
528 | } | ||
529 | } | ||
530 | |||
531 | return 0; | ||
532 | } | ||
533 | |||
534 | static int x1205_attach(struct i2c_adapter *adapter) | ||
535 | { | ||
536 | dev_dbg(&adapter->dev, "%s\n", __FUNCTION__); | ||
537 | |||
538 | return i2c_probe(adapter, &addr_data, x1205_probe); | ||
539 | } | ||
540 | |||
541 | int x1205_direct_attach(int adapter_id, | ||
542 | struct i2c_client_address_data *address_data) | ||
543 | { | ||
544 | int err; | ||
545 | struct i2c_adapter *adapter = i2c_get_adapter(adapter_id); | ||
546 | |||
547 | if (adapter) { | ||
548 | err = i2c_probe(adapter, | ||
549 | address_data, x1205_probe); | ||
550 | |||
551 | i2c_put_adapter(adapter); | ||
552 | |||
553 | return err; | ||
554 | } | ||
555 | |||
556 | return -ENODEV; | ||
557 | } | ||
558 | |||
559 | static int x1205_probe(struct i2c_adapter *adapter, int address, int kind) | ||
560 | { | ||
561 | struct i2c_client *client; | ||
562 | struct x1205_data *data; | ||
563 | |||
564 | int err = 0; | ||
565 | |||
566 | dev_dbg(&adapter->dev, "%s\n", __FUNCTION__); | ||
567 | |||
568 | if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) { | ||
569 | err = -ENODEV; | ||
570 | goto exit; | ||
571 | } | ||
572 | |||
573 | if (!(data = kzalloc(sizeof(struct x1205_data), GFP_KERNEL))) { | ||
574 | err = -ENOMEM; | ||
575 | goto exit; | ||
576 | } | ||
577 | |||
578 | /* Initialize our structures */ | ||
579 | data->epoch = 2000; | ||
580 | |||
581 | client = &data->client; | ||
582 | client->addr = address; | ||
583 | client->driver = &x1205_driver; | ||
584 | client->adapter = adapter; | ||
585 | |||
586 | strlcpy(client->name, "x1205", I2C_NAME_SIZE); | ||
587 | |||
588 | i2c_set_clientdata(client, data); | ||
589 | |||
590 | /* Verify the chip is really an X1205 */ | ||
591 | if (kind < 0) { | ||
592 | if (x1205_validate_client(client) < 0) { | ||
593 | err = -ENODEV; | ||
594 | goto exit_kfree; | ||
595 | } | ||
596 | } | ||
597 | |||
598 | /* Inform the i2c layer */ | ||
599 | if ((err = i2c_attach_client(client))) | ||
600 | goto exit_kfree; | ||
601 | |||
602 | list_add(&data->list, &x1205_clients); | ||
603 | |||
604 | dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n"); | ||
605 | |||
606 | /* If requested, set the system time */ | ||
607 | if (hctosys) | ||
608 | x1205_hctosys(client); | ||
609 | |||
610 | return 0; | ||
611 | |||
612 | exit_kfree: | ||
613 | kfree(data); | ||
614 | |||
615 | exit: | ||
616 | return err; | ||
617 | } | ||
618 | |||
619 | static int x1205_detach(struct i2c_client *client) | ||
620 | { | ||
621 | int err; | ||
622 | struct x1205_data *data = i2c_get_clientdata(client); | ||
623 | |||
624 | dev_dbg(&client->dev, "%s\n", __FUNCTION__); | ||
625 | |||
626 | if ((err = i2c_detach_client(client))) | ||
627 | return err; | ||
628 | |||
629 | list_del(&data->list); | ||
630 | |||
631 | kfree(data); | ||
632 | |||
633 | return 0; | ||
634 | } | ||
635 | |||
636 | static int x1205_command(struct i2c_client *client, unsigned int cmd, | ||
637 | void *param) | ||
638 | { | ||
639 | if (param == NULL) | ||
640 | return -EINVAL; | ||
641 | |||
642 | if (!capable(CAP_SYS_TIME)) | ||
643 | return -EACCES; | ||
644 | |||
645 | dev_dbg(&client->dev, "%s: cmd=%d\n", __FUNCTION__, cmd); | ||
646 | |||
647 | switch (cmd) { | ||
648 | case X1205_CMD_GETDATETIME: | ||
649 | return x1205_get_datetime(client, param, X1205_CCR_BASE); | ||
650 | |||
651 | case X1205_CMD_SETTIME: | ||
652 | return x1205_set_datetime(client, param, 0, | ||
653 | X1205_CCR_BASE); | ||
654 | |||
655 | case X1205_CMD_SETDATETIME: | ||
656 | return x1205_set_datetime(client, param, 1, | ||
657 | X1205_CCR_BASE); | ||
658 | |||
659 | case X1205_CMD_GETALARM: | ||
660 | return x1205_get_datetime(client, param, X1205_ALM0_BASE); | ||
661 | |||
662 | case X1205_CMD_SETALARM: | ||
663 | return x1205_set_datetime(client, param, 1, | ||
664 | X1205_ALM0_BASE); | ||
665 | |||
666 | case X1205_CMD_GETDTRIM: | ||
667 | return x1205_get_dtrim(client, param); | ||
668 | |||
669 | case X1205_CMD_GETATRIM: | ||
670 | return x1205_get_atrim(client, param); | ||
671 | |||
672 | default: | ||
673 | return -EINVAL; | ||
674 | } | ||
675 | } | ||
676 | |||
677 | static int __init x1205_init(void) | ||
678 | { | ||
679 | return i2c_add_driver(&x1205_driver); | ||
680 | } | ||
681 | |||
682 | static void __exit x1205_exit(void) | ||
683 | { | ||
684 | i2c_del_driver(&x1205_driver); | ||
685 | } | ||
686 | |||
687 | MODULE_AUTHOR( | ||
688 | "Karen Spearel <kas11@tampabay.rr.com>, " | ||
689 | "Alessandro Zummo <a.zummo@towertech.it>"); | ||
690 | MODULE_DESCRIPTION("Xicor X1205 RTC driver"); | ||
691 | MODULE_LICENSE("GPL"); | ||
692 | MODULE_VERSION(DRV_VERSION); | ||
693 | |||
694 | EXPORT_SYMBOL_GPL(x1205_do_command); | ||
695 | EXPORT_SYMBOL_GPL(x1205_direct_attach); | ||
696 | |||
697 | module_init(x1205_init); | ||
698 | module_exit(x1205_exit); | ||