Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2021 Advanced Micro Devices, Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  *
0022  * Authors: AMD
0023  *
0024  */
0025 
0026 #include "reg_helper.h"
0027 #include "core_types.h"
0028 #include "dc_dmub_srv.h"
0029 #include "dcn31_panel_cntl.h"
0030 #include "atom.h"
0031 
0032 #define TO_DCN31_PANEL_CNTL(panel_cntl)\
0033     container_of(panel_cntl, struct dcn31_panel_cntl, base)
0034 
0035 #define CTX \
0036     dcn31_panel_cntl->base.ctx
0037 
0038 #define DC_LOGGER \
0039     dcn31_panel_cntl->base.ctx->logger
0040 
0041 static bool dcn31_query_backlight_info(struct panel_cntl *panel_cntl, union dmub_rb_cmd *cmd)
0042 {
0043     struct dcn31_panel_cntl *dcn31_panel_cntl = TO_DCN31_PANEL_CNTL(panel_cntl);
0044     struct dc_dmub_srv *dc_dmub_srv = panel_cntl->ctx->dmub_srv;
0045 
0046     if (!dc_dmub_srv)
0047         return false;
0048 
0049     memset(cmd, 0, sizeof(*cmd));
0050     cmd->panel_cntl.header.type = DMUB_CMD__PANEL_CNTL;
0051     cmd->panel_cntl.header.sub_type = DMUB_CMD__PANEL_CNTL_QUERY_BACKLIGHT_INFO;
0052     cmd->panel_cntl.header.payload_bytes = sizeof(cmd->panel_cntl.data);
0053     cmd->panel_cntl.data.inst = dcn31_panel_cntl->base.inst;
0054 
0055     return dc_dmub_srv_cmd_with_reply_data(dc_dmub_srv, cmd);
0056 }
0057 
0058 static uint32_t dcn31_get_16_bit_backlight_from_pwm(struct panel_cntl *panel_cntl)
0059 {
0060     union dmub_rb_cmd cmd;
0061 
0062     if (!dcn31_query_backlight_info(panel_cntl, &cmd))
0063         return 0;
0064 
0065     return cmd.panel_cntl.data.current_backlight;
0066 }
0067 
0068 static uint32_t dcn31_panel_cntl_hw_init(struct panel_cntl *panel_cntl)
0069 {
0070     struct dcn31_panel_cntl *dcn31_panel_cntl = TO_DCN31_PANEL_CNTL(panel_cntl);
0071     struct dc_dmub_srv *dc_dmub_srv = panel_cntl->ctx->dmub_srv;
0072     union dmub_rb_cmd cmd;
0073 
0074     if (!dc_dmub_srv)
0075         return 0;
0076 
0077     memset(&cmd, 0, sizeof(cmd));
0078     cmd.panel_cntl.header.type = DMUB_CMD__PANEL_CNTL;
0079     cmd.panel_cntl.header.sub_type = DMUB_CMD__PANEL_CNTL_HW_INIT;
0080     cmd.panel_cntl.header.payload_bytes = sizeof(cmd.panel_cntl.data);
0081     cmd.panel_cntl.data.inst = dcn31_panel_cntl->base.inst;
0082     cmd.panel_cntl.data.bl_pwm_cntl = panel_cntl->stored_backlight_registers.BL_PWM_CNTL;
0083     cmd.panel_cntl.data.bl_pwm_period_cntl = panel_cntl->stored_backlight_registers.BL_PWM_PERIOD_CNTL;
0084     cmd.panel_cntl.data.bl_pwm_ref_div1 =
0085         panel_cntl->stored_backlight_registers.LVTMA_PWRSEQ_REF_DIV_BL_PWM_REF_DIV;
0086     cmd.panel_cntl.data.bl_pwm_ref_div2 =
0087         panel_cntl->stored_backlight_registers.PANEL_PWRSEQ_REF_DIV2;
0088     if (!dc_dmub_srv_cmd_with_reply_data(dc_dmub_srv, &cmd))
0089         return 0;
0090 
0091     panel_cntl->stored_backlight_registers.BL_PWM_CNTL = cmd.panel_cntl.data.bl_pwm_cntl;
0092     panel_cntl->stored_backlight_registers.BL_PWM_CNTL2 = 0; /* unused */
0093     panel_cntl->stored_backlight_registers.BL_PWM_PERIOD_CNTL = cmd.panel_cntl.data.bl_pwm_period_cntl;
0094     panel_cntl->stored_backlight_registers.LVTMA_PWRSEQ_REF_DIV_BL_PWM_REF_DIV =
0095         cmd.panel_cntl.data.bl_pwm_ref_div1;
0096     panel_cntl->stored_backlight_registers.PANEL_PWRSEQ_REF_DIV2 =
0097         cmd.panel_cntl.data.bl_pwm_ref_div2;
0098 
0099     return cmd.panel_cntl.data.current_backlight;
0100 }
0101 
0102 static void dcn31_panel_cntl_destroy(struct panel_cntl **panel_cntl)
0103 {
0104     struct dcn31_panel_cntl *dcn31_panel_cntl = TO_DCN31_PANEL_CNTL(*panel_cntl);
0105 
0106     kfree(dcn31_panel_cntl);
0107     *panel_cntl = NULL;
0108 }
0109 
0110 static bool dcn31_is_panel_backlight_on(struct panel_cntl *panel_cntl)
0111 {
0112     union dmub_rb_cmd cmd;
0113 
0114     if (!dcn31_query_backlight_info(panel_cntl, &cmd))
0115         return false;
0116 
0117     return cmd.panel_cntl.data.is_backlight_on;
0118 }
0119 
0120 static bool dcn31_is_panel_powered_on(struct panel_cntl *panel_cntl)
0121 {
0122     union dmub_rb_cmd cmd;
0123 
0124     if (!dcn31_query_backlight_info(panel_cntl, &cmd))
0125         return false;
0126 
0127     return cmd.panel_cntl.data.is_powered_on;
0128 }
0129 
0130 static void dcn31_store_backlight_level(struct panel_cntl *panel_cntl)
0131 {
0132     union dmub_rb_cmd cmd;
0133 
0134     if (!dcn31_query_backlight_info(panel_cntl, &cmd))
0135         return;
0136 
0137     panel_cntl->stored_backlight_registers.BL_PWM_CNTL = cmd.panel_cntl.data.bl_pwm_cntl;
0138     panel_cntl->stored_backlight_registers.BL_PWM_CNTL2 = 0; /* unused */
0139     panel_cntl->stored_backlight_registers.BL_PWM_PERIOD_CNTL = cmd.panel_cntl.data.bl_pwm_period_cntl;
0140     panel_cntl->stored_backlight_registers.LVTMA_PWRSEQ_REF_DIV_BL_PWM_REF_DIV =
0141         cmd.panel_cntl.data.bl_pwm_ref_div1;
0142 }
0143 
0144 static const struct panel_cntl_funcs dcn31_link_panel_cntl_funcs = {
0145     .destroy = dcn31_panel_cntl_destroy,
0146     .hw_init = dcn31_panel_cntl_hw_init,
0147     .is_panel_backlight_on = dcn31_is_panel_backlight_on,
0148     .is_panel_powered_on = dcn31_is_panel_powered_on,
0149     .store_backlight_level = dcn31_store_backlight_level,
0150     .get_current_backlight = dcn31_get_16_bit_backlight_from_pwm,
0151 };
0152 
0153 void dcn31_panel_cntl_construct(
0154     struct dcn31_panel_cntl *dcn31_panel_cntl,
0155     const struct panel_cntl_init_data *init_data)
0156 {
0157     dcn31_panel_cntl->base.funcs = &dcn31_link_panel_cntl_funcs;
0158     dcn31_panel_cntl->base.ctx = init_data->ctx;
0159     dcn31_panel_cntl->base.inst = init_data->inst;
0160 }