From patchwork Mon Apr 28 20:17:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Harvey X-Patchwork-Id: 343577 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 546E0140077 for ; Tue, 29 Apr 2014 06:19:56 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 161934BA88; Mon, 28 Apr 2014 22:19:43 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WM6btLPLNDNw; Mon, 28 Apr 2014 22:19:42 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7314D4BAA9; Mon, 28 Apr 2014 22:19:05 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9B0DA4B8EA for ; Mon, 28 Apr 2014 22:18:42 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0Z-lOF-6G4a8 for ; Mon, 28 Apr 2014 22:18:39 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-pa0-f50.google.com (mail-pa0-f50.google.com [209.85.220.50]) by theia.denx.de (Postfix) with ESMTPS id 1A9B34B823 for ; Mon, 28 Apr 2014 22:18:06 +0200 (CEST) Received: by mail-pa0-f50.google.com with SMTP id rd3so6236741pab.9 for ; Mon, 28 Apr 2014 13:18:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bqxuhKFyPDtzqasqHyzxy5Xj9g3vCdxMqTH+B4E2COw=; b=bPOnXQXsdJnYYHH1cOJs91pWufoCm6EuKKRCOmdSmF8d4sBbyBP1D97qNhqcIkr/IT civWeyannnC1sNz7TLZxySIhNQPV54e64hfASPVV0nzl1yzCZiqTtDDHeEnoCy8Mjw5k ltEafq776EsUcgIziBvo8myBiIk7g42Wg6soonzqeRT4J4VxPHJ1l4ua78TIeq7z6MBk FahMviRG5HRI3tY7rLRPUVvOoZDB7l6dgnXZn/nG4H7dkoYNTgxdDT7h5lLm8JEaieU8 /SRrbCJxxmw3XFkQup8gypggsVLPaClEYGIp+EcaNhk9sqp4WHEgyyBCdcVkUQWgaMTt EbfQ== X-Gm-Message-State: ALoCoQnK58a5UjWTKlLOPcyB/0q6puU8fLMaY1dKjdSTmvA3OmLbyHPTPgOSPTUOB4LaUGIjH6vI X-Received: by 10.68.162.1 with SMTP id xw1mr11467151pbb.128.1398716285129; Mon, 28 Apr 2014 13:18:05 -0700 (PDT) Received: from tharvey-gw.gw (68-189-91-139.static.snlo.ca.charter.com. [68.189.91.139]) by mx.google.com with ESMTPSA id zv3sm96756925pab.20.2014.04.28.13.18.03 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 28 Apr 2014 13:18:04 -0700 (PDT) From: Tim Harvey To: Stefano Babic Date: Mon, 28 Apr 2014 13:17:36 -0700 Message-Id: <1398716258-8420-11-git-send-email-tharvey@gateworks.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1398716258-8420-1-git-send-email-tharvey@gateworks.com> References: <1398716258-8420-1-git-send-email-tharvey@gateworks.com> Cc: Otavio Salvador , u-boot@lists.denx.de, Tom Rini , Stefan Roese Subject: [U-Boot] [PATCH 10/12] imx: ventana: split read_eeprom into standalone file X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Split the read_eeprom function out so that it can be shared (ie with SPL) Signed-off-by: Tim Harvey --- board/gateworks/gw_ventana/Makefile | 2 +- board/gateworks/gw_ventana/eeprom.c | 89 +++++++++++++++++++++++++++++ board/gateworks/gw_ventana/gw_ventana.c | 89 +---------------------------- board/gateworks/gw_ventana/ventana_eeprom.h | 11 ++++ 4 files changed, 102 insertions(+), 89 deletions(-) create mode 100644 board/gateworks/gw_ventana/eeprom.c diff --git a/board/gateworks/gw_ventana/Makefile b/board/gateworks/gw_ventana/Makefile index e8dab89..03bd1fd 100644 --- a/board/gateworks/gw_ventana/Makefile +++ b/board/gateworks/gw_ventana/Makefile @@ -6,5 +6,5 @@ # SPDX-License-Identifier: GPL-2.0+ # -obj-y := gw_ventana.o gsc.o +obj-y := gw_ventana.o gsc.o eeprom.o diff --git a/board/gateworks/gw_ventana/eeprom.c b/board/gateworks/gw_ventana/eeprom.c new file mode 100644 index 0000000..e90186e --- /dev/null +++ b/board/gateworks/gw_ventana/eeprom.c @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2014 Gateworks Corporation + * Author: Tim Harvey + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include + +#include "gsc.h" +#include "ventana_eeprom.h" + +/* read ventana EEPROM, check for validity, and return baseboard type */ +int +read_eeprom(int bus, struct ventana_board_info *info) +{ + int i; + int chksum; + char baseboard; + int type; + unsigned char *buf = (unsigned char *)info; + + memset(info, 0, sizeof(*info)); + + /* + * On a board with a missing/depleted backup battery for GSC, the + * board may be ready to probe the GSC before its firmware is + * running. We will wait here indefinately for the GSC/EEPROM. + */ + while (1) { + if (0 == i2c_set_bus_num(bus) && + 0 == i2c_probe(GSC_EEPROM_ADDR)) + break; + mdelay(1); + } + + /* read eeprom config section */ + if (gsc_i2c_read(GSC_EEPROM_ADDR, 0x00, 1, buf, sizeof(*info))) { + puts("EEPROM: Failed to read EEPROM\n"); + info->model[0] = 0; + return GW_UNKNOWN; + } + + /* sanity checks */ + if (info->model[0] != 'G' || info->model[1] != 'W') { + puts("EEPROM: Invalid Model in EEPROM\n"); + info->model[0] = 0; + return GW_UNKNOWN; + } + + /* validate checksum */ + for (chksum = 0, i = 0; i < sizeof(*info)-2; i++) + chksum += buf[i]; + if ((info->chksum[0] != chksum>>8) || + (info->chksum[1] != (chksum&0xff))) { + puts("EEPROM: Failed EEPROM checksum\n"); + info->model[0] = 0; + return GW_UNKNOWN; + } + + /* original GW5400-A prototype */ + baseboard = info->model[3]; + if (strncasecmp((const char *)info->model, "GW5400-A", 8) == 0) + baseboard = '0'; + + switch (baseboard) { + case '0': /* original GW5400-A prototype */ + type = GW54proto; + break; + case '1': + type = GW51xx; + break; + case '2': + type = GW52xx; + break; + case '3': + type = GW53xx; + break; + case '4': + type = GW54xx; + break; + default: + printf("EEPROM: Unknown model in EEPROM: %s\n", info->model); + type = GW_UNKNOWN; + break; + } + return type; +} diff --git a/board/gateworks/gw_ventana/gw_ventana.c b/board/gateworks/gw_ventana/gw_ventana.c index 2113740..3b6bc01 100644 --- a/board/gateworks/gw_ventana/gw_ventana.c +++ b/board/gateworks/gw_ventana/gw_ventana.c @@ -81,15 +81,6 @@ DECLARE_GLOBAL_DATA_PTR; */ static struct ventana_board_info ventana_info; -enum { - GW54proto, /* original GW5400-A prototype */ - GW51xx, - GW52xx, - GW53xx, - GW54xx, - GW_UNKNOWN, -}; - int board_type; /* UART1: Function varies per baseboard */ @@ -368,84 +359,6 @@ int board_eth_init(bd_t *bis) return 0; } -/* read ventana EEPROM, check for validity, and return baseboard type */ -static int -read_eeprom(void) -{ - int i; - int chksum; - char baseboard; - int type; - struct ventana_board_info *info = &ventana_info; - unsigned char *buf = (unsigned char *)&ventana_info; - - memset(info, 0, sizeof(ventana_info)); - - /* - * On a board with a missing/depleted backup battery for GSC, the - * board may be ready to probe the GSC before its firmware is - * running. We will wait here indefinately for the GSC/EEPROM. - */ - while (1) { - if (0 == i2c_set_bus_num(I2C_GSC) && - 0 == i2c_probe(GSC_EEPROM_ADDR)) - break; - mdelay(1); - } - - /* read eeprom config section */ - if (gsc_i2c_read(GSC_EEPROM_ADDR, 0x00, 1, buf, sizeof(ventana_info))) { - puts("EEPROM: Failed to read EEPROM\n"); - info->model[0] = 0; - return GW_UNKNOWN; - } - - /* sanity checks */ - if (info->model[0] != 'G' || info->model[1] != 'W') { - puts("EEPROM: Invalid Model in EEPROM\n"); - info->model[0] = 0; - return GW_UNKNOWN; - } - - /* validate checksum */ - for (chksum = 0, i = 0; i < sizeof(*info)-2; i++) - chksum += buf[i]; - if ((info->chksum[0] != chksum>>8) || - (info->chksum[1] != (chksum&0xff))) { - puts("EEPROM: Failed EEPROM checksum\n"); - info->model[0] = 0; - return GW_UNKNOWN; - } - - /* original GW5400-A prototype */ - baseboard = info->model[3]; - if (strncasecmp((const char *)info->model, "GW5400-A", 8) == 0) - baseboard = '0'; - - switch (baseboard) { - case '0': /* original GW5400-A prototype */ - type = GW54proto; - break; - case '1': - type = GW51xx; - break; - case '2': - type = GW52xx; - break; - case '3': - type = GW53xx; - break; - case '4': - type = GW54xx; - break; - default: - printf("EEPROM: Unknown model in EEPROM: %s\n", info->model); - type = GW_UNKNOWN; - break; - } - return type; -} - /* * Baseboard specific GPIO */ @@ -924,7 +837,7 @@ int board_init(void) setup_sata(); #endif /* read Gateworks EEPROM into global struct (used later) */ - board_type = read_eeprom(); + board_type = read_eeprom(I2C_GSC, &ventana_info); /* board-specifc GPIO iomux */ if (board_type < GW_UNKNOWN) { diff --git a/board/gateworks/gw_ventana/ventana_eeprom.h b/board/gateworks/gw_ventana/ventana_eeprom.h index 434b604..5b065be 100644 --- a/board/gateworks/gw_ventana/ventana_eeprom.h +++ b/board/gateworks/gw_ventana/ventana_eeprom.h @@ -103,4 +103,15 @@ enum { EECONFIG_RES15, }; +enum { + GW54proto, /* original GW5400-A prototype */ + GW51xx, + GW52xx, + GW53xx, + GW54xx, + GW_UNKNOWN, +}; + +int read_eeprom(int bus, struct ventana_board_info *); + #endif