1250840Smarcel/*- 2250840Smarcel * Copyright (c) 2009-2010 The FreeBSD Foundation 3250840Smarcel * All rights reserved. 4250840Smarcel * 5250840Smarcel * This software was developed by Semihalf under sponsorship from 6250840Smarcel * the FreeBSD Foundation. 7250840Smarcel * 8250840Smarcel * Redistribution and use in source and binary forms, with or without 9250840Smarcel * modification, are permitted provided that the following conditions 10250840Smarcel * are met: 11250840Smarcel * 1. Redistributions of source code must retain the above copyright 12250840Smarcel * notice, this list of conditions and the following disclaimer. 13250840Smarcel * 2. Redistributions in binary form must reproduce the above copyright 14250840Smarcel * notice, this list of conditions and the following disclaimer in the 15250840Smarcel * documentation and/or other materials provided with the distribution. 16250840Smarcel * 17250840Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18250840Smarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19250840Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20250840Smarcel * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21250840Smarcel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22250840Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23250840Smarcel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24250840Smarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25250840Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26250840Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27250840Smarcel * SUCH DAMAGE. 28250840Smarcel */ 29250840Smarcel 30250840Smarcel#include <sys/cdefs.h> 31250840Smarcel__FBSDID("$FreeBSD: stable/11/sys/dev/uart/uart_cpu_fdt.c 340145 2018-11-04 23:28:56Z mmacy $"); 32250840Smarcel 33257556Sian#include "opt_platform.h" 34257556Sian 35250840Smarcel#include <sys/param.h> 36250840Smarcel#include <sys/bus.h> 37250840Smarcel#include <sys/kernel.h> 38250840Smarcel#include <sys/module.h> 39257183Snwhitehorn#include <sys/systm.h> 40250840Smarcel 41257144Snwhitehorn#include <vm/vm.h> 42257144Snwhitehorn#include <vm/pmap.h> 43257144Snwhitehorn 44250840Smarcel#include <machine/bus.h> 45250840Smarcel 46250840Smarcel#include <dev/fdt/fdt_common.h> 47250840Smarcel#include <dev/ofw/ofw_bus.h> 48250840Smarcel#include <dev/ofw/ofw_bus_subr.h> 49250840Smarcel#include <dev/uart/uart.h> 50250840Smarcel#include <dev/uart/uart_bus.h> 51250840Smarcel#include <dev/uart/uart_cpu.h> 52279723Sian#include <dev/uart/uart_cpu_fdt.h> 53250840Smarcel 54250840Smarcel/* 55250840Smarcel * UART console routines. 56250840Smarcel */ 57250840Smarcelbus_space_tag_t uart_bus_space_io; 58250840Smarcelbus_space_tag_t uart_bus_space_mem; 59250840Smarcel 60281074Sandrewint 61250840Smarceluart_cpu_eqres(struct uart_bas *b1, struct uart_bas *b2) 62250840Smarcel{ 63250840Smarcel 64257111Sray if (b1->bst != b2->bst) 65257111Sray return (0); 66257111Sray if (pmap_kextract(b1->bsh) == 0) 67257111Sray return (0); 68257111Sray if (pmap_kextract(b2->bsh) == 0) 69257111Sray return (0); 70257111Sray return ((pmap_kextract(b1->bsh) == pmap_kextract(b2->bsh)) ? 1 : 0); 71250840Smarcel} 72250840Smarcel 73250840Smarcelint 74250840Smarceluart_cpu_getdev(int devtype, struct uart_devinfo *di) 75250840Smarcel{ 76250840Smarcel struct uart_class *class; 77331885Sgonzo bus_space_tag_t bst; 78331885Sgonzo bus_space_handle_t bsh; 79331885Sgonzo u_int shift, rclk; 80331885Sgonzo int br, err; 81250840Smarcel 82257183Snwhitehorn /* Allow overriding the FDT using the environment. */ 83250840Smarcel class = &uart_ns8250_class; 84250840Smarcel err = uart_getenv(devtype, di, class); 85250840Smarcel if (!err) 86250840Smarcel return (0); 87250840Smarcel 88250840Smarcel if (devtype != UART_DEV_CONSOLE) 89250840Smarcel return (ENXIO); 90250840Smarcel 91331885Sgonzo err = uart_cpu_fdt_probe(&class, &bst, &bsh, &br, &rclk, &shift); 92331885Sgonzo if (err != 0) 93331885Sgonzo return (err); 94257195Snwhitehorn 95250840Smarcel /* 96279723Sian * Finalize configuration. 97279723Sian */ 98250840Smarcel di->bas.chan = 0; 99331885Sgonzo di->bas.regshft = shift; 100250840Smarcel di->baudrate = br; 101331885Sgonzo di->bas.rclk = rclk; 102250840Smarcel di->ops = uart_getops(class); 103250840Smarcel di->databits = 8; 104250840Smarcel di->stopbits = 1; 105250840Smarcel di->parity = UART_PARITY_NONE; 106331885Sgonzo di->bas.bst = bst; 107331885Sgonzo di->bas.bsh = bsh; 108250840Smarcel 109295909Sian uart_bus_space_mem = di->bas.bst; 110295909Sian uart_bus_space_io = NULL; 111295909Sian 112295909Sian return (err); 113250840Smarcel} 114