diff options
Diffstat (limited to 'drivers/rtc')
| -rw-r--r-- | drivers/rtc/Kconfig | 38 | ||||
| -rw-r--r-- | drivers/rtc/Makefile | 3 | ||||
| -rw-r--r-- | drivers/rtc/interface.c | 102 | ||||
| -rw-r--r-- | drivers/rtc/rtc-at32ap700x.c | 10 | ||||
| -rw-r--r-- | drivers/rtc/rtc-at91rm9200.c | 4 | ||||
| -rw-r--r-- | drivers/rtc/rtc-at91sam9.c | 1 | ||||
| -rw-r--r-- | drivers/rtc/rtc-cmos.c | 31 | ||||
| -rw-r--r-- | drivers/rtc/rtc-dev.c | 12 | ||||
| -rw-r--r-- | drivers/rtc/rtc-ds1374.c | 2 | ||||
| -rw-r--r-- | drivers/rtc/rtc-fm3130.c | 501 | ||||
| -rw-r--r-- | drivers/rtc/rtc-m41t80.c | 7 | ||||
| -rw-r--r-- | drivers/rtc/rtc-omap.c | 1 | ||||
| -rw-r--r-- | drivers/rtc/rtc-pcf8563.c | 1 | ||||
| -rw-r--r-- | drivers/rtc/rtc-pl030.c | 217 | ||||
| -rw-r--r-- | drivers/rtc/rtc-pl031.c | 36 | ||||
| -rw-r--r-- | drivers/rtc/rtc-ppc.c | 69 | ||||
| -rw-r--r-- | drivers/rtc/rtc-s3c.c | 4 | ||||
| -rw-r--r-- | drivers/rtc/rtc-sa1100.c | 41 | ||||
| -rw-r--r-- | drivers/rtc/rtc-x1205.c | 111 |
19 files changed, 1100 insertions, 91 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 6cc2c0330230..fc85bf2e4a97 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig | |||
| @@ -256,6 +256,17 @@ config RTC_DRV_S35390A | |||
| 256 | This driver can also be built as a module. If so the module | 256 | This driver can also be built as a module. If so the module |
| 257 | will be called rtc-s35390a. | 257 | will be called rtc-s35390a. |
| 258 | 258 | ||
| 259 | config RTC_DRV_FM3130 | ||
| 260 | tristate "Ramtron FM3130" | ||
| 261 | help | ||
| 262 | If you say Y here you will get support for the | ||
| 263 | Ramtron FM3130 RTC chips. | ||
| 264 | Ramtron FM3130 is a chip with two separate devices inside, | ||
| 265 | RTC clock and FRAM. This driver provides only RTC functionality. | ||
| 266 | |||
| 267 | This driver can also be built as a module. If so the module | ||
| 268 | will be called rtc-fm3130. | ||
| 269 | |||
| 259 | endif # I2C | 270 | endif # I2C |
| 260 | 271 | ||
| 261 | comment "SPI RTC drivers" | 272 | comment "SPI RTC drivers" |
| @@ -458,6 +469,16 @@ config RTC_DRV_VR41XX | |||
| 458 | To compile this driver as a module, choose M here: the | 469 | To compile this driver as a module, choose M here: the |
| 459 | module will be called rtc-vr41xx. | 470 | module will be called rtc-vr41xx. |
| 460 | 471 | ||
| 472 | config RTC_DRV_PL030 | ||
| 473 | tristate "ARM AMBA PL030 RTC" | ||
| 474 | depends on ARM_AMBA | ||
| 475 | help | ||
| 476 | If you say Y here you will get access to ARM AMBA | ||
| 477 | PrimeCell PL030 RTC found on certain ARM SOCs. | ||
| 478 | |||
| 479 | To compile this driver as a module, choose M here: the | ||
| 480 | module will be called rtc-pl030. | ||
| 481 | |||
| 461 | config RTC_DRV_PL031 | 482 | config RTC_DRV_PL031 |
| 462 | tristate "ARM AMBA PL031 RTC" | 483 | tristate "ARM AMBA PL031 RTC" |
| 463 | depends on ARM_AMBA | 484 | depends on ARM_AMBA |
| @@ -484,12 +505,13 @@ config RTC_DRV_AT91RM9200 | |||
| 484 | this is powered by the backup power supply. | 505 | this is powered by the backup power supply. |
| 485 | 506 | ||
| 486 | config RTC_DRV_AT91SAM9 | 507 | config RTC_DRV_AT91SAM9 |
| 487 | tristate "AT91SAM9x" | 508 | tristate "AT91SAM9x/AT91CAP9" |
| 488 | depends on ARCH_AT91 && !(ARCH_AT91RM9200 || ARCH_AT91X40) | 509 | depends on ARCH_AT91 && !(ARCH_AT91RM9200 || ARCH_AT91X40) |
| 489 | help | 510 | help |
| 490 | RTC driver for the Atmel AT91SAM9x internal RTT (Real Time Timer). | 511 | RTC driver for the Atmel AT91SAM9x and AT91CAP9 internal RTT |
| 491 | These timers are powered by the backup power supply (such as a | 512 | (Real Time Timer). These timers are powered by the backup power |
| 492 | small coin cell battery), but do not need to be used as RTCs. | 513 | supply (such as a small coin cell battery), but do not need to |
| 514 | be used as RTCs. | ||
| 493 | 515 | ||
| 494 | (On AT91SAM9rl chips you probably want to use the dedicated RTC | 516 | (On AT91SAM9rl chips you probably want to use the dedicated RTC |
| 495 | module and leave the RTT available for other uses.) | 517 | module and leave the RTT available for other uses.) |
| @@ -534,4 +556,12 @@ config RTC_DRV_RS5C313 | |||
| 534 | help | 556 | help |
| 535 | If you say yes here you get support for the Ricoh RS5C313 RTC chips. | 557 | If you say yes here you get support for the Ricoh RS5C313 RTC chips. |
| 536 | 558 | ||
| 559 | config RTC_DRV_PPC | ||
| 560 | tristate "PowerPC machine dependent RTC support" | ||
| 561 | depends on PPC_MERGE | ||
| 562 | help | ||
| 563 | The PowerPC kernel has machine-specific functions for accessing | ||
| 564 | the RTC. This exposes that functionality through the generic RTC | ||
| 565 | class. | ||
| 566 | |||
| 537 | endif # RTC_CLASS | 567 | endif # RTC_CLASS |
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index 872f1218ff9f..b5d9d67df887 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile | |||
| @@ -31,6 +31,7 @@ obj-$(CONFIG_RTC_DRV_DS1553) += rtc-ds1553.o | |||
| 31 | obj-$(CONFIG_RTC_DRV_DS1672) += rtc-ds1672.o | 31 | obj-$(CONFIG_RTC_DRV_DS1672) += rtc-ds1672.o |
| 32 | obj-$(CONFIG_RTC_DRV_DS1742) += rtc-ds1742.o | 32 | obj-$(CONFIG_RTC_DRV_DS1742) += rtc-ds1742.o |
| 33 | obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o | 33 | obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o |
| 34 | obj-$(CONFIG_RTC_DRV_FM3130) += rtc-fm3130.o | ||
| 34 | obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o | 35 | obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o |
| 35 | obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o | 36 | obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o |
| 36 | obj-$(CONFIG_RTC_DRV_M48T59) += rtc-m48t59.o | 37 | obj-$(CONFIG_RTC_DRV_M48T59) += rtc-m48t59.o |
| @@ -40,7 +41,9 @@ obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o | |||
| 40 | obj-$(CONFIG_RTC_DRV_OMAP) += rtc-omap.o | 41 | obj-$(CONFIG_RTC_DRV_OMAP) += rtc-omap.o |
| 41 | obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o | 42 | obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o |
| 42 | obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o | 43 | obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o |
| 44 | obj-$(CONFIG_RTC_DRV_PL030) += rtc-pl030.o | ||
| 43 | obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o | 45 | obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o |
| 46 | obj-$(CONFIG_RTC_DRV_PPC) += rtc-ppc.o | ||
| 44 | obj-$(CONFIG_RTC_DRV_R9701) += rtc-r9701.o | 47 | obj-$(CONFIG_RTC_DRV_R9701) += rtc-r9701.o |
| 45 | obj-$(CONFIG_RTC_DRV_RS5C313) += rtc-rs5c313.o | 48 | obj-$(CONFIG_RTC_DRV_RS5C313) += rtc-rs5c313.o |
| 46 | obj-$(CONFIG_RTC_DRV_RS5C348) += rtc-rs5c348.o | 49 | obj-$(CONFIG_RTC_DRV_RS5C348) += rtc-rs5c348.o |
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c index 7e3ad4f3b343..58b7336640ff 100644 --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c | |||
| @@ -126,12 +126,25 @@ int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) | |||
| 126 | int err; | 126 | int err; |
| 127 | struct rtc_time before, now; | 127 | struct rtc_time before, now; |
| 128 | int first_time = 1; | 128 | int first_time = 1; |
| 129 | unsigned long t_now, t_alm; | ||
| 130 | enum { none, day, month, year } missing = none; | ||
| 131 | unsigned days; | ||
| 129 | 132 | ||
| 130 | /* The lower level RTC driver may not be capable of filling | 133 | /* The lower level RTC driver may return -1 in some fields, |
| 131 | * in all fields of the rtc_time struct (eg. rtc-cmos), | 134 | * creating invalid alarm->time values, for reasons like: |
| 132 | * and so might instead return -1 in some fields. | 135 | * |
| 133 | * We deal with that here by grabbing a current RTC timestamp | 136 | * - The hardware may not be capable of filling them in; |
| 134 | * and using values from that for any missing (-1) values. | 137 | * many alarms match only on time-of-day fields, not |
| 138 | * day/month/year calendar data. | ||
| 139 | * | ||
| 140 | * - Some hardware uses illegal values as "wildcard" match | ||
| 141 | * values, which non-Linux firmware (like a BIOS) may try | ||
| 142 | * to set up as e.g. "alarm 15 minutes after each hour". | ||
| 143 | * Linux uses only oneshot alarms. | ||
| 144 | * | ||
| 145 | * When we see that here, we deal with it by using values from | ||
| 146 | * a current RTC timestamp for any missing (-1) values. The | ||
| 147 | * RTC driver prevents "periodic alarm" modes. | ||
| 135 | * | 148 | * |
| 136 | * But this can be racey, because some fields of the RTC timestamp | 149 | * But this can be racey, because some fields of the RTC timestamp |
| 137 | * may have wrapped in the interval since we read the RTC alarm, | 150 | * may have wrapped in the interval since we read the RTC alarm, |
| @@ -174,6 +187,10 @@ int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) | |||
| 174 | if (!alarm->enabled) | 187 | if (!alarm->enabled) |
| 175 | return 0; | 188 | return 0; |
| 176 | 189 | ||
| 190 | /* full-function RTCs won't have such missing fields */ | ||
| 191 | if (rtc_valid_tm(&alarm->time) == 0) | ||
| 192 | return 0; | ||
| 193 | |||
| 177 | /* get the "after" timestamp, to detect wrapped fields */ | 194 | /* get the "after" timestamp, to detect wrapped fields */ |
| 178 | err = rtc_read_time(rtc, &now); | 195 | err = rtc_read_time(rtc, &now); |
| 179 | if (err < 0) | 196 | if (err < 0) |
| @@ -183,22 +200,85 @@ int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) | |||
| 183 | } while ( before.tm_min != now.tm_min | 200 | } while ( before.tm_min != now.tm_min |
| 184 | || before.tm_hour != now.tm_hour | 201 | || before.tm_hour != now.tm_hour |
| 185 | || before.tm_mon != now.tm_mon | 202 | || before.tm_mon != now.tm_mon |
| 186 | || before.tm_year != now.tm_year | 203 | || before.tm_year != now.tm_year); |
| 187 | || before.tm_isdst != now.tm_isdst); | ||
| 188 | 204 | ||
| 189 | /* Fill in any missing alarm fields using the timestamp */ | 205 | /* Fill in the missing alarm fields using the timestamp; we |
| 206 | * know there's at least one since alarm->time is invalid. | ||
| 207 | */ | ||
| 190 | if (alarm->time.tm_sec == -1) | 208 | if (alarm->time.tm_sec == -1) |
| 191 | alarm->time.tm_sec = now.tm_sec; | 209 | alarm->time.tm_sec = now.tm_sec; |
| 192 | if (alarm->time.tm_min == -1) | 210 | if (alarm->time.tm_min == -1) |
| 193 | alarm->time.tm_min = now.tm_min; | 211 | alarm->time.tm_min = now.tm_min; |
| 194 | if (alarm->time.tm_hour == -1) | 212 | if (alarm->time.tm_hour == -1) |
| 195 | alarm->time.tm_hour = now.tm_hour; | 213 | alarm->time.tm_hour = now.tm_hour; |
| 196 | if (alarm->time.tm_mday == -1) | 214 | |
| 215 | /* For simplicity, only support date rollover for now */ | ||
| 216 | if (alarm->time.tm_mday == -1) { | ||
| 197 | alarm->time.tm_mday = now.tm_mday; | 217 | alarm->time.tm_mday = now.tm_mday; |
| 198 | if (alarm->time.tm_mon == -1) | 218 | missing = day; |
| 219 | } | ||
| 220 | if (alarm->time.tm_mon == -1) { | ||
| 199 | alarm->time.tm_mon = now.tm_mon; | 221 | alarm->time.tm_mon = now.tm_mon; |
| 200 | if (alarm->time.tm_year == -1) | 222 | if (missing == none) |
| 223 | missing = month; | ||
| 224 | } | ||
| 225 | if (alarm->time.tm_year == -1) { | ||
| 201 | alarm->time.tm_year = now.tm_year; | 226 | alarm->time.tm_year = now.tm_year; |
| 227 | if (missing == none) | ||
| 228 | missing = year; | ||
| 229 | } | ||
| 230 | |||
| 231 | /* with luck, no rollover is needed */ | ||
| 232 | rtc_tm_to_time(&now, &t_now); | ||
| 233 | rtc_tm_to_time(&alarm->time, &t_alm); | ||
| 234 | if (t_now < t_alm) | ||
| 235 | goto done; | ||
| 236 | |||
| 237 | switch (missing) { | ||
| 238 | |||
| 239 | /* 24 hour rollover ... if it's now 10am Monday, an alarm that | ||
| 240 | * that will trigger at 5am will do so at 5am Tuesday, which | ||
| 241 | * could also be in the next month or year. This is a common | ||
| 242 | * case, especially for PCs. | ||
| 243 | */ | ||
| 244 | case day: | ||
| 245 | dev_dbg(&rtc->dev, "alarm rollover: %s\n", "day"); | ||
| 246 | t_alm += 24 * 60 * 60; | ||
| 247 | rtc_time_to_tm(t_alm, &alarm->time); | ||
| 248 | break; | ||
| 249 | |||
| 250 | /* Month rollover ... if it's the 31th, an alarm on the 3rd will | ||
| 251 | * be next month. An alarm matching on the 30th, 29th, or 28th | ||
| 252 | * may end up in the month after that! Many newer PCs support | ||
| 253 | * this type of alarm. | ||
| 254 | */ | ||
| 255 | case month: | ||
| 256 | dev_dbg(&rtc->dev, "alarm rollover: %s\n", "month"); | ||
| 257 | do { | ||
| 258 | if (alarm->time.tm_mon < 11) | ||
| 259 | alarm->time.tm_mon++; | ||
| 260 | else { | ||
| 261 | alarm->time.tm_mon = 0; | ||
| 262 | alarm->time.tm_year++; | ||
| 263 | } | ||
| 264 | days = rtc_month_days(alarm->time.tm_mon, | ||
| 265 | alarm->time.tm_year); | ||
| 266 | } while (days < alarm->time.tm_mday); | ||
| 267 | break; | ||
| 268 | |||
| 269 | /* Year rollover ... easy except for leap years! */ | ||
| 270 | case year: | ||
| 271 | dev_dbg(&rtc->dev, "alarm rollover: %s\n", "year"); | ||
| 272 | do { | ||
| 273 | alarm->time.tm_year++; | ||
| 274 | } while (!rtc_valid_tm(&alarm->time)); | ||
| 275 | break; | ||
| 276 | |||
| 277 | default: | ||
| 278 | dev_warn(&rtc->dev, "alarm rollover not handled\n"); | ||
| 279 | } | ||
| 280 | |||
| 281 | done: | ||
| 202 | return 0; | 282 | return 0; |
| 203 | } | 283 | } |
| 204 | EXPORT_SYMBOL_GPL(rtc_read_alarm); | 284 | EXPORT_SYMBOL_GPL(rtc_read_alarm); |
diff --git a/drivers/rtc/rtc-at32ap700x.c b/drivers/rtc/rtc-at32ap700x.c index 42244f14b41c..90b9a6503e15 100644 --- a/drivers/rtc/rtc-at32ap700x.c +++ b/drivers/rtc/rtc-at32ap700x.c | |||
| @@ -94,8 +94,11 @@ static int at32_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
| 94 | { | 94 | { |
| 95 | struct rtc_at32ap700x *rtc = dev_get_drvdata(dev); | 95 | struct rtc_at32ap700x *rtc = dev_get_drvdata(dev); |
| 96 | 96 | ||
| 97 | spin_lock_irq(&rtc->lock); | ||
| 97 | rtc_time_to_tm(rtc->alarm_time, &alrm->time); | 98 | rtc_time_to_tm(rtc->alarm_time, &alrm->time); |
| 98 | alrm->pending = rtc_readl(rtc, IMR) & RTC_BIT(IMR_TOPI) ? 1 : 0; | 99 | alrm->enabled = rtc_readl(rtc, IMR) & RTC_BIT(IMR_TOPI) ? 1 : 0; |
| 100 | alrm->pending = rtc_readl(rtc, ISR) & RTC_BIT(ISR_TOPI) ? 1 : 0; | ||
| 101 | spin_unlock_irq(&rtc->lock); | ||
| 99 | 102 | ||
| 100 | return 0; | 103 | return 0; |
| 101 | } | 104 | } |
| @@ -119,7 +122,7 @@ static int at32_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
| 119 | spin_lock_irq(&rtc->lock); | 122 | spin_lock_irq(&rtc->lock); |
| 120 | rtc->alarm_time = alarm_unix_time; | 123 | rtc->alarm_time = alarm_unix_time; |
| 121 | rtc_writel(rtc, TOP, rtc->alarm_time); | 124 | rtc_writel(rtc, TOP, rtc->alarm_time); |
| 122 | if (alrm->pending) | 125 | if (alrm->enabled) |
| 123 | rtc_writel(rtc, CTRL, rtc_readl(rtc, CTRL) | 126 | rtc_writel(rtc, CTRL, rtc_readl(rtc, CTRL) |
| 124 | | RTC_BIT(CTRL_TOPEN)); | 127 | | RTC_BIT(CTRL_TOPEN)); |
| 125 | else | 128 | else |
| @@ -262,6 +265,7 @@ static int __init at32_rtc_probe(struct platform_device *pdev) | |||
| 262 | } | 265 | } |
| 263 | 266 | ||
| 264 | platform_set_drvdata(pdev, rtc); | 267 | platform_set_drvdata(pdev, rtc); |
| 268 | device_init_wakeup(&pdev->dev, 1); | ||
| 265 | 269 | ||
| 266 | dev_info(&pdev->dev, "Atmel RTC for AT32AP700x at %08lx irq %ld\n", | 270 | dev_info(&pdev->dev, "Atmel RTC for AT32AP700x at %08lx irq %ld\n", |
| 267 | (unsigned long)rtc->regs, rtc->irq); | 271 | (unsigned long)rtc->regs, rtc->irq); |
| @@ -281,6 +285,8 @@ static int __exit at32_rtc_remove(struct platform_device *pdev) | |||
| 281 | { | 285 | { |
| 282 | struct rtc_at32ap700x *rtc = platform_get_drvdata(pdev); | 286 | struct rtc_at32ap700x *rtc = platform_get_drvdata(pdev); |
| 283 | 287 | ||
| 288 | device_init_wakeup(&pdev->dev, 0); | ||
| 289 | |||
| 284 | free_irq(rtc->irq, rtc); | 290 | free_irq(rtc->irq, rtc); |
| 285 | iounmap(rtc->regs); | 291 | iounmap(rtc->regs); |
| 286 | rtc_device_unregister(rtc->rtc); | 292 | rtc_device_unregister(rtc->rtc); |
diff --git a/drivers/rtc/rtc-at91rm9200.c b/drivers/rtc/rtc-at91rm9200.c index 39e64ab1ecb7..9c3db934cc24 100644 --- a/drivers/rtc/rtc-at91rm9200.c +++ b/drivers/rtc/rtc-at91rm9200.c | |||
| @@ -29,10 +29,6 @@ | |||
| 29 | #include <linux/completion.h> | 29 | #include <linux/completion.h> |
| 30 | 30 | ||
| 31 | #include <asm/uaccess.h> | 31 | #include <asm/uaccess.h> |
| 32 | #include <asm/rtc.h> | ||
| 33 | |||
| 34 | #include <asm/mach/time.h> | ||
| 35 | |||
| 36 | #include <asm/arch/at91_rtc.h> | 32 | #include <asm/arch/at91_rtc.h> |
| 37 | 33 | ||
| 38 | 34 | ||
diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c index 38d8742a4bdf..f0246ef413a4 100644 --- a/drivers/rtc/rtc-at91sam9.c +++ b/drivers/rtc/rtc-at91sam9.c | |||
| @@ -19,7 +19,6 @@ | |||
| 19 | #include <linux/interrupt.h> | 19 | #include <linux/interrupt.h> |
| 20 | #include <linux/ioctl.h> | 20 | #include <linux/ioctl.h> |
| 21 | 21 | ||
| 22 | #include <asm/mach/time.h> | ||
| 23 | #include <asm/arch/board.h> | 22 | #include <asm/arch/board.h> |
| 24 | #include <asm/arch/at91_rtt.h> | 23 | #include <asm/arch/at91_rtt.h> |
| 25 | 24 | ||
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c index d060a06ce05b..d7bb9bac71df 100644 --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c | |||
| @@ -905,19 +905,7 @@ static struct pnp_driver cmos_pnp_driver = { | |||
| 905 | .resume = cmos_pnp_resume, | 905 | .resume = cmos_pnp_resume, |
| 906 | }; | 906 | }; |
| 907 | 907 | ||
| 908 | static int __init cmos_init(void) | 908 | #endif /* CONFIG_PNP */ |
| 909 | { | ||
| 910 | return pnp_register_driver(&cmos_pnp_driver); | ||
| 911 | } | ||
| 912 | module_init(cmos_init); | ||
| 913 | |||
| 914 | static void __exit cmos_exit(void) | ||
| 915 | { | ||
| 916 | pnp_unregister_driver(&cmos_pnp_driver); | ||
| 917 | } | ||
| 918 | module_exit(cmos_exit); | ||
| 919 | |||
| 920 | #else /* no PNP */ | ||
| 921 | 909 | ||
| 922 | /*----------------------------------------------------------------*/ | 910 | /*----------------------------------------------------------------*/ |
| 923 | 911 | ||
| @@ -958,20 +946,33 @@ static struct platform_driver cmos_platform_driver = { | |||
| 958 | 946 | ||
| 959 | static int __init cmos_init(void) | 947 | static int __init cmos_init(void) |
| 960 | { | 948 | { |
| 949 | #ifdef CONFIG_PNP | ||
| 950 | if (pnp_platform_devices) | ||
| 951 | return pnp_register_driver(&cmos_pnp_driver); | ||
| 952 | else | ||
| 953 | return platform_driver_probe(&cmos_platform_driver, | ||
| 954 | cmos_platform_probe); | ||
| 955 | #else | ||
| 961 | return platform_driver_probe(&cmos_platform_driver, | 956 | return platform_driver_probe(&cmos_platform_driver, |
| 962 | cmos_platform_probe); | 957 | cmos_platform_probe); |
| 958 | #endif /* CONFIG_PNP */ | ||
| 963 | } | 959 | } |
| 964 | module_init(cmos_init); | 960 | module_init(cmos_init); |
| 965 | 961 | ||
| 966 | static void __exit cmos_exit(void) | 962 | static void __exit cmos_exit(void) |
| 967 | { | 963 | { |
| 964 | #ifdef CONFIG_PNP | ||
| 965 | if (pnp_platform_devices) | ||
| 966 | pnp_unregister_driver(&cmos_pnp_driver); | ||
| 967 | else | ||
| 968 | platform_driver_unregister(&cmos_platform_driver); | ||
| 969 | #else | ||
| 968 | platform_driver_unregister(&cmos_platform_driver); | 970 | platform_driver_unregister(&cmos_platform_driver); |
| 971 | #endif /* CONFIG_PNP */ | ||
| 969 | } | 972 | } |
| 970 | module_exit(cmos_exit); | 973 | module_exit(cmos_exit); |
| 971 | 974 | ||
| 972 | 975 | ||
| 973 | #endif /* !PNP */ | ||
| 974 | |||
| 975 | MODULE_AUTHOR("David Brownell"); | 976 | MODULE_AUTHOR("David Brownell"); |
| 976 | MODULE_DESCRIPTION("Driver for PC-style 'CMOS' RTCs"); | 977 | MODULE_DESCRIPTION("Driver for PC-style 'CMOS' RTCs"); |
| 977 | MODULE_LICENSE("GPL"); | 978 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c index 90dfa0df747a..0114a78b7cbb 100644 --- a/drivers/rtc/rtc-dev.c +++ b/drivers/rtc/rtc-dev.c | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | 13 | ||
| 14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
| 15 | #include <linux/rtc.h> | 15 | #include <linux/rtc.h> |
| 16 | #include <linux/smp_lock.h> | ||
| 16 | #include "rtc-core.h" | 17 | #include "rtc-core.h" |
| 17 | 18 | ||
| 18 | static dev_t rtc_devt; | 19 | static dev_t rtc_devt; |
| @@ -26,8 +27,11 @@ static int rtc_dev_open(struct inode *inode, struct file *file) | |||
| 26 | struct rtc_device, char_dev); | 27 | struct rtc_device, char_dev); |
| 27 | const struct rtc_class_ops *ops = rtc->ops; | 28 | const struct rtc_class_ops *ops = rtc->ops; |
| 28 | 29 | ||
| 29 | if (test_and_set_bit_lock(RTC_DEV_BUSY, &rtc->flags)) | 30 | lock_kernel(); |
| 30 | return -EBUSY; | 31 | if (test_and_set_bit_lock(RTC_DEV_BUSY, &rtc->flags)) { |
| 32 | err = -EBUSY; | ||
| 33 | goto out; | ||
| 34 | } | ||
| 31 | 35 | ||
| 32 | file->private_data = rtc; | 36 | file->private_data = rtc; |
| 33 | 37 | ||
| @@ -37,11 +41,13 @@ static int rtc_dev_open(struct inode *inode, struct file *file) | |||
| 37 | rtc->irq_data = 0; | 41 | rtc->irq_data = 0; |
| 38 | spin_unlock_irq(&rtc->irq_lock); | 42 | spin_unlock_irq(&rtc->irq_lock); |
| 39 | 43 | ||
| 40 | return 0; | 44 | goto out; |
| 41 | } | 45 | } |
| 42 | 46 | ||
| 43 | /* something has gone wrong */ | 47 | /* something has gone wrong */ |
| 44 | clear_bit_unlock(RTC_DEV_BUSY, &rtc->flags); | 48 | clear_bit_unlock(RTC_DEV_BUSY, &rtc->flags); |
| 49 | out: | ||
| 50 | unlock_kernel(); | ||
| 45 | return err; | 51 | return err; |
| 46 | } | 52 | } |
| 47 | 53 | ||
diff --git a/drivers/rtc/rtc-ds1374.c b/drivers/rtc/rtc-ds1374.c index fa2d2f8b3f4d..640acd20fdde 100644 --- a/drivers/rtc/rtc-ds1374.c +++ b/drivers/rtc/rtc-ds1374.c | |||
| @@ -42,7 +42,7 @@ | |||
| 42 | #define DS1374_REG_TCR 0x09 /* Trickle Charge */ | 42 | #define DS1374_REG_TCR 0x09 /* Trickle Charge */ |
| 43 | 43 | ||
| 44 | static const struct i2c_device_id ds1374_id[] = { | 44 | static const struct i2c_device_id ds1374_id[] = { |
| 45 | { "rtc-ds1374", 0 }, | 45 | { "ds1374", 0 }, |
| 46 | { } | 46 | { } |
| 47 | }; | 47 | }; |
| 48 | MODULE_DEVICE_TABLE(i2c, ds1374_id); | 48 | MODULE_DEVICE_TABLE(i2c, ds1374_id); |
diff --git a/drivers/rtc/rtc-fm3130.c b/drivers/rtc/rtc-fm3130.c new file mode 100644 index 000000000000..abfdfcbaa059 --- /dev/null +++ b/drivers/rtc/rtc-fm3130.c | |||
| @@ -0,0 +1,501 @@ | |||
| 1 | /* | ||
| 2 | * rtc-fm3130.c - RTC driver for Ramtron FM3130 I2C chip. | ||
| 3 | * | ||
| 4 | * Copyright (C) 2008 Sergey Lapin | ||
| 5 | * Based on ds1307 driver by James Chapman and David Brownell | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License version 2 as | ||
| 9 | * published by the Free Software Foundation. | ||
| 10 | */ | ||
| 11 | |||
| 12 | #include <linux/module.h> | ||
| 13 | #include <linux/i2c.h> | ||
| 14 | #include <linux/rtc.h> | ||
| 15 | #include <linux/bcd.h> | ||
| 16 | |||
| 17 | #define FM3130_RTC_CONTROL (0x0) | ||
| 18 | #define FM3130_CAL_CONTROL (0x1) | ||
| 19 | #define FM3130_RTC_SECONDS (0x2) | ||
| 20 | #define FM3130_RTC_MINUTES (0x3) | ||
| 21 | #define FM3130_RTC_HOURS (0x4) | ||
| 22 | #define FM3130_RTC_DAY (0x5) | ||
| 23 | #define FM3130_RTC_DATE (0x6) | ||
| 24 | #define FM3130_RTC_MONTHS (0x7) | ||
| 25 | #define FM3130_RTC_YEARS (0x8) | ||
| 26 | |||
| 27 | #define FM3130_ALARM_SECONDS (0x9) | ||
| 28 | #define FM3130_ALARM_MINUTES (0xa) | ||
| 29 | #define FM3130_ALARM_HOURS (0xb) | ||
| 30 | #define FM3130_ALARM_DATE (0xc) | ||
| 31 | #define FM3130_ALARM_MONTHS (0xd) | ||
| 32 | #define FM3130_ALARM_WP_CONTROL (0xe) | ||
| 33 | |||
| 34 | #define FM3130_CAL_CONTROL_BIT_nOSCEN (1 << 7) /* Osciallator enabled */ | ||
| 35 | #define FM3130_RTC_CONTROL_BIT_LB (1 << 7) /* Low battery */ | ||
| 36 | #define FM3130_RTC_CONTROL_BIT_AF (1 << 6) /* Alarm flag */ | ||
| 37 | #define FM3130_RTC_CONTROL_BIT_CF (1 << 5) /* Century overflow */ | ||
| 38 | #define FM3130_RTC_CONTROL_BIT_POR (1 << 4) /* Power on reset */ | ||
| 39 | #define FM3130_RTC_CONTROL_BIT_AEN (1 << 3) /* Alarm enable */ | ||
| 40 | #define FM3130_RTC_CONTROL_BIT_CAL (1 << 2) /* Calibration mode */ | ||
| 41 | #define FM3130_RTC_CONTROL_BIT_WRITE (1 << 1) /* W=1 -> write mode W=0 normal */ | ||
| 42 | #define FM3130_RTC_CONTROL_BIT_READ (1 << 0) /* R=1 -> read mode R=0 normal */ | ||
| 43 | |||
| 44 | #define FM3130_CLOCK_REGS 7 | ||
| 45 | #define FM3130_ALARM_REGS 5 | ||
| 46 | |||
| 47 | struct fm3130 { | ||
| 48 | u8 reg_addr_time; | ||
| 49 | u8 reg_addr_alarm; | ||
| 50 | u8 regs[15]; | ||
| 51 | struct i2c_msg msg[4]; | ||
| 52 | struct i2c_client *client; | ||
| 53 | struct rtc_device *rtc; | ||
| 54 | int data_valid; | ||
| 55 | int alarm; | ||
| 56 | }; | ||
| 57 | static const struct i2c_device_id fm3130_id[] = { | ||
| 58 | { "fm3130", 0 }, | ||
| 59 | { } | ||
| 60 | }; | ||
| 61 | MODULE_DEVICE_TABLE(i2c, fm3130_id); | ||
| 62 | |||
| 63 | #define FM3130_MODE_NORMAL 0 | ||
| 64 | #define FM3130_MODE_WRITE 1 | ||
| 65 | #define FM3130_MODE_READ 2 | ||
| 66 | |||
| 67 | static void fm3130_rtc_mode(struct device *dev, int mode) | ||
| 68 | { | ||
| 69 | struct fm3130 *fm3130 = dev_get_drvdata(dev); | ||
| 70 | |||
| 71 | fm3130->regs[FM3130_RTC_CONTROL] = | ||
| 72 | i2c_smbus_read_byte_data(fm3130->client, FM3130_RTC_CONTROL); | ||
| 73 | switch (mode) { | ||
| 74 | case FM3130_MODE_NORMAL: | ||
| 75 | fm3130->regs[FM3130_RTC_CONTROL] &= | ||
| 76 | ~(FM3130_RTC_CONTROL_BIT_WRITE | | ||
| 77 | FM3130_RTC_CONTROL_BIT_READ); | ||
| 78 | break; | ||
| 79 | case FM3130_MODE_WRITE: | ||
| 80 | fm3130->regs[FM3130_RTC_CONTROL] |= FM3130_RTC_CONTROL_BIT_WRITE; | ||
| 81 | break; | ||
| 82 | case FM3130_MODE_READ: | ||
| 83 | fm3130->regs[FM3130_RTC_CONTROL] |= FM3130_RTC_CONTROL_BIT_READ; | ||
| 84 | break; | ||
| 85 | default: | ||
| 86 | dev_dbg(dev, "invalid mode %d\n", mode); | ||
| 87 | break; | ||
| 88 | } | ||
| 89 | /* Checking for alarm */ | ||
| 90 | if (fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_AF) { | ||
| 91 | fm3130->alarm = 1; | ||
| 92 | fm3130->regs[FM3130_RTC_CONTROL] &= ~FM3130_RTC_CONTROL_BIT_AF; | ||
| 93 | } | ||
| 94 | i2c_smbus_write_byte_data(fm3130->client, | ||
| 95 | FM3130_RTC_CONTROL, fm3130->regs[FM3130_RTC_CONTROL]); | ||
| 96 | } | ||
| 97 | |||
| 98 | static int fm3130_get_time(struct device *dev, struct rtc_time *t) | ||
| 99 | { | ||
| 100 | struct fm3130 *fm3130 = dev_get_drvdata(dev); | ||
| 101 | int tmp; | ||
| 102 | |||
| 103 | if (!fm3130->data_valid) { | ||
| 104 | /* We have invalid data in RTC, probably due | ||
| 105 | to battery faults or other problems. Return EIO | ||
| 106 | for now, it will allow us to set data later insted | ||
| 107 | of error during probing which disables device */ | ||
| 108 | return -EIO; | ||
| 109 | } | ||
| 110 | fm3130_rtc_mode(dev, FM3130_MODE_READ); | ||
| 111 | |||
| 112 | /* read the RTC date and time registers all at once */ | ||
| 113 | tmp = i2c_transfer(to_i2c_adapter(fm3130->client->dev.parent), | ||
| 114 | fm3130->msg, 2); | ||
| 115 | if (tmp != 2) { | ||
| 116 | dev_err(dev, "%s error %d\n", "read", tmp); | ||
| 117 | return -EIO; | ||
| 118 | } | ||
| 119 | |||
| 120 | fm3130_rtc_mode(dev, FM3130_MODE_NORMAL); | ||
| 121 | |||
| 122 | dev_dbg(dev, "%s: %02x %02x %02x %02x %02x %02x %02x %02x" | ||
| 123 | "%02x %02x %02x %02x %02x %02x %02x\n", | ||
| 124 | "read", | ||
| 125 | fm3130->regs[0], fm3130->regs[1], | ||
| 126 | fm3130->regs[2], fm3130->regs[3], | ||
| 127 | fm3130->regs[4], fm3130->regs[5], | ||
| 128 | fm3130->regs[6], fm3130->regs[7], | ||
| 129 | fm3130->regs[8], fm3130->regs[9], | ||
| 130 | fm3130->regs[0xa], fm3130->regs[0xb], | ||
| 131 | fm3130->regs[0xc], fm3130->regs[0xd], | ||
| 132 | fm3130->regs[0xe]); | ||
| 133 | |||
| 134 | t->tm_sec = BCD2BIN(fm3130->regs[FM3130_RTC_SECONDS] & 0x7f); | ||
| 135 | t->tm_min = BCD2BIN(fm3130->regs[FM3130_RTC_MINUTES] & 0x7f); | ||
| 136 | tmp = fm3130->regs[FM3130_RTC_HOURS] & 0x3f; | ||
| 137 | t->tm_hour = BCD2BIN(tmp); | ||
| 138 | t->tm_wday = BCD2BIN(fm3130->regs[FM3130_RTC_DAY] & 0x07) - 1; | ||
| 139 | t->tm_mday = BCD2BIN(fm3130->regs[FM3130_RTC_DATE] & 0x3f); | ||
| 140 | tmp = fm3130->regs[FM3130_RTC_MONTHS] & 0x1f; | ||
| 141 | t->tm_mon = BCD2BIN(tmp) - 1; | ||
| 142 | |||
| 143 | /* assume 20YY not 19YY, and ignore CF bit */ | ||
| 144 | t->tm_year = BCD2BIN(fm3130->regs[FM3130_RTC_YEARS]) + 100; | ||
| 145 | |||
| 146 | dev_dbg(dev, "%s secs=%d, mins=%d, " | ||
| 147 | "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n", | ||
| 148 | "read", t->tm_sec, t->tm_min, | ||
| 149 | t->tm_hour, t->tm_mday, | ||
| 150 | t->tm_mon, t->tm_year, t->tm_wday); | ||
| 151 | |||
| 152 | /* initial clock setting can be undefined */ | ||
| 153 | return rtc_valid_tm(t); | ||
| 154 | } | ||
| 155 | |||
| 156 | |||
| 157 | static int fm3130_set_time(struct device *dev, struct rtc_time *t) | ||
| 158 | { | ||
| 159 | struct fm3130 *fm3130 = dev_get_drvdata(dev); | ||
| 160 | int tmp, i; | ||
| 161 | u8 *buf = fm3130->regs; | ||
| 162 | |||
| 163 | dev_dbg(dev, "%s secs=%d, mins=%d, " | ||
| 164 | "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n", | ||
| 165 | "write", t->tm_sec, t->tm_min, | ||
| 166 | t->tm_hour, t->tm_mday, | ||
| 167 | t->tm_mon, t->tm_year, t->tm_wday); | ||
| 168 | |||
| 169 | /* first register addr */ | ||
| 170 | buf[FM3130_RTC_SECONDS] = BIN2BCD(t->tm_sec); | ||
| 171 | buf[FM3130_RTC_MINUTES] = BIN2BCD(t->tm_min); | ||
| 172 | buf[FM3130_RTC_HOURS] = BIN2BCD(t->tm_hour); | ||
| 173 | buf[FM3130_RTC_DAY] = BIN2BCD(t->tm_wday + 1); | ||
| 174 | buf[FM3130_RTC_DATE] = BIN2BCD(t->tm_mday); | ||
| 175 | buf[FM3130_RTC_MONTHS] = BIN2BCD(t->tm_mon + 1); | ||
| 176 | |||
| 177 | /* assume 20YY not 19YY */ | ||
| 178 | tmp = t->tm_year - 100; | ||
| 179 | buf[FM3130_RTC_YEARS] = BIN2BCD(tmp); | ||
| 180 | |||
| 181 | dev_dbg(dev, "%s: %02x %02x %02x %02x %02x %02x %02x" | ||
| 182 | "%02x %02x %02x %02x %02x %02x %02x %02x\n", | ||
| 183 | "write", buf[0], buf[1], buf[2], buf[3], | ||
| 184 | buf[4], buf[5], buf[6], buf[7], | ||
| 185 | buf[8], buf[9], buf[0xa], buf[0xb], | ||
| 186 | buf[0xc], buf[0xd], buf[0xe]); | ||
| 187 | |||
| 188 | fm3130_rtc_mode(dev, FM3130_MODE_WRITE); | ||
| 189 | |||
| 190 | /* Writing time registers, we don't support multibyte transfers */ | ||
| 191 | for (i = 0; i < FM3130_CLOCK_REGS; i++) { | ||
| 192 | i2c_smbus_write_byte_data(fm3130->client, | ||
| 193 | FM3130_RTC_SECONDS + i, | ||
| 194 | fm3130->regs[FM3130_RTC_SECONDS + i]); | ||
| 195 | } | ||
| 196 | |||
| 197 | fm3130_rtc_mode(dev, FM3130_MODE_NORMAL); | ||
| 198 | |||
| 199 | /* We assume here that data are valid once written */ | ||
| 200 | if (!fm3130->data_valid) | ||
| 201 | fm3130->data_valid = 1; | ||
| 202 | return 0; | ||
| 203 | } | ||
| 204 | |||
| 205 | static int fm3130_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | ||
| 206 | { | ||
| 207 | struct fm3130 *fm3130 = dev_get_drvdata(dev); | ||
| 208 | int tmp; | ||
| 209 | struct rtc_time *tm = &alrm->time; | ||
| 210 | /* read the RTC alarm registers all at once */ | ||
| 211 | tmp = i2c_transfer(to_i2c_adapter(fm3130->client->dev.parent), | ||
| 212 | &fm3130->msg[2], 2); | ||
| 213 | if (tmp != 2) { | ||
| 214 | dev_err(dev, "%s error %d\n", "read", tmp); | ||
| 215 | return -EIO; | ||
| 216 | } | ||
| 217 | dev_dbg(dev, "alarm read %02x %02x %02x %02x %02x\n", | ||
| 218 | fm3130->regs[FM3130_ALARM_SECONDS], | ||
| 219 | fm3130->regs[FM3130_ALARM_MINUTES], | ||
| 220 | fm3130->regs[FM3130_ALARM_HOURS], | ||
| 221 | fm3130->regs[FM3130_ALARM_DATE], | ||
| 222 | fm3130->regs[FM3130_ALARM_MONTHS]); | ||
| 223 | |||
| 224 | |||
| 225 | tm->tm_sec = BCD2BIN(fm3130->regs[FM3130_ALARM_SECONDS] & 0x7F); | ||
| 226 | tm->tm_min = BCD2BIN(fm3130->regs[FM3130_ALARM_MINUTES] & 0x7F); | ||
| 227 | tm->tm_hour = BCD2BIN(fm3130->regs[FM3130_ALARM_HOURS] & 0x3F); | ||
| 228 | tm->tm_mday = BCD2BIN(fm3130->regs[FM3130_ALARM_DATE] & 0x3F); | ||
| 229 | tm->tm_mon = BCD2BIN(fm3130->regs[FM3130_ALARM_MONTHS] & 0x1F); | ||
| 230 | if (tm->tm_mon > 0) | ||
| 231 | tm->tm_mon -= 1; /* RTC is 1-12, tm_mon is 0-11 */ | ||
| 232 | dev_dbg(dev, "%s secs=%d, mins=%d, " | ||
| 233 | "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n", | ||
| 234 | "read alarm", tm->tm_sec, tm->tm_min, | ||
| 235 | tm->tm_hour, tm->tm_mday, | ||
| 236 | tm->tm_mon, tm->tm_year, tm->tm_wday); | ||
| 237 | |||
| 238 | return 0; | ||
| 239 | } | ||
| 240 | |||
| 241 | static int fm3130_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | ||
| 242 | { | ||
| 243 | struct fm3130 *fm3130 = dev_get_drvdata(dev); | ||
| 244 | struct rtc_time *tm = &alrm->time; | ||
| 245 | int i; | ||
| 246 | |||
| 247 | dev_dbg(dev, "%s secs=%d, mins=%d, " | ||
| 248 | "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n", | ||
| 249 | "write alarm", tm->tm_sec, tm->tm_min, | ||
| 250 | tm->tm_hour, tm->tm_mday, | ||
| 251 | tm->tm_mon, tm->tm_year, tm->tm_wday); | ||
| 252 | |||
| 253 | if (tm->tm_sec != -1) | ||
| 254 | fm3130->regs[FM3130_ALARM_SECONDS] = | ||
| 255 | BIN2BCD(tm->tm_sec) | 0x80; | ||
| 256 | |||
| 257 | if (tm->tm_min != -1) | ||
| 258 | fm3130->regs[FM3130_ALARM_MINUTES] = | ||
| 259 | BIN2BCD(tm->tm_min) | 0x80; | ||
| 260 | |||
| 261 | if (tm->tm_hour != -1) | ||
| 262 | fm3130->regs[FM3130_ALARM_HOURS] = | ||
| 263 | BIN2BCD(tm->tm_hour) | 0x80; | ||
| 264 | |||
| 265 | if (tm->tm_mday != -1) | ||
| 266 | fm3130->regs[FM3130_ALARM_DATE] = | ||
| 267 | BIN2BCD(tm->tm_mday) | 0x80; | ||
| 268 | |||
| 269 | if (tm->tm_mon != -1) | ||
| 270 | fm3130->regs[FM3130_ALARM_MONTHS] = | ||
| 271 | BIN2BCD(tm->tm_mon + 1) | 0x80; | ||
| 272 | |||
| 273 | dev_dbg(dev, "alarm write %02x %02x %02x %02x %02x\n", | ||
| 274 | fm3130->regs[FM3130_ALARM_SECONDS], | ||
| 275 | fm3130->regs[FM3130_ALARM_MINUTES], | ||
| 276 | fm3130->regs[FM3130_ALARM_HOURS], | ||
| 277 | fm3130->regs[FM3130_ALARM_DATE], | ||
| 278 | fm3130->regs[FM3130_ALARM_MONTHS]); | ||
| 279 | /* Writing time registers, we don't support multibyte transfers */ | ||
| 280 | for (i = 0; i < FM3130_ALARM_REGS; i++) { | ||
| 281 | i2c_smbus_write_byte_data(fm3130->client, | ||
| 282 | FM3130_ALARM_SECONDS + i, | ||
| 283 | fm3130->regs[FM3130_ALARM_SECONDS + i]); | ||
| 284 | } | ||
| 285 | fm3130->regs[FM3130_RTC_CONTROL] = | ||
| 286 | i2c_smbus_read_byte_data(fm3130->client, FM3130_RTC_CONTROL); | ||
| 287 | /* Checking for alarm */ | ||
| 288 | if (fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_AF) { | ||
| 289 | fm3130->alarm = 1; | ||
| 290 | fm3130->regs[FM3130_RTC_CONTROL] &= ~FM3130_RTC_CONTROL_BIT_AF; | ||
| 291 | } | ||
| 292 | if (alrm->enabled) { | ||
| 293 | i2c_smbus_write_byte_data(fm3130->client, FM3130_RTC_CONTROL, | ||
| 294 | (fm3130->regs[FM3130_RTC_CONTROL] & | ||
| 295 | ~(FM3130_RTC_CONTROL_BIT_CAL)) | | ||
| 296 | FM3130_RTC_CONTROL_BIT_AEN); | ||
| 297 | } else { | ||
| 298 | i2c_smbus_write_byte_data(fm3130->client, FM3130_RTC_CONTROL, | ||
| 299 | fm3130->regs[FM3130_RTC_CONTROL] & | ||
| 300 | ~(FM3130_RTC_CONTROL_BIT_AEN)); | ||
| 301 | } | ||
| 302 | return 0; | ||
| 303 | } | ||
| 304 | |||
| 305 | static const struct rtc_class_ops fm3130_rtc_ops = { | ||
| 306 | .read_time = fm3130_get_time, | ||
| 307 | .set_time = fm3130_set_time, | ||
| 308 | .read_alarm = fm3130_read_alarm, | ||
| 309 | .set_alarm = fm3130_set_alarm, | ||
| 310 | }; | ||
| 311 | |||
| 312 | static struct i2c_driver fm3130_driver; | ||
| 313 | |||
| 314 | static int __devinit fm3130_probe(struct i2c_client *client, | ||
| 315 | const struct i2c_device_id *id) | ||
| 316 | { | ||
| 317 | struct fm3130 *fm3130; | ||
| 318 | int err = -ENODEV; | ||
| 319 | int tmp; | ||
| 320 | struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); | ||
| 321 | |||
| 322 | if (!i2c_check_functionality(adapter, | ||
| 323 | I2C_FUNC_I2C | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) | ||
| 324 | return -EIO; | ||
| 325 | |||
| 326 | fm3130 = kzalloc(sizeof(struct fm3130), GFP_KERNEL); | ||
| 327 | |||
| 328 | if (!fm3130) | ||
| 329 | return -ENOMEM; | ||
| 330 | |||
| 331 | fm3130->client = client; | ||
| 332 | i2c_set_clientdata(client, fm3130); | ||
| 333 | fm3130->reg_addr_time = FM3130_RTC_SECONDS; | ||
| 334 | fm3130->reg_addr_alarm = FM3130_ALARM_SECONDS; | ||
| 335 | |||
| 336 | /* Messages to read time */ | ||
| 337 | fm3130->msg[0].addr = client->addr; | ||
| 338 | fm3130->msg[0].flags = 0; | ||
| 339 | fm3130->msg[0].len = 1; | ||
| 340 | fm3130->msg[0].buf = &fm3130->reg_addr_time; | ||
| 341 | |||
| 342 | fm3130->msg[1].addr = client->addr; | ||
| 343 | fm3130->msg[1].flags = I2C_M_RD; | ||
| 344 | fm3130->msg[1].len = FM3130_CLOCK_REGS; | ||
| 345 | fm3130->msg[1].buf = &fm3130->regs[FM3130_RTC_SECONDS]; | ||
| 346 | |||
| 347 | /* Messages to read alarm */ | ||
| 348 | fm3130->msg[2].addr = client->addr; | ||
| 349 | fm3130->msg[2].flags = 0; | ||
| 350 | fm3130->msg[2].len = 1; | ||
| 351 | fm3130->msg[2].buf = &fm3130->reg_addr_alarm; | ||
| 352 | |||
| 353 | fm3130->msg[3].addr = client->addr; | ||
| 354 | fm3130->msg[3].flags = I2C_M_RD; | ||
| 355 | fm3130->msg[3].len = FM3130_ALARM_REGS; | ||
| 356 | fm3130->msg[3].buf = &fm3130->regs[FM3130_ALARM_SECONDS]; | ||
| 357 | |||
| 358 | fm3130->data_valid = 0; | ||
| 359 | |||
| 360 | tmp = i2c_transfer(adapter, fm3130->msg, 4); | ||
| 361 | if (tmp != 4) { | ||
| 362 | pr_debug("read error %d\n", tmp); | ||
| 363 | err = -EIO; | ||
| 364 | goto exit_free; | ||
| 365 | } | ||
| 366 | |||
| 367 | fm3130->regs[FM3130_RTC_CONTROL] = | ||
| 368 | i2c_smbus_read_byte_data(client, FM3130_RTC_CONTROL); | ||
| 369 | fm3130->regs[FM3130_CAL_CONTROL] = | ||
| 370 | i2c_smbus_read_byte_data(client, FM3130_CAL_CONTROL); | ||
| 371 | |||
| 372 | /* Checking for alarm */ | ||
| 373 | if (fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_AF) { | ||
| 374 | fm3130->alarm = 1; | ||
| 375 | fm3130->regs[FM3130_RTC_CONTROL] &= ~FM3130_RTC_CONTROL_BIT_AF; | ||
| 376 | } | ||
| 377 | |||
| 378 | /* Disabling calibration mode */ | ||
| 379 | if (fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_CAL) | ||
| 380 | i2c_smbus_write_byte_data(client, FM3130_RTC_CONTROL, | ||
| 381 | fm3130->regs[FM3130_RTC_CONTROL] & | ||
| 382 | ~(FM3130_RTC_CONTROL_BIT_CAL)); | ||
| 383 | dev_warn(&client->dev, "Disabling calibration mode!\n"); | ||
| 384 | |||
| 385 | /* Disabling read and write modes */ | ||
| 386 | if (fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_WRITE || | ||
| 387 | fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_READ) | ||
| 388 | i2c_smbus_write_byte_data(client, FM3130_RTC_CONTROL, | ||
| 389 | fm3130->regs[FM3130_RTC_CONTROL] & | ||
| 390 | ~(FM3130_RTC_CONTROL_BIT_READ | | ||
| 391 | FM3130_RTC_CONTROL_BIT_WRITE)); | ||
| 392 | dev_warn(&client->dev, "Disabling READ or WRITE mode!\n"); | ||
| 393 | |||
| 394 | /* oscillator off? turn it on, so clock can tick. */ | ||
| 395 | if (fm3130->regs[FM3130_CAL_CONTROL] & FM3130_CAL_CONTROL_BIT_nOSCEN) | ||
| 396 | i2c_smbus_write_byte_data(client, FM3130_CAL_CONTROL, | ||
| 397 | fm3130->regs[FM3130_CAL_CONTROL] & | ||
| 398 | ~(FM3130_CAL_CONTROL_BIT_nOSCEN)); | ||
| 399 | |||
| 400 | /* oscillator fault? clear flag, and warn */ | ||
| 401 | if (fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_LB) | ||
| 402 | dev_warn(&client->dev, "Low battery!\n"); | ||
| 403 | |||
| 404 | /* oscillator fault? clear flag, and warn */ | ||
| 405 | if (fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_POR) { | ||
| 406 | i2c_smbus_write_byte_data(client, FM3130_RTC_CONTROL, | ||
| 407 | fm3130->regs[FM3130_RTC_CONTROL] & | ||
| 408 | ~FM3130_RTC_CONTROL_BIT_POR); | ||
| 409 | dev_warn(&client->dev, "SET TIME!\n"); | ||
| 410 | } | ||
| 411 | /* ACS is controlled by alarm */ | ||
| 412 | i2c_smbus_write_byte_data(client, FM3130_ALARM_WP_CONTROL, 0x80); | ||
| 413 | |||
| 414 | /* TODO */ | ||
| 415 | /* TODO need to sanity check alarm */ | ||
| 416 | tmp = fm3130->regs[FM3130_RTC_SECONDS]; | ||
| 417 | tmp = BCD2BIN(tmp & 0x7f); | ||
| 418 | if (tmp > 60) | ||
| 419 | goto exit_bad; | ||
| 420 | tmp = BCD2BIN(fm3130->regs[FM3130_RTC_MINUTES] & 0x7f); | ||
| 421 | if (tmp > 60) | ||
| 422 | goto exit_bad; | ||
| 423 | |||
| 424 | tmp = BCD2BIN(fm3130->regs[FM3130_RTC_DATE] & 0x3f); | ||
| 425 | if (tmp == 0 || tmp > 31) | ||
| 426 | goto exit_bad; | ||
| 427 | |||
| 428 | tmp = BCD2BIN(fm3130->regs[FM3130_RTC_MONTHS] & 0x1f); | ||
| 429 | if (tmp == 0 || tmp > 12) | ||
| 430 | goto exit_bad; | ||
| 431 | |||
| 432 | tmp = fm3130->regs[FM3130_RTC_HOURS]; | ||
| 433 | |||
| 434 | fm3130->data_valid = 1; | ||
| 435 | |||
| 436 | exit_bad: | ||
| 437 | if (!fm3130->data_valid) | ||
| 438 | dev_dbg(&client->dev, | ||
| 439 | "%s: %02x %02x %02x %02x %02x %02x %02x %02x" | ||
| 440 | "%02x %02x %02x %02x %02x %02x %02x\n", | ||
| 441 | "bogus registers", | ||
| 442 | fm3130->regs[0], fm3130->regs[1], | ||
| 443 | fm3130->regs[2], fm3130->regs[3], | ||
| 444 | fm3130->regs[4], fm3130->regs[5], | ||
| 445 | fm3130->regs[6], fm3130->regs[7], | ||
| 446 | fm3130->regs[8], fm3130->regs[9], | ||
| 447 | fm3130->regs[0xa], fm3130->regs[0xb], | ||
| 448 | fm3130->regs[0xc], fm3130->regs[0xd], | ||
| 449 | fm3130->regs[0xe]); | ||
| 450 | |||
| 451 | /* We won't bail out here because we just got invalid data. | ||
| 452 | Time setting from u-boot doesn't work anyway */ | ||
| 453 | fm3130->rtc = rtc_device_register(client->name, &client->dev, | ||
| 454 | &fm3130_rtc_ops, THIS_MODULE); | ||
| 455 | if (IS_ERR(fm3130->rtc)) { | ||
| 456 | err = PTR_ERR(fm3130->rtc); | ||
| 457 | dev_err(&client->dev, | ||
| 458 | "unable to register the class device\n"); | ||
| 459 | goto exit_free; | ||
| 460 | } | ||
| 461 | return 0; | ||
| 462 | exit_free: | ||
| 463 | kfree(fm3130); | ||
| 464 | return err; | ||
| 465 | } | ||
| 466 | |||
| 467 | static int __devexit fm3130_remove(struct i2c_client *client) | ||
| 468 | { | ||
| 469 | struct fm3130 *fm3130 = i2c_get_clientdata(client); | ||
| 470 | |||
| 471 | rtc_device_unregister(fm3130->rtc); | ||
| 472 | kfree(fm3130); | ||
| 473 | return 0; | ||
| 474 | } | ||
| 475 | |||
| 476 | static struct i2c_driver fm3130_driver = { | ||
| 477 | .driver = { | ||
| 478 | .name = "rtc-fm3130", | ||
| 479 | .owner = THIS_MODULE, | ||
| 480 | }, | ||
| 481 | .probe = fm3130_probe, | ||
| 482 | .remove = __devexit_p(fm3130_remove), | ||
| 483 | .id_table = fm3130_id, | ||
| 484 | }; | ||
| 485 | |||
| 486 | static int __init fm3130_init(void) | ||
| 487 | { | ||
| 488 | return i2c_add_driver(&fm3130_driver); | ||
| 489 | } | ||
| 490 | module_init(fm3130_init); | ||
| 491 | |||
| 492 | static void __exit fm3130_exit(void) | ||
| 493 | { | ||
| 494 | i2c_del_driver(&fm3130_driver); | ||
| 495 | } | ||
| 496 | module_exit(fm3130_exit); | ||
| 497 | |||
| 498 | MODULE_DESCRIPTION("RTC driver for FM3130"); | ||
| 499 | MODULE_AUTHOR("Sergey Lapin <slapin@ossfans.org>"); | ||
| 500 | MODULE_LICENSE("GPL"); | ||
| 501 | |||
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c index a3e0880b38fb..0a19c06019be 100644 --- a/drivers/rtc/rtc-m41t80.c +++ b/drivers/rtc/rtc-m41t80.c | |||
| @@ -17,6 +17,7 @@ | |||
| 17 | #include <linux/init.h> | 17 | #include <linux/init.h> |
| 18 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
| 19 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
| 20 | #include <linux/smp_lock.h> | ||
| 20 | #include <linux/string.h> | 21 | #include <linux/string.h> |
| 21 | #include <linux/i2c.h> | 22 | #include <linux/i2c.h> |
| 22 | #include <linux/rtc.h> | 23 | #include <linux/rtc.h> |
| @@ -655,12 +656,16 @@ static int wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | |||
| 655 | static int wdt_open(struct inode *inode, struct file *file) | 656 | static int wdt_open(struct inode *inode, struct file *file) |
| 656 | { | 657 | { |
| 657 | if (MINOR(inode->i_rdev) == WATCHDOG_MINOR) { | 658 | if (MINOR(inode->i_rdev) == WATCHDOG_MINOR) { |
| 658 | if (test_and_set_bit(0, &wdt_is_open)) | 659 | lock_kernel(); |
| 660 | if (test_and_set_bit(0, &wdt_is_open)) { | ||
| 661 | unlock_kernel(); | ||
| 659 | return -EBUSY; | 662 | return -EBUSY; |
| 663 | } | ||
| 660 | /* | 664 | /* |
| 661 | * Activate | 665 | * Activate |
| 662 | */ | 666 | */ |
| 663 | wdt_is_open = 1; | 667 | wdt_is_open = 1; |
| 668 | unlock_kernel(); | ||
| 664 | return 0; | 669 | return 0; |
| 665 | } | 670 | } |
| 666 | return -ENODEV; | 671 | return -ENODEV; |
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c index 58f81c774943..eb23d8423f42 100644 --- a/drivers/rtc/rtc-omap.c +++ b/drivers/rtc/rtc-omap.c | |||
| @@ -22,7 +22,6 @@ | |||
| 22 | #include <linux/platform_device.h> | 22 | #include <linux/platform_device.h> |
| 23 | 23 | ||
| 24 | #include <asm/io.h> | 24 | #include <asm/io.h> |
| 25 | #include <asm/mach/time.h> | ||
| 26 | 25 | ||
| 27 | 26 | ||
| 28 | /* The OMAP1 RTC is a year/month/day/hours/minutes/seconds BCD clock | 27 | /* The OMAP1 RTC is a year/month/day/hours/minutes/seconds BCD clock |
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c index 0fc4c3630780..748a502a6355 100644 --- a/drivers/rtc/rtc-pcf8563.c +++ b/drivers/rtc/rtc-pcf8563.c | |||
| @@ -302,6 +302,7 @@ static int pcf8563_remove(struct i2c_client *client) | |||
| 302 | 302 | ||
| 303 | static const struct i2c_device_id pcf8563_id[] = { | 303 | static const struct i2c_device_id pcf8563_id[] = { |
| 304 | { "pcf8563", 0 }, | 304 | { "pcf8563", 0 }, |
| 305 | { "rtc8564", 0 }, | ||
| 305 | { } | 306 | { } |
| 306 | }; | 307 | }; |
| 307 | MODULE_DEVICE_TABLE(i2c, pcf8563_id); | 308 | MODULE_DEVICE_TABLE(i2c, pcf8563_id); |
diff --git a/drivers/rtc/rtc-pl030.c b/drivers/rtc/rtc-pl030.c new file mode 100644 index 000000000000..8448eeb9d675 --- /dev/null +++ b/drivers/rtc/rtc-pl030.c | |||
| @@ -0,0 +1,217 @@ | |||
| 1 | /* | ||
| 2 | * linux/drivers/rtc/rtc-pl030.c | ||
| 3 | * | ||
| 4 | * Copyright (C) 2000-2001 Deep Blue Solutions Ltd. | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License version 2 as | ||
| 8 | * published by the Free Software Foundation. | ||
| 9 | */ | ||
| 10 | #include <linux/module.h> | ||
| 11 | #include <linux/rtc.h> | ||
| 12 | #include <linux/init.h> | ||
| 13 | #include <linux/interrupt.h> | ||
| 14 | #include <linux/amba/bus.h> | ||
| 15 | #include <linux/io.h> | ||
| 16 | |||
| 17 | #define RTC_DR (0) | ||
| 18 | #define RTC_MR (4) | ||
| 19 | #define RTC_STAT (8) | ||
| 20 | #define RTC_EOI (8) | ||
| 21 | #define RTC_LR (12) | ||
| 22 | #define RTC_CR (16) | ||
| 23 | #define RTC_CR_MIE (1 << 0) | ||
| 24 | |||
| 25 | struct pl030_rtc { | ||
| 26 | struct rtc_device *rtc; | ||
| 27 | void __iomem *base; | ||
| 28 | }; | ||
| 29 | |||
| 30 | static irqreturn_t pl030_interrupt(int irq, void *dev_id) | ||
| 31 | { | ||
| 32 | struct pl030_rtc *rtc = dev_id; | ||
| 33 | writel(0, rtc->base + RTC_EOI); | ||
| 34 | return IRQ_HANDLED; | ||
| 35 | } | ||
| 36 | |||
| 37 | static int pl030_open(struct device *dev) | ||
| 38 | { | ||
| 39 | return 0; | ||
| 40 | } | ||
| 41 | |||
| 42 | static void pl030_release(struct device *dev) | ||
| 43 | { | ||
| 44 | } | ||
| 45 | |||
| 46 | static int pl030_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) | ||
| 47 | { | ||
| 48 | return -ENOIOCTLCMD; | ||
| 49 | } | ||
| 50 | |||
| 51 | static int pl030_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | ||
| 52 | { | ||
| 53 | struct pl030_rtc *rtc = dev_get_drvdata(dev); | ||
| 54 | |||
| 55 | rtc_time_to_tm(readl(rtc->base + RTC_MR), &alrm->time); | ||
| 56 | return 0; | ||
| 57 | } | ||
| 58 | |||
| 59 | static int pl030_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | ||
| 60 | { | ||
| 61 | struct pl030_rtc *rtc = dev_get_drvdata(dev); | ||
| 62 | unsigned long time; | ||
| 63 | int ret; | ||
| 64 | |||
| 65 | /* | ||
| 66 | * At the moment, we can only deal with non-wildcarded alarm times. | ||
| 67 | */ | ||
| 68 | ret = rtc_valid_tm(&alrm->time); | ||
| 69 | if (ret == 0) | ||
| 70 | ret = rtc_tm_to_time(&alrm->time, &time); | ||
| 71 | if (ret == 0) | ||
| 72 | writel(time, rtc->base + RTC_MR); | ||
| 73 | return ret; | ||
| 74 | } | ||
| 75 | |||
| 76 | static int pl030_read_time(struct device *dev, struct rtc_time *tm) | ||
| 77 | { | ||
| 78 | struct pl030_rtc *rtc = dev_get_drvdata(dev); | ||
| 79 | |||
| 80 | rtc_time_to_tm(readl(rtc->base + RTC_DR), tm); | ||
| 81 | |||
| 82 | return 0; | ||
| 83 | } | ||
| 84 | |||
| 85 | /* | ||
| 86 | * Set the RTC time. Unfortunately, we can't accurately set | ||
| 87 | * the point at which the counter updates. | ||
| 88 | * | ||
| 89 | * Also, since RTC_LR is transferred to RTC_CR on next rising | ||
| 90 | * edge of the 1Hz clock, we must write the time one second | ||
| 91 | * in advance. | ||
| 92 | */ | ||
| 93 | static int pl030_set_time(struct device *dev, struct rtc_time *tm) | ||
| 94 | { | ||
| 95 | struct pl030_rtc *rtc = dev_get_drvdata(dev); | ||
| 96 | unsigned long time; | ||
| 97 | int ret; | ||
| 98 | |||
| 99 | ret = rtc_tm_to_time(tm, &time); | ||
| 100 | if (ret == 0) | ||
| 101 | writel(time + 1, rtc->base + RTC_LR); | ||
| 102 | |||
| 103 | return ret; | ||
| 104 | } | ||
| 105 | |||
| 106 | static const struct rtc_class_ops pl030_ops = { | ||
| 107 | .open = pl030_open, | ||
| 108 | .release = pl030_release, | ||
| 109 | .ioctl = pl030_ioctl, | ||
| 110 | .read_time = pl030_read_time, | ||
| 111 | .set_time = pl030_set_time, | ||
| 112 | .read_alarm = pl030_read_alarm, | ||
| 113 | .set_alarm = pl030_set_alarm, | ||
| 114 | }; | ||
| 115 | |||
| 116 | static int pl030_probe(struct amba_device *dev, void *id) | ||
| 117 | { | ||
| 118 | struct pl030_rtc *rtc; | ||
| 119 | int ret; | ||
| 120 | |||
| 121 | ret = amba_request_regions(dev, NULL); | ||
| 122 | if (ret) | ||
| 123 | goto err_req; | ||
| 124 | |||
| 125 | rtc = kmalloc(sizeof(*rtc), GFP_KERNEL); | ||
| 126 | if (!rtc) { | ||
| 127 | ret = -ENOMEM; | ||
| 128 | goto err_rtc; | ||
| 129 | } | ||
| 130 | |||
| 131 | rtc->base = ioremap(dev->res.start, SZ_4K); | ||
| 132 | if (!rtc->base) { | ||
| 133 | ret = -ENOMEM; | ||
| 134 | goto err_map; | ||
| 135 | } | ||
| 136 | |||
| 137 | __raw_writel(0, rtc->base + RTC_CR); | ||
| 138 | __raw_writel(0, rtc->base + RTC_EOI); | ||
| 139 | |||
| 140 | amba_set_drvdata(dev, rtc); | ||
| 141 | |||
| 142 | ret = request_irq(dev->irq[0], pl030_interrupt, IRQF_DISABLED, | ||
| 143 | "rtc-pl030", rtc); | ||
| 144 | if (ret) | ||
| 145 | goto err_irq; | ||
| 146 | |||
| 147 | rtc->rtc = rtc_device_register("pl030", &dev->dev, &pl030_ops, | ||
| 148 | THIS_MODULE); | ||
| 149 | if (IS_ERR(rtc->rtc)) { | ||
| 150 | ret = PTR_ERR(rtc->rtc); | ||
| 151 | goto err_reg; | ||
| 152 | } | ||
| 153 | |||
| 154 | return 0; | ||
| 155 | |||
| 156 | err_reg: | ||
| 157 | free_irq(dev->irq[0], rtc); | ||
| 158 | err_irq: | ||
| 159 | iounmap(rtc->base); | ||
| 160 | err_map: | ||
| 161 | kfree(rtc); | ||
| 162 | err_rtc: | ||
| 163 | amba_release_regions(dev); | ||
| 164 | err_req: | ||
| 165 | return ret; | ||
| 166 | } | ||
| 167 | |||
| 168 | static int pl030_remove(struct amba_device *dev) | ||
| 169 | { | ||
| 170 | struct pl030_rtc *rtc = amba_get_drvdata(dev); | ||
| 171 | |||
| 172 | amba_set_drvdata(dev, NULL); | ||
| 173 | |||
| 174 | writel(0, rtc->base + RTC_CR); | ||
| 175 | |||
| 176 | free_irq(dev->irq[0], rtc); | ||
| 177 | rtc_device_unregister(rtc->rtc); | ||
| 178 | iounmap(rtc->base); | ||
| 179 | kfree(rtc); | ||
| 180 | amba_release_regions(dev); | ||
| 181 | |||
| 182 | return 0; | ||
| 183 | } | ||
| 184 | |||
| 185 | static struct amba_id pl030_ids[] = { | ||
| 186 | { | ||
| 187 | .id = 0x00041030, | ||
| 188 | .mask = 0x000fffff, | ||
| 189 | }, | ||
| 190 | { 0, 0 }, | ||
| 191 | }; | ||
| 192 | |||
| 193 | static struct amba_driver pl030_driver = { | ||
| 194 | .drv = { | ||
| 195 | .name = "rtc-pl030", | ||
| 196 | }, | ||
| 197 | .probe = pl030_probe, | ||
| 198 | .remove = pl030_remove, | ||
| 199 | .id_table = pl030_ids, | ||
| 200 | }; | ||
| 201 | |||
| 202 | static int __init pl030_init(void) | ||
| 203 | { | ||
| 204 | return amba_driver_register(&pl030_driver); | ||
| 205 | } | ||
| 206 | |||
| 207 | static void __exit pl030_exit(void) | ||
| 208 | { | ||
| 209 | amba_driver_unregister(&pl030_driver); | ||
| 210 | } | ||
| 211 | |||
| 212 | module_init(pl030_init); | ||
| 213 | module_exit(pl030_exit); | ||
| 214 | |||
| 215 | MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>"); | ||
| 216 | MODULE_DESCRIPTION("ARM AMBA PL030 RTC Driver"); | ||
| 217 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/rtc/rtc-pl031.c b/drivers/rtc/rtc-pl031.c index 2fd49edcc712..08b4610ec5a6 100644 --- a/drivers/rtc/rtc-pl031.c +++ b/drivers/rtc/rtc-pl031.c | |||
| @@ -12,23 +12,12 @@ | |||
| 12 | * as published by the Free Software Foundation; either version | 12 | * as published by the Free Software Foundation; either version |
| 13 | * 2 of the License, or (at your option) any later version. | 13 | * 2 of the License, or (at your option) any later version. |
| 14 | */ | 14 | */ |
| 15 | |||
| 16 | #include <linux/platform_device.h> | ||
| 17 | #include <linux/module.h> | 15 | #include <linux/module.h> |
| 18 | #include <linux/rtc.h> | 16 | #include <linux/rtc.h> |
| 19 | #include <linux/init.h> | 17 | #include <linux/init.h> |
| 20 | #include <linux/fs.h> | ||
| 21 | #include <linux/interrupt.h> | 18 | #include <linux/interrupt.h> |
| 22 | #include <linux/string.h> | ||
| 23 | #include <linux/pm.h> | ||
| 24 | #include <linux/bitops.h> | ||
| 25 | |||
| 26 | #include <linux/amba/bus.h> | 19 | #include <linux/amba/bus.h> |
| 27 | 20 | #include <linux/io.h> | |
| 28 | #include <asm/io.h> | ||
| 29 | #include <asm/hardware.h> | ||
| 30 | #include <asm/irq.h> | ||
| 31 | #include <asm/rtc.h> | ||
| 32 | 21 | ||
| 33 | /* | 22 | /* |
| 34 | * Register definitions | 23 | * Register definitions |
| @@ -142,13 +131,12 @@ static int pl031_remove(struct amba_device *adev) | |||
| 142 | { | 131 | { |
| 143 | struct pl031_local *ldata = dev_get_drvdata(&adev->dev); | 132 | struct pl031_local *ldata = dev_get_drvdata(&adev->dev); |
| 144 | 133 | ||
| 145 | if (ldata) { | 134 | amba_set_drvdata(adev, NULL); |
| 146 | dev_set_drvdata(&adev->dev, NULL); | 135 | free_irq(adev->irq[0], ldata->rtc); |
| 147 | free_irq(adev->irq[0], ldata->rtc); | 136 | rtc_device_unregister(ldata->rtc); |
| 148 | rtc_device_unregister(ldata->rtc); | 137 | iounmap(ldata->base); |
| 149 | iounmap(ldata->base); | 138 | kfree(ldata); |
| 150 | kfree(ldata); | 139 | amba_release_regions(adev); |
| 151 | } | ||
| 152 | 140 | ||
| 153 | return 0; | 141 | return 0; |
| 154 | } | 142 | } |
| @@ -158,13 +146,15 @@ static int pl031_probe(struct amba_device *adev, void *id) | |||
| 158 | int ret; | 146 | int ret; |
| 159 | struct pl031_local *ldata; | 147 | struct pl031_local *ldata; |
| 160 | 148 | ||
| 149 | ret = amba_request_regions(adev, NULL); | ||
| 150 | if (ret) | ||
| 151 | goto err_req; | ||
| 161 | 152 | ||
| 162 | ldata = kmalloc(sizeof(struct pl031_local), GFP_KERNEL); | 153 | ldata = kmalloc(sizeof(struct pl031_local), GFP_KERNEL); |
| 163 | if (!ldata) { | 154 | if (!ldata) { |
| 164 | ret = -ENOMEM; | 155 | ret = -ENOMEM; |
| 165 | goto out; | 156 | goto out; |
| 166 | } | 157 | } |
| 167 | dev_set_drvdata(&adev->dev, ldata); | ||
| 168 | 158 | ||
| 169 | ldata->base = ioremap(adev->res.start, | 159 | ldata->base = ioremap(adev->res.start, |
| 170 | adev->res.end - adev->res.start + 1); | 160 | adev->res.end - adev->res.start + 1); |
| @@ -173,6 +163,8 @@ static int pl031_probe(struct amba_device *adev, void *id) | |||
| 173 | goto out_no_remap; | 163 | goto out_no_remap; |
| 174 | } | 164 | } |
| 175 | 165 | ||
| 166 | amba_set_drvdata(adev, ldata); | ||
| 167 | |||
| 176 | if (request_irq(adev->irq[0], pl031_interrupt, IRQF_DISABLED, | 168 | if (request_irq(adev->irq[0], pl031_interrupt, IRQF_DISABLED, |
| 177 | "rtc-pl031", ldata->rtc)) { | 169 | "rtc-pl031", ldata->rtc)) { |
| 178 | ret = -EIO; | 170 | ret = -EIO; |
| @@ -192,10 +184,12 @@ out_no_rtc: | |||
| 192 | free_irq(adev->irq[0], ldata->rtc); | 184 | free_irq(adev->irq[0], ldata->rtc); |
| 193 | out_no_irq: | 185 | out_no_irq: |
| 194 | iounmap(ldata->base); | 186 | iounmap(ldata->base); |
| 187 | amba_set_drvdata(adev, NULL); | ||
| 195 | out_no_remap: | 188 | out_no_remap: |
| 196 | dev_set_drvdata(&adev->dev, NULL); | ||
| 197 | kfree(ldata); | 189 | kfree(ldata); |
| 198 | out: | 190 | out: |
| 191 | amba_release_regions(adev); | ||
| 192 | err_req: | ||
| 199 | return ret; | 193 | return ret; |
| 200 | } | 194 | } |
| 201 | 195 | ||
diff --git a/drivers/rtc/rtc-ppc.c b/drivers/rtc/rtc-ppc.c new file mode 100644 index 000000000000..c8e97e25ef7e --- /dev/null +++ b/drivers/rtc/rtc-ppc.c | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | /* | ||
| 2 | * RTC driver for ppc_md RTC functions | ||
| 3 | * | ||
| 4 | * © 2007 Red Hat, Inc. | ||
| 5 | * | ||
| 6 | * Author: David Woodhouse <dwmw2@infradead.org> | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify | ||
| 9 | * it under the terms of the GNU General Public License version 2 as | ||
| 10 | * published by the Free Software Foundation. | ||
| 11 | */ | ||
| 12 | |||
| 13 | |||
| 14 | #include <linux/module.h> | ||
| 15 | #include <linux/err.h> | ||
| 16 | #include <linux/rtc.h> | ||
| 17 | #include <linux/platform_device.h> | ||
| 18 | #include <asm/machdep.h> | ||
| 19 | |||
| 20 | static int ppc_rtc_read_time(struct device *dev, struct rtc_time *tm) | ||
| 21 | { | ||
| 22 | ppc_md.get_rtc_time(tm); | ||
| 23 | return 0; | ||
| 24 | } | ||
| 25 | |||
| 26 | static int ppc_rtc_set_time(struct device *dev, struct rtc_time *tm) | ||
| 27 | { | ||
| 28 | return ppc_md.set_rtc_time(tm); | ||
| 29 | } | ||
| 30 | |||
| 31 | static const struct rtc_class_ops ppc_rtc_ops = { | ||
| 32 | .set_time = ppc_rtc_set_time, | ||
| 33 | .read_time = ppc_rtc_read_time, | ||
| 34 | }; | ||
| 35 | |||
| 36 | static struct rtc_device *rtc; | ||
| 37 | static struct platform_device *ppc_rtc_pdev; | ||
| 38 | |||
| 39 | static int __init ppc_rtc_init(void) | ||
| 40 | { | ||
| 41 | if (!ppc_md.get_rtc_time || !ppc_md.set_rtc_time) | ||
| 42 | return -ENODEV; | ||
| 43 | |||
| 44 | ppc_rtc_pdev = platform_device_register_simple("ppc-rtc", 0, NULL, 0); | ||
| 45 | if (IS_ERR(ppc_rtc_pdev)) | ||
| 46 | return PTR_ERR(ppc_rtc_pdev); | ||
| 47 | |||
| 48 | rtc = rtc_device_register("ppc_md", &ppc_rtc_pdev->dev, | ||
| 49 | &ppc_rtc_ops, THIS_MODULE); | ||
| 50 | if (IS_ERR(rtc)) { | ||
| 51 | platform_device_unregister(ppc_rtc_pdev); | ||
| 52 | return PTR_ERR(rtc); | ||
| 53 | } | ||
| 54 | |||
| 55 | return 0; | ||
| 56 | } | ||
| 57 | |||
| 58 | static void __exit ppc_rtc_exit(void) | ||
| 59 | { | ||
| 60 | rtc_device_unregister(rtc); | ||
| 61 | platform_device_unregister(ppc_rtc_pdev); | ||
| 62 | } | ||
| 63 | |||
| 64 | module_init(ppc_rtc_init); | ||
| 65 | module_exit(ppc_rtc_exit); | ||
| 66 | |||
| 67 | MODULE_LICENSE("GPL"); | ||
| 68 | MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); | ||
| 69 | MODULE_DESCRIPTION("Generic RTC class driver for PowerPC"); | ||
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c index f26e0cad8f16..fed86e507fdf 100644 --- a/drivers/rtc/rtc-s3c.c +++ b/drivers/rtc/rtc-s3c.c | |||
| @@ -26,10 +26,6 @@ | |||
| 26 | #include <asm/uaccess.h> | 26 | #include <asm/uaccess.h> |
| 27 | #include <asm/io.h> | 27 | #include <asm/io.h> |
| 28 | #include <asm/irq.h> | 28 | #include <asm/irq.h> |
| 29 | #include <asm/rtc.h> | ||
| 30 | |||
| 31 | #include <asm/mach/time.h> | ||
| 32 | |||
| 33 | #include <asm/plat-s3c/regs-rtc.h> | 29 | #include <asm/plat-s3c/regs-rtc.h> |
| 34 | 30 | ||
| 35 | /* I have yet to find an S3C implementation with more than one | 31 | /* I have yet to find an S3C implementation with more than one |
diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c index 82f62d25f921..f47294c60148 100644 --- a/drivers/rtc/rtc-sa1100.c +++ b/drivers/rtc/rtc-sa1100.c | |||
| @@ -33,7 +33,6 @@ | |||
| 33 | 33 | ||
| 34 | #include <asm/hardware.h> | 34 | #include <asm/hardware.h> |
| 35 | #include <asm/irq.h> | 35 | #include <asm/irq.h> |
| 36 | #include <asm/rtc.h> | ||
| 37 | 36 | ||
| 38 | #ifdef CONFIG_ARCH_PXA | 37 | #ifdef CONFIG_ARCH_PXA |
| 39 | #include <asm/arch/pxa-regs.h> | 38 | #include <asm/arch/pxa-regs.h> |
| @@ -47,6 +46,42 @@ static unsigned long rtc_freq = 1024; | |||
| 47 | static struct rtc_time rtc_alarm; | 46 | static struct rtc_time rtc_alarm; |
| 48 | static DEFINE_SPINLOCK(sa1100_rtc_lock); | 47 | static DEFINE_SPINLOCK(sa1100_rtc_lock); |
| 49 | 48 | ||
| 49 | static inline int rtc_periodic_alarm(struct rtc_time *tm) | ||
| 50 | { | ||
| 51 | return (tm->tm_year == -1) || | ||
| 52 | ((unsigned)tm->tm_mon >= 12) || | ||
| 53 | ((unsigned)(tm->tm_mday - 1) >= 31) || | ||
| 54 | ((unsigned)tm->tm_hour > 23) || | ||
| 55 | ((unsigned)tm->tm_min > 59) || | ||
| 56 | ((unsigned)tm->tm_sec > 59); | ||
| 57 | } | ||
| 58 | |||
| 59 | /* | ||
| 60 | * Calculate the next alarm time given the requested alarm time mask | ||
| 61 | * and the current time. | ||
| 62 | */ | ||
| 63 | static void rtc_next_alarm_time(struct rtc_time *next, struct rtc_time *now, struct rtc_time *alrm) | ||
| 64 | { | ||
| 65 | unsigned long next_time; | ||
| 66 | unsigned long now_time; | ||
| 67 | |||
| 68 | next->tm_year = now->tm_year; | ||
| 69 | next->tm_mon = now->tm_mon; | ||
| 70 | next->tm_mday = now->tm_mday; | ||
| 71 | next->tm_hour = alrm->tm_hour; | ||
| 72 | next->tm_min = alrm->tm_min; | ||
| 73 | next->tm_sec = alrm->tm_sec; | ||
| 74 | |||
| 75 | rtc_tm_to_time(now, &now_time); | ||
| 76 | rtc_tm_to_time(next, &next_time); | ||
| 77 | |||
| 78 | if (next_time < now_time) { | ||
| 79 | /* Advance one day */ | ||
| 80 | next_time += 60 * 60 * 24; | ||
| 81 | rtc_time_to_tm(next_time, next); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 50 | static int rtc_update_alarm(struct rtc_time *alrm) | 85 | static int rtc_update_alarm(struct rtc_time *alrm) |
| 51 | { | 86 | { |
| 52 | struct rtc_time alarm_tm, now_tm; | 87 | struct rtc_time alarm_tm, now_tm; |
| @@ -331,14 +366,14 @@ static int sa1100_rtc_probe(struct platform_device *pdev) | |||
| 331 | RCNR = 0; | 366 | RCNR = 0; |
| 332 | } | 367 | } |
| 333 | 368 | ||
| 369 | device_init_wakeup(&pdev->dev, 1); | ||
| 370 | |||
| 334 | rtc = rtc_device_register(pdev->name, &pdev->dev, &sa1100_rtc_ops, | 371 | rtc = rtc_device_register(pdev->name, &pdev->dev, &sa1100_rtc_ops, |
| 335 | THIS_MODULE); | 372 | THIS_MODULE); |
| 336 | 373 | ||
| 337 | if (IS_ERR(rtc)) | 374 | if (IS_ERR(rtc)) |
| 338 | return PTR_ERR(rtc); | 375 | return PTR_ERR(rtc); |
| 339 | 376 | ||
| 340 | device_init_wakeup(&pdev->dev, 1); | ||
| 341 | |||
| 342 | platform_set_drvdata(pdev, rtc); | 377 | platform_set_drvdata(pdev, rtc); |
| 343 | 378 | ||
| 344 | return 0; | 379 | return 0; |
diff --git a/drivers/rtc/rtc-x1205.c b/drivers/rtc/rtc-x1205.c index eaf55945f21b..7dcfba1bbfe1 100644 --- a/drivers/rtc/rtc-x1205.c +++ b/drivers/rtc/rtc-x1205.c | |||
| @@ -71,6 +71,7 @@ | |||
| 71 | #define X1205_SR_RTCF 0x01 /* Clock failure */ | 71 | #define X1205_SR_RTCF 0x01 /* Clock failure */ |
| 72 | #define X1205_SR_WEL 0x02 /* Write Enable Latch */ | 72 | #define X1205_SR_WEL 0x02 /* Write Enable Latch */ |
| 73 | #define X1205_SR_RWEL 0x04 /* Register Write Enable */ | 73 | #define X1205_SR_RWEL 0x04 /* Register Write Enable */ |
| 74 | #define X1205_SR_AL0 0x20 /* Alarm 0 match */ | ||
| 74 | 75 | ||
| 75 | #define X1205_DTR_DTR0 0x01 | 76 | #define X1205_DTR_DTR0 0x01 |
| 76 | #define X1205_DTR_DTR1 0x02 | 77 | #define X1205_DTR_DTR1 0x02 |
| @@ -78,6 +79,8 @@ | |||
| 78 | 79 | ||
| 79 | #define X1205_HR_MIL 0x80 /* Set in ccr.hour for 24 hr mode */ | 80 | #define X1205_HR_MIL 0x80 /* Set in ccr.hour for 24 hr mode */ |
| 80 | 81 | ||
| 82 | #define X1205_INT_AL0E 0x20 /* Alarm 0 enable */ | ||
| 83 | |||
| 81 | static struct i2c_driver x1205_driver; | 84 | static struct i2c_driver x1205_driver; |
| 82 | 85 | ||
| 83 | /* | 86 | /* |
| @@ -89,8 +92,8 @@ static int x1205_get_datetime(struct i2c_client *client, struct rtc_time *tm, | |||
| 89 | unsigned char reg_base) | 92 | unsigned char reg_base) |
| 90 | { | 93 | { |
| 91 | unsigned char dt_addr[2] = { 0, reg_base }; | 94 | unsigned char dt_addr[2] = { 0, reg_base }; |
| 92 | |||
| 93 | unsigned char buf[8]; | 95 | unsigned char buf[8]; |
| 96 | int i; | ||
| 94 | 97 | ||
| 95 | struct i2c_msg msgs[] = { | 98 | struct i2c_msg msgs[] = { |
| 96 | { client->addr, 0, 2, dt_addr }, /* setup read ptr */ | 99 | { client->addr, 0, 2, dt_addr }, /* setup read ptr */ |
| @@ -98,7 +101,7 @@ static int x1205_get_datetime(struct i2c_client *client, struct rtc_time *tm, | |||
| 98 | }; | 101 | }; |
| 99 | 102 | ||
| 100 | /* read date registers */ | 103 | /* read date registers */ |
| 101 | if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { | 104 | if (i2c_transfer(client->adapter, &msgs[0], 2) != 2) { |
| 102 | dev_err(&client->dev, "%s: read error\n", __func__); | 105 | dev_err(&client->dev, "%s: read error\n", __func__); |
| 103 | return -EIO; | 106 | return -EIO; |
| 104 | } | 107 | } |
| @@ -110,6 +113,11 @@ static int x1205_get_datetime(struct i2c_client *client, struct rtc_time *tm, | |||
| 110 | buf[0], buf[1], buf[2], buf[3], | 113 | buf[0], buf[1], buf[2], buf[3], |
| 111 | buf[4], buf[5], buf[6], buf[7]); | 114 | buf[4], buf[5], buf[6], buf[7]); |
| 112 | 115 | ||
| 116 | /* Mask out the enable bits if these are alarm registers */ | ||
| 117 | if (reg_base < X1205_CCR_BASE) | ||
| 118 | for (i = 0; i <= 4; i++) | ||
| 119 | buf[i] &= 0x7F; | ||
| 120 | |||
| 113 | tm->tm_sec = BCD2BIN(buf[CCR_SEC]); | 121 | tm->tm_sec = BCD2BIN(buf[CCR_SEC]); |
| 114 | tm->tm_min = BCD2BIN(buf[CCR_MIN]); | 122 | tm->tm_min = BCD2BIN(buf[CCR_MIN]); |
| 115 | tm->tm_hour = BCD2BIN(buf[CCR_HOUR] & 0x3F); /* hr is 0-23 */ | 123 | tm->tm_hour = BCD2BIN(buf[CCR_HOUR] & 0x3F); /* hr is 0-23 */ |
| @@ -138,7 +146,7 @@ static int x1205_get_status(struct i2c_client *client, unsigned char *sr) | |||
| 138 | }; | 146 | }; |
| 139 | 147 | ||
| 140 | /* read status register */ | 148 | /* read status register */ |
| 141 | if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { | 149 | if (i2c_transfer(client->adapter, &msgs[0], 2) != 2) { |
| 142 | dev_err(&client->dev, "%s: read error\n", __func__); | 150 | dev_err(&client->dev, "%s: read error\n", __func__); |
| 143 | return -EIO; | 151 | return -EIO; |
| 144 | } | 152 | } |
| @@ -147,10 +155,11 @@ static int x1205_get_status(struct i2c_client *client, unsigned char *sr) | |||
| 147 | } | 155 | } |
| 148 | 156 | ||
| 149 | static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm, | 157 | static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm, |
| 150 | int datetoo, u8 reg_base) | 158 | int datetoo, u8 reg_base, unsigned char alm_enable) |
| 151 | { | 159 | { |
| 152 | int i, xfer; | 160 | int i, xfer, nbytes; |
| 153 | unsigned char buf[8]; | 161 | unsigned char buf[8]; |
| 162 | unsigned char rdata[10] = { 0, reg_base }; | ||
| 154 | 163 | ||
| 155 | static const unsigned char wel[3] = { 0, X1205_REG_SR, | 164 | static const unsigned char wel[3] = { 0, X1205_REG_SR, |
| 156 | X1205_SR_WEL }; | 165 | X1205_SR_WEL }; |
| @@ -189,6 +198,11 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm, | |||
| 189 | buf[CCR_Y2K] = BIN2BCD(tm->tm_year / 100); | 198 | buf[CCR_Y2K] = BIN2BCD(tm->tm_year / 100); |
| 190 | } | 199 | } |
| 191 | 200 | ||
| 201 | /* If writing alarm registers, set compare bits on registers 0-4 */ | ||
| 202 | if (reg_base < X1205_CCR_BASE) | ||
| 203 | for (i = 0; i <= 4; i++) | ||
| 204 | buf[i] |= 0x80; | ||
| 205 | |||
| 192 | /* this sequence is required to unlock the chip */ | 206 | /* this sequence is required to unlock the chip */ |
| 193 | if ((xfer = i2c_master_send(client, wel, 3)) != 3) { | 207 | if ((xfer = i2c_master_send(client, wel, 3)) != 3) { |
| 194 | dev_err(&client->dev, "%s: wel - %d\n", __func__, xfer); | 208 | dev_err(&client->dev, "%s: wel - %d\n", __func__, xfer); |
| @@ -200,19 +214,57 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm, | |||
| 200 | return -EIO; | 214 | return -EIO; |
| 201 | } | 215 | } |
| 202 | 216 | ||
| 217 | |||
| 203 | /* write register's data */ | 218 | /* write register's data */ |
| 204 | for (i = 0; i < (datetoo ? 8 : 3); i++) { | 219 | if (datetoo) |
| 205 | unsigned char rdata[3] = { 0, reg_base + i, buf[i] }; | 220 | nbytes = 8; |
| 221 | else | ||
| 222 | nbytes = 3; | ||
| 223 | for (i = 0; i < nbytes; i++) | ||
| 224 | rdata[2+i] = buf[i]; | ||
| 225 | |||
| 226 | xfer = i2c_master_send(client, rdata, nbytes+2); | ||
| 227 | if (xfer != nbytes+2) { | ||
| 228 | dev_err(&client->dev, | ||
| 229 | "%s: result=%d addr=%02x, data=%02x\n", | ||
| 230 | __func__, | ||
| 231 | xfer, rdata[1], rdata[2]); | ||
| 232 | return -EIO; | ||
| 233 | } | ||
| 234 | |||
| 235 | /* If we wrote to the nonvolatile region, wait 10msec for write cycle*/ | ||
| 236 | if (reg_base < X1205_CCR_BASE) { | ||
| 237 | unsigned char al0e[3] = { 0, X1205_REG_INT, 0 }; | ||
| 238 | |||
| 239 | msleep(10); | ||
| 206 | 240 | ||
| 207 | xfer = i2c_master_send(client, rdata, 3); | 241 | /* ...and set or clear the AL0E bit in the INT register */ |
| 242 | |||
| 243 | /* Need to set RWEL again as the write has cleared it */ | ||
| 244 | xfer = i2c_master_send(client, rwel, 3); | ||
| 208 | if (xfer != 3) { | 245 | if (xfer != 3) { |
| 209 | dev_err(&client->dev, | 246 | dev_err(&client->dev, |
| 210 | "%s: xfer=%d addr=%02x, data=%02x\n", | 247 | "%s: aloe rwel - %d\n", |
| 211 | __func__, | 248 | __func__, |
| 212 | xfer, rdata[1], rdata[2]); | 249 | xfer); |
| 250 | return -EIO; | ||
| 251 | } | ||
| 252 | |||
| 253 | if (alm_enable) | ||
| 254 | al0e[2] = X1205_INT_AL0E; | ||
| 255 | |||
| 256 | xfer = i2c_master_send(client, al0e, 3); | ||
| 257 | if (xfer != 3) { | ||
| 258 | dev_err(&client->dev, | ||
| 259 | "%s: al0e - %d\n", | ||
| 260 | __func__, | ||
| 261 | xfer); | ||
| 213 | return -EIO; | 262 | return -EIO; |
| 214 | } | 263 | } |
| 215 | }; | 264 | |
| 265 | /* and wait 10msec again for this write to complete */ | ||
| 266 | msleep(10); | ||
| 267 | } | ||
| 216 | 268 | ||
| 217 | /* disable further writes */ | 269 | /* disable further writes */ |
| 218 | if ((xfer = i2c_master_send(client, diswe, 3)) != 3) { | 270 | if ((xfer = i2c_master_send(client, diswe, 3)) != 3) { |
| @@ -230,9 +282,9 @@ static int x1205_fix_osc(struct i2c_client *client) | |||
| 230 | 282 | ||
| 231 | tm.tm_hour = tm.tm_min = tm.tm_sec = 0; | 283 | tm.tm_hour = tm.tm_min = tm.tm_sec = 0; |
| 232 | 284 | ||
| 233 | if ((err = x1205_set_datetime(client, &tm, 0, X1205_CCR_BASE)) < 0) | 285 | err = x1205_set_datetime(client, &tm, 0, X1205_CCR_BASE, 0); |
| 234 | dev_err(&client->dev, | 286 | if (err < 0) |
| 235 | "unable to restart the oscillator\n"); | 287 | dev_err(&client->dev, "unable to restart the oscillator\n"); |
| 236 | 288 | ||
| 237 | return err; | 289 | return err; |
| 238 | } | 290 | } |
| @@ -248,7 +300,7 @@ static int x1205_get_dtrim(struct i2c_client *client, int *trim) | |||
| 248 | }; | 300 | }; |
| 249 | 301 | ||
| 250 | /* read dtr register */ | 302 | /* read dtr register */ |
| 251 | if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { | 303 | if (i2c_transfer(client->adapter, &msgs[0], 2) != 2) { |
| 252 | dev_err(&client->dev, "%s: read error\n", __func__); | 304 | dev_err(&client->dev, "%s: read error\n", __func__); |
| 253 | return -EIO; | 305 | return -EIO; |
| 254 | } | 306 | } |
| @@ -280,7 +332,7 @@ static int x1205_get_atrim(struct i2c_client *client, int *trim) | |||
| 280 | }; | 332 | }; |
| 281 | 333 | ||
| 282 | /* read atr register */ | 334 | /* read atr register */ |
| 283 | if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { | 335 | if (i2c_transfer(client->adapter, &msgs[0], 2) != 2) { |
| 284 | dev_err(&client->dev, "%s: read error\n", __func__); | 336 | dev_err(&client->dev, "%s: read error\n", __func__); |
| 285 | return -EIO; | 337 | return -EIO; |
| 286 | } | 338 | } |
| @@ -403,14 +455,33 @@ static int x1205_validate_client(struct i2c_client *client) | |||
| 403 | 455 | ||
| 404 | static int x1205_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | 456 | static int x1205_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
| 405 | { | 457 | { |
| 406 | return x1205_get_datetime(to_i2c_client(dev), | 458 | int err; |
| 407 | &alrm->time, X1205_ALM0_BASE); | 459 | unsigned char intreg, status; |
| 460 | static unsigned char int_addr[2] = { 0, X1205_REG_INT }; | ||
| 461 | struct i2c_client *client = to_i2c_client(dev); | ||
| 462 | struct i2c_msg msgs[] = { | ||
| 463 | { client->addr, 0, 2, int_addr }, /* setup read ptr */ | ||
| 464 | { client->addr, I2C_M_RD, 1, &intreg }, /* read INT register */ | ||
| 465 | }; | ||
| 466 | |||
| 467 | /* read interrupt register and status register */ | ||
| 468 | if (i2c_transfer(client->adapter, &msgs[0], 2) != 2) { | ||
| 469 | dev_err(&client->dev, "%s: read error\n", __func__); | ||
| 470 | return -EIO; | ||
| 471 | } | ||
| 472 | err = x1205_get_status(client, &status); | ||
| 473 | if (err == 0) { | ||
| 474 | alrm->pending = (status & X1205_SR_AL0) ? 1 : 0; | ||
| 475 | alrm->enabled = (intreg & X1205_INT_AL0E) ? 1 : 0; | ||
| 476 | err = x1205_get_datetime(client, &alrm->time, X1205_ALM0_BASE); | ||
| 477 | } | ||
| 478 | return err; | ||
| 408 | } | 479 | } |
| 409 | 480 | ||
| 410 | static int x1205_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | 481 | static int x1205_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
| 411 | { | 482 | { |
| 412 | return x1205_set_datetime(to_i2c_client(dev), | 483 | return x1205_set_datetime(to_i2c_client(dev), |
| 413 | &alrm->time, 1, X1205_ALM0_BASE); | 484 | &alrm->time, 1, X1205_ALM0_BASE, alrm->enabled); |
| 414 | } | 485 | } |
| 415 | 486 | ||
| 416 | static int x1205_rtc_read_time(struct device *dev, struct rtc_time *tm) | 487 | static int x1205_rtc_read_time(struct device *dev, struct rtc_time *tm) |
| @@ -422,7 +493,7 @@ static int x1205_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
| 422 | static int x1205_rtc_set_time(struct device *dev, struct rtc_time *tm) | 493 | static int x1205_rtc_set_time(struct device *dev, struct rtc_time *tm) |
| 423 | { | 494 | { |
| 424 | return x1205_set_datetime(to_i2c_client(dev), | 495 | return x1205_set_datetime(to_i2c_client(dev), |
| 425 | tm, 1, X1205_CCR_BASE); | 496 | tm, 1, X1205_CCR_BASE, 0); |
| 426 | } | 497 | } |
| 427 | 498 | ||
| 428 | static int x1205_rtc_proc(struct device *dev, struct seq_file *seq) | 499 | static int x1205_rtc_proc(struct device *dev, struct seq_file *seq) |
