2 * Copyright 2021 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 "reg_helper.h"
27 #include "core_types.h"
28 #include "dc_dmub_srv.h"
29 #include "dcn31_panel_cntl.h"
32 #define TO_DCN31_PANEL_CNTL(panel_cntl)\
33 container_of(panel_cntl, struct dcn31_panel_cntl, base)
36 dcn31_panel_cntl->base.ctx
39 dcn31_panel_cntl->base.ctx->logger
41 static bool dcn31_query_backlight_info(struct panel_cntl *panel_cntl, union dmub_rb_cmd *cmd)
43 struct dcn31_panel_cntl *dcn31_panel_cntl = TO_DCN31_PANEL_CNTL(panel_cntl);
44 struct dc_dmub_srv *dc_dmub_srv = panel_cntl->ctx->dmub_srv;
49 memset(cmd, 0, sizeof(*cmd));
50 cmd->panel_cntl.header.type = DMUB_CMD__PANEL_CNTL;
51 cmd->panel_cntl.header.sub_type = DMUB_CMD__PANEL_CNTL_QUERY_BACKLIGHT_INFO;
52 cmd->panel_cntl.header.payload_bytes = sizeof(cmd->panel_cntl.data);
53 cmd->panel_cntl.data.inst = dcn31_panel_cntl->base.inst;
55 return dc_dmub_srv_cmd_with_reply_data(dc_dmub_srv, cmd);
58 static uint32_t dcn31_get_16_bit_backlight_from_pwm(struct panel_cntl *panel_cntl)
60 union dmub_rb_cmd cmd;
62 if (!dcn31_query_backlight_info(panel_cntl, &cmd))
65 return cmd.panel_cntl.data.current_backlight;
68 uint32_t dcn31_panel_cntl_hw_init(struct panel_cntl *panel_cntl)
70 struct dcn31_panel_cntl *dcn31_panel_cntl = TO_DCN31_PANEL_CNTL(panel_cntl);
71 struct dc_dmub_srv *dc_dmub_srv = panel_cntl->ctx->dmub_srv;
72 union dmub_rb_cmd cmd;
77 memset(&cmd, 0, sizeof(cmd));
78 cmd.panel_cntl.header.type = DMUB_CMD__PANEL_CNTL;
79 cmd.panel_cntl.header.sub_type = DMUB_CMD__PANEL_CNTL_HW_INIT;
80 cmd.panel_cntl.header.payload_bytes = sizeof(cmd.panel_cntl.data);
81 cmd.panel_cntl.data.inst = dcn31_panel_cntl->base.inst;
82 cmd.panel_cntl.data.bl_pwm_cntl = panel_cntl->stored_backlight_registers.BL_PWM_CNTL;
83 cmd.panel_cntl.data.bl_pwm_period_cntl = panel_cntl->stored_backlight_registers.BL_PWM_PERIOD_CNTL;
84 cmd.panel_cntl.data.bl_pwm_ref_div1 =
85 panel_cntl->stored_backlight_registers.LVTMA_PWRSEQ_REF_DIV_BL_PWM_REF_DIV;
87 if (!dc_dmub_srv_cmd_with_reply_data(dc_dmub_srv, &cmd))
90 panel_cntl->stored_backlight_registers.BL_PWM_CNTL = cmd.panel_cntl.data.bl_pwm_cntl;
91 panel_cntl->stored_backlight_registers.BL_PWM_CNTL2 = 0; /* unused */
92 panel_cntl->stored_backlight_registers.BL_PWM_PERIOD_CNTL = cmd.panel_cntl.data.bl_pwm_period_cntl;
93 panel_cntl->stored_backlight_registers.LVTMA_PWRSEQ_REF_DIV_BL_PWM_REF_DIV =
94 cmd.panel_cntl.data.bl_pwm_ref_div1;
96 return cmd.panel_cntl.data.current_backlight;
99 void dcn31_panel_cntl_destroy(struct panel_cntl **panel_cntl)
101 struct dcn31_panel_cntl *dcn31_panel_cntl = TO_DCN31_PANEL_CNTL(*panel_cntl);
103 kfree(dcn31_panel_cntl);
107 bool dcn31_is_panel_backlight_on(struct panel_cntl *panel_cntl)
109 union dmub_rb_cmd cmd;
111 if (!dcn31_query_backlight_info(panel_cntl, &cmd))
114 return cmd.panel_cntl.data.is_backlight_on;
117 bool dcn31_is_panel_powered_on(struct panel_cntl *panel_cntl)
119 union dmub_rb_cmd cmd;
121 if (!dcn31_query_backlight_info(panel_cntl, &cmd))
124 return cmd.panel_cntl.data.is_powered_on;
127 void dcn31_store_backlight_level(struct panel_cntl *panel_cntl)
129 union dmub_rb_cmd cmd;
131 if (!dcn31_query_backlight_info(panel_cntl, &cmd))
134 panel_cntl->stored_backlight_registers.BL_PWM_CNTL = cmd.panel_cntl.data.bl_pwm_cntl;
135 panel_cntl->stored_backlight_registers.BL_PWM_CNTL2 = 0; /* unused */
136 panel_cntl->stored_backlight_registers.BL_PWM_PERIOD_CNTL = cmd.panel_cntl.data.bl_pwm_period_cntl;
137 panel_cntl->stored_backlight_registers.LVTMA_PWRSEQ_REF_DIV_BL_PWM_REF_DIV =
138 cmd.panel_cntl.data.bl_pwm_ref_div1;
141 static const struct panel_cntl_funcs dcn31_link_panel_cntl_funcs = {
142 .destroy = dcn31_panel_cntl_destroy,
143 .hw_init = dcn31_panel_cntl_hw_init,
144 .is_panel_backlight_on = dcn31_is_panel_backlight_on,
145 .is_panel_powered_on = dcn31_is_panel_powered_on,
146 .store_backlight_level = dcn31_store_backlight_level,
147 .get_current_backlight = dcn31_get_16_bit_backlight_from_pwm,
150 void dcn31_panel_cntl_construct(
151 struct dcn31_panel_cntl *dcn31_panel_cntl,
152 const struct panel_cntl_init_data *init_data)
154 dcn31_panel_cntl->base.funcs = &dcn31_link_panel_cntl_funcs;
155 dcn31_panel_cntl->base.ctx = init_data->ctx;
156 dcn31_panel_cntl->base.inst = init_data->inst;