unsigned long
rtc_time_ds1386(paddr_t base, unsigned reg_shift, int mmap, int cent_reg) {
	struct tm	tm;
	unsigned	cent;

	//Tell Neutrino what kind of chip for 'rtc' utility
	hwi_add_rtc("ds1386", base, reg_shift, 16, mmap, cent_reg);

	chip_access(base, reg_shift, mmap, 16);

   	do {
		// convert BCD to binary 
		tm.tm_sec 	= bcd2bin(chip_read8(1));		// seconds
		tm.tm_min 	= bcd2bin(chip_read8(2));		// minutes
		tm.tm_hour	= bcd2bin(chip_read8(4) & 0x3f);	// hours
		tm.tm_mday	= bcd2bin(chip_read8(8));		// day
		tm.tm_mon	= bcd2bin(chip_read8(9) & 0x3f) - 1;	// month
		tm.tm_year	= bcd2bin(chip_read8(10));		// year

		//Loop while time inconsistent
	} while(tm.tm_sec != bcd2bin(chip_read8(1)));

	if(cent_reg >= 0) {
		cent = bcd2bin(chip_read8(cent_reg));		// century
		if(cent == 20) tm.tm_year += 100;
	} else if(tm.tm_year < 70) {
		tm.tm_year += 100;
	}

	chip_done();


	return(calc_time_t(&tm));
}
void
init_8250(unsigned channel, const char *init, const char *defaults) {
    unsigned long 	baud;
    unsigned long	div;
    unsigned long	clk;
    paddr_t			base;
    unsigned		shift;

    baud = 0;
    parse_line(channel, defaults, &baud, &clk, &div);
    parse_line(channel, init, &baud, &clk, &div);

    base = dbg_device[channel].base;
    shift = dbg_device[channel].shift;
    chip_access(base, shift, 0, REG_MS);

    // Wait for all pending characters to be output...
    do {
    } while(!(chip_read8(REG_LS) & LSR_TSRE));

    if(baud != 0) {
        unsigned count = clk / (baud * div);

        // Program divisor latch
        chip_write8(REG_LC, LCR_DLAB);
        chip_write8(REG_DL0, count & 0xff);
        chip_write8(REG_DL1, count >> 8);
        chip_write8(REG_LC, 0x03);
    }
Beispiel #3
0
unsigned long
rtc_time_s3c2410(unsigned base)
{
	struct tm	tm;

	hwi_add_device(HWI_ITEM_BUS_UNKNOWN, HWI_ITEM_DEVCLASS_RTC, "s3c2410", 0);
	hwi_add_location(base, S3C2410_RTC_SIZE, 0, hwi_find_as(base, 1));

	// get the current time from the RTC, and convert it to seconds since epoch

    chip_access(base, 0, 0, S3C2410_RTC_SIZE);

	// enable RTC 
	chip_write8(S3C2410_RTCCON, chip_read8(S3C2410_RTCCON) | 1);

    // convert BCD to binary
    tm.tm_sec  = bcd2bin(chip_read8(S3C2410_BCDSEC) & 0xff);    // seconds
    tm.tm_min  = bcd2bin(chip_read8(S3C2410_BCDMIN) & 0xff);    // minutes
    tm.tm_hour = bcd2bin(chip_read8(S3C2410_BCDHOUR) & 0xff);   // hours
    tm.tm_mday = bcd2bin(chip_read8(S3C2410_BCDDAY) & 0xff);    // day
    tm.tm_mon  = bcd2bin(chip_read8(S3C2410_BCDMON) & 0xff) -1;    // month
    tm.tm_year = (bcd2bin(chip_read8(S3C2410_BCDYEAR) & 0xff))+100;   // year

    chip_done();

    return(calc_time_t(&tm));

}
int
RTCFUNC(set,ds1386)(struct tm *tm, int cent_reg) {
	unsigned	seconds;
	unsigned	minutes;
	unsigned	hours;
	unsigned	day;
	unsigned	month;
	unsigned	year;
	unsigned	cent;

	// convert binary to BCD
	seconds	= BIN2BCD(tm->tm_sec);
	minutes	= BIN2BCD(tm->tm_min);
	hours	= BIN2BCD(tm->tm_hour);
	day 	= BIN2BCD(tm->tm_mday);
	month	= BIN2BCD(tm->tm_mon + 1);
	year	= BIN2BCD(tm->tm_year % 100);
	cent	= BIN2BCD((tm->tm_year / 100) + 19);

#ifdef DIAG
	fprintf(stderr,"rtc set: cent=%d; year=%d (after adjustment)\n",cent,year);
#endif

	month |= chip_read8(9) & 0x40;	/* ESQW# */

	chip_write8(9, 0);	/* turn off clock */

	chip_write8(0, 0);	//hundredth's of second
	chip_write8(1, seconds);
	chip_write8(2, minutes);
	chip_write8(4, hours | MILTIME);
	chip_write8(6, tm->tm_wday + 1);
	chip_write8(8, day);
	chip_write8(10, year);
	if(cent_reg >= 0) {
		chip_write8(cent_reg, cent);
	}

	chip_write8(9, month & 0x5f);	/* EOSC# low to start clock */
	chip_write8(CMD_REG, chip_read8(CMD_REG) | TRANSFER_ENABLE);

	return(0);
}
Beispiel #5
0
static	unsigned
cmos(unsigned i) {
	unsigned temp;

	_disable();		
	chip_write8(0,i);
	temp = chip_read8(1);
	_enable();		
	return(temp);
}
Beispiel #6
0
int
RTCFUNC(set,ds15x1)(struct tm *tm, int cent_reg) {
	unsigned	seconds;
	unsigned	minutes;
	unsigned	hours;
	unsigned	day;
	unsigned	month;
	unsigned	year;
	unsigned	cent;
	unsigned	ctrlb;

	/* convert binary to BCD */
	seconds	= BIN2BCD(tm->tm_sec);
	minutes	= BIN2BCD(tm->tm_min);
	hours	= BIN2BCD(tm->tm_hour);
	day 	= BIN2BCD(tm->tm_mday);
	month	= BIN2BCD(tm->tm_mon + 1);
	year	= BIN2BCD(tm->tm_year % 100);
	cent	= BIN2BCD((tm->tm_year / 100) + 19);

#ifdef DIAG
	fprintf(stderr,"rtc set: cent=%d; year=%d (after adjustment)\n",cent,year);
#endif

	month |= chip_read8(5) & 0xE0;	/* EOSC#/E32K#/BB32 */

	ctrlb = chip_read8(DS15x1_CONTROLB);
	chip_write8(DS15x1_CONTROLB, ctrlb & ~TRANSFER_ENABLE);

	chip_write8(0, seconds);
	chip_write8(1, minutes);
	chip_write8(2, hours);
	chip_write8(3, tm->tm_wday + 1);
	chip_write8(4, day);
	chip_write8(5, month);
	chip_write8(6, year);
	if (cent_reg >= 0)
		chip_write8(cent_reg, cent);

	chip_write8(DS15x1_CONTROLB, ctrlb | TRANSFER_ENABLE);

	return (0);
}
Beispiel #7
0
int
RTCFUNC(get,ds15x1)(struct tm *tm, int cent_reg) {
	unsigned	cent;
	unsigned	sec;
	unsigned	min;
	unsigned	hour;
	unsigned	mday;
	unsigned	mon;
	unsigned	year;
	unsigned	ctrlb;

	ctrlb = chip_read8(DS15x1_CONTROLB);
	if (!(ctrlb & TRANSFER_ENABLE)) {
		struct timespec	cur;

		chip_write8(DS15x1_CONTROLB, ctrlb | TRANSFER_ENABLE);
		cur.tv_sec = 0;
		cur.tv_nsec = 10000000;
		nanosleep(&cur, NULL); 	/* wait 0.01 sec for update */
	}

	chip_write8(DS15x1_CONTROLB, ctrlb & ~TRANSFER_ENABLE);
	
	/* convert BCD to binary */
	sec  = chip_read8(0);
	min  = chip_read8(1);
	hour = chip_read8(2);
	mday = chip_read8(4);
	mon  = chip_read8(5) & 0x1F;
	year = chip_read8(6);

	tm->tm_sec 	= BCD2BIN(sec);
	tm->tm_min 	= BCD2BIN(min);
	tm->tm_hour	= BCD2BIN(hour);
	tm->tm_mday	= BCD2BIN(mday);
	tm->tm_mon	= BCD2BIN(mon) - 1;
	tm->tm_year	= BCD2BIN(year);
	if (cent_reg >= 0) {
		cent	= chip_read8(cent_reg);	/* century */
		if (cent == 0x20)
			tm->tm_year += 100;
	} else if (tm->tm_year < 70)
		tm->tm_year += 100;

	chip_write8(DS15x1_CONTROLB, ctrlb | TRANSFER_ENABLE);

#ifdef DIAG
	fprintf(stderr,"rtc read: cent=%d; year=%d\n",cent,tm->tm_year);
#endif

	return(0);
}
    // Wait for all pending characters to be output...
    do {
    } while(!(chip_read8(REG_LS) & LSR_TSRE));

    if(baud != 0) {
        unsigned count = clk / (baud * div);

        // Program divisor latch
        chip_write8(REG_LC, LCR_DLAB);
        chip_write8(REG_DL0, count & 0xff);
        chip_write8(REG_DL1, count >> 8);
        chip_write8(REG_LC, 0x03);
    }

    // 8 bits no parity
    chip_write8(REG_MC, (chip_read8(REG_MC) & 0xE4) | MCR_DTR|MCR_RTS|MCR_OUT2);
    chip_done();
}

void
put_8250(int c) {
    paddr_t		base;
    unsigned	shift;

    base = dbg_device[0].base;
    shift = dbg_device[0].shift;
    chip_access(base, shift, 0, REG_MS);
    do {
    } while(!(chip_read8(REG_LS) & LSR_TXRDY));
    chip_write8(REG_TX, c);
    chip_done();
int
RTCFUNC(get,ds1386)(struct tm *tm, int cent_reg) {
	unsigned	cent;
	unsigned	sec;
	unsigned	min;
	unsigned	hour;
	unsigned	mday;
	unsigned	mon;
	unsigned	year;
	

	if(!(chip_read8(CMD_REG) & TRANSFER_ENABLE)) {
		struct timespec	cur;

		chip_write8(CMD_REG, chip_read8(CMD_REG) | TRANSFER_ENABLE);
		cur.tv_sec = 0;
		cur.tv_nsec = 10000000;
		nanosleep(&cur, NULL); 	/* wait 0.01 sec for update */
	}

	chip_write8(CMD_REG, chip_read8(CMD_REG) & ~TRANSFER_ENABLE);
	
	// convert BCD to binary 
	sec 	= chip_read8(1);		// seconds
	min 	= chip_read8(2);		// minutes
	hour	= chip_read8(4) & 0x3f;	// hours
	mday	= chip_read8(8);		// day
	mon		= chip_read8(9) & 0x3f;	// month
	year	= chip_read8(10);		// year

	tm->tm_sec 	= BCD2BIN(sec);
	tm->tm_min 	= BCD2BIN(min);
	tm->tm_hour	= BCD2BIN(hour);
	tm->tm_mday	= BCD2BIN(mday);
	tm->tm_mon	= BCD2BIN(mon) - 1;
	tm->tm_year	= BCD2BIN(year);
	if(cent_reg >= 0) {
		cent	= chip_read8(cent_reg);	// century
		cent	= BCD2BIN(cent);
		if(cent == 20) tm->tm_year += 100;
	} else if(tm->tm_year < 70) {
		tm->tm_year += 100;
	}

	chip_write8(CMD_REG, chip_read8(CMD_REG) | TRANSFER_ENABLE);

#ifdef DIAG
	fprintf(stderr,"rtc read: cent=%d; year=%d\n",cent,tm->tm_year);
#endif

	return(0);
}
Beispiel #10
0
unsigned long
rtc_time_ds1743(paddr_t base, unsigned reg_shift, int mmap, int cent_reg) {
	struct tm	tm;
	unsigned	cent;
	unsigned	reg;

	//Tell Neutrino what kind of chip for 'rtc' utility
	hwi_add_rtc("ds1743", base, reg_shift, DS1743_YEAR+1, mmap, -1);

	chip_access(base, reg_shift, mmap, DS1743_YEAR+1);

	// Stop the chip from updating
	chip_write8(DS1743_CONTROL, chip_read8(DS1743_CONTROL) | DS1743_CONTROL_R);

	reg = chip_read8(DS1743_SECONDS);
	if(reg & DS1743_SECONDS_OSC) {
		// clock oscillator not running
		chip_write8(DS1743_SECONDS, reg & ~DS1743_SECONDS_OSC);
	}
	reg = chip_read8(DS1743_DAY);
	if(reg & DS1743_DAY_FT) {
		// need to turn off frequency test mode
		chip_write8(DS1743_DAY, reg & ~DS1743_DAY_FT);
	}

	// convert BCD to binary 
	tm.tm_sec 	= bcd2bin(chip_read8(DS1743_SECONDS) & DS1743_SECONDS_MASK);
	tm.tm_min 	= bcd2bin(chip_read8(DS1743_MINUTES) & DS1743_MINUTES_MASK);
	tm.tm_hour	= bcd2bin(chip_read8(DS1743_HOUR) & DS1743_HOUR_MASK);
	tm.tm_mday	= bcd2bin(chip_read8(DS1743_DATE) & DS1743_DATE_MASK);
	tm.tm_mon	= bcd2bin(chip_read8(DS1743_MONTH) & DS1743_MONTH_MASK) - 1;
	tm.tm_year	= bcd2bin(chip_read8(DS1743_YEAR));
	cent		= bcd2bin(chip_read8(DS1743_CONTROL) & DS1743_CONTROL_CENT_MASK);

	// Start the chip updating again
	chip_write8(DS1743_CONTROL, chip_read8(DS1743_CONTROL) & ~DS1743_CONTROL_R);

	tm.tm_year += (cent-19) * 100;

	chip_done();

	return(calc_time_t(&tm));
}
static int
rdcmos(unsigned i) {
 	return(chip_read8(i));
}
Beispiel #12
0
static int
rdcmos(unsigned i) {
	chip_write8(0, i);			//CMOS addr reg
	return(chip_read8(1));		//CMOS data reg
}
unsigned long
rtc_time_rtc72423(paddr_t base, unsigned reg_shift, int mmap, int cent_reg) {
	struct tm	tm;
	unsigned	bottom;

	//Tell Neutrino what kind of chip for 'rtc' utility
	hwi_add_rtc("rtc72423", base, reg_shift, 16, mmap, cent_reg);

	chip_access(base, reg_shift, mmap, 16);

   	do {
		// get the data
		bottom = chip_read8(0);
		tm.tm_sec	= bcd2bin((chip_read8(1)  <<4) | bottom);
		tm.tm_min	= bcd2bin((chip_read8(3)  <<4) | chip_read8(2));
		tm.tm_hour	= bcd2bin(((chip_read8(5) & 3)  <<4) | chip_read8(4));
		tm.tm_mday	= bcd2bin((chip_read8(7)  <<4) | chip_read8(6));
		tm.tm_mon	= bcd2bin((chip_read8(9)  <<4) | chip_read8(8));
		tm.tm_year	= bcd2bin((chip_read8(11) <<4) | chip_read8(10));

		//Loop while time inconsistent
	} while(bottom != chip_read8(0));

	chip_done();

	if(tm.tm_year < 70) tm.tm_year += 100;
	return(calc_time_t(&tm));
}