Exemplo n.º 1
0
void rtc_reset (void)
{
	rtc_write8(RTC_CONFIG_B, 0x82); /* disable the RTC to update the regs */
	rtc_write8(RTC_CONFIG_A, 0x20); /* Normal OP */
	rtc_write8(RTC_CONFIG_B, 0x00);
	rtc_write8(RTC_CONFIG_B, 0x00);
	rtc_write8(RTC_CONFIG_B, 0x02); /* enable the RTC to update the regs */
}
Exemplo n.º 2
0
static int write_seeds_to_cmos(struct pei_data *pei_data)
{
	u16 c1, c2, checksum;
	struct udevice *dev;
	int ret = 0;

	ret = uclass_get_device(UCLASS_RTC, 0, &dev);
	if (ret) {
		debug("Cannot find RTC: err=%d\n", ret);
		return -ENODEV;
	}

	/* Save the MRC seed values to CMOS */
	rtc_write32(dev, CMOS_OFFSET_MRC_SEED, pei_data->scrambler_seed);
	debug("Save scrambler seed    0x%08x to CMOS 0x%02x\n",
	      pei_data->scrambler_seed, CMOS_OFFSET_MRC_SEED);

	rtc_write32(dev, CMOS_OFFSET_MRC_SEED_S3, pei_data->scrambler_seed_s3);
	debug("Save s3 scrambler seed 0x%08x to CMOS 0x%02x\n",
	      pei_data->scrambler_seed_s3, CMOS_OFFSET_MRC_SEED_S3);

	/* Save a simple checksum of the seed values */
	c1 = compute_ip_checksum((u8 *)&pei_data->scrambler_seed,
				 sizeof(u32));
	c2 = compute_ip_checksum((u8 *)&pei_data->scrambler_seed_s3,
				 sizeof(u32));
	checksum = add_ip_checksums(sizeof(u32), c1, c2);

	rtc_write8(dev, CMOS_OFFSET_MRC_SEED_CHK, checksum & 0xff);
	rtc_write8(dev, CMOS_OFFSET_MRC_SEED_CHK + 1, (checksum >> 8) & 0xff);

	return 0;
}
Exemplo n.º 3
0
int rtc_set (struct rtc_time *tmp)
{
#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
	rtc_write8(RTC_CONFIG_B, 0x82); /* disable the RTC to update the regs */

	rtc_write8(RTC_YEAR, bin2bcd(tmp->tm_year % 100));
	rtc_write8(RTC_MONTH, bin2bcd(tmp->tm_mon));
	rtc_write8(RTC_DAY_OF_WEEK, bin2bcd(tmp->tm_wday));
	rtc_write8(RTC_DATE_OF_MONTH, bin2bcd(tmp->tm_mday));
	rtc_write8(RTC_HOURS, bin2bcd(tmp->tm_hour));
	rtc_write8(RTC_MINUTES, bin2bcd(tmp->tm_min));
	rtc_write8(RTC_SECONDS, bin2bcd(tmp->tm_sec));
	rtc_write8(RTC_CONFIG_B, 0x02); /* enable the RTC to update the regs */

	return 0;
}
Exemplo n.º 4
0
static void mc146818_init(void)
{
#if CLEAR_CMOS
	int i;

	rtc_write8(RTC_SECONDS_ALARM, 0);
	rtc_write8(RTC_MINUTES_ALARM, 0);
	rtc_write8(RTC_HOURS_ALARM, 0);
	for (i = RTC_CONFIG_A; i < RTC_REG_SIZE; i++)
		rtc_write8(i, 0);
	printf("RTC: zeroing CMOS RAM\n");
#endif

	/* Setup the real time clock */
	mc146818_write8(RTC_CONFIG_B, RTC_CONFIG_B_24H);
	/* Setup the frequency it operates at */
	mc146818_write8(RTC_CONFIG_A, RTC_CONFIG_A_REF_CLCK_32KHZ |
			RTC_CONFIG_A_RATE_1024HZ);
	/* Ensure all reserved bits are 0 in register D */
	mc146818_write8(RTC_CONFIG_D, RTC_CONFIG_D_VALID_RAM_AND_TIME);

	/* Clear any pending interrupts */
	mc146818_read8(RTC_CONFIG_C);
}