blob: 41fe4d896a7c8f79ec00659f597270c6689a8c43 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: BSD-3-Clause
Mateusz Kulikowski08592132016-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 Kulikowski08592132016-03-31 23:12:32 +02008 */
9
Stephen Warren135aa952016-06-17 09:44:00 -060010#include <clk-uclass.h>
Mateusz Kulikowski08592132016-03-31 23:12:32 +020011#include <dm.h>
12#include <errno.h>
13#include <asm/io.h>
14#include <linux/bitops.h>
Caleb Connollyc744e632024-02-26 17:26:21 +000015#include <dt-bindings/clock/qcom,gcc-msm8916.h>
Konrad Dybcio3ead6612023-11-07 12:41:01 +000016
Caleb Connollya623c142023-11-07 12:40:59 +000017#include "clock-qcom.h"
Mateusz Kulikowski08592132016-03-31 23:12:32 +020018
Caleb Connolly37ea1342023-11-07 12:41:03 +000019/* Clocks: (from CLK_CTL_BASE) */
20#define GPLL0_STATUS (0x2101C)
21#define APCS_GPLL_ENA_VOTE (0x45000)
22#define APCS_CLOCK_BRANCH_ENA_VOTE (0x45004)
23
24#define SDCC_BCR(n) ((n * 0x1000) + 0x41000)
Caleb Connollyd33d4e02024-04-03 14:07:40 +020025#define SDCC_CMD_RCGR(n) (((n + 1) * 0x1000) + 0x41004)
Caleb Connolly37ea1342023-11-07 12:41:03 +000026#define SDCC_APPS_CBCR(n) ((n * 0x1000) + 0x41018)
27#define SDCC_AHB_CBCR(n) ((n * 0x1000) + 0x4101C)
28
29/* BLSP1 AHB clock (root clock for BLSP) */
30#define BLSP1_AHB_CBCR 0x1008
31
32/* Uart clock control registers */
Sumit Garg6e992a62024-04-12 15:24:33 +053033#define BLSP1_UART1_APPS_CBCR (0x203C)
34#define BLSP1_UART1_APPS_CMD_RCGR (0x2044)
Caleb Connolly37ea1342023-11-07 12:41:03 +000035#define BLSP1_UART2_APPS_CBCR (0x302C)
36#define BLSP1_UART2_APPS_CMD_RCGR (0x3034)
Caleb Connolly37ea1342023-11-07 12:41:03 +000037
Mateusz Kulikowski08592132016-03-31 23:12:32 +020038/* GPLL0 clock control registers */
Mateusz Kulikowski08592132016-03-31 23:12:32 +020039#define GPLL0_STATUS_ACTIVE BIT(17)
Mateusz Kulikowski08592132016-03-31 23:12:32 +020040
Ramon Fried640dc342018-05-16 12:13:39 +030041static struct pll_vote_clk gpll0_vote_clk = {
Jorge Ramirez-Ortiz7c75f7f2018-01-10 11:33:49 +010042 .status = GPLL0_STATUS,
43 .status_bit = GPLL0_STATUS_ACTIVE,
44 .ena_vote = APCS_GPLL_ENA_VOTE,
Ramon Fried640dc342018-05-16 12:13:39 +030045 .vote_bit = BIT(0),
46};
47
48static struct vote_clk gcc_blsp1_ahb_clk = {
49 .cbcr_reg = BLSP1_AHB_CBCR,
50 .ena_vote = APCS_CLOCK_BRANCH_ENA_VOTE,
51 .vote_bit = BIT(10),
Jorge Ramirez-Ortiz7c75f7f2018-01-10 11:33:49 +010052};
53
54/* SDHCI */
Sumit Garg6e992a62024-04-12 15:24:33 +053055static int apq8016_clk_init_sdc(struct msm_clk_priv *priv, int slot, uint rate)
Mateusz Kulikowski08592132016-03-31 23:12:32 +020056{
Caleb Connollyd5db46c2023-11-07 12:41:05 +000057 int div = 15; /* 100MHz default */
Mateusz Kulikowski08592132016-03-31 23:12:32 +020058
59 if (rate == 200000000)
60 div = 4;
61
62 clk_enable_cbc(priv->base + SDCC_AHB_CBCR(slot));
63 /* 800Mhz/div, gpll0 */
Caleb Connollyd33d4e02024-04-03 14:07:40 +020064 clk_rcg_set_rate_mnd(priv->base, SDCC_CMD_RCGR(slot), div, 0, 0,
Caleb Connolly6acc4432023-11-07 12:41:04 +000065 CFG_CLK_SRC_GPLL0, 8);
Ramon Fried640dc342018-05-16 12:13:39 +030066 clk_enable_gpll0(priv->base, &gpll0_vote_clk);
Mateusz Kulikowski08592132016-03-31 23:12:32 +020067 clk_enable_cbc(priv->base + SDCC_APPS_CBCR(slot));
68
69 return rate;
70}
71
Jorge Ramirez-Ortiz7c75f7f2018-01-10 11:33:49 +010072/* UART: 115200 */
Sumit Garg6e992a62024-04-12 15:24:33 +053073int apq8016_clk_init_uart(phys_addr_t base, unsigned long id)
Mateusz Kulikowski08592132016-03-31 23:12:32 +020074{
Sumit Garg6e992a62024-04-12 15:24:33 +053075 u32 cmd_rcgr, apps_cbcr;
76
77 switch (id) {
78 case GCC_BLSP1_UART1_APPS_CLK:
79 cmd_rcgr = BLSP1_UART1_APPS_CMD_RCGR;
80 apps_cbcr = BLSP1_UART1_APPS_CBCR;
81 break;
82 case GCC_BLSP1_UART2_APPS_CLK:
83 cmd_rcgr = BLSP1_UART2_APPS_CMD_RCGR;
84 apps_cbcr = BLSP1_UART2_APPS_CBCR;
85 break;
86 default:
87 return 0;
88 }
89
Ramon Fried640dc342018-05-16 12:13:39 +030090 /* Enable AHB clock */
Caleb Connollycbf31522024-03-01 15:00:24 +000091 clk_enable_vote_clk(base, &gcc_blsp1_ahb_clk);
Ramon Fried640dc342018-05-16 12:13:39 +030092
Mateusz Kulikowski08592132016-03-31 23:12:32 +020093 /* 7372800 uart block clock @ GPLL0 */
Sumit Garg6e992a62024-04-12 15:24:33 +053094 clk_rcg_set_rate_mnd(base, cmd_rcgr, 1, 144, 15625, CFG_CLK_SRC_GPLL0,
95 16);
Ramon Fried640dc342018-05-16 12:13:39 +030096
97 /* Vote for gpll0 clock */
Caleb Connollycbf31522024-03-01 15:00:24 +000098 clk_enable_gpll0(base, &gpll0_vote_clk);
Ramon Fried640dc342018-05-16 12:13:39 +030099
Mateusz Kulikowski08592132016-03-31 23:12:32 +0200100 /* Enable core clk */
Sumit Garg6e992a62024-04-12 15:24:33 +0530101 clk_enable_cbc(base + apps_cbcr);
Mateusz Kulikowski08592132016-03-31 23:12:32 +0200102
103 return 0;
104}
105
Caleb Connolly37ea1342023-11-07 12:41:03 +0000106static ulong apq8016_clk_set_rate(struct clk *clk, ulong rate)
Mateusz Kulikowski08592132016-03-31 23:12:32 +0200107{
Stephen Warren135aa952016-06-17 09:44:00 -0600108 struct msm_clk_priv *priv = dev_get_priv(clk->dev);
Mateusz Kulikowski08592132016-03-31 23:12:32 +0200109
Stephen Warren135aa952016-06-17 09:44:00 -0600110 switch (clk->id) {
Caleb Connollyc744e632024-02-26 17:26:21 +0000111 case GCC_SDCC1_APPS_CLK: /* SDC1 */
Sumit Garg6e992a62024-04-12 15:24:33 +0530112 return apq8016_clk_init_sdc(priv, 0, rate);
Caleb Connollyc744e632024-02-26 17:26:21 +0000113 case GCC_SDCC2_APPS_CLK: /* SDC2 */
Sumit Garg6e992a62024-04-12 15:24:33 +0530114 return apq8016_clk_init_sdc(priv, 1, rate);
115 case GCC_BLSP1_UART1_APPS_CLK: /* UART1 */
Caleb Connollyc744e632024-02-26 17:26:21 +0000116 case GCC_BLSP1_UART2_APPS_CLK: /* UART2 */
Sumit Garg6e992a62024-04-12 15:24:33 +0530117 apq8016_clk_init_uart(priv->base, clk->id);
Caleb Connolly8a4e0432024-04-15 16:03:38 +0100118 return 7372800;
Mateusz Kulikowski08592132016-03-31 23:12:32 +0200119 default:
120 return 0;
121 }
122}
Sumit Gargc9e384e2022-08-04 19:57:14 +0530123
Caleb Connolly37ea1342023-11-07 12:41:03 +0000124static struct msm_clk_data apq8016_clk_data = {
125 .set_rate = apq8016_clk_set_rate,
126};
Konrad Dybcio3ead6612023-11-07 12:41:01 +0000127
128static const struct udevice_id gcc_apq8016_of_match[] = {
129 {
Caleb Connolly7d96cca2024-02-26 17:26:09 +0000130 .compatible = "qcom,gcc-msm8916",
Caleb Connolly37ea1342023-11-07 12:41:03 +0000131 .data = (ulong)&apq8016_clk_data,
Konrad Dybcio3ead6612023-11-07 12:41:01 +0000132 },
133 { }
134};
135
136U_BOOT_DRIVER(gcc_apq8016) = {
137 .name = "gcc_apq8016",
138 .id = UCLASS_NOP,
139 .of_match = gcc_apq8016_of_match,
140 .bind = qcom_cc_bind,
141 .flags = DM_FLAG_PRE_RELOC,
142};