blob: 20c3b8c086d73c79697b0621f4b2abf5fb426c67 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Wenyou Yangd9b23e22017-09-01 16:26:16 +08002/*
3 * Copyright (C) 2017 Microchip
4 * Wenyou Yang <wenyou.yang@microchip.com>
Wenyou Yangd9b23e22017-09-01 16:26:16 +08005 */
6
7#include <common.h>
Eugen Hristevafaea1f2018-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 Yangd9b23e22017-09-01 16:26:16 +080015
Eugen Hristev61b4dbb2018-10-08 09:54:27 +030016char *get_cpu_name(void);
17
Wenyou Yangd9b23e22017-09-01 16:26:16 +080018void dummy(void)
19{
20}
Eugen Hristevafaea1f2018-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)
Eugen Hristevad371d82019-06-12 13:16:18 +030032 goto pda_detect_err;
Eugen Hristevafaea1f2018-09-18 10:35:42 +030033
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)
Eugen Hristevad371d82019-06-12 13:16:18 +030044 goto pda_detect_err;
Eugen Hristevafaea1f2018-09-18 10:35:42 +030045 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 }
Eugen Hristevad371d82019-06-12 13:16:18 +030064
65pda_detect_err:
Eugen Hristevafaea1f2018-09-18 10:35:42 +030066 env_set("pda", (const char *)buf);
67}
68#else
69void at91_pda_detect(void)
70{
71}
72#endif
Eugen Hristev61b4dbb2018-10-08 09:54:27 +030073
74void at91_prepare_cpu_var(void)
75{
76 env_set("cpu", get_cpu_name());
77}