No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / hp700 / dev / asp.c
blobf1af96a6d57e6fc69fad9e3b9bb713f76a322367
1 /* $NetBSD: asp.c,v 1.14 2009/05/24 06:53:34 skrll Exp $ */
3 /* $OpenBSD: asp.c,v 1.5 2000/02/09 05:04:22 mickey Exp $ */
5 /*
6 * Copyright (c) 1998-2003 Michael Shalayeff
7 * All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE.
32 * References:
34 * 1. Cobra/Coral I/O Subsystem External Reference Specification
35 * Hewlett-Packard
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: asp.c,v 1.14 2009/05/24 06:53:34 skrll Exp $");
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/device.h>
45 #include <sys/reboot.h>
47 #include <machine/bus.h>
48 #include <machine/iomod.h>
49 #include <machine/autoconf.h>
50 #include <machine/cpufunc.h>
52 #include <hp700/hp700/machdep.h>
53 #include <hp700/dev/cpudevs.h>
54 #include <hp700/dev/viper.h>
56 #include <hp700/gsc/gscbusvar.h>
58 struct asp_hwr {
59 uint8_t asp_reset;
60 uint8_t asp_resv[31];
61 uint8_t asp_version;
62 uint8_t asp_resv1[15];
63 uint8_t asp_scsidsync;
64 uint8_t asp_resv2[15];
65 uint8_t asp_error;
68 struct asp_trs {
69 uint32_t asp_irr;
70 uint32_t asp_imr;
71 uint32_t asp_ipr;
72 uint32_t asp_icr;
73 uint32_t asp_iar;
74 uint32_t asp_resv[3];
75 uint8_t asp_cled;
76 uint8_t asp_resv1[3];
77 struct {
78 u_int :20,
79 asp_spu : 3, /* SPU ID board jumper */
80 #define ASP_SPUCOBRA 0
81 #define ASP_SPUCORAL 1
82 #define ASP_SPUBUSH 2
83 #define ASP_SPUHARDBALL 3
84 #define ASP_SPUSCORPIO 4
85 #define ASP_SPUCORAL2 5
86 asp_sw : 1, /* front switch is normal */
87 asp_clk : 1, /* SCSI clock is doubled */
88 asp_lan : 2, /* LAN iface selector */
89 #define ASP_LANINVAL 0
90 #define ASP_LANAUI 1
91 #define ASP_LANTHIN 2
92 #define ASP_LANMISS 3
93 asp_lanf: 1, /* LAN AUI fuse is ok */
94 asp_spwr: 1, /* SCSI power ok */
95 asp_scsi: 3; /* SCSI ctrl ID */
96 } _asp_ios;
97 #define asp_spu _asp_ios.asp_spu
98 #define asp_sw _asp_ios.asp_sw
99 #define asp_clk _asp_ios.asp_clk
100 #define asp_lan _asp_ios.asp_lan
101 #define asp_lanf _asp_ios.asp_lanf
102 #define asp_spwr _asp_ios.asp_spwr
103 #define asp_scsi _asp_ios.asp_scsi
106 #define ASP_BANK_SZ 0x02000000
107 #define ASP_REG_INT 0x00800000
108 #define ASP_ETHER_ADDR 0x00810000
109 #define ASP_REG_MISC 0x0082f000
111 const struct asp_spus_tag {
112 char name[12];
113 int ledword;
114 } asp_spus[] = {
115 { "Cobra", 0 },
116 { "Coral", 0 },
117 { "Bushmaster", 0 },
118 { "Hardball", 1 },
119 { "Scorpio", 0 },
120 { "Coral II", 1 },
121 { "#6", 0 },
122 { "#7", 0 }
125 struct asp_softc {
126 device_t sc_dev;
128 struct hp700_int_reg sc_int_reg;
130 volatile struct asp_hwr *sc_hw;
131 volatile struct asp_trs *sc_trs;
134 int aspmatch(device_t, cfdata_t, void *);
135 void aspattach(device_t, device_t, void *);
137 CFATTACH_DECL_NEW(asp, sizeof(struct asp_softc),
138 aspmatch, aspattach, NULL, NULL);
141 * Before a module is matched, this fixes up its gsc_attach_args.
143 static void asp_fix_args(void *, struct gsc_attach_args *);
144 static void
145 asp_fix_args(void *_sc, struct gsc_attach_args *ga)
147 hppa_hpa_t module_offset;
148 struct asp_softc *sc = _sc;
151 * Determine this module's interrupt bit.
153 module_offset = ga->ga_hpa - (hppa_hpa_t) sc->sc_trs;
154 ga->ga_irq = HP700CF_IRQ_UNDEF;
155 #define ASP_IRQ(off, irq) if (module_offset == off) ga->ga_irq = irq
156 ASP_IRQ(0x22000, 6); /* com1 */
157 ASP_IRQ(0x23000, 5); /* com0 */
158 ASP_IRQ(0x24000, 7); /* lpt */
159 ASP_IRQ(0x25000, 9); /* osiop */
160 ASP_IRQ(0x26000, 8); /* ie */
161 ASP_IRQ(0x30000, 3); /* siop */
162 ASP_IRQ(0x800000, 13); /* harmony */
163 #undef ASP_IRQ
167 aspmatch(device_t parent, cfdata_t cf, void *aux)
169 struct confargs *ca = aux;
171 if (ca->ca_type.iodc_type != HPPA_TYPE_BHA ||
172 ca->ca_type.iodc_sv_model != HPPA_BHA_ASP)
173 return 0;
175 /* Make sure we have an IRQ. */
176 if (ca->ca_irq == HP700CF_IRQ_UNDEF)
177 ca->ca_irq = hp700_intr_allocate_bit(&int_reg_cpu);
180 * Forcibly mask the HPA down to the start of the ASP
181 * chip address space.
183 ca->ca_hpa &= ~(ASP_BANK_SZ - 1);
185 return 1;
188 void
189 aspattach(device_t parent, device_t self, void *aux)
191 struct confargs *ca = aux;
192 struct asp_softc *sc = device_private(self);
193 struct gsc_attach_args ga;
194 bus_space_handle_t ioh;
195 uint32_t irr;
196 int s;
198 sc->sc_dev = self;
201 * Map the ASP interrupt registers.
203 if (bus_space_map(ca->ca_iot, ca->ca_hpa + ASP_REG_INT,
204 sizeof(struct asp_trs), 0, &ioh))
205 panic("aspattach: can't map interrupt registers.");
206 sc->sc_trs = (struct asp_trs *)ioh;
209 * Map the ASP miscellaneous registers.
211 if (bus_space_map(ca->ca_iot, ca->ca_hpa + ASP_REG_MISC,
212 sizeof(struct asp_hwr), 0, &ioh))
213 panic("aspattach: can't map miscellaneous registers.");
214 sc->sc_hw = (struct asp_hwr *)ioh;
217 * Map the Ethernet address and read it out.
219 if (bus_space_map(ca->ca_iot, ca->ca_hpa + ASP_ETHER_ADDR,
220 sizeof(ga.ga_ether_address), 0, &ioh))
221 panic("aspattach: can't map EEPROM.");
222 bus_space_read_region_1(ca->ca_iot, ioh, 0,
223 ga.ga_ether_address, sizeof(ga.ga_ether_address));
224 bus_space_unmap(ca->ca_iot, ioh, sizeof(ga.ga_ether_address));
226 #ifdef USELEDS
227 machine_ledaddr = &sc->sc_trs->asp_cled;
228 machine_ledword = asp_spus[sc->sc_trs->asp_spu].ledword;
229 #endif
231 /* reset ASP */
232 /* sc->sc_hw->asp_reset = 1; */
233 /* delay(400000); */
235 s = splhigh();
236 viper_setintrwnd(1 << ca->ca_irq);
238 sc->sc_trs->asp_imr = ~0;
239 irr = sc->sc_trs->asp_irr;
240 sc->sc_trs->asp_imr = 0;
241 splx(s);
243 aprint_normal(": %s rev %d, lan %d scsi %d\n",
244 asp_spus[sc->sc_trs->asp_spu].name, sc->sc_hw->asp_version,
245 sc->sc_trs->asp_lan, sc->sc_trs->asp_scsi);
247 /* Establish the interrupt register. */
248 hp700_intr_reg_establish(&sc->sc_int_reg);
249 sc->sc_int_reg.int_reg_mask = &sc->sc_trs->asp_imr;
250 sc->sc_int_reg.int_reg_req = &sc->sc_trs->asp_irr;
252 /* Attach the GSC bus. */
253 ga.ga_ca = *ca; /* clone from us */
254 if (strcmp(parent->dv_xname, "mainbus0") == 0) {
255 ga.ga_dp.dp_bc[0] = ga.ga_dp.dp_bc[1];
256 ga.ga_dp.dp_bc[1] = ga.ga_dp.dp_bc[2];
257 ga.ga_dp.dp_bc[2] = ga.ga_dp.dp_bc[3];
258 ga.ga_dp.dp_bc[3] = ga.ga_dp.dp_bc[4];
259 ga.ga_dp.dp_bc[4] = ga.ga_dp.dp_bc[5];
260 ga.ga_dp.dp_bc[5] = ga.ga_dp.dp_mod;
261 ga.ga_dp.dp_mod = 0;
264 ga.ga_name = "gsc";
265 ga.ga_int_reg = &sc->sc_int_reg;
266 ga.ga_fix_args = asp_fix_args;
267 ga.ga_fix_args_cookie = sc;
268 ga.ga_scsi_target = sc->sc_trs->asp_scsi;
269 config_found(self, &ga, gscprint);