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