2 * Copyright 2012-16 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
26 #include <linux/delay.h>
27 #include <linux/slab.h>
29 #include "core_types.h"
30 #include "link_encoder.h"
32 #include "dm_services.h"
33 #include "reg_helper.h"
34 #include "fixed31_32.h"
37 #define TO_DCE_DMCU(dmcu)\
38 container_of(dmcu, struct dce_dmcu, base)
44 #define FN(reg_name, field_name) \
45 dmcu_dce->dmcu_shift->field_name, dmcu_dce->dmcu_mask->field_name
50 /* PSR related commands */
51 #define PSR_ENABLE 0x20
54 #define PSR_SET_WAITLOOP 0x31
55 #define MCP_INIT_DMCU 0x88
56 #define MCP_INIT_IRAM 0x89
57 #define MCP_SYNC_PHY_LOCK 0x90
58 #define MCP_SYNC_PHY_UNLOCK 0x91
59 #define MCP_BL_SET_PWM_FRAC 0x6A /* Enable or disable Fractional PWM */
60 #define MASTER_COMM_CNTL_REG__MASTER_COMM_INTERRUPT_MASK 0x00000001L
63 #define mmMP0_SMN_C2PMSG_58 0x1607A
65 //Register access policy version
66 #define mmMP0_SMN_C2PMSG_91 0x1609B
68 static bool dce_dmcu_init(struct dmcu
*dmcu
)
74 bool dce_dmcu_load_iram(struct dmcu
*dmcu
,
75 unsigned int start_offset
,
79 struct dce_dmcu
*dmcu_dce
= TO_DCE_DMCU(dmcu
);
80 unsigned int count
= 0;
82 /* Enable write access to IRAM */
83 REG_UPDATE_2(DMCU_RAM_ACCESS_CTRL
,
84 IRAM_HOST_ACCESS_EN
, 1,
85 IRAM_WR_ADDR_AUTO_INC
, 1);
87 REG_WAIT(DCI_MEM_PWR_STATUS
, DMCU_IRAM_MEM_PWR_STATE
, 0, 2, 10);
89 REG_WRITE(DMCU_IRAM_WR_CTRL
, start_offset
);
91 for (count
= 0; count
< bytes
; count
++)
92 REG_WRITE(DMCU_IRAM_WR_DATA
, src
[count
]);
94 /* Disable write access to IRAM to allow dynamic sleep state */
95 REG_UPDATE_2(DMCU_RAM_ACCESS_CTRL
,
96 IRAM_HOST_ACCESS_EN
, 0,
97 IRAM_WR_ADDR_AUTO_INC
, 0);
102 static void dce_get_dmcu_psr_state(struct dmcu
*dmcu
, enum dc_psr_state
*state
)
104 struct dce_dmcu
*dmcu_dce
= TO_DCE_DMCU(dmcu
);
106 uint32_t psr_state_offset
= 0xf0;
108 /* Enable write access to IRAM */
109 REG_UPDATE(DMCU_RAM_ACCESS_CTRL
, IRAM_HOST_ACCESS_EN
, 1);
111 REG_WAIT(DCI_MEM_PWR_STATUS
, DMCU_IRAM_MEM_PWR_STATE
, 0, 2, 10);
113 /* Write address to IRAM_RD_ADDR in DMCU_IRAM_RD_CTRL */
114 REG_WRITE(DMCU_IRAM_RD_CTRL
, psr_state_offset
);
116 /* Read data from IRAM_RD_DATA in DMCU_IRAM_RD_DATA*/
117 *state
= (enum dc_psr_state
)REG_READ(DMCU_IRAM_RD_DATA
);
119 /* Disable write access to IRAM after finished using IRAM
120 * in order to allow dynamic sleep state
122 REG_UPDATE(DMCU_RAM_ACCESS_CTRL
, IRAM_HOST_ACCESS_EN
, 0);
125 static void dce_dmcu_set_psr_enable(struct dmcu
*dmcu
, bool enable
, bool wait
)
127 struct dce_dmcu
*dmcu_dce
= TO_DCE_DMCU(dmcu
);
128 unsigned int dmcu_max_retry_on_wait_reg_ready
= 801;
129 unsigned int dmcu_wait_reg_ready_interval
= 100;
131 unsigned int retryCount
;
132 enum dc_psr_state state
= PSR_STATE0
;
134 /* waitDMCUReadyForCmd */
135 REG_WAIT(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 0,
136 dmcu_wait_reg_ready_interval
,
137 dmcu_max_retry_on_wait_reg_ready
);
139 /* setDMCUParam_Cmd */
141 REG_UPDATE(MASTER_COMM_CMD_REG
, MASTER_COMM_CMD_REG_BYTE0
,
144 REG_UPDATE(MASTER_COMM_CMD_REG
, MASTER_COMM_CMD_REG_BYTE0
,
148 REG_UPDATE(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 1);
150 for (retryCount
= 0; retryCount
<= 100; retryCount
++) {
151 dce_get_dmcu_psr_state(dmcu
, &state
);
153 if (state
!= PSR_STATE0
)
156 if (state
== PSR_STATE0
)
164 static bool dce_dmcu_setup_psr(struct dmcu
*dmcu
,
165 struct dc_link
*link
,
166 struct psr_context
*psr_context
)
168 struct dce_dmcu
*dmcu_dce
= TO_DCE_DMCU(dmcu
);
170 unsigned int dmcu_max_retry_on_wait_reg_ready
= 801;
171 unsigned int dmcu_wait_reg_ready_interval
= 100;
173 union dce_dmcu_psr_config_data_reg1 masterCmdData1
;
174 union dce_dmcu_psr_config_data_reg2 masterCmdData2
;
175 union dce_dmcu_psr_config_data_reg3 masterCmdData3
;
177 link
->link_enc
->funcs
->psr_program_dp_dphy_fast_training(link
->link_enc
,
178 psr_context
->psrExitLinkTrainingRequired
);
180 /* Enable static screen interrupts for PSR supported display */
181 /* Disable the interrupt coming from other displays. */
182 REG_UPDATE_4(DMCU_INTERRUPT_TO_UC_EN_MASK
,
183 STATIC_SCREEN1_INT_TO_UC_EN
, 0,
184 STATIC_SCREEN2_INT_TO_UC_EN
, 0,
185 STATIC_SCREEN3_INT_TO_UC_EN
, 0,
186 STATIC_SCREEN4_INT_TO_UC_EN
, 0);
188 switch (psr_context
->controllerId
) {
189 /* Driver uses case 1 for unconfigured */
191 REG_UPDATE(DMCU_INTERRUPT_TO_UC_EN_MASK
,
192 STATIC_SCREEN1_INT_TO_UC_EN
, 1);
195 REG_UPDATE(DMCU_INTERRUPT_TO_UC_EN_MASK
,
196 STATIC_SCREEN2_INT_TO_UC_EN
, 1);
199 REG_UPDATE(DMCU_INTERRUPT_TO_UC_EN_MASK
,
200 STATIC_SCREEN3_INT_TO_UC_EN
, 1);
203 REG_UPDATE(DMCU_INTERRUPT_TO_UC_EN_MASK
,
204 STATIC_SCREEN4_INT_TO_UC_EN
, 1);
207 /* CZ/NL only has 4 CRTC!!
209 * There is no interrupt enable mask for these instances.
213 /* CZ/NL only has 4 CRTC!!
214 * These are here because they are defined in HW regspec,
215 * but not really valid. There is no interrupt enable mask
216 * for these instances.
220 REG_UPDATE(DMCU_INTERRUPT_TO_UC_EN_MASK
,
221 STATIC_SCREEN1_INT_TO_UC_EN
, 1);
225 link
->link_enc
->funcs
->psr_program_secondary_packet(link
->link_enc
,
226 psr_context
->sdpTransmitLineNumDeadline
);
228 /* waitDMCUReadyForCmd */
229 REG_WAIT(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 0,
230 dmcu_wait_reg_ready_interval
,
231 dmcu_max_retry_on_wait_reg_ready
);
233 /* setDMCUParam_PSRHostConfigData */
234 masterCmdData1
.u32All
= 0;
235 masterCmdData1
.bits
.timehyst_frames
= psr_context
->timehyst_frames
;
236 masterCmdData1
.bits
.hyst_lines
= psr_context
->hyst_lines
;
237 masterCmdData1
.bits
.rfb_update_auto_en
=
238 psr_context
->rfb_update_auto_en
;
239 masterCmdData1
.bits
.dp_port_num
= psr_context
->transmitterId
;
240 masterCmdData1
.bits
.dcp_sel
= psr_context
->controllerId
;
241 masterCmdData1
.bits
.phy_type
= psr_context
->phyType
;
242 masterCmdData1
.bits
.frame_cap_ind
=
243 psr_context
->psrFrameCaptureIndicationReq
;
244 masterCmdData1
.bits
.aux_chan
= psr_context
->channel
;
245 masterCmdData1
.bits
.aux_repeat
= psr_context
->aux_repeats
;
246 dm_write_reg(dmcu
->ctx
, REG(MASTER_COMM_DATA_REG1
),
247 masterCmdData1
.u32All
);
249 masterCmdData2
.u32All
= 0;
250 masterCmdData2
.bits
.dig_fe
= psr_context
->engineId
;
251 masterCmdData2
.bits
.dig_be
= psr_context
->transmitterId
;
252 masterCmdData2
.bits
.skip_wait_for_pll_lock
=
253 psr_context
->skipPsrWaitForPllLock
;
254 masterCmdData2
.bits
.frame_delay
= psr_context
->frame_delay
;
255 masterCmdData2
.bits
.smu_phy_id
= psr_context
->smuPhyId
;
256 masterCmdData2
.bits
.num_of_controllers
=
257 psr_context
->numberOfControllers
;
258 dm_write_reg(dmcu
->ctx
, REG(MASTER_COMM_DATA_REG2
),
259 masterCmdData2
.u32All
);
261 masterCmdData3
.u32All
= 0;
262 masterCmdData3
.bits
.psr_level
= psr_context
->psr_level
.u32all
;
263 dm_write_reg(dmcu
->ctx
, REG(MASTER_COMM_DATA_REG3
),
264 masterCmdData3
.u32All
);
266 /* setDMCUParam_Cmd */
267 REG_UPDATE(MASTER_COMM_CMD_REG
,
268 MASTER_COMM_CMD_REG_BYTE0
, PSR_SET
);
271 REG_UPDATE(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 1);
276 static bool dce_is_dmcu_initialized(struct dmcu
*dmcu
)
278 struct dce_dmcu
*dmcu_dce
= TO_DCE_DMCU(dmcu
);
279 unsigned int dmcu_uc_reset
;
281 /* microcontroller is not running */
282 REG_GET(DMCU_STATUS
, UC_IN_RESET
, &dmcu_uc_reset
);
284 /* DMCU is not running */
291 static void dce_psr_wait_loop(
293 unsigned int wait_loop_number
)
295 struct dce_dmcu
*dmcu_dce
= TO_DCE_DMCU(dmcu
);
296 union dce_dmcu_psr_config_data_wait_loop_reg1 masterCmdData1
;
298 if (dmcu
->cached_wait_loop_number
== wait_loop_number
)
301 /* DMCU is not running */
302 if (!dce_is_dmcu_initialized(dmcu
))
305 /* waitDMCUReadyForCmd */
306 REG_WAIT(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 0, 1, 10000);
308 masterCmdData1
.u32
= 0;
309 masterCmdData1
.bits
.wait_loop
= wait_loop_number
;
310 dmcu
->cached_wait_loop_number
= wait_loop_number
;
311 dm_write_reg(dmcu
->ctx
, REG(MASTER_COMM_DATA_REG1
), masterCmdData1
.u32
);
313 /* setDMCUParam_Cmd */
314 REG_UPDATE(MASTER_COMM_CMD_REG
, MASTER_COMM_CMD_REG_BYTE0
, PSR_SET_WAITLOOP
);
317 REG_UPDATE(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 1);
320 static void dce_get_psr_wait_loop(
321 struct dmcu
*dmcu
, unsigned int *psr_wait_loop_number
)
323 *psr_wait_loop_number
= dmcu
->cached_wait_loop_number
;
327 #if defined(CONFIG_DRM_AMD_DC_DCN)
328 static void dcn10_get_dmcu_version(struct dmcu
*dmcu
)
330 struct dce_dmcu
*dmcu_dce
= TO_DCE_DMCU(dmcu
);
331 uint32_t dmcu_version_offset
= 0xf1;
333 /* Enable write access to IRAM */
334 REG_UPDATE_2(DMCU_RAM_ACCESS_CTRL
,
335 IRAM_HOST_ACCESS_EN
, 1,
336 IRAM_RD_ADDR_AUTO_INC
, 1);
338 REG_WAIT(DMU_MEM_PWR_CNTL
, DMCU_IRAM_MEM_PWR_STATE
, 0, 2, 10);
340 /* Write address to IRAM_RD_ADDR and read from DATA register */
341 REG_WRITE(DMCU_IRAM_RD_CTRL
, dmcu_version_offset
);
342 dmcu
->dmcu_version
.interface_version
= REG_READ(DMCU_IRAM_RD_DATA
);
343 dmcu
->dmcu_version
.abm_version
= REG_READ(DMCU_IRAM_RD_DATA
);
344 dmcu
->dmcu_version
.psr_version
= REG_READ(DMCU_IRAM_RD_DATA
);
345 dmcu
->dmcu_version
.build_version
= ((REG_READ(DMCU_IRAM_RD_DATA
) << 8) |
346 REG_READ(DMCU_IRAM_RD_DATA
));
348 /* Disable write access to IRAM to allow dynamic sleep state */
349 REG_UPDATE_2(DMCU_RAM_ACCESS_CTRL
,
350 IRAM_HOST_ACCESS_EN
, 0,
351 IRAM_RD_ADDR_AUTO_INC
, 0);
354 static void dcn10_dmcu_enable_fractional_pwm(struct dmcu
*dmcu
,
355 uint32_t fractional_pwm
)
357 struct dce_dmcu
*dmcu_dce
= TO_DCE_DMCU(dmcu
);
359 /* Wait until microcontroller is ready to process interrupt */
360 REG_WAIT(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 0, 100, 800);
362 /* Set PWM fractional enable/disable */
363 REG_WRITE(MASTER_COMM_DATA_REG1
, fractional_pwm
);
365 /* Set command to enable or disable fractional PWM microcontroller */
366 REG_UPDATE(MASTER_COMM_CMD_REG
, MASTER_COMM_CMD_REG_BYTE0
,
367 MCP_BL_SET_PWM_FRAC
);
369 /* Notify microcontroller of new command */
370 REG_UPDATE(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 1);
372 /* Ensure command has been executed before continuing */
373 REG_WAIT(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 0, 100, 800);
376 static bool dcn10_dmcu_init(struct dmcu
*dmcu
)
378 struct dce_dmcu
*dmcu_dce
= TO_DCE_DMCU(dmcu
);
379 const struct dc_config
*config
= &dmcu
->ctx
->dc
->config
;
381 struct dc_context
*ctx
= dmcu
->ctx
;
384 // F E D C B A - bit 0 is A, bit 5 is F
385 unsigned int tx_interrupt_mask
= 0;
388 /* Definition of DC_DMCU_SCRATCH
389 * 0 : firmare not loaded
390 * 1 : PSP load DMCU FW but not initialized
391 * 2 : Firmware already initialized
393 dmcu
->dmcu_state
= REG_READ(DC_DMCU_SCRATCH
);
395 for (i
= 0; i
< ctx
->dc
->link_count
; i
++) {
396 if (ctx
->dc
->links
[i
]->link_enc
->features
.flags
.bits
.DP_IS_USB_C
) {
397 if (ctx
->dc
->links
[i
]->link_enc
->transmitter
>= TRANSMITTER_UNIPHY_A
&&
398 ctx
->dc
->links
[i
]->link_enc
->transmitter
<= TRANSMITTER_UNIPHY_F
) {
399 tx_interrupt_mask
|= 1 << ctx
->dc
->links
[i
]->link_enc
->transmitter
;
404 switch (dmcu
->dmcu_state
) {
408 case DMCU_LOADED_UNINITIALIZED
:
409 /* Wait until microcontroller is ready to process interrupt */
410 REG_WAIT(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 0, 100, 800);
412 /* Set initialized ramping boundary value */
413 REG_WRITE(MASTER_COMM_DATA_REG1
, 0xFFFF);
415 /* Set backlight ramping stepsize */
416 REG_WRITE(MASTER_COMM_DATA_REG2
, abm_gain_stepsize
);
418 REG_WRITE(MASTER_COMM_DATA_REG3
, tx_interrupt_mask
);
420 /* Set command to initialize microcontroller */
421 REG_UPDATE(MASTER_COMM_CMD_REG
, MASTER_COMM_CMD_REG_BYTE0
,
424 /* Notify microcontroller of new command */
425 REG_UPDATE(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 1);
427 /* Ensure command has been executed before continuing */
428 REG_WAIT(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 0, 100, 800);
430 // Check state is initialized
431 dmcu
->dmcu_state
= REG_READ(DC_DMCU_SCRATCH
);
433 // If microcontroller is not in running state, fail
434 if (dmcu
->dmcu_state
== DMCU_RUNNING
) {
435 /* Retrieve and cache the DMCU firmware version. */
436 dcn10_get_dmcu_version(dmcu
);
438 /* Initialize DMCU to use fractional PWM or not */
439 dcn10_dmcu_enable_fractional_pwm(dmcu
,
440 (config
->disable_fractional_pwm
== false) ? 1 : 0);
459 static bool dcn21_dmcu_init(struct dmcu
*dmcu
)
461 struct dce_dmcu
*dmcu_dce
= TO_DCE_DMCU(dmcu
);
462 uint32_t dmcub_psp_version
= REG_READ(DMCUB_SCRATCH15
);
464 if (dmcu
->auto_load_dmcu
&& dmcub_psp_version
== 0) {
468 return dcn10_dmcu_init(dmcu
);
471 static bool dcn10_dmcu_load_iram(struct dmcu
*dmcu
,
472 unsigned int start_offset
,
476 struct dce_dmcu
*dmcu_dce
= TO_DCE_DMCU(dmcu
);
477 unsigned int count
= 0;
479 /* If microcontroller is not running, do nothing */
480 if (dmcu
->dmcu_state
!= DMCU_RUNNING
)
483 /* Enable write access to IRAM */
484 REG_UPDATE_2(DMCU_RAM_ACCESS_CTRL
,
485 IRAM_HOST_ACCESS_EN
, 1,
486 IRAM_WR_ADDR_AUTO_INC
, 1);
488 REG_WAIT(DMU_MEM_PWR_CNTL
, DMCU_IRAM_MEM_PWR_STATE
, 0, 2, 10);
490 REG_WRITE(DMCU_IRAM_WR_CTRL
, start_offset
);
492 for (count
= 0; count
< bytes
; count
++)
493 REG_WRITE(DMCU_IRAM_WR_DATA
, src
[count
]);
495 /* Disable write access to IRAM to allow dynamic sleep state */
496 REG_UPDATE_2(DMCU_RAM_ACCESS_CTRL
,
497 IRAM_HOST_ACCESS_EN
, 0,
498 IRAM_WR_ADDR_AUTO_INC
, 0);
500 /* Wait until microcontroller is ready to process interrupt */
501 REG_WAIT(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 0, 100, 800);
503 /* Set command to signal IRAM is loaded and to initialize IRAM */
504 REG_UPDATE(MASTER_COMM_CMD_REG
, MASTER_COMM_CMD_REG_BYTE0
,
507 /* Notify microcontroller of new command */
508 REG_UPDATE(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 1);
510 /* Ensure command has been executed before continuing */
511 REG_WAIT(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 0, 100, 800);
516 static void dcn10_get_dmcu_psr_state(struct dmcu
*dmcu
, enum dc_psr_state
*state
)
518 struct dce_dmcu
*dmcu_dce
= TO_DCE_DMCU(dmcu
);
520 uint32_t psr_state_offset
= 0xf0;
522 /* If microcontroller is not running, do nothing */
523 if (dmcu
->dmcu_state
!= DMCU_RUNNING
)
526 /* Enable write access to IRAM */
527 REG_UPDATE(DMCU_RAM_ACCESS_CTRL
, IRAM_HOST_ACCESS_EN
, 1);
529 REG_WAIT(DMU_MEM_PWR_CNTL
, DMCU_IRAM_MEM_PWR_STATE
, 0, 2, 10);
531 /* Write address to IRAM_RD_ADDR in DMCU_IRAM_RD_CTRL */
532 REG_WRITE(DMCU_IRAM_RD_CTRL
, psr_state_offset
);
534 /* Read data from IRAM_RD_DATA in DMCU_IRAM_RD_DATA*/
535 *state
= (enum dc_psr_state
)REG_READ(DMCU_IRAM_RD_DATA
);
537 /* Disable write access to IRAM after finished using IRAM
538 * in order to allow dynamic sleep state
540 REG_UPDATE(DMCU_RAM_ACCESS_CTRL
, IRAM_HOST_ACCESS_EN
, 0);
543 static void dcn10_dmcu_set_psr_enable(struct dmcu
*dmcu
, bool enable
, bool wait
)
545 struct dce_dmcu
*dmcu_dce
= TO_DCE_DMCU(dmcu
);
546 unsigned int dmcu_max_retry_on_wait_reg_ready
= 801;
547 unsigned int dmcu_wait_reg_ready_interval
= 100;
549 unsigned int retryCount
;
550 enum dc_psr_state state
= PSR_STATE0
;
552 /* If microcontroller is not running, do nothing */
553 if (dmcu
->dmcu_state
!= DMCU_RUNNING
)
556 /* waitDMCUReadyForCmd */
557 REG_WAIT(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 0,
558 dmcu_wait_reg_ready_interval
,
559 dmcu_max_retry_on_wait_reg_ready
);
561 /* setDMCUParam_Cmd */
563 REG_UPDATE(MASTER_COMM_CMD_REG
, MASTER_COMM_CMD_REG_BYTE0
,
566 REG_UPDATE(MASTER_COMM_CMD_REG
, MASTER_COMM_CMD_REG_BYTE0
,
570 REG_UPDATE(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 1);
572 /* Below loops 1000 x 500us = 500 ms.
573 * Exit PSR may need to wait 1-2 frames to power up. Timeout after at
574 * least a few frames. Should never hit the max retry assert below.
577 for (retryCount
= 0; retryCount
<= 1000; retryCount
++) {
578 dcn10_get_dmcu_psr_state(dmcu
, &state
);
580 if (state
!= PSR_STATE0
)
583 if (state
== PSR_STATE0
)
589 /* assert if max retry hit */
590 if (retryCount
>= 1000)
595 static bool dcn10_dmcu_setup_psr(struct dmcu
*dmcu
,
596 struct dc_link
*link
,
597 struct psr_context
*psr_context
)
599 struct dce_dmcu
*dmcu_dce
= TO_DCE_DMCU(dmcu
);
601 unsigned int dmcu_max_retry_on_wait_reg_ready
= 801;
602 unsigned int dmcu_wait_reg_ready_interval
= 100;
604 union dce_dmcu_psr_config_data_reg1 masterCmdData1
;
605 union dce_dmcu_psr_config_data_reg2 masterCmdData2
;
606 union dce_dmcu_psr_config_data_reg3 masterCmdData3
;
608 /* If microcontroller is not running, do nothing */
609 if (dmcu
->dmcu_state
!= DMCU_RUNNING
)
612 link
->link_enc
->funcs
->psr_program_dp_dphy_fast_training(link
->link_enc
,
613 psr_context
->psrExitLinkTrainingRequired
);
615 /* Enable static screen interrupts for PSR supported display */
616 /* Disable the interrupt coming from other displays. */
617 REG_UPDATE_4(DMCU_INTERRUPT_TO_UC_EN_MASK
,
618 STATIC_SCREEN1_INT_TO_UC_EN
, 0,
619 STATIC_SCREEN2_INT_TO_UC_EN
, 0,
620 STATIC_SCREEN3_INT_TO_UC_EN
, 0,
621 STATIC_SCREEN4_INT_TO_UC_EN
, 0);
623 switch (psr_context
->controllerId
) {
624 /* Driver uses case 1 for unconfigured */
626 REG_UPDATE(DMCU_INTERRUPT_TO_UC_EN_MASK
,
627 STATIC_SCREEN1_INT_TO_UC_EN
, 1);
630 REG_UPDATE(DMCU_INTERRUPT_TO_UC_EN_MASK
,
631 STATIC_SCREEN2_INT_TO_UC_EN
, 1);
634 REG_UPDATE(DMCU_INTERRUPT_TO_UC_EN_MASK
,
635 STATIC_SCREEN3_INT_TO_UC_EN
, 1);
638 REG_UPDATE(DMCU_INTERRUPT_TO_UC_EN_MASK
,
639 STATIC_SCREEN4_INT_TO_UC_EN
, 1);
642 /* CZ/NL only has 4 CRTC!!
644 * There is no interrupt enable mask for these instances.
648 /* CZ/NL only has 4 CRTC!!
649 * These are here because they are defined in HW regspec,
650 * but not really valid. There is no interrupt enable mask
651 * for these instances.
655 REG_UPDATE(DMCU_INTERRUPT_TO_UC_EN_MASK
,
656 STATIC_SCREEN1_INT_TO_UC_EN
, 1);
660 link
->link_enc
->funcs
->psr_program_secondary_packet(link
->link_enc
,
661 psr_context
->sdpTransmitLineNumDeadline
);
663 if (psr_context
->allow_smu_optimizations
)
664 REG_UPDATE(SMU_INTERRUPT_CONTROL
, DC_SMU_INT_ENABLE
, 1);
666 /* waitDMCUReadyForCmd */
667 REG_WAIT(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 0,
668 dmcu_wait_reg_ready_interval
,
669 dmcu_max_retry_on_wait_reg_ready
);
671 /* setDMCUParam_PSRHostConfigData */
672 masterCmdData1
.u32All
= 0;
673 masterCmdData1
.bits
.timehyst_frames
= psr_context
->timehyst_frames
;
674 masterCmdData1
.bits
.hyst_lines
= psr_context
->hyst_lines
;
675 masterCmdData1
.bits
.rfb_update_auto_en
=
676 psr_context
->rfb_update_auto_en
;
677 masterCmdData1
.bits
.dp_port_num
= psr_context
->transmitterId
;
678 masterCmdData1
.bits
.dcp_sel
= psr_context
->controllerId
;
679 masterCmdData1
.bits
.phy_type
= psr_context
->phyType
;
680 masterCmdData1
.bits
.frame_cap_ind
=
681 psr_context
->psrFrameCaptureIndicationReq
;
682 masterCmdData1
.bits
.aux_chan
= psr_context
->channel
;
683 masterCmdData1
.bits
.aux_repeat
= psr_context
->aux_repeats
;
684 masterCmdData1
.bits
.allow_smu_optimizations
= psr_context
->allow_smu_optimizations
;
685 dm_write_reg(dmcu
->ctx
, REG(MASTER_COMM_DATA_REG1
),
686 masterCmdData1
.u32All
);
688 masterCmdData2
.u32All
= 0;
689 masterCmdData2
.bits
.dig_fe
= psr_context
->engineId
;
690 masterCmdData2
.bits
.dig_be
= psr_context
->transmitterId
;
691 masterCmdData2
.bits
.skip_wait_for_pll_lock
=
692 psr_context
->skipPsrWaitForPllLock
;
693 masterCmdData2
.bits
.frame_delay
= psr_context
->frame_delay
;
694 masterCmdData2
.bits
.smu_phy_id
= psr_context
->smuPhyId
;
695 masterCmdData2
.bits
.num_of_controllers
=
696 psr_context
->numberOfControllers
;
697 dm_write_reg(dmcu
->ctx
, REG(MASTER_COMM_DATA_REG2
),
698 masterCmdData2
.u32All
);
700 masterCmdData3
.u32All
= 0;
701 masterCmdData3
.bits
.psr_level
= psr_context
->psr_level
.u32all
;
702 dm_write_reg(dmcu
->ctx
, REG(MASTER_COMM_DATA_REG3
),
703 masterCmdData3
.u32All
);
706 /* setDMCUParam_Cmd */
707 REG_UPDATE(MASTER_COMM_CMD_REG
,
708 MASTER_COMM_CMD_REG_BYTE0
, PSR_SET
);
711 REG_UPDATE(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 1);
713 /* waitDMCUReadyForCmd */
714 REG_WAIT(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 0, 1, 10000);
719 static void dcn10_psr_wait_loop(
721 unsigned int wait_loop_number
)
723 struct dce_dmcu
*dmcu_dce
= TO_DCE_DMCU(dmcu
);
724 union dce_dmcu_psr_config_data_wait_loop_reg1 masterCmdData1
;
726 /* If microcontroller is not running, do nothing */
727 if (dmcu
->dmcu_state
!= DMCU_RUNNING
)
730 if (wait_loop_number
!= 0) {
731 /* waitDMCUReadyForCmd */
732 REG_WAIT(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 0, 1, 10000);
734 masterCmdData1
.u32
= 0;
735 masterCmdData1
.bits
.wait_loop
= wait_loop_number
;
736 dmcu
->cached_wait_loop_number
= wait_loop_number
;
737 dm_write_reg(dmcu
->ctx
, REG(MASTER_COMM_DATA_REG1
), masterCmdData1
.u32
);
739 /* setDMCUParam_Cmd */
740 REG_UPDATE(MASTER_COMM_CMD_REG
, MASTER_COMM_CMD_REG_BYTE0
, PSR_SET_WAITLOOP
);
743 REG_UPDATE(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 1);
747 static void dcn10_get_psr_wait_loop(
748 struct dmcu
*dmcu
, unsigned int *psr_wait_loop_number
)
750 *psr_wait_loop_number
= dmcu
->cached_wait_loop_number
;
754 static bool dcn10_is_dmcu_initialized(struct dmcu
*dmcu
)
756 /* microcontroller is not running */
757 if (dmcu
->dmcu_state
!= DMCU_RUNNING
)
764 static bool dcn20_lock_phy(struct dmcu
*dmcu
)
766 struct dce_dmcu
*dmcu_dce
= TO_DCE_DMCU(dmcu
);
768 /* If microcontroller is not running, do nothing */
769 if (dmcu
->dmcu_state
!= DMCU_RUNNING
)
772 /* waitDMCUReadyForCmd */
773 REG_WAIT(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 0, 1, 10000);
775 /* setDMCUParam_Cmd */
776 REG_UPDATE(MASTER_COMM_CMD_REG
, MASTER_COMM_CMD_REG_BYTE0
, MCP_SYNC_PHY_LOCK
);
779 REG_UPDATE(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 1);
781 /* waitDMCUReadyForCmd */
782 REG_WAIT(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 0, 1, 10000);
787 static bool dcn20_unlock_phy(struct dmcu
*dmcu
)
789 struct dce_dmcu
*dmcu_dce
= TO_DCE_DMCU(dmcu
);
791 /* If microcontroller is not running, do nothing */
792 if (dmcu
->dmcu_state
!= DMCU_RUNNING
)
795 /* waitDMCUReadyForCmd */
796 REG_WAIT(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 0, 1, 10000);
798 /* setDMCUParam_Cmd */
799 REG_UPDATE(MASTER_COMM_CMD_REG
, MASTER_COMM_CMD_REG_BYTE0
, MCP_SYNC_PHY_UNLOCK
);
802 REG_UPDATE(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 1);
804 /* waitDMCUReadyForCmd */
805 REG_WAIT(MASTER_COMM_CNTL_REG
, MASTER_COMM_INTERRUPT
, 0, 1, 10000);
810 #endif //(CONFIG_DRM_AMD_DC_DCN)
812 static const struct dmcu_funcs dce_funcs
= {
813 .dmcu_init
= dce_dmcu_init
,
814 .load_iram
= dce_dmcu_load_iram
,
815 .set_psr_enable
= dce_dmcu_set_psr_enable
,
816 .setup_psr
= dce_dmcu_setup_psr
,
817 .get_psr_state
= dce_get_dmcu_psr_state
,
818 .set_psr_wait_loop
= dce_psr_wait_loop
,
819 .get_psr_wait_loop
= dce_get_psr_wait_loop
,
820 .is_dmcu_initialized
= dce_is_dmcu_initialized
823 #if defined(CONFIG_DRM_AMD_DC_DCN)
824 static const struct dmcu_funcs dcn10_funcs
= {
825 .dmcu_init
= dcn10_dmcu_init
,
826 .load_iram
= dcn10_dmcu_load_iram
,
827 .set_psr_enable
= dcn10_dmcu_set_psr_enable
,
828 .setup_psr
= dcn10_dmcu_setup_psr
,
829 .get_psr_state
= dcn10_get_dmcu_psr_state
,
830 .set_psr_wait_loop
= dcn10_psr_wait_loop
,
831 .get_psr_wait_loop
= dcn10_get_psr_wait_loop
,
832 .is_dmcu_initialized
= dcn10_is_dmcu_initialized
835 static const struct dmcu_funcs dcn20_funcs
= {
836 .dmcu_init
= dcn10_dmcu_init
,
837 .load_iram
= dcn10_dmcu_load_iram
,
838 .set_psr_enable
= dcn10_dmcu_set_psr_enable
,
839 .setup_psr
= dcn10_dmcu_setup_psr
,
840 .get_psr_state
= dcn10_get_dmcu_psr_state
,
841 .set_psr_wait_loop
= dcn10_psr_wait_loop
,
842 .get_psr_wait_loop
= dcn10_get_psr_wait_loop
,
843 .is_dmcu_initialized
= dcn10_is_dmcu_initialized
,
844 .lock_phy
= dcn20_lock_phy
,
845 .unlock_phy
= dcn20_unlock_phy
848 static const struct dmcu_funcs dcn21_funcs
= {
849 .dmcu_init
= dcn21_dmcu_init
,
850 .load_iram
= dcn10_dmcu_load_iram
,
851 .set_psr_enable
= dcn10_dmcu_set_psr_enable
,
852 .setup_psr
= dcn10_dmcu_setup_psr
,
853 .get_psr_state
= dcn10_get_dmcu_psr_state
,
854 .set_psr_wait_loop
= dcn10_psr_wait_loop
,
855 .get_psr_wait_loop
= dcn10_get_psr_wait_loop
,
856 .is_dmcu_initialized
= dcn10_is_dmcu_initialized
,
857 .lock_phy
= dcn20_lock_phy
,
858 .unlock_phy
= dcn20_unlock_phy
862 static void dce_dmcu_construct(
863 struct dce_dmcu
*dmcu_dce
,
864 struct dc_context
*ctx
,
865 const struct dce_dmcu_registers
*regs
,
866 const struct dce_dmcu_shift
*dmcu_shift
,
867 const struct dce_dmcu_mask
*dmcu_mask
)
869 struct dmcu
*base
= &dmcu_dce
->base
;
872 base
->funcs
= &dce_funcs
;
873 base
->cached_wait_loop_number
= 0;
875 dmcu_dce
->regs
= regs
;
876 dmcu_dce
->dmcu_shift
= dmcu_shift
;
877 dmcu_dce
->dmcu_mask
= dmcu_mask
;
880 #if defined(CONFIG_DRM_AMD_DC_DCN)
881 static void dcn21_dmcu_construct(
882 struct dce_dmcu
*dmcu_dce
,
883 struct dc_context
*ctx
,
884 const struct dce_dmcu_registers
*regs
,
885 const struct dce_dmcu_shift
*dmcu_shift
,
886 const struct dce_dmcu_mask
*dmcu_mask
)
888 uint32_t psp_version
= 0;
890 dce_dmcu_construct(dmcu_dce
, ctx
, regs
, dmcu_shift
, dmcu_mask
);
892 if (!IS_FPGA_MAXIMUS_DC(ctx
->dce_environment
)) {
893 psp_version
= dm_read_reg(ctx
, mmMP0_SMN_C2PMSG_58
);
894 dmcu_dce
->base
.auto_load_dmcu
= ((psp_version
& 0x00FF00FF) > 0x00110029);
895 dmcu_dce
->base
.psp_version
= psp_version
;
900 struct dmcu
*dce_dmcu_create(
901 struct dc_context
*ctx
,
902 const struct dce_dmcu_registers
*regs
,
903 const struct dce_dmcu_shift
*dmcu_shift
,
904 const struct dce_dmcu_mask
*dmcu_mask
)
906 struct dce_dmcu
*dmcu_dce
= kzalloc(sizeof(*dmcu_dce
), GFP_KERNEL
);
908 if (dmcu_dce
== NULL
) {
914 dmcu_dce
, ctx
, regs
, dmcu_shift
, dmcu_mask
);
916 dmcu_dce
->base
.funcs
= &dce_funcs
;
918 return &dmcu_dce
->base
;
921 #if defined(CONFIG_DRM_AMD_DC_DCN)
922 struct dmcu
*dcn10_dmcu_create(
923 struct dc_context
*ctx
,
924 const struct dce_dmcu_registers
*regs
,
925 const struct dce_dmcu_shift
*dmcu_shift
,
926 const struct dce_dmcu_mask
*dmcu_mask
)
928 struct dce_dmcu
*dmcu_dce
= kzalloc(sizeof(*dmcu_dce
), GFP_KERNEL
);
930 if (dmcu_dce
== NULL
) {
936 dmcu_dce
, ctx
, regs
, dmcu_shift
, dmcu_mask
);
938 dmcu_dce
->base
.funcs
= &dcn10_funcs
;
940 return &dmcu_dce
->base
;
943 struct dmcu
*dcn20_dmcu_create(
944 struct dc_context
*ctx
,
945 const struct dce_dmcu_registers
*regs
,
946 const struct dce_dmcu_shift
*dmcu_shift
,
947 const struct dce_dmcu_mask
*dmcu_mask
)
949 struct dce_dmcu
*dmcu_dce
= kzalloc(sizeof(*dmcu_dce
), GFP_KERNEL
);
951 if (dmcu_dce
== NULL
) {
957 dmcu_dce
, ctx
, regs
, dmcu_shift
, dmcu_mask
);
959 dmcu_dce
->base
.funcs
= &dcn20_funcs
;
961 return &dmcu_dce
->base
;
964 struct dmcu
*dcn21_dmcu_create(
965 struct dc_context
*ctx
,
966 const struct dce_dmcu_registers
*regs
,
967 const struct dce_dmcu_shift
*dmcu_shift
,
968 const struct dce_dmcu_mask
*dmcu_mask
)
970 struct dce_dmcu
*dmcu_dce
= kzalloc(sizeof(*dmcu_dce
), GFP_KERNEL
);
972 if (dmcu_dce
== NULL
) {
977 dcn21_dmcu_construct(
978 dmcu_dce
, ctx
, regs
, dmcu_shift
, dmcu_mask
);
980 dmcu_dce
->base
.funcs
= &dcn21_funcs
;
982 return &dmcu_dce
->base
;
986 void dce_dmcu_destroy(struct dmcu
**dmcu
)
988 struct dce_dmcu
*dmcu_dce
= TO_DCE_DMCU(*dmcu
);