Home | History | Annotate | Line # | Download | only in rockchip
rk_platform.c revision 1.2
      1  1.2     skrll /* $NetBSD: rk_platform.c,v 1.2 2018/08/05 14:02:35 skrll Exp $ */
      2  1.1  jmcneill 
      3  1.1  jmcneill /*-
      4  1.1  jmcneill  * Copyright (c) 2018 Jared McNeill <jmcneill (at) invisible.ca>
      5  1.1  jmcneill  * All rights reserved.
      6  1.1  jmcneill  *
      7  1.1  jmcneill  * Redistribution and use in source and binary forms, with or without
      8  1.1  jmcneill  * modification, are permitted provided that the following conditions
      9  1.1  jmcneill  * are met:
     10  1.1  jmcneill  * 1. Redistributions of source code must retain the above copyright
     11  1.1  jmcneill  *    notice, this list of conditions and the following disclaimer.
     12  1.1  jmcneill  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  jmcneill  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  jmcneill  *    documentation and/or other materials provided with the distribution.
     15  1.1  jmcneill  *
     16  1.1  jmcneill  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  1.1  jmcneill  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  1.1  jmcneill  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  1.1  jmcneill  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  1.1  jmcneill  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21  1.1  jmcneill  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22  1.1  jmcneill  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23  1.1  jmcneill  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24  1.1  jmcneill  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  1.1  jmcneill  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  1.1  jmcneill  * SUCH DAMAGE.
     27  1.1  jmcneill  */
     28  1.1  jmcneill 
     29  1.1  jmcneill #include "opt_soc.h"
     30  1.1  jmcneill #include "opt_multiprocessor.h"
     31  1.1  jmcneill #include "opt_fdt_arm.h"
     32  1.1  jmcneill 
     33  1.1  jmcneill #include <sys/cdefs.h>
     34  1.2     skrll __KERNEL_RCSID(0, "$NetBSD: rk_platform.c,v 1.2 2018/08/05 14:02:35 skrll Exp $");
     35  1.1  jmcneill 
     36  1.1  jmcneill #include <sys/param.h>
     37  1.1  jmcneill #include <sys/bus.h>
     38  1.1  jmcneill #include <sys/cpu.h>
     39  1.1  jmcneill #include <sys/device.h>
     40  1.1  jmcneill #include <sys/termios.h>
     41  1.1  jmcneill 
     42  1.1  jmcneill #include <dev/fdt/fdtvar.h>
     43  1.1  jmcneill #include <arm/fdt/arm_fdtvar.h>
     44  1.1  jmcneill 
     45  1.1  jmcneill #include <uvm/uvm_extern.h>
     46  1.1  jmcneill 
     47  1.1  jmcneill #include <machine/bootconfig.h>
     48  1.1  jmcneill #include <arm/cpufunc.h>
     49  1.1  jmcneill 
     50  1.1  jmcneill #include <arm/cortex/gtmr_var.h>
     51  1.1  jmcneill 
     52  1.1  jmcneill #include <dev/ic/ns16550reg.h>
     53  1.1  jmcneill #include <dev/ic/comreg.h>
     54  1.1  jmcneill 
     55  1.1  jmcneill #include <arm/arm/psci.h>
     56  1.1  jmcneill #include <arm/fdt/psci_fdt.h>
     57  1.1  jmcneill 
     58  1.1  jmcneill #include <libfdt.h>
     59  1.1  jmcneill 
     60  1.1  jmcneill extern struct arm32_bus_dma_tag arm_generic_dma_tag;
     61  1.1  jmcneill extern struct bus_space arm_generic_bs_tag;
     62  1.1  jmcneill extern struct bus_space arm_generic_a4x_bs_tag;
     63  1.1  jmcneill 
     64  1.1  jmcneill static void
     65  1.1  jmcneill rk_platform_init_attach_args(struct fdt_attach_args *faa)
     66  1.1  jmcneill {
     67  1.1  jmcneill 	faa->faa_bst = &arm_generic_bs_tag;
     68  1.1  jmcneill 	faa->faa_a4x_bst = &arm_generic_a4x_bs_tag;
     69  1.1  jmcneill 	faa->faa_dmat = &arm_generic_dma_tag;
     70  1.1  jmcneill }
     71  1.1  jmcneill 
     72  1.1  jmcneill static void
     73  1.1  jmcneill rk_platform_device_register(device_t self, void *aux)
     74  1.1  jmcneill {
     75  1.1  jmcneill }
     76  1.1  jmcneill 
     77  1.1  jmcneill static void
     78  1.1  jmcneill rk_platform_bootstrap(void)
     79  1.1  jmcneill {
     80  1.1  jmcneill 	void *fdt_data = __UNCONST(fdtbus_get_data());
     81  1.1  jmcneill 
     82  1.1  jmcneill 	psci_fdt_bootstrap();
     83  1.1  jmcneill 
     84  1.1  jmcneill 	const int chosen_off = fdt_path_offset(fdt_data, "/chosen");
     85  1.1  jmcneill 	if (chosen_off < 0)
     86  1.1  jmcneill 		return;
     87  1.1  jmcneill 
     88  1.1  jmcneill 	if (match_bootconf_option(boot_args, "console", "fb")) {
     89  1.1  jmcneill 		const int framebuffer_off =
     90  1.1  jmcneill 		    fdt_path_offset(fdt_data, "/chosen/framebuffer");
     91  1.1  jmcneill 		if (framebuffer_off >= 0) {
     92  1.1  jmcneill 			const char *status = fdt_getprop(fdt_data,
     93  1.1  jmcneill 			    framebuffer_off, "status", NULL);
     94  1.1  jmcneill 			if (status == NULL || strncmp(status, "ok", 2) == 0) {
     95  1.1  jmcneill 				fdt_setprop_string(fdt_data, chosen_off,
     96  1.1  jmcneill 				    "stdout-path", "/chosen/framebuffer");
     97  1.1  jmcneill 			}
     98  1.1  jmcneill 		}
     99  1.1  jmcneill 	} else if (match_bootconf_option(boot_args, "console", "serial")) {
    100  1.1  jmcneill 		fdt_setprop_string(fdt_data, chosen_off,
    101  1.1  jmcneill 		    "stdout-path", "serial0:115200n8");
    102  1.1  jmcneill 	}
    103  1.1  jmcneill }
    104  1.1  jmcneill 
    105  1.1  jmcneill #ifdef SOC_RK3328
    106  1.1  jmcneill 
    107  1.1  jmcneill #include <arm/rockchip/rk3328_platform.h>
    108  1.1  jmcneill 
    109  1.1  jmcneill static const struct pmap_devmap *
    110  1.1  jmcneill rk3328_platform_devmap(void)
    111  1.1  jmcneill {
    112  1.1  jmcneill 	static const struct pmap_devmap devmap[] = {
    113  1.1  jmcneill 		DEVMAP_ENTRY(RK3328_CORE_VBASE,
    114  1.1  jmcneill 			     RK3328_CORE_PBASE,
    115  1.1  jmcneill 			     RK3328_CORE_SIZE),
    116  1.1  jmcneill 		DEVMAP_ENTRY_END
    117  1.1  jmcneill 	};
    118  1.1  jmcneill 
    119  1.1  jmcneill 	return devmap;
    120  1.1  jmcneill }
    121  1.1  jmcneill 
    122  1.1  jmcneill void rk3328_platform_early_putchar(char);
    123  1.1  jmcneill 
    124  1.1  jmcneill void
    125  1.1  jmcneill rk3328_platform_early_putchar(char c)
    126  1.1  jmcneill {
    127  1.1  jmcneill #ifdef CONSADDR
    128  1.1  jmcneill #define CONSADDR_VA	((CONSADDR - RK3328_CORE_PBASE) + RK3328_CORE_VBASE)
    129  1.1  jmcneill 	volatile uint32_t *uartaddr = cpu_earlydevice_va_p() ?
    130  1.1  jmcneill 	    (volatile uint32_t *)CONSADDR_VA :
    131  1.1  jmcneill 	    (volatile uint32_t *)CONSADDR;
    132  1.1  jmcneill 
    133  1.1  jmcneill 	while ((le32toh(uartaddr[com_lsr]) & LSR_TXRDY) == 0)
    134  1.1  jmcneill 		;
    135  1.1  jmcneill 
    136  1.1  jmcneill 	uartaddr[com_data] = htole32(c);
    137  1.1  jmcneill #undef CONSADDR_VA
    138  1.1  jmcneill #endif
    139  1.1  jmcneill }
    140  1.1  jmcneill 
    141  1.1  jmcneill static u_int
    142  1.1  jmcneill rk3328_platform_uart_freq(void)
    143  1.1  jmcneill {
    144  1.1  jmcneill 	return RK3328_UART_FREQ;
    145  1.1  jmcneill }
    146  1.1  jmcneill 
    147  1.1  jmcneill static const struct arm_platform rk3328_platform = {
    148  1.2     skrll 	.ap_devmap = rk3328_platform_devmap,
    149  1.2     skrll 	.ap_bootstrap = rk_platform_bootstrap,
    150  1.2     skrll 	.ap_init_attach_args = rk_platform_init_attach_args,
    151  1.2     skrll 	.ap_early_putchar = rk3328_platform_early_putchar,
    152  1.2     skrll 	.ap_device_register = rk_platform_device_register,
    153  1.2     skrll 	.ap_reset = psci_fdt_reset,
    154  1.2     skrll 	.ap_delay = gtmr_delay,
    155  1.2     skrll 	.ap_uart_freq = rk3328_platform_uart_freq,
    156  1.1  jmcneill };
    157  1.1  jmcneill 
    158  1.1  jmcneill ARM_PLATFORM(rk3328, "rockchip,rk3328", &rk3328_platform);
    159  1.1  jmcneill 
    160  1.1  jmcneill #endif /* SOC_RK3328 */
    161