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 | 2e0644a | 2023-04-28 12:08:09 +0800 | [diff] [blame] | 12 | #include <firmware/imx/sci/sci.h> |
Peng Fan | 5e80d5a | 2018-10-18 14:28:30 +0200 | [diff] [blame] | 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 | { |
Simon Glass | 29ff16a | 2021-03-25 10:26:08 +1300 | [diff] [blame] | 32 | return -EINVAL; |
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 | |
Simon Glass | 495e80f | 2023-02-05 15:36:26 -0700 | [diff] [blame] | 45 | #if IS_ENABLED(CONFIG_CMD_CLK) |
Igor Prusov | 1a3427b | 2023-11-09 13:55:15 +0300 | [diff] [blame] | 46 | static void imx8_clk_dump(struct udevice *dev) |
Peng Fan | 5e80d5a | 2018-10-18 14:28:30 +0200 | [diff] [blame] | 47 | { |
Peng Fan | 5e80d5a | 2018-10-18 14:28:30 +0200 | [diff] [blame] | 48 | struct clk clk; |
| 49 | unsigned long rate; |
| 50 | int i, ret; |
| 51 | |
Peng Fan | 5e80d5a | 2018-10-18 14:28:30 +0200 | [diff] [blame] | 52 | printf("Clk\t\tHz\n"); |
| 53 | |
Peng Fan | 6a8e5f9 | 2019-03-05 02:32:33 +0000 | [diff] [blame] | 54 | for (i = 0; i < num_clks; i++) { |
Peng Fan | 5e80d5a | 2018-10-18 14:28:30 +0200 | [diff] [blame] | 55 | clk.id = imx8_clk_names[i].id; |
| 56 | ret = clk_request(dev, &clk); |
| 57 | if (ret < 0) { |
| 58 | debug("%s clk_request() failed: %d\n", __func__, ret); |
| 59 | continue; |
| 60 | } |
| 61 | |
| 62 | ret = clk_get_rate(&clk); |
| 63 | rate = ret; |
| 64 | |
| 65 | clk_free(&clk); |
| 66 | |
Simon Glass | 29ff16a | 2021-03-25 10:26:08 +1300 | [diff] [blame] | 67 | if (ret == -EINVAL) { |
Peng Fan | 5e80d5a | 2018-10-18 14:28:30 +0200 | [diff] [blame] | 68 | printf("clk ID %lu not supported yet\n", |
| 69 | imx8_clk_names[i].id); |
| 70 | continue; |
| 71 | } |
| 72 | if (ret < 0) { |
| 73 | printf("%s %lu: get_rate err: %d\n", |
| 74 | __func__, imx8_clk_names[i].id, ret); |
| 75 | continue; |
| 76 | } |
| 77 | |
| 78 | printf("%s(%3lu):\t%lu\n", |
| 79 | imx8_clk_names[i].name, imx8_clk_names[i].id, rate); |
| 80 | } |
Peng Fan | 5e80d5a | 2018-10-18 14:28:30 +0200 | [diff] [blame] | 81 | } |
| 82 | #endif |
| 83 | |
| 84 | static struct clk_ops imx8_clk_ops = { |
| 85 | .set_rate = imx8_clk_set_rate, |
| 86 | .get_rate = imx8_clk_get_rate, |
| 87 | .enable = imx8_clk_enable, |
| 88 | .disable = imx8_clk_disable, |
Igor Prusov | 1a3427b | 2023-11-09 13:55:15 +0300 | [diff] [blame] | 89 | #if IS_ENABLED(CONFIG_CMD_CLK) |
| 90 | .dump = imx8_clk_dump, |
| 91 | #endif |
Peng Fan | 5e80d5a | 2018-10-18 14:28:30 +0200 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | static int imx8_clk_probe(struct udevice *dev) |
| 95 | { |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | static const struct udevice_id imx8_clk_ids[] = { |
| 100 | { .compatible = "fsl,imx8qxp-clk" }, |
Peng Fan | 9a0dc91 | 2019-03-05 02:32:35 +0000 | [diff] [blame] | 101 | { .compatible = "fsl,imx8qm-clk" }, |
Peng Fan | 5e80d5a | 2018-10-18 14:28:30 +0200 | [diff] [blame] | 102 | { }, |
| 103 | }; |
| 104 | |
| 105 | U_BOOT_DRIVER(imx8_clk) = { |
| 106 | .name = "clk_imx8", |
| 107 | .id = UCLASS_CLK, |
| 108 | .of_match = imx8_clk_ids, |
| 109 | .ops = &imx8_clk_ops, |
| 110 | .probe = imx8_clk_probe, |
| 111 | .flags = DM_FLAG_PRE_RELOC, |
| 112 | }; |