Peng Fan | 5e80d5a | 2018-10-18 14:28:30 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright 2018 NXP |
| 4 | * Peng Fan <peng.fan@nxp.com> |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <clk-uclass.h> |
| 9 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 11 | #include <malloc.h> |
Peng Fan | 5e80d5a | 2018-10-18 14:28:30 +0200 | [diff] [blame] | 12 | #include <asm/arch/sci/sci.h> |
| 13 | #include <asm/arch/clock.h> |
| 14 | #include <dt-bindings/clock/imx8qxp-clock.h> |
| 15 | #include <dt-bindings/soc/imx_rsrc.h> |
| 16 | #include <misc.h> |
| 17 | |
Peng Fan | 6a8e5f9 | 2019-03-05 02:32:33 +0000 | [diff] [blame] | 18 | #include "clk-imx8.h" |
Peng Fan | 5e80d5a | 2018-10-18 14:28:30 +0200 | [diff] [blame] | 19 | |
Peng Fan | 6a8e5f9 | 2019-03-05 02:32:33 +0000 | [diff] [blame] | 20 | __weak ulong imx8_clk_get_rate(struct clk *clk) |
Peng Fan | 5e80d5a | 2018-10-18 14:28:30 +0200 | [diff] [blame] | 21 | { |
Peng Fan | 6a8e5f9 | 2019-03-05 02:32:33 +0000 | [diff] [blame] | 22 | return 0; |
Peng Fan | 5e80d5a | 2018-10-18 14:28:30 +0200 | [diff] [blame] | 23 | } |
| 24 | |
Peng Fan | 6a8e5f9 | 2019-03-05 02:32:33 +0000 | [diff] [blame] | 25 | __weak ulong imx8_clk_set_rate(struct clk *clk, unsigned long rate) |
Peng Fan | 5e80d5a | 2018-10-18 14:28:30 +0200 | [diff] [blame] | 26 | { |
Peng Fan | 6a8e5f9 | 2019-03-05 02:32:33 +0000 | [diff] [blame] | 27 | return 0; |
Peng Fan | 5e80d5a | 2018-10-18 14:28:30 +0200 | [diff] [blame] | 28 | } |
| 29 | |
Peng Fan | 6a8e5f9 | 2019-03-05 02:32:33 +0000 | [diff] [blame] | 30 | __weak int __imx8_clk_enable(struct clk *clk, bool enable) |
Peng Fan | 5e80d5a | 2018-10-18 14:28:30 +0200 | [diff] [blame] | 31 | { |
Peng Fan | 6a8e5f9 | 2019-03-05 02:32:33 +0000 | [diff] [blame] | 32 | return -ENOTSUPP; |
Peng Fan | 5e80d5a | 2018-10-18 14:28:30 +0200 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | static int imx8_clk_disable(struct clk *clk) |
| 36 | { |
| 37 | return __imx8_clk_enable(clk, 0); |
| 38 | } |
| 39 | |
| 40 | static int imx8_clk_enable(struct clk *clk) |
| 41 | { |
| 42 | return __imx8_clk_enable(clk, 1); |
| 43 | } |
| 44 | |
| 45 | #if CONFIG_IS_ENABLED(CMD_CLK) |
| 46 | int soc_clk_dump(void) |
| 47 | { |
| 48 | struct udevice *dev; |
| 49 | struct clk clk; |
| 50 | unsigned long rate; |
| 51 | int i, ret; |
| 52 | |
| 53 | ret = uclass_get_device_by_driver(UCLASS_CLK, |
| 54 | DM_GET_DRIVER(imx8_clk), &dev); |
| 55 | if (ret) |
| 56 | return ret; |
| 57 | |
| 58 | printf("Clk\t\tHz\n"); |
| 59 | |
Peng Fan | 6a8e5f9 | 2019-03-05 02:32:33 +0000 | [diff] [blame] | 60 | for (i = 0; i < num_clks; i++) { |
Peng Fan | 5e80d5a | 2018-10-18 14:28:30 +0200 | [diff] [blame] | 61 | clk.id = imx8_clk_names[i].id; |
| 62 | ret = clk_request(dev, &clk); |
| 63 | if (ret < 0) { |
| 64 | debug("%s clk_request() failed: %d\n", __func__, ret); |
| 65 | continue; |
| 66 | } |
| 67 | |
| 68 | ret = clk_get_rate(&clk); |
| 69 | rate = ret; |
| 70 | |
| 71 | clk_free(&clk); |
| 72 | |
| 73 | if (ret == -ENOTSUPP) { |
| 74 | printf("clk ID %lu not supported yet\n", |
| 75 | imx8_clk_names[i].id); |
| 76 | continue; |
| 77 | } |
| 78 | if (ret < 0) { |
| 79 | printf("%s %lu: get_rate err: %d\n", |
| 80 | __func__, imx8_clk_names[i].id, ret); |
| 81 | continue; |
| 82 | } |
| 83 | |
| 84 | printf("%s(%3lu):\t%lu\n", |
| 85 | imx8_clk_names[i].name, imx8_clk_names[i].id, rate); |
| 86 | } |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | #endif |
| 91 | |
| 92 | static struct clk_ops imx8_clk_ops = { |
| 93 | .set_rate = imx8_clk_set_rate, |
| 94 | .get_rate = imx8_clk_get_rate, |
| 95 | .enable = imx8_clk_enable, |
| 96 | .disable = imx8_clk_disable, |
| 97 | }; |
| 98 | |
| 99 | static int imx8_clk_probe(struct udevice *dev) |
| 100 | { |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | static const struct udevice_id imx8_clk_ids[] = { |
| 105 | { .compatible = "fsl,imx8qxp-clk" }, |
Peng Fan | 9a0dc91 | 2019-03-05 02:32:35 +0000 | [diff] [blame] | 106 | { .compatible = "fsl,imx8qm-clk" }, |
Peng Fan | 5e80d5a | 2018-10-18 14:28:30 +0200 | [diff] [blame] | 107 | { }, |
| 108 | }; |
| 109 | |
| 110 | U_BOOT_DRIVER(imx8_clk) = { |
| 111 | .name = "clk_imx8", |
| 112 | .id = UCLASS_CLK, |
| 113 | .of_match = imx8_clk_ids, |
| 114 | .ops = &imx8_clk_ops, |
| 115 | .probe = imx8_clk_probe, |
| 116 | .flags = DM_FLAG_PRE_RELOC, |
| 117 | }; |