obio.c revision 236987
1227825Stheraven/*	$NetBSD: obio.c,v 1.11 2003/07/15 00:25:05 lukem Exp $	*/
2227825Stheraven
3227825Stheraven/*-
4227825Stheraven * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
5227825Stheraven * All rights reserved.
6227825Stheraven *
7227825Stheraven * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8227825Stheraven *
9227825Stheraven * Redistribution and use in source and binary forms, with or without
10227825Stheraven * modification, are permitted provided that the following conditions
11227825Stheraven * are met:
12227825Stheraven * 1. Redistributions of source code must retain the above copyright
13246487Stheraven *    notice, this list of conditions and the following disclaimer.
14227825Stheraven * 2. Redistributions in binary form must reproduce the above copyright
15246487Stheraven *    notice, this list of conditions and the following disclaimer in the
16246487Stheraven *    documentation and/or other materials provided with the distribution.
17246487Stheraven * 3. All advertising materials mentioning features or use of this software
18246487Stheraven *    must display the following acknowledgement:
19227825Stheraven *	This product includes software developed for the NetBSD Project by
20227825Stheraven *	Wasabi Systems, Inc.
21227825Stheraven * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22227825Stheraven *    or promote products derived from this software without specific prior
23227825Stheraven *    written permission.
24227825Stheraven *
25227825Stheraven * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26227825Stheraven * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27227825Stheraven * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28227825Stheraven * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
29227825Stheraven * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30227825Stheraven * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31227825Stheraven * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32227825Stheraven * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33227825Stheraven * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34227825Stheraven * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35227825Stheraven * POSSIBILITY OF SUCH DAMAGE.
36227825Stheraven */
37227825Stheraven
38227825Stheraven/*
39227825Stheraven * On-board device autoconfiguration support for Intel IQ80321
40227825Stheraven * evaluation boards.
41227825Stheraven */
42227825Stheraven
43227825Stheraven#include <sys/cdefs.h>
44227825Stheraven__FBSDID("$FreeBSD: head/sys/arm/xscale/i8134x/obio.c 236987 2012-06-13 04:38:09Z imp $");
45227825Stheraven
46227825Stheraven#include <sys/param.h>
47227825Stheraven#include <sys/systm.h>
48227825Stheraven#include <sys/bus.h>
49227825Stheraven#include <sys/kernel.h>
50227825Stheraven#include <sys/module.h>
51227825Stheraven#include <sys/rman.h>
52227825Stheraven#include <sys/malloc.h>
53227825Stheraven
54227825Stheraven#include <machine/bus.h>
55227825Stheraven
56227825Stheraven#include <arm/xscale/i8134x/i81342reg.h>
57227825Stheraven#include <arm/xscale/i8134x/obiovar.h>
58227825Stheraven
59227825Stheraven
60227825Stheravenstatic int
61227825Stheravenobio_probe(device_t dev)
62227825Stheraven{
63227825Stheraven	return (0);
64227825Stheraven}
65227825Stheraven
66227825Stheravenstatic int
67227825Stheravenobio_attach(device_t dev)
68227825Stheraven{
69227825Stheraven	struct obio_softc *sc = device_get_softc(dev);
70227825Stheraven
71227825Stheraven	sc->oba_st = &obio_bs_tag;
72227825Stheraven	sc->oba_rman.rm_type = RMAN_ARRAY;
73227825Stheraven	sc->oba_rman.rm_descr = "OBIO I/O";
74227825Stheraven	if (rman_init(&sc->oba_rman) != 0 ||
75227825Stheraven	    rman_manage_region(&sc->oba_rman,
76227825Stheraven	    IOP34X_UART0_VADDR, IOP34X_UART1_VADDR + 0x40) != 0)
77227825Stheraven		panic("obio_attach: failed to set up I/O rman");
78227825Stheraven	sc->oba_irq_rman.rm_type = RMAN_ARRAY;
79227825Stheraven	sc->oba_irq_rman.rm_descr = "OBIO IRQ";
80227825Stheraven	if (rman_init(&sc->oba_irq_rman) != 0 ||
81227825Stheraven	    rman_manage_region(&sc->oba_irq_rman, ICU_INT_UART0, ICU_INT_UART1) != 0)
82227825Stheraven		panic("obio_attach: failed to set up IRQ rman");
83227825Stheraven	device_add_child(dev, "uart", 0);
84227825Stheraven	device_add_child(dev, "uart", 1);
85227825Stheraven	bus_generic_probe(dev);
86227825Stheraven	bus_generic_attach(dev);
87227825Stheraven	return (0);
88227825Stheraven}
89227825Stheraven
90227825Stheravenstatic struct resource *
91227825Stheravenobio_alloc_resource(device_t bus, device_t child, int type, int *rid,
92227825Stheraven    u_long start, u_long end, u_long count, u_int flags)
93227825Stheraven{
94227825Stheraven	struct resource *rv;
95227825Stheraven	struct rman *rm;
96227825Stheraven	bus_space_tag_t bt = NULL;
97227825Stheraven	bus_space_handle_t bh = 0;
98227825Stheraven	struct obio_softc *sc = device_get_softc(bus);
99227825Stheraven	int unit = device_get_unit(child);
100227825Stheraven
101227825Stheraven	switch (type) {
102227825Stheraven	case SYS_RES_IRQ:
103227825Stheraven		rm = &sc->oba_irq_rman;
104227825Stheraven		if (unit == 0)
105227825Stheraven			start = end = ICU_INT_UART0;
106227825Stheraven		else
107227825Stheraven			start = end = ICU_INT_UART1;
108227825Stheraven		break;
109227825Stheraven	case SYS_RES_MEMORY:
110227825Stheraven		return (NULL);
111227825Stheraven	case SYS_RES_IOPORT:
112227825Stheraven		rm = &sc->oba_rman;
113227825Stheraven		bt = sc->oba_st;
114227825Stheraven		if (unit == 0) {
115227825Stheraven			bh = IOP34X_UART0_VADDR;
116227825Stheraven			start = bh;
117227825Stheraven			end = IOP34X_UART1_VADDR;
118227825Stheraven		} else {
119227825Stheraven			bh = IOP34X_UART1_VADDR;
120227825Stheraven			start = bh;
121227825Stheraven			end = start + 0x40;
122227825Stheraven		}
123227825Stheraven		break;
124227825Stheraven	default:
125227825Stheraven		return (NULL);
126227825Stheraven	}
127227825Stheraven
128227825Stheraven
129227825Stheraven	rv = rman_reserve_resource(rm, start, end, count, flags, child);
130227825Stheraven	if (rv == NULL)
131227825Stheraven		return (NULL);
132227825Stheraven	if (type == SYS_RES_IRQ)
133227825Stheraven		return (rv);
134227825Stheraven	rman_set_rid(rv, *rid);
135227825Stheraven	rman_set_bustag(rv, bt);
136227825Stheraven	rman_set_bushandle(rv, bh);
137227825Stheraven
138227825Stheraven	return (rv);
139227825Stheraven
140227825Stheraven}
141227825Stheraven
142227825Stheravenstatic int
143227825Stheravenobio_activate_resource(device_t bus, device_t child, int type, int rid,
144227825Stheraven    struct resource *r)
145227825Stheraven{
146227825Stheraven	return (0);
147227825Stheraven}
148227825Stheravenstatic device_method_t obio_methods[] = {
149227825Stheraven	DEVMETHOD(device_probe, obio_probe),
150227825Stheraven	DEVMETHOD(device_attach, obio_attach),
151227825Stheraven
152246487Stheraven	DEVMETHOD(bus_alloc_resource, obio_alloc_resource),
153227825Stheraven	DEVMETHOD(bus_activate_resource, obio_activate_resource),
154246487Stheraven	DEVMETHOD(bus_setup_intr,	bus_generic_setup_intr),
155246487Stheraven	DEVMETHOD(bus_teardown_intr,	bus_generic_teardown_intr),
156227825Stheraven
157246487Stheraven	{0, 0},
158227825Stheraven};
159227825Stheraven
160249998Sdimstatic driver_t obio_driver = {
161249998Sdim	"obio",
162227825Stheraven	obio_methods,
163227825Stheraven	sizeof(struct obio_softc),
164227825Stheraven};
165246487Stheravenstatic devclass_t obio_devclass;
166227825Stheraven
167246487StheravenDRIVER_MODULE(obio, iq, obio_driver, obio_devclass, 0, 0);
168246487Stheraven