Home | History | Annotate | Line # | Download | only in samsung
exynos_soc.c revision 1.6
      1 /*	$NetBSD: exynos_soc.c,v 1.6 2014/04/22 16:10:48 reinoud Exp $	*/
      2 /*-
      3  * Copyright (c) 2014 The NetBSD Foundation, Inc.
      4  * All rights reserved.
      5  *
      6  * This code is derived from software contributed to The NetBSD Foundation
      7  * by Reinoud Zandijk.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     20  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     21  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28  * POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #include "opt_exynos.h"
     32 
     33 #define	_ARM32_BUS_DMA_PRIVATE
     34 
     35 #include <sys/cdefs.h>
     36 __KERNEL_RCSID(1, "$NetBSD: exynos_soc.c,v 1.6 2014/04/22 16:10:48 reinoud Exp $");
     37 
     38 #include <sys/param.h>
     39 #include <sys/bus.h>
     40 #include <sys/cpu.h>
     41 #include <sys/device.h>
     42 
     43 #include <prop/proplib.h>
     44 
     45 #include <net/if.h>
     46 #include <net/if_ether.h>
     47 
     48 #include <arm/locore.h>
     49 
     50 #include <arm/mainbus/mainbus.h>
     51 #include <arm/cortex/mpcore_var.h>
     52 
     53 #include <arm/samsung/exynos_reg.h>
     54 #include <arm/samsung/exynos_var.h>
     55 #include <arm/samsung/smc.h>
     56 
     57 #include <arm/cortex/pl310_var.h>
     58 #include <arm/cortex/pl310_reg.h>
     59 
     60 /* XXXNH */
     61 #include <evbarm/odroid/platform.h>
     62 
     63 bus_space_handle_t exynos_core_bsh;
     64 
     65 /* these variables are retrieved in start.S and stored in .data */
     66 uint32_t  exynos_soc_id = 0;
     67 uint32_t  exynos_pop_id = 0;
     68 
     69 
     70 /*
     71  * the early serial console
     72  */
     73 #ifdef EXYNOS_CONSOLE_EARLY
     74 
     75 #include "opt_sscom.h"
     76 #include <arm/samsung/sscom_reg.h>
     77 #include <arm/samsung/sscom_var.h>
     78 #include <dev/cons.h>
     79 
     80 static volatile uint8_t *uart_base;
     81 
     82 #define CON_REG(a) (*((volatile uint32_t *)(uart_base + (a))))
     83 
     84 static int
     85 exynos_cngetc(dev_t dv)
     86 {
     87         if ((CON_REG(SSCOM_UTRSTAT) & UTRSTAT_RXREADY) == 0)
     88 		return -1;
     89 
     90 	return CON_REG(SSCOM_URXH);
     91 }
     92 
     93 static void
     94 exynos_cnputc(dev_t dv, int c)
     95 {
     96 	int timo = 150000;
     97 
     98 	while ((CON_REG(SSCOM_UFSTAT) & UFSTAT_TXFULL) && --timo > 0);
     99 
    100 	CON_REG(SSCOM_UTXH) = c & 0xff;
    101 }
    102 
    103 static struct consdev exynos_earlycons = {
    104 	.cn_putc = exynos_cnputc,
    105 	.cn_getc = exynos_cngetc,
    106 	.cn_pollc = nullcnpollc,
    107 };
    108 #endif /* EXYNOS_CONSOLE_EARLY */
    109 
    110 
    111 #ifdef ARM_TRUSTZONE_FIRMWARE
    112 int
    113 exynos_do_idle(void)
    114 {
    115         exynos_smc(SMC_CMD_SLEEP, 0, 0, 0);
    116 
    117 	return 0;
    118 }
    119 
    120 
    121 int
    122 exynos_set_cpu_boot_addr(int cpu, vaddr_t boot_addr)
    123 {
    124 	/* XXX we need to map in iRAM space for this XXX */
    125 	return 0;
    126 }
    127 
    128 
    129 int
    130 exynos_cpu_boot(int cpu)
    131 {
    132 	exynos_smc(SMC_CMD_CPU1BOOT, cpu, 0, 0);
    133 
    134 	return 0;
    135 }
    136 
    137 
    138 /*
    139  * The latency values used below are `magic' and probably chosen empiricaly.
    140  * For the 4210 variant the data latency is lower, a 0x110. This is currently
    141  * not enforced.
    142  *
    143  * The prefetch values are also different for the revision 0 of the
    144  * Exynos4412, but why?
    145  */
    146 
    147 int
    148 exynos_l2cc_init(void)
    149 {
    150 	const uint32_t tag_latency  = 0x110;
    151 	const uint32_t data_latency = IS_EXYNOS4410_P() ? 0x110 : 0x120;
    152 	const uint32_t prefetch4412   = /* 0111 0001 0000 0000 0000 0000 0000 0111 */
    153 				PREFETCHCTL_DBLLINEF_EN  |
    154 				PREFETCHCTL_INSTRPREF_EN |
    155 				PREFETCHCTL_DATAPREF_EN  |
    156 				PREFETCHCTL_PREF_DROP_EN |
    157 				PREFETCHCTL_PREFETCH_OFFSET_7;
    158 	const uint32_t prefetch4412_r0 = /* 0011 0000 0000 0000 0000 0000 0000 0111 */
    159 				PREFETCHCTL_INSTRPREF_EN |
    160 				PREFETCHCTL_DATAPREF_EN  |
    161 				PREFETCHCTL_PREFETCH_OFFSET_7;
    162 	const uint32_t aux_val      =    /* 0111 1100 0100 0111 0000 0000 0000 0001 */
    163 				AUXCTL_EARLY_BRESP_EN |
    164 				AUXCTL_I_PREFETCH     |
    165 				AUXCTL_D_PREFETCH     |
    166 				AUXCTL_NS_INT_ACC_CTL |
    167 				AUXCTL_NS_INT_LOCK_EN |
    168 				AUXCTL_SHARED_ATT_OVR |
    169 				AUXCTL_WAY_SIZE_RSVD7 << 16 | /* why rsvd7 ??? */
    170 				AUXCTL_FULL_LINE_WR0;
    171 	const uint32_t aux_keepmask =    /* 1100 0010 0000 0000 1111 1111 1111 1111  */
    172 				AUXCTL_RSVD31         |
    173 				AUXCTL_EARLY_BRESP_EN |
    174 				AUXCTL_CACHE_REPL_RR  |
    175 
    176 				AUXCTL_SH_ATTR_INV_ENA|
    177 				AUXCTL_EXCL_CACHE_CFG |
    178 				AUXCTL_ST_BUF_DEV_LIM_EN |
    179 				AUXCTL_HIPRO_SO_DEV_EN |
    180 				AUXCTL_FULL_LINE_WR0  |
    181 				0xffff;
    182 	uint32_t prefetch;
    183 
    184 	/* check the bitmaps are the same as the linux implementation uses */
    185 	KASSERT(prefetch4412    == 0x71000007);
    186 	KASSERT(prefetch4412_r0 == 0x30000007);
    187 	KASSERT(aux_val         == 0x7C470001);
    188 	KASSERT(aux_keepmask    == 0xC200FFFF);
    189 
    190 	if (IS_EXYNOS4412_R0_P())
    191 		prefetch = prefetch4412_r0;
    192 	else
    193 		prefetch = prefetch4412;	/* newer than >= r1_0 */
    194 	;
    195 
    196 	exynos_smc(SMC_CMD_L2X0SETUP1, tag_latency, data_latency, prefetch);
    197 	exynos_smc(SMC_CMD_L2X0SETUP2,
    198 		POWERCTL_DYNCLKGATE | POWERCTL_STANDBY,
    199 		aux_val, aux_keepmask);
    200 	exynos_smc(SMC_CMD_L2X0INVALL, 0, 0, 0);
    201 	exynos_smc(SMC_CMD_L2X0CTRL, 1, 0, 0);
    202 
    203 	return 0;
    204 }
    205 #endif /* ARM_TRUSTZONE_FIRMWARE */
    206 
    207 
    208 #ifndef EXYNOS4
    209 #	define EXYNOS4_CORE_SIZE 0
    210 #endif
    211 #ifndef EXYNOS5
    212 #	define EXYNOS5_CORE_SIZE 0
    213 #endif
    214 void
    215 exynos_bootstrap(vaddr_t iobase, vaddr_t uartbase)
    216 {
    217 	int error;
    218 	size_t core_size = IS_EXYNOS4_P() ?
    219 		EXYNOS4_CORE_SIZE : EXYNOS5_CORE_SIZE;
    220 
    221 	/* set up early console so we can use printf() and friends */
    222 #ifdef EXYNOS_CONSOLE_EARLY
    223 	uart_base = (volatile uint8_t *) uartbase;
    224 	cn_tab = &exynos_earlycons;
    225 	printf("Exynos early console operational\n\n");
    226 #endif
    227 	/* map in the exynos io registers */
    228 	error = bus_space_map(&exynos_bs_tag, EXYNOS_CORE_PBASE,
    229 		core_size, 0, &exynos_core_bsh);
    230 	if (error)
    231 		panic("%s: failed to map in Exynos io registers: %d",
    232 			__func__, error);
    233 	KASSERT(exynos_core_bsh == iobase);
    234 }
    235 
    236 
    237 void
    238 exynos_device_register(device_t self, void *aux)
    239 {
    240 	if (device_is_a(self, "armperiph")
    241 	    && device_is_a(device_parent(self), "mainbus")) {
    242 		/*
    243 		 * XXX KLUDGE ALERT XXX
    244 		 * The iot mainbus supplies is completely wrong since it scales
    245 		 * addresses by 2.  The simpliest remedy is to replace with our
    246 		 * bus space used for the armcore regisers (which armperiph uses).
    247 		 */
    248 		struct mainbus_attach_args * const mb = aux;
    249 		mb->mb_iot = &exynos_bs_tag;
    250 		return;
    251 	}
    252 	if (device_is_a(self, "armgic")
    253 	    && device_is_a(device_parent(self), "armperiph")) {
    254 		/*
    255 		 * The Exynos4420 armgic is located at a different location!
    256 		 */
    257 
    258 		struct mpcore_attach_args * const mpcaa = aux;
    259 		extern uint32_t exynos_soc_id;
    260 
    261 		switch (EXYNOS_PRODUCT_ID(exynos_soc_id)) {
    262 #if defined(EXYNOS5)
    263 		case 0xe5410:
    264 			/* offsets not changed on matt's request */
    265 #if 0
    266 			mpcaa->mpcaa_memh = EXYNOS_CORE_VBASE;
    267 			mpcaa->mpcaa_off1 = EXYNOS5_GIC_IOP_DISTRIBUTOR_OFFSET;
    268 			mpcaa->mpcaa_off2 = EXYNOS5_GIC_IOP_CONTROLLER_OFFSET;
    269 #endif
    270 			break;
    271 #endif
    272 #if defined(EXYNOS4)
    273 		case 0xe4410:
    274 		case 0xe4412:
    275 			mpcaa->mpcaa_memh = EXYNOS_CORE_VBASE;
    276 			mpcaa->mpcaa_off1 = EXYNOS4_GIC_DISTRIBUTOR_OFFSET;
    277 			mpcaa->mpcaa_off2 = EXYNOS4_GIC_CNTR_OFFSET;
    278 			break;
    279 #endif
    280 		default:
    281 			panic("%s: unknown SoC product id %#x", __func__,
    282 			    (u_int)EXYNOS_PRODUCT_ID(exynos_soc_id));
    283 		}
    284 		return;
    285 	}
    286 #if defined(CPU_CORTEXA7) || defined(CPU_CORTEXA15)
    287 	if (device_is_a(self, "armgtmr")) {
    288 		/*
    289 		 * The frequency of the generic timer is the reference
    290 		 * frequency.
    291 		 */
    292 		prop_dictionary_set_uint32(device_properties(self),
    293 		    "frequency", 24000000);
    294 		return;
    295 	}
    296 #endif
    297 
    298 	exyo_device_register(self, aux);
    299 }
    300 
    301