public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Leif Lindholm <leif.lindholm@linaro.org>
To: Jun Nie <jun.nie@linaro.org>
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 <michael.d.kinney@intel.com>,
	Liming Gao <liming.gao@intel.com>
Subject: Re: [PATCH 2/4] Platforms: Add ZX RTC driver for Sanchip SoC
Date: Thu, 10 Aug 2017 16:15:03 +0100	[thread overview]
Message-ID: <20170810151503.bdkvjdn47njhlweg@bivouac.eciton.net> (raw)
In-Reply-To: <1502287959-16806-2-git-send-email-jun.nie@linaro.org>

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


  parent reply	other threads:[~2017-08-10 15:12 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1502287959-16806-1-git-send-email-jun.nie@linaro.org>
2017-08-10 13:04 ` [PATCH 1/4] Platforms: Add Sanchip Zx296718 basic library Leif Lindholm
2017-08-10 14:16   ` Laszlo Ersek
     [not found]   ` <e3573cc7-875f-6b44-12dd-b76ec8c9272a@linaro.org>
2017-08-17 15:51     ` Leif Lindholm
     [not found] ` <1502287959-16806-2-git-send-email-jun.nie@linaro.org>
2017-08-10 14:03   ` [PATCH 2/4] Platforms: Add ZX RTC driver for Sanchip SoC Leif Lindholm
2017-08-17 15:43     ` Jun Nie
2017-08-17 15:55       ` Leif Lindholm
2017-08-10 15:15   ` Leif Lindholm [this message]
     [not found] ` <1502287959-16806-3-git-send-email-jun.nie@linaro.org>
2017-08-10 14:41   ` [PATCH 3/4] Platforms/zx: Add boot manager lib and entries Leif Lindholm
2017-08-17 15:45     ` Jun Nie
2017-08-17 18:53       ` Leif Lindholm
     [not found] ` <1502287959-16806-4-git-send-email-jun.nie@linaro.org>
2017-08-10 15:00   ` [PATCH 4/4] Platforms/zx: Add platform build system files Leif Lindholm
2017-08-17 15:46     ` Jun Nie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170810151503.bdkvjdn47njhlweg@bivouac.eciton.net \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox