soc/mediatek: rtc: Use `bool` as return type

BUG=b:176307061
TEST=emerge-asurada coreboot; emerge-kukui coreboot emerge-oak coreboot
     boot to shell on Asurada

Signed-off-by: Yidi Lin <yidi.lin@mediatek.com>
Change-Id: Id31fa04edc2920c1767d9f08ab7af0ab4a15bc24
Reviewed-on: https://review.coreboot.org/c/coreboot/+/49137
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Yu-Ping Wu <yupingso@google.com>
This commit is contained in:
Yidi Lin 2021-01-06 15:27:13 +08:00 committed by Hung-Te Lin
parent 9990a17200
commit 54f8b9ee74
8 changed files with 61 additions and 58 deletions

View File

@ -6,6 +6,7 @@
#include <bcd.h> #include <bcd.h>
#include <console/console.h> #include <console/console.h>
#include <rtc.h> #include <rtc.h>
#include <stdbool.h>
#define RTCTAG "[RTC]" #define RTCTAG "[RTC]"
#define rtc_info(fmt, arg ...) printk(BIOS_INFO, RTCTAG "%s,%d: " fmt, \ #define rtc_info(fmt, arg ...) printk(BIOS_INFO, RTCTAG "%s,%d: " fmt, \
@ -94,14 +95,13 @@ enum {
}; };
/* external API */ /* external API */
int rtc_busy_wait(void); bool rtc_write_trigger(void);
int rtc_write_trigger(void); bool rtc_writeif_unlock(void);
int rtc_writeif_unlock(void); bool rtc_xosc_write(u16 val);
int rtc_xosc_write(u16 val); bool rtc_lpen(u16 con);
int rtc_lpen(u16 con); bool rtc_reg_init(void);
int rtc_reg_init(void);
void rtc_osc_init(void); void rtc_osc_init(void);
int rtc_powerkey_init(void); bool rtc_powerkey_init(void);
void rtc_boot_common(void); void rtc_boot_common(void);
#endif /* SOC_MEDIATEK_RTC_COMMON_H */ #endif /* SOC_MEDIATEK_RTC_COMMON_H */

View File

@ -5,7 +5,7 @@
#include <timer.h> #include <timer.h>
/* ensure rtc write success */ /* ensure rtc write success */
int rtc_busy_wait(void) static bool rtc_busy_wait(void)
{ {
struct stopwatch sw; struct stopwatch sw;
u16 bbpu; u16 bbpu;
@ -17,30 +17,30 @@ int rtc_busy_wait(void)
/* Time > 1sec, time out and set recovery mode enable.*/ /* Time > 1sec, time out and set recovery mode enable.*/
if (stopwatch_expired(&sw)) { if (stopwatch_expired(&sw)) {
rtc_info("BBPU CBUSY time out !!\n"); rtc_info("BBPU CBUSY time out !!\n");
return 0; return false;
} }
} while (bbpu & RTC_BBPU_CBUSY); } while (bbpu & RTC_BBPU_CBUSY);
return 1; return true;
} }
int rtc_write_trigger(void) bool rtc_write_trigger(void)
{ {
rtc_write(RTC_WRTGR, 1); rtc_write(RTC_WRTGR, 1);
return rtc_busy_wait(); return rtc_busy_wait();
} }
/* unlock rtc write interface */ /* unlock rtc write interface */
int rtc_writeif_unlock(void) bool rtc_writeif_unlock(void)
{ {
rtc_write(RTC_PROT, RTC_PROT_UNLOCK1); rtc_write(RTC_PROT, RTC_PROT_UNLOCK1);
if (!rtc_write_trigger()) if (!rtc_write_trigger())
return 0; return false;
rtc_write(RTC_PROT, RTC_PROT_UNLOCK2); rtc_write(RTC_PROT, RTC_PROT_UNLOCK2);
if (!rtc_write_trigger()) if (!rtc_write_trigger())
return 0; return false;
return 1; return true;
} }
/* set rtc time */ /* set rtc time */
@ -71,20 +71,20 @@ int rtc_get(struct rtc_time *time)
} }
/* set rtc xosc setting */ /* set rtc xosc setting */
int rtc_xosc_write(u16 val) bool rtc_xosc_write(u16 val)
{ {
u16 bbpu; u16 bbpu;
rtc_write(RTC_OSC32CON, RTC_OSC32CON_UNLOCK1); rtc_write(RTC_OSC32CON, RTC_OSC32CON_UNLOCK1);
if (!rtc_busy_wait()) if (!rtc_busy_wait())
return 0; return false;
rtc_write(RTC_OSC32CON, RTC_OSC32CON_UNLOCK2); rtc_write(RTC_OSC32CON, RTC_OSC32CON_UNLOCK2);
if (!rtc_busy_wait()) if (!rtc_busy_wait())
return 0; return false;
rtc_write(RTC_OSC32CON, val); rtc_write(RTC_OSC32CON, val);
if (!rtc_busy_wait()) if (!rtc_busy_wait())
return 0; return false;
rtc_read(RTC_BBPU, &bbpu); rtc_read(RTC_BBPU, &bbpu);
bbpu |= RTC_BBPU_KEY | RTC_BBPU_RELOAD; bbpu |= RTC_BBPU_KEY | RTC_BBPU_RELOAD;
@ -94,31 +94,31 @@ int rtc_xosc_write(u16 val)
} }
/* enable lpd subroutine */ /* enable lpd subroutine */
int rtc_lpen(u16 con) bool rtc_lpen(u16 con)
{ {
con &= ~RTC_CON_LPRST; con &= ~RTC_CON_LPRST;
rtc_write(RTC_CON, con); rtc_write(RTC_CON, con);
if (!rtc_write_trigger()) if (!rtc_write_trigger())
return 0; return false;
con |= RTC_CON_LPRST; con |= RTC_CON_LPRST;
rtc_write(RTC_CON, con); rtc_write(RTC_CON, con);
if (!rtc_write_trigger()) if (!rtc_write_trigger())
return 0; return false;
con &= ~RTC_CON_LPRST; con &= ~RTC_CON_LPRST;
rtc_write(RTC_CON, con); rtc_write(RTC_CON, con);
if (!rtc_write_trigger()) if (!rtc_write_trigger())
return 0; return false;
return 1; return true;
} }
/* initialize rtc related registers */ /* initialize rtc related registers */
int rtc_reg_init(void) bool rtc_reg_init(void)
{ {
u16 irqsta; u16 irqsta;
@ -136,7 +136,7 @@ int rtc_reg_init(void)
rtc_write(RTC_DIFF, 0); rtc_write(RTC_DIFF, 0);
rtc_write(RTC_CALI, 0); rtc_write(RTC_CALI, 0);
if (!rtc_write_trigger()) if (!rtc_write_trigger())
return 0; return false;
rtc_read(RTC_IRQ_STA, &irqsta); /* read clear */ rtc_read(RTC_IRQ_STA, &irqsta); /* read clear */
@ -153,7 +153,7 @@ int rtc_reg_init(void)
} }
/* write powerkeys to enable rtc functions */ /* write powerkeys to enable rtc functions */
int rtc_powerkey_init(void) bool rtc_powerkey_init(void)
{ {
rtc_write(RTC_POWERKEY1, RTC_POWERKEY1_KEY); rtc_write(RTC_POWERKEY1, RTC_POWERKEY1_KEY);
rtc_write(RTC_POWERKEY2, RTC_POWERKEY2_KEY); rtc_write(RTC_POWERKEY2, RTC_POWERKEY2_KEY);

View File

@ -5,6 +5,7 @@
#include <soc/pmic_wrap_common.h> #include <soc/pmic_wrap_common.h>
#include <soc/rtc_common.h> #include <soc/rtc_common.h>
#include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include "mt6391.h" #include "mt6391.h"

View File

@ -10,7 +10,7 @@
#define RTC_GPIO_USER_MASK ((1 << 13) - (1 << 8)) #define RTC_GPIO_USER_MASK ((1 << 13) - (1 << 8))
/* initialize rtc related gpio */ /* initialize rtc related gpio */
static int rtc_gpio_init(void) static bool rtc_gpio_init(void)
{ {
u16 con; u16 con;
@ -41,21 +41,21 @@ void rtc_osc_init(void)
} }
/* low power detect setting */ /* low power detect setting */
static int rtc_lpd_init(void) static bool rtc_lpd_init(void)
{ {
pwrap_write_field(RTC_CON, RTC_CON_LPEN, RTC_CON_LPRST, 0); pwrap_write_field(RTC_CON, RTC_CON_LPEN, RTC_CON_LPRST, 0);
if (!rtc_write_trigger()) if (!rtc_write_trigger())
return 0; return false;
pwrap_write_field(RTC_CON, RTC_CON_LPRST, 0, 0); pwrap_write_field(RTC_CON, RTC_CON_LPRST, 0, 0);
if (!rtc_write_trigger()) if (!rtc_write_trigger())
return 0; return false;
pwrap_write_field(RTC_CON, 0, RTC_CON_LPRST, 0); pwrap_write_field(RTC_CON, 0, RTC_CON_LPRST, 0);
if (!rtc_write_trigger()) if (!rtc_write_trigger())
return 0; return false;
return 1; return true;
} }
/* rtc init check */ /* rtc init check */

View File

@ -5,6 +5,7 @@
#include <soc/pmic_wrap_common.h> #include <soc/pmic_wrap_common.h>
#include <soc/rtc_common.h> #include <soc/rtc_common.h>
#include <stdbool.h>
/* RTC registers */ /* RTC registers */
enum { enum {
@ -205,7 +206,7 @@ enum {
/* external API */ /* external API */
void rtc_bbpu_power_on(void); void rtc_bbpu_power_on(void);
int rtc_init(int recover); int rtc_init(int recover);
int rtc_gpio_init(void); bool rtc_gpio_init(void);
void rtc_boot(void); void rtc_boot(void);
u16 rtc_get_frequency_meter(u16 val, u16 measure_src, u16 window_size); u16 rtc_get_frequency_meter(u16 val, u16 measure_src, u16 window_size);
void mt6358_dcxo_disable_unused(void); void mt6358_dcxo_disable_unused(void);

View File

@ -11,7 +11,7 @@
#define RTC_GPIO_USER_MASK ((1 << 13) - (1 << 8)) #define RTC_GPIO_USER_MASK ((1 << 13) - (1 << 8))
/* initialize rtc setting of using dcxo clock */ /* initialize rtc setting of using dcxo clock */
static int rtc_enable_dcxo(void) static bool rtc_enable_dcxo(void)
{ {
u16 bbpu, con, osc32con, sec; u16 bbpu, con, osc32con, sec;
@ -22,7 +22,7 @@ static int rtc_enable_dcxo(void)
mdelay(1); mdelay(1);
if (!rtc_writeif_unlock()) { if (!rtc_writeif_unlock()) {
rtc_info("rtc_writeif_unlock() failed\n"); rtc_info("rtc_writeif_unlock() failed\n");
return 0; return false;
} }
rtc_read(RTC_OSC32CON, &osc32con); rtc_read(RTC_OSC32CON, &osc32con);
@ -32,7 +32,7 @@ static int rtc_enable_dcxo(void)
| RTC_EMB_K_EOSC32_MODE | RTC_EMBCK_SEL_OPTION; | RTC_EMB_K_EOSC32_MODE | RTC_EMBCK_SEL_OPTION;
if (!rtc_xosc_write(osc32con)) { if (!rtc_xosc_write(osc32con)) {
rtc_info("rtc_xosc_write() failed\n"); rtc_info("rtc_xosc_write() failed\n");
return 0; return false;
} }
rtc_read(RTC_CON, &con); rtc_read(RTC_CON, &con);
@ -40,11 +40,11 @@ static int rtc_enable_dcxo(void)
rtc_read(RTC_AL_SEC, &sec); rtc_read(RTC_AL_SEC, &sec);
rtc_info("con=0x%x, osc32con=0x%x, sec=0x%x\n", con, osc32con, sec); rtc_info("con=0x%x, osc32con=0x%x, sec=0x%x\n", con, osc32con, sec);
return 1; return true;
} }
/* initialize rtc related gpio */ /* initialize rtc related gpio */
int rtc_gpio_init(void) bool rtc_gpio_init(void)
{ {
u16 con; u16 con;
@ -115,7 +115,7 @@ u16 rtc_get_frequency_meter(u16 val, u16 measure_src, u16 window_size)
rtc_read(PMIC_RG_FQMTR_CON0, &fqmtr_busy); rtc_read(PMIC_RG_FQMTR_CON0, &fqmtr_busy);
if (stopwatch_expired(&sw)) { if (stopwatch_expired(&sw)) {
rtc_info("get frequency time out !!\n"); rtc_info("get frequency time out !!\n");
return 0; return false;
} }
} while (fqmtr_busy & PMIC_FQMTR_CON0_BUSY); } while (fqmtr_busy & PMIC_FQMTR_CON0_BUSY);
@ -143,7 +143,7 @@ u16 rtc_get_frequency_meter(u16 val, u16 measure_src, u16 window_size)
} }
/* low power detect setting */ /* low power detect setting */
static int rtc_lpd_init(void) static bool rtc_lpd_init(void)
{ {
u16 con, sec; u16 con, sec;
@ -152,19 +152,19 @@ static int rtc_lpd_init(void)
sec |= RTC_LPD_OPT_F32K_CK_ALIVE; sec |= RTC_LPD_OPT_F32K_CK_ALIVE;
rtc_write(RTC_AL_SEC, sec); rtc_write(RTC_AL_SEC, sec);
if (!rtc_write_trigger()) if (!rtc_write_trigger())
return 0; return false;
/* init XOSC32 to detect 32k clock stop */ /* init XOSC32 to detect 32k clock stop */
rtc_read(RTC_CON, &con); rtc_read(RTC_CON, &con);
con |= RTC_CON_XOSC32_LPEN; con |= RTC_CON_XOSC32_LPEN;
if (!rtc_lpen(con)) if (!rtc_lpen(con))
return 0; return false;
/* init EOSC32 to detect rtc low power */ /* init EOSC32 to detect rtc low power */
rtc_read(RTC_CON, &con); rtc_read(RTC_CON, &con);
con |= RTC_CON_EOSC32_LPEN; con |= RTC_CON_EOSC32_LPEN;
if (!rtc_lpen(con)) if (!rtc_lpen(con))
return 0; return false;
rtc_read(RTC_CON, &con); rtc_read(RTC_CON, &con);
con &= ~RTC_CON_XOSC32_LPEN; con &= ~RTC_CON_XOSC32_LPEN;
@ -176,9 +176,9 @@ static int rtc_lpd_init(void)
sec |= RTC_LPD_OPT_EOSC_LPD; sec |= RTC_LPD_OPT_EOSC_LPD;
rtc_write(RTC_AL_SEC, sec); rtc_write(RTC_AL_SEC, sec);
if (!rtc_write_trigger()) if (!rtc_write_trigger())
return 0; return false;
return 1; return true;
} }
static bool rtc_hw_init(void) static bool rtc_hw_init(void)

View File

@ -4,6 +4,7 @@
#define SOC_MEDIATEK_MT8192_RTC_H #define SOC_MEDIATEK_MT8192_RTC_H
#include <soc/pmif.h> #include <soc/pmif.h>
#include <stdbool.h>
/* RTC registers */ /* RTC registers */
enum { enum {
@ -224,7 +225,7 @@ void rtc_read(u16 addr, u16 *rdata);
void rtc_write(u16 addr, u16 wdata); void rtc_write(u16 addr, u16 wdata);
void rtc_bbpu_power_on(void); void rtc_bbpu_power_on(void);
int rtc_init(int recover); int rtc_init(int recover);
int rtc_gpio_init(void); bool rtc_gpio_init(void);
void rtc_boot(void); void rtc_boot(void);
u16 rtc_get_frequency_meter(u16 val, u16 measure_src, u16 window_size); u16 rtc_get_frequency_meter(u16 val, u16 measure_src, u16 window_size);
void mt6359_dcxo_disable_unused(void); void mt6359_dcxo_disable_unused(void);

View File

@ -41,11 +41,11 @@ static void rtc_write_field(u16 reg, u16 val, u16 mask, u16 shift)
} }
/* initialize rtc setting of using dcxo clock */ /* initialize rtc setting of using dcxo clock */
static int rtc_enable_dcxo(void) static bool rtc_enable_dcxo(void)
{ {
if (!rtc_writeif_unlock()) { if (!rtc_writeif_unlock()) {
rtc_info("rtc_writeif_unlock() failed\n"); rtc_info("rtc_writeif_unlock() failed\n");
return 0; return false;
} }
u16 bbpu, con, osc32con, sec; u16 bbpu, con, osc32con, sec;
@ -58,18 +58,18 @@ static int rtc_enable_dcxo(void)
if (!rtc_xosc_write(osc32con)) { if (!rtc_xosc_write(osc32con)) {
rtc_info("rtc_xosc_write() failed\n"); rtc_info("rtc_xosc_write() failed\n");
return 0; return false;
} }
rtc_read(RTC_CON, &con); rtc_read(RTC_CON, &con);
rtc_read(RTC_OSC32CON, &osc32con); rtc_read(RTC_OSC32CON, &osc32con);
rtc_read(RTC_AL_SEC, &sec); rtc_read(RTC_AL_SEC, &sec);
rtc_info("con=%#x, osc32con=%#x, sec=%#x\n", con, osc32con, sec); rtc_info("con=%#x, osc32con=%#x, sec=%#x\n", con, osc32con, sec);
return 1; return true;
} }
/* initialize rtc related gpio */ /* initialize rtc related gpio */
int rtc_gpio_init(void) bool rtc_gpio_init(void)
{ {
u16 con; u16 con;
@ -134,7 +134,7 @@ u16 rtc_get_frequency_meter(u16 val, u16 measure_src, u16 window_size)
rtc_read(PMIC_RG_FQMTR_CON0, &fqmtr_busy); rtc_read(PMIC_RG_FQMTR_CON0, &fqmtr_busy);
if (stopwatch_expired(&sw)) { if (stopwatch_expired(&sw)) {
rtc_info("get frequency time out!\n"); rtc_info("get frequency time out!\n");
return 0; return false;
} }
} while (fqmtr_busy & PMIC_FQMTR_CON0_BUSY); } while (fqmtr_busy & PMIC_FQMTR_CON0_BUSY);
@ -162,7 +162,7 @@ u16 rtc_get_frequency_meter(u16 val, u16 measure_src, u16 window_size)
} }
/* low power detect setting */ /* low power detect setting */
static int rtc_lpd_init(void) static bool rtc_lpd_init(void)
{ {
u16 con, sec; u16 con, sec;
@ -172,26 +172,26 @@ static int rtc_lpd_init(void)
rtc_write(RTC_AL_SEC, sec); rtc_write(RTC_AL_SEC, sec);
if (!rtc_write_trigger()) if (!rtc_write_trigger())
return 0; return false;
/* init XOSC32 to detect 32k clock stop */ /* init XOSC32 to detect 32k clock stop */
rtc_read(RTC_CON, &con); rtc_read(RTC_CON, &con);
con |= RTC_CON_XOSC32_LPEN; con |= RTC_CON_XOSC32_LPEN;
if (!rtc_lpen(con)) if (!rtc_lpen(con))
return 0; return false;
/* init EOSC32 to detect rtc low power */ /* init EOSC32 to detect rtc low power */
rtc_read(RTC_CON, &con); rtc_read(RTC_CON, &con);
con |= RTC_CON_EOSC32_LPEN; con |= RTC_CON_EOSC32_LPEN;
if (!rtc_lpen(con)) if (!rtc_lpen(con))
return 0; return false;
rtc_read(RTC_CON, &con); rtc_read(RTC_CON, &con);
rtc_info("check RTC_CON_LPSTA_RAW after LP init: %#x\n", con); rtc_info("check RTC_CON_LPSTA_RAW after LP init: %#x\n", con);
return 1; return true;
} }
static bool rtc_hw_init(void) static bool rtc_hw_init(void)