blob: c93c0e52e30d52c1a3ecd6e17fdd073f31f032ef [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 Glass614a9a22020-07-19 10:15:42 -06008#include <dm.h>
Simon Glass5e6201b2019-08-01 09:46:51 -06009#include <env.h>
Eugen Hristev7d1787f2018-09-18 10:35:42 +030010#include <w1.h>
11#include <w1-eeprom.h>
12#include <dm/device-internal.h>
13
14#define AT91_PDA_EEPROM_ID_OFFSET 15
15#define AT91_PDA_EEPROM_ID_LENGTH 5
16#define AT91_PDA_EEPROM_DEFAULT_BUS 0
Wenyou Yanga3b84f42017-09-01 16:26:16 +080017
Eugen Hristev3232f9b2018-10-08 09:54:27 +030018char *get_cpu_name(void);
19
Wenyou Yanga3b84f42017-09-01 16:26:16 +080020void dummy(void)
21{
22}
Eugen Hristev7d1787f2018-09-18 10:35:42 +030023
24#if defined CONFIG_W1
25void at91_pda_detect(void)
26{
27 struct udevice *bus, *dev;
28 u8 buf[AT91_PDA_EEPROM_ID_LENGTH + 1] = {0};
29 int ret;
30 int pda = 0;
31
32 ret = w1_get_bus(AT91_PDA_EEPROM_DEFAULT_BUS, &bus);
33 if (ret)
Eugen Hristeva9646c42019-06-12 13:16:18 +030034 goto pda_detect_err;
Eugen Hristev7d1787f2018-09-18 10:35:42 +030035
36 for (device_find_first_child(bus, &dev);
37 dev;
38 device_find_next_child(&dev)) {
39 ret = device_probe(dev);
40 if (ret) {
41 continue;
42 } else {
43 ret = w1_eeprom_read_buf(dev, AT91_PDA_EEPROM_ID_OFFSET,
44 (u8 *)buf, AT91_PDA_EEPROM_ID_LENGTH);
45 if (ret)
Eugen Hristeva9646c42019-06-12 13:16:18 +030046 goto pda_detect_err;
Eugen Hristev7d1787f2018-09-18 10:35:42 +030047 break;
48 }
49 }
Simon Glassff9b9032021-07-24 09:03:30 -060050 pda = dectoul((const char *)buf, NULL);
Eugen Hristev7d1787f2018-09-18 10:35:42 +030051
52 switch (pda) {
53 case 7000:
54 if (buf[4] == 'B')
55 printf("PDA TM7000B detected\n");
56 else
57 printf("PDA TM7000 detected\n");
58 break;
59 case 4300:
60 printf("PDA TM4300 detected\n");
61 break;
62 case 5000:
63 printf("PDA TM5000 detected\n");
64 break;
65 }
Eugen Hristeva9646c42019-06-12 13:16:18 +030066
67pda_detect_err:
Eugen Hristev7d1787f2018-09-18 10:35:42 +030068 env_set("pda", (const char *)buf);
69}
70#else
71void at91_pda_detect(void)
72{
73}
74#endif
Eugen Hristev3232f9b2018-10-08 09:54:27 +030075
76void at91_prepare_cpu_var(void)
77{
78 env_set("cpu", get_cpu_name());
79}