timer: imx-gpt: Add timer support for i.MX SoCs family
PATCH 1/1 timer: imx-gpt: Add timer support for i.MX SoCs family
From: Mr-Bossman <[email protected]>
This timer driver is using GPT Timer (General Purpose Timer) available on almost all i.MX SoCs family.
--- drivers/timer/Kconfig | 7 ++ drivers/timer/Makefile | 1 + drivers/timer/imx-gpt-timer.c | 134 ++++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 drivers/timer/imx-gpt-timer.c
drivers/timer/Kconfig +7 -0
@@ -227,4 +227,11 @@ config MCHP_PIT64B_TIMER Select this to enable support for Microchip 64-bit periodic interval timer. +config IMX_GPT_TIMER + bool "NXP i.MX GPT timer support" + depends on TIMER + help + Select this to enable support for the timer found on + NXP i.MX devices. + endmenu
drivers/timer/Makefile +1 -0
@@ -25,3 +25,4 @@ obj-$(CONFIG_STM32_TIMER) += stm32_timer.o 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
drivers/timer/imx-gpt-timer.c new file +134 -0
134 lines not on this page · raw message
Signature · 1 line
2.30.0
PATCH 1/1 timer: imx-gpt: Add timer support for i.MX SoCs family
Hi Jesse,
Quoted 4 lines · Jesse Taube
From: Mr-Bossman <[email protected]>
This timer driver is using GPT Timer (General Purpose Timer) available on almost all i.MX SoCs family.
Please provide more explanation about costraints it has. It works only with a source clock at 24Mhz. So something like:
'''
This timer driver is using GPT Timer (General Purpose Timer) available on almost all i.MX SoCs family. Since this driver is only meant to provide u-boot timer counter and most of i.MX* SoCs use 24Mhz crystal source so let's deal only that specific source.
'''
Quoted 44 lines
Signed-off-by Giulio Benetti <[email protected]>Signed-off-by Jesse Taube <[email protected]>--- drivers/timer/Kconfig | 7 ++ drivers/timer/Makefile | 1 + drivers/timer/imx-gpt-timer.c | 134 ++++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+)create mode 100644
drivers/timer/imx-gpt-timer.cdrivers/timer/Kconfig +7
-0@@ -227,4 +227,11 @@ config MCHP_PIT64B_TIMER Select this to enable support for Microchip 64-bit periodic interval timer. +config IMX_GPT_TIMER + bool "NXP i.MX GPT timer support" + depends on TIMER + help + Select this to enable support for the timer found on + NXP i.MX devices. + endmenudrivers/timer/Makefile +1
-0@@ -25,3 +25,4 @@ obj-$(CONFIG_STM32_TIMER) += stm32_timer.o 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.odrivers/timer/imx-gpt-timer.c new file +3
-0@@ -0,0 +1,134 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2020
drivers/timer/imx-gpt-timer.c line 13
Quoted 10 lines
drivers/timer/imx-gpt-timer.c new file +10
-0+* Author(s): Giulio Benetti <[email protected]> +*/ + +#include <common.h> +#include <clk.h> +#include <dm.h> +#include <fdtdec.h> +#include <timer.h> +#include <dm/device_compat.h> +
Please remove newline ^^^
drivers/timer/imx-gpt-timer.c line 19
Quoted 6 lines
drivers/timer/imx-gpt-timer.c new file +6
-0+#include <asm/io.h> + +#define GPT_CR_SWR 0x00008000 +#define GPT_CR_CLKSRC 0x000001C0 +#define GPT_CR_EN_24M 0x00004000 +#define GPT_CR_EN 0x00000001
Please keep the same tabs above as below
drivers/timer/imx-gpt-timer.c line 24
Quoted 5 lines
drivers/timer/imx-gpt-timer.c new file +5
-0+#define GPT_PR_PRESCALER 0x00000FFF +#define GPT_PR_PRESCALER24M 0x0000F000 + +#define NO_CLOCK (0) +#define IPG_CLK (1 << 6)
ditto
drivers/timer/imx-gpt-timer.c line 26
Quoted 2 lines
drivers/timer/imx-gpt-timer.c new file +2
-0+#define IPG_CLK_HF (2 << 6) +#define IPG_EXT (3 << 6)
ditto
Quoted 55 lines
drivers/timer/imx-gpt-timer.c new file +55
-0+#define IPG_CLK_32K (4 << 6) +#define IPG_CLK_24M (5 << 6) + +struct imx_gpt_timer_regs { +u32 cr; +u32 pr; +u32 sr; +u32 ir; +u32 ocr1; +u32 ocr2; +u32 ocr3; +u32 icr1; +u32 icr2; +u32 cnt; +}; + +struct imx_gpt_timer_priv { +struct imx_gpt_timer_regs *base; +}; + +static u64 imx_gpt_timer_get_count (struct udevice *dev) +{ +struct imx_gpt_timer_priv *priv =dev_get_priv (dev); +struct imx_gpt_timer_regs *regs = priv->base; + +return readl (®s->cnt); +} + +static int imx_gpt_timer_probe (struct udevice *dev) +{ +struct timer_dev_priv *uc_priv =dev_get_uclass_priv (dev); +struct imx_gpt_timer_priv *priv =dev_get_priv (dev); +struct imx_gpt_timer_regs *regs; +struct clk clk; +fdt_addr_t addr; +u32 prescaler; +u32 rate; +int ret; + + addr =dev_read_addr (dev); +if (addr ==FDT_ADDR_T_NONE ) +return -EINVAL ; + + priv->base = (struct imx_gpt_timer_regs *)addr; + + ret =clk_get_by_index (dev,0 , &clk); +if (ret <0 ) +return ret; + + ret =clk_enable (&clk); +if (ret) { +dev_err (dev,"Failed to enable clock\n" ); +return ret; + } +
drivers/timer/imx-gpt-timer.c line 91
Quoted 10 lines
drivers/timer/imx-gpt-timer.c new file +10
-0+ regs = priv->base; + +/* Reset the timer */ +setbits_le32 (®s->cr,GPT_CR_SWR ); + +/* Wait for timer to finish reset */ +while (readl (®s->cr) &GPT_CR_SWR ) + ; + +/* Get timer clock rate */
This is a useless comment, don't describe talking functions
drivers/timer/imx-gpt-timer.c line 94
Quoted 3 lines
drivers/timer/imx-gpt-timer.c new file +3
-0+ rate =clk_get_rate (&clk); + +/* Is timer clock rate valid, If not go to 24MHz clock*/
ditto and 24Mhz is dealt after
Signature · 2 lines
Giulio Benetti Benetti Engineering sas
drivers/timer/imx-gpt-timer.c line 104
Quoted 10 lines
drivers/timer/imx-gpt-timer.c new file +10
-0+if ((int )rate <=0 ) { +dev_err (dev,"Could not get clock rate...\n" ); +return -EINVAL ; + } +/* Only support 24MHz clock */ +if (rate !=24000000UL ) { +dev_err (dev,"Clock rate other than 24MHz not supported...\n" ); +return -EINVAL ; + } +/* we set timer prescaler to obtain a 1MHz timer counter frequency */
Capital /* We ... */
drivers/timer/imx-gpt-timer.c line 112
Quoted 8 lines
drivers/timer/imx-gpt-timer.c new file +8
-0+ prescaler = (rate /CONFIG_SYS_HZ_CLOCK ) -1 ; +writel (GPT_PR_PRESCALER & prescaler, ®s->pr); +/* Set timer frequency to 1MHz */ + uc_priv->clock_rate =CONFIG_SYS_HZ_CLOCK ; + +clrbits_le32 (®s->cr,GPT_CR_CLKSRC ); +setbits_le32 (®s->cr,IPG_CLK ); +/* start timer */
Capital /* Start ... */
Also, you're resending 4/4 only of this patchset but we would expect having a new patchset generated with:
# git format-patch -M -s -o outgoing -4 --cover-letter -v2
-v2 tag every patch as the second iteration of this patchset and it's useful to distinguish new patches from old ones.
Also, for every patch you have to indicate what changes from v1->v2.
You should put this infos after commit log end and the 3 dashes like:
---V1->V2:
* changed this
* modified this
* etc.
---
Of course same goes for V2->V3/while keeping V1->V2 and so on until it's accepted. If not all patches have been accepted then next time send only the not accepted ones.
Best regards
Signature · 2 lines
Giulio Benetti Benetti Engineering sas
Quoted 23 lines
drivers/timer/imx-gpt-timer.c new file +22
-0+setbits_le32 (®s->cr,GPT_CR_EN ); + +return 0 ; +} + +static const struct timer_ops imx_gpt_timer_ops = { + .get_count = imx_gpt_timer_get_count, +}; + +static const struct udevice_id imx_gpt_timer_ids[] = { + { .compatible ="fsl,imxrt-gpt" }, + {} +}; + +U_BOOT_DRIVER (imx_gpt_timer) = { + .name ="imx_gpt_timer" , + .id =UCLASS_TIMER , + .of_match = imx_gpt_timer_ids, + .priv_auto =sizeof (struct imx_gpt_timer_priv ), + .probe = imx_gpt_timer_probe, + .ops = &imx_gpt_timer_ops, +};