todm5819p_rmc.c revision 1c42de6d020629af774dd9e9fc81be3f3ed9398e
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * CDDL HEADER START
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * The contents of this file are subject to the terms of the
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * Common Development and Distribution License (the "License").
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * You may not use this file except in compliance with the License.
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * See the License for the specific language governing permissions
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * and limitations under the License.
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * When distributing Covered Code, include this CDDL HEADER in each
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * If applicable, add the following below this CDDL HEADER, with the
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * fields enclosed by brackets "[]" replaced with your own identifying
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * information: Portions Copyright [yyyy] [name of copyright owner]
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * CDDL HEADER END
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * Use is subject to license terms.
1c42de6d020629af774dd9e9fc81be3f3ed9398egd#pragma ident "%Z%%M% %I% %E% SMI"
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * tod driver module for ALI M5819P part
1c42de6d020629af774dd9e9fc81be3f3ed9398egdstatic void todm5819p_rmc_clear_power_alarm(void);
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * External variables
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * Global variables
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * Module linkage information for the kernel.
1c42de6d020629af774dd9e9fc81be3f3ed9398egd tod_ops.tod_set_power_alarm = todm5819p_rmc_set_power_alarm;
1c42de6d020629af774dd9e9fc81be3f3ed9398egd tod_ops.tod_clear_power_alarm = todm5819p_rmc_clear_power_alarm;
1c42de6d020629af774dd9e9fc81be3f3ed9398egd tod_ops.tod_get_cpufrequency = todm5819p_rmc_get_cpufrequency;
1c42de6d020629af774dd9e9fc81be3f3ed9398egd "detected: hardware watchdog disabled");
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * The loadable-module _info(9E) entry point
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * Read the current time from the clock chip and convert to UNIX form.
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * Assumes that the year in the clock chip is valid.
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * Must be called with tod_lock held.
1c42de6d020629af774dd9e9fc81be3f3ed9398egd /* set the hw watchdog timer if it's been activated */
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * The empty set_watchdog routine returns a 0. So if a
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * coded routine fails we will look for a -1 for a failure.
1c42de6d020629af774dd9e9fc81be3f3ed9398egd "watchdog timer.");
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * Read current time from the tod. If the tod isn't accessible, wait and
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * Run critical in the time critical section to avoid being interrupted
1c42de6d020629af774dd9e9fc81be3f3ed9398egd for (i = 0; i < TODM5819_UIP_RETRY_THRESH; i++) {
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * tod is inaccessible: just return current software time
1c42de6d020629af774dd9e9fc81be3f3ed9398egd return (ts);
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * tod_year is base 1900 so this code needs to adjust the true year
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * retrieved from the rtc's century and year fields.
1c42de6d020629af774dd9e9fc81be3f3ed9398egd tod.tod_year = rtc->rtc_year + (rtc->rtc_century * 100) - 1900;
1c42de6d020629af774dd9e9fc81be3f3ed9398egdstatic void
1c42de6d020629af774dd9e9fc81be3f3ed9398egd /* Read date alarm */
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * Write the specified time into the clock chip.
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * Must be called with tod_lock held.
1c42de6d020629af774dd9e9fc81be3f3ed9398egdstatic void
1c42de6d020629af774dd9e9fc81be3f3ed9398egd /* tod_year is base 1900 so this code needs to adjust */
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * Unfreeze
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * program the rtc registers for alarm to go off at the specified time
1c42de6d020629af774dd9e9fc81be3f3ed9398egdstatic void
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * disable alarms and clear AF flag by reading reg C
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * Write alarm values and enable alarm
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * clear alarm interrupt
1c42de6d020629af774dd9e9fc81be3f3ed9398egdstatic void
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * Determine the cpu frequency by watching the TOD chip rollover twice.
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * Cpu clock rate is determined by computing the ticks added (in tick register)
1c42de6d020629af774dd9e9fc81be3f3ed9398egd * during one second interval on TOD.
1c42de6d020629af774dd9e9fc81be3f3ed9398egd/*ARGSUSED*/
1c42de6d020629af774dd9e9fc81be3f3ed9398egd return (0);
1c42de6d020629af774dd9e9fc81be3f3ed9398egd return (0);