1/*	$OpenBSD: gecko.c,v 1.1 2008/04/27 14:39:51 kettenis Exp $	*/
2
3/*
4 * Copyright (c) 2007 Mark Kettenis
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#include <sys/param.h>
20#include <sys/device.h>
21#include <sys/kernel.h>
22#include <sys/systm.h>
23
24#include <machine/autoconf.h>
25#include <sys/bus.h>
26#include <machine/cpu.h>
27#include <machine/iomod.h>
28#include <machine/pdc.h>
29
30#include <hppa/dev/cpudevs.h>
31
32struct gecko_softc {
33	device_t		sc_dv;
34
35	bus_space_tag_t		sc_iot;
36	bus_space_handle_t 	sc_ioh;
37};
38
39int	gecko_match(device_t, cfdata_t, void *);
40void	gecko_attach(device_t, device_t, void *);
41static device_t gecko_callback(device_t, struct confargs *);
42
43CFATTACH_DECL_NEW(gecko, sizeof(struct gecko_softc), gecko_match,
44    gecko_attach, NULL, NULL);
45
46int
47gecko_match(device_t parent, cfdata_t match, void *aux)
48{
49	struct confargs *ca = aux;
50
51	if (ca->ca_type.iodc_type != HPPA_TYPE_BCPORT ||
52	    ca->ca_type.iodc_sv_model != HPPA_BCPORT_PORT)
53		return (0);
54
55	if (ca->ca_type.iodc_model == 0x50 &&
56	    ca->ca_type.iodc_revision == 0x00)
57		return (1);
58
59	return (0);
60}
61
62void
63gecko_attach(device_t parent, device_t self, void *aux)
64{
65	struct gecko_softc *sc = device_private(self);
66	struct confargs *ca = aux, nca;
67	volatile struct iomod *regs;
68
69	sc->sc_dv = self;
70	sc->sc_iot = ca->ca_iot;
71	if (bus_space_map(sc->sc_iot, ca->ca_hpa, IOMOD_HPASIZE, 0,
72	    &sc->sc_ioh)) {
73		aprint_error(": can't map IO space\n");
74		return;
75	}
76	regs = bus_space_vaddr(ca->ca_iot, sc->sc_ioh);
77
78	aprint_verbose(": %x-%x", regs->io_io_low, regs->io_io_high);
79
80	aprint_normal("\n");
81
82	nca = *ca;
83	nca.ca_hpabase = regs->io_io_low;
84	nca.ca_nmodules = MAXMODBUS;
85
86	pdc_scanbus(self, &nca, gecko_callback);
87}
88
89static device_t
90gecko_callback(device_t self, struct confargs *ca)
91{
92
93	return config_round(self, ca, mbprint,
94	    CFARGS(.submatch = mbsubmatch));
95}
96
97