예제 #1
0
파일: rtc.c 프로젝트: canistation/coreboot
/* initialize rtc setting of using dcxo clock */
static int rtc_enable_dcxo(void)
{
	u16 bbpu, con, osc32con, sec;

	rtc_read(RTC_BBPU, &bbpu);
	rtc_write(RTC_BBPU, bbpu | RTC_BBPU_KEY | RTC_BBPU_RELOAD);
	rtc_write_trigger();

	mdelay(1);
	if (!rtc_writeif_unlock()) { /* Unlock for reload */
		rtc_info("rtc_writeif_unlock() fail\n");
		return 0;
	}

	rtc_read(RTC_OSC32CON, &osc32con);
	osc32con &= ~RTC_EMBCK_SRC_SEL;
	osc32con |= RTC_XOSC32_ENB | RTC_REG_XOSC32_ENB;
	if (!rtc_xosc_write(osc32con)) {
		rtc_info("rtc_xosc_write() fail\n");
		return 0;
	}
	rtc_read(RTC_BBPU, &bbpu);
	rtc_write(RTC_BBPU, bbpu | RTC_BBPU_KEY | RTC_BBPU_RELOAD);
	rtc_write_trigger();

	rtc_read(RTC_CON, &con);
	rtc_read(RTC_OSC32CON, &osc32con);
	rtc_read(RTC_AL_SEC, &sec);
	rtc_info("con=0x%x, osc32con=0x%x, sec=0x%x\n", con, osc32con, sec);

	return 1;
}
예제 #2
0
void rtc_gpio_disable_32k(rtc_gpio_user_t user)
{
	u16 con, pdn1;
	unsigned long flags;

	if (user < RTC_GPIO_USER_WIFI || user > RTC_GPIO_USER_FM)
		return;

	spin_lock_irqsave(&rtc_lock, flags);
	pdn1 = rtc_read(RTC_PDN1) & ~(1U << user);
	rtc_write(RTC_PDN1, pdn1);
	rtc_write_trigger();

	if (!(pdn1 & RTC_GPIO_USER_MASK)) {	/* no users */
		if (get_chip_eco_ver() == CHIP_E1) {
			/* keep exporting 32K to avoid f32k_ck drift */
		} else {
			con = rtc_read(RTC_CON) | RTC_CON_F32KOB;
			rtc_write(RTC_CON, con);
			rtc_write_trigger();

			con = rtc_read(RTC_OSC32CON) & ~RTC_OSC32CON_GPIOCKEN;
			rtc_xosc_write(con, true);
		}
	}
	spin_unlock_irqrestore(&rtc_lock, flags);

	printk(RTC_SAY "RTC_GPIO user %d disables 32k (0x%x)\n", user, pdn1);
}
예제 #3
0
void rtc_gpio_enable_32k(rtc_gpio_user_t user)
{
	u16 con, pdn1;
	unsigned long flags;

	if (user < RTC_GPIO_USER_WIFI || user > RTC_GPIO_USER_FM)
		return;

	spin_lock_irqsave(&rtc_lock, flags);
	pdn1 = rtc_read(RTC_PDN1);
	if (!(pdn1 & RTC_GPIO_USER_MASK)) {	/* first user */
		con = rtc_read(RTC_OSC32CON) | RTC_OSC32CON_GPIOCKEN;
		rtc_xosc_write(con, true);

		con = rtc_read(RTC_CON) & ~RTC_CON_F32KOB;
		rtc_write(RTC_CON, con);
		rtc_write_trigger();
	}

	pdn1 |= (1U << user);
	rtc_write(RTC_PDN1, pdn1);
	rtc_write_trigger();
	spin_unlock_irqrestore(&rtc_lock, flags);

	printk(RTC_SAY "RTC_GPIO user %d enables 32k (0x%x)\n", user, pdn1);
}
예제 #4
0
void rtc_bbpu_power_down(void)
{
	u16 bbpu, con;
	unsigned long flags;

	spin_lock_irqsave(&rtc_lock, flags);
	rtc_writeif_unlock();

	/* disable 32K export if there are no RTC_GPIO users */
	if (!(rtc_read(RTC_PDN1) & RTC_GPIO_USER_MASK)) {
		con = rtc_read(RTC_CON) | RTC_CON_F32KOB;
		rtc_write(RTC_CON, con);
		rtc_write_trigger();

		con = rtc_read(RTC_OSC32CON) & ~RTC_OSC32CON_GPIOCKEN;
		rtc_xosc_write(con, false);
	}

	/* pull PWRBB low */
	bbpu = RTC_BBPU_KEY | RTC_BBPU_AUTO | RTC_BBPU_PWREN;
	rtc_write(RTC_BBPU, bbpu);
	rtc_write_trigger();
	spin_unlock_irqrestore(&rtc_lock, flags);
}