Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Clock drivers for Qualcomm APQ8016 |
| 4 | * |
| 5 | * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com> |
| 6 | * |
| 7 | * Based on Little Kernel driver, simplified |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 11 | #include <clk-uclass.h> |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 12 | #include <dm.h> |
| 13 | #include <errno.h> |
| 14 | #include <asm/io.h> |
| 15 | #include <linux/bitops.h> |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 16 | #include "clock-snapdragon.h" |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 17 | |
| 18 | /* GPLL0 clock control registers */ |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 19 | #define GPLL0_STATUS_ACTIVE BIT(17) |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 20 | |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 21 | static const struct bcr_regs sdc_regs[] = { |
| 22 | { |
| 23 | .cfg_rcgr = SDCC_CFG_RCGR(1), |
| 24 | .cmd_rcgr = SDCC_CMD_RCGR(1), |
| 25 | .M = SDCC_M(1), |
| 26 | .N = SDCC_N(1), |
| 27 | .D = SDCC_D(1), |
| 28 | }, |
| 29 | { |
| 30 | .cfg_rcgr = SDCC_CFG_RCGR(2), |
| 31 | .cmd_rcgr = SDCC_CMD_RCGR(2), |
| 32 | .M = SDCC_M(2), |
| 33 | .N = SDCC_N(2), |
| 34 | .D = SDCC_D(2), |
| 35 | } |
| 36 | }; |
| 37 | |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 38 | static struct pll_vote_clk gpll0_vote_clk = { |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 39 | .status = GPLL0_STATUS, |
| 40 | .status_bit = GPLL0_STATUS_ACTIVE, |
| 41 | .ena_vote = APCS_GPLL_ENA_VOTE, |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 42 | .vote_bit = BIT(0), |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 43 | }; |
| 44 | |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 45 | static struct vote_clk gcc_blsp1_ahb_clk = { |
| 46 | .cbcr_reg = BLSP1_AHB_CBCR, |
| 47 | .ena_vote = APCS_CLOCK_BRANCH_ENA_VOTE, |
| 48 | .vote_bit = BIT(10), |
| 49 | }; |
| 50 | |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 51 | /* SDHCI */ |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 52 | static int clk_init_sdc(struct msm_clk_priv *priv, int slot, uint rate) |
| 53 | { |
| 54 | int div = 8; /* 100MHz default */ |
| 55 | |
| 56 | if (rate == 200000000) |
| 57 | div = 4; |
| 58 | |
| 59 | clk_enable_cbc(priv->base + SDCC_AHB_CBCR(slot)); |
| 60 | /* 800Mhz/div, gpll0 */ |
| 61 | clk_rcg_set_rate_mnd(priv->base, &sdc_regs[slot], div, 0, 0, |
| 62 | CFG_CLK_SRC_GPLL0); |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 63 | clk_enable_gpll0(priv->base, &gpll0_vote_clk); |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 64 | clk_enable_cbc(priv->base + SDCC_APPS_CBCR(slot)); |
| 65 | |
| 66 | return rate; |
| 67 | } |
| 68 | |
| 69 | static const struct bcr_regs uart2_regs = { |
| 70 | .cfg_rcgr = BLSP1_UART2_APPS_CFG_RCGR, |
| 71 | .cmd_rcgr = BLSP1_UART2_APPS_CMD_RCGR, |
| 72 | .M = BLSP1_UART2_APPS_M, |
| 73 | .N = BLSP1_UART2_APPS_N, |
| 74 | .D = BLSP1_UART2_APPS_D, |
| 75 | }; |
| 76 | |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 77 | /* UART: 115200 */ |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 78 | static int clk_init_uart(struct msm_clk_priv *priv) |
| 79 | { |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 80 | /* Enable AHB clock */ |
| 81 | clk_enable_vote_clk(priv->base, &gcc_blsp1_ahb_clk); |
| 82 | |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 83 | /* 7372800 uart block clock @ GPLL0 */ |
| 84 | clk_rcg_set_rate_mnd(priv->base, &uart2_regs, 1, 144, 15625, |
| 85 | CFG_CLK_SRC_GPLL0); |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 86 | |
| 87 | /* Vote for gpll0 clock */ |
| 88 | clk_enable_gpll0(priv->base, &gpll0_vote_clk); |
| 89 | |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 90 | /* Enable core clk */ |
| 91 | clk_enable_cbc(priv->base + BLSP1_UART2_APPS_CBCR); |
| 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 96 | ulong msm_set_rate(struct clk *clk, ulong rate) |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 97 | { |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 98 | struct msm_clk_priv *priv = dev_get_priv(clk->dev); |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 99 | |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 100 | switch (clk->id) { |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 101 | case 0: /* SDC1 */ |
| 102 | return clk_init_sdc(priv, 0, rate); |
| 103 | break; |
| 104 | case 1: /* SDC2 */ |
| 105 | return clk_init_sdc(priv, 1, rate); |
| 106 | break; |
| 107 | case 4: /* UART2 */ |
| 108 | return clk_init_uart(priv); |
| 109 | break; |
| 110 | default: |
| 111 | return 0; |
| 112 | } |
| 113 | } |
Sumit Garg | 1d1ca6e | 2022-08-04 19:57:14 +0530 | [diff] [blame^] | 114 | |
| 115 | int msm_enable(struct clk *clk) |
| 116 | { |
| 117 | return 0; |
| 118 | } |