diff options
Diffstat (limited to 'drivers/rtc/rtc-mxc.c')
| -rw-r--r-- | drivers/rtc/rtc-mxc.c | 55 |
1 files changed, 20 insertions, 35 deletions
diff --git a/drivers/rtc/rtc-mxc.c b/drivers/rtc/rtc-mxc.c index 3c3f8d10ab43..09d422b9f7f7 100644 --- a/drivers/rtc/rtc-mxc.c +++ b/drivers/rtc/rtc-mxc.c | |||
| @@ -106,7 +106,7 @@ static inline int is_imx1_rtc(struct rtc_plat_data *data) | |||
| 106 | * This function is used to obtain the RTC time or the alarm value in | 106 | * This function is used to obtain the RTC time or the alarm value in |
| 107 | * second. | 107 | * second. |
| 108 | */ | 108 | */ |
| 109 | static u32 get_alarm_or_time(struct device *dev, int time_alarm) | 109 | static time64_t get_alarm_or_time(struct device *dev, int time_alarm) |
| 110 | { | 110 | { |
| 111 | struct platform_device *pdev = to_platform_device(dev); | 111 | struct platform_device *pdev = to_platform_device(dev); |
| 112 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | 112 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); |
| @@ -129,29 +129,28 @@ static u32 get_alarm_or_time(struct device *dev, int time_alarm) | |||
| 129 | hr = hr_min >> 8; | 129 | hr = hr_min >> 8; |
| 130 | min = hr_min & 0xff; | 130 | min = hr_min & 0xff; |
| 131 | 131 | ||
| 132 | return (((day * 24 + hr) * 60) + min) * 60 + sec; | 132 | return ((((time64_t)day * 24 + hr) * 60) + min) * 60 + sec; |
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | /* | 135 | /* |
| 136 | * This function sets the RTC alarm value or the time value. | 136 | * This function sets the RTC alarm value or the time value. |
| 137 | */ | 137 | */ |
| 138 | static void set_alarm_or_time(struct device *dev, int time_alarm, u32 time) | 138 | static void set_alarm_or_time(struct device *dev, int time_alarm, time64_t time) |
| 139 | { | 139 | { |
| 140 | u32 day, hr, min, sec, temp; | 140 | u32 tod, day, hr, min, sec, temp; |
| 141 | struct platform_device *pdev = to_platform_device(dev); | 141 | struct platform_device *pdev = to_platform_device(dev); |
| 142 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | 142 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); |
| 143 | void __iomem *ioaddr = pdata->ioaddr; | 143 | void __iomem *ioaddr = pdata->ioaddr; |
| 144 | 144 | ||
| 145 | day = time / 86400; | 145 | day = div_s64_rem(time, 86400, &tod); |
| 146 | time -= day * 86400; | ||
| 147 | 146 | ||
| 148 | /* time is within a day now */ | 147 | /* time is within a day now */ |
| 149 | hr = time / 3600; | 148 | hr = tod / 3600; |
| 150 | time -= hr * 3600; | 149 | tod -= hr * 3600; |
| 151 | 150 | ||
| 152 | /* time is within an hour now */ | 151 | /* time is within an hour now */ |
| 153 | min = time / 60; | 152 | min = tod / 60; |
| 154 | sec = time - min * 60; | 153 | sec = tod - min * 60; |
| 155 | 154 | ||
| 156 | temp = (hr << 8) + min; | 155 | temp = (hr << 8) + min; |
| 157 | 156 | ||
| @@ -173,29 +172,18 @@ static void set_alarm_or_time(struct device *dev, int time_alarm, u32 time) | |||
| 173 | * This function updates the RTC alarm registers and then clears all the | 172 | * This function updates the RTC alarm registers and then clears all the |
| 174 | * interrupt status bits. | 173 | * interrupt status bits. |
| 175 | */ | 174 | */ |
| 176 | static int rtc_update_alarm(struct device *dev, struct rtc_time *alrm) | 175 | static void rtc_update_alarm(struct device *dev, struct rtc_time *alrm) |
| 177 | { | 176 | { |
| 178 | struct rtc_time alarm_tm, now_tm; | 177 | time64_t time; |
| 179 | unsigned long now, time; | ||
| 180 | struct platform_device *pdev = to_platform_device(dev); | 178 | struct platform_device *pdev = to_platform_device(dev); |
| 181 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | 179 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); |
| 182 | void __iomem *ioaddr = pdata->ioaddr; | 180 | void __iomem *ioaddr = pdata->ioaddr; |
| 183 | 181 | ||
| 184 | now = get_alarm_or_time(dev, MXC_RTC_TIME); | 182 | time = rtc_tm_to_time64(alrm); |
| 185 | rtc_time_to_tm(now, &now_tm); | ||
| 186 | alarm_tm.tm_year = now_tm.tm_year; | ||
| 187 | alarm_tm.tm_mon = now_tm.tm_mon; | ||
| 188 | alarm_tm.tm_mday = now_tm.tm_mday; | ||
| 189 | alarm_tm.tm_hour = alrm->tm_hour; | ||
| 190 | alarm_tm.tm_min = alrm->tm_min; | ||
| 191 | alarm_tm.tm_sec = alrm->tm_sec; | ||
| 192 | rtc_tm_to_time(&alarm_tm, &time); | ||
| 193 | 183 | ||
| 194 | /* clear all the interrupt status bits */ | 184 | /* clear all the interrupt status bits */ |
| 195 | writew(readw(ioaddr + RTC_RTCISR), ioaddr + RTC_RTCISR); | 185 | writew(readw(ioaddr + RTC_RTCISR), ioaddr + RTC_RTCISR); |
| 196 | set_alarm_or_time(dev, MXC_RTC_ALARM, time); | 186 | set_alarm_or_time(dev, MXC_RTC_ALARM, time); |
| 197 | |||
| 198 | return 0; | ||
| 199 | } | 187 | } |
| 200 | 188 | ||
| 201 | static void mxc_rtc_irq_enable(struct device *dev, unsigned int bit, | 189 | static void mxc_rtc_irq_enable(struct device *dev, unsigned int bit, |
| @@ -283,14 +271,14 @@ static int mxc_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) | |||
| 283 | */ | 271 | */ |
| 284 | static int mxc_rtc_read_time(struct device *dev, struct rtc_time *tm) | 272 | static int mxc_rtc_read_time(struct device *dev, struct rtc_time *tm) |
| 285 | { | 273 | { |
| 286 | u32 val; | 274 | time64_t val; |
| 287 | 275 | ||
| 288 | /* Avoid roll-over from reading the different registers */ | 276 | /* Avoid roll-over from reading the different registers */ |
| 289 | do { | 277 | do { |
| 290 | val = get_alarm_or_time(dev, MXC_RTC_TIME); | 278 | val = get_alarm_or_time(dev, MXC_RTC_TIME); |
| 291 | } while (val != get_alarm_or_time(dev, MXC_RTC_TIME)); | 279 | } while (val != get_alarm_or_time(dev, MXC_RTC_TIME)); |
| 292 | 280 | ||
| 293 | rtc_time_to_tm(val, tm); | 281 | rtc_time64_to_tm(val, tm); |
| 294 | 282 | ||
| 295 | return 0; | 283 | return 0; |
| 296 | } | 284 | } |
| @@ -298,7 +286,7 @@ static int mxc_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
| 298 | /* | 286 | /* |
| 299 | * This function sets the internal RTC time based on tm in Gregorian date. | 287 | * This function sets the internal RTC time based on tm in Gregorian date. |
| 300 | */ | 288 | */ |
| 301 | static int mxc_rtc_set_mmss(struct device *dev, unsigned long time) | 289 | static int mxc_rtc_set_mmss(struct device *dev, time64_t time) |
| 302 | { | 290 | { |
| 303 | struct platform_device *pdev = to_platform_device(dev); | 291 | struct platform_device *pdev = to_platform_device(dev); |
| 304 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | 292 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); |
| @@ -309,9 +297,9 @@ static int mxc_rtc_set_mmss(struct device *dev, unsigned long time) | |||
| 309 | if (is_imx1_rtc(pdata)) { | 297 | if (is_imx1_rtc(pdata)) { |
| 310 | struct rtc_time tm; | 298 | struct rtc_time tm; |
| 311 | 299 | ||
| 312 | rtc_time_to_tm(time, &tm); | 300 | rtc_time64_to_tm(time, &tm); |
| 313 | tm.tm_year = 70; | 301 | tm.tm_year = 70; |
| 314 | rtc_tm_to_time(&tm, &time); | 302 | time = rtc_tm_to_time64(&tm); |
| 315 | } | 303 | } |
| 316 | 304 | ||
| 317 | /* Avoid roll-over from reading the different registers */ | 305 | /* Avoid roll-over from reading the different registers */ |
| @@ -333,7 +321,7 @@ static int mxc_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
| 333 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | 321 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); |
| 334 | void __iomem *ioaddr = pdata->ioaddr; | 322 | void __iomem *ioaddr = pdata->ioaddr; |
| 335 | 323 | ||
| 336 | rtc_time_to_tm(get_alarm_or_time(dev, MXC_RTC_ALARM), &alrm->time); | 324 | rtc_time64_to_tm(get_alarm_or_time(dev, MXC_RTC_ALARM), &alrm->time); |
| 337 | alrm->pending = ((readw(ioaddr + RTC_RTCISR) & RTC_ALM_BIT)) ? 1 : 0; | 325 | alrm->pending = ((readw(ioaddr + RTC_RTCISR) & RTC_ALM_BIT)) ? 1 : 0; |
| 338 | 326 | ||
| 339 | return 0; | 327 | return 0; |
| @@ -346,11 +334,8 @@ static int mxc_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
| 346 | { | 334 | { |
| 347 | struct platform_device *pdev = to_platform_device(dev); | 335 | struct platform_device *pdev = to_platform_device(dev); |
| 348 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | 336 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); |
| 349 | int ret; | ||
| 350 | 337 | ||
| 351 | ret = rtc_update_alarm(dev, &alrm->time); | 338 | rtc_update_alarm(dev, &alrm->time); |
| 352 | if (ret) | ||
| 353 | return ret; | ||
| 354 | 339 | ||
| 355 | memcpy(&pdata->g_rtc_alarm, &alrm->time, sizeof(struct rtc_time)); | 340 | memcpy(&pdata->g_rtc_alarm, &alrm->time, sizeof(struct rtc_time)); |
| 356 | mxc_rtc_irq_enable(dev, RTC_ALM_BIT, alrm->enabled); | 341 | mxc_rtc_irq_enable(dev, RTC_ALM_BIT, alrm->enabled); |
| @@ -362,7 +347,7 @@ static int mxc_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
| 362 | static struct rtc_class_ops mxc_rtc_ops = { | 347 | static struct rtc_class_ops mxc_rtc_ops = { |
| 363 | .release = mxc_rtc_release, | 348 | .release = mxc_rtc_release, |
| 364 | .read_time = mxc_rtc_read_time, | 349 | .read_time = mxc_rtc_read_time, |
| 365 | .set_mmss = mxc_rtc_set_mmss, | 350 | .set_mmss64 = mxc_rtc_set_mmss, |
| 366 | .read_alarm = mxc_rtc_read_alarm, | 351 | .read_alarm = mxc_rtc_read_alarm, |
| 367 | .set_alarm = mxc_rtc_set_alarm, | 352 | .set_alarm = mxc_rtc_set_alarm, |
| 368 | .alarm_irq_enable = mxc_rtc_alarm_irq_enable, | 353 | .alarm_irq_enable = mxc_rtc_alarm_irq_enable, |
