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