diff --git a/core/arch/arm/plat-sam/conf.mk b/core/arch/arm/plat-sam/conf.mk index 3539bc5b134..bf8b6270ec2 100644 --- a/core/arch/arm/plat-sam/conf.mk +++ b/core/arch/arm/plat-sam/conf.mk @@ -20,6 +20,7 @@ include core/arch/arm/cpu/cortex-a7.mk $(call force,CFG_SAMA7G5,y) $(call force,CFG_GIC,y) $(call force,CFG_TZC400,y) +$(call force,CFG_MICROCHIP_PIT,y) else include core/arch/arm/cpu/cortex-a5.mk $(call force,CFG_SAMA5D2,y) diff --git a/core/drivers/microchip_pit.c b/core/drivers/microchip_pit.c new file mode 100644 index 00000000000..318ba24d28d --- /dev/null +++ b/core/drivers/microchip_pit.c @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: BSD-2-Clause +/* + * Copyright (c) 2024, Microchip + */ + +#include +#include +#include +#include +#include + +#define MCHP_PIT64B_FREQ UL(5000000) /* 5 MHz */ + +static TEE_Result microchip_pit_probe(const void *fdt, int node, + const void *compat_data __unused) +{ + TEE_Result res = TEE_ERROR_GENERIC; + struct clk *parent = NULL; + struct clk *pclk = NULL; + struct clk *gclk = NULL; + size_t i = 0; + + res = clk_dt_get_by_name(fdt, node, "pclk", &pclk); + if (res) + return res; + + res = clk_dt_get_by_name(fdt, node, "gclk", &gclk); + if (res) + return res; + + res = clk_enable(pclk); + if (res) + panic(); + + do { + parent = clk_get_parent_by_index(gclk, i++); + if (!memcmp("syspll", clk_get_name(parent), sizeof("syspll"))) + break; + } while (parent); + if (!parent) + panic(); + + res = clk_set_parent(gclk, parent); + if (res) + panic(); + + res = clk_set_rate(gclk, MCHP_PIT64B_FREQ); + if (res) + panic(); + + return clk_enable(gclk); +} + +static const struct dt_device_match microchip_pit_match_table[] = { + { .compatible = "microchip,sama7g5-pit64b" }, + { } +}; + +DEFINE_DT_DRIVER(microchip_pit_dt_driver) = { + .name = "microchip_pit", + .type = DT_DRIVER_NOTYPE, + .match_table = microchip_pit_match_table, + .probe = microchip_pit_probe, +}; diff --git a/core/drivers/sub.mk b/core/drivers/sub.mk index 1538bd6b898..d4dc1696c0b 100644 --- a/core/drivers/sub.mk +++ b/core/drivers/sub.mk @@ -32,6 +32,7 @@ srcs-$(CFG_ATMEL_WDT) += atmel_wdt.c srcs-$(CFG_ATMEL_RTC) += atmel_rtc.c srcs-$(CFG_ATMEL_PIOBU) += atmel_piobu.c srcs-$(CFG_ATMEL_TCB) += atmel_tcb.c +srcs-$(CFG_MICROCHIP_PIT) += microchip_pit.c srcs-$(CFG_AMLOGIC_UART) += amlogic_uart.c srcs-$(CFG_MVEBU_UART) += mvebu_uart.c srcs-$(CFG_STM32_BSEC) += stm32_bsec.c