FreeBSD/sys/mips/cavium/octeon_ds1337.c
/*
 * 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.
 */
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.
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(&reg, 0, sizeof(reg));
    memset(&ct, 0, sizeof(ct));
    for(retry=0; retry<2; retry++)
    {
	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; 
    }
    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))   
    {
	ct.hour = (ct.hour + 12) % 24;
    }
    ct.dow = (reg[3] & 0x7) - 1; 
    ct.day = bcd2bin(reg[4] & 0x3f);
    ct.mon  = bcd2bin(reg[5] & 0x1f); 
#if defined(OCTEON_BOARD_CAPK_0100ND)
    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;
}
uint32_t cvmx_rtc_ds1337_read ( void ) { int i , retry ; uint8_t reg [ 8 ] ; uint8_t sec ; struct clocktime ct ; struct timespec ts ; memset ( & reg , 0 , sizeof ( reg ) ) ; memset ( & ct , 0 , sizeof ( ct ) ) ; for ( retry = 0 ; retry < 2 ; retry ++ ) { 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 ; } 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 ) ) { ct . hour = ( ct . hour + 12 ) % 24 ; } ct . dow = ( reg [ 3 ] & 0x7 ) - 1 ; ct . day = bcd2bin ( reg [ 4 ] & 0x3f ) ; ct . mon = bcd2bin ( reg [ 5 ] & 0x1f ) ; #if defined ( OCTEON_BOARD_CAPK_0100ND ) 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 ( " \n " ) ; if ( clock_ct_to_ts ( & ct , & ts ) != 0 ) { cvmx_dprintf ( " \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.
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 .
/* Lockless read: detects the infrequent roll-over and retries */ /* Time did not roll-over, value is correct */ /* AM/PM format and is PM time */ /* Day of week field is 0..6 */ /* Month field is 1..12 */ /*
     * CAPK-0100ND uses DS1307 that does not have century bit
     */