Commit e402af6c authored by Ludovic Desroches's avatar Ludovic Desroches Committed by Nicolas Ferre

ARM: at91: fix rtc-at91sam9 irq issue due to sparse irq support

AT91_ID_SYS as virq is incorrect because of spare irq support which
introduces NR_IRQS_LEGACY offset. It modifies rtc-at91sam9 driver in
order to get irq from resources.
Signed-off-by: default avatarLudovic Desroches <ludovic.desroches@atmel.com>
Signed-off-by: default avatarNicolas Ferre <nicolas.ferre@atmel.com>
parent 85ebea12
...@@ -726,6 +726,8 @@ static struct resource rtt_resources[] = { ...@@ -726,6 +726,8 @@ static struct resource rtt_resources[] = {
.flags = IORESOURCE_MEM, .flags = IORESOURCE_MEM,
}, { }, {
.flags = IORESOURCE_MEM, .flags = IORESOURCE_MEM,
}, {
.flags = IORESOURCE_IRQ,
}, },
}; };
...@@ -744,10 +746,12 @@ static void __init at91_add_device_rtt_rtc(void) ...@@ -744,10 +746,12 @@ static void __init at91_add_device_rtt_rtc(void)
* The second resource is needed: * The second resource is needed:
* GPBR will serve as the storage for RTC time offset * GPBR will serve as the storage for RTC time offset
*/ */
at91sam9260_rtt_device.num_resources = 2; at91sam9260_rtt_device.num_resources = 3;
rtt_resources[1].start = AT91SAM9260_BASE_GPBR + rtt_resources[1].start = AT91SAM9260_BASE_GPBR +
4 * CONFIG_RTC_DRV_AT91SAM9_GPBR; 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR;
rtt_resources[1].end = rtt_resources[1].start + 3; rtt_resources[1].end = rtt_resources[1].start + 3;
rtt_resources[2].start = NR_IRQS_LEGACY + AT91_ID_SYS;
rtt_resources[2].end = NR_IRQS_LEGACY + AT91_ID_SYS;
} }
#else #else
static void __init at91_add_device_rtt_rtc(void) static void __init at91_add_device_rtt_rtc(void)
......
...@@ -609,6 +609,8 @@ static struct resource rtt_resources[] = { ...@@ -609,6 +609,8 @@ static struct resource rtt_resources[] = {
.flags = IORESOURCE_MEM, .flags = IORESOURCE_MEM,
}, { }, {
.flags = IORESOURCE_MEM, .flags = IORESOURCE_MEM,
}, {
.flags = IORESOURCE_IRQ,
} }
}; };
...@@ -626,10 +628,12 @@ static void __init at91_add_device_rtt_rtc(void) ...@@ -626,10 +628,12 @@ static void __init at91_add_device_rtt_rtc(void)
* The second resource is needed: * The second resource is needed:
* GPBR will serve as the storage for RTC time offset * GPBR will serve as the storage for RTC time offset
*/ */
at91sam9261_rtt_device.num_resources = 2; at91sam9261_rtt_device.num_resources = 3;
rtt_resources[1].start = AT91SAM9261_BASE_GPBR + rtt_resources[1].start = AT91SAM9261_BASE_GPBR +
4 * CONFIG_RTC_DRV_AT91SAM9_GPBR; 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR;
rtt_resources[1].end = rtt_resources[1].start + 3; rtt_resources[1].end = rtt_resources[1].start + 3;
rtt_resources[2].start = NR_IRQS_LEGACY + AT91_ID_SYS;
rtt_resources[2].end = NR_IRQS_LEGACY + AT91_ID_SYS;
} }
#else #else
static void __init at91_add_device_rtt_rtc(void) static void __init at91_add_device_rtt_rtc(void)
......
...@@ -990,6 +990,8 @@ static struct resource rtt0_resources[] = { ...@@ -990,6 +990,8 @@ static struct resource rtt0_resources[] = {
.flags = IORESOURCE_MEM, .flags = IORESOURCE_MEM,
}, { }, {
.flags = IORESOURCE_MEM, .flags = IORESOURCE_MEM,
}, {
.flags = IORESOURCE_IRQ,
} }
}; };
...@@ -1006,6 +1008,8 @@ static struct resource rtt1_resources[] = { ...@@ -1006,6 +1008,8 @@ static struct resource rtt1_resources[] = {
.flags = IORESOURCE_MEM, .flags = IORESOURCE_MEM,
}, { }, {
.flags = IORESOURCE_MEM, .flags = IORESOURCE_MEM,
}, {
.flags = IORESOURCE_IRQ,
} }
}; };
...@@ -1027,14 +1031,14 @@ static void __init at91_add_device_rtt_rtc(void) ...@@ -1027,14 +1031,14 @@ static void __init at91_add_device_rtt_rtc(void)
* The second resource is needed only for the chosen RTT: * The second resource is needed only for the chosen RTT:
* GPBR will serve as the storage for RTC time offset * GPBR will serve as the storage for RTC time offset
*/ */
at91sam9263_rtt0_device.num_resources = 2; at91sam9263_rtt0_device.num_resources = 3;
at91sam9263_rtt1_device.num_resources = 1; at91sam9263_rtt1_device.num_resources = 1;
pdev = &at91sam9263_rtt0_device; pdev = &at91sam9263_rtt0_device;
r = rtt0_resources; r = rtt0_resources;
break; break;
case 1: case 1:
at91sam9263_rtt0_device.num_resources = 1; at91sam9263_rtt0_device.num_resources = 1;
at91sam9263_rtt1_device.num_resources = 2; at91sam9263_rtt1_device.num_resources = 3;
pdev = &at91sam9263_rtt1_device; pdev = &at91sam9263_rtt1_device;
r = rtt1_resources; r = rtt1_resources;
break; break;
...@@ -1047,6 +1051,8 @@ static void __init at91_add_device_rtt_rtc(void) ...@@ -1047,6 +1051,8 @@ static void __init at91_add_device_rtt_rtc(void)
pdev->name = "rtc-at91sam9"; pdev->name = "rtc-at91sam9";
r[1].start = AT91SAM9263_BASE_GPBR + 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR; r[1].start = AT91SAM9263_BASE_GPBR + 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR;
r[1].end = r[1].start + 3; r[1].end = r[1].start + 3;
r[2].start = NR_IRQS_LEGACY + AT91_ID_SYS;
r[2].end = NR_IRQS_LEGACY + AT91_ID_SYS;
} }
#else #else
static void __init at91_add_device_rtt_rtc(void) static void __init at91_add_device_rtt_rtc(void)
......
...@@ -1293,6 +1293,8 @@ static struct resource rtt_resources[] = { ...@@ -1293,6 +1293,8 @@ static struct resource rtt_resources[] = {
.flags = IORESOURCE_MEM, .flags = IORESOURCE_MEM,
}, { }, {
.flags = IORESOURCE_MEM, .flags = IORESOURCE_MEM,
}, {
.flags = IORESOURCE_IRQ,
} }
}; };
...@@ -1310,10 +1312,12 @@ static void __init at91_add_device_rtt_rtc(void) ...@@ -1310,10 +1312,12 @@ static void __init at91_add_device_rtt_rtc(void)
* The second resource is needed: * The second resource is needed:
* GPBR will serve as the storage for RTC time offset * GPBR will serve as the storage for RTC time offset
*/ */
at91sam9g45_rtt_device.num_resources = 2; at91sam9g45_rtt_device.num_resources = 3;
rtt_resources[1].start = AT91SAM9G45_BASE_GPBR + rtt_resources[1].start = AT91SAM9G45_BASE_GPBR +
4 * CONFIG_RTC_DRV_AT91SAM9_GPBR; 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR;
rtt_resources[1].end = rtt_resources[1].start + 3; rtt_resources[1].end = rtt_resources[1].start + 3;
rtt_resources[2].start = NR_IRQS_LEGACY + AT91_ID_SYS;
rtt_resources[2].end = NR_IRQS_LEGACY + AT91_ID_SYS;
} }
#else #else
static void __init at91_add_device_rtt_rtc(void) static void __init at91_add_device_rtt_rtc(void)
......
...@@ -688,6 +688,8 @@ static struct resource rtt_resources[] = { ...@@ -688,6 +688,8 @@ static struct resource rtt_resources[] = {
.flags = IORESOURCE_MEM, .flags = IORESOURCE_MEM,
}, { }, {
.flags = IORESOURCE_MEM, .flags = IORESOURCE_MEM,
}, {
.flags = IORESOURCE_IRQ,
} }
}; };
...@@ -705,10 +707,12 @@ static void __init at91_add_device_rtt_rtc(void) ...@@ -705,10 +707,12 @@ static void __init at91_add_device_rtt_rtc(void)
* The second resource is needed: * The second resource is needed:
* GPBR will serve as the storage for RTC time offset * GPBR will serve as the storage for RTC time offset
*/ */
at91sam9rl_rtt_device.num_resources = 2; at91sam9rl_rtt_device.num_resources = 3;
rtt_resources[1].start = AT91SAM9RL_BASE_GPBR + rtt_resources[1].start = AT91SAM9RL_BASE_GPBR +
4 * CONFIG_RTC_DRV_AT91SAM9_GPBR; 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR;
rtt_resources[1].end = rtt_resources[1].start + 3; rtt_resources[1].end = rtt_resources[1].start + 3;
rtt_resources[2].start = NR_IRQS_LEGACY + AT91_ID_SYS;
rtt_resources[2].end = NR_IRQS_LEGACY + AT91_ID_SYS;
} }
#else #else
static void __init at91_add_device_rtt_rtc(void) static void __init at91_add_device_rtt_rtc(void)
......
...@@ -58,6 +58,7 @@ struct sam9_rtc { ...@@ -58,6 +58,7 @@ struct sam9_rtc {
struct rtc_device *rtcdev; struct rtc_device *rtcdev;
u32 imr; u32 imr;
void __iomem *gpbr; void __iomem *gpbr;
int irq;
}; };
#define rtt_readl(rtc, field) \ #define rtt_readl(rtc, field) \
...@@ -292,7 +293,7 @@ static int __devinit at91_rtc_probe(struct platform_device *pdev) ...@@ -292,7 +293,7 @@ static int __devinit at91_rtc_probe(struct platform_device *pdev)
{ {
struct resource *r, *r_gpbr; struct resource *r, *r_gpbr;
struct sam9_rtc *rtc; struct sam9_rtc *rtc;
int ret; int ret, irq;
u32 mr; u32 mr;
r = platform_get_resource(pdev, IORESOURCE_MEM, 0); r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
...@@ -302,10 +303,18 @@ static int __devinit at91_rtc_probe(struct platform_device *pdev) ...@@ -302,10 +303,18 @@ static int __devinit at91_rtc_probe(struct platform_device *pdev)
return -ENODEV; return -ENODEV;
} }
irq = platform_get_irq(pdev, 0);
if (irq < 0) {
dev_err(&pdev->dev, "failed to get interrupt resource\n");
return irq;
}
rtc = kzalloc(sizeof *rtc, GFP_KERNEL); rtc = kzalloc(sizeof *rtc, GFP_KERNEL);
if (!rtc) if (!rtc)
return -ENOMEM; return -ENOMEM;
rtc->irq = irq;
/* platform setup code should have handled this; sigh */ /* platform setup code should have handled this; sigh */
if (!device_can_wakeup(&pdev->dev)) if (!device_can_wakeup(&pdev->dev))
device_init_wakeup(&pdev->dev, 1); device_init_wakeup(&pdev->dev, 1);
...@@ -345,11 +354,10 @@ static int __devinit at91_rtc_probe(struct platform_device *pdev) ...@@ -345,11 +354,10 @@ static int __devinit at91_rtc_probe(struct platform_device *pdev)
} }
/* register irq handler after we know what name we'll use */ /* register irq handler after we know what name we'll use */
ret = request_irq(AT91_ID_SYS, at91_rtc_interrupt, ret = request_irq(rtc->irq, at91_rtc_interrupt, IRQF_SHARED,
IRQF_SHARED,
dev_name(&rtc->rtcdev->dev), rtc); dev_name(&rtc->rtcdev->dev), rtc);
if (ret) { if (ret) {
dev_dbg(&pdev->dev, "can't share IRQ %d?\n", AT91_ID_SYS); dev_dbg(&pdev->dev, "can't share IRQ %d?\n", rtc->irq);
rtc_device_unregister(rtc->rtcdev); rtc_device_unregister(rtc->rtcdev);
goto fail_register; goto fail_register;
} }
...@@ -386,7 +394,7 @@ static int __devexit at91_rtc_remove(struct platform_device *pdev) ...@@ -386,7 +394,7 @@ static int __devexit at91_rtc_remove(struct platform_device *pdev)
/* disable all interrupts */ /* disable all interrupts */
rtt_writel(rtc, MR, mr & ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN)); rtt_writel(rtc, MR, mr & ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN));
free_irq(AT91_ID_SYS, rtc); free_irq(rtc->irq, rtc);
rtc_device_unregister(rtc->rtcdev); rtc_device_unregister(rtc->rtcdev);
...@@ -423,7 +431,7 @@ static int at91_rtc_suspend(struct platform_device *pdev, ...@@ -423,7 +431,7 @@ static int at91_rtc_suspend(struct platform_device *pdev,
rtc->imr = mr & (AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN); rtc->imr = mr & (AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN);
if (rtc->imr) { if (rtc->imr) {
if (device_may_wakeup(&pdev->dev) && (mr & AT91_RTT_ALMIEN)) { if (device_may_wakeup(&pdev->dev) && (mr & AT91_RTT_ALMIEN)) {
enable_irq_wake(AT91_ID_SYS); enable_irq_wake(rtc->irq);
/* don't let RTTINC cause wakeups */ /* don't let RTTINC cause wakeups */
if (mr & AT91_RTT_RTTINCIEN) if (mr & AT91_RTT_RTTINCIEN)
rtt_writel(rtc, MR, mr & ~AT91_RTT_RTTINCIEN); rtt_writel(rtc, MR, mr & ~AT91_RTT_RTTINCIEN);
...@@ -441,7 +449,7 @@ static int at91_rtc_resume(struct platform_device *pdev) ...@@ -441,7 +449,7 @@ static int at91_rtc_resume(struct platform_device *pdev)
if (rtc->imr) { if (rtc->imr) {
if (device_may_wakeup(&pdev->dev)) if (device_may_wakeup(&pdev->dev))
disable_irq_wake(AT91_ID_SYS); disable_irq_wake(rtc->irq);
mr = rtt_readl(rtc, MR); mr = rtt_readl(rtc, MR);
rtt_writel(rtc, MR, mr | rtc->imr); rtt_writel(rtc, MR, mr | rtc->imr);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment