xref: /titanic_41/usr/src/uts/sun4u/snowbird/sys/todds1307.h (revision fd06a699040f011e80ab8ac5213bb0a47858e69b)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_TODDS1307_H
27 #define	_TODDS1307_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #include <sys/i2c/clients/i2c_client.h>
36 
37 extern char	*v_rtc_addr_reg;
38 extern volatile uint8_t	*v_rtc_data_reg;
39 
40 #define	DS1307_ADDR_REG		*(volatile uint8_t *)v_rtc_addr_reg
41 #define	DS1307_DATA_REG		*(volatile uint8_t *)v_rtc_data_reg
42 #define	DS1307_NODE_TYPE	"ddi_i2c:tod"
43 
44 struct rtc_t {
45 	uint8_t		rtc_sec;	/* Seconds[0-60] */
46 	uint8_t		rtc_min;	/* Minutes[0-60] */
47 	uint8_t		rtc_hrs;	/* Hours[(1-12)/(0-23)] */
48 	uint8_t		rtc_dow;	/* Day of week[1-7] */
49 	uint8_t		rtc_dom;	/* Day of month[(1-28/29/30/31)] */
50 	uint8_t		rtc_mon;	/* Month[1-12] */
51 	uint8_t		rtc_year;	/* Year[00-99] */
52 	uint8_t		rtc_ctl;	/* DS1307 Control register */
53 };
54 
55 
56 /*
57  * Register definitions for RTC driver (DS1307 chip)
58  */
59 
60 #define	RTC_SEC		0x00	/* 00h Second */
61 #define	RTC_MIN		0x01	/* 01h Minutes */
62 #define	RTC_HRS		0x02	/* 02h Hours */
63 #define	RTC_DOW		0x03	/* 03h Day-of-week */
64 #define	RTC_DOM		0x04	/* 04h Day-of-month */
65 #define	RTC_MON		0x05	/* 05h Month */
66 #define	RTC_YEAR	0x06	/* 06h Year */
67 #define	RTC_CTL		0x07	/* 07h Control reg. */
68 
69 /* Oscillator */
70 
71 #define	OSCILLATOR_REG		0x00	/* Oscillator Reg Addr */
72 #define	OSCILLATOR_DISABLE	0x80
73 
74 /* per instance based */
75 
76 #define	TOD_DETACHED		0x00	/* TOD detached */
77 #define	TOD_ATTACHED		0x01	/* TOD attached */
78 
79 typedef struct ds1307_state {
80 	i2c_client_hdl_t	ds1307_i2c_hdl;
81 	char			i2ctod_name[MAXNAMELEN];  /* node name */
82 	kmutex_t		i2ctod_mutex;   /* protects soft state */
83 	int			instance;
84 	dev_info_t		*dip;
85 	uint32_t		state;
86 	ddi_periodic_t		cycid; /* periodical callback */
87 	struct rtc_t		rtc;
88 	i2c_transfer_t		*i2c_tp;
89 	ddi_softintr_t   	soft_intr_id;
90 	uint32_t		progress;
91 }ds1307_state_t;
92 
93 #ifdef	__cplusplus
94 }
95 #endif
96 
97 #endif	/* _TODDS1307_H */
98