Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Mark A. Greer | 5e9f4f2 | 2006-04-25 13:04:54 +0200 | [diff] [blame] | 2 | * I2C client/driver for the ST M41T00 family of i2c rtc chips. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Author: Mark A. Greer <mgreer@mvista.com> |
| 5 | * |
Mark A. Greer | 5e9f4f2 | 2006-04-25 13:04:54 +0200 | [diff] [blame] | 6 | * 2005, 2006 (c) MontaVista Software, Inc. This file is licensed under |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * the terms of the GNU General Public License version 2. This program |
| 8 | * is licensed "as is" without any warranty of any kind, whether express |
| 9 | * or implied. |
| 10 | */ |
| 11 | /* |
| 12 | * This i2c client/driver wedges between the drivers/char/genrtc.c RTC |
| 13 | * interface and the SMBus interface of the i2c subsystem. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/interrupt.h> |
| 19 | #include <linux/i2c.h> |
| 20 | #include <linux/rtc.h> |
| 21 | #include <linux/bcd.h> |
Mark A. Greer | 8c750c0 | 2006-03-31 23:06:03 +0200 | [diff] [blame] | 22 | #include <linux/workqueue.h> |
Mark A. Greer | 5e9f4f2 | 2006-04-25 13:04:54 +0200 | [diff] [blame] | 23 | #include <linux/platform_device.h> |
| 24 | #include <linux/m41t00.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <asm/time.h> |
| 26 | #include <asm/rtc.h> |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | static struct i2c_driver m41t00_driver; |
| 29 | static struct i2c_client *save_client; |
| 30 | |
| 31 | static unsigned short ignore[] = { I2C_CLIENT_END }; |
Mark A. Greer | 5e9f4f2 | 2006-04-25 13:04:54 +0200 | [diff] [blame] | 32 | static unsigned short normal_addr[] = { I2C_CLIENT_END, I2C_CLIENT_END }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | static struct i2c_client_address_data addr_data = { |
Mark A. Greer | e931b8d | 2006-03-31 23:06:46 +0200 | [diff] [blame] | 35 | .normal_i2c = normal_addr, |
| 36 | .probe = ignore, |
| 37 | .ignore = ignore, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
Mark A. Greer | 5e9f4f2 | 2006-04-25 13:04:54 +0200 | [diff] [blame] | 40 | struct m41t00_chip_info { |
| 41 | u8 type; |
| 42 | char *name; |
| 43 | u8 read_limit; |
| 44 | u8 sec; /* Offsets for chip regs */ |
| 45 | u8 min; |
| 46 | u8 hour; |
| 47 | u8 day; |
| 48 | u8 mon; |
| 49 | u8 year; |
| 50 | u8 alarm_mon; |
| 51 | u8 alarm_hour; |
| 52 | u8 sqw; |
| 53 | u8 sqw_freq; |
| 54 | }; |
| 55 | |
| 56 | static struct m41t00_chip_info m41t00_chip_info_tbl[] = { |
| 57 | { |
| 58 | .type = M41T00_TYPE_M41T00, |
| 59 | .name = "m41t00", |
| 60 | .read_limit = 5, |
| 61 | .sec = 0, |
| 62 | .min = 1, |
| 63 | .hour = 2, |
| 64 | .day = 4, |
| 65 | .mon = 5, |
| 66 | .year = 6, |
| 67 | }, |
| 68 | { |
| 69 | .type = M41T00_TYPE_M41T81, |
| 70 | .name = "m41t81", |
| 71 | .read_limit = 1, |
| 72 | .sec = 1, |
| 73 | .min = 2, |
| 74 | .hour = 3, |
| 75 | .day = 5, |
| 76 | .mon = 6, |
| 77 | .year = 7, |
| 78 | .alarm_mon = 0xa, |
| 79 | .alarm_hour = 0xc, |
| 80 | .sqw = 0x13, |
| 81 | }, |
| 82 | { |
| 83 | .type = M41T00_TYPE_M41T85, |
| 84 | .name = "m41t85", |
| 85 | .read_limit = 1, |
| 86 | .sec = 1, |
| 87 | .min = 2, |
| 88 | .hour = 3, |
| 89 | .day = 5, |
| 90 | .mon = 6, |
| 91 | .year = 7, |
| 92 | .alarm_mon = 0xa, |
| 93 | .alarm_hour = 0xc, |
| 94 | .sqw = 0x13, |
| 95 | }, |
| 96 | }; |
| 97 | static struct m41t00_chip_info *m41t00_chip; |
| 98 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | ulong |
| 100 | m41t00_get_rtc_time(void) |
| 101 | { |
Mark A. Greer | e931b8d | 2006-03-31 23:06:46 +0200 | [diff] [blame] | 102 | s32 sec, min, hour, day, mon, year; |
| 103 | s32 sec1, min1, hour1, day1, mon1, year1; |
Mark A. Greer | 5e9f4f2 | 2006-04-25 13:04:54 +0200 | [diff] [blame] | 104 | u8 reads = 0; |
| 105 | u8 buf[8], msgbuf[1] = { 0 }; /* offset into rtc's regs */ |
| 106 | struct i2c_msg msgs[] = { |
| 107 | { |
| 108 | .addr = save_client->addr, |
| 109 | .flags = 0, |
| 110 | .len = 1, |
| 111 | .buf = msgbuf, |
| 112 | }, |
| 113 | { |
| 114 | .addr = save_client->addr, |
| 115 | .flags = I2C_M_RD, |
| 116 | .len = 8, |
| 117 | .buf = buf, |
| 118 | }, |
| 119 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
| 121 | sec = min = hour = day = mon = year = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | do { |
Mark A. Greer | 5e9f4f2 | 2006-04-25 13:04:54 +0200 | [diff] [blame] | 124 | if (i2c_transfer(save_client->adapter, msgs, 2) < 0) |
| 125 | goto read_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
| 127 | sec1 = sec; |
| 128 | min1 = min; |
| 129 | hour1 = hour; |
| 130 | day1 = day; |
| 131 | mon1 = mon; |
| 132 | year1 = year; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
Mark A. Greer | 5e9f4f2 | 2006-04-25 13:04:54 +0200 | [diff] [blame] | 134 | sec = buf[m41t00_chip->sec] & 0x7f; |
| 135 | min = buf[m41t00_chip->min] & 0x7f; |
| 136 | hour = buf[m41t00_chip->hour] & 0x3f; |
| 137 | day = buf[m41t00_chip->day] & 0x3f; |
| 138 | mon = buf[m41t00_chip->mon] & 0x1f; |
| 139 | year = buf[m41t00_chip->year]; |
| 140 | } while ((++reads < m41t00_chip->read_limit) && ((sec != sec1) |
| 141 | || (min != min1) || (hour != hour1) || (day != day1) |
| 142 | || (mon != mon1) || (year != year1))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
Mark A. Greer | 5e9f4f2 | 2006-04-25 13:04:54 +0200 | [diff] [blame] | 144 | if ((m41t00_chip->read_limit > 1) && ((sec != sec1) || (min != min1) |
| 145 | || (hour != hour1) || (day != day1) || (mon != mon1) |
| 146 | || (year != year1))) |
| 147 | goto read_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
Mark A. Greer | e931b8d | 2006-03-31 23:06:46 +0200 | [diff] [blame] | 149 | sec = BCD2BIN(sec); |
| 150 | min = BCD2BIN(min); |
| 151 | hour = BCD2BIN(hour); |
| 152 | day = BCD2BIN(day); |
| 153 | mon = BCD2BIN(mon); |
| 154 | year = BCD2BIN(year); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | year += 1900; |
| 157 | if (year < 1970) |
| 158 | year += 100; |
| 159 | |
| 160 | return mktime(year, mon, day, hour, min, sec); |
Mark A. Greer | 5e9f4f2 | 2006-04-25 13:04:54 +0200 | [diff] [blame] | 161 | |
| 162 | read_err: |
| 163 | dev_err(&save_client->dev, "m41t00_get_rtc_time: Read error\n"); |
| 164 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | } |
Mark A. Greer | 5e9f4f2 | 2006-04-25 13:04:54 +0200 | [diff] [blame] | 166 | EXPORT_SYMBOL_GPL(m41t00_get_rtc_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
| 168 | static void |
Mark A. Greer | 8c750c0 | 2006-03-31 23:06:03 +0200 | [diff] [blame] | 169 | m41t00_set(void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | { |
| 171 | struct rtc_time tm; |
Mark A. Greer | 5e9f4f2 | 2006-04-25 13:04:54 +0200 | [diff] [blame] | 172 | int nowtime = *(int *)arg; |
| 173 | s32 sec, min, hour, day, mon, year; |
| 174 | u8 wbuf[9], *buf = &wbuf[1], msgbuf[1] = { 0 }; |
| 175 | struct i2c_msg msgs[] = { |
| 176 | { |
| 177 | .addr = save_client->addr, |
| 178 | .flags = 0, |
| 179 | .len = 1, |
| 180 | .buf = msgbuf, |
| 181 | }, |
| 182 | { |
| 183 | .addr = save_client->addr, |
| 184 | .flags = I2C_M_RD, |
| 185 | .len = 8, |
| 186 | .buf = buf, |
| 187 | }, |
| 188 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
| 190 | to_tm(nowtime, &tm); |
| 191 | tm.tm_year = (tm.tm_year - 1900) % 100; |
| 192 | |
Mark A. Greer | 5e9f4f2 | 2006-04-25 13:04:54 +0200 | [diff] [blame] | 193 | sec = BIN2BCD(tm.tm_sec); |
| 194 | min = BIN2BCD(tm.tm_min); |
| 195 | hour = BIN2BCD(tm.tm_hour); |
| 196 | day = BIN2BCD(tm.tm_mday); |
| 197 | mon = BIN2BCD(tm.tm_mon); |
| 198 | year = BIN2BCD(tm.tm_year); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
Mark A. Greer | 5e9f4f2 | 2006-04-25 13:04:54 +0200 | [diff] [blame] | 200 | /* Read reg values into buf[0..7]/wbuf[1..8] */ |
| 201 | if (i2c_transfer(save_client->adapter, msgs, 2) < 0) { |
| 202 | dev_err(&save_client->dev, "m41t00_set: Read error\n"); |
| 203 | return; |
| 204 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Mark A. Greer | 5e9f4f2 | 2006-04-25 13:04:54 +0200 | [diff] [blame] | 206 | wbuf[0] = 0; /* offset into rtc's regs */ |
| 207 | buf[m41t00_chip->sec] = (buf[m41t00_chip->sec] & ~0x7f) | (sec & 0x7f); |
| 208 | buf[m41t00_chip->min] = (buf[m41t00_chip->min] & ~0x7f) | (min & 0x7f); |
| 209 | buf[m41t00_chip->hour] = (buf[m41t00_chip->hour] & ~0x3f) | (hour& 0x3f); |
| 210 | buf[m41t00_chip->day] = (buf[m41t00_chip->day] & ~0x3f) | (day & 0x3f); |
| 211 | buf[m41t00_chip->mon] = (buf[m41t00_chip->mon] & ~0x1f) | (mon & 0x1f); |
Philippe De Muyter | 81ffbc0 | 2007-01-05 17:54:05 +0100 | [diff] [blame] | 212 | buf[m41t00_chip->year] = year; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
Mark A. Greer | 5e9f4f2 | 2006-04-25 13:04:54 +0200 | [diff] [blame] | 214 | if (i2c_master_send(save_client, wbuf, 9) < 0) |
| 215 | dev_err(&save_client->dev, "m41t00_set: Write error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Mark A. Greer | 8c750c0 | 2006-03-31 23:06:03 +0200 | [diff] [blame] | 218 | static ulong new_time; |
Al Viro | 91c7c56 | 2006-12-06 19:50:06 +0000 | [diff] [blame] | 219 | /* well, isn't this API just _lovely_? */ |
| 220 | static void |
| 221 | m41t00_barf(struct work_struct *unusable) |
| 222 | { |
| 223 | m41t00_set(&new_time); |
| 224 | } |
| 225 | |
Mark A. Greer | 8c750c0 | 2006-03-31 23:06:03 +0200 | [diff] [blame] | 226 | static struct workqueue_struct *m41t00_wq; |
Al Viro | 91c7c56 | 2006-12-06 19:50:06 +0000 | [diff] [blame] | 227 | static DECLARE_WORK(m41t00_work, m41t00_barf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
| 229 | int |
| 230 | m41t00_set_rtc_time(ulong nowtime) |
| 231 | { |
| 232 | new_time = nowtime; |
| 233 | |
| 234 | if (in_interrupt()) |
Mark A. Greer | 8c750c0 | 2006-03-31 23:06:03 +0200 | [diff] [blame] | 235 | queue_work(m41t00_wq, &m41t00_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | else |
Mark A. Greer | 8c750c0 | 2006-03-31 23:06:03 +0200 | [diff] [blame] | 237 | m41t00_set(&new_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
| 239 | return 0; |
| 240 | } |
Mark A. Greer | 5e9f4f2 | 2006-04-25 13:04:54 +0200 | [diff] [blame] | 241 | EXPORT_SYMBOL_GPL(m41t00_set_rtc_time); |
| 242 | |
| 243 | /* |
| 244 | ***************************************************************************** |
| 245 | * |
| 246 | * platform_data Driver Interface |
| 247 | * |
| 248 | ***************************************************************************** |
| 249 | */ |
| 250 | static int __init |
| 251 | m41t00_platform_probe(struct platform_device *pdev) |
| 252 | { |
| 253 | struct m41t00_platform_data *pdata; |
| 254 | int i; |
| 255 | |
| 256 | if (pdev && (pdata = pdev->dev.platform_data)) { |
| 257 | normal_addr[0] = pdata->i2c_addr; |
| 258 | |
| 259 | for (i=0; i<ARRAY_SIZE(m41t00_chip_info_tbl); i++) |
| 260 | if (m41t00_chip_info_tbl[i].type == pdata->type) { |
| 261 | m41t00_chip = &m41t00_chip_info_tbl[i]; |
| 262 | m41t00_chip->sqw_freq = pdata->sqw_freq; |
| 263 | return 0; |
| 264 | } |
| 265 | } |
| 266 | return -ENODEV; |
| 267 | } |
| 268 | |
| 269 | static int __exit |
| 270 | m41t00_platform_remove(struct platform_device *pdev) |
| 271 | { |
| 272 | return 0; |
| 273 | } |
| 274 | |
| 275 | static struct platform_driver m41t00_platform_driver = { |
| 276 | .probe = m41t00_platform_probe, |
| 277 | .remove = m41t00_platform_remove, |
| 278 | .driver = { |
| 279 | .owner = THIS_MODULE, |
| 280 | .name = M41T00_DRV_NAME, |
| 281 | }, |
| 282 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
| 284 | /* |
| 285 | ***************************************************************************** |
| 286 | * |
| 287 | * Driver Interface |
| 288 | * |
| 289 | ***************************************************************************** |
| 290 | */ |
| 291 | static int |
| 292 | m41t00_probe(struct i2c_adapter *adap, int addr, int kind) |
| 293 | { |
| 294 | struct i2c_client *client; |
| 295 | int rc; |
| 296 | |
Mark A. Greer | 5e9f4f2 | 2006-04-25 13:04:54 +0200 | [diff] [blame] | 297 | if (!i2c_check_functionality(adap, I2C_FUNC_I2C |
| 298 | | I2C_FUNC_SMBUS_BYTE_DATA)) |
| 299 | return 0; |
| 300 | |
Deepak Saxena | 5263ebb | 2005-10-17 23:09:43 +0200 | [diff] [blame] | 301 | client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | if (!client) |
| 303 | return -ENOMEM; |
| 304 | |
Mark A. Greer | 5e9f4f2 | 2006-04-25 13:04:54 +0200 | [diff] [blame] | 305 | strlcpy(client->name, m41t00_chip->name, I2C_NAME_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | client->addr = addr; |
| 307 | client->adapter = adap; |
| 308 | client->driver = &m41t00_driver; |
| 309 | |
Mark A. Greer | 5e9f4f2 | 2006-04-25 13:04:54 +0200 | [diff] [blame] | 310 | if ((rc = i2c_attach_client(client))) |
| 311 | goto attach_err; |
| 312 | |
| 313 | if (m41t00_chip->type != M41T00_TYPE_M41T00) { |
| 314 | /* If asked, disable SQW, set SQW frequency & re-enable */ |
| 315 | if (m41t00_chip->sqw_freq) |
| 316 | if (((rc = i2c_smbus_read_byte_data(client, |
| 317 | m41t00_chip->alarm_mon)) < 0) |
| 318 | || ((rc = i2c_smbus_write_byte_data(client, |
| 319 | m41t00_chip->alarm_mon, rc & ~0x40)) <0) |
| 320 | || ((rc = i2c_smbus_write_byte_data(client, |
| 321 | m41t00_chip->sqw, |
| 322 | m41t00_chip->sqw_freq)) < 0) |
| 323 | || ((rc = i2c_smbus_write_byte_data(client, |
| 324 | m41t00_chip->alarm_mon, rc | 0x40)) <0)) |
| 325 | goto sqw_err; |
| 326 | |
| 327 | /* Make sure HT (Halt Update) bit is cleared */ |
| 328 | if ((rc = i2c_smbus_read_byte_data(client, |
| 329 | m41t00_chip->alarm_hour)) < 0) |
| 330 | goto ht_err; |
| 331 | |
| 332 | if (rc & 0x40) |
| 333 | if ((rc = i2c_smbus_write_byte_data(client, |
| 334 | m41t00_chip->alarm_hour, rc & ~0x40))<0) |
| 335 | goto ht_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Mark A. Greer | 5e9f4f2 | 2006-04-25 13:04:54 +0200 | [diff] [blame] | 338 | /* Make sure ST (stop) bit is cleared */ |
| 339 | if ((rc = i2c_smbus_read_byte_data(client, m41t00_chip->sec)) < 0) |
| 340 | goto st_err; |
| 341 | |
| 342 | if (rc & 0x80) |
| 343 | if ((rc = i2c_smbus_write_byte_data(client, m41t00_chip->sec, |
| 344 | rc & ~0x80)) < 0) |
| 345 | goto st_err; |
| 346 | |
| 347 | m41t00_wq = create_singlethread_workqueue(m41t00_chip->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | save_client = client; |
| 349 | return 0; |
Mark A. Greer | 5e9f4f2 | 2006-04-25 13:04:54 +0200 | [diff] [blame] | 350 | |
| 351 | st_err: |
| 352 | dev_err(&client->dev, "m41t00_probe: Can't clear ST bit\n"); |
| 353 | goto attach_err; |
| 354 | ht_err: |
| 355 | dev_err(&client->dev, "m41t00_probe: Can't clear HT bit\n"); |
| 356 | goto attach_err; |
| 357 | sqw_err: |
| 358 | dev_err(&client->dev, "m41t00_probe: Can't set SQW Frequency\n"); |
| 359 | attach_err: |
| 360 | kfree(client); |
| 361 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | static int |
| 365 | m41t00_attach(struct i2c_adapter *adap) |
| 366 | { |
| 367 | return i2c_probe(adap, &addr_data, m41t00_probe); |
| 368 | } |
| 369 | |
| 370 | static int |
| 371 | m41t00_detach(struct i2c_client *client) |
| 372 | { |
Mark A. Greer | e931b8d | 2006-03-31 23:06:46 +0200 | [diff] [blame] | 373 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | |
| 375 | if ((rc = i2c_detach_client(client)) == 0) { |
Jean Delvare | 5da69ba | 2005-07-01 14:28:15 +0200 | [diff] [blame] | 376 | kfree(client); |
Mark A. Greer | 8c750c0 | 2006-03-31 23:06:03 +0200 | [diff] [blame] | 377 | destroy_workqueue(m41t00_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | } |
| 379 | return rc; |
| 380 | } |
| 381 | |
| 382 | static struct i2c_driver m41t00_driver = { |
Laurent Riffard | a9718b0 | 2005-11-26 20:36:00 +0100 | [diff] [blame] | 383 | .driver = { |
Laurent Riffard | a9718b0 | 2005-11-26 20:36:00 +0100 | [diff] [blame] | 384 | .name = M41T00_DRV_NAME, |
| 385 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | .id = I2C_DRIVERID_STM41T00, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | .attach_adapter = m41t00_attach, |
| 388 | .detach_client = m41t00_detach, |
| 389 | }; |
| 390 | |
| 391 | static int __init |
| 392 | m41t00_init(void) |
| 393 | { |
Mark A. Greer | 5e9f4f2 | 2006-04-25 13:04:54 +0200 | [diff] [blame] | 394 | int rc; |
| 395 | |
| 396 | if (!(rc = platform_driver_register(&m41t00_platform_driver))) |
| 397 | rc = i2c_add_driver(&m41t00_driver); |
| 398 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | static void __exit |
| 402 | m41t00_exit(void) |
| 403 | { |
| 404 | i2c_del_driver(&m41t00_driver); |
Mark A. Greer | 5e9f4f2 | 2006-04-25 13:04:54 +0200 | [diff] [blame] | 405 | platform_driver_unregister(&m41t00_platform_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | module_init(m41t00_init); |
| 409 | module_exit(m41t00_exit); |
| 410 | |
| 411 | MODULE_AUTHOR("Mark A. Greer <mgreer@mvista.com>"); |
| 412 | MODULE_DESCRIPTION("ST Microelectronics M41T00 RTC I2C Client Driver"); |
| 413 | MODULE_LICENSE("GPL"); |