1135669Scognet/*	$NetBSD: obio.c,v 1.11 2003/07/15 00:25:05 lukem Exp $	*/
2135669Scognet
3139735Simp/*-
4135669Scognet * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
5135669Scognet * All rights reserved.
6135669Scognet *
7135669Scognet * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8135669Scognet *
9135669Scognet * Redistribution and use in source and binary forms, with or without
10135669Scognet * modification, are permitted provided that the following conditions
11135669Scognet * are met:
12135669Scognet * 1. Redistributions of source code must retain the above copyright
13135669Scognet *    notice, this list of conditions and the following disclaimer.
14135669Scognet * 2. Redistributions in binary form must reproduce the above copyright
15135669Scognet *    notice, this list of conditions and the following disclaimer in the
16135669Scognet *    documentation and/or other materials provided with the distribution.
17135669Scognet * 3. All advertising materials mentioning features or use of this software
18135669Scognet *    must display the following acknowledgement:
19135669Scognet *	This product includes software developed for the NetBSD Project by
20135669Scognet *	Wasabi Systems, Inc.
21135669Scognet * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22135669Scognet *    or promote products derived from this software without specific prior
23135669Scognet *    written permission.
24135669Scognet *
25135669Scognet * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26135669Scognet * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27135669Scognet * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28135669Scognet * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
29135669Scognet * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30135669Scognet * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31135669Scognet * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32135669Scognet * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33135669Scognet * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34135669Scognet * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35135669Scognet * POSSIBILITY OF SUCH DAMAGE.
36135669Scognet */
37135669Scognet
38135669Scognet/*
39135669Scognet * On-board device autoconfiguration support for Intel IQ80321
40135669Scognet * evaluation boards.
41135669Scognet */
42135669Scognet
43135669Scognet#include <sys/cdefs.h>
44135669Scognet__FBSDID("$FreeBSD$");
45135669Scognet
46135669Scognet#include <sys/param.h>
47135669Scognet#include <sys/systm.h>
48135669Scognet#include <sys/bus.h>
49135669Scognet#include <sys/kernel.h>
50135669Scognet#include <sys/module.h>
51135669Scognet#include <sys/rman.h>
52135669Scognet#include <sys/malloc.h>
53135669Scognet
54135669Scognet#include <machine/bus.h>
55135669Scognet
56135669Scognet#include <arm/xscale/i80321/i80321reg.h>
57135669Scognet
58135669Scognet#include <arm/xscale/i80321/iq80321reg.h>
59135669Scognet#include <arm/xscale/i80321/obiovar.h>
60135669Scognet
61135669Scognetint	obio_probe(device_t);
62135669Scognetint	obio_attach(device_t);
63135669Scognet
64135669Scognetint
65135669Scognetobio_probe(device_t dev)
66135669Scognet{
67135669Scognet	return (0);
68135669Scognet}
69135669Scognet
70135669Scognetint
71135669Scognetobio_attach(device_t dev)
72135669Scognet{
73135669Scognet	struct obio_softc *sc = device_get_softc(dev);
74135669Scognet
75135669Scognet	sc->oba_st = &obio_bs_tag;
76135669Scognet	sc->oba_addr = IQ80321_OBIO_BASE;
77135669Scognet	sc->oba_size = IQ80321_OBIO_SIZE;
78135669Scognet	sc->oba_rman.rm_type = RMAN_ARRAY;
79135669Scognet	sc->oba_rman.rm_descr = "OBIO I/O";
80135669Scognet	if (rman_init(&sc->oba_rman) != 0 ||
81135669Scognet	    rman_manage_region(&sc->oba_rman,
82135669Scognet	    sc->oba_addr, sc->oba_addr + sc->oba_size) != 0)
83135669Scognet		panic("obio_attach: failed to set up I/O rman");
84150552Scognet	sc->oba_irq_rman.rm_type = RMAN_ARRAY;
85150552Scognet	sc->oba_irq_rman.rm_descr = "OBIO IRQ";
86150552Scognet	if (rman_init(&sc->oba_irq_rman) != 0 ||
87150552Scognet	    rman_manage_region(&sc->oba_irq_rman, 28, 28) != 0)
88150552Scognet		panic("obio_attach: failed to set up IRQ rman");
89135669Scognet	device_add_child(dev, "uart", 0);
90135669Scognet	bus_generic_probe(dev);
91135669Scognet	bus_generic_attach(dev);
92135669Scognet	return (0);
93135669Scognet}
94135669Scognet
95135669Scognetstatic struct resource *
96135669Scognetobio_alloc_resource(device_t bus, device_t child, int type, int *rid,
97135669Scognet    u_long start, u_long end, u_long count, u_int flags)
98135669Scognet{
99135669Scognet	struct resource *rv;
100135669Scognet	struct rman *rm;
101150552Scognet	bus_space_tag_t bt = NULL;
102150552Scognet	bus_space_handle_t bh = 0;
103135669Scognet	struct obio_softc *sc = device_get_softc(bus);
104135669Scognet
105135669Scognet	switch (type) {
106150552Scognet	case SYS_RES_IRQ:
107150552Scognet		rm = &sc->oba_irq_rman;
108150552Scognet		break;
109135669Scognet	case SYS_RES_MEMORY:
110135669Scognet		return (NULL);
111135669Scognet	case SYS_RES_IOPORT:
112135669Scognet		rm = &sc->oba_rman;
113135669Scognet		bt = sc->oba_st;
114135669Scognet		bh = sc->oba_addr;
115150552Scognet		start = bh;
116135669Scognet		break;
117135669Scognet	default:
118135669Scognet		return (NULL);
119135669Scognet	}
120135669Scognet
121135669Scognet
122135669Scognet	rv = rman_reserve_resource(rm, start, end, count, flags, child);
123236987Simp	if (rv == NULL)
124135669Scognet		return (NULL);
125150552Scognet	if (type == SYS_RES_IRQ)
126150552Scognet		return (rv);
127157891Simp	rman_set_rid(rv, *rid);
128135669Scognet	rman_set_bustag(rv, bt);
129135669Scognet	rman_set_bushandle(rv, bh);
130135669Scognet
131135669Scognet	return (rv);
132135669Scognet
133135669Scognet}
134135669Scognet
135135669Scognetstatic int
136135669Scognetobio_activate_resource(device_t bus, device_t child, int type, int rid,
137135669Scognet    struct resource *r)
138135669Scognet{
139135669Scognet	return (0);
140135669Scognet}
141135669Scognetstatic device_method_t obio_methods[] = {
142135669Scognet	DEVMETHOD(device_probe, obio_probe),
143135669Scognet	DEVMETHOD(device_attach, obio_attach),
144135669Scognet
145135669Scognet	DEVMETHOD(bus_alloc_resource, obio_alloc_resource),
146135669Scognet	DEVMETHOD(bus_activate_resource, obio_activate_resource),
147135669Scognet	DEVMETHOD(bus_setup_intr,	bus_generic_setup_intr),
148135669Scognet	DEVMETHOD(bus_teardown_intr,	bus_generic_teardown_intr),
149135669Scognet
150135669Scognet	{0, 0},
151135669Scognet};
152135669Scognet
153135669Scognetstatic driver_t obio_driver = {
154135669Scognet	"obio",
155135669Scognet	obio_methods,
156135669Scognet	sizeof(struct obio_softc),
157135669Scognet};
158135669Scognetstatic devclass_t obio_devclass;
159135669Scognet
160135669ScognetDRIVER_MODULE(obio, iq, obio_driver, obio_devclass, 0, 0);
161