Home | History | Annotate | Line # | Download | only in samsung
exynos_platform.c revision 1.8.2.6
      1  1.8.2.6  pgoyette /* $NetBSD: exynos_platform.c,v 1.8.2.6 2018/11/26 01:52:20 pgoyette Exp $ */
      2      1.1  jmcneill 
      3      1.1  jmcneill /*-
      4      1.1  jmcneill  * Copyright (c) 2017 Jared D. 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.8.2.3  pgoyette #include "opt_arm_debug.h"
     30  1.8.2.4  pgoyette #include "opt_console.h"
     31      1.1  jmcneill #include "opt_exynos.h"
     32      1.1  jmcneill #include "opt_multiprocessor.h"
     33  1.8.2.4  pgoyette #include "opt_console.h"
     34      1.1  jmcneill 
     35      1.1  jmcneill #include "ukbd.h"
     36      1.1  jmcneill 
     37      1.1  jmcneill #include <sys/cdefs.h>
     38  1.8.2.6  pgoyette __KERNEL_RCSID(0, "$NetBSD: exynos_platform.c,v 1.8.2.6 2018/11/26 01:52:20 pgoyette Exp $");
     39      1.1  jmcneill 
     40      1.1  jmcneill #include <sys/param.h>
     41      1.1  jmcneill #include <sys/bus.h>
     42      1.1  jmcneill #include <sys/cpu.h>
     43      1.1  jmcneill #include <sys/device.h>
     44      1.1  jmcneill #include <sys/termios.h>
     45      1.1  jmcneill 
     46      1.1  jmcneill #include <dev/fdt/fdtvar.h>
     47      1.1  jmcneill 
     48      1.1  jmcneill #include <uvm/uvm_extern.h>
     49      1.1  jmcneill 
     50      1.1  jmcneill #include <machine/bootconfig.h>
     51      1.1  jmcneill #include <arm/cpufunc.h>
     52      1.1  jmcneill 
     53      1.1  jmcneill #include <arm/samsung/exynos_reg.h>
     54      1.1  jmcneill #include <arm/samsung/exynos_var.h>
     55  1.8.2.2  pgoyette #include <arm/samsung/mct_var.h>
     56  1.8.2.3  pgoyette #include <arm/samsung/sscom_reg.h>
     57      1.1  jmcneill 
     58      1.2  jmcneill #include <evbarm/exynos/platform.h>
     59  1.8.2.5  pgoyette #include <evbarm/fdt/machdep.h>
     60      1.2  jmcneill 
     61      1.1  jmcneill #include <arm/fdt/arm_fdtvar.h>
     62      1.1  jmcneill 
     63  1.8.2.3  pgoyette void exynos_platform_early_putchar(char);
     64      1.1  jmcneill 
     65  1.8.2.3  pgoyette #define	EXYNOS5_SWRESET_REG	0x10040400
     66      1.1  jmcneill 
     67      1.2  jmcneill #define EXYNOS_IOPHYSTOVIRT(a) \
     68      1.2  jmcneill     ((vaddr_t)(((a) - EXYNOS_CORE_PBASE) + EXYNOS_CORE_VBASE))
     69      1.2  jmcneill 
     70  1.8.2.4  pgoyette #define	EXYNOS5800_PMU_BASE		0x10040000
     71  1.8.2.4  pgoyette #define	EXYNOS5800_PMU_SIZE		0x20000
     72  1.8.2.4  pgoyette #define	 EXYNOS5800_PMU_CORE_CONFIG(n)	(0x2000 + 0x80 * (n))
     73  1.8.2.4  pgoyette #define	 EXYNOS5800_PMU_CORE_STATUS(n)	(0x2004 + 0x80 * (n))
     74  1.8.2.4  pgoyette #define	 EXYNOS5800_PMU_CORE_POWER_EN	0x3
     75  1.8.2.4  pgoyette #define	EXYNOS5800_SYSRAM_BASE		0x0207301c
     76  1.8.2.4  pgoyette #define	EXYNOS5800_SYSRAM_SIZE		0x4
     77  1.8.2.4  pgoyette 
     78  1.8.2.4  pgoyette static void
     79  1.8.2.5  pgoyette exynos_platform_bootstrap(void)
     80  1.8.2.4  pgoyette {
     81  1.8.2.5  pgoyette 
     82  1.8.2.4  pgoyette #if defined(MULTIPROCESSOR)
     83  1.8.2.5  pgoyette 	arm_cpu_max = 1 + __SHIFTOUT(armreg_l2ctrl_read(), L2CTRL_NUMCPU);
     84  1.8.2.5  pgoyette #endif
     85  1.8.2.5  pgoyette }
     86  1.8.2.5  pgoyette 
     87  1.8.2.5  pgoyette static void
     88  1.8.2.5  pgoyette exynos5800_mpstart(void)
     89  1.8.2.5  pgoyette {
     90  1.8.2.5  pgoyette #if defined(MULTIPROCESSOR)
     91  1.8.2.5  pgoyette 	extern void cpu_mpstart(void);
     92  1.8.2.4  pgoyette 	bus_space_tag_t bst = &armv7_generic_bs_tag;
     93  1.8.2.4  pgoyette 	bus_space_handle_t pmu_bsh, sysram_bsh;
     94  1.8.2.4  pgoyette 	uint32_t val, started = 0;
     95  1.8.2.4  pgoyette 	int n;
     96  1.8.2.4  pgoyette 
     97  1.8.2.4  pgoyette 	bus_space_map(bst, EXYNOS5800_PMU_BASE, EXYNOS5800_PMU_SIZE, 0, &pmu_bsh);
     98  1.8.2.4  pgoyette 	bus_space_map(bst, EXYNOS5800_SYSRAM_BASE, EXYNOS5800_SYSRAM_SIZE, 0, &sysram_bsh);
     99  1.8.2.4  pgoyette 
    100  1.8.2.5  pgoyette 	bus_space_write_4(bst, sysram_bsh, 0, KERN_VTOPHYS((vaddr_t)cpu_mpstart));
    101  1.8.2.4  pgoyette 	bus_space_barrier(bst, sysram_bsh, 0, 4, BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE);
    102  1.8.2.4  pgoyette 
    103  1.8.2.4  pgoyette 	for (n = 1; n < arm_cpu_max; n++) {
    104  1.8.2.4  pgoyette 		bus_space_write_4(bst, pmu_bsh, EXYNOS5800_PMU_CORE_CONFIG(n),
    105  1.8.2.4  pgoyette 		    EXYNOS5800_PMU_CORE_POWER_EN);
    106  1.8.2.4  pgoyette 		for (u_int i = 0x01000000; i > 0; i--) {
    107  1.8.2.4  pgoyette 			val = bus_space_read_4(bst, pmu_bsh, EXYNOS5800_PMU_CORE_STATUS(n));
    108  1.8.2.4  pgoyette 			if ((val & EXYNOS5800_PMU_CORE_POWER_EN) == EXYNOS5800_PMU_CORE_POWER_EN) {
    109  1.8.2.4  pgoyette 				started |= __BIT(n);
    110  1.8.2.4  pgoyette 				break;
    111  1.8.2.4  pgoyette 			}
    112  1.8.2.4  pgoyette 		}
    113  1.8.2.4  pgoyette 	}
    114  1.8.2.4  pgoyette 
    115  1.8.2.4  pgoyette 	for (u_int i = 0x10000000; i > 0; i--) {
    116  1.8.2.4  pgoyette 		arm_dmb();
    117  1.8.2.4  pgoyette 		if (arm_cpu_hatched == started)
    118  1.8.2.4  pgoyette 			break;
    119  1.8.2.4  pgoyette 	}
    120  1.8.2.4  pgoyette 
    121  1.8.2.4  pgoyette 	bus_space_unmap(bst, sysram_bsh, EXYNOS5800_SYSRAM_SIZE);
    122  1.8.2.4  pgoyette 	bus_space_unmap(bst, pmu_bsh, EXYNOS5800_PMU_SIZE);
    123  1.8.2.4  pgoyette #endif
    124  1.8.2.4  pgoyette }
    125  1.8.2.4  pgoyette 
    126  1.8.2.4  pgoyette static struct of_compat_data mp_compat_data[] = {
    127  1.8.2.5  pgoyette 	{ "samsung,exynos5800",		(uintptr_t)exynos5800_mpstart },
    128  1.8.2.4  pgoyette 	{ NULL }
    129  1.8.2.4  pgoyette };
    130  1.8.2.4  pgoyette 
    131      1.1  jmcneill static void
    132  1.8.2.5  pgoyette exynos_platform_mpstart(void)
    133      1.1  jmcneill {
    134  1.8.2.3  pgoyette 
    135  1.8.2.5  pgoyette 	void (*mp_start)(void) = NULL;
    136  1.8.2.5  pgoyette 
    137  1.8.2.5  pgoyette //	exynos_bootstrap();
    138  1.8.2.4  pgoyette 
    139  1.8.2.4  pgoyette 	const struct of_compat_data *cd = of_search_compatible(OF_finddevice("/"), mp_compat_data);
    140  1.8.2.4  pgoyette 	if (cd)
    141  1.8.2.5  pgoyette 		mp_start = (void (*)(void))cd->data;
    142  1.8.2.4  pgoyette 
    143  1.8.2.5  pgoyette 	if (mp_start)
    144  1.8.2.5  pgoyette 		mp_start();
    145      1.1  jmcneill }
    146      1.1  jmcneill 
    147      1.1  jmcneill static void
    148      1.1  jmcneill exynos_platform_init_attach_args(struct fdt_attach_args *faa)
    149      1.1  jmcneill {
    150      1.1  jmcneill 	extern struct bus_space armv7_generic_bs_tag;
    151      1.1  jmcneill 	extern struct bus_space armv7_generic_a4x_bs_tag;
    152  1.8.2.1  pgoyette 	extern struct arm32_bus_dma_tag arm_generic_dma_tag;
    153      1.1  jmcneill 
    154      1.1  jmcneill 	faa->faa_bst = &armv7_generic_bs_tag;
    155      1.1  jmcneill 	faa->faa_a4x_bst = &armv7_generic_a4x_bs_tag;
    156  1.8.2.1  pgoyette 	faa->faa_dmat = &arm_generic_dma_tag;
    157      1.1  jmcneill }
    158      1.1  jmcneill 
    159  1.8.2.3  pgoyette void
    160      1.1  jmcneill exynos_platform_early_putchar(char c)
    161      1.1  jmcneill {
    162  1.8.2.3  pgoyette #ifdef CONSADDR
    163  1.8.2.3  pgoyette #define CONSADDR_VA	(CONSADDR - EXYNOS_CORE_PBASE + EXYNOS_CORE_VBASE)
    164  1.8.2.3  pgoyette 
    165  1.8.2.3  pgoyette 	volatile uint32_t *uartaddr = cpu_earlydevice_va_p() ?
    166  1.8.2.3  pgoyette 	    (volatile uint32_t *)CONSADDR_VA :
    167  1.8.2.3  pgoyette 	    (volatile uint32_t *)CONSADDR;
    168  1.8.2.3  pgoyette 
    169  1.8.2.3  pgoyette 	while ((uartaddr[SSCOM_UFSTAT / 4] & UFSTAT_TXFULL) != 0)
    170  1.8.2.3  pgoyette 		;
    171      1.2  jmcneill 
    172  1.8.2.3  pgoyette 	uartaddr[SSCOM_UTXH / 4] = c;
    173      1.4  jmcneill #endif
    174      1.1  jmcneill }
    175      1.1  jmcneill 
    176      1.1  jmcneill static void
    177      1.1  jmcneill exynos_platform_device_register(device_t self, void *aux)
    178      1.1  jmcneill {
    179      1.1  jmcneill 	exynos_device_register(self, aux);
    180      1.1  jmcneill }
    181      1.1  jmcneill 
    182      1.1  jmcneill static void
    183      1.6  jmcneill exynos5_platform_reset(void)
    184      1.1  jmcneill {
    185      1.6  jmcneill 	bus_space_tag_t bst = &armv7_generic_bs_tag;
    186      1.6  jmcneill 	bus_space_handle_t bsh;
    187      1.6  jmcneill 
    188      1.6  jmcneill 	bus_space_map(bst, EXYNOS5_SWRESET_REG, 4, 0, &bsh);
    189      1.6  jmcneill 	bus_space_write_4(bst, bsh, 0, 1);
    190      1.1  jmcneill }
    191      1.1  jmcneill 
    192      1.1  jmcneill static u_int
    193      1.1  jmcneill exynos_platform_uart_freq(void)
    194      1.1  jmcneill {
    195      1.1  jmcneill 	return EXYNOS_UART_FREQ;
    196      1.1  jmcneill }
    197      1.1  jmcneill 
    198  1.8.2.3  pgoyette 
    199  1.8.2.3  pgoyette #if defined(SOC_EXYNOS4)
    200  1.8.2.3  pgoyette static const struct pmap_devmap *
    201  1.8.2.3  pgoyette exynos4_platform_devmap(void)
    202  1.8.2.3  pgoyette {
    203  1.8.2.3  pgoyette 	static const struct pmap_devmap devmap[] = {
    204  1.8.2.3  pgoyette 		DEVMAP_ENTRY(EXYNOS_CORE_VBASE,
    205  1.8.2.3  pgoyette 			     EXYNOS_CORE_PBASE,
    206  1.8.2.3  pgoyette 			     EXYNOS4_CORE_SIZE),
    207  1.8.2.3  pgoyette 		DEVMAP_ENTRY(EXYNOS4_AUDIOCORE_VBASE,
    208  1.8.2.3  pgoyette 			     EXYNOS4_AUDIOCORE_PBASE,
    209  1.8.2.3  pgoyette 			     EXYNOS4_AUDIOCORE_SIZE),
    210  1.8.2.3  pgoyette 		DEVMAP_ENTRY_END
    211  1.8.2.3  pgoyette 	};
    212  1.8.2.3  pgoyette 
    213  1.8.2.3  pgoyette 	return devmap;
    214  1.8.2.3  pgoyette }
    215  1.8.2.3  pgoyette 
    216  1.8.2.5  pgoyette static void
    217  1.8.2.5  pgoyette exynos4_platform_bootstrap(void)
    218  1.8.2.5  pgoyette {
    219  1.8.2.5  pgoyette 
    220  1.8.2.5  pgoyette 	exynos_bootstrap(4);
    221  1.8.2.5  pgoyette 
    222  1.8.2.5  pgoyette 	exynos_platform_bootstrap();
    223  1.8.2.5  pgoyette }
    224  1.8.2.5  pgoyette 
    225  1.8.2.3  pgoyette static const struct arm_platform exynos4_platform = {
    226  1.8.2.3  pgoyette 	.ap_devmap = exynos4_platform_devmap,
    227  1.8.2.5  pgoyette //	.ap_mpstart = exynos4_mpstart,
    228  1.8.2.5  pgoyette 	.ap_bootstrap = exynos4_platform_bootstrap,
    229  1.8.2.3  pgoyette 	.ap_init_attach_args = exynos_platform_init_attach_args,
    230  1.8.2.3  pgoyette 	.ap_device_register = exynos_platform_device_register,
    231  1.8.2.3  pgoyette 	.ap_reset = exynos5_platform_reset,
    232  1.8.2.3  pgoyette 	.ap_delay = mct_delay,
    233  1.8.2.3  pgoyette 	.ap_uart_freq = exynos_platform_uart_freq,
    234  1.8.2.3  pgoyette };
    235  1.8.2.3  pgoyette 
    236  1.8.2.3  pgoyette ARM_PLATFORM(exynos4, "samsung,exynos4", &exynos4_platform);
    237  1.8.2.3  pgoyette #endif
    238  1.8.2.3  pgoyette 
    239  1.8.2.3  pgoyette 
    240  1.8.2.3  pgoyette #if defined(SOC_EXYNOS5)
    241  1.8.2.3  pgoyette static const struct pmap_devmap *
    242  1.8.2.3  pgoyette exynos5_platform_devmap(void)
    243  1.8.2.3  pgoyette {
    244  1.8.2.3  pgoyette 	static const struct pmap_devmap devmap[] = {
    245  1.8.2.3  pgoyette 		DEVMAP_ENTRY(EXYNOS_CORE_VBASE,
    246  1.8.2.3  pgoyette 			     EXYNOS_CORE_PBASE,
    247  1.8.2.3  pgoyette 			     EXYNOS5_CORE_SIZE),
    248  1.8.2.3  pgoyette 		DEVMAP_ENTRY(EXYNOS5_AUDIOCORE_VBASE,
    249  1.8.2.3  pgoyette 			     EXYNOS5_AUDIOCORE_PBASE,
    250  1.8.2.3  pgoyette 			     EXYNOS5_AUDIOCORE_SIZE),
    251  1.8.2.4  pgoyette 		DEVMAP_ENTRY(EXYNOS5_SYSRAM_VBASE,
    252  1.8.2.4  pgoyette 			     EXYNOS5_SYSRAM_PBASE,
    253  1.8.2.4  pgoyette 			     EXYNOS5_SYSRAM_SIZE),
    254  1.8.2.3  pgoyette 		DEVMAP_ENTRY_END
    255  1.8.2.3  pgoyette 	};
    256  1.8.2.3  pgoyette 
    257  1.8.2.3  pgoyette 	return devmap;
    258  1.8.2.3  pgoyette }
    259  1.8.2.3  pgoyette 
    260  1.8.2.5  pgoyette static void
    261  1.8.2.5  pgoyette exynos5_platform_bootstrap(void)
    262  1.8.2.5  pgoyette {
    263  1.8.2.5  pgoyette 
    264  1.8.2.5  pgoyette 	exynos_bootstrap(5);
    265  1.8.2.5  pgoyette 
    266  1.8.2.5  pgoyette 	exynos_platform_bootstrap();
    267  1.8.2.5  pgoyette }
    268  1.8.2.5  pgoyette 
    269      1.1  jmcneill static const struct arm_platform exynos5_platform = {
    270  1.8.2.3  pgoyette 	.ap_devmap = exynos5_platform_devmap,
    271  1.8.2.5  pgoyette 	.ap_bootstrap = exynos5_platform_bootstrap,
    272  1.8.2.5  pgoyette 	.ap_mpstart = exynos_platform_mpstart,
    273  1.8.2.3  pgoyette 	.ap_init_attach_args = exynos_platform_init_attach_args,
    274  1.8.2.3  pgoyette 	.ap_device_register = exynos_platform_device_register,
    275  1.8.2.3  pgoyette 	.ap_reset = exynos5_platform_reset,
    276  1.8.2.3  pgoyette 	.ap_delay = mct_delay,
    277  1.8.2.3  pgoyette 	.ap_uart_freq = exynos_platform_uart_freq,
    278      1.1  jmcneill };
    279      1.1  jmcneill 
    280      1.1  jmcneill ARM_PLATFORM(exynos5, "samsung,exynos5", &exynos5_platform);
    281  1.8.2.3  pgoyette #endif
    282