summaryrefslogtreecommitdiffstats
path: root/arch/arm/boards/vscom-baltos/board.c
blob: 1a4dc30936a4aed694412faf187c893c024f6d08 (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
/*
 * (C) Copyright 2008
 * Texas Instruments, <www.ti.com>
 * Raghavendra KH <r-khandenahally@ti.com>
 *
 * Copyright (C) 2012 Jan Luebbe <j.luebbe@pengutronix.de>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * 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.
 */

/**
 * @file
 * @brief OnRISC Baltos Specific Board Initialization routines
 */

#include <common.h>
#include <init.h>
#include <driver.h>
#include <envfs.h>
#include <environment.h>
#include <globalvar.h>
#include <linux/sizes.h>
#include <net.h>
#include <envfs.h>
#include <bootsource.h>
#include <asm/armlinux.h>
#include <generated/mach-types.h>
#include <mach/am33xx-generic.h>
#include <mach/am33xx-silicon.h>
#include <mach/sys_info.h>
#include <mach/syslib.h>
#include <mach/gpmc.h>
#include <linux/err.h>
#include <mach/bbu.h>
#include <libfile.h>
#include <gpio.h>

static struct omap_barebox_part baltos_barebox_part = {
	.nand_offset = SZ_512K,
	.nand_size = 0x1e0000,
};

#ifndef CONFIG_OMAP_BUILD_IFT
struct bsp_vs_hwparam {
	uint32_t Magic;
	uint32_t HwRev;
	uint32_t SerialNumber;
	char PrdDate[11];
	uint16_t SystemId;
	uint8_t MAC1[6];
	uint8_t MAC2[6];
	uint8_t MAC3[6];
} __attribute__ ((packed));

static int baltos_read_eeprom(void)
{
	struct bsp_vs_hwparam hw_param;
	size_t size;
	char *buf;
	int rc;
	unsigned char mac_addr[6];

	rc = read_file_2("/dev/eeprom0",
			 &size,
			 (void *)&buf,
			 sizeof(hw_param));
	if (rc && rc != -EFBIG)
		return rc;

	memcpy(&hw_param, buf, sizeof(hw_param));

	free(buf);

	if (hw_param.Magic == 0xDEADBEEF) {
		/* setup MAC1 */
		mac_addr[0] = hw_param.MAC1[0];
		mac_addr[1] = hw_param.MAC1[1];
		mac_addr[2] = hw_param.MAC1[2];
		mac_addr[3] = hw_param.MAC1[3];
		mac_addr[4] = hw_param.MAC1[4];
		mac_addr[5] = hw_param.MAC1[5];

		eth_register_ethaddr(0, mac_addr);

		/* setup MAC2 */
		mac_addr[0] = hw_param.MAC2[0];
		mac_addr[1] = hw_param.MAC2[1];
		mac_addr[2] = hw_param.MAC2[2];
		mac_addr[3] = hw_param.MAC2[3];
		mac_addr[4] = hw_param.MAC2[4];
		mac_addr[5] = hw_param.MAC2[5];

		eth_register_ethaddr(1, mac_addr);
	} else {
		printf("Baltos: incorrect magic number (0x%x) "
		       "in EEPROM\n",
		       hw_param.Magic);

		hw_param.SystemId = 0;
	}

	globalvar_add_simple_uint32_fixed("board.id", hw_param.SystemId, "%u");

	/* enable mPCIe slot */
	gpio_direction_output(100, 1);

	/* configure output signals of the external GPIO controller */
	if (hw_param.SystemId == 210 || hw_param.SystemId == 211) {
		gpio_direction_output(132, 0);
		gpio_direction_output(133, 0);
		gpio_direction_output(134, 0);
		gpio_direction_output(135, 0);
	}

	return 0;
}
environment_initcall(baltos_read_eeprom);
#endif

static int baltos_devices_init(void)
{
	if (!of_machine_is_compatible("vscom,onrisc"))
		return 0;

	globalvar_add_simple_string_fixed("board.variant", "baltos");

	if (bootsource_get() == BOOTSOURCE_MMC)
		omap_set_bootmmc_devname("mmc0");

	omap_set_barebox_part(&baltos_barebox_part);

	if (IS_ENABLED(CONFIG_SHELL_NONE))
		return am33xx_of_register_bootdevice();

	return 0;
}
coredevice_initcall(baltos_devices_init);