board: atmel: add support for pda detection
authorEugen Hristev <eugen.hristev@microchip.com>
Tue, 18 Sep 2018 07:35:42 +0000 (10:35 +0300)
committerTom Rini <trini@konsulko.com>
Sat, 29 Sep 2018 00:22:39 +0000 (20:22 -0400)
This adds the support for PDA detection as common code for
Atmel boards.
Using the one wire interface over GPIO , an EEPROM memory is read
and compared to preprogrammed values for PDA screens TM4300, TM7000
and TM7000B.
Once the PDA is detected, an environment variable is set accordingly.

Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>
board/atmel/common/board.c

index 650eb2238c7d9be72d8b9f79546f670a6ec36dda..8f9b5e137c413b98711a6d25844d76b18bbbc572 100644 (file)
@@ -5,7 +5,64 @@
  */
 
 #include <common.h>
+#include <w1.h>
+#include <w1-eeprom.h>
+#include <dm/device-internal.h>
+
+#define AT91_PDA_EEPROM_ID_OFFSET              15
+#define AT91_PDA_EEPROM_ID_LENGTH              5
+#define AT91_PDA_EEPROM_DEFAULT_BUS            0
 
 void dummy(void)
 {
 }
+
+#if defined CONFIG_W1
+void at91_pda_detect(void)
+{
+       struct udevice *bus, *dev;
+       u8 buf[AT91_PDA_EEPROM_ID_LENGTH + 1] = {0};
+       int ret;
+       int pda = 0;
+
+       ret = w1_get_bus(AT91_PDA_EEPROM_DEFAULT_BUS, &bus);
+       if (ret)
+               return;
+
+       for (device_find_first_child(bus, &dev);
+            dev;
+            device_find_next_child(&dev)) {
+               ret = device_probe(dev);
+               if (ret) {
+                       continue;
+               } else {
+                       ret = w1_eeprom_read_buf(dev, AT91_PDA_EEPROM_ID_OFFSET,
+                                                (u8 *)buf, AT91_PDA_EEPROM_ID_LENGTH);
+                       if (ret)
+                               return;
+                       break;
+               }
+       }
+       pda = simple_strtoul((const char *)buf, NULL, 10);
+
+       switch (pda) {
+       case 7000:
+               if (buf[4] == 'B')
+                       printf("PDA TM7000B detected\n");
+               else
+                       printf("PDA TM7000 detected\n");
+               break;
+       case 4300:
+               printf("PDA TM4300 detected\n");
+               break;
+       case 5000:
+               printf("PDA TM5000 detected\n");
+               break;
+       }
+       env_set("pda", (const char *)buf);
+}
+#else
+void at91_pda_detect(void)
+{
+}
+#endif