summaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-layerscape/boot.c
blob: 4d074205ccd14911e00ddbce8c9a48a720ffe69e (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
// SPDX-License-Identifier: GPL-2.0

#include <common.h>
#include <init.h>
#include <bootsource.h>
#include <linux/bitfield.h>
#include <mach/layerscape/layerscape.h>
#include <soc/fsl/immap_lsch2.h>
#include <soc/fsl/immap_lsch3.h>

enum bootsource ls1046a_bootsource_get(void)
{
	void __iomem *dcfg = IOMEM(LSCH2_DCFG_ADDR);
	uint32_t rcw_src;

	rcw_src = in_be32(dcfg) >> 23;

	if (rcw_src == 0x40)
		return BOOTSOURCE_MMC;
	if ((rcw_src & 0x1fe) == 0x44)
		return BOOTSOURCE_SPI_NOR;
	if ((rcw_src & 0x1f0) == 0x10)
		/* 8bit NOR Flash */
		return BOOTSOURCE_NOR;
	if ((rcw_src & 0x1f0) == 0x20)
		/* 16bit NOR Flash */
		return BOOTSOURCE_NOR;

	return BOOTSOURCE_UNKNOWN;
}

enum bootsource ls1021a_bootsource_get(void)
{
	return ls1046a_bootsource_get();
}

void ls1021a_bootsource_init(void)
{
	bootsource_set_raw(ls1021a_bootsource_get(), BOOTSOURCE_INSTANCE_UNKNOWN);
}

void ls1046a_bootsource_init(void)
{
	bootsource_set_raw(ls1046a_bootsource_get(), BOOTSOURCE_INSTANCE_UNKNOWN);
}

#define PORSR1_RCW_SRC	GENMASK(26, 23)

static enum bootsource ls1028a_bootsource_get(int *instance)
{
	void __iomem *porsr1 = IOMEM(LSCH3_DCFG_BASE);
	uint32_t rcw_src;

	rcw_src = FIELD_GET(PORSR1_RCW_SRC, readl(porsr1));

	printf("%s: 0x%08x\n", __func__, rcw_src);

	switch (rcw_src) {
	case 8:
		*instance = 0;
		return BOOTSOURCE_MMC;
	case 9:
		*instance = 1;
		return BOOTSOURCE_MMC;
	case 0xa:
		return BOOTSOURCE_I2C;
	case 0xd:
	case 0xc:
		return BOOTSOURCE_NAND;
	case 0xf:
		return BOOTSOURCE_SPI_NOR;
	}

	return BOOTSOURCE_UNKNOWN;
}

void ls1028a_bootsource_init(void)
{
	int instance = BOOTSOURCE_INSTANCE_UNKNOWN;
	enum bootsource source = ls1028a_bootsource_get(&instance);

	bootsource_set_raw(source, instance);
}