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: stable/11/sys/arm/xscale/i8134x/obio.c 331890 2018-04-02 22:02:49Z gonzo $");
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
59171626Scognetstatic int
60171626Scognetobio_probe(device_t dev)
61171626Scognet{
62171626Scognet	return (0);
63171626Scognet}
64171626Scognet
65171626Scognetstatic int
66171626Scognetobio_attach(device_t dev)
67171626Scognet{
68171626Scognet	struct obio_softc *sc = device_get_softc(dev);
69171626Scognet
70331890Sgonzo	sc->oba_st = arm_base_bs_tag;
71171626Scognet	sc->oba_rman.rm_type = RMAN_ARRAY;
72171626Scognet	sc->oba_rman.rm_descr = "OBIO I/O";
73171626Scognet	if (rman_init(&sc->oba_rman) != 0 ||
74171626Scognet	    rman_manage_region(&sc->oba_rman,
75171626Scognet	    IOP34X_UART0_VADDR, IOP34X_UART1_VADDR + 0x40) != 0)
76171626Scognet		panic("obio_attach: failed to set up I/O rman");
77171626Scognet	sc->oba_irq_rman.rm_type = RMAN_ARRAY;
78171626Scognet	sc->oba_irq_rman.rm_descr = "OBIO IRQ";
79171626Scognet	if (rman_init(&sc->oba_irq_rman) != 0 ||
80171626Scognet	    rman_manage_region(&sc->oba_irq_rman, ICU_INT_UART0, ICU_INT_UART1) != 0)
81171626Scognet		panic("obio_attach: failed to set up IRQ rman");
82171626Scognet	device_add_child(dev, "uart", 0);
83171626Scognet	device_add_child(dev, "uart", 1);
84171626Scognet	bus_generic_probe(dev);
85171626Scognet	bus_generic_attach(dev);
86171626Scognet	return (0);
87171626Scognet}
88171626Scognet
89171626Scognetstatic struct resource *
90171626Scognetobio_alloc_resource(device_t bus, device_t child, int type, int *rid,
91294883Sjhibbits    rman_res_t start, rman_res_t end, rman_res_t count, u_int flags)
92171626Scognet{
93171626Scognet	struct resource *rv;
94171626Scognet	struct rman *rm;
95171626Scognet	bus_space_tag_t bt = NULL;
96171626Scognet	bus_space_handle_t bh = 0;
97171626Scognet	struct obio_softc *sc = device_get_softc(bus);
98171626Scognet	int unit = device_get_unit(child);
99171626Scognet
100171626Scognet	switch (type) {
101171626Scognet	case SYS_RES_IRQ:
102171626Scognet		rm = &sc->oba_irq_rman;
103171626Scognet		if (unit == 0)
104171626Scognet			start = end = ICU_INT_UART0;
105171626Scognet		else
106171626Scognet			start = end = ICU_INT_UART1;
107171626Scognet		break;
108171626Scognet	case SYS_RES_MEMORY:
109171626Scognet		return (NULL);
110171626Scognet	case SYS_RES_IOPORT:
111171626Scognet		rm = &sc->oba_rman;
112171626Scognet		bt = sc->oba_st;
113171626Scognet		if (unit == 0) {
114171626Scognet			bh = IOP34X_UART0_VADDR;
115171626Scognet			start = bh;
116171626Scognet			end = IOP34X_UART1_VADDR;
117171626Scognet		} else {
118171626Scognet			bh = IOP34X_UART1_VADDR;
119171626Scognet			start = bh;
120171626Scognet			end = start + 0x40;
121171626Scognet		}
122171626Scognet		break;
123171626Scognet	default:
124171626Scognet		return (NULL);
125171626Scognet	}
126171626Scognet
127171626Scognet
128171626Scognet	rv = rman_reserve_resource(rm, start, end, count, flags, child);
129236987Simp	if (rv == NULL)
130171626Scognet		return (NULL);
131171626Scognet	if (type == SYS_RES_IRQ)
132171626Scognet		return (rv);
133171626Scognet	rman_set_rid(rv, *rid);
134171626Scognet	rman_set_bustag(rv, bt);
135171626Scognet	rman_set_bushandle(rv, bh);
136171626Scognet
137171626Scognet	return (rv);
138171626Scognet
139171626Scognet}
140171626Scognet
141171626Scognetstatic int
142171626Scognetobio_activate_resource(device_t bus, device_t child, int type, int rid,
143171626Scognet    struct resource *r)
144171626Scognet{
145171626Scognet	return (0);
146171626Scognet}
147171626Scognetstatic device_method_t obio_methods[] = {
148171626Scognet	DEVMETHOD(device_probe, obio_probe),
149171626Scognet	DEVMETHOD(device_attach, obio_attach),
150171626Scognet
151171626Scognet	DEVMETHOD(bus_alloc_resource, obio_alloc_resource),
152171626Scognet	DEVMETHOD(bus_activate_resource, obio_activate_resource),
153171626Scognet	DEVMETHOD(bus_setup_intr,	bus_generic_setup_intr),
154171626Scognet	DEVMETHOD(bus_teardown_intr,	bus_generic_teardown_intr),
155171626Scognet
156171626Scognet	{0, 0},
157171626Scognet};
158171626Scognet
159171626Scognetstatic driver_t obio_driver = {
160171626Scognet	"obio",
161171626Scognet	obio_methods,
162171626Scognet	sizeof(struct obio_softc),
163171626Scognet};
164171626Scognetstatic devclass_t obio_devclass;
165171626Scognet
166171626ScognetDRIVER_MODULE(obio, iq, obio_driver, obio_devclass, 0, 0);
167