uboot/board/atmel/common/board.c
<<
>>
Prefs
   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 <dm.h>
   9#include <env.h>
  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
  17
  18char *get_cpu_name(void);
  19
  20void dummy(void)
  21{
  22}
  23
  24#if defined CONFIG_W1
  25void 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)
  34                goto pda_detect_err;
  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)
  46                                goto pda_detect_err;
  47                        break;
  48                }
  49        }
  50        pda = dectoul((const char *)buf, NULL);
  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        }
  66
  67pda_detect_err:
  68        env_set("pda", (const char *)buf);
  69}
  70#else
  71void at91_pda_detect(void)
  72{
  73}
  74#endif
  75
  76void at91_prepare_cpu_var(void)
  77{
  78        env_set("cpu", get_cpu_name());
  79}
  80