void cvmx_rtc_ds1337_dump_state(void) { int i = 0; printf("RTC:\n"); printf("%d : %02X ", i, cvmx_twsi_read8(CVMX_RTC_DS1337_ADDR, 0x0)); for(i=1; i<16; i++) { printf("%02X ", cvmx_twsi_read8_cur_addr(CVMX_RTC_DS1337_ADDR)); } printf("\n"); }
/* * Board-specifc RTC read * Time is expressed in seconds from epoch (Jan 1 1970 at 00:00:00 UTC) * and converted internally to calendar format. */ uint32_t cvmx_rtc_ds1337_read(void) { int i, retry; uint8_t reg[8]; uint8_t sec; struct clocktime ct; struct timespec ts; memset(®, 0, sizeof(reg)); memset(&ct, 0, sizeof(ct)); for(retry=0; retry<2; retry++) { /* Lockless read: detects the infrequent roll-over and retries */ reg[0] = cvmx_twsi_read8(CVMX_RTC_DS1337_ADDR, 0x0); for(i=1; i<7; i++) reg[i] = cvmx_twsi_read8_cur_addr(CVMX_RTC_DS1337_ADDR); sec = cvmx_twsi_read8(CVMX_RTC_DS1337_ADDR, 0x0); if ((sec & 0xf) == (reg[0] & 0xf)) break; /* Time did not roll-over, value is correct */ } ct.sec = bcd2bin(reg[0] & 0x7f); ct.min = bcd2bin(reg[1] & 0x7f); ct.hour = bcd2bin(reg[2] & 0x3f); if ((reg[2] & 0x40) && (reg[2] & 0x20)) /* AM/PM format and is PM time */ { ct.hour = (ct.hour + 12) % 24; } ct.dow = (reg[3] & 0x7); /* Day of week field is 1..7 */ ct.day = bcd2bin(reg[4] & 0x3f); ct.mon = bcd2bin(reg[5] & 0x1f); /* Month field is 1..12 */ #if defined(OCTEON_BOARD_CAPK_0100ND) /* * CAPK-0100ND uses DS1307 that does not have century bit */ ct.year = 2000 + bcd2bin(reg[6]); #else ct.year = ((reg[5] & 0x80) ? 2000 : 1900) + bcd2bin(reg[6]); #endif if (validate_ct_struct(&ct)) cvmx_dprintf("Warning: RTC calendar is not configured properly\n"); if (clock_ct_to_ts(&ct, &ts) != 0) { cvmx_dprintf("Warning: RTC calendar is not configured properly\n"); return 0; } return ts.tv_sec; }
/* * Board-specifc RTC read * Time is expressed in seconds from epoch (Jan 1 1970 at 00:00:00 UTC) * and converted internally to calendar format. */ uint32_t cvmx_rtc_ds1337_read(void) { int i, retry; uint32_t time; uint8_t reg[8]; uint8_t sec; struct tm tms; memset(®, 0, sizeof(reg)); memset(&tms, 0, sizeof(struct tm)); for(retry=0; retry<2; retry++) { /* Lockless read: detects the infrequent roll-over and retries */ reg[0] = cvmx_twsi_read8(CVMX_RTC_DS1337_ADDR, 0x0); for(i=1; i<7; i++) reg[i] = cvmx_twsi_read8_cur_addr(CVMX_RTC_DS1337_ADDR); sec = cvmx_twsi_read8(CVMX_RTC_DS1337_ADDR, 0x0); if ((sec & 0xf) == (reg[0] & 0xf)) break; /* Time did not roll-over, value is correct */ } tms.tm_sec = bcd2bin(reg[0] & 0x7f); tms.tm_min = bcd2bin(reg[1] & 0x7f); tms.tm_hour = bcd2bin(reg[2] & 0x3f); if ((reg[2] & 0x40) && (reg[2] & 0x20)) /* AM/PM format and is PM time */ { tms.tm_hour = (tms.tm_hour + 12) % 24; } tms.tm_wday = (reg[3] & 0x7) - 1; /* Day of week field is 0..6 */ tms.tm_mday = bcd2bin(reg[4] & 0x3f); tms.tm_mon = bcd2bin(reg[5] & 0x1f) - 1; /* Month field is 0..11 */ tms.tm_year = ((reg[5] & 0x80) ? 100 : 0) + bcd2bin(reg[6]); if (validate_tm_struct(&tms)) cvmx_dprintf("Warning: RTC calendar is not configured properly\n"); time = mktime(&tms); return time; }