diff options
Diffstat (limited to 'drivers/rtc')
| -rw-r--r-- | drivers/rtc/rtc-cmos.c | 129 |
1 files changed, 117 insertions, 12 deletions
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c index 29cf1457ca10..ab455ddb16cf 100644 --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c | |||
| @@ -393,6 +393,80 @@ static const struct rtc_class_ops cmos_rtc_ops = { | |||
| 393 | 393 | ||
| 394 | /*----------------------------------------------------------------*/ | 394 | /*----------------------------------------------------------------*/ |
| 395 | 395 | ||
| 396 | /* | ||
| 397 | * All these chips have at least 64 bytes of address space, shared by | ||
| 398 | * RTC registers and NVRAM. Most of those bytes of NVRAM are used | ||
| 399 | * by boot firmware. Modern chips have 128 or 256 bytes. | ||
| 400 | */ | ||
| 401 | |||
| 402 | #define NVRAM_OFFSET (RTC_REG_D + 1) | ||
| 403 | |||
| 404 | static ssize_t | ||
| 405 | cmos_nvram_read(struct kobject *kobj, struct bin_attribute *attr, | ||
| 406 | char *buf, loff_t off, size_t count) | ||
| 407 | { | ||
| 408 | int retval; | ||
| 409 | |||
| 410 | if (unlikely(off >= attr->size)) | ||
| 411 | return 0; | ||
| 412 | if ((off + count) > attr->size) | ||
| 413 | count = attr->size - off; | ||
| 414 | |||
| 415 | spin_lock_irq(&rtc_lock); | ||
| 416 | for (retval = 0, off += NVRAM_OFFSET; count--; retval++, off++) | ||
| 417 | *buf++ = CMOS_READ(off); | ||
| 418 | spin_unlock_irq(&rtc_lock); | ||
| 419 | |||
| 420 | return retval; | ||
| 421 | } | ||
| 422 | |||
| 423 | static ssize_t | ||
| 424 | cmos_nvram_write(struct kobject *kobj, struct bin_attribute *attr, | ||
| 425 | char *buf, loff_t off, size_t count) | ||
| 426 | { | ||
| 427 | struct cmos_rtc *cmos; | ||
| 428 | int retval; | ||
| 429 | |||
| 430 | cmos = dev_get_drvdata(container_of(kobj, struct device, kobj)); | ||
| 431 | if (unlikely(off >= attr->size)) | ||
| 432 | return -EFBIG; | ||
| 433 | if ((off + count) > attr->size) | ||
| 434 | count = attr->size - off; | ||
| 435 | |||
| 436 | /* NOTE: on at least PCs and Ataris, the boot firmware uses a | ||
| 437 | * checksum on part of the NVRAM data. That's currently ignored | ||
| 438 | * here. If userspace is smart enough to know what fields of | ||
| 439 | * NVRAM to update, updating checksums is also part of its job. | ||
| 440 | */ | ||
| 441 | spin_lock_irq(&rtc_lock); | ||
| 442 | for (retval = 0, off += NVRAM_OFFSET; count--; retval++, off++) { | ||
| 443 | /* don't trash RTC registers */ | ||
| 444 | if (off == cmos->day_alrm | ||
| 445 | || off == cmos->mon_alrm | ||
| 446 | || off == cmos->century) | ||
| 447 | buf++; | ||
| 448 | else | ||
| 449 | CMOS_WRITE(*buf++, off); | ||
| 450 | } | ||
| 451 | spin_unlock_irq(&rtc_lock); | ||
| 452 | |||
| 453 | return retval; | ||
| 454 | } | ||
| 455 | |||
| 456 | static struct bin_attribute nvram = { | ||
| 457 | .attr = { | ||
| 458 | .name = "nvram", | ||
| 459 | .mode = S_IRUGO | S_IWUSR, | ||
| 460 | .owner = THIS_MODULE, | ||
| 461 | }, | ||
| 462 | |||
| 463 | .read = cmos_nvram_read, | ||
| 464 | .write = cmos_nvram_write, | ||
| 465 | /* size gets set up later */ | ||
| 466 | }; | ||
| 467 | |||
| 468 | /*----------------------------------------------------------------*/ | ||
| 469 | |||
| 396 | static struct cmos_rtc cmos_rtc; | 470 | static struct cmos_rtc cmos_rtc; |
| 397 | 471 | ||
| 398 | static irqreturn_t cmos_interrupt(int irq, void *p) | 472 | static irqreturn_t cmos_interrupt(int irq, void *p) |
| @@ -412,11 +486,9 @@ static irqreturn_t cmos_interrupt(int irq, void *p) | |||
| 412 | } | 486 | } |
| 413 | 487 | ||
| 414 | #ifdef CONFIG_PNP | 488 | #ifdef CONFIG_PNP |
| 415 | #define is_pnp() 1 | ||
| 416 | #define INITSECTION | 489 | #define INITSECTION |
| 417 | 490 | ||
| 418 | #else | 491 | #else |
| 419 | #define is_pnp() 0 | ||
| 420 | #define INITSECTION __init | 492 | #define INITSECTION __init |
| 421 | #endif | 493 | #endif |
| 422 | 494 | ||
| @@ -426,6 +498,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq) | |||
| 426 | struct cmos_rtc_board_info *info = dev->platform_data; | 498 | struct cmos_rtc_board_info *info = dev->platform_data; |
| 427 | int retval = 0; | 499 | int retval = 0; |
| 428 | unsigned char rtc_control; | 500 | unsigned char rtc_control; |
| 501 | unsigned address_space; | ||
| 429 | 502 | ||
| 430 | /* there can be only one ... */ | 503 | /* there can be only one ... */ |
| 431 | if (cmos_rtc.dev) | 504 | if (cmos_rtc.dev) |
| @@ -450,15 +523,36 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq) | |||
| 450 | cmos_rtc.irq = rtc_irq; | 523 | cmos_rtc.irq = rtc_irq; |
| 451 | cmos_rtc.iomem = ports; | 524 | cmos_rtc.iomem = ports; |
| 452 | 525 | ||
| 526 | /* Heuristic to deduce NVRAM size ... do what the legacy NVRAM | ||
| 527 | * driver did, but don't reject unknown configs. Old hardware | ||
| 528 | * won't address 128 bytes, and for now we ignore the way newer | ||
| 529 | * chips can address 256 bytes (using two more i/o ports). | ||
| 530 | */ | ||
| 531 | #if defined(CONFIG_ATARI) | ||
| 532 | address_space = 64; | ||
| 533 | #elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) | ||
| 534 | address_space = 128; | ||
| 535 | #else | ||
| 536 | #warning Assuming 128 bytes of RTC+NVRAM address space, not 64 bytes. | ||
| 537 | address_space = 128; | ||
| 538 | #endif | ||
| 539 | |||
| 453 | /* For ACPI systems extension info comes from the FADT. On others, | 540 | /* For ACPI systems extension info comes from the FADT. On others, |
| 454 | * board specific setup provides it as appropriate. Systems where | 541 | * board specific setup provides it as appropriate. Systems where |
| 455 | * the alarm IRQ isn't automatically a wakeup IRQ (like ACPI, and | 542 | * the alarm IRQ isn't automatically a wakeup IRQ (like ACPI, and |
| 456 | * some almost-clones) can provide hooks to make that behave. | 543 | * some almost-clones) can provide hooks to make that behave. |
| 544 | * | ||
| 545 | * Note that ACPI doesn't preclude putting these registers into | ||
| 546 | * "extended" areas of the chip, including some that we won't yet | ||
| 547 | * expect CMOS_READ and friends to handle. | ||
| 457 | */ | 548 | */ |
| 458 | if (info) { | 549 | if (info) { |
| 459 | cmos_rtc.day_alrm = info->rtc_day_alarm; | 550 | if (info->rtc_day_alarm && info->rtc_day_alarm < 128) |
| 460 | cmos_rtc.mon_alrm = info->rtc_mon_alarm; | 551 | cmos_rtc.day_alrm = info->rtc_day_alarm; |
| 461 | cmos_rtc.century = info->rtc_century; | 552 | if (info->rtc_mon_alarm && info->rtc_mon_alarm < 128) |
| 553 | cmos_rtc.mon_alrm = info->rtc_mon_alarm; | ||
| 554 | if (info->rtc_century && info->rtc_century < 128) | ||
| 555 | cmos_rtc.century = info->rtc_century; | ||
| 462 | 556 | ||
| 463 | if (info->wake_on && info->wake_off) { | 557 | if (info->wake_on && info->wake_off) { |
| 464 | cmos_rtc.wake_on = info->wake_on; | 558 | cmos_rtc.wake_on = info->wake_on; |
| @@ -518,10 +612,13 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq) | |||
| 518 | goto cleanup1; | 612 | goto cleanup1; |
| 519 | } | 613 | } |
| 520 | 614 | ||
| 521 | /* REVISIT optionally make 50 or 114 bytes NVRAM available, | 615 | /* export at least the first block of NVRAM */ |
| 522 | * like rtc-ds1553, rtc-ds1742 ... this will often include | 616 | nvram.size = address_space - NVRAM_OFFSET; |
| 523 | * registers for century, and day/month alarm. | 617 | retval = sysfs_create_bin_file(&dev->kobj, &nvram); |
| 524 | */ | 618 | if (retval < 0) { |
| 619 | dev_dbg(dev, "can't create nvram file? %d\n", retval); | ||
| 620 | goto cleanup2; | ||
| 621 | } | ||
| 525 | 622 | ||
| 526 | pr_info("%s: alarms up to one %s%s\n", | 623 | pr_info("%s: alarms up to one %s%s\n", |
| 527 | cmos_rtc.rtc->dev.bus_id, | 624 | cmos_rtc.rtc->dev.bus_id, |
| @@ -536,6 +633,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq) | |||
| 536 | 633 | ||
| 537 | return 0; | 634 | return 0; |
| 538 | 635 | ||
| 636 | cleanup2: | ||
| 637 | if (is_valid_irq(rtc_irq)) | ||
| 638 | free_irq(rtc_irq, cmos_rtc.rtc); | ||
| 539 | cleanup1: | 639 | cleanup1: |
| 540 | cmos_rtc.dev = NULL; | 640 | cmos_rtc.dev = NULL; |
| 541 | rtc_device_unregister(cmos_rtc.rtc); | 641 | rtc_device_unregister(cmos_rtc.rtc); |
| @@ -563,6 +663,8 @@ static void __exit cmos_do_remove(struct device *dev) | |||
| 563 | 663 | ||
| 564 | cmos_do_shutdown(); | 664 | cmos_do_shutdown(); |
| 565 | 665 | ||
| 666 | sysfs_remove_bin_file(&dev->kobj, &nvram); | ||
| 667 | |||
| 566 | if (is_valid_irq(cmos->irq)) | 668 | if (is_valid_irq(cmos->irq)) |
| 567 | free_irq(cmos->irq, cmos->rtc); | 669 | free_irq(cmos->irq, cmos->rtc); |
| 568 | 670 | ||
| @@ -659,9 +761,12 @@ static int cmos_resume(struct device *dev) | |||
| 659 | 761 | ||
| 660 | /*----------------------------------------------------------------*/ | 762 | /*----------------------------------------------------------------*/ |
| 661 | 763 | ||
| 662 | /* The "CMOS" RTC normally lives on the platform_bus. On ACPI systems, | 764 | /* On non-x86 systems, a "CMOS" RTC lives most naturally on platform_bus. |
| 663 | * the device node will always be created as a PNPACPI device. Plus | 765 | * ACPI systems always list these as PNPACPI devices, and pre-ACPI PCs |
| 664 | * pre-ACPI PCs probably list it in the PNPBIOS tables. | 766 | * probably list them in similar PNPBIOS tables; so PNP is more common. |
| 767 | * | ||
| 768 | * We don't use legacy "poke at the hardware" probing. Ancient PCs that | ||
| 769 | * predate even PNPBIOS should set up platform_bus devices. | ||
| 665 | */ | 770 | */ |
| 666 | 771 | ||
| 667 | #ifdef CONFIG_PNP | 772 | #ifdef CONFIG_PNP |
