txioman.c revision 1.1
1/*	$NetBSD: txioman.c,v 1.1 2000/01/16 21:47:00 uch Exp $ */
2
3/*
4 * Copyright (c) 2000, by UCHIYAMA Yasushi
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. The name of the developer may NOT be used to endorse or promote products
13 *    derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 */
28#include "opt_tx39_debug.h"
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/device.h>
33
34#include <machine/bus.h>
35#include <machine/intr.h>
36
37#include <machine/config_hook.h>
38#include <machine/platid.h>
39#include <machine/platid_mask.h>
40
41#include <hpcmips/tx/tx39var.h>
42#include <hpcmips/tx/tx39iovar.h>
43
44#include <hpcmips/tx/txiomanvar.h>
45#include <hpcmips/tx/txsnd.h>
46
47#include "locators.h"
48
49int	txioman_match __P((struct device*, struct cfdata*, void*));
50void	txioman_attach __P((struct device*, struct device*, void*));
51
52struct txioman_softc {
53	struct	device sc_dev;
54	tx_chipset_tag_t sc_tc;
55};
56
57struct cfattach txioman_ca = {
58	sizeof(struct txioman_softc), txioman_match, txioman_attach
59};
60
61void	__txioman_led		__P((txioman_tag_t, int, int));
62void	__txioman_backlight	__P((txioman_tag_t, int));
63void	__txioman_uart_init	__P((txioman_tag_t));
64void	__txioman_uarta_init	__P((txioman_tag_t, void*));
65
66struct txioman_tag txioman_null_tag = {
67	NULL,
68	__txioman_led,
69	__txioman_backlight,
70	__txioman_uart_init,
71	__txioman_uarta_init,
72};
73
74void	__mobilon_backlight	__P((txioman_tag_t, int));
75void	__mobilon_uart_init	__P((txioman_tag_t));
76void	__mobilon_uarta_init	__P((txioman_tag_t, void*));
77
78struct txioman_tag txioman_mobilon_tag = {
79	NULL,
80	__txioman_led,
81	__mobilon_backlight,
82	__mobilon_uart_init,
83	__mobilon_uarta_init,
84};
85
86void	__compaq_led		__P((txioman_tag_t, int, int));
87void	__compaq_uarta_init	__P((txioman_tag_t, void*));
88
89struct txioman_tag txioman_compaq_tag = {
90	NULL,
91	__compaq_led,
92	__txioman_backlight,
93	__txioman_uart_init,
94	__compaq_uarta_init,
95};
96
97const struct txioman_platform_table {
98	platid_t	tp_platform;
99	char*		tp_name;
100	txioman_tag_t	tp_tag;
101} txioman_platform_table[] = {
102	{{{PLATID_WILD, PLATID_MACH_COMPAQ_C}},
103	 "Compaq-C",
104	 &txioman_compaq_tag},
105
106	{{{PLATID_WILD, PLATID_MACH_SHARP_MOBILON}},
107	 "Mobilon HC",
108	 &txioman_mobilon_tag},
109
110	{{{0, 0}}, "", &txioman_null_tag}
111};
112
113txioman_tag_t	txioman_tag_lookup __P((void));
114
115int	__config_hook_backlight __P((void*, int, long, void*));
116
117int
118txioman_match(parent, cf, aux)
119	struct device *parent;
120	struct cfdata *cf;
121	void *aux;
122{
123	platid_mask_t mask;
124
125	if (cf->cf_loc[TXIOMANIFCF_PLATFORM] ==
126	    TXIOMANIFCF_PLATFORM_DEFAULT) {
127		return 1;
128	}
129
130	mask = PLATID_DEREF(cf->cf_loc[TXIOMANIFCF_PLATFORM]);
131	if (platid_match(&platid, &mask)) {
132		return 2;
133	}
134
135	return 0;
136}
137
138void
139txioman_attach(parent, self, aux)
140	struct device *parent;
141	struct device *self;
142	void *aux;
143{
144	struct txioman_attach_args *tia = aux;
145	struct txioman_softc *sc = (void*)self;
146	txioman_tag_t tag;
147
148	sc->sc_tc = tia->tia_tc;
149
150	tag = txioman_tag_lookup();
151	tag->ti_v = sc;
152
153	/*
154	 * register myself to tx_chipset.
155	 */
156	tx_conf_register_ioman(sc->sc_tc, tag);
157
158	/*
159	 * register backlight config_hook if any.
160	 */
161	config_hook(CONFIG_HOOK_BUTTONEVENT,
162		    CONFIG_HOOK_BUTTONEVENT_LIGHT,
163		    CONFIG_HOOK_SHARE, /* btnmgr */
164		    __config_hook_backlight, sc->sc_tc);
165
166}
167
168txioman_tag_t
169txioman_tag_lookup()
170{
171	const struct txioman_platform_table *tab;
172	platid_mask_t mask;
173
174	for (tab = txioman_platform_table;
175	     tab->tp_tag != &txioman_null_tag; tab++) {
176
177		mask = PLATID_DEREF(&tab->tp_platform);
178
179		if (platid_match(&platid, &mask))
180			goto out;
181	}
182out:
183	printf(": %s\n", tab->tp_name);
184
185	return tab->tp_tag;
186}
187
188/*
189 * default functions.
190 */
191void
192__txioman_led(ti, type, onoff)
193	txioman_tag_t ti;
194	int type, onoff;
195{
196}
197
198void
199__txioman_backlight(ti, onoff)
200	txioman_tag_t ti;
201	int onoff;
202{
203}
204
205void
206__txioman_uart_init(ti)
207	txioman_tag_t ti;
208{
209}
210
211void
212__txioman_uarta_init(ti, cookie)
213	txioman_tag_t ti;
214	void *cookie;
215{
216}
217
218/*
219 * Compaq-C functions.
220 */
221void
222__compaq_led(ti, type, onoff)
223	txioman_tag_t ti;
224	int type, onoff;
225{
226	struct txioman_softc *sc = (void*)ti;
227
228	/* Green LED */
229	tx39io_portout(sc->sc_tc, TXPORT(TXMFIO, 3),
230		       onoff ? TXOFF : TXON);
231}
232
233extern int	__compaq_uart_dcd	__P((void*));
234extern int	__mobilon_uart_dcd	__P((void*));
235
236void
237__compaq_uarta_init(ti, cookie)
238	txioman_tag_t ti;
239	void *cookie;
240{
241	struct txioman_softc *sc = (void*)ti;
242	tx_chipset_tag_t tc = sc->sc_tc;
243
244	tx_intr_establish(tc, MAKEINTR(3, (1<<30)), IST_EDGE, IPL_TTY,
245			  __compaq_uart_dcd, cookie);
246	tx_intr_establish(tc, MAKEINTR(4, (1<<30)), IST_EDGE, IPL_TTY,
247			  __compaq_uart_dcd, cookie);
248	tx_intr_establish(tc, MAKEINTR(3, (1<<5)), IST_EDGE, IPL_TTY,
249			  __compaq_uart_dcd, cookie);
250	tx_intr_establish(tc, MAKEINTR(4, (1<<5)), IST_EDGE, IPL_TTY,
251			  __compaq_uart_dcd, cookie);
252}
253
254/*
255 * Mobilon HC functions
256 */
257void
258__mobilon_backlight(ti, onoff)
259	txioman_tag_t ti;
260	int onoff;
261{
262	struct txioman_softc *sc = (void*)ti;
263
264	tx39io_portout(sc->sc_tc, TXPORT(TXMFIO, 14),
265		       onoff ? TXON : TXOFF);
266}
267
268void
269__mobilon_uart_init(ti)
270	txioman_tag_t ti;
271{
272	struct txioman_softc *sc = (void*)ti;
273
274	tx39io_portout(sc->sc_tc, TXPORT(TXIO, 5), TXON);
275	tx39io_portout(sc->sc_tc, TXPORT(TXMFIO, 15), TXON);
276}
277
278void
279__mobilon_uarta_init(ti, cookie)
280	txioman_tag_t ti;
281	void *cookie;
282{
283#if not_required /* ??? this is harmful... */
284	struct txioman_softc *sc = (void*)ti;
285	tx_chipset_tag_t tc = sc->sc_tc;
286
287	tx_intr_establish(tc, MAKEINTR(5, (1<<4)), IST_EDGE, IPL_TTY,
288			  __mobilon_uart_dcd, cookie);
289	tx_intr_establish(tc, MAKEINTR(5, (1<<11)), IST_EDGE, IPL_TTY,
290			  __mobilon_uart_dcd, cookie);
291	tx_intr_establish(tc, MAKEINTR(5, (1<<6)), IST_EDGE, IPL_TTY,
292			  __mobilon_uart_dcd, cookie);
293	tx_intr_establish(tc, MAKEINTR(5, (1<<13)), IST_EDGE, IPL_TTY,
294			  __mobilon_uart_dcd, cookie);
295#endif
296}
297
298/*
299 * config_hook.
300 */
301int
302__config_hook_backlight(arg, type, id, msg)
303	void*	arg;
304	int	type;
305	long	id;
306	void*	msg;
307{
308	static int onoff; /* XXX */
309	tx_chipset_tag_t tc = arg;
310
311	onoff ^= 1;
312
313	txioman_backlight(tc, onoff);
314	txioman_led(tc, 0, onoff); /* test */
315	tx_sound_mute(tc, !onoff); /* test */
316
317	return 0;
318}
319