Handling of extended interrupts (kickstart, wake-up, ram-clear) was moved off to a work queue, but the interrupts aren't acknowledged in the interrupt handler. This leads to a deadlock, if driver is used with interrupts. To fix this we use a threaded interrupt, get rid of the work queue and do locking with just the rtc mutex lock.
Unified · Split
| @@ -510,10 +510,6 @@ static int · 509 unmodified lines | ||
| 510 | 510 | ds1685_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) |
| 511 | 511 | { |
| 512 | 512 | struct ds1685_priv *rtc = dev_get_drvdata(dev); |
| 513 | − unsigned long flags = 0; | |
| 514 | − | |
| 515 | − /* Enable/disable the Alarm IRQ-Enable flag. */ | |
| 516 | − spin_lock_irqsave(&rtc->lock, flags); | |
| 517 | 513 | |
| 518 | 514 | /* Flip the requisite interrupt-enable bit. */ |
| 519 | 515 | if (enabled) |
| @@ -525,7 +521,6 @@ ds1685_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) · 5 unmodified lines | ||
| 525 | 521 | |
| 526 | 522 | /* Read Control C to clear all the flag bits. */ |
| 527 | 523 | rtc->read(rtc, RTC_CTRL_C); |
| 528 | − spin_unlock_irqrestore(&rtc->lock, flags); | |
| 529 | 524 | |
| 530 | 525 | return 0; |
| 531 | 526 | } |
| @@ -533,98 +528,18 @@ ds1685_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) · 1 unmodified line | ||
| 533 | 528 | |
| 534 | 529 | |
| 535 | 530 | /* ----------------------------------------------------------------------- */ |
| 536 | −/* IRQ handler & workqueue. */ | |
| 537 | − | |
| 538 | −/** | |
| 539 | − * ds1685_rtc_irq_handler - IRQ handler. | |
| 540 | − * @irq: IRQ number. | |
| 541 | − * @dev_id: platform device pointer. | |
| 542 | − */ | |
| 543 | −static irqreturn_t | |
| 544 | −ds1685_rtc_irq_handler(int irq, void *dev_id) | |
| 545 | −{ | |
| 546 | − struct platform_device *pdev = dev_id; | |
| 547 | − struct ds1685_priv *rtc = platform_get_drvdata(pdev); | |
| 548 | − u8 ctrlb, ctrlc; | |
| 549 | − unsigned long events = 0; | |
| 550 | − u8 num_irqs = 0; | |
| 551 | − | |
| 552 | − /* Abort early if the device isn't ready yet (i.e., DEBUG_SHIRQ). */ | |
| 553 | − if (unlikely(!rtc)) | |
| 554 | − return IRQ_HANDLED; | |
| 555 | − | |
| 556 | − /* Ctrlb holds the interrupt-enable bits and ctrlc the flag bits. */ | |
| 557 | − spin_lock(&rtc->lock); | |
| 558 | − ctrlb = rtc->read(rtc, RTC_CTRL_B); | |
| 559 | − ctrlc = rtc->read(rtc, RTC_CTRL_C); | |
| 560 | − | |
| 561 | − /* Is the IRQF bit set? */ | |
| 562 | − if (likely(ctrlc & RTC_CTRL_C_IRQF)) { | |
| 563 | − /* | |
| 564 | − * We need to determine if it was one of the standard | |
| 565 | − * events: PF, AF, or UF. If so, we handle them and | |
| 566 | − * update the RTC core. | |
| 567 | − */ | |
| 568 | − if (likely(ctrlc & RTC_CTRL_B_PAU_MASK)) { | |
| 569 | − events = RTC_IRQF; | |
| 570 | − | |
| 571 | − /* Check for a periodic interrupt. */ | |
| 572 | − if ((ctrlb & RTC_CTRL_B_PIE) && | |
| 573 | − (ctrlc & RTC_CTRL_C_PF)) { | |
| 574 | − events |= RTC_PF; | |
| 575 | − num_irqs++; | |
| 576 | − } | |
| 577 | − | |
| 578 | − /* Check for an alarm interrupt. */ | |
| 579 | − if ((ctrlb & RTC_CTRL_B_AIE) && | |
| 580 | − (ctrlc & RTC_CTRL_C_AF)) { | |
| 581 | − events |= RTC_AF; | |
| 582 | − num_irqs++; | |
| 583 | − } | |
| 584 | − | |
| 585 | − /* Check for an update interrupt. */ | |
| 586 | − if ((ctrlb & RTC_CTRL_B_UIE) && | |
| 587 | − (ctrlc & RTC_CTRL_C_UF)) { | |
| 588 | − events |= RTC_UF; | |
| 589 | − num_irqs++; | |
| 590 | − } | |
| 591 | − | |
| 592 | − rtc_update_irq(rtc->dev, num_irqs, events); | |
| 593 | − } else { | |
| 594 | − /* | |
| 595 | − * One of the "extended" interrupts was received that | |
| 596 | − * is not recognized by the RTC core. These need to | |
| 597 | − * be handled in task context as they can call other | |
| 598 | − * functions and the time spent in irq context needs | |
| 599 | − * to be minimized. Schedule them into a workqueue | |
| 600 | − * and inform the RTC core that the IRQs were handled. | |
| 601 | − */ | |
| 602 | − spin_unlock(&rtc->lock); | |
| 603 | − schedule_work(&rtc->work); | |
| 604 | − rtc_update_irq(rtc->dev, 0, 0); | |
| 605 | − return IRQ_HANDLED; | |
| 606 | − } | |
| 607 | − } | |
| 608 | − spin_unlock(&rtc->lock); | |
| 609 | − | |
| 610 | − return events ? IRQ_HANDLED : IRQ_NONE; | |
| 611 | −} | |
| 531 | +/* IRQ handler */ | |
| 612 | 532 | |
| 613 | 533 | /** |
| 614 | − * ds1685_rtc_work_queue - work queue handler. | |
| 615 | − * @work: work_struct containing data to work on in task context. | |
| 534 | + * ds1685_rtc_extended_irq - take care of extended interrupts | |
| 535 | + * @rtc: pointer to the ds1685 rtc structure. | |
| 536 | + * @pdev: platform device pointer. | |
| 616 | 537 | */ |
| 617 | 538 | static void |
| 618 | −ds1685_rtc_work_queue(struct work_struct *work) | |
| 539 | +ds1685_rtc_extended_irq(struct ds1685_priv *rtc, struct platform_device *pdev) | |
| 619 | 540 | { |
| 620 | − struct ds1685_priv *rtc = container_of(work, | |
| 621 | − struct ds1685_priv, work); | |
| 622 | − struct platform_device *pdev = to_platform_device(&rtc->dev->dev); | |
| 623 | − struct mutex *rtc_mutex = &rtc->dev->ops_lock; | |
| 624 | 541 | u8 ctrl4a, ctrl4b; |
| 625 | 542 | |
| 626 | − mutex_lock(rtc_mutex); | |
| 627 | − | |
| 628 | 543 | ds1685_rtc_switch_to_bank1(rtc); |
| 629 | 544 | ctrl4a = rtc->read(rtc, RTC_EXT_CTRL_4A); |
| 630 | 545 | ctrl4b = rtc->read(rtc, RTC_EXT_CTRL_4B); |
| @@ -703,8 +618,76 @@ ds1685_rtc_work_queue(struct work_struct *work) · 72 unmodified lines | ||
| 703 | 618 | "RAM-Clear IRQ just occurred!\n"); |
| 704 | 619 | } |
| 705 | 620 | ds1685_rtc_switch_to_bank0(rtc); |
| 621 | +} | |
| 622 | + | |
| 623 | +/** | |
| 624 | + * ds1685_rtc_irq_handler - IRQ handler. | |
| 625 | + * @irq: IRQ number. | |
| 626 | + * @dev_id: platform device pointer. | |
| 627 | + */ | |
| 628 | +static irqreturn_t | |
| 629 | +ds1685_rtc_irq_handler(int irq, void *dev_id) | |
| 630 | +{ | |
| 631 | + struct platform_device *pdev = dev_id; | |
| 632 | + struct ds1685_priv *rtc = platform_get_drvdata(pdev); | |
| 633 | + struct mutex *rtc_mutex; | |
| 634 | + u8 ctrlb, ctrlc; | |
| 635 | + unsigned long events = 0; | |
| 636 | + u8 num_irqs = 0; | |
| 637 | + | |
| 638 | + /* Abort early if the device isn't ready yet (i.e., DEBUG_SHIRQ). */ | |
| 639 | + if (unlikely(!rtc)) | |
| 640 | + return IRQ_HANDLED; | |
| 641 | + | |
| 642 | + rtc_mutex = &rtc->dev->ops_lock; | |
| 643 | + mutex_lock(rtc_mutex); | |
| 644 | + | |
| 645 | + /* Ctrlb holds the interrupt-enable bits and ctrlc the flag bits. */ | |
| 646 | + ctrlb = rtc->read(rtc, RTC_CTRL_B); | |
| 647 | + ctrlc = rtc->read(rtc, RTC_CTRL_C); | |
| 648 | + | |
| 649 | + /* Is the IRQF bit set? */ | |
| 650 | + if (likely(ctrlc & RTC_CTRL_C_IRQF)) { | |
| 651 | + /* | |
| 652 | + * We need to determine if it was one of the standard | |
| 653 | + * events: PF, AF, or UF. If so, we handle them and | |
| 654 | + * update the RTC core. | |
| 655 | + */ | |
| 656 | + if (likely(ctrlc & RTC_CTRL_B_PAU_MASK)) { | |
| 657 | + events = RTC_IRQF; | |
| 658 | + | |
| 659 | + /* Check for a periodic interrupt. */ | |
| 660 | + if ((ctrlb & RTC_CTRL_B_PIE) && | |
| 661 | + (ctrlc & RTC_CTRL_C_PF)) { | |
| 662 | + events |= RTC_PF; | |
| 663 | + num_irqs++; | |
| 664 | + } | |
| 665 | + | |
| 666 | + /* Check for an alarm interrupt. */ | |
| 667 | + if ((ctrlb & RTC_CTRL_B_AIE) && | |
| 668 | + (ctrlc & RTC_CTRL_C_AF)) { | |
| 669 | + events |= RTC_AF; | |
| 670 | + num_irqs++; | |
| 671 | + } | |
| 706 | 672 | |
| 673 | + /* Check for an update interrupt. */ | |
| 674 | + if ((ctrlb & RTC_CTRL_B_UIE) && | |
| 675 | + (ctrlc & RTC_CTRL_C_UF)) { | |
| 676 | + events |= RTC_UF; | |
| 677 | + num_irqs++; | |
| 678 | + } | |
| 679 | + } else { | |
| 680 | + /* | |
| 681 | + * One of the "extended" interrupts was received that | |
| 682 | + * is not recognized by the RTC core. | |
| 683 | + */ | |
| 684 | + ds1685_rtc_extended_irq(rtc, pdev); | |
| 685 | + } | |
| 686 | + } | |
| 687 | + rtc_update_irq(rtc->dev, num_irqs, events); | |
| 707 | 688 | mutex_unlock(rtc_mutex); |
| 689 | + | |
| 690 | + return events ? IRQ_HANDLED : IRQ_NONE; | |
| 708 | 691 | } |
| 709 | 692 | /* ----------------------------------------------------------------------- */ |
| 710 | 693 | |
| @@ -833,11 +816,15 @@ static int ds1685_nvram_read(void *priv, unsigned int pos, void *val, · 122 unmodified lines | ||
| 833 | 816 | size_t size) |
| 834 | 817 | { |
| 835 | 818 | struct ds1685_priv *rtc = priv; |
| 819 | + struct mutex *rtc_mutex = &rtc->dev->ops_lock; | |
| 836 | 820 | ssize_t count; |
| 837 | − unsigned long flags = 0; | |
| 838 | 821 | u8 *buf = val; |
| 822 | + int err; | |
| 823 | + | |
| 824 | + err = mutex_lock_interruptible(rtc_mutex); | |
| 825 | + if (err) | |
| 826 | + return err; | |
| 839 | 827 | |
| 840 | − spin_lock_irqsave(&rtc->lock, flags); | |
| 841 | 828 | ds1685_rtc_switch_to_bank0(rtc); |
| 842 | 829 | |
| 843 | 830 | /* Read NVRAM in time and bank0 registers. */ |
| @@ -887,7 +874,7 @@ static int ds1685_nvram_read(void *priv, unsigned int pos, void *val, · 43 unmodified lines | ||
| 887 | 874 | ds1685_rtc_switch_to_bank0(rtc); |
| 888 | 875 | } |
| 889 | 876 | #endif /* !CONFIG_RTC_DRV_DS1689 */ |
| 890 | − spin_unlock_irqrestore(&rtc->lock, flags); | |
| 877 | + mutex_unlock(rtc_mutex); | |
| 891 | 878 | |
| 892 | 879 | return 0; |
| 893 | 880 | } |
| @@ -896,11 +883,15 @@ static int ds1685_nvram_write(void *priv, unsigned int pos, void *val, · 2 unmodified lines | ||
| 896 | 883 | size_t size) |
| 897 | 884 | { |
| 898 | 885 | struct ds1685_priv *rtc = priv; |
| 886 | + struct mutex *rtc_mutex = &rtc->dev->ops_lock; | |
| 899 | 887 | ssize_t count; |
| 900 | − unsigned long flags = 0; | |
| 901 | 888 | u8 *buf = val; |
| 889 | + int err; | |
| 890 | + | |
| 891 | + err = mutex_lock_interruptible(rtc_mutex); | |
| 892 | + if (err) | |
| 893 | + return err; | |
| 902 | 894 | |
| 903 | − spin_lock_irqsave(&rtc->lock, flags); | |
| 904 | 895 | ds1685_rtc_switch_to_bank0(rtc); |
| 905 | 896 | |
| 906 | 897 | /* Write NVRAM in time and bank0 registers. */ |
| @@ -950,7 +941,7 @@ static int ds1685_nvram_write(void *priv, unsigned int pos, void *val, · 43 unmodified lines | ||
| 950 | 941 | ds1685_rtc_switch_to_bank0(rtc); |
| 951 | 942 | } |
| 952 | 943 | #endif /* !CONFIG_RTC_DRV_DS1689 */ |
| 953 | − spin_unlock_irqrestore(&rtc->lock, flags); | |
| 944 | + mutex_unlock(rtc_mutex); | |
| 954 | 945 | |
| 955 | 946 | return 0; |
| 956 | 947 | } |
| @@ -1141,9 +1132,7 @@ ds1685_rtc_probe(struct platform_device *pdev) · 184 unmodified lines | ||
| 1141 | 1132 | if (pdata->plat_post_ram_clear) |
| 1142 | 1133 | rtc->post_ram_clear = pdata->plat_post_ram_clear; |
| 1143 | 1134 | |
| 1144 | − /* Init the spinlock, workqueue, & set the driver data. */ | |
| 1145 | − spin_lock_init(&rtc->lock); | |
| 1146 | − INIT_WORK(&rtc->work, ds1685_rtc_work_queue); | |
| 1135 | + /* set the driver data. */ | |
| 1147 | 1136 | platform_set_drvdata(pdev, rtc); |
| 1148 | 1137 | |
| 1149 | 1138 | /* Turn the oscillator on if is not already on (DV1 = 1). */ |
| @@ -1299,22 +1288,23 @@ ds1685_rtc_probe(struct platform_device *pdev) · 149 unmodified lines | ||
| 1299 | 1288 | */ |
| 1300 | 1289 | if (!pdata->no_irq) { |
| 1301 | 1290 | ret = platform_get_irq(pdev, 0); |
| 1302 | − if (ret > 0) { | |
| 1303 | − rtc->irq_num = ret; | |
| 1304 | − | |
| 1305 | − /* Request an IRQ. */ | |
| 1306 | − ret = devm_request_irq(&pdev->dev, rtc->irq_num, | |
| 1307 | − ds1685_rtc_irq_handler, | |
| 1308 | − IRQF_SHARED, pdev->name, pdev); | |
| 1309 | − | |
| 1310 | − /* Check to see if something came back. */ | |
| 1311 | − if (unlikely(ret)) { | |
| 1312 | − dev_warn(&pdev->dev, | |
| 1313 | − "RTC interrupt not available\n"); | |
| 1314 | − rtc->irq_num = 0; | |
| 1315 | − } | |
| 1316 | − } else | |
| 1291 | + if (ret <= 0) | |
| 1317 | 1292 | return ret; |
| 1293 | + | |
| 1294 | + rtc->irq_num = ret; | |
| 1295 | + | |
| 1296 | + /* Request an IRQ. */ | |
| 1297 | + ret = devm_request_threaded_irq(&pdev->dev, rtc->irq_num, | |
| 1298 | + NULL, ds1685_rtc_irq_handler, | |
| 1299 | + IRQF_SHARED | IRQF_ONESHOT, | |
| 1300 | + pdev->name, pdev); | |
| 1301 | + | |
| 1302 | + /* Check to see if something came back. */ | |
| 1303 | + if (unlikely(ret)) { | |
| 1304 | + dev_warn(&pdev->dev, | |
| 1305 | + "RTC interrupt not available\n"); | |
| 1306 | + rtc->irq_num = 0; | |
| 1307 | + } | |
| 1318 | 1308 | } |
| 1319 | 1309 | rtc->no_irq = pdata->no_irq; |
| 1320 | 1310 | |
| @@ -1361,8 +1351,6 @@ ds1685_rtc_remove(struct platform_device *pdev) · 40 unmodified lines | ||
| 1361 | 1351 | (rtc->read(rtc, RTC_EXT_CTRL_4A) & |
| 1362 | 1352 | ~(RTC_CTRL_4A_RWK_MASK))); |
| 1363 | 1353 | |
| 1364 | − cancel_work_sync(&rtc->work); | |
| 1365 | − | |
| 1366 | 1354 | return 0; |
| 1367 | 1355 | } |
| 1368 | 1356 | |
| @@ -48,8 +48,6 @@ struct ds1685_priv { · 47 unmodified lines | ||
| 48 | 48 | u32 regstep; |
| 49 | 49 | resource_size_t baseaddr; |
| 50 | 50 | size_t size; |
| 51 | − spinlock_t lock; | |
| 52 | − struct work_struct work; | |
| 53 | 51 | int irq_num; |
| 54 | 52 | bool bcd_mode; |
| 55 | 53 | bool no_irq; |