From patchwork Thu Mar 16 14:26:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 739853 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3vkW5X6NLHz9rvt for ; Fri, 17 Mar 2017 01:27:28 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Ja38FCg2"; dkim-atps=neutral Received: by lists.denx.de (Postfix, from userid 105) id 90EA8C21C5F; Thu, 16 Mar 2017 14:25:34 +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=FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID 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 1964DC21C76; Thu, 16 Mar 2017 14:23:14 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A126BC21C5E; Thu, 16 Mar 2017 14:22:37 +0000 (UTC) Received: from mail-pf0-f193.google.com (mail-pf0-f193.google.com [209.85.192.193]) by lists.denx.de (Postfix) with ESMTPS id 5D821C21C61 for ; Thu, 16 Mar 2017 14:22:34 +0000 (UTC) Received: by mail-pf0-f193.google.com with SMTP id r137so2147012pfr.3 for ; Thu, 16 Mar 2017 07:22:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=nT2nI6cttpqav8/Zl0ix/JoIUkqtmsb5GnrT1S4k/sA=; b=Ja38FCg2EQ6J4aWCaLy3hfmak5w200J/moQ+zpxan4g1lhwng6JKw+j8uYFM0+75Rv I99QG+SS58/YEjEmjlaqvWAtYCqaIMT+HftGHmoaezWQWNAqFXwQ87byWIrOvxNlzMdf UO+7hDOJq3DXIrQdL6Apzwp2Y0BFH99NZF0A0s2Eg8L5ibntnFVifhf3D2kHaA4OpTqY 6Py7te0P1Fcl98rvQ/pSALIu4XnzF2aBUoIuV0fYN56gNdhV9nTK0dx4RBnd9zNQr6kD GwBYKj8jgUkChkr7PHSqt2V1cuDZPR2VFEjFA531HTAZQSBKyyekra0b0Znlv88ZrzOP DyWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=nT2nI6cttpqav8/Zl0ix/JoIUkqtmsb5GnrT1S4k/sA=; b=htb7P0wDsdXOoy/+M5rNmzDtjVS6Q6QjNrpC6nkip/teQJWq15QYvu+M2rswcg4VfP goTSjuCZ9za+1+mJDyxaEkaL1kCT4AYk256mpYgLCQxoFoHy9l2UC9Jb0tLb0jQOtILR CllNf+hYtOu//o0Btc6QTuAT7/RmTDZKJNCUNwC6Y6ZNex30oN+AXruTdGX+LiNtzR7B Sl1gyOm6HnVYiJVtSYBjaDtJa+EiU+d6ZD2TiJRPGG3CJS61IXj3Zg4afJeu+mX6MsRN By2cMo0YPVYOG9lk9PE5EzFs5ommPQUG1I5JBu8mvMqQxqLHOIEbMTSV6wxHvUVoFw/F SBiA== X-Gm-Message-State: AFeK/H2QfVuD5fYn9lo7v5hPdX97bBcNYatPibewLl3I3cEn87hGHnUX8T36jGXNSdtq+w== X-Received: by 10.99.173.6 with SMTP id g6mr10031707pgf.75.1489674153005; Thu, 16 Mar 2017 07:22:33 -0700 (PDT) Received: from ala-d2121-lx1.wrs.com (unknown-157-139.windriver.com. [147.11.157.139]) by smtp.gmail.com with ESMTPSA id c64sm11039959pfa.45.2017.03.16.07.22.31 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 Mar 2017 07:22:32 -0700 (PDT) From: Bin Meng To: Simon Glass , Stefan Roese , U-Boot Mailing List Date: Thu, 16 Mar 2017 07:26:38 -0700 Message-Id: <1489674408-17498-13-git-send-email-bmeng.cn@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1489674408-17498-1-git-send-email-bmeng.cn@gmail.com> References: <1489674408-17498-1-git-send-email-bmeng.cn@gmail.com> Subject: [U-Boot] [PATCH 12/22] x86: Add an early CMOS access library 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This adds a library that provides CMOS (inside RTC SRAM) access at a very early stage when driver model is not available yet. Signed-off-by: Bin Meng Reviewed-by: Simon Glass --- arch/x86/include/asm/early_cmos.h | 43 +++++++++++++++++++++++++++++++++ arch/x86/lib/Makefile | 1 + arch/x86/lib/early_cmos.c | 51 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 arch/x86/include/asm/early_cmos.h create mode 100644 arch/x86/lib/early_cmos.c diff --git a/arch/x86/include/asm/early_cmos.h b/arch/x86/include/asm/early_cmos.h new file mode 100644 index 0000000..cd2634d --- /dev/null +++ b/arch/x86/include/asm/early_cmos.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2017, Bin Meng + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef __EARLY_CMOS_H +#define __EARLY_CMOS_H + +/* CMOS actually resides in the RTC SRAM */ +#define CMOS_IO_PORT 0x70 + +/** + * cmos_read8() - Get 8-bit data stored at the given address + * + * This reads from CMOS for the 8-bit data stored at the given address. + * + * @addr: RTC SRAM address + * @return: 8-bit data stored at the given address + */ +u8 cmos_read8(u8 addr); + +/** + * cmos_read16() - Get 16-bit data stored at the given address + * + * This reads from CMOS for the 16-bit data stored at the given address. + * + * @addr: RTC SRAM address + * @return: 16-bit data stored at the given address + */ +u16 cmos_read16(u8 addr); + +/** + * cmos_read32() - Get 32-bit data stored at the given address + * + * This reads from CMOS for the 32-bit data stored at the given address. + * + * @addr: RTC SRAM address + * @return: 32-bit data stored at the given address + */ +u32 cmos_read32(u8 addr); + +#endif /* __EARLY_CMOS_H */ diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile index c61f931..cd4e976 100644 --- a/arch/x86/lib/Makefile +++ b/arch/x86/lib/Makefile @@ -15,6 +15,7 @@ obj-$(CONFIG_CMD_BOOTM) += bootm.o endif obj-y += cmd_boot.o obj-$(CONFIG_SEABIOS) += coreboot_table.o +obj-y += early_cmos.o obj-$(CONFIG_EFI) += efi/ obj-y += e820.o obj-y += gcc.o diff --git a/arch/x86/lib/early_cmos.c b/arch/x86/lib/early_cmos.c new file mode 100644 index 0000000..fa0b327 --- /dev/null +++ b/arch/x86/lib/early_cmos.c @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2017, Bin Meng + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +/* + * This library provides CMOS (inside RTC SRAM) access routines at a very + * early stage when driver model is not available yet. Only read access is + * provided. The 16-bit/32-bit read are compatible with driver model RTC + * uclass write ops, that data is stored in little-endian mode. + */ + +#include +#include +#include + +u8 cmos_read8(u8 addr) +{ + outb(addr, CMOS_IO_PORT); + + return inb(CMOS_IO_PORT + 1); +} + +u16 cmos_read16(u8 addr) +{ + u16 value = 0; + u16 data; + int i; + + for (i = 0; i < sizeof(value); i++) { + data = cmos_read8(addr + i); + value |= data << (i << 3); + } + + return value; +} + +u32 cmos_read32(u8 addr) +{ + u32 value = 0; + u32 data; + int i; + + for (i = 0; i < sizeof(value); i++) { + data = cmos_read8(addr + i); + value |= data << (i << 3); + } + + return value; +}