xref: /titanic_44/usr/src/uts/sun4u/sys/todds1337.h (revision 4a634bb80136cc001d14ab96addd9915105e5223)
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	_TODDS1337_H
27 #define	_TODDS1337_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	DS1337_ADDR_REG		*(volatile uint8_t *)v_rtc_addr_reg
41 #define	DS1337_DATA_REG		*(volatile uint8_t *)v_rtc_data_reg
42 #define	DS1337_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_asec;	/* Alarm #1 seconds */
53 	uint8_t		rtc_amin;	/* Alarm #1 minutes */
54 	uint8_t		rtc_ahrs;	/* Alarm #1 hours   */
55 	uint8_t		rtc_aday;	/* Alarm #1 day [month/week] */
56 	uint8_t		rtc_a2min;	/* Alarm #2 minutes */
57 	uint8_t		rtc_a2hrs;	/* Alarm #2 hours   */
58 	uint8_t		rtc_a2day;	/* Alarm #2 day [month/week] */
59 	uint8_t		rtc_ctl;	/* DS1337 Control register */
60 	uint8_t		rtc_status;	/* DS1337 Status register  */
61 };
62 
63 
64 /*
65  * Register definitions for RTC driver (DS1337 chip)
66  */
67 
68 #define	RTC_SEC		0x00	/* 00h Second */
69 #define	RTC_MIN		0x01	/* 01h Minutes */
70 #define	RTC_HRS		0x02	/* 02h Hours */
71 #define	RTC_DOW		0x03	/* 03h Day-of-week */
72 #define	RTC_DOM		0x04	/* 04h Day-of-month */
73 #define	RTC_MON		0x05	/* 05h Month */
74 #define	RTC_YEAR	0x06	/* 06h Year */
75 #define	RTC_ALARM_SEC	0x07	/* 07h Alarm #1 Second  */
76 #define	RTC_ALARM_MIN	0x08	/* 08h Alarm #1 Minutes */
77 #define	RTC_ALARM_HRS	0x09	/* 09h Alarm #1 Hours   */
78 #define	RTC_ALARM_DAY	0x0a	/* 0Ah Alarm #1 Day [month/week] */
79 #define	RTC_CTL		0x0e	/* 0Eh Control register */
80 #define	RTC_STATUS	0x0f	/* 0Fh Status register  */
81 
82 #define	RTC_DYDT_MASK	0x40
83 
84 /*
85  * Control register definitions
86  */
87 
88 #define	RTC_CTL_EOSC	0x80	/* Active low */
89 #define	RTC_CTL_RS2	0x10
90 #define	RTC_CTL_RS1	0x08
91 #define	RTC_CTL_INTCN	0x04
92 #define	RTC_CTL_A2IE	0x02
93 #define	RTC_CTL_A1IE	0x01
94 
95 
96 /*
97  * Status register definitions
98  */
99 
100 #define	RTC_STATUS_OSF	0x80
101 #define	RTC_STATUS_A2F	0x02
102 #define	RTC_STATUS_A1F	0x01
103 
104 /* per instance based */
105 
106 #define	TOD_DETACHED		0x00	/* TOD detached */
107 #define	TOD_ATTACHED		0x01	/* TOD attached */
108 
109 typedef struct ds1337_state {
110 	i2c_client_hdl_t	ds1337_i2c_hdl;
111 	char			i2ctod_name[MAXNAMELEN];  /* node name */
112 	kmutex_t		i2ctod_mutex;   /* protects soft state */
113 	int			instance;
114 	dev_info_t		*dip;
115 	uint32_t		state;
116 	ddi_periodic_t		cycid; /* periodical callback */
117 	struct rtc_t		rtc;
118 	i2c_transfer_t		*i2c_tp;
119 	ddi_softintr_t   	soft_intr_id;
120 	uint32_t		progress;
121 }ds1337_state_t;
122 
123 #ifdef	__cplusplus
124 }
125 #endif
126 
127 #endif	/* _TODDS1337_H */
128