blob: 3bddbd2759064fdea320c8c99ec0640efb6eb395 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: BSD-3-Clause
Mateusz Kulikowski2507d822016-03-31 23:12:32 +02002/*
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 Kulikowski2507d822016-03-31 23:12:32 +02008 */
9
10#include <common.h>
Stephen Warrena9622432016-06-17 09:44:00 -060011#include <clk-uclass.h>
Mateusz Kulikowski2507d822016-03-31 23:12:32 +020012#include <dm.h>
13#include <errno.h>
14#include <asm/io.h>
15#include <linux/bitops.h>
Konrad Dybcio6c0b8442023-11-07 12:41:01 +000016
Caleb Connolly878b26a2023-11-07 12:40:59 +000017#include "clock-qcom.h"
Mateusz Kulikowski2507d822016-03-31 23:12:32 +020018
19/* GPLL0 clock control registers */
Mateusz Kulikowski2507d822016-03-31 23:12:32 +020020#define GPLL0_STATUS_ACTIVE BIT(17)
Mateusz Kulikowski2507d822016-03-31 23:12:32 +020021
Mateusz Kulikowski2507d822016-03-31 23:12:32 +020022static const struct bcr_regs sdc_regs[] = {
23 {
24 .cfg_rcgr = SDCC_CFG_RCGR(1),
25 .cmd_rcgr = SDCC_CMD_RCGR(1),
26 .M = SDCC_M(1),
27 .N = SDCC_N(1),
28 .D = SDCC_D(1),
29 },
30 {
31 .cfg_rcgr = SDCC_CFG_RCGR(2),
32 .cmd_rcgr = SDCC_CMD_RCGR(2),
33 .M = SDCC_M(2),
34 .N = SDCC_N(2),
35 .D = SDCC_D(2),
36 }
37};
38
Ramon Friedae299772018-05-16 12:13:39 +030039static struct pll_vote_clk gpll0_vote_clk = {
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010040 .status = GPLL0_STATUS,
41 .status_bit = GPLL0_STATUS_ACTIVE,
42 .ena_vote = APCS_GPLL_ENA_VOTE,
Ramon Friedae299772018-05-16 12:13:39 +030043 .vote_bit = BIT(0),
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010044};
45
Ramon Friedae299772018-05-16 12:13:39 +030046static struct vote_clk gcc_blsp1_ahb_clk = {
47 .cbcr_reg = BLSP1_AHB_CBCR,
48 .ena_vote = APCS_CLOCK_BRANCH_ENA_VOTE,
49 .vote_bit = BIT(10),
50};
51
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010052/* SDHCI */
Mateusz Kulikowski2507d822016-03-31 23:12:32 +020053static int clk_init_sdc(struct msm_clk_priv *priv, int slot, uint rate)
54{
55 int div = 8; /* 100MHz default */
56
57 if (rate == 200000000)
58 div = 4;
59
60 clk_enable_cbc(priv->base + SDCC_AHB_CBCR(slot));
61 /* 800Mhz/div, gpll0 */
62 clk_rcg_set_rate_mnd(priv->base, &sdc_regs[slot], div, 0, 0,
63 CFG_CLK_SRC_GPLL0);
Ramon Friedae299772018-05-16 12:13:39 +030064 clk_enable_gpll0(priv->base, &gpll0_vote_clk);
Mateusz Kulikowski2507d822016-03-31 23:12:32 +020065 clk_enable_cbc(priv->base + SDCC_APPS_CBCR(slot));
66
67 return rate;
68}
69
70static const struct bcr_regs uart2_regs = {
71 .cfg_rcgr = BLSP1_UART2_APPS_CFG_RCGR,
72 .cmd_rcgr = BLSP1_UART2_APPS_CMD_RCGR,
73 .M = BLSP1_UART2_APPS_M,
74 .N = BLSP1_UART2_APPS_N,
75 .D = BLSP1_UART2_APPS_D,
76};
77
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010078/* UART: 115200 */
Mateusz Kulikowski2507d822016-03-31 23:12:32 +020079static int clk_init_uart(struct msm_clk_priv *priv)
80{
Ramon Friedae299772018-05-16 12:13:39 +030081 /* Enable AHB clock */
82 clk_enable_vote_clk(priv->base, &gcc_blsp1_ahb_clk);
83
Mateusz Kulikowski2507d822016-03-31 23:12:32 +020084 /* 7372800 uart block clock @ GPLL0 */
85 clk_rcg_set_rate_mnd(priv->base, &uart2_regs, 1, 144, 15625,
86 CFG_CLK_SRC_GPLL0);
Ramon Friedae299772018-05-16 12:13:39 +030087
88 /* Vote for gpll0 clock */
89 clk_enable_gpll0(priv->base, &gpll0_vote_clk);
90
Mateusz Kulikowski2507d822016-03-31 23:12:32 +020091 /* Enable core clk */
92 clk_enable_cbc(priv->base + BLSP1_UART2_APPS_CBCR);
93
94 return 0;
95}
96
Stephen Warrena9622432016-06-17 09:44:00 -060097ulong msm_set_rate(struct clk *clk, ulong rate)
Mateusz Kulikowski2507d822016-03-31 23:12:32 +020098{
Stephen Warrena9622432016-06-17 09:44:00 -060099 struct msm_clk_priv *priv = dev_get_priv(clk->dev);
Mateusz Kulikowski2507d822016-03-31 23:12:32 +0200100
Stephen Warrena9622432016-06-17 09:44:00 -0600101 switch (clk->id) {
Mateusz Kulikowski2507d822016-03-31 23:12:32 +0200102 case 0: /* SDC1 */
103 return clk_init_sdc(priv, 0, rate);
104 break;
105 case 1: /* SDC2 */
106 return clk_init_sdc(priv, 1, rate);
107 break;
108 case 4: /* UART2 */
109 return clk_init_uart(priv);
110 break;
111 default:
112 return 0;
113 }
114}
Sumit Garg1d1ca6e2022-08-04 19:57:14 +0530115
116int msm_enable(struct clk *clk)
117{
118 return 0;
119}
Konrad Dybcio6c0b8442023-11-07 12:41:01 +0000120
121static const struct udevice_id gcc_apq8016_of_match[] = {
122 {
123 .compatible = "qcom,gcc-apq8016",
124 /* TODO: add reset map */
125 },
126 { }
127};
128
129U_BOOT_DRIVER(gcc_apq8016) = {
130 .name = "gcc_apq8016",
131 .id = UCLASS_NOP,
132 .of_match = gcc_apq8016_of_match,
133 .bind = qcom_cc_bind,
134 .flags = DM_FLAG_PRE_RELOC,
135};