1098ca2bdSWarner Losh /*- 227d5dc18SMarcel Moolenaar * Copyright (c) 2003 Marcel Moolenaar 327d5dc18SMarcel Moolenaar * All rights reserved. 427d5dc18SMarcel Moolenaar * 527d5dc18SMarcel Moolenaar * Redistribution and use in source and binary forms, with or without 627d5dc18SMarcel Moolenaar * modification, are permitted provided that the following conditions 727d5dc18SMarcel Moolenaar * are met: 827d5dc18SMarcel Moolenaar * 927d5dc18SMarcel Moolenaar * 1. Redistributions of source code must retain the above copyright 1027d5dc18SMarcel Moolenaar * notice, this list of conditions and the following disclaimer. 1127d5dc18SMarcel Moolenaar * 2. Redistributions in binary form must reproduce the above copyright 1227d5dc18SMarcel Moolenaar * notice, this list of conditions and the following disclaimer in the 1327d5dc18SMarcel Moolenaar * documentation and/or other materials provided with the distribution. 1427d5dc18SMarcel Moolenaar * 1527d5dc18SMarcel Moolenaar * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1627d5dc18SMarcel Moolenaar * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1727d5dc18SMarcel Moolenaar * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1827d5dc18SMarcel Moolenaar * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1927d5dc18SMarcel Moolenaar * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2027d5dc18SMarcel Moolenaar * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2127d5dc18SMarcel Moolenaar * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2227d5dc18SMarcel Moolenaar * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2327d5dc18SMarcel Moolenaar * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2427d5dc18SMarcel Moolenaar * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2527d5dc18SMarcel Moolenaar * 2627d5dc18SMarcel Moolenaar * $FreeBSD$ 2727d5dc18SMarcel Moolenaar */ 2827d5dc18SMarcel Moolenaar 2927d5dc18SMarcel Moolenaar #ifndef _DEV_UART_H_ 3027d5dc18SMarcel Moolenaar #define _DEV_UART_H_ 3127d5dc18SMarcel Moolenaar 3227d5dc18SMarcel Moolenaar /* 3327d5dc18SMarcel Moolenaar * Bus access structure. This structure holds the minimum information needed 3427d5dc18SMarcel Moolenaar * to access the UART. The rclk field, although not important to actually 3527d5dc18SMarcel Moolenaar * access the UART, is important for baudrate programming, delay loops and 3627d5dc18SMarcel Moolenaar * other timing related computations. 3727d5dc18SMarcel Moolenaar */ 3827d5dc18SMarcel Moolenaar struct uart_bas { 3927d5dc18SMarcel Moolenaar bus_space_tag_t bst; 4027d5dc18SMarcel Moolenaar bus_space_handle_t bsh; 41875f70dbSMarcel Moolenaar u_int chan; 4227d5dc18SMarcel Moolenaar u_int rclk; 43875f70dbSMarcel Moolenaar u_int regshft; 4427d5dc18SMarcel Moolenaar }; 4527d5dc18SMarcel Moolenaar 4627d5dc18SMarcel Moolenaar #define uart_regofs(bas, reg) ((reg) << (bas)->regshft) 4727d5dc18SMarcel Moolenaar 4827d5dc18SMarcel Moolenaar #define uart_getreg(bas, reg) \ 4927d5dc18SMarcel Moolenaar bus_space_read_1((bas)->bst, (bas)->bsh, uart_regofs(bas, reg)) 5027d5dc18SMarcel Moolenaar #define uart_setreg(bas, reg, value) \ 5127d5dc18SMarcel Moolenaar bus_space_write_1((bas)->bst, (bas)->bsh, uart_regofs(bas, reg), value) 5227d5dc18SMarcel Moolenaar 5327d5dc18SMarcel Moolenaar /* 5427d5dc18SMarcel Moolenaar * XXX we don't know the length of the bus space address range in use by 5527d5dc18SMarcel Moolenaar * the UART. Since barriers don't use the length field currently, we put 5627d5dc18SMarcel Moolenaar * a zero there for now. 5727d5dc18SMarcel Moolenaar */ 5827d5dc18SMarcel Moolenaar #define uart_barrier(bas) \ 5927d5dc18SMarcel Moolenaar bus_space_barrier((bas)->bst, (bas)->bsh, 0, 0, \ 6027d5dc18SMarcel Moolenaar BUS_SPACE_BARRIER_READ|BUS_SPACE_BARRIER_WRITE) 6127d5dc18SMarcel Moolenaar 6227d5dc18SMarcel Moolenaar /* 63f8100ce2SMarcel Moolenaar * UART device classes. 64f8100ce2SMarcel Moolenaar */ 65f8100ce2SMarcel Moolenaar struct uart_class; 66f8100ce2SMarcel Moolenaar 67a2c472e7SAleksandr Rybalko extern struct uart_class uart_imx_class __attribute__((weak)); 68f8100ce2SMarcel Moolenaar extern struct uart_class uart_ns8250_class __attribute__((weak)); 696b7ba544SRafal Jaworowski extern struct uart_class uart_quicc_class __attribute__((weak)); 705d490515SAleksandr Rybalko extern struct uart_class uart_s3c2410_class __attribute__((weak)); 71f8100ce2SMarcel Moolenaar extern struct uart_class uart_sab82532_class __attribute__((weak)); 72d5dba21cSMarius Strobl extern struct uart_class uart_sbbc_class __attribute__((weak)); 73f8100ce2SMarcel Moolenaar extern struct uart_class uart_z8530_class __attribute__((weak)); 748dee0fd0SOleksandr Tymoshenko extern struct uart_class uart_lpc_class __attribute__((weak)); 75f70f23ccSOleksandr Tymoshenko extern struct uart_class uart_pl011_class __attribute__((weak)); 76735c7fe5SWojciech A. Koszek extern struct uart_class uart_cdnc_class __attribute__((weak)); 77aef60d8cSIan Lepore extern struct uart_class uart_ti8250_class __attribute__((weak)); 78f8100ce2SMarcel Moolenaar 79*64958185SIan Lepore #ifdef FDT 80*64958185SIan Lepore struct ofw_compat_data; 81*64958185SIan Lepore extern const struct ofw_compat_data *uart_fdt_compat_data; 82*64958185SIan Lepore #endif 83*64958185SIan Lepore 8481df65c3SYoshihiro Takahashi #ifdef PC98 8581df65c3SYoshihiro Takahashi struct uart_class *uart_pc98_getdev(u_long port); 8681df65c3SYoshihiro Takahashi #endif 8781df65c3SYoshihiro Takahashi 88f8100ce2SMarcel Moolenaar /* 8927d5dc18SMarcel Moolenaar * Device flags. 9027d5dc18SMarcel Moolenaar */ 9127d5dc18SMarcel Moolenaar #define UART_FLAGS_CONSOLE(f) ((f) & 0x10) 9227d5dc18SMarcel Moolenaar #define UART_FLAGS_DBGPORT(f) ((f) & 0x80) 93823c77d7SSam Leffler #define UART_FLAGS_FCR_RX_LOW(f) ((f) & 0x100) 94823c77d7SSam Leffler #define UART_FLAGS_FCR_RX_MEDL(f) ((f) & 0x200) 95823c77d7SSam Leffler #define UART_FLAGS_FCR_RX_MEDH(f) ((f) & 0x400) 96823c77d7SSam Leffler #define UART_FLAGS_FCR_RX_HIGH(f) ((f) & 0x800) 9727d5dc18SMarcel Moolenaar 9827d5dc18SMarcel Moolenaar /* 9927d5dc18SMarcel Moolenaar * Data parity values (magical numbers related to ns8250). 10027d5dc18SMarcel Moolenaar */ 10127d5dc18SMarcel Moolenaar #define UART_PARITY_NONE 0 10227d5dc18SMarcel Moolenaar #define UART_PARITY_ODD 1 10327d5dc18SMarcel Moolenaar #define UART_PARITY_EVEN 3 10427d5dc18SMarcel Moolenaar #define UART_PARITY_MARK 5 10527d5dc18SMarcel Moolenaar #define UART_PARITY_SPACE 7 10627d5dc18SMarcel Moolenaar 10727d5dc18SMarcel Moolenaar #endif /* _DEV_UART_H_ */ 108