12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378
#include "dm_services.h"
#include "dc.h"
#include "mod_power.h"
#include "core_types.h"
#include "dmcu.h"
#include "abm.h"
#include "power_helpers.h"
#include "dce/dmub_psr.h"
#include "dal_asic_id.h"
#include "link_service.h"
#include <linux/math.h>
#define DC_TRACE_LEVEL_MESSAGE(...) /* do nothing */
#define DC_TRACE_LEVEL_MESSAGEP(...) /* do nothing */
#define DIV_ROUNDUP(a, b) (((a)+((b)/2))/(b))
#define bswap16_based_on_endian(big_endian, value) \
((big_endian) ? cpu_to_be16(value) : cpu_to_le16(value))
static const unsigned char min_reduction_table[13] = {
0xff, 0xfa, 0xf0, 0xf0, 0xd9, 0xcd, 0xc0, 0xb1, 0x99, 0x93, 0x80, 0x82, 0x66};
static const unsigned char max_reduction_table[13] = {
0xf5, 0xe5, 0xd9, 0xcd, 0xb1, 0xa5, 0xa5, 0x80, 0x65, 0x4d, 0x4d, 0x4d, 0x32};
static const unsigned char min_reduction_table_v_2_2[13] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xeb, 0xd4, 0xc0, 0xc0};
static const unsigned char max_reduction_table_v_2_2[13] = {
0xf5, 0xe5, 0xbf, 0xb1, 0xa5, 0x85, 0x7c, 0x65, 0x4d, 0x40, 0x32, 0x20, 0x20};
static const unsigned char abm_config[abm_defines_max_config][abm_defines_max_level] = {
{ 2, 5, 7, 8 },
{ 2, 5, 8, 11 },
{ 0, 2, 4, 8 },
{ 3, 6, 10, 12 },
};
struct abm_parameters {
unsigned char min_reduction;
unsigned char max_reduction;
unsigned char bright_pos_gain;
unsigned char dark_pos_gain;
unsigned char brightness_gain;
unsigned char contrast_factor;
unsigned char deviation_gain;
unsigned char min_knee;
unsigned char max_knee;
unsigned short blRampReduction;
unsigned short blRampStart;
};
static const struct abm_parameters abm_settings_config0[abm_defines_max_level] = {
{0xff, 0xbf, 0x20, 0x00, 0xff, 0x99, 0xb3, 0x40, 0xe0, 0xf777, 0xcccc},
{0xde, 0x85, 0x20, 0x00, 0xe0, 0x90, 0xa8, 0x40, 0xc8, 0xf777, 0xcccc},
{0xb0, 0x50, 0x20, 0x00, 0xc0, 0x88, 0x78, 0x70, 0xa0, 0xeeee, 0x9999},
{0x82, 0x40, 0x20, 0x00, 0x00, 0xb8, 0xb3, 0x70, 0x70, 0xe333, 0xb333},
};
static const struct abm_parameters abm_settings_config1[abm_defines_max_level] = {
{0xf0, 0xd9, 0x20, 0x00, 0x00, 0xff, 0xb3, 0x70, 0x70, 0xcccc, 0xcccc},
{0xcd, 0xa5, 0x20, 0x00, 0x00, 0xff, 0xb3, 0x70, 0x70, 0xcccc, 0xcccc},
{0x99, 0x65, 0x20, 0x00, 0x00, 0xff, 0xb3, 0x70, 0x70, 0xcccc, 0xcccc},
{0x82, 0x4d, 0x20, 0x00, 0x00, 0xff, 0xb3, 0x70, 0x70, 0xcccc, 0xcccc},
};
static const struct abm_parameters abm_settings_config2[abm_defines_max_level] = {
{0xf0, 0xbf, 0x20, 0x00, 0x88, 0x99, 0xb3, 0x40, 0xe0, 0x0000, 0xcccc},
{0xd8, 0x85, 0x20, 0x00, 0x70, 0x90, 0xa8, 0x40, 0xc8, 0x0700, 0xb333},
{0xb8, 0x58, 0x20, 0x00, 0x64, 0x88, 0x78, 0x70, 0xa0, 0x7000, 0x9999},
{0x82, 0x40, 0x20, 0x00, 0x00, 0xb8, 0xb3, 0x70, 0x70, 0xc333, 0xb333},
};
static const struct abm_parameters * const abm_settings[] = {
abm_settings_config0,
abm_settings_config1,
abm_settings_config2,
};
static const struct dm_bl_data_point custom_backlight_curve0[] = {
{2, 14}, {4, 16}, {6, 18}, {8, 21}, {10, 23}, {12, 26}, {14, 29}, {16, 32}, {18, 35},
{20, 38}, {22, 41}, {24, 44}, {26, 48}, {28, 52}, {30, 55}, {32, 59}, {34, 62},
{36, 67}, {38, 71}, {40, 75}, {42, 80}, {44, 84}, {46, 88}, {48, 93}, {50, 98},
{52, 103}, {54, 108}, {56, 113}, {58, 118}, {60, 123}, {62, 129}, {64, 135}, {66, 140},
{68, 146}, {70, 152}, {72, 158}, {74, 164}, {76, 171}, {78, 177}, {80, 183}, {82, 190},
{84, 197}, {86, 204}, {88, 211}, {90, 218}, {92, 225}, {94, 232}, {96, 240}, {98, 247}};
struct custom_backlight_profile {
uint8_t ac_level_percentage;
uint8_t dc_level_percentage;
uint8_t min_input_signal;
uint8_t max_input_signal;
uint8_t num_data_points;
const struct dm_bl_data_point *data_points;
};
static const struct custom_backlight_profile custom_backlight_profiles[] = {
{100, 32, 12, 255, ARRAY_SIZE(custom_backlight_curve0), custom_backlight_curve0},
};
#define NUM_AMBI_LEVEL 5
#define NUM_AGGR_LEVEL 4
#define NUM_POWER_FN_SEGS 8
#define NUM_BL_CURVE_SEGS 16
#define IRAM_SIZE 256
#define IRAM_RESERVE_AREA_START_V2 0xF0 // reserve 0xF0~0xF6 are write by DMCU only
#define IRAM_RESERVE_AREA_END_V2 0xF6 // reserve 0xF0~0xF6 are write by DMCU only
#define IRAM_RESERVE_AREA_START_V2_2 0xF0 // reserve 0xF0~0xFF are write by DMCU only
#define IRAM_RESERVE_AREA_END_V2_2 0xFF // reserve 0xF0~0xFF are write by DMCU only
#pragma pack(push, 1)
struct iram_table_v_2 {
uint16_t min_abm_backlight;
uint8_t min_reduction[NUM_AMBI_LEVEL][NUM_AGGR_LEVEL];
uint8_t max_reduction[NUM_AMBI_LEVEL][NUM_AGGR_LEVEL];
uint8_t bright_pos_gain[NUM_AMBI_LEVEL][NUM_AGGR_LEVEL];
uint8_t bright_neg_gain[NUM_AMBI_LEVEL][NUM_AGGR_LEVEL];
uint8_t dark_pos_gain[NUM_AMBI_LEVEL][NUM_AGGR_LEVEL];
uint8_t dark_neg_gain[NUM_AMBI_LEVEL][NUM_AGGR_LEVEL];
uint8_t iir_curve[NUM_AMBI_LEVEL];
uint8_t deviation_gain;
uint16_t crgb_thresh[NUM_POWER_FN_SEGS];
uint16_t crgb_offset[NUM_POWER_FN_SEGS];
uint16_t crgb_slope[NUM_POWER_FN_SEGS];
uint16_t backlight_thresholds[NUM_BL_CURVE_SEGS];
uint16_t backlight_offsets[NUM_BL_CURVE_SEGS];
uint8_t psr_state;
uint8_t dmcu_mcp_interface_version;
uint8_t dmcu_abm_feature_version;
uint8_t dmcu_psr_feature_version;
uint16_t dmcu_version;
uint8_t dmcu_state;
uint16_t blRampReduction;
uint16_t blRampStart;
uint8_t dummy5;
uint8_t dummy6;
uint8_t dummy7;
uint8_t dummy8;
uint8_t dummy9;
};
struct iram_table_v_2_2 {
uint16_t flags;
uint8_t min_reduction[NUM_AMBI_LEVEL][NUM_AGGR_LEVEL];
uint8_t max_reduction[NUM_AMBI_LEVEL][NUM_AGGR_LEVEL];
uint8_t bright_pos_gain[NUM_AMBI_LEVEL][NUM_AGGR_LEVEL];
uint8_t dark_pos_gain[NUM_AMBI_LEVEL][NUM_AGGR_LEVEL];
uint8_t hybrid_factor[NUM_AGGR_LEVEL];
uint8_t contrast_factor[NUM_AGGR_LEVEL];
uint8_t deviation_gain[NUM_AGGR_LEVEL];
uint8_t iir_curve[NUM_AMBI_LEVEL];
uint8_t min_knee[NUM_AGGR_LEVEL];
uint8_t max_knee[NUM_AGGR_LEVEL];
uint16_t min_abm_backlight;
uint8_t pad[19];
uint16_t crgb_thresh[NUM_POWER_FN_SEGS];
uint16_t crgb_offset[NUM_POWER_FN_SEGS];
uint16_t crgb_slope[NUM_POWER_FN_SEGS];
uint16_t backlight_thresholds[NUM_BL_CURVE_SEGS];
uint16_t backlight_offsets[NUM_BL_CURVE_SEGS];
uint8_t psr_state;
uint8_t dmcu_mcp_interface_version;
uint8_t dmcu_abm_feature_version;
uint8_t dmcu_psr_feature_version;
uint16_t dmcu_version;
uint8_t dmcu_state;
uint8_t dummy1;
uint8_t dummy2;
uint8_t dummy3;
uint8_t dummy4;
uint8_t dummy5;
uint8_t dummy6;
uint8_t dummy7;
uint8_t dummy8;
uint8_t dummy9;
};
#pragma pack(pop)
#define MOD_POWER_MAX_CONCURRENT_STREAMS 32
#define SMOOTH_BRIGHTNESS_ADJUSTMENT_TIME_IN_MS 500
#define MOD_POWER_TO_CORE(mod_power)\
container_of(mod_power, struct core_power, mod_public)
#define BACKLIGHT_MILLIPERCENT_MAX (100 * 1000)
static uint16_t backlight_8_to_16(unsigned int backlight_8bit)
{
return (uint16_t)(backlight_8bit * 0x101);
}
void mod_power_set_backlight_control_type(struct core_power *core_power,
unsigned int inst, enum backlight_control_type backlight_control_type)
{
if (core_power == NULL)
return;
core_power->bl_prop[inst].backlight_control_type = backlight_control_type;
}
static bool is_vesa_abc(struct core_power *core_power, unsigned int inst)
{
if (core_power == NULL)
return false;
return core_power->bl_prop[inst].backlight_control_type ==
BACKLIGHT_CONTROL_VESA_AUX;
}
static unsigned int backlight_millipercent_to_millinit_legacy(
struct core_power *core_power, unsigned int millipercent, unsigned int inst)
{
if (core_power == NULL)
return 0;
return (unsigned int)div_u64((unsigned long long)millipercent *
core_power->bl_prop[inst].nits_range,
100000) +
core_power->bl_prop[inst].min_brightness_millinits;
}
unsigned int backlight_millipercent_to_millinit(
struct core_power *core_power, unsigned int millipercent, unsigned int inst)
{
if (!is_vesa_abc(core_power, inst))
return backlight_millipercent_to_millinit_legacy(core_power, millipercent, inst);
if (core_power == NULL)
return 0;
if (millipercent >= BACKLIGHT_MILLIPERCENT_MAX)
return core_power->bl_prop[inst].max_brightness_millinits;
return (unsigned int)div_u64((unsigned long long)millipercent *
core_power->bl_prop[inst].max_brightness_millinits,
BACKLIGHT_MILLIPERCENT_MAX);
}
static unsigned int backlight_millinit_to_millipercent_legacy(
struct core_power *core_power, unsigned int millinit, unsigned int inst)
{
unsigned int millipercent = 0;
unsigned long long numerator = 0;
if (core_power == NULL)
return 0;
if (millinit <= core_power->bl_prop[inst].min_brightness_millinits)
return 0;
if (millinit >= core_power->bl_prop[inst].max_brightness_millinits)
return BACKLIGHT_MILLIPERCENT_MAX;
numerator = (((unsigned long long)millinit) -
core_power->bl_prop[inst].min_brightness_millinits) * 100000;
millipercent = ((unsigned int)div_u64(numerator,
core_power->bl_prop[inst].nits_range));
return millipercent;
}
static unsigned int backlight_millinit_to_millipercent(
struct core_power *core_power, unsigned int millinit, unsigned int inst)
{
if (!is_vesa_abc(core_power, inst))
return backlight_millinit_to_millipercent_legacy(core_power, millinit, inst);
if (core_power == NULL)
return 0;
if (core_power->bl_prop[inst].max_brightness_millinits == 0)
return 0;
if (millinit >= core_power->bl_prop[inst].max_brightness_millinits)
return BACKLIGHT_MILLIPERCENT_MAX;
return (unsigned int)div_u64((unsigned long long)millinit * 100000,
core_power->bl_prop[inst].max_brightness_millinits);
}
static unsigned int backlight_pwm_to_millipercent_legacy(
struct core_power *core_power, unsigned int pwm, unsigned int inst)
{
unsigned int millipercent = 0;
unsigned int max_index = 0;
if (core_power == NULL)
return 0;
if (!core_power->bl_prop[inst].backlight_caps_valid)
return 0;
if (core_power->bl_prop[inst].num_backlight_levels < 2)
return 0;
max_index = core_power->bl_prop[inst].num_backlight_levels - 1;
if (pwm <= core_power->bl_prop[inst].backlight_lut[0])
return 0;
if (pwm > core_power->bl_prop[inst].backlight_lut[max_index])
return (100 * 1000);
unsigned int min = 0;
unsigned int max = max_index;
unsigned int mid = 0;
while (max >= min) {
mid = (min + max) / 2;
if (core_power->bl_prop[inst].backlight_lut[mid] < pwm)
min = mid + 1;
else if (core_power->bl_prop[inst].backlight_lut[mid] > pwm)
max = mid - 1;
else
break;
}
if (max < min) {
unsigned int min_delta;
unsigned int mid_delta;
unsigned int max_delta;
min_delta = (core_power->bl_prop[inst].backlight_lut[min] > pwm) ?
core_power->bl_prop[inst].backlight_lut[min] - pwm :
pwm - core_power->bl_prop[inst].backlight_lut[min];
mid_delta = (core_power->bl_prop[inst].backlight_lut[mid] > pwm) ?
core_power->bl_prop[inst].backlight_lut[mid] - pwm :
pwm - core_power->bl_prop[inst].backlight_lut[mid];
max_delta = (core_power->bl_prop[inst].backlight_lut[max] > pwm) ?
core_power->bl_prop[inst].backlight_lut[max] - pwm :
pwm - core_power->bl_prop[inst].backlight_lut[max];
if ((min_delta < mid_delta) && (min_delta < max_delta))
mid = min;
if ((max_delta < mid_delta) && (max_delta < min_delta))
mid = max;
}
millipercent = BACKLIGHT_MILLIPERCENT_MAX * mid / max_index;
return millipercent;
}
static unsigned int backlight_pwm_to_millipercent(
struct core_power *core_power, unsigned int pwm, unsigned int inst)
{
if (!is_vesa_abc(core_power, inst))
return backlight_pwm_to_millipercent_legacy(core_power, pwm, inst);
if (core_power == NULL)
return 0;
if (core_power->bl_prop[inst].max_backlight_pwm == 0)
return 0;
if (pwm >= core_power->bl_prop[inst].max_backlight_pwm)
return BACKLIGHT_MILLIPERCENT_MAX;
return (unsigned int)div_u64((unsigned long long)pwm *
BACKLIGHT_MILLIPERCENT_MAX,
core_power->bl_prop[inst].max_backlight_pwm);
}
static unsigned int backlight_pwm_to_millinit_legacy(
struct core_power *core_power, unsigned int pwm, unsigned int inst)
{
unsigned int millinit = 0;
if (core_power == NULL)
return 0;
if (pwm <= core_power->bl_prop[inst].min_backlight_pwm)
return core_power->bl_prop[inst].min_brightness_millinits;
if (pwm >= core_power->bl_prop[inst].max_backlight_pwm)
return core_power->bl_prop[inst].max_brightness_millinits;
millinit = ((unsigned int)div_u64(((unsigned long long)pwm -
core_power->bl_prop[inst].min_backlight_pwm) *
core_power->bl_prop[inst].nits_range,
core_power->bl_prop[inst].backlight_range));
millinit += core_power->bl_prop[inst].min_brightness_millinits;
if (millinit > core_power->bl_prop[inst].max_brightness_millinits)
millinit = core_power->bl_prop[inst].max_brightness_millinits;
return millinit;
}
static unsigned int backlight_pwm_to_millinit(
struct core_power *core_power, unsigned int pwm, unsigned int inst)
{
if (!is_vesa_abc(core_power, inst))
return backlight_pwm_to_millinit_legacy(core_power, pwm, inst);
if (core_power == NULL)
return 0;
if (core_power->bl_prop[inst].max_backlight_pwm == 0)
return 0;
if (pwm >= core_power->bl_prop[inst].max_backlight_pwm)
return core_power->bl_prop[inst].max_brightness_millinits;
return (unsigned int)div_u64((unsigned long long)pwm *
core_power->bl_prop[inst].max_brightness_millinits,
core_power->bl_prop[inst].max_backlight_pwm);
}
static unsigned int backlight_millipercent_to_pwm_legacy(
struct core_power *core_power, unsigned int millipercent, unsigned int inst)
{
unsigned int pwm = (unsigned int)-1;
unsigned int index = 0;
if (core_power == NULL)
return 0;
if (core_power->bl_prop->use_linear_backlight_curve) {
pwm = core_power->bl_prop[inst].min_backlight_pwm +
(unsigned int) div_u64((unsigned long long) millipercent *
core_power->bl_prop[inst].backlight_range,
100000);
if (pwm > core_power->bl_prop[inst].max_backlight_pwm)
pwm = core_power->bl_prop[inst].max_backlight_pwm;
return pwm;
}
if (millipercent >= (100 * 1000))
return core_power->bl_prop[inst].backlight_lut[core_power->bl_prop[inst].num_backlight_levels - 1];
index = ((core_power->bl_prop[inst].num_backlight_levels - 1) *
millipercent) / 100000;
if (core_power->bl_prop[inst].backlight_lut == NULL)
return pwm;
pwm = core_power->bl_prop[inst].backlight_lut[index];
return pwm;
}
unsigned int backlight_millipercent_to_pwm(
struct core_power *core_power, unsigned int millipercent, unsigned int inst)
{
if (!is_vesa_abc(core_power, inst))
return backlight_millipercent_to_pwm_legacy(core_power, millipercent, inst);
if (core_power == NULL)
return 0;
if (millipercent >= BACKLIGHT_MILLIPERCENT_MAX)
return core_power->bl_prop[inst].max_backlight_pwm;
return (unsigned int)div_u64((unsigned long long)millipercent *
core_power->bl_prop[inst].max_backlight_pwm,
BACKLIGHT_MILLIPERCENT_MAX);
}
static unsigned int backlight_millinit_to_pwm_legacy(
struct core_power *core_power, unsigned int millinit, unsigned int inst)
{
unsigned int pwm = 0;
if (core_power == NULL)
return 0;
if (millinit >= core_power->bl_prop[inst].max_brightness_millinits)
return core_power->bl_prop[inst].max_backlight_pwm;
else if (millinit <= core_power->bl_prop[inst].min_brightness_millinits)
return core_power->bl_prop[inst].min_backlight_pwm;
pwm = ((unsigned int)div_u64(((unsigned long long)millinit -
core_power->bl_prop[inst].min_brightness_millinits) *
core_power->bl_prop[inst].backlight_range,
core_power->bl_prop[inst].nits_range));
pwm += core_power->bl_prop[inst].min_backlight_pwm;
if (pwm > core_power->bl_prop[inst].max_backlight_pwm)
pwm = core_power->bl_prop[inst].max_backlight_pwm;
return pwm;
}
static unsigned int backlight_millinit_to_pwm(
struct core_power *core_power, unsigned int millinit, unsigned int inst)
{
if (!is_vesa_abc(core_power, inst))
return backlight_millinit_to_pwm_legacy(core_power, millinit, inst);
if (core_power == NULL)
return 0;
if (core_power->bl_prop[inst].max_brightness_millinits == 0)
return 0;
if (millinit >= core_power->bl_prop[inst].max_brightness_millinits)
return core_power->bl_prop[inst].max_backlight_pwm;
return (unsigned int)div_u64((unsigned long long)millinit *
core_power->bl_prop[inst].max_backlight_pwm,
core_power->bl_prop[inst].max_brightness_millinits);
}
static bool validate_ext_backlight_caps(
struct dm_acpi_atif_backlight_caps *ext_backlight_caps)
{
unsigned int i;
unsigned int num_of_data_points = 0;
unsigned int last_signal_level = 0;
unsigned int last_luminance = 0;
num_of_data_points = ext_backlight_caps->num_data_points;
if (num_of_data_points > BL_DATA_POINTS)
return false;
if (ext_backlight_caps->min_input_signal >= ext_backlight_caps->max_input_signal)
return false;
last_signal_level = ext_backlight_caps->min_input_signal;
for (i = 0; i < num_of_data_points; i++) {
unsigned int luminance = ext_backlight_caps->data_points[i].luminance;
unsigned int signal_level = ext_backlight_caps->data_points[i].signal_level;
if ((luminance <= last_luminance) || (luminance > BL_DATA_POINTS))
return false;
if ((signal_level <= last_signal_level) || (signal_level >= ext_backlight_caps->max_input_signal))
return false;
last_signal_level = signal_level;
last_luminance = luminance;
}
return true;
}
void initialize_backlight_caps(struct core_power *core_power, unsigned int inst)
{
unsigned int i;
struct dm_acpi_atif_backlight_caps *ext_backlight_caps = NULL;
bool custom_curve_present = false;
unsigned int num_levels = 0;
struct dc *dc = NULL;
enum dm_acpi_display_type acpi_display_type =
(inst == 0) ? AcpiDisplayType_LCD1 : AcpiDisplayType_LCD2;
if (core_power == NULL)
return;
dc = core_power->dc;
num_levels = core_power->bl_prop[inst].num_backlight_levels;
ext_backlight_caps = (struct dm_acpi_atif_backlight_caps *)
(kzalloc_obj(struct dm_acpi_atif_backlight_caps));
if (ext_backlight_caps == NULL)
return;
if (dm_query_extended_brightness_caps
(dc->ctx, acpi_display_type, ext_backlight_caps)) {
custom_curve_present = validate_ext_backlight_caps(ext_backlight_caps);
}
if (core_power->bl_prop[inst].use_custom_backlight_caps &&
fill_custom_backlight_caps(
core_power->bl_prop[inst].custom_backlight_caps_config_no,
ext_backlight_caps)) {
custom_curve_present = validate_ext_backlight_caps(ext_backlight_caps);
}
if (custom_curve_present) {
unsigned int index = 1;
unsigned int num_of_data_points = ext_backlight_caps->num_data_points;
core_power->bl_prop[inst].ac_backlight_percent =
ext_backlight_caps->ac_level_percentage;
core_power->bl_prop[inst].dc_backlight_percent =
ext_backlight_caps->dc_level_percentage;
core_power->bl_prop[inst].backlight_lut[0] =
backlight_8_to_16(
ext_backlight_caps->min_input_signal);
core_power->bl_prop[inst].backlight_lut[num_levels - 1] =
backlight_8_to_16(
ext_backlight_caps->max_input_signal);
for (i = 0; i < num_of_data_points; i++) {
unsigned int luminance =
ext_backlight_caps->data_points[i].luminance;
unsigned int signal_level =
backlight_8_to_16(
ext_backlight_caps->data_points[i].signal_level);
luminance = (luminance * num_levels) / 101;
if (index < luminance) {
unsigned int base_value =
core_power->bl_prop[inst].backlight_lut[index-1];
unsigned int delta_signal =
signal_level - base_value;
unsigned int delta_luma =
luminance - index + 1;
unsigned int step = delta_signal;
for (; index < luminance; index++) {
core_power->bl_prop[inst].backlight_lut[index] =
base_value + (step / delta_luma);
step += delta_signal;
}
}
core_power->bl_prop[inst].backlight_lut[index++] = signal_level;
}
if (index < num_levels - 1) {
unsigned int base_value =
core_power->bl_prop[inst].backlight_lut[index-1];
unsigned int delta_signal =
core_power->bl_prop[inst].backlight_lut[num_levels - 1] -
base_value;
unsigned int delta_luma = num_levels - index;
unsigned int step = delta_signal;
for (; index < num_levels - 1; index++) {
core_power->bl_prop[inst].backlight_lut[index] =
base_value + (step / delta_luma);
step += delta_signal;
}
}
} else {
unsigned int backlight_curve_coeff_a_factor =
num_levels * num_levels;
unsigned int backlight_curve_coeff_b = num_levels;
unsigned int delta =
core_power->bl_prop[inst].backlight_lut[num_levels - 1] -
core_power->bl_prop[inst].backlight_lut[0];
unsigned int coeffC = core_power->bl_prop[inst].backlight_lut[0];
unsigned int coeffB =
(backlight_curve_coeff_b < delta ?
backlight_curve_coeff_b : delta);
unsigned long long coeffA = delta - coeffB;
for (i = 1; i < num_levels - 1; i++) {
uint64_t lut_val = div_u64(coeffA * i * i, backlight_curve_coeff_a_factor) +
div_u64((uint64_t)coeffB * i, backlight_curve_coeff_b) + coeffC;
ASSERT(lut_val <= 0xFFFFFFFF);
core_power->bl_prop[inst].backlight_lut[i] = (unsigned int)lut_val;
}
}
if (ext_backlight_caps != NULL)
kfree(ext_backlight_caps);
core_power->bl_prop[inst].backlight_caps_valid = true;
}
static void varibright_set_level(struct core_power *core_power)
{
if (!core_power->varibright_prop.varibright_active ||
!core_power->varibright_prop.varibright_user_enable)
core_power->varibright_prop.varibright_hw_level = 0;
else
core_power->varibright_prop.varibright_hw_level =
core_power->varibright_prop.varibright_level;
}
bool mod_power_hw_init_backlight(struct mod_power *mod_power)
{
struct core_power *core_power = NULL;
struct dc *dc = NULL;
struct dmcu *dmcu = NULL;
struct dmcu_iram_parameters params;
unsigned int i;
if (mod_power == NULL)
return false;
core_power = MOD_POWER_TO_CORE(mod_power);
dc = core_power->dc;
for (i = 0; i < core_power->edp_num; i++) {
params.set = core_power->varibright_prop.varibright_config_setting;
params.backlight_ramping_override = core_power->bl_prop[i].backlight_ramping_override;
params.backlight_ramping_reduction = core_power->bl_prop[i].backlight_ramping_reduction;
params.backlight_ramping_start = core_power->bl_prop[i].backlight_ramping_start;
params.backlight_lut_array = core_power->bl_prop[i].backlight_lut;
params.backlight_lut_array_size = core_power->bl_prop[i].num_backlight_levels;
params.min_abm_backlight = core_power->bl_prop[i].min_abm_backlight;
dmcu = dc->res_pool->dmcu;
if (dmcu) {
return dmcu_load_iram(dmcu, params);
} else if (dc->ctx->dmub_srv) {
if (!dmub_init_abm_config(dc->res_pool, params, i))
return false;
} else
return false;
}
return true;
}
void mod_power_update_backlight_on_mode_change(
struct core_power *core_power,
struct dc_link *link,
unsigned int panel_inst,
uint8_t aux_inst,
bool is_hdr)
{
struct set_backlight_level_params backlight_level_params = { 0 };
mod_power_set_backlight_control_type(core_power, panel_inst,
link->backlight_control_type);
if ((link->dpcd_sink_ext_caps.bits.hdr_aux_backlight_control == 1 ||
link->dpcd_sink_ext_caps.bits.sdr_aux_backlight_control == 1) &&
link->backlight_control_type == BACKLIGHT_CONTROL_AMD_AUX)
dc_link_set_backlight_level_nits(link, core_power->bl_state[panel_inst].isHDR,
core_power->bl_state[panel_inst].backlight_millinit, 0);
backlight_level_params.frame_ramp = 0;
fill_backlight_level_params(core_power, &backlight_level_params, panel_inst, aux_inst,
core_power->bl_state[panel_inst].backlight_pwm, link->backlight_control_type,
core_power->bl_state[panel_inst].backlight_millinit, 0, is_hdr);
dc_link_set_backlight_level(link, &backlight_level_params);
}
static bool set_backlight_millinits_aux(struct core_power *core_power,
struct dc_stream_state *stream,
unsigned int backlight_millinits,
unsigned int transition_time_millisec,
unsigned int inst)
{
struct dc_link *link = NULL;
if (core_power == NULL)
return false;
if (stream == NULL)
return true;
link = dc_stream_get_link(stream);
if (link->backlight_control_type == BACKLIGHT_CONTROL_VESA_AUX &&
link->dc->caps.dmub_caps.aux_backlight_support)
return true;
return dc_link_set_backlight_level_nits(link, core_power->bl_state[inst].isHDR,
backlight_millinits, transition_time_millisec);
}
static bool set_backlight(struct core_power *core_power,
struct dc_stream_state *stream,
struct set_backlight_level_params *backlight_level_params,
unsigned int inst)
{
bool retv = false;
unsigned int frame_ramp = 0;
unsigned int vsync_rate_hz;
union dmcu_abm_set_bl_params params;
const struct dc_link *link = NULL;
unsigned int backlight_pwm_u16_16 = backlight_level_params->backlight_pwm_u16_16;
unsigned int transition_time_millisec = backlight_level_params->transition_time_in_ms;
if (core_power == NULL)
return false;
core_power->bl_state[inst].backlight_pwm = backlight_pwm_u16_16;
if (stream == NULL)
return true;
if (stream->link->connector_signal != SIGNAL_TYPE_EDP)
return false;
if (transition_time_millisec != 0) {
unsigned int v_total =
(stream->adjust.v_total_max == 0) ? stream->timing.v_total : stream->adjust.v_total_max;
vsync_rate_hz = (unsigned int)div_u64(div_u64((stream->
timing.pix_clk_100hz * 100),
v_total),
stream->timing.h_total);
if (core_power->bl_state[inst].smooth_brightness_enabled)
frame_ramp = ((vsync_rate_hz *
transition_time_millisec) + 500) / 1000;
}
core_power->bl_state[inst].frame_ramp = frame_ramp;
params.u32All = 0;
params.bits.gradual_change = (frame_ramp > 0);
params.bits.frame_ramp = frame_ramp;
link = dc_stream_get_link(stream);
mod_power_set_psr_event(&core_power->mod_public, stream, true, psr_event_hw_programming, true);
mod_power_set_replay_event(&core_power->mod_public, stream, true, replay_event_hw_programming, true);
backlight_level_params->frame_ramp = params.u32All;
retv = dc_link_set_backlight_level(link, backlight_level_params);
mod_power_set_psr_event(&core_power->mod_public, stream, false, psr_event_hw_programming, false);
mod_power_set_replay_event(&core_power->mod_public, stream, false, replay_event_hw_programming, false);
return retv;
}
void fill_backlight_level_params(struct core_power *core_power,
struct set_backlight_level_params *backlight_level_params,
int panel_inst, uint8_t aux_inst, unsigned int backlight_pwm,
enum backlight_control_type backlight_control_type,
unsigned int backlight_millinit, unsigned int transition_time_millisec,
bool is_hdr)
{
struct pwr_backlight_properties *bl_prop = &core_power->bl_prop[panel_inst];
backlight_level_params->aux_inst = aux_inst;
backlight_level_params->backlight_pwm_u16_16 = backlight_pwm;
backlight_level_params->control_type = backlight_control_type;
backlight_level_params->backlight_millinits = backlight_millinit;
backlight_level_params->transition_time_in_ms = transition_time_millisec;
backlight_level_params->min_luminance = bl_prop->min_brightness_millinits;
backlight_level_params->max_luminance = bl_prop->max_brightness_millinits;
backlight_level_params->min_backlight_pwm = bl_prop->min_backlight_pwm;
backlight_level_params->max_backlight_pwm = bl_prop->max_backlight_pwm;
if (backlight_control_type == BACKLIGHT_CONTROL_AMD_AUX && !is_hdr)
backlight_level_params->control_type = BACKLIGHT_CONTROL_PWM;
}
bool mod_power_set_backlight_nits(struct mod_power *mod_power,
struct dc_stream_state *stream,
unsigned int backlight_millinit,
unsigned int transition_time_millisec,
bool skip_aux,
bool is_hdr)
{
struct core_power *core_power = NULL;
unsigned int backlight_pwm;
unsigned int panel_inst = 0;
struct set_backlight_level_params backlight_level_params = { 0 };
const struct dc_link *link = NULL;
uint8_t aux_inst = 0;
if (mod_power == NULL)
return false;
core_power = MOD_POWER_TO_CORE(mod_power);
link = dc_stream_get_link(stream);
aux_inst = link->dc->link_srv->get_ddc_aux_inst(link);
if (!dc_get_edp_link_panel_inst(core_power->dc, stream->link, &panel_inst))
return false;
if (!skip_aux) {
if (!set_backlight_millinits_aux(core_power, stream,
backlight_millinit, transition_time_millisec, panel_inst))
return false;
}
core_power->bl_state[panel_inst].backlight_millinit = backlight_millinit;
core_power->bl_state[panel_inst].backlight_millipercent =
backlight_millinit_to_millipercent(
core_power, backlight_millinit, panel_inst);
backlight_pwm = backlight_millinit_to_pwm(
core_power, backlight_millinit, panel_inst);
fill_backlight_level_params(core_power, &backlight_level_params, panel_inst, aux_inst, backlight_pwm,
link->backlight_control_type, backlight_millinit, transition_time_millisec, is_hdr);
return set_backlight(core_power, stream,
&backlight_level_params, panel_inst);
}
bool mod_power_backlight_percent_to_nits(struct mod_power *mod_power,
struct dc_stream_state *stream,
unsigned int backlight_millipercent,
unsigned int *backlight_millinit)
{
struct core_power *core_power = NULL;
unsigned int inst = 0;
if (mod_power == NULL)
return false;
core_power = MOD_POWER_TO_CORE(mod_power);
if (!dc_get_edp_link_panel_inst(core_power->dc, stream->link, &inst))
return false;
*backlight_millinit = backlight_millipercent_to_millinit(
core_power, backlight_millipercent, inst);
return true;
}
bool mod_power_backlight_nits_to_percent(struct mod_power *mod_power,
struct dc_stream_state *stream,
unsigned int backlight_millinit,
unsigned int *backlight_millipercent)
{
struct core_power *core_power = NULL;
unsigned int inst = 0;
if (mod_power == NULL)
return false;
core_power = MOD_POWER_TO_CORE(mod_power);
if (!dc_get_edp_link_panel_inst(core_power->dc, stream->link, &inst))
return false;
*backlight_millipercent = backlight_millinit_to_millipercent(
core_power, backlight_millinit, inst);
return true;
}
bool mod_power_set_backlight_percent(struct mod_power *mod_power,
struct dc_stream_state *stream,
unsigned int backlight_millipercent,
unsigned int transition_time_millisec,
bool is_hdr)
{
struct core_power *core_power = NULL;
struct set_backlight_level_params backlight_level_params = { 0 };
const struct dc_link *link = NULL;
unsigned int backlight_pwm;
unsigned int panel_inst = 0;
uint8_t aux_inst = 0;
if (mod_power == NULL)
return false;
core_power = MOD_POWER_TO_CORE(mod_power);
link = dc_stream_get_link(stream);
aux_inst = link->dc->link_srv->get_ddc_aux_inst(link);
if (!dc_get_edp_link_panel_inst(core_power->dc, stream->link, &panel_inst))
return false;
core_power->bl_state[panel_inst].backlight_millipercent = backlight_millipercent;
core_power->bl_state[panel_inst].backlight_millinit =
backlight_millipercent_to_millinit(
core_power, backlight_millipercent, panel_inst);
backlight_pwm = backlight_millipercent_to_pwm(
core_power, backlight_millipercent, panel_inst);
fill_backlight_level_params(core_power, &backlight_level_params, panel_inst,
aux_inst, backlight_pwm, link->backlight_control_type,
core_power->bl_state[panel_inst].backlight_millinit, transition_time_millisec, is_hdr);
return set_backlight(core_power, stream,
&backlight_level_params, panel_inst);
}
void mod_power_update_backlight(struct mod_power *mod_power,
struct dc_stream_state *stream,
unsigned int backlight_millipercent)
{
struct core_power *core_power = NULL;
unsigned int inst = 0;
if (mod_power == NULL)
return;
core_power = MOD_POWER_TO_CORE(mod_power);
if (!dc_get_edp_link_panel_inst(core_power->dc, stream->link, &inst))
return;
core_power->bl_state[inst].backlight_millipercent = backlight_millipercent;
core_power->bl_state[inst].backlight_millinit =
backlight_millipercent_to_millinit(
core_power, backlight_millipercent, inst);
core_power->bl_state[inst].backlight_pwm = backlight_millipercent_to_pwm(
core_power, backlight_millipercent, inst);
}
void mod_power_update_backlight_nits(struct mod_power *mod_power,
struct dc_stream_state *stream,
unsigned int backlight_millinit)
{
struct core_power *core_power = NULL;
unsigned int inst = 0;
if (mod_power == NULL)
return;
core_power = MOD_POWER_TO_CORE(mod_power);
if (!dc_get_edp_link_panel_inst(core_power->dc, stream->link, &inst))
return;
core_power->bl_state[inst].backlight_millinit = backlight_millinit;
core_power->bl_state[inst].backlight_millipercent = backlight_millinit_to_millipercent(
core_power, backlight_millinit, inst);
core_power->bl_state[inst].backlight_pwm = backlight_millinit_to_pwm(
core_power, backlight_millinit, inst);
}
bool mod_power_get_backlight_pwm(struct mod_power *mod_power,
unsigned int *backlight_pwm,
unsigned int inst)
{
struct core_power *core_power = NULL;
if (mod_power == NULL)
return false;
core_power = MOD_POWER_TO_CORE(mod_power);
*backlight_pwm = core_power->bl_state[inst].backlight_pwm;
return true;
}
bool mod_power_get_backlight_nits(struct mod_power *mod_power,
unsigned int *backlight_millinit,
unsigned int inst)
{
struct core_power *core_power = NULL;
if (mod_power == NULL)
return false;
core_power = MOD_POWER_TO_CORE(mod_power);
*backlight_millinit = core_power->bl_state[inst].backlight_millinit;
return true;
}
bool mod_power_get_backlight_percent(struct mod_power *mod_power,
unsigned int *backlight_millipercent,
unsigned int inst)
{
struct core_power *core_power = NULL;
if (mod_power == NULL)
return false;
core_power = MOD_POWER_TO_CORE(mod_power);
*backlight_millipercent = core_power->bl_state[inst].backlight_millipercent;
return true;
}
bool mod_power_get_hw_target_backlight_pwm_nits(struct mod_power *mod_power,
const struct dc_link *link,
unsigned int *backlight_millinit,
unsigned int inst)
{
struct core_power *core_power = NULL;
unsigned int backlight_u16_16 = 0;
if (mod_power == NULL)
return false;
core_power = MOD_POWER_TO_CORE(mod_power);
if (mod_power_get_hw_target_backlight_pwm(mod_power, link,
&backlight_u16_16)) {
*backlight_millinit =
backlight_pwm_to_millinit(core_power,
backlight_u16_16, inst);
return true;
}
return false;
}
bool mod_power_get_hw_target_backlight_pwm_percent(struct mod_power *mod_power,
const struct dc_link *link,
unsigned int *backlight_millipercent,
unsigned int inst)
{
struct core_power *core_power = NULL;
unsigned int backlight_u16_16 = 0;
if (mod_power == NULL)
return false;
core_power = MOD_POWER_TO_CORE(mod_power);
if (mod_power_get_hw_target_backlight_pwm(mod_power, link,
&backlight_u16_16)) {
*backlight_millipercent =
backlight_pwm_to_millipercent(core_power,
backlight_u16_16, inst);
return true;
}
return false;
}
bool mod_power_get_hw_target_backlight_pwm(struct mod_power *mod_power,
const struct dc_link *link,
unsigned int *backlight_u16_16)
{
if (mod_power == NULL)
return false;
*backlight_u16_16 = dc_link_get_target_backlight_pwm(link);
return true;
}
bool mod_power_get_hw_backlight_pwm_nits(struct mod_power *mod_power,
const struct dc_link *link,
unsigned int *backlight_millinit,
unsigned int inst)
{
struct core_power *core_power = NULL;
unsigned int backlight_u16_16 = 0;
if (mod_power == NULL)
return false;
core_power = MOD_POWER_TO_CORE(mod_power);
if (mod_power_get_hw_backlight_pwm(mod_power, link, &backlight_u16_16)) {
*backlight_millinit =
backlight_pwm_to_millinit(core_power,
backlight_u16_16, inst);
return true;
}
return false;
}
bool mod_power_get_hw_backlight_aux_nits(struct mod_power *mod_power,
struct dc_stream_state **streams, int num_streams,
unsigned int *backlight_millinit_avg,
unsigned int *backlight_millinit_peak)
{
struct core_power *core_power = NULL;
struct dc_link *link = NULL;
int stream_index;
if (mod_power == NULL)
return false;
core_power = MOD_POWER_TO_CORE(mod_power);
if (core_power == NULL)
return false;
if (num_streams < 1)
return true;
for (stream_index = 0; stream_index < num_streams; stream_index++)
if (streams[stream_index]->link->connector_signal == SIGNAL_TYPE_EDP ||
streams[stream_index]->link->connector_signal == SIGNAL_TYPE_DISPLAY_PORT)
break;
if (stream_index == num_streams)
return false;
link = dc_stream_get_link(streams[stream_index]);
if (link->dpcd_sink_ext_caps.bits.hdr_aux_backlight_control == 0)
return false;
return dc_link_get_backlight_level_nits(link, backlight_millinit_avg,
backlight_millinit_peak);
}
bool mod_power_get_hw_backlight_pwm_percent(struct mod_power *mod_power,
const struct dc_link *link,
unsigned int *backlight_millipercent,
unsigned int inst)
{
struct core_power *core_power = NULL;
unsigned int backlight_u16_16 = 0;
if (mod_power == NULL)
return false;
core_power = MOD_POWER_TO_CORE(mod_power);
if (mod_power_get_hw_backlight_pwm(mod_power, link, &backlight_u16_16)) {
*backlight_millipercent =
backlight_pwm_to_millipercent(core_power,
backlight_u16_16, inst);
return true;
}
return false;
}
bool mod_power_get_hw_backlight_pwm(struct mod_power *mod_power,
const struct dc_link *link,
unsigned int *backlight_u16_16)
{
if (mod_power == NULL)
return false;
*backlight_u16_16 = dc_link_get_backlight_level(link);
return true;
}
bool mod_power_get_panel_backlight_boundaries(
struct mod_power *mod_power,
unsigned int *out_min_backlight,
unsigned int *out_max_backlight,
unsigned int *out_ac_backlight_percent,
unsigned int *out_dc_backlight_percent,
unsigned int inst)
{
struct core_power *core_power = NULL;
if (mod_power == NULL)
return false;
core_power = MOD_POWER_TO_CORE(mod_power);
if (core_power->bl_prop[inst].backlight_caps_valid) {
*out_min_backlight = core_power->bl_prop[inst].backlight_lut[0];
*out_max_backlight =
core_power->bl_prop[inst].backlight_lut[
core_power->bl_prop[inst].num_backlight_levels - 1];
*out_ac_backlight_percent =
core_power->bl_prop[inst].ac_backlight_percent;
*out_dc_backlight_percent =
core_power->bl_prop[inst].dc_backlight_percent;
return true;
}
return false;
}
bool mod_power_set_smooth_brightness(struct mod_power *mod_power,
bool enable_brightness,
unsigned int inst)
{
struct core_power *core_power = NULL;
if (mod_power == NULL)
return false;
core_power = MOD_POWER_TO_CORE(mod_power);
core_power->bl_state[inst].smooth_brightness_enabled = enable_brightness;
return true;
}
bool mod_power_varibright_feature_enable(struct mod_power *mod_power, bool enable,
struct dc_stream_update *stream_update)
{
struct core_power *core_power = NULL;
if (mod_power == NULL)
return false;
core_power = MOD_POWER_TO_CORE(mod_power);
core_power->varibright_prop.varibright_user_enable = enable;
varibright_set_level(core_power);
*stream_update->abm_level = core_power->varibright_prop.varibright_hw_level;
DC_TRACE_LEVEL_MESSAGEP(DAL_TRACE_LEVEL_INFORMATION,
WPP_BIT_FLAG_Backlight_ABM,
">ABM feature enable: enable=%u su->varibright_level=%u varibright_hw_level=%u",
(unsigned int) enable,
*stream_update->abm_level,
core_power->varibright_prop.varibright_hw_level);
return true;
}
bool mod_power_varibright_activate(struct mod_power *mod_power,
bool activate,
struct dc_stream_update *stream_update)
{
struct core_power *core_power = NULL;
if (mod_power == NULL)
return false;
core_power = MOD_POWER_TO_CORE(mod_power);
core_power->varibright_prop.varibright_active = activate;
varibright_set_level(core_power);
*stream_update->abm_level = core_power->varibright_prop.varibright_hw_level;
DC_TRACE_LEVEL_MESSAGEP(DAL_TRACE_LEVEL_INFORMATION,
WPP_BIT_FLAG_Backlight_ABM,
">ABM activate: activate=%u su->varibright_level=%u",
(unsigned int) activate,
*stream_update->abm_level);
return true;
}
bool mod_power_varibright_set_level(struct mod_power *mod_power, unsigned int level,
struct dc_stream_update *stream_update)
{
struct core_power *core_power = NULL;
if (mod_power == NULL)
return false;
core_power = MOD_POWER_TO_CORE(mod_power);
core_power->varibright_prop.varibright_level = level;
core_power->varibright_prop.varibright_hw_level = level;
varibright_set_level(core_power);
*stream_update->abm_level = core_power->varibright_prop.varibright_hw_level;
DC_TRACE_LEVEL_MESSAGEP(DAL_TRACE_LEVEL_INFORMATION,
WPP_BIT_FLAG_Backlight_ABM,
">ABM set level: level=%u -> (varibright_level=%u varibright_hw_level=%u) -> su->varibright_level=%u",
level,
core_power->varibright_prop.varibright_level,
core_power->varibright_prop.varibright_hw_level,
*stream_update->abm_level);
return true;
}
bool mod_power_varibright_set_hw_level(struct mod_power *mod_power, unsigned int level,
struct dc_stream_update *stream_update)
{
struct core_power *core_power = NULL;
if (mod_power == NULL)
return false;
core_power = MOD_POWER_TO_CORE(mod_power);
if (level == 0 || level == ABM_LEVEL_IMMEDIATE_DISABLE)
core_power->varibright_prop.varibright_active = 0;
else
core_power->varibright_prop.varibright_active = 1;
core_power->varibright_prop.varibright_hw_level = level;
*stream_update->abm_level = core_power->varibright_prop.varibright_hw_level;
DC_TRACE_LEVEL_MESSAGEP(DAL_TRACE_LEVEL_INFORMATION,
WPP_BIT_FLAG_Backlight_ABM,
">ABM set level: level=%u -> (varibright_level=%u varibright_hw_level=%u) -> su->varibright_level=%u",
level,
core_power->varibright_prop.varibright_level,
core_power->varibright_prop.varibright_hw_level,
*stream_update->abm_level);
return true;
}
bool mod_power_get_varibright_level(struct mod_power *mod_power,
unsigned int *varibright_level)
{
struct core_power *core_power = NULL;
if (mod_power == NULL)
return false;
core_power = MOD_POWER_TO_CORE(mod_power);
*varibright_level = core_power->varibright_prop.varibright_level;
DC_TRACE_LEVEL_MESSAGEP(DAL_TRACE_LEVEL_INFORMATION,
WPP_BIT_FLAG_Backlight_ABM,
">get varibright level: cp->varibright_level=%u",
*varibright_level);
return true;
}
bool mod_power_get_varibright_hw_level(struct mod_power *mod_power,
unsigned int *varibright_level)
{
struct core_power *core_power = NULL;
if (mod_power == NULL)
return false;
core_power = MOD_POWER_TO_CORE(mod_power);
*varibright_level = core_power->varibright_prop.varibright_hw_level;
DC_TRACE_LEVEL_MESSAGEP(DAL_TRACE_LEVEL_INFORMATION,
WPP_BIT_FLAG_Backlight_ABM,
">get varibright HW level: hw_level=%u",
*varibright_level);
return true;
}
bool mod_power_get_varibright_default_level(struct mod_power *mod_power,
unsigned int *varibright_level)
{
struct core_power *core_power = NULL;
if (mod_power == NULL)
return false;
core_power = MOD_POWER_TO_CORE(mod_power);
*varibright_level = core_power->varibright_prop.def_varibright_level;
DC_TRACE_LEVEL_MESSAGEP(DAL_TRACE_LEVEL_INFORMATION,
WPP_BIT_FLAG_Backlight_ABM,
">get varibright default level: def_varibright_level=%u",
*varibright_level);
return true;
}
bool mod_power_get_varibright_enable(struct mod_power *mod_power,
bool *varibright_enable)
{
struct core_power *core_power = NULL;
if (mod_power == NULL)
return false;
core_power = MOD_POWER_TO_CORE(mod_power);
*varibright_enable = core_power->varibright_prop.varibright_user_enable;
DC_TRACE_LEVEL_MESSAGEP(DAL_TRACE_LEVEL_INFORMATION,
WPP_BIT_FLAG_Backlight_ABM,
">get varibright enable state: varibright_user_enable=%u",
(unsigned int) (*varibright_enable));
return true;
}
bool mod_power_is_abm_active(struct mod_power *mod_power,
const struct dc_link *link,
unsigned int inst)
{
unsigned int user_backlight = 0;
unsigned int current_backlight = 0;
bool is_active = false;
if (mod_power == NULL)
return false;
mod_power_get_backlight_pwm(mod_power, &user_backlight, inst);
mod_power_get_hw_backlight_pwm(mod_power, link, ¤t_backlight);
if (user_backlight != current_backlight)
is_active = true;
else
is_active = false;
DC_TRACE_LEVEL_MESSAGEP(DAL_TRACE_LEVEL_INFORMATION,
WPP_BIT_FLAG_Backlight_ABM,
">get ABM active state: is_active=%u (user_backlight_pwm=%u, current_backlight_pwm=%u)",
(unsigned int)is_active,
user_backlight,
current_backlight);
return is_active;
}
bool mod_power_is_abm_supported(struct mod_power *mod_power,
unsigned int inst)
{
struct core_power *core_power = NULL;
struct dc *dc = NULL;
if (mod_power == NULL)
return false;
core_power = MOD_POWER_TO_CORE(mod_power);
dc = core_power->dc;
if (dc->ctx->dmub_srv) {
if (!dmub_is_abm_supported(dc->res_pool, inst))
return false;
} else
return false;
return true;
}
bool mod_power_abm_set_event(struct mod_power *mod_power,
unsigned int full_screen, unsigned int trans_info,
unsigned int hdr_mode, unsigned int scaling_enable,
unsigned int scaling_strength_map, unsigned int inst)
{
struct core_power *core_power = NULL;
struct dc *dc = NULL;
if (mod_power == NULL)
return false;
core_power = MOD_POWER_TO_CORE(mod_power);
dc = core_power->dc;
if (dc->ctx->dmub_srv) {
if (!dmub_set_abm_event(dc->res_pool, full_screen, trans_info,
hdr_mode, scaling_enable, scaling_strength_map, inst))
return false;
} else
return false;
return true;
}
bool mod_power_abm_set_strength(struct mod_power *mod_power,
unsigned int strength,
unsigned int inst)
{
struct core_power *core_power = NULL;
struct dc *dc = NULL;
if (mod_power == NULL)
return false;
core_power = MOD_POWER_TO_CORE(mod_power);
dc = core_power->dc;
if (dc->ctx->dmub_srv) {
if (!dmub_set_abm_strength(dc->res_pool, strength, inst))
return false;
} else
return false;
return true;
}
static void fill_backlight_transform_table(struct dmcu_iram_parameters params,
struct iram_table_v_2 *table)
{
unsigned int i;
unsigned int num_entries = NUM_BL_CURVE_SEGS;
unsigned int lut_index;
table->backlight_thresholds[0] = 0;
ASSERT(params.backlight_lut_array[0] <= 0xFFFF);
table->backlight_offsets[0] = (uint16_t)params.backlight_lut_array[0];
table->backlight_thresholds[num_entries-1] = 0xFFFF;
ASSERT(params.backlight_lut_array[params.backlight_lut_array_size - 1] <= 0xFFFF);
table->backlight_offsets[num_entries-1] =
(uint16_t)params.backlight_lut_array[params.backlight_lut_array_size - 1];
for (i = 1; i+1 < num_entries; i++) {
lut_index = (params.backlight_lut_array_size - 1) * i / (num_entries - 1);
ASSERT(lut_index < params.backlight_lut_array_size);
unsigned int threshold_val = DIV_ROUNDUP((i * 65536), num_entries);
unsigned int offset_val = params.backlight_lut_array[lut_index];
ASSERT(threshold_val <= 0xFFFF);
ASSERT(offset_val <= 0xFFFF);
table->backlight_thresholds[i] = cpu_to_be16((uint16_t)threshold_val);
table->backlight_offsets[i] = cpu_to_be16((uint16_t)offset_val);
}
}
static void fill_backlight_transform_table_v_2_2(struct dmcu_iram_parameters params,
struct iram_table_v_2_2 *table, bool big_endian)
{
unsigned int i;
unsigned int num_entries = NUM_BL_CURVE_SEGS;
unsigned int lut_index;
table->backlight_thresholds[0] = 0;
ASSERT(params.backlight_lut_array[0] <= 0xFFFF);
table->backlight_offsets[0] = (uint16_t)params.backlight_lut_array[0];
table->backlight_thresholds[num_entries-1] = 0xFFFF;
ASSERT(params.backlight_lut_array[params.backlight_lut_array_size - 1] <= 0xFFFF);
table->backlight_offsets[num_entries-1] =
(uint16_t)params.backlight_lut_array[params.backlight_lut_array_size - 1];
for (i = 1; i+1 < num_entries; i++) {
lut_index = DIV_ROUNDUP((i * params.backlight_lut_array_size), num_entries);
ASSERT(lut_index < params.backlight_lut_array_size);
unsigned int threshold_val = DIV_ROUNDUP((i * 65536), num_entries);
unsigned int offset_val = params.backlight_lut_array[lut_index];
ASSERT(threshold_val <= 0xFFFF);
ASSERT(offset_val <= 0xFFFF);
table->backlight_thresholds[i] = (big_endian) ?
cpu_to_be16((uint16_t)threshold_val) : cpu_to_le16((uint16_t)threshold_val);
table->backlight_offsets[i] = (big_endian) ?
cpu_to_be16((uint16_t)offset_val) : cpu_to_le16((uint16_t)offset_val);
}
}
static void fill_iram_v_2(struct iram_table_v_2 *ram_table, struct dmcu_iram_parameters params)
{
unsigned int set = params.set;
ram_table->min_abm_backlight =
cpu_to_be16(params.min_abm_backlight);
ram_table->deviation_gain = 0xb3;
ram_table->blRampReduction =
cpu_to_be16(params.backlight_ramping_reduction);
ram_table->blRampStart =
cpu_to_be16(params.backlight_ramping_start);
ram_table->min_reduction[0][0] = min_reduction_table[abm_config[set][0]];
ram_table->min_reduction[1][0] = min_reduction_table[abm_config[set][0]];
ram_table->min_reduction[2][0] = min_reduction_table[abm_config[set][0]];
ram_table->min_reduction[3][0] = min_reduction_table[abm_config[set][0]];
ram_table->min_reduction[4][0] = min_reduction_table[abm_config[set][0]];
ram_table->max_reduction[0][0] = max_reduction_table[abm_config[set][0]];
ram_table->max_reduction[1][0] = max_reduction_table[abm_config[set][0]];
ram_table->max_reduction[2][0] = max_reduction_table[abm_config[set][0]];
ram_table->max_reduction[3][0] = max_reduction_table[abm_config[set][0]];
ram_table->max_reduction[4][0] = max_reduction_table[abm_config[set][0]];
ram_table->min_reduction[0][1] = min_reduction_table[abm_config[set][1]];
ram_table->min_reduction[1][1] = min_reduction_table[abm_config[set][1]];
ram_table->min_reduction[2][1] = min_reduction_table[abm_config[set][1]];
ram_table->min_reduction[3][1] = min_reduction_table[abm_config[set][1]];
ram_table->min_reduction[4][1] = min_reduction_table[abm_config[set][1]];
ram_table->max_reduction[0][1] = max_reduction_table[abm_config[set][1]];
ram_table->max_reduction[1][1] = max_reduction_table[abm_config[set][1]];
ram_table->max_reduction[2][1] = max_reduction_table[abm_config[set][1]];
ram_table->max_reduction[3][1] = max_reduction_table[abm_config[set][1]];
ram_table->max_reduction[4][1] = max_reduction_table[abm_config[set][1]];
ram_table->min_reduction[0][2] = min_reduction_table[abm_config[set][2]];
ram_table->min_reduction[1][2] = min_reduction_table[abm_config[set][2]];
ram_table->min_reduction[2][2] = min_reduction_table[abm_config[set][2]];
ram_table->min_reduction[3][2] = min_reduction_table[abm_config[set][2]];
ram_table->min_reduction[4][2] = min_reduction_table[abm_config[set][2]];
ram_table->max_reduction[0][2] = max_reduction_table[abm_config[set][2]];
ram_table->max_reduction[1][2] = max_reduction_table[abm_config[set][2]];
ram_table->max_reduction[2][2] = max_reduction_table[abm_config[set][2]];
ram_table->max_reduction[3][2] = max_reduction_table[abm_config[set][2]];
ram_table->max_reduction[4][2] = max_reduction_table[abm_config[set][2]];
ram_table->min_reduction[0][3] = min_reduction_table[abm_config[set][3]];
ram_table->min_reduction[1][3] = min_reduction_table[abm_config[set][3]];
ram_table->min_reduction[2][3] = min_reduction_table[abm_config[set][3]];
ram_table->min_reduction[3][3] = min_reduction_table[abm_config[set][3]];
ram_table->min_reduction[4][3] = min_reduction_table[abm_config[set][3]];
ram_table->max_reduction[0][3] = max_reduction_table[abm_config[set][3]];
ram_table->max_reduction[1][3] = max_reduction_table[abm_config[set][3]];
ram_table->max_reduction[2][3] = max_reduction_table[abm_config[set][3]];
ram_table->max_reduction[3][3] = max_reduction_table[abm_config[set][3]];
ram_table->max_reduction[4][3] = max_reduction_table[abm_config[set][3]];
ram_table->bright_pos_gain[0][0] = 0x20;
ram_table->bright_pos_gain[0][1] = 0x20;
ram_table->bright_pos_gain[0][2] = 0x20;
ram_table->bright_pos_gain[0][3] = 0x20;
ram_table->bright_pos_gain[1][0] = 0x20;
ram_table->bright_pos_gain[1][1] = 0x20;
ram_table->bright_pos_gain[1][2] = 0x20;
ram_table->bright_pos_gain[1][3] = 0x20;
ram_table->bright_pos_gain[2][0] = 0x20;
ram_table->bright_pos_gain[2][1] = 0x20;
ram_table->bright_pos_gain[2][2] = 0x20;
ram_table->bright_pos_gain[2][3] = 0x20;
ram_table->bright_pos_gain[3][0] = 0x20;
ram_table->bright_pos_gain[3][1] = 0x20;
ram_table->bright_pos_gain[3][2] = 0x20;
ram_table->bright_pos_gain[3][3] = 0x20;
ram_table->bright_pos_gain[4][0] = 0x20;
ram_table->bright_pos_gain[4][1] = 0x20;
ram_table->bright_pos_gain[4][2] = 0x20;
ram_table->bright_pos_gain[4][3] = 0x20;
ram_table->bright_neg_gain[0][0] = 0x00;
ram_table->bright_neg_gain[0][1] = 0x00;
ram_table->bright_neg_gain[0][2] = 0x00;
ram_table->bright_neg_gain[0][3] = 0x00;
ram_table->bright_neg_gain[1][0] = 0x00;
ram_table->bright_neg_gain[1][1] = 0x00;
ram_table->bright_neg_gain[1][2] = 0x00;
ram_table->bright_neg_gain[1][3] = 0x00;
ram_table->bright_neg_gain[2][0] = 0x00;
ram_table->bright_neg_gain[2][1] = 0x00;
ram_table->bright_neg_gain[2][2] = 0x00;
ram_table->bright_neg_gain[2][3] = 0x00;
ram_table->bright_neg_gain[3][0] = 0x00;
ram_table->bright_neg_gain[3][1] = 0x00;
ram_table->bright_neg_gain[3][2] = 0x00;
ram_table->bright_neg_gain[3][3] = 0x00;
ram_table->bright_neg_gain[4][0] = 0x00;
ram_table->bright_neg_gain[4][1] = 0x00;
ram_table->bright_neg_gain[4][2] = 0x00;
ram_table->bright_neg_gain[4][3] = 0x00;
ram_table->dark_pos_gain[0][0] = 0x00;
ram_table->dark_pos_gain[0][1] = 0x00;
ram_table->dark_pos_gain[0][2] = 0x00;
ram_table->dark_pos_gain[0][3] = 0x00;
ram_table->dark_pos_gain[1][0] = 0x00;
ram_table->dark_pos_gain[1][1] = 0x00;
ram_table->dark_pos_gain[1][2] = 0x00;
ram_table->dark_pos_gain[1][3] = 0x00;
ram_table->dark_pos_gain[2][0] = 0x00;
ram_table->dark_pos_gain[2][1] = 0x00;
ram_table->dark_pos_gain[2][2] = 0x00;
ram_table->dark_pos_gain[2][3] = 0x00;
ram_table->dark_pos_gain[3][0] = 0x00;
ram_table->dark_pos_gain[3][1] = 0x00;
ram_table->dark_pos_gain[3][2] = 0x00;
ram_table->dark_pos_gain[3][3] = 0x00;
ram_table->dark_pos_gain[4][0] = 0x00;
ram_table->dark_pos_gain[4][1] = 0x00;
ram_table->dark_pos_gain[4][2] = 0x00;
ram_table->dark_pos_gain[4][3] = 0x00;
ram_table->dark_neg_gain[0][0] = 0x00;
ram_table->dark_neg_gain[0][1] = 0x00;
ram_table->dark_neg_gain[0][2] = 0x00;
ram_table->dark_neg_gain[0][3] = 0x00;
ram_table->dark_neg_gain[1][0] = 0x00;
ram_table->dark_neg_gain[1][1] = 0x00;
ram_table->dark_neg_gain[1][2] = 0x00;
ram_table->dark_neg_gain[1][3] = 0x00;
ram_table->dark_neg_gain[2][0] = 0x00;
ram_table->dark_neg_gain[2][1] = 0x00;
ram_table->dark_neg_gain[2][2] = 0x00;
ram_table->dark_neg_gain[2][3] = 0x00;
ram_table->dark_neg_gain[3][0] = 0x00;
ram_table->dark_neg_gain[3][1] = 0x00;
ram_table->dark_neg_gain[3][2] = 0x00;
ram_table->dark_neg_gain[3][3] = 0x00;
ram_table->dark_neg_gain[4][0] = 0x00;
ram_table->dark_neg_gain[4][1] = 0x00;
ram_table->dark_neg_gain[4][2] = 0x00;
ram_table->dark_neg_gain[4][3] = 0x00;
ram_table->iir_curve[0] = 0x65;
ram_table->iir_curve[1] = 0x65;
ram_table->iir_curve[2] = 0x65;
ram_table->iir_curve[3] = 0x65;
ram_table->iir_curve[4] = 0x65;
ram_table->crgb_thresh[0] = cpu_to_be16(0x13b6);
ram_table->crgb_thresh[1] = cpu_to_be16(0x1648);
ram_table->crgb_thresh[2] = cpu_to_be16(0x18e3);
ram_table->crgb_thresh[3] = cpu_to_be16(0x1b41);
ram_table->crgb_thresh[4] = cpu_to_be16(0x1d46);
ram_table->crgb_thresh[5] = cpu_to_be16(0x1f21);
ram_table->crgb_thresh[6] = cpu_to_be16(0x2167);
ram_table->crgb_thresh[7] = cpu_to_be16(0x2384);
ram_table->crgb_offset[0] = cpu_to_be16(0x2999);
ram_table->crgb_offset[1] = cpu_to_be16(0x3999);
ram_table->crgb_offset[2] = cpu_to_be16(0x4666);
ram_table->crgb_offset[3] = cpu_to_be16(0x5999);
ram_table->crgb_offset[4] = cpu_to_be16(0x6333);
ram_table->crgb_offset[5] = cpu_to_be16(0x7800);
ram_table->crgb_offset[6] = cpu_to_be16(0x8c00);
ram_table->crgb_offset[7] = cpu_to_be16(0xa000);
ram_table->crgb_slope[0] = cpu_to_be16(0x3147);
ram_table->crgb_slope[1] = cpu_to_be16(0x2978);
ram_table->crgb_slope[2] = cpu_to_be16(0x23a2);
ram_table->crgb_slope[3] = cpu_to_be16(0x1f55);
ram_table->crgb_slope[4] = cpu_to_be16(0x1c63);
ram_table->crgb_slope[5] = cpu_to_be16(0x1a0f);
ram_table->crgb_slope[6] = cpu_to_be16(0x178d);
ram_table->crgb_slope[7] = cpu_to_be16(0x15ab);
fill_backlight_transform_table(
params, ram_table);
}
static void fill_iram_v_2_2(struct iram_table_v_2_2 *ram_table, struct dmcu_iram_parameters params)
{
unsigned int set = params.set;
ram_table->flags = 0x0;
ram_table->min_abm_backlight =
cpu_to_be16(params.min_abm_backlight);
ram_table->deviation_gain[0] = 0xb3;
ram_table->deviation_gain[1] = 0xa8;
ram_table->deviation_gain[2] = 0x98;
ram_table->deviation_gain[3] = 0x68;
ram_table->min_reduction[0][0] = min_reduction_table_v_2_2[abm_config[set][0]];
ram_table->min_reduction[1][0] = min_reduction_table_v_2_2[abm_config[set][0]];
ram_table->min_reduction[2][0] = min_reduction_table_v_2_2[abm_config[set][0]];
ram_table->min_reduction[3][0] = min_reduction_table_v_2_2[abm_config[set][0]];
ram_table->min_reduction[4][0] = min_reduction_table_v_2_2[abm_config[set][0]];
ram_table->max_reduction[0][0] = max_reduction_table_v_2_2[abm_config[set][0]];
ram_table->max_reduction[1][0] = max_reduction_table_v_2_2[abm_config[set][0]];
ram_table->max_reduction[2][0] = max_reduction_table_v_2_2[abm_config[set][0]];
ram_table->max_reduction[3][0] = max_reduction_table_v_2_2[abm_config[set][0]];
ram_table->max_reduction[4][0] = max_reduction_table_v_2_2[abm_config[set][0]];
ram_table->min_reduction[0][1] = min_reduction_table_v_2_2[abm_config[set][1]];
ram_table->min_reduction[1][1] = min_reduction_table_v_2_2[abm_config[set][1]];
ram_table->min_reduction[2][1] = min_reduction_table_v_2_2[abm_config[set][1]];
ram_table->min_reduction[3][1] = min_reduction_table_v_2_2[abm_config[set][1]];
ram_table->min_reduction[4][1] = min_reduction_table_v_2_2[abm_config[set][1]];
ram_table->max_reduction[0][1] = max_reduction_table_v_2_2[abm_config[set][1]];
ram_table->max_reduction[1][1] = max_reduction_table_v_2_2[abm_config[set][1]];
ram_table->max_reduction[2][1] = max_reduction_table_v_2_2[abm_config[set][1]];
ram_table->max_reduction[3][1] = max_reduction_table_v_2_2[abm_config[set][1]];
ram_table->max_reduction[4][1] = max_reduction_table_v_2_2[abm_config[set][1]];
ram_table->min_reduction[0][2] = min_reduction_table_v_2_2[abm_config[set][2]];
ram_table->min_reduction[1][2] = min_reduction_table_v_2_2[abm_config[set][2]];
ram_table->min_reduction[2][2] = min_reduction_table_v_2_2[abm_config[set][2]];
ram_table->min_reduction[3][2] = min_reduction_table_v_2_2[abm_config[set][2]];
ram_table->min_reduction[4][2] = min_reduction_table_v_2_2[abm_config[set][2]];
ram_table->max_reduction[0][2] = max_reduction_table_v_2_2[abm_config[set][2]];
ram_table->max_reduction[1][2] = max_reduction_table_v_2_2[abm_config[set][2]];
ram_table->max_reduction[2][2] = max_reduction_table_v_2_2[abm_config[set][2]];
ram_table->max_reduction[3][2] = max_reduction_table_v_2_2[abm_config[set][2]];
ram_table->max_reduction[4][2] = max_reduction_table_v_2_2[abm_config[set][2]];
ram_table->min_reduction[0][3] = min_reduction_table_v_2_2[abm_config[set][3]];
ram_table->min_reduction[1][3] = min_reduction_table_v_2_2[abm_config[set][3]];
ram_table->min_reduction[2][3] = min_reduction_table_v_2_2[abm_config[set][3]];
ram_table->min_reduction[3][3] = min_reduction_table_v_2_2[abm_config[set][3]];
ram_table->min_reduction[4][3] = min_reduction_table_v_2_2[abm_config[set][3]];
ram_table->max_reduction[0][3] = max_reduction_table_v_2_2[abm_config[set][3]];
ram_table->max_reduction[1][3] = max_reduction_table_v_2_2[abm_config[set][3]];
ram_table->max_reduction[2][3] = max_reduction_table_v_2_2[abm_config[set][3]];
ram_table->max_reduction[3][3] = max_reduction_table_v_2_2[abm_config[set][3]];
ram_table->max_reduction[4][3] = max_reduction_table_v_2_2[abm_config[set][3]];
ram_table->bright_pos_gain[0][0] = 0x20;
ram_table->bright_pos_gain[0][1] = 0x20;
ram_table->bright_pos_gain[0][2] = 0x20;
ram_table->bright_pos_gain[0][3] = 0x20;
ram_table->bright_pos_gain[1][0] = 0x20;
ram_table->bright_pos_gain[1][1] = 0x20;
ram_table->bright_pos_gain[1][2] = 0x20;
ram_table->bright_pos_gain[1][3] = 0x20;
ram_table->bright_pos_gain[2][0] = 0x20;
ram_table->bright_pos_gain[2][1] = 0x20;
ram_table->bright_pos_gain[2][2] = 0x20;
ram_table->bright_pos_gain[2][3] = 0x20;
ram_table->bright_pos_gain[3][0] = 0x20;
ram_table->bright_pos_gain[3][1] = 0x20;
ram_table->bright_pos_gain[3][2] = 0x20;
ram_table->bright_pos_gain[3][3] = 0x20;
ram_table->bright_pos_gain[4][0] = 0x20;
ram_table->bright_pos_gain[4][1] = 0x20;
ram_table->bright_pos_gain[4][2] = 0x20;
ram_table->bright_pos_gain[4][3] = 0x20;
ram_table->dark_pos_gain[0][0] = 0x00;
ram_table->dark_pos_gain[0][1] = 0x00;
ram_table->dark_pos_gain[0][2] = 0x00;
ram_table->dark_pos_gain[0][3] = 0x00;
ram_table->dark_pos_gain[1][0] = 0x00;
ram_table->dark_pos_gain[1][1] = 0x00;
ram_table->dark_pos_gain[1][2] = 0x00;
ram_table->dark_pos_gain[1][3] = 0x00;
ram_table->dark_pos_gain[2][0] = 0x00;
ram_table->dark_pos_gain[2][1] = 0x00;
ram_table->dark_pos_gain[2][2] = 0x00;
ram_table->dark_pos_gain[2][3] = 0x00;
ram_table->dark_pos_gain[3][0] = 0x00;
ram_table->dark_pos_gain[3][1] = 0x00;
ram_table->dark_pos_gain[3][2] = 0x00;
ram_table->dark_pos_gain[3][3] = 0x00;
ram_table->dark_pos_gain[4][0] = 0x00;
ram_table->dark_pos_gain[4][1] = 0x00;
ram_table->dark_pos_gain[4][2] = 0x00;
ram_table->dark_pos_gain[4][3] = 0x00;
ram_table->hybrid_factor[0] = 0xff;
ram_table->hybrid_factor[1] = 0xff;
ram_table->hybrid_factor[2] = 0xff;
ram_table->hybrid_factor[3] = 0xc0;
ram_table->contrast_factor[0] = 0x99;
ram_table->contrast_factor[1] = 0x99;
ram_table->contrast_factor[2] = 0x90;
ram_table->contrast_factor[3] = 0x80;
ram_table->iir_curve[0] = 0x65;
ram_table->iir_curve[1] = 0x65;
ram_table->iir_curve[2] = 0x65;
ram_table->iir_curve[3] = 0x65;
ram_table->iir_curve[4] = 0x65;
ram_table->crgb_thresh[0] = cpu_to_be16(0x127c);
ram_table->crgb_thresh[1] = cpu_to_be16(0x151b);
ram_table->crgb_thresh[2] = cpu_to_be16(0x17d5);
ram_table->crgb_thresh[3] = cpu_to_be16(0x1a56);
ram_table->crgb_thresh[4] = cpu_to_be16(0x1c83);
ram_table->crgb_thresh[5] = cpu_to_be16(0x1e72);
ram_table->crgb_thresh[6] = cpu_to_be16(0x20f0);
ram_table->crgb_thresh[7] = cpu_to_be16(0x232b);
ram_table->crgb_offset[0] = cpu_to_be16(0x2999);
ram_table->crgb_offset[1] = cpu_to_be16(0x3999);
ram_table->crgb_offset[2] = cpu_to_be16(0x4666);
ram_table->crgb_offset[3] = cpu_to_be16(0x5999);
ram_table->crgb_offset[4] = cpu_to_be16(0x6333);
ram_table->crgb_offset[5] = cpu_to_be16(0x7800);
ram_table->crgb_offset[6] = cpu_to_be16(0x8c00);
ram_table->crgb_offset[7] = cpu_to_be16(0xa000);
ram_table->crgb_slope[0] = cpu_to_be16(0x3609);
ram_table->crgb_slope[1] = cpu_to_be16(0x2dfa);
ram_table->crgb_slope[2] = cpu_to_be16(0x27ea);
ram_table->crgb_slope[3] = cpu_to_be16(0x235d);
ram_table->crgb_slope[4] = cpu_to_be16(0x2042);
ram_table->crgb_slope[5] = cpu_to_be16(0x1dc3);
ram_table->crgb_slope[6] = cpu_to_be16(0x1b1a);
ram_table->crgb_slope[7] = cpu_to_be16(0x1910);
fill_backlight_transform_table_v_2_2(
params, ram_table, true);
}
static void fill_iram_v_2_3(struct iram_table_v_2_2 *ram_table, struct dmcu_iram_parameters params, bool big_endian)
{
unsigned int i, j;
unsigned int set = params.set;
ram_table->flags = 0x0;
ram_table->min_abm_backlight = (uint16_t)((big_endian) ?
cpu_to_be16(params.min_abm_backlight) :
cpu_to_le16(params.min_abm_backlight));
for (i = 0; i < NUM_AGGR_LEVEL; i++) {
ram_table->hybrid_factor[i] = (uint8_t)abm_settings[set][i].brightness_gain;
ram_table->contrast_factor[i] = abm_settings[set][i].contrast_factor;
ram_table->deviation_gain[i] = abm_settings[set][i].deviation_gain;
ram_table->min_knee[i] = abm_settings[set][i].min_knee;
ram_table->max_knee[i] = abm_settings[set][i].max_knee;
for (j = 0; j < NUM_AMBI_LEVEL; j++) {
ram_table->min_reduction[j][i] = abm_settings[set][i].min_reduction;
ram_table->max_reduction[j][i] = abm_settings[set][i].max_reduction;
ram_table->bright_pos_gain[j][i] = abm_settings[set][i].bright_pos_gain;
ram_table->dark_pos_gain[j][i] = abm_settings[set][i].dark_pos_gain;
}
}
ram_table->iir_curve[0] = 0x65;
ram_table->iir_curve[1] = 0x65;
ram_table->iir_curve[2] = 0x65;
ram_table->iir_curve[3] = 0x65;
ram_table->iir_curve[4] = 0x65;
ram_table->crgb_thresh[0] = bswap16_based_on_endian(big_endian, 0x127c);
ram_table->crgb_thresh[1] = bswap16_based_on_endian(big_endian, 0x151b);
ram_table->crgb_thresh[2] = bswap16_based_on_endian(big_endian, 0x17d5);
ram_table->crgb_thresh[3] = bswap16_based_on_endian(big_endian, 0x1a56);
ram_table->crgb_thresh[4] = bswap16_based_on_endian(big_endian, 0x1c83);
ram_table->crgb_thresh[5] = bswap16_based_on_endian(big_endian, 0x1e72);
ram_table->crgb_thresh[6] = bswap16_based_on_endian(big_endian, 0x20f0);
ram_table->crgb_thresh[7] = bswap16_based_on_endian(big_endian, 0x232b);
ram_table->crgb_offset[0] = bswap16_based_on_endian(big_endian, 0x2999);
ram_table->crgb_offset[1] = bswap16_based_on_endian(big_endian, 0x3999);
ram_table->crgb_offset[2] = bswap16_based_on_endian(big_endian, 0x4666);
ram_table->crgb_offset[3] = bswap16_based_on_endian(big_endian, 0x5999);
ram_table->crgb_offset[4] = bswap16_based_on_endian(big_endian, 0x6333);
ram_table->crgb_offset[5] = bswap16_based_on_endian(big_endian, 0x7800);
ram_table->crgb_offset[6] = bswap16_based_on_endian(big_endian, 0x8c00);
ram_table->crgb_offset[7] = bswap16_based_on_endian(big_endian, 0xa000);
ram_table->crgb_slope[0] = bswap16_based_on_endian(big_endian, 0x3609);
ram_table->crgb_slope[1] = bswap16_based_on_endian(big_endian, 0x2dfa);
ram_table->crgb_slope[2] = bswap16_based_on_endian(big_endian, 0x27ea);
ram_table->crgb_slope[3] = bswap16_based_on_endian(big_endian, 0x235d);
ram_table->crgb_slope[4] = bswap16_based_on_endian(big_endian, 0x2042);
ram_table->crgb_slope[5] = bswap16_based_on_endian(big_endian, 0x1dc3);
ram_table->crgb_slope[6] = bswap16_based_on_endian(big_endian, 0x1b1a);
ram_table->crgb_slope[7] = bswap16_based_on_endian(big_endian, 0x1910);
fill_backlight_transform_table_v_2_2(
params, ram_table, big_endian);
}
bool dmub_init_abm_config(struct resource_pool *res_pool,
struct dmcu_iram_parameters params,
unsigned int inst)
{
struct iram_table_v_2_2 ram_table;
struct abm_config_table config;
unsigned int set = params.set;
bool result = false;
uint32_t i, j = 0;
if (res_pool->abm == NULL && res_pool->multiple_abms[inst] == NULL)
return false;
memset(&ram_table, 0, sizeof(ram_table));
memset(&config, 0, sizeof(config));
fill_iram_v_2_3(&ram_table, params, false);
for (i = 0; i < NUM_POWER_FN_SEGS; i++) {
config.crgb_thresh[i] = ram_table.crgb_thresh[i];
config.crgb_offset[i] = ram_table.crgb_offset[i];
config.crgb_slope[i] = ram_table.crgb_slope[i];
}
for (i = 0; i < NUM_BL_CURVE_SEGS; i++) {
config.backlight_thresholds[i] = ram_table.backlight_thresholds[i];
config.backlight_offsets[i] = ram_table.backlight_offsets[i];
}
for (i = 0; i < NUM_AMBI_LEVEL; i++)
config.iir_curve[i] = ram_table.iir_curve[i];
for (i = 0; i < NUM_AMBI_LEVEL; i++) {
for (j = 0; j < NUM_AGGR_LEVEL; j++) {
config.min_reduction[i][j] = ram_table.min_reduction[i][j];
config.max_reduction[i][j] = ram_table.max_reduction[i][j];
config.bright_pos_gain[i][j] = ram_table.bright_pos_gain[i][j];
config.dark_pos_gain[i][j] = ram_table.dark_pos_gain[i][j];
}
}
for (i = 0; i < NUM_AGGR_LEVEL; i++) {
config.hybrid_factor[i] = ram_table.hybrid_factor[i];
config.contrast_factor[i] = ram_table.contrast_factor[i];
config.deviation_gain[i] = ram_table.deviation_gain[i];
config.min_knee[i] = ram_table.min_knee[i];
config.max_knee[i] = ram_table.max_knee[i];
}
if (params.backlight_ramping_override) {
ASSERT(params.backlight_ramping_reduction <= 0xFFFF);
ASSERT(params.backlight_ramping_start <= 0xFFFF);
for (i = 0; i < NUM_AGGR_LEVEL; i++) {
config.blRampReduction[i] = (uint16_t)params.backlight_ramping_reduction;
config.blRampStart[i] = (uint16_t)params.backlight_ramping_start;
}
} else {
for (i = 0; i < NUM_AGGR_LEVEL; i++) {
config.blRampReduction[i] = abm_settings[set][i].blRampReduction;
config.blRampStart[i] = abm_settings[set][i].blRampStart;
}
}
config.min_abm_backlight = ram_table.min_abm_backlight;
if (res_pool->multiple_abms[inst]) {
result = res_pool->multiple_abms[inst]->funcs->init_abm_config(
res_pool->multiple_abms[inst], (char *)(&config), sizeof(struct abm_config_table), inst);
} else
result = res_pool->abm->funcs->init_abm_config(
res_pool->abm, (char *)(&config), sizeof(struct abm_config_table), 0);
return result;
}
bool dmub_is_abm_supported(struct resource_pool *res_pool, unsigned int inst)
{
if (res_pool->abm == NULL && res_pool->multiple_abms[inst] == NULL)
return false;
return true;
}
bool dmub_set_abm_event(struct resource_pool *res_pool,
unsigned int full_screen, unsigned int trans_info,
unsigned int hdr_mode, unsigned int scaling_enable, unsigned int scaling_strength_map,
unsigned int inst)
{
bool result = false;
if (res_pool->abm == NULL && res_pool->multiple_abms[inst] == NULL)
return false;
if (res_pool->multiple_abms[inst]) {
if (res_pool->multiple_abms[inst]->funcs->set_abm_event)
result = res_pool->multiple_abms[inst]->funcs->set_abm_event(
res_pool->multiple_abms[inst], full_screen, trans_info,
hdr_mode, scaling_enable, scaling_strength_map, inst);
} else {
if (res_pool->abm->funcs->set_abm_event)
result = res_pool->abm->funcs->set_abm_event(
res_pool->abm, full_screen, trans_info,
hdr_mode, scaling_enable, scaling_strength_map, inst);
}
return result;
}
bool dmub_set_abm_strength(struct resource_pool *res_pool,
unsigned int strength,
unsigned int inst)
{
bool result = false;
if (res_pool->abm == NULL && res_pool->multiple_abms[inst] == NULL)
return false;
if (res_pool->multiple_abms[inst]) {
if (res_pool->multiple_abms[inst]->funcs->set_abm_level)
result = res_pool->multiple_abms[inst]->funcs->set_abm_level(
res_pool->multiple_abms[inst], strength);
} else {
if (res_pool->abm->funcs->set_abm_level)
result = res_pool->abm->funcs->set_abm_level(
res_pool->abm, strength);
}
return result;
}
bool dmcu_load_iram(struct dmcu *dmcu,
struct dmcu_iram_parameters params)
{
unsigned char ram_table[IRAM_SIZE];
bool result = false;
if (dmcu == NULL)
return false;
if (dmcu && !dmcu->funcs->is_dmcu_initialized(dmcu))
return true;
memset(&ram_table, 0, sizeof(ram_table));
if (dmcu->dmcu_version.abm_version == 0x24) {
fill_iram_v_2_3((struct iram_table_v_2_2 *)ram_table, params, true);
result = dmcu->funcs->load_iram(dmcu, 0, (char *)(&ram_table),
IRAM_RESERVE_AREA_START_V2_2);
} else if (dmcu->dmcu_version.abm_version == 0x23) {
fill_iram_v_2_3((struct iram_table_v_2_2 *)ram_table, params, true);
result = dmcu->funcs->load_iram(
dmcu, 0, (char *)(&ram_table), IRAM_RESERVE_AREA_START_V2_2);
} else if (dmcu->dmcu_version.abm_version == 0x22) {
fill_iram_v_2_2((struct iram_table_v_2_2 *)ram_table, params);
result = dmcu->funcs->load_iram(
dmcu, 0, (char *)(&ram_table), IRAM_RESERVE_AREA_START_V2_2);
} else {
fill_iram_v_2((struct iram_table_v_2 *)ram_table, params);
result = dmcu->funcs->load_iram(
dmcu, 0, (char *)(&ram_table), IRAM_RESERVE_AREA_START_V2);
if (result)
result = dmcu->funcs->load_iram(
dmcu, IRAM_RESERVE_AREA_END_V2 + 1,
(char *)(&ram_table) + IRAM_RESERVE_AREA_END_V2 + 1,
sizeof(ram_table) - IRAM_RESERVE_AREA_END_V2 - 1);
}
return result;
}
bool fill_custom_backlight_caps(unsigned int config_no, struct dm_acpi_atif_backlight_caps *caps)
{
unsigned int data_points_size;
uint64_t caps_size;
if (config_no >= ARRAY_SIZE(custom_backlight_profiles))
return false;
data_points_size = custom_backlight_profiles[config_no].num_data_points
* sizeof(custom_backlight_profiles[config_no].data_points[0]);
caps_size = sizeof(struct dm_acpi_atif_backlight_caps) - sizeof(caps->data_points) + data_points_size;
ASSERT(caps_size <= 0xFFFF);
caps->size = (uint16_t)caps_size;
caps->flags = 0;
caps->error_code = 0;
caps->ac_level_percentage = custom_backlight_profiles[config_no].ac_level_percentage;
caps->dc_level_percentage = custom_backlight_profiles[config_no].dc_level_percentage;
caps->min_input_signal = custom_backlight_profiles[config_no].min_input_signal;
caps->max_input_signal = custom_backlight_profiles[config_no].max_input_signal;
caps->num_data_points = (uint8_t)custom_backlight_profiles[config_no].num_data_points;
memcpy(caps->data_points, custom_backlight_profiles[config_no].data_points, data_points_size);
return true;
}