1*cbab9cadSchs /* $NetBSD: ucbio.c,v 1.12 2012/10/27 17:17:53 chs Exp $ */
2c26429faSuch
3fc9212e5Such /*-
4fc9212e5Such * Copyright (c) 2000 The NetBSD Foundation, Inc.
5c26429faSuch * All rights reserved.
6c26429faSuch *
7fc9212e5Such * This code is derived from software contributed to The NetBSD Foundation
8fc9212e5Such * by UCHIYAMA Yasushi.
9fc9212e5Such *
10c26429faSuch * Redistribution and use in source and binary forms, with or without
11c26429faSuch * modification, are permitted provided that the following conditions
12c26429faSuch * are met:
13c26429faSuch * 1. Redistributions of source code must retain the above copyright
14c26429faSuch * notice, this list of conditions and the following disclaimer.
15fc9212e5Such * 2. Redistributions in binary form must reproduce the above copyright
16fc9212e5Such * notice, this list of conditions and the following disclaimer in the
17fc9212e5Such * documentation and/or other materials provided with the distribution.
18c26429faSuch *
19fc9212e5Such * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20fc9212e5Such * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21fc9212e5Such * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22fc9212e5Such * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23fc9212e5Such * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24fc9212e5Such * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25fc9212e5Such * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26fc9212e5Such * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27fc9212e5Such * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28fc9212e5Such * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29fc9212e5Such * POSSIBILITY OF SUCH DAMAGE.
30c26429faSuch */
31c26429faSuch
32c26429faSuch /*
33c26429faSuch * Device driver for PHILIPS UCB1200 Advanced modem/audio analog front-end
34c26429faSuch * General Purpose I/O part.
35c26429faSuch */
36c26429faSuch
370c82163cSlukem #include <sys/cdefs.h>
38*cbab9cadSchs __KERNEL_RCSID(0, "$NetBSD: ucbio.c,v 1.12 2012/10/27 17:17:53 chs Exp $");
390c82163cSlukem
40c26429faSuch #include <sys/param.h>
41c26429faSuch #include <sys/systm.h>
42c26429faSuch #include <sys/device.h>
43c26429faSuch
44c26429faSuch #include <machine/bus.h>
45c26429faSuch #include <machine/intr.h>
46c26429faSuch
47c26429faSuch #include <hpcmips/tx/tx39var.h>
48c26429faSuch #include <hpcmips/tx/tx39sibvar.h>
49c26429faSuch #include <hpcmips/tx/tx39sibreg.h>
50c26429faSuch
51c26429faSuch #include <hpcmips/dev/ucb1200var.h>
52c26429faSuch #include <hpcmips/dev/ucb1200reg.h>
53c26429faSuch
540774d043Such #include <dev/hpc/hpciovar.h> /* I/O manager */
550774d043Such
567d170993Such #include <machine/debug.h>
577d170993Such
58*cbab9cadSchs int ucbio_match(device_t, cfdata_t, void *);
59*cbab9cadSchs void ucbio_attach(device_t, device_t, void *);
60c26429faSuch
61fc9212e5Such struct betty_port_status {
62fc9212e5Such u_int16_t dir;
63fc9212e5Such u_int16_t in, out;
64fc9212e5Such };
65c26429faSuch
66c26429faSuch struct ucbio_softc {
67*cbab9cadSchs device_t sc_dev;
68fc9212e5Such tx_chipset_tag_t sc_tc;
69fc9212e5Such
70fc9212e5Such struct betty_port_status sc_stat, sc_ostat;
710774d043Such struct hpcio_chip sc_hc;
72c26429faSuch };
73c26429faSuch
74*cbab9cadSchs CFATTACH_DECL_NEW(ucbio, sizeof(struct ucbio_softc),
75c5e91d44Sthorpej ucbio_match, ucbio_attach, NULL, NULL);
76c26429faSuch
77fc9212e5Such /* I/O */
780774d043Such static int betty_in(hpcio_chip_t, int);
790774d043Such static void betty_out(hpcio_chip_t, int, int);
80fc9212e5Such /* interrupt */
810774d043Such static hpcio_intr_handle_t betty_intr_establish(hpcio_chip_t, int, int,
820774d043Such int (*)(void *), void *);
830774d043Such static void betty_intr_disestablish(hpcio_chip_t, void *);
84fc9212e5Such /* debug */
850774d043Such static void betty_update(hpcio_chip_t);
860774d043Such static void betty_dump(hpcio_chip_t);
87c26429faSuch
88c26429faSuch int
ucbio_match(device_t parent,cfdata_t cf,void * aux)89*cbab9cadSchs ucbio_match(device_t parent, cfdata_t cf, void *aux)
90c26429faSuch {
910774d043Such return (1);
92c26429faSuch }
93c26429faSuch
94c26429faSuch void
ucbio_attach(device_t parent,device_t self,void * aux)95*cbab9cadSchs ucbio_attach(device_t parent, device_t self, void *aux)
96c26429faSuch {
97c26429faSuch struct ucb1200_attach_args *ucba = aux;
98*cbab9cadSchs struct ucbio_softc *sc = device_private(self);
990774d043Such struct hpcio_chip *hc = &sc->sc_hc;
100c26429faSuch
101*cbab9cadSchs sc->sc_dev = self;
102fc9212e5Such sc->sc_tc = ucba->ucba_tc;
103c26429faSuch printf("\n");
104c26429faSuch
1050774d043Such hc->hc_sc = sc;
1060774d043Such hc->hc_chipid = 2;
1070774d043Such hc->hc_name = "UCB1200";
1080774d043Such hc->hc_portread = betty_in;
1090774d043Such hc->hc_portwrite = betty_out;
1100774d043Such hc->hc_intr_establish = betty_intr_establish;
1110774d043Such hc->hc_intr_disestablish = betty_intr_disestablish;
1120774d043Such hc->hc_update = betty_update;
1130774d043Such hc->hc_dump = betty_dump;
114fc9212e5Such
1150774d043Such tx_conf_register_ioman(sc->sc_tc, hc);
116fc9212e5Such
1170774d043Such hpcio_update(hc);
1180774d043Such hpcio_dump(hc);
119c26429faSuch }
120c26429faSuch
121fc9212e5Such /* basic I/O */
122fc9212e5Such static void
betty_out(hpcio_chip_t hc,int port,int onoff)1230774d043Such betty_out(hpcio_chip_t hc, int port, int onoff)
124c26429faSuch {
1250774d043Such struct ucbio_softc *sc = hc->hc_sc;
126fc9212e5Such tx_chipset_tag_t tc = sc->sc_tc;
127fc9212e5Such txreg_t reg, pos;
128c26429faSuch
129fc9212e5Such pos = 1 << port;
130fc9212e5Such reg = txsibsf0_reg_read(tc, UCB1200_IO_DATA_REG);
131fc9212e5Such if (onoff)
132fc9212e5Such reg |= pos;
133fc9212e5Such else
134fc9212e5Such reg &= ~pos;
135fc9212e5Such txsibsf0_reg_write(tc, UCB1200_IO_DATA_REG, reg);
136c26429faSuch }
137c26429faSuch
138fc9212e5Such static int
betty_in(hpcio_chip_t hc,int port)1390774d043Such betty_in(hpcio_chip_t hc, int port)
140c26429faSuch {
1410774d043Such struct ucbio_softc *sc = hc->hc_sc;
142fc9212e5Such tx_chipset_tag_t tc = sc->sc_tc;
143fc9212e5Such txreg_t reg = txsibsf0_reg_read(tc, UCB1200_IO_DATA_REG);
1440774d043Such
1450774d043Such return (reg & (1 << port));
146c26429faSuch }
147fc9212e5Such
148fc9212e5Such /* interrupt method not implemented */
1490774d043Such static hpcio_intr_handle_t
betty_intr_establish(hpcio_chip_t hc,int port,int mode,int (* func)(void *),void * func_arg)1500774d043Such betty_intr_establish(hpcio_chip_t hc, int port, int mode, int (*func)(void *),
1510774d043Such void *func_arg)
152fc9212e5Such {
1530774d043Such struct ucbio_softc *sc = hc->hc_sc;
154fc9212e5Such
155*cbab9cadSchs printf("%s: %s not implemented.\n", device_xname(sc->sc_dev),
1569b2b412cSperry __func__);
1570774d043Such
1580774d043Such return (0);
159fc9212e5Such }
160fc9212e5Such
161fc9212e5Such static void
betty_intr_disestablish(hpcio_chip_t hc,void * ih)1620774d043Such betty_intr_disestablish(hpcio_chip_t hc, void *ih)
163fc9212e5Such {
1640774d043Such struct ucbio_softc *sc = hc->hc_sc;
1650774d043Such
166*cbab9cadSchs printf("%s: %s not implemented.\n", device_xname(sc->sc_dev),
1679b2b412cSperry __func__);
168fc9212e5Such }
169fc9212e5Such
170fc9212e5Such /* debug */
171fc9212e5Such static void
betty_update(hpcio_chip_t hc)1720774d043Such betty_update(hpcio_chip_t hc)
173fc9212e5Such {
1740774d043Such struct ucbio_softc *sc = hc->hc_sc;
175fc9212e5Such tx_chipset_tag_t tc = sc->sc_tc;
176fc9212e5Such struct betty_port_status *stat = &sc->sc_stat;
177fc9212e5Such u_int16_t dir, data;
178fc9212e5Such
179fc9212e5Such sc->sc_ostat = *stat; /* save old status */
180fc9212e5Such dir = stat->dir = txsibsf0_reg_read(tc, UCB1200_IO_DIR_REG);
181fc9212e5Such data = txsibsf0_reg_read(tc, UCB1200_IO_DATA_REG);
182fc9212e5Such stat->out = data & dir;
183fc9212e5Such stat->in = data & ~dir;
184fc9212e5Such }
185fc9212e5Such
186fc9212e5Such static void
betty_dump(hpcio_chip_t hc)1870774d043Such betty_dump(hpcio_chip_t hc)
188fc9212e5Such {
1897d170993Such #ifdef UCBIO_DEBUG
1900774d043Such struct ucbio_softc *sc = hc->hc_sc;
191fc9212e5Such struct betty_port_status *stat = &sc->sc_stat;
192fc9212e5Such
193fc9212e5Such printf("[BETTY I/O]\n");
194fc9212e5Such printf("IN ");
1957d170993Such dbg_bit_print(stat->in);
196fc9212e5Such printf("OUT ");
1977d170993Such dbg_bit_print(stat->out);
198fc9212e5Such printf("DIR ");
1997d170993Such dbg_bit_print(stat->dir);
2007d170993Such #endif /* UCBIO_DEBUG */
201fc9212e5Such }
202