blob: fc300a4210bdde3ec98ecb49888f4c770d13f5b0 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Wenyou Yanga3b84f42017-09-01 16:26:16 +08002/*
3 * Copyright (C) 2017 Microchip
4 * Wenyou Yang <wenyou.yang@microchip.com>
Wenyou Yanga3b84f42017-09-01 16:26:16 +08005 */
6
7#include <common.h>
Eugen Hristev7d1787f2018-09-18 10:35:42 +03008#include <w1.h>
9#include <w1-eeprom.h>
10#include <dm/device-internal.h>
11
12#define AT91_PDA_EEPROM_ID_OFFSET 15
13#define AT91_PDA_EEPROM_ID_LENGTH 5
14#define AT91_PDA_EEPROM_DEFAULT_BUS 0
Wenyou Yanga3b84f42017-09-01 16:26:16 +080015
Eugen Hristev3232f9b2018-10-08 09:54:27 +030016char *get_cpu_name(void);
17
Wenyou Yanga3b84f42017-09-01 16:26:16 +080018void dummy(void)
19{
20}
Eugen Hristev7d1787f2018-09-18 10:35:42 +030021
22#if defined CONFIG_W1
23void at91_pda_detect(void)
24{
25 struct udevice *bus, *dev;
26 u8 buf[AT91_PDA_EEPROM_ID_LENGTH + 1] = {0};
27 int ret;
28 int pda = 0;
29
30 ret = w1_get_bus(AT91_PDA_EEPROM_DEFAULT_BUS, &bus);
31 if (ret)
32 return;
33
34 for (device_find_first_child(bus, &dev);
35 dev;
36 device_find_next_child(&dev)) {
37 ret = device_probe(dev);
38 if (ret) {
39 continue;
40 } else {
41 ret = w1_eeprom_read_buf(dev, AT91_PDA_EEPROM_ID_OFFSET,
42 (u8 *)buf, AT91_PDA_EEPROM_ID_LENGTH);
43 if (ret)
44 return;
45 break;
46 }
47 }
48 pda = simple_strtoul((const char *)buf, NULL, 10);
49
50 switch (pda) {
51 case 7000:
52 if (buf[4] == 'B')
53 printf("PDA TM7000B detected\n");
54 else
55 printf("PDA TM7000 detected\n");
56 break;
57 case 4300:
58 printf("PDA TM4300 detected\n");
59 break;
60 case 5000:
61 printf("PDA TM5000 detected\n");
62 break;
63 }
64 env_set("pda", (const char *)buf);
65}
66#else
67void at91_pda_detect(void)
68{
69}
70#endif
Eugen Hristev3232f9b2018-10-08 09:54:27 +030071
72void at91_prepare_cpu_var(void)
73{
74 env_set("cpu", get_cpu_name());
75}