Commit be5f7a03 authored by Atsushi Nemoto's avatar Atsushi Nemoto Committed by james toy

* Use its own spinlock instead of rtc->irq_lock

* Check pdata->rtc before calling rtc_update_irq
* Disable interrupt after rtc_device_unregister
Signed-off-by: default avatarAtsushi Nemoto <anemo@mba.ocn.ne.jp>
Acked-by: default avatarAlessandro Zummo <a.zummo@towertech.it>
Cc: David Brownell <david-b@pacbell.net>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 57acaa4d
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
struct tx4939rtc_plat_data { struct tx4939rtc_plat_data {
struct rtc_device *rtc; struct rtc_device *rtc;
struct tx4939_rtc_reg __iomem *rtcreg; struct tx4939_rtc_reg __iomem *rtcreg;
spinlock_t lock;
}; };
static struct tx4939rtc_plat_data *get_tx4939rtc_plat_data(struct device *dev) static struct tx4939rtc_plat_data *get_tx4939rtc_plat_data(struct device *dev)
...@@ -52,14 +53,14 @@ static int tx4939_rtc_set_mmss(struct device *dev, unsigned long secs) ...@@ -52,14 +53,14 @@ static int tx4939_rtc_set_mmss(struct device *dev, unsigned long secs)
buf[3] = secs >> 8; buf[3] = secs >> 8;
buf[4] = secs >> 16; buf[4] = secs >> 16;
buf[5] = secs >> 24; buf[5] = secs >> 24;
spin_lock_irq(&pdata->rtc->irq_lock); spin_lock_irq(&pdata->lock);
__raw_writel(0, &rtcreg->adr); __raw_writel(0, &rtcreg->adr);
for (i = 0; i < 6; i++) for (i = 0; i < 6; i++)
__raw_writel(buf[i], &rtcreg->dat); __raw_writel(buf[i], &rtcreg->dat);
ret = tx4939_rtc_cmd(rtcreg, ret = tx4939_rtc_cmd(rtcreg,
TX4939_RTCCTL_COMMAND_SETTIME | TX4939_RTCCTL_COMMAND_SETTIME |
(__raw_readl(&rtcreg->ctl) & TX4939_RTCCTL_ALME)); (__raw_readl(&rtcreg->ctl) & TX4939_RTCCTL_ALME));
spin_unlock_irq(&pdata->rtc->irq_lock); spin_unlock_irq(&pdata->lock);
return ret; return ret;
} }
...@@ -71,18 +72,18 @@ static int tx4939_rtc_read_time(struct device *dev, struct rtc_time *tm) ...@@ -71,18 +72,18 @@ static int tx4939_rtc_read_time(struct device *dev, struct rtc_time *tm)
unsigned long sec; unsigned long sec;
unsigned char buf[6]; unsigned char buf[6];
spin_lock_irq(&pdata->rtc->irq_lock); spin_lock_irq(&pdata->lock);
ret = tx4939_rtc_cmd(rtcreg, ret = tx4939_rtc_cmd(rtcreg,
TX4939_RTCCTL_COMMAND_GETTIME | TX4939_RTCCTL_COMMAND_GETTIME |
(__raw_readl(&rtcreg->ctl) & TX4939_RTCCTL_ALME)); (__raw_readl(&rtcreg->ctl) & TX4939_RTCCTL_ALME));
if (ret) { if (ret) {
spin_unlock_irq(&pdata->rtc->irq_lock); spin_unlock_irq(&pdata->lock);
return ret; return ret;
} }
__raw_writel(2, &rtcreg->adr); __raw_writel(2, &rtcreg->adr);
for (i = 2; i < 6; i++) for (i = 2; i < 6; i++)
buf[i] = __raw_readl(&rtcreg->dat); buf[i] = __raw_readl(&rtcreg->dat);
spin_unlock_irq(&pdata->rtc->irq_lock); spin_unlock_irq(&pdata->lock);
sec = (buf[5] << 24) | (buf[4] << 16) | (buf[3] << 8) | buf[2]; sec = (buf[5] << 24) | (buf[4] << 16) | (buf[3] << 8) | buf[2];
rtc_time_to_tm(sec, tm); rtc_time_to_tm(sec, tm);
return rtc_valid_tm(tm); return rtc_valid_tm(tm);
...@@ -110,13 +111,13 @@ static int tx4939_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) ...@@ -110,13 +111,13 @@ static int tx4939_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
buf[3] = sec >> 8; buf[3] = sec >> 8;
buf[4] = sec >> 16; buf[4] = sec >> 16;
buf[5] = sec >> 24; buf[5] = sec >> 24;
spin_lock_irq(&pdata->rtc->irq_lock); spin_lock_irq(&pdata->lock);
__raw_writel(0, &rtcreg->adr); __raw_writel(0, &rtcreg->adr);
for (i = 0; i < 6; i++) for (i = 0; i < 6; i++)
__raw_writel(buf[i], &rtcreg->dat); __raw_writel(buf[i], &rtcreg->dat);
ret = tx4939_rtc_cmd(rtcreg, TX4939_RTCCTL_COMMAND_SETALARM | ret = tx4939_rtc_cmd(rtcreg, TX4939_RTCCTL_COMMAND_SETALARM |
(alrm->enabled ? TX4939_RTCCTL_ALME : 0)); (alrm->enabled ? TX4939_RTCCTL_ALME : 0));
spin_unlock_irq(&pdata->rtc->irq_lock); spin_unlock_irq(&pdata->lock);
return ret; return ret;
} }
...@@ -129,12 +130,12 @@ static int tx4939_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) ...@@ -129,12 +130,12 @@ static int tx4939_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
unsigned char buf[6]; unsigned char buf[6];
u32 ctl; u32 ctl;
spin_lock_irq(&pdata->rtc->irq_lock); spin_lock_irq(&pdata->lock);
ret = tx4939_rtc_cmd(rtcreg, ret = tx4939_rtc_cmd(rtcreg,
TX4939_RTCCTL_COMMAND_GETALARM | TX4939_RTCCTL_COMMAND_GETALARM |
(__raw_readl(&rtcreg->ctl) & TX4939_RTCCTL_ALME)); (__raw_readl(&rtcreg->ctl) & TX4939_RTCCTL_ALME));
if (ret) { if (ret) {
spin_unlock_irq(&pdata->rtc->irq_lock); spin_unlock_irq(&pdata->lock);
return ret; return ret;
} }
__raw_writel(2, &rtcreg->adr); __raw_writel(2, &rtcreg->adr);
...@@ -143,7 +144,7 @@ static int tx4939_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) ...@@ -143,7 +144,7 @@ static int tx4939_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
ctl = __raw_readl(&rtcreg->ctl); ctl = __raw_readl(&rtcreg->ctl);
alrm->enabled = (ctl & TX4939_RTCCTL_ALME) ? 1 : 0; alrm->enabled = (ctl & TX4939_RTCCTL_ALME) ? 1 : 0;
alrm->pending = (ctl & TX4939_RTCCTL_ALMD) ? 1 : 0; alrm->pending = (ctl & TX4939_RTCCTL_ALMD) ? 1 : 0;
spin_unlock_irq(&pdata->rtc->irq_lock); spin_unlock_irq(&pdata->lock);
sec = (buf[5] << 24) | (buf[4] << 16) | (buf[3] << 8) | buf[2]; sec = (buf[5] << 24) | (buf[4] << 16) | (buf[3] << 8) | buf[2];
rtc_time_to_tm(sec, &alrm->time); rtc_time_to_tm(sec, &alrm->time);
return rtc_valid_tm(&alrm->time); return rtc_valid_tm(&alrm->time);
...@@ -153,11 +154,11 @@ static int tx4939_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) ...@@ -153,11 +154,11 @@ static int tx4939_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
{ {
struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev); struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev);
spin_lock_irq(&pdata->rtc->irq_lock); spin_lock_irq(&pdata->lock);
tx4939_rtc_cmd(pdata->rtcreg, tx4939_rtc_cmd(pdata->rtcreg,
TX4939_RTCCTL_COMMAND_NOP | TX4939_RTCCTL_COMMAND_NOP |
(enabled ? TX4939_RTCCTL_ALME : 0)); (enabled ? TX4939_RTCCTL_ALME : 0));
spin_unlock_irq(&pdata->rtc->irq_lock); spin_unlock_irq(&pdata->lock);
return 0; return 0;
} }
...@@ -167,12 +168,13 @@ static irqreturn_t tx4939_rtc_interrupt(int irq, void *dev_id) ...@@ -167,12 +168,13 @@ static irqreturn_t tx4939_rtc_interrupt(int irq, void *dev_id)
struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg;
unsigned long events = RTC_IRQF; unsigned long events = RTC_IRQF;
spin_lock(&pdata->rtc->irq_lock); spin_lock(&pdata->lock);
if (__raw_readl(&rtcreg->ctl) & TX4939_RTCCTL_ALMD) { if (__raw_readl(&rtcreg->ctl) & TX4939_RTCCTL_ALMD) {
events |= RTC_AF; events |= RTC_AF;
tx4939_rtc_cmd(rtcreg, TX4939_RTCCTL_COMMAND_NOP); tx4939_rtc_cmd(rtcreg, TX4939_RTCCTL_COMMAND_NOP);
} }
spin_unlock(&pdata->rtc->irq_lock); spin_unlock(&pdata->lock);
if (likely(pdata->rtc))
rtc_update_irq(pdata->rtc, 1, events); rtc_update_irq(pdata->rtc, 1, events);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
...@@ -194,13 +196,13 @@ static ssize_t tx4939_rtc_nvram_read(struct kobject *kobj, ...@@ -194,13 +196,13 @@ static ssize_t tx4939_rtc_nvram_read(struct kobject *kobj,
struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg;
ssize_t count; ssize_t count;
spin_lock_irq(&pdata->rtc->irq_lock); spin_lock_irq(&pdata->lock);
for (count = 0; size > 0 && pos < TX4939_RTC_REG_RAMSIZE; for (count = 0; size > 0 && pos < TX4939_RTC_REG_RAMSIZE;
count++, size--) { count++, size--) {
__raw_writel(pos++, &rtcreg->adr); __raw_writel(pos++, &rtcreg->adr);
*buf++ = __raw_readl(&rtcreg->dat); *buf++ = __raw_readl(&rtcreg->dat);
} }
spin_unlock_irq(&pdata->rtc->irq_lock); spin_unlock_irq(&pdata->lock);
return count; return count;
} }
...@@ -213,13 +215,13 @@ static ssize_t tx4939_rtc_nvram_write(struct kobject *kobj, ...@@ -213,13 +215,13 @@ static ssize_t tx4939_rtc_nvram_write(struct kobject *kobj,
struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg;
ssize_t count; ssize_t count;
spin_lock_irq(&pdata->rtc->irq_lock); spin_lock_irq(&pdata->lock);
for (count = 0; size > 0 && pos < TX4939_RTC_REG_RAMSIZE; for (count = 0; size > 0 && pos < TX4939_RTC_REG_RAMSIZE;
count++, size--) { count++, size--) {
__raw_writel(pos++, &rtcreg->adr); __raw_writel(pos++, &rtcreg->adr);
__raw_writel(*buf++, &rtcreg->dat); __raw_writel(*buf++, &rtcreg->dat);
} }
spin_unlock_irq(&pdata->rtc->irq_lock); spin_unlock_irq(&pdata->lock);
return count; return count;
} }
...@@ -259,6 +261,7 @@ static int __init tx4939_rtc_probe(struct platform_device *pdev) ...@@ -259,6 +261,7 @@ static int __init tx4939_rtc_probe(struct platform_device *pdev)
if (!pdata->rtcreg) if (!pdata->rtcreg)
return -EBUSY; return -EBUSY;
spin_lock_init(&pdata->lock);
tx4939_rtc_cmd(pdata->rtcreg, TX4939_RTCCTL_COMMAND_NOP); tx4939_rtc_cmd(pdata->rtcreg, TX4939_RTCCTL_COMMAND_NOP);
if (devm_request_irq(&pdev->dev, irq, tx4939_rtc_interrupt, if (devm_request_irq(&pdev->dev, irq, tx4939_rtc_interrupt,
IRQF_DISABLED, pdev->name, &pdev->dev) < 0) IRQF_DISABLED, pdev->name, &pdev->dev) < 0)
...@@ -277,14 +280,12 @@ static int __init tx4939_rtc_probe(struct platform_device *pdev) ...@@ -277,14 +280,12 @@ static int __init tx4939_rtc_probe(struct platform_device *pdev)
static int __exit tx4939_rtc_remove(struct platform_device *pdev) static int __exit tx4939_rtc_remove(struct platform_device *pdev)
{ {
struct tx4939rtc_plat_data *pdata = platform_get_drvdata(pdev); struct tx4939rtc_plat_data *pdata = platform_get_drvdata(pdev);
struct rtc_device *rtc = pdata->rtc;
spin_lock_irq(&rtc->irq_lock);
tx4939_rtc_cmd(pdata->rtcreg, TX4939_RTCCTL_COMMAND_NOP);
spin_unlock_irq(&rtc->irq_lock);
sysfs_remove_bin_file(&pdev->dev.kobj, &tx4939_rtc_nvram_attr); sysfs_remove_bin_file(&pdev->dev.kobj, &tx4939_rtc_nvram_attr);
rtc_device_unregister(rtc); rtc_device_unregister(pdata->rtc);
platform_set_drvdata(pdev, NULL); spin_lock_irq(&pdata->lock);
tx4939_rtc_cmd(pdata->rtcreg, TX4939_RTCCTL_COMMAND_NOP);
spin_unlock_irq(&pdata->lock);
return 0; return 0;
} }
......
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