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