diff options
Diffstat (limited to 'drivers/rtc/rtc-ds1307.c')
| -rw-r--r-- | drivers/rtc/rtc-ds1307.c | 66 |
1 files changed, 27 insertions, 39 deletions
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c index f389a28720d2..bbf97e65202a 100644 --- a/drivers/rtc/rtc-ds1307.c +++ b/drivers/rtc/rtc-ds1307.c | |||
| @@ -99,45 +99,38 @@ struct ds1307 { | |||
| 99 | }; | 99 | }; |
| 100 | 100 | ||
| 101 | struct chip_desc { | 101 | struct chip_desc { |
| 102 | char name[9]; | ||
| 103 | unsigned nvram56:1; | 102 | unsigned nvram56:1; |
| 104 | unsigned alarm:1; | 103 | unsigned alarm:1; |
| 105 | enum ds_type type; | ||
| 106 | }; | 104 | }; |
| 107 | 105 | ||
| 108 | static const struct chip_desc chips[] = { { | 106 | static const struct chip_desc chips[] = { |
| 109 | .name = "ds1307", | 107 | [ds_1307] = { |
| 110 | .type = ds_1307, | ||
| 111 | .nvram56 = 1, | 108 | .nvram56 = 1, |
| 112 | }, { | 109 | }, |
| 113 | .name = "ds1337", | 110 | [ds_1337] = { |
| 114 | .type = ds_1337, | ||
| 115 | .alarm = 1, | 111 | .alarm = 1, |
| 116 | }, { | 112 | }, |
| 117 | .name = "ds1338", | 113 | [ds_1338] = { |
| 118 | .type = ds_1338, | ||
| 119 | .nvram56 = 1, | 114 | .nvram56 = 1, |
| 120 | }, { | 115 | }, |
| 121 | .name = "ds1339", | 116 | [ds_1339] = { |
| 122 | .type = ds_1339, | ||
| 123 | .alarm = 1, | 117 | .alarm = 1, |
| 124 | }, { | 118 | }, |
| 125 | .name = "ds1340", | 119 | [ds_1340] = { |
| 126 | .type = ds_1340, | 120 | }, |
| 127 | }, { | 121 | [m41t00] = { |
| 128 | .name = "m41t00", | ||
| 129 | .type = m41t00, | ||
| 130 | }, }; | 122 | }, }; |
| 131 | 123 | ||
| 132 | static inline const struct chip_desc *find_chip(const char *s) | 124 | static const struct i2c_device_id ds1307_id[] = { |
| 133 | { | 125 | { "ds1307", ds_1307 }, |
| 134 | unsigned i; | 126 | { "ds1337", ds_1337 }, |
| 135 | 127 | { "ds1338", ds_1338 }, | |
| 136 | for (i = 0; i < ARRAY_SIZE(chips); i++) | 128 | { "ds1339", ds_1339 }, |
| 137 | if (strnicmp(s, chips[i].name, sizeof chips[i].name) == 0) | 129 | { "ds1340", ds_1340 }, |
| 138 | return &chips[i]; | 130 | { "m41t00", m41t00 }, |
| 139 | return NULL; | 131 | { } |
| 140 | } | 132 | }; |
| 133 | MODULE_DEVICE_TABLE(i2c, ds1307_id); | ||
| 141 | 134 | ||
| 142 | static int ds1307_get_time(struct device *dev, struct rtc_time *t) | 135 | static int ds1307_get_time(struct device *dev, struct rtc_time *t) |
| 143 | { | 136 | { |
| @@ -326,21 +319,15 @@ static struct bin_attribute nvram = { | |||
| 326 | 319 | ||
| 327 | static struct i2c_driver ds1307_driver; | 320 | static struct i2c_driver ds1307_driver; |
| 328 | 321 | ||
| 329 | static int __devinit ds1307_probe(struct i2c_client *client) | 322 | static int __devinit ds1307_probe(struct i2c_client *client, |
| 323 | const struct i2c_device_id *id) | ||
| 330 | { | 324 | { |
| 331 | struct ds1307 *ds1307; | 325 | struct ds1307 *ds1307; |
| 332 | int err = -ENODEV; | 326 | int err = -ENODEV; |
| 333 | int tmp; | 327 | int tmp; |
| 334 | const struct chip_desc *chip; | 328 | const struct chip_desc *chip = &chips[id->driver_data]; |
| 335 | struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); | 329 | struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); |
| 336 | 330 | ||
| 337 | chip = find_chip(client->name); | ||
| 338 | if (!chip) { | ||
| 339 | dev_err(&client->dev, "unknown chip type '%s'\n", | ||
| 340 | client->name); | ||
| 341 | return -ENODEV; | ||
| 342 | } | ||
| 343 | |||
| 344 | if (!i2c_check_functionality(adapter, | 331 | if (!i2c_check_functionality(adapter, |
| 345 | I2C_FUNC_I2C | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) | 332 | I2C_FUNC_I2C | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) |
| 346 | return -EIO; | 333 | return -EIO; |
| @@ -361,7 +348,7 @@ static int __devinit ds1307_probe(struct i2c_client *client) | |||
| 361 | ds1307->msg[1].len = sizeof(ds1307->regs); | 348 | ds1307->msg[1].len = sizeof(ds1307->regs); |
| 362 | ds1307->msg[1].buf = ds1307->regs; | 349 | ds1307->msg[1].buf = ds1307->regs; |
| 363 | 350 | ||
| 364 | ds1307->type = chip->type; | 351 | ds1307->type = id->driver_data; |
| 365 | 352 | ||
| 366 | switch (ds1307->type) { | 353 | switch (ds1307->type) { |
| 367 | case ds_1337: | 354 | case ds_1337: |
| @@ -550,6 +537,7 @@ static struct i2c_driver ds1307_driver = { | |||
| 550 | }, | 537 | }, |
| 551 | .probe = ds1307_probe, | 538 | .probe = ds1307_probe, |
| 552 | .remove = __devexit_p(ds1307_remove), | 539 | .remove = __devexit_p(ds1307_remove), |
| 540 | .id_table = ds1307_id, | ||
| 553 | }; | 541 | }; |
| 554 | 542 | ||
| 555 | static int __init ds1307_init(void) | 543 | static int __init ds1307_init(void) |
