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