txioman.c revision 1.1
11.1Such/*	$NetBSD: txioman.c,v 1.1 2000/01/16 21:47:00 uch Exp $ */
21.1Such
31.1Such/*
41.1Such * Copyright (c) 2000, by UCHIYAMA Yasushi
51.1Such * All rights reserved.
61.1Such *
71.1Such * Redistribution and use in source and binary forms, with or without
81.1Such * modification, are permitted provided that the following conditions
91.1Such * are met:
101.1Such * 1. Redistributions of source code must retain the above copyright
111.1Such *    notice, this list of conditions and the following disclaimer.
121.1Such * 2. The name of the developer may NOT be used to endorse or promote products
131.1Such *    derived from this software without specific prior written permission.
141.1Such *
151.1Such * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
161.1Such * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
171.1Such * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
181.1Such * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
191.1Such * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
201.1Such * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
211.1Such * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
221.1Such * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
231.1Such * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
241.1Such * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
251.1Such * SUCH DAMAGE.
261.1Such *
271.1Such */
281.1Such#include "opt_tx39_debug.h"
291.1Such
301.1Such#include <sys/param.h>
311.1Such#include <sys/systm.h>
321.1Such#include <sys/device.h>
331.1Such
341.1Such#include <machine/bus.h>
351.1Such#include <machine/intr.h>
361.1Such
371.1Such#include <machine/config_hook.h>
381.1Such#include <machine/platid.h>
391.1Such#include <machine/platid_mask.h>
401.1Such
411.1Such#include <hpcmips/tx/tx39var.h>
421.1Such#include <hpcmips/tx/tx39iovar.h>
431.1Such
441.1Such#include <hpcmips/tx/txiomanvar.h>
451.1Such#include <hpcmips/tx/txsnd.h>
461.1Such
471.1Such#include "locators.h"
481.1Such
491.1Suchint	txioman_match __P((struct device*, struct cfdata*, void*));
501.1Suchvoid	txioman_attach __P((struct device*, struct device*, void*));
511.1Such
521.1Suchstruct txioman_softc {
531.1Such	struct	device sc_dev;
541.1Such	tx_chipset_tag_t sc_tc;
551.1Such};
561.1Such
571.1Suchstruct cfattach txioman_ca = {
581.1Such	sizeof(struct txioman_softc), txioman_match, txioman_attach
591.1Such};
601.1Such
611.1Suchvoid	__txioman_led		__P((txioman_tag_t, int, int));
621.1Suchvoid	__txioman_backlight	__P((txioman_tag_t, int));
631.1Suchvoid	__txioman_uart_init	__P((txioman_tag_t));
641.1Suchvoid	__txioman_uarta_init	__P((txioman_tag_t, void*));
651.1Such
661.1Suchstruct txioman_tag txioman_null_tag = {
671.1Such	NULL,
681.1Such	__txioman_led,
691.1Such	__txioman_backlight,
701.1Such	__txioman_uart_init,
711.1Such	__txioman_uarta_init,
721.1Such};
731.1Such
741.1Suchvoid	__mobilon_backlight	__P((txioman_tag_t, int));
751.1Suchvoid	__mobilon_uart_init	__P((txioman_tag_t));
761.1Suchvoid	__mobilon_uarta_init	__P((txioman_tag_t, void*));
771.1Such
781.1Suchstruct txioman_tag txioman_mobilon_tag = {
791.1Such	NULL,
801.1Such	__txioman_led,
811.1Such	__mobilon_backlight,
821.1Such	__mobilon_uart_init,
831.1Such	__mobilon_uarta_init,
841.1Such};
851.1Such
861.1Suchvoid	__compaq_led		__P((txioman_tag_t, int, int));
871.1Suchvoid	__compaq_uarta_init	__P((txioman_tag_t, void*));
881.1Such
891.1Suchstruct txioman_tag txioman_compaq_tag = {
901.1Such	NULL,
911.1Such	__compaq_led,
921.1Such	__txioman_backlight,
931.1Such	__txioman_uart_init,
941.1Such	__compaq_uarta_init,
951.1Such};
961.1Such
971.1Suchconst struct txioman_platform_table {
981.1Such	platid_t	tp_platform;
991.1Such	char*		tp_name;
1001.1Such	txioman_tag_t	tp_tag;
1011.1Such} txioman_platform_table[] = {
1021.1Such	{{{PLATID_WILD, PLATID_MACH_COMPAQ_C}},
1031.1Such	 "Compaq-C",
1041.1Such	 &txioman_compaq_tag},
1051.1Such
1061.1Such	{{{PLATID_WILD, PLATID_MACH_SHARP_MOBILON}},
1071.1Such	 "Mobilon HC",
1081.1Such	 &txioman_mobilon_tag},
1091.1Such
1101.1Such	{{{0, 0}}, "", &txioman_null_tag}
1111.1Such};
1121.1Such
1131.1Suchtxioman_tag_t	txioman_tag_lookup __P((void));
1141.1Such
1151.1Suchint	__config_hook_backlight __P((void*, int, long, void*));
1161.1Such
1171.1Suchint
1181.1Suchtxioman_match(parent, cf, aux)
1191.1Such	struct device *parent;
1201.1Such	struct cfdata *cf;
1211.1Such	void *aux;
1221.1Such{
1231.1Such	platid_mask_t mask;
1241.1Such
1251.1Such	if (cf->cf_loc[TXIOMANIFCF_PLATFORM] ==
1261.1Such	    TXIOMANIFCF_PLATFORM_DEFAULT) {
1271.1Such		return 1;
1281.1Such	}
1291.1Such
1301.1Such	mask = PLATID_DEREF(cf->cf_loc[TXIOMANIFCF_PLATFORM]);
1311.1Such	if (platid_match(&platid, &mask)) {
1321.1Such		return 2;
1331.1Such	}
1341.1Such
1351.1Such	return 0;
1361.1Such}
1371.1Such
1381.1Suchvoid
1391.1Suchtxioman_attach(parent, self, aux)
1401.1Such	struct device *parent;
1411.1Such	struct device *self;
1421.1Such	void *aux;
1431.1Such{
1441.1Such	struct txioman_attach_args *tia = aux;
1451.1Such	struct txioman_softc *sc = (void*)self;
1461.1Such	txioman_tag_t tag;
1471.1Such
1481.1Such	sc->sc_tc = tia->tia_tc;
1491.1Such
1501.1Such	tag = txioman_tag_lookup();
1511.1Such	tag->ti_v = sc;
1521.1Such
1531.1Such	/*
1541.1Such	 * register myself to tx_chipset.
1551.1Such	 */
1561.1Such	tx_conf_register_ioman(sc->sc_tc, tag);
1571.1Such
1581.1Such	/*
1591.1Such	 * register backlight config_hook if any.
1601.1Such	 */
1611.1Such	config_hook(CONFIG_HOOK_BUTTONEVENT,
1621.1Such		    CONFIG_HOOK_BUTTONEVENT_LIGHT,
1631.1Such		    CONFIG_HOOK_SHARE, /* btnmgr */
1641.1Such		    __config_hook_backlight, sc->sc_tc);
1651.1Such
1661.1Such}
1671.1Such
1681.1Suchtxioman_tag_t
1691.1Suchtxioman_tag_lookup()
1701.1Such{
1711.1Such	const struct txioman_platform_table *tab;
1721.1Such	platid_mask_t mask;
1731.1Such
1741.1Such	for (tab = txioman_platform_table;
1751.1Such	     tab->tp_tag != &txioman_null_tag; tab++) {
1761.1Such
1771.1Such		mask = PLATID_DEREF(&tab->tp_platform);
1781.1Such
1791.1Such		if (platid_match(&platid, &mask))
1801.1Such			goto out;
1811.1Such	}
1821.1Suchout:
1831.1Such	printf(": %s\n", tab->tp_name);
1841.1Such
1851.1Such	return tab->tp_tag;
1861.1Such}
1871.1Such
1881.1Such/*
1891.1Such * default functions.
1901.1Such */
1911.1Suchvoid
1921.1Such__txioman_led(ti, type, onoff)
1931.1Such	txioman_tag_t ti;
1941.1Such	int type, onoff;
1951.1Such{
1961.1Such}
1971.1Such
1981.1Suchvoid
1991.1Such__txioman_backlight(ti, onoff)
2001.1Such	txioman_tag_t ti;
2011.1Such	int onoff;
2021.1Such{
2031.1Such}
2041.1Such
2051.1Suchvoid
2061.1Such__txioman_uart_init(ti)
2071.1Such	txioman_tag_t ti;
2081.1Such{
2091.1Such}
2101.1Such
2111.1Suchvoid
2121.1Such__txioman_uarta_init(ti, cookie)
2131.1Such	txioman_tag_t ti;
2141.1Such	void *cookie;
2151.1Such{
2161.1Such}
2171.1Such
2181.1Such/*
2191.1Such * Compaq-C functions.
2201.1Such */
2211.1Suchvoid
2221.1Such__compaq_led(ti, type, onoff)
2231.1Such	txioman_tag_t ti;
2241.1Such	int type, onoff;
2251.1Such{
2261.1Such	struct txioman_softc *sc = (void*)ti;
2271.1Such
2281.1Such	/* Green LED */
2291.1Such	tx39io_portout(sc->sc_tc, TXPORT(TXMFIO, 3),
2301.1Such		       onoff ? TXOFF : TXON);
2311.1Such}
2321.1Such
2331.1Suchextern int	__compaq_uart_dcd	__P((void*));
2341.1Suchextern int	__mobilon_uart_dcd	__P((void*));
2351.1Such
2361.1Suchvoid
2371.1Such__compaq_uarta_init(ti, cookie)
2381.1Such	txioman_tag_t ti;
2391.1Such	void *cookie;
2401.1Such{
2411.1Such	struct txioman_softc *sc = (void*)ti;
2421.1Such	tx_chipset_tag_t tc = sc->sc_tc;
2431.1Such
2441.1Such	tx_intr_establish(tc, MAKEINTR(3, (1<<30)), IST_EDGE, IPL_TTY,
2451.1Such			  __compaq_uart_dcd, cookie);
2461.1Such	tx_intr_establish(tc, MAKEINTR(4, (1<<30)), IST_EDGE, IPL_TTY,
2471.1Such			  __compaq_uart_dcd, cookie);
2481.1Such	tx_intr_establish(tc, MAKEINTR(3, (1<<5)), IST_EDGE, IPL_TTY,
2491.1Such			  __compaq_uart_dcd, cookie);
2501.1Such	tx_intr_establish(tc, MAKEINTR(4, (1<<5)), IST_EDGE, IPL_TTY,
2511.1Such			  __compaq_uart_dcd, cookie);
2521.1Such}
2531.1Such
2541.1Such/*
2551.1Such * Mobilon HC functions
2561.1Such */
2571.1Suchvoid
2581.1Such__mobilon_backlight(ti, onoff)
2591.1Such	txioman_tag_t ti;
2601.1Such	int onoff;
2611.1Such{
2621.1Such	struct txioman_softc *sc = (void*)ti;
2631.1Such
2641.1Such	tx39io_portout(sc->sc_tc, TXPORT(TXMFIO, 14),
2651.1Such		       onoff ? TXON : TXOFF);
2661.1Such}
2671.1Such
2681.1Suchvoid
2691.1Such__mobilon_uart_init(ti)
2701.1Such	txioman_tag_t ti;
2711.1Such{
2721.1Such	struct txioman_softc *sc = (void*)ti;
2731.1Such
2741.1Such	tx39io_portout(sc->sc_tc, TXPORT(TXIO, 5), TXON);
2751.1Such	tx39io_portout(sc->sc_tc, TXPORT(TXMFIO, 15), TXON);
2761.1Such}
2771.1Such
2781.1Suchvoid
2791.1Such__mobilon_uarta_init(ti, cookie)
2801.1Such	txioman_tag_t ti;
2811.1Such	void *cookie;
2821.1Such{
2831.1Such#if not_required /* ??? this is harmful... */
2841.1Such	struct txioman_softc *sc = (void*)ti;
2851.1Such	tx_chipset_tag_t tc = sc->sc_tc;
2861.1Such
2871.1Such	tx_intr_establish(tc, MAKEINTR(5, (1<<4)), IST_EDGE, IPL_TTY,
2881.1Such			  __mobilon_uart_dcd, cookie);
2891.1Such	tx_intr_establish(tc, MAKEINTR(5, (1<<11)), IST_EDGE, IPL_TTY,
2901.1Such			  __mobilon_uart_dcd, cookie);
2911.1Such	tx_intr_establish(tc, MAKEINTR(5, (1<<6)), IST_EDGE, IPL_TTY,
2921.1Such			  __mobilon_uart_dcd, cookie);
2931.1Such	tx_intr_establish(tc, MAKEINTR(5, (1<<13)), IST_EDGE, IPL_TTY,
2941.1Such			  __mobilon_uart_dcd, cookie);
2951.1Such#endif
2961.1Such}
2971.1Such
2981.1Such/*
2991.1Such * config_hook.
3001.1Such */
3011.1Suchint
3021.1Such__config_hook_backlight(arg, type, id, msg)
3031.1Such	void*	arg;
3041.1Such	int	type;
3051.1Such	long	id;
3061.1Such	void*	msg;
3071.1Such{
3081.1Such	static int onoff; /* XXX */
3091.1Such	tx_chipset_tag_t tc = arg;
3101.1Such
3111.1Such	onoff ^= 1;
3121.1Such
3131.1Such	txioman_backlight(tc, onoff);
3141.1Such	txioman_led(tc, 0, onoff); /* test */
3151.1Such	tx_sound_mute(tc, !onoff); /* test */
3161.1Such
3171.1Such	return 0;
3181.1Such}
319