aboutsummaryrefslogtreecommitdiff
path: root/drivers/misc/stm32_rcc.c
blob: 87d9928362be9ec7260ad54b94cb5f6b34a43996 (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
 * Author(s): Patrice Chotard, <patrice.chotard@st.com> for STMicroelectronics.
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include <common.h>
#include <dm.h>
#include <misc.h>
#include <stm32_rcc.h>
#include <dm/device-internal.h>
#include <dm/lists.h>

struct stm32_rcc_clk stm32_rcc_clk_f4 = {
	.drv_name = "stm32fx_rcc_clock",
	.soc = STM32F4,
};

struct stm32_rcc_clk stm32_rcc_clk_f7 = {
	.drv_name = "stm32fx_rcc_clock",
	.soc = STM32F7,
};

struct stm32_rcc_clk stm32_rcc_clk_h7 = {
	.drv_name = "stm32h7_rcc_clock",
};

static int stm32_rcc_bind(struct udevice *dev)
{
	struct udevice *child;
	struct driver *drv;
	struct stm32_rcc_clk *rcc_clk =
		(struct stm32_rcc_clk *)dev_get_driver_data(dev);
	int ret;

	debug("%s(dev=%p)\n", __func__, dev);

	drv = lists_driver_lookup_name(rcc_clk->drv_name);
	if (!drv) {
		debug("Cannot find driver '%s'\n", rcc_clk->drv_name);
		return -ENOENT;
	}

	ret = device_bind_with_driver_data(dev, drv, rcc_clk->drv_name,
					   rcc_clk->soc,
					   dev_ofnode(dev), &child);

	if (ret)
		return ret;

#ifdef CONFIG_SPL_BUILD
	return 0;
#else
	return device_bind_driver_to_node(dev, "stm32_rcc_reset",
					  "stm32_rcc_reset",
					  dev_ofnode(dev), &child);
#endif
}

static const struct misc_ops stm32_rcc_ops = {
};

static const struct udevice_id stm32_rcc_ids[] = {
	{.compatible = "st,stm32f42xx-rcc", .data = (ulong)&stm32_rcc_clk_f4 },
	{.compatible = "st,stm32f746-rcc", .data = (ulong)&stm32_rcc_clk_f7 },
	{.compatible = "st,stm32h743-rcc", .data = (ulong)&stm32_rcc_clk_h7 },
	{ }
};

U_BOOT_DRIVER(stm32_rcc) = {
	.name		= "stm32-rcc",
	.id		= UCLASS_MISC,
	.of_match	= stm32_rcc_ids,
	.bind		= stm32_rcc_bind,
	.ops		= &stm32_rcc_ops,
};