1/*-
2 * Copyright (c) 2002 The NetBSD Foundation, Inc.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to The NetBSD Foundation
6 * by Martin Husemann <martin@NetBSD.org>.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
31__KERNEL_RCSID(0, "$NetBSD: isic_pcmcia_elsa_mcall.c,v 1.13 2007/10/19 12:01:05 ad Exp $");
32
33#include "opt_isicpcmcia.h"
34#ifdef ISICPCMCIA_ELSA_MCALL
35
36#include <sys/param.h>
37#if defined(__FreeBSD__) && __FreeBSD__ >= 3
38#include <sys/ioccom.h>
39#else
40#include <sys/ioctl.h>
41#endif
42#include <sys/kernel.h>
43#include <sys/systm.h>
44#include <sys/mbuf.h>
45
46#ifdef __FreeBSD__
47#include <machine/clock.h>
48#include <i386/isa/isa_device.h>
49#else
50#include <sys/bus.h>
51#include <sys/device.h>
52#endif
53
54#include <sys/socket.h>
55#include <net/if.h>
56
57#if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
58#include <sys/callout.h>
59#endif
60
61#ifdef __FreeBSD__
62#include <machine/i4b_debug.h>
63#include <machine/i4b_ioctl.h>
64#else
65#include <netisdn/i4b_debug.h>
66#include <netisdn/i4b_ioctl.h>
67
68#include <dev/pcmcia/pcmciareg.h>
69#include <dev/pcmcia/pcmciavar.h>
70#endif
71
72#include <netisdn/i4b_l2.h>
73#include <netisdn/i4b_l1l2.h>
74#include <dev/ic/isic_l1.h>
75#include <dev/ic/isac.h>
76#include <dev/ic/hscx.h>
77#include <dev/ic/ipac.h>
78
79#include <dev/pcmcia/isic_pcmcia.h>
80
81#ifndef __FreeBSD__
82/* PCMCIA support routines */
83static u_int8_t elsa_mcall_read_reg(struct isic_softc *sc, int what, bus_size_t offs);
84static void elsa_mcall_write_reg(struct isic_softc *sc, int what, bus_size_t offs, u_int8_t data);
85static void elsa_mcall_read_fifo(struct isic_softc *sc, int what, void *buf, size_t size);
86static void elsa_mcall_write_fifo(struct isic_softc *sc, int what, const void *data, size_t size);
87#endif
88
89/*---------------------------------------------------------------------------*
90 *	read fifo routines
91 *---------------------------------------------------------------------------*/
92#ifdef __FreeBSD__
93static int PCMCIA_IO_BASE = 0;		/* ap: XXX hack */
94static void
95elsa_mcall_read_fifo(void *buf, const void *base, size_t len)
96{
97}
98#else
99static void
100elsa_mcall_read_fifo(struct isic_softc *sc, int what,
101	void *buf, size_t size)
102{
103	/*
104	bus_space_tag_t t = sc->sc_maps[0].t;
105	bus_space_handle_t h = sc->sc_maps[0].h;
106	*/
107}
108#endif
109
110/*---------------------------------------------------------------------------*
111 *	write fifo routines
112 *---------------------------------------------------------------------------*/
113#ifdef __FreeBSD__
114static void
115elsa_mcall_write_fifo(void *base, const void *buf, size_t len)
116{
117}
118#else
119static void
120elsa_mcall_write_fifo(struct isic_softc *sc, int what,
121	const void *buf, size_t size)
122{
123	/*
124	bus_space_tag_t t = sc->sc_maps[0].t;
125	bus_space_handle_t h = sc->sc_maps[0].h;
126	*/
127}
128#endif
129
130/*---------------------------------------------------------------------------*
131 *	write register routines
132 *---------------------------------------------------------------------------*/
133#ifdef __FreeBSD__
134static void
135elsa_mcall_write_reg(u_char *base, u_int offset, u_int v)
136{
137}
138#else
139static void
140elsa_mcall_write_reg(struct isic_softc *sc, int what,
141	bus_size_t offs, u_int8_t data)
142{
143	/*
144	bus_space_tag_t t = sc->sc_maps[0].t;
145	bus_space_handle_t h = sc->sc_maps[0].h;
146	*/
147}
148#endif
149
150/*---------------------------------------------------------------------------*
151 *	read register routines
152 *---------------------------------------------------------------------------*/
153#ifdef __FreeBSD__
154static u_char
155elsa_mcall_read_reg(u_char *base, u_int offset)
156{
157	return 0;
158}
159#else
160static u_int8_t
161elsa_mcall_read_reg(struct isic_softc *sc, int what,
162	bus_size_t offs)
163{
164	/*
165	bus_space_tag_t t = sc->sc_maps[0].t;
166	bus_space_handle_t h = sc->sc_maps[0].h;
167	*/
168	return 0;
169}
170#endif
171
172#ifdef __FreeBSD__
173#else
174
175/*
176 * XXX - one time only! Some of this has to go into an enable
177 * function, with apropriate counterpart in disable, so a card
178 * could be removed an inserted again.
179 */
180int
181isic_attach_elsamcall(struct pcmcia_isic_softc *psc, struct pcmcia_config_entry *cfe, struct pcmcia_attach_args *pa)
182{
183	struct isic_softc *sc = &psc->sc_isic;
184	bus_space_tag_t t;
185	bus_space_handle_t h;
186
187	/* Validate config info */
188	if (cfe->num_memspace != 0)
189		printf(": unexpected number of memory spaces %d should be 0\n",
190			cfe->num_memspace);
191	if (cfe->num_iospace != 1)
192		printf(": unexpected number of memory spaces %d should be 1\n",
193			cfe->num_iospace);
194
195	/* Allocate pcmcia space */
196	if (pcmcia_io_alloc(pa->pf, 0, cfe->iospace[0].length,
197			    cfe->iospace[0].length, &psc->sc_pcioh))
198		printf(": can't allocate i/o space\n");
199
200	/* map them */
201	if (pcmcia_io_map(pa->pf, ((cfe->flags & PCMCIA_CFE_IO16) ?
202	    PCMCIA_WIDTH_IO16 : PCMCIA_WIDTH_IO8), &psc->sc_pcioh,
203	    &psc->sc_io_window)) {
204		printf(": can't map i/o space\n");
205		return 0;
206	}
207
208	/* Setup bus space maps */
209	sc->sc_num_mappings = 1;
210	MALLOC_MAPS(sc);
211
212	/* Copy our handles/tags to the MI maps */
213	sc->sc_maps[0].t = psc->sc_pcioh.iot;
214	sc->sc_maps[0].h = psc->sc_pcioh.ioh;
215	sc->sc_maps[0].offset = 0;
216	sc->sc_maps[0].size = 0;	/* not our mapping */
217
218	t = sc->sc_maps[0].t;
219	h = sc->sc_maps[0].h;
220
221	sc->clearirq = NULL;
222	sc->readreg = elsa_mcall_read_reg;
223	sc->writereg = elsa_mcall_write_reg;
224
225	sc->readfifo = elsa_mcall_read_fifo;
226	sc->writefifo = elsa_mcall_write_fifo;
227
228	/* setup IOM bus type */
229
230	sc->sc_bustyp = BUS_TYPE_IOM2;
231
232	sc->sc_ipac = 1;
233	sc->sc_bfifolen = IPAC_BFIFO_LEN;
234
235	return 1;
236}
237#endif
238
239#endif /* ISICPCMCIA_ELSA_MCALL */
240