/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* tod driver module for ALI M5819P part
*/
#include <sys/todm5819p.h>
#include <sys/rmc_comm_dp.h>
#include <sys/rmc_comm_drvintf.h>
#include <sys/machsystm.h>
static timestruc_t todm5819p_rmc_get(void);
static void todm5819p_rmc_set(timestruc_t);
static uint_t todm5819p_rmc_clear_watchdog_timer(void);
static void todm5819p_rmc_set_power_alarm(timestruc_t);
static void todm5819p_rmc_clear_power_alarm(void);
static uint64_t todm5819p_rmc_get_cpufrequency(void);
/*
* External variables
*/
extern int watchdog_enable;
extern int watchdog_available;
extern int boothowto;
/*
* Global variables
*/
int m5819p_debug_flags;
/*
* Module linkage information for the kernel.
*/
&mod_miscops, "tod module for ALI M5819P"
};
};
static void write_rtc_time(struct rtc_t *);
static void write_rtc_alarm(struct rtc_t *);
int
_init(void)
{
"detected: hardware watchdog disabled");
}
}
return (mod_install(&modlinkage));
}
int
_fini(void)
{
return (EBUSY);
return (mod_remove(&modlinkage));
}
/*
* The loadable-module _info(9E) entry point
*/
int
{
}
/*
* Read the current time from the clock chip and convert to UNIX form.
* Assumes that the year in the clock chip is valid.
* Must be called with tod_lock held.
*/
static timestruc_t
todm5819p_rmc_get(void)
{
int i;
int s;
/* set the hw watchdog timer if it's been activated */
if (watchdog_activated) {
int ret = 0;
/*
* The empty set_watchdog routine returns a 0. So if a
* coded routine fails we will look for a -1 for a failure.
*/
if (ret == -1)
"watchdog timer.");
}
/*
* Read current time from the tod. If the tod isn't accessible, wait and
* retry.
* Run critical in the time critical section to avoid being interrupted
*/
for (i = 0; i < TODM5819_UIP_RETRY_THRESH; i++) {
s = ddi_enter_critical();
if (!(M5819P_DATA_REG & RTC_UIP)) {
break;
}
}
if (i == TODM5819_UIP_RETRY_THRESH) {
/*
* tod is inaccessible: just return current software time
*/
return (hrestime);
}
/* read was successful so ensure failure flag is clear */
return (ts);
}
static todinfo_t
{
/*
* tod_year is base 1900 so this code needs to adjust the true year
* retrieved from the rtc's century and year fields.
*/
return (tod);
}
static void
{
/* Read date alarm */
}
/*
* Write the specified time into the clock chip.
* Must be called with tod_lock held.
*/
static void
{
int year;
/* tod_year is base 1900 so this code needs to adjust */
(void) rmc_comm_request_nowait(&request, 0);
}
void
{
int i;
/*
* Freeze
*/
/*
* If an update cycle is in progress wait for the UIP flag to
* clear. If we write whilst UIP is still set there is a slight
* but real possibility of corrupting the RTC date and time
* registers.
*
* The expected wait is one internal cycle of the chip. We could
* simply spin but this may hang a CPU if we were to have a broken
* RTC chip where UIP is stuck, so we use a retry loop instead.
* No critical section is needed here as the UIP flag will not be
* re-asserted until we clear RTC_SET.
*/
for (i = 0; i < TODM5819_UIP_RETRY_THRESH; i++) {
if (!(M5819P_DATA_REG & RTC_UIP)) {
break;
}
}
if (i < TODM5819_UIP_RETRY_THRESH) {
} else {
}
/*
* Unfreeze
*/
}
void
{
}
/*
* program the rtc registers for alarm to go off at the specified time
*/
static void
{
/*
* disable alarms and clear AF flag by reading reg C
*/
(void) M5819P_DATA_REG;
/*
* Write alarm values and enable alarm
*/
}
/*
* clear alarm interrupt
*/
static void
{
}
/*
* Determine the cpu frequency by watching the TOD chip rollover twice.
* Cpu clock rate is determined by computing the ticks added (in tick register)
* during one second interval on TOD.
*/
{
return (find_cpufrequency(v_rtc_data_reg));
}
/*ARGSUSED*/
static uint_t
{
return (0);
}
static uint_t
{
return (0);
}