blob: c41706c4005c011094220c843b98f1a759a60146 [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>
Simon Glass5e6201b2019-08-01 09:46:51 -06008#include <env.h>
Eugen Hristev7d1787f2018-09-18 10:35:42 +03009#include <w1.h>
10#include <w1-eeprom.h>
11#include <dm/device-internal.h>
12
13#define AT91_PDA_EEPROM_ID_OFFSET 15
14#define AT91_PDA_EEPROM_ID_LENGTH 5
15#define AT91_PDA_EEPROM_DEFAULT_BUS 0
Wenyou Yanga3b84f42017-09-01 16:26:16 +080016
Eugen Hristev3232f9b2018-10-08 09:54:27 +030017char *get_cpu_name(void);
18
Wenyou Yanga3b84f42017-09-01 16:26:16 +080019void dummy(void)
20{
21}
Eugen Hristev7d1787f2018-09-18 10:35:42 +030022
23#if defined CONFIG_W1
24void at91_pda_detect(void)
25{
26 struct udevice *bus, *dev;
27 u8 buf[AT91_PDA_EEPROM_ID_LENGTH + 1] = {0};
28 int ret;
29 int pda = 0;
30
31 ret = w1_get_bus(AT91_PDA_EEPROM_DEFAULT_BUS, &bus);
32 if (ret)
Eugen Hristeva9646c42019-06-12 13:16:18 +030033 goto pda_detect_err;
Eugen Hristev7d1787f2018-09-18 10:35:42 +030034
35 for (device_find_first_child(bus, &dev);
36 dev;
37 device_find_next_child(&dev)) {
38 ret = device_probe(dev);
39 if (ret) {
40 continue;
41 } else {
42 ret = w1_eeprom_read_buf(dev, AT91_PDA_EEPROM_ID_OFFSET,
43 (u8 *)buf, AT91_PDA_EEPROM_ID_LENGTH);
44 if (ret)
Eugen Hristeva9646c42019-06-12 13:16:18 +030045 goto pda_detect_err;
Eugen Hristev7d1787f2018-09-18 10:35:42 +030046 break;
47 }
48 }
49 pda = simple_strtoul((const char *)buf, NULL, 10);
50
51 switch (pda) {
52 case 7000:
53 if (buf[4] == 'B')
54 printf("PDA TM7000B detected\n");
55 else
56 printf("PDA TM7000 detected\n");
57 break;
58 case 4300:
59 printf("PDA TM4300 detected\n");
60 break;
61 case 5000:
62 printf("PDA TM5000 detected\n");
63 break;
64 }
Eugen Hristeva9646c42019-06-12 13:16:18 +030065
66pda_detect_err:
Eugen Hristev7d1787f2018-09-18 10:35:42 +030067 env_set("pda", (const char *)buf);
68}
69#else
70void at91_pda_detect(void)
71{
72}
73#endif
Eugen Hristev3232f9b2018-10-08 09:54:27 +030074
75void at91_prepare_cpu_var(void)
76{
77 env_set("cpu", get_cpu_name());
78}