17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*88294e09SRichard Bean * Common Development and Distribution License (the "License"). 6*88294e09SRichard Bean * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*88294e09SRichard Bean * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #include <sys/types.h> 277c478bd9Sstevel@tonic-gate #include <sys/conf.h> 287c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 297c478bd9Sstevel@tonic-gate #include <sys/open.h> 307c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 317c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #include <sys/todm5819.h> 347c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 357c478bd9Sstevel@tonic-gate #include <sys/stat.h> 367c478bd9Sstevel@tonic-gate #include <sys/clock.h> 377c478bd9Sstevel@tonic-gate #include <sys/reboot.h> 387c478bd9Sstevel@tonic-gate #include <sys/machsystm.h> 397c478bd9Sstevel@tonic-gate #include <sys/poll.h> 407c478bd9Sstevel@tonic-gate #include <sys/pbio.h> 417c478bd9Sstevel@tonic-gate #include <sys/lom_priv.h> 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate #define WDOG_ON 1 447c478bd9Sstevel@tonic-gate #define WDOG_OFF 0 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate static timestruc_t todbl_get(void); 477c478bd9Sstevel@tonic-gate static void todbl_set(timestruc_t); 487c478bd9Sstevel@tonic-gate static uint_t todbl_set_watchdog_timer(uint_t); 497c478bd9Sstevel@tonic-gate static uint_t todbl_clear_watchdog_timer(void); 507c478bd9Sstevel@tonic-gate static void todbl_set_power_alarm(timestruc_t); 517c478bd9Sstevel@tonic-gate static void todbl_clear_power_alarm(void); 527c478bd9Sstevel@tonic-gate static uint64_t todbl_get_cpufrequency(void); 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate static todinfo_t rtc_to_tod(struct rtc_t *); 557c478bd9Sstevel@tonic-gate static uint_t read_rtc(struct rtc_t *); 567c478bd9Sstevel@tonic-gate static void write_rtc_time(struct rtc_t *); 577c478bd9Sstevel@tonic-gate static uint_t configure_wdog(uint8_t new_state); 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate extern uint64_t find_cpufrequency(volatile uint8_t *); 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate /* 627c478bd9Sstevel@tonic-gate * External variables 637c478bd9Sstevel@tonic-gate */ 647c478bd9Sstevel@tonic-gate extern int watchdog_enable; 657c478bd9Sstevel@tonic-gate extern int watchdog_available; 667c478bd9Sstevel@tonic-gate extern int watchdog_activated; 677c478bd9Sstevel@tonic-gate extern uint_t watchdog_timeout_seconds; 687c478bd9Sstevel@tonic-gate extern int boothowto; 697c478bd9Sstevel@tonic-gate extern void (*bsc_drv_func_ptr)(struct bscv_idi_info *); 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate /* 727c478bd9Sstevel@tonic-gate * Global variables 737c478bd9Sstevel@tonic-gate */ 747c478bd9Sstevel@tonic-gate int m5819_debug_flags; 757c478bd9Sstevel@tonic-gate uint8_t wdog_reset_on_timeout = 1; 767c478bd9Sstevel@tonic-gate static clock_t last_pat_lbt; 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate static struct modlmisc modlmisc = { 80*88294e09SRichard Bean &mod_miscops, "todblade module", 817c478bd9Sstevel@tonic-gate }; 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 847c478bd9Sstevel@tonic-gate MODREV_1, &modlmisc, NULL 857c478bd9Sstevel@tonic-gate }; 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate int 897c478bd9Sstevel@tonic-gate _init(void) 907c478bd9Sstevel@tonic-gate { 917c478bd9Sstevel@tonic-gate if (strcmp(tod_module_name, "todblade") == 0) { 927c478bd9Sstevel@tonic-gate RTC_PUT8(RTC_B, (RTC_DM | RTC_HM)); 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate tod_ops.tod_get = todbl_get; 957c478bd9Sstevel@tonic-gate tod_ops.tod_set = todbl_set; 967c478bd9Sstevel@tonic-gate tod_ops.tod_set_watchdog_timer = 977c478bd9Sstevel@tonic-gate todbl_set_watchdog_timer; 987c478bd9Sstevel@tonic-gate tod_ops.tod_clear_watchdog_timer = 997c478bd9Sstevel@tonic-gate todbl_clear_watchdog_timer; 1007c478bd9Sstevel@tonic-gate tod_ops.tod_set_power_alarm = todbl_set_power_alarm; 1017c478bd9Sstevel@tonic-gate tod_ops.tod_clear_power_alarm = todbl_clear_power_alarm; 1027c478bd9Sstevel@tonic-gate tod_ops.tod_get_cpufrequency = todbl_get_cpufrequency; 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate if (watchdog_enable && (boothowto & RB_DEBUG)) { 1057c478bd9Sstevel@tonic-gate watchdog_available = 0; 1067c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "todblade: kernel debugger " 1077c478bd9Sstevel@tonic-gate "detected: hardware watchdog disabled"); 1087c478bd9Sstevel@tonic-gate } 1097c478bd9Sstevel@tonic-gate } 1107c478bd9Sstevel@tonic-gate return (mod_install(&modlinkage)); 1117c478bd9Sstevel@tonic-gate } 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate int 1147c478bd9Sstevel@tonic-gate _fini(void) 1157c478bd9Sstevel@tonic-gate { 1167c478bd9Sstevel@tonic-gate if (strcmp(tod_module_name, "todblade") == 0) { 1177c478bd9Sstevel@tonic-gate return (EBUSY); 1187c478bd9Sstevel@tonic-gate } else { 1197c478bd9Sstevel@tonic-gate return (mod_remove(&modlinkage)); 1207c478bd9Sstevel@tonic-gate } 1217c478bd9Sstevel@tonic-gate } 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate /* 1247c478bd9Sstevel@tonic-gate * The loadable-module _info(9E) entry point 1257c478bd9Sstevel@tonic-gate */ 1267c478bd9Sstevel@tonic-gate int 1277c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 1287c478bd9Sstevel@tonic-gate { 1297c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 1307c478bd9Sstevel@tonic-gate } 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate /* 1347c478bd9Sstevel@tonic-gate * Read the current time from the clock chip and convert to UNIX form. 1357c478bd9Sstevel@tonic-gate * Assumes that the year in the clock chip is valid. 1367c478bd9Sstevel@tonic-gate * Must be called with tod_lock held. 1377c478bd9Sstevel@tonic-gate */ 1387c478bd9Sstevel@tonic-gate static timestruc_t 1397c478bd9Sstevel@tonic-gate todbl_get(void) 1407c478bd9Sstevel@tonic-gate { 1417c478bd9Sstevel@tonic-gate int i; 1427c478bd9Sstevel@tonic-gate timestruc_t ts; 1437c478bd9Sstevel@tonic-gate struct rtc_t rtc; 1447c478bd9Sstevel@tonic-gate struct bscv_idi_info bscv_info; 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tod_lock)); 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate /* 1497c478bd9Sstevel@tonic-gate * We must check that the value of watchdog enable hasnt changed 1507c478bd9Sstevel@tonic-gate * as its a user knob for turning it on and off 1517c478bd9Sstevel@tonic-gate */ 1527c478bd9Sstevel@tonic-gate if (watchdog_available) { 1537c478bd9Sstevel@tonic-gate if (watchdog_activated && !watchdog_enable) { 1547c478bd9Sstevel@tonic-gate (void) configure_wdog(WDOG_OFF); 1557c478bd9Sstevel@tonic-gate } else if (!watchdog_activated && watchdog_enable) { 1567c478bd9Sstevel@tonic-gate (void) configure_wdog(WDOG_ON); 1577c478bd9Sstevel@tonic-gate } else if (watchdog_activated && 1587c478bd9Sstevel@tonic-gate (ddi_get_lbolt() - last_pat_lbt) >= 1597c478bd9Sstevel@tonic-gate SEC_TO_TICK(1)) { 1607c478bd9Sstevel@tonic-gate /* 1617c478bd9Sstevel@tonic-gate * PAT THE WATCHDOG!! 1627c478bd9Sstevel@tonic-gate * We dont want to accelerate the pat frequency 1637c478bd9Sstevel@tonic-gate * when userland calls to the TOD_GET_DATE ioctl 1647c478bd9Sstevel@tonic-gate * pass through here. 1657c478bd9Sstevel@tonic-gate */ 1667c478bd9Sstevel@tonic-gate bscv_info.type = BSCV_IDI_WDOG_PAT; 1677c478bd9Sstevel@tonic-gate bscv_info.data = NULL; 1687c478bd9Sstevel@tonic-gate bscv_info.size = 0; 1697c478bd9Sstevel@tonic-gate if (bsc_drv_func_ptr != NULL) { 1707c478bd9Sstevel@tonic-gate (*bsc_drv_func_ptr)(&bscv_info); 1717c478bd9Sstevel@tonic-gate last_pat_lbt = ddi_get_lbolt(); 1727c478bd9Sstevel@tonic-gate } 1737c478bd9Sstevel@tonic-gate } 1747c478bd9Sstevel@tonic-gate } 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate /* 1777c478bd9Sstevel@tonic-gate * Read from the tod, and if it isnt accessible wait 1787c478bd9Sstevel@tonic-gate * before retrying. 1797c478bd9Sstevel@tonic-gate */ 1807c478bd9Sstevel@tonic-gate for (i = 0; i < TODM5819_UIP_RETRY_THRESH; i++) { 1817c478bd9Sstevel@tonic-gate if (read_rtc(&rtc)) 1827c478bd9Sstevel@tonic-gate break; 1837c478bd9Sstevel@tonic-gate drv_usecwait(TODM5819_UIP_WAIT_USEC); 1847c478bd9Sstevel@tonic-gate } 1857c478bd9Sstevel@tonic-gate if (i == TODM5819_UIP_RETRY_THRESH) { 1867c478bd9Sstevel@tonic-gate /* 1877c478bd9Sstevel@tonic-gate * We couldnt read from the tod 1887c478bd9Sstevel@tonic-gate */ 1897c478bd9Sstevel@tonic-gate tod_fault_reset(); 1907c478bd9Sstevel@tonic-gate return (hrestime); 1917c478bd9Sstevel@tonic-gate } 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate DPRINTF("todbl_get: century=%d year=%d dom=%d hrs=%d\n", 1947c478bd9Sstevel@tonic-gate rtc.rtc_century, rtc.rtc_year, rtc.rtc_dom, rtc.rtc_hrs); 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate ts.tv_sec = tod_to_utc(rtc_to_tod(&rtc)); 1977c478bd9Sstevel@tonic-gate ts.tv_nsec = 0; 1987c478bd9Sstevel@tonic-gate return (ts); 1997c478bd9Sstevel@tonic-gate } 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate static todinfo_t 2027c478bd9Sstevel@tonic-gate rtc_to_tod(struct rtc_t *rtc) 2037c478bd9Sstevel@tonic-gate { 2047c478bd9Sstevel@tonic-gate todinfo_t tod; 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate /* 2077c478bd9Sstevel@tonic-gate * tod_year is base 1900 so this code needs to adjust the true 2087c478bd9Sstevel@tonic-gate * year retrieved from the rtc's century and year fields. 2097c478bd9Sstevel@tonic-gate */ 2107c478bd9Sstevel@tonic-gate tod.tod_year = rtc->rtc_year + (rtc->rtc_century * 100) - 1900; 2117c478bd9Sstevel@tonic-gate tod.tod_month = rtc->rtc_mon; 2127c478bd9Sstevel@tonic-gate tod.tod_day = rtc->rtc_dom; 2137c478bd9Sstevel@tonic-gate tod.tod_dow = rtc->rtc_dow; 2147c478bd9Sstevel@tonic-gate tod.tod_hour = rtc->rtc_hrs; 2157c478bd9Sstevel@tonic-gate tod.tod_min = rtc->rtc_min; 2167c478bd9Sstevel@tonic-gate tod.tod_sec = rtc->rtc_sec; 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate return (tod); 2197c478bd9Sstevel@tonic-gate } 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate static uint_t 2237c478bd9Sstevel@tonic-gate read_rtc(struct rtc_t *rtc) 2247c478bd9Sstevel@tonic-gate { 2257c478bd9Sstevel@tonic-gate int s; 2267c478bd9Sstevel@tonic-gate uint_t rtc_readable = 0; 2277c478bd9Sstevel@tonic-gate 2287c478bd9Sstevel@tonic-gate s = splhi(); 2297c478bd9Sstevel@tonic-gate /* 2307c478bd9Sstevel@tonic-gate * If UIP bit is not set we have at least 274us 2317c478bd9Sstevel@tonic-gate * to read the values. 2327c478bd9Sstevel@tonic-gate */ 2337c478bd9Sstevel@tonic-gate if (!(RTC_GET8(RTC_A) & RTC_UIP)) { 2347c478bd9Sstevel@tonic-gate rtc_readable = 1; 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate rtc->rtc_sec = RTC_GET8(RTC_SEC); 2377c478bd9Sstevel@tonic-gate rtc->rtc_asec = RTC_GET8(RTC_ASEC); 2387c478bd9Sstevel@tonic-gate rtc->rtc_min = RTC_GET8(RTC_MIN); 2397c478bd9Sstevel@tonic-gate rtc->rtc_amin = RTC_GET8(RTC_AMIN); 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate rtc->rtc_hrs = RTC_GET8(RTC_HRS); 2427c478bd9Sstevel@tonic-gate rtc->rtc_ahrs = RTC_GET8(RTC_AHRS); 2437c478bd9Sstevel@tonic-gate rtc->rtc_dow = RTC_GET8(RTC_DOW); 2447c478bd9Sstevel@tonic-gate rtc->rtc_dom = RTC_GET8(RTC_DOM); 2457c478bd9Sstevel@tonic-gate rtc->rtc_adom = RTC_GET8(RTC_D) & 0x3f; 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate rtc->rtc_mon = RTC_GET8(RTC_MON); 2487c478bd9Sstevel@tonic-gate rtc->rtc_year = RTC_GET8(RTC_YEAR); 2497c478bd9Sstevel@tonic-gate rtc->rtc_century = RTC_GET8(RTC_CENTURY); 2507c478bd9Sstevel@tonic-gate rtc->rtc_amon = 0; 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate /* Clear wakeup data */ 2537c478bd9Sstevel@tonic-gate rtc->apc_wdwr = 0; 2547c478bd9Sstevel@tonic-gate rtc->apc_wdmr = 0; 2557c478bd9Sstevel@tonic-gate rtc->apc_wmr = 0; 2567c478bd9Sstevel@tonic-gate rtc->apc_wyr = 0; 2577c478bd9Sstevel@tonic-gate rtc->apc_wcr = 0; 2587c478bd9Sstevel@tonic-gate } 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate splx(s); 2617c478bd9Sstevel@tonic-gate return (rtc_readable); 2627c478bd9Sstevel@tonic-gate } 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate /* 2657c478bd9Sstevel@tonic-gate * Write the specified time into the clock chip. 2667c478bd9Sstevel@tonic-gate * Must be called with tod_lock held. 2677c478bd9Sstevel@tonic-gate */ 2687c478bd9Sstevel@tonic-gate static void 2697c478bd9Sstevel@tonic-gate todbl_set(timestruc_t ts) 2707c478bd9Sstevel@tonic-gate { 2717c478bd9Sstevel@tonic-gate struct rtc_t rtc; 2727c478bd9Sstevel@tonic-gate todinfo_t tod = utc_to_tod(ts.tv_sec); 2737c478bd9Sstevel@tonic-gate struct bscv_idi_info bscv_info; 2747c478bd9Sstevel@tonic-gate int year; 2757c478bd9Sstevel@tonic-gate 2767c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tod_lock)); 2777c478bd9Sstevel@tonic-gate 2787c478bd9Sstevel@tonic-gate /* tod_year is base 1900 so this code needs to adjust */ 2797c478bd9Sstevel@tonic-gate year = 1900 + tod.tod_year; 2807c478bd9Sstevel@tonic-gate rtc.rtc_year = year % 100; 2817c478bd9Sstevel@tonic-gate rtc.rtc_century = year / 100; 2827c478bd9Sstevel@tonic-gate rtc.rtc_mon = (uint8_t)tod.tod_month; 2837c478bd9Sstevel@tonic-gate rtc.rtc_dom = (uint8_t)tod.tod_day; 2847c478bd9Sstevel@tonic-gate rtc.rtc_dow = (uint8_t)tod.tod_dow; 2857c478bd9Sstevel@tonic-gate rtc.rtc_hrs = (uint8_t)tod.tod_hour; 2867c478bd9Sstevel@tonic-gate rtc.rtc_min = (uint8_t)tod.tod_min; 2877c478bd9Sstevel@tonic-gate rtc.rtc_sec = (uint8_t)tod.tod_sec; 2887c478bd9Sstevel@tonic-gate DPRINTF("todbl_set: century=%d year=%d dom=%d hrs=%d\n", 2897c478bd9Sstevel@tonic-gate rtc.rtc_century, rtc.rtc_year, rtc.rtc_dom, rtc.rtc_hrs); 2907c478bd9Sstevel@tonic-gate 2917c478bd9Sstevel@tonic-gate write_rtc_time(&rtc); 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate /* 2947c478bd9Sstevel@tonic-gate * Because of a generic solaris problem where calls to stime() 2957c478bd9Sstevel@tonic-gate * starve calls to tod_get(), we need to check to see when the 2967c478bd9Sstevel@tonic-gate * watchdog was last patted and pat it if necessary. 2977c478bd9Sstevel@tonic-gate */ 2987c478bd9Sstevel@tonic-gate if (watchdog_activated && 2997c478bd9Sstevel@tonic-gate (ddi_get_lbolt() - last_pat_lbt) >= SEC_TO_TICK(1)) { 3007c478bd9Sstevel@tonic-gate /* 3017c478bd9Sstevel@tonic-gate * Pat the watchdog! 3027c478bd9Sstevel@tonic-gate */ 3037c478bd9Sstevel@tonic-gate bscv_info.type = BSCV_IDI_WDOG_PAT; 3047c478bd9Sstevel@tonic-gate bscv_info.data = NULL; 3057c478bd9Sstevel@tonic-gate bscv_info.size = 0; 3067c478bd9Sstevel@tonic-gate if (bsc_drv_func_ptr != NULL) { 3077c478bd9Sstevel@tonic-gate (*bsc_drv_func_ptr)(&bscv_info); 3087c478bd9Sstevel@tonic-gate last_pat_lbt = ddi_get_lbolt(); 3097c478bd9Sstevel@tonic-gate } 3107c478bd9Sstevel@tonic-gate } 3117c478bd9Sstevel@tonic-gate } 3127c478bd9Sstevel@tonic-gate 3137c478bd9Sstevel@tonic-gate static void 3147c478bd9Sstevel@tonic-gate write_rtc_time(struct rtc_t *rtc) 3157c478bd9Sstevel@tonic-gate { 3167c478bd9Sstevel@tonic-gate uint8_t regb; 3177c478bd9Sstevel@tonic-gate 3187c478bd9Sstevel@tonic-gate /* 3197c478bd9Sstevel@tonic-gate * Freeze 3207c478bd9Sstevel@tonic-gate */ 3217c478bd9Sstevel@tonic-gate regb = RTC_GET8(RTC_B); 3227c478bd9Sstevel@tonic-gate RTC_PUT8(RTC_B, (regb | RTC_SET)); 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate RTC_PUT8(RTC_SEC, (rtc->rtc_sec)); 3257c478bd9Sstevel@tonic-gate RTC_PUT8(RTC_ASEC, (rtc->rtc_asec)); 3267c478bd9Sstevel@tonic-gate RTC_PUT8(RTC_MIN, (rtc->rtc_min)); 3277c478bd9Sstevel@tonic-gate RTC_PUT8(RTC_AMIN, (rtc->rtc_amin)); 3287c478bd9Sstevel@tonic-gate 3297c478bd9Sstevel@tonic-gate RTC_PUT8(RTC_HRS, (rtc->rtc_hrs)); 3307c478bd9Sstevel@tonic-gate RTC_PUT8(RTC_AHRS, (rtc->rtc_ahrs)); 3317c478bd9Sstevel@tonic-gate RTC_PUT8(RTC_DOW, (rtc->rtc_dow)); 3327c478bd9Sstevel@tonic-gate RTC_PUT8(RTC_DOM, (rtc->rtc_dom)); 3337c478bd9Sstevel@tonic-gate 3347c478bd9Sstevel@tonic-gate RTC_PUT8(RTC_MON, (rtc->rtc_mon)); 3357c478bd9Sstevel@tonic-gate RTC_PUT8(RTC_YEAR, (rtc->rtc_year)); 3367c478bd9Sstevel@tonic-gate RTC_PUT8(RTC_CENTURY, (rtc->rtc_century)); 3377c478bd9Sstevel@tonic-gate 3387c478bd9Sstevel@tonic-gate /* 3397c478bd9Sstevel@tonic-gate * Unfreeze 3407c478bd9Sstevel@tonic-gate */ 3417c478bd9Sstevel@tonic-gate RTC_PUT8(RTC_B, regb); 3427c478bd9Sstevel@tonic-gate } 3437c478bd9Sstevel@tonic-gate 3447c478bd9Sstevel@tonic-gate 3457c478bd9Sstevel@tonic-gate 3467c478bd9Sstevel@tonic-gate /* 3477c478bd9Sstevel@tonic-gate * The TOD alarm functionality is not supported on our platform 3487c478bd9Sstevel@tonic-gate * as the interrupt is not wired, so do nothing. 3497c478bd9Sstevel@tonic-gate */ 3507c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 3517c478bd9Sstevel@tonic-gate static void 3527c478bd9Sstevel@tonic-gate todbl_set_power_alarm(timestruc_t ts) 3537c478bd9Sstevel@tonic-gate { 3547c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tod_lock)); 3557c478bd9Sstevel@tonic-gate } 3567c478bd9Sstevel@tonic-gate 3577c478bd9Sstevel@tonic-gate /* 3587c478bd9Sstevel@tonic-gate * clear alarm interrupt 3597c478bd9Sstevel@tonic-gate */ 3607c478bd9Sstevel@tonic-gate static void 3617c478bd9Sstevel@tonic-gate todbl_clear_power_alarm(void) 3627c478bd9Sstevel@tonic-gate { 3637c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tod_lock)); 3647c478bd9Sstevel@tonic-gate } 3657c478bd9Sstevel@tonic-gate 3667c478bd9Sstevel@tonic-gate /* 3677c478bd9Sstevel@tonic-gate * Determine the cpu frequency by watching the TOD chip rollover twice. 3687c478bd9Sstevel@tonic-gate * Cpu clock rate is determined by computing the ticks added (in tick register) 3697c478bd9Sstevel@tonic-gate * during one second interval on TOD. 3707c478bd9Sstevel@tonic-gate */ 3717c478bd9Sstevel@tonic-gate uint64_t 3727c478bd9Sstevel@tonic-gate todbl_get_cpufrequency(void) 3737c478bd9Sstevel@tonic-gate { 3747c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tod_lock)); 3757c478bd9Sstevel@tonic-gate M5819_ADDR_REG = RTC_SEC; 3767c478bd9Sstevel@tonic-gate return (find_cpufrequency(v_rtc_data_reg)); 3777c478bd9Sstevel@tonic-gate } 3787c478bd9Sstevel@tonic-gate 3797c478bd9Sstevel@tonic-gate 3807c478bd9Sstevel@tonic-gate static uint_t 3817c478bd9Sstevel@tonic-gate todbl_set_watchdog_timer(uint_t timeoutval) 3827c478bd9Sstevel@tonic-gate { 3837c478bd9Sstevel@tonic-gate /* 3847c478bd9Sstevel@tonic-gate * We get started during kernel intilaisation only 3857c478bd9Sstevel@tonic-gate * if watchdog_enable is set. 3867c478bd9Sstevel@tonic-gate */ 3877c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tod_lock)); 3887c478bd9Sstevel@tonic-gate 3897c478bd9Sstevel@tonic-gate if (watchdog_available && (!watchdog_activated || 3907c478bd9Sstevel@tonic-gate (watchdog_activated && (timeoutval != watchdog_timeout_seconds)))) { 3917c478bd9Sstevel@tonic-gate watchdog_timeout_seconds = timeoutval; 3927c478bd9Sstevel@tonic-gate if (configure_wdog(WDOG_ON)) 3937c478bd9Sstevel@tonic-gate return (watchdog_timeout_seconds); 3947c478bd9Sstevel@tonic-gate } 3957c478bd9Sstevel@tonic-gate return (0); 3967c478bd9Sstevel@tonic-gate } 3977c478bd9Sstevel@tonic-gate 3987c478bd9Sstevel@tonic-gate static uint_t 3997c478bd9Sstevel@tonic-gate todbl_clear_watchdog_timer(void) 4007c478bd9Sstevel@tonic-gate { 4017c478bd9Sstevel@tonic-gate /* 4027c478bd9Sstevel@tonic-gate * The core kernel will call us here to disable the wdog when: 4037c478bd9Sstevel@tonic-gate * 1. we're panicing 4047c478bd9Sstevel@tonic-gate * 2. we're entering debug 4057c478bd9Sstevel@tonic-gate * 3. we're rebooting 4067c478bd9Sstevel@tonic-gate */ 4077c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tod_lock)); 4087c478bd9Sstevel@tonic-gate 4097c478bd9Sstevel@tonic-gate if (watchdog_available && watchdog_activated) { 4107c478bd9Sstevel@tonic-gate watchdog_enable = 0; 4117c478bd9Sstevel@tonic-gate if (!configure_wdog(WDOG_OFF)) 4127c478bd9Sstevel@tonic-gate return (0); 4137c478bd9Sstevel@tonic-gate } 4147c478bd9Sstevel@tonic-gate return (watchdog_timeout_seconds); 4157c478bd9Sstevel@tonic-gate } 4167c478bd9Sstevel@tonic-gate 4177c478bd9Sstevel@tonic-gate static uint_t 4187c478bd9Sstevel@tonic-gate configure_wdog(uint8_t new_state) 4197c478bd9Sstevel@tonic-gate { 4207c478bd9Sstevel@tonic-gate bscv_wdog_t wdog_cmd; 4217c478bd9Sstevel@tonic-gate struct bscv_idi_info bscv_info; 4227c478bd9Sstevel@tonic-gate 4237c478bd9Sstevel@tonic-gate if (new_state == WDOG_ON || new_state == WDOG_OFF) { 4247c478bd9Sstevel@tonic-gate 4257c478bd9Sstevel@tonic-gate wdog_cmd.enable_wdog = new_state; 4267c478bd9Sstevel@tonic-gate wdog_cmd.wdog_timeout_s = watchdog_timeout_seconds; 4277c478bd9Sstevel@tonic-gate wdog_cmd.reset_system_on_timeout = wdog_reset_on_timeout; 4287c478bd9Sstevel@tonic-gate bscv_info.type = BSCV_IDI_WDOG_CFG; 4297c478bd9Sstevel@tonic-gate bscv_info.data = &wdog_cmd; 4307c478bd9Sstevel@tonic-gate bscv_info.size = sizeof (wdog_cmd); 4317c478bd9Sstevel@tonic-gate 4327c478bd9Sstevel@tonic-gate if (bsc_drv_func_ptr != NULL) { 4337c478bd9Sstevel@tonic-gate watchdog_activated = new_state; 4347c478bd9Sstevel@tonic-gate (*bsc_drv_func_ptr)(&bscv_info); 4357c478bd9Sstevel@tonic-gate return (1); 4367c478bd9Sstevel@tonic-gate } 4377c478bd9Sstevel@tonic-gate } 4387c478bd9Sstevel@tonic-gate return (0); 4397c478bd9Sstevel@tonic-gate 4407c478bd9Sstevel@tonic-gate } 441