Robert Marko | e479a7d | 2020-07-06 10:37:54 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Clock drivers for Qualcomm IPQ40xx |
| 4 | * |
Robert Marko | 96d6036 | 2020-10-08 22:05:10 +0200 | [diff] [blame] | 5 | * Copyright (c) 2020 Sartura Ltd. |
Robert Marko | e479a7d | 2020-07-06 10:37:54 +0200 | [diff] [blame] | 6 | * |
| 7 | * Author: Robert Marko <robert.marko@sartura.hr> |
| 8 | * |
| 9 | */ |
| 10 | |
Robert Marko | e479a7d | 2020-07-06 10:37:54 +0200 | [diff] [blame] | 11 | #include <clk-uclass.h> |
Robert Marko | 9053453 | 2020-10-28 13:56:23 +0100 | [diff] [blame] | 12 | #include <common.h> |
Robert Marko | e479a7d | 2020-07-06 10:37:54 +0200 | [diff] [blame] | 13 | #include <dm.h> |
| 14 | #include <errno.h> |
| 15 | |
Robert Marko | 5ae1541 | 2020-09-10 16:00:00 +0200 | [diff] [blame] | 16 | #include <dt-bindings/clock/qcom,ipq4019-gcc.h> |
| 17 | |
Robert Marko | e479a7d | 2020-07-06 10:37:54 +0200 | [diff] [blame] | 18 | struct msm_clk_priv { |
| 19 | phys_addr_t base; |
| 20 | }; |
| 21 | |
| 22 | ulong msm_set_rate(struct clk *clk, ulong rate) |
| 23 | { |
| 24 | switch (clk->id) { |
Robert Marko | 5ae1541 | 2020-09-10 16:00:00 +0200 | [diff] [blame] | 25 | case GCC_BLSP1_UART1_APPS_CLK: /*UART1*/ |
Robert Marko | e479a7d | 2020-07-06 10:37:54 +0200 | [diff] [blame] | 26 | /* This clock is already initialized by SBL1 */ |
Robert Marko | 96d6036 | 2020-10-08 22:05:10 +0200 | [diff] [blame] | 27 | return 0; |
Robert Marko | e479a7d | 2020-07-06 10:37:54 +0200 | [diff] [blame] | 28 | default: |
Robert Marko | 20476b5 | 2020-10-28 13:56:25 +0100 | [diff] [blame] | 29 | return -EINVAL; |
Robert Marko | e479a7d | 2020-07-06 10:37:54 +0200 | [diff] [blame] | 30 | } |
| 31 | } |
| 32 | |
| 33 | static int msm_clk_probe(struct udevice *dev) |
| 34 | { |
| 35 | struct msm_clk_priv *priv = dev_get_priv(dev); |
| 36 | |
Robert Marko | 9053453 | 2020-10-28 13:56:23 +0100 | [diff] [blame] | 37 | priv->base = dev_read_addr(dev); |
Robert Marko | e479a7d | 2020-07-06 10:37:54 +0200 | [diff] [blame] | 38 | if (priv->base == FDT_ADDR_T_NONE) |
| 39 | return -EINVAL; |
| 40 | |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | static ulong msm_clk_set_rate(struct clk *clk, ulong rate) |
| 45 | { |
| 46 | return msm_set_rate(clk, rate); |
| 47 | } |
| 48 | |
Robert Marko | 96d6036 | 2020-10-08 22:05:10 +0200 | [diff] [blame] | 49 | static int msm_enable(struct clk *clk) |
| 50 | { |
| 51 | switch (clk->id) { |
| 52 | case GCC_BLSP1_QUP1_SPI_APPS_CLK: /*SPI1*/ |
| 53 | /* This clock is already initialized by SBL1 */ |
| 54 | return 0; |
Robert Marko | cfec8d3 | 2020-10-08 22:05:14 +0200 | [diff] [blame] | 55 | case GCC_PRNG_AHB_CLK: /*PRNG*/ |
| 56 | /* This clock is already initialized by SBL1 */ |
| 57 | return 0; |
Robert Marko | a282ada | 2020-10-28 13:56:26 +0100 | [diff] [blame] | 58 | case GCC_USB3_MASTER_CLK: |
| 59 | case GCC_USB3_SLEEP_CLK: |
| 60 | case GCC_USB3_MOCK_UTMI_CLK: |
| 61 | case GCC_USB2_MASTER_CLK: |
| 62 | case GCC_USB2_SLEEP_CLK: |
| 63 | case GCC_USB2_MOCK_UTMI_CLK: |
| 64 | /* These clocks is already initialized by SBL1 */ |
| 65 | return 0; |
Robert Marko | 96d6036 | 2020-10-08 22:05:10 +0200 | [diff] [blame] | 66 | default: |
Robert Marko | 20476b5 | 2020-10-28 13:56:25 +0100 | [diff] [blame] | 67 | return -EINVAL; |
Robert Marko | 96d6036 | 2020-10-08 22:05:10 +0200 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | |
Robert Marko | e479a7d | 2020-07-06 10:37:54 +0200 | [diff] [blame] | 71 | static struct clk_ops msm_clk_ops = { |
| 72 | .set_rate = msm_clk_set_rate, |
Robert Marko | 96d6036 | 2020-10-08 22:05:10 +0200 | [diff] [blame] | 73 | .enable = msm_enable, |
Robert Marko | e479a7d | 2020-07-06 10:37:54 +0200 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | static const struct udevice_id msm_clk_ids[] = { |
| 77 | { .compatible = "qcom,gcc-ipq4019" }, |
| 78 | { } |
| 79 | }; |
| 80 | |
| 81 | U_BOOT_DRIVER(clk_msm) = { |
| 82 | .name = "clk_msm", |
| 83 | .id = UCLASS_CLK, |
| 84 | .of_match = msm_clk_ids, |
| 85 | .ops = &msm_clk_ops, |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 86 | .priv_auto = sizeof(struct msm_clk_priv), |
Robert Marko | e479a7d | 2020-07-06 10:37:54 +0200 | [diff] [blame] | 87 | .probe = msm_clk_probe, |
| 88 | }; |