xref: /titanic_52/usr/src/uts/sun4u/sys/todds1337.h (revision 734b6a94890be549309b21156f8ed6d4561cac51)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_TODDS1337_H
28 #define	_TODDS1337_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/cyclic.h>
37 #include <sys/i2c/clients/i2c_client.h>
38 
39 extern char	*v_rtc_addr_reg;
40 extern volatile uint8_t	*v_rtc_data_reg;
41 
42 #define	DS1337_ADDR_REG		*(volatile uint8_t *)v_rtc_addr_reg
43 #define	DS1337_DATA_REG		*(volatile uint8_t *)v_rtc_data_reg
44 #define	DS1337_NODE_TYPE	"ddi_i2c:tod"
45 
46 struct rtc_t {
47 	uint8_t		rtc_sec;	/* Seconds[0-60] */
48 	uint8_t		rtc_min;	/* Minutes[0-60] */
49 	uint8_t		rtc_hrs;	/* Hours[(1-12)/(0-23)] */
50 	uint8_t		rtc_dow;	/* Day of week[1-7] */
51 	uint8_t		rtc_dom;	/* Day of month[(1-28/29/30/31)] */
52 	uint8_t		rtc_mon;	/* Month[1-12] */
53 	uint8_t		rtc_year;	/* Year[00-99] */
54 	uint8_t		rtc_asec;	/* Alarm #1 seconds */
55 	uint8_t		rtc_amin;	/* Alarm #1 minutes */
56 	uint8_t		rtc_ahrs;	/* Alarm #1 hours   */
57 	uint8_t		rtc_aday;	/* Alarm #1 day [month/week] */
58 	uint8_t		rtc_a2min;	/* Alarm #2 minutes */
59 	uint8_t		rtc_a2hrs;	/* Alarm #2 hours   */
60 	uint8_t		rtc_a2day;	/* Alarm #2 day [month/week] */
61 	uint8_t		rtc_ctl;	/* DS1337 Control register */
62 	uint8_t		rtc_status;	/* DS1337 Status register  */
63 };
64 
65 
66 /*
67  * Register definitions for RTC driver (DS1337 chip)
68  */
69 
70 #define	RTC_SEC		0x00	/* 00h Second */
71 #define	RTC_MIN		0x01	/* 01h Minutes */
72 #define	RTC_HRS		0x02	/* 02h Hours */
73 #define	RTC_DOW		0x03	/* 03h Day-of-week */
74 #define	RTC_DOM		0x04	/* 04h Day-of-month */
75 #define	RTC_MON		0x05	/* 05h Month */
76 #define	RTC_YEAR	0x06	/* 06h Year */
77 #define	RTC_ALARM_SEC	0x07	/* 07h Alarm #1 Second  */
78 #define	RTC_ALARM_MIN	0x08	/* 08h Alarm #1 Minutes */
79 #define	RTC_ALARM_HRS	0x09	/* 09h Alarm #1 Hours   */
80 #define	RTC_ALARM_DAY	0x0a	/* 0Ah Alarm #1 Day [month/week] */
81 #define	RTC_CTL		0x0e	/* 0Eh Control register */
82 #define	RTC_STATUS	0x0f	/* 0Fh Status register  */
83 
84 #define	RTC_DYDT_MASK	0x40
85 
86 /*
87  * Control register definitions
88  */
89 
90 #define	RTC_CTL_EOSC	0x80	/* Active low */
91 #define	RTC_CTL_RS2	0x10
92 #define	RTC_CTL_RS1	0x08
93 #define	RTC_CTL_INTCN	0x04
94 #define	RTC_CTL_A2IE	0x02
95 #define	RTC_CTL_A1IE	0x01
96 
97 
98 /*
99  * Status register definitions
100  */
101 
102 #define	RTC_STATUS_OSF	0x80
103 #define	RTC_STATUS_A2F	0x02
104 #define	RTC_STATUS_A1F	0x01
105 
106 /* per instance based */
107 
108 #define	TOD_DETACHED		0x00	/* TOD detached */
109 #define	TOD_ATTACHED		0x01	/* TOD attached */
110 
111 typedef struct ds1337_state {
112 	i2c_client_hdl_t	ds1337_i2c_hdl;
113 	char			i2ctod_name[MAXNAMELEN];  /* node name */
114 	kmutex_t		i2ctod_mutex;   /* protects soft state */
115 	int			instance;
116 	dev_info_t		*dip;
117 	uint32_t		state;
118 	cyclic_id_t		cycid;
119 	struct rtc_t		rtc;
120 	i2c_transfer_t		*i2c_tp;
121 	ddi_softintr_t   	soft_intr_id;
122 	uint32_t		progress;
123 }ds1337_state_t;
124 
125 #ifdef	__cplusplus
126 }
127 #endif
128 
129 #endif	/* _TODDS1337_H */
130