summaryrefslogtreecommitdiffstats
path: root/arch/arm/boards/phytec-phycore-omap4460/lowlevel.c
blob: 8c25eab7ce59648208a0248af66181b819f7c1f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
 * (C) Copyright 2004-2009
 * Texas Instruments, <www.ti.com>
 * Richard Woodruff <r-woodruff2@ti.com>
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */
#include <common.h>
#include <init.h>
#include <io.h>
#include <linux/sizes.h>
#include <mach/generic.h>
#include <mach/omap4-mux.h>
#include <mach/omap4-silicon.h>
#include <mach/omap4-generic.h>
#include <mach/omap4-clock.h>
#include <mach/syslib.h>
#include <asm/barebox-arm.h>
#include <asm/barebox-arm-head.h>

#include "mux.h"

#define TPS62361_VSEL0_GPIO    182
#define LPDDR2_2G              0x5
#define LPDDR2_4G              0x6
#define LPDDR2_DENSITY_MASK		0x3C
#define LPDDR2_DENSITY_SHIFT		2
#define EMIF_SDRAM_CONFIG		0x0008
#define EMIF_LPDDR2_MODE_REG_CONFIG	0x0050
#define EMIF_LPDDR2_MODE_REG_DATA	0x0040

/* 512MB */
static const struct ddr_regs ddr_regs_mt42L64M64_25_400_mhz = {
	.tim1		= 0x0EEB0662,
	.tim2		= 0x20370DD2,
	.tim3		= 0x00BFC33F,
	.phy_ctrl_1	= 0x849FF408,
	.ref_ctrl	= 0x00000618,
	.config_init	= 0x80001AB1,
	.config_final	= 0x80001AB1,
	.zq_config	= 0xd0093215,
	.mr1		= 0x83,
	.mr2		= 0x4
};

/* 1GB */
static const struct ddr_regs ddr_regs_mt42L128M64_25_400_mhz = {
	.tim1		= 0x0EEB0663,
	.tim2		= 0x205715D2,
	.tim3		= 0x00BFC53F,
	.phy_ctrl_1	= 0x849FF408,
	.ref_ctrl	= 0x00000618,
	.config_init	= 0x80001AB9,
	.config_final	= 0x80001AB9,
	.zq_config	= 0x50093215,
	.mr1		= 0x83,
	.mr2		= 0x4
};

static const struct ddr_regs ddr_regs_mt42L128M64D2LL_25_400_mhz = {
	.tim1           = 0x10EB0662,
	.tim2           = 0x205715D2,
	.tim3           = 0x00B1C53F,
	.phy_ctrl_1     = 0x849FF409,
	.ref_ctrl       = 0x00000618,
	.config_init    = 0x80001AB2,
	.config_final   = 0x80001AB2,
	.zq_config      = 0x500B3214,
	.mr1            = 0x83,
	.mr2            = 0x4
};

static void noinline pcm049_init_lowlevel(void)
{
	unsigned int density;

	struct dpll_param core = OMAP4_CORE_DPLL_PARAM_19M2_DDR400;
	struct dpll_param mpu44xx = OMAP4_MPU_DPLL_PARAM_19M2_MPU1000;
	struct dpll_param mpu4460 = OMAP4_MPU_DPLL_PARAM_19M2_MPU920;
	struct dpll_param iva = OMAP4_IVA_DPLL_PARAM_19M2;
	struct dpll_param per = OMAP4_PER_DPLL_PARAM_19M2;
	struct dpll_param abe = OMAP4_ABE_DPLL_PARAM_19M2;
	struct dpll_param usb = OMAP4_USB_DPLL_PARAM_19M2;
	unsigned int rev = omap4_revision();

	phycore_omap4460_set_muxconf_regs();

	if (IS_ENABLED(CONFIG_1024MB_DDR2RAM)) {
		omap4_ddr_init(&ddr_regs_mt42L64M64_25_400_mhz, &core);
		writel(EMIF_SDRAM_CONFIG, OMAP44XX_EMIF1_BASE +
		       EMIF_LPDDR2_MODE_REG_CONFIG);
		density = (readl(OMAP44XX_EMIF1_BASE + EMIF_LPDDR2_MODE_REG_DATA) &
			   LPDDR2_DENSITY_MASK) >> LPDDR2_DENSITY_SHIFT;
		if (density == LPDDR2_2G)
			omap4_ddr_init(&ddr_regs_mt42L128M64_25_400_mhz, &core);
		else if (density == LPDDR2_4G)
			omap4_ddr_init(&ddr_regs_mt42L128M64D2LL_25_400_mhz, &core);
	} else {
		omap4_ddr_init(&ddr_regs_mt42L64M64_25_400_mhz, &core);
	}

	/* Set VCORE1 = 1.3 V, VCORE2 = VCORE3 = 1.21V */
	if (rev < OMAP4460_ES1_0)
		omap4430_scale_vcores();
	else
		omap4460_scale_vcores(TPS62361_VSEL0_GPIO, 1320);

	writel(CM_SYS_CLKSEL_19M2, CM_SYS_CLKSEL);

	/* Configure all DPLL's at 100% OPP */
	if (rev < OMAP4460_ES1_0)
		omap4_configure_mpu_dpll(&mpu44xx);
	else
		omap4_configure_mpu_dpll(&mpu4460);

	omap4_configure_iva_dpll(&iva);
	omap4_configure_per_dpll(&per);
	omap4_configure_abe_dpll(&abe);
	omap4_configure_usb_dpll(&usb);

	/* Enable all clocks */
	omap4_enable_all_clocks();

	sr32(OMAP44XX_SCRM_AUXCLK3, 8, 1, 0x1);  /* enable software ioreq */
	sr32(OMAP44XX_SCRM_AUXCLK3, 1, 2, 0x0);  /* set for sys_clk (19.2MHz) */
	sr32(OMAP44XX_SCRM_AUXCLK3, 16, 4, 0x0); /* set divisor to 1 */
	sr32(OMAP44XX_SCRM_ALTCLKSRC, 0, 1, 0x1);  /* activate clock source */
	sr32(OMAP44XX_SCRM_ALTCLKSRC, 2, 2, 0x3);  /* enable clocks */
}

void __bare_init __naked barebox_arm_reset_vector(uint32_t r0, uint32_t r1, uint32_t r2)
{
	omap4_save_bootinfo((void *)r0);

	arm_cpu_lowlevel_init();

	if (get_pc() > 0x80000000)
		goto out;

	arm_setup_stack(0x4030d000);

	pcm049_init_lowlevel();
out:
	barebox_arm_entry(0x80000000, SZ_512M, NULL);
}