1171626Scognet/*	$NetBSD: obio.c,v 1.11 2003/07/15 00:25:05 lukem Exp $	*/
2171626Scognet
3171626Scognet/*-
4171626Scognet * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
5171626Scognet * All rights reserved.
6171626Scognet *
7171626Scognet * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8171626Scognet *
9171626Scognet * Redistribution and use in source and binary forms, with or without
10171626Scognet * modification, are permitted provided that the following conditions
11171626Scognet * are met:
12171626Scognet * 1. Redistributions of source code must retain the above copyright
13171626Scognet *    notice, this list of conditions and the following disclaimer.
14171626Scognet * 2. Redistributions in binary form must reproduce the above copyright
15171626Scognet *    notice, this list of conditions and the following disclaimer in the
16171626Scognet *    documentation and/or other materials provided with the distribution.
17171626Scognet * 3. All advertising materials mentioning features or use of this software
18171626Scognet *    must display the following acknowledgement:
19171626Scognet *	This product includes software developed for the NetBSD Project by
20171626Scognet *	Wasabi Systems, Inc.
21171626Scognet * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22171626Scognet *    or promote products derived from this software without specific prior
23171626Scognet *    written permission.
24171626Scognet *
25171626Scognet * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26171626Scognet * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27171626Scognet * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28171626Scognet * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
29171626Scognet * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30171626Scognet * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31171626Scognet * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32171626Scognet * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33171626Scognet * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34171626Scognet * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35171626Scognet * POSSIBILITY OF SUCH DAMAGE.
36171626Scognet */
37171626Scognet
38171626Scognet/*
39171626Scognet * On-board device autoconfiguration support for Intel IQ80321
40171626Scognet * evaluation boards.
41171626Scognet */
42171626Scognet
43171626Scognet#include <sys/cdefs.h>
44171626Scognet__FBSDID("$FreeBSD$");
45171626Scognet
46171626Scognet#include <sys/param.h>
47171626Scognet#include <sys/systm.h>
48171626Scognet#include <sys/bus.h>
49171626Scognet#include <sys/kernel.h>
50171626Scognet#include <sys/module.h>
51171626Scognet#include <sys/rman.h>
52171626Scognet#include <sys/malloc.h>
53171626Scognet
54171626Scognet#include <machine/bus.h>
55171626Scognet
56171626Scognet#include <arm/xscale/i8134x/i81342reg.h>
57171626Scognet#include <arm/xscale/i8134x/obiovar.h>
58171626Scognet
59278727Sianbus_space_tag_t obio_bs_tag;
60171626Scognet
61171626Scognetstatic int
62171626Scognetobio_probe(device_t dev)
63171626Scognet{
64171626Scognet	return (0);
65171626Scognet}
66171626Scognet
67171626Scognetstatic int
68171626Scognetobio_attach(device_t dev)
69171626Scognet{
70171626Scognet	struct obio_softc *sc = device_get_softc(dev);
71171626Scognet
72278727Sian	obio_bs_tag = arm_base_bs_tag;
73278727Sian	sc->oba_st = obio_bs_tag;
74171626Scognet	sc->oba_rman.rm_type = RMAN_ARRAY;
75171626Scognet	sc->oba_rman.rm_descr = "OBIO I/O";
76171626Scognet	if (rman_init(&sc->oba_rman) != 0 ||
77171626Scognet	    rman_manage_region(&sc->oba_rman,
78171626Scognet	    IOP34X_UART0_VADDR, IOP34X_UART1_VADDR + 0x40) != 0)
79171626Scognet		panic("obio_attach: failed to set up I/O rman");
80171626Scognet	sc->oba_irq_rman.rm_type = RMAN_ARRAY;
81171626Scognet	sc->oba_irq_rman.rm_descr = "OBIO IRQ";
82171626Scognet	if (rman_init(&sc->oba_irq_rman) != 0 ||
83171626Scognet	    rman_manage_region(&sc->oba_irq_rman, ICU_INT_UART0, ICU_INT_UART1) != 0)
84171626Scognet		panic("obio_attach: failed to set up IRQ rman");
85171626Scognet	device_add_child(dev, "uart", 0);
86171626Scognet	device_add_child(dev, "uart", 1);
87171626Scognet	bus_generic_probe(dev);
88171626Scognet	bus_generic_attach(dev);
89171626Scognet	return (0);
90171626Scognet}
91171626Scognet
92171626Scognetstatic struct resource *
93171626Scognetobio_alloc_resource(device_t bus, device_t child, int type, int *rid,
94171626Scognet    u_long start, u_long end, u_long count, u_int flags)
95171626Scognet{
96171626Scognet	struct resource *rv;
97171626Scognet	struct rman *rm;
98171626Scognet	bus_space_tag_t bt = NULL;
99171626Scognet	bus_space_handle_t bh = 0;
100171626Scognet	struct obio_softc *sc = device_get_softc(bus);
101171626Scognet	int unit = device_get_unit(child);
102171626Scognet
103171626Scognet	switch (type) {
104171626Scognet	case SYS_RES_IRQ:
105171626Scognet		rm = &sc->oba_irq_rman;
106171626Scognet		if (unit == 0)
107171626Scognet			start = end = ICU_INT_UART0;
108171626Scognet		else
109171626Scognet			start = end = ICU_INT_UART1;
110171626Scognet		break;
111171626Scognet	case SYS_RES_MEMORY:
112171626Scognet		return (NULL);
113171626Scognet	case SYS_RES_IOPORT:
114171626Scognet		rm = &sc->oba_rman;
115171626Scognet		bt = sc->oba_st;
116171626Scognet		if (unit == 0) {
117171626Scognet			bh = IOP34X_UART0_VADDR;
118171626Scognet			start = bh;
119171626Scognet			end = IOP34X_UART1_VADDR;
120171626Scognet		} else {
121171626Scognet			bh = IOP34X_UART1_VADDR;
122171626Scognet			start = bh;
123171626Scognet			end = start + 0x40;
124171626Scognet		}
125171626Scognet		break;
126171626Scognet	default:
127171626Scognet		return (NULL);
128171626Scognet	}
129171626Scognet
130171626Scognet
131171626Scognet	rv = rman_reserve_resource(rm, start, end, count, flags, child);
132236987Simp	if (rv == NULL)
133171626Scognet		return (NULL);
134171626Scognet	if (type == SYS_RES_IRQ)
135171626Scognet		return (rv);
136171626Scognet	rman_set_rid(rv, *rid);
137171626Scognet	rman_set_bustag(rv, bt);
138171626Scognet	rman_set_bushandle(rv, bh);
139171626Scognet
140171626Scognet	return (rv);
141171626Scognet
142171626Scognet}
143171626Scognet
144171626Scognetstatic int
145171626Scognetobio_activate_resource(device_t bus, device_t child, int type, int rid,
146171626Scognet    struct resource *r)
147171626Scognet{
148171626Scognet	return (0);
149171626Scognet}
150171626Scognetstatic device_method_t obio_methods[] = {
151171626Scognet	DEVMETHOD(device_probe, obio_probe),
152171626Scognet	DEVMETHOD(device_attach, obio_attach),
153171626Scognet
154171626Scognet	DEVMETHOD(bus_alloc_resource, obio_alloc_resource),
155171626Scognet	DEVMETHOD(bus_activate_resource, obio_activate_resource),
156171626Scognet	DEVMETHOD(bus_setup_intr,	bus_generic_setup_intr),
157171626Scognet	DEVMETHOD(bus_teardown_intr,	bus_generic_teardown_intr),
158171626Scognet
159171626Scognet	{0, 0},
160171626Scognet};
161171626Scognet
162171626Scognetstatic driver_t obio_driver = {
163171626Scognet	"obio",
164171626Scognet	obio_methods,
165171626Scognet	sizeof(struct obio_softc),
166171626Scognet};
167171626Scognetstatic devclass_t obio_devclass;
168171626Scognet
169171626ScognetDRIVER_MODULE(obio, iq, obio_driver, obio_devclass, 0, 0);
170