diff options
Diffstat (limited to 'drivers/rtc/rtc-s3c.c')
| -rw-r--r-- | drivers/rtc/rtc-s3c.c | 194 |
1 files changed, 54 insertions, 140 deletions
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c index 4241eeab3386..76cbad7a99d3 100644 --- a/drivers/rtc/rtc-s3c.c +++ b/drivers/rtc/rtc-s3c.c | |||
| @@ -39,7 +39,6 @@ struct s3c_rtc { | |||
| 39 | void __iomem *base; | 39 | void __iomem *base; |
| 40 | struct clk *rtc_clk; | 40 | struct clk *rtc_clk; |
| 41 | struct clk *rtc_src_clk; | 41 | struct clk *rtc_src_clk; |
| 42 | bool enabled; | ||
| 43 | 42 | ||
| 44 | struct s3c_rtc_data *data; | 43 | struct s3c_rtc_data *data; |
| 45 | 44 | ||
| @@ -67,26 +66,25 @@ struct s3c_rtc_data { | |||
| 67 | void (*disable) (struct s3c_rtc *info); | 66 | void (*disable) (struct s3c_rtc *info); |
| 68 | }; | 67 | }; |
| 69 | 68 | ||
| 70 | static void s3c_rtc_alarm_clk_enable(struct s3c_rtc *info, bool enable) | 69 | static void s3c_rtc_enable_clk(struct s3c_rtc *info) |
| 71 | { | 70 | { |
| 72 | unsigned long irq_flags; | 71 | unsigned long irq_flags; |
| 73 | 72 | ||
| 74 | spin_lock_irqsave(&info->alarm_clk_lock, irq_flags); | 73 | spin_lock_irqsave(&info->alarm_clk_lock, irq_flags); |
| 75 | if (enable) { | 74 | clk_enable(info->rtc_clk); |
| 76 | if (!info->enabled) { | 75 | if (info->data->needs_src_clk) |
| 77 | clk_enable(info->rtc_clk); | 76 | clk_enable(info->rtc_src_clk); |
| 78 | if (info->data->needs_src_clk) | 77 | spin_unlock_irqrestore(&info->alarm_clk_lock, irq_flags); |
| 79 | clk_enable(info->rtc_src_clk); | 78 | } |
| 80 | info->enabled = true; | 79 | |
| 81 | } | 80 | static void s3c_rtc_disable_clk(struct s3c_rtc *info) |
| 82 | } else { | 81 | { |
| 83 | if (info->enabled) { | 82 | unsigned long irq_flags; |
| 84 | if (info->data->needs_src_clk) | 83 | |
| 85 | clk_disable(info->rtc_src_clk); | 84 | spin_lock_irqsave(&info->alarm_clk_lock, irq_flags); |
| 86 | clk_disable(info->rtc_clk); | 85 | if (info->data->needs_src_clk) |
| 87 | info->enabled = false; | 86 | clk_disable(info->rtc_src_clk); |
| 88 | } | 87 | clk_disable(info->rtc_clk); |
| 89 | } | ||
| 90 | spin_unlock_irqrestore(&info->alarm_clk_lock, irq_flags); | 88 | spin_unlock_irqrestore(&info->alarm_clk_lock, irq_flags); |
| 91 | } | 89 | } |
| 92 | 90 | ||
| @@ -119,20 +117,16 @@ static int s3c_rtc_setaie(struct device *dev, unsigned int enabled) | |||
| 119 | 117 | ||
| 120 | dev_dbg(info->dev, "%s: aie=%d\n", __func__, enabled); | 118 | dev_dbg(info->dev, "%s: aie=%d\n", __func__, enabled); |
| 121 | 119 | ||
| 122 | clk_enable(info->rtc_clk); | 120 | s3c_rtc_enable_clk(info); |
| 123 | if (info->data->needs_src_clk) | 121 | |
| 124 | clk_enable(info->rtc_src_clk); | ||
| 125 | tmp = readb(info->base + S3C2410_RTCALM) & ~S3C2410_RTCALM_ALMEN; | 122 | tmp = readb(info->base + S3C2410_RTCALM) & ~S3C2410_RTCALM_ALMEN; |
| 126 | 123 | ||
| 127 | if (enabled) | 124 | if (enabled) |
| 128 | tmp |= S3C2410_RTCALM_ALMEN; | 125 | tmp |= S3C2410_RTCALM_ALMEN; |
| 129 | 126 | ||
| 130 | writeb(tmp, info->base + S3C2410_RTCALM); | 127 | writeb(tmp, info->base + S3C2410_RTCALM); |
| 131 | if (info->data->needs_src_clk) | ||
| 132 | clk_disable(info->rtc_src_clk); | ||
| 133 | clk_disable(info->rtc_clk); | ||
| 134 | 128 | ||
| 135 | s3c_rtc_alarm_clk_enable(info, enabled); | 129 | s3c_rtc_disable_clk(info); |
| 136 | 130 | ||
| 137 | return 0; | 131 | return 0; |
| 138 | } | 132 | } |
| @@ -143,18 +137,12 @@ static int s3c_rtc_setfreq(struct s3c_rtc *info, int freq) | |||
| 143 | if (!is_power_of_2(freq)) | 137 | if (!is_power_of_2(freq)) |
| 144 | return -EINVAL; | 138 | return -EINVAL; |
| 145 | 139 | ||
| 146 | clk_enable(info->rtc_clk); | ||
| 147 | if (info->data->needs_src_clk) | ||
| 148 | clk_enable(info->rtc_src_clk); | ||
| 149 | spin_lock_irq(&info->pie_lock); | 140 | spin_lock_irq(&info->pie_lock); |
| 150 | 141 | ||
| 151 | if (info->data->set_freq) | 142 | if (info->data->set_freq) |
| 152 | info->data->set_freq(info, freq); | 143 | info->data->set_freq(info, freq); |
| 153 | 144 | ||
| 154 | spin_unlock_irq(&info->pie_lock); | 145 | spin_unlock_irq(&info->pie_lock); |
| 155 | if (info->data->needs_src_clk) | ||
| 156 | clk_disable(info->rtc_src_clk); | ||
| 157 | clk_disable(info->rtc_clk); | ||
| 158 | 146 | ||
| 159 | return 0; | 147 | return 0; |
| 160 | } | 148 | } |
| @@ -165,9 +153,7 @@ static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm) | |||
| 165 | struct s3c_rtc *info = dev_get_drvdata(dev); | 153 | struct s3c_rtc *info = dev_get_drvdata(dev); |
| 166 | unsigned int have_retried = 0; | 154 | unsigned int have_retried = 0; |
| 167 | 155 | ||
| 168 | clk_enable(info->rtc_clk); | 156 | s3c_rtc_enable_clk(info); |
| 169 | if (info->data->needs_src_clk) | ||
| 170 | clk_enable(info->rtc_src_clk); | ||
| 171 | 157 | ||
| 172 | retry_get_time: | 158 | retry_get_time: |
| 173 | rtc_tm->tm_min = readb(info->base + S3C2410_RTCMIN); | 159 | rtc_tm->tm_min = readb(info->base + S3C2410_RTCMIN); |
| @@ -194,6 +180,8 @@ static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm) | |||
| 194 | rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon); | 180 | rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon); |
| 195 | rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year); | 181 | rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year); |
| 196 | 182 | ||
| 183 | s3c_rtc_disable_clk(info); | ||
| 184 | |||
| 197 | rtc_tm->tm_year += 100; | 185 | rtc_tm->tm_year += 100; |
| 198 | 186 | ||
| 199 | dev_dbg(dev, "read time %04d.%02d.%02d %02d:%02d:%02d\n", | 187 | dev_dbg(dev, "read time %04d.%02d.%02d %02d:%02d:%02d\n", |
| @@ -202,10 +190,6 @@ static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm) | |||
| 202 | 190 | ||
| 203 | rtc_tm->tm_mon -= 1; | 191 | rtc_tm->tm_mon -= 1; |
| 204 | 192 | ||
| 205 | if (info->data->needs_src_clk) | ||
| 206 | clk_disable(info->rtc_src_clk); | ||
| 207 | clk_disable(info->rtc_clk); | ||
| 208 | |||
| 209 | return rtc_valid_tm(rtc_tm); | 193 | return rtc_valid_tm(rtc_tm); |
| 210 | } | 194 | } |
| 211 | 195 | ||
| @@ -225,9 +209,7 @@ static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm) | |||
| 225 | return -EINVAL; | 209 | return -EINVAL; |
| 226 | } | 210 | } |
| 227 | 211 | ||
| 228 | clk_enable(info->rtc_clk); | 212 | s3c_rtc_enable_clk(info); |
| 229 | if (info->data->needs_src_clk) | ||
| 230 | clk_enable(info->rtc_src_clk); | ||
| 231 | 213 | ||
| 232 | writeb(bin2bcd(tm->tm_sec), info->base + S3C2410_RTCSEC); | 214 | writeb(bin2bcd(tm->tm_sec), info->base + S3C2410_RTCSEC); |
| 233 | writeb(bin2bcd(tm->tm_min), info->base + S3C2410_RTCMIN); | 215 | writeb(bin2bcd(tm->tm_min), info->base + S3C2410_RTCMIN); |
| @@ -236,9 +218,7 @@ static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm) | |||
| 236 | writeb(bin2bcd(tm->tm_mon + 1), info->base + S3C2410_RTCMON); | 218 | writeb(bin2bcd(tm->tm_mon + 1), info->base + S3C2410_RTCMON); |
| 237 | writeb(bin2bcd(year), info->base + S3C2410_RTCYEAR); | 219 | writeb(bin2bcd(year), info->base + S3C2410_RTCYEAR); |
| 238 | 220 | ||
| 239 | if (info->data->needs_src_clk) | 221 | s3c_rtc_disable_clk(info); |
| 240 | clk_disable(info->rtc_src_clk); | ||
| 241 | clk_disable(info->rtc_clk); | ||
| 242 | 222 | ||
| 243 | return 0; | 223 | return 0; |
| 244 | } | 224 | } |
| @@ -249,9 +229,7 @@ static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
| 249 | struct rtc_time *alm_tm = &alrm->time; | 229 | struct rtc_time *alm_tm = &alrm->time; |
| 250 | unsigned int alm_en; | 230 | unsigned int alm_en; |
| 251 | 231 | ||
| 252 | clk_enable(info->rtc_clk); | 232 | s3c_rtc_enable_clk(info); |
| 253 | if (info->data->needs_src_clk) | ||
| 254 | clk_enable(info->rtc_src_clk); | ||
| 255 | 233 | ||
| 256 | alm_tm->tm_sec = readb(info->base + S3C2410_ALMSEC); | 234 | alm_tm->tm_sec = readb(info->base + S3C2410_ALMSEC); |
| 257 | alm_tm->tm_min = readb(info->base + S3C2410_ALMMIN); | 235 | alm_tm->tm_min = readb(info->base + S3C2410_ALMMIN); |
| @@ -262,6 +240,8 @@ static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
| 262 | 240 | ||
| 263 | alm_en = readb(info->base + S3C2410_RTCALM); | 241 | alm_en = readb(info->base + S3C2410_RTCALM); |
| 264 | 242 | ||
| 243 | s3c_rtc_disable_clk(info); | ||
| 244 | |||
| 265 | alrm->enabled = (alm_en & S3C2410_RTCALM_ALMEN) ? 1 : 0; | 245 | alrm->enabled = (alm_en & S3C2410_RTCALM_ALMEN) ? 1 : 0; |
| 266 | 246 | ||
| 267 | dev_dbg(dev, "read alarm %d, %04d.%02d.%02d %02d:%02d:%02d\n", | 247 | dev_dbg(dev, "read alarm %d, %04d.%02d.%02d %02d:%02d:%02d\n", |
| @@ -269,9 +249,7 @@ static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
| 269 | 1900 + alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday, | 249 | 1900 + alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday, |
| 270 | alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec); | 250 | alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec); |
| 271 | 251 | ||
| 272 | |||
| 273 | /* decode the alarm enable field */ | 252 | /* decode the alarm enable field */ |
| 274 | |||
| 275 | if (alm_en & S3C2410_RTCALM_SECEN) | 253 | if (alm_en & S3C2410_RTCALM_SECEN) |
| 276 | alm_tm->tm_sec = bcd2bin(alm_tm->tm_sec); | 254 | alm_tm->tm_sec = bcd2bin(alm_tm->tm_sec); |
| 277 | else | 255 | else |
| @@ -304,10 +282,6 @@ static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
| 304 | else | 282 | else |
| 305 | alm_tm->tm_year = -1; | 283 | alm_tm->tm_year = -1; |
| 306 | 284 | ||
| 307 | if (info->data->needs_src_clk) | ||
| 308 | clk_disable(info->rtc_src_clk); | ||
| 309 | clk_disable(info->rtc_clk); | ||
| 310 | |||
| 311 | return 0; | 285 | return 0; |
| 312 | } | 286 | } |
| 313 | 287 | ||
| @@ -317,15 +291,13 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
| 317 | struct rtc_time *tm = &alrm->time; | 291 | struct rtc_time *tm = &alrm->time; |
| 318 | unsigned int alrm_en; | 292 | unsigned int alrm_en; |
| 319 | 293 | ||
| 320 | clk_enable(info->rtc_clk); | ||
| 321 | if (info->data->needs_src_clk) | ||
| 322 | clk_enable(info->rtc_src_clk); | ||
| 323 | |||
| 324 | dev_dbg(dev, "s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n", | 294 | dev_dbg(dev, "s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n", |
| 325 | alrm->enabled, | 295 | alrm->enabled, |
| 326 | 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday, | 296 | 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday, |
| 327 | tm->tm_hour, tm->tm_min, tm->tm_sec); | 297 | tm->tm_hour, tm->tm_min, tm->tm_sec); |
| 328 | 298 | ||
| 299 | s3c_rtc_enable_clk(info); | ||
| 300 | |||
| 329 | alrm_en = readb(info->base + S3C2410_RTCALM) & S3C2410_RTCALM_ALMEN; | 301 | alrm_en = readb(info->base + S3C2410_RTCALM) & S3C2410_RTCALM_ALMEN; |
| 330 | writeb(0x00, info->base + S3C2410_RTCALM); | 302 | writeb(0x00, info->base + S3C2410_RTCALM); |
| 331 | 303 | ||
| @@ -348,11 +320,9 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
| 348 | 320 | ||
| 349 | writeb(alrm_en, info->base + S3C2410_RTCALM); | 321 | writeb(alrm_en, info->base + S3C2410_RTCALM); |
| 350 | 322 | ||
| 351 | s3c_rtc_setaie(dev, alrm->enabled); | 323 | s3c_rtc_disable_clk(info); |
| 352 | 324 | ||
| 353 | if (info->data->needs_src_clk) | 325 | s3c_rtc_setaie(dev, alrm->enabled); |
| 354 | clk_disable(info->rtc_src_clk); | ||
| 355 | clk_disable(info->rtc_clk); | ||
| 356 | 326 | ||
| 357 | return 0; | 327 | return 0; |
| 358 | } | 328 | } |
| @@ -361,16 +331,12 @@ static int s3c_rtc_proc(struct device *dev, struct seq_file *seq) | |||
| 361 | { | 331 | { |
| 362 | struct s3c_rtc *info = dev_get_drvdata(dev); | 332 | struct s3c_rtc *info = dev_get_drvdata(dev); |
| 363 | 333 | ||
| 364 | clk_enable(info->rtc_clk); | 334 | s3c_rtc_enable_clk(info); |
| 365 | if (info->data->needs_src_clk) | ||
| 366 | clk_enable(info->rtc_src_clk); | ||
| 367 | 335 | ||
| 368 | if (info->data->enable_tick) | 336 | if (info->data->enable_tick) |
| 369 | info->data->enable_tick(info, seq); | 337 | info->data->enable_tick(info, seq); |
| 370 | 338 | ||
| 371 | if (info->data->needs_src_clk) | 339 | s3c_rtc_disable_clk(info); |
| 372 | clk_disable(info->rtc_src_clk); | ||
| 373 | clk_disable(info->rtc_clk); | ||
| 374 | 340 | ||
| 375 | return 0; | 341 | return 0; |
| 376 | } | 342 | } |
| @@ -388,10 +354,6 @@ static void s3c24xx_rtc_enable(struct s3c_rtc *info) | |||
| 388 | { | 354 | { |
| 389 | unsigned int con, tmp; | 355 | unsigned int con, tmp; |
| 390 | 356 | ||
| 391 | clk_enable(info->rtc_clk); | ||
| 392 | if (info->data->needs_src_clk) | ||
| 393 | clk_enable(info->rtc_src_clk); | ||
| 394 | |||
| 395 | con = readw(info->base + S3C2410_RTCCON); | 357 | con = readw(info->base + S3C2410_RTCCON); |
| 396 | /* re-enable the device, and check it is ok */ | 358 | /* re-enable the device, and check it is ok */ |
| 397 | if ((con & S3C2410_RTCCON_RTCEN) == 0) { | 359 | if ((con & S3C2410_RTCCON_RTCEN) == 0) { |
| @@ -417,20 +379,12 @@ static void s3c24xx_rtc_enable(struct s3c_rtc *info) | |||
| 417 | writew(tmp & ~S3C2410_RTCCON_CLKRST, | 379 | writew(tmp & ~S3C2410_RTCCON_CLKRST, |
| 418 | info->base + S3C2410_RTCCON); | 380 | info->base + S3C2410_RTCCON); |
| 419 | } | 381 | } |
| 420 | |||
| 421 | if (info->data->needs_src_clk) | ||
| 422 | clk_disable(info->rtc_src_clk); | ||
| 423 | clk_disable(info->rtc_clk); | ||
| 424 | } | 382 | } |
| 425 | 383 | ||
| 426 | static void s3c24xx_rtc_disable(struct s3c_rtc *info) | 384 | static void s3c24xx_rtc_disable(struct s3c_rtc *info) |
| 427 | { | 385 | { |
| 428 | unsigned int con; | 386 | unsigned int con; |
| 429 | 387 | ||
| 430 | clk_enable(info->rtc_clk); | ||
| 431 | if (info->data->needs_src_clk) | ||
| 432 | clk_enable(info->rtc_src_clk); | ||
| 433 | |||
| 434 | con = readw(info->base + S3C2410_RTCCON); | 388 | con = readw(info->base + S3C2410_RTCCON); |
| 435 | con &= ~S3C2410_RTCCON_RTCEN; | 389 | con &= ~S3C2410_RTCCON_RTCEN; |
| 436 | writew(con, info->base + S3C2410_RTCCON); | 390 | writew(con, info->base + S3C2410_RTCCON); |
| @@ -438,28 +392,16 @@ static void s3c24xx_rtc_disable(struct s3c_rtc *info) | |||
| 438 | con = readb(info->base + S3C2410_TICNT); | 392 | con = readb(info->base + S3C2410_TICNT); |
| 439 | con &= ~S3C2410_TICNT_ENABLE; | 393 | con &= ~S3C2410_TICNT_ENABLE; |
| 440 | writeb(con, info->base + S3C2410_TICNT); | 394 | writeb(con, info->base + S3C2410_TICNT); |
| 441 | |||
| 442 | if (info->data->needs_src_clk) | ||
| 443 | clk_disable(info->rtc_src_clk); | ||
| 444 | clk_disable(info->rtc_clk); | ||
| 445 | } | 395 | } |
| 446 | 396 | ||
| 447 | static void s3c6410_rtc_disable(struct s3c_rtc *info) | 397 | static void s3c6410_rtc_disable(struct s3c_rtc *info) |
| 448 | { | 398 | { |
| 449 | unsigned int con; | 399 | unsigned int con; |
| 450 | 400 | ||
| 451 | clk_enable(info->rtc_clk); | ||
| 452 | if (info->data->needs_src_clk) | ||
| 453 | clk_enable(info->rtc_src_clk); | ||
| 454 | |||
| 455 | con = readw(info->base + S3C2410_RTCCON); | 401 | con = readw(info->base + S3C2410_RTCCON); |
| 456 | con &= ~S3C64XX_RTCCON_TICEN; | 402 | con &= ~S3C64XX_RTCCON_TICEN; |
| 457 | con &= ~S3C2410_RTCCON_RTCEN; | 403 | con &= ~S3C2410_RTCCON_RTCEN; |
| 458 | writew(con, info->base + S3C2410_RTCCON); | 404 | writew(con, info->base + S3C2410_RTCCON); |
| 459 | |||
| 460 | if (info->data->needs_src_clk) | ||
| 461 | clk_disable(info->rtc_src_clk); | ||
| 462 | clk_disable(info->rtc_clk); | ||
| 463 | } | 405 | } |
| 464 | 406 | ||
| 465 | static int s3c_rtc_remove(struct platform_device *pdev) | 407 | static int s3c_rtc_remove(struct platform_device *pdev) |
| @@ -554,6 +496,20 @@ static int s3c_rtc_probe(struct platform_device *pdev) | |||
| 554 | 496 | ||
| 555 | device_init_wakeup(&pdev->dev, 1); | 497 | device_init_wakeup(&pdev->dev, 1); |
| 556 | 498 | ||
| 499 | /* Check RTC Time */ | ||
| 500 | if (s3c_rtc_gettime(&pdev->dev, &rtc_tm)) { | ||
| 501 | rtc_tm.tm_year = 100; | ||
| 502 | rtc_tm.tm_mon = 0; | ||
| 503 | rtc_tm.tm_mday = 1; | ||
| 504 | rtc_tm.tm_hour = 0; | ||
| 505 | rtc_tm.tm_min = 0; | ||
| 506 | rtc_tm.tm_sec = 0; | ||
| 507 | |||
| 508 | s3c_rtc_settime(&pdev->dev, &rtc_tm); | ||
| 509 | |||
| 510 | dev_warn(&pdev->dev, "warning: invalid RTC value so initializing it\n"); | ||
| 511 | } | ||
| 512 | |||
| 557 | /* register RTC and exit */ | 513 | /* register RTC and exit */ |
| 558 | info->rtc = devm_rtc_device_register(&pdev->dev, "s3c", &s3c_rtcops, | 514 | info->rtc = devm_rtc_device_register(&pdev->dev, "s3c", &s3c_rtcops, |
| 559 | THIS_MODULE); | 515 | THIS_MODULE); |
| @@ -577,36 +533,21 @@ static int s3c_rtc_probe(struct platform_device *pdev) | |||
| 577 | goto err_nortc; | 533 | goto err_nortc; |
| 578 | } | 534 | } |
| 579 | 535 | ||
| 580 | /* Check RTC Time */ | ||
| 581 | s3c_rtc_gettime(&pdev->dev, &rtc_tm); | ||
| 582 | |||
| 583 | if (rtc_valid_tm(&rtc_tm)) { | ||
| 584 | rtc_tm.tm_year = 100; | ||
| 585 | rtc_tm.tm_mon = 0; | ||
| 586 | rtc_tm.tm_mday = 1; | ||
| 587 | rtc_tm.tm_hour = 0; | ||
| 588 | rtc_tm.tm_min = 0; | ||
| 589 | rtc_tm.tm_sec = 0; | ||
| 590 | |||
| 591 | s3c_rtc_settime(&pdev->dev, &rtc_tm); | ||
| 592 | |||
| 593 | dev_warn(&pdev->dev, "warning: invalid RTC value so initializing it\n"); | ||
| 594 | } | ||
| 595 | |||
| 596 | if (info->data->select_tick_clk) | 536 | if (info->data->select_tick_clk) |
| 597 | info->data->select_tick_clk(info); | 537 | info->data->select_tick_clk(info); |
| 598 | 538 | ||
| 599 | s3c_rtc_setfreq(info, 1); | 539 | s3c_rtc_setfreq(info, 1); |
| 600 | 540 | ||
| 601 | if (info->data->needs_src_clk) | 541 | s3c_rtc_disable_clk(info); |
| 602 | clk_disable(info->rtc_src_clk); | ||
| 603 | clk_disable(info->rtc_clk); | ||
| 604 | 542 | ||
| 605 | return 0; | 543 | return 0; |
| 606 | 544 | ||
| 607 | err_nortc: | 545 | err_nortc: |
| 608 | if (info->data->disable) | 546 | if (info->data->disable) |
| 609 | info->data->disable(info); | 547 | info->data->disable(info); |
| 548 | |||
| 549 | if (info->data->needs_src_clk) | ||
| 550 | clk_disable_unprepare(info->rtc_src_clk); | ||
| 610 | clk_disable_unprepare(info->rtc_clk); | 551 | clk_disable_unprepare(info->rtc_clk); |
| 611 | 552 | ||
| 612 | return ret; | 553 | return ret; |
| @@ -618,9 +559,7 @@ static int s3c_rtc_suspend(struct device *dev) | |||
| 618 | { | 559 | { |
| 619 | struct s3c_rtc *info = dev_get_drvdata(dev); | 560 | struct s3c_rtc *info = dev_get_drvdata(dev); |
| 620 | 561 | ||
| 621 | clk_enable(info->rtc_clk); | 562 | s3c_rtc_enable_clk(info); |
| 622 | if (info->data->needs_src_clk) | ||
| 623 | clk_enable(info->rtc_src_clk); | ||
| 624 | 563 | ||
| 625 | /* save TICNT for anyone using periodic interrupts */ | 564 | /* save TICNT for anyone using periodic interrupts */ |
| 626 | if (info->data->save_tick_cnt) | 565 | if (info->data->save_tick_cnt) |
| @@ -636,10 +575,6 @@ static int s3c_rtc_suspend(struct device *dev) | |||
| 636 | dev_err(dev, "enable_irq_wake failed\n"); | 575 | dev_err(dev, "enable_irq_wake failed\n"); |
| 637 | } | 576 | } |
| 638 | 577 | ||
| 639 | if (info->data->needs_src_clk) | ||
| 640 | clk_disable(info->rtc_src_clk); | ||
| 641 | clk_disable(info->rtc_clk); | ||
| 642 | |||
| 643 | return 0; | 578 | return 0; |
| 644 | } | 579 | } |
| 645 | 580 | ||
| @@ -647,25 +582,19 @@ static int s3c_rtc_resume(struct device *dev) | |||
| 647 | { | 582 | { |
| 648 | struct s3c_rtc *info = dev_get_drvdata(dev); | 583 | struct s3c_rtc *info = dev_get_drvdata(dev); |
| 649 | 584 | ||
| 650 | clk_enable(info->rtc_clk); | ||
| 651 | if (info->data->needs_src_clk) | ||
| 652 | clk_enable(info->rtc_src_clk); | ||
| 653 | |||
| 654 | if (info->data->enable) | 585 | if (info->data->enable) |
| 655 | info->data->enable(info); | 586 | info->data->enable(info); |
| 656 | 587 | ||
| 657 | if (info->data->restore_tick_cnt) | 588 | if (info->data->restore_tick_cnt) |
| 658 | info->data->restore_tick_cnt(info); | 589 | info->data->restore_tick_cnt(info); |
| 659 | 590 | ||
| 591 | s3c_rtc_disable_clk(info); | ||
| 592 | |||
| 660 | if (device_may_wakeup(dev) && info->wake_en) { | 593 | if (device_may_wakeup(dev) && info->wake_en) { |
| 661 | disable_irq_wake(info->irq_alarm); | 594 | disable_irq_wake(info->irq_alarm); |
| 662 | info->wake_en = false; | 595 | info->wake_en = false; |
| 663 | } | 596 | } |
| 664 | 597 | ||
| 665 | if (info->data->needs_src_clk) | ||
| 666 | clk_disable(info->rtc_src_clk); | ||
| 667 | clk_disable(info->rtc_clk); | ||
| 668 | |||
| 669 | return 0; | 598 | return 0; |
| 670 | } | 599 | } |
| 671 | #endif | 600 | #endif |
| @@ -673,29 +602,13 @@ static SIMPLE_DEV_PM_OPS(s3c_rtc_pm_ops, s3c_rtc_suspend, s3c_rtc_resume); | |||
| 673 | 602 | ||
| 674 | static void s3c24xx_rtc_irq(struct s3c_rtc *info, int mask) | 603 | static void s3c24xx_rtc_irq(struct s3c_rtc *info, int mask) |
| 675 | { | 604 | { |
| 676 | clk_enable(info->rtc_clk); | ||
| 677 | if (info->data->needs_src_clk) | ||
| 678 | clk_enable(info->rtc_src_clk); | ||
| 679 | rtc_update_irq(info->rtc, 1, RTC_AF | RTC_IRQF); | 605 | rtc_update_irq(info->rtc, 1, RTC_AF | RTC_IRQF); |
| 680 | if (info->data->needs_src_clk) | ||
| 681 | clk_disable(info->rtc_src_clk); | ||
| 682 | clk_disable(info->rtc_clk); | ||
| 683 | |||
| 684 | s3c_rtc_alarm_clk_enable(info, false); | ||
| 685 | } | 606 | } |
| 686 | 607 | ||
| 687 | static void s3c6410_rtc_irq(struct s3c_rtc *info, int mask) | 608 | static void s3c6410_rtc_irq(struct s3c_rtc *info, int mask) |
| 688 | { | 609 | { |
| 689 | clk_enable(info->rtc_clk); | ||
| 690 | if (info->data->needs_src_clk) | ||
| 691 | clk_enable(info->rtc_src_clk); | ||
| 692 | rtc_update_irq(info->rtc, 1, RTC_AF | RTC_IRQF); | 610 | rtc_update_irq(info->rtc, 1, RTC_AF | RTC_IRQF); |
| 693 | writeb(mask, info->base + S3C2410_INTP); | 611 | writeb(mask, info->base + S3C2410_INTP); |
| 694 | if (info->data->needs_src_clk) | ||
| 695 | clk_disable(info->rtc_src_clk); | ||
| 696 | clk_disable(info->rtc_clk); | ||
| 697 | |||
| 698 | s3c_rtc_alarm_clk_enable(info, false); | ||
| 699 | } | 612 | } |
| 700 | 613 | ||
| 701 | static void s3c2410_rtc_setfreq(struct s3c_rtc *info, int freq) | 614 | static void s3c2410_rtc_setfreq(struct s3c_rtc *info, int freq) |
| @@ -849,6 +762,7 @@ static struct s3c_rtc_data const s3c2443_rtc_data = { | |||
| 849 | 762 | ||
| 850 | static struct s3c_rtc_data const s3c6410_rtc_data = { | 763 | static struct s3c_rtc_data const s3c6410_rtc_data = { |
| 851 | .max_user_freq = 32768, | 764 | .max_user_freq = 32768, |
| 765 | .needs_src_clk = true, | ||
| 852 | .irq_handler = s3c6410_rtc_irq, | 766 | .irq_handler = s3c6410_rtc_irq, |
| 853 | .set_freq = s3c6410_rtc_setfreq, | 767 | .set_freq = s3c6410_rtc_setfreq, |
| 854 | .enable_tick = s3c6410_rtc_enable_tick, | 768 | .enable_tick = s3c6410_rtc_enable_tick, |
