File: microchip_pit.c

package info (click to toggle)
optee-os 4.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 31,960 kB
  • sloc: ansic: 444,388; asm: 12,922; python: 3,719; makefile: 1,681; sh: 238
file content (65 lines) | stat: -rw-r--r-- 1,336 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// SPDX-License-Identifier: BSD-2-Clause
/*
 * Copyright (c) 2024, Microchip
 */

#include <assert.h>
#include <drivers/clk.h>
#include <drivers/clk_dt.h>
#include <kernel/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();

	while (1) {
		parent = clk_get_parent_by_index(gclk, i++);
		if (!parent)
			panic();
		if (!memcmp("syspll", clk_get_name(parent),
			    sizeof("syspll") - 1))
			break;
	}

	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,
};