diff options
author | Krzysztof Helt <krzysztof.h1@wp.pl> | 2008-09-03 18:12:34 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-09-03 18:39:11 -0400 |
commit | 94fe7424a4c21940b4569200faaf0a0a5efd2924 (patch) | |
tree | 1c19837578b0774008df1e2430cf32353cf95286 | |
parent | 3ca60f6e637cee8c735a7448fd912fe1a6e42fc1 (diff) |
rtc-m48t59: add support for M48T02 and M48T59 chips
Add support for two compatible RTC:
- M48T08 which does not have alarm part,
- M48T08 which does not have alarm part and has
only 2KB of NVRAM
These types covers all Mostek's RTC used in Sun UltraSparc workstations.
Tested on Sun Ultra60 with M48T59 RTC.
Signed-off-by: Krzysztof Helt <krzysztof.h1@wp.pl>
Signed-off-by: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/rtc/Kconfig | 7 | ||||
-rw-r--r-- | drivers/rtc/rtc-m48t59.c | 47 | ||||
-rw-r--r-- | include/linux/rtc/m48t59.h | 45 |
3 files changed, 69 insertions, 30 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index ecdff2002476..daf08fe980d0 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig | |||
@@ -406,10 +406,13 @@ config RTC_DRV_M48T86 | |||
406 | will be called rtc-m48t86. | 406 | will be called rtc-m48t86. |
407 | 407 | ||
408 | config RTC_DRV_M48T59 | 408 | config RTC_DRV_M48T59 |
409 | tristate "ST M48T59" | 409 | tristate "ST M48T59/M48T08/M48T02" |
410 | help | 410 | help |
411 | If you say Y here you will get support for the | 411 | If you say Y here you will get support for the |
412 | ST M48T59 RTC chip. | 412 | ST M48T59 RTC chip and compatible ST M48T08 and M48T02. |
413 | |||
414 | These chips are usually found in Sun SPARC and UltraSPARC | ||
415 | workstations. | ||
413 | 416 | ||
414 | This driver can also be built as a module, if so, the module | 417 | This driver can also be built as a module, if so, the module |
415 | will be called "rtc-m48t59". | 418 | will be called "rtc-m48t59". |
diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c index e085ab2c3dbe..50f9f10b32f0 100644 --- a/drivers/rtc/rtc-m48t59.c +++ b/drivers/rtc/rtc-m48t59.c | |||
@@ -24,8 +24,9 @@ | |||
24 | #define NO_IRQ (-1) | 24 | #define NO_IRQ (-1) |
25 | #endif | 25 | #endif |
26 | 26 | ||
27 | #define M48T59_READ(reg) pdata->read_byte(dev, reg) | 27 | #define M48T59_READ(reg) (pdata->read_byte(dev, pdata->offset + reg)) |
28 | #define M48T59_WRITE(val, reg) pdata->write_byte(dev, reg, val) | 28 | #define M48T59_WRITE(val, reg) \ |
29 | (pdata->write_byte(dev, pdata->offset + reg, val)) | ||
29 | 30 | ||
30 | #define M48T59_SET_BITS(mask, reg) \ | 31 | #define M48T59_SET_BITS(mask, reg) \ |
31 | M48T59_WRITE((M48T59_READ(reg) | (mask)), (reg)) | 32 | M48T59_WRITE((M48T59_READ(reg) | (mask)), (reg)) |
@@ -309,6 +310,11 @@ static const struct rtc_class_ops m48t59_rtc_ops = { | |||
309 | .proc = m48t59_rtc_proc, | 310 | .proc = m48t59_rtc_proc, |
310 | }; | 311 | }; |
311 | 312 | ||
313 | static const struct rtc_class_ops m48t02_rtc_ops = { | ||
314 | .read_time = m48t59_rtc_read_time, | ||
315 | .set_time = m48t59_rtc_set_time, | ||
316 | }; | ||
317 | |||
312 | static ssize_t m48t59_nvram_read(struct kobject *kobj, | 318 | static ssize_t m48t59_nvram_read(struct kobject *kobj, |
313 | struct bin_attribute *bin_attr, | 319 | struct bin_attribute *bin_attr, |
314 | char *buf, loff_t pos, size_t size) | 320 | char *buf, loff_t pos, size_t size) |
@@ -320,7 +326,7 @@ static ssize_t m48t59_nvram_read(struct kobject *kobj, | |||
320 | ssize_t cnt = 0; | 326 | ssize_t cnt = 0; |
321 | unsigned long flags; | 327 | unsigned long flags; |
322 | 328 | ||
323 | for (; size > 0 && pos < M48T59_NVRAM_SIZE; cnt++, size--) { | 329 | for (; size > 0 && pos < pdata->offset; cnt++, size--) { |
324 | spin_lock_irqsave(&m48t59->lock, flags); | 330 | spin_lock_irqsave(&m48t59->lock, flags); |
325 | *buf++ = M48T59_READ(cnt); | 331 | *buf++ = M48T59_READ(cnt); |
326 | spin_unlock_irqrestore(&m48t59->lock, flags); | 332 | spin_unlock_irqrestore(&m48t59->lock, flags); |
@@ -340,7 +346,7 @@ static ssize_t m48t59_nvram_write(struct kobject *kobj, | |||
340 | ssize_t cnt = 0; | 346 | ssize_t cnt = 0; |
341 | unsigned long flags; | 347 | unsigned long flags; |
342 | 348 | ||
343 | for (; size > 0 && pos < M48T59_NVRAM_SIZE; cnt++, size--) { | 349 | for (; size > 0 && pos < pdata->offset; cnt++, size--) { |
344 | spin_lock_irqsave(&m48t59->lock, flags); | 350 | spin_lock_irqsave(&m48t59->lock, flags); |
345 | M48T59_WRITE(*buf++, cnt); | 351 | M48T59_WRITE(*buf++, cnt); |
346 | spin_unlock_irqrestore(&m48t59->lock, flags); | 352 | spin_unlock_irqrestore(&m48t59->lock, flags); |
@@ -357,7 +363,6 @@ static struct bin_attribute m48t59_nvram_attr = { | |||
357 | }, | 363 | }, |
358 | .read = m48t59_nvram_read, | 364 | .read = m48t59_nvram_read, |
359 | .write = m48t59_nvram_write, | 365 | .write = m48t59_nvram_write, |
360 | .size = M48T59_NVRAM_SIZE, | ||
361 | }; | 366 | }; |
362 | 367 | ||
363 | static int __devinit m48t59_rtc_probe(struct platform_device *pdev) | 368 | static int __devinit m48t59_rtc_probe(struct platform_device *pdev) |
@@ -366,6 +371,8 @@ static int __devinit m48t59_rtc_probe(struct platform_device *pdev) | |||
366 | struct m48t59_private *m48t59 = NULL; | 371 | struct m48t59_private *m48t59 = NULL; |
367 | struct resource *res; | 372 | struct resource *res; |
368 | int ret = -ENOMEM; | 373 | int ret = -ENOMEM; |
374 | char *name; | ||
375 | const struct rtc_class_ops *ops; | ||
369 | 376 | ||
370 | /* This chip could be memory-mapped or I/O-mapped */ | 377 | /* This chip could be memory-mapped or I/O-mapped */ |
371 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 378 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
@@ -390,6 +397,8 @@ static int __devinit m48t59_rtc_probe(struct platform_device *pdev) | |||
390 | /* Ensure we only kmalloc platform data once */ | 397 | /* Ensure we only kmalloc platform data once */ |
391 | pdev->dev.platform_data = pdata; | 398 | pdev->dev.platform_data = pdata; |
392 | } | 399 | } |
400 | if (!pdata->type) | ||
401 | pdata->type = M48T59RTC_TYPE_M48T59; | ||
393 | 402 | ||
394 | /* Try to use the generic memory read/write ops */ | 403 | /* Try to use the generic memory read/write ops */ |
395 | if (!pdata->write_byte) | 404 | if (!pdata->write_byte) |
@@ -419,14 +428,36 @@ static int __devinit m48t59_rtc_probe(struct platform_device *pdev) | |||
419 | if (ret) | 428 | if (ret) |
420 | goto out; | 429 | goto out; |
421 | } | 430 | } |
431 | switch (pdata->type) { | ||
432 | case M48T59RTC_TYPE_M48T59: | ||
433 | name = "m48t59"; | ||
434 | ops = &m48t59_rtc_ops; | ||
435 | pdata->offset = 0x1ff0; | ||
436 | break; | ||
437 | case M48T59RTC_TYPE_M48T02: | ||
438 | name = "m48t02"; | ||
439 | ops = &m48t02_rtc_ops; | ||
440 | pdata->offset = 0x7f0; | ||
441 | break; | ||
442 | case M48T59RTC_TYPE_M48T08: | ||
443 | name = "m48t08"; | ||
444 | ops = &m48t02_rtc_ops; | ||
445 | pdata->offset = 0x1ff0; | ||
446 | break; | ||
447 | default: | ||
448 | dev_err(&pdev->dev, "Unknown RTC type\n"); | ||
449 | ret = -ENODEV; | ||
450 | goto out; | ||
451 | } | ||
422 | 452 | ||
423 | m48t59->rtc = rtc_device_register("m48t59", &pdev->dev, | 453 | m48t59->rtc = rtc_device_register(name, &pdev->dev, ops, THIS_MODULE); |
424 | &m48t59_rtc_ops, THIS_MODULE); | ||
425 | if (IS_ERR(m48t59->rtc)) { | 454 | if (IS_ERR(m48t59->rtc)) { |
426 | ret = PTR_ERR(m48t59->rtc); | 455 | ret = PTR_ERR(m48t59->rtc); |
427 | goto out; | 456 | goto out; |
428 | } | 457 | } |
429 | 458 | ||
459 | m48t59_nvram_attr.size = pdata->offset; | ||
460 | |||
430 | ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr); | 461 | ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr); |
431 | if (ret) | 462 | if (ret) |
432 | goto out; | 463 | goto out; |
@@ -489,5 +520,5 @@ module_init(m48t59_rtc_init); | |||
489 | module_exit(m48t59_rtc_exit); | 520 | module_exit(m48t59_rtc_exit); |
490 | 521 | ||
491 | MODULE_AUTHOR("Mark Zhan <rongkai.zhan@windriver.com>"); | 522 | MODULE_AUTHOR("Mark Zhan <rongkai.zhan@windriver.com>"); |
492 | MODULE_DESCRIPTION("M48T59 RTC driver"); | 523 | MODULE_DESCRIPTION("M48T59/M48T02/M48T08 RTC driver"); |
493 | MODULE_LICENSE("GPL"); | 524 | MODULE_LICENSE("GPL"); |
diff --git a/include/linux/rtc/m48t59.h b/include/linux/rtc/m48t59.h index e8c7c21ceb1f..41798505d157 100644 --- a/include/linux/rtc/m48t59.h +++ b/include/linux/rtc/m48t59.h | |||
@@ -18,40 +18,45 @@ | |||
18 | /* | 18 | /* |
19 | * M48T59 Register Offset | 19 | * M48T59 Register Offset |
20 | */ | 20 | */ |
21 | #define M48T59_YEAR 0x1fff | 21 | #define M48T59_YEAR 0xf |
22 | #define M48T59_MONTH 0x1ffe | 22 | #define M48T59_MONTH 0xe |
23 | #define M48T59_MDAY 0x1ffd /* Day of Month */ | 23 | #define M48T59_MDAY 0xd /* Day of Month */ |
24 | #define M48T59_WDAY 0x1ffc /* Day of Week */ | 24 | #define M48T59_WDAY 0xc /* Day of Week */ |
25 | #define M48T59_WDAY_CB 0x20 /* Century Bit */ | 25 | #define M48T59_WDAY_CB 0x20 /* Century Bit */ |
26 | #define M48T59_WDAY_CEB 0x10 /* Century Enable Bit */ | 26 | #define M48T59_WDAY_CEB 0x10 /* Century Enable Bit */ |
27 | #define M48T59_HOUR 0x1ffb | 27 | #define M48T59_HOUR 0xb |
28 | #define M48T59_MIN 0x1ffa | 28 | #define M48T59_MIN 0xa |
29 | #define M48T59_SEC 0x1ff9 | 29 | #define M48T59_SEC 0x9 |
30 | #define M48T59_CNTL 0x1ff8 | 30 | #define M48T59_CNTL 0x8 |
31 | #define M48T59_CNTL_READ 0x40 | 31 | #define M48T59_CNTL_READ 0x40 |
32 | #define M48T59_CNTL_WRITE 0x80 | 32 | #define M48T59_CNTL_WRITE 0x80 |
33 | #define M48T59_WATCHDOG 0x1ff7 | 33 | #define M48T59_WATCHDOG 0x7 |
34 | #define M48T59_INTR 0x1ff6 | 34 | #define M48T59_INTR 0x6 |
35 | #define M48T59_INTR_AFE 0x80 /* Alarm Interrupt Enable */ | 35 | #define M48T59_INTR_AFE 0x80 /* Alarm Interrupt Enable */ |
36 | #define M48T59_INTR_ABE 0x20 | 36 | #define M48T59_INTR_ABE 0x20 |
37 | #define M48T59_ALARM_DATE 0x1ff5 | 37 | #define M48T59_ALARM_DATE 0x5 |
38 | #define M48T59_ALARM_HOUR 0x1ff4 | 38 | #define M48T59_ALARM_HOUR 0x4 |
39 | #define M48T59_ALARM_MIN 0x1ff3 | 39 | #define M48T59_ALARM_MIN 0x3 |
40 | #define M48T59_ALARM_SEC 0x1ff2 | 40 | #define M48T59_ALARM_SEC 0x2 |
41 | #define M48T59_UNUSED 0x1ff1 | 41 | #define M48T59_UNUSED 0x1 |
42 | #define M48T59_FLAGS 0x1ff0 | 42 | #define M48T59_FLAGS 0x0 |
43 | #define M48T59_FLAGS_WDT 0x80 /* watchdog timer expired */ | 43 | #define M48T59_FLAGS_WDT 0x80 /* watchdog timer expired */ |
44 | #define M48T59_FLAGS_AF 0x40 /* alarm */ | 44 | #define M48T59_FLAGS_AF 0x40 /* alarm */ |
45 | #define M48T59_FLAGS_BF 0x10 /* low battery */ | 45 | #define M48T59_FLAGS_BF 0x10 /* low battery */ |
46 | 46 | ||
47 | #define M48T59_NVRAM_SIZE 0x1ff0 | 47 | #define M48T59RTC_TYPE_M48T59 0 /* to keep compatibility */ |
48 | #define M48T59RTC_TYPE_M48T02 1 | ||
49 | #define M48T59RTC_TYPE_M48T08 2 | ||
48 | 50 | ||
49 | struct m48t59_plat_data { | 51 | struct m48t59_plat_data { |
50 | /* The method to access M48T59 registers, | 52 | /* The method to access M48T59 registers */ |
51 | * NOTE: The 'ofs' should be 0x00~0x1fff | ||
52 | */ | ||
53 | void (*write_byte)(struct device *dev, u32 ofs, u8 val); | 53 | void (*write_byte)(struct device *dev, u32 ofs, u8 val); |
54 | unsigned char (*read_byte)(struct device *dev, u32 ofs); | 54 | unsigned char (*read_byte)(struct device *dev, u32 ofs); |
55 | |||
56 | int type; /* RTC model */ | ||
57 | |||
58 | /* offset to RTC registers, automatically set according to the type */ | ||
59 | unsigned int offset; | ||
55 | }; | 60 | }; |
56 | 61 | ||
57 | #endif /* _LINUX_RTC_M48T59_H_ */ | 62 | #endif /* _LINUX_RTC_M48T59_H_ */ |