public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Bryan Brattlof <bb@ti.com>
To: Tom Rini <trini@konsulko.com>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	Christian Gmeiner <christian.gmeiner@gmail.com>,
	Andrew Davis <afd@ti.com>
Cc: UBoot Mailing List <u-boot@lists.denx.de>, Bryan Brattlof <bb@ti.com>
Subject: [PATCH 1/3] board: ti: common: add rtc setup to common folder
Date: Tue, 7 Nov 2023 17:21:41 -0600	[thread overview]
Message-ID: <20231107232139.2839534-6-bb@ti.com> (raw)
In-Reply-To: <20231107232139.2839534-5-bb@ti.com>

All of the starter kit boards for the am62xxx extended family utilize
the same 32k crystal oscillator for a more accurate clock for the RTC
instance. Add the setup the clock mux and debounce configuration to the
common board directory so the entire am62xxx extended family can utilize
it.

Signed-off-by: Bryan Brattlof <bb@ti.com>
---
 board/ti/common/Kconfig |  8 +++++++
 board/ti/common/rtc.c   | 47 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+)
 create mode 100644 board/ti/common/rtc.c

diff --git a/board/ti/common/Kconfig b/board/ti/common/Kconfig
index 49edd98014ab7..56a65c0a402bb 100644
--- a/board/ti/common/Kconfig
+++ b/board/ti/common/Kconfig
@@ -1,3 +1,11 @@
+config BOARD_HAS_32K_RTC_CRYSTAL
+	bool "Enable the 32k crystial for RTC"
+	help
+	   Some of Texas Instrument's Starter-Kit boards have
+	   an onboard 32k crystal. Select this option if you wish Uboot
+	   to enable this crystal for Linux
+	default n
+
 config TI_I2C_BOARD_DETECT
 	bool "Support for Board detection for TI platforms"
 	help
diff --git a/board/ti/common/rtc.c b/board/ti/common/rtc.c
new file mode 100644
index 0000000000000..e117a927765c5
--- /dev/null
+++ b/board/ti/common/rtc.c
@@ -0,0 +1,47 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * RTC setup for TI Platforms
+ *
+ * Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/
+ */
+#include <asm/arch/hardware.h>
+#include <asm/io.h>
+#include <log.h>
+
+#define WKUP_CTRLMMR_DBOUNCE_CFG1 0x04504084
+#define WKUP_CTRLMMR_DBOUNCE_CFG2 0x04504088
+#define WKUP_CTRLMMR_DBOUNCE_CFG3 0x0450408c
+#define WKUP_CTRLMMR_DBOUNCE_CFG4 0x04504090
+#define WKUP_CTRLMMR_DBOUNCE_CFG5 0x04504094
+#define WKUP_CTRLMMR_DBOUNCE_CFG6 0x04504098
+
+void board_rtc_init(void)
+{
+	u32 val;
+
+	/* We have 32k crystal, so lets enable it */
+	val = readl(MCU_CTRL_LFXOSC_CTRL);
+	val &= ~(MCU_CTRL_LFXOSC_32K_DISABLE_VAL);
+	writel(val, MCU_CTRL_LFXOSC_CTRL);
+
+	/* Add any TRIM needed for the crystal here.. */
+	/* Make sure to mux up to take the SoC 32k from the crystal */
+	writel(MCU_CTRL_DEVICE_CLKOUT_LFOSC_SELECT_VAL,
+	       MCU_CTRL_DEVICE_CLKOUT_32K_CTRL);
+
+	/* Setup debounce conf registers - arbitrary values.
+	 * Times are approx
+	 */
+	/* 1.9ms debounce @ 32k */
+	writel(WKUP_CTRLMMR_DBOUNCE_CFG1, 0x1);
+	/* 5ms debounce @ 32k */
+	writel(WKUP_CTRLMMR_DBOUNCE_CFG2, 0x5);
+	/* 20ms debounce @ 32k */
+	writel(WKUP_CTRLMMR_DBOUNCE_CFG3, 0x14);
+	/* 46ms debounce @ 32k */
+	writel(WKUP_CTRLMMR_DBOUNCE_CFG4, 0x18);
+	/* 100ms debounce @ 32k */
+	writel(WKUP_CTRLMMR_DBOUNCE_CFG5, 0x1c);
+	/* 156ms debounce @ 32k */
+	writel(WKUP_CTRLMMR_DBOUNCE_CFG6, 0x1f);
+}
-- 
2.42.0


  reply	other threads:[~2023-11-07 23:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-07 23:21 [PATCH 0/3] board: ti: common: setup mux and debounce for 32k RTC crystal Bryan Brattlof
2023-11-07 23:21 ` Bryan Brattlof [this message]
2023-11-07 23:30   ` [PATCH 1/3] board: ti: common: add rtc setup to common folder Tom Rini
2023-11-08 15:46     ` Bryan Brattlof
2023-11-08 16:49       ` Tom Rini
2023-11-08  7:26   ` Vignesh Raghavendra
2023-11-08 15:38     ` Bryan Brattlof
2023-11-07 23:21 ` [PATCH 2/3] configs: am62ax: setup the 32k RTC crystal Bryan Brattlof
2023-11-07 23:32   ` Tom Rini
2023-11-07 23:21 ` [PATCH 3/3] configs: am62x: move 32K RTC crystal to common Bryan Brattlof

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-all 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=20231107232139.2839534-6-bb@ti.com \
    --to=bb@ti.com \
    --cc=afd@ti.com \
    --cc=christian.gmeiner@gmail.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=vigneshr@ti.com \
    /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