1cb34ed44SMarcel Moolenaar /*- 24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3718cf2ccSPedro F. Giffuni * 4cb34ed44SMarcel Moolenaar * Copyright (c) 2009-2010 The FreeBSD Foundation 5cb34ed44SMarcel Moolenaar * 6cb34ed44SMarcel Moolenaar * This software was developed by Semihalf under sponsorship from 7cb34ed44SMarcel Moolenaar * the FreeBSD Foundation. 8cb34ed44SMarcel Moolenaar * 9cb34ed44SMarcel Moolenaar * Redistribution and use in source and binary forms, with or without 10cb34ed44SMarcel Moolenaar * modification, are permitted provided that the following conditions 11cb34ed44SMarcel Moolenaar * are met: 12cb34ed44SMarcel Moolenaar * 1. Redistributions of source code must retain the above copyright 13cb34ed44SMarcel Moolenaar * notice, this list of conditions and the following disclaimer. 14cb34ed44SMarcel Moolenaar * 2. Redistributions in binary form must reproduce the above copyright 15cb34ed44SMarcel Moolenaar * notice, this list of conditions and the following disclaimer in the 16cb34ed44SMarcel Moolenaar * documentation and/or other materials provided with the distribution. 17cb34ed44SMarcel Moolenaar * 18cb34ed44SMarcel Moolenaar * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19cb34ed44SMarcel Moolenaar * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20cb34ed44SMarcel Moolenaar * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21cb34ed44SMarcel Moolenaar * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22cb34ed44SMarcel Moolenaar * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23cb34ed44SMarcel Moolenaar * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24cb34ed44SMarcel Moolenaar * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25cb34ed44SMarcel Moolenaar * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26cb34ed44SMarcel Moolenaar * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27cb34ed44SMarcel Moolenaar * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28cb34ed44SMarcel Moolenaar * SUCH DAMAGE. 29cb34ed44SMarcel Moolenaar */ 30cb34ed44SMarcel Moolenaar 31cb34ed44SMarcel Moolenaar #include <sys/cdefs.h> 3264958185SIan Lepore #include "opt_platform.h" 3364958185SIan Lepore 34cb34ed44SMarcel Moolenaar #include <sys/param.h> 35cb34ed44SMarcel Moolenaar #include <sys/bus.h> 36cb34ed44SMarcel Moolenaar #include <sys/kernel.h> 37cb34ed44SMarcel Moolenaar #include <sys/module.h> 38dce533f3SNathan Whitehorn #include <sys/systm.h> 39cb34ed44SMarcel Moolenaar 40c20809e1SNathan Whitehorn #include <vm/vm.h> 41c20809e1SNathan Whitehorn #include <vm/pmap.h> 42c20809e1SNathan Whitehorn 43cb34ed44SMarcel Moolenaar #include <machine/bus.h> 44cb34ed44SMarcel Moolenaar 45cb34ed44SMarcel Moolenaar #include <dev/fdt/fdt_common.h> 46cb34ed44SMarcel Moolenaar #include <dev/ofw/ofw_bus.h> 47cb34ed44SMarcel Moolenaar #include <dev/ofw/ofw_bus_subr.h> 48cb34ed44SMarcel Moolenaar #include <dev/uart/uart.h> 49cb34ed44SMarcel Moolenaar #include <dev/uart/uart_bus.h> 50cb34ed44SMarcel Moolenaar #include <dev/uart/uart_cpu.h> 51bd69e3adSIan Lepore #include <dev/uart/uart_cpu_fdt.h> 52cb34ed44SMarcel Moolenaar 53cb34ed44SMarcel Moolenaar /* 54cb34ed44SMarcel Moolenaar * UART console routines. 55cb34ed44SMarcel Moolenaar */ 56cb34ed44SMarcel Moolenaar bus_space_tag_t uart_bus_space_io; 57cb34ed44SMarcel Moolenaar bus_space_tag_t uart_bus_space_mem; 58cb34ed44SMarcel Moolenaar 5906d8b1edSAndrew Turner int 60cb34ed44SMarcel Moolenaar uart_cpu_eqres(struct uart_bas *b1, struct uart_bas *b2) 61cb34ed44SMarcel Moolenaar { 62cb34ed44SMarcel Moolenaar 634162dff9SAleksandr Rybalko if (b1->bst != b2->bst) 644162dff9SAleksandr Rybalko return (0); 654162dff9SAleksandr Rybalko if (pmap_kextract(b1->bsh) == 0) 664162dff9SAleksandr Rybalko return (0); 674162dff9SAleksandr Rybalko if (pmap_kextract(b2->bsh) == 0) 684162dff9SAleksandr Rybalko return (0); 694162dff9SAleksandr Rybalko return ((pmap_kextract(b1->bsh) == pmap_kextract(b2->bsh)) ? 1 : 0); 70cb34ed44SMarcel Moolenaar } 71cb34ed44SMarcel Moolenaar 72cb34ed44SMarcel Moolenaar int 73cb34ed44SMarcel Moolenaar uart_cpu_getdev(int devtype, struct uart_devinfo *di) 74cb34ed44SMarcel Moolenaar { 75cb34ed44SMarcel Moolenaar struct uart_class *class; 76d4c89391SAndrew Turner bus_space_tag_t bst; 77d4c89391SAndrew Turner bus_space_handle_t bsh; 78c214a270SRuslan Bukin u_int shift, iowidth, rclk; 79d4c89391SAndrew Turner int br, err; 80cb34ed44SMarcel Moolenaar 81dce533f3SNathan Whitehorn /* Allow overriding the FDT using the environment. */ 82cb34ed44SMarcel Moolenaar class = &uart_ns8250_class; 83cb34ed44SMarcel Moolenaar err = uart_getenv(devtype, di, class); 84*852233cfSWarner Losh if (err == 0) 85cb34ed44SMarcel Moolenaar return (0); 86cb34ed44SMarcel Moolenaar 871c5d066aSMitchell Horne err = uart_cpu_fdt_probe(&class, &bst, &bsh, &br, &rclk, 881c5d066aSMitchell Horne &shift, &iowidth, devtype); 89d4c89391SAndrew Turner if (err != 0) 90cb34ed44SMarcel Moolenaar return (err); 91405ada37SAndrew Turner 92405ada37SAndrew Turner /* 93cb34ed44SMarcel Moolenaar * Finalize configuration. 94cb34ed44SMarcel Moolenaar */ 95cb34ed44SMarcel Moolenaar di->bas.chan = 0; 96d4c89391SAndrew Turner di->bas.regshft = shift; 97c214a270SRuslan Bukin di->bas.regiowidth = iowidth; 98cb34ed44SMarcel Moolenaar di->baudrate = br; 99d4c89391SAndrew Turner di->bas.rclk = rclk; 100cb34ed44SMarcel Moolenaar di->ops = uart_getops(class); 101cb34ed44SMarcel Moolenaar di->databits = 8; 102cb34ed44SMarcel Moolenaar di->stopbits = 1; 103cb34ed44SMarcel Moolenaar di->parity = UART_PARITY_NONE; 104d4c89391SAndrew Turner di->bas.bst = bst; 105d4c89391SAndrew Turner di->bas.bsh = bsh; 106cb34ed44SMarcel Moolenaar 10799c41022SIan Lepore uart_bus_space_mem = di->bas.bst; 10899c41022SIan Lepore uart_bus_space_io = NULL; 10999c41022SIan Lepore 11099c41022SIan Lepore return (err); 111cb34ed44SMarcel Moolenaar } 112