xref: /onnv-gate/usr/src/uts/sun4u/io/todm5819.c (revision 11752:9c475fee0b48)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*11752STrevor.Thompson@Sun.COM  * Common Development and Distribution License (the "License").
6*11752STrevor.Thompson@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*11752STrevor.Thompson@Sun.COM  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #include <sys/types.h>
270Sstevel@tonic-gate #include <sys/conf.h>
280Sstevel@tonic-gate #include <sys/kmem.h>
290Sstevel@tonic-gate #include <sys/open.h>
300Sstevel@tonic-gate #include <sys/ddi.h>
310Sstevel@tonic-gate #include <sys/sunddi.h>
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #include <sys/todm5819.h>
340Sstevel@tonic-gate #include <sys/modctl.h>
350Sstevel@tonic-gate #include <sys/stat.h>
360Sstevel@tonic-gate #include <sys/clock.h>
370Sstevel@tonic-gate #include <sys/reboot.h>
380Sstevel@tonic-gate #include <sys/machsystm.h>
390Sstevel@tonic-gate #include <sys/poll.h>
400Sstevel@tonic-gate #include <sys/pbio.h>
410Sstevel@tonic-gate 
420Sstevel@tonic-gate static timestruc_t	todm5819_get(void);
430Sstevel@tonic-gate static void		todm5819_set(timestruc_t);
440Sstevel@tonic-gate static uint_t		todm5819_set_watchdog_timer(uint_t);
450Sstevel@tonic-gate static uint_t		todm5819_clear_watchdog_timer(void);
460Sstevel@tonic-gate static void		todm5819_set_power_alarm(timestruc_t);
470Sstevel@tonic-gate static void		todm5819_clear_power_alarm(void);
480Sstevel@tonic-gate static uint64_t		todm5819_get_cpufrequency(void);
490Sstevel@tonic-gate 
500Sstevel@tonic-gate extern uint64_t		find_cpufrequency(volatile uint8_t *);
510Sstevel@tonic-gate 
520Sstevel@tonic-gate /*
530Sstevel@tonic-gate  * External variables
540Sstevel@tonic-gate  */
550Sstevel@tonic-gate extern int		watchdog_enable;
560Sstevel@tonic-gate extern int		watchdog_available;
570Sstevel@tonic-gate extern int		boothowto;
580Sstevel@tonic-gate 
590Sstevel@tonic-gate /*
600Sstevel@tonic-gate  * Global variables
610Sstevel@tonic-gate  */
620Sstevel@tonic-gate int m5819_debug_flags;
630Sstevel@tonic-gate 
640Sstevel@tonic-gate static todinfo_t	rtc_to_tod(struct rtc_t *);
650Sstevel@tonic-gate static uint_t		read_rtc(struct rtc_t *);
660Sstevel@tonic-gate static void		write_rtc_time(struct rtc_t *);
670Sstevel@tonic-gate static void		write_rtc_alarm(struct rtc_t *);
680Sstevel@tonic-gate 
690Sstevel@tonic-gate 
700Sstevel@tonic-gate static struct modlmisc modlmisc = {
710Sstevel@tonic-gate 	&mod_miscops, "tod module for ALI M5819",
720Sstevel@tonic-gate };
730Sstevel@tonic-gate 
740Sstevel@tonic-gate static struct modlinkage modlinkage = {
750Sstevel@tonic-gate 	MODREV_1, &modlmisc, NULL
760Sstevel@tonic-gate };
770Sstevel@tonic-gate 
780Sstevel@tonic-gate 
790Sstevel@tonic-gate int
_init(void)800Sstevel@tonic-gate _init(void)
810Sstevel@tonic-gate {
820Sstevel@tonic-gate 	if (strcmp(tod_module_name, "todm5819") == 0 ||
83*11752STrevor.Thompson@Sun.COM 	    strcmp(tod_module_name, "m5819") == 0) {
840Sstevel@tonic-gate 		RTC_PUT8(RTC_B, (RTC_DM | RTC_HM));
850Sstevel@tonic-gate 
860Sstevel@tonic-gate 		tod_ops.tod_get = todm5819_get;
870Sstevel@tonic-gate 		tod_ops.tod_set = todm5819_set;
88*11752STrevor.Thompson@Sun.COM 		tod_ops.tod_set_watchdog_timer = todm5819_set_watchdog_timer;
890Sstevel@tonic-gate 		tod_ops.tod_clear_watchdog_timer =
90*11752STrevor.Thompson@Sun.COM 		    todm5819_clear_watchdog_timer;
910Sstevel@tonic-gate 		tod_ops.tod_set_power_alarm = todm5819_set_power_alarm;
920Sstevel@tonic-gate 		tod_ops.tod_clear_power_alarm = todm5819_clear_power_alarm;
930Sstevel@tonic-gate 		tod_ops.tod_get_cpufrequency = todm5819_get_cpufrequency;
940Sstevel@tonic-gate 
950Sstevel@tonic-gate 		/*
960Sstevel@tonic-gate 		 * check if hardware watchdog timer is available and user
970Sstevel@tonic-gate 		 * enabled it.
980Sstevel@tonic-gate 		 */
990Sstevel@tonic-gate 		if (watchdog_enable) {
1000Sstevel@tonic-gate 			if (!watchdog_available) {
1010Sstevel@tonic-gate 				cmn_err(CE_WARN, "m5819: Hardware watchdog "
1020Sstevel@tonic-gate 				    "unavailable");
1030Sstevel@tonic-gate 			} else if (boothowto & RB_DEBUG) {
1040Sstevel@tonic-gate 				cmn_err(CE_WARN, "m5819: Hardware watchdog "
1050Sstevel@tonic-gate 				    "disabled [debugger]");
1060Sstevel@tonic-gate 			}
1070Sstevel@tonic-gate 		}
1080Sstevel@tonic-gate 	}
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate 	return (mod_install(&modlinkage));
1110Sstevel@tonic-gate }
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate int
_fini(void)1140Sstevel@tonic-gate _fini(void)
1150Sstevel@tonic-gate {
1160Sstevel@tonic-gate 	if (strcmp(tod_module_name, "m5819") == 0 ||
117*11752STrevor.Thompson@Sun.COM 	    strcmp(tod_module_name, "todm5819") == 0) {
1180Sstevel@tonic-gate 		return (EBUSY);
1190Sstevel@tonic-gate 	} else {
1200Sstevel@tonic-gate 		return (mod_remove(&modlinkage));
1210Sstevel@tonic-gate 	}
1220Sstevel@tonic-gate }
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate /*
1250Sstevel@tonic-gate  * The loadable-module _info(9E) entry point
1260Sstevel@tonic-gate  */
1270Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1280Sstevel@tonic-gate _info(struct modinfo *modinfop)
1290Sstevel@tonic-gate {
1300Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
1310Sstevel@tonic-gate }
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate /*
1350Sstevel@tonic-gate  * Read the current time from the clock chip and convert to UNIX form.
1360Sstevel@tonic-gate  * Assumes that the year in the clock chip is valid.
1370Sstevel@tonic-gate  * Must be called with tod_lock held.
1380Sstevel@tonic-gate  */
1390Sstevel@tonic-gate static timestruc_t
todm5819_get(void)1400Sstevel@tonic-gate todm5819_get(void)
1410Sstevel@tonic-gate {
1420Sstevel@tonic-gate 	int i;
1430Sstevel@tonic-gate 	timestruc_t ts;
1440Sstevel@tonic-gate 	struct rtc_t rtc;
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&tod_lock));
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate 	/*
1490Sstevel@tonic-gate 	 * Read from the tod, and if it isnt accessible wait
1500Sstevel@tonic-gate 	 * before retrying.
1510Sstevel@tonic-gate 	 */
1520Sstevel@tonic-gate 	for (i = 0; i < TODM5819_UIP_RETRY_THRESH; i++) {
1530Sstevel@tonic-gate 		if (read_rtc(&rtc))
1540Sstevel@tonic-gate 			break;
1550Sstevel@tonic-gate 		drv_usecwait(TODM5819_UIP_WAIT_USEC);
1560Sstevel@tonic-gate 	}
1570Sstevel@tonic-gate 	if (i == TODM5819_UIP_RETRY_THRESH) {
1580Sstevel@tonic-gate 		/*
159*11752STrevor.Thompson@Sun.COM 		 * We couldn't read from the TOD.
1600Sstevel@tonic-gate 		 */
161*11752STrevor.Thompson@Sun.COM 		tod_status_set(TOD_GET_FAILED);
1620Sstevel@tonic-gate 		return (hrestime);
1630Sstevel@tonic-gate 	}
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate 	DPRINTF("todm5819_get: century=%d year=%d dom=%d hrs=%d\n",
166*11752STrevor.Thompson@Sun.COM 	    rtc.rtc_century, rtc.rtc_year, rtc.rtc_dom, rtc.rtc_hrs);
167*11752STrevor.Thompson@Sun.COM 
168*11752STrevor.Thompson@Sun.COM 	/* read was successful so ensure failure flag is clear */
169*11752STrevor.Thompson@Sun.COM 	tod_status_clear(TOD_GET_FAILED);
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate 	ts.tv_sec = tod_to_utc(rtc_to_tod(&rtc));
1720Sstevel@tonic-gate 	ts.tv_nsec = 0;
1730Sstevel@tonic-gate 	return (ts);
1740Sstevel@tonic-gate }
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate static todinfo_t
rtc_to_tod(struct rtc_t * rtc)1770Sstevel@tonic-gate rtc_to_tod(struct rtc_t *rtc)
1780Sstevel@tonic-gate {
1790Sstevel@tonic-gate 	todinfo_t tod;
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate 	/*
1820Sstevel@tonic-gate 	 * tod_year is base 1900 so this code needs to adjust the true
1830Sstevel@tonic-gate 	 * year retrieved from the rtc's century and year fields.
1840Sstevel@tonic-gate 	 */
1850Sstevel@tonic-gate 	tod.tod_year	= rtc->rtc_year + (rtc->rtc_century * 100) - 1900;
1860Sstevel@tonic-gate 	tod.tod_month	= rtc->rtc_mon;
1870Sstevel@tonic-gate 	tod.tod_day	= rtc->rtc_dom;
1880Sstevel@tonic-gate 	tod.tod_dow	= rtc->rtc_dow;
1890Sstevel@tonic-gate 	tod.tod_hour	= rtc->rtc_hrs;
1900Sstevel@tonic-gate 	tod.tod_min	= rtc->rtc_min;
1910Sstevel@tonic-gate 	tod.tod_sec	= rtc->rtc_sec;
1920Sstevel@tonic-gate 
1930Sstevel@tonic-gate 	return (tod);
1940Sstevel@tonic-gate }
1950Sstevel@tonic-gate 
1960Sstevel@tonic-gate uint_t
read_rtc(struct rtc_t * rtc)1970Sstevel@tonic-gate read_rtc(struct rtc_t *rtc)
1980Sstevel@tonic-gate {
1990Sstevel@tonic-gate 	int s;
2000Sstevel@tonic-gate 	uint_t rtc_readable = 0;
2010Sstevel@tonic-gate 
2020Sstevel@tonic-gate 	s = splhi();
2030Sstevel@tonic-gate 	/*
2040Sstevel@tonic-gate 	 * If UIP bit is not set we have at least 274us
2050Sstevel@tonic-gate 	 * to read the values. Otherwise we have up to
2060Sstevel@tonic-gate 	 * 336us to wait before we can read it
2070Sstevel@tonic-gate 	 */
2080Sstevel@tonic-gate 	if (!(RTC_GET8(RTC_A) & RTC_UIP)) {
2090Sstevel@tonic-gate 		rtc_readable = 1;
2100Sstevel@tonic-gate 
2110Sstevel@tonic-gate 		rtc->rtc_sec = RTC_GET8(RTC_SEC);
2120Sstevel@tonic-gate 		rtc->rtc_asec = RTC_GET8(RTC_ASEC);
2130Sstevel@tonic-gate 		rtc->rtc_min = RTC_GET8(RTC_MIN);
2140Sstevel@tonic-gate 		rtc->rtc_amin = RTC_GET8(RTC_AMIN);
2150Sstevel@tonic-gate 
2160Sstevel@tonic-gate 		rtc->rtc_hrs = RTC_GET8(RTC_HRS);
2170Sstevel@tonic-gate 		rtc->rtc_ahrs = RTC_GET8(RTC_AHRS);
2180Sstevel@tonic-gate 		rtc->rtc_dow = RTC_GET8(RTC_DOW);
2190Sstevel@tonic-gate 		rtc->rtc_dom = RTC_GET8(RTC_DOM);
2200Sstevel@tonic-gate 		rtc->rtc_adom = RTC_GET8(RTC_D) & 0x3f;
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate 		rtc->rtc_mon = RTC_GET8(RTC_MON);
2230Sstevel@tonic-gate 		rtc->rtc_year = RTC_GET8(RTC_YEAR);
2240Sstevel@tonic-gate 		rtc->rtc_century = RTC_GET8(RTC_CENTURY);
2250Sstevel@tonic-gate 		rtc->rtc_amon = 0;
2260Sstevel@tonic-gate 
2270Sstevel@tonic-gate 		/* Clear wakeup data */
2280Sstevel@tonic-gate 		rtc->apc_wdwr = 0;
2290Sstevel@tonic-gate 		rtc->apc_wdmr = 0;
2300Sstevel@tonic-gate 		rtc->apc_wmr = 0;
2310Sstevel@tonic-gate 		rtc->apc_wyr = 0;
2320Sstevel@tonic-gate 		rtc->apc_wcr = 0;
2330Sstevel@tonic-gate 	}
2340Sstevel@tonic-gate 	splx(s);
2350Sstevel@tonic-gate 	return (rtc_readable);
2360Sstevel@tonic-gate }
2370Sstevel@tonic-gate 
2380Sstevel@tonic-gate /*
2390Sstevel@tonic-gate  * Write the specified time into the clock chip.
2400Sstevel@tonic-gate  * Must be called with tod_lock held.
2410Sstevel@tonic-gate  */
2420Sstevel@tonic-gate static void
todm5819_set(timestruc_t ts)2430Sstevel@tonic-gate todm5819_set(timestruc_t ts)
2440Sstevel@tonic-gate {
2450Sstevel@tonic-gate 	struct rtc_t	rtc;
2460Sstevel@tonic-gate 	todinfo_t tod = utc_to_tod(ts.tv_sec);
2470Sstevel@tonic-gate 	int year;
2480Sstevel@tonic-gate 
2490Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&tod_lock));
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate 	/* tod_year is base 1900 so this code needs to adjust */
2520Sstevel@tonic-gate 	year = 1900 + tod.tod_year;
2530Sstevel@tonic-gate 	rtc.rtc_year	= year % 100;
2540Sstevel@tonic-gate 	rtc.rtc_century = year / 100;
2550Sstevel@tonic-gate 	rtc.rtc_mon	= (uint8_t)tod.tod_month;
2560Sstevel@tonic-gate 	rtc.rtc_dom	= (uint8_t)tod.tod_day;
2570Sstevel@tonic-gate 	rtc.rtc_dow	= (uint8_t)tod.tod_dow;
2580Sstevel@tonic-gate 	rtc.rtc_hrs	= (uint8_t)tod.tod_hour;
2590Sstevel@tonic-gate 	rtc.rtc_min	= (uint8_t)tod.tod_min;
2600Sstevel@tonic-gate 	rtc.rtc_sec	= (uint8_t)tod.tod_sec;
2610Sstevel@tonic-gate 	DPRINTF("todm5819_set: century=%d year=%d dom=%d hrs=%d\n",
2620Sstevel@tonic-gate 	    rtc.rtc_century, rtc.rtc_year, rtc.rtc_dom, rtc.rtc_hrs);
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate 	write_rtc_time(&rtc);
2650Sstevel@tonic-gate }
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate void
write_rtc_time(struct rtc_t * rtc)2680Sstevel@tonic-gate write_rtc_time(struct rtc_t *rtc)
2690Sstevel@tonic-gate {
2700Sstevel@tonic-gate 	uint8_t	regb;
271*11752STrevor.Thompson@Sun.COM 	int	i;
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate 	/*
2740Sstevel@tonic-gate 	 * Freeze
2750Sstevel@tonic-gate 	 */
2760Sstevel@tonic-gate 	regb = RTC_GET8(RTC_B);
2770Sstevel@tonic-gate 	RTC_PUT8(RTC_B, (regb | RTC_SET));
2780Sstevel@tonic-gate 
279*11752STrevor.Thompson@Sun.COM 	/*
280*11752STrevor.Thompson@Sun.COM 	 * If an update is in progress wait for the UIP flag to clear.
281*11752STrevor.Thompson@Sun.COM 	 * If we write whilst UIP is still set there is a slight but real
282*11752STrevor.Thompson@Sun.COM 	 * possibility of corrupting the RTC date and time registers.
283*11752STrevor.Thompson@Sun.COM 	 *
284*11752STrevor.Thompson@Sun.COM 	 * The expected wait is one internal cycle of the chip.  We could
285*11752STrevor.Thompson@Sun.COM 	 * simply spin but this may hang a CPU if we were to have a broken
286*11752STrevor.Thompson@Sun.COM 	 * RTC chip where UIP is stuck, so we use a retry loop instead.
287*11752STrevor.Thompson@Sun.COM 	 * No critical section is needed here as the UIP flag will not be
288*11752STrevor.Thompson@Sun.COM 	 * re-asserted until we clear RTC_SET.
289*11752STrevor.Thompson@Sun.COM 	 */
290*11752STrevor.Thompson@Sun.COM 	for (i = 0; i < TODM5819_UIP_RETRY_THRESH; i++) {
291*11752STrevor.Thompson@Sun.COM 		if (!(RTC_GET8(RTC_A) & RTC_UIP)) {
292*11752STrevor.Thompson@Sun.COM 			break;
293*11752STrevor.Thompson@Sun.COM 		}
294*11752STrevor.Thompson@Sun.COM 		drv_usecwait(TODM5819_UIP_WAIT_USEC);
295*11752STrevor.Thompson@Sun.COM 	}
296*11752STrevor.Thompson@Sun.COM 	if (i < TODM5819_UIP_RETRY_THRESH) {
297*11752STrevor.Thompson@Sun.COM 		RTC_PUT8(RTC_SEC, (rtc->rtc_sec));
298*11752STrevor.Thompson@Sun.COM 		RTC_PUT8(RTC_ASEC, (rtc->rtc_asec));
299*11752STrevor.Thompson@Sun.COM 		RTC_PUT8(RTC_MIN, (rtc->rtc_min));
300*11752STrevor.Thompson@Sun.COM 		RTC_PUT8(RTC_AMIN, (rtc->rtc_amin));
3010Sstevel@tonic-gate 
302*11752STrevor.Thompson@Sun.COM 		RTC_PUT8(RTC_HRS, (rtc->rtc_hrs));
303*11752STrevor.Thompson@Sun.COM 		RTC_PUT8(RTC_AHRS, (rtc->rtc_ahrs));
304*11752STrevor.Thompson@Sun.COM 		RTC_PUT8(RTC_DOW, (rtc->rtc_dow));
305*11752STrevor.Thompson@Sun.COM 		RTC_PUT8(RTC_DOM, (rtc->rtc_dom));
3060Sstevel@tonic-gate 
307*11752STrevor.Thompson@Sun.COM 		RTC_PUT8(RTC_MON, (rtc->rtc_mon));
308*11752STrevor.Thompson@Sun.COM 		RTC_PUT8(RTC_YEAR, (rtc->rtc_year));
309*11752STrevor.Thompson@Sun.COM 		RTC_PUT8(RTC_CENTURY, (rtc->rtc_century));
310*11752STrevor.Thompson@Sun.COM 	} else {
311*11752STrevor.Thompson@Sun.COM 		cmn_err(CE_WARN, "todm5819: Could not write the RTC\n");
312*11752STrevor.Thompson@Sun.COM 	}
3130Sstevel@tonic-gate 
3140Sstevel@tonic-gate 	/*
3150Sstevel@tonic-gate 	 * Unfreeze
3160Sstevel@tonic-gate 	 */
3170Sstevel@tonic-gate 	RTC_PUT8(RTC_B, regb);
3180Sstevel@tonic-gate }
3190Sstevel@tonic-gate 
3200Sstevel@tonic-gate 
3210Sstevel@tonic-gate void
write_rtc_alarm(struct rtc_t * rtc)3220Sstevel@tonic-gate write_rtc_alarm(struct rtc_t *rtc)
3230Sstevel@tonic-gate {
3240Sstevel@tonic-gate 	RTC_PUT8(RTC_ASEC, (rtc->rtc_asec));
3250Sstevel@tonic-gate 	RTC_PUT8(RTC_AMIN, (rtc->rtc_amin));
3260Sstevel@tonic-gate 	RTC_PUT8(RTC_AHRS, (rtc->rtc_ahrs));
3270Sstevel@tonic-gate 	RTC_PUT8(RTC_D, (rtc->rtc_adom));
3280Sstevel@tonic-gate }
3290Sstevel@tonic-gate 
3300Sstevel@tonic-gate /*
3310Sstevel@tonic-gate  * program the rtc registers for alarm to go off at the specified time
3320Sstevel@tonic-gate  */
3330Sstevel@tonic-gate static void
todm5819_set_power_alarm(timestruc_t ts)3340Sstevel@tonic-gate todm5819_set_power_alarm(timestruc_t ts)
3350Sstevel@tonic-gate {
3360Sstevel@tonic-gate 	todinfo_t	tod;
3370Sstevel@tonic-gate 	uint8_t		regb;
3380Sstevel@tonic-gate 	struct rtc_t	rtc;
3390Sstevel@tonic-gate 
3400Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&tod_lock));
3410Sstevel@tonic-gate 	tod = utc_to_tod(ts.tv_sec);
3420Sstevel@tonic-gate 
3430Sstevel@tonic-gate 	/*
3440Sstevel@tonic-gate 	 * disable alarms
3450Sstevel@tonic-gate 	 */
3460Sstevel@tonic-gate 	regb = RTC_GET8(RTC_B);
3470Sstevel@tonic-gate 	RTC_PUT8(RTC_B, (regb & ~RTC_AIE));
3480Sstevel@tonic-gate 
3490Sstevel@tonic-gate 
3500Sstevel@tonic-gate 	rtc.rtc_asec = (uint8_t)tod.tod_sec;
3510Sstevel@tonic-gate 	rtc.rtc_amin = (uint8_t)tod.tod_min;
3520Sstevel@tonic-gate 	rtc.rtc_ahrs = (uint8_t)tod.tod_hour;
3530Sstevel@tonic-gate 	rtc.rtc_adom = (uint8_t)tod.tod_day;
3540Sstevel@tonic-gate 
3550Sstevel@tonic-gate 	write_rtc_alarm(&rtc);
3560Sstevel@tonic-gate 	/*
3570Sstevel@tonic-gate 	 * Enable alarm.
3580Sstevel@tonic-gate 	 */
3590Sstevel@tonic-gate 	RTC_PUT8(RTC_B, (regb | RTC_AIE));
3600Sstevel@tonic-gate }
3610Sstevel@tonic-gate 
3620Sstevel@tonic-gate /*
3630Sstevel@tonic-gate  * clear alarm interrupt
3640Sstevel@tonic-gate  */
3650Sstevel@tonic-gate static void
todm5819_clear_power_alarm(void)3660Sstevel@tonic-gate todm5819_clear_power_alarm(void)
3670Sstevel@tonic-gate {
3680Sstevel@tonic-gate 	uint8_t regb;
3690Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&tod_lock));
3700Sstevel@tonic-gate 
3710Sstevel@tonic-gate 	regb = RTC_GET8(RTC_B);
3720Sstevel@tonic-gate 	RTC_PUT8(RTC_B, (regb & ~RTC_AIE));
3730Sstevel@tonic-gate }
3740Sstevel@tonic-gate 
3750Sstevel@tonic-gate /*
3760Sstevel@tonic-gate  * Determine the cpu frequency by watching the TOD chip rollover twice.
3770Sstevel@tonic-gate  * Cpu clock rate is determined by computing the ticks added (in tick register)
3780Sstevel@tonic-gate  * during one second interval on TOD.
3790Sstevel@tonic-gate  */
3800Sstevel@tonic-gate uint64_t
todm5819_get_cpufrequency(void)3810Sstevel@tonic-gate todm5819_get_cpufrequency(void)
3820Sstevel@tonic-gate {
3830Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&tod_lock));
3840Sstevel@tonic-gate 	M5819_ADDR_REG = RTC_SEC;
3850Sstevel@tonic-gate 	return (find_cpufrequency(v_rtc_data_reg));
3860Sstevel@tonic-gate }
3870Sstevel@tonic-gate 
3880Sstevel@tonic-gate 
3890Sstevel@tonic-gate /*ARGSUSED*/
3900Sstevel@tonic-gate static uint_t
todm5819_set_watchdog_timer(uint_t timeoutval)3910Sstevel@tonic-gate todm5819_set_watchdog_timer(uint_t timeoutval)
3920Sstevel@tonic-gate {
3930Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&tod_lock));
3940Sstevel@tonic-gate 	return (0);
3950Sstevel@tonic-gate }
3960Sstevel@tonic-gate 
3970Sstevel@tonic-gate static uint_t
todm5819_clear_watchdog_timer(void)3980Sstevel@tonic-gate todm5819_clear_watchdog_timer(void)
3990Sstevel@tonic-gate {
4000Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&tod_lock));
4010Sstevel@tonic-gate 	return (0);
4020Sstevel@tonic-gate }
403