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