linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/2] clocksource: loongson2_hpet: add hpet driver support
@ 2022-09-30  9:35 Yinbo Zhu
  2022-09-30  9:35 ` [PATCH v1 2/2] dt-bindings: hpet: add loongson2k hpet binding Yinbo Zhu
  2022-09-30 14:43 ` [PATCH v1 1/2] clocksource: loongson2_hpet: add hpet driver support WANG Xuerui
  0 siblings, 2 replies; 7+ messages in thread
From: Yinbo Zhu @ 2022-09-30  9:35 UTC (permalink / raw)
  To: Daniel Lezcano, Thomas Gleixner, Rob Herring,
	Krzysztof Kozlowski, Huacai Chen, WANG Xuerui, Jiaxun Yang,
	Jianmin Lv, Yun Liu, Yang Li, linux-kernel, devicetree,
	loongarch, Yinbo Zhu

HPET (High Precision Event Timer) defines a new set of timers, which
are used by the operating system to schedule threads, interrupt the
kernel and interrupt the multimedia timer server. The operating
system can assign different timers to different applications. By
configuration, each timer can generate interrupt independently.

The loongson2 HPET module includes a main count and three comparators
, all of which are 32 bits wide. Among the three comparators, only
one comparator supports periodic interrupt, all three comparators
support non periodic interrupts.

Signed-off-by: Yinbo Zhu <zhuyinbo@loongson.cn>
---
 MAINTAINERS                          |   6 +
 arch/loongarch/kernel/time.c         |   3 +
 drivers/clocksource/Kconfig          |   9 +
 drivers/clocksource/Makefile         |   1 +
 drivers/clocksource/loongson2_hpet.c | 332 +++++++++++++++++++++++++++
 5 files changed, 351 insertions(+)
 create mode 100644 drivers/clocksource/loongson2_hpet.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 0be0f520c032..c2e8eac61642 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11907,6 +11907,12 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/thermal/loongson,ls2k-thermal.yaml
 F:	drivers/thermal/loongson2_thermal.c
 
+LOONGSON2 SOC SERIES HPET DRIVER
+M:	Yinbo Zhu <zhuyinbo@loongson.cn>
+L:	linux-kernel@vger.kernel.org
+S:	Maintained
+F:	drivers/clocksource/loongson2_hpet.c
+
 LSILOGIC MPT FUSION DRIVERS (FC/SAS/SPI)
 M:	Sathya Prakash <sathya.prakash@broadcom.com>
 M:	Sreekanth Reddy <sreekanth.reddy@broadcom.com>
diff --git a/arch/loongarch/kernel/time.c b/arch/loongarch/kernel/time.c
index 786735dcc8d6..74f34c74679a 100644
--- a/arch/loongarch/kernel/time.c
+++ b/arch/loongarch/kernel/time.c
@@ -214,6 +214,9 @@ int __init constant_clocksource_init(void)
 
 void __init time_init(void)
 {
+#ifdef CONFIG_TIMER_PROBE
+	timer_probe();
+#endif
 	if (!cpu_has_cpucfg)
 		const_clock_freq = cpu_clock_freq;
 	else
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index 4f2bb7315b67..1c7ab3541d81 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -721,4 +721,13 @@ config GOLDFISH_TIMER
 	help
 	  Support for the timer/counter of goldfish-rtc
 
+config LOONGSON2_HPET
+	bool "Loongson2 High Precision Event Timer (HPET)"
+	select TIMER_PROBE
+	select TIMER_OF
+	help
+	  This option enables Loongson2 High Precision Event Timer
+	  (HPET) module driver. It supports the oneshot, the periodic
+	  modes and high resolution. It is used as a clocksource and
+	  a clockevent.
 endmenu
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index 64ab547de97b..1a3abb770f11 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -88,3 +88,4 @@ obj-$(CONFIG_MICROCHIP_PIT64B)		+= timer-microchip-pit64b.o
 obj-$(CONFIG_MSC313E_TIMER)		+= timer-msc313e.o
 obj-$(CONFIG_GOLDFISH_TIMER)		+= timer-goldfish.o
 obj-$(CONFIG_GXP_TIMER)			+= timer-gxp.o
+obj-$(CONFIG_LOONGSON2_HPET)		+= loongson2_hpet.o
diff --git a/drivers/clocksource/loongson2_hpet.c b/drivers/clocksource/loongson2_hpet.c
new file mode 100644
index 000000000000..5525edd255eb
--- /dev/null
+++ b/drivers/clocksource/loongson2_hpet.c
@@ -0,0 +1,332 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Author: Yinbo Zhu <zhuyinbo@loongson.cn>
+ * Copyright (C) 2022-2023 Loongson Technology Corporation Limited
+ */
+
+#include <linux/init.h>
+#include <linux/percpu.h>
+#include <linux/delay.h>
+#include <linux/spinlock.h>
+#include <linux/interrupt.h>
+#include <asm/time.h>
+#include <linux/of_irq.h>
+#include <linux/of_address.h>
+
+/* HPET regs */
+#define HPET_CFG                0x010
+#define HPET_STATUS             0x020
+#define HPET_COUNTER            0x0f0
+#define HPET_T0_IRS             0x001
+#define HPET_T0_CFG             0x100
+#define HPET_T0_CMP             0x108
+#define HPET_CFG_ENABLE         0x001
+#define HPET_TN_LEVEL           0x0002
+#define HPET_TN_ENABLE          0x0004
+#define HPET_TN_PERIODIC        0x0008
+#define HPET_TN_SETVAL          0x0040
+#define HPET_TN_32BIT           0x0100
+
+#define HPET_MIN_CYCLES		16
+#define HPET_MIN_PROG_DELTA	(HPET_MIN_CYCLES * 12)
+#define HPET_COMPARE_VAL	((hpet_freq + HZ / 2) / HZ)
+
+void __iomem			*hpet_mmio_base;
+unsigned int			hpet_freq;
+unsigned int			hpet_t0_irq;
+unsigned int			hpet_irq_flags;
+unsigned int			hpet_t0_cfg;
+
+static DEFINE_SPINLOCK(hpet_lock);
+DEFINE_PER_CPU(struct clock_event_device, hpet_clockevent_device);
+
+static int hpet_read(int offset)
+{
+	return readl(hpet_mmio_base + offset);
+}
+
+static void hpet_write(int offset, int data)
+{
+	writel(data, hpet_mmio_base + offset);
+}
+
+static void hpet_start_counter(void)
+{
+	unsigned int cfg = hpet_read(HPET_CFG);
+
+	cfg |= HPET_CFG_ENABLE;
+	hpet_write(HPET_CFG, cfg);
+}
+
+static void hpet_stop_counter(void)
+{
+	unsigned int cfg = hpet_read(HPET_CFG);
+
+	cfg &= ~HPET_CFG_ENABLE;
+	hpet_write(HPET_CFG, cfg);
+}
+
+static void hpet_reset_counter(void)
+{
+	hpet_write(HPET_COUNTER, 0);
+	hpet_write(HPET_COUNTER + 4, 0);
+}
+
+static void hpet_restart_counter(void)
+{
+	hpet_stop_counter();
+	hpet_reset_counter();
+	hpet_start_counter();
+}
+
+static void hpet_enable_legacy_int(void)
+{
+	/* Do nothing on Loongson2 */
+}
+
+static int hpet_set_state_periodic(struct clock_event_device *evt)
+{
+	int cfg;
+
+	spin_lock(&hpet_lock);
+
+	pr_info("set clock event to periodic mode!\n");
+	/* stop counter */
+	hpet_stop_counter();
+	hpet_reset_counter();
+	hpet_write(HPET_T0_CMP, 0);
+
+	/* enables the timer0 to generate a periodic interrupt */
+	cfg = hpet_read(HPET_T0_CFG);
+	cfg &= ~HPET_TN_LEVEL;
+	cfg |= HPET_TN_ENABLE | HPET_TN_PERIODIC | HPET_TN_SETVAL |
+		HPET_TN_32BIT | hpet_irq_flags;
+	hpet_write(HPET_T0_CFG, cfg);
+
+	/* set the comparator */
+	hpet_write(HPET_T0_CMP, HPET_COMPARE_VAL);
+	udelay(1);
+	hpet_write(HPET_T0_CMP, HPET_COMPARE_VAL);
+
+	/* start counter */
+	hpet_start_counter();
+
+	spin_unlock(&hpet_lock);
+	return 0;
+}
+
+static int hpet_set_state_shutdown(struct clock_event_device *evt)
+{
+	int cfg;
+
+	spin_lock(&hpet_lock);
+
+	cfg = hpet_read(HPET_T0_CFG);
+	cfg &= ~HPET_TN_ENABLE;
+	hpet_write(HPET_T0_CFG, cfg);
+
+	spin_unlock(&hpet_lock);
+	return 0;
+}
+
+static int hpet_set_state_oneshot(struct clock_event_device *evt)
+{
+	int cfg;
+
+	spin_lock(&hpet_lock);
+
+	pr_info("set clock event to one shot mode!\n");
+	cfg = hpet_read(HPET_T0_CFG);
+	/*
+	 * set timer0 type
+	 * 1 : periodic interrupt
+	 * 0 : non-periodic(oneshot) interrupt
+	 */
+	cfg &= ~HPET_TN_PERIODIC;
+	cfg |= HPET_TN_ENABLE | HPET_TN_32BIT |
+		hpet_irq_flags;
+	hpet_write(HPET_T0_CFG, cfg);
+
+	/* start counter */
+	hpet_start_counter();
+
+	spin_unlock(&hpet_lock);
+	return 0;
+}
+
+static int hpet_tick_resume(struct clock_event_device *evt)
+{
+	spin_lock(&hpet_lock);
+	hpet_enable_legacy_int();
+	spin_unlock(&hpet_lock);
+
+	return 0;
+}
+
+static int hpet_next_event(unsigned long delta,
+		struct clock_event_device *evt)
+{
+	u32 cnt;
+	s32 res;
+
+	cnt = hpet_read(HPET_COUNTER);
+	cnt += (u32) delta;
+	hpet_write(HPET_T0_CMP, cnt);
+
+	res = (s32)(cnt - hpet_read(HPET_COUNTER));
+
+	return res < HPET_MIN_CYCLES ? -ETIME : 0;
+}
+
+static irqreturn_t hpet_irq_handler(int irq, void *data)
+{
+	int is_irq;
+	struct clock_event_device *cd;
+	unsigned int cpu = smp_processor_id();
+
+	is_irq = hpet_read(HPET_STATUS);
+	if (is_irq & HPET_T0_IRS) {
+		/* clear the TIMER0 irq status register */
+		hpet_write(HPET_STATUS, HPET_T0_IRS);
+		cd = &per_cpu(hpet_clockevent_device, cpu);
+		cd->event_handler(cd);
+		return IRQ_HANDLED;
+	}
+	return IRQ_NONE;
+}
+
+static struct irqaction hpet_irq_str = {
+	.handler = hpet_irq_handler,
+	.flags = IRQD_NO_BALANCING | IRQF_TIMER,
+	.name = "hpet",
+};
+
+/*
+ * HPET address assignation and irq setting should be done in bios.
+ * But, sometimes bios don't do this, we just setup here directly.
+ */
+static void hpet_setup(void)
+{
+	hpet_enable_legacy_int();
+}
+
+static int hpet_setup_irq(struct clock_event_device *cd)
+{
+	setup_irq(cd->irq, &hpet_irq_str);
+
+	disable_irq(cd->irq);
+	irq_set_affinity(cd->irq, cd->cpumask);
+	enable_irq(cd->irq);
+
+	return 0;
+}
+
+static int __init loongson2_hpet_clockevent_init(void)
+{
+	unsigned int cpu = smp_processor_id();
+	struct clock_event_device *cd;
+
+	hpet_setup();
+
+	cd = &per_cpu(hpet_clockevent_device, cpu);
+	cd->name = "hpet";
+	cd->rating = 300;
+	cd->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
+	cd->set_state_shutdown = hpet_set_state_shutdown;
+	cd->set_state_periodic = hpet_set_state_periodic;
+	cd->set_state_oneshot = hpet_set_state_oneshot;
+	cd->tick_resume = hpet_tick_resume;
+	cd->set_next_event = hpet_next_event;
+	cd->irq = hpet_t0_irq;
+	cd->cpumask = cpumask_of(cpu);
+	clockevent_set_clock(cd, hpet_freq);
+	cd->max_delta_ns = clockevent_delta2ns(0x7fffffff, cd);
+	cd->max_delta_ticks = 0x7fffffff;
+	cd->min_delta_ns = clockevent_delta2ns(HPET_MIN_PROG_DELTA, cd);
+	cd->min_delta_ticks = HPET_MIN_PROG_DELTA;
+
+	clockevents_register_device(cd);
+	hpet_setup_irq(cd);
+
+	pr_info("hpet clock event device register\n");
+
+	return 0;
+}
+
+static u64 hpet_read_counter(struct clocksource *cs)
+{
+	return (u64)hpet_read(HPET_COUNTER);
+}
+
+static void hpet_suspend(struct clocksource *cs)
+{
+	hpet_t0_cfg = hpet_read(HPET_T0_CFG);
+}
+
+static void hpet_resume(struct clocksource *cs)
+{
+	hpet_write(HPET_T0_CFG, hpet_t0_cfg);
+	hpet_setup();
+	hpet_restart_counter();
+}
+
+struct clocksource csrc_hpet = {
+	.name = "hpet",
+	.rating = 300,
+	.read = hpet_read_counter,
+	.mask = CLOCKSOURCE_MASK(32),
+	/* oneshot mode work normal with this flag */
+	.flags = CLOCK_SOURCE_IS_CONTINUOUS,
+	.suspend = hpet_suspend,
+	.resume = hpet_resume,
+	.mult = 0,
+	.shift = 10,
+};
+
+static int __init loongson2_hpet_clocksource_init(void)
+{
+	csrc_hpet.mult = clocksource_hz2mult(hpet_freq, csrc_hpet.shift);
+
+	/* start counter */
+	hpet_start_counter();
+
+	return clocksource_register_hz(&csrc_hpet, hpet_freq);
+}
+
+static int __init loongson2_hpet_init(struct device_node *np)
+{
+	u32 clk;
+	int ret;
+
+	hpet_mmio_base = of_iomap(np, 0);
+	if (!hpet_mmio_base) {
+		pr_err("hpet: unable to map loongson2 hpet registers\n");
+		goto err;
+	}
+
+	ret = -EINVAL;
+	hpet_t0_irq = irq_of_parse_and_map(np, 0);
+	if (hpet_t0_irq <= 0) {
+		pr_err("hpet: unable to get IRQ from DT, %d\n", hpet_t0_irq);
+		goto err;
+	}
+
+	if (!of_property_read_u32(np, "clock-frequency", &clk))
+		hpet_freq = clk;
+	else
+		goto err;
+
+	hpet_irq_flags = HPET_TN_LEVEL;
+
+	loongson2_hpet_clocksource_init();
+
+	loongson2_hpet_clockevent_init();
+
+	return 0;
+
+err:
+	iounmap(hpet_mmio_base);
+	return ret;
+}
+
+TIMER_OF_DECLARE(loongson2_hpet, "loongson,ls2k-hpet", loongson2_hpet_init);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v1 2/2] dt-bindings: hpet: add loongson2k hpet binding
  2022-09-30  9:35 [PATCH v1 1/2] clocksource: loongson2_hpet: add hpet driver support Yinbo Zhu
@ 2022-09-30  9:35 ` Yinbo Zhu
  2022-09-30  9:58   ` Krzysztof Kozlowski
  2022-09-30 14:43 ` [PATCH v1 1/2] clocksource: loongson2_hpet: add hpet driver support WANG Xuerui
  1 sibling, 1 reply; 7+ messages in thread
From: Yinbo Zhu @ 2022-09-30  9:35 UTC (permalink / raw)
  To: Daniel Lezcano, Thomas Gleixner, Rob Herring,
	Krzysztof Kozlowski, Huacai Chen, WANG Xuerui, Jiaxun Yang,
	Jianmin Lv, Yun Liu, Yang Li, linux-kernel, devicetree,
	loongarch, Yinbo Zhu

Add the loongson2k High Precision Event Timer (HPET) binding
with DT schema format using json-schema.

Signed-off-by: Yinbo Zhu <zhuyinbo@loongson.cn>
---
 .../bindings/timer/loongson,ls2k-hpet.yaml    | 41 +++++++++++++++++++
 MAINTAINERS                                   |  1 +
 2 files changed, 42 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/timer/loongson,ls2k-hpet.yaml

diff --git a/Documentation/devicetree/bindings/timer/loongson,ls2k-hpet.yaml b/Documentation/devicetree/bindings/timer/loongson,ls2k-hpet.yaml
new file mode 100644
index 000000000000..1a8785076228
--- /dev/null
+++ b/Documentation/devicetree/bindings/timer/loongson,ls2k-hpet.yaml
@@ -0,0 +1,41 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/timer/loongson,ls2k-hpet.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Loongson2k High Precision Event Timer (HPET)
+
+maintainers:
+  - Yinbo Zhu <zhuyinbo@loongson.cn>
+
+properties:
+  compatible:
+    const: loongson,ls2k-hpet
+
+  reg:
+    maxItems: 1
+
+  clock-frequency: true
+
+  interrupts:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - clock-frequency
+  - interrupts
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    hpet0: hpet@1fe24000 {
+        compatible = "loongson,ls2k-hpet";
+        reg = <0x1fe24000 0x15f>;
+        clock-frequency = <125000000>;
+        interrupt-parent = <&liointc0>;
+        interrupts = <21 IRQ_TYPE_LEVEL_LOW>;
+    };
diff --git a/MAINTAINERS b/MAINTAINERS
index c2e8eac61642..a162b6fba6fe 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11911,6 +11911,7 @@ LOONGSON2 SOC SERIES HPET DRIVER
 M:	Yinbo Zhu <zhuyinbo@loongson.cn>
 L:	linux-kernel@vger.kernel.org
 S:	Maintained
+F:	Documentation/devicetree/bindings/timer/loongson,ls2k-hpet.yaml
 F:	drivers/clocksource/loongson2_hpet.c
 
 LSILOGIC MPT FUSION DRIVERS (FC/SAS/SPI)
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 2/2] dt-bindings: hpet: add loongson2k hpet binding
  2022-09-30  9:35 ` [PATCH v1 2/2] dt-bindings: hpet: add loongson2k hpet binding Yinbo Zhu
@ 2022-09-30  9:58   ` Krzysztof Kozlowski
  2022-10-08  3:21     ` Yinbo Zhu
  0 siblings, 1 reply; 7+ messages in thread
From: Krzysztof Kozlowski @ 2022-09-30  9:58 UTC (permalink / raw)
  To: Yinbo Zhu, Daniel Lezcano, Thomas Gleixner, Rob Herring,
	Krzysztof Kozlowski, Huacai Chen, WANG Xuerui, Jiaxun Yang,
	Jianmin Lv, Yun Liu, Yang Li, linux-kernel, devicetree,
	loongarch

On 30/09/2022 11:35, Yinbo Zhu wrote:
> Add the loongson2k High Precision Event Timer (HPET) binding
> with DT schema format using json-schema.
> 
> Signed-off-by: Yinbo Zhu <zhuyinbo@loongson.cn>
> ---
>  .../bindings/timer/loongson,ls2k-hpet.yaml    | 41 +++++++++++++++++++
>  MAINTAINERS                                   |  1 +
>  2 files changed, 42 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/timer/loongson,ls2k-hpet.yaml
> 
> diff --git a/Documentation/devicetree/bindings/timer/loongson,ls2k-hpet.yaml b/Documentation/devicetree/bindings/timer/loongson,ls2k-hpet.yaml
> new file mode 100644
> index 000000000000..1a8785076228
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/timer/loongson,ls2k-hpet.yaml
> @@ -0,0 +1,41 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/timer/loongson,ls2k-hpet.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Loongson2k High Precision Event Timer (HPET)
> +
> +maintainers:
> +  - Yinbo Zhu <zhuyinbo@loongson.cn>
> +
> +properties:
> +  compatible:
> +    const: loongson,ls2k-hpet
> +
> +  reg:
> +    maxItems: 1
> +
> +  clock-frequency: true

clock frequency of what? I assume it's too early to use common clock
framework and just get the clock?

> +
> +  interrupts:
> +    maxItems: 1
> +
> +required:
> +  - compatible
> +  - reg
> +  - clock-frequency
> +  - interrupts
> +
> +additionalProperties: false
> +
> +examples:
> +  - |
> +    #include <dt-bindings/interrupt-controller/irq.h>
> +    hpet0: hpet@1fe24000 {

Node name: timer
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation

You can drop the  "hpet0" label.


Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 1/2] clocksource: loongson2_hpet: add hpet driver support
  2022-09-30  9:35 [PATCH v1 1/2] clocksource: loongson2_hpet: add hpet driver support Yinbo Zhu
  2022-09-30  9:35 ` [PATCH v1 2/2] dt-bindings: hpet: add loongson2k hpet binding Yinbo Zhu
@ 2022-09-30 14:43 ` WANG Xuerui
  2022-10-08  2:59   ` Yinbo Zhu
  1 sibling, 1 reply; 7+ messages in thread
From: WANG Xuerui @ 2022-09-30 14:43 UTC (permalink / raw)
  To: Yinbo Zhu, Daniel Lezcano, Thomas Gleixner, Rob Herring,
	Krzysztof Kozlowski, Huacai Chen, Jiaxun Yang, Jianmin Lv,
	Yun Liu, Yang Li, linux-kernel, devicetree, loongarch

Hi,

On 9/30/22 17:35, Yinbo Zhu wrote:
> HPET (High Precision Event Timer) defines a new set of timers, which
> are used by the operating system to schedule threads, interrupt the
> kernel and interrupt the multimedia timer server. The operating
> system can assign different timers to different applications. By
> configuration, each timer can generate interrupt independently.
>
> The loongson2 HPET module includes a main count and three comparators
> , all of which are 32 bits wide. Among the three comparators, only
> one comparator supports periodic interrupt, all three comparators
> support non periodic interrupts.
>
> Signed-off-by: Yinbo Zhu <zhuyinbo@loongson.cn>
> ---
>   MAINTAINERS                          |   6 +
>   arch/loongarch/kernel/time.c         |   3 +
>   drivers/clocksource/Kconfig          |   9 +
>   drivers/clocksource/Makefile         |   1 +
>   drivers/clocksource/loongson2_hpet.c | 332 +++++++++++++++++++++++++++
>   5 files changed, 351 insertions(+)
>   create mode 100644 drivers/clocksource/loongson2_hpet.c

Thanks for the contribution, but as HPET is a fairly common peripheral 
that have well standardized behavior, why not simply add DT support to 
the drivers/char/hpet.c and be done with it?

-- 
WANG "xen0n" Xuerui

Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 1/2] clocksource: loongson2_hpet: add hpet driver support
  2022-09-30 14:43 ` [PATCH v1 1/2] clocksource: loongson2_hpet: add hpet driver support WANG Xuerui
@ 2022-10-08  2:59   ` Yinbo Zhu
  0 siblings, 0 replies; 7+ messages in thread
From: Yinbo Zhu @ 2022-10-08  2:59 UTC (permalink / raw)
  To: WANG Xuerui, Daniel Lezcano, Thomas Gleixner, Rob Herring,
	Krzysztof Kozlowski, Huacai Chen, Jiaxun Yang, Jianmin Lv,
	Yun Liu, Yang Li, linux-kernel, devicetree, loongarch, zhuyinbo



在 2022/9/30 下午10:43, WANG Xuerui 写道:
> Hi,
> 
> On 9/30/22 17:35, Yinbo Zhu wrote:
>> HPET (High Precision Event Timer) defines a new set of timers, which
>> are used by the operating system to schedule threads, interrupt the
>> kernel and interrupt the multimedia timer server. The operating
>> system can assign different timers to different applications. By
>> configuration, each timer can generate interrupt independently.
>>
>> The loongson2 HPET module includes a main count and three comparators
>> , all of which are 32 bits wide. Among the three comparators, only
>> one comparator supports periodic interrupt, all three comparators
>> support non periodic interrupts.
>>
>> Signed-off-by: Yinbo Zhu <zhuyinbo@loongson.cn>
>> ---
>>   MAINTAINERS                          |   6 +
>>   arch/loongarch/kernel/time.c         |   3 +
>>   drivers/clocksource/Kconfig          |   9 +
>>   drivers/clocksource/Makefile         |   1 +
>>   drivers/clocksource/loongson2_hpet.c | 332 +++++++++++++++++++++++++++
>>   5 files changed, 351 insertions(+)
>>   create mode 100644 drivers/clocksource/loongson2_hpet.c
> 
> Thanks for the contribution, but as HPET is a fairly common peripheral 
> that have well standardized behavior, why not simply add DT support to 
> the drivers/char/hpet.c and be done with it?
At present, the drivers/char/hpet.c doesn't support DT(dts parse) and
loongson2 soc wasn't belong to X86 or IA64 architecture, Although it is
an option to add DT support for this driver, I consider that the hpet
design of loongson2 series socs may not be universal. In addition, I
notice that mips and x86 have their own hpet drivers. In order to reduce
the impact on the public driver and make more flexible modifications to
the loongson2 hpet driver under its own architecture, a separate
loongson2 hpet driver was submitted.

config HPET
         bool "HPET - High Precision Event Timer" if (X86 || IA64)
         default n
         depends on ACPI
         help
           If you say Y here, you will have a miscdevice named 
"/dev/hpet/".  Each
           open selects one of the timers supported by the HPET.  The 
timers are
           non-periodic and/or periodic.


BRs
Yinbo Zhu.

> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 2/2] dt-bindings: hpet: add loongson2k hpet binding
  2022-09-30  9:58   ` Krzysztof Kozlowski
@ 2022-10-08  3:21     ` Yinbo Zhu
  2022-10-09 15:14       ` Krzysztof Kozlowski
  0 siblings, 1 reply; 7+ messages in thread
From: Yinbo Zhu @ 2022-10-08  3:21 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Daniel Lezcano, Thomas Gleixner,
	Rob Herring, Krzysztof Kozlowski, Huacai Chen, WANG Xuerui,
	Jiaxun Yang, Jianmin Lv, Yun Liu, Yang Li, linux-kernel,
	devicetree, loongarch, zhuyinbo



在 2022/9/30 下午5:58, Krzysztof Kozlowski 写道:
> On 30/09/2022 11:35, Yinbo Zhu wrote:
>> Add the loongson2k High Precision Event Timer (HPET) binding
>> with DT schema format using json-schema.
>>
>> Signed-off-by: Yinbo Zhu <zhuyinbo@loongson.cn>
>> ---
>>   .../bindings/timer/loongson,ls2k-hpet.yaml    | 41 +++++++++++++++++++
>>   MAINTAINERS                                   |  1 +
>>   2 files changed, 42 insertions(+)
>>   create mode 100644 Documentation/devicetree/bindings/timer/loongson,ls2k-hpet.yaml
>>
>> diff --git a/Documentation/devicetree/bindings/timer/loongson,ls2k-hpet.yaml b/Documentation/devicetree/bindings/timer/loongson,ls2k-hpet.yaml
>> new file mode 100644
>> index 000000000000..1a8785076228
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/timer/loongson,ls2k-hpet.yaml
>> @@ -0,0 +1,41 @@
>> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
>> +%YAML 1.2
>> +---
>> +$id: http://devicetree.org/schemas/timer/loongson,ls2k-hpet.yaml#
>> +$schema: http://devicetree.org/meta-schemas/core.yaml#
>> +
>> +title: Loongson2k High Precision Event Timer (HPET)
>> +
>> +maintainers:
>> +  - Yinbo Zhu <zhuyinbo@loongson.cn>
>> +
>> +properties:
>> +  compatible:
>> +    const: loongson,ls2k-hpet
>> +
>> +  reg:
>> +    maxItems: 1
>> +
>> +  clock-frequency: true
> 
> clock frequency of what? I assume it's too early to use common clock
> framework and just get the clock?
The clock-frequency is 125000000, It doesn't support use common clock 
framework and just get the clock from dts, and I refer 
"arm,armv7m-systick" to add the clock-frequency information:

   clock-frequency: true

oneOf:
   - required:
       - clocks
   - required:
       - clock-frequency
> 
>> +
>> +  interrupts:
>> +    maxItems: 1
>> +
>> +required:
>> +  - compatible
>> +  - reg
>> +  - clock-frequency
>> +  - interrupts
>> +
>> +additionalProperties: false
>> +
>> +examples:
>> +  - |
>> +    #include <dt-bindings/interrupt-controller/irq.h>
>> +    hpet0: hpet@1fe24000 {
> 
> Node name: timer
> https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation
> 
> You can drop the  "hpet0" label.
okay, I got it.
> 
> 
> Best regards,
> Krzysztof
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 2/2] dt-bindings: hpet: add loongson2k hpet binding
  2022-10-08  3:21     ` Yinbo Zhu
@ 2022-10-09 15:14       ` Krzysztof Kozlowski
  0 siblings, 0 replies; 7+ messages in thread
From: Krzysztof Kozlowski @ 2022-10-09 15:14 UTC (permalink / raw)
  To: Yinbo Zhu, Daniel Lezcano, Thomas Gleixner, Rob Herring,
	Krzysztof Kozlowski, Huacai Chen, WANG Xuerui, Jiaxun Yang,
	Jianmin Lv, Yun Liu, Yang Li, linux-kernel, devicetree,
	loongarch

On 08/10/2022 05:21, Yinbo Zhu wrote:
> 
> 
> 在 2022/9/30 下午5:58, Krzysztof Kozlowski 写道:
>> On 30/09/2022 11:35, Yinbo Zhu wrote:
>>> Add the loongson2k High Precision Event Timer (HPET) binding
>>> with DT schema format using json-schema.
>>>
>>> Signed-off-by: Yinbo Zhu <zhuyinbo@loongson.cn>
>>> ---
>>>   .../bindings/timer/loongson,ls2k-hpet.yaml    | 41 +++++++++++++++++++
>>>   MAINTAINERS                                   |  1 +
>>>   2 files changed, 42 insertions(+)
>>>   create mode 100644 Documentation/devicetree/bindings/timer/loongson,ls2k-hpet.yaml
>>>
>>> diff --git a/Documentation/devicetree/bindings/timer/loongson,ls2k-hpet.yaml b/Documentation/devicetree/bindings/timer/loongson,ls2k-hpet.yaml
>>> new file mode 100644
>>> index 000000000000..1a8785076228
>>> --- /dev/null
>>> +++ b/Documentation/devicetree/bindings/timer/loongson,ls2k-hpet.yaml
>>> @@ -0,0 +1,41 @@
>>> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
>>> +%YAML 1.2
>>> +---
>>> +$id: http://devicetree.org/schemas/timer/loongson,ls2k-hpet.yaml#
>>> +$schema: http://devicetree.org/meta-schemas/core.yaml#
>>> +
>>> +title: Loongson2k High Precision Event Timer (HPET)
>>> +
>>> +maintainers:
>>> +  - Yinbo Zhu <zhuyinbo@loongson.cn>
>>> +
>>> +properties:
>>> +  compatible:
>>> +    const: loongson,ls2k-hpet
>>> +
>>> +  reg:
>>> +    maxItems: 1
>>> +
>>> +  clock-frequency: true
>>
>> clock frequency of what? I assume it's too early to use common clock
>> framework and just get the clock?

Still you did not answer: which/what clock?

> The clock-frequency is 125000000, It doesn't support use common clock 
> framework 

But it should use CCF, if possible.

> and just get the clock from dts, and I refer 

How do you "get" the clock from DTS?

> "arm,armv7m-systick" to add the clock-frequency information:

Better go with Common Clock Framework instead.

> 
>    clock-frequency: true
> 
> oneOf:
>    - required:
>        - clocks
>    - required:
>        - clock-frequency
>>

Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-10-09 15:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-30  9:35 [PATCH v1 1/2] clocksource: loongson2_hpet: add hpet driver support Yinbo Zhu
2022-09-30  9:35 ` [PATCH v1 2/2] dt-bindings: hpet: add loongson2k hpet binding Yinbo Zhu
2022-09-30  9:58   ` Krzysztof Kozlowski
2022-10-08  3:21     ` Yinbo Zhu
2022-10-09 15:14       ` Krzysztof Kozlowski
2022-09-30 14:43 ` [PATCH v1 1/2] clocksource: loongson2_hpet: add hpet driver support WANG Xuerui
2022-10-08  2:59   ` Yinbo Zhu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).