allow coexistance of N build and AC build.
[tomato.git] / release / src-rt-6.x / cfe / cfe / dev / dev_ns16550_pci.c
blobe9087e7484fef43e57291e4437e4c2f20dc784b6
1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
3 *
4 * NS16550 UART driver (PCI) File: dev_ns16550_pci.c
5 *
6 * This is a console device driver for a PCI NS16550 UART
7 *
8 * Author: Mitch Lichtenberg (mpl@broadcom.com)
9 *
10 *********************************************************************
12 * Copyright 2000,2001,2002,2003
13 * Broadcom Corporation. All rights reserved.
15 * This software is furnished under license and may be used and
16 * copied only in accordance with the following terms and
17 * conditions. Subject to these conditions, you may download,
18 * copy, install, use, modify and distribute modified or unmodified
19 * copies of this software in source and/or binary form. No title
20 * or ownership is transferred hereby.
22 * 1) Any source code used, modified or distributed must reproduce
23 * and retain this copyright notice and list of conditions
24 * as they appear in the source file.
26 * 2) No right is granted to use any trade name, trademark, or
27 * logo of Broadcom Corporation. The "Broadcom Corporation"
28 * name may not be used to endorse or promote products derived
29 * from this software without the prior written permission of
30 * Broadcom Corporation.
32 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
33 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
34 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
35 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
36 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
37 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
38 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
40 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
41 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
42 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
43 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
44 * THE POSSIBILITY OF SUCH DAMAGE.
45 ********************************************************************* */
48 #include "lib_types.h"
49 #include "lib_malloc.h"
50 #include "lib_printf.h"
51 #include "cfe_iocb.h"
52 #include "cfe_device.h"
53 #include "cfe_ioctl.h"
55 #include "pcivar.h"
56 #include "pcireg.h"
59 /* Probe routine for real UART driver */
60 extern void ns16550_uart_probe(cfe_driver_t *drv,
61 unsigned long probe_a, unsigned long probe_b,
62 void *probe_ptr);
64 /* Probe routine for this UART driver. */
65 static void ns16550pci_uart_probe(cfe_driver_t *drv,
66 unsigned long probe_a, unsigned long probe_b,
67 void *probe_ptr);
69 /* We just glom onto the dispatch table in the real driver */
70 extern const cfe_devdisp_t ns16550_uart_dispatch;
72 const cfe_driver_t ns16550pci_uart = {
73 "PCI NS16550 UART",
74 "uart",
75 CFE_DEV_SERIAL,
76 &ns16550_uart_dispatch,
77 ns16550pci_uart_probe
81 static void
82 ns16550pci_uart_probe(cfe_driver_t *drv,
83 unsigned long probe_a, unsigned long probe_b,
84 void *probe_ptr)
86 int index;
88 /*
89 * NS16550-compatible UART on the PCI bus
90 * probe_a, probe_b and probe_ptr are unused.
92 * This is for generic 16550-like UARTs. We use the PCI class and
93 * interface codes to identify compatible hardware. We require
94 * 16550 or better compatibility. The 16{6,7,8,9}50 parts are
95 * claimed to be 16550 compatible but are as yet untested.
98 for (index = 0; ; index++) {
99 pcitag_t tag;
100 pcireg_t cr;
101 phys_addr_t pa;
103 if (pci_find_class(PCI_CLASS_COMMUNICATIONS, index, &tag) != 0) {
104 break;
107 cr = pci_conf_read(tag, PCI_CLASS_REG);
108 if (PCI_SUBCLASS(cr) == PCI_SUBCLASS_COMMUNICATIONS_SERIAL
109 && PCI_INTERFACE(cr) >= 0x02 /* 16550 .. */
110 && PCI_INTERFACE(cr) <= 0x06) { /* 16950 */
111 if (pci_map_io(tag, PCI_MAPREG(0), PCI_MATCH_BYTES, &pa) == 0)
112 ns16550_uart_probe(drv, pa, 0, NULL);