2 * Copyright 2012-15 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 "dce/dce_8_0_d.h"
27 #include "dce/dce_8_0_sh_mask.h"
29 #include "dm_services.h"
31 #include "link_encoder.h"
32 #include "stream_encoder.h"
35 #include "include/irq_service_interface.h"
36 #include "irq/dce80/irq_service_dce80.h"
37 #include "dce110/dce110_timing_generator.h"
38 #include "dce110/dce110_resource.h"
39 #include "dce80/dce80_timing_generator.h"
40 #include "dce/dce_mem_input.h"
41 #include "dce/dce_link_encoder.h"
42 #include "dce/dce_stream_encoder.h"
43 #include "dce/dce_ipp.h"
44 #include "dce/dce_transform.h"
45 #include "dce/dce_opp.h"
46 #include "dce/dce_clock_source.h"
47 #include "dce/dce_audio.h"
48 #include "dce/dce_hwseq.h"
49 #include "dce80/dce80_hwseq.h"
50 #include "dce100/dce100_resource.h"
51 #include "dce/dce_panel_cntl.h"
53 #include "reg_helper.h"
55 #include "dce/dce_dmcu.h"
56 #include "dce/dce_aux.h"
57 #include "dce/dce_abm.h"
58 #include "dce/dce_i2c.h"
59 /* TODO remove this include */
61 #ifndef mmMC_HUB_RDREQ_DMIF_LIMIT
62 #include "gmc/gmc_7_1_d.h"
63 #include "gmc/gmc_7_1_sh_mask.h"
66 #include "dce80/dce80_resource.h"
68 #ifndef mmDP_DPHY_INTERNAL_CTRL
69 #define mmDP_DPHY_INTERNAL_CTRL 0x1CDE
70 #define mmDP0_DP_DPHY_INTERNAL_CTRL 0x1CDE
71 #define mmDP1_DP_DPHY_INTERNAL_CTRL 0x1FDE
72 #define mmDP2_DP_DPHY_INTERNAL_CTRL 0x42DE
73 #define mmDP3_DP_DPHY_INTERNAL_CTRL 0x45DE
74 #define mmDP4_DP_DPHY_INTERNAL_CTRL 0x48DE
75 #define mmDP5_DP_DPHY_INTERNAL_CTRL 0x4BDE
76 #define mmDP6_DP_DPHY_INTERNAL_CTRL 0x4EDE
80 #ifndef mmBIOS_SCRATCH_2
81 #define mmBIOS_SCRATCH_2 0x05CB
82 #define mmBIOS_SCRATCH_3 0x05CC
83 #define mmBIOS_SCRATCH_6 0x05CF
86 #ifndef mmDP_DPHY_FAST_TRAINING
87 #define mmDP_DPHY_FAST_TRAINING 0x1CCE
88 #define mmDP0_DP_DPHY_FAST_TRAINING 0x1CCE
89 #define mmDP1_DP_DPHY_FAST_TRAINING 0x1FCE
90 #define mmDP2_DP_DPHY_FAST_TRAINING 0x42CE
91 #define mmDP3_DP_DPHY_FAST_TRAINING 0x45CE
92 #define mmDP4_DP_DPHY_FAST_TRAINING 0x48CE
93 #define mmDP5_DP_DPHY_FAST_TRAINING 0x4BCE
94 #define mmDP6_DP_DPHY_FAST_TRAINING 0x4ECE
98 #ifndef mmHPD_DC_HPD_CONTROL
99 #define mmHPD_DC_HPD_CONTROL 0x189A
100 #define mmHPD0_DC_HPD_CONTROL 0x189A
101 #define mmHPD1_DC_HPD_CONTROL 0x18A2
102 #define mmHPD2_DC_HPD_CONTROL 0x18AA
103 #define mmHPD3_DC_HPD_CONTROL 0x18B2
104 #define mmHPD4_DC_HPD_CONTROL 0x18BA
105 #define mmHPD5_DC_HPD_CONTROL 0x18C2
108 #define DCE11_DIG_FE_CNTL 0x4a00
109 #define DCE11_DIG_BE_CNTL 0x4a47
110 #define DCE11_DP_SEC 0x4ac3
112 static const struct dce110_timing_generator_offsets dce80_tg_offsets[] = {
114 .crtc = (mmCRTC0_CRTC_CONTROL - mmCRTC_CONTROL),
115 .dcp = (mmGRPH_CONTROL - mmGRPH_CONTROL),
116 .dmif = (mmDMIF_PG0_DPG_WATERMARK_MASK_CONTROL
117 - mmDPG_WATERMARK_MASK_CONTROL),
120 .crtc = (mmCRTC1_CRTC_CONTROL - mmCRTC_CONTROL),
121 .dcp = (mmDCP1_GRPH_CONTROL - mmGRPH_CONTROL),
122 .dmif = (mmDMIF_PG1_DPG_WATERMARK_MASK_CONTROL
123 - mmDPG_WATERMARK_MASK_CONTROL),
126 .crtc = (mmCRTC2_CRTC_CONTROL - mmCRTC_CONTROL),
127 .dcp = (mmDCP2_GRPH_CONTROL - mmGRPH_CONTROL),
128 .dmif = (mmDMIF_PG2_DPG_WATERMARK_MASK_CONTROL
129 - mmDPG_WATERMARK_MASK_CONTROL),
132 .crtc = (mmCRTC3_CRTC_CONTROL - mmCRTC_CONTROL),
133 .dcp = (mmDCP3_GRPH_CONTROL - mmGRPH_CONTROL),
134 .dmif = (mmDMIF_PG3_DPG_WATERMARK_MASK_CONTROL
135 - mmDPG_WATERMARK_MASK_CONTROL),
138 .crtc = (mmCRTC4_CRTC_CONTROL - mmCRTC_CONTROL),
139 .dcp = (mmDCP4_GRPH_CONTROL - mmGRPH_CONTROL),
140 .dmif = (mmDMIF_PG4_DPG_WATERMARK_MASK_CONTROL
141 - mmDPG_WATERMARK_MASK_CONTROL),
144 .crtc = (mmCRTC5_CRTC_CONTROL - mmCRTC_CONTROL),
145 .dcp = (mmDCP5_GRPH_CONTROL - mmGRPH_CONTROL),
146 .dmif = (mmDMIF_PG5_DPG_WATERMARK_MASK_CONTROL
147 - mmDPG_WATERMARK_MASK_CONTROL),
151 /* set register offset */
152 #define SR(reg_name)\
153 .reg_name = mm ## reg_name
155 /* set register offset with instance */
156 #define SRI(reg_name, block, id)\
157 .reg_name = mm ## block ## id ## _ ## reg_name
159 #define ipp_regs(id)\
161 IPP_COMMON_REG_LIST_DCE_BASE(id)\
164 static const struct dce_ipp_registers ipp_regs[] = {
173 static const struct dce_ipp_shift ipp_shift = {
174 IPP_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
177 static const struct dce_ipp_mask ipp_mask = {
178 IPP_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
181 #define transform_regs(id)\
183 XFM_COMMON_REG_LIST_DCE80(id)\
186 static const struct dce_transform_registers xfm_regs[] = {
195 static const struct dce_transform_shift xfm_shift = {
196 XFM_COMMON_MASK_SH_LIST_DCE80(__SHIFT)
199 static const struct dce_transform_mask xfm_mask = {
200 XFM_COMMON_MASK_SH_LIST_DCE80(_MASK)
203 #define aux_regs(id)\
208 static const struct dce110_link_enc_aux_registers link_enc_aux_regs[] = {
217 #define hpd_regs(id)\
222 static const struct dce110_link_enc_hpd_registers link_enc_hpd_regs[] = {
231 #define link_regs(id)\
233 LE_DCE80_REG_LIST(id)\
236 static const struct dce110_link_enc_registers link_enc_regs[] = {
246 #define stream_enc_regs(id)\
248 SE_COMMON_REG_LIST_DCE_BASE(id),\
252 static const struct dce110_stream_enc_registers stream_enc_regs[] = {
262 static const struct dce_stream_encoder_shift se_shift = {
263 SE_COMMON_MASK_SH_LIST_DCE80_100(__SHIFT)
266 static const struct dce_stream_encoder_mask se_mask = {
267 SE_COMMON_MASK_SH_LIST_DCE80_100(_MASK)
270 static const struct dce_panel_cntl_registers panel_cntl_regs[] = {
271 { DCE_PANEL_CNTL_REG_LIST() }
274 static const struct dce_panel_cntl_shift panel_cntl_shift = {
275 DCE_PANEL_CNTL_MASK_SH_LIST(__SHIFT)
278 static const struct dce_panel_cntl_mask panel_cntl_mask = {
279 DCE_PANEL_CNTL_MASK_SH_LIST(_MASK)
282 #define opp_regs(id)\
284 OPP_DCE_80_REG_LIST(id),\
287 static const struct dce_opp_registers opp_regs[] = {
296 static const struct dce_opp_shift opp_shift = {
297 OPP_COMMON_MASK_SH_LIST_DCE_80(__SHIFT)
300 static const struct dce_opp_mask opp_mask = {
301 OPP_COMMON_MASK_SH_LIST_DCE_80(_MASK)
304 static const struct dce110_aux_registers_shift aux_shift = {
305 DCE10_AUX_MASK_SH_LIST(__SHIFT)
308 static const struct dce110_aux_registers_mask aux_mask = {
309 DCE10_AUX_MASK_SH_LIST(_MASK)
312 #define aux_engine_regs(id)\
314 AUX_COMMON_REG_LIST(id), \
315 .AUX_RESET_MASK = 0 \
318 static const struct dce110_aux_registers aux_engine_regs[] = {
327 #define audio_regs(id)\
329 AUD_COMMON_REG_LIST(id)\
332 static const struct dce_audio_registers audio_regs[] = {
342 static const struct dce_audio_shift audio_shift = {
343 AUD_COMMON_MASK_SH_LIST(__SHIFT)
346 static const struct dce_audio_mask audio_mask = {
347 AUD_COMMON_MASK_SH_LIST(_MASK)
350 #define clk_src_regs(id)\
352 CS_COMMON_REG_LIST_DCE_80(id),\
356 static const struct dce110_clk_src_regs clk_src_regs[] = {
362 static const struct dce110_clk_src_shift cs_shift = {
363 CS_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
366 static const struct dce110_clk_src_mask cs_mask = {
367 CS_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
370 static const struct bios_registers bios_regs = {
371 .BIOS_SCRATCH_3 = mmBIOS_SCRATCH_3,
372 .BIOS_SCRATCH_6 = mmBIOS_SCRATCH_6
375 static const struct resource_caps res_cap = {
376 .num_timing_generator = 6,
378 .num_stream_encoder = 6,
383 static const struct resource_caps res_cap_81 = {
384 .num_timing_generator = 4,
386 .num_stream_encoder = 7,
391 static const struct resource_caps res_cap_83 = {
392 .num_timing_generator = 2,
394 .num_stream_encoder = 6,
399 static const struct dc_plane_cap plane_cap = {
400 .type = DC_PLANE_TYPE_DCE_RGB,
402 .pixel_format_support = {
408 .max_upscale_factor = {
414 .max_downscale_factor = {
421 static const struct dc_debug_options debug_defaults = {
422 .enable_legacy_fast_update = true,
425 static const struct dce_dmcu_registers dmcu_regs = {
426 DMCU_DCE80_REG_LIST()
429 static const struct dce_dmcu_shift dmcu_shift = {
430 DMCU_MASK_SH_LIST_DCE80(__SHIFT)
433 static const struct dce_dmcu_mask dmcu_mask = {
434 DMCU_MASK_SH_LIST_DCE80(_MASK)
436 static const struct dce_abm_registers abm_regs = {
437 ABM_DCE110_COMMON_REG_LIST()
440 static const struct dce_abm_shift abm_shift = {
441 ABM_MASK_SH_LIST_DCE110(__SHIFT)
444 static const struct dce_abm_mask abm_mask = {
445 ABM_MASK_SH_LIST_DCE110(_MASK)
449 #define REG(reg) mm ## reg
451 #ifndef mmCC_DC_HDMI_STRAPS
452 #define mmCC_DC_HDMI_STRAPS 0x1918
453 #define CC_DC_HDMI_STRAPS__HDMI_DISABLE_MASK 0x40
454 #define CC_DC_HDMI_STRAPS__HDMI_DISABLE__SHIFT 0x6
455 #define CC_DC_HDMI_STRAPS__AUDIO_STREAM_NUMBER_MASK 0x700
456 #define CC_DC_HDMI_STRAPS__AUDIO_STREAM_NUMBER__SHIFT 0x8
459 static int map_transmitter_id_to_phy_instance(
460 enum transmitter transmitter)
462 switch (transmitter) {
463 case TRANSMITTER_UNIPHY_A:
465 case TRANSMITTER_UNIPHY_B:
467 case TRANSMITTER_UNIPHY_C:
469 case TRANSMITTER_UNIPHY_D:
471 case TRANSMITTER_UNIPHY_E:
473 case TRANSMITTER_UNIPHY_F:
475 case TRANSMITTER_UNIPHY_G:
483 static void read_dce_straps(
484 struct dc_context *ctx,
485 struct resource_straps *straps)
487 REG_GET_2(CC_DC_HDMI_STRAPS,
488 HDMI_DISABLE, &straps->hdmi_disable,
489 AUDIO_STREAM_NUMBER, &straps->audio_stream_number);
491 REG_GET(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO, &straps->dc_pinstraps_audio);
494 static struct audio *create_audio(
495 struct dc_context *ctx, unsigned int inst)
497 return dce_audio_create(ctx, inst,
498 &audio_regs[inst], &audio_shift, &audio_mask);
501 static struct timing_generator *dce80_timing_generator_create(
502 struct dc_context *ctx,
504 const struct dce110_timing_generator_offsets *offsets)
506 struct dce110_timing_generator *tg110 =
507 kzalloc(sizeof(struct dce110_timing_generator), GFP_KERNEL);
512 dce80_timing_generator_construct(tg110, ctx, instance, offsets);
516 static struct output_pixel_processor *dce80_opp_create(
517 struct dc_context *ctx,
520 struct dce110_opp *opp =
521 kzalloc(sizeof(struct dce110_opp), GFP_KERNEL);
526 dce110_opp_construct(opp,
527 ctx, inst, &opp_regs[inst], &opp_shift, &opp_mask);
531 static struct dce_aux *dce80_aux_engine_create(
532 struct dc_context *ctx,
535 struct aux_engine_dce110 *aux_engine =
536 kzalloc(sizeof(struct aux_engine_dce110), GFP_KERNEL);
541 dce110_aux_engine_construct(aux_engine, ctx, inst,
542 SW_AUX_TIMEOUT_PERIOD_MULTIPLIER * AUX_TIMEOUT_PERIOD,
543 &aux_engine_regs[inst],
546 ctx->dc->caps.extended_aux_timeout_support);
548 return &aux_engine->base;
550 #define i2c_inst_regs(id) { I2C_HW_ENGINE_COMMON_REG_LIST(id) }
552 static const struct dce_i2c_registers i2c_hw_regs[] = {
561 static const struct dce_i2c_shift i2c_shifts = {
562 I2C_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
565 static const struct dce_i2c_mask i2c_masks = {
566 I2C_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
569 static struct dce_i2c_hw *dce80_i2c_hw_create(
570 struct dc_context *ctx,
573 struct dce_i2c_hw *dce_i2c_hw =
574 kzalloc(sizeof(struct dce_i2c_hw), GFP_KERNEL);
579 dce_i2c_hw_construct(dce_i2c_hw, ctx, inst,
580 &i2c_hw_regs[inst], &i2c_shifts, &i2c_masks);
585 static struct dce_i2c_sw *dce80_i2c_sw_create(
586 struct dc_context *ctx)
588 struct dce_i2c_sw *dce_i2c_sw =
589 kzalloc(sizeof(struct dce_i2c_sw), GFP_KERNEL);
594 dce_i2c_sw_construct(dce_i2c_sw, ctx);
598 static struct stream_encoder *dce80_stream_encoder_create(
599 enum engine_id eng_id,
600 struct dc_context *ctx)
602 struct dce110_stream_encoder *enc110 =
603 kzalloc(sizeof(struct dce110_stream_encoder), GFP_KERNEL);
608 dce110_stream_encoder_construct(enc110, ctx, ctx->dc_bios, eng_id,
609 &stream_enc_regs[eng_id],
610 &se_shift, &se_mask);
611 return &enc110->base;
614 #define SRII(reg_name, block, id)\
615 .reg_name[id] = mm ## block ## id ## _ ## reg_name
617 static const struct dce_hwseq_registers hwseq_reg = {
618 HWSEQ_DCE8_REG_LIST()
621 static const struct dce_hwseq_shift hwseq_shift = {
622 HWSEQ_DCE8_MASK_SH_LIST(__SHIFT)
625 static const struct dce_hwseq_mask hwseq_mask = {
626 HWSEQ_DCE8_MASK_SH_LIST(_MASK)
629 static struct dce_hwseq *dce80_hwseq_create(
630 struct dc_context *ctx)
632 struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
636 hws->regs = &hwseq_reg;
637 hws->shifts = &hwseq_shift;
638 hws->masks = &hwseq_mask;
643 static const struct resource_create_funcs res_create_funcs = {
644 .read_dce_straps = read_dce_straps,
645 .create_audio = create_audio,
646 .create_stream_encoder = dce80_stream_encoder_create,
647 .create_hwseq = dce80_hwseq_create,
650 #define mi_inst_regs(id) { \
651 MI_DCE8_REG_LIST(id), \
652 .MC_HUB_RDREQ_DMIF_LIMIT = mmMC_HUB_RDREQ_DMIF_LIMIT \
654 static const struct dce_mem_input_registers mi_regs[] = {
663 static const struct dce_mem_input_shift mi_shifts = {
664 MI_DCE8_MASK_SH_LIST(__SHIFT),
665 .ENABLE = MC_HUB_RDREQ_DMIF_LIMIT__ENABLE__SHIFT
668 static const struct dce_mem_input_mask mi_masks = {
669 MI_DCE8_MASK_SH_LIST(_MASK),
670 .ENABLE = MC_HUB_RDREQ_DMIF_LIMIT__ENABLE_MASK
673 static struct mem_input *dce80_mem_input_create(
674 struct dc_context *ctx,
677 struct dce_mem_input *dce_mi = kzalloc(sizeof(struct dce_mem_input),
685 dce_mem_input_construct(dce_mi, ctx, inst, &mi_regs[inst], &mi_shifts, &mi_masks);
686 dce_mi->wa.single_head_rdreq_dmif_limit = 2;
687 return &dce_mi->base;
690 static void dce80_transform_destroy(struct transform **xfm)
692 kfree(TO_DCE_TRANSFORM(*xfm));
696 static struct transform *dce80_transform_create(
697 struct dc_context *ctx,
700 struct dce_transform *transform =
701 kzalloc(sizeof(struct dce_transform), GFP_KERNEL);
706 dce_transform_construct(transform, ctx, inst,
707 &xfm_regs[inst], &xfm_shift, &xfm_mask);
708 transform->prescaler_on = false;
709 return &transform->base;
712 static const struct encoder_feature_support link_enc_feature = {
713 .max_hdmi_deep_color = COLOR_DEPTH_121212,
714 .max_hdmi_pixel_clock = 297000,
715 .flags.bits.IS_HBR2_CAPABLE = true,
716 .flags.bits.IS_TPS3_CAPABLE = true
719 static struct link_encoder *dce80_link_encoder_create(
720 struct dc_context *ctx,
721 const struct encoder_init_data *enc_init_data)
723 struct dce110_link_encoder *enc110 =
724 kzalloc(sizeof(struct dce110_link_encoder), GFP_KERNEL);
731 map_transmitter_id_to_phy_instance(enc_init_data->transmitter);
733 dce110_link_encoder_construct(enc110,
736 &link_enc_regs[link_regs_id],
737 &link_enc_aux_regs[enc_init_data->channel - 1],
738 &link_enc_hpd_regs[enc_init_data->hpd_source]);
739 return &enc110->base;
742 static struct panel_cntl *dce80_panel_cntl_create(const struct panel_cntl_init_data *init_data)
744 struct dce_panel_cntl *panel_cntl =
745 kzalloc(sizeof(struct dce_panel_cntl), GFP_KERNEL);
750 dce_panel_cntl_construct(panel_cntl,
752 &panel_cntl_regs[init_data->inst],
756 return &panel_cntl->base;
759 static struct clock_source *dce80_clock_source_create(
760 struct dc_context *ctx,
761 struct dc_bios *bios,
762 enum clock_source_id id,
763 const struct dce110_clk_src_regs *regs,
766 struct dce110_clk_src *clk_src =
767 kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL);
772 if (dce110_clk_src_construct(clk_src, ctx, bios, id,
773 regs, &cs_shift, &cs_mask)) {
774 clk_src->base.dp_clk_src = dp_clk_src;
775 return &clk_src->base;
783 static void dce80_clock_source_destroy(struct clock_source **clk_src)
785 kfree(TO_DCE110_CLK_SRC(*clk_src));
789 static struct input_pixel_processor *dce80_ipp_create(
790 struct dc_context *ctx, uint32_t inst)
792 struct dce_ipp *ipp = kzalloc(sizeof(struct dce_ipp), GFP_KERNEL);
799 dce_ipp_construct(ipp, ctx, inst,
800 &ipp_regs[inst], &ipp_shift, &ipp_mask);
804 static void dce80_resource_destruct(struct dce110_resource_pool *pool)
808 for (i = 0; i < pool->base.pipe_count; i++) {
809 if (pool->base.opps[i] != NULL)
810 dce110_opp_destroy(&pool->base.opps[i]);
812 if (pool->base.transforms[i] != NULL)
813 dce80_transform_destroy(&pool->base.transforms[i]);
815 if (pool->base.ipps[i] != NULL)
816 dce_ipp_destroy(&pool->base.ipps[i]);
818 if (pool->base.mis[i] != NULL) {
819 kfree(TO_DCE_MEM_INPUT(pool->base.mis[i]));
820 pool->base.mis[i] = NULL;
823 if (pool->base.timing_generators[i] != NULL) {
824 kfree(DCE110TG_FROM_TG(pool->base.timing_generators[i]));
825 pool->base.timing_generators[i] = NULL;
829 for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
830 if (pool->base.engines[i] != NULL)
831 dce110_engine_destroy(&pool->base.engines[i]);
832 if (pool->base.hw_i2cs[i] != NULL) {
833 kfree(pool->base.hw_i2cs[i]);
834 pool->base.hw_i2cs[i] = NULL;
836 if (pool->base.sw_i2cs[i] != NULL) {
837 kfree(pool->base.sw_i2cs[i]);
838 pool->base.sw_i2cs[i] = NULL;
842 for (i = 0; i < pool->base.stream_enc_count; i++) {
843 if (pool->base.stream_enc[i] != NULL)
844 kfree(DCE110STRENC_FROM_STRENC(pool->base.stream_enc[i]));
847 for (i = 0; i < pool->base.clk_src_count; i++) {
848 if (pool->base.clock_sources[i] != NULL) {
849 dce80_clock_source_destroy(&pool->base.clock_sources[i]);
853 if (pool->base.abm != NULL)
854 dce_abm_destroy(&pool->base.abm);
856 if (pool->base.dmcu != NULL)
857 dce_dmcu_destroy(&pool->base.dmcu);
859 if (pool->base.dp_clock_source != NULL)
860 dce80_clock_source_destroy(&pool->base.dp_clock_source);
862 for (i = 0; i < pool->base.audio_count; i++) {
863 if (pool->base.audios[i] != NULL) {
864 dce_aud_destroy(&pool->base.audios[i]);
868 if (pool->base.irqs != NULL) {
869 dal_irq_service_destroy(&pool->base.irqs);
873 static bool dce80_validate_bandwidth(
875 struct dc_state *context,
879 bool at_least_one_pipe = false;
881 for (i = 0; i < dc->res_pool->pipe_count; i++) {
882 if (context->res_ctx.pipe_ctx[i].stream)
883 at_least_one_pipe = true;
886 if (at_least_one_pipe) {
887 /* TODO implement when needed but for now hardcode max value*/
888 context->bw_ctx.bw.dce.dispclk_khz = 681000;
889 context->bw_ctx.bw.dce.yclk_khz = 250000 * MEMORY_TYPE_MULTIPLIER_CZ;
891 context->bw_ctx.bw.dce.dispclk_khz = 0;
892 context->bw_ctx.bw.dce.yclk_khz = 0;
898 static bool dce80_validate_surface_sets(
899 struct dc_state *context)
903 for (i = 0; i < context->stream_count; i++) {
904 if (context->stream_status[i].plane_count == 0)
907 if (context->stream_status[i].plane_count > 1)
910 if (context->stream_status[i].plane_states[0]->format
911 >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN)
918 static enum dc_status dce80_validate_global(
920 struct dc_state *context)
922 if (!dce80_validate_surface_sets(context))
923 return DC_FAIL_SURFACE_VALIDATE;
928 static void dce80_destroy_resource_pool(struct resource_pool **pool)
930 struct dce110_resource_pool *dce110_pool = TO_DCE110_RES_POOL(*pool);
932 dce80_resource_destruct(dce110_pool);
937 static const struct resource_funcs dce80_res_pool_funcs = {
938 .destroy = dce80_destroy_resource_pool,
939 .link_enc_create = dce80_link_encoder_create,
940 .panel_cntl_create = dce80_panel_cntl_create,
941 .validate_bandwidth = dce80_validate_bandwidth,
942 .validate_plane = dce100_validate_plane,
943 .add_stream_to_ctx = dce100_add_stream_to_ctx,
944 .validate_global = dce80_validate_global,
945 .find_first_free_match_stream_enc_for_link = dce100_find_first_free_match_stream_enc_for_link
948 static bool dce80_construct(
949 uint8_t num_virtual_links,
951 struct dce110_resource_pool *pool)
954 struct dc_context *ctx = dc->ctx;
957 ctx->dc_bios->regs = &bios_regs;
959 pool->base.res_cap = &res_cap;
960 pool->base.funcs = &dce80_res_pool_funcs;
963 /*************************************************
964 * Resource + asic cap harcoding *
965 *************************************************/
966 pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
967 pool->base.pipe_count = res_cap.num_timing_generator;
968 pool->base.timing_generator_count = res_cap.num_timing_generator;
969 dc->caps.max_downscale_ratio = 200;
970 dc->caps.i2c_speed_in_khz = 40;
971 dc->caps.i2c_speed_in_khz_hdcp = 40;
972 dc->caps.max_cursor_size = 128;
973 dc->caps.min_horizontal_blanking_period = 80;
974 dc->caps.dual_link_dvi = true;
975 dc->caps.extended_aux_timeout_support = false;
976 dc->debug = debug_defaults;
978 /*************************************************
980 *************************************************/
984 if (bp->fw_info_valid && bp->fw_info.external_clock_source_frequency_for_dp != 0) {
985 pool->base.dp_clock_source =
986 dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_EXTERNAL, NULL, true);
988 pool->base.clock_sources[0] =
989 dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL0, &clk_src_regs[0], false);
990 pool->base.clock_sources[1] =
991 dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL1, &clk_src_regs[1], false);
992 pool->base.clock_sources[2] =
993 dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL2, &clk_src_regs[2], false);
994 pool->base.clk_src_count = 3;
997 pool->base.dp_clock_source =
998 dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL0, &clk_src_regs[0], true);
1000 pool->base.clock_sources[0] =
1001 dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL1, &clk_src_regs[1], false);
1002 pool->base.clock_sources[1] =
1003 dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL2, &clk_src_regs[2], false);
1004 pool->base.clk_src_count = 2;
1007 if (pool->base.dp_clock_source == NULL) {
1008 dm_error("DC: failed to create dp clock source!\n");
1009 BREAK_TO_DEBUGGER();
1010 goto res_create_fail;
1013 for (i = 0; i < pool->base.clk_src_count; i++) {
1014 if (pool->base.clock_sources[i] == NULL) {
1015 dm_error("DC: failed to create clock sources!\n");
1016 BREAK_TO_DEBUGGER();
1017 goto res_create_fail;
1021 pool->base.dmcu = dce_dmcu_create(ctx,
1025 if (pool->base.dmcu == NULL) {
1026 dm_error("DC: failed to create dmcu!\n");
1027 BREAK_TO_DEBUGGER();
1028 goto res_create_fail;
1031 pool->base.abm = dce_abm_create(ctx,
1035 if (pool->base.abm == NULL) {
1036 dm_error("DC: failed to create abm!\n");
1037 BREAK_TO_DEBUGGER();
1038 goto res_create_fail;
1042 struct irq_service_init_data init_data;
1043 init_data.ctx = dc->ctx;
1044 pool->base.irqs = dal_irq_service_dce80_create(&init_data);
1045 if (!pool->base.irqs)
1046 goto res_create_fail;
1049 for (i = 0; i < pool->base.pipe_count; i++) {
1050 pool->base.timing_generators[i] = dce80_timing_generator_create(
1051 ctx, i, &dce80_tg_offsets[i]);
1052 if (pool->base.timing_generators[i] == NULL) {
1053 BREAK_TO_DEBUGGER();
1054 dm_error("DC: failed to create tg!\n");
1055 goto res_create_fail;
1058 pool->base.mis[i] = dce80_mem_input_create(ctx, i);
1059 if (pool->base.mis[i] == NULL) {
1060 BREAK_TO_DEBUGGER();
1061 dm_error("DC: failed to create memory input!\n");
1062 goto res_create_fail;
1065 pool->base.ipps[i] = dce80_ipp_create(ctx, i);
1066 if (pool->base.ipps[i] == NULL) {
1067 BREAK_TO_DEBUGGER();
1068 dm_error("DC: failed to create input pixel processor!\n");
1069 goto res_create_fail;
1072 pool->base.transforms[i] = dce80_transform_create(ctx, i);
1073 if (pool->base.transforms[i] == NULL) {
1074 BREAK_TO_DEBUGGER();
1075 dm_error("DC: failed to create transform!\n");
1076 goto res_create_fail;
1079 pool->base.opps[i] = dce80_opp_create(ctx, i);
1080 if (pool->base.opps[i] == NULL) {
1081 BREAK_TO_DEBUGGER();
1082 dm_error("DC: failed to create output pixel processor!\n");
1083 goto res_create_fail;
1087 for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
1088 pool->base.engines[i] = dce80_aux_engine_create(ctx, i);
1089 if (pool->base.engines[i] == NULL) {
1090 BREAK_TO_DEBUGGER();
1092 "DC:failed to create aux engine!!\n");
1093 goto res_create_fail;
1095 pool->base.hw_i2cs[i] = dce80_i2c_hw_create(ctx, i);
1096 if (pool->base.hw_i2cs[i] == NULL) {
1097 BREAK_TO_DEBUGGER();
1099 "DC:failed to create i2c engine!!\n");
1100 goto res_create_fail;
1102 pool->base.sw_i2cs[i] = dce80_i2c_sw_create(ctx);
1103 if (pool->base.sw_i2cs[i] == NULL) {
1104 BREAK_TO_DEBUGGER();
1106 "DC:failed to create sw i2c!!\n");
1107 goto res_create_fail;
1111 dc->caps.max_planes = pool->base.pipe_count;
1113 for (i = 0; i < dc->caps.max_planes; ++i)
1114 dc->caps.planes[i] = plane_cap;
1116 dc->caps.disable_dp_clk_share = true;
1118 if (!resource_construct(num_virtual_links, dc, &pool->base,
1120 goto res_create_fail;
1122 /* Create hardware sequencer */
1123 dce80_hw_sequencer_construct(dc);
1128 dce80_resource_destruct(pool);
1132 struct resource_pool *dce80_create_resource_pool(
1133 uint8_t num_virtual_links,
1136 struct dce110_resource_pool *pool =
1137 kzalloc(sizeof(struct dce110_resource_pool), GFP_KERNEL);
1142 if (dce80_construct(num_virtual_links, dc, pool))
1146 BREAK_TO_DEBUGGER();
1150 static bool dce81_construct(
1151 uint8_t num_virtual_links,
1153 struct dce110_resource_pool *pool)
1156 struct dc_context *ctx = dc->ctx;
1159 ctx->dc_bios->regs = &bios_regs;
1161 pool->base.res_cap = &res_cap_81;
1162 pool->base.funcs = &dce80_res_pool_funcs;
1165 /*************************************************
1166 * Resource + asic cap harcoding *
1167 *************************************************/
1168 pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
1169 pool->base.pipe_count = res_cap_81.num_timing_generator;
1170 pool->base.timing_generator_count = res_cap_81.num_timing_generator;
1171 dc->caps.max_downscale_ratio = 200;
1172 dc->caps.i2c_speed_in_khz = 40;
1173 dc->caps.i2c_speed_in_khz_hdcp = 40;
1174 dc->caps.max_cursor_size = 128;
1175 dc->caps.min_horizontal_blanking_period = 80;
1176 dc->caps.is_apu = true;
1178 /*************************************************
1179 * Create resources *
1180 *************************************************/
1184 if (bp->fw_info_valid && bp->fw_info.external_clock_source_frequency_for_dp != 0) {
1185 pool->base.dp_clock_source =
1186 dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_EXTERNAL, NULL, true);
1188 pool->base.clock_sources[0] =
1189 dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL0, &clk_src_regs[0], false);
1190 pool->base.clock_sources[1] =
1191 dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL1, &clk_src_regs[1], false);
1192 pool->base.clock_sources[2] =
1193 dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL2, &clk_src_regs[2], false);
1194 pool->base.clk_src_count = 3;
1197 pool->base.dp_clock_source =
1198 dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL0, &clk_src_regs[0], true);
1200 pool->base.clock_sources[0] =
1201 dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL1, &clk_src_regs[1], false);
1202 pool->base.clock_sources[1] =
1203 dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL2, &clk_src_regs[2], false);
1204 pool->base.clk_src_count = 2;
1207 if (pool->base.dp_clock_source == NULL) {
1208 dm_error("DC: failed to create dp clock source!\n");
1209 BREAK_TO_DEBUGGER();
1210 goto res_create_fail;
1213 for (i = 0; i < pool->base.clk_src_count; i++) {
1214 if (pool->base.clock_sources[i] == NULL) {
1215 dm_error("DC: failed to create clock sources!\n");
1216 BREAK_TO_DEBUGGER();
1217 goto res_create_fail;
1221 pool->base.dmcu = dce_dmcu_create(ctx,
1225 if (pool->base.dmcu == NULL) {
1226 dm_error("DC: failed to create dmcu!\n");
1227 BREAK_TO_DEBUGGER();
1228 goto res_create_fail;
1231 pool->base.abm = dce_abm_create(ctx,
1235 if (pool->base.abm == NULL) {
1236 dm_error("DC: failed to create abm!\n");
1237 BREAK_TO_DEBUGGER();
1238 goto res_create_fail;
1242 struct irq_service_init_data init_data;
1243 init_data.ctx = dc->ctx;
1244 pool->base.irqs = dal_irq_service_dce80_create(&init_data);
1245 if (!pool->base.irqs)
1246 goto res_create_fail;
1249 for (i = 0; i < pool->base.pipe_count; i++) {
1250 pool->base.timing_generators[i] = dce80_timing_generator_create(
1251 ctx, i, &dce80_tg_offsets[i]);
1252 if (pool->base.timing_generators[i] == NULL) {
1253 BREAK_TO_DEBUGGER();
1254 dm_error("DC: failed to create tg!\n");
1255 goto res_create_fail;
1258 pool->base.mis[i] = dce80_mem_input_create(ctx, i);
1259 if (pool->base.mis[i] == NULL) {
1260 BREAK_TO_DEBUGGER();
1261 dm_error("DC: failed to create memory input!\n");
1262 goto res_create_fail;
1265 pool->base.ipps[i] = dce80_ipp_create(ctx, i);
1266 if (pool->base.ipps[i] == NULL) {
1267 BREAK_TO_DEBUGGER();
1268 dm_error("DC: failed to create input pixel processor!\n");
1269 goto res_create_fail;
1272 pool->base.transforms[i] = dce80_transform_create(ctx, i);
1273 if (pool->base.transforms[i] == NULL) {
1274 BREAK_TO_DEBUGGER();
1275 dm_error("DC: failed to create transform!\n");
1276 goto res_create_fail;
1279 pool->base.opps[i] = dce80_opp_create(ctx, i);
1280 if (pool->base.opps[i] == NULL) {
1281 BREAK_TO_DEBUGGER();
1282 dm_error("DC: failed to create output pixel processor!\n");
1283 goto res_create_fail;
1287 for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
1288 pool->base.engines[i] = dce80_aux_engine_create(ctx, i);
1289 if (pool->base.engines[i] == NULL) {
1290 BREAK_TO_DEBUGGER();
1292 "DC:failed to create aux engine!!\n");
1293 goto res_create_fail;
1295 pool->base.hw_i2cs[i] = dce80_i2c_hw_create(ctx, i);
1296 if (pool->base.hw_i2cs[i] == NULL) {
1297 BREAK_TO_DEBUGGER();
1299 "DC:failed to create i2c engine!!\n");
1300 goto res_create_fail;
1302 pool->base.sw_i2cs[i] = dce80_i2c_sw_create(ctx);
1303 if (pool->base.sw_i2cs[i] == NULL) {
1304 BREAK_TO_DEBUGGER();
1306 "DC:failed to create sw i2c!!\n");
1307 goto res_create_fail;
1311 dc->caps.max_planes = pool->base.pipe_count;
1313 for (i = 0; i < dc->caps.max_planes; ++i)
1314 dc->caps.planes[i] = plane_cap;
1316 dc->caps.disable_dp_clk_share = true;
1318 if (!resource_construct(num_virtual_links, dc, &pool->base,
1320 goto res_create_fail;
1322 /* Create hardware sequencer */
1323 dce80_hw_sequencer_construct(dc);
1328 dce80_resource_destruct(pool);
1332 struct resource_pool *dce81_create_resource_pool(
1333 uint8_t num_virtual_links,
1336 struct dce110_resource_pool *pool =
1337 kzalloc(sizeof(struct dce110_resource_pool), GFP_KERNEL);
1342 if (dce81_construct(num_virtual_links, dc, pool))
1346 BREAK_TO_DEBUGGER();
1350 static bool dce83_construct(
1351 uint8_t num_virtual_links,
1353 struct dce110_resource_pool *pool)
1356 struct dc_context *ctx = dc->ctx;
1359 ctx->dc_bios->regs = &bios_regs;
1361 pool->base.res_cap = &res_cap_83;
1362 pool->base.funcs = &dce80_res_pool_funcs;
1365 /*************************************************
1366 * Resource + asic cap harcoding *
1367 *************************************************/
1368 pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
1369 pool->base.pipe_count = res_cap_83.num_timing_generator;
1370 pool->base.timing_generator_count = res_cap_83.num_timing_generator;
1371 dc->caps.max_downscale_ratio = 200;
1372 dc->caps.i2c_speed_in_khz = 40;
1373 dc->caps.i2c_speed_in_khz_hdcp = 40;
1374 dc->caps.max_cursor_size = 128;
1375 dc->caps.min_horizontal_blanking_period = 80;
1376 dc->caps.is_apu = true;
1377 dc->debug = debug_defaults;
1379 /*************************************************
1380 * Create resources *
1381 *************************************************/
1385 if (bp->fw_info_valid && bp->fw_info.external_clock_source_frequency_for_dp != 0) {
1386 pool->base.dp_clock_source =
1387 dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_EXTERNAL, NULL, true);
1389 pool->base.clock_sources[0] =
1390 dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL1, &clk_src_regs[0], false);
1391 pool->base.clock_sources[1] =
1392 dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL2, &clk_src_regs[1], false);
1393 pool->base.clk_src_count = 2;
1396 pool->base.dp_clock_source =
1397 dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL1, &clk_src_regs[0], true);
1399 pool->base.clock_sources[0] =
1400 dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL2, &clk_src_regs[1], false);
1401 pool->base.clk_src_count = 1;
1404 if (pool->base.dp_clock_source == NULL) {
1405 dm_error("DC: failed to create dp clock source!\n");
1406 BREAK_TO_DEBUGGER();
1407 goto res_create_fail;
1410 for (i = 0; i < pool->base.clk_src_count; i++) {
1411 if (pool->base.clock_sources[i] == NULL) {
1412 dm_error("DC: failed to create clock sources!\n");
1413 BREAK_TO_DEBUGGER();
1414 goto res_create_fail;
1418 pool->base.dmcu = dce_dmcu_create(ctx,
1422 if (pool->base.dmcu == NULL) {
1423 dm_error("DC: failed to create dmcu!\n");
1424 BREAK_TO_DEBUGGER();
1425 goto res_create_fail;
1428 pool->base.abm = dce_abm_create(ctx,
1432 if (pool->base.abm == NULL) {
1433 dm_error("DC: failed to create abm!\n");
1434 BREAK_TO_DEBUGGER();
1435 goto res_create_fail;
1439 struct irq_service_init_data init_data;
1440 init_data.ctx = dc->ctx;
1441 pool->base.irqs = dal_irq_service_dce80_create(&init_data);
1442 if (!pool->base.irqs)
1443 goto res_create_fail;
1446 for (i = 0; i < pool->base.pipe_count; i++) {
1447 pool->base.timing_generators[i] = dce80_timing_generator_create(
1448 ctx, i, &dce80_tg_offsets[i]);
1449 if (pool->base.timing_generators[i] == NULL) {
1450 BREAK_TO_DEBUGGER();
1451 dm_error("DC: failed to create tg!\n");
1452 goto res_create_fail;
1455 pool->base.mis[i] = dce80_mem_input_create(ctx, i);
1456 if (pool->base.mis[i] == NULL) {
1457 BREAK_TO_DEBUGGER();
1458 dm_error("DC: failed to create memory input!\n");
1459 goto res_create_fail;
1462 pool->base.ipps[i] = dce80_ipp_create(ctx, i);
1463 if (pool->base.ipps[i] == NULL) {
1464 BREAK_TO_DEBUGGER();
1465 dm_error("DC: failed to create input pixel processor!\n");
1466 goto res_create_fail;
1469 pool->base.transforms[i] = dce80_transform_create(ctx, i);
1470 if (pool->base.transforms[i] == NULL) {
1471 BREAK_TO_DEBUGGER();
1472 dm_error("DC: failed to create transform!\n");
1473 goto res_create_fail;
1476 pool->base.opps[i] = dce80_opp_create(ctx, i);
1477 if (pool->base.opps[i] == NULL) {
1478 BREAK_TO_DEBUGGER();
1479 dm_error("DC: failed to create output pixel processor!\n");
1480 goto res_create_fail;
1484 for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
1485 pool->base.engines[i] = dce80_aux_engine_create(ctx, i);
1486 if (pool->base.engines[i] == NULL) {
1487 BREAK_TO_DEBUGGER();
1489 "DC:failed to create aux engine!!\n");
1490 goto res_create_fail;
1492 pool->base.hw_i2cs[i] = dce80_i2c_hw_create(ctx, i);
1493 if (pool->base.hw_i2cs[i] == NULL) {
1494 BREAK_TO_DEBUGGER();
1496 "DC:failed to create i2c engine!!\n");
1497 goto res_create_fail;
1499 pool->base.sw_i2cs[i] = dce80_i2c_sw_create(ctx);
1500 if (pool->base.sw_i2cs[i] == NULL) {
1501 BREAK_TO_DEBUGGER();
1503 "DC:failed to create sw i2c!!\n");
1504 goto res_create_fail;
1508 dc->caps.max_planes = pool->base.pipe_count;
1510 for (i = 0; i < dc->caps.max_planes; ++i)
1511 dc->caps.planes[i] = plane_cap;
1513 dc->caps.disable_dp_clk_share = true;
1515 if (!resource_construct(num_virtual_links, dc, &pool->base,
1517 goto res_create_fail;
1519 /* Create hardware sequencer */
1520 dce80_hw_sequencer_construct(dc);
1525 dce80_resource_destruct(pool);
1529 struct resource_pool *dce83_create_resource_pool(
1530 uint8_t num_virtual_links,
1533 struct dce110_resource_pool *pool =
1534 kzalloc(sizeof(struct dce110_resource_pool), GFP_KERNEL);
1539 if (dce83_construct(num_virtual_links, dc, pool))
1542 BREAK_TO_DEBUGGER();