drm/amd/pp: Add a helper to set field in u32
authorRex Zhu <Rex.Zhu@amd.com>
Fri, 23 Feb 2018 08:32:55 +0000 (16:32 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 5 Mar 2018 20:39:36 +0000 (15:39 -0500)
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Rex Zhu <Rex.Zhu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c
drivers/gpu/drm/amd/powerplay/inc/hwmgr.h

index 2c7bb05..aea1076 100644 (file)
@@ -64,6 +64,22 @@ uint16_t convert_to_vddc(uint8_t vid)
        return (uint16_t) ((6200 - (vid * 25)) / VOLTAGE_SCALE);
 }
 
+uint32_t phm_set_field_to_u32(u32 offset, u32 original_data, u32 field, u32 size)
+{
+       u32 mask = 0;
+       u32 shift = 0;
+
+       shift = (offset % 4) << 3;
+       if (size == sizeof(uint8_t))
+               mask = 0xFF << shift;
+       else if (size == sizeof(uint16_t))
+               mask = 0xFFFF << shift;
+
+       original_data &= ~mask;
+       original_data |= (field << shift);
+       return original_data;
+}
+
 static int phm_thermal_l2h_irq(void *private_data,
                 unsigned src_id, const uint32_t *iv_entry)
 {
index ae73956..2dc2e2c 100644 (file)
@@ -829,6 +829,8 @@ extern int rv_init_function_pointers(struct pp_hwmgr *hwmgr);
 extern int phm_get_voltage_evv_on_sclk(struct pp_hwmgr *hwmgr, uint8_t voltage_type,
                                uint32_t sclk, uint16_t id, uint16_t *voltage);
 
+extern uint32_t phm_set_field_to_u32(u32 offset, u32 original_data, u32 field, u32 size);
+
 #define PHM_ENTIRE_REGISTER_MASK 0xFFFFFFFFU
 
 #define PHM_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT