Home | History | Annotate | Line # | Download | only in dev
clock_subr.h revision 1.19.50.1
      1 /*	$NetBSD: clock_subr.h,v 1.19.50.1 2008/06/02 13:23:11 mjf Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Gordon W. Ross
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #ifndef _DEV_CLOCK_SUBR_H_
     33 #define _DEV_CLOCK_SUBR_H_
     34 
     35 /*
     36  * "POSIX time" to/from "YY/MM/DD/hh/mm/ss"
     37  */
     38 struct clock_ymdhms {
     39 	u_short dt_year;
     40 	u_char dt_mon;
     41 	u_char dt_day;
     42 	u_char dt_wday;	/* Day of week */
     43 	u_char dt_hour;
     44 	u_char dt_min;
     45 	u_char dt_sec;
     46 };
     47 
     48 time_t	clock_ymdhms_to_secs(struct clock_ymdhms *);
     49 void	clock_secs_to_ymdhms(time_t, struct clock_ymdhms *);
     50 
     51 /*
     52  * BCD to binary and binary to BCD.
     53  */
     54 #define	FROMBCD(x)	bcdtobin((x))
     55 #define	TOBCD(x)	bintobcd((x))
     56 
     57 /* Some handy constants. */
     58 #define SECDAY		(24 * 60 * 60)
     59 #define SECYR		(SECDAY * 365)
     60 
     61 /* Traditional POSIX base year */
     62 #define	POSIX_BASE_YEAR	1970
     63 
     64 /*
     65  * Interface to time-of-day clock devices.
     66  *
     67  * todr_gettime: convert time-of-day clock into a `struct timeval'
     68  * todr_settime: set time-of-day clock from a `struct timeval'
     69  *
     70  * (this is probably not so useful:)
     71  * todr_setwen: provide a machine-dependent TOD clock write-enable callback
     72  *		function which takes one boolean argument:
     73  *			1 to enable writes; 0 to disable writes.
     74  */
     75 struct todr_chip_handle {
     76 	void	*cookie;	/* Device specific data */
     77 	void	*bus_cookie;	/* Bus specific data */
     78 	time_t	base_time;	/* Base time (e.g. rootfs time) */
     79 
     80 	int	(*todr_gettime)(struct todr_chip_handle *,
     81 				volatile struct timeval *);
     82 	int	(*todr_settime)(struct todr_chip_handle *,
     83 				volatile struct timeval *);
     84 	int	(*todr_gettime_ymdhms)(struct todr_chip_handle *,
     85 	    			struct clock_ymdhms *);
     86 	int	(*todr_settime_ymdhms)(struct todr_chip_handle *,
     87 	    			struct clock_ymdhms *);
     88 	int	(*todr_setwen)(struct todr_chip_handle *, int);
     89 
     90 };
     91 typedef struct todr_chip_handle *todr_chip_handle_t;
     92 
     93 #define todr_wenable(ct, v)	if ((ct)->todr_setwen) \
     94 					((*(ct)->todr_setwen)(ct, v))
     95 
     96 /*
     97  * Probably these should evolve into internal routines in kern_todr.c.
     98  */
     99 extern int todr_gettime(todr_chip_handle_t tch, volatile struct timeval *);
    100 extern int todr_settime(todr_chip_handle_t tch, volatile struct timeval *);
    101 
    102 /*
    103  * Machine-dependent function that machine-independent RTC drivers can
    104  * use to register their todr_chip_handle_t with inittodr()/resettodr().
    105  */
    106 void	todr_attach(todr_chip_handle_t);
    107 
    108 #endif /* _DEV_CLOCK_SUBR_H_ */
    109