Exemplo n.º 1
1
static void
ds1307_convert_to_time( struct rtc_time *dt, char *buf)
{
	dt->tm_sec = BCD_TO_BIN(buf[0]);
	dt->tm_min = BCD_TO_BIN(buf[1]);

	if ( TWELVE_HOUR_MODE(buf[2]) )
	{
		dt->tm_hour = HOURS_12(buf[2]);
		if (HOURS_AP(buf[2])) /* PM */
		{
			dt->tm_hour += 12;
		}
	}
	else /* 24-hour-mode */
	{
		dt->tm_hour = HOURS_24(buf[2]);
	}

	dt->tm_mday = BCD_TO_BIN(buf[4]);
	/* dt->tm_mon is zero-based */
	dt->tm_mon = BCD_TO_BIN(buf[5]) - 1;
	/* year is 1900 + dt->tm_year */
	dt->tm_year = BCD_TO_BIN(buf[6]) + 100;

	if( rtc_debug > 2)
	{
		printk("ds1307_get_datetime: year = %d\n", dt->tm_year);
		printk("ds1307_get_datetime: mon  = %d\n", dt->tm_mon);
		printk("ds1307_get_datetime: mday = %d\n", dt->tm_mday);
		printk("ds1307_get_datetime: hour = %d\n", dt->tm_hour);
		printk("ds1307_get_datetime: min  = %d\n", dt->tm_min);
		printk("ds1307_get_datetime: sec  = %d\n", dt->tm_sec);
	}
}
Exemplo n.º 2
0
Arquivo: vcd.c Projeto: Ackhuman/vlc
/*****************************************************************************
 * EntryPoints: Reads the information about the entry points on the disc.
 *****************************************************************************/
static int EntryPoints( access_t *p_access )
{
    access_sys_t *p_sys = p_access->p_sys;
    uint8_t      sector[VCD_DATA_SIZE];

    entries_sect_t entries;
    int i_nb;

    /* Read the entry point sector */
    if( ioctl_ReadSectors( VLC_OBJECT(p_access), p_sys->vcddev,
        VCD_ENTRIES_SECTOR, sector, 1, VCD_TYPE ) < 0 )
    {
        msg_Err( p_access, "could not read entry points sector" );
        return VLC_EGENERIC;
    }
    memcpy( &entries, sector, CD_SECTOR_SIZE );

    i_nb = GetWBE( &entries.i_entries_nb );
    if( i_nb > 500 )
    {
        msg_Err( p_access, "invalid entry points number" );
        return VLC_EGENERIC;
    }

    if( strncmp( entries.psz_id, "ENTRYVCD", sizeof( entries.psz_id ) ) &&
        strncmp( entries.psz_id, "ENTRYSVD", sizeof( entries.psz_id ) ) )
    {
        msg_Err( p_access, "unrecognized entry points format" );
        return VLC_EGENERIC;
    }

    for( int i = 0; i < i_nb; i++ )
    {
        const int i_title = BCD_TO_BIN(entries.entry[i].i_track) - 2;
        const int i_sector =
            (MSF_TO_LBA2( BCD_TO_BIN( entries.entry[i].msf.minute ),
                          BCD_TO_BIN( entries.entry[i].msf.second ),
                          BCD_TO_BIN( entries.entry[i].msf.frame  ) ));
        seekpoint_t *s;

        if( i_title < 0 ) continue;   /* Should not occur */
        if( i_title >= p_sys->i_titles ) continue;

        msg_Dbg( p_access, "Entry[%d] title=%d sector=%d",
                 i, i_title, i_sector );

        s = vlc_seekpoint_New();
        s->i_byte_offset = (i_sector - p_sys->p_sectors[i_title+1]) *
            VCD_DATA_SIZE;

        TAB_APPEND( p_sys->title[i_title]->i_seekpoint,
                    p_sys->title[i_title]->seekpoint, s );
    }

    return VLC_SUCCESS;
}
Exemplo n.º 3
0
void getdate( struct date *dateblk)
{
 unsigned long tmp;
 __asm__ __volatile__("int $0x40":"=a"(tmp):"0"(29)); 
 dateblk->da_year=2000+(tmp&0xff);
 dateblk->da_mon=(tmp>>8)&0xff;
 dateblk->da_day=(tmp>>16)&0xff;
 BCD_TO_BIN(dateblk->da_year);
 BCD_TO_BIN(dateblk->da_mon);
 BCD_TO_BIN(dateblk->da_day);
}
Exemplo n.º 4
0
void _dos_getdate(struct _dosdate_t *date)
{
 unsigned long tmp;
 __asm__ __volatile__("int $0x40":"=a"(tmp):"0"(29)); 
 date->year=2000+(tmp&0xff);
 date->month=(tmp>>8)&0xff;
 date->day= (tmp>>16)&0xff;
 date->dayofweek=0; /* xxx - how to do it correctly ? */
 BCD_TO_BIN(date->year);
 BCD_TO_BIN(date->month);
 BCD_TO_BIN(date->day);
}
//---------------------------------------------------------------------------------------------------------------------------
//
// 获得 CMOS 时间
//
//---------------------------------------------------------------------------------------------------------------------------
void GetCmosTime(CmosTime* t)
{
	if (t) {
		t->sec =   ReadCmos(0);
		t->min =  ReadCmos(2);
		t->hour=  ReadCmos(4);
	}
	BCD_TO_BIN(t->sec);
	BCD_TO_BIN(t->min);
	BCD_TO_BIN(t->hour);

}
//-----------------------------------------------------------------------------------------------------------------------------
//
//获得 CMOS 日期
//
//-----------------------------------------------------------------------------------------------------------------------------
void GetCmosDate(CmosDate* d)
{
	if (d) {
		d->dayofweek =ReadCmos(6);
		d->day =ReadCmos(7);
		d->month =ReadCmos(8);
		d->year = ReadCmos(9);
	}
	BCD_TO_BIN(d->day);
	BCD_TO_BIN(d->month);
	BCD_TO_BIN(d->year);
	d->year+=2000;

}
Exemplo n.º 7
0
static int rtc8564_get_datetime(struct i2c_client *client, struct rtc_tm *dt)
{
	int ret = -EIO;
	unsigned char buf[15];

	_DBG(1, "client=%p, dt=%p", client, dt);

	if (!dt)
		return -EINVAL;

	memset(buf, 0, sizeof(buf));

	ret = rtc8564_read(client, 0, buf, 15);
	if (ret)
		return ret;

	/* century stored in minute alarm reg */
	dt->year = BCD_TO_BIN(buf[RTC8564_REG_YEAR]);
	dt->year += 100 * BCD_TO_BIN(buf[RTC8564_REG_AL_MIN] & 0x3f);
	dt->mday = BCD_TO_BIN(buf[RTC8564_REG_DAY] & 0x3f);
	dt->wday = BCD_TO_BIN(buf[RTC8564_REG_WDAY] & 7);
	dt->mon = BCD_TO_BIN(buf[RTC8564_REG_MON_CENT] & 0x1f);

	dt->secs = BCD_TO_BIN(buf[RTC8564_REG_SEC] & 0x7f);
	dt->vl = (buf[RTC8564_REG_SEC] & 0x80) == 0x80;
	dt->mins = BCD_TO_BIN(buf[RTC8564_REG_MIN] & 0x7f);
	dt->hours = BCD_TO_BIN(buf[RTC8564_REG_HR] & 0x3f);

	_DBGRTCTM(2, *dt);

	return 0;
}
Exemplo n.º 8
0
Arquivo: rtc.c Projeto: 274914765/C
/*
 * In order to set the CMOS clock precisely, set_rtc_mmss has to be called 500
 * ms after the second nowtime has started, because when nowtime is written
 * into the registers of the CMOS clock, it will jump to the next second
 * precisely 500 ms later.  Check the Motorola MC146818A or Dallas DS12887 data
 * sheet for details.
 *
 * BUG: This routine does not handle hour overflow properly; it just
 *      sets the minutes. Usually you'll only notice that after reboot!
 */
static int set_rtc_mmss(unsigned long nowtime)
{
    unsigned char save_control, save_freq_select;
    int retval = 0;
    int real_seconds, real_minutes, cmos_minutes;

    /* gets recalled with irq locally disabled */
    spin_lock(&rtc_lock);
    save_control = CMOS_READ(RTC_CONTROL); /* tell the clock it's being
                        * set */
    CMOS_WRITE(save_control | RTC_SET, RTC_CONTROL);

    save_freq_select = CMOS_READ(RTC_FREQ_SELECT); /* stop and reset
                            * prescaler */
    CMOS_WRITE(save_freq_select | RTC_DIV_RESET2, RTC_FREQ_SELECT);

    cmos_minutes = CMOS_READ(RTC_MINUTES);
    if (!(save_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
        BCD_TO_BIN(cmos_minutes);

    /*
     * since we're only adjusting minutes and seconds,
     * don't interfere with hour overflow. This avoids
     * messing with unknown time zones but requires your
     * RTC not to be off by more than 15 minutes
     */
    real_seconds = nowtime % 60;
    real_minutes = nowtime / 60;
    if (((abs(real_minutes - cmos_minutes) + 15) / 30) & 1)
        /* correct for half hour time zone */
        real_minutes += 30;
    real_minutes %= 60;

    if (abs(real_minutes - cmos_minutes) < 30) {
        if (!(save_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
            BIN_TO_BCD(real_seconds);
            BIN_TO_BCD(real_minutes);
        }
        CMOS_WRITE(real_seconds, RTC_SECONDS);
        CMOS_WRITE(real_minutes, RTC_MINUTES);
    } else {
        printk(KERN_WARNING
               "set_rtc_mmss: can't update from %d to %d\n",
               cmos_minutes, real_minutes);
        retval = -1;
    }

    /* The following flags have to be released exactly in this order,
     * otherwise the DS12887 (popular MC146818A clone with integrated
     * battery and quartz) will not reset the oscillator and will not
     * update precisely 500 ms later. You won't find this mentioned in
     * the Dallas Semiconductor data sheets, but who believes data
     * sheets anyway ...                           -- Markus Kuhn
     */
    CMOS_WRITE(save_control, RTC_CONTROL);
    CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT);
    spin_unlock(&rtc_lock);

    return retval;
}
Exemplo n.º 9
0
__initfunc(int rtc_init(void))
{
	unsigned long flags;
#ifdef __alpha__
	unsigned int year, ctrl;
	unsigned long uip_watchdog;
	char *guess = NULL;
#endif
	printk(KERN_INFO "Real Time Clock Driver v%s\n", RTC_VERSION);
	if(request_irq(RTC_IRQ, rtc_interrupt, SA_INTERRUPT, "rtc", NULL))
	{
		/* Yeah right, seeing as irq 8 doesn't even hit the bus. */
		printk(KERN_ERR "rtc: IRQ %d is not free.\n", RTC_IRQ);
		return -EIO;
	}
	misc_register(&rtc_dev);
	/* Check region? Naaah! Just snarf it up. */
	request_region(RTC_PORT(0), RTC_IO_EXTENT, "rtc");
#ifdef __alpha__
	rtc_freq = HZ;
	
	/* Each operating system on an Alpha uses its own epoch.
	   Let's try to guess which one we are using now. */
	
	uip_watchdog = jiffies;
	if (rtc_is_updating() != 0)
		while (jiffies - uip_watchdog < 2*HZ/100)
			barrier();
	
	save_flags(flags);
	cli();
	year = CMOS_READ(RTC_YEAR);
	ctrl = CMOS_READ(RTC_CONTROL);
	restore_flags(flags);
	
	if (!(ctrl & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
		BCD_TO_BIN(year);       /* This should never happen... */
	
	if (year > 10 && year < 44) {
		epoch = 1980;
		guess = "ARC console";
	} else if (year < 96) {
		epoch = 1952;
		guess = "Digital UNIX";
	}
	if (guess)
		printk("rtc: %s epoch (%lu) detected\n", guess, epoch);
#endif
	init_timer(&rtc_irq_timer);
	rtc_irq_timer.function = rtc_dropped_irq;
	rtc_wait = NULL;
	save_flags(flags);
	cli();
	/* Initialize periodic freq. to CMOS reset default, which is 1024Hz */
	CMOS_WRITE(((CMOS_READ(RTC_FREQ_SELECT) & 0xF0) | 0x06), RTC_FREQ_SELECT);
	restore_flags(flags);
	rtc_freq = 1024;
	return 0;
}
Exemplo n.º 10
0
/*==========================================================================
 FUNCTION:DS3231 driver
 PURPOSE:
 ---------------------------------------------------------------------------*/
bool Crtc::getDate(u16* year, u08* mon, u08* day, u08* hour, u08* min) {
	u08 buf[0x12];
	// send address
	buf[0] = 0x00;
	i2c->masterSend(rtc_id, 1, buf);
	// get the data
	i2c->masterReceive(rtc_id, 7, buf);

	//datetime.sec = BCD_TO_BIN (buf[0] & 0x7F);
	*min = BCD_TO_BIN (buf[1] & 0x7F);
	*hour = BCD_TO_BIN (buf[2] & 0x3F);
	//*wday = (buf[3]) & 0x7; //1--7
	*day = BCD_TO_BIN (buf[4] & 0x3F); //01--31
	*mon = BCD_TO_BIN (buf[5] & 0x1F);
	*year = BCD_TO_BIN (buf[6]) + 2000; /* byte*/
	return true;
}
Exemplo n.º 11
0
static int evm_read_time(struct device *dev, struct rtc_time *tm)
{
	char rtcdata [9];

	rtcdata[0] = 2;
	rtcdata[1] = 1;
	davinci_i2c_write(2, rtcdata, 0x23);

	msleep(1);
	davinci_i2c_read(9, rtcdata, 0x23);
	msleep(1);

	/* FIXME the RTC reports 12-hour time, without an AM/PM indicator,
	 * but Linux requires that we report 24 hour time...
	 */

	tm->tm_year = BCD_TO_BIN(rtcdata[3]) * 100
			+ BCD_TO_BIN(rtcdata[2])
			- 1900;
	tm->tm_mon = BCD_TO_BIN(rtcdata[4]);
	tm->tm_mday = BCD_TO_BIN(rtcdata[5]);
	tm->tm_hour = BCD_TO_BIN(rtcdata[6]);
	tm->tm_min = BCD_TO_BIN(rtcdata[7]);
	tm->tm_sec = BCD_TO_BIN(rtcdata[8]);

	return 0;
}
Exemplo n.º 12
0
static unsigned long __init get_swarm_time(void)
{
	unsigned int year, mon, day, hour, min, sec, y2k;

	sec = xicor_read(X1241REG_SC);
	min = xicor_read(X1241REG_MN);
	hour = xicor_read(X1241REG_HR);

	if (hour & X1241REG_HR_MIL) {
		hour &= 0x3f;
	} else {
		if (hour & 0x20)
			hour = (hour & 0xf) + 0x12;
	}

	BCD_TO_BIN(sec);
	BCD_TO_BIN(min);
	BCD_TO_BIN(hour);

	day = xicor_read(X1241REG_DT);
	mon = xicor_read(X1241REG_MO);
	year = xicor_read(X1241REG_YR);
	y2k = xicor_read(X1241REG_Y2K);
 
	BCD_TO_BIN(day);
	BCD_TO_BIN(mon);
	BCD_TO_BIN(year);
	BCD_TO_BIN(y2k);

	year += (y2k * 100);

	return mktime(year, mon, day, hour, min, sec);
}
Exemplo n.º 13
0
INT8S pcf8563_read(TIME* ptime)
{
	INT8U time_ram[10];
	INT8U sub_addr, mode, year;

	if(NULL == ptime){
		return -1;
	}

	mode = 1;
	sub_addr = 0x02;
	
	if(IRcvStr(PCF8563_I2C_PORT, 0xA2, sub_addr, mode, time_ram, 7) == false){
		return 	-1;
	}
	
	ptime->second = BCD_TO_BIN(time_ram[0] & 0x7F);
	ptime->minute = BCD_TO_BIN(time_ram[1] & 0x7F);
	ptime->hour   = BCD_TO_BIN(time_ram[2] & 0x3F);
	ptime->day    = BCD_TO_BIN(time_ram[3] & 0x3F);
	ptime->week   = BCD_TO_BIN(time_ram[4] & 0x07);
	ptime->month  = BCD_TO_BIN(time_ram[5] & 0x1F);
	
	// йю╪меп╤о
	if(time_ram[5]&(0x80)){
		ptime->year = 1900;
	}else{
		ptime->year = 2000;
	}
	year = BCD_TO_BIN(time_ram[6]);
	ptime->year += year; 

	return 0;
}
Exemplo n.º 14
0
static int
pcf8583_get_datetime(struct i2c_client *client, struct rtc_tm *dt)
{
	unsigned char buf[8], addr[1] = { 1 };
	struct i2c_msg msgs[2] = {
		{ client->addr, 0,        1, addr },
		{ client->addr, I2C_M_RD, 6, buf  }
	};
	int ret = -EIO;

	memset(buf, 0, sizeof(buf));

	ret = i2c_transfer(client->adapter, msgs, 2);
	if (ret == 2) {
		dt->year_off = buf[4] >> 6;
		dt->wday     = buf[5] >> 5;

		buf[4] &= 0x3f;
		buf[5] &= 0x1f;

		dt->cs       = BCD_TO_BIN(buf[0]);
		dt->secs     = BCD_TO_BIN(buf[1]);
		dt->mins     = BCD_TO_BIN(buf[2]);
		dt->hours    = BCD_TO_BIN(buf[3]);
		dt->mday     = BCD_TO_BIN(buf[4]);
		dt->mon      = BCD_TO_BIN(buf[5]);

		ret = 0;
	}
Exemplo n.º 15
0
static void time_init(void)
{
	struct mktime time;
	int i;

	for (i = 0 ; i < 1000000 ; i++)
		if (!(CMOS_READ(10) & 0x80))
			break;
	do {
		time.sec = CMOS_READ(0);
		time.min = CMOS_READ(2);
		time.hour = CMOS_READ(4);
		time.day = CMOS_READ(7);
		time.mon = CMOS_READ(8);
		time.year = CMOS_READ(9);
	} while (time.sec != CMOS_READ(0));
	BCD_TO_BIN(time.sec);
	BCD_TO_BIN(time.min);
	BCD_TO_BIN(time.hour);
	BCD_TO_BIN(time.day);
	BCD_TO_BIN(time.mon);
	BCD_TO_BIN(time.year);
	time.mon--;
	startup_time = kernel_mktime(&time);
}
Exemplo n.º 16
0
void maple_get_rtc_time(struct rtc_time *tm)
{
	do {
		tm->tm_sec = maple_clock_read(RTC_SECONDS);
		tm->tm_min = maple_clock_read(RTC_MINUTES);
		tm->tm_hour = maple_clock_read(RTC_HOURS);
		tm->tm_mday = maple_clock_read(RTC_DAY_OF_MONTH);
		tm->tm_mon = maple_clock_read(RTC_MONTH);
		tm->tm_year = maple_clock_read(RTC_YEAR);
	} while (tm->tm_sec != maple_clock_read(RTC_SECONDS));

	if (!(maple_clock_read(RTC_CONTROL) & RTC_DM_BINARY)
	    || RTC_ALWAYS_BCD) {
		BCD_TO_BIN(tm->tm_sec);
		BCD_TO_BIN(tm->tm_min);
		BCD_TO_BIN(tm->tm_hour);
		BCD_TO_BIN(tm->tm_mday);
		BCD_TO_BIN(tm->tm_mon);
		BCD_TO_BIN(tm->tm_year);
	  }
	if ((tm->tm_year + 1900) < 1970)
		tm->tm_year += 100;

	GregorianDay(tm);
}
Exemplo n.º 17
0
void
get_rtc_time(struct rtc_time *rtc_tm) 
{
	unsigned long flags;

	local_irq_save(flags);

	rtc_tm->tm_sec = CMOS_READ(RTC_SECONDS);
	rtc_tm->tm_min = CMOS_READ(RTC_MINUTES);
	rtc_tm->tm_hour = CMOS_READ(RTC_HOURS);
	rtc_tm->tm_mday = CMOS_READ(RTC_DAY_OF_MONTH);
	rtc_tm->tm_mon = CMOS_READ(RTC_MONTH);
	rtc_tm->tm_year = CMOS_READ(RTC_YEAR);

	local_irq_restore(flags);
	
	BCD_TO_BIN(rtc_tm->tm_sec);
	BCD_TO_BIN(rtc_tm->tm_min);
	BCD_TO_BIN(rtc_tm->tm_hour);
	BCD_TO_BIN(rtc_tm->tm_mday);
	BCD_TO_BIN(rtc_tm->tm_mon);
	BCD_TO_BIN(rtc_tm->tm_year);

	/*
	 * Account for differences between how the RTC uses the values
	 * and how they are defined in a struct rtc_time;
	 */

	if (rtc_tm->tm_year <= 69)
		rtc_tm->tm_year += 100;

	rtc_tm->tm_mon--;
}
Exemplo n.º 18
0
void
get_rtc_time(struct rtc_time *tm)
{
	tm->tm_sec = rtc_read(RTC_SECONDS);
	tm->tm_min = rtc_read(RTC_MINUTES);
	tm->tm_hour = rtc_read(RTC_HOURS);
	tm->tm_mday = rtc_read(RTC_DAY_OF_MONTH);
	tm->tm_mon = rtc_read(RTC_MONTH);
	tm->tm_year = rtc_read(RTC_YEAR);

	if (tm->tm_sec & 0x80)
		printk(KERN_WARNING "%s: RTC Low Voltage - date/time is not reliable!\n", PCF8563_NAME);

	tm->tm_year = BCD_TO_BIN(tm->tm_year) + ((tm->tm_mon & 0x80) ? 100 : 0);
	tm->tm_sec &= 0x7f;
	tm->tm_min &= 0x7f;
	tm->tm_hour &= 0x3f;
	tm->tm_mday &= 0x3f;
	tm->tm_mon &= 0x1f;

	BCD_TO_BIN(tm->tm_sec);
	BCD_TO_BIN(tm->tm_min);
	BCD_TO_BIN(tm->tm_hour);
	BCD_TO_BIN(tm->tm_mday);
	BCD_TO_BIN(tm->tm_mon);
	tm->tm_mon--; /* Month is 1..12 in RTC but 0..11 in linux */
}
Exemplo n.º 19
0
static __init unsigned long get_m48t35_time(void)
{
	unsigned int year, month, date, hour, min, sec;
	struct m48t35_rtc *rtc;
	nasid_t nid;

	nid = get_nasid();
	rtc = (struct m48t35_rtc *)(KL_CONFIG_CH_CONS_INFO(nid)->memory_base +
							IOC3_BYTEBUS_DEV0);

	spin_lock(&rtc_lock);
	rtc->control |= M48T35_RTC_READ;
	sec = rtc->sec;
	min = rtc->min;
	hour = rtc->hour;
	date = rtc->date;
	month = rtc->month;
	year = rtc->year;
	rtc->control &= ~M48T35_RTC_READ;
	spin_unlock(&rtc_lock);

	BCD_TO_BIN(sec);
	BCD_TO_BIN(min);
	BCD_TO_BIN(hour);
	BCD_TO_BIN(date);
	BCD_TO_BIN(month);
	BCD_TO_BIN(year);

	year += 1970;

	return mktime(year, month, date, hour, min, sec);
}
Exemplo n.º 20
0
void
get_rtc_time(struct rtc_time *tm)
{
	tm->tm_sec  = rtc_read(RTC_SECONDS);
	tm->tm_min  = rtc_read(RTC_MINUTES);
	tm->tm_hour = rtc_read(RTC_HOURS);
	tm->tm_mday = rtc_read(RTC_DAY_OF_MONTH);
	tm->tm_wday = rtc_read(RTC_WEEKDAY);
	tm->tm_mon  = rtc_read(RTC_MONTH);
	tm->tm_year = rtc_read(RTC_YEAR);

	if (tm->tm_sec & 0x80)
		printk(KERN_WARNING "%s: RTC Voltage Low - reliable date/time "
		       "information is no longer guaranteed!\n", PCF8563_NAME);

	tm->tm_year  = BCD_TO_BIN(tm->tm_year) + ((tm->tm_mon & 0x80) ? 100 : 0);
	tm->tm_sec  &= 0x7F;
	tm->tm_min  &= 0x7F;
	tm->tm_hour &= 0x3F;
	tm->tm_mday &= 0x3F;
	tm->tm_wday &= 0x07; /* Not coded in BCD. */
	tm->tm_mon  &= 0x1F;

	BCD_TO_BIN(tm->tm_sec);
	BCD_TO_BIN(tm->tm_min);
	BCD_TO_BIN(tm->tm_hour);
	BCD_TO_BIN(tm->tm_mday);
	BCD_TO_BIN(tm->tm_mon);
	tm->tm_mon--; /* Month is 1..12 in RTC but 0..11 in linux */
}
Exemplo n.º 21
0
uint32 GetBootTime (void)
{
    uint32 i;
    struct Tm tm;

    for (i=0; i <10000000; i++)
        if ((CMOS_READ (CMOS_CTRL_REG_A) & RTC_UIP) == 0)
            break;

    tm.sec 	= CMOS_READ (CMOS_SECONDS);
    tm.min 	= CMOS_READ (CMOS_MINUTES);
    tm.hour	= CMOS_READ (CMOS_HOURS);
    tm.mday = CMOS_READ (CMOS_DATE_OF_MONTH);
    tm.mon 	= CMOS_READ (CMOS_MONTH);
    tm.year	= CMOS_READ (CMOS_YEAR);


    if (!(CMOS_READ (CMOS_CTRL_REG_B) & RTC_DM_BINARY))
    {
        BCD_TO_BIN (tm.sec);
        BCD_TO_BIN (tm.min);
        BCD_TO_BIN (tm.hour);
        BCD_TO_BIN (tm.mday);
        BCD_TO_BIN (tm.mon);
        BCD_TO_BIN (tm.year);
    }
    if ((tm.year += 1900) < 1970)
        tm.year += 100;

    tm.year -= 1900;
    tm.mon -=1;

    return MakeTime(&tm);
}
Exemplo n.º 22
0
long get_cmos_time(void)
{
	unsigned int year, mon, day, hour, min, sec;
	do {
		sec = CMOS_READ(RTC_SECONDS);
		min = CMOS_READ(RTC_MINUTES);
		hour = CMOS_READ(RTC_HOURS);
		day = CMOS_READ(RTC_DAY_OF_MONTH);
		mon = CMOS_READ(RTC_MONTH);
		year = CMOS_READ(RTC_YEAR);
	} while (sec != CMOS_READ(RTC_SECONDS));

	BCD_TO_BIN(sec);
	BCD_TO_BIN(min);
	BCD_TO_BIN(hour);
	BCD_TO_BIN(day);
	BCD_TO_BIN(mon);
	BCD_TO_BIN(year);

	if ((year += 1900) < 1970)
		year += 100;

	early_print("%d/%d/%d, %d:%d:%d\n",
		year, mon, day, hour, min, sec);

	return mktime(year, mon, day, hour, min, sec);
}
Exemplo n.º 23
0
Arquivo: mktime.c Projeto: OXKernel/ox
time_t ktime(time_t *t)
{
	struct tm tms = {0};
    time_t tmp = 0;

	do {
		tms.tm_sec = CMOS_READ(0);
		tms.tm_min = CMOS_READ(2);
		tms.tm_hour = CMOS_READ(4);
		tms.tm_mday = CMOS_READ(7);
		tms.tm_mon = CMOS_READ(8);
		tms.tm_year = CMOS_READ(9);
	} while (tms.tm_sec != CMOS_READ(0));

	BCD_TO_BIN(tms.tm_sec);
	BCD_TO_BIN(tms.tm_min);
	BCD_TO_BIN(tms.tm_hour);
	BCD_TO_BIN(tms.tm_mday);
	BCD_TO_BIN(tms.tm_mon);
	BCD_TO_BIN(tms.tm_year);
	tms.tm_mon--;

	tmp = kmktime(&tms);

    if(t) {
        (*t) = tmp;
    }
    return tmp;
}/* ktime */
Exemplo n.º 24
0
unsigned long
get_cmos_time(void)
{
	unsigned int year, mon, day, hour, min, sec;

	sec = CMOS_READ(RTC_SECONDS);
	min = CMOS_READ(RTC_MINUTES);
	hour = CMOS_READ(RTC_HOURS);
	day = CMOS_READ(RTC_DAY_OF_MONTH);
	mon = CMOS_READ(RTC_MONTH);
	year = CMOS_READ(RTC_YEAR);

	printk("rtc: sec 0x%x min 0x%x hour 0x%x day 0x%x mon 0x%x year 0x%x\n", 
	       sec, min, hour, day, mon, year);

	BCD_TO_BIN(sec);
	BCD_TO_BIN(min);
	BCD_TO_BIN(hour);
	BCD_TO_BIN(day);
	BCD_TO_BIN(mon);
	BCD_TO_BIN(year);

	if ((year += 1900) < 1970)
		year += 100;

	return mktime(year, mon, day, hour, min, sec);
}
Exemplo n.º 25
0
static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm)
{
	struct rtc_time *alm_tm = &alrm->time;
	void __iomem *base = s3c_rtc_base;
	unsigned int alm_en;

	alm_tm->tm_sec  = readb(base + S3C2410_ALMSEC);
	alm_tm->tm_min  = readb(base + S3C2410_ALMMIN);
	alm_tm->tm_hour = readb(base + S3C2410_ALMHOUR);
	alm_tm->tm_mon  = readb(base + S3C2410_ALMMON);
	alm_tm->tm_mday = readb(base + S3C2410_ALMDATE);
	alm_tm->tm_year = readb(base + S3C2410_ALMYEAR);

	alm_en = readb(base + S3C2410_RTCALM);

	alrm->enabled = (alm_en & S3C2410_RTCALM_ALMEN) ? 1 : 0;

	pr_debug("read alarm %02x %02x.%02x.%02x %02x/%02x/%02x\n",
		 alm_en,
		 alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday,
		 alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec);


	/* decode the alarm enable field */

	if (alm_en & S3C2410_RTCALM_SECEN)
		BCD_TO_BIN(alm_tm->tm_sec);
	else
		alm_tm->tm_sec = 0xff;

	if (alm_en & S3C2410_RTCALM_MINEN)
		BCD_TO_BIN(alm_tm->tm_min);
	else
		alm_tm->tm_min = 0xff;

	if (alm_en & S3C2410_RTCALM_HOUREN)
		BCD_TO_BIN(alm_tm->tm_hour);
	else
		alm_tm->tm_hour = 0xff;

	if (alm_en & S3C2410_RTCALM_DAYEN)
		BCD_TO_BIN(alm_tm->tm_mday);
	else
		alm_tm->tm_mday = 0xff;

	if (alm_en & S3C2410_RTCALM_MONEN) {
		BCD_TO_BIN(alm_tm->tm_mon);
		alm_tm->tm_mon -= 1;
	} else {
		alm_tm->tm_mon = 0xff;
	}

	if (alm_en & S3C2410_RTCALM_YEAREN)
		BCD_TO_BIN(alm_tm->tm_year);
	else
		alm_tm->tm_year = 0xffff;

	return 0;
}
Exemplo n.º 26
0
static void get_rtc_alm_time(struct rtc_time *alm_tm)
{
	unsigned char ctrl;

	/*
	 * Only the values that we read from the RTC are set. That
	 * means only tm_hour, tm_min, and tm_sec.
	 */
	spin_lock_irq(&rtc_lock);
	alm_tm->tm_sec = CMOS_READ(RTC_SECONDS_ALARM);
	alm_tm->tm_min = CMOS_READ(RTC_MINUTES_ALARM);
	alm_tm->tm_hour = CMOS_READ(RTC_HOURS_ALARM);
	ctrl = CMOS_READ(RTC_CONTROL);
	spin_unlock_irq(&rtc_lock);

	if (!(ctrl & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
	{
		BCD_TO_BIN(alm_tm->tm_sec);
		BCD_TO_BIN(alm_tm->tm_min);
		BCD_TO_BIN(alm_tm->tm_hour);
	}
}
Exemplo n.º 27
0
__initfunc(void time_init(void))
{
	unsigned int epoch, year, mon, day, hour, min, sec;
	int i;

	/* The Linux interpretation of the CMOS clock register contents:
	 * When the Update-In-Progress (UIP) flag goes from 1 to 0, the
	 * RTC registers show the second which has precisely just started.
	 * Let's hope other operating systems interpret the RTC the same way.
	 */
	/* read RTC exactly on falling edge of update flag */
	for (i = 0 ; i < 1000000 ; i++)	/* may take up to 1 second... */
		if (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP)
			break;
	for (i = 0 ; i < 1000000 ; i++)	/* must try at least 2.228 ms */
		if (!(CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP))
			break;
	do { /* Isn't this overkill ? UIP above should guarantee consistency */
		sec = CMOS_READ(RTC_SECONDS);
		min = CMOS_READ(RTC_MINUTES);
		hour = CMOS_READ(RTC_HOURS);
		day = CMOS_READ(RTC_DAY_OF_MONTH);
		mon = CMOS_READ(RTC_MONTH);
		year = CMOS_READ(RTC_YEAR);
	} while (sec != CMOS_READ(RTC_SECONDS));
	if (!(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
	  {
	    BCD_TO_BIN(sec);
	    BCD_TO_BIN(min);
	    BCD_TO_BIN(hour);
	    BCD_TO_BIN(day);
	    BCD_TO_BIN(mon);
	    BCD_TO_BIN(year);
	  }

	/* Attempt to guess the epoch.  This is the same heuristic as in rtc.c so
	   no stupid things will happen to timekeeping.  Who knows, maybe Ultrix
  	   also uses 1952 as epoch ...  */
	if (year > 10 && year < 44) {
		epoch = 1980;
	} else if (year < 96) {
		epoch = 1952;
	}
	year += epoch;

	xtime.tv_sec = mktime(year, mon, day, hour, min, sec);
	xtime.tv_usec = 0;

	init_cycle_counter();

	if (cyclecounter_available) {
		write_32bit_cp0_register(CP0_COUNT, 0);
		do_gettimeoffset = do_fast_gettimeoffset;
		irq0.handler = r4k_timer_interrupt;
	}

	board_time_init(&irq0);
}
Exemplo n.º 28
0
void get_rtc_time(struct rtc_time *rtc_tm)
{

	unsigned long flags, uip_watchdog = jiffies;
	unsigned char ctrl;

	/*
	 * read RTC once any update in progress is done. The update
	 * can take just over 2ms. We wait 10 to 20ms. There is no need to
	 * to poll-wait (up to 1s - eeccch) for the falling edge of RTC_UIP.
	 * If you need to know *exactly* when a second has started, enable
	 * periodic update complete interrupts, (via ioctl) and then 
	 * immediately read /dev/rtc which will block until you get the IRQ.
	 * Once the read clears, read the RTC time (again via ioctl). Easy.
	 */

	if (rtc_is_updating() != 0)
		while (jiffies - uip_watchdog < 2*HZ/100)
			barrier();

	/*
	 * Only the values that we read from the RTC are set. We leave
	 * tm_wday, tm_yday and tm_isdst untouched. Even though the
	 * RTC has RTC_DAY_OF_WEEK, we ignore it, as it is only updated
	 * by the RTC when initially set to a non-zero value.
	 */
	save_flags(flags);
	cli();
	rtc_tm->tm_sec = CMOS_READ(RTC_SECONDS);
	rtc_tm->tm_min = CMOS_READ(RTC_MINUTES);
	rtc_tm->tm_hour = CMOS_READ(RTC_HOURS);
	rtc_tm->tm_mday = CMOS_READ(RTC_DAY_OF_MONTH);
	rtc_tm->tm_mon = CMOS_READ(RTC_MONTH);
	rtc_tm->tm_year = CMOS_READ(RTC_YEAR);
	ctrl = CMOS_READ(RTC_CONTROL);
	restore_flags(flags);

	if (!(ctrl & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
	{
		BCD_TO_BIN(rtc_tm->tm_sec);
		BCD_TO_BIN(rtc_tm->tm_min);
		BCD_TO_BIN(rtc_tm->tm_hour);
		BCD_TO_BIN(rtc_tm->tm_mday);
		BCD_TO_BIN(rtc_tm->tm_mon);
		BCD_TO_BIN(rtc_tm->tm_year);
	}

	/*
	 * Account for differences between how the RTC uses the values
	 * and how they are defined in a struct rtc_time;
	 */
	if ((rtc_tm->tm_year += (epoch - 1900)) <= 69)
		rtc_tm->tm_year += 100;

	rtc_tm->tm_mon--;
}
Exemplo n.º 29
0
void get_rtc_alm_time(struct rtc_time *alm_tm)
{
	unsigned long flags;
	unsigned char ctrl;

	/*
	 * Only the values that we read from the RTC are set. That
	 * means only tm_hour, tm_min, and tm_sec.
	 */
	save_flags(flags);
	cli();
	alm_tm->tm_sec = CMOS_READ(RTC_SECONDS_ALARM);
	alm_tm->tm_min = CMOS_READ(RTC_MINUTES_ALARM);
	alm_tm->tm_hour = CMOS_READ(RTC_HOURS_ALARM);
	ctrl = CMOS_READ(RTC_CONTROL);
	restore_flags(flags);

	if (!(ctrl & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
	{
		BCD_TO_BIN(alm_tm->tm_sec);
		BCD_TO_BIN(alm_tm->tm_min);
		BCD_TO_BIN(alm_tm->tm_hour);
	}
}
Exemplo n.º 30
0
__prep
unsigned long mk48t59_get_rtc_time(void)
{
	unsigned char save_control;
	unsigned int year, mon, day, hour, min, sec;
	int i;

	/* Make sure the time is not stopped. */
	save_control = ppc_md.nvram_read_val(MK48T59_RTC_CONTROLB);
	
	ppc_md.nvram_write_val(MK48T59_RTC_CONTROLA,
			     (save_control & (~MK48T59_RTC_CB_STOP)));

	/* Now make sure the read bit is off so the value will change. */
	save_control = ppc_md.nvram_read_val(MK48T59_RTC_CONTROLA);
	save_control &= ~MK48T59_RTC_CA_READ;
	ppc_md.nvram_write_val(MK48T59_RTC_CONTROLA, save_control);

	/* Read the seconds value to see when it changes. */
	sec = ppc_md.nvram_read_val(MK48T59_RTC_SECONDS);
		
	/* Wait until the seconds value changes, then read the value. */
	for (i = 0 ; i < 1000000 ; i++)	{ /* may take up to 1 second... */
	   if (ppc_md.nvram_read_val(MK48T59_RTC_SECONDS) != sec) {
	      break;
	   }
	}

	/* Set the register to read the value. */
	ppc_md.nvram_write_val(MK48T59_RTC_CONTROLA,
			     (save_control | MK48T59_RTC_CA_READ));

	sec = ppc_md.nvram_read_val(MK48T59_RTC_SECONDS);
	min = ppc_md.nvram_read_val(MK48T59_RTC_MINUTES);
	hour = ppc_md.nvram_read_val(MK48T59_RTC_HOURS);
	day = ppc_md.nvram_read_val(MK48T59_RTC_DAY_OF_MONTH);
	mon = ppc_md.nvram_read_val(MK48T59_RTC_MONTH);
	year = ppc_md.nvram_read_val(MK48T59_RTC_YEAR);

	/* Let the time values change again. */
	ppc_md.nvram_write_val(MK48T59_RTC_CONTROLA, save_control);

	BCD_TO_BIN(sec);
	BCD_TO_BIN(min);
	BCD_TO_BIN(hour);
	BCD_TO_BIN(day);
	BCD_TO_BIN(mon);
	BCD_TO_BIN(year);

	year = year + 1900;
	if (year < 1970) {
		year += 100;
	}

	return mktime(year, mon, day, hour, min, sec);
}