Esempio n. 1
0
/*
 * write the alarm register settings
 *
 * we only have the use to interrupt every second, otherwise
 * known as the update interrupt, or the interrupt if the whole
 * date/hours/mins/secs matches.  the ds1511 has many more
 * permutations, but the kernel doesn't.
 */
 static void
ds1511_rtc_update_alarm(struct rtc_plat_data *pdata)
{
	unsigned long flags;

	spin_lock_irqsave(&pdata->lock, flags);
	rtc_write(pdata->alrm_mday < 0 || (pdata->irqen & RTC_UF) ?
	       0x80 : bin2bcd(pdata->alrm_mday) & 0x3f,
	       RTC_ALARM_DATE);
	rtc_write(pdata->alrm_hour < 0 || (pdata->irqen & RTC_UF) ?
	       0x80 : bin2bcd(pdata->alrm_hour) & 0x3f,
	       RTC_ALARM_HOUR);
	rtc_write(pdata->alrm_min < 0 || (pdata->irqen & RTC_UF) ?
	       0x80 : bin2bcd(pdata->alrm_min) & 0x7f,
	       RTC_ALARM_MIN);
	rtc_write(pdata->alrm_sec < 0 || (pdata->irqen & RTC_UF) ?
	       0x80 : bin2bcd(pdata->alrm_sec) & 0x7f,
	       RTC_ALARM_SEC);
	rtc_write(rtc_read(RTC_CMD) | (pdata->irqen ? RTC_TIE : 0), RTC_CMD);
	rtc_read(RTC_CMD1);	/* clear interrupts */
	spin_unlock_irqrestore(&pdata->lock, flags);
}
Esempio n. 2
0
static void ds1553_rtc_update_alarm(struct rtc_plat_data *pdata)
{
	void __iomem *ioaddr = pdata->ioaddr;
	unsigned long flags;

	spin_lock_irqsave(&pdata->rtc->irq_lock, flags);
	writeb(pdata->alrm_mday < 0 || (pdata->irqen & RTC_UF) ?
	       0x80 : bin2bcd(pdata->alrm_mday),
	       ioaddr + RTC_DATE_ALARM);
	writeb(pdata->alrm_hour < 0 || (pdata->irqen & RTC_UF) ?
	       0x80 : bin2bcd(pdata->alrm_hour),
	       ioaddr + RTC_HOURS_ALARM);
	writeb(pdata->alrm_min < 0 || (pdata->irqen & RTC_UF) ?
	       0x80 : bin2bcd(pdata->alrm_min),
	       ioaddr + RTC_MINUTES_ALARM);
	writeb(pdata->alrm_sec < 0 || (pdata->irqen & RTC_UF) ?
	       0x80 : bin2bcd(pdata->alrm_sec),
	       ioaddr + RTC_SECONDS_ALARM);
	writeb(pdata->irqen ? RTC_INTS_AE : 0, ioaddr + RTC_INTERRUPTS);
	readb(ioaddr + RTC_FLAGS);	/* clear interrupts */
	spin_unlock_irqrestore(&pdata->rtc->irq_lock, flags);
}
static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
{
	struct rtc_time *tm = &alrm->time;
	void __iomem *base = s3c_rtc_base;
	unsigned int alrm_en;

	clk_enable(rtc_clk);
	dev_dbg(dev, "s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n",
		 alrm->enabled,
		 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
		 tm->tm_hour, tm->tm_min, tm->tm_sec);

	alrm_en = readb(base + S3C2410_RTCALM) & S3C2410_RTCALM_ALMEN;
	writeb(0x00, base + S3C2410_RTCALM);

	if (tm->tm_sec < 60 && tm->tm_sec >= 0) {
		alrm_en |= S3C2410_RTCALM_SECEN;
		writeb(bin2bcd(tm->tm_sec), base + S3C2410_ALMSEC);
	}

	if (tm->tm_min < 60 && tm->tm_min >= 0) {
		alrm_en |= S3C2410_RTCALM_MINEN;
		writeb(bin2bcd(tm->tm_min), base + S3C2410_ALMMIN);
	}

	if (tm->tm_hour < 24 && tm->tm_hour >= 0) {
		alrm_en |= S3C2410_RTCALM_HOUREN;
		writeb(bin2bcd(tm->tm_hour), base + S3C2410_ALMHOUR);
	}

	dev_dbg(dev, "setting S3C2410_RTCALM to %08x\n", alrm_en);

	writeb(alrm_en, base + S3C2410_RTCALM);

	s3c_rtc_setaie(dev, alrm->enabled);

	clk_disable(rtc_clk);
	return 0;
}
/*
 * linux rtc-module does not support wday alarm
 * and only 24h time mode supported indeed
 */
static int sd2068_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
{
	struct i2c_client *client = to_i2c_client(dev);
	struct sd2068 *sd2068 = i2c_get_clientdata(client);
	int control, stat;
	int ret;
	u8 buf[7];

	if (client->irq <= 0)
		return -EINVAL;

	mutex_lock(&sd2068->mutex);

	buf[0] = bin2bcd(alarm->time.tm_sec);
	buf[1] = bin2bcd(alarm->time.tm_min);
	buf[2] = bin2bcd(alarm->time.tm_hour);
	buf[3] = bin2bcd(alarm->time.tm_wday);
	buf[4] = bin2bcd(alarm->time.tm_mday);
	buf[5] = bin2bcd(alarm->time.tm_mon);
	buf[6] = bin2bcd(alarm->time.tm_year);

	/* clear alarm interrupt enable bit */
	ret = i2c_smbus_read_byte_data(client, SD2068_CTR2);
	if (ret < 0)
		goto out;
	control = ret;
	control &= ~(SD2068_CTR2_INTAE);
	ret = i2c_smbus_write_byte_data(client, SD2068_CTR2, control);
	if (ret < 0)
		goto out;

	/* clear any pending alarm flag */
/*	ret = i2c_smbus_read_byte_data(client, SD2068_SR);
	if (ret < 0)
		goto out;
	stat = ret;
	stat &= ~(SD2068_SR_A1F | SD2068_SR_A2F);
	ret = i2c_smbus_write_byte_data(client, SD2068_SR, stat);
	if (ret < 0)
		goto out;*/

	ret = i2c_smbus_write_i2c_block_data(client, SD2068_ALARM1, 7, buf);

	ret = i2c_smbus_write_byte_data(client, SD2068_ALARM_EN, 0x7f);

	if (alarm->enabled) {
		control |= SD2068_CTR2_INTAE;
		ret = i2c_smbus_write_byte_data(client, SD2068_CTR2, control);
	}
out:
	mutex_unlock(&sd2068->mutex);
	return ret;
}
Esempio n. 5
0
void RTC_DS1307::adjust(const DateTime& dt) {
    Wire.beginTransmission(DS1307_ADDRESS);
    Wire_write(DS1307_Registers::Second);
    Wire_write(bin2bcd(dt.second()));
    Wire_write(bin2bcd(dt.minute()));
    Wire_write(bin2bcd(dt.hour()));
    Wire_write(bin2bcd(0));
    Wire_write(bin2bcd(dt.day()));
    Wire_write(bin2bcd(dt.month()));
    Wire_write(bin2bcd(dt.year() - 2000));
    Wire.endTransmission();
}
Esempio n. 6
0
void RTC_BQ32000::adjust(const DateTime& dt) {
    Wire.beginTransmission(BQ32000_ADDRESS);
    Wire.write((byte) 0);
    Wire.write(bin2bcd(dt.second()));
    Wire.write(bin2bcd(dt.minute()));
    Wire.write(bin2bcd(dt.hour()));
    Wire.write(bin2bcd(0));
    Wire.write(bin2bcd(dt.day()));
    Wire.write(bin2bcd(dt.month()));
    Wire.write(bin2bcd(dt.year() - 2000));
    Wire.endTransmission();
}
void RTC_DS1307::adjust(const DateTime& dt) {
  Wire.beginTransmission(DS1307_ADDRESS);
  Wire._I2C_WRITE((byte)0); // start at location 0
  Wire._I2C_WRITE(bin2bcd(dt.second()));
  Wire._I2C_WRITE(bin2bcd(dt.minute()));
  Wire._I2C_WRITE(bin2bcd(dt.hour()));
  Wire._I2C_WRITE(bin2bcd(0));
  Wire._I2C_WRITE(bin2bcd(dt.day()));
  Wire._I2C_WRITE(bin2bcd(dt.month()));
  Wire._I2C_WRITE(bin2bcd(dt.year() - 2000));
  Wire.endTransmission();
}
Esempio n. 8
0
void RTC_DS1307::adjust(const DateTime& dt) {
  twi_buf[0] = 0;
  twi_buf[1] = bin2bcd(dt.second());
  twi_buf[2] = bin2bcd(dt.minute());
  twi_buf[3] = bin2bcd(dt.hour());
  twi_buf[4] = bin2bcd(0);
  twi_buf[5] = bin2bcd(dt.day());
  twi_buf[6] = bin2bcd(dt.month());
  twi_buf[7] = bin2bcd(dt.year() - 2000);
  twi_buf[8] = 0;
  twi_writeTo(DS1307_ADDRESS, 9);
}
Esempio n. 9
0
int atari_tt_set_clock_mmss (unsigned long nowtime)
{
    int retval = 0;
    short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60;
    unsigned char save_control, save_freq_select, rtc_minutes;

    save_control = RTC_READ (RTC_CONTROL); /* tell the clock it's being set */
    RTC_WRITE (RTC_CONTROL, save_control | RTC_SET);

    save_freq_select = RTC_READ (RTC_FREQ_SELECT); /* stop and reset prescaler */
    RTC_WRITE (RTC_FREQ_SELECT, save_freq_select | RTC_DIV_RESET2);

    rtc_minutes = RTC_READ (RTC_MINUTES);
    if (!(save_control & RTC_DM_BINARY))
	rtc_minutes = bcd2bin(rtc_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 30 minutes.  */
    if ((rtc_minutes < real_minutes
         ? real_minutes - rtc_minutes
         : rtc_minutes - real_minutes) < 30)
        {
            if (!(save_control & RTC_DM_BINARY))
                {
		    real_seconds = bin2bcd(real_seconds);
		    real_minutes = bin2bcd(real_minutes);
                }
            RTC_WRITE (RTC_SECONDS, real_seconds);
            RTC_WRITE (RTC_MINUTES, real_minutes);
        }
    else
        retval = -1;

    RTC_WRITE (RTC_FREQ_SELECT, save_freq_select);
    RTC_WRITE (RTC_CONTROL, save_control);
    return retval;
}
int xicor_set_time(unsigned long t)
{
	struct rtc_time tm;
	int tmp;
	unsigned long flags;

	rtc_time_to_tm(t, &tm);
	tm.tm_year += 1900;

	spin_lock_irqsave(&rtc_lock, flags);
	/* unlock writes to the CCR */
	xicor_write(X1241REG_SR, X1241REG_SR_WEL);
	xicor_write(X1241REG_SR, X1241REG_SR_WEL | X1241REG_SR_RWEL);

	/* trivial ones */
	tm.tm_sec = bin2bcd(tm.tm_sec);
	xicor_write(X1241REG_SC, tm.tm_sec);

	tm.tm_min = bin2bcd(tm.tm_min);
	xicor_write(X1241REG_MN, tm.tm_min);

	tm.tm_mday = bin2bcd(tm.tm_mday);
	xicor_write(X1241REG_DT, tm.tm_mday);

	/* tm_mon starts from 0, *ick* */
	tm.tm_mon ++;
	tm.tm_mon = bin2bcd(tm.tm_mon);
	xicor_write(X1241REG_MO, tm.tm_mon);

	/* year is split */
	tmp = tm.tm_year / 100;
	tm.tm_year %= 100;
	xicor_write(X1241REG_YR, tm.tm_year);
	xicor_write(X1241REG_Y2K, tmp);

	/* hour is the most tricky one */
	tmp = xicor_read(X1241REG_HR);
	if (tmp & X1241REG_HR_MIL) {
		/* 24 hour format */
		tm.tm_hour = bin2bcd(tm.tm_hour);
		tmp = (tmp & ~0x3f) | (tm.tm_hour & 0x3f);
	} else {
		/* 12 hour format, with 0x2 for pm */
		tmp = tmp & ~0x3f;
		if (tm.tm_hour >= 12) {
			tmp |= 0x20;
			tm.tm_hour -= 12;
		}
		tm.tm_hour = bin2bcd(tm.tm_hour);
		tmp |= tm.tm_hour;
	}
	xicor_write(X1241REG_HR, tmp);

	xicor_write(X1241REG_SR, 0);
	spin_unlock_irqrestore(&rtc_lock, flags);

	return 0;
}
void RTC_MCP7940::adjust(const DateTime& dt) {	//change date and time registers based on user input
  Wire.beginTransmission(RTC_ADD);
  Wire.write((byte) 0);
  Wire.write(bin2bcd((byte) 10000000));
  Wire.write(bin2bcd(dt.minute()));
  Wire.write(bin2bcd(dt.hour()));
  Wire.write(bin2bcd(0x8)); //enable RTC battery backup function
  Wire.write(bin2bcd(dt.day()));
  Wire.write(bin2bcd(dt.month()));
  Wire.write(bin2bcd(dt.year()-2000));
  Wire.write((byte) 0);
  Wire.endTransmission();
}
Esempio n. 12
0
void RTC_DS1307::adjust(const DateTime& dt) {
    WIRE.beginTransmission(DS1307_ADDRESS);
    WIRE.send(0);
    WIRE.send(bin2bcd(dt.second()));
    WIRE.send(bin2bcd(dt.minute()));
    WIRE.send(bin2bcd(dt.hour()));
    WIRE.send(bin2bcd(0));
    WIRE.send(bin2bcd(dt.day()));
    WIRE.send(bin2bcd(dt.month()));
    WIRE.send(bin2bcd(dt.year() - 2000));
    WIRE.send(0);
    WIRE.endTransmission();
}
Esempio n. 13
0
// Example: PCF8523.adjust (DateTime(2014, 8, 14, 1, 49, 0))
// Sets RTC time to 2014/14/8 1:49 a.m.
void PCF8523::adjust(const DateTime& dt) {
  WIRE.beginTransmission(PCF8523_ADDRESS);
  WIRE._I2C_WRITE(0x03);
  WIRE._I2C_WRITE(bin2bcd(dt.second()));
  WIRE._I2C_WRITE(bin2bcd(dt.minute()));
  WIRE._I2C_WRITE(bin2bcd(dt.hour()));
  WIRE._I2C_WRITE(bin2bcd(dt.day()));
  WIRE._I2C_WRITE(bin2bcd(0));
  WIRE._I2C_WRITE(bin2bcd(dt.month()));
  WIRE._I2C_WRITE(bin2bcd(dt.year() - 2000));
  WIRE._I2C_WRITE(0);
  WIRE.endTransmission();
}
Esempio n. 14
0
/*	Set this Real Time Clocks initial time. */
void RTC_DS3231::SetDateTime(const DateTime& dt)
{
    Wire.beginTransmission(DS3231_ADDRESS);	// Wake the I2C device
    Wire.SEND(0);							// Advance its internal register pointer.
    Wire.SEND(bin2bcd(dt.second()));		// Send data...
    Wire.SEND(bin2bcd(dt.minute()));
    Wire.SEND(bin2bcd(dt.hour()));
    Wire.SEND(bin2bcd(0));					// Skip the day of week.
    Wire.SEND(bin2bcd(dt.day()));		
    Wire.SEND(bin2bcd(dt.month()));
    Wire.SEND(bin2bcd(dt.year() - 2000));
    Wire.endTransmission();					// End the transmission
}
int rtc_set (struct rtc_time *tmp)
{
	uchar save_ctrl_b;
	uchar sec, min, hour, mday, wday, mon, year;

#ifdef RTC_DEBUG
	printf ( "Set DATE: %4d-%02d-%02d (wday=%d)  TIME: %2d:%02d:%02d\n",
		tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
		tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
#endif

	if( !(rtc_read(RTC_CONTROL_B) & RTC_CB_DM))
	{	    /* Information is in BCD format */
		year = bin2bcd(tmp->tm_year % 100);
		mon  = bin2bcd(tmp->tm_mon);
		wday = bin2bcd(tmp->tm_wday);
		mday = bin2bcd(tmp->tm_mday);
		hour = bin2bcd(tmp->tm_hour);
		min  = bin2bcd(tmp->tm_min);
		sec  = bin2bcd(tmp->tm_sec);
	}
	else
	{
		year = tmp->tm_year % 100;
		mon  = tmp->tm_mon;
		wday = tmp->tm_wday;
		mday = tmp->tm_mday;
		hour = tmp->tm_hour;
		min  = tmp->tm_min;
		sec  = tmp->tm_sec;
	}

	/* disables the RTC to update the regs */
	save_ctrl_b = rtc_read(RTC_CONTROL_B);
	save_ctrl_b |= RTC_CB_SET;
	rtc_write(RTC_CONTROL_B, save_ctrl_b);

	rtc_write (RTC_YEAR, year);
	rtc_write (RTC_MONTH, mon);
	rtc_write (RTC_DAY_OF_WEEK, wday);
	rtc_write (RTC_DATE_OF_MONTH, mday);
	rtc_write (RTC_HOURS, hour);
	rtc_write (RTC_MINUTES, min);
	rtc_write (RTC_SECONDS, sec);

	/* enables the RTC to update the regs */
	save_ctrl_b &= ~RTC_CB_SET;
	rtc_write(RTC_CONTROL_B, save_ctrl_b);

	return 0;
}
Esempio n. 16
0
//-----------------------------------------------------
void ServiceSetRtc(void){
 register unsigned char data;
 unsigned char time_out;
 PlayServiceFile(PLAY_SERVICE,SERVICE_CALENDAR_SET);
 ReadDsRtcTime(); // Read date/time RTC from DS3231
 data = bcd2bin(DS_CALENDAR.Hour);    DS_CALENDAR.Hour    = data;
 data = bcd2bin(DS_CALENDAR.Minutes); DS_CALENDAR.Minutes = data;  
 data = bcd2bin(DS_CALENDAR.Date);    DS_CALENDAR.Date    = data;
 data = bcd2bin(DS_CALENDAR.Month);   DS_CALENDAR.Month   = data;
 if(DS_CALENDAR.Year < 9) DS_CALENDAR.Year = 9;
 data = bcd2bin(DS_CALENDAR.Year);    DS_CALENDAR.Year    = data; 
 PlayDateRTC();
 PlayTimeRTC();
 while(1){
  PlayServiceFile(PLAY_SERVICE,SERVICE_SET_DATE_TIME_FILE);
  time_out = WaitKey(PREV,NEXT,-1,EXIT);
  if(time_out == false) break;
   PlayBeep();
   // exit and Save date/time RTC to DS3231
   if(KEY == EXIT){
    CLEAR_KEYPAD();
    data = bin2bcd(DS_CALENDAR.Hour);    DS_CALENDAR.Hour    = data;
    data = bin2bcd(DS_CALENDAR.Minutes); DS_CALENDAR.Minutes = data;  
    data = bin2bcd(DS_CALENDAR.Date);    DS_CALENDAR.Date    = data;
    data = bin2bcd(DS_CALENDAR.Month);   DS_CALENDAR.Month   = data;
    data = bin2bcd(DS_CALENDAR.Year);    DS_CALENDAR.Year    = data;  
    WriteDsRtcTime();
    break;
   }
   // Set DATE RTC
   if(KEY == PREV){ CLEAR_KEYPAD(); ServiceSetDateRTC(); }
   // Set TIME RTC
   if(KEY == NEXT){ CLEAR_KEYPAD(); ServiceSetTimeRTC(); }
  }
 return;
}
Esempio n. 17
0
/*
 * Set alarm time and date in RTC
 */
static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
{
    struct rtc_time tm;

    at91_rtc_decodetime(AT91_RTC_TIMR, AT91_RTC_CALR, &tm);

    at91_alarm_year = tm.tm_year;

    tm.tm_mon = alrm->time.tm_mon;
    tm.tm_mday = alrm->time.tm_mday;
    tm.tm_hour = alrm->time.tm_hour;
    tm.tm_min = alrm->time.tm_min;
    tm.tm_sec = alrm->time.tm_sec;

    at91_rtc_write_idr(AT91_RTC_ALARM);
    at91_rtc_write(AT91_RTC_TIMALR,
                   bin2bcd(tm.tm_sec) << 0
                   | bin2bcd(tm.tm_min) << 8
                   | bin2bcd(tm.tm_hour) << 16
                   | AT91_RTC_HOUREN | AT91_RTC_MINEN | AT91_RTC_SECEN);
    at91_rtc_write(AT91_RTC_CALALR,
                   bin2bcd(tm.tm_mon + 1) << 16		/* tm_mon starts at zero */
                   | bin2bcd(tm.tm_mday) << 24
                   | AT91_RTC_DATEEN | AT91_RTC_MTHEN);

    if (alrm->enabled) {
        at91_rtc_write(AT91_RTC_SCCR, AT91_RTC_ALARM);
        at91_rtc_write_ier(AT91_RTC_ALARM);
    }

    dev_dbg(dev, "%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__,
            at91_alarm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour,
            tm.tm_min, tm.tm_sec);

    return 0;
}
Esempio n. 18
0
bool RTC_DS3231::setAlarmHour(uint8_t alarm, uint8_t hh) {

   setAlarm(alarm);
   Wire.beginTransmission(DS3231_ADDRESS);
   Wire.write(alarm_addr[alarm-1]);
   if(alarm==DS3231_ALARM_1)
      Wire.write(0);                             // second = 0 and A*M1 = 0
   Wire.write(0);                                // minute = 0 and A*M2 = 0
   Wire.write(bin2bcd(hh) & ~0x80);              // hour = hh and A*M3 = 0
   Wire.write(0x80);                             // A*M4 = 1;
   Wire.endTransmission();

   return true;
   // This code below to check Time was set right or not
   // return (hh==readAlarmTime(alarm).hh) ? true:false;
}
Esempio n. 19
0
/* set clock time from *tmp in DS1306 RTC */
void rtc_set (struct rtc_time *tmp)
{
    debug ("Set DATE: %4d-%02d-%02d (wday=%d)  TIME: %2d:%02d:%02d\n",
           tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
           tmp->tm_hour, tmp->tm_min, tmp->tm_sec);

    rtc_write (RTC_SECONDS, bin2bcd (tmp->tm_sec));
    rtc_write (RTC_MINUTES, bin2bcd (tmp->tm_min));
    rtc_write (RTC_HOURS, bin2bcd (tmp->tm_hour));
    rtc_write (RTC_DAY_OF_WEEK, bin2bcd (tmp->tm_wday + 1));
    rtc_write (RTC_DATE_OF_MONTH, bin2bcd (tmp->tm_mday));
    rtc_write (RTC_MONTH, bin2bcd (tmp->tm_mon));
    rtc_write (RTC_YEAR, bin2bcd (tmp->tm_year - 2000));
}
Esempio n. 20
0
/*
 * Board-specific RTC write
 * Time returned is in seconds from epoch (Jan 1 1970 at 00:00:00 UTC)
 */
int cvmx_rtc_ds1337_write(uint32_t time)
{
    struct clocktime ct;
    struct timespec ts;
    int       i, rc, retry;
    uint8_t   reg[8];
    uint8_t   sec;

    ts.tv_sec = time;
    ts.tv_nsec = 0;

    clock_ts_to_ct(&ts, &ct);

    if (validate_ct_struct(&ct))
    {
	cvmx_dprintf("Error: RTC was passed wrong calendar values, write failed\n");
	goto ct_invalid;
    }

    reg[0] = bin2bcd(ct.sec);
    reg[1] = bin2bcd(ct.min);
    reg[2] = bin2bcd(ct.hour);       /* Force 0..23 format even if using AM/PM */
    reg[3] = bin2bcd(ct.dow);
    reg[4] = bin2bcd(ct.day);
    reg[5] = bin2bcd(ct.mon);
    if (ct.year >= 2000)             /* Set century bit*/
    {
	reg[5] |= 0x80;
    }
    reg[6] = bin2bcd(ct.year % 100);

    /* Lockless write: detects the infrequent roll-over and retries */
    for(retry=0; retry<2; retry++)
    {
	rc = 0;
	for(i=0; i<7; i++)
	{
	    rc |= cvmx_twsi_write8(CVMX_RTC_DS1337_ADDR, i, reg[i]);
	}

	sec = cvmx_twsi_read8(CVMX_RTC_DS1337_ADDR, 0x0);
	if ((sec & 0xf) == (reg[0] & 0xf))
	    break; /* Time did not roll-over, value is correct */
    }

    return (rc ? -1 : 0);

 ct_invalid:
    return -1;
}
Esempio n. 21
0
static void m41t11_settime(struct rtc_time *rtime)
{
	down(&m41t11_mutex);
	m41t11_writebyte(M41T11_YEAR, bin2bcd(rtime->tm_year));
	m41t11_writebyte(M41T11_MON, bin2bcd(rtime->tm_mon+1));
	m41t11_writebyte(M41T11_MDAY, bin2bcd(rtime->tm_mday));
	m41t11_writebyte(M41T11_WDAY, bin2bcd(rtime->tm_wday+1));
	m41t11_writebyte(M41T11_HOUR, bin2bcd(rtime->tm_hour) |
		((rtime->tm_year > 99) ? 0xc0 : 0x80));
	m41t11_writebyte(M41T11_MIN, bin2bcd(rtime->tm_min));
	m41t11_writebyte(M41T11_SEC, bin2bcd(rtime->tm_sec));
	m41t11_writebyte(M41T11_FTOUT, 0x90);
	up(&m41t11_mutex);
}
Esempio n. 22
0
void RTC_DS1388::adjust(const DateTime& dt) {
  Wire.beginTransmission(DS1307_ADDRESS);
  Wire.write((byte) 0);
  Wire.write(bin2bcd(0)); // hundreds of seconds 0x00
  Wire.write(bin2bcd(dt.second())); // 0x01
  Wire.write(bin2bcd(dt.minute())); // 0x02
  Wire.write(bin2bcd(dt.hour())); // 0x03
  Wire.write(bin2bcd(0)); // 0x04
  Wire.write(bin2bcd(dt.day())); // 0x05
  Wire.write(bin2bcd(dt.month())); // 0x06
  Wire.write(bin2bcd(dt.year() - 2000)); // 0x07
  Wire.endTransmission();

  Wire.beginTransmission(DS1307_ADDRESS);
  Wire.write((byte) 0x0b);
  Wire.write((byte) 0x00);			//clear the 'time is invalid ' flag bit (OSF)
  Wire.endTransmission();
}
Esempio n. 23
0
void rtc_set (struct rtc_time *tmp)
{

	debug ( "Set DATE: %4d-%02d-%02d (wday=%d)  TIME: %2d:%02d:%02d\n",
		tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
		tmp->tm_hour, tmp->tm_min, tmp->tm_sec);

	rtc_write (0x9E, 0x00);
	rtc_write (0x80, 0);	/* Clear seconds to ensure no rollover */
	rtc_write (0x92, bin2bcd(tmp->tm_year / 100));
	rtc_write (0x8c, bin2bcd(tmp->tm_year % 100));
	rtc_write (0x8a, bin2bcd(tmp->tm_wday));
	rtc_write (0x88, bin2bcd(tmp->tm_mon));
	rtc_write (0x86, bin2bcd(tmp->tm_mday));
	rtc_write (0x84, bin2bcd(tmp->tm_hour));
	rtc_write (0x82, bin2bcd(tmp->tm_min ));
	rtc_write (0x80, bin2bcd(tmp->tm_sec ));
}
Esempio n. 24
0
static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
{
	struct rtc_time *tm = &alrm->time;
	void __iomem *base = s3c_rtc_base;
	unsigned int alrm_en;

	int year = tm->tm_year - 100;

	pr_debug("s3c_rtc_setalarm: %d, %02x/%02x/%02x %02x.%02x.%02x\n",
		 alrm->enabled,
		 tm->tm_mday & 0xff, tm->tm_mon & 0xff, tm->tm_year & 0xff,
		 tm->tm_hour & 0xff, tm->tm_min & 0xff, tm->tm_sec);

	alrm_en = readb(base + S3C2410_RTCALM) & S3C2410_RTCALM_ALMEN;
	writeb(0x00, base + S3C2410_RTCALM);

	if (tm->tm_sec < 60 && tm->tm_sec >= 0) {
		alrm_en |= S3C2410_RTCALM_SECEN;
		writeb(bin2bcd(tm->tm_sec), base + S3C2410_ALMSEC);
	}

	if (tm->tm_min < 60 && tm->tm_min >= 0) {
		alrm_en |= S3C2410_RTCALM_MINEN;
		writeb(bin2bcd(tm->tm_min), base + S3C2410_ALMMIN);
	}

	if (tm->tm_hour < 24 && tm->tm_hour >= 0) {
		alrm_en |= S3C2410_RTCALM_HOUREN;
		writeb(bin2bcd(tm->tm_hour), base + S3C2410_ALMHOUR);
	}

	if (tm->tm_mday >= 0) {
		alrm_en |= S3C2410_RTCALM_DAYEN;
		writeb(bin2bcd(tm->tm_mday), base + S3C2410_ALMDATE);
	}

	if (tm->tm_mon < 13 && tm->tm_mon >= 0) {
		alrm_en |= S3C2410_RTCALM_MONEN;
		writeb(bin2bcd(tm->tm_mon + 1), base + S3C2410_ALMMON);
	}

	if (year < 100 && year >= 0) {
		alrm_en |= S3C2410_RTCALM_YEAREN;
		writeb(bin2bcd(year), base + S3C2410_ALMYEAR);
	}

	pr_debug("setting S3C2410_RTCALM to %08x\n", alrm_en);

	writeb(alrm_en, base + S3C2410_RTCALM);

	s3c_rtc_setaie(alrm->enabled);

	return 0;
}
Esempio n. 25
0
static void tm_to_regs(struct rtc_time *tm, u8 *regs)
{
	u8 high, low;

	high = (tm->tm_year + 1900) / 100;
	low = tm->tm_year % 100;
	regs[RTC_YEAR2] = bin2bcd(high);
	regs[RTC_YEAR1] = bin2bcd(low);
	regs[RTC_MONTH] = bin2bcd(tm->tm_mon + 1);
	regs[RTC_DATE] = bin2bcd(tm->tm_mday);
	regs[RTC_WEEKDAY] = tm->tm_wday + 1;
	regs[RTC_HOUR] = bin2bcd(tm->tm_hour);
	regs[RTC_MIN] = bin2bcd(tm->tm_min);
	regs[RTC_SEC] = bin2bcd(tm->tm_sec);
}
Esempio n. 26
0
int rtc_set(const struct rtc_time *time)
{
	as3722rtc_init();

	as3722_write(AS3722_RTC_SECOND, bin2bcd(time->sec));
	as3722_write(AS3722_RTC_MINUTE, bin2bcd(time->min));
	as3722_write(AS3722_RTC_HOUR, bin2bcd(time->hour));
	as3722_write(AS3722_RTC_DAY, bin2bcd(time->mday));
	as3722_write(AS3722_RTC_MONTH, bin2bcd(time->mon));
	as3722_write(AS3722_RTC_YEAR, bin2bcd(time->year));
	return 0;
}
Esempio n. 27
0
/*
 * Board-specific RTC write
 * Time returned is in seconds from epoch (Jan 1 1970 at 00:00:00 UTC)
 */
int cvmx_rtc_ds1337_write(uint32_t time)
{
    int       i, rc, retry;
    struct tm tms;
    uint8_t   reg[8];
    uint8_t   sec;
    time_t    time_from_epoch = time;


    localtime_r(&time_from_epoch, &tms);

    if (validate_tm_struct(&tms))
    {
	cvmx_dprintf("Error: RTC was passed wrong calendar values, write failed\n");
	goto tm_invalid;
    }

    reg[0] = bin2bcd(tms.tm_sec);
    reg[1] = bin2bcd(tms.tm_min);
    reg[2] = bin2bcd(tms.tm_hour);      /* Force 0..23 format even if using AM/PM */
    reg[3] = bin2bcd(tms.tm_wday + 1);
    reg[4] = bin2bcd(tms.tm_mday);
    reg[5] = bin2bcd(tms.tm_mon + 1);
    if (tms.tm_year >= 100)             /* Set century bit*/
    {
	reg[5] |= 0x80;
    }
    reg[6] = bin2bcd(tms.tm_year % 100);

    /* Lockless write: detects the infrequent roll-over and retries */
    for(retry=0; retry<2; retry++)
    {
	rc = 0;
	for(i=0; i<7; i++)
	{
	    rc |= cvmx_twsi_write8(CVMX_RTC_DS1337_ADDR, i, reg[i]);
	}

	sec = cvmx_twsi_read8(CVMX_RTC_DS1337_ADDR, 0x0);
	if ((sec & 0xf) == (reg[0] & 0xf))
	    break; /* Time did not roll-over, value is correct */
    }

    return (rc ? -1 : 0);

 tm_invalid:
    return -1;
}
Esempio n. 28
0
void ds1302_set_time(RTC_TIME_t *tm)
{
    /* Stop RTC */
    ds1302_write(DS1302_SEC, ds1302_read(DS1302_SEC) | 0x80);

    ds1302_write(DS1302_SEC,  bin2bcd(tm->tm_sec));
    ds1302_write(DS1302_MIN,  bin2bcd(tm->tm_min));
    ds1302_write(DS1302_HOUR, bin2bcd(tm->tm_hour));
    ds1302_write(DS1302_DAY,  bin2bcd(tm->tm_wday));
    ds1302_write(DS1302_DATE, bin2bcd(tm->tm_mday));
    ds1302_write(DS1302_MON,  bin2bcd(tm->tm_mon + 1));
    ds1302_write(DS1302_YEAR, bin2bcd(tm->tm_year % 100));

    /* Start RTC */
    ds1302_write(DS1302_SEC, ds1302_read(DS1302_SEC) & ~0x80);
}
Esempio n. 29
0
void RTC_DS3231::adjust(const DateTime& dt) {
  Wire.beginTransmission(DS3231_ADDRESS);
  Wire._I2C_WRITE((byte)0); // start at location 0
  Wire._I2C_WRITE(bin2bcd(dt.second()));
  Wire._I2C_WRITE(bin2bcd(dt.minute()));
  Wire._I2C_WRITE(bin2bcd(dt.hour()));
  Wire._I2C_WRITE(bin2bcd(0));
  Wire._I2C_WRITE(bin2bcd(dt.day()));
  Wire._I2C_WRITE(bin2bcd(dt.month()));
  Wire._I2C_WRITE(bin2bcd(dt.year() - 2000));
  Wire.endTransmission();

  uint8_t statreg = read_i2c_register(DS3231_ADDRESS, DS3231_STATUSREG);
  statreg &= ~0x80; // flip OSF bit
  write_i2c_register(DS3231_ADDRESS, DS3231_STATUSREG, statreg);
}
Esempio n. 30
0
void RTC_DS1307::adjust(const DateTime& dt) {
    Wire.beginTransmission(DS1307_ADDRESS);
    Wire.WIRE_WRITE(0);
    Wire.WIRE_WRITE(bin2bcd(dt.second()));
    Wire.WIRE_WRITE(bin2bcd(dt.minute()));
    Wire.WIRE_WRITE(bin2bcd(dt.hour()));
    Wire.WIRE_WRITE(bin2bcd(0));
    Wire.WIRE_WRITE(bin2bcd(dt.day()));
    Wire.WIRE_WRITE(bin2bcd(dt.month()));
    Wire.WIRE_WRITE(bin2bcd(dt.year() - 2000));
    Wire.WIRE_WRITE(0);
    Wire.endTransmission();
    
    prevUnixtime = dt.unixtime();
    prevMillis = millis();
}