blob: a08d7e82eb3462bf825116ec5a1645abb9c81137 [file] [log] [blame]
Wenyou Yang8c772bd2016-07-20 17:55:12 +08001/*
2 * Copyright (C) 2016 Atmel Corporation
3 * Wenyou.Yang <wenyou.yang@atmel.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
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 int at91_pmc_bind(struct udevice *dev)
18{
19 return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false);
20}
21
22static const struct udevice_id at91_pmc_match[] = {
23 { .compatible = "atmel,sama5d2-pmc" },
24 {}
25};
26
27U_BOOT_DRIVER(at91_pmc) = {
28 .name = "at91-pmc-core",
29 .id = UCLASS_CLK,
30 .of_match = at91_pmc_match,
31 .bind = at91_pmc_bind,
32};
33
34int at91_pmc_core_probe(struct udevice *dev)
35{
36 struct pmc_platdata *plat = dev_get_platdata(dev);
37
38 dev = dev_get_parent(dev);
39
40 plat->reg_base = (struct at91_pmc *)dev_get_addr_ptr(dev);
41
42 return 0;
43}
44
45int at91_pmc_clk_node_bind(struct udevice *dev)
46{
47 const void *fdt = gd->fdt_blob;
48 int offset = dev->of_offset;
49 const char *name;
50 int ret;
51
52 for (offset = fdt_first_subnode(fdt, offset);
53 offset > 0;
54 offset = fdt_next_subnode(fdt, offset)) {
55 name = fdt_get_name(fdt, offset, NULL);
56 if (!name)
57 return -EINVAL;
58
59 ret = device_bind_driver_to_node(dev, "clk", name,
60 offset, NULL);
61 if (ret)
62 return ret;
63 }
64
65 return 0;
66}
67
68U_BOOT_DRIVER(clk_generic) = {
69 .id = UCLASS_CLK,
70 .name = "clk",
71};