1164426Ssam/*-
2164426Ssam * Copyright (c) 2003 Marcel Moolenaar
3164426Ssam * All rights reserved.
4164426Ssam *
5164426Ssam * Redistribution and use in source and binary forms, with or without
6164426Ssam * modification, are permitted provided that the following conditions
7164426Ssam * are met:
8164426Ssam *
9164426Ssam * 1. Redistributions of source code must retain the above copyright
10164426Ssam *    notice, this list of conditions and the following disclaimer.
11164426Ssam * 2. Redistributions in binary form must reproduce the above copyright
12164426Ssam *    notice, this list of conditions and the following disclaimer in the
13164426Ssam *    documentation and/or other materials provided with the distribution.
14164426Ssam *
15164426Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16164426Ssam * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17164426Ssam * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18164426Ssam * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19164426Ssam * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20164426Ssam * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21164426Ssam * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22164426Ssam * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23164426Ssam * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24164426Ssam * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25164426Ssam */
26164426Ssam
27164426Ssam#include <sys/cdefs.h>
28164426Ssam__FBSDID("$FreeBSD$");
29164426Ssam
30164426Ssam#include <sys/param.h>
31164426Ssam#include <sys/systm.h>
32164426Ssam#include <sys/bus.h>
33164426Ssam#include <sys/cons.h>
34164426Ssam#include <machine/bus.h>
35164426Ssam
36164426Ssam#include <dev/uart/uart.h>
37164426Ssam#include <dev/uart/uart_cpu.h>
38164426Ssam
39164426Ssam#include <arm/xscale/ixp425/ixp425reg.h>
40164426Ssam#include <arm/xscale/ixp425/ixp425var.h>
41164426Ssam
42164426Ssambus_space_tag_t uart_bus_space_io;
43164426Ssambus_space_tag_t uart_bus_space_mem;
44164426Ssam
45164426Ssamint
46164426Ssamuart_cpu_eqres(struct uart_bas *b1, struct uart_bas *b2)
47164426Ssam{
48164426Ssam	return ((b1->bsh == b2->bsh && b1->bst == b2->bst) ? 1 : 0);
49164426Ssam}
50164426Ssam
51164426Ssamint
52164426Ssamuart_cpu_getdev(int devtype, struct uart_devinfo *di)
53164426Ssam{
54170109Sjhay	uint32_t i, ivar, vaddr;
55170109Sjhay
56170109Sjhay	/*
57170109Sjhay	 * Scan the hints. The IXP425 only have 2 serial ports, so only
58170109Sjhay	 * scan them.
59170109Sjhay	 */
60170109Sjhay	for (i = 0; i < 2; i++) {
61170109Sjhay		if (resource_int_value("uart", i, "flags", &ivar))
62170109Sjhay			continue;
63170109Sjhay		if (devtype == UART_DEV_CONSOLE && !UART_FLAGS_CONSOLE(ivar))
64170109Sjhay			continue;
65170109Sjhay		if (devtype == UART_DEV_DBGPORT && !UART_FLAGS_DBGPORT(ivar))
66170109Sjhay			continue;
67170109Sjhay		/*
68170109Sjhay		 * We have a possible device. Make sure it's enabled and
69170109Sjhay		 * that we have an I/O port.
70170109Sjhay		 */
71170109Sjhay		if (resource_int_value("uart", i, "disabled", &ivar) == 0 &&
72170109Sjhay		    ivar != 0)
73170109Sjhay			continue;
74170109Sjhay		if (resource_int_value("uart", i, "addr", &ivar) != 0 ||
75170109Sjhay		    ivar == 0)
76170109Sjhay			continue;
77170109Sjhay		/* Got it. Fill in the instance and return it. */
78170109Sjhay		di->ops = uart_getops(&uart_ns8250_class);
79170109Sjhay		di->bas.chan = 0;
80170109Sjhay		di->bas.bst = &ixp425_a4x_bs_tag;
81170109Sjhay		di->bas.regshft = 0;
82170109Sjhay		di->bas.rclk = IXP425_UART_FREQ;
83170109Sjhay		di->baudrate = 115200;
84170109Sjhay		di->databits = 8;
85170109Sjhay		di->stopbits = 1;
86170109Sjhay		di->parity = UART_PARITY_NONE;
87170109Sjhay		uart_bus_space_io = NULL;
88170109Sjhay		uart_bus_space_mem = &ixp425_a4x_bs_tag;
89170109Sjhay
90170109Sjhay		getvbase(ivar, IXP425_REG_SIZE, &vaddr);
91170109Sjhay		di->bas.bsh = vaddr;
92170109Sjhay		return (0);
93170109Sjhay	}
94170109Sjhay
95170109Sjhay	return (ENXIO);
96164426Ssam}
97