1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * Copyright (C) 2017 Microchip 4 * Wenyou Yang <wenyou.yang@microchip.com> 5 */ 6 7 #include <common.h> 8 #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 15 16 char *get_cpu_name(void); 17 18 void dummy(void) 19 { 20 } 21 22 #if defined CONFIG_W1 23 void 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 67 void at91_pda_detect(void) 68 { 69 } 70 #endif 71 72 void at91_prepare_cpu_var(void) 73 { 74 env_set("cpu", get_cpu_name()); 75 } 76