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