1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2015-2020, NVIDIA CORPORATION. All rights reserved.
6 #include <linux/bitfield.h>
8 #include <linux/clk/tegra.h>
9 #include <linux/debugfs.h>
10 #include <linux/delay.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/of_address.h>
14 #include <linux/of_platform.h>
15 #include <linux/of_reserved_mem.h>
16 #include <linux/slab.h>
17 #include <linux/thermal.h>
18 #include <soc/tegra/fuse.h>
19 #include <soc/tegra/mc.h>
21 #include "tegra210-emc.h"
22 #include "tegra210-mc.h"
24 /* CLK_RST_CONTROLLER_CLK_SOURCE_EMC */
25 #define EMC_CLK_EMC_2X_CLK_SRC_SHIFT 29
26 #define EMC_CLK_EMC_2X_CLK_SRC_MASK \
27 (0x7 << EMC_CLK_EMC_2X_CLK_SRC_SHIFT)
28 #define EMC_CLK_SOURCE_PLLM_LJ 0x4
29 #define EMC_CLK_SOURCE_PLLMB_LJ 0x5
30 #define EMC_CLK_FORCE_CC_TRIGGER BIT(27)
31 #define EMC_CLK_MC_EMC_SAME_FREQ BIT(16)
32 #define EMC_CLK_EMC_2X_CLK_DIVISOR_SHIFT 0
33 #define EMC_CLK_EMC_2X_CLK_DIVISOR_MASK \
34 (0xff << EMC_CLK_EMC_2X_CLK_DIVISOR_SHIFT)
36 /* CLK_RST_CONTROLLER_CLK_SOURCE_EMC_DLL */
37 #define DLL_CLK_EMC_DLL_CLK_SRC_SHIFT 29
38 #define DLL_CLK_EMC_DLL_CLK_SRC_MASK \
39 (0x7 << DLL_CLK_EMC_DLL_CLK_SRC_SHIFT)
40 #define DLL_CLK_EMC_DLL_DDLL_CLK_SEL_SHIFT 10
41 #define DLL_CLK_EMC_DLL_DDLL_CLK_SEL_MASK \
42 (0x3 << DLL_CLK_EMC_DLL_DDLL_CLK_SEL_SHIFT)
45 #define EMC_DLL_SWITCH_OUT 2
46 #define DLL_CLK_EMC_DLL_CLK_DIVISOR_SHIFT 0
47 #define DLL_CLK_EMC_DLL_CLK_DIVISOR_MASK \
48 (0xff << DLL_CLK_EMC_DLL_CLK_DIVISOR_SHIFT)
50 /* MC_EMEM_ARB_MISC0 */
51 #define MC_EMEM_ARB_MISC0_EMC_SAME_FREQ BIT(27)
53 /* EMC_DATA_BRLSHFT_X */
54 #define EMC0_EMC_DATA_BRLSHFT_0_INDEX 2
55 #define EMC1_EMC_DATA_BRLSHFT_0_INDEX 3
56 #define EMC0_EMC_DATA_BRLSHFT_1_INDEX 4
57 #define EMC1_EMC_DATA_BRLSHFT_1_INDEX 5
59 #define TRIM_REG(chan, rank, reg, byte) \
60 (((EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ## reg ## \
61 _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte ## _MASK & \
62 next->trim_regs[EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## \
63 rank ## _ ## reg ## _INDEX]) >> \
64 EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ## reg ## \
65 _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte ## _SHIFT) \
67 (((EMC_DATA_BRLSHFT_ ## rank ## _RANK ## rank ## _BYTE ## \
68 byte ## _DATA_BRLSHFT_MASK & \
69 next->trim_perch_regs[EMC ## chan ## \
70 _EMC_DATA_BRLSHFT_ ## rank ## _INDEX]) >> \
71 EMC_DATA_BRLSHFT_ ## rank ## _RANK ## rank ## _BYTE ## \
72 byte ## _DATA_BRLSHFT_SHIFT) * 64))
74 #define CALC_TEMP(rank, reg, byte1, byte2, n) \
75 (((new[n] << EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ## \
76 reg ## _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte1 ## _SHIFT) & \
77 EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ## reg ## \
78 _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte1 ## _MASK) \
80 ((new[n + 1] << EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ##\
81 reg ## _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte2 ## _SHIFT) & \
82 EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ## reg ## \
83 _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte2 ## _MASK))
85 #define REFRESH_SPEEDUP(value, speedup) \
86 (((value) & 0xffff0000) | ((value) & 0xffff) * (speedup))
88 #define LPDDR2_MR4_SRR GENMASK(2, 0)
90 static const struct tegra210_emc_sequence
*tegra210_emc_sequences
[] = {
94 static const struct tegra210_emc_table_register_offsets
95 tegra210_emc_table_register_offsets
= {
139 EMC_BURST_REFRESH_NUM
,
140 EMC_PRE_REFRESH_REQ_CNT
,
165 EMC_CFG_DIG_DLL_PERIOD
,
169 EMC_PMACRO_QUSE_DDLL_RANK0_4
,
170 EMC_PMACRO_QUSE_DDLL_RANK0_5
,
171 EMC_PMACRO_QUSE_DDLL_RANK1_4
,
172 EMC_PMACRO_QUSE_DDLL_RANK1_5
,
174 EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_4
,
175 EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_5
,
176 EMC_PMACRO_OB_DDLL_LONG_DQS_RANK0_0
,
177 EMC_PMACRO_OB_DDLL_LONG_DQS_RANK0_1
,
178 EMC_PMACRO_OB_DDLL_LONG_DQS_RANK0_2
,
179 EMC_PMACRO_OB_DDLL_LONG_DQS_RANK0_3
,
180 EMC_PMACRO_OB_DDLL_LONG_DQS_RANK0_4
,
181 EMC_PMACRO_OB_DDLL_LONG_DQS_RANK0_5
,
182 EMC_PMACRO_OB_DDLL_LONG_DQS_RANK1_0
,
183 EMC_PMACRO_OB_DDLL_LONG_DQS_RANK1_1
,
184 EMC_PMACRO_OB_DDLL_LONG_DQS_RANK1_2
,
185 EMC_PMACRO_OB_DDLL_LONG_DQS_RANK1_3
,
186 EMC_PMACRO_OB_DDLL_LONG_DQS_RANK1_4
,
187 EMC_PMACRO_OB_DDLL_LONG_DQS_RANK1_5
,
188 EMC_PMACRO_DDLL_LONG_CMD_0
,
189 EMC_PMACRO_DDLL_LONG_CMD_1
,
190 EMC_PMACRO_DDLL_LONG_CMD_2
,
191 EMC_PMACRO_DDLL_LONG_CMD_3
,
192 EMC_PMACRO_DDLL_LONG_CMD_4
,
193 EMC_PMACRO_DDLL_SHORT_CMD_0
,
194 EMC_PMACRO_DDLL_SHORT_CMD_1
,
195 EMC_PMACRO_DDLL_SHORT_CMD_2
,
196 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK0_BYTE0_3
,
197 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK0_BYTE1_3
,
198 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK0_BYTE2_3
,
199 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK0_BYTE3_3
,
200 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK0_BYTE4_3
,
201 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK0_BYTE5_3
,
202 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK0_BYTE6_3
,
203 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK0_BYTE7_3
,
204 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK0_CMD0_3
,
205 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK0_CMD1_3
,
206 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK0_CMD2_3
,
207 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK0_CMD3_3
,
208 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_BYTE0_3
,
209 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_BYTE1_3
,
210 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_BYTE2_3
,
211 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_BYTE3_3
,
212 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_BYTE4_3
,
213 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_BYTE5_3
,
214 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_BYTE6_3
,
215 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_BYTE7_3
,
216 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_CMD0_0
,
217 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_CMD0_1
,
218 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_CMD0_2
,
219 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_CMD0_3
,
220 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_CMD1_0
,
221 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_CMD1_1
,
222 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_CMD1_2
,
223 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_CMD1_3
,
224 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_CMD2_0
,
225 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_CMD2_1
,
226 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_CMD2_2
,
227 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_CMD2_3
,
228 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_CMD3_0
,
229 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_CMD3_1
,
230 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_CMD3_2
,
231 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_CMD3_3
,
240 EMC_AUTO_CAL_CHANNEL
,
243 EMC_PMACRO_AUTOCAL_CFG_COMMON
,
247 EMC_DYN_SELF_REF_CONTROL
,
253 EMC_PMACRO_PAD_CFG_CTRL
,
254 EMC_PMACRO_DATA_PAD_RX_CTRL
,
255 EMC_PMACRO_CMD_PAD_RX_CTRL
,
256 EMC_PMACRO_DATA_RX_TERM_MODE
,
257 EMC_PMACRO_CMD_RX_TERM_MODE
,
258 EMC_PMACRO_CMD_PAD_TX_CTRL
,
259 EMC_PMACRO_DATA_PAD_TX_CTRL
,
260 EMC_PMACRO_COMMON_PAD_TX_CTRL
,
261 EMC_PMACRO_VTTGEN_CTRL_0
,
262 EMC_PMACRO_VTTGEN_CTRL_1
,
263 EMC_PMACRO_VTTGEN_CTRL_2
,
264 EMC_PMACRO_BRICK_CTRL_RFU1
,
265 EMC_PMACRO_CMD_BRICK_CTRL_FDPD
,
266 EMC_PMACRO_BRICK_CTRL_RFU2
,
267 EMC_PMACRO_DATA_BRICK_CTRL_FDPD
,
268 EMC_PMACRO_BG_BIAS_CTRL_0
,
270 EMC_PMACRO_TX_PWRD_0
,
271 EMC_PMACRO_TX_PWRD_1
,
272 EMC_PMACRO_TX_PWRD_2
,
273 EMC_PMACRO_TX_PWRD_3
,
274 EMC_PMACRO_TX_PWRD_4
,
275 EMC_PMACRO_TX_PWRD_5
,
276 EMC_CONFIG_SAMPLE_DELAY
,
277 EMC_PMACRO_TX_SEL_CLK_SRC_0
,
278 EMC_PMACRO_TX_SEL_CLK_SRC_1
,
279 EMC_PMACRO_TX_SEL_CLK_SRC_2
,
280 EMC_PMACRO_TX_SEL_CLK_SRC_3
,
281 EMC_PMACRO_TX_SEL_CLK_SRC_4
,
282 EMC_PMACRO_TX_SEL_CLK_SRC_5
,
283 EMC_PMACRO_DDLL_BYPASS
,
284 EMC_PMACRO_DDLL_PWRD_0
,
285 EMC_PMACRO_DDLL_PWRD_1
,
286 EMC_PMACRO_DDLL_PWRD_2
,
287 EMC_PMACRO_CMD_CTRL_0
,
288 EMC_PMACRO_CMD_CTRL_1
,
289 EMC_PMACRO_CMD_CTRL_2
,
301 EMC_TRAINING_VREF_SETTLE
,
302 EMC_TRAINING_CA_FINE_CTRL
,
303 EMC_TRAINING_CA_CTRL_MISC
,
304 EMC_TRAINING_CA_CTRL_MISC1
,
305 EMC_TRAINING_CA_VREF_CTRL
,
306 EMC_TRAINING_QUSE_CORS_CTRL
,
307 EMC_TRAINING_QUSE_FINE_CTRL
,
308 EMC_TRAINING_QUSE_CTRL_MISC
,
309 EMC_TRAINING_QUSE_VREF_CTRL
,
310 EMC_TRAINING_READ_FINE_CTRL
,
311 EMC_TRAINING_READ_CTRL_MISC
,
312 EMC_TRAINING_READ_VREF_CTRL
,
313 EMC_TRAINING_WRITE_FINE_CTRL
,
314 EMC_TRAINING_WRITE_CTRL_MISC
,
315 EMC_TRAINING_WRITE_VREF_CTRL
,
320 EMC_PMACRO_IB_DDLL_LONG_DQS_RANK0_0
,
321 EMC_PMACRO_IB_DDLL_LONG_DQS_RANK0_1
,
322 EMC_PMACRO_IB_DDLL_LONG_DQS_RANK0_2
,
323 EMC_PMACRO_IB_DDLL_LONG_DQS_RANK0_3
,
324 EMC_PMACRO_IB_DDLL_LONG_DQS_RANK1_0
,
325 EMC_PMACRO_IB_DDLL_LONG_DQS_RANK1_1
,
326 EMC_PMACRO_IB_DDLL_LONG_DQS_RANK1_2
,
327 EMC_PMACRO_IB_DDLL_LONG_DQS_RANK1_3
,
328 EMC_PMACRO_IB_DDLL_SHORT_DQ_RANK0_BYTE0_0
,
329 EMC_PMACRO_IB_DDLL_SHORT_DQ_RANK0_BYTE0_1
,
330 EMC_PMACRO_IB_DDLL_SHORT_DQ_RANK0_BYTE0_2
,
331 EMC_PMACRO_IB_DDLL_SHORT_DQ_RANK0_BYTE1_0
,
332 EMC_PMACRO_IB_DDLL_SHORT_DQ_RANK0_BYTE1_1
,
333 EMC_PMACRO_IB_DDLL_SHORT_DQ_RANK0_BYTE1_2
,
334 EMC_PMACRO_IB_DDLL_SHORT_DQ_RANK0_BYTE2_0
,
335 EMC_PMACRO_IB_DDLL_SHORT_DQ_RANK0_BYTE2_1
,
336 EMC_PMACRO_IB_DDLL_SHORT_DQ_RANK0_BYTE2_2
,
337 EMC_PMACRO_IB_DDLL_SHORT_DQ_RANK0_BYTE3_0
,
338 EMC_PMACRO_IB_DDLL_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,
435 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_BYTE3_0
,
436 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_BYTE3_1
,
437 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_BYTE3_2
,
438 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_BYTE4_0
,
439 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_BYTE4_1
,
440 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_BYTE4_2
,
441 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_BYTE5_0
,
442 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_BYTE5_1
,
443 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_BYTE5_2
,
444 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_BYTE6_0
,
445 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_BYTE6_1
,
446 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_BYTE6_2
,
447 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_BYTE7_0
,
448 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_BYTE7_1
,
449 EMC_PMACRO_OB_DDLL_SHORT_DQ_RANK1_BYTE7_2
,
450 EMC_PMACRO_QUSE_DDLL_RANK0_0
,
451 EMC_PMACRO_QUSE_DDLL_RANK0_1
,
452 EMC_PMACRO_QUSE_DDLL_RANK0_2
,
453 EMC_PMACRO_QUSE_DDLL_RANK0_3
,
454 EMC_PMACRO_QUSE_DDLL_RANK1_0
,
455 EMC_PMACRO_QUSE_DDLL_RANK1_1
,
456 EMC_PMACRO_QUSE_DDLL_RANK1_2
,
457 EMC_PMACRO_QUSE_DDLL_RANK1_3
461 MC_EMEM_ARB_OUTSTANDING_REQ
,
462 MC_EMEM_ARB_REFPB_HP_CTRL
,
463 MC_EMEM_ARB_REFPB_BANK_CTRL
,
464 MC_EMEM_ARB_TIMING_RCD
,
465 MC_EMEM_ARB_TIMING_RP
,
466 MC_EMEM_ARB_TIMING_RC
,
467 MC_EMEM_ARB_TIMING_RAS
,
468 MC_EMEM_ARB_TIMING_FAW
,
469 MC_EMEM_ARB_TIMING_RRD
,
470 MC_EMEM_ARB_TIMING_RAP2PRE
,
471 MC_EMEM_ARB_TIMING_WAP2PRE
,
472 MC_EMEM_ARB_TIMING_R2R
,
473 MC_EMEM_ARB_TIMING_W2W
,
474 MC_EMEM_ARB_TIMING_R2W
,
475 MC_EMEM_ARB_TIMING_CCDMW
,
476 MC_EMEM_ARB_TIMING_W2R
,
477 MC_EMEM_ARB_TIMING_RFCPB
,
478 MC_EMEM_ARB_DA_TURNS
,
479 MC_EMEM_ARB_DA_COVERS
,
483 MC_EMEM_ARB_RING1_THROTTLE
,
484 MC_EMEM_ARB_DHYST_CTRL
,
485 MC_EMEM_ARB_DHYST_TIMEOUT_UTIL_0
,
486 MC_EMEM_ARB_DHYST_TIMEOUT_UTIL_1
,
487 MC_EMEM_ARB_DHYST_TIMEOUT_UTIL_2
,
488 MC_EMEM_ARB_DHYST_TIMEOUT_UTIL_3
,
489 MC_EMEM_ARB_DHYST_TIMEOUT_UTIL_4
,
490 MC_EMEM_ARB_DHYST_TIMEOUT_UTIL_5
,
491 MC_EMEM_ARB_DHYST_TIMEOUT_UTIL_6
,
492 MC_EMEM_ARB_DHYST_TIMEOUT_UTIL_7
,
495 MC_MLL_MPCORER_PTSA_RATE
,
497 MC_PTSA_GRANT_DECREMENT
,
498 MC_LATENCY_ALLOWANCE_XUSB_0
,
499 MC_LATENCY_ALLOWANCE_XUSB_1
,
500 MC_LATENCY_ALLOWANCE_TSEC_0
,
501 MC_LATENCY_ALLOWANCE_SDMMCA_0
,
502 MC_LATENCY_ALLOWANCE_SDMMCAA_0
,
503 MC_LATENCY_ALLOWANCE_SDMMC_0
,
504 MC_LATENCY_ALLOWANCE_SDMMCAB_0
,
505 MC_LATENCY_ALLOWANCE_PPCS_0
,
506 MC_LATENCY_ALLOWANCE_PPCS_1
,
507 MC_LATENCY_ALLOWANCE_MPCORE_0
,
508 MC_LATENCY_ALLOWANCE_HC_0
,
509 MC_LATENCY_ALLOWANCE_HC_1
,
510 MC_LATENCY_ALLOWANCE_AVPC_0
,
511 MC_LATENCY_ALLOWANCE_GPU_0
,
512 MC_LATENCY_ALLOWANCE_GPU2_0
,
513 MC_LATENCY_ALLOWANCE_NVENC_0
,
514 MC_LATENCY_ALLOWANCE_NVDEC_0
,
515 MC_LATENCY_ALLOWANCE_VIC_0
,
516 MC_LATENCY_ALLOWANCE_VI2_0
,
517 MC_LATENCY_ALLOWANCE_ISP2_0
,
518 MC_LATENCY_ALLOWANCE_ISP2_1
,
520 .burst_per_channel
= {
521 { .bank
= 0, .offset
= EMC_MRW10
, },
522 { .bank
= 1, .offset
= EMC_MRW10
, },
523 { .bank
= 0, .offset
= EMC_MRW11
, },
524 { .bank
= 1, .offset
= EMC_MRW11
, },
525 { .bank
= 0, .offset
= EMC_MRW12
, },
526 { .bank
= 1, .offset
= EMC_MRW12
, },
527 { .bank
= 0, .offset
= EMC_MRW13
, },
528 { .bank
= 1, .offset
= EMC_MRW13
, },
530 .trim_per_channel
= {
531 { .bank
= 0, .offset
= EMC_CMD_BRLSHFT_0
, },
532 { .bank
= 1, .offset
= EMC_CMD_BRLSHFT_1
, },
533 { .bank
= 0, .offset
= EMC_DATA_BRLSHFT_0
, },
534 { .bank
= 1, .offset
= EMC_DATA_BRLSHFT_0
, },
535 { .bank
= 0, .offset
= EMC_DATA_BRLSHFT_1
, },
536 { .bank
= 1, .offset
= EMC_DATA_BRLSHFT_1
, },
537 { .bank
= 0, .offset
= EMC_QUSE_BRLSHFT_0
, },
538 { .bank
= 1, .offset
= EMC_QUSE_BRLSHFT_1
, },
539 { .bank
= 0, .offset
= EMC_QUSE_BRLSHFT_2
, },
540 { .bank
= 1, .offset
= EMC_QUSE_BRLSHFT_3
, },
542 .vref_per_channel
= {
545 .offset
= EMC_TRAINING_OPT_DQS_IB_VREF_RANK0
,
548 .offset
= EMC_TRAINING_OPT_DQS_IB_VREF_RANK0
,
551 .offset
= EMC_TRAINING_OPT_DQS_IB_VREF_RANK1
,
554 .offset
= EMC_TRAINING_OPT_DQS_IB_VREF_RANK1
,
559 static void tegra210_emc_train(struct timer_list
*timer
)
561 struct tegra210_emc
*emc
= from_timer(emc
, timer
, training
);
567 spin_lock_irqsave(&emc
->lock
, flags
);
569 if (emc
->sequence
->periodic_compensation
)
570 emc
->sequence
->periodic_compensation(emc
);
572 spin_unlock_irqrestore(&emc
->lock
, flags
);
574 mod_timer(&emc
->training
,
575 jiffies
+ msecs_to_jiffies(emc
->training_interval
));
578 static void tegra210_emc_training_start(struct tegra210_emc
*emc
)
580 mod_timer(&emc
->training
,
581 jiffies
+ msecs_to_jiffies(emc
->training_interval
));
584 static void tegra210_emc_training_stop(struct tegra210_emc
*emc
)
586 del_timer(&emc
->training
);
589 static unsigned int tegra210_emc_get_temperature(struct tegra210_emc
*emc
)
595 spin_lock_irqsave(&emc
->lock
, flags
);
597 for (i
= 0; i
< emc
->num_devices
; i
++) {
598 value
= tegra210_emc_mrr_read(emc
, i
, 4);
602 "sensor reading changed for device %u: %08x\n",
605 value
= FIELD_GET(LPDDR2_MR4_SRR
, value
);
610 spin_unlock_irqrestore(&emc
->lock
, flags
);
615 static void tegra210_emc_poll_refresh(struct timer_list
*timer
)
617 struct tegra210_emc
*emc
= from_timer(emc
, timer
, refresh_timer
);
618 unsigned int temperature
;
620 if (!emc
->debugfs
.temperature
)
621 temperature
= tegra210_emc_get_temperature(emc
);
623 temperature
= emc
->debugfs
.temperature
;
625 if (temperature
== emc
->temperature
)
628 switch (temperature
) {
630 /* temperature is fine, using regular refresh */
631 dev_dbg(emc
->dev
, "switching to nominal refresh...\n");
632 tegra210_emc_set_refresh(emc
, TEGRA210_EMC_REFRESH_NOMINAL
);
636 dev_dbg(emc
->dev
, "switching to 2x refresh...\n");
637 tegra210_emc_set_refresh(emc
, TEGRA210_EMC_REFRESH_2X
);
641 dev_dbg(emc
->dev
, "switching to 4x refresh...\n");
642 tegra210_emc_set_refresh(emc
, TEGRA210_EMC_REFRESH_4X
);
646 dev_dbg(emc
->dev
, "switching to throttle refresh...\n");
647 tegra210_emc_set_refresh(emc
, TEGRA210_EMC_REFRESH_THROTTLE
);
651 WARN(1, "invalid DRAM temperature state %u\n", temperature
);
655 emc
->temperature
= temperature
;
658 if (atomic_read(&emc
->refresh_poll
) > 0) {
659 unsigned int interval
= emc
->refresh_poll_interval
;
660 unsigned int timeout
= msecs_to_jiffies(interval
);
662 mod_timer(&emc
->refresh_timer
, jiffies
+ timeout
);
666 static void tegra210_emc_poll_refresh_stop(struct tegra210_emc
*emc
)
668 atomic_set(&emc
->refresh_poll
, 0);
669 del_timer_sync(&emc
->refresh_timer
);
672 static void tegra210_emc_poll_refresh_start(struct tegra210_emc
*emc
)
674 atomic_set(&emc
->refresh_poll
, 1);
676 mod_timer(&emc
->refresh_timer
,
677 jiffies
+ msecs_to_jiffies(emc
->refresh_poll_interval
));
680 static int tegra210_emc_cd_max_state(struct thermal_cooling_device
*cd
,
681 unsigned long *state
)
688 static int tegra210_emc_cd_get_state(struct thermal_cooling_device
*cd
,
689 unsigned long *state
)
691 struct tegra210_emc
*emc
= cd
->devdata
;
693 *state
= atomic_read(&emc
->refresh_poll
);
698 static int tegra210_emc_cd_set_state(struct thermal_cooling_device
*cd
,
701 struct tegra210_emc
*emc
= cd
->devdata
;
703 if (state
== atomic_read(&emc
->refresh_poll
))
707 tegra210_emc_poll_refresh_start(emc
);
709 tegra210_emc_poll_refresh_stop(emc
);
714 static struct thermal_cooling_device_ops tegra210_emc_cd_ops
= {
715 .get_max_state
= tegra210_emc_cd_max_state
,
716 .get_cur_state
= tegra210_emc_cd_get_state
,
717 .set_cur_state
= tegra210_emc_cd_set_state
,
720 static void tegra210_emc_set_clock(struct tegra210_emc
*emc
, u32 clksrc
)
722 emc
->sequence
->set_clock(emc
, clksrc
);
724 if (emc
->next
->periodic_training
)
725 tegra210_emc_training_start(emc
);
727 tegra210_emc_training_stop(emc
);
730 static void tegra210_change_dll_src(struct tegra210_emc
*emc
,
733 u32 dll_setting
= emc
->next
->dll_clk_src
;
737 emc_clk_src
= (clksrc
& EMC_CLK_EMC_2X_CLK_SRC_MASK
) >>
738 EMC_CLK_EMC_2X_CLK_SRC_SHIFT
;
739 emc_clk_div
= (clksrc
& EMC_CLK_EMC_2X_CLK_DIVISOR_MASK
) >>
740 EMC_CLK_EMC_2X_CLK_DIVISOR_SHIFT
;
742 dll_setting
&= ~(DLL_CLK_EMC_DLL_CLK_SRC_MASK
|
743 DLL_CLK_EMC_DLL_CLK_DIVISOR_MASK
);
744 dll_setting
|= emc_clk_src
<< DLL_CLK_EMC_DLL_CLK_SRC_SHIFT
;
745 dll_setting
|= emc_clk_div
<< DLL_CLK_EMC_DLL_CLK_DIVISOR_SHIFT
;
747 dll_setting
&= ~DLL_CLK_EMC_DLL_DDLL_CLK_SEL_MASK
;
748 if (emc_clk_src
== EMC_CLK_SOURCE_PLLMB_LJ
)
749 dll_setting
|= (PLLM_VCOB
<<
750 DLL_CLK_EMC_DLL_DDLL_CLK_SEL_SHIFT
);
751 else if (emc_clk_src
== EMC_CLK_SOURCE_PLLM_LJ
)
752 dll_setting
|= (PLLM_VCOA
<<
753 DLL_CLK_EMC_DLL_DDLL_CLK_SEL_SHIFT
);
755 dll_setting
|= (EMC_DLL_SWITCH_OUT
<<
756 DLL_CLK_EMC_DLL_DDLL_CLK_SEL_SHIFT
);
758 tegra210_clk_emc_dll_update_setting(dll_setting
);
760 if (emc
->next
->clk_out_enb_x_0_clk_enb_emc_dll
)
761 tegra210_clk_emc_dll_enable(true);
763 tegra210_clk_emc_dll_enable(false);
766 int tegra210_emc_set_refresh(struct tegra210_emc
*emc
,
767 enum tegra210_emc_refresh refresh
)
769 struct tegra210_emc_timing
*timings
;
772 if ((emc
->dram_type
!= DRAM_TYPE_LPDDR2
&&
773 emc
->dram_type
!= DRAM_TYPE_LPDDR4
) ||
777 if (refresh
> TEGRA210_EMC_REFRESH_THROTTLE
)
780 if (refresh
== emc
->refresh
)
783 spin_lock_irqsave(&emc
->lock
, flags
);
785 if (refresh
== TEGRA210_EMC_REFRESH_THROTTLE
&& emc
->derated
)
786 timings
= emc
->derated
;
788 timings
= emc
->nominal
;
790 if (timings
!= emc
->timings
) {
791 unsigned int index
= emc
->last
- emc
->timings
;
794 clksrc
= emc
->provider
.configs
[index
].value
|
795 EMC_CLK_FORCE_CC_TRIGGER
;
797 emc
->next
= &timings
[index
];
798 emc
->timings
= timings
;
800 tegra210_emc_set_clock(emc
, clksrc
);
802 tegra210_emc_adjust_timing(emc
, emc
->last
);
803 tegra210_emc_timing_update(emc
);
805 if (refresh
!= TEGRA210_EMC_REFRESH_NOMINAL
)
806 emc_writel(emc
, EMC_REF_REF_CMD
, EMC_REF
);
809 spin_unlock_irqrestore(&emc
->lock
, flags
);
814 u32
tegra210_emc_mrr_read(struct tegra210_emc
*emc
, unsigned int chip
,
815 unsigned int address
)
820 value
= (chip
& EMC_MRR_DEV_SEL_MASK
) << EMC_MRR_DEV_SEL_SHIFT
|
821 (address
& EMC_MRR_MA_MASK
) << EMC_MRR_MA_SHIFT
;
822 emc_writel(emc
, value
, EMC_MRR
);
824 for (i
= 0; i
< emc
->num_channels
; i
++)
825 WARN(tegra210_emc_wait_for_update(emc
, i
, EMC_EMC_STATUS
,
826 EMC_EMC_STATUS_MRR_DIVLD
, 1),
827 "Timed out waiting for MRR %u (ch=%u)\n", address
, i
);
829 for (i
= 0; i
< emc
->num_channels
; i
++) {
830 value
= emc_channel_readl(emc
, i
, EMC_MRR
);
831 value
&= EMC_MRR_DATA_MASK
;
833 ret
= (ret
<< 16) | value
;
839 void tegra210_emc_do_clock_change(struct tegra210_emc
*emc
, u32 clksrc
)
843 mc_readl(emc
->mc
, MC_EMEM_ADR_CFG
);
844 emc_readl(emc
, EMC_INTSTATUS
);
846 tegra210_clk_emc_update_setting(clksrc
);
848 err
= tegra210_emc_wait_for_update(emc
, 0, EMC_INTSTATUS
,
849 EMC_INTSTATUS_CLKCHANGE_COMPLETE
,
852 dev_warn(emc
->dev
, "clock change completion error: %d\n", err
);
855 struct tegra210_emc_timing
*tegra210_emc_find_timing(struct tegra210_emc
*emc
,
860 for (i
= 0; i
< emc
->num_timings
; i
++)
861 if (emc
->timings
[i
].rate
* 1000UL == rate
)
862 return &emc
->timings
[i
];
867 int tegra210_emc_wait_for_update(struct tegra210_emc
*emc
, unsigned int channel
,
868 unsigned int offset
, u32 bit_mask
, bool state
)
873 for (i
= 0; i
< EMC_STATUS_UPDATE_TIMEOUT
; i
++) {
874 value
= emc_channel_readl(emc
, channel
, offset
);
875 if (!!(value
& bit_mask
) == state
)
884 void tegra210_emc_set_shadow_bypass(struct tegra210_emc
*emc
, int set
)
886 u32 emc_dbg
= emc_readl(emc
, EMC_DBG
);
889 emc_writel(emc
, emc_dbg
| EMC_DBG_WRITE_MUX_ACTIVE
, EMC_DBG
);
891 emc_writel(emc
, emc_dbg
& ~EMC_DBG_WRITE_MUX_ACTIVE
, EMC_DBG
);
894 u32
tegra210_emc_get_dll_state(struct tegra210_emc_timing
*next
)
896 if (next
->emc_emrs
& 0x1)
902 void tegra210_emc_timing_update(struct tegra210_emc
*emc
)
907 emc_writel(emc
, 0x1, EMC_TIMING_CONTROL
);
909 for (i
= 0; i
< emc
->num_channels
; i
++) {
910 err
|= tegra210_emc_wait_for_update(emc
, i
, EMC_EMC_STATUS
,
911 EMC_EMC_STATUS_TIMING_UPDATE_STALLED
,
916 dev_warn(emc
->dev
, "timing update error: %d\n", err
);
919 unsigned long tegra210_emc_actual_osc_clocks(u32 in
)
931 void tegra210_emc_start_periodic_compensation(struct tegra210_emc
*emc
)
935 emc_writel(emc
, mpc_req
, EMC_MPC
);
936 mpc_req
= emc_readl(emc
, EMC_MPC
);
939 u32
tegra210_emc_compensate(struct tegra210_emc_timing
*next
, u32 offset
)
941 u32 temp
= 0, rate
= next
->rate
/ 1000;
942 s32 delta
[4], delta_taps
[4];
944 TRIM_REG(0, 0, 0, 0),
945 TRIM_REG(0, 0, 0, 1),
946 TRIM_REG(0, 0, 1, 2),
947 TRIM_REG(0, 0, 1, 3),
949 TRIM_REG(1, 0, 2, 4),
950 TRIM_REG(1, 0, 2, 5),
951 TRIM_REG(1, 0, 3, 6),
952 TRIM_REG(1, 0, 3, 7),
954 TRIM_REG(0, 1, 0, 0),
955 TRIM_REG(0, 1, 0, 1),
956 TRIM_REG(0, 1, 1, 2),
957 TRIM_REG(0, 1, 1, 3),
959 TRIM_REG(1, 1, 2, 4),
960 TRIM_REG(1, 1, 2, 5),
961 TRIM_REG(1, 1, 3, 6),
967 case EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_0
:
968 case EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_1
:
969 case EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_2
:
970 case EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_3
:
971 case EMC_DATA_BRLSHFT_0
:
972 delta
[0] = 128 * (next
->current_dram_clktree
[C0D0U0
] -
973 next
->trained_dram_clktree
[C0D0U0
]);
974 delta
[1] = 128 * (next
->current_dram_clktree
[C0D0U1
] -
975 next
->trained_dram_clktree
[C0D0U1
]);
976 delta
[2] = 128 * (next
->current_dram_clktree
[C1D0U0
] -
977 next
->trained_dram_clktree
[C1D0U0
]);
978 delta
[3] = 128 * (next
->current_dram_clktree
[C1D0U1
] -
979 next
->trained_dram_clktree
[C1D0U1
]);
981 delta_taps
[0] = (delta
[0] * (s32
)rate
) / 1000000;
982 delta_taps
[1] = (delta
[1] * (s32
)rate
) / 1000000;
983 delta_taps
[2] = (delta
[2] * (s32
)rate
) / 1000000;
984 delta_taps
[3] = (delta
[3] * (s32
)rate
) / 1000000;
986 for (i
= 0; i
< 4; i
++) {
987 if ((delta_taps
[i
] > next
->tree_margin
) ||
988 (delta_taps
[i
] < (-1 * next
->tree_margin
))) {
989 new[i
* 2] = new[i
* 2] + delta_taps
[i
];
990 new[i
* 2 + 1] = new[i
* 2 + 1] +
995 if (offset
== EMC_DATA_BRLSHFT_0
) {
996 for (i
= 0; i
< 8; i
++)
997 new[i
] = new[i
] / 64;
999 for (i
= 0; i
< 8; i
++)
1000 new[i
] = new[i
] % 64;
1005 case EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_0
:
1006 case EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_1
:
1007 case EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_2
:
1008 case EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_3
:
1009 case EMC_DATA_BRLSHFT_1
:
1010 delta
[0] = 128 * (next
->current_dram_clktree
[C0D1U0
] -
1011 next
->trained_dram_clktree
[C0D1U0
]);
1012 delta
[1] = 128 * (next
->current_dram_clktree
[C0D1U1
] -
1013 next
->trained_dram_clktree
[C0D1U1
]);
1014 delta
[2] = 128 * (next
->current_dram_clktree
[C1D1U0
] -
1015 next
->trained_dram_clktree
[C1D1U0
]);
1016 delta
[3] = 128 * (next
->current_dram_clktree
[C1D1U1
] -
1017 next
->trained_dram_clktree
[C1D1U1
]);
1019 delta_taps
[0] = (delta
[0] * (s32
)rate
) / 1000000;
1020 delta_taps
[1] = (delta
[1] * (s32
)rate
) / 1000000;
1021 delta_taps
[2] = (delta
[2] * (s32
)rate
) / 1000000;
1022 delta_taps
[3] = (delta
[3] * (s32
)rate
) / 1000000;
1024 for (i
= 0; i
< 4; i
++) {
1025 if ((delta_taps
[i
] > next
->tree_margin
) ||
1026 (delta_taps
[i
] < (-1 * next
->tree_margin
))) {
1027 new[8 + i
* 2] = new[8 + i
* 2] +
1029 new[8 + i
* 2 + 1] = new[8 + i
* 2 + 1] +
1034 if (offset
== EMC_DATA_BRLSHFT_1
) {
1035 for (i
= 0; i
< 8; i
++)
1036 new[i
+ 8] = new[i
+ 8] / 64;
1038 for (i
= 0; i
< 8; i
++)
1039 new[i
+ 8] = new[i
+ 8] % 64;
1046 case EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_0
:
1047 temp
= CALC_TEMP(0, 0, 0, 1, 0);
1050 case EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_1
:
1051 temp
= CALC_TEMP(0, 1, 2, 3, 2);
1054 case EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_2
:
1055 temp
= CALC_TEMP(0, 2, 4, 5, 4);
1058 case EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_3
:
1059 temp
= CALC_TEMP(0, 3, 6, 7, 6);
1062 case EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_0
:
1063 temp
= CALC_TEMP(1, 0, 0, 1, 8);
1066 case EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_1
:
1067 temp
= CALC_TEMP(1, 1, 2, 3, 10);
1070 case EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_2
:
1071 temp
= CALC_TEMP(1, 2, 4, 5, 12);
1074 case EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_3
:
1075 temp
= CALC_TEMP(1, 3, 6, 7, 14);
1078 case EMC_DATA_BRLSHFT_0
:
1080 EMC_DATA_BRLSHFT_0_RANK0_BYTE0_DATA_BRLSHFT_SHIFT
) &
1081 EMC_DATA_BRLSHFT_0_RANK0_BYTE0_DATA_BRLSHFT_MASK
) |
1083 EMC_DATA_BRLSHFT_0_RANK0_BYTE1_DATA_BRLSHFT_SHIFT
) &
1084 EMC_DATA_BRLSHFT_0_RANK0_BYTE1_DATA_BRLSHFT_MASK
) |
1086 EMC_DATA_BRLSHFT_0_RANK0_BYTE2_DATA_BRLSHFT_SHIFT
) &
1087 EMC_DATA_BRLSHFT_0_RANK0_BYTE2_DATA_BRLSHFT_MASK
) |
1089 EMC_DATA_BRLSHFT_0_RANK0_BYTE3_DATA_BRLSHFT_SHIFT
) &
1090 EMC_DATA_BRLSHFT_0_RANK0_BYTE3_DATA_BRLSHFT_MASK
) |
1092 EMC_DATA_BRLSHFT_0_RANK0_BYTE4_DATA_BRLSHFT_SHIFT
) &
1093 EMC_DATA_BRLSHFT_0_RANK0_BYTE4_DATA_BRLSHFT_MASK
) |
1095 EMC_DATA_BRLSHFT_0_RANK0_BYTE5_DATA_BRLSHFT_SHIFT
) &
1096 EMC_DATA_BRLSHFT_0_RANK0_BYTE5_DATA_BRLSHFT_MASK
) |
1098 EMC_DATA_BRLSHFT_0_RANK0_BYTE6_DATA_BRLSHFT_SHIFT
) &
1099 EMC_DATA_BRLSHFT_0_RANK0_BYTE6_DATA_BRLSHFT_MASK
) |
1101 EMC_DATA_BRLSHFT_0_RANK0_BYTE7_DATA_BRLSHFT_SHIFT
) &
1102 EMC_DATA_BRLSHFT_0_RANK0_BYTE7_DATA_BRLSHFT_MASK
);
1105 case EMC_DATA_BRLSHFT_1
:
1107 EMC_DATA_BRLSHFT_1_RANK1_BYTE0_DATA_BRLSHFT_SHIFT
) &
1108 EMC_DATA_BRLSHFT_1_RANK1_BYTE0_DATA_BRLSHFT_MASK
) |
1110 EMC_DATA_BRLSHFT_1_RANK1_BYTE1_DATA_BRLSHFT_SHIFT
) &
1111 EMC_DATA_BRLSHFT_1_RANK1_BYTE1_DATA_BRLSHFT_MASK
) |
1113 EMC_DATA_BRLSHFT_1_RANK1_BYTE2_DATA_BRLSHFT_SHIFT
) &
1114 EMC_DATA_BRLSHFT_1_RANK1_BYTE2_DATA_BRLSHFT_MASK
) |
1116 EMC_DATA_BRLSHFT_1_RANK1_BYTE3_DATA_BRLSHFT_SHIFT
) &
1117 EMC_DATA_BRLSHFT_1_RANK1_BYTE3_DATA_BRLSHFT_MASK
) |
1119 EMC_DATA_BRLSHFT_1_RANK1_BYTE4_DATA_BRLSHFT_SHIFT
) &
1120 EMC_DATA_BRLSHFT_1_RANK1_BYTE4_DATA_BRLSHFT_MASK
) |
1122 EMC_DATA_BRLSHFT_1_RANK1_BYTE5_DATA_BRLSHFT_SHIFT
) &
1123 EMC_DATA_BRLSHFT_1_RANK1_BYTE5_DATA_BRLSHFT_MASK
) |
1125 EMC_DATA_BRLSHFT_1_RANK1_BYTE6_DATA_BRLSHFT_SHIFT
) &
1126 EMC_DATA_BRLSHFT_1_RANK1_BYTE6_DATA_BRLSHFT_MASK
) |
1128 EMC_DATA_BRLSHFT_1_RANK1_BYTE7_DATA_BRLSHFT_SHIFT
) &
1129 EMC_DATA_BRLSHFT_1_RANK1_BYTE7_DATA_BRLSHFT_MASK
);
1139 u32
tegra210_emc_dll_prelock(struct tegra210_emc
*emc
, u32 clksrc
)
1144 value
= emc_readl(emc
, EMC_CFG_DIG_DLL
);
1145 value
&= ~EMC_CFG_DIG_DLL_CFG_DLL_LOCK_LIMIT_MASK
;
1146 value
|= (3 << EMC_CFG_DIG_DLL_CFG_DLL_LOCK_LIMIT_SHIFT
);
1147 value
&= ~EMC_CFG_DIG_DLL_CFG_DLL_EN
;
1148 value
&= ~EMC_CFG_DIG_DLL_CFG_DLL_MODE_MASK
;
1149 value
|= (3 << EMC_CFG_DIG_DLL_CFG_DLL_MODE_SHIFT
);
1150 value
|= EMC_CFG_DIG_DLL_CFG_DLL_STALL_ALL_TRAFFIC
;
1151 value
&= ~EMC_CFG_DIG_DLL_CFG_DLL_STALL_RW_UNTIL_LOCK
;
1152 value
&= ~EMC_CFG_DIG_DLL_CFG_DLL_STALL_ALL_UNTIL_LOCK
;
1153 emc_writel(emc
, value
, EMC_CFG_DIG_DLL
);
1154 emc_writel(emc
, 1, EMC_TIMING_CONTROL
);
1156 for (i
= 0; i
< emc
->num_channels
; i
++)
1157 tegra210_emc_wait_for_update(emc
, i
, EMC_EMC_STATUS
,
1158 EMC_EMC_STATUS_TIMING_UPDATE_STALLED
,
1161 for (i
= 0; i
< emc
->num_channels
; i
++) {
1163 value
= emc_channel_readl(emc
, i
, EMC_CFG_DIG_DLL
);
1164 if ((value
& EMC_CFG_DIG_DLL_CFG_DLL_EN
) == 0)
1169 value
= emc
->next
->burst_regs
[EMC_DLL_CFG_0_INDEX
];
1170 emc_writel(emc
, value
, EMC_DLL_CFG_0
);
1172 value
= emc_readl(emc
, EMC_DLL_CFG_1
);
1173 value
&= EMC_DLL_CFG_1_DDLLCAL_CTRL_START_TRIM_MASK
;
1175 if (emc
->next
->rate
>= 400000 && emc
->next
->rate
< 600000)
1177 else if (emc
->next
->rate
>= 600000 && emc
->next
->rate
< 800000)
1179 else if (emc
->next
->rate
>= 800000 && emc
->next
->rate
< 1000000)
1181 else if (emc
->next
->rate
>= 1000000 && emc
->next
->rate
< 1200000)
1186 emc_writel(emc
, value
, EMC_DLL_CFG_1
);
1188 tegra210_change_dll_src(emc
, clksrc
);
1190 value
= emc_readl(emc
, EMC_CFG_DIG_DLL
);
1191 value
|= EMC_CFG_DIG_DLL_CFG_DLL_EN
;
1192 emc_writel(emc
, value
, EMC_CFG_DIG_DLL
);
1194 tegra210_emc_timing_update(emc
);
1196 for (i
= 0; i
< emc
->num_channels
; i
++) {
1198 value
= emc_channel_readl(emc
, 0, EMC_CFG_DIG_DLL
);
1199 if (value
& EMC_CFG_DIG_DLL_CFG_DLL_EN
)
1205 value
= emc_readl(emc
, EMC_DIG_DLL_STATUS
);
1207 if ((value
& EMC_DIG_DLL_STATUS_DLL_PRIV_UPDATED
) == 0)
1210 if ((value
& EMC_DIG_DLL_STATUS_DLL_LOCK
) == 0)
1216 value
= emc_readl(emc
, EMC_DIG_DLL_STATUS
);
1218 return value
& EMC_DIG_DLL_STATUS_DLL_OUT_MASK
;
1221 u32
tegra210_emc_dvfs_power_ramp_up(struct tegra210_emc
*emc
, u32 clk
,
1224 u32 cmd_pad
, dq_pad
, rfu1
, cfg5
, common_tx
, ramp_up_wait
= 0;
1225 const struct tegra210_emc_timing
*timing
;
1232 cmd_pad
= timing
->burst_regs
[EMC_PMACRO_CMD_PAD_TX_CTRL_INDEX
];
1233 dq_pad
= timing
->burst_regs
[EMC_PMACRO_DATA_PAD_TX_CTRL_INDEX
];
1234 rfu1
= timing
->burst_regs
[EMC_PMACRO_BRICK_CTRL_RFU1_INDEX
];
1235 cfg5
= timing
->burst_regs
[EMC_FBIO_CFG5_INDEX
];
1236 common_tx
= timing
->burst_regs
[EMC_PMACRO_COMMON_PAD_TX_CTRL_INDEX
];
1238 cmd_pad
|= EMC_PMACRO_CMD_PAD_TX_CTRL_CMD_DQ_TX_DRVFORCEON
;
1240 if (clk
< 1000000 / DVFS_FGCG_MID_SPEED_THRESHOLD
) {
1241 ccfifo_writel(emc
, common_tx
& 0xa,
1242 EMC_PMACRO_COMMON_PAD_TX_CTRL
, 0);
1243 ccfifo_writel(emc
, common_tx
& 0xf,
1244 EMC_PMACRO_COMMON_PAD_TX_CTRL
,
1245 (100000 / clk
) + 1);
1246 ramp_up_wait
+= 100000;
1248 ccfifo_writel(emc
, common_tx
| 0x8,
1249 EMC_PMACRO_COMMON_PAD_TX_CTRL
, 0);
1252 if (clk
< 1000000 / DVFS_FGCG_HIGH_SPEED_THRESHOLD
) {
1253 if (clk
< 1000000 / IOBRICK_DCC_THRESHOLD
) {
1255 EMC_PMACRO_CMD_PAD_TX_CTRL_CMD_DQSP_TX_E_DCC
|
1256 EMC_PMACRO_CMD_PAD_TX_CTRL_CMD_DQSN_TX_E_DCC
;
1258 ~(EMC_PMACRO_CMD_PAD_TX_CTRL_CMD_DQ_TX_E_DCC
|
1259 EMC_PMACRO_CMD_PAD_TX_CTRL_CMD_CMD_TX_E_DCC
);
1260 ccfifo_writel(emc
, cmd_pad
,
1261 EMC_PMACRO_CMD_PAD_TX_CTRL
,
1262 (100000 / clk
) + 1);
1263 ramp_up_wait
+= 100000;
1266 EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_DQSP_TX_E_DCC
|
1267 EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_DQSN_TX_E_DCC
;
1269 ~(EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_DQ_TX_E_DCC
|
1270 EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_CMD_TX_E_DCC
);
1271 ccfifo_writel(emc
, dq_pad
,
1272 EMC_PMACRO_DATA_PAD_TX_CTRL
, 0);
1273 ccfifo_writel(emc
, rfu1
& 0xfe40fe40,
1274 EMC_PMACRO_BRICK_CTRL_RFU1
, 0);
1276 ccfifo_writel(emc
, rfu1
& 0xfe40fe40,
1277 EMC_PMACRO_BRICK_CTRL_RFU1
,
1278 (100000 / clk
) + 1);
1279 ramp_up_wait
+= 100000;
1282 ccfifo_writel(emc
, rfu1
& 0xfeedfeed,
1283 EMC_PMACRO_BRICK_CTRL_RFU1
, (100000 / clk
) + 1);
1284 ramp_up_wait
+= 100000;
1286 if (clk
< 1000000 / IOBRICK_DCC_THRESHOLD
) {
1288 EMC_PMACRO_CMD_PAD_TX_CTRL_CMD_DQSP_TX_E_DCC
|
1289 EMC_PMACRO_CMD_PAD_TX_CTRL_CMD_DQSN_TX_E_DCC
|
1290 EMC_PMACRO_CMD_PAD_TX_CTRL_CMD_DQ_TX_E_DCC
|
1291 EMC_PMACRO_CMD_PAD_TX_CTRL_CMD_CMD_TX_E_DCC
;
1292 ccfifo_writel(emc
, cmd_pad
,
1293 EMC_PMACRO_CMD_PAD_TX_CTRL
,
1294 (100000 / clk
) + 1);
1295 ramp_up_wait
+= 100000;
1298 EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_DQSP_TX_E_DCC
|
1299 EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_DQSN_TX_E_DCC
|
1300 EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_DQ_TX_E_DCC
|
1301 EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_CMD_TX_E_DCC
;
1302 ccfifo_writel(emc
, dq_pad
,
1303 EMC_PMACRO_DATA_PAD_TX_CTRL
, 0);
1304 ccfifo_writel(emc
, rfu1
,
1305 EMC_PMACRO_BRICK_CTRL_RFU1
, 0);
1307 ccfifo_writel(emc
, rfu1
,
1308 EMC_PMACRO_BRICK_CTRL_RFU1
,
1309 (100000 / clk
) + 1);
1310 ramp_up_wait
+= 100000;
1313 ccfifo_writel(emc
, cfg5
& ~EMC_FBIO_CFG5_CMD_TX_DIS
,
1314 EMC_FBIO_CFG5
, (100000 / clk
) + 10);
1315 ramp_up_wait
+= 100000 + (10 * clk
);
1316 } else if (clk
< 1000000 / DVFS_FGCG_MID_SPEED_THRESHOLD
) {
1317 ccfifo_writel(emc
, rfu1
| 0x06000600,
1318 EMC_PMACRO_BRICK_CTRL_RFU1
, (100000 / clk
) + 1);
1319 ccfifo_writel(emc
, cfg5
& ~EMC_FBIO_CFG5_CMD_TX_DIS
,
1320 EMC_FBIO_CFG5
, (100000 / clk
) + 10);
1321 ramp_up_wait
+= 100000 + 10 * clk
;
1323 ccfifo_writel(emc
, rfu1
| 0x00000600,
1324 EMC_PMACRO_BRICK_CTRL_RFU1
, 0);
1325 ccfifo_writel(emc
, cfg5
& ~EMC_FBIO_CFG5_CMD_TX_DIS
,
1327 ramp_up_wait
+= 12 * clk
;
1330 cmd_pad
&= ~EMC_PMACRO_CMD_PAD_TX_CTRL_CMD_DQ_TX_DRVFORCEON
;
1331 ccfifo_writel(emc
, cmd_pad
, EMC_PMACRO_CMD_PAD_TX_CTRL
, 5);
1333 return ramp_up_wait
;
1336 u32
tegra210_emc_dvfs_power_ramp_down(struct tegra210_emc
*emc
, u32 clk
,
1339 u32 ramp_down_wait
= 0, cmd_pad
, dq_pad
, rfu1
, cfg5
, common_tx
;
1340 const struct tegra210_emc_timing
*entry
;
1348 cmd_pad
= entry
->burst_regs
[EMC_PMACRO_CMD_PAD_TX_CTRL_INDEX
];
1349 dq_pad
= entry
->burst_regs
[EMC_PMACRO_DATA_PAD_TX_CTRL_INDEX
];
1350 rfu1
= entry
->burst_regs
[EMC_PMACRO_BRICK_CTRL_RFU1_INDEX
];
1351 cfg5
= entry
->burst_regs
[EMC_FBIO_CFG5_INDEX
];
1352 common_tx
= entry
->burst_regs
[EMC_PMACRO_COMMON_PAD_TX_CTRL_INDEX
];
1354 cmd_pad
|= EMC_PMACRO_CMD_PAD_TX_CTRL_CMD_DQ_TX_DRVFORCEON
;
1356 ccfifo_writel(emc
, cmd_pad
, EMC_PMACRO_CMD_PAD_TX_CTRL
, 0);
1357 ccfifo_writel(emc
, cfg5
| EMC_FBIO_CFG5_CMD_TX_DIS
,
1359 ramp_down_wait
= 12 * clk
;
1361 seq_wait
= (100000 / clk
) + 1;
1363 if (clk
< (1000000 / DVFS_FGCG_HIGH_SPEED_THRESHOLD
)) {
1364 if (clk
< (1000000 / IOBRICK_DCC_THRESHOLD
)) {
1366 ~(EMC_PMACRO_CMD_PAD_TX_CTRL_CMD_DQ_TX_E_DCC
|
1367 EMC_PMACRO_CMD_PAD_TX_CTRL_CMD_CMD_TX_E_DCC
);
1369 EMC_PMACRO_CMD_PAD_TX_CTRL_CMD_DQSP_TX_E_DCC
|
1370 EMC_PMACRO_CMD_PAD_TX_CTRL_CMD_DQSN_TX_E_DCC
;
1371 ccfifo_writel(emc
, cmd_pad
,
1372 EMC_PMACRO_CMD_PAD_TX_CTRL
, seq_wait
);
1373 ramp_down_wait
+= 100000;
1376 ~(EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_DQ_TX_E_DCC
|
1377 EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_CMD_TX_E_DCC
);
1379 EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_DQSP_TX_E_DCC
|
1380 EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_DQSN_TX_E_DCC
;
1381 ccfifo_writel(emc
, dq_pad
,
1382 EMC_PMACRO_DATA_PAD_TX_CTRL
, 0);
1383 ccfifo_writel(emc
, rfu1
& ~0x01120112,
1384 EMC_PMACRO_BRICK_CTRL_RFU1
, 0);
1386 ccfifo_writel(emc
, rfu1
& ~0x01120112,
1387 EMC_PMACRO_BRICK_CTRL_RFU1
, seq_wait
);
1388 ramp_down_wait
+= 100000;
1391 ccfifo_writel(emc
, rfu1
& ~0x01bf01bf,
1392 EMC_PMACRO_BRICK_CTRL_RFU1
, seq_wait
);
1393 ramp_down_wait
+= 100000;
1395 if (clk
< (1000000 / IOBRICK_DCC_THRESHOLD
)) {
1397 ~(EMC_PMACRO_CMD_PAD_TX_CTRL_CMD_DQ_TX_E_DCC
|
1398 EMC_PMACRO_CMD_PAD_TX_CTRL_CMD_CMD_TX_E_DCC
|
1399 EMC_PMACRO_CMD_PAD_TX_CTRL_CMD_DQSP_TX_E_DCC
|
1400 EMC_PMACRO_CMD_PAD_TX_CTRL_CMD_DQSN_TX_E_DCC
);
1401 ccfifo_writel(emc
, cmd_pad
,
1402 EMC_PMACRO_CMD_PAD_TX_CTRL
, seq_wait
);
1403 ramp_down_wait
+= 100000;
1406 ~(EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_DQ_TX_E_DCC
|
1407 EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_CMD_TX_E_DCC
|
1408 EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_DQSP_TX_E_DCC
|
1409 EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_DQSN_TX_E_DCC
);
1410 ccfifo_writel(emc
, dq_pad
,
1411 EMC_PMACRO_DATA_PAD_TX_CTRL
, 0);
1412 ccfifo_writel(emc
, rfu1
& ~0x07ff07ff,
1413 EMC_PMACRO_BRICK_CTRL_RFU1
, 0);
1415 ccfifo_writel(emc
, rfu1
& ~0x07ff07ff,
1416 EMC_PMACRO_BRICK_CTRL_RFU1
, seq_wait
);
1417 ramp_down_wait
+= 100000;
1420 ccfifo_writel(emc
, rfu1
& ~0xffff07ff,
1421 EMC_PMACRO_BRICK_CTRL_RFU1
, seq_wait
+ 19);
1422 ramp_down_wait
+= 100000 + (20 * clk
);
1425 if (clk
< (1000000 / DVFS_FGCG_MID_SPEED_THRESHOLD
)) {
1426 ramp_down_wait
+= 100000;
1427 ccfifo_writel(emc
, common_tx
& ~0x5,
1428 EMC_PMACRO_COMMON_PAD_TX_CTRL
, seq_wait
);
1429 ramp_down_wait
+= 100000;
1430 ccfifo_writel(emc
, common_tx
& ~0xf,
1431 EMC_PMACRO_COMMON_PAD_TX_CTRL
, seq_wait
);
1432 ramp_down_wait
+= 100000;
1433 ccfifo_writel(emc
, 0, 0, seq_wait
);
1434 ramp_down_wait
+= 100000;
1436 ccfifo_writel(emc
, common_tx
& ~0xf,
1437 EMC_PMACRO_COMMON_PAD_TX_CTRL
, seq_wait
);
1440 return ramp_down_wait
;
1443 void tegra210_emc_reset_dram_clktree_values(struct tegra210_emc_timing
*timing
)
1445 timing
->current_dram_clktree
[C0D0U0
] =
1446 timing
->trained_dram_clktree
[C0D0U0
];
1447 timing
->current_dram_clktree
[C0D0U1
] =
1448 timing
->trained_dram_clktree
[C0D0U1
];
1449 timing
->current_dram_clktree
[C1D0U0
] =
1450 timing
->trained_dram_clktree
[C1D0U0
];
1451 timing
->current_dram_clktree
[C1D0U1
] =
1452 timing
->trained_dram_clktree
[C1D0U1
];
1453 timing
->current_dram_clktree
[C1D1U0
] =
1454 timing
->trained_dram_clktree
[C1D1U0
];
1455 timing
->current_dram_clktree
[C1D1U1
] =
1456 timing
->trained_dram_clktree
[C1D1U1
];
1459 static void update_dll_control(struct tegra210_emc
*emc
, u32 value
, bool state
)
1463 emc_writel(emc
, value
, EMC_CFG_DIG_DLL
);
1464 tegra210_emc_timing_update(emc
);
1466 for (i
= 0; i
< emc
->num_channels
; i
++)
1467 tegra210_emc_wait_for_update(emc
, i
, EMC_CFG_DIG_DLL
,
1468 EMC_CFG_DIG_DLL_CFG_DLL_EN
,
1472 void tegra210_emc_dll_disable(struct tegra210_emc
*emc
)
1476 value
= emc_readl(emc
, EMC_CFG_DIG_DLL
);
1477 value
&= ~EMC_CFG_DIG_DLL_CFG_DLL_EN
;
1479 update_dll_control(emc
, value
, false);
1482 void tegra210_emc_dll_enable(struct tegra210_emc
*emc
)
1486 value
= emc_readl(emc
, EMC_CFG_DIG_DLL
);
1487 value
|= EMC_CFG_DIG_DLL_CFG_DLL_EN
;
1489 update_dll_control(emc
, value
, true);
1492 void tegra210_emc_adjust_timing(struct tegra210_emc
*emc
,
1493 struct tegra210_emc_timing
*timing
)
1495 u32 dsr_cntrl
= timing
->burst_regs
[EMC_DYN_SELF_REF_CONTROL_INDEX
];
1496 u32 pre_ref
= timing
->burst_regs
[EMC_PRE_REFRESH_REQ_CNT_INDEX
];
1497 u32 ref
= timing
->burst_regs
[EMC_REFRESH_INDEX
];
1499 switch (emc
->refresh
) {
1500 case TEGRA210_EMC_REFRESH_NOMINAL
:
1501 case TEGRA210_EMC_REFRESH_THROTTLE
:
1504 case TEGRA210_EMC_REFRESH_2X
:
1505 ref
= REFRESH_SPEEDUP(ref
, 2);
1506 pre_ref
= REFRESH_SPEEDUP(pre_ref
, 2);
1507 dsr_cntrl
= REFRESH_SPEEDUP(dsr_cntrl
, 2);
1510 case TEGRA210_EMC_REFRESH_4X
:
1511 ref
= REFRESH_SPEEDUP(ref
, 4);
1512 pre_ref
= REFRESH_SPEEDUP(pre_ref
, 4);
1513 dsr_cntrl
= REFRESH_SPEEDUP(dsr_cntrl
, 4);
1517 dev_warn(emc
->dev
, "failed to set refresh: %d\n", emc
->refresh
);
1521 emc_writel(emc
, ref
, emc
->offsets
->burst
[EMC_REFRESH_INDEX
]);
1522 emc_writel(emc
, pre_ref
,
1523 emc
->offsets
->burst
[EMC_PRE_REFRESH_REQ_CNT_INDEX
]);
1524 emc_writel(emc
, dsr_cntrl
,
1525 emc
->offsets
->burst
[EMC_DYN_SELF_REF_CONTROL_INDEX
]);
1528 static int tegra210_emc_set_rate(struct device
*dev
,
1529 const struct tegra210_clk_emc_config
*config
)
1531 struct tegra210_emc
*emc
= dev_get_drvdata(dev
);
1532 struct tegra210_emc_timing
*timing
= NULL
;
1533 unsigned long rate
= config
->rate
;
1534 s64 last_change_delay
;
1535 unsigned long flags
;
1538 if (rate
== emc
->last
->rate
* 1000UL)
1541 for (i
= 0; i
< emc
->num_timings
; i
++) {
1542 if (emc
->timings
[i
].rate
* 1000UL == rate
) {
1543 timing
= &emc
->timings
[i
];
1551 if (rate
> 204000000 && !timing
->trained
)
1555 last_change_delay
= ktime_us_delta(ktime_get(), emc
->clkchange_time
);
1557 /* XXX use non-busy-looping sleep? */
1558 if ((last_change_delay
>= 0) &&
1559 (last_change_delay
< emc
->clkchange_delay
))
1560 udelay(emc
->clkchange_delay
- (int)last_change_delay
);
1562 spin_lock_irqsave(&emc
->lock
, flags
);
1563 tegra210_emc_set_clock(emc
, config
->value
);
1564 emc
->clkchange_time
= ktime_get();
1566 spin_unlock_irqrestore(&emc
->lock
, flags
);
1574 * The memory controller driver exposes some files in debugfs that can be used
1575 * to control the EMC frequency. The top-level directory can be found here:
1577 * /sys/kernel/debug/emc
1579 * It contains the following files:
1581 * - available_rates: This file contains a list of valid, space-separated
1584 * - min_rate: Writing a value to this file sets the given frequency as the
1585 * floor of the permitted range. If this is higher than the currently
1586 * configured EMC frequency, this will cause the frequency to be
1587 * increased so that it stays within the valid range.
1589 * - max_rate: Similarily to the min_rate file, writing a value to this file
1590 * sets the given frequency as the ceiling of the permitted range. If
1591 * the value is lower than the currently configured EMC frequency, this
1592 * will cause the frequency to be decreased so that it stays within the
1596 static bool tegra210_emc_validate_rate(struct tegra210_emc
*emc
,
1601 for (i
= 0; i
< emc
->num_timings
; i
++)
1602 if (rate
== emc
->timings
[i
].rate
* 1000UL)
1608 static int tegra210_emc_debug_available_rates_show(struct seq_file
*s
,
1611 struct tegra210_emc
*emc
= s
->private;
1612 const char *prefix
= "";
1615 for (i
= 0; i
< emc
->num_timings
; i
++) {
1616 seq_printf(s
, "%s%u", prefix
, emc
->timings
[i
].rate
* 1000);
1625 static int tegra210_emc_debug_available_rates_open(struct inode
*inode
,
1628 return single_open(file
, tegra210_emc_debug_available_rates_show
,
1632 static const struct file_operations tegra210_emc_debug_available_rates_fops
= {
1633 .open
= tegra210_emc_debug_available_rates_open
,
1635 .llseek
= seq_lseek
,
1636 .release
= single_release
,
1639 static int tegra210_emc_debug_min_rate_get(void *data
, u64
*rate
)
1641 struct tegra210_emc
*emc
= data
;
1643 *rate
= emc
->debugfs
.min_rate
;
1648 static int tegra210_emc_debug_min_rate_set(void *data
, u64 rate
)
1650 struct tegra210_emc
*emc
= data
;
1653 if (!tegra210_emc_validate_rate(emc
, rate
))
1656 err
= clk_set_min_rate(emc
->clk
, rate
);
1660 emc
->debugfs
.min_rate
= rate
;
1665 DEFINE_SIMPLE_ATTRIBUTE(tegra210_emc_debug_min_rate_fops
,
1666 tegra210_emc_debug_min_rate_get
,
1667 tegra210_emc_debug_min_rate_set
, "%llu\n");
1669 static int tegra210_emc_debug_max_rate_get(void *data
, u64
*rate
)
1671 struct tegra210_emc
*emc
= data
;
1673 *rate
= emc
->debugfs
.max_rate
;
1678 static int tegra210_emc_debug_max_rate_set(void *data
, u64 rate
)
1680 struct tegra210_emc
*emc
= data
;
1683 if (!tegra210_emc_validate_rate(emc
, rate
))
1686 err
= clk_set_max_rate(emc
->clk
, rate
);
1690 emc
->debugfs
.max_rate
= rate
;
1695 DEFINE_SIMPLE_ATTRIBUTE(tegra210_emc_debug_max_rate_fops
,
1696 tegra210_emc_debug_max_rate_get
,
1697 tegra210_emc_debug_max_rate_set
, "%llu\n");
1699 static int tegra210_emc_debug_temperature_get(void *data
, u64
*temperature
)
1701 struct tegra210_emc
*emc
= data
;
1704 if (!emc
->debugfs
.temperature
)
1705 value
= tegra210_emc_get_temperature(emc
);
1707 value
= emc
->debugfs
.temperature
;
1709 *temperature
= value
;
1714 static int tegra210_emc_debug_temperature_set(void *data
, u64 temperature
)
1716 struct tegra210_emc
*emc
= data
;
1718 if (temperature
> 7)
1721 emc
->debugfs
.temperature
= temperature
;
1726 DEFINE_SIMPLE_ATTRIBUTE(tegra210_emc_debug_temperature_fops
,
1727 tegra210_emc_debug_temperature_get
,
1728 tegra210_emc_debug_temperature_set
, "%llu\n");
1730 static void tegra210_emc_debugfs_init(struct tegra210_emc
*emc
)
1732 struct device
*dev
= emc
->dev
;
1736 emc
->debugfs
.min_rate
= ULONG_MAX
;
1737 emc
->debugfs
.max_rate
= 0;
1739 for (i
= 0; i
< emc
->num_timings
; i
++) {
1740 if (emc
->timings
[i
].rate
* 1000UL < emc
->debugfs
.min_rate
)
1741 emc
->debugfs
.min_rate
= emc
->timings
[i
].rate
* 1000UL;
1743 if (emc
->timings
[i
].rate
* 1000UL > emc
->debugfs
.max_rate
)
1744 emc
->debugfs
.max_rate
= emc
->timings
[i
].rate
* 1000UL;
1747 if (!emc
->num_timings
) {
1748 emc
->debugfs
.min_rate
= clk_get_rate(emc
->clk
);
1749 emc
->debugfs
.max_rate
= emc
->debugfs
.min_rate
;
1752 err
= clk_set_rate_range(emc
->clk
, emc
->debugfs
.min_rate
,
1753 emc
->debugfs
.max_rate
);
1755 dev_err(dev
, "failed to set rate range [%lu-%lu] for %pC\n",
1756 emc
->debugfs
.min_rate
, emc
->debugfs
.max_rate
,
1761 emc
->debugfs
.root
= debugfs_create_dir("emc", NULL
);
1762 if (!emc
->debugfs
.root
) {
1763 dev_err(dev
, "failed to create debugfs directory\n");
1767 debugfs_create_file("available_rates", 0444, emc
->debugfs
.root
, emc
,
1768 &tegra210_emc_debug_available_rates_fops
);
1769 debugfs_create_file("min_rate", 0644, emc
->debugfs
.root
, emc
,
1770 &tegra210_emc_debug_min_rate_fops
);
1771 debugfs_create_file("max_rate", 0644, emc
->debugfs
.root
, emc
,
1772 &tegra210_emc_debug_max_rate_fops
);
1773 debugfs_create_file("temperature", 0644, emc
->debugfs
.root
, emc
,
1774 &tegra210_emc_debug_temperature_fops
);
1777 static void tegra210_emc_detect(struct tegra210_emc
*emc
)
1781 /* probe the number of connected DRAM devices */
1782 value
= mc_readl(emc
->mc
, MC_EMEM_ADR_CFG
);
1784 if (value
& MC_EMEM_ADR_CFG_EMEM_NUMDEV
)
1785 emc
->num_devices
= 2;
1787 emc
->num_devices
= 1;
1789 /* probe the type of DRAM */
1790 value
= emc_readl(emc
, EMC_FBIO_CFG5
);
1791 emc
->dram_type
= value
& 0x3;
1793 /* probe the number of channels */
1794 value
= emc_readl(emc
, EMC_FBIO_CFG7
);
1796 if ((value
& EMC_FBIO_CFG7_CH1_ENABLE
) &&
1797 (value
& EMC_FBIO_CFG7_CH0_ENABLE
))
1798 emc
->num_channels
= 2;
1800 emc
->num_channels
= 1;
1803 static int tegra210_emc_validate_timings(struct tegra210_emc
*emc
,
1804 struct tegra210_emc_timing
*timings
,
1805 unsigned int num_timings
)
1809 for (i
= 0; i
< num_timings
; i
++) {
1810 u32 min_volt
= timings
[i
].min_volt
;
1811 u32 rate
= timings
[i
].rate
;
1816 if ((i
> 0) && ((rate
<= timings
[i
- 1].rate
) ||
1817 (min_volt
< timings
[i
- 1].min_volt
)))
1820 if (timings
[i
].revision
!= timings
[0].revision
)
1827 static int tegra210_emc_probe(struct platform_device
*pdev
)
1829 struct thermal_cooling_device
*cd
;
1830 unsigned long current_rate
;
1831 struct tegra210_emc
*emc
;
1832 struct device_node
*np
;
1836 emc
= devm_kzalloc(&pdev
->dev
, sizeof(*emc
), GFP_KERNEL
);
1840 emc
->clk
= devm_clk_get(&pdev
->dev
, "emc");
1841 if (IS_ERR(emc
->clk
))
1842 return PTR_ERR(emc
->clk
);
1844 platform_set_drvdata(pdev
, emc
);
1845 spin_lock_init(&emc
->lock
);
1846 emc
->dev
= &pdev
->dev
;
1848 emc
->mc
= devm_tegra_memory_controller_get(&pdev
->dev
);
1849 if (IS_ERR(emc
->mc
))
1850 return PTR_ERR(emc
->mc
);
1852 emc
->regs
= devm_platform_ioremap_resource(pdev
, 0);
1853 if (IS_ERR(emc
->regs
))
1854 return PTR_ERR(emc
->regs
);
1856 for (i
= 0; i
< 2; i
++) {
1857 emc
->channel
[i
] = devm_platform_ioremap_resource(pdev
, 1 + i
);
1858 if (IS_ERR(emc
->channel
[i
]))
1859 return PTR_ERR(emc
->channel
[i
]);
1863 tegra210_emc_detect(emc
);
1864 np
= pdev
->dev
.of_node
;
1866 /* attach to the nominal and (optional) derated tables */
1867 err
= of_reserved_mem_device_init_by_name(emc
->dev
, np
, "nominal");
1869 dev_err(emc
->dev
, "failed to get nominal EMC table: %d\n", err
);
1873 err
= of_reserved_mem_device_init_by_name(emc
->dev
, np
, "derated");
1874 if (err
< 0 && err
!= -ENODEV
) {
1875 dev_err(emc
->dev
, "failed to get derated EMC table: %d\n", err
);
1879 /* validate the tables */
1881 err
= tegra210_emc_validate_timings(emc
, emc
->nominal
,
1888 err
= tegra210_emc_validate_timings(emc
, emc
->derated
,
1894 /* default to the nominal table */
1895 emc
->timings
= emc
->nominal
;
1897 /* pick the current timing based on the current EMC clock rate */
1898 current_rate
= clk_get_rate(emc
->clk
) / 1000;
1900 for (i
= 0; i
< emc
->num_timings
; i
++) {
1901 if (emc
->timings
[i
].rate
== current_rate
) {
1902 emc
->last
= &emc
->timings
[i
];
1907 if (i
== emc
->num_timings
) {
1908 dev_err(emc
->dev
, "no EMC table entry found for %lu kHz\n",
1914 /* pick a compatible clock change sequence for the EMC table */
1915 for (i
= 0; i
< ARRAY_SIZE(tegra210_emc_sequences
); i
++) {
1916 const struct tegra210_emc_sequence
*sequence
=
1917 tegra210_emc_sequences
[i
];
1919 if (emc
->timings
[0].revision
== sequence
->revision
) {
1920 emc
->sequence
= sequence
;
1925 if (!emc
->sequence
) {
1926 dev_err(&pdev
->dev
, "sequence %u not supported\n",
1927 emc
->timings
[0].revision
);
1932 emc
->offsets
= &tegra210_emc_table_register_offsets
;
1933 emc
->refresh
= TEGRA210_EMC_REFRESH_NOMINAL
;
1935 emc
->provider
.owner
= THIS_MODULE
;
1936 emc
->provider
.dev
= &pdev
->dev
;
1937 emc
->provider
.set_rate
= tegra210_emc_set_rate
;
1939 emc
->provider
.configs
= devm_kcalloc(&pdev
->dev
, emc
->num_timings
,
1940 sizeof(*emc
->provider
.configs
),
1942 if (!emc
->provider
.configs
) {
1947 emc
->provider
.num_configs
= emc
->num_timings
;
1949 for (i
= 0; i
< emc
->provider
.num_configs
; i
++) {
1950 struct tegra210_emc_timing
*timing
= &emc
->timings
[i
];
1951 struct tegra210_clk_emc_config
*config
=
1952 &emc
->provider
.configs
[i
];
1955 config
->rate
= timing
->rate
* 1000UL;
1956 config
->value
= timing
->clk_src_emc
;
1958 value
= timing
->burst_mc_regs
[MC_EMEM_ARB_MISC0_INDEX
];
1960 if ((value
& MC_EMEM_ARB_MISC0_EMC_SAME_FREQ
) == 0)
1961 config
->same_freq
= false;
1963 config
->same_freq
= true;
1966 err
= tegra210_clk_emc_attach(emc
->clk
, &emc
->provider
);
1968 dev_err(&pdev
->dev
, "failed to attach to EMC clock: %d\n", err
);
1972 emc
->clkchange_delay
= 100;
1973 emc
->training_interval
= 100;
1974 dev_set_drvdata(emc
->dev
, emc
);
1976 timer_setup(&emc
->refresh_timer
, tegra210_emc_poll_refresh
,
1978 atomic_set(&emc
->refresh_poll
, 0);
1979 emc
->refresh_poll_interval
= 1000;
1981 timer_setup(&emc
->training
, tegra210_emc_train
, 0);
1983 tegra210_emc_debugfs_init(emc
);
1985 cd
= devm_thermal_of_cooling_device_register(emc
->dev
, np
, "emc", emc
,
1986 &tegra210_emc_cd_ops
);
1989 dev_err(emc
->dev
, "failed to register cooling device: %d\n",
1997 debugfs_remove_recursive(emc
->debugfs
.root
);
1998 tegra210_clk_emc_detach(emc
->clk
);
2000 of_reserved_mem_device_release(emc
->dev
);
2005 static int tegra210_emc_remove(struct platform_device
*pdev
)
2007 struct tegra210_emc
*emc
= platform_get_drvdata(pdev
);
2009 debugfs_remove_recursive(emc
->debugfs
.root
);
2010 tegra210_clk_emc_detach(emc
->clk
);
2011 of_reserved_mem_device_release(emc
->dev
);
2016 static int __maybe_unused
tegra210_emc_suspend(struct device
*dev
)
2018 struct tegra210_emc
*emc
= dev_get_drvdata(dev
);
2021 err
= clk_rate_exclusive_get(emc
->clk
);
2023 dev_err(emc
->dev
, "failed to acquire clock: %d\n", err
);
2027 emc
->resume_rate
= clk_get_rate(emc
->clk
);
2029 clk_set_rate(emc
->clk
, 204000000);
2030 tegra210_clk_emc_detach(emc
->clk
);
2032 dev_dbg(dev
, "suspending at %lu Hz\n", clk_get_rate(emc
->clk
));
2037 static int __maybe_unused
tegra210_emc_resume(struct device
*dev
)
2039 struct tegra210_emc
*emc
= dev_get_drvdata(dev
);
2042 err
= tegra210_clk_emc_attach(emc
->clk
, &emc
->provider
);
2044 dev_err(dev
, "failed to attach to EMC clock: %d\n", err
);
2048 clk_set_rate(emc
->clk
, emc
->resume_rate
);
2049 clk_rate_exclusive_put(emc
->clk
);
2051 dev_dbg(dev
, "resuming at %lu Hz\n", clk_get_rate(emc
->clk
));
2056 static const struct dev_pm_ops tegra210_emc_pm_ops
= {
2057 SET_SYSTEM_SLEEP_PM_OPS(tegra210_emc_suspend
, tegra210_emc_resume
)
2060 static const struct of_device_id tegra210_emc_of_match
[] = {
2061 { .compatible
= "nvidia,tegra210-emc", },
2064 MODULE_DEVICE_TABLE(of
, tegra210_emc_of_match
);
2066 static struct platform_driver tegra210_emc_driver
= {
2068 .name
= "tegra210-emc",
2069 .of_match_table
= tegra210_emc_of_match
,
2070 .pm
= &tegra210_emc_pm_ops
,
2072 .probe
= tegra210_emc_probe
,
2073 .remove
= tegra210_emc_remove
,
2076 module_platform_driver(tegra210_emc_driver
);
2078 MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
2079 MODULE_AUTHOR("Joseph Lo <josephl@nvidia.com>");
2080 MODULE_DESCRIPTION("NVIDIA Tegra210 EMC driver");
2081 MODULE_LICENSE("GPL v2");