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
61278727Sianbus_space_tag_t obio_bs_tag;
62278727Sian
63135669Scognetint	obio_probe(device_t);
64135669Scognetint	obio_attach(device_t);
65135669Scognet
66135669Scognetint
67135669Scognetobio_probe(device_t dev)
68135669Scognet{
69135669Scognet	return (0);
70135669Scognet}
71135669Scognet
72135669Scognetint
73135669Scognetobio_attach(device_t dev)
74135669Scognet{
75135669Scognet	struct obio_softc *sc = device_get_softc(dev);
76135669Scognet
77278727Sian	obio_bs_tag = arm_base_bs_tag;
78278727Sian        sc->oba_st = obio_bs_tag;
79135669Scognet	sc->oba_addr = IQ80321_OBIO_BASE;
80135669Scognet	sc->oba_size = IQ80321_OBIO_SIZE;
81135669Scognet	sc->oba_rman.rm_type = RMAN_ARRAY;
82135669Scognet	sc->oba_rman.rm_descr = "OBIO I/O";
83135669Scognet	if (rman_init(&sc->oba_rman) != 0 ||
84135669Scognet	    rman_manage_region(&sc->oba_rman,
85135669Scognet	    sc->oba_addr, sc->oba_addr + sc->oba_size) != 0)
86135669Scognet		panic("obio_attach: failed to set up I/O rman");
87150552Scognet	sc->oba_irq_rman.rm_type = RMAN_ARRAY;
88150552Scognet	sc->oba_irq_rman.rm_descr = "OBIO IRQ";
89150552Scognet	if (rman_init(&sc->oba_irq_rman) != 0 ||
90150552Scognet	    rman_manage_region(&sc->oba_irq_rman, 28, 28) != 0)
91150552Scognet		panic("obio_attach: failed to set up IRQ rman");
92135669Scognet	device_add_child(dev, "uart", 0);
93135669Scognet	bus_generic_probe(dev);
94135669Scognet	bus_generic_attach(dev);
95135669Scognet	return (0);
96135669Scognet}
97135669Scognet
98135669Scognetstatic struct resource *
99135669Scognetobio_alloc_resource(device_t bus, device_t child, int type, int *rid,
100135669Scognet    u_long start, u_long end, u_long count, u_int flags)
101135669Scognet{
102135669Scognet	struct resource *rv;
103135669Scognet	struct rman *rm;
104150552Scognet	bus_space_tag_t bt = NULL;
105150552Scognet	bus_space_handle_t bh = 0;
106135669Scognet	struct obio_softc *sc = device_get_softc(bus);
107135669Scognet
108135669Scognet	switch (type) {
109150552Scognet	case SYS_RES_IRQ:
110150552Scognet		rm = &sc->oba_irq_rman;
111150552Scognet		break;
112135669Scognet	case SYS_RES_MEMORY:
113135669Scognet		return (NULL);
114135669Scognet	case SYS_RES_IOPORT:
115135669Scognet		rm = &sc->oba_rman;
116135669Scognet		bt = sc->oba_st;
117135669Scognet		bh = sc->oba_addr;
118150552Scognet		start = bh;
119135669Scognet		break;
120135669Scognet	default:
121135669Scognet		return (NULL);
122135669Scognet	}
123135669Scognet
124135669Scognet
125135669Scognet	rv = rman_reserve_resource(rm, start, end, count, flags, child);
126236987Simp	if (rv == NULL)
127135669Scognet		return (NULL);
128150552Scognet	if (type == SYS_RES_IRQ)
129150552Scognet		return (rv);
130157891Simp	rman_set_rid(rv, *rid);
131135669Scognet	rman_set_bustag(rv, bt);
132135669Scognet	rman_set_bushandle(rv, bh);
133135669Scognet
134135669Scognet	return (rv);
135135669Scognet
136135669Scognet}
137135669Scognet
138135669Scognetstatic int
139135669Scognetobio_activate_resource(device_t bus, device_t child, int type, int rid,
140135669Scognet    struct resource *r)
141135669Scognet{
142135669Scognet	return (0);
143135669Scognet}
144135669Scognetstatic device_method_t obio_methods[] = {
145135669Scognet	DEVMETHOD(device_probe, obio_probe),
146135669Scognet	DEVMETHOD(device_attach, obio_attach),
147135669Scognet
148135669Scognet	DEVMETHOD(bus_alloc_resource, obio_alloc_resource),
149135669Scognet	DEVMETHOD(bus_activate_resource, obio_activate_resource),
150135669Scognet	DEVMETHOD(bus_setup_intr,	bus_generic_setup_intr),
151135669Scognet	DEVMETHOD(bus_teardown_intr,	bus_generic_teardown_intr),
152135669Scognet
153135669Scognet	{0, 0},
154135669Scognet};
155135669Scognet
156135669Scognetstatic driver_t obio_driver = {
157135669Scognet	"obio",
158135669Scognet	obio_methods,
159135669Scognet	sizeof(struct obio_softc),
160135669Scognet};
161135669Scognetstatic devclass_t obio_devclass;
162135669Scognet
163135669ScognetDRIVER_MODULE(obio, iq, obio_driver, obio_devclass, 0, 0);
164