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