clk-cpu-8996.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2020, The Linux Foundation. All rights reserved.
  4. */
  5. /*
  6. * Each of the CPU clusters (Power and Perf) on msm8996 are
  7. * clocked via 2 PLLs, a primary and alternate. There are also
  8. * 2 Mux'es, a primary and secondary all connected together
  9. * as shown below
  10. *
  11. * +-------+
  12. * XO | |
  13. * +------------------>0 |
  14. * SYS_APCS_AUX | |
  15. * +------------------>3 |
  16. * | |
  17. * PLL/2 | SMUX +----+
  18. * +------->1 | |
  19. * | | | |
  20. * | +-------+ | +-------+
  21. * | +---->0 |
  22. * | | |
  23. * +---------------+ | +----------->1 | CPU clk
  24. * |Primary PLL +----+ PLL_EARLY | | +------>
  25. * | +------+-----------+ +------>2 PMUX |
  26. * +---------------+ | | | |
  27. * | +------+ | +-->3 |
  28. * +--^+ ACD +-----+ | +-------+
  29. * +---------------+ +------+ |
  30. * |Alt PLL | |
  31. * | +---------------------------+
  32. * +---------------+ PLL_EARLY
  33. *
  34. * The primary PLL is what drives the CPU clk, except for times
  35. * when we are reprogramming the PLL itself (for rate changes) when
  36. * we temporarily switch to an alternate PLL.
  37. *
  38. * The primary PLL operates on a single VCO range, between 600MHz
  39. * and 3GHz. However the CPUs do support OPPs with frequencies
  40. * between 300MHz and 600MHz. In order to support running the CPUs
  41. * at those frequencies we end up having to lock the PLL at twice
  42. * the rate and drive the CPU clk via the PLL/2 output and SMUX.
  43. *
  44. * So for frequencies above 600MHz we follow the following path
  45. * Primary PLL --> PLL_EARLY --> PMUX(1) --> CPU clk
  46. * and for frequencies between 300MHz and 600MHz we follow
  47. * Primary PLL --> PLL/2 --> SMUX(1) --> PMUX(0) --> CPU clk
  48. *
  49. * ACD stands for Adaptive Clock Distribution and is used to
  50. * detect voltage droops.
  51. */
  52. #include <linux/bitfield.h>
  53. #include <linux/clk.h>
  54. #include <linux/clk-provider.h>
  55. #include <linux/io.h>
  56. #include <linux/module.h>
  57. #include <linux/platform_device.h>
  58. #include <linux/regmap.h>
  59. #include <soc/qcom/kryo-l2-accessors.h>
  60. #include <asm/cputype.h>
  61. #include "clk-alpha-pll.h"
  62. #include "clk-regmap.h"
  63. #include "clk-regmap-mux.h"
  64. enum _pmux_input {
  65. SMUX_INDEX = 0,
  66. PLL_INDEX,
  67. ACD_INDEX,
  68. ALT_INDEX,
  69. NUM_OF_PMUX_INPUTS
  70. };
  71. #define DIV_2_THRESHOLD 600000000
  72. #define PWRCL_REG_OFFSET 0x0
  73. #define PERFCL_REG_OFFSET 0x80000
  74. #define MUX_OFFSET 0x40
  75. #define CLK_CTL_OFFSET 0x44
  76. #define CLK_CTL_AUTO_CLK_SEL BIT(8)
  77. #define ALT_PLL_OFFSET 0x100
  78. #define SSSCTL_OFFSET 0x160
  79. #define PSCTL_OFFSET 0x164
  80. #define PMUX_MASK 0x3
  81. #define MUX_AUTO_CLK_SEL_ALWAYS_ON_MASK GENMASK(5, 4)
  82. #define MUX_AUTO_CLK_SEL_ALWAYS_ON_GPLL0_SEL \
  83. FIELD_PREP(MUX_AUTO_CLK_SEL_ALWAYS_ON_MASK, 0x03)
  84. static const u8 prim_pll_regs[PLL_OFF_MAX_REGS] = {
  85. [PLL_OFF_L_VAL] = 0x04,
  86. [PLL_OFF_ALPHA_VAL] = 0x08,
  87. [PLL_OFF_USER_CTL] = 0x10,
  88. [PLL_OFF_CONFIG_CTL] = 0x18,
  89. [PLL_OFF_CONFIG_CTL_U] = 0x1c,
  90. [PLL_OFF_TEST_CTL] = 0x20,
  91. [PLL_OFF_TEST_CTL_U] = 0x24,
  92. [PLL_OFF_STATUS] = 0x28,
  93. };
  94. static const u8 alt_pll_regs[PLL_OFF_MAX_REGS] = {
  95. [PLL_OFF_L_VAL] = 0x04,
  96. [PLL_OFF_ALPHA_VAL] = 0x08,
  97. [PLL_OFF_USER_CTL] = 0x10,
  98. [PLL_OFF_CONFIG_CTL] = 0x18,
  99. [PLL_OFF_TEST_CTL] = 0x20,
  100. [PLL_OFF_STATUS] = 0x28,
  101. };
  102. /* PLLs */
  103. static const struct alpha_pll_config hfpll_config = {
  104. .l = 54,
  105. .config_ctl_val = 0x200d4828,
  106. .config_ctl_hi_val = 0x006,
  107. .test_ctl_val = 0x1c000000,
  108. .test_ctl_hi_val = 0x00004000,
  109. .pre_div_mask = BIT(12),
  110. .post_div_mask = 0x3 << 8,
  111. .post_div_val = 0x1 << 8,
  112. .main_output_mask = BIT(0),
  113. .early_output_mask = BIT(3),
  114. };
  115. static const struct clk_parent_data pll_parent[] = {
  116. { .fw_name = "xo" },
  117. };
  118. static struct clk_alpha_pll pwrcl_pll = {
  119. .offset = PWRCL_REG_OFFSET,
  120. .regs = prim_pll_regs,
  121. .flags = SUPPORTS_DYNAMIC_UPDATE | SUPPORTS_FSM_MODE,
  122. .clkr.hw.init = &(struct clk_init_data){
  123. .name = "pwrcl_pll",
  124. .parent_data = pll_parent,
  125. .num_parents = ARRAY_SIZE(pll_parent),
  126. .ops = &clk_alpha_pll_hwfsm_ops,
  127. },
  128. };
  129. static struct clk_alpha_pll perfcl_pll = {
  130. .offset = PERFCL_REG_OFFSET,
  131. .regs = prim_pll_regs,
  132. .flags = SUPPORTS_DYNAMIC_UPDATE | SUPPORTS_FSM_MODE,
  133. .clkr.hw.init = &(struct clk_init_data){
  134. .name = "perfcl_pll",
  135. .parent_data = pll_parent,
  136. .num_parents = ARRAY_SIZE(pll_parent),
  137. .ops = &clk_alpha_pll_hwfsm_ops,
  138. },
  139. };
  140. static struct clk_fixed_factor pwrcl_pll_postdiv = {
  141. .mult = 1,
  142. .div = 2,
  143. .hw.init = &(struct clk_init_data){
  144. .name = "pwrcl_pll_postdiv",
  145. .parent_data = &(const struct clk_parent_data){
  146. .hw = &pwrcl_pll.clkr.hw
  147. },
  148. .num_parents = 1,
  149. .ops = &clk_fixed_factor_ops,
  150. .flags = CLK_SET_RATE_PARENT,
  151. },
  152. };
  153. static struct clk_fixed_factor perfcl_pll_postdiv = {
  154. .mult = 1,
  155. .div = 2,
  156. .hw.init = &(struct clk_init_data){
  157. .name = "perfcl_pll_postdiv",
  158. .parent_data = &(const struct clk_parent_data){
  159. .hw = &perfcl_pll.clkr.hw
  160. },
  161. .num_parents = 1,
  162. .ops = &clk_fixed_factor_ops,
  163. .flags = CLK_SET_RATE_PARENT,
  164. },
  165. };
  166. static struct clk_fixed_factor perfcl_pll_acd = {
  167. .mult = 1,
  168. .div = 1,
  169. .hw.init = &(struct clk_init_data){
  170. .name = "perfcl_pll_acd",
  171. .parent_data = &(const struct clk_parent_data){
  172. .hw = &perfcl_pll.clkr.hw
  173. },
  174. .num_parents = 1,
  175. .ops = &clk_fixed_factor_ops,
  176. .flags = CLK_SET_RATE_PARENT,
  177. },
  178. };
  179. static struct clk_fixed_factor pwrcl_pll_acd = {
  180. .mult = 1,
  181. .div = 1,
  182. .hw.init = &(struct clk_init_data){
  183. .name = "pwrcl_pll_acd",
  184. .parent_data = &(const struct clk_parent_data){
  185. .hw = &pwrcl_pll.clkr.hw
  186. },
  187. .num_parents = 1,
  188. .ops = &clk_fixed_factor_ops,
  189. .flags = CLK_SET_RATE_PARENT,
  190. },
  191. };
  192. static const struct pll_vco alt_pll_vco_modes[] = {
  193. VCO(3, 250000000, 500000000),
  194. VCO(2, 500000000, 750000000),
  195. VCO(1, 750000000, 1000000000),
  196. VCO(0, 1000000000, 2150400000),
  197. };
  198. static const struct alpha_pll_config altpll_config = {
  199. .l = 16,
  200. .vco_val = 0x3 << 20,
  201. .vco_mask = 0x3 << 20,
  202. .config_ctl_val = 0x4001051b,
  203. .post_div_mask = 0x3 << 8,
  204. .post_div_val = 0x1 << 8,
  205. .main_output_mask = BIT(0),
  206. .early_output_mask = BIT(3),
  207. };
  208. static struct clk_alpha_pll pwrcl_alt_pll = {
  209. .offset = PWRCL_REG_OFFSET + ALT_PLL_OFFSET,
  210. .regs = alt_pll_regs,
  211. .vco_table = alt_pll_vco_modes,
  212. .num_vco = ARRAY_SIZE(alt_pll_vco_modes),
  213. .flags = SUPPORTS_OFFLINE_REQ | SUPPORTS_FSM_MODE,
  214. .clkr.hw.init = &(struct clk_init_data) {
  215. .name = "pwrcl_alt_pll",
  216. .parent_data = pll_parent,
  217. .num_parents = ARRAY_SIZE(pll_parent),
  218. .ops = &clk_alpha_pll_hwfsm_ops,
  219. },
  220. };
  221. static struct clk_alpha_pll perfcl_alt_pll = {
  222. .offset = PERFCL_REG_OFFSET + ALT_PLL_OFFSET,
  223. .regs = alt_pll_regs,
  224. .vco_table = alt_pll_vco_modes,
  225. .num_vco = ARRAY_SIZE(alt_pll_vco_modes),
  226. .flags = SUPPORTS_OFFLINE_REQ | SUPPORTS_FSM_MODE,
  227. .clkr.hw.init = &(struct clk_init_data) {
  228. .name = "perfcl_alt_pll",
  229. .parent_data = pll_parent,
  230. .num_parents = ARRAY_SIZE(pll_parent),
  231. .ops = &clk_alpha_pll_hwfsm_ops,
  232. },
  233. };
  234. struct clk_cpu_8996_pmux {
  235. u32 reg;
  236. struct notifier_block nb;
  237. struct clk_regmap clkr;
  238. };
  239. static int cpu_clk_notifier_cb(struct notifier_block *nb, unsigned long event,
  240. void *data);
  241. #define to_clk_cpu_8996_pmux_nb(_nb) \
  242. container_of(_nb, struct clk_cpu_8996_pmux, nb)
  243. static inline struct clk_cpu_8996_pmux *to_clk_cpu_8996_pmux_hw(struct clk_hw *hw)
  244. {
  245. return container_of(to_clk_regmap(hw), struct clk_cpu_8996_pmux, clkr);
  246. }
  247. static u8 clk_cpu_8996_pmux_get_parent(struct clk_hw *hw)
  248. {
  249. struct clk_regmap *clkr = to_clk_regmap(hw);
  250. struct clk_cpu_8996_pmux *cpuclk = to_clk_cpu_8996_pmux_hw(hw);
  251. u32 val;
  252. regmap_read(clkr->regmap, cpuclk->reg, &val);
  253. return FIELD_GET(PMUX_MASK, val);
  254. }
  255. static int clk_cpu_8996_pmux_set_parent(struct clk_hw *hw, u8 index)
  256. {
  257. struct clk_regmap *clkr = to_clk_regmap(hw);
  258. struct clk_cpu_8996_pmux *cpuclk = to_clk_cpu_8996_pmux_hw(hw);
  259. u32 val;
  260. val = FIELD_PREP(PMUX_MASK, index);
  261. return regmap_update_bits(clkr->regmap, cpuclk->reg, PMUX_MASK, val);
  262. }
  263. static int clk_cpu_8996_pmux_determine_rate(struct clk_hw *hw,
  264. struct clk_rate_request *req)
  265. {
  266. struct clk_hw *parent;
  267. if (req->rate < (DIV_2_THRESHOLD / 2))
  268. return -EINVAL;
  269. if (req->rate < DIV_2_THRESHOLD)
  270. parent = clk_hw_get_parent_by_index(hw, SMUX_INDEX);
  271. else
  272. parent = clk_hw_get_parent_by_index(hw, ACD_INDEX);
  273. if (!parent)
  274. return -EINVAL;
  275. req->best_parent_rate = clk_hw_round_rate(parent, req->rate);
  276. req->best_parent_hw = parent;
  277. return 0;
  278. }
  279. static const struct clk_ops clk_cpu_8996_pmux_ops = {
  280. .set_parent = clk_cpu_8996_pmux_set_parent,
  281. .get_parent = clk_cpu_8996_pmux_get_parent,
  282. .determine_rate = clk_cpu_8996_pmux_determine_rate,
  283. };
  284. static const struct parent_map smux_parent_map[] = {
  285. { .cfg = 0, }, /* xo */
  286. { .cfg = 1, }, /* pll */
  287. { .cfg = 3, }, /* sys_apcs_aux */
  288. };
  289. static const struct clk_parent_data pwrcl_smux_parents[] = {
  290. { .fw_name = "xo" },
  291. { .hw = &pwrcl_pll_postdiv.hw },
  292. { .fw_name = "sys_apcs_aux" },
  293. };
  294. static const struct clk_parent_data perfcl_smux_parents[] = {
  295. { .fw_name = "xo" },
  296. { .hw = &perfcl_pll_postdiv.hw },
  297. { .fw_name = "sys_apcs_aux" },
  298. };
  299. static struct clk_regmap_mux pwrcl_smux = {
  300. .reg = PWRCL_REG_OFFSET + MUX_OFFSET,
  301. .shift = 2,
  302. .width = 2,
  303. .parent_map = smux_parent_map,
  304. .clkr.hw.init = &(struct clk_init_data) {
  305. .name = "pwrcl_smux",
  306. .parent_data = pwrcl_smux_parents,
  307. .num_parents = ARRAY_SIZE(pwrcl_smux_parents),
  308. .ops = &clk_regmap_mux_closest_ops,
  309. .flags = CLK_SET_RATE_PARENT,
  310. },
  311. };
  312. static struct clk_regmap_mux perfcl_smux = {
  313. .reg = PERFCL_REG_OFFSET + MUX_OFFSET,
  314. .shift = 2,
  315. .width = 2,
  316. .parent_map = smux_parent_map,
  317. .clkr.hw.init = &(struct clk_init_data) {
  318. .name = "perfcl_smux",
  319. .parent_data = perfcl_smux_parents,
  320. .num_parents = ARRAY_SIZE(perfcl_smux_parents),
  321. .ops = &clk_regmap_mux_closest_ops,
  322. .flags = CLK_SET_RATE_PARENT,
  323. },
  324. };
  325. static const struct clk_hw *pwrcl_pmux_parents[] = {
  326. [SMUX_INDEX] = &pwrcl_smux.clkr.hw,
  327. [PLL_INDEX] = &pwrcl_pll.clkr.hw,
  328. [ACD_INDEX] = &pwrcl_pll_acd.hw,
  329. [ALT_INDEX] = &pwrcl_alt_pll.clkr.hw,
  330. };
  331. static const struct clk_hw *perfcl_pmux_parents[] = {
  332. [SMUX_INDEX] = &perfcl_smux.clkr.hw,
  333. [PLL_INDEX] = &perfcl_pll.clkr.hw,
  334. [ACD_INDEX] = &perfcl_pll_acd.hw,
  335. [ALT_INDEX] = &perfcl_alt_pll.clkr.hw,
  336. };
  337. static struct clk_cpu_8996_pmux pwrcl_pmux = {
  338. .reg = PWRCL_REG_OFFSET + MUX_OFFSET,
  339. .nb.notifier_call = cpu_clk_notifier_cb,
  340. .clkr.hw.init = &(struct clk_init_data) {
  341. .name = "pwrcl_pmux",
  342. .parent_hws = pwrcl_pmux_parents,
  343. .num_parents = ARRAY_SIZE(pwrcl_pmux_parents),
  344. .ops = &clk_cpu_8996_pmux_ops,
  345. /* CPU clock is critical and should never be gated */
  346. .flags = CLK_SET_RATE_PARENT | CLK_IS_CRITICAL,
  347. },
  348. };
  349. static struct clk_cpu_8996_pmux perfcl_pmux = {
  350. .reg = PERFCL_REG_OFFSET + MUX_OFFSET,
  351. .nb.notifier_call = cpu_clk_notifier_cb,
  352. .clkr.hw.init = &(struct clk_init_data) {
  353. .name = "perfcl_pmux",
  354. .parent_hws = perfcl_pmux_parents,
  355. .num_parents = ARRAY_SIZE(perfcl_pmux_parents),
  356. .ops = &clk_cpu_8996_pmux_ops,
  357. /* CPU clock is critical and should never be gated */
  358. .flags = CLK_SET_RATE_PARENT | CLK_IS_CRITICAL,
  359. },
  360. };
  361. static const struct regmap_config cpu_msm8996_regmap_config = {
  362. .reg_bits = 32,
  363. .reg_stride = 4,
  364. .val_bits = 32,
  365. .max_register = 0x80210,
  366. .fast_io = true,
  367. .val_format_endian = REGMAP_ENDIAN_LITTLE,
  368. };
  369. static struct clk_hw *cpu_msm8996_hw_clks[] = {
  370. &pwrcl_pll_postdiv.hw,
  371. &perfcl_pll_postdiv.hw,
  372. &pwrcl_pll_acd.hw,
  373. &perfcl_pll_acd.hw,
  374. };
  375. static struct clk_regmap *cpu_msm8996_clks[] = {
  376. &pwrcl_pll.clkr,
  377. &perfcl_pll.clkr,
  378. &pwrcl_alt_pll.clkr,
  379. &perfcl_alt_pll.clkr,
  380. &pwrcl_smux.clkr,
  381. &perfcl_smux.clkr,
  382. &pwrcl_pmux.clkr,
  383. &perfcl_pmux.clkr,
  384. };
  385. static void qcom_cpu_clk_msm8996_acd_init(struct regmap *regmap);
  386. static int qcom_cpu_clk_msm8996_register_clks(struct device *dev,
  387. struct regmap *regmap)
  388. {
  389. int i, ret;
  390. /* Select GPLL0 for 300MHz for both clusters */
  391. regmap_write(regmap, PERFCL_REG_OFFSET + MUX_OFFSET, 0xc);
  392. regmap_write(regmap, PWRCL_REG_OFFSET + MUX_OFFSET, 0xc);
  393. /* Ensure write goes through before PLLs are reconfigured */
  394. udelay(5);
  395. /* Set the auto clock sel always-on source to GPLL0/2 (300MHz) */
  396. regmap_update_bits(regmap, PWRCL_REG_OFFSET + MUX_OFFSET,
  397. MUX_AUTO_CLK_SEL_ALWAYS_ON_MASK,
  398. MUX_AUTO_CLK_SEL_ALWAYS_ON_GPLL0_SEL);
  399. regmap_update_bits(regmap, PERFCL_REG_OFFSET + MUX_OFFSET,
  400. MUX_AUTO_CLK_SEL_ALWAYS_ON_MASK,
  401. MUX_AUTO_CLK_SEL_ALWAYS_ON_GPLL0_SEL);
  402. clk_alpha_pll_configure(&pwrcl_pll, regmap, &hfpll_config);
  403. clk_alpha_pll_configure(&perfcl_pll, regmap, &hfpll_config);
  404. clk_alpha_pll_configure(&pwrcl_alt_pll, regmap, &altpll_config);
  405. clk_alpha_pll_configure(&perfcl_alt_pll, regmap, &altpll_config);
  406. /* Wait for PLL(s) to lock */
  407. udelay(50);
  408. /* Enable auto clock selection for both clusters */
  409. regmap_update_bits(regmap, PWRCL_REG_OFFSET + CLK_CTL_OFFSET,
  410. CLK_CTL_AUTO_CLK_SEL, CLK_CTL_AUTO_CLK_SEL);
  411. regmap_update_bits(regmap, PERFCL_REG_OFFSET + CLK_CTL_OFFSET,
  412. CLK_CTL_AUTO_CLK_SEL, CLK_CTL_AUTO_CLK_SEL);
  413. /* Ensure write goes through before muxes are switched */
  414. udelay(5);
  415. qcom_cpu_clk_msm8996_acd_init(regmap);
  416. /* Pulse swallower and soft-start settings */
  417. regmap_write(regmap, PWRCL_REG_OFFSET + PSCTL_OFFSET, 0x00030005);
  418. regmap_write(regmap, PERFCL_REG_OFFSET + PSCTL_OFFSET, 0x00030005);
  419. /* Switch clusters to use the ACD leg */
  420. regmap_write(regmap, PWRCL_REG_OFFSET + MUX_OFFSET, 0x32);
  421. regmap_write(regmap, PERFCL_REG_OFFSET + MUX_OFFSET, 0x32);
  422. for (i = 0; i < ARRAY_SIZE(cpu_msm8996_hw_clks); i++) {
  423. ret = devm_clk_hw_register(dev, cpu_msm8996_hw_clks[i]);
  424. if (ret)
  425. return ret;
  426. }
  427. for (i = 0; i < ARRAY_SIZE(cpu_msm8996_clks); i++) {
  428. ret = devm_clk_register_regmap(dev, cpu_msm8996_clks[i]);
  429. if (ret)
  430. return ret;
  431. }
  432. /* Enable alt PLLs */
  433. clk_prepare_enable(pwrcl_alt_pll.clkr.hw.clk);
  434. clk_prepare_enable(perfcl_alt_pll.clkr.hw.clk);
  435. devm_clk_notifier_register(dev, pwrcl_pmux.clkr.hw.clk, &pwrcl_pmux.nb);
  436. devm_clk_notifier_register(dev, perfcl_pmux.clkr.hw.clk, &perfcl_pmux.nb);
  437. return ret;
  438. }
  439. #define CPU_CLUSTER_AFFINITY_MASK 0xf00
  440. #define PWRCL_AFFINITY_MASK 0x000
  441. #define PERFCL_AFFINITY_MASK 0x100
  442. #define L2ACDCR_REG 0x580ULL
  443. #define L2ACDTD_REG 0x581ULL
  444. #define L2ACDDVMRC_REG 0x584ULL
  445. #define L2ACDSSCR_REG 0x589ULL
  446. static DEFINE_SPINLOCK(qcom_clk_acd_lock);
  447. static void qcom_cpu_clk_msm8996_acd_init(struct regmap *regmap)
  448. {
  449. u64 hwid;
  450. u32 val;
  451. unsigned long flags;
  452. spin_lock_irqsave(&qcom_clk_acd_lock, flags);
  453. val = kryo_l2_get_indirect_reg(L2ACDTD_REG);
  454. if (val == 0x00006a11)
  455. goto out;
  456. kryo_l2_set_indirect_reg(L2ACDTD_REG, 0x00006a11);
  457. kryo_l2_set_indirect_reg(L2ACDDVMRC_REG, 0x000e0f0f);
  458. kryo_l2_set_indirect_reg(L2ACDSSCR_REG, 0x00000601);
  459. kryo_l2_set_indirect_reg(L2ACDCR_REG, 0x002c5ffd);
  460. hwid = read_cpuid_mpidr();
  461. if ((hwid & CPU_CLUSTER_AFFINITY_MASK) == PWRCL_AFFINITY_MASK)
  462. regmap_write(regmap, PWRCL_REG_OFFSET + SSSCTL_OFFSET, 0xf);
  463. else
  464. regmap_write(regmap, PERFCL_REG_OFFSET + SSSCTL_OFFSET, 0xf);
  465. out:
  466. spin_unlock_irqrestore(&qcom_clk_acd_lock, flags);
  467. }
  468. static int cpu_clk_notifier_cb(struct notifier_block *nb, unsigned long event,
  469. void *data)
  470. {
  471. struct clk_cpu_8996_pmux *cpuclk = to_clk_cpu_8996_pmux_nb(nb);
  472. struct clk_notifier_data *cnd = data;
  473. switch (event) {
  474. case PRE_RATE_CHANGE:
  475. qcom_cpu_clk_msm8996_acd_init(cpuclk->clkr.regmap);
  476. /*
  477. * Avoid overvolting. clk_core_set_rate_nolock() walks from top
  478. * to bottom, so it will change the rate of the PLL before
  479. * chaging the parent of PMUX. This can result in pmux getting
  480. * clocked twice the expected rate.
  481. *
  482. * Manually switch to PLL/2 here.
  483. */
  484. if (cnd->new_rate < DIV_2_THRESHOLD &&
  485. cnd->old_rate > DIV_2_THRESHOLD)
  486. clk_cpu_8996_pmux_set_parent(&cpuclk->clkr.hw, SMUX_INDEX);
  487. break;
  488. case ABORT_RATE_CHANGE:
  489. /* Revert manual change */
  490. if (cnd->new_rate < DIV_2_THRESHOLD &&
  491. cnd->old_rate > DIV_2_THRESHOLD)
  492. clk_cpu_8996_pmux_set_parent(&cpuclk->clkr.hw, ACD_INDEX);
  493. break;
  494. default:
  495. break;
  496. }
  497. return NOTIFY_OK;
  498. };
  499. static int qcom_cpu_clk_msm8996_driver_probe(struct platform_device *pdev)
  500. {
  501. static void __iomem *base;
  502. struct regmap *regmap;
  503. struct clk_hw_onecell_data *data;
  504. struct device *dev = &pdev->dev;
  505. int ret;
  506. data = devm_kzalloc(dev, struct_size(data, hws, 2), GFP_KERNEL);
  507. if (!data)
  508. return -ENOMEM;
  509. data->num = 2;
  510. base = devm_platform_ioremap_resource(pdev, 0);
  511. if (IS_ERR(base))
  512. return PTR_ERR(base);
  513. regmap = devm_regmap_init_mmio(dev, base, &cpu_msm8996_regmap_config);
  514. if (IS_ERR(regmap))
  515. return PTR_ERR(regmap);
  516. ret = qcom_cpu_clk_msm8996_register_clks(dev, regmap);
  517. if (ret)
  518. return ret;
  519. data->hws[0] = &pwrcl_pmux.clkr.hw;
  520. data->hws[1] = &perfcl_pmux.clkr.hw;
  521. return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, data);
  522. }
  523. static const struct of_device_id qcom_cpu_clk_msm8996_match_table[] = {
  524. { .compatible = "qcom,msm8996-apcc" },
  525. {}
  526. };
  527. MODULE_DEVICE_TABLE(of, qcom_cpu_clk_msm8996_match_table);
  528. static struct platform_driver qcom_cpu_clk_msm8996_driver = {
  529. .probe = qcom_cpu_clk_msm8996_driver_probe,
  530. .driver = {
  531. .name = "qcom-msm8996-apcc",
  532. .of_match_table = qcom_cpu_clk_msm8996_match_table,
  533. },
  534. };
  535. module_platform_driver(qcom_cpu_clk_msm8996_driver);
  536. MODULE_DESCRIPTION("QCOM MSM8996 CPU Clock Driver");
  537. MODULE_LICENSE("GPL v2");