From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-x231.google.com (mail-wm0-x231.google.com [IPv6:2a00:1450:400c:c09::231]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3042121B06E9B for ; Thu, 10 Aug 2017 08:12:48 -0700 (PDT) Received: by mail-wm0-x231.google.com with SMTP id f15so25327163wmg.1 for ; Thu, 10 Aug 2017 08:15:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=o3BVVwb4SbVLE2CUqdUuueDFZiiR7oGjXdN7VNEaEDs=; b=eFmEK+RmdIGaP3B51s8j2XJusVYNLPHekQhSzMpikvJbzr3TsPXEGCOb5cqhNvhbnM 3xgBhqwWgP3d+BZr6WGegqGF04CPhe6/4gKNw1y1lQbTTCP0KunMHxtMMd8INYUNrWVN I/PSCI8DHQGwZzXqkESsZnsdsKeEWdNCj0U6s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=o3BVVwb4SbVLE2CUqdUuueDFZiiR7oGjXdN7VNEaEDs=; b=b9xRJCAPgo49VpErCZW75moh3QAB6mf+E/mYDZ0huOMmeZYAZPFxvD4uJJuYW9pcTL sQKI/HFQp/oDXDrhL7xIkYbNugrM1amfcMmYAMXW9r0DjaNiYwNYrTP1ZYQAKxLoEGYh IoBLiHGMoVTWDWYvhxVBqRKKWoyF7Fctm9y7FCJ2GLyPVl7R1ABoO4Vwtm7fVGDvqk5V wA5S6fu/1I1Ie3JcwgUP4lPTqLqrHqXl0UluUsSiw4L+4IMB83SDFLIUcd9xtcgJbUQp XKCZHnGqbNtgiadHdxD9R3w2ZK51Vp/NaIncURupKPxSjmMLC0taol4DTYq/R4bxqPCI L4GQ== X-Gm-Message-State: AHYfb5iQ1dSA+Chk/PSWxbrX7ajQqycMbwXDl6K1Zrf5/UHqIMffrLhy WhYq9WZJYjg7G79v X-Received: by 10.28.109.146 with SMTP id b18mr7513146wmi.34.1502378106068; Thu, 10 Aug 2017 08:15:06 -0700 (PDT) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id n24sm5436925wrn.59.2017.08.10.08.15.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Aug 2017 08:15:05 -0700 (PDT) Date: Thu, 10 Aug 2017 16:15:03 +0100 From: Leif Lindholm To: Jun Nie Cc: haojian.zhuang@linaro.org, ard.biesheuvel@linaro.org, linaro-uefi@lists.linaro.org, shawn.guo@linaro.org, jason.liu@linaro.org, edk2-devel@lists.01.org, Michael D Kinney , Liming Gao Message-ID: <20170810151503.bdkvjdn47njhlweg@bivouac.eciton.net> References: <1502287959-16806-1-git-send-email-jun.nie@linaro.org> <1502287959-16806-2-git-send-email-jun.nie@linaro.org> MIME-Version: 1.0 In-Reply-To: <1502287959-16806-2-git-send-email-jun.nie@linaro.org> User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [PATCH 2/4] Platforms: Add ZX RTC driver for Sanchip SoC X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Aug 2017 15:12:48 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Just another thought. On Wed, Aug 09, 2017 at 10:12:37PM +0800, Jun Nie wrote: > diff --git a/Silicon/Sanchip/Library/Zx6718RealTimeClockLib/Zx296718RealTimeClock.h b/Silicon/Sanchip/Library/Zx6718RealTimeClockLib/Zx296718RealTimeClock.h > new file mode 100644 > index 0000000..3b5a4d4 > --- /dev/null > +++ b/Silicon/Sanchip/Library/Zx6718RealTimeClockLib/Zx296718RealTimeClock.h > @@ -0,0 +1,102 @@ > +/** @file > +* > +* Copyright (C) 2017 Sanechips Technology Co., Ltd. > +* Copyright (c) 2017, Linaro Ltd. > +* > +* This program and the accompanying materials > +* are licensed and made available under the terms and conditions of the BSD License > +* which accompanies this distribution. The full text of the license may be found at > +* http://opensource.org/licenses/bsd-license.php > +* > +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. > +* > +* Based on the files under ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf > +**/ > + > + > +#ifndef __DS3231_REAL_TIME_CLOCK_H__ > +#define __DS3231_REAL_TIME_CLOCK_H__ > + > +#define RTC_POWER_INI1_PARA (0xCDBC) > +#define RTC_POWER_INI2_PARA (0xCFCC) > +#define CONFIG_PARMETER (0xC1CD) > + > +#define ZX_RTC_CMP_VALUE (0x3FFF) > +#define WAIT_FOR_COUNT (2000) > +#define INIT_DELAY (100) > + > + > +/* RTC Control register description */ > +#define RTC_CTRL_STOP (~(0x1 << 0)) > +#define RTC_CTRL_RUN (0x1 << 0) > +#define RTC_CTRL_ROUND30S (0x1 << 1) > +#define RTC_CTRL_AUTO_COMPENSATION (0x1 << 2) > +#define RTC_CTRL_MODULE12 (0x1 << 3) > +#define RTC_CTRL_MODULE24 (~(0x1 << 3)) > +#define RTC_CTRL_SET_32_COUNTER (0x1 << 5) > +#define RTC_CTRL_SOFT_RESET (0x1 << 6) > +#define RTC_CTRL_CLK_32K_OUTEN (0x1 << 8) > + > +#define RTC_CTRL_BIT6_0 ( ~(0x1 << 6)) > +#define RTC_CTRL_BIT6_1 (0x1 << 6) > + > + > + > +/* RTC Interrupt register description */ > +#define RTC_EVERY_MASK (0x3 << 0) > +#define RTC_EVERY_SEC 0x00 /* second periodic intrrupt */ > +#define RTC_EVERY_MIN 0x01 /* minute periodic interrupt */ > +#define RTC_EVERY_HR 0x02 /* hour periodic interrupt */ > +#define RTC_EVERY_DAY 0x03 /* day periodic interrupt */ > +#define RTC_IT_TIMER (0x1 << 2) /* Enable periodic interrupt */ > +#define RTC_IT_ALARM (0x1 << 3) /* Enable alarm clock interrupt */ > +#define RTC_IT_MASK (0x3 << 2) > + > +/* RTC Status register description */ > +#define RTC_BUSY (0x1 << 0) /* Read-only, indicate refresh*/ > +#define RTC_RUN (0x1 << 1) /* Read-only, RTC is running */ > +#define RTC_ALARM (0x1 << 6) /* Read/Write, Alarm interrupt has been generated */ > +#define RTC_TIMER (0x1 << 7) /* Read/Write, Timer interrupt has been generated */ > +#define RTC_POWER_UP (0x1 << 8) /* Read/Write, Reset */ > + > +#define TM_YEAR_START 1900 > + > +#define TM_MONTH_OFFSET 1 > + > +#define TM_WDAY_SUNDAY 0 > +#define ZX_RTC_SUNDAY 7 > + > +#define BCD2BIN(val) (((val) & 0x0f) + ((val) >> 4) * 10) > +#define BIN2BCD(val) ((((val) / 10) << 4) + (val) % 10) Are these not equivalent to DecimalToBcd8/BcdToDecimal8 in BaseLib? If so, could we drop these and use the BasLib versions in the code? > + > +#define BCD4_2_BIN(x) (( (x) & 0x0F) + \ > + ((((x) & 0x0F0) >> 4) * 10) + \ > + ((((x) & 0xF00) >> 8) * 100) + \ > + ((((x) & 0xF000) >> 12) * 1000)) > + > + > +#define BIN_2_BCD4(x) (((x % 10) & 0x0F) | \ > + (((x /10 ) % 10) << 4) | \ > + (((x /100) % 10) << 8) | \ > + (((x /1000) % 10) << 12)) > + And would these not be DecimalToBcd16/BcdToDecimal16? Should we add those to BaseLib? / Leif