summaryrefslogtreecommitdiff
path: root/board/atmel/common/board.c
blob: c41706c4005c011094220c843b98f1a759a60146 (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
// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (C) 2017 Microchip
 *		      Wenyou Yang <wenyou.yang@microchip.com>
 */

#include <common.h>
#include <env.h>
#include <w1.h>
#include <w1-eeprom.h>
#include <dm/device-internal.h>

#define AT91_PDA_EEPROM_ID_OFFSET		15
#define AT91_PDA_EEPROM_ID_LENGTH		5
#define AT91_PDA_EEPROM_DEFAULT_BUS		0

char *get_cpu_name(void);

void dummy(void)
{
}

#if defined CONFIG_W1
void at91_pda_detect(void)
{
	struct udevice *bus, *dev;
	u8 buf[AT91_PDA_EEPROM_ID_LENGTH + 1] = {0};
	int ret;
	int pda = 0;

	ret = w1_get_bus(AT91_PDA_EEPROM_DEFAULT_BUS, &bus);
	if (ret)
		goto pda_detect_err;

	for (device_find_first_child(bus, &dev);
	     dev;
	     device_find_next_child(&dev)) {
		ret = device_probe(dev);
		if (ret) {
			continue;
		} else {
			ret = w1_eeprom_read_buf(dev, AT91_PDA_EEPROM_ID_OFFSET,
						 (u8 *)buf, AT91_PDA_EEPROM_ID_LENGTH);
			if (ret)
				goto pda_detect_err;
			break;
		}
	}
	pda = simple_strtoul((const char *)buf, NULL, 10);

	switch (pda) {
	case 7000:
		if (buf[4] == 'B')
			printf("PDA TM7000B detected\n");
		else
			printf("PDA TM7000 detected\n");
		break;
	case 4300:
		printf("PDA TM4300 detected\n");
		break;
	case 5000:
		printf("PDA TM5000 detected\n");
		break;
	}

pda_detect_err:
	env_set("pda", (const char *)buf);
}
#else
void at91_pda_detect(void)
{
}
#endif

void at91_prepare_cpu_var(void)
{
	env_set("cpu", get_cpu_name());
}