Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Wenyou Yang | d9b23e2 | 2017-09-01 16:26:16 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017 Microchip |
| 4 | * Wenyou Yang <wenyou.yang@microchip.com> |
Wenyou Yang | d9b23e2 | 2017-09-01 16:26:16 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Eugen Hristev | afaea1f | 2018-09-18 10:35:42 +0300 | [diff] [blame] | 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 |
Wenyou Yang | d9b23e2 | 2017-09-01 16:26:16 +0800 | [diff] [blame] | 15 | |
Eugen Hristev | 61b4dbb | 2018-10-08 09:54:27 +0300 | [diff] [blame] | 16 | char *get_cpu_name(void); |
| 17 | |
Wenyou Yang | d9b23e2 | 2017-09-01 16:26:16 +0800 | [diff] [blame] | 18 | void dummy(void) |
| 19 | { |
| 20 | } |
Eugen Hristev | afaea1f | 2018-09-18 10:35:42 +0300 | [diff] [blame] | 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) |
Eugen Hristev | ad371d8 | 2019-06-12 13:16:18 +0300 | [diff] [blame] | 32 | goto pda_detect_err; |
Eugen Hristev | afaea1f | 2018-09-18 10:35:42 +0300 | [diff] [blame] | 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) |
Eugen Hristev | ad371d8 | 2019-06-12 13:16:18 +0300 | [diff] [blame] | 44 | goto pda_detect_err; |
Eugen Hristev | afaea1f | 2018-09-18 10:35:42 +0300 | [diff] [blame] | 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 | } |
Eugen Hristev | ad371d8 | 2019-06-12 13:16:18 +0300 | [diff] [blame] | 64 | |
| 65 | pda_detect_err: |
Eugen Hristev | afaea1f | 2018-09-18 10:35:42 +0300 | [diff] [blame] | 66 | env_set("pda", (const char *)buf); |
| 67 | } |
| 68 | #else |
| 69 | void at91_pda_detect(void) |
| 70 | { |
| 71 | } |
| 72 | #endif |
Eugen Hristev | 61b4dbb | 2018-10-08 09:54:27 +0300 | [diff] [blame] | 73 | |
| 74 | void at91_prepare_cpu_var(void) |
| 75 | { |
| 76 | env_set("cpu", get_cpu_name()); |
| 77 | } |