Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Wenyou Yang | a3b84f4 | 2017-09-01 16:26:16 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017 Microchip |
| 4 | * Wenyou Yang <wenyou.yang@microchip.com> |
Wenyou Yang | a3b84f4 | 2017-09-01 16:26:16 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Eugen Hristev | 7d1787f | 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 | a3b84f4 | 2017-09-01 16:26:16 +0800 | [diff] [blame] | 15 | |
| 16 | void dummy(void) |
| 17 | { |
| 18 | } |
Eugen Hristev | 7d1787f | 2018-09-18 10:35:42 +0300 | [diff] [blame] | 19 | |
| 20 | #if defined CONFIG_W1 |
| 21 | void at91_pda_detect(void) |
| 22 | { |
| 23 | struct udevice *bus, *dev; |
| 24 | u8 buf[AT91_PDA_EEPROM_ID_LENGTH + 1] = {0}; |
| 25 | int ret; |
| 26 | int pda = 0; |
| 27 | |
| 28 | ret = w1_get_bus(AT91_PDA_EEPROM_DEFAULT_BUS, &bus); |
| 29 | if (ret) |
| 30 | return; |
| 31 | |
| 32 | for (device_find_first_child(bus, &dev); |
| 33 | dev; |
| 34 | device_find_next_child(&dev)) { |
| 35 | ret = device_probe(dev); |
| 36 | if (ret) { |
| 37 | continue; |
| 38 | } else { |
| 39 | ret = w1_eeprom_read_buf(dev, AT91_PDA_EEPROM_ID_OFFSET, |
| 40 | (u8 *)buf, AT91_PDA_EEPROM_ID_LENGTH); |
| 41 | if (ret) |
| 42 | return; |
| 43 | break; |
| 44 | } |
| 45 | } |
| 46 | pda = simple_strtoul((const char *)buf, NULL, 10); |
| 47 | |
| 48 | switch (pda) { |
| 49 | case 7000: |
| 50 | if (buf[4] == 'B') |
| 51 | printf("PDA TM7000B detected\n"); |
| 52 | else |
| 53 | printf("PDA TM7000 detected\n"); |
| 54 | break; |
| 55 | case 4300: |
| 56 | printf("PDA TM4300 detected\n"); |
| 57 | break; |
| 58 | case 5000: |
| 59 | printf("PDA TM5000 detected\n"); |
| 60 | break; |
| 61 | } |
| 62 | env_set("pda", (const char *)buf); |
| 63 | } |
| 64 | #else |
| 65 | void at91_pda_detect(void) |
| 66 | { |
| 67 | } |
| 68 | #endif |