1
2
3
4
5
6
7
8#include <common.h>
9#include <clk-uclass.h>
10#include <dm/device.h>
11#include <dm/lists.h>
12#include <dm/root.h>
13#include "pmc.h"
14
15DECLARE_GLOBAL_DATA_PTR;
16
17static const struct udevice_id at91_pmc_match[] = {
18 { .compatible = "atmel,sama5d2-pmc" },
19 {}
20};
21
22U_BOOT_DRIVER(at91_pmc) = {
23 .name = "at91-pmc",
24 .id = UCLASS_SIMPLE_BUS,
25 .of_match = at91_pmc_match,
26};
27
28
29
30int at91_pmc_core_probe(struct udevice *dev)
31{
32 struct pmc_platdata *plat = dev_get_platdata(dev);
33
34 dev = dev_get_parent(dev);
35
36 plat->reg_base = (struct at91_pmc *)dev_get_addr_ptr(dev);
37
38 return 0;
39}
40
41
42
43
44
45
46
47int at91_clk_sub_device_bind(struct udevice *dev, const char *drv_name)
48{
49 const void *fdt = gd->fdt_blob;
50 int offset = dev->of_offset;
51 bool pre_reloc_only = !(gd->flags & GD_FLG_RELOC);
52 const char *name;
53 int ret;
54
55 for (offset = fdt_first_subnode(fdt, offset);
56 offset > 0;
57 offset = fdt_next_subnode(fdt, offset)) {
58 if (pre_reloc_only &&
59 !fdt_getprop(fdt, offset, "u-boot,dm-pre-reloc", NULL))
60 continue;
61
62
63
64
65 fdt_get_property(fdt, offset, "compatible", &ret);
66 if (ret >= 0)
67 continue;
68
69 if (ret != -FDT_ERR_NOTFOUND)
70 return ret;
71
72 name = fdt_get_name(fdt, offset, NULL);
73 if (!name)
74 return -EINVAL;
75 ret = device_bind_driver_to_node(dev, drv_name, name,
76 offset, NULL);
77 if (ret)
78 return ret;
79 }
80
81 return 0;
82}
83
84int at91_clk_of_xlate(struct clk *clk, struct fdtdec_phandle_args *args)
85{
86 int periph;
87
88 if (args->args_count) {
89 debug("Invalid args_count: %d\n", args->args_count);
90 return -EINVAL;
91 }
92
93 periph = fdtdec_get_uint(gd->fdt_blob, clk->dev->of_offset, "reg", -1);
94 if (periph < 0)
95 return -EINVAL;
96
97 clk->id = periph;
98
99 return 0;
100}
101
102int at91_clk_probe(struct udevice *dev)
103{
104 struct udevice *dev_periph_container, *dev_pmc;
105 struct pmc_platdata *plat = dev_get_platdata(dev);
106
107 dev_periph_container = dev_get_parent(dev);
108 dev_pmc = dev_get_parent(dev_periph_container);
109
110 plat->reg_base = (struct at91_pmc *)dev_get_addr_ptr(dev_pmc);
111
112 return 0;
113}
114