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/slab.h>
28 #include "dce/dce_6_0_d.h"
29 #include "dce/dce_6_0_sh_mask.h"
31 #include "dm_services.h"
33 #include "link_encoder.h"
34 #include "stream_encoder.h"
37 #include "include/irq_service_interface.h"
38 #include "irq/dce60/irq_service_dce60.h"
39 #include "dce110/dce110_timing_generator.h"
40 #include "dce110/dce110_resource.h"
41 #include "dce60/dce60_timing_generator.h"
42 #include "dce/dce_mem_input.h"
43 #include "dce/dce_link_encoder.h"
44 #include "dce/dce_stream_encoder.h"
45 #include "dce/dce_ipp.h"
46 #include "dce/dce_transform.h"
47 #include "dce/dce_opp.h"
48 #include "dce/dce_clock_source.h"
49 #include "dce/dce_audio.h"
50 #include "dce/dce_hwseq.h"
51 #include "dce60/dce60_hw_sequencer.h"
52 #include "dce100/dce100_resource.h"
53 #include "dce/dce_panel_cntl.h"
55 #include "reg_helper.h"
57 #include "dce/dce_dmcu.h"
58 #include "dce/dce_aux.h"
59 #include "dce/dce_abm.h"
60 #include "dce/dce_i2c.h"
61 /* TODO remove this include */
63 #ifndef mmMC_HUB_RDREQ_DMIF_LIMIT
64 #include "gmc/gmc_6_0_d.h"
65 #include "gmc/gmc_6_0_sh_mask.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
79 #ifndef mmBIOS_SCRATCH_2
80 #define mmBIOS_SCRATCH_2 0x05CB
81 #define mmBIOS_SCRATCH_3 0x05CC
82 #define mmBIOS_SCRATCH_6 0x05CF
85 #ifndef mmDP_DPHY_FAST_TRAINING
86 #define mmDP_DPHY_FAST_TRAINING 0x1CCE
87 #define mmDP0_DP_DPHY_FAST_TRAINING 0x1CCE
88 #define mmDP1_DP_DPHY_FAST_TRAINING 0x1FCE
89 #define mmDP2_DP_DPHY_FAST_TRAINING 0x42CE
90 #define mmDP3_DP_DPHY_FAST_TRAINING 0x45CE
91 #define mmDP4_DP_DPHY_FAST_TRAINING 0x48CE
92 #define mmDP5_DP_DPHY_FAST_TRAINING 0x4BCE
96 #ifndef mmHPD_DC_HPD_CONTROL
97 #define mmHPD_DC_HPD_CONTROL 0x189A
98 #define mmHPD0_DC_HPD_CONTROL 0x189A
99 #define mmHPD1_DC_HPD_CONTROL 0x18A2
100 #define mmHPD2_DC_HPD_CONTROL 0x18AA
101 #define mmHPD3_DC_HPD_CONTROL 0x18B2
102 #define mmHPD4_DC_HPD_CONTROL 0x18BA
103 #define mmHPD5_DC_HPD_CONTROL 0x18C2
106 #define DCE11_DIG_FE_CNTL 0x4a00
107 #define DCE11_DIG_BE_CNTL 0x4a47
108 #define DCE11_DP_SEC 0x4ac3
110 static const struct dce110_timing_generator_offsets dce60_tg_offsets[] = {
112 .crtc = (mmCRTC0_CRTC_CONTROL - mmCRTC_CONTROL),
113 .dcp = (mmGRPH_CONTROL - mmGRPH_CONTROL),
114 .dmif = (mmDMIF_PG0_DPG_PIPE_ARBITRATION_CONTROL3
115 - mmDPG_PIPE_ARBITRATION_CONTROL3),
118 .crtc = (mmCRTC1_CRTC_CONTROL - mmCRTC_CONTROL),
119 .dcp = (mmDCP1_GRPH_CONTROL - mmGRPH_CONTROL),
120 .dmif = (mmDMIF_PG1_DPG_PIPE_ARBITRATION_CONTROL3
121 - mmDPG_PIPE_ARBITRATION_CONTROL3),
124 .crtc = (mmCRTC2_CRTC_CONTROL - mmCRTC_CONTROL),
125 .dcp = (mmDCP2_GRPH_CONTROL - mmGRPH_CONTROL),
126 .dmif = (mmDMIF_PG2_DPG_PIPE_ARBITRATION_CONTROL3
127 - mmDPG_PIPE_ARBITRATION_CONTROL3),
130 .crtc = (mmCRTC3_CRTC_CONTROL - mmCRTC_CONTROL),
131 .dcp = (mmDCP3_GRPH_CONTROL - mmGRPH_CONTROL),
132 .dmif = (mmDMIF_PG3_DPG_PIPE_ARBITRATION_CONTROL3
133 - mmDPG_PIPE_ARBITRATION_CONTROL3),
136 .crtc = (mmCRTC4_CRTC_CONTROL - mmCRTC_CONTROL),
137 .dcp = (mmDCP4_GRPH_CONTROL - mmGRPH_CONTROL),
138 .dmif = (mmDMIF_PG4_DPG_PIPE_ARBITRATION_CONTROL3
139 - mmDPG_PIPE_ARBITRATION_CONTROL3),
142 .crtc = (mmCRTC5_CRTC_CONTROL - mmCRTC_CONTROL),
143 .dcp = (mmDCP5_GRPH_CONTROL - mmGRPH_CONTROL),
144 .dmif = (mmDMIF_PG5_DPG_PIPE_ARBITRATION_CONTROL3
145 - mmDPG_PIPE_ARBITRATION_CONTROL3),
149 /* set register offset */
150 #define SR(reg_name)\
151 .reg_name = mm ## reg_name
153 /* set register offset with instance */
154 #define SRI(reg_name, block, id)\
155 .reg_name = mm ## block ## id ## _ ## reg_name
157 #define ipp_regs(id)\
159 IPP_COMMON_REG_LIST_DCE_BASE(id)\
162 static const struct dce_ipp_registers ipp_regs[] = {
171 static const struct dce_ipp_shift ipp_shift = {
172 IPP_DCE60_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
175 static const struct dce_ipp_mask ipp_mask = {
176 IPP_DCE60_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
179 #define transform_regs(id)\
181 XFM_COMMON_REG_LIST_DCE60(id)\
184 static const struct dce_transform_registers xfm_regs[] = {
193 static const struct dce_transform_shift xfm_shift = {
194 XFM_COMMON_MASK_SH_LIST_DCE60(__SHIFT)
197 static const struct dce_transform_mask xfm_mask = {
198 XFM_COMMON_MASK_SH_LIST_DCE60(_MASK)
201 #define aux_regs(id)\
206 static const struct dce110_link_enc_aux_registers link_enc_aux_regs[] = {
215 #define hpd_regs(id)\
220 static const struct dce110_link_enc_hpd_registers link_enc_hpd_regs[] = {
229 #define link_regs(id)\
231 LE_DCE60_REG_LIST(id)\
234 static const struct dce110_link_enc_registers link_enc_regs[] = {
243 #define stream_enc_regs(id)\
245 SE_COMMON_REG_LIST_DCE_BASE(id),\
249 static const struct dce110_stream_enc_registers stream_enc_regs[] = {
258 static const struct dce_stream_encoder_shift se_shift = {
259 SE_COMMON_MASK_SH_LIST_DCE80_100(__SHIFT)
262 static const struct dce_stream_encoder_mask se_mask = {
263 SE_COMMON_MASK_SH_LIST_DCE80_100(_MASK)
266 static const struct dce_panel_cntl_registers panel_cntl_regs[] = {
267 { DCE_PANEL_CNTL_REG_LIST() }
270 static const struct dce_panel_cntl_shift panel_cntl_shift = {
271 DCE_PANEL_CNTL_MASK_SH_LIST(__SHIFT)
274 static const struct dce_panel_cntl_mask panel_cntl_mask = {
275 DCE_PANEL_CNTL_MASK_SH_LIST(_MASK)
278 #define opp_regs(id)\
280 OPP_DCE_60_REG_LIST(id),\
283 static const struct dce_opp_registers opp_regs[] = {
292 static const struct dce_opp_shift opp_shift = {
293 OPP_COMMON_MASK_SH_LIST_DCE_60(__SHIFT)
296 static const struct dce_opp_mask opp_mask = {
297 OPP_COMMON_MASK_SH_LIST_DCE_60(_MASK)
300 static const struct dce110_aux_registers_shift aux_shift = {
301 DCE10_AUX_MASK_SH_LIST(__SHIFT)
304 static const struct dce110_aux_registers_mask aux_mask = {
305 DCE10_AUX_MASK_SH_LIST(_MASK)
308 #define aux_engine_regs(id)\
310 AUX_COMMON_REG_LIST(id), \
311 .AUX_RESET_MASK = 0 \
314 static const struct dce110_aux_registers aux_engine_regs[] = {
323 #define audio_regs(id)\
325 AUD_COMMON_REG_LIST(id)\
328 static const struct dce_audio_registers audio_regs[] = {
337 static const struct dce_audio_shift audio_shift = {
338 AUD_DCE60_MASK_SH_LIST(__SHIFT)
341 static const struct dce_audio_mask audio_mask = {
342 AUD_DCE60_MASK_SH_LIST(_MASK)
345 #define clk_src_regs(id)\
347 CS_COMMON_REG_LIST_DCE_80(id),\
351 static const struct dce110_clk_src_regs clk_src_regs[] = {
357 static const struct dce110_clk_src_shift cs_shift = {
358 CS_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
361 static const struct dce110_clk_src_mask cs_mask = {
362 CS_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
365 static const struct bios_registers bios_regs = {
366 .BIOS_SCRATCH_3 = mmBIOS_SCRATCH_3,
367 .BIOS_SCRATCH_6 = mmBIOS_SCRATCH_6
370 static const struct resource_caps res_cap = {
371 .num_timing_generator = 6,
373 .num_stream_encoder = 6,
378 static const struct resource_caps res_cap_61 = {
379 .num_timing_generator = 4,
381 .num_stream_encoder = 6,
386 static const struct resource_caps res_cap_64 = {
387 .num_timing_generator = 2,
389 .num_stream_encoder = 2,
394 static const struct dc_plane_cap plane_cap = {
395 .type = DC_PLANE_TYPE_DCE_RGB,
397 .pixel_format_support = {
403 .max_upscale_factor = {
409 .max_downscale_factor = {
416 static const struct dce_dmcu_registers dmcu_regs = {
417 DMCU_DCE60_REG_LIST()
420 static const struct dce_dmcu_shift dmcu_shift = {
421 DMCU_MASK_SH_LIST_DCE60(__SHIFT)
424 static const struct dce_dmcu_mask dmcu_mask = {
425 DMCU_MASK_SH_LIST_DCE60(_MASK)
427 static const struct dce_abm_registers abm_regs = {
428 ABM_DCE110_COMMON_REG_LIST()
431 static const struct dce_abm_shift abm_shift = {
432 ABM_MASK_SH_LIST_DCE110(__SHIFT)
435 static const struct dce_abm_mask abm_mask = {
436 ABM_MASK_SH_LIST_DCE110(_MASK)
440 #define REG(reg) mm ## reg
442 #ifndef mmCC_DC_HDMI_STRAPS
443 #define mmCC_DC_HDMI_STRAPS 0x1918
444 #define CC_DC_HDMI_STRAPS__HDMI_DISABLE_MASK 0x40
445 #define CC_DC_HDMI_STRAPS__HDMI_DISABLE__SHIFT 0x6
446 #define CC_DC_HDMI_STRAPS__AUDIO_STREAM_NUMBER_MASK 0x700
447 #define CC_DC_HDMI_STRAPS__AUDIO_STREAM_NUMBER__SHIFT 0x8
450 static int map_transmitter_id_to_phy_instance(
451 enum transmitter transmitter)
453 switch (transmitter) {
454 case TRANSMITTER_UNIPHY_A:
457 case TRANSMITTER_UNIPHY_B:
460 case TRANSMITTER_UNIPHY_C:
463 case TRANSMITTER_UNIPHY_D:
466 case TRANSMITTER_UNIPHY_E:
469 case TRANSMITTER_UNIPHY_F:
472 case TRANSMITTER_UNIPHY_G:
481 static void read_dce_straps(
482 struct dc_context *ctx,
483 struct resource_straps *straps)
485 REG_GET_2(CC_DC_HDMI_STRAPS,
486 HDMI_DISABLE, &straps->hdmi_disable,
487 AUDIO_STREAM_NUMBER, &straps->audio_stream_number);
489 REG_GET(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO, &straps->dc_pinstraps_audio);
492 static struct audio *create_audio(
493 struct dc_context *ctx, unsigned int inst)
495 return dce60_audio_create(ctx, inst,
496 &audio_regs[inst], &audio_shift, &audio_mask);
499 static struct timing_generator *dce60_timing_generator_create(
500 struct dc_context *ctx,
502 const struct dce110_timing_generator_offsets *offsets)
504 struct dce110_timing_generator *tg110 =
505 kzalloc(sizeof(struct dce110_timing_generator), GFP_KERNEL);
510 dce60_timing_generator_construct(tg110, ctx, instance, offsets);
514 static struct output_pixel_processor *dce60_opp_create(
515 struct dc_context *ctx,
518 struct dce110_opp *opp =
519 kzalloc(sizeof(struct dce110_opp), GFP_KERNEL);
524 dce60_opp_construct(opp,
525 ctx, inst, &opp_regs[inst], &opp_shift, &opp_mask);
529 struct dce_aux *dce60_aux_engine_create(
530 struct dc_context *ctx,
533 struct aux_engine_dce110 *aux_engine =
534 kzalloc(sizeof(struct aux_engine_dce110), GFP_KERNEL);
539 dce110_aux_engine_construct(aux_engine, ctx, inst,
540 SW_AUX_TIMEOUT_PERIOD_MULTIPLIER * AUX_TIMEOUT_PERIOD,
541 &aux_engine_regs[inst],
544 ctx->dc->caps.extended_aux_timeout_support);
546 return &aux_engine->base;
548 #define i2c_inst_regs(id) { I2C_HW_ENGINE_COMMON_REG_LIST(id) }
550 static const struct dce_i2c_registers i2c_hw_regs[] = {
559 static const struct dce_i2c_shift i2c_shifts = {
560 I2C_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
563 static const struct dce_i2c_mask i2c_masks = {
564 I2C_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
567 struct dce_i2c_hw *dce60_i2c_hw_create(
568 struct dc_context *ctx,
571 struct dce_i2c_hw *dce_i2c_hw =
572 kzalloc(sizeof(struct dce_i2c_hw), GFP_KERNEL);
577 dce_i2c_hw_construct(dce_i2c_hw, ctx, inst,
578 &i2c_hw_regs[inst], &i2c_shifts, &i2c_masks);
583 struct dce_i2c_sw *dce60_i2c_sw_create(
584 struct dc_context *ctx)
586 struct dce_i2c_sw *dce_i2c_sw =
587 kzalloc(sizeof(struct dce_i2c_sw), GFP_KERNEL);
592 dce_i2c_sw_construct(dce_i2c_sw, ctx);
596 static struct stream_encoder *dce60_stream_encoder_create(
597 enum engine_id eng_id,
598 struct dc_context *ctx)
600 struct dce110_stream_encoder *enc110 =
601 kzalloc(sizeof(struct dce110_stream_encoder), GFP_KERNEL);
606 dce110_stream_encoder_construct(enc110, ctx, ctx->dc_bios, eng_id,
607 &stream_enc_regs[eng_id],
608 &se_shift, &se_mask);
609 return &enc110->base;
612 #define SRII(reg_name, block, id)\
613 .reg_name[id] = mm ## block ## id ## _ ## reg_name
615 static const struct dce_hwseq_registers hwseq_reg = {
616 HWSEQ_DCE6_REG_LIST()
619 static const struct dce_hwseq_shift hwseq_shift = {
620 HWSEQ_DCE6_MASK_SH_LIST(__SHIFT)
623 static const struct dce_hwseq_mask hwseq_mask = {
624 HWSEQ_DCE6_MASK_SH_LIST(_MASK)
627 static struct dce_hwseq *dce60_hwseq_create(
628 struct dc_context *ctx)
630 struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
634 hws->regs = &hwseq_reg;
635 hws->shifts = &hwseq_shift;
636 hws->masks = &hwseq_mask;
641 static const struct resource_create_funcs res_create_funcs = {
642 .read_dce_straps = read_dce_straps,
643 .create_audio = create_audio,
644 .create_stream_encoder = dce60_stream_encoder_create,
645 .create_hwseq = dce60_hwseq_create,
648 #define mi_inst_regs(id) { \
649 MI_DCE6_REG_LIST(id), \
650 .MC_HUB_RDREQ_DMIF_LIMIT = mmMC_HUB_RDREQ_DMIF_LIMIT \
652 static const struct dce_mem_input_registers mi_regs[] = {
661 static const struct dce_mem_input_shift mi_shifts = {
662 MI_DCE6_MASK_SH_LIST(__SHIFT),
663 .ENABLE = MC_HUB_RDREQ_DMIF_LIMIT__ENABLE__SHIFT
666 static const struct dce_mem_input_mask mi_masks = {
667 MI_DCE6_MASK_SH_LIST(_MASK),
668 .ENABLE = MC_HUB_RDREQ_DMIF_LIMIT__ENABLE_MASK
671 static struct mem_input *dce60_mem_input_create(
672 struct dc_context *ctx,
675 struct dce_mem_input *dce_mi = kzalloc(sizeof(struct dce_mem_input),
683 dce60_mem_input_construct(dce_mi, ctx, inst, &mi_regs[inst], &mi_shifts, &mi_masks);
684 dce_mi->wa.single_head_rdreq_dmif_limit = 2;
685 return &dce_mi->base;
688 static void dce60_transform_destroy(struct transform **xfm)
690 kfree(TO_DCE_TRANSFORM(*xfm));
694 static struct transform *dce60_transform_create(
695 struct dc_context *ctx,
698 struct dce_transform *transform =
699 kzalloc(sizeof(struct dce_transform), GFP_KERNEL);
704 dce60_transform_construct(transform, ctx, inst,
705 &xfm_regs[inst], &xfm_shift, &xfm_mask);
706 transform->prescaler_on = false;
707 return &transform->base;
710 static const struct encoder_feature_support link_enc_feature = {
711 .max_hdmi_deep_color = COLOR_DEPTH_121212,
712 .max_hdmi_pixel_clock = 297000,
713 .flags.bits.IS_HBR2_CAPABLE = true,
714 .flags.bits.IS_TPS3_CAPABLE = true
717 struct link_encoder *dce60_link_encoder_create(
718 const struct encoder_init_data *enc_init_data)
720 struct dce110_link_encoder *enc110 =
721 kzalloc(sizeof(struct dce110_link_encoder), GFP_KERNEL);
728 map_transmitter_id_to_phy_instance(enc_init_data->transmitter);
730 dce60_link_encoder_construct(enc110,
733 &link_enc_regs[link_regs_id],
734 &link_enc_aux_regs[enc_init_data->channel - 1],
735 &link_enc_hpd_regs[enc_init_data->hpd_source]);
736 return &enc110->base;
739 static struct panel_cntl *dce60_panel_cntl_create(const struct panel_cntl_init_data *init_data)
741 struct dce_panel_cntl *panel_cntl =
742 kzalloc(sizeof(struct dce_panel_cntl), GFP_KERNEL);
747 dce_panel_cntl_construct(panel_cntl,
749 &panel_cntl_regs[init_data->inst],
753 return &panel_cntl->base;
756 struct clock_source *dce60_clock_source_create(
757 struct dc_context *ctx,
758 struct dc_bios *bios,
759 enum clock_source_id id,
760 const struct dce110_clk_src_regs *regs,
763 struct dce110_clk_src *clk_src =
764 kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL);
769 if (dce110_clk_src_construct(clk_src, ctx, bios, id,
770 regs, &cs_shift, &cs_mask)) {
771 clk_src->base.dp_clk_src = dp_clk_src;
772 return &clk_src->base;
780 void dce60_clock_source_destroy(struct clock_source **clk_src)
782 kfree(TO_DCE110_CLK_SRC(*clk_src));
786 static struct input_pixel_processor *dce60_ipp_create(
787 struct dc_context *ctx, uint32_t inst)
789 struct dce_ipp *ipp = kzalloc(sizeof(struct dce_ipp), GFP_KERNEL);
796 dce60_ipp_construct(ipp, ctx, inst,
797 &ipp_regs[inst], &ipp_shift, &ipp_mask);
801 static void dce60_resource_destruct(struct dce110_resource_pool *pool)
805 for (i = 0; i < pool->base.pipe_count; i++) {
806 if (pool->base.opps[i] != NULL)
807 dce110_opp_destroy(&pool->base.opps[i]);
809 if (pool->base.transforms[i] != NULL)
810 dce60_transform_destroy(&pool->base.transforms[i]);
812 if (pool->base.ipps[i] != NULL)
813 dce_ipp_destroy(&pool->base.ipps[i]);
815 if (pool->base.mis[i] != NULL) {
816 kfree(TO_DCE_MEM_INPUT(pool->base.mis[i]));
817 pool->base.mis[i] = NULL;
820 if (pool->base.timing_generators[i] != NULL) {
821 kfree(DCE110TG_FROM_TG(pool->base.timing_generators[i]));
822 pool->base.timing_generators[i] = NULL;
826 for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
827 if (pool->base.engines[i] != NULL)
828 dce110_engine_destroy(&pool->base.engines[i]);
829 if (pool->base.hw_i2cs[i] != NULL) {
830 kfree(pool->base.hw_i2cs[i]);
831 pool->base.hw_i2cs[i] = NULL;
833 if (pool->base.sw_i2cs[i] != NULL) {
834 kfree(pool->base.sw_i2cs[i]);
835 pool->base.sw_i2cs[i] = NULL;
839 for (i = 0; i < pool->base.stream_enc_count; i++) {
840 if (pool->base.stream_enc[i] != NULL)
841 kfree(DCE110STRENC_FROM_STRENC(pool->base.stream_enc[i]));
844 for (i = 0; i < pool->base.clk_src_count; i++) {
845 if (pool->base.clock_sources[i] != NULL) {
846 dce60_clock_source_destroy(&pool->base.clock_sources[i]);
850 if (pool->base.abm != NULL)
851 dce_abm_destroy(&pool->base.abm);
853 if (pool->base.dmcu != NULL)
854 dce_dmcu_destroy(&pool->base.dmcu);
856 if (pool->base.dp_clock_source != NULL)
857 dce60_clock_source_destroy(&pool->base.dp_clock_source);
859 for (i = 0; i < pool->base.audio_count; i++) {
860 if (pool->base.audios[i] != NULL) {
861 dce_aud_destroy(&pool->base.audios[i]);
865 if (pool->base.irqs != NULL) {
866 dal_irq_service_destroy(&pool->base.irqs);
870 bool dce60_validate_bandwidth(
872 struct dc_state *context,
876 bool at_least_one_pipe = false;
878 for (i = 0; i < dc->res_pool->pipe_count; i++) {
879 if (context->res_ctx.pipe_ctx[i].stream)
880 at_least_one_pipe = true;
883 if (at_least_one_pipe) {
884 /* TODO implement when needed but for now hardcode max value*/
885 context->bw_ctx.bw.dce.dispclk_khz = 681000;
886 context->bw_ctx.bw.dce.yclk_khz = 250000 * MEMORY_TYPE_MULTIPLIER_CZ;
888 context->bw_ctx.bw.dce.dispclk_khz = 0;
889 context->bw_ctx.bw.dce.yclk_khz = 0;
895 static bool dce60_validate_surface_sets(
896 struct dc_state *context)
900 for (i = 0; i < context->stream_count; i++) {
901 if (context->stream_status[i].plane_count == 0)
904 if (context->stream_status[i].plane_count > 1)
907 if (context->stream_status[i].plane_states[0]->format
908 >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN)
915 enum dc_status dce60_validate_global(
917 struct dc_state *context)
919 if (!dce60_validate_surface_sets(context))
920 return DC_FAIL_SURFACE_VALIDATE;
925 static void dce60_destroy_resource_pool(struct resource_pool **pool)
927 struct dce110_resource_pool *dce110_pool = TO_DCE110_RES_POOL(*pool);
929 dce60_resource_destruct(dce110_pool);
934 static const struct resource_funcs dce60_res_pool_funcs = {
935 .destroy = dce60_destroy_resource_pool,
936 .link_enc_create = dce60_link_encoder_create,
937 .panel_cntl_create = dce60_panel_cntl_create,
938 .validate_bandwidth = dce60_validate_bandwidth,
939 .validate_plane = dce100_validate_plane,
940 .add_stream_to_ctx = dce100_add_stream_to_ctx,
941 .validate_global = dce60_validate_global,
942 .find_first_free_match_stream_enc_for_link = dce100_find_first_free_match_stream_enc_for_link
945 static bool dce60_construct(
946 uint8_t num_virtual_links,
948 struct dce110_resource_pool *pool)
951 struct dc_context *ctx = dc->ctx;
954 ctx->dc_bios->regs = &bios_regs;
956 pool->base.res_cap = &res_cap;
957 pool->base.funcs = &dce60_res_pool_funcs;
960 /*************************************************
961 * Resource + asic cap harcoding *
962 *************************************************/
963 pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
964 pool->base.pipe_count = res_cap.num_timing_generator;
965 pool->base.timing_generator_count = res_cap.num_timing_generator;
966 dc->caps.max_downscale_ratio = 200;
967 dc->caps.i2c_speed_in_khz = 40;
968 dc->caps.max_cursor_size = 64;
969 dc->caps.dual_link_dvi = true;
970 dc->caps.extended_aux_timeout_support = false;
972 /*************************************************
974 *************************************************/
978 if (bp->fw_info_valid && bp->fw_info.external_clock_source_frequency_for_dp != 0) {
979 pool->base.dp_clock_source =
980 dce60_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_EXTERNAL, NULL, true);
982 pool->base.clock_sources[0] =
983 dce60_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL0, &clk_src_regs[0], false);
984 pool->base.clock_sources[1] =
985 dce60_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL1, &clk_src_regs[1], false);
986 pool->base.clk_src_count = 2;
989 pool->base.dp_clock_source =
990 dce60_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL0, &clk_src_regs[0], true);
992 pool->base.clock_sources[0] =
993 dce60_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL1, &clk_src_regs[1], false);
994 pool->base.clk_src_count = 1;
997 if (pool->base.dp_clock_source == NULL) {
998 dm_error("DC: failed to create dp clock source!\n");
1000 goto res_create_fail;
1003 for (i = 0; i < pool->base.clk_src_count; i++) {
1004 if (pool->base.clock_sources[i] == NULL) {
1005 dm_error("DC: failed to create clock sources!\n");
1006 BREAK_TO_DEBUGGER();
1007 goto res_create_fail;
1011 pool->base.dmcu = dce_dmcu_create(ctx,
1015 if (pool->base.dmcu == NULL) {
1016 dm_error("DC: failed to create dmcu!\n");
1017 BREAK_TO_DEBUGGER();
1018 goto res_create_fail;
1021 pool->base.abm = dce_abm_create(ctx,
1025 if (pool->base.abm == NULL) {
1026 dm_error("DC: failed to create abm!\n");
1027 BREAK_TO_DEBUGGER();
1028 goto res_create_fail;
1032 struct irq_service_init_data init_data;
1033 init_data.ctx = dc->ctx;
1034 pool->base.irqs = dal_irq_service_dce60_create(&init_data);
1035 if (!pool->base.irqs)
1036 goto res_create_fail;
1039 for (i = 0; i < pool->base.pipe_count; i++) {
1040 pool->base.timing_generators[i] = dce60_timing_generator_create(
1041 ctx, i, &dce60_tg_offsets[i]);
1042 if (pool->base.timing_generators[i] == NULL) {
1043 BREAK_TO_DEBUGGER();
1044 dm_error("DC: failed to create tg!\n");
1045 goto res_create_fail;
1048 pool->base.mis[i] = dce60_mem_input_create(ctx, i);
1049 if (pool->base.mis[i] == NULL) {
1050 BREAK_TO_DEBUGGER();
1051 dm_error("DC: failed to create memory input!\n");
1052 goto res_create_fail;
1055 pool->base.ipps[i] = dce60_ipp_create(ctx, i);
1056 if (pool->base.ipps[i] == NULL) {
1057 BREAK_TO_DEBUGGER();
1058 dm_error("DC: failed to create input pixel processor!\n");
1059 goto res_create_fail;
1062 pool->base.transforms[i] = dce60_transform_create(ctx, i);
1063 if (pool->base.transforms[i] == NULL) {
1064 BREAK_TO_DEBUGGER();
1065 dm_error("DC: failed to create transform!\n");
1066 goto res_create_fail;
1069 pool->base.opps[i] = dce60_opp_create(ctx, i);
1070 if (pool->base.opps[i] == NULL) {
1071 BREAK_TO_DEBUGGER();
1072 dm_error("DC: failed to create output pixel processor!\n");
1073 goto res_create_fail;
1077 for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
1078 pool->base.engines[i] = dce60_aux_engine_create(ctx, i);
1079 if (pool->base.engines[i] == NULL) {
1080 BREAK_TO_DEBUGGER();
1082 "DC:failed to create aux engine!!\n");
1083 goto res_create_fail;
1085 pool->base.hw_i2cs[i] = dce60_i2c_hw_create(ctx, i);
1086 if (pool->base.hw_i2cs[i] == NULL) {
1087 BREAK_TO_DEBUGGER();
1089 "DC:failed to create i2c engine!!\n");
1090 goto res_create_fail;
1092 pool->base.sw_i2cs[i] = dce60_i2c_sw_create(ctx);
1093 if (pool->base.sw_i2cs[i] == NULL) {
1094 BREAK_TO_DEBUGGER();
1096 "DC:failed to create sw i2c!!\n");
1097 goto res_create_fail;
1101 dc->caps.max_planes = pool->base.pipe_count;
1103 for (i = 0; i < dc->caps.max_planes; ++i)
1104 dc->caps.planes[i] = plane_cap;
1106 dc->caps.disable_dp_clk_share = true;
1108 if (!resource_construct(num_virtual_links, dc, &pool->base,
1110 goto res_create_fail;
1112 /* Create hardware sequencer */
1113 dce60_hw_sequencer_construct(dc);
1118 dce60_resource_destruct(pool);
1122 struct resource_pool *dce60_create_resource_pool(
1123 uint8_t num_virtual_links,
1126 struct dce110_resource_pool *pool =
1127 kzalloc(sizeof(struct dce110_resource_pool), GFP_KERNEL);
1132 if (dce60_construct(num_virtual_links, dc, pool))
1135 BREAK_TO_DEBUGGER();
1139 static bool dce61_construct(
1140 uint8_t num_virtual_links,
1142 struct dce110_resource_pool *pool)
1145 struct dc_context *ctx = dc->ctx;
1148 ctx->dc_bios->regs = &bios_regs;
1150 pool->base.res_cap = &res_cap_61;
1151 pool->base.funcs = &dce60_res_pool_funcs;
1154 /*************************************************
1155 * Resource + asic cap harcoding *
1156 *************************************************/
1157 pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
1158 pool->base.pipe_count = res_cap_61.num_timing_generator;
1159 pool->base.timing_generator_count = res_cap_61.num_timing_generator;
1160 dc->caps.max_downscale_ratio = 200;
1161 dc->caps.i2c_speed_in_khz = 40;
1162 dc->caps.max_cursor_size = 64;
1163 dc->caps.is_apu = true;
1165 /*************************************************
1166 * Create resources *
1167 *************************************************/
1171 if (bp->fw_info_valid && bp->fw_info.external_clock_source_frequency_for_dp != 0) {
1172 pool->base.dp_clock_source =
1173 dce60_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_EXTERNAL, NULL, true);
1175 pool->base.clock_sources[0] =
1176 dce60_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL0, &clk_src_regs[0], false);
1177 pool->base.clock_sources[1] =
1178 dce60_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL1, &clk_src_regs[1], false);
1179 pool->base.clock_sources[2] =
1180 dce60_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL2, &clk_src_regs[2], false);
1181 pool->base.clk_src_count = 3;
1184 pool->base.dp_clock_source =
1185 dce60_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL0, &clk_src_regs[0], true);
1187 pool->base.clock_sources[0] =
1188 dce60_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL1, &clk_src_regs[1], false);
1189 pool->base.clock_sources[1] =
1190 dce60_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL2, &clk_src_regs[2], false);
1191 pool->base.clk_src_count = 2;
1194 if (pool->base.dp_clock_source == NULL) {
1195 dm_error("DC: failed to create dp clock source!\n");
1196 BREAK_TO_DEBUGGER();
1197 goto res_create_fail;
1200 for (i = 0; i < pool->base.clk_src_count; i++) {
1201 if (pool->base.clock_sources[i] == NULL) {
1202 dm_error("DC: failed to create clock sources!\n");
1203 BREAK_TO_DEBUGGER();
1204 goto res_create_fail;
1208 pool->base.dmcu = dce_dmcu_create(ctx,
1212 if (pool->base.dmcu == NULL) {
1213 dm_error("DC: failed to create dmcu!\n");
1214 BREAK_TO_DEBUGGER();
1215 goto res_create_fail;
1218 pool->base.abm = dce_abm_create(ctx,
1222 if (pool->base.abm == NULL) {
1223 dm_error("DC: failed to create abm!\n");
1224 BREAK_TO_DEBUGGER();
1225 goto res_create_fail;
1229 struct irq_service_init_data init_data;
1230 init_data.ctx = dc->ctx;
1231 pool->base.irqs = dal_irq_service_dce60_create(&init_data);
1232 if (!pool->base.irqs)
1233 goto res_create_fail;
1236 for (i = 0; i < pool->base.pipe_count; i++) {
1237 pool->base.timing_generators[i] = dce60_timing_generator_create(
1238 ctx, i, &dce60_tg_offsets[i]);
1239 if (pool->base.timing_generators[i] == NULL) {
1240 BREAK_TO_DEBUGGER();
1241 dm_error("DC: failed to create tg!\n");
1242 goto res_create_fail;
1245 pool->base.mis[i] = dce60_mem_input_create(ctx, i);
1246 if (pool->base.mis[i] == NULL) {
1247 BREAK_TO_DEBUGGER();
1248 dm_error("DC: failed to create memory input!\n");
1249 goto res_create_fail;
1252 pool->base.ipps[i] = dce60_ipp_create(ctx, i);
1253 if (pool->base.ipps[i] == NULL) {
1254 BREAK_TO_DEBUGGER();
1255 dm_error("DC: failed to create input pixel processor!\n");
1256 goto res_create_fail;
1259 pool->base.transforms[i] = dce60_transform_create(ctx, i);
1260 if (pool->base.transforms[i] == NULL) {
1261 BREAK_TO_DEBUGGER();
1262 dm_error("DC: failed to create transform!\n");
1263 goto res_create_fail;
1266 pool->base.opps[i] = dce60_opp_create(ctx, i);
1267 if (pool->base.opps[i] == NULL) {
1268 BREAK_TO_DEBUGGER();
1269 dm_error("DC: failed to create output pixel processor!\n");
1270 goto res_create_fail;
1274 for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
1275 pool->base.engines[i] = dce60_aux_engine_create(ctx, i);
1276 if (pool->base.engines[i] == NULL) {
1277 BREAK_TO_DEBUGGER();
1279 "DC:failed to create aux engine!!\n");
1280 goto res_create_fail;
1282 pool->base.hw_i2cs[i] = dce60_i2c_hw_create(ctx, i);
1283 if (pool->base.hw_i2cs[i] == NULL) {
1284 BREAK_TO_DEBUGGER();
1286 "DC:failed to create i2c engine!!\n");
1287 goto res_create_fail;
1289 pool->base.sw_i2cs[i] = dce60_i2c_sw_create(ctx);
1290 if (pool->base.sw_i2cs[i] == NULL) {
1291 BREAK_TO_DEBUGGER();
1293 "DC:failed to create sw i2c!!\n");
1294 goto res_create_fail;
1298 dc->caps.max_planes = pool->base.pipe_count;
1300 for (i = 0; i < dc->caps.max_planes; ++i)
1301 dc->caps.planes[i] = plane_cap;
1303 dc->caps.disable_dp_clk_share = true;
1305 if (!resource_construct(num_virtual_links, dc, &pool->base,
1307 goto res_create_fail;
1309 /* Create hardware sequencer */
1310 dce60_hw_sequencer_construct(dc);
1315 dce60_resource_destruct(pool);
1319 struct resource_pool *dce61_create_resource_pool(
1320 uint8_t num_virtual_links,
1323 struct dce110_resource_pool *pool =
1324 kzalloc(sizeof(struct dce110_resource_pool), GFP_KERNEL);
1329 if (dce61_construct(num_virtual_links, dc, pool))
1332 BREAK_TO_DEBUGGER();
1336 static bool dce64_construct(
1337 uint8_t num_virtual_links,
1339 struct dce110_resource_pool *pool)
1342 struct dc_context *ctx = dc->ctx;
1345 ctx->dc_bios->regs = &bios_regs;
1347 pool->base.res_cap = &res_cap_64;
1348 pool->base.funcs = &dce60_res_pool_funcs;
1351 /*************************************************
1352 * Resource + asic cap harcoding *
1353 *************************************************/
1354 pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
1355 pool->base.pipe_count = res_cap_64.num_timing_generator;
1356 pool->base.timing_generator_count = res_cap_64.num_timing_generator;
1357 dc->caps.max_downscale_ratio = 200;
1358 dc->caps.i2c_speed_in_khz = 40;
1359 dc->caps.max_cursor_size = 64;
1360 dc->caps.is_apu = true;
1362 /*************************************************
1363 * Create resources *
1364 *************************************************/
1368 if (bp->fw_info_valid && bp->fw_info.external_clock_source_frequency_for_dp != 0) {
1369 pool->base.dp_clock_source =
1370 dce60_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_EXTERNAL, NULL, true);
1372 pool->base.clock_sources[0] =
1373 dce60_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL1, &clk_src_regs[0], false);
1374 pool->base.clock_sources[1] =
1375 dce60_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL2, &clk_src_regs[1], false);
1376 pool->base.clk_src_count = 2;
1379 pool->base.dp_clock_source =
1380 dce60_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL1, &clk_src_regs[0], true);
1382 pool->base.clock_sources[0] =
1383 dce60_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL2, &clk_src_regs[1], false);
1384 pool->base.clk_src_count = 1;
1387 if (pool->base.dp_clock_source == NULL) {
1388 dm_error("DC: failed to create dp clock source!\n");
1389 BREAK_TO_DEBUGGER();
1390 goto res_create_fail;
1393 for (i = 0; i < pool->base.clk_src_count; i++) {
1394 if (pool->base.clock_sources[i] == NULL) {
1395 dm_error("DC: failed to create clock sources!\n");
1396 BREAK_TO_DEBUGGER();
1397 goto res_create_fail;
1401 pool->base.dmcu = dce_dmcu_create(ctx,
1405 if (pool->base.dmcu == NULL) {
1406 dm_error("DC: failed to create dmcu!\n");
1407 BREAK_TO_DEBUGGER();
1408 goto res_create_fail;
1411 pool->base.abm = dce_abm_create(ctx,
1415 if (pool->base.abm == NULL) {
1416 dm_error("DC: failed to create abm!\n");
1417 BREAK_TO_DEBUGGER();
1418 goto res_create_fail;
1422 struct irq_service_init_data init_data;
1423 init_data.ctx = dc->ctx;
1424 pool->base.irqs = dal_irq_service_dce60_create(&init_data);
1425 if (!pool->base.irqs)
1426 goto res_create_fail;
1429 for (i = 0; i < pool->base.pipe_count; i++) {
1430 pool->base.timing_generators[i] = dce60_timing_generator_create(
1431 ctx, i, &dce60_tg_offsets[i]);
1432 if (pool->base.timing_generators[i] == NULL) {
1433 BREAK_TO_DEBUGGER();
1434 dm_error("DC: failed to create tg!\n");
1435 goto res_create_fail;
1438 pool->base.mis[i] = dce60_mem_input_create(ctx, i);
1439 if (pool->base.mis[i] == NULL) {
1440 BREAK_TO_DEBUGGER();
1441 dm_error("DC: failed to create memory input!\n");
1442 goto res_create_fail;
1445 pool->base.ipps[i] = dce60_ipp_create(ctx, i);
1446 if (pool->base.ipps[i] == NULL) {
1447 BREAK_TO_DEBUGGER();
1448 dm_error("DC: failed to create input pixel processor!\n");
1449 goto res_create_fail;
1452 pool->base.transforms[i] = dce60_transform_create(ctx, i);
1453 if (pool->base.transforms[i] == NULL) {
1454 BREAK_TO_DEBUGGER();
1455 dm_error("DC: failed to create transform!\n");
1456 goto res_create_fail;
1459 pool->base.opps[i] = dce60_opp_create(ctx, i);
1460 if (pool->base.opps[i] == NULL) {
1461 BREAK_TO_DEBUGGER();
1462 dm_error("DC: failed to create output pixel processor!\n");
1463 goto res_create_fail;
1467 for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
1468 pool->base.engines[i] = dce60_aux_engine_create(ctx, i);
1469 if (pool->base.engines[i] == NULL) {
1470 BREAK_TO_DEBUGGER();
1472 "DC:failed to create aux engine!!\n");
1473 goto res_create_fail;
1475 pool->base.hw_i2cs[i] = dce60_i2c_hw_create(ctx, i);
1476 if (pool->base.hw_i2cs[i] == NULL) {
1477 BREAK_TO_DEBUGGER();
1479 "DC:failed to create i2c engine!!\n");
1480 goto res_create_fail;
1482 pool->base.sw_i2cs[i] = dce60_i2c_sw_create(ctx);
1483 if (pool->base.sw_i2cs[i] == NULL) {
1484 BREAK_TO_DEBUGGER();
1486 "DC:failed to create sw i2c!!\n");
1487 goto res_create_fail;
1491 dc->caps.max_planes = pool->base.pipe_count;
1493 for (i = 0; i < dc->caps.max_planes; ++i)
1494 dc->caps.planes[i] = plane_cap;
1496 dc->caps.disable_dp_clk_share = true;
1498 if (!resource_construct(num_virtual_links, dc, &pool->base,
1500 goto res_create_fail;
1502 /* Create hardware sequencer */
1503 dce60_hw_sequencer_construct(dc);
1508 dce60_resource_destruct(pool);
1512 struct resource_pool *dce64_create_resource_pool(
1513 uint8_t num_virtual_links,
1516 struct dce110_resource_pool *pool =
1517 kzalloc(sizeof(struct dce110_resource_pool), GFP_KERNEL);
1522 if (dce64_construct(num_virtual_links, dc, pool))
1525 BREAK_TO_DEBUGGER();