All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lubomir Rintel <lkundrak@v3.sk>
To: u-boot@lists.denx.de
Subject: [PATCH RFC 08/20] timer: Add Ingenic JZ4730 timer driver
Date: Tue, 17 Nov 2020 22:00:06 +0100	[thread overview]
Message-ID: <20201117210018.751469-9-lkundrak@v3.sk> (raw)
In-Reply-To: <20201117210018.751469-1-lkundrak@v3.sk>

This adds support for a timer block on JZ4730 SoC.

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
---
 drivers/timer/Kconfig        |  8 ++++
 drivers/timer/Makefile       |  1 +
 drivers/timer/jz4730_timer.c | 83 ++++++++++++++++++++++++++++++++++++
 3 files changed, 92 insertions(+)
 create mode 100644 drivers/timer/jz4730_timer.c

diff --git a/drivers/timer/Kconfig b/drivers/timer/Kconfig
index 80743a25519..9d5a84c03ea 100644
--- a/drivers/timer/Kconfig
+++ b/drivers/timer/Kconfig
@@ -110,6 +110,14 @@ config DESIGNWARE_APB_TIMER
 	  Enables support for the Designware APB Timer driver. This timer is
 	  present on Altera SoCFPGA SoCs.
 
+config JZ4730_TIMER
+	bool "Ingenic JZ4730 timer support"
+	depends on TIMER
+	default y if SOC_JZ4730
+	help
+	  Select this to enable support for the timer found on
+	  devices based on the Ingenic JZ4730 SoC.
+
 config MPC83XX_TIMER
 	bool "MPC83xx timer support"
 	depends on TIMER
diff --git a/drivers/timer/Makefile b/drivers/timer/Makefile
index eb5c48cc6ce..67529c78e59 100644
--- a/drivers/timer/Makefile
+++ b/drivers/timer/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_ATCPIT100_TIMER) += atcpit100_timer.o
 obj-$(CONFIG_ATMEL_PIT_TIMER) += atmel_pit_timer.o
 obj-$(CONFIG_CADENCE_TTC_TIMER)	+= cadence-ttc.o
 obj-$(CONFIG_DESIGNWARE_APB_TIMER)	+= dw-apb-timer.o
+obj-$(CONFIG_JZ4730_TIMER) += jz4730_timer.o
 obj-$(CONFIG_MPC83XX_TIMER) += mpc83xx_timer.o
 obj-$(CONFIG_NOMADIK_MTU_TIMER)	+= nomadik-mtu-timer.o
 obj-$(CONFIG_OMAP_TIMER)	+= omap-timer.o
diff --git a/drivers/timer/jz4730_timer.c b/drivers/timer/jz4730_timer.c
new file mode 100644
index 00000000000..d2c77a20993
--- /dev/null
+++ b/drivers/timer/jz4730_timer.c
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * JZ4730 Timer driver.
+ *
+ * Copyright (c) 2020 Lubomir Rintel <lkundrak@v3.sk>
+ */
+
+#include <common.h>
+#include <config.h>
+#include <clk.h>
+#include <dm.h>
+#include <timer.h>
+#include <time.h>
+#include <asm/global_data.h>
+#include <asm/io.h>
+#include <linux/bitops.h>
+
+#define CHANNEL_ID  0
+
+#define OST_TER		(0x00)
+#define OST_TRDR(n)	(0x10 + ((n) * 0x20))
+#define OST_TCNT(n)	(0x14 + ((n) * 0x20))
+#define OST_TCSR(n)	(0x18 + ((n) * 0x20))
+#define OST_TCRB(n)	(0x1c + ((n) * 0x20))
+
+#define OST_TCSR_CKS_PCLK_256	0x0003
+
+struct jz4730_timer_priv {
+	void __iomem *base;
+};
+
+static u64 jz4730_timer_get_count(struct udevice *dev)
+{
+	struct jz4730_timer_priv *priv = dev_get_priv(dev);
+	u32 val = readl(priv->base + OST_TCNT(CHANNEL_ID));
+
+	return timer_conv_64(U32_MAX - val);
+}
+
+static int jz4730_timer_probe(struct udevice *dev)
+{
+	struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+	struct jz4730_timer_priv *priv = dev_get_priv(dev);
+	struct clk clk;
+	int ret;
+
+	priv->base = dev_remap_addr(dev);
+	if (!priv->base)
+		return -EINVAL;
+
+	ret = clk_get_by_name(dev, "pclk", &clk);
+	if (ret)
+		return ret;
+
+	uc_priv->clock_rate = clk_get_rate(&clk);
+	uc_priv->clock_rate /= 256;
+
+	writew(OST_TCSR_CKS_PCLK_256, priv->base + OST_TCSR(CHANNEL_ID));
+	writel(U32_MAX, priv->base + OST_TRDR(CHANNEL_ID));
+	writel(U32_MAX, priv->base + OST_TCNT(CHANNEL_ID));
+	writeb(BIT(CHANNEL_ID), priv->base + OST_TER);
+
+	return 0;
+}
+
+static const struct timer_ops jz4730_timer_ops = {
+	.get_count = jz4730_timer_get_count,
+};
+
+static const struct udevice_id jz4730_timer_ids[] = {
+	{ .compatible = "ingenic,jz4730-tcu" },
+	{ }
+};
+
+U_BOOT_DRIVER(jz4730_timer) = {
+	.name = "jz4730_timer",
+	.id = UCLASS_TIMER,
+	.of_match = jz4730_timer_ids,
+	.priv_auto_alloc_size = sizeof(struct jz4730_timer_priv),
+	.probe = jz4730_timer_probe,
+	.ops = &jz4730_timer_ops,
+	.flags = DM_FLAG_PRE_RELOC,
+};
-- 
2.28.0

  parent reply	other threads:[~2020-11-17 21:00 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-17 20:59 [PATCH RFC 00/20] MIPS: Add support for JZ4730 and Skytone Alpha 400 Lubomir Rintel
2020-11-17 20:59 ` [PATCH RFC 01/20] config: Remove CONFIG_SYS_ID_EEPROM Lubomir Rintel
2020-11-17 21:00 ` [PATCH RFC 02/20] mtd: Allow building nand_spl_simple w/o SPL_NAND_ECC Lubomir Rintel
2020-11-17 21:00 ` [PATCH RFC 03/20] cmd/mac: Don't build unless CONFIG_CMD_MAC is enabled Lubomir Rintel
2020-11-17 22:17   ` Daniel Schwierzeck
2020-11-17 21:00 ` [PATCH RFC 04/20] mips: Don't access CP0_EBASE on JZ47XX Lubomir Rintel
2020-11-17 21:00 ` [PATCH RFC 05/20] ns16550: Turn on the UME bit if on ARCH_JZ47XX Lubomir Rintel
2020-11-17 22:29   ` Daniel Schwierzeck
2020-11-18  6:55     ` Lubomir Rintel
2020-11-17 21:00 ` [PATCH RFC 06/20] clk: Add driver for Ingenic JZ4730 CGU Lubomir Rintel
2020-11-17 21:00 ` [PATCH RFC 07/20] timer-uclass: Tolerate failure to get clock rate in pre_probe Lubomir Rintel
2020-11-17 21:00 ` Lubomir Rintel [this message]
2020-11-17 21:00 ` [PATCH RFC 09/20] mmc: Default to JZ47XX_MMC=y on ARCH_JZ47XX Lubomir Rintel
2020-11-17 21:00 ` [PATCH RFC 10/20] mmc/jz_mmc: Add a JZ4740 compatible string Lubomir Rintel
2020-11-18 13:56   ` Ezequiel Garcia
2020-11-17 21:00 ` [PATCH RFC 11/20] mmc/jz_mmc: Support wp-gpio/cd-gpio Lubomir Rintel
2020-11-17 21:00 ` [PATCH RFC 12/20] pinctrl: Add Ingenic JZ4730 pin control and GPIO driver Lubomir Rintel
2020-11-17 22:39   ` Daniel Schwierzeck
2020-11-17 21:00 ` [PATCH RFC 13/20] nand: Use correct prototype of board_nand_init() with SPL_NAND_SIMPLE Lubomir Rintel
2020-11-17 21:00 ` [PATCH RFC 14/20] nand/raw: Add Ingenic JZ4730 NAND flash driver Lubomir Rintel
2020-11-17 21:00 ` [PATCH RFC 15/20] watchdog: Add Ingenic JZ4730 watchdog timer driver Lubomir Rintel
2020-11-17 21:00 ` [PATCH RFC 16/20] net: Add Ingenic JZ4730 Ethernet driver Lubomir Rintel
2020-11-17 21:00 ` [PATCH RFC 17/20] mips: dts: Add Ingenic JZ4730 Lubomir Rintel
2020-11-17 21:00 ` [PATCH RFC 18/20] mips/mach-jz47xx: Add Ingenic JZ4730 support Lubomir Rintel
2020-11-17 21:00 ` [PATCH RFC 19/20] mips: dts: Add Skytone Alpha 400 Lubomir Rintel
2020-11-17 21:00 ` [PATCH RFC 20/20] board: " Lubomir Rintel

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=20201117210018.751469-9-lkundrak@v3.sk \
    --to=lkundrak@v3.sk \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.