Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Wenyou Yang | 8c772bd | 2016-07-20 17:55:12 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016 Atmel Corporation |
| 4 | * Wenyou.Yang <wenyou.yang@atmel.com> |
Wenyou Yang | 8c772bd | 2016-07-20 17:55:12 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <clk-uclass.h> |
Simon Glass | 11c89f3 | 2017-05-17 17:18:03 -0600 | [diff] [blame] | 9 | #include <dm.h> |
Wenyou Yang | 8c772bd | 2016-07-20 17:55:12 +0800 | [diff] [blame] | 10 | #include <dm/lists.h> |
Heiko Stübner | 9a2cdca | 2017-02-18 19:46:21 +0100 | [diff] [blame] | 11 | #include <dm/util.h> |
Wenyou Yang | 8c772bd | 2016-07-20 17:55:12 +0800 | [diff] [blame] | 12 | #include "pmc.h" |
| 13 | |
| 14 | DECLARE_GLOBAL_DATA_PTR; |
| 15 | |
Wenyou Yang | 8c772bd | 2016-07-20 17:55:12 +0800 | [diff] [blame] | 16 | static const struct udevice_id at91_pmc_match[] = { |
Wenyou Yang | 217c968 | 2017-04-14 14:53:24 +0800 | [diff] [blame] | 17 | { .compatible = "atmel,at91rm9200-pmc" }, |
| 18 | { .compatible = "atmel,at91sam9260-pmc" }, |
| 19 | { .compatible = "atmel,at91sam9g45-pmc" }, |
| 20 | { .compatible = "atmel,at91sam9n12-pmc" }, |
| 21 | { .compatible = "atmel,at91sam9x5-pmc" }, |
| 22 | { .compatible = "atmel,sama5d3-pmc" }, |
Wenyou Yang | 8c772bd | 2016-07-20 17:55:12 +0800 | [diff] [blame] | 23 | { .compatible = "atmel,sama5d2-pmc" }, |
| 24 | {} |
| 25 | }; |
| 26 | |
| 27 | U_BOOT_DRIVER(at91_pmc) = { |
Wenyou Yang | e400930 | 2016-09-13 10:25:55 +0800 | [diff] [blame] | 28 | .name = "at91-pmc", |
| 29 | .id = UCLASS_SIMPLE_BUS, |
Wenyou Yang | 8c772bd | 2016-07-20 17:55:12 +0800 | [diff] [blame] | 30 | .of_match = at91_pmc_match, |
Wenyou Yang | 8c772bd | 2016-07-20 17:55:12 +0800 | [diff] [blame] | 31 | }; |
| 32 | |
Wenyou Yang | 9a71d39 | 2016-09-27 11:00:29 +0800 | [diff] [blame] | 33 | /*---------------------------------------------------------*/ |
| 34 | |
Wenyou Yang | 8c772bd | 2016-07-20 17:55:12 +0800 | [diff] [blame] | 35 | int at91_pmc_core_probe(struct udevice *dev) |
| 36 | { |
| 37 | struct pmc_platdata *plat = dev_get_platdata(dev); |
| 38 | |
| 39 | dev = dev_get_parent(dev); |
| 40 | |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 41 | plat->reg_base = (struct at91_pmc *)devfdt_get_addr_ptr(dev); |
Wenyou Yang | 8c772bd | 2016-07-20 17:55:12 +0800 | [diff] [blame] | 42 | |
| 43 | return 0; |
| 44 | } |
| 45 | |
Wenyou Yang | 9a71d39 | 2016-09-27 11:00:29 +0800 | [diff] [blame] | 46 | /** |
| 47 | * at91_clk_sub_device_bind() - for the at91 clock driver |
| 48 | * Recursively bind its children as clk devices. |
| 49 | * |
| 50 | * @return: 0 on success, or negative error code on failure |
| 51 | */ |
| 52 | int at91_clk_sub_device_bind(struct udevice *dev, const char *drv_name) |
Wenyou Yang | 8c772bd | 2016-07-20 17:55:12 +0800 | [diff] [blame] | 53 | { |
| 54 | const void *fdt = gd->fdt_blob; |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 55 | int offset = dev_of_offset(dev); |
Wenyou Yang | 9a71d39 | 2016-09-27 11:00:29 +0800 | [diff] [blame] | 56 | bool pre_reloc_only = !(gd->flags & GD_FLG_RELOC); |
Wenyou Yang | 8c772bd | 2016-07-20 17:55:12 +0800 | [diff] [blame] | 57 | const char *name; |
| 58 | int ret; |
| 59 | |
| 60 | for (offset = fdt_first_subnode(fdt, offset); |
| 61 | offset > 0; |
| 62 | offset = fdt_next_subnode(fdt, offset)) { |
Wenyou Yang | 9a71d39 | 2016-09-27 11:00:29 +0800 | [diff] [blame] | 63 | if (pre_reloc_only && |
Patrick Delaunay | f656ba8 | 2019-03-20 18:21:24 +0100 | [diff] [blame] | 64 | !dm_ofnode_pre_reloc(offset_to_ofnode(offset))) |
Wenyou Yang | 9a71d39 | 2016-09-27 11:00:29 +0800 | [diff] [blame] | 65 | continue; |
| 66 | /* |
| 67 | * If this node has "compatible" property, this is not |
| 68 | * a clock sub-node, but a normal device. skip. |
| 69 | */ |
| 70 | fdt_get_property(fdt, offset, "compatible", &ret); |
| 71 | if (ret >= 0) |
| 72 | continue; |
| 73 | |
| 74 | if (ret != -FDT_ERR_NOTFOUND) |
| 75 | return ret; |
| 76 | |
Wenyou Yang | 8c772bd | 2016-07-20 17:55:12 +0800 | [diff] [blame] | 77 | name = fdt_get_name(fdt, offset, NULL); |
| 78 | if (!name) |
| 79 | return -EINVAL; |
Wenyou Yang | 9a71d39 | 2016-09-27 11:00:29 +0800 | [diff] [blame] | 80 | ret = device_bind_driver_to_node(dev, drv_name, name, |
Simon Glass | e6dd8da | 2017-05-18 20:09:07 -0600 | [diff] [blame] | 81 | offset_to_ofnode(offset), NULL); |
Wenyou Yang | 8c772bd | 2016-07-20 17:55:12 +0800 | [diff] [blame] | 82 | if (ret) |
| 83 | return ret; |
| 84 | } |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | |
Simon Glass | b7ae277 | 2017-05-18 20:09:40 -0600 | [diff] [blame] | 89 | int at91_clk_of_xlate(struct clk *clk, struct ofnode_phandle_args *args) |
Wenyou Yang | 9a71d39 | 2016-09-27 11:00:29 +0800 | [diff] [blame] | 90 | { |
| 91 | int periph; |
| 92 | |
| 93 | if (args->args_count) { |
| 94 | debug("Invalid args_count: %d\n", args->args_count); |
| 95 | return -EINVAL; |
| 96 | } |
| 97 | |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 98 | periph = fdtdec_get_uint(gd->fdt_blob, dev_of_offset(clk->dev), "reg", |
| 99 | -1); |
Wenyou Yang | 9a71d39 | 2016-09-27 11:00:29 +0800 | [diff] [blame] | 100 | if (periph < 0) |
| 101 | return -EINVAL; |
| 102 | |
| 103 | clk->id = periph; |
| 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | int at91_clk_probe(struct udevice *dev) |
| 109 | { |
| 110 | struct udevice *dev_periph_container, *dev_pmc; |
| 111 | struct pmc_platdata *plat = dev_get_platdata(dev); |
| 112 | |
| 113 | dev_periph_container = dev_get_parent(dev); |
| 114 | dev_pmc = dev_get_parent(dev_periph_container); |
| 115 | |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 116 | plat->reg_base = (struct at91_pmc *)devfdt_get_addr_ptr(dev_pmc); |
Wenyou Yang | 9a71d39 | 2016-09-27 11:00:29 +0800 | [diff] [blame] | 117 | |
| 118 | return 0; |
| 119 | } |