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