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> |
Simon Glass | 9fb625c | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 8 | #include <env.h> |
Eugen Hristev | afaea1f | 2018-09-18 10:35:42 +0300 | [diff] [blame] | 9 | #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 Yang | d9b23e2 | 2017-09-01 16:26:16 +0800 | [diff] [blame] | 16 | |
Eugen Hristev | 61b4dbb | 2018-10-08 09:54:27 +0300 | [diff] [blame] | 17 | char *get_cpu_name(void); |
| 18 | |
Wenyou Yang | d9b23e2 | 2017-09-01 16:26:16 +0800 | [diff] [blame] | 19 | void dummy(void) |
| 20 | { |
| 21 | } |
Eugen Hristev | afaea1f | 2018-09-18 10:35:42 +0300 | [diff] [blame] | 22 | |
| 23 | #if defined CONFIG_W1 |
| 24 | void 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 Hristev | ad371d8 | 2019-06-12 13:16:18 +0300 | [diff] [blame] | 33 | goto pda_detect_err; |
Eugen Hristev | afaea1f | 2018-09-18 10:35:42 +0300 | [diff] [blame] | 34 | |
| 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 Hristev | ad371d8 | 2019-06-12 13:16:18 +0300 | [diff] [blame] | 45 | goto pda_detect_err; |
Eugen Hristev | afaea1f | 2018-09-18 10:35:42 +0300 | [diff] [blame] | 46 | 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 Hristev | ad371d8 | 2019-06-12 13:16:18 +0300 | [diff] [blame] | 65 | |
| 66 | pda_detect_err: |
Eugen Hristev | afaea1f | 2018-09-18 10:35:42 +0300 | [diff] [blame] | 67 | env_set("pda", (const char *)buf); |
| 68 | } |
| 69 | #else |
| 70 | void at91_pda_detect(void) |
| 71 | { |
| 72 | } |
| 73 | #endif |
Eugen Hristev | 61b4dbb | 2018-10-08 09:54:27 +0300 | [diff] [blame] | 74 | |
| 75 | void at91_prepare_cpu_var(void) |
| 76 | { |
| 77 | env_set("cpu", get_cpu_name()); |
| 78 | } |