blob: 8f9b5e137c413b98711a6d25844d76b18bbbc572 [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
16void dummy(void)
17{
18}
Eugen Hristevafaea1f2018-09-18 10:35:42 +030019
20#if defined CONFIG_W1
21void at91_pda_detect(void)
22{
23 struct udevice *bus, *dev;
24 u8 buf[AT91_PDA_EEPROM_ID_LENGTH + 1] = {0};
25 int ret;
26 int pda = 0;
27
28 ret = w1_get_bus(AT91_PDA_EEPROM_DEFAULT_BUS, &bus);
29 if (ret)
30 return;
31
32 for (device_find_first_child(bus, &dev);
33 dev;
34 device_find_next_child(&dev)) {
35 ret = device_probe(dev);
36 if (ret) {
37 continue;
38 } else {
39 ret = w1_eeprom_read_buf(dev, AT91_PDA_EEPROM_ID_OFFSET,
40 (u8 *)buf, AT91_PDA_EEPROM_ID_LENGTH);
41 if (ret)
42 return;
43 break;
44 }
45 }
46 pda = simple_strtoul((const char *)buf, NULL, 10);
47
48 switch (pda) {
49 case 7000:
50 if (buf[4] == 'B')
51 printf("PDA TM7000B detected\n");
52 else
53 printf("PDA TM7000 detected\n");
54 break;
55 case 4300:
56 printf("PDA TM4300 detected\n");
57 break;
58 case 5000:
59 printf("PDA TM5000 detected\n");
60 break;
61 }
62 env_set("pda", (const char *)buf);
63}
64#else
65void at91_pda_detect(void)
66{
67}
68#endif