Skip to content

Commit

Permalink
drivers: microchip_pit: add driver for sama7g54's pit64b
Browse files Browse the repository at this point in the history
Add support for the peripheral PIT64B in sama7g54. In the driver the clocks
are initialized for PIT64B.

Signed-off-by: Tony Han <[email protected]>
  • Loading branch information
TonyHan11 committed Nov 6, 2024
1 parent cbed67d commit 2ce7559
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/arch/arm/plat-sam/conf.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
64 changes: 64 additions & 0 deletions core/drivers/microchip_pit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// SPDX-License-Identifier: BSD-2-Clause
/*
* Copyright (c) 2024, Microchip
*/

#include <assert.h>
#include <drivers/clk.h>
#include <drivers/clk_dt.h>
#include <dt_driver.h>
#include <string.h>

#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,
};
1 change: 1 addition & 0 deletions core/drivers/sub.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2ce7559

Please sign in to comment.