2 * Copyright (c) 1997, 2001 Hellmuth Michaelis. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 *---------------------------------------------------------------------------
27 * i4b_drn_ngo.c - Dr. Neuhaus Niccy GO@ and SAGEM Cybermod
28 * --------------------------------------------------------
30 * $FreeBSD: src/sys/i4b/layer1/isic/i4b_drn_ngo.c,v 1.5.2.1 2001/08/10 14:08:38 obrien Exp $
32 * last edit-date: [Wed Jan 24 09:07:44 2001]
34 *---------------------------------------------------------------------------*/
39 #if (NISIC > 0) && defined(DRN_NGO)
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/socket.h>
46 #include <machine/i4b_ioctl.h>
48 #include <i4b/layer1/isic/i4b_isic.h>
49 #include <i4b/layer1/isic/i4b_hscx.h>
51 /*---------------------------------------------------------------------------*
52 * Niccy GO@ definitions
54 * the card uses 2 i/o addressranges each using 2 bytes
57 * offset 0 - ISAC dataregister
58 * offset 1 - HSCX dataregister
60 * offset 0 - ISAC addressregister
61 * offset 1 - HSCX addressregister
63 * to access an ISAC/HSCX register, you have to write the register
64 * number into the ISAC or HSCX addressregister and then read/write
65 * data for the ISAC/HSCX register into/from the corresponding
68 * Thanks to Klaus Muehle of Dr. Neuhaus Telekommunikation for giving
69 * out this information!
71 *---------------------------------------------------------------------------*/
72 #define NICCY_PORT_MIN 0x200
73 #define NICCY_PORT_MAX 0x3e0
75 #define HSCX_ABIT 0x1000 /* flag, HSCX A is meant */
76 #define HSCX_BBIT 0x2000 /* flag, HSCX B is meant */
78 #define HSCX_BOFF 0x40
80 #define ADDR_OFF 2 /* address register range offset */
88 /*---------------------------------------------------------------------------*
89 * Dr. Neuhaus Niccy GO@ read fifo routine
90 *---------------------------------------------------------------------------*/
92 drnngo_read_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
94 bus_space_tag_t tdata, tadr;
95 bus_space_handle_t hdata, hadr;
97 tdata = rman_get_bustag(sc->sc_resources.io_base[0]);
98 hdata = rman_get_bushandle(sc->sc_resources.io_base[0]);
99 tadr = rman_get_bustag(sc->sc_resources.io_base[1]);
100 hadr = rman_get_bushandle(sc->sc_resources.io_base[1]);
105 bus_space_write_1 (tadr ,hadr, ISAC_ADDR,0x0);
106 bus_space_read_multi_1(tdata,hdata,ISAC_DATA,buf,size);
108 case ISIC_WHAT_HSCXA:
109 bus_space_write_1 (tadr ,hadr ,HSCX_ADDR,0x0);
110 bus_space_read_multi_1(tdata,hdata,HSCX_DATA,buf,size);
112 case ISIC_WHAT_HSCXB:
113 bus_space_write_1 (tadr ,hadr ,HSCX_ADDR,HSCX_BOFF);
114 bus_space_read_multi_1(tdata,hdata,HSCX_DATA,buf,size);
119 /*---------------------------------------------------------------------------*
120 * Dr. Neuhaus Niccy GO@ write fifo routine
121 *---------------------------------------------------------------------------*/
123 drnngo_write_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
125 bus_space_tag_t tdata, tadr;
126 bus_space_handle_t hdata, hadr;
128 tdata = rman_get_bustag(sc->sc_resources.io_base[0]);
129 hdata = rman_get_bushandle(sc->sc_resources.io_base[0]);
130 tadr = rman_get_bustag(sc->sc_resources.io_base[1]);
131 hadr = rman_get_bushandle(sc->sc_resources.io_base[1]);
136 bus_space_write_1 (tadr ,hadr, ISAC_ADDR,0x0);
137 bus_space_write_multi_1(tdata,hdata,ISAC_DATA,buf,size);
139 case ISIC_WHAT_HSCXA:
140 bus_space_write_1 (tadr ,hadr ,HSCX_ADDR,0x0);
141 bus_space_write_multi_1(tdata,hdata,HSCX_DATA,buf,size);
143 case ISIC_WHAT_HSCXB:
144 bus_space_write_1 (tadr ,hadr ,HSCX_ADDR,HSCX_BOFF);
145 bus_space_write_multi_1(tdata,hdata,HSCX_DATA,buf,size);
150 /*---------------------------------------------------------------------------*
151 * Dr. Neuhaus Niccy GO@ write register routine
152 *---------------------------------------------------------------------------*/
154 drnngo_write_reg(struct l1_softc *sc, int what, bus_size_t reg, u_int8_t data)
156 bus_space_tag_t tdata, tadr;
157 bus_space_handle_t hdata, hadr;
159 tdata = rman_get_bustag(sc->sc_resources.io_base[0]);
160 hdata = rman_get_bushandle(sc->sc_resources.io_base[0]);
161 tadr = rman_get_bustag(sc->sc_resources.io_base[1]);
162 hadr = rman_get_bushandle(sc->sc_resources.io_base[1]);
167 bus_space_write_1(tadr ,hadr, ISAC_ADDR,reg);
168 bus_space_write_1(tdata,hdata,ISAC_DATA,data);
170 case ISIC_WHAT_HSCXA:
171 bus_space_write_1(tadr ,hadr ,HSCX_ADDR,reg);
172 bus_space_write_1(tdata,hdata,HSCX_DATA,data);
174 case ISIC_WHAT_HSCXB:
175 bus_space_write_1(tadr ,hadr ,HSCX_ADDR,reg+HSCX_BOFF);
176 bus_space_write_1(tdata,hdata,HSCX_DATA,data);
181 /*---------------------------------------------------------------------------*
182 * Dr. Neuhaus Niccy GO@ read register routine
183 *---------------------------------------------------------------------------*/
185 drnngo_read_reg(struct l1_softc *sc, int what, bus_size_t reg)
187 bus_space_tag_t tdata, tadr;
188 bus_space_handle_t hdata, hadr;
190 tdata = rman_get_bustag(sc->sc_resources.io_base[0]);
191 hdata = rman_get_bushandle(sc->sc_resources.io_base[0]);
192 tadr = rman_get_bustag(sc->sc_resources.io_base[1]);
193 hadr = rman_get_bushandle(sc->sc_resources.io_base[1]);
198 bus_space_write_1(tadr ,hadr, ISAC_ADDR,reg);
199 return bus_space_read_1(tdata,hdata,ISAC_DATA);
200 case ISIC_WHAT_HSCXA:
201 bus_space_write_1(tadr ,hadr ,HSCX_ADDR,reg);
202 return bus_space_read_1(tdata,hdata,HSCX_DATA);
203 case ISIC_WHAT_HSCXB:
204 bus_space_write_1(tadr ,hadr ,HSCX_ADDR,reg+HSCX_BOFF);
205 return bus_space_read_1(tdata,hdata,HSCX_DATA);
211 /*---------------------------------------------------------------------------*
212 * probe for ISA PnP cards
213 *---------------------------------------------------------------------------*/
215 isic_attach_drnngo(device_t dev)
217 int unit = device_get_unit(dev);
218 struct l1_softc *sc = &l1_sc[unit];
220 sc->sc_resources.io_rid[1] = 1;
223 * this card needs a second io_base,
224 * free resources if we don't get it
227 if(!(sc->sc_resources.io_base[1] =
228 bus_alloc_resource(dev, SYS_RES_IOPORT,
229 &sc->sc_resources.io_rid[1],
230 0UL, ~0UL, 1, RF_ACTIVE)))
232 printf("isic%d: Failed to get second io base.\n", unit);
233 isic_detach_common(dev);
237 /* setup ISAC access routines */
240 sc->readreg = drnngo_read_reg;
241 sc->writereg = drnngo_write_reg;
243 sc->readfifo = drnngo_read_fifo;
244 sc->writefifo = drnngo_write_fifo;
246 /* setup card type */
248 sc->sc_cardtyp = CARD_TYPEP_DRNNGO;
250 /* setup IOM bus type */
252 sc->sc_bustyp = BUS_TYPE_IOM2;
255 sc->sc_bfifolen = HSCX_FIFO_LEN;
260 #endif /* (NISIC > 0) && defined(DRN_NGO) */