From 30382096955a955d681f8059927061b010c2a509 Mon Sep 17 00:00:00 2001 From: "Charles E. Youse" Date: Wed, 11 Sep 2019 16:45:43 -0400 Subject: [PATCH] drivers/timer/hpet.c: migrate to devicetree This driver was still using CONFIG_* values to determine its address, IRQ, etc. Add a binding for an "intel,hpet" device and migrate this driver to devicetree. Fixes: #18657 Signed-off-by: Charles E. Youse --- boards/x86/minnowboard/minnowboard.dts | 3 +++ boards/x86/minnowboard/minnowboard_defconfig | 1 - boards/x86/qemu_x86/qemu_x86.dts | 4 ++++ .../x86/qemu_x86/qemu_x86_coverage_defconfig | 1 - boards/x86/qemu_x86/qemu_x86_defconfig | 1 - boards/x86/qemu_x86/qemu_x86_nommu_defconfig | 1 - boards/x86/up_squared/Kconfig.defconfig | 7 ------- drivers/timer/Kconfig | 21 ------------------- drivers/timer/hpet.c | 9 ++++---- dts/bindings/timer/intel,hpet.yaml | 18 ++++++++++++++++ dts/x86/apollo_lake.dtsi | 10 +++++++++ dts/x86/atom.dtsi | 10 +++++++++ dts/x86/ia32.dtsi | 11 +++++++++- soc/x86/apollo_lake/soc.c | 2 +- soc/x86/atom/soc.c | 2 +- soc/x86/ia32/soc.c | 3 ++- tests/kernel/context/src/main.c | 2 +- 17 files changed, 65 insertions(+), 41 deletions(-) create mode 100644 dts/bindings/timer/intel,hpet.yaml diff --git a/boards/x86/minnowboard/minnowboard.dts b/boards/x86/minnowboard/minnowboard.dts index 75ae0944a01..0477520053c 100644 --- a/boards/x86/minnowboard/minnowboard.dts +++ b/boards/x86/minnowboard/minnowboard.dts @@ -39,3 +39,6 @@ current-speed = <115200>; }; +&hpet { + status = "okay"; +}; diff --git a/boards/x86/minnowboard/minnowboard_defconfig b/boards/x86/minnowboard/minnowboard_defconfig index 79b9eb426d3..a590205ef82 100644 --- a/boards/x86/minnowboard/minnowboard_defconfig +++ b/boards/x86/minnowboard/minnowboard_defconfig @@ -5,7 +5,6 @@ CONFIG_SOC_ATOM=y CONFIG_BOARD_MINNOWBOARD=y CONFIG_CPU_ATOM=y CONFIG_HPET_TIMER=y -CONFIG_HPET_TIMER_IRQ=2 CONFIG_PIC_DISABLE=y CONFIG_LOAPIC=y CONFIG_CONSOLE=y diff --git a/boards/x86/qemu_x86/qemu_x86.dts b/boards/x86/qemu_x86/qemu_x86.dts index 6eda4fc46ee..1f6af0db321 100644 --- a/boards/x86/qemu_x86/qemu_x86.dts +++ b/boards/x86/qemu_x86/qemu_x86.dts @@ -73,6 +73,10 @@ current-speed = <115200>; }; +&hpet { + status = "okay"; +}; + &flash_sim0 { /* * For more information, see: diff --git a/boards/x86/qemu_x86/qemu_x86_coverage_defconfig b/boards/x86/qemu_x86/qemu_x86_coverage_defconfig index 565342117a5..fc9f4a38cc8 100644 --- a/boards/x86/qemu_x86/qemu_x86_coverage_defconfig +++ b/boards/x86/qemu_x86/qemu_x86_coverage_defconfig @@ -5,7 +5,6 @@ CONFIG_SOC_IA32=y CONFIG_BOARD_QEMU_X86=y CONFIG_CPU_MINUTEIA=y CONFIG_HPET_TIMER=y -CONFIG_HPET_TIMER_IRQ=2 CONFIG_PIC_DISABLE=y CONFIG_LOAPIC=y CONFIG_CONSOLE=y diff --git a/boards/x86/qemu_x86/qemu_x86_defconfig b/boards/x86/qemu_x86/qemu_x86_defconfig index 441efc1f4d4..efcb9273546 100644 --- a/boards/x86/qemu_x86/qemu_x86_defconfig +++ b/boards/x86/qemu_x86/qemu_x86_defconfig @@ -5,7 +5,6 @@ CONFIG_SOC_IA32=y CONFIG_BOARD_QEMU_X86=y CONFIG_CPU_MINUTEIA=y CONFIG_HPET_TIMER=y -CONFIG_HPET_TIMER_IRQ=2 CONFIG_PIC_DISABLE=y CONFIG_LOAPIC=y CONFIG_CONSOLE=y diff --git a/boards/x86/qemu_x86/qemu_x86_nommu_defconfig b/boards/x86/qemu_x86/qemu_x86_nommu_defconfig index b1a1f58762b..52a083cc130 100644 --- a/boards/x86/qemu_x86/qemu_x86_nommu_defconfig +++ b/boards/x86/qemu_x86/qemu_x86_nommu_defconfig @@ -5,7 +5,6 @@ CONFIG_SOC_IA32=y CONFIG_BOARD_QEMU_X86=y CONFIG_CPU_MINUTEIA=y CONFIG_HPET_TIMER=y -CONFIG_HPET_TIMER_IRQ=2 CONFIG_PIC_DISABLE=y CONFIG_LOAPIC=y CONFIG_CONSOLE=y diff --git a/boards/x86/up_squared/Kconfig.defconfig b/boards/x86/up_squared/Kconfig.defconfig index fc44730d9b4..e091108e233 100644 --- a/boards/x86/up_squared/Kconfig.defconfig +++ b/boards/x86/up_squared/Kconfig.defconfig @@ -31,13 +31,6 @@ endif # I2C config APIC_TIMER default y if !HPET_TIMER -if HPET_TIMER - -config HPET_TIMER_IRQ - default 2 - -endif # HPET_TIMER - if APIC_TIMER config APIC_TIMER_IRQ diff --git a/drivers/timer/Kconfig b/drivers/timer/Kconfig index 7c680718120..ad5da1be01c 100644 --- a/drivers/timer/Kconfig +++ b/drivers/timer/Kconfig @@ -69,27 +69,6 @@ menuconfig HPET_TIMER This option selects High Precision Event Timer (HPET) as a system timer. -if HPET_TIMER -config HPET_TIMER_BASE_ADDRESS - hex "HPET Base Address" - default 0xFED00000 - help - This options specifies the base address of the HPET timer device. - -config HPET_TIMER_IRQ - int "HPET Timer IRQ" - default 2 - help - This option specifies the IRQ used by the HPET timer. - -config HPET_TIMER_IRQ_PRIORITY - int "HPET Timer IRQ Priority" - default 4 - help - This option specifies the IRQ priority used by the HPET timer. - -endif #HPET_TIMER - menuconfig LOAPIC_TIMER bool "LOAPIC timer" depends on LOAPIC && X86 diff --git a/drivers/timer/hpet.c b/drivers/timer/hpet.c index 3f08e096cf2..1e77b2509a0 100644 --- a/drivers/timer/hpet.c +++ b/drivers/timer/hpet.c @@ -8,7 +8,7 @@ #include #define HPET_REG32(off) (*(volatile u32_t *)(long) \ - (CONFIG_HPET_TIMER_BASE_ADDRESS + (off))) + (DT_INST_0_INTEL_HPET_BASE_ADDRESS + (off))) #define CLK_PERIOD_REG HPET_REG32(0x04) /* High dword of caps reg */ #define GENERAL_CONF_REG HPET_REG32(0x10) @@ -69,10 +69,11 @@ int z_clock_driver_init(struct device *device) extern int z_clock_hw_cycles_per_sec; u32_t hz; - IRQ_CONNECT(CONFIG_HPET_TIMER_IRQ, CONFIG_HPET_TIMER_IRQ_PRIORITY, + IRQ_CONNECT(DT_INST_0_INTEL_HPET_IRQ_0, + DT_INST_0_INTEL_HPET_IRQ_0_PRIORITY, hpet_isr, 0, 0); - set_timer0_irq(CONFIG_HPET_TIMER_IRQ); - irq_enable(CONFIG_HPET_TIMER_IRQ); + set_timer0_irq(DT_INST_0_INTEL_HPET_IRQ_0); + irq_enable(DT_INST_0_INTEL_HPET_IRQ_0); /* CLK_PERIOD_REG is in femtoseconds (1e-15 sec) */ hz = (u32_t)(1000000000000000ull / CLK_PERIOD_REG); diff --git a/dts/bindings/timer/intel,hpet.yaml b/dts/bindings/timer/intel,hpet.yaml new file mode 100644 index 00000000000..c3f2159cc6d --- /dev/null +++ b/dts/bindings/timer/intel,hpet.yaml @@ -0,0 +1,18 @@ +# Copyright (c) 2019 Intel Corp. +# SPDX-License-Identifier: Apache-2.0 + +title: HPET + +description: > + This binding represents the High-Precision Event Timer + +compatible: "intel,hpet" + +include: base.yaml + +properties: + reg: + required: true + + interrupts: + required: true diff --git a/dts/x86/apollo_lake.dtsi b/dts/x86/apollo_lake.dtsi index ca4364a4c58..ca61ab3c024 100644 --- a/dts/x86/apollo_lake.dtsi +++ b/dts/x86/apollo_lake.dtsi @@ -227,5 +227,15 @@ status = "okay"; }; + + hpet: hpet@fed00000 { + label = "HPET"; + compatible = "intel,hpet"; + reg = <0xfed00000 0x400>; + interrupts = <2 IRQ_TYPE_EDGE_RISING 4>; + interrupt-parent = <&intc>; + + status = "okay"; + }; }; }; diff --git a/dts/x86/atom.dtsi b/dts/x86/atom.dtsi index c85c5d26399..b835db611b1 100644 --- a/dts/x86/atom.dtsi +++ b/dts/x86/atom.dtsi @@ -65,5 +65,15 @@ status = "disabled"; }; + + hpet: hpet@fed00000 { + label = "HPET"; + compatible = "intel,hpet"; + reg = <0xfed00000 0x400>; + interrupts = <2 IRQ_TYPE_EDGE_RISING 4>; + interrupt-parent = <&intc>; + + status = "disabled"; + }; }; }; diff --git a/dts/x86/ia32.dtsi b/dts/x86/ia32.dtsi index 4e6163845ee..ddfb376d917 100644 --- a/dts/x86/ia32.dtsi +++ b/dts/x86/ia32.dtsi @@ -39,7 +39,6 @@ compatible = "simple-bus"; ranges; - uart0: uart@3f8 { compatible = "ns16550"; reg = <0x000003f8 0x100>; @@ -61,5 +60,15 @@ status = "disabled"; }; + + hpet: hpet@fed00000 { + label = "HPET"; + compatible = "intel,hpet"; + reg = <0xfed00000 0x400>; + interrupts = <2 IRQ_TYPE_EDGE_RISING 4>; + interrupt-parent = <&intc>; + + status = "disabled"; + }; }; }; diff --git a/soc/x86/apollo_lake/soc.c b/soc/x86/apollo_lake/soc.c index 47b5aa333ed..78319617353 100644 --- a/soc/x86/apollo_lake/soc.c +++ b/soc/x86/apollo_lake/soc.c @@ -27,7 +27,7 @@ MMU_BOOT_REGION(CONFIG_LOAPIC_BASE_ADDRESS, 4 * 1024, MMU_ENTRY_WRITE); MMU_BOOT_REGION(DT_IOAPIC_BASE_ADDRESS, 1024 * 1024, MMU_ENTRY_WRITE); #ifdef CONFIG_HPET_TIMER -MMU_BOOT_REGION(CONFIG_HPET_TIMER_BASE_ADDRESS, KB(4), MMU_ENTRY_WRITE); +MMU_BOOT_REGION(DT_INST_0_INTEL_HPET_BASE_ADDRESS, KB(4), MMU_ENTRY_WRITE); #endif /* CONFIG_HPET_TIMER */ /* for UARTs */ diff --git a/soc/x86/atom/soc.c b/soc/x86/atom/soc.c index 5a4204fbf21..e8fc184a556 100644 --- a/soc/x86/atom/soc.c +++ b/soc/x86/atom/soc.c @@ -38,7 +38,7 @@ MMU_BOOT_REGION(0xB0700000, 4*1024, MMU_ENTRY_WRITE); MMU_BOOT_REGION(0xB0500000, 256*1024, MMU_ENTRY_WRITE); #ifdef CONFIG_HPET_TIMER -MMU_BOOT_REGION(CONFIG_HPET_TIMER_BASE_ADDRESS, KB(4), MMU_ENTRY_WRITE); +MMU_BOOT_REGION(DT_INST_0_INTEL_HPET_BASE_ADDRESS, KB(4), MMU_ENTRY_WRITE); #endif /* CONFIG_HPET_TIMER */ #endif /* CONFIG_X86_MMU */ diff --git a/soc/x86/ia32/soc.c b/soc/x86/ia32/soc.c index 2e926a92e31..859667812e3 100644 --- a/soc/x86/ia32/soc.c +++ b/soc/x86/ia32/soc.c @@ -23,8 +23,9 @@ #ifdef CONFIG_X86_MMU MMU_BOOT_REGION(CONFIG_LOAPIC_BASE_ADDRESS, KB(4), MMU_ENTRY_WRITE); MMU_BOOT_REGION(DT_IOAPIC_BASE_ADDRESS, MB(1), MMU_ENTRY_WRITE); + #ifdef CONFIG_HPET_TIMER -MMU_BOOT_REGION(CONFIG_HPET_TIMER_BASE_ADDRESS, KB(4), MMU_ENTRY_WRITE); +MMU_BOOT_REGION(DT_INST_0_INTEL_HPET_BASE_ADDRESS, KB(4), MMU_ENTRY_WRITE); #endif #ifdef CONFIG_ETH_E1000 diff --git a/tests/kernel/context/src/main.c b/tests/kernel/context/src/main.c index d4cca0f9e3f..9d1707b5e9b 100644 --- a/tests/kernel/context/src/main.c +++ b/tests/kernel/context/src/main.c @@ -48,7 +48,7 @@ * is not defined in platform, generate an error */ #if defined(CONFIG_HPET_TIMER) -#define TICK_IRQ CONFIG_HPET_TIMER_IRQ +#define TICK_IRQ DT_INST_0_INTEL_HPET_IRQ_0 #elif defined(CONFIG_APIC_TIMER) #define TICK_IRQ CONFIG_APIC_TIMER_IRQ #elif defined(CONFIG_LOAPIC_TIMER)