From patchwork Thu Aug 9 13:54:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 955654 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=microchip.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41mVbx2sdSz9s0n for ; Fri, 10 Aug 2018 00:13:49 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 11B2AC21DF9; Thu, 9 Aug 2018 14:05:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 09380C21EBB; Thu, 9 Aug 2018 14:00:05 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 48C44C21ED5; Thu, 9 Aug 2018 13:59:59 +0000 (UTC) Received: from esa2.microchip.iphmx.com (esa2.microchip.iphmx.com [68.232.149.84]) by lists.denx.de (Postfix) with ESMTPS id 19647C21E42 for ; Thu, 9 Aug 2018 13:59:43 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.53,215,1531810800"; d="scan'208";a="17647553" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 09 Aug 2018 06:59:43 -0700 Received: from eh-station.mchp-main.com (10.10.76.4) by chn-sv-exch07.mchp-main.com (10.10.76.108) with Microsoft SMTP Server id 14.3.352.0; Thu, 9 Aug 2018 06:59:42 -0700 From: Eugen Hristev To: Date: Thu, 9 Aug 2018 16:54:02 +0300 Message-ID: <1533822854-4349-19-git-send-email-eugen.hristev@microchip.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1533822854-4349-1-git-send-email-eugen.hristev@microchip.com> References: <1533822854-4349-1-git-send-email-eugen.hristev@microchip.com> MIME-Version: 1.0 Cc: nicolas.ferre@microchip.com Subject: [U-Boot] [PATCH v2 18/30] board: atmel: add support for pda detection X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 --- board/atmel/common/board.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/board/atmel/common/board.c b/board/atmel/common/board.c index 650eb22..b9cf54c 100644 --- a/board/atmel/common/board.c +++ b/board/atmel/common/board.c @@ -5,7 +5,62 @@ */ #include +#include +#include +#include + +#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 { + w1_eeprom_read_buf(dev, AT91_PDA_EEPROM_ID_OFFSET, + (u8 *)buf, AT91_PDA_EEPROM_ID_LENGTH); + 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