2013-05-21 03:05:49 +00:00
|
|
|
/*-
|
2017-11-27 14:52:40 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2013-05-21 03:05:49 +00:00
|
|
|
* Copyright (c) 2009-2010 The FreeBSD Foundation
|
|
|
|
*
|
|
|
|
* This software was developed by Semihalf under sponsorship from
|
|
|
|
* the FreeBSD Foundation.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2013-11-02 20:14:39 +00:00
|
|
|
#include "opt_platform.h"
|
|
|
|
|
2013-05-21 03:05:49 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/module.h>
|
2013-10-26 18:25:55 +00:00
|
|
|
#include <sys/systm.h>
|
2013-05-21 03:05:49 +00:00
|
|
|
|
2013-10-26 03:22:57 +00:00
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/pmap.h>
|
|
|
|
|
2013-05-21 03:05:49 +00:00
|
|
|
#include <machine/bus.h>
|
|
|
|
|
|
|
|
#include <dev/fdt/fdt_common.h>
|
|
|
|
#include <dev/ofw/ofw_bus.h>
|
|
|
|
#include <dev/ofw/ofw_bus_subr.h>
|
|
|
|
#include <dev/uart/uart.h>
|
|
|
|
#include <dev/uart/uart_bus.h>
|
|
|
|
#include <dev/uart/uart_cpu.h>
|
2015-03-07 15:18:57 +00:00
|
|
|
#include <dev/uart/uart_cpu_fdt.h>
|
2013-05-21 03:05:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* UART console routines.
|
|
|
|
*/
|
|
|
|
bus_space_tag_t uart_bus_space_io;
|
|
|
|
bus_space_tag_t uart_bus_space_mem;
|
|
|
|
|
|
|
|
int
|
|
|
|
uart_cpu_eqres(struct uart_bas *b1, struct uart_bas *b2)
|
|
|
|
{
|
|
|
|
|
2013-10-25 11:44:39 +00:00
|
|
|
if (b1->bst != b2->bst)
|
|
|
|
return (0);
|
|
|
|
if (pmap_kextract(b1->bsh) == 0)
|
|
|
|
return (0);
|
|
|
|
if (pmap_kextract(b2->bsh) == 0)
|
|
|
|
return (0);
|
|
|
|
return ((pmap_kextract(b1->bsh) == pmap_kextract(b2->bsh)) ? 1 : 0);
|
2013-05-21 03:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
uart_cpu_getdev(int devtype, struct uart_devinfo *di)
|
|
|
|
{
|
|
|
|
struct uart_class *class;
|
2016-07-20 17:19:47 +00:00
|
|
|
bus_space_tag_t bst;
|
|
|
|
bus_space_handle_t bsh;
|
2017-02-27 20:08:42 +00:00
|
|
|
u_int shift, iowidth, rclk;
|
2016-07-20 17:19:47 +00:00
|
|
|
int br, err;
|
2013-05-21 03:05:49 +00:00
|
|
|
|
2013-10-26 18:25:55 +00:00
|
|
|
/* Allow overriding the FDT using the environment. */
|
2013-05-21 03:05:49 +00:00
|
|
|
class = &uart_ns8250_class;
|
|
|
|
err = uart_getenv(devtype, di, class);
|
|
|
|
if (!err)
|
|
|
|
return (0);
|
|
|
|
|
2020-12-02 21:01:52 +00:00
|
|
|
err = uart_cpu_fdt_probe(&class, &bst, &bsh, &br, &rclk,
|
|
|
|
&shift, &iowidth, devtype);
|
2016-07-20 17:19:47 +00:00
|
|
|
if (err != 0)
|
|
|
|
return (err);
|
2015-04-11 17:16:23 +00:00
|
|
|
|
2015-03-07 15:18:57 +00:00
|
|
|
/*
|
|
|
|
* Finalize configuration.
|
|
|
|
*/
|
2013-05-21 03:05:49 +00:00
|
|
|
di->bas.chan = 0;
|
2016-07-20 17:19:47 +00:00
|
|
|
di->bas.regshft = shift;
|
2017-02-27 20:08:42 +00:00
|
|
|
di->bas.regiowidth = iowidth;
|
2013-05-21 03:05:49 +00:00
|
|
|
di->baudrate = br;
|
2016-07-20 17:19:47 +00:00
|
|
|
di->bas.rclk = rclk;
|
2013-05-21 03:05:49 +00:00
|
|
|
di->ops = uart_getops(class);
|
|
|
|
di->databits = 8;
|
|
|
|
di->stopbits = 1;
|
|
|
|
di->parity = UART_PARITY_NONE;
|
2016-07-20 17:19:47 +00:00
|
|
|
di->bas.bst = bst;
|
|
|
|
di->bas.bsh = bsh;
|
2013-05-21 03:05:49 +00:00
|
|
|
|
2016-02-23 02:57:45 +00:00
|
|
|
uart_bus_space_mem = di->bas.bst;
|
|
|
|
uart_bus_space_io = NULL;
|
|
|
|
|
|
|
|
return (err);
|
2013-05-21 03:05:49 +00:00
|
|
|
}
|