xref: /freebsd/sys/powerpc/powermac/cudavar.h (revision f4b37ed0f8b307b1f3f0f630ca725d68f1dff30d)
1 /*-
2  * Copyright (c) 2006 Michael Lorenz
3  * Copyright (c) 2008 Nathan Whitehorn
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of The NetBSD Foundation nor the names of its
15  *    contributors may be used to endorse or promote products derived
16  *    from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  *
30  * $FreeBSD$
31  *
32  */
33 
34 #ifndef	_POWERPC_CUDAVAR_H_
35 #define	_POWERPC_CUDAVAR_H_
36 
37 #define CUDA_DEVSTR	"Apple CUDA I/O Controller"
38 #define	CUDA_MAXPACKETS	10
39 
40 /* Cuda addresses */
41 #define CUDA_ADB	0
42 #define CUDA_PSEUDO	1
43 #define CUDA_ERROR	2	/* error codes? */
44 #define CUDA_TIMER	3
45 #define CUDA_POWER	4
46 #define CUDA_IIC	5	/* XXX ??? */
47 #define CUDA_PMU	6
48 #define CUDA_ADB_QUERY	7
49 
50 /* Cuda commands */
51 #define CMD_AUTOPOLL	1
52 #define CMD_READ_RTC	3
53 #define CMD_WRITE_RTC	9
54 #define CMD_POWEROFF	10
55 #define CMD_RESET	17
56 #define CMD_IIC		34
57 
58 /* Cuda state codes */
59 #define CUDA_NOTREADY	0x1	/* has not been initialized yet */
60 #define CUDA_IDLE	0x2	/* the bus is currently idle */
61 #define CUDA_OUT	0x3	/* sending out a command */
62 #define CUDA_IN		0x4	/* receiving data */
63 #define CUDA_POLLING	0x5	/* polling - II only */
64 
65 struct cuda_packet {
66 	uint8_t len;
67 	uint8_t type;
68 
69 	uint8_t data[253];
70 	STAILQ_ENTRY(cuda_packet) pkt_q;
71 };
72 
73 STAILQ_HEAD(cuda_pktq, cuda_packet);
74 
75 struct cuda_softc {
76 	device_t	sc_dev;
77 	int		sc_memrid;
78 	struct resource	*sc_memr;
79 	int     	sc_irqrid;
80         struct resource *sc_irq;
81         void    	*sc_ih;
82 
83 	struct mtx	sc_mutex;
84 
85 	device_t	adb_bus;
86 
87 	int		sc_node;
88 	volatile int	sc_state;
89 	int		sc_waiting;
90 	int		sc_polling;
91 	int		sc_iic_done;
92 	volatile int	sc_autopoll;
93 	uint32_t	sc_rtc;
94 
95 	int sc_i2c_read_len;
96 
97 	/* internal buffers */
98 	uint8_t		sc_in[256];
99 	uint8_t		sc_out[256];
100 	int		sc_sent;
101 	int		sc_out_length;
102 	int		sc_received;
103 
104 	struct cuda_packet sc_pkts[CUDA_MAXPACKETS];
105 	struct cuda_pktq sc_inq;
106 	struct cuda_pktq sc_outq;
107 	struct cuda_pktq sc_freeq;
108 };
109 
110 #endif /* _POWERPC_CUDAVAR_H_ */
111