Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / hp700 / dev / lasi.c
blobdf26f11f04fa025b98ae643fedf3a54b4d81320a
1 /* $NetBSD: lasi.c,v 1.14 2009/05/24 06:53:34 skrll Exp $ */
3 /* $OpenBSD: lasi.c,v 1.4 2001/06/09 03:57:19 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.
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: lasi.c,v 1.14 2009/05/24 06:53:34 skrll Exp $");
34 #undef LASIDEBUG
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/device.h>
39 #include <sys/reboot.h>
41 #include <machine/bus.h>
42 #include <machine/iomod.h>
43 #include <machine/autoconf.h>
45 #include <hp700/dev/cpudevs.h>
47 #include <hp700/gsc/gscbusvar.h>
49 struct lasi_hwr {
50 uint32_t lasi_power;
51 #define LASI_BLINK 0x01
52 #define LASI_OFF 0x02
53 uint32_t lasi_error;
54 uint32_t lasi_version;
55 uint32_t lasi_reset;
56 uint32_t lasi_arbmask;
59 struct lasi_trs {
60 uint32_t lasi_irr; /* int requset register */
61 uint32_t lasi_imr; /* int mask register */
62 uint32_t lasi_ipr; /* int pending register */
63 uint32_t lasi_icr; /* int command? register */
64 uint32_t lasi_iar; /* int acquire? register */
67 #define LASI_BANK_SZ 0x200000
68 #define LASI_REG_INT 0x100000
69 #define LASI_REG_MISC 0x10c000
71 struct lasi_softc {
72 device_t sc_dev;
74 struct hp700_int_reg sc_int_reg;
76 struct lasi_hwr volatile *sc_hw;
77 struct lasi_trs volatile *sc_trs;
80 int lasimatch(device_t, cfdata_t, void *);
81 void lasiattach(device_t, device_t, void *);
83 CFATTACH_DECL_NEW(lasi, sizeof(struct lasi_softc),
84 lasimatch, lasiattach, NULL, NULL);
86 extern struct cfdriver lasi_cd;
88 void lasi_cold_hook(int);
91 * Before a module is matched, this fixes up its gsc_attach_args.
93 static void lasi_fix_args(void *, struct gsc_attach_args *);
94 static void
95 lasi_fix_args(void *_sc, struct gsc_attach_args *ga)
97 struct lasi_softc *sc = _sc;
98 hppa_hpa_t module_offset;
99 struct pdc_lan_station_id pdc_mac PDC_ALIGNMENT;
102 * Determine this module's interrupt bit.
104 module_offset = ga->ga_hpa - (hppa_hpa_t) sc->sc_trs;
105 ga->ga_irq = HP700CF_IRQ_UNDEF;
106 #define LASI_IRQ(off, irq) if (module_offset == off) ga->ga_irq = irq
107 LASI_IRQ(0x2000, 7); /* lpt */
108 LASI_IRQ(0x4000, 13); /* harmony */
109 LASI_IRQ(0x4040, 16); /* harmony telephone0 */
110 LASI_IRQ(0x4060, 17); /* harmony telephone1 */
111 LASI_IRQ(0x5000, 5); /* com */
112 LASI_IRQ(0x6000, 9); /* osiop */
113 LASI_IRQ(0x7000, 8); /* ie */
114 LASI_IRQ(0x8000, 26); /* pckbc */
115 LASI_IRQ(0xa000, 20); /* fdc */
116 #undef LASI_IRQ
119 * If this is the Ethernet adapter, get its Ethernet address.
121 if (module_offset == 0x7000) {
122 if (pdc_call((iodcio_t)pdc, 0, PDC_LAN_STATION_ID,
123 PDC_LAN_STATION_ID_READ, &pdc_mac, ga->ga_hpa) == 0)
124 memcpy(ga->ga_ether_address, pdc_mac.addr,
125 sizeof(ga->ga_ether_address));
130 lasimatch(device_t parent, cfdata_t cf, void *aux)
132 struct confargs *ca = aux;
134 if (ca->ca_type.iodc_type != HPPA_TYPE_BHA ||
135 ca->ca_type.iodc_sv_model != HPPA_BHA_LASI)
136 return 0;
138 /* Make sure we have an IRQ. */
139 if (ca->ca_irq == HP700CF_IRQ_UNDEF)
140 ca->ca_irq = hp700_intr_allocate_bit(&int_reg_cpu);
143 * Forcibly mask the HPA down to the start of the LASI
144 * chip address space.
146 ca->ca_hpa &= ~(LASI_BANK_SZ - 1);
148 return 1;
151 void
152 lasiattach(device_t parent, device_t self, void *aux)
154 struct confargs *ca = aux;
155 struct lasi_softc *sc = device_private(self);
156 struct gsc_attach_args ga;
157 bus_space_handle_t ioh;
158 int s, in;
160 sc->sc_dev = self;
162 * Map the LASI interrupt registers.
164 if (bus_space_map(ca->ca_iot, ca->ca_hpa + LASI_REG_INT,
165 sizeof(struct lasi_trs), 0, &ioh))
166 panic("lasiattach: can't map interrupt registers");
167 sc->sc_trs = (struct lasi_trs *)ioh;
170 * Map the LASI miscellaneous registers.
172 if (bus_space_map(ca->ca_iot, ca->ca_hpa + LASI_REG_MISC,
173 sizeof(struct lasi_hwr), 0, &ioh))
174 panic("lasiattach: can't map misc registers");
175 sc->sc_hw = (struct lasi_hwr *)ioh;
177 /* XXX should we reset the chip here? */
179 aprint_normal(": rev %d.%d\n", (sc->sc_hw->lasi_version & 0xf0) >> 4,
180 sc->sc_hw->lasi_version & 0xf);
182 /* interrupts guts */
183 s = splhigh();
184 sc->sc_trs->lasi_iar = cpu_gethpa(0) | (31 - ca->ca_irq);
185 sc->sc_trs->lasi_icr = 0;
186 sc->sc_trs->lasi_imr = ~0U;
187 in = sc->sc_trs->lasi_irr;
188 sc->sc_trs->lasi_imr = 0;
189 splx(s);
191 /* Establish the interrupt register. */
192 hp700_intr_reg_establish(&sc->sc_int_reg);
193 sc->sc_int_reg.int_reg_mask = &sc->sc_trs->lasi_imr;
194 sc->sc_int_reg.int_reg_req = &sc->sc_trs->lasi_irr;
196 /* Attach the GSC bus. */
197 ga.ga_ca = *ca; /* clone from us */
198 if (strcmp(parent->dv_xname, "mainbus0") == 0) {
199 ga.ga_dp.dp_bc[0] = ga.ga_dp.dp_bc[1];
200 ga.ga_dp.dp_bc[1] = ga.ga_dp.dp_bc[2];
201 ga.ga_dp.dp_bc[2] = ga.ga_dp.dp_bc[3];
202 ga.ga_dp.dp_bc[3] = ga.ga_dp.dp_bc[4];
203 ga.ga_dp.dp_bc[4] = ga.ga_dp.dp_bc[5];
204 ga.ga_dp.dp_bc[5] = ga.ga_dp.dp_mod;
205 ga.ga_dp.dp_mod = 0;
208 ga.ga_name = "gsc";
209 ga.ga_int_reg = &sc->sc_int_reg;
210 ga.ga_fix_args = lasi_fix_args;
211 ga.ga_fix_args_cookie = sc;
212 ga.ga_scsi_target = 7; /* XXX */
213 config_found(self, &ga, gscprint);
215 /* could be already set by power(4) */
216 if (!cold_hook)
217 cold_hook = lasi_cold_hook;
220 void
221 lasi_cold_hook(int on)
223 struct lasi_softc *sc = device_private(lasi_cd.cd_devs[0]);
225 if (!sc)
226 return;
228 switch (on) {
229 case HPPA_COLD_COLD:
230 sc->sc_hw->lasi_power = LASI_BLINK;
231 break;
232 case HPPA_COLD_HOT:
233 sc->sc_hw->lasi_power = 0;
234 break;
235 case HPPA_COLD_OFF:
236 sc->sc_hw->lasi_power = LASI_OFF;
237 break;