Home | History | Annotate | Line # | Download | only in dev
a34kbbc.c revision 1.3.8.1
      1  1.3.8.1  bouyer /*	$NetBSD: a34kbbc.c,v 1.3.8.1 2000/11/20 19:58:26 bouyer Exp $	*/
      2      1.1      is 
      3      1.1      is /*
      4      1.1      is  * Copyright (c) 1988 University of Utah.
      5      1.1      is  * Copyright (c) 1982, 1990 The Regents of the University of California.
      6      1.1      is  * All rights reserved.
      7      1.1      is  *
      8      1.1      is  * This code is derived from software contributed to Berkeley by
      9      1.1      is  * the Systems Programming Group of the University of Utah Computer
     10      1.1      is  * Science Department.
     11      1.1      is  *
     12      1.1      is  * Redistribution and use in source and binary forms, with or without
     13      1.1      is  * modification, are permitted provided that the following conditions
     14      1.1      is  * are met:
     15      1.1      is  * 1. Redistributions of source code must retain the above copyright
     16      1.1      is  *    notice, this list of conditions and the following disclaimer.
     17      1.1      is  * 2. Redistributions in binary form must reproduce the above copyright
     18      1.1      is  *    notice, this list of conditions and the following disclaimer in the
     19      1.1      is  *    documentation and/or other materials provided with the distribution.
     20      1.1      is  * 3. All advertising materials mentioning features or use of this software
     21      1.1      is  *    must display the following acknowledgement:
     22      1.1      is  *	This product includes software developed by the University of
     23      1.1      is  *	California, Berkeley and its contributors.
     24      1.1      is  * 4. Neither the name of the University nor the names of its contributors
     25      1.1      is  *    may be used to endorse or promote products derived from this software
     26      1.1      is  *    without specific prior written permission.
     27      1.1      is  *
     28      1.1      is  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     29      1.1      is  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     30      1.1      is  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     31      1.1      is  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     32      1.1      is  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     33      1.1      is  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     34      1.1      is  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     35      1.1      is  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     36      1.1      is  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     37      1.1      is  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     38      1.1      is  * SUCH DAMAGE.
     39      1.1      is  *
     40      1.1      is  * from: Utah $Hdr: clock.c 1.18 91/01/21$
     41      1.1      is  *
     42      1.1      is  *	@(#)clock.c	7.6 (Berkeley) 5/7/91
     43      1.1      is  */
     44      1.1      is 
     45      1.1      is #include <sys/param.h>
     46      1.1      is #include <sys/kernel.h>
     47      1.1      is #include <sys/device.h>
     48      1.1      is #include <sys/systm.h>
     49      1.1      is #include <machine/psl.h>
     50      1.1      is #include <machine/cpu.h>
     51      1.1      is #include <amiga/amiga/device.h>
     52      1.1      is #include <amiga/amiga/custom.h>
     53      1.1      is #include <amiga/amiga/cia.h>
     54      1.1      is #include <amiga/dev/rtc.h>
     55      1.1      is #include <amiga/dev/zbusvar.h>
     56      1.1      is 
     57      1.1      is #include <dev/clock_subr.h>
     58      1.1      is 
     59      1.1      is int a34kbbc_match __P((struct device *, struct cfdata *, void *));
     60      1.1      is void a34kbbc_attach __P((struct device *, struct device *, void *));
     61      1.1      is 
     62      1.1      is struct cfattach a34kbbc_ca = {
     63      1.1      is 	sizeof(struct device), a34kbbc_match, a34kbbc_attach
     64      1.1      is };
     65      1.1      is 
     66      1.1      is void *a34kclockaddr;
     67      1.3      is int a34kugettod __P((struct timeval *));
     68      1.3      is int a34kusettod __P((struct timeval *));
     69      1.1      is 
     70      1.1      is int
     71      1.1      is a34kbbc_match(pdp, cfp, auxp)
     72      1.1      is 	struct device *pdp;
     73      1.1      is 	struct cfdata *cfp;
     74      1.1      is 	void *auxp;
     75      1.1      is {
     76  1.3.8.1  bouyer 	static int a34kbbc_matched = 0;
     77  1.3.8.1  bouyer 
     78      1.1      is 	if (!matchname("a34kbbc", auxp))
     79      1.1      is 		return(0);
     80      1.1      is 
     81  1.3.8.1  bouyer 	/* Allow only once instance. */
     82  1.3.8.1  bouyer 	if (a34kbbc_matched)
     83  1.3.8.1  bouyer 		return(0);
     84      1.1      is 
     85      1.1      is 	if (!(is_a3000() || is_a4000()))
     86      1.1      is 		return(0);
     87      1.1      is 
     88      1.1      is 	a34kclockaddr = (void *)ztwomap(0xdc0000);
     89      1.3      is 	if (a34kugettod(0) == 0)
     90      1.1      is 		return(0);
     91      1.1      is 
     92  1.3.8.1  bouyer 	a34kbbc_matched = 1;
     93      1.1      is 	return(1);
     94      1.1      is }
     95      1.1      is 
     96      1.1      is /*
     97      1.1      is  * Attach us to the rtc function pointers.
     98      1.1      is  */
     99      1.1      is void
    100      1.1      is a34kbbc_attach(pdp, dp, auxp)
    101      1.1      is 	struct device *pdp, *dp;
    102      1.1      is 	void *auxp;
    103      1.1      is {
    104      1.1      is 	printf("\n");
    105      1.1      is 	a34kclockaddr = (void *)ztwomap(0xdc0000);
    106      1.1      is 
    107      1.3      is 	ugettod = a34kugettod;
    108      1.3      is 	usettod = a34kusettod;
    109      1.1      is }
    110      1.1      is 
    111      1.3      is int
    112      1.3      is a34kugettod(tvp)
    113      1.3      is 	struct timeval *tvp;
    114      1.1      is {
    115      1.1      is 	struct rtclock3000 *rt;
    116      1.1      is 	struct clock_ymdhms dt;
    117      1.1      is 	time_t secs;
    118      1.1      is 
    119      1.1      is 	rt = a34kclockaddr;
    120      1.1      is 
    121      1.1      is 	/* hold clock */
    122      1.1      is 	rt->control1 = A3CONTROL1_HOLD_CLOCK;
    123      1.1      is 
    124      1.1      is 	/* Copy the info.  Careful about the order! */
    125      1.1      is 	dt.dt_sec   = rt->second1 * 10 + rt->second2;
    126      1.1      is 	dt.dt_min   = rt->minute1 * 10 + rt->minute2;
    127      1.1      is 	dt.dt_hour  = rt->hour1   * 10 + rt->hour2;
    128      1.1      is 	dt.dt_wday  = rt->weekday;
    129      1.1      is 	dt.dt_day   = rt->day1    * 10 + rt->day2;
    130      1.1      is 	dt.dt_mon   = rt->month1  * 10 + rt->month2;
    131      1.1      is 	dt.dt_year  = rt->year1   * 10 + rt->year2;
    132      1.1      is 
    133      1.1      is 	dt.dt_year += CLOCK_BASE_YEAR;
    134      1.1      is 	/* let it run again.. */
    135      1.1      is 	rt->control1 = A3CONTROL1_FREE_CLOCK;
    136      1.1      is 
    137  1.3.8.1  bouyer 	if (dt.dt_year < STARTOFTIME)
    138  1.3.8.1  bouyer 		dt.dt_year += 100;
    139  1.3.8.1  bouyer 
    140  1.3.8.1  bouyer 
    141      1.1      is 	if ((dt.dt_hour > 23) ||
    142      1.1      is 	    (dt.dt_wday > 6) ||
    143      1.1      is 	    (dt.dt_day  > 31) ||
    144      1.1      is 	    (dt.dt_mon  > 12) ||
    145  1.3.8.1  bouyer 	    /* (dt.dt_year < STARTOFTIME) || */ (dt.dt_year > 2036))
    146      1.1      is 		return (0);
    147      1.1      is 
    148      1.1      is 	secs = clock_ymdhms_to_secs(&dt);
    149      1.3      is 	if (tvp)
    150      1.3      is 		tvp->tv_sec = secs;
    151      1.3      is 	return (1);
    152      1.1      is }
    153      1.1      is 
    154      1.1      is int
    155      1.3      is a34kusettod(tvp)
    156      1.3      is 	struct timeval *tvp;
    157      1.1      is {
    158      1.1      is 	struct rtclock3000 *rt;
    159      1.1      is 	struct clock_ymdhms dt;
    160      1.3      is 	time_t secs;
    161      1.1      is 
    162      1.1      is 	rt = a34kclockaddr;
    163      1.3      is 	secs = tvp->tv_sec;
    164      1.1      is 	/*
    165      1.1      is 	 * there seem to be problems with the bitfield addressing
    166      1.1      is 	 * currently used..
    167      1.1      is 	 */
    168      1.1      is 
    169      1.1      is 	if (! rt)
    170      1.1      is 		return (0);
    171      1.1      is 
    172      1.1      is 	clock_secs_to_ymdhms(secs, &dt);
    173      1.1      is 
    174  1.3.8.1  bouyer 	rt->control1 = A3CONTROL1_HOLD_CLOCK;		/* implies mode 0 */
    175      1.1      is 	rt->second1 = dt.dt_sec / 10;
    176      1.1      is 	rt->second2 = dt.dt_sec % 10;
    177      1.1      is 	rt->minute1 = dt.dt_min / 10;
    178      1.1      is 	rt->minute2 = dt.dt_min % 10;
    179      1.1      is 	rt->hour1   = dt.dt_hour / 10;
    180      1.1      is 	rt->hour2   = dt.dt_hour % 10;
    181      1.1      is 	rt->weekday = dt.dt_wday;
    182      1.1      is 	rt->day1    = dt.dt_day / 10;
    183      1.1      is 	rt->day2    = dt.dt_day % 10;
    184      1.1      is 	rt->month1  = dt.dt_mon / 10;
    185      1.1      is 	rt->month2  = dt.dt_mon % 10;
    186  1.3.8.1  bouyer 	rt->year1   = (dt.dt_year / 10) % 10;
    187      1.1      is 	rt->year2   = dt.dt_year % 10;
    188  1.3.8.1  bouyer 	rt->control1 = A3CONTROL1_HOLD_CLOCK | 1;	/* mode 1 registers */
    189  1.3.8.1  bouyer 	rt->leapyear = dt.dt_year; 		/* XXX implicit % 4 */
    190  1.3.8.1  bouyer 	rt->control1 = A3CONTROL1_FREE_CLOCK;		/* implies mode 1 */
    191      1.1      is 
    192      1.1      is 	return (1);
    193      1.1      is }
    194