Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause |
Jorge Ramirez-Ortiz | 4b684a6 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Clock drivers for Qualcomm APQ8096 |
| 4 | * |
| 5 | * (C) Copyright 2017 Jorge Ramirez Ortiz <jorge.ramirez-ortiz@linaro.org> |
| 6 | * |
| 7 | * Based on Little Kernel driver, simplified |
Jorge Ramirez-Ortiz | 4b684a6 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <clk-uclass.h> |
| 12 | #include <dm.h> |
| 13 | #include <errno.h> |
| 14 | #include <asm/io.h> |
| 15 | #include <linux/bitops.h> |
| 16 | #include "clock-snapdragon.h" |
| 17 | |
| 18 | /* GPLL0 clock control registers */ |
| 19 | #define GPLL0_STATUS_ACTIVE BIT(30) |
| 20 | #define APCS_GPLL_ENA_VOTE_GPLL0 BIT(0) |
| 21 | |
| 22 | static const struct bcr_regs sdc_regs = { |
| 23 | .cfg_rcgr = SDCC2_CFG_RCGR, |
| 24 | .cmd_rcgr = SDCC2_CMD_RCGR, |
| 25 | .M = SDCC2_M, |
| 26 | .N = SDCC2_N, |
| 27 | .D = SDCC2_D, |
| 28 | }; |
| 29 | |
Ramon Fried | 640dc34 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 30 | static const struct pll_vote_clk gpll0_vote_clk = { |
Jorge Ramirez-Ortiz | 4b684a6 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 31 | .status = GPLL0_STATUS, |
| 32 | .status_bit = GPLL0_STATUS_ACTIVE, |
| 33 | .ena_vote = APCS_GPLL_ENA_VOTE, |
| 34 | .vote_bit = APCS_GPLL_ENA_VOTE_GPLL0, |
| 35 | }; |
| 36 | |
Ramon Fried | 604aa9d | 2019-01-12 11:47:24 +0200 | [diff] [blame] | 37 | static struct vote_clk gcc_blsp2_ahb_clk = { |
| 38 | .cbcr_reg = BLSP2_AHB_CBCR, |
| 39 | .ena_vote = APCS_CLOCK_BRANCH_ENA_VOTE, |
| 40 | .vote_bit = BIT(15), |
| 41 | }; |
| 42 | |
Jorge Ramirez-Ortiz | 4b684a6 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 43 | static int clk_init_sdc(struct msm_clk_priv *priv, uint rate) |
| 44 | { |
| 45 | int div = 3; |
| 46 | |
| 47 | clk_enable_cbc(priv->base + SDCC2_AHB_CBCR); |
| 48 | clk_rcg_set_rate_mnd(priv->base, &sdc_regs, div, 0, 0, |
| 49 | CFG_CLK_SRC_GPLL0); |
Ramon Fried | 640dc34 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 50 | clk_enable_gpll0(priv->base, &gpll0_vote_clk); |
Jorge Ramirez-Ortiz | 4b684a6 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 51 | clk_enable_cbc(priv->base + SDCC2_APPS_CBCR); |
| 52 | |
| 53 | return rate; |
| 54 | } |
| 55 | |
Ramon Fried | 604aa9d | 2019-01-12 11:47:24 +0200 | [diff] [blame] | 56 | static const struct bcr_regs uart2_regs = { |
| 57 | .cfg_rcgr = BLSP2_UART2_APPS_CFG_RCGR, |
| 58 | .cmd_rcgr = BLSP2_UART2_APPS_CMD_RCGR, |
| 59 | .M = BLSP2_UART2_APPS_M, |
| 60 | .N = BLSP2_UART2_APPS_N, |
| 61 | .D = BLSP2_UART2_APPS_D, |
| 62 | }; |
| 63 | |
| 64 | static int clk_init_uart(struct msm_clk_priv *priv) |
| 65 | { |
| 66 | /* Enable AHB clock */ |
| 67 | clk_enable_vote_clk(priv->base, &gcc_blsp2_ahb_clk); |
| 68 | |
| 69 | /* 7372800 uart block clock @ GPLL0 */ |
| 70 | clk_rcg_set_rate_mnd(priv->base, &uart2_regs, 1, 192, 15625, |
| 71 | CFG_CLK_SRC_GPLL0); |
| 72 | |
| 73 | /* Vote for gpll0 clock */ |
| 74 | clk_enable_gpll0(priv->base, &gpll0_vote_clk); |
| 75 | |
| 76 | /* Enable core clk */ |
| 77 | clk_enable_cbc(priv->base + BLSP2_UART2_APPS_CBCR); |
| 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
Jorge Ramirez-Ortiz | 4b684a6 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 82 | ulong msm_set_rate(struct clk *clk, ulong rate) |
| 83 | { |
| 84 | struct msm_clk_priv *priv = dev_get_priv(clk->dev); |
| 85 | |
| 86 | switch (clk->id) { |
| 87 | case 0: /* SDC1 */ |
| 88 | return clk_init_sdc(priv, rate); |
| 89 | break; |
Ramon Fried | 604aa9d | 2019-01-12 11:47:24 +0200 | [diff] [blame] | 90 | case 4: /*UART2*/ |
| 91 | return clk_init_uart(priv); |
Jorge Ramirez-Ortiz | 4b684a6 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 92 | default: |
| 93 | return 0; |
| 94 | } |
| 95 | } |
Sumit Garg | c9e384e | 2022-08-04 19:57:14 +0530 | [diff] [blame] | 96 | |
| 97 | int msm_enable(struct clk *clk) |
| 98 | { |
| 99 | return 0; |
| 100 | } |