1184299Snwhitehorn/*-
2184299Snwhitehorn * Copyright (c) 2006 Michael Lorenz
3184299Snwhitehorn * Copyright (c) 2008 Nathan Whitehorn
4184299Snwhitehorn * All rights reserved.
5184299Snwhitehorn *
6184299Snwhitehorn * Redistribution and use in source and binary forms, with or without
7184299Snwhitehorn * modification, are permitted provided that the following conditions
8184299Snwhitehorn * are met:
9184299Snwhitehorn * 1. Redistributions of source code must retain the above copyright
10184299Snwhitehorn *    notice, this list of conditions and the following disclaimer.
11184299Snwhitehorn * 2. Redistributions in binary form must reproduce the above copyright
12184299Snwhitehorn *    notice, this list of conditions and the following disclaimer in the
13184299Snwhitehorn *    documentation and/or other materials provided with the distribution.
14184299Snwhitehorn * 3. Neither the name of The NetBSD Foundation nor the names of its
15184299Snwhitehorn *    contributors may be used to endorse or promote products derived
16184299Snwhitehorn *    from this software without specific prior written permission.
17184299Snwhitehorn *
18184299Snwhitehorn * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19184299Snwhitehorn * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20184299Snwhitehorn * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21184299Snwhitehorn * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22184299Snwhitehorn * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23184299Snwhitehorn * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24184299Snwhitehorn * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25184299Snwhitehorn * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26184299Snwhitehorn * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27184299Snwhitehorn * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28184299Snwhitehorn * POSSIBILITY OF SUCH DAMAGE.
29184299Snwhitehorn *
30184299Snwhitehorn * $FreeBSD$
31184299Snwhitehorn *
32184299Snwhitehorn */
33184299Snwhitehorn
34184299Snwhitehorn#ifndef	_POWERPC_CUDAVAR_H_
35184299Snwhitehorn#define	_POWERPC_CUDAVAR_H_
36184299Snwhitehorn
37184299Snwhitehorn#define CUDA_DEVSTR	"Apple CUDA I/O Controller"
38186046Snwhitehorn#define	CUDA_MAXPACKETS	10
39184299Snwhitehorn
40184299Snwhitehorn/* Cuda addresses */
41184299Snwhitehorn#define CUDA_ADB	0
42184299Snwhitehorn#define CUDA_PSEUDO	1
43184299Snwhitehorn#define CUDA_ERROR	2	/* error codes? */
44184299Snwhitehorn#define CUDA_TIMER	3
45184299Snwhitehorn#define CUDA_POWER	4
46184299Snwhitehorn#define CUDA_IIC	5	/* XXX ??? */
47184299Snwhitehorn#define CUDA_PMU	6
48184299Snwhitehorn#define CUDA_ADB_QUERY	7
49184299Snwhitehorn
50184299Snwhitehorn/* Cuda commands */
51184299Snwhitehorn#define CMD_AUTOPOLL	1
52184299Snwhitehorn#define CMD_READ_RTC	3
53184299Snwhitehorn#define CMD_WRITE_RTC	9
54184299Snwhitehorn#define CMD_POWEROFF	10
55184299Snwhitehorn#define CMD_RESET	17
56184299Snwhitehorn#define CMD_IIC		34
57184299Snwhitehorn
58184299Snwhitehorn/* Cuda state codes */
59184299Snwhitehorn#define CUDA_NOTREADY	0x1	/* has not been initialized yet */
60184299Snwhitehorn#define CUDA_IDLE	0x2	/* the bus is currently idle */
61184299Snwhitehorn#define CUDA_OUT	0x3	/* sending out a command */
62184299Snwhitehorn#define CUDA_IN		0x4	/* receiving data */
63184299Snwhitehorn#define CUDA_POLLING	0x5	/* polling - II only */
64184299Snwhitehorn
65185724Snwhitehornstruct cuda_packet {
66185724Snwhitehorn	uint8_t len;
67185724Snwhitehorn	uint8_t type;
68185724Snwhitehorn
69185724Snwhitehorn	uint8_t data[253];
70185724Snwhitehorn	STAILQ_ENTRY(cuda_packet) pkt_q;
71185724Snwhitehorn};
72185724Snwhitehorn
73185724SnwhitehornSTAILQ_HEAD(cuda_pktq, cuda_packet);
74185724Snwhitehorn
75184299Snwhitehornstruct cuda_softc {
76184299Snwhitehorn	device_t	sc_dev;
77184299Snwhitehorn	int		sc_memrid;
78184299Snwhitehorn	struct resource	*sc_memr;
79184299Snwhitehorn	int     	sc_irqrid;
80184299Snwhitehorn        struct resource *sc_irq;
81184299Snwhitehorn        void    	*sc_ih;
82184299Snwhitehorn
83184299Snwhitehorn	struct mtx	sc_mutex;
84184299Snwhitehorn
85184299Snwhitehorn	device_t	adb_bus;
86184299Snwhitehorn
87185724Snwhitehorn	int		sc_node;
88185724Snwhitehorn	volatile int	sc_state;
89185724Snwhitehorn	int		sc_waiting;
90185724Snwhitehorn	int		sc_polling;
91185724Snwhitehorn	int		sc_iic_done;
92185724Snwhitehorn	volatile int	sc_autopoll;
93205506Snwhitehorn	uint32_t	sc_rtc;
94184299Snwhitehorn
95184299Snwhitehorn	int sc_i2c_read_len;
96184299Snwhitehorn
97184299Snwhitehorn	/* internal buffers */
98185724Snwhitehorn	uint8_t		sc_in[256];
99185724Snwhitehorn	uint8_t		sc_out[256];
100185724Snwhitehorn	int		sc_sent;
101185724Snwhitehorn	int		sc_out_length;
102185724Snwhitehorn	int		sc_received;
103185724Snwhitehorn
104186046Snwhitehorn	struct cuda_packet sc_pkts[CUDA_MAXPACKETS];
105185724Snwhitehorn	struct cuda_pktq sc_inq;
106185724Snwhitehorn	struct cuda_pktq sc_outq;
107186046Snwhitehorn	struct cuda_pktq sc_freeq;
108184299Snwhitehorn};
109184299Snwhitehorn
110184299Snwhitehorn#endif /* _POWERPC_CUDAVAR_H_ */
111