aboutsummaryrefslogtreecommitdiff
path: root/board/st-ericsson/u5500/u5500.c
blob: 451cbac732d51b6c6f0ad2147876b72a925f41d9 (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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
/*
 * Copyright (C) ST-Ericsson SA 2010
 *
 * Author: Michael Brandt <michael.brandt@stericsson.com> for ST-Ericsson
 * License terms: GNU General Public License (GPL), version 2.
 */

#include <config.h>
#include <common.h>
#include <asm/io.h>
#include <asm/errno.h>
#include <asm/arch/hardware.h>
#include <mmc.h>
#include <asm/arch/clock.h>
#include <asm/arch/cpu.h>
#include <asm/arch/common.h>
#include <asm/arch/prcmu.h>
#include <part.h>
#include <asm/arch/itp.h>
#include <asm/arch/mloader.h>
#include <asm/arch/prcmu-db5500.h>

#include "db5500_pins.h"
#include "db8500_pincfg.h"

#include <u8500_mmc_host.h>
#include <u5500_keypad.h>
/* offset for GPIO ALTB register */
#define DB5500_GPIO_AFSLB	0x24
/* BOOT ROM backup bit value to peripheral boot */
#define PERIPHERAL_BOOT_MODE (1 << 29)

#define BACKUPRAM_ROM_DEBUG_ADDR 0xFFC
#define MMC_BLOCK_ID	0x20

/*
 * GPIO pin config
 */

static pin_cfg_t gpio_config[] = {

	/* I2C */
	GPIO3_I2C1_SCL		| PIN_INPUT_PULLUP,
	GPIO4_I2C1_SDA		| PIN_INPUT_PULLUP,
	GPIO218_I2C2_SCL	| PIN_INPUT_PULLUP,
	GPIO219_I2C2_SDA	| PIN_INPUT_PULLUP,

	/* MMC2 (POP eMMC) */
	GPIO5_MC0_DAT0		| PIN_INPUT_PULLUP,
	GPIO6_MC0_DAT1		| PIN_INPUT_PULLUP,
	GPIO7_MC0_DAT2		| PIN_INPUT_PULLUP,
	GPIO8_MC0_DAT3		| PIN_INPUT_PULLUP,
	GPIO9_MC0_DAT4		| PIN_INPUT_PULLUP,
	GPIO10_MC0_DAT5		| PIN_INPUT_PULLUP,
	GPIO11_MC0_DAT6		| PIN_INPUT_PULLUP,
	GPIO12_MC0_DAT7		| PIN_INPUT_PULLUP,
	GPIO13_MC0_CMD		| PIN_INPUT_PULLUP,
	GPIO14_MC0_CLK		| PIN_OUTPUT_LOW,

	GPIO16_MC2_CMD		| PIN_INPUT_PULLUP,
	GPIO17_MC2_CLK		| PIN_OUTPUT_LOW,
	GPIO23_MC2_DAT0		| PIN_INPUT_PULLUP,
	GPIO19_MC2_DAT1		| PIN_INPUT_PULLUP,
	GPIO24_MC2_DAT2		| PIN_INPUT_PULLUP,
	GPIO20_MC2_DAT3		| PIN_INPUT_PULLUP,
	GPIO25_MC2_DAT4		| PIN_INPUT_PULLUP,
	GPIO21_MC2_DAT5		| PIN_INPUT_PULLUP,
	GPIO26_MC2_DAT6		| PIN_INPUT_PULLUP,
	GPIO22_MC2_DAT7		| PIN_INPUT_PULLUP,

	/* Keypad GPIO */
	GPIO128_KP_I0		| PIN_INPUT_PULLUP,
	GPIO129_KP_O0		| PIN_OUTPUT_HIGH,
	GPIO130_KP_I1		| PIN_INPUT_PULLUP,
	GPIO131_KP_O1		| PIN_OUTPUT_HIGH,
	GPIO132_KP_I2		| PIN_INPUT_PULLUP,
	GPIO133_KP_O2		| PIN_OUTPUT_HIGH,
	GPIO134_KP_I3		| PIN_INPUT_PULLUP,
	GPIO135_KP_O3		| PIN_OUTPUT_HIGH,
	GPIO136_KP_I4		| PIN_INPUT_PULLUP,
	GPIO137_KP_O4		| PIN_OUTPUT_HIGH,
	GPIO138_KP_I5		| PIN_INPUT_PULLUP,
	GPIO139_KP_O5		| PIN_OUTPUT_HIGH,
	GPIO140_KP_I6		| PIN_INPUT_PULLUP,
	GPIO141_KP_O6		| PIN_OUTPUT_HIGH,
	GPIO142_KP_I7		| PIN_INPUT_PULLUP,
	GPIO143_KP_O7		| PIN_OUTPUT_HIGH,
};

static pin_cfg_t sdcard_gpio_config[] = {

	/* SDI1 (SD-CARD) */
	GPIO191_MC1_DAT0        | PIN_INPUT_PULLUP,
	GPIO192_MC1_DAT1        | PIN_INPUT_PULLUP,
	GPIO193_MC1_DAT2        | PIN_INPUT_PULLUP,
	GPIO194_MC1_DAT3        | PIN_INPUT_PULLUP,
	GPIO195_MC1_CLK         | PIN_OUTPUT_LOW,
	GPIO196_MC1_CMD         | PIN_INPUT_PULLUP,
	GPIO197_MC1_CMDDIR      | PIN_OUTPUT_HIGH,
	GPIO198_MC1_FBCLK       | PIN_INPUT_NOPULL,
	GPIO199_MC1_DAT0DIR     | PIN_OUTPUT_HIGH,

	/* SD_CARD detect */
	GPIO180_GPIO		| PIN_INPUT_PULLUP,
	GPIO227_GPIO		| PIN_OUTPUT_HIGH,
	GPIO185_GPIO		| PIN_OUTPUT_LOW
};

int errno;

/*
 * Flag to indicate from where to where we have to copy the initialised data.
 * In case we were loaded, its value is -1 and .data must be saved for an
 * eventual restart. It is 1 if .data was restored, i.e. we were restarted,
 * e.g. by kexec.
 */
static volatile int data_init_flag = -1; /* -1 to get it into .data section */

DECLARE_GLOBAL_DATA_PTR;
#if defined(CONFIG_SHOW_BOOT_PROGRESS)
void show_boot_progress(int progress)
{
    printf("Boot reached stage %d\n", progress);
}
#endif

/*
 * Miscellaneous platform dependent initialisations
 */

int board_early_access(block_dev_desc_t *block_dev)
{
	/*
	 * Don't load itp and modem if restarted (eg crashdump).
	 */
	if (!(data_init_flag > 0)) {
#ifdef CONFIG_ITP_LOAD
		itp_read_config(block_dev);
		if (itp_is_modem_in_config())
			if (mloader_load_modem(block_dev))
				return 1;

		if (itp_is_itp_in_config())
			if (itp_load_itp(block_dev))
				return 1;
#endif
	}
	return 0;
}

int board_init(void)
{
	extern char _idata_start[];
	extern char _data_start[];
	extern char _data_end[];
	unsigned long data_len;
	u32 gpio_value;

	data_len = _data_end - _data_start;
	if (++data_init_flag == 0) {
		/*
		 * first init after reset/loading
		 * save .data section for restart
		 */
		memcpy(_idata_start, _data_start, data_len);
	} else {
		/*
		 * restart, e.g. by kexec
		 * copy back .data section
		 */
		memcpy(_data_start, _idata_start, data_len);
		/* memcpy set data_init_flag back to zero */
		++data_init_flag;
	}

	gd->bd->bi_arch_number = 2890;	/* MACH_TYPE_U5500 */
	gd->bd->bi_boot_params = 0x00000100;

	u5500_clock_enable(1, 1, 1); /* SDI0 */
	u5500_clock_enable(5, 4, 4); /* SDI1 */

	/* Disable the altB functionality for GPIO64,65 */
	if (cpu_is_u5500v2()) {
		gpio_value = readl(U5500_GPIOBANK2_BASE + DB5500_GPIO_AFSLB);
		writel((gpio_value & ~(MASK_BIT0 | MASK_BIT1)),
				(U5500_GPIOBANK2_BASE + DB5500_GPIO_AFSLB));
	}

	 /* Configure GPIO settings */
	db8500_gpio_config_pins(gpio_config,
					ARRAY_SIZE(gpio_config));

	prcmu_init();

	return 0;
}

int dram_init(void)
{

	gd->bd->bi_dram[0].start = 0;
	gd->bd->bi_dram[0].size = 0x20000000;	/* 512 MiB */

	return 0;
}


int restarted(void)
{
	return data_init_flag > 0;
}


/*
 * board_mmc_init - initialize all the mmc/sd host controllers.
 * Called by generic mmc framework.
 */
int board_mmc_init(bd_t *bis)
{
	int error;
	struct mmc *dev;
	int mmc_blk_id = 0;

	debugX(DBG_LVL_VERBOSE, "mmc_host - board_mmc_init\n");

	(void) bis;  /* Parameter not used! */

	/*
		Fix me in 5500 v2.1
		Dynamic detection of booting device by reading
		ROM debug register from BACKUP RAM and register the
		corresponding EMMC.
		This is done due to wrong configuration of MMC0 clock
		in ROM code for u5500 v2.
	*/
	if (cpu_is_u5500v2())
		mmc_blk_id = readl(U5500_BACKUPRAM1_BASE +
					BACKUPRAM_ROM_DEBUG_ADDR);

	dev = u8500_alloc_mmc_struct();
	if (!dev)
		return -1;

	if (mmc_blk_id & MMC_BLOCK_ID) {
		error = u8500_emmc_host_init(dev,
			(struct sdi_registers *)U5500_SDI2_BASE);
		if (error) {
			printf("emmc2 %d\n", error);
			return -1;
		}
	} else {
		error = u8500_emmc_host_init(dev,
			(struct sdi_registers *)U5500_SDI0_BASE);
		if (error) {
			printf("emmc_host_init() %d\n", error);
			return -1;
		}
	}
	mmc_register(dev);
	debugX(DBG_LVL_VERBOSE, "registered emmc interface number is:%d\n",
		dev->block_dev.dev);
	mmc_init(dev);

	/*
	 * In a perfect world board_early_access shouldn't be here but we want
	 * some functionality to be loaded as quickly as possible and putting it
	 * here will get the shortest time to start that functionality. Time
	 * saved by putting it here compared to later is somewhere between
	 * 0.3-0.7s. That is enough to be able to justify putting it here.
	 */

	/*
	 * Since we are interrupting the 'generic' MMC device printouts,
	 * we reformat a bit due to the early access code
	 */

	printf("\n");
	board_early_access(&dev->block_dev);
	printf("  ");

	dev = u8500_alloc_mmc_struct();
	if (!dev)
		return -1;

	error = u8500_mmc_host_init(dev,
			(struct sdi_registers *)U5500_SDI1_BASE);
	if (error) {
		printf("mmc_host_init() %d \n", error);
		return -1;
	}

	mmc_register(dev);
	debugX(DBG_LVL_VERBOSE, "registered mmc/sd interface number is:%d\n",
	      dev->block_dev.dev);

	return 0;
}

#ifdef BOARD_LATE_INIT

/*
 * called after all initialisation were done, but before the generic
 * mmc_initialize().
 */
int board_late_init(void)
{
	char strbuf[80];
	u8 byte;

	/*
	 * Create a memargs variable which points uses either the memargs256 or
	 * memargs512 environment variable, depending on the memory size.
	 * memargs is used to build the bootargs, memargs256 and memargs512 are
	 * stored in the environment.
	 */
	if (gd->bd->bi_dram[0].size == 0x10000000) {
		setenv("memargs", "setenv bootargs ${bootargs} ${memargs256}");
		setenv("mem", "256M");
	} else {
		setenv("memargs", "setenv bootargs ${bootargs} ${memargs512}");
		setenv("mem", "512M");
	}

	/* LDO G for SD card (2.91V) */
	byte = 0x3f;
	(void) prcmu_abb_write(0x3, 0x78, &byte, (u8)sizeof(byte));

	/*
	 * Set MMC_CARD_VSEL (GPIO185) to '0', since we use 2.9V for
	 * interfacing the SD-card (set '1' if it is 1.8V).
	 * Set MMC_CARD_CTRL (GPIO227) to '1' to enable the levelshifter
	 * outputs.
	 */
	db8500_gpio_make_output(GPIO187_GPIO, 0);
	db8500_gpio_make_output(GPIO227_GPIO, 1);

	/*
	 * Create crashkernel env dynamically since it depends on U-Boot start
	 * address. U-Boot itself is used for dumping.
	 * The 32K offset is hardcoded in the kexec-tools.
	 * Parsed by Linux setup.c:reserve_crashkernel() using
	 * lib/cmdline.c:memparse().
	 * crashkernel=ramsize-range:size[,...][@offset]
	 */
	sprintf(strbuf, "crashkernel=1M@0x%lx", _armboot_start - 0x8000);
	setenv("crashkernel", strbuf);

	/*
	 * Check for a crashdump, if data_init_flag > 0, i.e. we were
	 * restarted e.g. by kexec. Do not check for crashdump if we were just
	 * loaded from the x-loader.
	 */
	if (data_init_flag > 0)
		setenv("preboot", "checkcrash");

#ifdef CONFIG_MMC

	/* Configure SD Card GPIO settings */
	db8500_gpio_config_pins(sdcard_gpio_config,
					ARRAY_SIZE(sdcard_gpio_config));

#endif
	/* init keypad */
	init_keypad();
	return 0;
}
#endif /* BOARD_LATE_INIT */
/* sets the peripheral boot mode */
void set_to_peripheral_boot_mode(void)
{
	writel(PERIPHERAL_BOOT_MODE,
		U5500_BACKUPRAM1_BASE + BACKUPRAM_ROM_DEBUG_ADDR);
}