blob: d6df0365afcaeba911cba6f165fed5283b54824d [file] [log] [blame]
Dzmitry Sankouski038f2b92021-10-17 13:44:30 +03001// SPDX-License-Identifier: BSD-3-Clause
2/*
3 * Clock drivers for Qualcomm SDM845
4 *
5 * (C) Copyright 2017 Jorge Ramirez Ortiz <jorge.ramirez-ortiz@linaro.org>
6 * (C) Copyright 2021 Dzmitry Sankouski <dsankouski@gmail.com>
7 *
8 * Based on Little Kernel driver, simplified
9 */
10
11#include <common.h>
12#include <clk-uclass.h>
13#include <dm.h>
14#include <errno.h>
15#include <asm/io.h>
16#include <linux/bitops.h>
Sumit Garg8bdffc32022-07-12 12:42:06 +053017#include <dt-bindings/clock/qcom,gcc-sdm845.h>
Dzmitry Sankouski038f2b92021-10-17 13:44:30 +030018#include "clock-snapdragon.h"
19
20#define F(f, s, h, m, n) { (f), (s), (2 * (h) - 1), (m), (n) }
21
22struct freq_tbl {
23 uint freq;
24 uint src;
25 u8 pre_div;
26 u16 m;
27 u16 n;
28};
29
30static const struct freq_tbl ftbl_gcc_qupv3_wrap0_s0_clk_src[] = {
31 F(7372800, CFG_CLK_SRC_GPLL0_EVEN, 1, 384, 15625),
32 F(14745600, CFG_CLK_SRC_GPLL0_EVEN, 1, 768, 15625),
33 F(19200000, CFG_CLK_SRC_CXO, 1, 0, 0),
34 F(29491200, CFG_CLK_SRC_GPLL0_EVEN, 1, 1536, 15625),
35 F(32000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 8, 75),
36 F(48000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 4, 25),
37 F(64000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 16, 75),
38 F(80000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 4, 15),
39 F(96000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 8, 25),
40 F(100000000, CFG_CLK_SRC_GPLL0_EVEN, 3, 0, 0),
41 F(102400000, CFG_CLK_SRC_GPLL0_EVEN, 1, 128, 375),
42 F(112000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 28, 75),
43 F(117964800, CFG_CLK_SRC_GPLL0_EVEN, 1, 6144, 15625),
44 F(120000000, CFG_CLK_SRC_GPLL0_EVEN, 2.5, 0, 0),
45 F(128000000, CFG_CLK_SRC_GPLL0, 1, 16, 75),
46 { }
47};
48
49static const struct bcr_regs uart2_regs = {
50 .cfg_rcgr = SE9_UART_APPS_CFG_RCGR,
51 .cmd_rcgr = SE9_UART_APPS_CMD_RCGR,
52 .M = SE9_UART_APPS_M,
53 .N = SE9_UART_APPS_N,
54 .D = SE9_UART_APPS_D,
55};
56
57const struct freq_tbl *qcom_find_freq(const struct freq_tbl *f, uint rate)
58{
59 if (!f)
60 return NULL;
61
62 if (!f->freq)
63 return f;
64
65 for (; f->freq; f++)
66 if (rate <= f->freq)
67 return f;
68
69 /* Default to our fastest rate */
70 return f - 1;
71}
72
73static int clk_init_uart(struct msm_clk_priv *priv, uint rate)
74{
75 const struct freq_tbl *freq = qcom_find_freq(ftbl_gcc_qupv3_wrap0_s0_clk_src, rate);
76
77 clk_rcg_set_rate_mnd(priv->base, &uart2_regs,
78 freq->pre_div, freq->m, freq->n, freq->src);
79
80 return 0;
81}
82
83ulong 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) {
Sumit Garg8bdffc32022-07-12 12:42:06 +053088 case GCC_QUPV3_WRAP1_S1_CLK: /*UART2*/
Dzmitry Sankouski038f2b92021-10-17 13:44:30 +030089 return clk_init_uart(priv, rate);
90 default:
91 return 0;
92 }
93}
Sumit Garg1d1ca6e2022-08-04 19:57:14 +053094
95int msm_enable(struct clk *clk)
96{
97 return 0;
98}