Lines Matching full:rtc
3 * An rtc driver for the Dallas/Maxim DS1685/DS1687 and related real-time
13 * Application Note 90, Using the Multiplex Bus RTC Extended Features.
23 #include <linux/rtc.h>
26 #include <linux/rtc/ds1685.h>
40 * ds1685_read - read a value from an rtc register.
41 * @rtc: pointer to the ds1685 rtc structure.
45 ds1685_read(struct ds1685_priv *rtc, int reg) in ds1685_read() argument
47 return readb((u8 __iomem *)rtc->regs + in ds1685_read()
48 (reg * rtc->regstep)); in ds1685_read()
52 * ds1685_write - write a value to an rtc register.
53 * @rtc: pointer to the ds1685 rtc structure.
58 ds1685_write(struct ds1685_priv *rtc, int reg, u8 value) in ds1685_write() argument
60 writeb(value, ((u8 __iomem *)rtc->regs + in ds1685_write()
61 (reg * rtc->regstep))); in ds1685_write()
71 * ds1685_indirect_read - read a value from an rtc register.
72 * @rtc: pointer to the ds1685 rtc structure.
76 ds1685_indirect_read(struct ds1685_priv *rtc, int reg) in ds1685_indirect_read() argument
78 writeb(reg, rtc->regs); in ds1685_indirect_read()
79 return readb(rtc->data); in ds1685_indirect_read()
83 * ds1685_indirect_write - write a value to an rtc register.
84 * @rtc: pointer to the ds1685 rtc structure.
89 ds1685_indirect_write(struct ds1685_priv *rtc, int reg, u8 value) in ds1685_indirect_write() argument
91 writeb(reg, rtc->regs); in ds1685_indirect_write()
92 writeb(value, rtc->data); in ds1685_indirect_write()
100 * @rtc: pointer to the ds1685 rtc structure.
108 ds1685_rtc_bcd2bin(struct ds1685_priv *rtc, u8 val, u8 bcd_mask, u8 bin_mask) in ds1685_rtc_bcd2bin() argument
110 if (rtc->bcd_mode) in ds1685_rtc_bcd2bin()
118 * @rtc: pointer to the ds1685 rtc structure.
126 ds1685_rtc_bin2bcd(struct ds1685_priv *rtc, u8 val, u8 bin_mask, u8 bcd_mask) in ds1685_rtc_bin2bcd() argument
128 if (rtc->bcd_mode) in ds1685_rtc_bin2bcd()
136 * @rtc: pointer to the ds1685 rtc structure.
142 ds1685_rtc_check_mday(struct ds1685_priv *rtc, u8 mday) in ds1685_rtc_check_mday() argument
144 if (rtc->bcd_mode) { in ds1685_rtc_check_mday()
155 * ds1685_rtc_switch_to_bank0 - switch the rtc to bank 0.
156 * @rtc: pointer to the ds1685 rtc structure.
159 ds1685_rtc_switch_to_bank0(struct ds1685_priv *rtc) in ds1685_rtc_switch_to_bank0() argument
161 rtc->write(rtc, RTC_CTRL_A, in ds1685_rtc_switch_to_bank0()
162 (rtc->read(rtc, RTC_CTRL_A) & ~(RTC_CTRL_A_DV0))); in ds1685_rtc_switch_to_bank0()
166 * ds1685_rtc_switch_to_bank1 - switch the rtc to bank 1.
167 * @rtc: pointer to the ds1685 rtc structure.
170 ds1685_rtc_switch_to_bank1(struct ds1685_priv *rtc) in ds1685_rtc_switch_to_bank1() argument
172 rtc->write(rtc, RTC_CTRL_A, in ds1685_rtc_switch_to_bank1()
173 (rtc->read(rtc, RTC_CTRL_A) | RTC_CTRL_A_DV0)); in ds1685_rtc_switch_to_bank1()
177 * ds1685_rtc_begin_data_access - prepare the rtc for data access.
178 * @rtc: pointer to the ds1685 rtc structure.
180 * This takes several steps to prepare the rtc for access to get/set time
181 * and alarm values from the rtc registers:
186 * - Switches the rtc to bank 1. This allows access to all relevant
187 * data for normal rtc operation, as bank 0 contains only the nvram.
190 ds1685_rtc_begin_data_access(struct ds1685_priv *rtc) in ds1685_rtc_begin_data_access() argument
193 rtc->write(rtc, RTC_CTRL_B, in ds1685_rtc_begin_data_access()
194 (rtc->read(rtc, RTC_CTRL_B) | RTC_CTRL_B_SET)); in ds1685_rtc_begin_data_access()
197 ds1685_rtc_switch_to_bank1(rtc); in ds1685_rtc_begin_data_access()
200 while (rtc->read(rtc, RTC_EXT_CTRL_4A) & RTC_CTRL_4A_INCR) in ds1685_rtc_begin_data_access()
205 * ds1685_rtc_end_data_access - end data access on the rtc.
206 * @rtc: pointer to the ds1685 rtc structure.
209 * - Switches the rtc back to bank 0.
213 ds1685_rtc_end_data_access(struct ds1685_priv *rtc) in ds1685_rtc_end_data_access() argument
216 ds1685_rtc_switch_to_bank0(rtc); in ds1685_rtc_end_data_access()
219 rtc->write(rtc, RTC_CTRL_B, in ds1685_rtc_end_data_access()
220 (rtc->read(rtc, RTC_CTRL_B) & ~(RTC_CTRL_B_SET))); in ds1685_rtc_end_data_access()
225 * @rtc: pointer to the ds1685 rtc structure.
238 ds1685_rtc_get_ssn(struct ds1685_priv *rtc, u8 *ssn) in ds1685_rtc_get_ssn() argument
240 ssn[0] = rtc->read(rtc, RTC_BANK1_SSN_MODEL); in ds1685_rtc_get_ssn()
241 ssn[1] = rtc->read(rtc, RTC_BANK1_SSN_BYTE_1); in ds1685_rtc_get_ssn()
242 ssn[2] = rtc->read(rtc, RTC_BANK1_SSN_BYTE_2); in ds1685_rtc_get_ssn()
243 ssn[3] = rtc->read(rtc, RTC_BANK1_SSN_BYTE_3); in ds1685_rtc_get_ssn()
244 ssn[4] = rtc->read(rtc, RTC_BANK1_SSN_BYTE_4); in ds1685_rtc_get_ssn()
245 ssn[5] = rtc->read(rtc, RTC_BANK1_SSN_BYTE_5); in ds1685_rtc_get_ssn()
246 ssn[6] = rtc->read(rtc, RTC_BANK1_SSN_BYTE_6); in ds1685_rtc_get_ssn()
247 ssn[7] = rtc->read(rtc, RTC_BANK1_SSN_CRC); in ds1685_rtc_get_ssn()
263 struct ds1685_priv *rtc = dev_get_drvdata(dev); in ds1685_rtc_read_time() local
267 /* Fetch the time info from the RTC registers. */ in ds1685_rtc_read_time()
268 ds1685_rtc_begin_data_access(rtc); in ds1685_rtc_read_time()
269 seconds = rtc->read(rtc, RTC_SECS); in ds1685_rtc_read_time()
270 minutes = rtc->read(rtc, RTC_MINS); in ds1685_rtc_read_time()
271 hours = rtc->read(rtc, RTC_HRS); in ds1685_rtc_read_time()
272 wday = rtc->read(rtc, RTC_WDAY); in ds1685_rtc_read_time()
273 mday = rtc->read(rtc, RTC_MDAY); in ds1685_rtc_read_time()
274 month = rtc->read(rtc, RTC_MONTH); in ds1685_rtc_read_time()
275 years = rtc->read(rtc, RTC_YEAR); in ds1685_rtc_read_time()
276 century = rtc->read(rtc, RTC_CENTURY); in ds1685_rtc_read_time()
277 ds1685_rtc_end_data_access(rtc); in ds1685_rtc_read_time()
280 years = ds1685_rtc_bcd2bin(rtc, years, RTC_YEAR_BCD_MASK, in ds1685_rtc_read_time()
282 century = ds1685_rtc_bcd2bin(rtc, century, RTC_CENTURY_MASK, in ds1685_rtc_read_time()
284 tm->tm_sec = ds1685_rtc_bcd2bin(rtc, seconds, RTC_SECS_BCD_MASK, in ds1685_rtc_read_time()
286 tm->tm_min = ds1685_rtc_bcd2bin(rtc, minutes, RTC_MINS_BCD_MASK, in ds1685_rtc_read_time()
288 tm->tm_hour = ds1685_rtc_bcd2bin(rtc, hours, RTC_HRS_24_BCD_MASK, in ds1685_rtc_read_time()
290 tm->tm_wday = (ds1685_rtc_bcd2bin(rtc, wday, RTC_WDAY_MASK, in ds1685_rtc_read_time()
292 tm->tm_mday = ds1685_rtc_bcd2bin(rtc, mday, RTC_MDAY_BCD_MASK, in ds1685_rtc_read_time()
294 tm->tm_mon = (ds1685_rtc_bcd2bin(rtc, month, RTC_MONTH_BCD_MASK, in ds1685_rtc_read_time()
298 tm->tm_isdst = 0; /* RTC has hardcoded timezone, so don't use. */ in ds1685_rtc_read_time()
311 struct ds1685_priv *rtc = dev_get_drvdata(dev); in ds1685_rtc_set_time() local
315 seconds = ds1685_rtc_bin2bcd(rtc, tm->tm_sec, RTC_SECS_BIN_MASK, in ds1685_rtc_set_time()
317 minutes = ds1685_rtc_bin2bcd(rtc, tm->tm_min, RTC_MINS_BIN_MASK, in ds1685_rtc_set_time()
319 hours = ds1685_rtc_bin2bcd(rtc, tm->tm_hour, RTC_HRS_24_BIN_MASK, in ds1685_rtc_set_time()
321 wday = ds1685_rtc_bin2bcd(rtc, (tm->tm_wday + 1), RTC_WDAY_MASK, in ds1685_rtc_set_time()
323 mday = ds1685_rtc_bin2bcd(rtc, tm->tm_mday, RTC_MDAY_BIN_MASK, in ds1685_rtc_set_time()
325 month = ds1685_rtc_bin2bcd(rtc, (tm->tm_mon + 1), RTC_MONTH_BIN_MASK, in ds1685_rtc_set_time()
327 years = ds1685_rtc_bin2bcd(rtc, (tm->tm_year % 100), in ds1685_rtc_set_time()
329 century = ds1685_rtc_bin2bcd(rtc, ((tm->tm_year + 1900) / 100), in ds1685_rtc_set_time()
350 * RTC registers. in ds1685_rtc_set_time()
352 ds1685_rtc_begin_data_access(rtc); in ds1685_rtc_set_time()
353 ctrlb = rtc->read(rtc, RTC_CTRL_B); in ds1685_rtc_set_time()
354 if (rtc->bcd_mode) in ds1685_rtc_set_time()
358 rtc->write(rtc, RTC_CTRL_B, ctrlb); in ds1685_rtc_set_time()
359 rtc->write(rtc, RTC_SECS, seconds); in ds1685_rtc_set_time()
360 rtc->write(rtc, RTC_MINS, minutes); in ds1685_rtc_set_time()
361 rtc->write(rtc, RTC_HRS, hours); in ds1685_rtc_set_time()
362 rtc->write(rtc, RTC_WDAY, wday); in ds1685_rtc_set_time()
363 rtc->write(rtc, RTC_MDAY, mday); in ds1685_rtc_set_time()
364 rtc->write(rtc, RTC_MONTH, month); in ds1685_rtc_set_time()
365 rtc->write(rtc, RTC_YEAR, years); in ds1685_rtc_set_time()
366 rtc->write(rtc, RTC_CENTURY, century); in ds1685_rtc_set_time()
367 ds1685_rtc_end_data_access(rtc); in ds1685_rtc_set_time()
387 struct ds1685_priv *rtc = dev_get_drvdata(dev); in ds1685_rtc_read_alarm() local
391 /* Fetch the alarm info from the RTC alarm registers. */ in ds1685_rtc_read_alarm()
392 ds1685_rtc_begin_data_access(rtc); in ds1685_rtc_read_alarm()
393 seconds = rtc->read(rtc, RTC_SECS_ALARM); in ds1685_rtc_read_alarm()
394 minutes = rtc->read(rtc, RTC_MINS_ALARM); in ds1685_rtc_read_alarm()
395 hours = rtc->read(rtc, RTC_HRS_ALARM); in ds1685_rtc_read_alarm()
396 mday = rtc->read(rtc, RTC_MDAY_ALARM); in ds1685_rtc_read_alarm()
397 ctrlb = rtc->read(rtc, RTC_CTRL_B); in ds1685_rtc_read_alarm()
398 ctrlc = rtc->read(rtc, RTC_CTRL_C); in ds1685_rtc_read_alarm()
399 ds1685_rtc_end_data_access(rtc); in ds1685_rtc_read_alarm()
402 ret = ds1685_rtc_check_mday(rtc, mday); in ds1685_rtc_read_alarm()
409 * The Linux RTC system doesn't support the "don't care" capability in ds1685_rtc_read_alarm()
410 * of this RTC chip. We check for it anyways in case support is in ds1685_rtc_read_alarm()
414 alrm->time.tm_sec = ds1685_rtc_bcd2bin(rtc, seconds, in ds1685_rtc_read_alarm()
419 alrm->time.tm_min = ds1685_rtc_bcd2bin(rtc, minutes, in ds1685_rtc_read_alarm()
424 alrm->time.tm_hour = ds1685_rtc_bcd2bin(rtc, hours, in ds1685_rtc_read_alarm()
429 alrm->time.tm_mday = ds1685_rtc_bcd2bin(rtc, mday, RTC_MDAY_BCD_MASK, in ds1685_rtc_read_alarm()
445 struct ds1685_priv *rtc = dev_get_drvdata(dev); in ds1685_rtc_set_alarm() local
450 seconds = ds1685_rtc_bin2bcd(rtc, alrm->time.tm_sec, in ds1685_rtc_set_alarm()
453 minutes = ds1685_rtc_bin2bcd(rtc, alrm->time.tm_min, in ds1685_rtc_set_alarm()
456 hours = ds1685_rtc_bin2bcd(rtc, alrm->time.tm_hour, in ds1685_rtc_set_alarm()
459 mday = ds1685_rtc_bin2bcd(rtc, alrm->time.tm_mday, in ds1685_rtc_set_alarm()
464 ret = ds1685_rtc_check_mday(rtc, mday); in ds1685_rtc_set_alarm()
471 * The Linux RTC system doesn't support the "don't care" capability in ds1685_rtc_set_alarm()
472 * of this RTC chip because rtc_valid_tm tries to validate every in ds1685_rtc_set_alarm()
492 ds1685_rtc_begin_data_access(rtc); in ds1685_rtc_set_alarm()
493 ctrlb = rtc->read(rtc, RTC_CTRL_B); in ds1685_rtc_set_alarm()
494 rtc->write(rtc, RTC_CTRL_B, (ctrlb & ~(RTC_CTRL_B_AIE))); in ds1685_rtc_set_alarm()
497 rtc->read(rtc, RTC_CTRL_C); in ds1685_rtc_set_alarm()
501 * RTC registers. in ds1685_rtc_set_alarm()
503 ctrlb = rtc->read(rtc, RTC_CTRL_B); in ds1685_rtc_set_alarm()
504 if (rtc->bcd_mode) in ds1685_rtc_set_alarm()
508 rtc->write(rtc, RTC_CTRL_B, ctrlb); in ds1685_rtc_set_alarm()
509 rtc->write(rtc, RTC_SECS_ALARM, seconds); in ds1685_rtc_set_alarm()
510 rtc->write(rtc, RTC_MINS_ALARM, minutes); in ds1685_rtc_set_alarm()
511 rtc->write(rtc, RTC_HRS_ALARM, hours); in ds1685_rtc_set_alarm()
512 rtc->write(rtc, RTC_MDAY_ALARM, mday); in ds1685_rtc_set_alarm()
516 ctrlb = rtc->read(rtc, RTC_CTRL_B); in ds1685_rtc_set_alarm()
518 rtc->write(rtc, RTC_CTRL_B, ctrlb); in ds1685_rtc_set_alarm()
522 ds1685_rtc_end_data_access(rtc); in ds1685_rtc_set_alarm()
540 struct ds1685_priv *rtc = dev_get_drvdata(dev); in ds1685_rtc_alarm_irq_enable() local
544 rtc->write(rtc, RTC_CTRL_B, (rtc->read(rtc, RTC_CTRL_B) | in ds1685_rtc_alarm_irq_enable()
547 rtc->write(rtc, RTC_CTRL_B, (rtc->read(rtc, RTC_CTRL_B) & in ds1685_rtc_alarm_irq_enable()
551 rtc->read(rtc, RTC_CTRL_C); in ds1685_rtc_alarm_irq_enable()
563 * @rtc: pointer to the ds1685 rtc structure.
567 ds1685_rtc_extended_irq(struct ds1685_priv *rtc, struct platform_device *pdev) in ds1685_rtc_extended_irq() argument
571 ds1685_rtc_switch_to_bank1(rtc); in ds1685_rtc_extended_irq()
572 ctrl4a = rtc->read(rtc, RTC_EXT_CTRL_4A); in ds1685_rtc_extended_irq()
573 ctrl4b = rtc->read(rtc, RTC_EXT_CTRL_4B); in ds1685_rtc_extended_irq()
582 rtc->write(rtc, RTC_EXT_CTRL_4B, in ds1685_rtc_extended_irq()
583 (rtc->read(rtc, RTC_EXT_CTRL_4B) & in ds1685_rtc_extended_irq()
587 rtc->write(rtc, RTC_EXT_CTRL_4A, in ds1685_rtc_extended_irq()
597 rtc->write(rtc, RTC_EXT_CTRL_4B, in ds1685_rtc_extended_irq()
598 (rtc->read(rtc, RTC_EXT_CTRL_4B) | in ds1685_rtc_extended_irq()
602 if (rtc->prepare_poweroff != NULL) in ds1685_rtc_extended_irq()
603 rtc->prepare_poweroff(); in ds1685_rtc_extended_irq()
615 rtc->write(rtc, RTC_EXT_CTRL_4A, in ds1685_rtc_extended_irq()
619 if (rtc->wake_alarm != NULL) in ds1685_rtc_extended_irq()
620 rtc->wake_alarm(); in ds1685_rtc_extended_irq()
637 rtc->write(rtc, RTC_EXT_CTRL_4A, in ds1685_rtc_extended_irq()
642 if (rtc->post_ram_clear != NULL) in ds1685_rtc_extended_irq()
643 rtc->post_ram_clear(); in ds1685_rtc_extended_irq()
648 ds1685_rtc_switch_to_bank0(rtc); in ds1685_rtc_extended_irq()
660 struct ds1685_priv *rtc = platform_get_drvdata(pdev); in ds1685_rtc_irq_handler() local
666 if (unlikely(!rtc)) in ds1685_rtc_irq_handler()
669 rtc_lock(rtc->dev); in ds1685_rtc_irq_handler()
672 ctrlb = rtc->read(rtc, RTC_CTRL_B); in ds1685_rtc_irq_handler()
673 ctrlc = rtc->read(rtc, RTC_CTRL_C); in ds1685_rtc_irq_handler()
680 * update the RTC core. in ds1685_rtc_irq_handler()
708 * is not recognized by the RTC core. in ds1685_rtc_irq_handler()
710 ds1685_rtc_extended_irq(rtc, pdev); in ds1685_rtc_irq_handler()
713 rtc_update_irq(rtc->dev, num_irqs, events); in ds1685_rtc_irq_handler()
714 rtc_unlock(rtc->dev); in ds1685_rtc_irq_handler()
754 struct ds1685_priv *rtc = dev_get_drvdata(dev); in ds1685_rtc_proc() local
759 ds1685_rtc_switch_to_bank1(rtc); in ds1685_rtc_proc()
760 ds1685_rtc_get_ssn(rtc, ssn); in ds1685_rtc_proc()
761 ctrla = rtc->read(rtc, RTC_CTRL_A); in ds1685_rtc_proc()
762 ctrlb = rtc->read(rtc, RTC_CTRL_B); in ds1685_rtc_proc()
763 ctrld = rtc->read(rtc, RTC_CTRL_D); in ds1685_rtc_proc()
764 ctrl4a = rtc->read(rtc, RTC_EXT_CTRL_4A); in ds1685_rtc_proc()
765 ctrl4b = rtc->read(rtc, RTC_EXT_CTRL_4B); in ds1685_rtc_proc()
766 ds1685_rtc_switch_to_bank0(rtc); in ds1685_rtc_proc()
768 /* Determine the RTC model. */ in ds1685_rtc_proc()
827 /* RTC Class operations */
843 struct ds1685_priv *rtc = priv; in ds1685_nvram_read() local
844 struct mutex *rtc_mutex = &rtc->dev->ops_lock; in ds1685_nvram_read()
853 ds1685_rtc_switch_to_bank0(rtc); in ds1685_nvram_read()
859 *buf++ = rtc->read(rtc, (NVRAM_TIME_BASE + pos++)); in ds1685_nvram_read()
861 *buf++ = rtc->read(rtc, (NVRAM_BANK0_BASE + pos++)); in ds1685_nvram_read()
866 ds1685_rtc_switch_to_bank1(rtc); in ds1685_nvram_read()
870 rtc->write(rtc, RTC_EXT_CTRL_4A, in ds1685_nvram_read()
871 (rtc->read(rtc, RTC_EXT_CTRL_4A) | in ds1685_nvram_read()
876 rtc->write(rtc, RTC_BANK1_RAM_ADDR_LSB, in ds1685_nvram_read()
886 rtc->write(rtc, RTC_BANK1_RAM_ADDR, in ds1685_nvram_read()
889 *buf++ = rtc->read(rtc, RTC_BANK1_RAM_DATA_PORT); in ds1685_nvram_read()
895 rtc->write(rtc, RTC_EXT_CTRL_4A, in ds1685_nvram_read()
896 (rtc->read(rtc, RTC_EXT_CTRL_4A) & in ds1685_nvram_read()
899 ds1685_rtc_switch_to_bank0(rtc); in ds1685_nvram_read()
910 struct ds1685_priv *rtc = priv; in ds1685_nvram_write() local
911 struct mutex *rtc_mutex = &rtc->dev->ops_lock; in ds1685_nvram_write()
920 ds1685_rtc_switch_to_bank0(rtc); in ds1685_nvram_write()
926 rtc->write(rtc, (NVRAM_TIME_BASE + pos++), in ds1685_nvram_write()
929 rtc->write(rtc, (NVRAM_BANK0_BASE), *buf++); in ds1685_nvram_write()
933 ds1685_rtc_switch_to_bank1(rtc); in ds1685_nvram_write()
937 rtc->write(rtc, RTC_EXT_CTRL_4A, in ds1685_nvram_write()
938 (rtc->read(rtc, RTC_EXT_CTRL_4A) | in ds1685_nvram_write()
943 rtc->write(rtc, RTC_BANK1_RAM_ADDR_LSB, in ds1685_nvram_write()
953 rtc->write(rtc, RTC_BANK1_RAM_ADDR, in ds1685_nvram_write()
956 rtc->write(rtc, RTC_BANK1_RAM_DATA_PORT, *buf++); in ds1685_nvram_write()
962 rtc->write(rtc, RTC_EXT_CTRL_4A, in ds1685_nvram_write()
963 (rtc->read(rtc, RTC_EXT_CTRL_4A) & in ds1685_nvram_write()
966 ds1685_rtc_switch_to_bank0(rtc); in ds1685_nvram_write()
987 struct ds1685_priv *rtc = dev_get_drvdata(dev->parent); in ds1685_rtc_sysfs_battery_show() local
990 ctrld = rtc->read(rtc, RTC_CTRL_D); in ds1685_rtc_sysfs_battery_show()
1007 struct ds1685_priv *rtc = dev_get_drvdata(dev->parent); in ds1685_rtc_sysfs_auxbatt_show() local
1010 ds1685_rtc_switch_to_bank1(rtc); in ds1685_rtc_sysfs_auxbatt_show()
1011 ctrl4a = rtc->read(rtc, RTC_EXT_CTRL_4A); in ds1685_rtc_sysfs_auxbatt_show()
1012 ds1685_rtc_switch_to_bank0(rtc); in ds1685_rtc_sysfs_auxbatt_show()
1029 struct ds1685_priv *rtc = dev_get_drvdata(dev->parent); in ds1685_rtc_sysfs_serial_show() local
1032 ds1685_rtc_switch_to_bank1(rtc); in ds1685_rtc_sysfs_serial_show()
1033 ds1685_rtc_get_ssn(rtc, ssn); in ds1685_rtc_sysfs_serial_show()
1034 ds1685_rtc_switch_to_bank0(rtc); in ds1685_rtc_sysfs_serial_show()
1041 * struct ds1685_rtc_sysfs_misc_attrs - list for misc RTC features.
1052 * struct ds1685_rtc_sysfs_misc_grp - attr group for misc RTC features.
1064 * ds1685_rtc_probe - initializes rtc driver.
1071 struct ds1685_priv *rtc; in ds1685_rtc_probe() local
1088 /* Allocate memory for the rtc device. */ in ds1685_rtc_probe()
1089 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); in ds1685_rtc_probe()
1090 if (!rtc) in ds1685_rtc_probe()
1096 rtc->regs = devm_platform_ioremap_resource(pdev, 0); in ds1685_rtc_probe()
1097 if (IS_ERR(rtc->regs)) in ds1685_rtc_probe()
1098 return PTR_ERR(rtc->regs); in ds1685_rtc_probe()
1099 rtc->read = ds1685_read; in ds1685_rtc_probe()
1100 rtc->write = ds1685_write; in ds1685_rtc_probe()
1103 rtc->regs = devm_platform_ioremap_resource(pdev, 0); in ds1685_rtc_probe()
1104 if (IS_ERR(rtc->regs)) in ds1685_rtc_probe()
1105 return PTR_ERR(rtc->regs); in ds1685_rtc_probe()
1106 rtc->data = devm_platform_ioremap_resource(pdev, 1); in ds1685_rtc_probe()
1107 if (IS_ERR(rtc->data)) in ds1685_rtc_probe()
1108 return PTR_ERR(rtc->data); in ds1685_rtc_probe()
1109 rtc->read = ds1685_indirect_read; in ds1685_rtc_probe()
1110 rtc->write = ds1685_indirect_write; in ds1685_rtc_probe()
1114 if (!rtc->read || !rtc->write) in ds1685_rtc_probe()
1119 rtc->regstep = pdata->regstep; in ds1685_rtc_probe()
1121 rtc->regstep = 1; in ds1685_rtc_probe()
1125 rtc->prepare_poweroff = pdata->plat_prepare_poweroff; in ds1685_rtc_probe()
1129 rtc->wake_alarm = pdata->plat_wake_alarm; in ds1685_rtc_probe()
1133 rtc->post_ram_clear = pdata->plat_post_ram_clear; in ds1685_rtc_probe()
1136 platform_set_drvdata(pdev, rtc); in ds1685_rtc_probe()
1139 ctrla = rtc->read(rtc, RTC_CTRL_A); in ds1685_rtc_probe()
1151 * the RTC setup so we have access to the extended functions. in ds1685_rtc_probe()
1154 rtc->write(rtc, RTC_CTRL_A, ctrla); in ds1685_rtc_probe()
1157 rtc->write(rtc, RTC_EXT_CTRL_4B, in ds1685_rtc_probe()
1158 (rtc->read(rtc, RTC_EXT_CTRL_4B) | RTC_CTRL_4B_E32K)); in ds1685_rtc_probe()
1161 rtc->write(rtc, RTC_CTRL_B, in ds1685_rtc_probe()
1162 (rtc->read(rtc, RTC_CTRL_B) | RTC_CTRL_B_SET)); in ds1685_rtc_probe()
1165 while (rtc->read(rtc, RTC_EXT_CTRL_4A) & RTC_CTRL_4A_INCR) in ds1685_rtc_probe()
1172 ctrlb = rtc->read(rtc, RTC_CTRL_B); in ds1685_rtc_probe()
1177 rtc->bcd_mode = pdata->bcd_mode; in ds1685_rtc_probe()
1181 * The RTC has hardcoded timezone information that is rendered in ds1685_rtc_probe()
1190 hours = rtc->read(rtc, RTC_HRS); in ds1685_rtc_probe()
1192 hours = ds1685_rtc_bcd2bin(rtc, hours, RTC_HRS_12_BCD_MASK, in ds1685_rtc_probe()
1200 rtc->write(rtc, RTC_CTRL_B, ctrlb); in ds1685_rtc_probe()
1203 rtc->write(rtc, RTC_HRS, in ds1685_rtc_probe()
1204 ds1685_rtc_bin2bcd(rtc, hours, in ds1685_rtc_probe()
1209 hours = rtc->read(rtc, RTC_HRS_ALARM); in ds1685_rtc_probe()
1211 hours = ds1685_rtc_bcd2bin(rtc, hours, RTC_HRS_12_BCD_MASK, in ds1685_rtc_probe()
1216 rtc->write(rtc, RTC_HRS_ALARM, in ds1685_rtc_probe()
1217 ds1685_rtc_bin2bcd(rtc, hours, in ds1685_rtc_probe()
1222 rtc->write(rtc, RTC_CTRL_B, ctrlb); in ds1685_rtc_probe()
1225 /* Unset the SET bit in Control B so the RTC can update. */ in ds1685_rtc_probe()
1226 rtc->write(rtc, RTC_CTRL_B, in ds1685_rtc_probe()
1227 (rtc->read(rtc, RTC_CTRL_B) & ~(RTC_CTRL_B_SET))); in ds1685_rtc_probe()
1230 if (!(rtc->read(rtc, RTC_CTRL_D) & RTC_CTRL_D_VRT)) in ds1685_rtc_probe()
1232 "Main battery is exhausted! RTC may be invalid!\n"); in ds1685_rtc_probe()
1235 if (!(rtc->read(rtc, RTC_EXT_CTRL_4A) & RTC_CTRL_4A_VRT2)) in ds1685_rtc_probe()
1240 rtc->write(rtc, RTC_CTRL_B, in ds1685_rtc_probe()
1241 (rtc->read(rtc, RTC_CTRL_B) & ~(RTC_CTRL_B_PAU_MASK))); in ds1685_rtc_probe()
1244 rtc->read(rtc, RTC_CTRL_C); in ds1685_rtc_probe()
1247 rtc->write(rtc, RTC_EXT_CTRL_4B, in ds1685_rtc_probe()
1248 (rtc->read(rtc, RTC_EXT_CTRL_4B) & ~(RTC_CTRL_4B_RWK_MASK))); in ds1685_rtc_probe()
1251 rtc->write(rtc, RTC_EXT_CTRL_4A, in ds1685_rtc_probe()
1252 (rtc->read(rtc, RTC_EXT_CTRL_4A) & ~(RTC_CTRL_4A_RWK_MASK))); in ds1685_rtc_probe()
1258 rtc->write(rtc, RTC_EXT_CTRL_4B, in ds1685_rtc_probe()
1259 (rtc->read(rtc, RTC_EXT_CTRL_4B) | RTC_CTRL_4B_KSE)); in ds1685_rtc_probe()
1278 rtc->dev = rtc_dev; in ds1685_rtc_probe()
1284 * RTC will still set the *IE / *F flags and raise IRQF in ctrlc, but in ds1685_rtc_probe()
1288 rtc->irq_num = platform_get_irq(pdev, 0); in ds1685_rtc_probe()
1289 if (rtc->irq_num <= 0) { in ds1685_rtc_probe()
1293 ret = devm_request_threaded_irq(&pdev->dev, rtc->irq_num, in ds1685_rtc_probe()
1301 "RTC interrupt not available\n"); in ds1685_rtc_probe()
1302 rtc->irq_num = 0; in ds1685_rtc_probe()
1307 ds1685_rtc_switch_to_bank0(rtc); in ds1685_rtc_probe()
1313 nvmem_cfg.priv = rtc; in ds1685_rtc_probe()
1322 * ds1685_rtc_remove - removes rtc driver.
1328 struct ds1685_priv *rtc = platform_get_drvdata(pdev); in ds1685_rtc_remove() local
1331 rtc->write(rtc, RTC_CTRL_B, in ds1685_rtc_remove()
1332 (rtc->read(rtc, RTC_CTRL_B) & in ds1685_rtc_remove()
1336 rtc->read(rtc, RTC_CTRL_C); in ds1685_rtc_remove()
1339 rtc->write(rtc, RTC_EXT_CTRL_4B, in ds1685_rtc_remove()
1340 (rtc->read(rtc, RTC_EXT_CTRL_4B) & in ds1685_rtc_remove()
1344 rtc->write(rtc, RTC_EXT_CTRL_4A, in ds1685_rtc_remove()
1345 (rtc->read(rtc, RTC_EXT_CTRL_4A) & in ds1685_rtc_remove()
1350 * ds1685_rtc_driver - rtc driver properties.
1354 .name = "rtc-ds1685",
1367 * ds1685_rtc_poweroff - uses the RTC chip to power the system off.
1374 struct ds1685_priv *rtc; in ds1685_rtc_poweroff() local
1376 /* Check for valid RTC data, else, spin forever. */ in ds1685_rtc_poweroff()
1382 /* Get the rtc data. */ in ds1685_rtc_poweroff()
1383 rtc = platform_get_drvdata(pdev); in ds1685_rtc_poweroff()
1391 if (rtc->irq_num) in ds1685_rtc_poweroff()
1392 disable_irq_nosync(rtc->irq_num); in ds1685_rtc_poweroff()
1395 ctrla = rtc->read(rtc, RTC_CTRL_A); in ds1685_rtc_poweroff()
1398 rtc->write(rtc, RTC_CTRL_A, ctrla); in ds1685_rtc_poweroff()
1405 ds1685_rtc_switch_to_bank1(rtc); in ds1685_rtc_poweroff()
1406 ctrl4a = rtc->read(rtc, RTC_EXT_CTRL_4A); in ds1685_rtc_poweroff()
1410 rtc->write(rtc, RTC_EXT_CTRL_4A, ctrl4a); in ds1685_rtc_poweroff()
1418 ctrl4b = rtc->read(rtc, RTC_EXT_CTRL_4B); in ds1685_rtc_poweroff()
1421 rtc->write(rtc, RTC_EXT_CTRL_4B, ctrl4b); in ds1685_rtc_poweroff()
1427 rtc->write(rtc, RTC_EXT_CTRL_4A, in ds1685_rtc_poweroff()
1441 MODULE_DESCRIPTION("Dallas/Maxim DS1685/DS1687-series RTC driver");
1443 MODULE_ALIAS("platform:rtc-ds1685");