1 /* $NetBSD: ucbio.c,v 1.10 2007/12/15 00:39:18 perry Exp $ */
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Device driver for PHILIPS UCB1200 Advanced modem/audio analog front-end
34 * General Purpose I/O part.
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: ucbio.c,v 1.10 2007/12/15 00:39:18 perry Exp $");
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/device.h>
44 #include <machine/bus.h>
45 #include <machine/intr.h>
47 #include <hpcmips/tx/tx39var.h>
48 #include <hpcmips/tx/tx39sibvar.h>
49 #include <hpcmips/tx/tx39sibreg.h>
51 #include <hpcmips/dev/ucb1200var.h>
52 #include <hpcmips/dev/ucb1200reg.h>
54 #include <dev/hpc/hpciovar.h> /* I/O manager */
56 #include <machine/debug.h>
58 int ucbio_match(struct device
*, struct cfdata
*, void *);
59 void ucbio_attach(struct device
*, struct device
*, void *);
61 struct betty_port_status
{
68 tx_chipset_tag_t sc_tc
;
70 struct betty_port_status sc_stat
, sc_ostat
;
71 struct hpcio_chip sc_hc
;
74 CFATTACH_DECL(ucbio
, sizeof(struct ucbio_softc
),
75 ucbio_match
, ucbio_attach
, NULL
, NULL
);
78 static int betty_in(hpcio_chip_t
, int);
79 static void betty_out(hpcio_chip_t
, int, int);
81 static hpcio_intr_handle_t
betty_intr_establish(hpcio_chip_t
, int, int,
82 int (*)(void *), void *);
83 static void betty_intr_disestablish(hpcio_chip_t
, void *);
85 static void betty_update(hpcio_chip_t
);
86 static void betty_dump(hpcio_chip_t
);
89 ucbio_match(struct device
*parent
, struct cfdata
*cf
, void *aux
)
95 ucbio_attach(struct device
*parent
, struct device
*self
, void *aux
)
97 struct ucb1200_attach_args
*ucba
= aux
;
98 struct ucbio_softc
*sc
= (void *)self
;
99 struct hpcio_chip
*hc
= &sc
->sc_hc
;
101 sc
->sc_tc
= ucba
->ucba_tc
;
106 hc
->hc_name
= "UCB1200";
107 hc
->hc_portread
= betty_in
;
108 hc
->hc_portwrite
= betty_out
;
109 hc
->hc_intr_establish
= betty_intr_establish
;
110 hc
->hc_intr_disestablish
= betty_intr_disestablish
;
111 hc
->hc_update
= betty_update
;
112 hc
->hc_dump
= betty_dump
;
114 tx_conf_register_ioman(sc
->sc_tc
, hc
);
122 betty_out(hpcio_chip_t hc
, int port
, int onoff
)
124 struct ucbio_softc
*sc
= hc
->hc_sc
;
125 tx_chipset_tag_t tc
= sc
->sc_tc
;
129 reg
= txsibsf0_reg_read(tc
, UCB1200_IO_DATA_REG
);
134 txsibsf0_reg_write(tc
, UCB1200_IO_DATA_REG
, reg
);
138 betty_in(hpcio_chip_t hc
, int port
)
140 struct ucbio_softc
*sc
= hc
->hc_sc
;
141 tx_chipset_tag_t tc
= sc
->sc_tc
;
142 txreg_t reg
= txsibsf0_reg_read(tc
, UCB1200_IO_DATA_REG
);
144 return (reg
& (1 << port
));
147 /* interrupt method not implemented */
148 static hpcio_intr_handle_t
149 betty_intr_establish(hpcio_chip_t hc
, int port
, int mode
, int (*func
)(void *),
152 struct ucbio_softc
*sc
= hc
->hc_sc
;
154 printf("%s: %s not implemented.\n", sc
->sc_dev
.dv_xname
,
161 betty_intr_disestablish(hpcio_chip_t hc
, void *ih
)
163 struct ucbio_softc
*sc
= hc
->hc_sc
;
165 printf("%s: %s not implemented.\n", sc
->sc_dev
.dv_xname
,
171 betty_update(hpcio_chip_t hc
)
173 struct ucbio_softc
*sc
= hc
->hc_sc
;
174 tx_chipset_tag_t tc
= sc
->sc_tc
;
175 struct betty_port_status
*stat
= &sc
->sc_stat
;
178 sc
->sc_ostat
= *stat
; /* save old status */
179 dir
= stat
->dir
= txsibsf0_reg_read(tc
, UCB1200_IO_DIR_REG
);
180 data
= txsibsf0_reg_read(tc
, UCB1200_IO_DATA_REG
);
181 stat
->out
= data
& dir
;
182 stat
->in
= data
& ~dir
;
186 betty_dump(hpcio_chip_t hc
)
189 struct ucbio_softc
*sc
= hc
->hc_sc
;
190 struct betty_port_status
*stat
= &sc
->sc_stat
;
192 printf("[BETTY I/O]\n");
194 dbg_bit_print(stat
->in
);
196 dbg_bit_print(stat
->out
);
198 dbg_bit_print(stat
->dir
);
199 #endif /* UCBIO_DEBUG */