Skip to contentSkip to conversation

microblaze: Fix timer and interrupt code

PATCH Applied Michal Simek 3 participants 6 messages Jun 8, 2022 – Jun 24, 2022

Subsystems (2)
lore
Share & tools
lore

Michal Simek

author maintainer
#0 lore raw

cover microblaze: Fix timer and interrupt code

Hi,

this series is moving timer to generic drivers/timer/ location and it is removing unused interrupt code in architecture.

note: This patchset is based on rela and cache series.

Thanks,
Michal

Michal Simek (2):
microblaze: Convert axi timer to DM driver
microblaze: Remove interrupt handler

 MAINTAINERS                                   |   1 +
 arch/Kconfig                                  |   6 +-
 arch/microblaze/cpu/Makefile                  |   2 +-
 arch/microblaze/cpu/interrupts.c              | 182 +-----------------
 arch/microblaze/cpu/timer.c                   | 123 ------------
 arch/microblaze/include/asm/microblaze_intc.h |  37 ----
 .../microblaze/include/asm/microblaze_timer.h |  26 ---
 drivers/timer/Kconfig                         |   8 +
 drivers/timer/Makefile                        |   1 +
 drivers/timer/xilinx-timer.c                  |  82 ++++++++
 10 files changed, 99 insertions(+), 369 deletions(-)
 delete mode 100644 arch/microblaze/cpu/timer.c
 delete mode 100644 arch/microblaze/include/asm/microblaze_intc.h
 delete mode 100644 arch/microblaze/include/asm/microblaze_timer.h
 create mode 100644 drivers/timer/xilinx-timer.c
Signature · 1 line
2.36.1
author maintainer
#4 lore raw

PATCH 2/2 microblaze: Remove interrupt handler

The primary purpose for this code was timer. By converting it to CONFIG_TIMER there is no code which uses this implementation that's why remove it. If there is a need to handle interrupts this patch can be reverted in future.

---

 arch/Kconfig                                  |   1 -
 arch/microblaze/cpu/interrupts.c              | 182 +-----------------
 arch/microblaze/include/asm/microblaze_intc.h |  37 ----
 3 files changed, 1 insertion(+), 219 deletions(-)
 delete mode 100644 arch/microblaze/include/asm/microblaze_intc.h
arch/Kconfig +0 -1
index 3d02d8e71afa..a8d0123b8106 100644
@@ -74,7 +74,6 @@ config M68K
 config MICROBLAZE
 	bool "MicroBlaze architecture"
 	select SUPPORT_OF_CONTROL
-	imply CMD_IRQ
 	imply CMD_TIMER
 	imply SPL_REGMAP if SPL
 	imply SPL_TIMER if SPL
arch/microblaze/cpu/interrupts.c +1 -181

201 lines not on this page · raw message

arch/microblaze/include/asm/microblaze_intc.h deleted +0 -37
deleted file mode 100644
index a7e8715851ea..000000000000
@@ -1,37 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
-/*
- * (C) Copyright 2007 Michal Simek
- *
- * Michal  SIMEK <[email protected]>
- */
-
-#include <irq_func.h>
-
-typedef volatile struct microblaze_intc_t {
-	int isr; /* interrupt status register */
-	int ipr; /* interrupt pending register */
-	int ier; /* interrupt enable register */
-	int iar; /* interrupt acknowledge register */
-	int sie; /* set interrupt enable bits */
-	int cie; /* clear interrupt enable bits */
-	int ivr; /* interrupt vector register */
-	int mer; /* master enable register */
-} microblaze_intc_t;
-
-struct irq_action {
-	interrupt_handler_t *handler; /* pointer to interrupt rutine */
-	void *arg;
-	int count; /* number of interrupt */
-};
-
-/**
- * Register and unregister interrupt handler rutines
- *
- * @param irq	IRQ number
- * @param hdlr	Interrupt handler rutine
- * @param arg	Pointer to argument which is passed to int. handler rutine
- * Return:	0 if registration pass, 1 if unregistration pass,
- *		or an error code < 0 otherwise
- */
-int install_interrupt_handler(int irq, interrupt_handler_t *hdlr,
-				       void *arg);
Signature · 1 line
2.36.1
author maintainer
#1 lore raw

PATCH 1/2 microblaze: Convert axi timer to DM driver

In reply to Michal Simek

Move axi timer driver from Microblaze to generic location. Origin implementation was irq based with counting down timer.

CONFIG_TIMER drivers are designed differently that timer is free running up timer with automatic reload without any interrupt.
Information about clock rates are find out in timer_pre_probe() that's why there is no need to get any additional information from DT in the driver itself (only register offset).

---

 MAINTAINERS                                   |   1 +
 arch/Kconfig                                  |   5 +
 arch/microblaze/cpu/Makefile                  |   2 +-
 arch/microblaze/cpu/timer.c                   | 123 ------------------
 .../microblaze/include/asm/microblaze_timer.h |  26 ----
 drivers/timer/Kconfig                         |   8 ++
 drivers/timer/Makefile                        |   1 +
 drivers/timer/xilinx-timer.c                  |  82 ++++++++++++
 8 files changed, 98 insertions(+), 150 deletions(-)
 delete mode 100644 arch/microblaze/cpu/timer.c
 delete mode 100644 arch/microblaze/include/asm/microblaze_timer.h
 create mode 100644 drivers/timer/xilinx-timer.c
MAINTAINERS +1 -0
index 28e4d3823861..a18762573d93 100644
@@ -975,6 +975,7 @@ F:	drivers/net/xilinx_emaclite.c
 F:	drivers/serial/serial_xuartlite.c
 F:	drivers/spi/xilinx_spi.c
 F:	drivers/sysreset/sysreset_gpio.c
+F:	drivers/timer/xilinx-timer.c
 F:	drivers/watchdog/xilinx_tb_wdt.c
 N:	xilinx
 
arch/Kconfig +5 -0
index d91475d24747..3d02d8e71afa 100644
@@ -75,6 +75,11 @@ config MICROBLAZE
 	bool "MicroBlaze architecture"
 	select SUPPORT_OF_CONTROL
 	imply CMD_IRQ
+	imply CMD_TIMER
+	imply SPL_REGMAP if SPL
+	imply SPL_TIMER if SPL
+	imply TIMER
+	imply XILINX_TIMER
 
 config MIPS
 	bool "MIPS architecture"
arch/microblaze/cpu/Makefile +1 -1
index ea65a0976eec..1c586a7de023 100644
@@ -5,7 +5,7 @@
 
 extra-y	= start.o
 obj-y	= irq.o
-obj-y	+= interrupts.o cache.o exception.o timer.o cpuinfo.o
+obj-y	+= interrupts.o cache.o exception.o cpuinfo.o
 obj-$(CONFIG_STATIC_RELA)	+= relocate.o
 obj-$(CONFIG_XILINX_MICROBLAZE0_PVR) += pvr.o
 obj-$(CONFIG_SPL_BUILD)	+= spl.o
arch/microblaze/cpu/timer.c deleted +0 -123

123 lines not on this page · raw message

arch/microblaze/include/asm/microblaze_timer.h deleted +0 -26
deleted file mode 100644
index 2ed1651ffcfa..000000000000
@@ -1,26 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
-/*
- * (C) Copyright 2007 Michal Simek
- *
- * Michal  SIMEK <[email protected]>
- */
-
-#define TIMER_ENABLE_ALL    0x400 /* ENALL */
-#define TIMER_PWM           0x200 /* PWMA0 */
-#define TIMER_INTERRUPT     0x100 /* T0INT */
-#define TIMER_ENABLE        0x080 /* ENT0 */
-#define TIMER_ENABLE_INTR   0x040 /* ENIT0 */
-#define TIMER_RESET         0x020 /* LOAD0 */
-#define TIMER_RELOAD        0x010 /* ARHT0 */
-#define TIMER_EXT_CAPTURE   0x008 /* CAPT0 */
-#define TIMER_EXT_COMPARE   0x004 /* GENT0 */
-#define TIMER_DOWN_COUNT    0x002 /* UDT0 */
-#define TIMER_CAPTURE_MODE  0x001 /* MDT0 */
-
-typedef volatile struct microblaze_timer_t {
-	int control; /* control/statuc register TCSR */
-	int loadreg; /* load register TLR */
-	int counter; /* timer/counter register */
-} microblaze_timer_t;
-
-int timer_init(void);
drivers/timer/Kconfig +8 -0
index 7b8ab56ed323..44d1a81bad3d 100644
@@ -272,4 +272,12 @@ config IMX_GPT_TIMER
 	  Select this to enable support for the timer found on
 	  NXP i.MX devices.
 
+config XILINX_TIMER
+	bool "Xilinx timer support"
+	depends on TIMER
+	select REGMAP
+	help
+	  Select this to enable support for the timer found on
+	  any Xilinx boards (axi timer).
+
 endmenu
drivers/timer/Makefile +1 -0
index b2f002d59789..4d06375317e1 100644
@@ -27,3 +27,4 @@ obj-$(CONFIG_X86_TSC_TIMER)	+= tsc_timer.o
 obj-$(CONFIG_MTK_TIMER)		+= mtk_timer.o
 obj-$(CONFIG_MCHP_PIT64B_TIMER)	+= mchp-pit64b-timer.o
 obj-$(CONFIG_IMX_GPT_TIMER)	+= imx-gpt-timer.o
+obj-$(CONFIG_XILINX_TIMER)	+= xilinx-timer.o
drivers/timer/xilinx-timer.c new file +82 -0

82 lines not on this page · raw message

Signature · 1 line
2.36.1
Tested-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] microblaze: Convert axi timer to DM driver

Hi Michal,

On 6/8/22 13:38, Michal Simek wrote:
[...]

drivers/timer/Kconfig config IMX_GPT_TIMER · line 278

Quoted 12 lines
drivers/timer/Kconfig +4 -0
index 7b8ab56ed323..44d1a81bad3d 100644
@@ -272,4 +272,12 @@ config IMX_GPT_TIMER
           Select this to enable support for the timer found on
           NXP i.MX devices.
 
+config XILINX_TIMER
+       bool "Xilinx timer support"
+       depends on TIMER
+       select REGMAP

I think the SPL select should also be added:

       select SPL_REGMAP if SPL

This will fix the spl link errors with the following config:

CONFIG_TIMER=y

CONFIG_SPL_TIMER=y

CONFIG_XILINX_TIMER=y

...

microblazeel-linux-ld.bfd: drivers/timer/xilinx-timer.o: in function `xilinx_timer_get_count':
drivers/timer/xilinx-timer.c:41: undefined reference to regmap_read' microblazeel-linux-ld.bfd: drivers/timer/xilinx-timer.o: in function xilinx_timer_probe':
drivers/timer/xilinx-timer.c:52: undefined reference to regmap_init_mem' microblazeel-linux-ld.bfd: drivers/timer/xilinx-timer.c:58: undefined reference to regmap_write' microblazeel-linux-ld.bfd: drivers/timer/xilinx-timer.c:59: undefined reference to regmap_write' microblazeel-linux-ld.bfd: drivers/timer/xilinx-timer.c:60: undefined reference to regmap_write' make[1]: *** [scripts/Makefile.spl:525: spl/u-boot-spl] Error 1

Thanks,

Ovidiu

Quoted 105 lines
drivers/timer/Kconfig +4 -0
+       help
+         Select this to enable support for the timer found on
+         any Xilinx boards (axi timer).
+
  endmenu
drivers/timer/Makefile +1 -0
index b2f002d59789..4d06375317e1 100644
@@ -27,3 +27,4 @@ obj-$(CONFIG_X86_TSC_TIMER)   += tsc_timer.o
  obj-$(CONFIG_MTK_TIMER)                += mtk_timer.o
  obj-$(CONFIG_MCHP_PIT64B_TIMER)        += mchp-pit64b-timer.o
  obj-$(CONFIG_IMX_GPT_TIMER)    += imx-gpt-timer.o
+obj-$(CONFIG_XILINX_TIMER)     += xilinx-timer.o
drivers/timer/xilinx-timer.c new file +82 -1
new file mode 100644
index 000000000000..75b4473b6397
@@ -0,0 +1,82 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2022 Advanced Micro Devices, Inc
+ * Michal Simek <[email protected]>
+ *
+ * (C) Copyright 2007 Michal Simek
+ * Michal SIMEK <[email protected]>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <timer.h>
+#include <regmap.h>
+#include <dm/device_compat.h>
+
+#define TIMER_ENABLE_ALL    0x400 /* ENALL */
+#define TIMER_PWM           0x200 /* PWMA0 */
+#define TIMER_INTERRUPT     0x100 /* T0INT */
+#define TIMER_ENABLE        0x080 /* ENT0 */
+#define TIMER_ENABLE_INTR   0x040 /* ENIT0 */
+#define TIMER_RESET         0x020 /* LOAD0 */
+#define TIMER_RELOAD        0x010 /* ARHT0 */
+#define TIMER_EXT_CAPTURE   0x008 /* CAPT0 */
+#define TIMER_EXT_COMPARE   0x004 /* GENT0 */
+#define TIMER_DOWN_COUNT    0x002 /* UDT0 */
+#define TIMER_CAPTURE_MODE  0x001 /* MDT0 */
+
+#define TIMER_CONTROL_OFFSET   0
+#define TIMER_LOADREG_OFFSET   4
+#define TIMER_COUNTER_OFFSET   8
+
+struct xilinx_timer_priv {
+       struct regmap *regs;
+};
+
+static u64 xilinx_timer_get_count(struct udevice *dev)
+{
+       struct xilinx_timer_priv *priv = dev_get_priv(dev);
+       u32 value;
+
+       regmap_read(priv->regs, TIMER_COUNTER_OFFSET, &value);
+
+       return value;
+}
+
+static int xilinx_timer_probe(struct udevice *dev)
+{
+       struct xilinx_timer_priv *priv = dev_get_priv(dev);
+       int ret;
+
+       /* uc_priv->clock_rate has already clock rate */
+       ret = regmap_init_mem(dev_ofnode(dev), &priv->regs);
+       if (ret) {
+               dev_dbg(dev, "failed to get regbase of timer\n");
+               return ret;
+       }
+
+       regmap_write(priv->regs, TIMER_LOADREG_OFFSET, 0);
+       regmap_write(priv->regs, TIMER_CONTROL_OFFSET, TIMER_RESET);
+       regmap_write(priv->regs, TIMER_CONTROL_OFFSET,
+                    TIMER_ENABLE | TIMER_RELOAD);
+
+       return 0;
+}
+
+static const struct timer_ops xilinx_timer_ops = {
+       .get_count = xilinx_timer_get_count,
+};
+
+static const struct udevice_id xilinx_timer_ids[] = {
+       { .compatible = "xlnx,xps-timer-1.00.a" },
+       {}
+};
+
+U_BOOT_DRIVER(xilinx_timer) = {
+       .name = "xilinx_timer",
+       .id = UCLASS_TIMER,
+       .of_match = xilinx_timer_ids,
+       .priv_auto = sizeof(struct xilinx_timer_priv),
+       .probe = xilinx_timer_probe,
+       .ops = &xilinx_timer_ops,
+};
--

2.36.1

maintainer
#3 lore raw

Re: [PATCH 1/2] microblaze: Convert axi timer to DM driver

Quoted 23 lines · Ovidiu Panait

CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.

Hi Michal,

On 6/8/22 13:38, Michal Simek wrote:
[...]

Quoted 8 lines
drivers/timer/Kconfig +0 -0
index 7b8ab56ed323..44d1a81bad3d 100644
@@ -272,4 +272,12 @@ config IMX_GPT_TIMER

           Select this to enable support for the timer found on NXP i.MX devices.

Quoted 4 lines

+config XILINX_TIMER
+       bool "Xilinx timer support"
+       depends on TIMER
+       select REGMAP

Quoted 4 lines

I think the SPL select should also be added:

       select SPL_REGMAP if SPL

No problem with it. Patch sent.

Thanks,
Michal

author maintainer Applied
#5 lore raw
In reply to Michal Simek

st 8. 6. 2022 v 12:39 odesílatel Michal Simek <[email protected]> napsal:

Quoted 32 lines

Hi,

this series is moving timer to generic drivers/timer/ location and it is removing unused interrupt code in architecture.

note: This patchset is based on rela and cache series.

Thanks,
Michal

Michal Simek (2):
microblaze: Convert axi timer to DM driver
microblaze: Remove interrupt handler

 MAINTAINERS                                   |   1 +
 arch/Kconfig                                  |   6 +-
 arch/microblaze/cpu/Makefile                  |   2 +-
 arch/microblaze/cpu/interrupts.c              | 182 +-----------------
 arch/microblaze/cpu/timer.c                   | 123 ------------
 arch/microblaze/include/asm/microblaze_intc.h |  37 ----
 .../microblaze/include/asm/microblaze_timer.h |  26 ---
 drivers/timer/Kconfig                         |   8 +
 drivers/timer/Makefile                        |   1 +
 drivers/timer/xilinx-timer.c                  |  82 ++++++++
 10 files changed, 99 insertions(+), 369 deletions(-)
 delete mode 100644 arch/microblaze/cpu/timer.c
 delete mode 100644 arch/microblaze/include/asm/microblaze_intc.h
 delete mode 100644 arch/microblaze/include/asm/microblaze_timer.h
 create mode 100644 drivers/timer/xilinx-timer.c
Quoted 3 lines

--
2.36.1

Applied.
M

Signature · 5 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Xilinx Microblaze
Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs
U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs