12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159 |
- /*
- * Copyright 2011 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: Alex Deucher
- */
- #include "drmP.h"
- #include "radeon.h"
- #include "radeon_asic.h"
- #include "rv6xxd.h"
- #include "r600_dpm.h"
- #include "rv6xx_dpm.h"
- #include "atom.h"
- #include <linux/seq_file.h>
- static u32 rv6xx_scale_count_given_unit(struct radeon_device *rdev,
- u32 unscaled_count, u32 unit);
- static struct rv6xx_ps *rv6xx_get_ps(struct radeon_ps *rps)
- {
- struct rv6xx_ps *ps = rps->ps_priv;
- return ps;
- }
- static struct rv6xx_power_info *rv6xx_get_pi(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rdev->pm.dpm.priv;
- return pi;
- }
- static void rv6xx_force_pcie_gen1(struct radeon_device *rdev)
- {
- u32 tmp;
- int i;
- tmp = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
- tmp &= LC_GEN2_EN;
- WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, tmp);
- tmp = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
- tmp |= LC_INITIATE_LINK_SPEED_CHANGE;
- WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, tmp);
- for (i = 0; i < rdev->usec_timeout; i++) {
- if (!(RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL) & LC_CURRENT_DATA_RATE))
- break;
- udelay(1);
- }
- tmp = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
- tmp &= ~LC_INITIATE_LINK_SPEED_CHANGE;
- WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, tmp);
- }
- static void rv6xx_enable_pcie_gen2_support(struct radeon_device *rdev)
- {
- u32 tmp;
- tmp = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
- if ((tmp & LC_OTHER_SIDE_EVER_SENT_GEN2) &&
- (tmp & LC_OTHER_SIDE_SUPPORTS_GEN2)) {
- tmp |= LC_GEN2_EN;
- WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, tmp);
- }
- }
- static void rv6xx_enable_bif_dynamic_pcie_gen2(struct radeon_device *rdev,
- bool enable)
- {
- u32 tmp;
- tmp = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL) & ~LC_HW_VOLTAGE_IF_CONTROL_MASK;
- if (enable)
- tmp |= LC_HW_VOLTAGE_IF_CONTROL(1);
- else
- tmp |= LC_HW_VOLTAGE_IF_CONTROL(0);
- WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, tmp);
- }
- static void rv6xx_enable_l0s(struct radeon_device *rdev)
- {
- u32 tmp;
- tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL) & ~LC_L0S_INACTIVITY_MASK;
- tmp |= LC_L0S_INACTIVITY(3);
- WREG32_PCIE_PORT(PCIE_LC_CNTL, tmp);
- }
- static void rv6xx_enable_l1(struct radeon_device *rdev)
- {
- u32 tmp;
- tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL);
- tmp &= ~LC_L1_INACTIVITY_MASK;
- tmp |= LC_L1_INACTIVITY(4);
- tmp &= ~LC_PMI_TO_L1_DIS;
- tmp &= ~LC_ASPM_TO_L1_DIS;
- WREG32_PCIE_PORT(PCIE_LC_CNTL, tmp);
- }
- static void rv6xx_enable_pll_sleep_in_l1(struct radeon_device *rdev)
- {
- u32 tmp;
- tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL) & ~LC_L1_INACTIVITY_MASK;
- tmp |= LC_L1_INACTIVITY(8);
- WREG32_PCIE_PORT(PCIE_LC_CNTL, tmp);
- /* NOTE, this is a PCIE indirect reg, not PCIE PORT */
- tmp = RREG32_PCIE(PCIE_P_CNTL);
- tmp |= P_PLL_PWRDN_IN_L1L23;
- tmp &= ~P_PLL_BUF_PDNB;
- tmp &= ~P_PLL_PDNB;
- tmp |= P_ALLOW_PRX_FRONTEND_SHUTOFF;
- WREG32_PCIE(PCIE_P_CNTL, tmp);
- }
- static int rv6xx_convert_clock_to_stepping(struct radeon_device *rdev,
- u32 clock, struct rv6xx_sclk_stepping *step)
- {
- int ret;
- struct atom_clock_dividers dividers;
- ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
- clock, false, ÷rs);
- if (ret)
- return ret;
- if (dividers.enable_post_div)
- step->post_divider = 2 + (dividers.post_div & 0xF) + (dividers.post_div >> 4);
- else
- step->post_divider = 1;
- step->vco_frequency = clock * step->post_divider;
- return 0;
- }
- static void rv6xx_output_stepping(struct radeon_device *rdev,
- u32 step_index, struct rv6xx_sclk_stepping *step)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- u32 ref_clk = rdev->clock.spll.reference_freq;
- u32 fb_divider;
- u32 spll_step_count = rv6xx_scale_count_given_unit(rdev,
- R600_SPLLSTEPTIME_DFLT *
- pi->spll_ref_div,
- R600_SPLLSTEPUNIT_DFLT);
- r600_engine_clock_entry_enable(rdev, step_index, true);
- r600_engine_clock_entry_enable_pulse_skipping(rdev, step_index, false);
- if (step->post_divider == 1)
- r600_engine_clock_entry_enable_post_divider(rdev, step_index, false);
- else {
- u32 lo_len = (step->post_divider - 2) / 2;
- u32 hi_len = step->post_divider - 2 - lo_len;
- r600_engine_clock_entry_enable_post_divider(rdev, step_index, true);
- r600_engine_clock_entry_set_post_divider(rdev, step_index, (hi_len << 4) | lo_len);
- }
- fb_divider = ((step->vco_frequency * pi->spll_ref_div) / ref_clk) >>
- pi->fb_div_scale;
- r600_engine_clock_entry_set_reference_divider(rdev, step_index,
- pi->spll_ref_div - 1);
- r600_engine_clock_entry_set_feedback_divider(rdev, step_index, fb_divider);
- r600_engine_clock_entry_set_step_time(rdev, step_index, spll_step_count);
- }
- static struct rv6xx_sclk_stepping rv6xx_next_vco_step(struct radeon_device *rdev,
- struct rv6xx_sclk_stepping *cur,
- bool increasing_vco, u32 step_size)
- {
- struct rv6xx_sclk_stepping next;
- next.post_divider = cur->post_divider;
- if (increasing_vco)
- next.vco_frequency = (cur->vco_frequency * (100 + step_size)) / 100;
- else
- next.vco_frequency = (cur->vco_frequency * 100 + 99 + step_size) / (100 + step_size);
- return next;
- }
- static bool rv6xx_can_step_post_div(struct radeon_device *rdev,
- struct rv6xx_sclk_stepping *cur,
- struct rv6xx_sclk_stepping *target)
- {
- return (cur->post_divider > target->post_divider) &&
- ((cur->vco_frequency * target->post_divider) <=
- (target->vco_frequency * (cur->post_divider - 1)));
- }
- static struct rv6xx_sclk_stepping rv6xx_next_post_div_step(struct radeon_device *rdev,
- struct rv6xx_sclk_stepping *cur,
- struct rv6xx_sclk_stepping *target)
- {
- struct rv6xx_sclk_stepping next = *cur;
- while (rv6xx_can_step_post_div(rdev, &next, target))
- next.post_divider--;
- return next;
- }
- static bool rv6xx_reached_stepping_target(struct radeon_device *rdev,
- struct rv6xx_sclk_stepping *cur,
- struct rv6xx_sclk_stepping *target,
- bool increasing_vco)
- {
- return (increasing_vco && (cur->vco_frequency >= target->vco_frequency)) ||
- (!increasing_vco && (cur->vco_frequency <= target->vco_frequency));
- }
- static void rv6xx_generate_steps(struct radeon_device *rdev,
- u32 low, u32 high,
- u32 start_index, u8 *end_index)
- {
- struct rv6xx_sclk_stepping cur;
- struct rv6xx_sclk_stepping target;
- bool increasing_vco;
- u32 step_index = start_index;
- rv6xx_convert_clock_to_stepping(rdev, low, &cur);
- rv6xx_convert_clock_to_stepping(rdev, high, &target);
- rv6xx_output_stepping(rdev, step_index++, &cur);
- increasing_vco = (target.vco_frequency >= cur.vco_frequency);
- if (target.post_divider > cur.post_divider)
- cur.post_divider = target.post_divider;
- while (1) {
- struct rv6xx_sclk_stepping next;
- if (rv6xx_can_step_post_div(rdev, &cur, &target))
- next = rv6xx_next_post_div_step(rdev, &cur, &target);
- else
- next = rv6xx_next_vco_step(rdev, &cur, increasing_vco, R600_VCOSTEPPCT_DFLT);
- if (rv6xx_reached_stepping_target(rdev, &next, &target, increasing_vco)) {
- struct rv6xx_sclk_stepping tiny =
- rv6xx_next_vco_step(rdev, &target, !increasing_vco, R600_ENDINGVCOSTEPPCT_DFLT);
- tiny.post_divider = next.post_divider;
- if (!rv6xx_reached_stepping_target(rdev, &tiny, &cur, !increasing_vco))
- rv6xx_output_stepping(rdev, step_index++, &tiny);
- if ((next.post_divider != target.post_divider) &&
- (next.vco_frequency != target.vco_frequency)) {
- struct rv6xx_sclk_stepping final_vco;
- final_vco.vco_frequency = target.vco_frequency;
- final_vco.post_divider = next.post_divider;
- rv6xx_output_stepping(rdev, step_index++, &final_vco);
- }
- rv6xx_output_stepping(rdev, step_index++, &target);
- break;
- } else
- rv6xx_output_stepping(rdev, step_index++, &next);
- cur = next;
- }
- *end_index = (u8)step_index - 1;
- }
- static void rv6xx_generate_single_step(struct radeon_device *rdev,
- u32 clock, u32 index)
- {
- struct rv6xx_sclk_stepping step;
- rv6xx_convert_clock_to_stepping(rdev, clock, &step);
- rv6xx_output_stepping(rdev, index, &step);
- }
- static void rv6xx_invalidate_intermediate_steps_range(struct radeon_device *rdev,
- u32 start_index, u32 end_index)
- {
- u32 step_index;
- for (step_index = start_index + 1; step_index < end_index; step_index++)
- r600_engine_clock_entry_enable(rdev, step_index, false);
- }
- static void rv6xx_set_engine_spread_spectrum_clk_s(struct radeon_device *rdev,
- u32 index, u32 clk_s)
- {
- WREG32_P(CG_SPLL_SPREAD_SPECTRUM_LOW + (index * 4),
- CLKS(clk_s), ~CLKS_MASK);
- }
- static void rv6xx_set_engine_spread_spectrum_clk_v(struct radeon_device *rdev,
- u32 index, u32 clk_v)
- {
- WREG32_P(CG_SPLL_SPREAD_SPECTRUM_LOW + (index * 4),
- CLKV(clk_v), ~CLKV_MASK);
- }
- static void rv6xx_enable_engine_spread_spectrum(struct radeon_device *rdev,
- u32 index, bool enable)
- {
- if (enable)
- WREG32_P(CG_SPLL_SPREAD_SPECTRUM_LOW + (index * 4),
- SSEN, ~SSEN);
- else
- WREG32_P(CG_SPLL_SPREAD_SPECTRUM_LOW + (index * 4),
- 0, ~SSEN);
- }
- static void rv6xx_set_memory_spread_spectrum_clk_s(struct radeon_device *rdev,
- u32 clk_s)
- {
- WREG32_P(CG_MPLL_SPREAD_SPECTRUM, CLKS(clk_s), ~CLKS_MASK);
- }
- static void rv6xx_set_memory_spread_spectrum_clk_v(struct radeon_device *rdev,
- u32 clk_v)
- {
- WREG32_P(CG_MPLL_SPREAD_SPECTRUM, CLKV(clk_v), ~CLKV_MASK);
- }
- static void rv6xx_enable_memory_spread_spectrum(struct radeon_device *rdev,
- bool enable)
- {
- if (enable)
- WREG32_P(CG_MPLL_SPREAD_SPECTRUM, SSEN, ~SSEN);
- else
- WREG32_P(CG_MPLL_SPREAD_SPECTRUM, 0, ~SSEN);
- }
- static void rv6xx_enable_dynamic_spread_spectrum(struct radeon_device *rdev,
- bool enable)
- {
- if (enable)
- WREG32_P(GENERAL_PWRMGT, DYN_SPREAD_SPECTRUM_EN, ~DYN_SPREAD_SPECTRUM_EN);
- else
- WREG32_P(GENERAL_PWRMGT, 0, ~DYN_SPREAD_SPECTRUM_EN);
- }
- static void rv6xx_memory_clock_entry_enable_post_divider(struct radeon_device *rdev,
- u32 index, bool enable)
- {
- if (enable)
- WREG32_P(MPLL_FREQ_LEVEL_0 + (index * 4),
- LEVEL0_MPLL_DIV_EN, ~LEVEL0_MPLL_DIV_EN);
- else
- WREG32_P(MPLL_FREQ_LEVEL_0 + (index * 4), 0, ~LEVEL0_MPLL_DIV_EN);
- }
- static void rv6xx_memory_clock_entry_set_post_divider(struct radeon_device *rdev,
- u32 index, u32 divider)
- {
- WREG32_P(MPLL_FREQ_LEVEL_0 + (index * 4),
- LEVEL0_MPLL_POST_DIV(divider), ~LEVEL0_MPLL_POST_DIV_MASK);
- }
- static void rv6xx_memory_clock_entry_set_feedback_divider(struct radeon_device *rdev,
- u32 index, u32 divider)
- {
- WREG32_P(MPLL_FREQ_LEVEL_0 + (index * 4), LEVEL0_MPLL_FB_DIV(divider),
- ~LEVEL0_MPLL_FB_DIV_MASK);
- }
- static void rv6xx_memory_clock_entry_set_reference_divider(struct radeon_device *rdev,
- u32 index, u32 divider)
- {
- WREG32_P(MPLL_FREQ_LEVEL_0 + (index * 4),
- LEVEL0_MPLL_REF_DIV(divider), ~LEVEL0_MPLL_REF_DIV_MASK);
- }
- static void rv6xx_vid_response_set_brt(struct radeon_device *rdev, u32 rt)
- {
- WREG32_P(VID_RT, BRT(rt), ~BRT_MASK);
- }
- static void rv6xx_enable_engine_feedback_and_reference_sync(struct radeon_device *rdev)
- {
- WREG32_P(SPLL_CNTL_MODE, SPLL_DIV_SYNC, ~SPLL_DIV_SYNC);
- }
- static u32 rv6xx_clocks_per_unit(u32 unit)
- {
- u32 tmp = 1 << (2 * unit);
- return tmp;
- }
- static u32 rv6xx_scale_count_given_unit(struct radeon_device *rdev,
- u32 unscaled_count, u32 unit)
- {
- u32 count_per_unit = rv6xx_clocks_per_unit(unit);
- return (unscaled_count + count_per_unit - 1) / count_per_unit;
- }
- static u32 rv6xx_compute_count_for_delay(struct radeon_device *rdev,
- u32 delay_us, u32 unit)
- {
- u32 ref_clk = rdev->clock.spll.reference_freq;
- return rv6xx_scale_count_given_unit(rdev, delay_us * (ref_clk / 100), unit);
- }
- static void rv6xx_calculate_engine_speed_stepping_parameters(struct radeon_device *rdev,
- struct rv6xx_ps *state)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- pi->hw.sclks[R600_POWER_LEVEL_LOW] =
- state->low.sclk;
- pi->hw.sclks[R600_POWER_LEVEL_MEDIUM] =
- state->medium.sclk;
- pi->hw.sclks[R600_POWER_LEVEL_HIGH] =
- state->high.sclk;
- pi->hw.low_sclk_index = R600_POWER_LEVEL_LOW;
- pi->hw.medium_sclk_index = R600_POWER_LEVEL_MEDIUM;
- pi->hw.high_sclk_index = R600_POWER_LEVEL_HIGH;
- }
- static void rv6xx_calculate_memory_clock_stepping_parameters(struct radeon_device *rdev,
- struct rv6xx_ps *state)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- pi->hw.mclks[R600_POWER_LEVEL_CTXSW] =
- state->high.mclk;
- pi->hw.mclks[R600_POWER_LEVEL_HIGH] =
- state->high.mclk;
- pi->hw.mclks[R600_POWER_LEVEL_MEDIUM] =
- state->medium.mclk;
- pi->hw.mclks[R600_POWER_LEVEL_LOW] =
- state->low.mclk;
- pi->hw.high_mclk_index = R600_POWER_LEVEL_HIGH;
- if (state->high.mclk == state->medium.mclk)
- pi->hw.medium_mclk_index =
- pi->hw.high_mclk_index;
- else
- pi->hw.medium_mclk_index = R600_POWER_LEVEL_MEDIUM;
- if (state->medium.mclk == state->low.mclk)
- pi->hw.low_mclk_index =
- pi->hw.medium_mclk_index;
- else
- pi->hw.low_mclk_index = R600_POWER_LEVEL_LOW;
- }
- static void rv6xx_calculate_voltage_stepping_parameters(struct radeon_device *rdev,
- struct rv6xx_ps *state)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- pi->hw.vddc[R600_POWER_LEVEL_CTXSW] = state->high.vddc;
- pi->hw.vddc[R600_POWER_LEVEL_HIGH] = state->high.vddc;
- pi->hw.vddc[R600_POWER_LEVEL_MEDIUM] = state->medium.vddc;
- pi->hw.vddc[R600_POWER_LEVEL_LOW] = state->low.vddc;
- pi->hw.backbias[R600_POWER_LEVEL_CTXSW] =
- (state->high.flags & ATOM_PPLIB_R600_FLAGS_BACKBIASENABLE) ? true : false;
- pi->hw.backbias[R600_POWER_LEVEL_HIGH] =
- (state->high.flags & ATOM_PPLIB_R600_FLAGS_BACKBIASENABLE) ? true : false;
- pi->hw.backbias[R600_POWER_LEVEL_MEDIUM] =
- (state->medium.flags & ATOM_PPLIB_R600_FLAGS_BACKBIASENABLE) ? true : false;
- pi->hw.backbias[R600_POWER_LEVEL_LOW] =
- (state->low.flags & ATOM_PPLIB_R600_FLAGS_BACKBIASENABLE) ? true : false;
- pi->hw.pcie_gen2[R600_POWER_LEVEL_HIGH] =
- (state->high.flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2) ? true : false;
- pi->hw.pcie_gen2[R600_POWER_LEVEL_MEDIUM] =
- (state->medium.flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2) ? true : false;
- pi->hw.pcie_gen2[R600_POWER_LEVEL_LOW] =
- (state->low.flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2) ? true : false;
- pi->hw.high_vddc_index = R600_POWER_LEVEL_HIGH;
- if ((state->high.vddc == state->medium.vddc) &&
- ((state->high.flags & ATOM_PPLIB_R600_FLAGS_BACKBIASENABLE) ==
- (state->medium.flags & ATOM_PPLIB_R600_FLAGS_BACKBIASENABLE)))
- pi->hw.medium_vddc_index =
- pi->hw.high_vddc_index;
- else
- pi->hw.medium_vddc_index = R600_POWER_LEVEL_MEDIUM;
- if ((state->medium.vddc == state->low.vddc) &&
- ((state->medium.flags & ATOM_PPLIB_R600_FLAGS_BACKBIASENABLE) ==
- (state->low.flags & ATOM_PPLIB_R600_FLAGS_BACKBIASENABLE)))
- pi->hw.low_vddc_index =
- pi->hw.medium_vddc_index;
- else
- pi->hw.medium_vddc_index = R600_POWER_LEVEL_LOW;
- }
- static inline u32 rv6xx_calculate_vco_frequency(u32 ref_clock,
- struct atom_clock_dividers *dividers,
- u32 fb_divider_scale)
- {
- return ref_clock * ((dividers->fb_div & ~1) << fb_divider_scale) /
- (dividers->ref_div + 1);
- }
- static inline u32 rv6xx_calculate_spread_spectrum_clk_v(u32 vco_freq, u32 ref_freq,
- u32 ss_rate, u32 ss_percent,
- u32 fb_divider_scale)
- {
- u32 fb_divider = vco_freq / ref_freq;
- return (ss_percent * ss_rate * 4 * (fb_divider * fb_divider) /
- (5375 * ((vco_freq * 10) / (4096 >> fb_divider_scale))));
- }
- static inline u32 rv6xx_calculate_spread_spectrum_clk_s(u32 ss_rate, u32 ref_freq)
- {
- return (((ref_freq * 10) / (ss_rate * 2)) - 1) / 4;
- }
- static void rv6xx_program_engine_spread_spectrum(struct radeon_device *rdev,
- u32 clock, enum r600_power_level level)
- {
- u32 ref_clk = rdev->clock.spll.reference_freq;
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- struct atom_clock_dividers dividers;
- struct radeon_atom_ss ss;
- u32 vco_freq, clk_v, clk_s;
- rv6xx_enable_engine_spread_spectrum(rdev, level, false);
- if (clock && pi->sclk_ss) {
- if (radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM, clock, false, ÷rs) == 0) {
- vco_freq = rv6xx_calculate_vco_frequency(ref_clk, ÷rs,
- pi->fb_div_scale);
- if (radeon_atombios_get_asic_ss_info(rdev, &ss,
- ASIC_INTERNAL_ENGINE_SS, vco_freq)) {
- clk_v = rv6xx_calculate_spread_spectrum_clk_v(vco_freq,
- (ref_clk / (dividers.ref_div + 1)),
- ss.rate,
- ss.percentage,
- pi->fb_div_scale);
- clk_s = rv6xx_calculate_spread_spectrum_clk_s(ss.rate,
- (ref_clk / (dividers.ref_div + 1)));
- rv6xx_set_engine_spread_spectrum_clk_v(rdev, level, clk_v);
- rv6xx_set_engine_spread_spectrum_clk_s(rdev, level, clk_s);
- rv6xx_enable_engine_spread_spectrum(rdev, level, true);
- }
- }
- }
- }
- static void rv6xx_program_sclk_spread_spectrum_parameters_except_lowest_entry(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- rv6xx_program_engine_spread_spectrum(rdev,
- pi->hw.sclks[R600_POWER_LEVEL_HIGH],
- R600_POWER_LEVEL_HIGH);
- rv6xx_program_engine_spread_spectrum(rdev,
- pi->hw.sclks[R600_POWER_LEVEL_MEDIUM],
- R600_POWER_LEVEL_MEDIUM);
- }
- static int rv6xx_program_mclk_stepping_entry(struct radeon_device *rdev,
- u32 entry, u32 clock)
- {
- struct atom_clock_dividers dividers;
- if (radeon_atom_get_clock_dividers(rdev, COMPUTE_MEMORY_PLL_PARAM, clock, false, ÷rs))
- return -EINVAL;
- rv6xx_memory_clock_entry_set_reference_divider(rdev, entry, dividers.ref_div);
- rv6xx_memory_clock_entry_set_feedback_divider(rdev, entry, dividers.fb_div);
- rv6xx_memory_clock_entry_set_post_divider(rdev, entry, dividers.post_div);
- if (dividers.enable_post_div)
- rv6xx_memory_clock_entry_enable_post_divider(rdev, entry, true);
- else
- rv6xx_memory_clock_entry_enable_post_divider(rdev, entry, false);
- return 0;
- }
- static void rv6xx_program_mclk_stepping_parameters_except_lowest_entry(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- int i;
- for (i = 1; i < R600_PM_NUMBER_OF_MCLKS; i++) {
- if (pi->hw.mclks[i])
- rv6xx_program_mclk_stepping_entry(rdev, i,
- pi->hw.mclks[i]);
- }
- }
- static void rv6xx_find_memory_clock_with_highest_vco(struct radeon_device *rdev,
- u32 requested_memory_clock,
- u32 ref_clk,
- struct atom_clock_dividers *dividers,
- u32 *vco_freq)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- struct atom_clock_dividers req_dividers;
- u32 vco_freq_temp;
- if (radeon_atom_get_clock_dividers(rdev, COMPUTE_MEMORY_PLL_PARAM,
- requested_memory_clock, false, &req_dividers) == 0) {
- vco_freq_temp = rv6xx_calculate_vco_frequency(ref_clk, &req_dividers,
- pi->fb_div_scale);
- if (vco_freq_temp > *vco_freq) {
- *dividers = req_dividers;
- *vco_freq = vco_freq_temp;
- }
- }
- }
- static void rv6xx_program_mclk_spread_spectrum_parameters(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- u32 ref_clk = rdev->clock.mpll.reference_freq;
- struct atom_clock_dividers dividers;
- struct radeon_atom_ss ss;
- u32 vco_freq = 0, clk_v, clk_s;
- rv6xx_enable_memory_spread_spectrum(rdev, false);
- if (pi->mclk_ss) {
- rv6xx_find_memory_clock_with_highest_vco(rdev,
- pi->hw.mclks[pi->hw.high_mclk_index],
- ref_clk,
- ÷rs,
- &vco_freq);
- rv6xx_find_memory_clock_with_highest_vco(rdev,
- pi->hw.mclks[pi->hw.medium_mclk_index],
- ref_clk,
- ÷rs,
- &vco_freq);
- rv6xx_find_memory_clock_with_highest_vco(rdev,
- pi->hw.mclks[pi->hw.low_mclk_index],
- ref_clk,
- ÷rs,
- &vco_freq);
- if (vco_freq) {
- if (radeon_atombios_get_asic_ss_info(rdev, &ss,
- ASIC_INTERNAL_MEMORY_SS, vco_freq)) {
- clk_v = rv6xx_calculate_spread_spectrum_clk_v(vco_freq,
- (ref_clk / (dividers.ref_div + 1)),
- ss.rate,
- ss.percentage,
- pi->fb_div_scale);
- clk_s = rv6xx_calculate_spread_spectrum_clk_s(ss.rate,
- (ref_clk / (dividers.ref_div + 1)));
- rv6xx_set_memory_spread_spectrum_clk_v(rdev, clk_v);
- rv6xx_set_memory_spread_spectrum_clk_s(rdev, clk_s);
- rv6xx_enable_memory_spread_spectrum(rdev, true);
- }
- }
- }
- }
- static int rv6xx_program_voltage_stepping_entry(struct radeon_device *rdev,
- u32 entry, u16 voltage)
- {
- u32 mask, set_pins;
- int ret;
- ret = radeon_atom_get_voltage_gpio_settings(rdev, voltage,
- SET_VOLTAGE_TYPE_ASIC_VDDC,
- &set_pins, &mask);
- if (ret)
- return ret;
- r600_voltage_control_program_voltages(rdev, entry, set_pins);
- return 0;
- }
- static void rv6xx_program_voltage_stepping_parameters_except_lowest_entry(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- int i;
- for (i = 1; i < R600_PM_NUMBER_OF_VOLTAGE_LEVELS; i++)
- rv6xx_program_voltage_stepping_entry(rdev, i,
- pi->hw.vddc[i]);
- }
- static void rv6xx_program_backbias_stepping_parameters_except_lowest_entry(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- if (pi->hw.backbias[1])
- WREG32_P(VID_UPPER_GPIO_CNTL, MEDIUM_BACKBIAS_VALUE, ~MEDIUM_BACKBIAS_VALUE);
- else
- WREG32_P(VID_UPPER_GPIO_CNTL, 0, ~MEDIUM_BACKBIAS_VALUE);
- if (pi->hw.backbias[2])
- WREG32_P(VID_UPPER_GPIO_CNTL, HIGH_BACKBIAS_VALUE, ~HIGH_BACKBIAS_VALUE);
- else
- WREG32_P(VID_UPPER_GPIO_CNTL, 0, ~HIGH_BACKBIAS_VALUE);
- }
- static void rv6xx_program_sclk_spread_spectrum_parameters_lowest_entry(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- rv6xx_program_engine_spread_spectrum(rdev,
- pi->hw.sclks[R600_POWER_LEVEL_LOW],
- R600_POWER_LEVEL_LOW);
- }
- static void rv6xx_program_mclk_stepping_parameters_lowest_entry(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- if (pi->hw.mclks[0])
- rv6xx_program_mclk_stepping_entry(rdev, 0,
- pi->hw.mclks[0]);
- }
- static void rv6xx_program_voltage_stepping_parameters_lowest_entry(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- rv6xx_program_voltage_stepping_entry(rdev, 0,
- pi->hw.vddc[0]);
- }
- static void rv6xx_program_backbias_stepping_parameters_lowest_entry(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- if (pi->hw.backbias[0])
- WREG32_P(VID_UPPER_GPIO_CNTL, LOW_BACKBIAS_VALUE, ~LOW_BACKBIAS_VALUE);
- else
- WREG32_P(VID_UPPER_GPIO_CNTL, 0, ~LOW_BACKBIAS_VALUE);
- }
- static u32 calculate_memory_refresh_rate(struct radeon_device *rdev,
- u32 engine_clock)
- {
- u32 dram_rows, dram_refresh_rate;
- u32 tmp;
- tmp = (RREG32(RAMCFG) & NOOFROWS_MASK) >> NOOFROWS_SHIFT;
- dram_rows = 1 << (tmp + 10);
- dram_refresh_rate = 1 << ((RREG32(MC_SEQ_RESERVE_M) & 0x3) + 3);
- return ((engine_clock * 10) * dram_refresh_rate / dram_rows - 32) / 64;
- }
- static void rv6xx_program_memory_timing_parameters(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- u32 sqm_ratio;
- u32 arb_refresh_rate;
- u32 high_clock;
- if (pi->hw.sclks[R600_POWER_LEVEL_HIGH] <
- (pi->hw.sclks[R600_POWER_LEVEL_LOW] * 0xFF / 0x40))
- high_clock = pi->hw.sclks[R600_POWER_LEVEL_HIGH];
- else
- high_clock =
- pi->hw.sclks[R600_POWER_LEVEL_LOW] * 0xFF / 0x40;
- radeon_atom_set_engine_dram_timings(rdev, high_clock, 0);
- sqm_ratio = (STATE0(64 * high_clock / pi->hw.sclks[R600_POWER_LEVEL_LOW]) |
- STATE1(64 * high_clock / pi->hw.sclks[R600_POWER_LEVEL_MEDIUM]) |
- STATE2(64 * high_clock / pi->hw.sclks[R600_POWER_LEVEL_HIGH]) |
- STATE3(64 * high_clock / pi->hw.sclks[R600_POWER_LEVEL_HIGH]));
- WREG32(SQM_RATIO, sqm_ratio);
- arb_refresh_rate =
- (POWERMODE0(calculate_memory_refresh_rate(rdev,
- pi->hw.sclks[R600_POWER_LEVEL_LOW])) |
- POWERMODE1(calculate_memory_refresh_rate(rdev,
- pi->hw.sclks[R600_POWER_LEVEL_MEDIUM])) |
- POWERMODE2(calculate_memory_refresh_rate(rdev,
- pi->hw.sclks[R600_POWER_LEVEL_HIGH])) |
- POWERMODE3(calculate_memory_refresh_rate(rdev,
- pi->hw.sclks[R600_POWER_LEVEL_HIGH])));
- WREG32(ARB_RFSH_RATE, arb_refresh_rate);
- }
- static void rv6xx_program_mpll_timing_parameters(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- r600_set_mpll_lock_time(rdev, R600_MPLLLOCKTIME_DFLT *
- pi->mpll_ref_div);
- r600_set_mpll_reset_time(rdev, R600_MPLLRESETTIME_DFLT);
- }
- static void rv6xx_program_bsp(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- u32 ref_clk = rdev->clock.spll.reference_freq;
- r600_calculate_u_and_p(R600_ASI_DFLT,
- ref_clk, 16,
- &pi->bsp,
- &pi->bsu);
- r600_set_bsp(rdev, pi->bsu, pi->bsp);
- }
- static void rv6xx_program_at(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- r600_set_at(rdev,
- (pi->hw.rp[0] * pi->bsp) / 200,
- (pi->hw.rp[1] * pi->bsp) / 200,
- (pi->hw.lp[2] * pi->bsp) / 200,
- (pi->hw.lp[1] * pi->bsp) / 200);
- }
- static void rv6xx_program_git(struct radeon_device *rdev)
- {
- r600_set_git(rdev, R600_GICST_DFLT);
- }
- static void rv6xx_program_tp(struct radeon_device *rdev)
- {
- int i;
- for (i = 0; i < R600_PM_NUMBER_OF_TC; i++)
- r600_set_tc(rdev, i, r600_utc[i], r600_dtc[i]);
- r600_select_td(rdev, R600_TD_DFLT);
- }
- static void rv6xx_program_vc(struct radeon_device *rdev)
- {
- r600_set_vrc(rdev, R600_VRC_DFLT);
- }
- static void rv6xx_clear_vc(struct radeon_device *rdev)
- {
- r600_set_vrc(rdev, 0);
- }
- static void rv6xx_program_tpp(struct radeon_device *rdev)
- {
- r600_set_tpu(rdev, R600_TPU_DFLT);
- r600_set_tpc(rdev, R600_TPC_DFLT);
- }
- static void rv6xx_program_sstp(struct radeon_device *rdev)
- {
- r600_set_sstu(rdev, R600_SSTU_DFLT);
- r600_set_sst(rdev, R600_SST_DFLT);
- }
- static void rv6xx_program_fcp(struct radeon_device *rdev)
- {
- r600_set_fctu(rdev, R600_FCTU_DFLT);
- r600_set_fct(rdev, R600_FCT_DFLT);
- }
- static void rv6xx_program_vddc3d_parameters(struct radeon_device *rdev)
- {
- r600_set_vddc3d_oorsu(rdev, R600_VDDC3DOORSU_DFLT);
- r600_set_vddc3d_oorphc(rdev, R600_VDDC3DOORPHC_DFLT);
- r600_set_vddc3d_oorsdc(rdev, R600_VDDC3DOORSDC_DFLT);
- r600_set_ctxcgtt3d_rphc(rdev, R600_CTXCGTT3DRPHC_DFLT);
- r600_set_ctxcgtt3d_rsdc(rdev, R600_CTXCGTT3DRSDC_DFLT);
- }
- static void rv6xx_program_voltage_timing_parameters(struct radeon_device *rdev)
- {
- u32 rt;
- r600_vid_rt_set_vru(rdev, R600_VRU_DFLT);
- r600_vid_rt_set_vrt(rdev,
- rv6xx_compute_count_for_delay(rdev,
- rdev->pm.dpm.voltage_response_time,
- R600_VRU_DFLT));
- rt = rv6xx_compute_count_for_delay(rdev,
- rdev->pm.dpm.backbias_response_time,
- R600_VRU_DFLT);
- rv6xx_vid_response_set_brt(rdev, (rt + 0x1F) >> 5);
- }
- static void rv6xx_program_engine_speed_parameters(struct radeon_device *rdev)
- {
- r600_vid_rt_set_ssu(rdev, R600_SPLLSTEPUNIT_DFLT);
- rv6xx_enable_engine_feedback_and_reference_sync(rdev);
- }
- static u64 rv6xx_get_master_voltage_mask(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- u64 master_mask = 0;
- int i;
- for (i = 0; i < R600_PM_NUMBER_OF_VOLTAGE_LEVELS; i++) {
- u32 tmp_mask, tmp_set_pins;
- int ret;
- ret = radeon_atom_get_voltage_gpio_settings(rdev,
- pi->hw.vddc[i],
- SET_VOLTAGE_TYPE_ASIC_VDDC,
- &tmp_set_pins, &tmp_mask);
- if (ret == 0)
- master_mask |= tmp_mask;
- }
- return master_mask;
- }
- static void rv6xx_program_voltage_gpio_pins(struct radeon_device *rdev)
- {
- r600_voltage_control_enable_pins(rdev,
- rv6xx_get_master_voltage_mask(rdev));
- }
- static void rv6xx_enable_static_voltage_control(struct radeon_device *rdev,
- struct radeon_ps *new_ps,
- bool enable)
- {
- struct rv6xx_ps *new_state = rv6xx_get_ps(new_ps);
- if (enable)
- radeon_atom_set_voltage(rdev,
- new_state->low.vddc,
- SET_VOLTAGE_TYPE_ASIC_VDDC);
- else
- r600_voltage_control_deactivate_static_control(rdev,
- rv6xx_get_master_voltage_mask(rdev));
- }
- static void rv6xx_enable_display_gap(struct radeon_device *rdev, bool enable)
- {
- if (enable) {
- u32 tmp = (DISP1_GAP(R600_PM_DISPLAY_GAP_VBLANK_OR_WM) |
- DISP2_GAP(R600_PM_DISPLAY_GAP_VBLANK_OR_WM) |
- DISP1_GAP_MCHG(R600_PM_DISPLAY_GAP_IGNORE) |
- DISP2_GAP_MCHG(R600_PM_DISPLAY_GAP_IGNORE) |
- VBI_TIMER_COUNT(0x3FFF) |
- VBI_TIMER_UNIT(7));
- WREG32(CG_DISPLAY_GAP_CNTL, tmp);
- WREG32_P(MCLK_PWRMGT_CNTL, USE_DISPLAY_GAP, ~USE_DISPLAY_GAP);
- } else
- WREG32_P(MCLK_PWRMGT_CNTL, 0, ~USE_DISPLAY_GAP);
- }
- static void rv6xx_program_power_level_enter_state(struct radeon_device *rdev)
- {
- r600_power_level_set_enter_index(rdev, R600_POWER_LEVEL_MEDIUM);
- }
- static void rv6xx_calculate_t(u32 l_f, u32 h_f, int h,
- int d_l, int d_r, u8 *l, u8 *r)
- {
- int a_n, a_d, h_r, l_r;
- h_r = d_l;
- l_r = 100 - d_r;
- a_n = (int)h_f * d_l + (int)l_f * (h - d_r);
- a_d = (int)l_f * l_r + (int)h_f * h_r;
- if (a_d != 0) {
- *l = d_l - h_r * a_n / a_d;
- *r = d_r + l_r * a_n / a_d;
- }
- }
- static void rv6xx_calculate_ap(struct radeon_device *rdev,
- struct rv6xx_ps *state)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- pi->hw.lp[0] = 0;
- pi->hw.rp[R600_PM_NUMBER_OF_ACTIVITY_LEVELS - 1]
- = 100;
- rv6xx_calculate_t(state->low.sclk,
- state->medium.sclk,
- R600_AH_DFLT,
- R600_LMP_DFLT,
- R600_RLP_DFLT,
- &pi->hw.lp[1],
- &pi->hw.rp[0]);
- rv6xx_calculate_t(state->medium.sclk,
- state->high.sclk,
- R600_AH_DFLT,
- R600_LHP_DFLT,
- R600_RMP_DFLT,
- &pi->hw.lp[2],
- &pi->hw.rp[1]);
- }
- static void rv6xx_calculate_stepping_parameters(struct radeon_device *rdev,
- struct radeon_ps *new_ps)
- {
- struct rv6xx_ps *new_state = rv6xx_get_ps(new_ps);
- rv6xx_calculate_engine_speed_stepping_parameters(rdev, new_state);
- rv6xx_calculate_memory_clock_stepping_parameters(rdev, new_state);
- rv6xx_calculate_voltage_stepping_parameters(rdev, new_state);
- rv6xx_calculate_ap(rdev, new_state);
- }
- static void rv6xx_program_stepping_parameters_except_lowest_entry(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- rv6xx_program_mclk_stepping_parameters_except_lowest_entry(rdev);
- if (pi->voltage_control)
- rv6xx_program_voltage_stepping_parameters_except_lowest_entry(rdev);
- rv6xx_program_backbias_stepping_parameters_except_lowest_entry(rdev);
- rv6xx_program_sclk_spread_spectrum_parameters_except_lowest_entry(rdev);
- rv6xx_program_mclk_spread_spectrum_parameters(rdev);
- rv6xx_program_memory_timing_parameters(rdev);
- }
- static void rv6xx_program_stepping_parameters_lowest_entry(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- rv6xx_program_mclk_stepping_parameters_lowest_entry(rdev);
- if (pi->voltage_control)
- rv6xx_program_voltage_stepping_parameters_lowest_entry(rdev);
- rv6xx_program_backbias_stepping_parameters_lowest_entry(rdev);
- rv6xx_program_sclk_spread_spectrum_parameters_lowest_entry(rdev);
- }
- static void rv6xx_program_power_level_low(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- r600_power_level_set_voltage_index(rdev, R600_POWER_LEVEL_LOW,
- pi->hw.low_vddc_index);
- r600_power_level_set_mem_clock_index(rdev, R600_POWER_LEVEL_LOW,
- pi->hw.low_mclk_index);
- r600_power_level_set_eng_clock_index(rdev, R600_POWER_LEVEL_LOW,
- pi->hw.low_sclk_index);
- r600_power_level_set_watermark_id(rdev, R600_POWER_LEVEL_LOW,
- R600_DISPLAY_WATERMARK_LOW);
- r600_power_level_set_pcie_gen2(rdev, R600_POWER_LEVEL_LOW,
- pi->hw.pcie_gen2[R600_POWER_LEVEL_LOW]);
- }
- static void rv6xx_program_power_level_low_to_lowest_state(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- r600_power_level_set_voltage_index(rdev, R600_POWER_LEVEL_LOW, 0);
- r600_power_level_set_mem_clock_index(rdev, R600_POWER_LEVEL_LOW, 0);
- r600_power_level_set_eng_clock_index(rdev, R600_POWER_LEVEL_LOW, 0);
- r600_power_level_set_watermark_id(rdev, R600_POWER_LEVEL_LOW,
- R600_DISPLAY_WATERMARK_LOW);
- r600_power_level_set_pcie_gen2(rdev, R600_POWER_LEVEL_LOW,
- pi->hw.pcie_gen2[R600_POWER_LEVEL_LOW]);
- }
- static void rv6xx_program_power_level_medium(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- r600_power_level_set_voltage_index(rdev, R600_POWER_LEVEL_MEDIUM,
- pi->hw.medium_vddc_index);
- r600_power_level_set_mem_clock_index(rdev, R600_POWER_LEVEL_MEDIUM,
- pi->hw.medium_mclk_index);
- r600_power_level_set_eng_clock_index(rdev, R600_POWER_LEVEL_MEDIUM,
- pi->hw.medium_sclk_index);
- r600_power_level_set_watermark_id(rdev, R600_POWER_LEVEL_MEDIUM,
- R600_DISPLAY_WATERMARK_LOW);
- r600_power_level_set_pcie_gen2(rdev, R600_POWER_LEVEL_MEDIUM,
- pi->hw.pcie_gen2[R600_POWER_LEVEL_MEDIUM]);
- }
- static void rv6xx_program_power_level_medium_for_transition(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- rv6xx_program_mclk_stepping_entry(rdev,
- R600_POWER_LEVEL_CTXSW,
- pi->hw.mclks[pi->hw.low_mclk_index]);
- r600_power_level_set_voltage_index(rdev, R600_POWER_LEVEL_MEDIUM, 1);
- r600_power_level_set_mem_clock_index(rdev, R600_POWER_LEVEL_MEDIUM,
- R600_POWER_LEVEL_CTXSW);
- r600_power_level_set_eng_clock_index(rdev, R600_POWER_LEVEL_MEDIUM,
- pi->hw.medium_sclk_index);
- r600_power_level_set_watermark_id(rdev, R600_POWER_LEVEL_MEDIUM,
- R600_DISPLAY_WATERMARK_LOW);
- rv6xx_enable_engine_spread_spectrum(rdev, R600_POWER_LEVEL_MEDIUM, false);
- r600_power_level_set_pcie_gen2(rdev, R600_POWER_LEVEL_MEDIUM,
- pi->hw.pcie_gen2[R600_POWER_LEVEL_LOW]);
- }
- static void rv6xx_program_power_level_high(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- r600_power_level_set_voltage_index(rdev, R600_POWER_LEVEL_HIGH,
- pi->hw.high_vddc_index);
- r600_power_level_set_mem_clock_index(rdev, R600_POWER_LEVEL_HIGH,
- pi->hw.high_mclk_index);
- r600_power_level_set_eng_clock_index(rdev, R600_POWER_LEVEL_HIGH,
- pi->hw.high_sclk_index);
- r600_power_level_set_watermark_id(rdev, R600_POWER_LEVEL_HIGH,
- R600_DISPLAY_WATERMARK_HIGH);
- r600_power_level_set_pcie_gen2(rdev, R600_POWER_LEVEL_HIGH,
- pi->hw.pcie_gen2[R600_POWER_LEVEL_HIGH]);
- }
- static void rv6xx_enable_backbias(struct radeon_device *rdev, bool enable)
- {
- if (enable)
- WREG32_P(GENERAL_PWRMGT, BACKBIAS_PAD_EN | BACKBIAS_DPM_CNTL,
- ~(BACKBIAS_PAD_EN | BACKBIAS_DPM_CNTL));
- else
- WREG32_P(GENERAL_PWRMGT, 0,
- ~(BACKBIAS_VALUE | BACKBIAS_PAD_EN | BACKBIAS_DPM_CNTL));
- }
- static void rv6xx_program_display_gap(struct radeon_device *rdev)
- {
- u32 tmp = RREG32(CG_DISPLAY_GAP_CNTL);
- tmp &= ~(DISP1_GAP_MCHG_MASK | DISP2_GAP_MCHG_MASK);
- if (rdev->pm.dpm.new_active_crtcs & 1) {
- tmp |= DISP1_GAP_MCHG(R600_PM_DISPLAY_GAP_VBLANK);
- tmp |= DISP2_GAP_MCHG(R600_PM_DISPLAY_GAP_IGNORE);
- } else if (rdev->pm.dpm.new_active_crtcs & 2) {
- tmp |= DISP1_GAP_MCHG(R600_PM_DISPLAY_GAP_IGNORE);
- tmp |= DISP2_GAP_MCHG(R600_PM_DISPLAY_GAP_VBLANK);
- } else {
- tmp |= DISP1_GAP_MCHG(R600_PM_DISPLAY_GAP_IGNORE);
- tmp |= DISP2_GAP_MCHG(R600_PM_DISPLAY_GAP_IGNORE);
- }
- WREG32(CG_DISPLAY_GAP_CNTL, tmp);
- }
- static void rv6xx_set_sw_voltage_to_safe(struct radeon_device *rdev,
- struct radeon_ps *new_ps,
- struct radeon_ps *old_ps)
- {
- struct rv6xx_ps *new_state = rv6xx_get_ps(new_ps);
- struct rv6xx_ps *old_state = rv6xx_get_ps(old_ps);
- u16 safe_voltage;
- safe_voltage = (new_state->low.vddc >= old_state->low.vddc) ?
- new_state->low.vddc : old_state->low.vddc;
- rv6xx_program_voltage_stepping_entry(rdev, R600_POWER_LEVEL_CTXSW,
- safe_voltage);
- WREG32_P(GENERAL_PWRMGT, SW_GPIO_INDEX(R600_POWER_LEVEL_CTXSW),
- ~SW_GPIO_INDEX_MASK);
- }
- static void rv6xx_set_sw_voltage_to_low(struct radeon_device *rdev,
- struct radeon_ps *old_ps)
- {
- struct rv6xx_ps *old_state = rv6xx_get_ps(old_ps);
- rv6xx_program_voltage_stepping_entry(rdev, R600_POWER_LEVEL_CTXSW,
- old_state->low.vddc);
- WREG32_P(GENERAL_PWRMGT, SW_GPIO_INDEX(R600_POWER_LEVEL_CTXSW),
- ~SW_GPIO_INDEX_MASK);
- }
- static void rv6xx_set_safe_backbias(struct radeon_device *rdev,
- struct radeon_ps *new_ps,
- struct radeon_ps *old_ps)
- {
- struct rv6xx_ps *new_state = rv6xx_get_ps(new_ps);
- struct rv6xx_ps *old_state = rv6xx_get_ps(old_ps);
- if ((new_state->low.flags & ATOM_PPLIB_R600_FLAGS_BACKBIASENABLE) &&
- (old_state->low.flags & ATOM_PPLIB_R600_FLAGS_BACKBIASENABLE))
- WREG32_P(GENERAL_PWRMGT, BACKBIAS_VALUE, ~BACKBIAS_VALUE);
- else
- WREG32_P(GENERAL_PWRMGT, 0, ~BACKBIAS_VALUE);
- }
- static void rv6xx_set_safe_pcie_gen2(struct radeon_device *rdev,
- struct radeon_ps *new_ps,
- struct radeon_ps *old_ps)
- {
- struct rv6xx_ps *new_state = rv6xx_get_ps(new_ps);
- struct rv6xx_ps *old_state = rv6xx_get_ps(old_ps);
- if ((new_state->low.flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2) !=
- (old_state->low.flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2))
- rv6xx_force_pcie_gen1(rdev);
- }
- static void rv6xx_enable_dynamic_voltage_control(struct radeon_device *rdev,
- bool enable)
- {
- if (enable)
- WREG32_P(GENERAL_PWRMGT, VOLT_PWRMGT_EN, ~VOLT_PWRMGT_EN);
- else
- WREG32_P(GENERAL_PWRMGT, 0, ~VOLT_PWRMGT_EN);
- }
- static void rv6xx_enable_dynamic_backbias_control(struct radeon_device *rdev,
- bool enable)
- {
- if (enable)
- WREG32_P(GENERAL_PWRMGT, BACKBIAS_DPM_CNTL, ~BACKBIAS_DPM_CNTL);
- else
- WREG32_P(GENERAL_PWRMGT, 0, ~BACKBIAS_DPM_CNTL);
- }
- static int rv6xx_step_sw_voltage(struct radeon_device *rdev,
- u16 initial_voltage,
- u16 target_voltage)
- {
- u16 current_voltage;
- u16 true_target_voltage;
- u16 voltage_step;
- int signed_voltage_step;
- if ((radeon_atom_get_voltage_step(rdev, SET_VOLTAGE_TYPE_ASIC_VDDC,
- &voltage_step)) ||
- (radeon_atom_round_to_true_voltage(rdev, SET_VOLTAGE_TYPE_ASIC_VDDC,
- initial_voltage, ¤t_voltage)) ||
- (radeon_atom_round_to_true_voltage(rdev, SET_VOLTAGE_TYPE_ASIC_VDDC,
- target_voltage, &true_target_voltage)))
- return -EINVAL;
- if (true_target_voltage < current_voltage)
- signed_voltage_step = -(int)voltage_step;
- else
- signed_voltage_step = voltage_step;
- while (current_voltage != true_target_voltage) {
- current_voltage += signed_voltage_step;
- rv6xx_program_voltage_stepping_entry(rdev, R600_POWER_LEVEL_CTXSW,
- current_voltage);
- msleep((rdev->pm.dpm.voltage_response_time + 999) / 1000);
- }
- return 0;
- }
- static int rv6xx_step_voltage_if_increasing(struct radeon_device *rdev,
- struct radeon_ps *new_ps,
- struct radeon_ps *old_ps)
- {
- struct rv6xx_ps *new_state = rv6xx_get_ps(new_ps);
- struct rv6xx_ps *old_state = rv6xx_get_ps(old_ps);
- if (new_state->low.vddc > old_state->low.vddc)
- return rv6xx_step_sw_voltage(rdev,
- old_state->low.vddc,
- new_state->low.vddc);
- return 0;
- }
- static int rv6xx_step_voltage_if_decreasing(struct radeon_device *rdev,
- struct radeon_ps *new_ps,
- struct radeon_ps *old_ps)
- {
- struct rv6xx_ps *new_state = rv6xx_get_ps(new_ps);
- struct rv6xx_ps *old_state = rv6xx_get_ps(old_ps);
- if (new_state->low.vddc < old_state->low.vddc)
- return rv6xx_step_sw_voltage(rdev,
- old_state->low.vddc,
- new_state->low.vddc);
- else
- return 0;
- }
- static void rv6xx_enable_high(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- if ((pi->restricted_levels < 1) ||
- (pi->restricted_levels == 3))
- r600_power_level_enable(rdev, R600_POWER_LEVEL_HIGH, true);
- }
- static void rv6xx_enable_medium(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- if (pi->restricted_levels < 2)
- r600_power_level_enable(rdev, R600_POWER_LEVEL_MEDIUM, true);
- }
- static void rv6xx_set_dpm_event_sources(struct radeon_device *rdev, u32 sources)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- bool want_thermal_protection;
- enum radeon_dpm_event_src dpm_event_src;
- switch (sources) {
- case 0:
- default:
- want_thermal_protection = false;
- break;
- case (1 << RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL):
- want_thermal_protection = true;
- dpm_event_src = RADEON_DPM_EVENT_SRC_DIGITAL;
- break;
- case (1 << RADEON_DPM_AUTO_THROTTLE_SRC_EXTERNAL):
- want_thermal_protection = true;
- dpm_event_src = RADEON_DPM_EVENT_SRC_EXTERNAL;
- break;
- case ((1 << RADEON_DPM_AUTO_THROTTLE_SRC_EXTERNAL) |
- (1 << RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL)):
- want_thermal_protection = true;
- dpm_event_src = RADEON_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL;
- break;
- }
- if (want_thermal_protection) {
- WREG32_P(CG_THERMAL_CTRL, DPM_EVENT_SRC(dpm_event_src), ~DPM_EVENT_SRC_MASK);
- if (pi->thermal_protection)
- WREG32_P(GENERAL_PWRMGT, 0, ~THERMAL_PROTECTION_DIS);
- } else {
- WREG32_P(GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, ~THERMAL_PROTECTION_DIS);
- }
- }
- static void rv6xx_enable_auto_throttle_source(struct radeon_device *rdev,
- enum radeon_dpm_auto_throttle_src source,
- bool enable)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- if (enable) {
- if (!(pi->active_auto_throttle_sources & (1 << source))) {
- pi->active_auto_throttle_sources |= 1 << source;
- rv6xx_set_dpm_event_sources(rdev, pi->active_auto_throttle_sources);
- }
- } else {
- if (pi->active_auto_throttle_sources & (1 << source)) {
- pi->active_auto_throttle_sources &= ~(1 << source);
- rv6xx_set_dpm_event_sources(rdev, pi->active_auto_throttle_sources);
- }
- }
- }
- static void rv6xx_enable_thermal_protection(struct radeon_device *rdev,
- bool enable)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- if (pi->active_auto_throttle_sources)
- r600_enable_thermal_protection(rdev, enable);
- }
- static void rv6xx_generate_transition_stepping(struct radeon_device *rdev,
- struct radeon_ps *new_ps,
- struct radeon_ps *old_ps)
- {
- struct rv6xx_ps *new_state = rv6xx_get_ps(new_ps);
- struct rv6xx_ps *old_state = rv6xx_get_ps(old_ps);
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- rv6xx_generate_steps(rdev,
- old_state->low.sclk,
- new_state->low.sclk,
- 0, &pi->hw.medium_sclk_index);
- }
- static void rv6xx_generate_low_step(struct radeon_device *rdev,
- struct radeon_ps *new_ps)
- {
- struct rv6xx_ps *new_state = rv6xx_get_ps(new_ps);
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- pi->hw.low_sclk_index = 0;
- rv6xx_generate_single_step(rdev,
- new_state->low.sclk,
- 0);
- }
- static void rv6xx_invalidate_intermediate_steps(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- rv6xx_invalidate_intermediate_steps_range(rdev, 0,
- pi->hw.medium_sclk_index);
- }
- static void rv6xx_generate_stepping_table(struct radeon_device *rdev,
- struct radeon_ps *new_ps)
- {
- struct rv6xx_ps *new_state = rv6xx_get_ps(new_ps);
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- pi->hw.low_sclk_index = 0;
- rv6xx_generate_steps(rdev,
- new_state->low.sclk,
- new_state->medium.sclk,
- 0,
- &pi->hw.medium_sclk_index);
- rv6xx_generate_steps(rdev,
- new_state->medium.sclk,
- new_state->high.sclk,
- pi->hw.medium_sclk_index,
- &pi->hw.high_sclk_index);
- }
- static void rv6xx_enable_spread_spectrum(struct radeon_device *rdev,
- bool enable)
- {
- if (enable)
- rv6xx_enable_dynamic_spread_spectrum(rdev, true);
- else {
- rv6xx_enable_engine_spread_spectrum(rdev, R600_POWER_LEVEL_LOW, false);
- rv6xx_enable_engine_spread_spectrum(rdev, R600_POWER_LEVEL_MEDIUM, false);
- rv6xx_enable_engine_spread_spectrum(rdev, R600_POWER_LEVEL_HIGH, false);
- rv6xx_enable_dynamic_spread_spectrum(rdev, false);
- rv6xx_enable_memory_spread_spectrum(rdev, false);
- }
- }
- static void rv6xx_reset_lvtm_data_sync(struct radeon_device *rdev)
- {
- if (ASIC_IS_DCE3(rdev))
- WREG32_P(DCE3_LVTMA_DATA_SYNCHRONIZATION, LVTMA_PFREQCHG, ~LVTMA_PFREQCHG);
- else
- WREG32_P(LVTMA_DATA_SYNCHRONIZATION, LVTMA_PFREQCHG, ~LVTMA_PFREQCHG);
- }
- static void rv6xx_enable_dynamic_pcie_gen2(struct radeon_device *rdev,
- struct radeon_ps *new_ps,
- bool enable)
- {
- struct rv6xx_ps *new_state = rv6xx_get_ps(new_ps);
- if (enable) {
- rv6xx_enable_bif_dynamic_pcie_gen2(rdev, true);
- rv6xx_enable_pcie_gen2_support(rdev);
- r600_enable_dynamic_pcie_gen2(rdev, true);
- } else {
- if (!(new_state->low.flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2))
- rv6xx_force_pcie_gen1(rdev);
- rv6xx_enable_bif_dynamic_pcie_gen2(rdev, false);
- r600_enable_dynamic_pcie_gen2(rdev, false);
- }
- }
- static void rv6xx_set_uvd_clock_before_set_eng_clock(struct radeon_device *rdev,
- struct radeon_ps *new_ps,
- struct radeon_ps *old_ps)
- {
- struct rv6xx_ps *new_state = rv6xx_get_ps(new_ps);
- struct rv6xx_ps *current_state = rv6xx_get_ps(old_ps);
- if ((new_ps->vclk == old_ps->vclk) &&
- (new_ps->dclk == old_ps->dclk))
- return;
- if (new_state->high.sclk >= current_state->high.sclk)
- return;
- radeon_set_uvd_clocks(rdev, new_ps->vclk, new_ps->dclk);
- }
- static void rv6xx_set_uvd_clock_after_set_eng_clock(struct radeon_device *rdev,
- struct radeon_ps *new_ps,
- struct radeon_ps *old_ps)
- {
- struct rv6xx_ps *new_state = rv6xx_get_ps(new_ps);
- struct rv6xx_ps *current_state = rv6xx_get_ps(old_ps);
- if ((new_ps->vclk == old_ps->vclk) &&
- (new_ps->dclk == old_ps->dclk))
- return;
- if (new_state->high.sclk < current_state->high.sclk)
- return;
- radeon_set_uvd_clocks(rdev, new_ps->vclk, new_ps->dclk);
- }
- int rv6xx_dpm_enable(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- struct radeon_ps *boot_ps = rdev->pm.dpm.boot_ps;
- if (r600_dynamicpm_enabled(rdev))
- return -EINVAL;
- if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_BACKBIAS)
- rv6xx_enable_backbias(rdev, true);
- if (pi->dynamic_ss)
- rv6xx_enable_spread_spectrum(rdev, true);
- rv6xx_program_mpll_timing_parameters(rdev);
- rv6xx_program_bsp(rdev);
- rv6xx_program_git(rdev);
- rv6xx_program_tp(rdev);
- rv6xx_program_tpp(rdev);
- rv6xx_program_sstp(rdev);
- rv6xx_program_fcp(rdev);
- rv6xx_program_vddc3d_parameters(rdev);
- rv6xx_program_voltage_timing_parameters(rdev);
- rv6xx_program_engine_speed_parameters(rdev);
- rv6xx_enable_display_gap(rdev, true);
- if (pi->display_gap == false)
- rv6xx_enable_display_gap(rdev, false);
- rv6xx_program_power_level_enter_state(rdev);
- rv6xx_calculate_stepping_parameters(rdev, boot_ps);
- if (pi->voltage_control)
- rv6xx_program_voltage_gpio_pins(rdev);
- rv6xx_generate_stepping_table(rdev, boot_ps);
- rv6xx_program_stepping_parameters_except_lowest_entry(rdev);
- rv6xx_program_stepping_parameters_lowest_entry(rdev);
- rv6xx_program_power_level_low(rdev);
- rv6xx_program_power_level_medium(rdev);
- rv6xx_program_power_level_high(rdev);
- rv6xx_program_vc(rdev);
- rv6xx_program_at(rdev);
- r600_power_level_enable(rdev, R600_POWER_LEVEL_LOW, true);
- r600_power_level_enable(rdev, R600_POWER_LEVEL_MEDIUM, true);
- r600_power_level_enable(rdev, R600_POWER_LEVEL_HIGH, true);
- rv6xx_enable_auto_throttle_source(rdev, RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL, true);
- r600_start_dpm(rdev);
- if (pi->voltage_control)
- rv6xx_enable_static_voltage_control(rdev, boot_ps, false);
- if (pi->dynamic_pcie_gen2)
- rv6xx_enable_dynamic_pcie_gen2(rdev, boot_ps, true);
- if (pi->gfx_clock_gating)
- r600_gfx_clockgating_enable(rdev, true);
- return 0;
- }
- void rv6xx_dpm_disable(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- struct radeon_ps *boot_ps = rdev->pm.dpm.boot_ps;
- if (!r600_dynamicpm_enabled(rdev))
- return;
- r600_power_level_enable(rdev, R600_POWER_LEVEL_LOW, true);
- r600_power_level_enable(rdev, R600_POWER_LEVEL_MEDIUM, true);
- rv6xx_enable_display_gap(rdev, false);
- rv6xx_clear_vc(rdev);
- r600_set_at(rdev, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF);
- if (pi->thermal_protection)
- r600_enable_thermal_protection(rdev, false);
- r600_wait_for_power_level(rdev, R600_POWER_LEVEL_LOW);
- r600_power_level_enable(rdev, R600_POWER_LEVEL_HIGH, false);
- r600_power_level_enable(rdev, R600_POWER_LEVEL_MEDIUM, false);
- if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_BACKBIAS)
- rv6xx_enable_backbias(rdev, false);
- rv6xx_enable_spread_spectrum(rdev, false);
- if (pi->voltage_control)
- rv6xx_enable_static_voltage_control(rdev, boot_ps, true);
- if (pi->dynamic_pcie_gen2)
- rv6xx_enable_dynamic_pcie_gen2(rdev, boot_ps, false);
- if (rdev->irq.installed &&
- r600_is_internal_thermal_sensor(rdev->pm.int_thermal_type)) {
- rdev->irq.dpm_thermal = false;
- radeon_irq_set(rdev);
- }
- if (pi->gfx_clock_gating)
- r600_gfx_clockgating_enable(rdev, false);
- r600_stop_dpm(rdev);
- }
- int rv6xx_dpm_set_power_state(struct radeon_device *rdev)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- struct radeon_ps *new_ps = rdev->pm.dpm.requested_ps;
- struct radeon_ps *old_ps = rdev->pm.dpm.current_ps;
- int ret;
- pi->restricted_levels = 0;
- rv6xx_set_uvd_clock_before_set_eng_clock(rdev, new_ps, old_ps);
- rv6xx_clear_vc(rdev);
- r600_power_level_enable(rdev, R600_POWER_LEVEL_LOW, true);
- r600_set_at(rdev, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF);
- if (pi->thermal_protection)
- r600_enable_thermal_protection(rdev, false);
- r600_wait_for_power_level(rdev, R600_POWER_LEVEL_LOW);
- r600_power_level_enable(rdev, R600_POWER_LEVEL_HIGH, false);
- r600_power_level_enable(rdev, R600_POWER_LEVEL_MEDIUM, false);
- rv6xx_generate_transition_stepping(rdev, new_ps, old_ps);
- rv6xx_program_power_level_medium_for_transition(rdev);
- if (pi->voltage_control) {
- rv6xx_set_sw_voltage_to_safe(rdev, new_ps, old_ps);
- if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_STEPVDDC)
- rv6xx_set_sw_voltage_to_low(rdev, old_ps);
- }
- if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_BACKBIAS)
- rv6xx_set_safe_backbias(rdev, new_ps, old_ps);
- if (pi->dynamic_pcie_gen2)
- rv6xx_set_safe_pcie_gen2(rdev, new_ps, old_ps);
- if (pi->voltage_control)
- rv6xx_enable_dynamic_voltage_control(rdev, false);
- if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_BACKBIAS)
- rv6xx_enable_dynamic_backbias_control(rdev, false);
- if (pi->voltage_control) {
- if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_STEPVDDC)
- rv6xx_step_voltage_if_increasing(rdev, new_ps, old_ps);
- msleep((rdev->pm.dpm.voltage_response_time + 999) / 1000);
- }
- r600_power_level_enable(rdev, R600_POWER_LEVEL_MEDIUM, true);
- r600_power_level_enable(rdev, R600_POWER_LEVEL_LOW, false);
- r600_wait_for_power_level_unequal(rdev, R600_POWER_LEVEL_LOW);
- rv6xx_generate_low_step(rdev, new_ps);
- rv6xx_invalidate_intermediate_steps(rdev);
- rv6xx_calculate_stepping_parameters(rdev, new_ps);
- rv6xx_program_stepping_parameters_lowest_entry(rdev);
- rv6xx_program_power_level_low_to_lowest_state(rdev);
- r600_power_level_enable(rdev, R600_POWER_LEVEL_LOW, true);
- r600_wait_for_power_level(rdev, R600_POWER_LEVEL_LOW);
- r600_power_level_enable(rdev, R600_POWER_LEVEL_MEDIUM, false);
- if (pi->voltage_control) {
- if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_STEPVDDC) {
- ret = rv6xx_step_voltage_if_decreasing(rdev, new_ps, old_ps);
- if (ret)
- return ret;
- }
- rv6xx_enable_dynamic_voltage_control(rdev, true);
- }
- if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_BACKBIAS)
- rv6xx_enable_dynamic_backbias_control(rdev, true);
- if (pi->dynamic_pcie_gen2)
- rv6xx_enable_dynamic_pcie_gen2(rdev, new_ps, true);
- rv6xx_reset_lvtm_data_sync(rdev);
- rv6xx_generate_stepping_table(rdev, new_ps);
- rv6xx_program_stepping_parameters_except_lowest_entry(rdev);
- rv6xx_program_power_level_low(rdev);
- rv6xx_program_power_level_medium(rdev);
- rv6xx_program_power_level_high(rdev);
- rv6xx_enable_medium(rdev);
- rv6xx_enable_high(rdev);
- if (pi->thermal_protection)
- rv6xx_enable_thermal_protection(rdev, true);
- rv6xx_program_vc(rdev);
- rv6xx_program_at(rdev);
- rv6xx_set_uvd_clock_after_set_eng_clock(rdev, new_ps, old_ps);
- return 0;
- }
- void rv6xx_setup_asic(struct radeon_device *rdev)
- {
- r600_enable_acpi_pm(rdev);
- if (radeon_aspm != 0) {
- if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_ASPM_L0s)
- rv6xx_enable_l0s(rdev);
- if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_ASPM_L1)
- rv6xx_enable_l1(rdev);
- if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_TURNOFFPLL_ASPML1)
- rv6xx_enable_pll_sleep_in_l1(rdev);
- }
- }
- void rv6xx_dpm_display_configuration_changed(struct radeon_device *rdev)
- {
- rv6xx_program_display_gap(rdev);
- }
- union power_info {
- struct _ATOM_POWERPLAY_INFO info;
- struct _ATOM_POWERPLAY_INFO_V2 info_2;
- struct _ATOM_POWERPLAY_INFO_V3 info_3;
- struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
- struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
- struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
- };
- union pplib_clock_info {
- struct _ATOM_PPLIB_R600_CLOCK_INFO r600;
- struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780;
- struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen;
- struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo;
- };
- union pplib_power_state {
- struct _ATOM_PPLIB_STATE v1;
- struct _ATOM_PPLIB_STATE_V2 v2;
- };
- static void rv6xx_parse_pplib_non_clock_info(struct radeon_device *rdev,
- struct radeon_ps *rps,
- struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info)
- {
- rps->caps = le32_to_cpu(non_clock_info->ulCapsAndSettings);
- rps->class = le16_to_cpu(non_clock_info->usClassification);
- rps->class2 = le16_to_cpu(non_clock_info->usClassification2);
- if (r600_is_uvd_state(rps->class, rps->class2)) {
- rps->vclk = RV6XX_DEFAULT_VCLK_FREQ;
- rps->dclk = RV6XX_DEFAULT_DCLK_FREQ;
- } else {
- rps->vclk = 0;
- rps->dclk = 0;
- }
- if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT)
- rdev->pm.dpm.boot_ps = rps;
- if (rps->class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE)
- rdev->pm.dpm.uvd_ps = rps;
- }
- static void rv6xx_parse_pplib_clock_info(struct radeon_device *rdev,
- struct radeon_ps *rps, int index,
- union pplib_clock_info *clock_info)
- {
- struct rv6xx_ps *ps = rv6xx_get_ps(rps);
- u32 sclk, mclk;
- u16 vddc;
- struct rv6xx_pl *pl;
- switch (index) {
- case 0:
- pl = &ps->low;
- break;
- case 1:
- pl = &ps->medium;
- break;
- case 2:
- default:
- pl = &ps->high;
- break;
- }
- sclk = le16_to_cpu(clock_info->r600.usEngineClockLow);
- sclk |= clock_info->r600.ucEngineClockHigh << 16;
- mclk = le16_to_cpu(clock_info->r600.usMemoryClockLow);
- mclk |= clock_info->r600.ucMemoryClockHigh << 16;
- pl->mclk = mclk;
- pl->sclk = sclk;
- pl->vddc = le16_to_cpu(clock_info->r600.usVDDC);
- pl->flags = le32_to_cpu(clock_info->r600.ulFlags);
- /* patch up vddc if necessary */
- if (pl->vddc == 0xff01) {
- if (radeon_atom_get_max_vddc(rdev, 0, 0, &vddc) == 0)
- pl->vddc = vddc;
- }
- /* fix up pcie gen2 */
- if (pl->flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2) {
- if ((rdev->family == CHIP_RV610) || (rdev->family == CHIP_RV630)) {
- if (pl->vddc < 1100)
- pl->flags &= ~ATOM_PPLIB_R600_FLAGS_PCIEGEN2;
- }
- }
- /* patch up boot state */
- if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT) {
- u16 vddc, vddci, mvdd;
- radeon_atombios_get_default_voltages(rdev, &vddc, &vddci, &mvdd);
- pl->mclk = rdev->clock.default_mclk;
- pl->sclk = rdev->clock.default_sclk;
- pl->vddc = vddc;
- }
- }
- static int rv6xx_parse_power_table(struct radeon_device *rdev)
- {
- struct radeon_mode_info *mode_info = &rdev->mode_info;
- struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
- union pplib_power_state *power_state;
- int i, j;
- union pplib_clock_info *clock_info;
- union power_info *power_info;
- int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
- u16 data_offset;
- u8 frev, crev;
- struct rv6xx_ps *ps;
- if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
- &frev, &crev, &data_offset))
- return -EINVAL;
- power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
- rdev->pm.dpm.ps = kzalloc(sizeof(struct radeon_ps) *
- power_info->pplib.ucNumStates, GFP_KERNEL);
- if (!rdev->pm.dpm.ps)
- return -ENOMEM;
- for (i = 0; i < power_info->pplib.ucNumStates; i++) {
- power_state = (union pplib_power_state *)
- (mode_info->atom_context->bios + data_offset +
- le16_to_cpu(power_info->pplib.usStateArrayOffset) +
- i * power_info->pplib.ucStateEntrySize);
- non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
- (mode_info->atom_context->bios + data_offset +
- le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset) +
- (power_state->v1.ucNonClockStateIndex *
- power_info->pplib.ucNonClockSize));
- if (power_info->pplib.ucStateEntrySize - 1) {
- u8 *idx;
- ps = kzalloc(sizeof(struct rv6xx_ps), GFP_KERNEL);
- if (ps == NULL) {
- kfree(rdev->pm.dpm.ps);
- return -ENOMEM;
- }
- rdev->pm.dpm.ps[i].ps_priv = ps;
- rv6xx_parse_pplib_non_clock_info(rdev, &rdev->pm.dpm.ps[i],
- non_clock_info);
- idx = (u8 *)&power_state->v1.ucClockStateIndices[0];
- for (j = 0; j < (power_info->pplib.ucStateEntrySize - 1); j++) {
- clock_info = (union pplib_clock_info *)
- (mode_info->atom_context->bios + data_offset +
- le16_to_cpu(power_info->pplib.usClockInfoArrayOffset) +
- (idx[j] * power_info->pplib.ucClockInfoSize));
- rv6xx_parse_pplib_clock_info(rdev,
- &rdev->pm.dpm.ps[i], j,
- clock_info);
- }
- }
- }
- rdev->pm.dpm.num_ps = power_info->pplib.ucNumStates;
- return 0;
- }
- int rv6xx_dpm_init(struct radeon_device *rdev)
- {
- struct radeon_atom_ss ss;
- struct atom_clock_dividers dividers;
- struct rv6xx_power_info *pi;
- int ret;
- pi = kzalloc(sizeof(struct rv6xx_power_info), GFP_KERNEL);
- if (pi == NULL)
- return -ENOMEM;
- rdev->pm.dpm.priv = pi;
- ret = r600_get_platform_caps(rdev);
- if (ret)
- return ret;
- ret = rv6xx_parse_power_table(rdev);
- if (ret)
- return ret;
- if (rdev->pm.dpm.voltage_response_time == 0)
- rdev->pm.dpm.voltage_response_time = R600_VOLTAGERESPONSETIME_DFLT;
- if (rdev->pm.dpm.backbias_response_time == 0)
- rdev->pm.dpm.backbias_response_time = R600_BACKBIASRESPONSETIME_DFLT;
- ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
- 0, false, ÷rs);
- if (ret)
- pi->spll_ref_div = dividers.ref_div + 1;
- else
- pi->spll_ref_div = R600_REFERENCEDIVIDER_DFLT;
- ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_MEMORY_PLL_PARAM,
- 0, false, ÷rs);
- if (ret)
- pi->mpll_ref_div = dividers.ref_div + 1;
- else
- pi->mpll_ref_div = R600_REFERENCEDIVIDER_DFLT;
- if (rdev->family >= CHIP_RV670)
- pi->fb_div_scale = 1;
- else
- pi->fb_div_scale = 0;
- pi->voltage_control =
- radeon_atom_is_voltage_gpio(rdev, SET_VOLTAGE_TYPE_ASIC_VDDC, 0);
- pi->gfx_clock_gating = true;
- pi->sclk_ss = radeon_atombios_get_asic_ss_info(rdev, &ss,
- ASIC_INTERNAL_ENGINE_SS, 0);
- pi->mclk_ss = radeon_atombios_get_asic_ss_info(rdev, &ss,
- ASIC_INTERNAL_MEMORY_SS, 0);
- /* Disable sclk ss, causes hangs on a lot of systems */
- pi->sclk_ss = false;
- if (pi->sclk_ss || pi->mclk_ss)
- pi->dynamic_ss = true;
- else
- pi->dynamic_ss = false;
- pi->dynamic_pcie_gen2 = true;
- if (pi->gfx_clock_gating &&
- (rdev->pm.int_thermal_type != THERMAL_TYPE_NONE))
- pi->thermal_protection = true;
- else
- pi->thermal_protection = false;
- pi->display_gap = true;
- return 0;
- }
- void rv6xx_dpm_print_power_state(struct radeon_device *rdev,
- struct radeon_ps *rps)
- {
- struct rv6xx_ps *ps = rv6xx_get_ps(rps);
- struct rv6xx_pl *pl;
- r600_dpm_print_class_info(rps->class, rps->class2);
- r600_dpm_print_cap_info(rps->caps);
- printk("\tuvd vclk: %d dclk: %d\n", rps->vclk, rps->dclk);
- pl = &ps->low;
- printk("\t\tpower level 0 sclk: %u mclk: %u vddc: %u\n",
- pl->sclk, pl->mclk, pl->vddc);
- pl = &ps->medium;
- printk("\t\tpower level 1 sclk: %u mclk: %u vddc: %u\n",
- pl->sclk, pl->mclk, pl->vddc);
- pl = &ps->high;
- printk("\t\tpower level 2 sclk: %u mclk: %u vddc: %u\n",
- pl->sclk, pl->mclk, pl->vddc);
- r600_dpm_print_ps_status(rdev, rps);
- }
- void rv6xx_dpm_debugfs_print_current_performance_level(struct radeon_device *rdev,
- struct seq_file *m)
- {
- struct radeon_ps *rps = rdev->pm.dpm.current_ps;
- struct rv6xx_ps *ps = rv6xx_get_ps(rps);
- struct rv6xx_pl *pl;
- u32 current_index =
- (RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURRENT_PROFILE_INDEX_MASK) >>
- CURRENT_PROFILE_INDEX_SHIFT;
- if (current_index > 2) {
- seq_printf(m, "invalid dpm profile %d\n", current_index);
- } else {
- if (current_index == 0)
- pl = &ps->low;
- else if (current_index == 1)
- pl = &ps->medium;
- else /* current_index == 2 */
- pl = &ps->high;
- seq_printf(m, "uvd vclk: %d dclk: %d\n", rps->vclk, rps->dclk);
- seq_printf(m, "power level %d sclk: %u mclk: %u vddc: %u\n",
- current_index, pl->sclk, pl->mclk, pl->vddc);
- }
- }
- /* get the current sclk in 10 khz units */
- u32 rv6xx_dpm_get_current_sclk(struct radeon_device *rdev)
- {
- struct radeon_ps *rps = rdev->pm.dpm.current_ps;
- struct rv6xx_ps *ps = rv6xx_get_ps(rps);
- struct rv6xx_pl *pl;
- u32 current_index =
- (RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURRENT_PROFILE_INDEX_MASK) >>
- CURRENT_PROFILE_INDEX_SHIFT;
- if (current_index > 2) {
- return 0;
- } else {
- if (current_index == 0)
- pl = &ps->low;
- else if (current_index == 1)
- pl = &ps->medium;
- else /* current_index == 2 */
- pl = &ps->high;
- return pl->sclk;
- }
- }
- /* get the current mclk in 10 khz units */
- u32 rv6xx_dpm_get_current_mclk(struct radeon_device *rdev)
- {
- struct radeon_ps *rps = rdev->pm.dpm.current_ps;
- struct rv6xx_ps *ps = rv6xx_get_ps(rps);
- struct rv6xx_pl *pl;
- u32 current_index =
- (RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURRENT_PROFILE_INDEX_MASK) >>
- CURRENT_PROFILE_INDEX_SHIFT;
- if (current_index > 2) {
- return 0;
- } else {
- if (current_index == 0)
- pl = &ps->low;
- else if (current_index == 1)
- pl = &ps->medium;
- else /* current_index == 2 */
- pl = &ps->high;
- return pl->mclk;
- }
- }
- void rv6xx_dpm_fini(struct radeon_device *rdev)
- {
- int i;
- for (i = 0; i < rdev->pm.dpm.num_ps; i++) {
- kfree(rdev->pm.dpm.ps[i].ps_priv);
- }
- kfree(rdev->pm.dpm.ps);
- kfree(rdev->pm.dpm.priv);
- }
- u32 rv6xx_dpm_get_sclk(struct radeon_device *rdev, bool low)
- {
- struct rv6xx_ps *requested_state = rv6xx_get_ps(rdev->pm.dpm.requested_ps);
- if (low)
- return requested_state->low.sclk;
- else
- return requested_state->high.sclk;
- }
- u32 rv6xx_dpm_get_mclk(struct radeon_device *rdev, bool low)
- {
- struct rv6xx_ps *requested_state = rv6xx_get_ps(rdev->pm.dpm.requested_ps);
- if (low)
- return requested_state->low.mclk;
- else
- return requested_state->high.mclk;
- }
- int rv6xx_dpm_force_performance_level(struct radeon_device *rdev,
- enum radeon_dpm_forced_level level)
- {
- struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
- if (level == RADEON_DPM_FORCED_LEVEL_HIGH) {
- pi->restricted_levels = 3;
- } else if (level == RADEON_DPM_FORCED_LEVEL_LOW) {
- pi->restricted_levels = 2;
- } else {
- pi->restricted_levels = 0;
- }
- rv6xx_clear_vc(rdev);
- r600_power_level_enable(rdev, R600_POWER_LEVEL_LOW, true);
- r600_set_at(rdev, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF);
- r600_wait_for_power_level(rdev, R600_POWER_LEVEL_LOW);
- r600_power_level_enable(rdev, R600_POWER_LEVEL_HIGH, false);
- r600_power_level_enable(rdev, R600_POWER_LEVEL_MEDIUM, false);
- rv6xx_enable_medium(rdev);
- rv6xx_enable_high(rdev);
- if (pi->restricted_levels == 3)
- r600_power_level_enable(rdev, R600_POWER_LEVEL_LOW, false);
- rv6xx_program_vc(rdev);
- rv6xx_program_at(rdev);
- rdev->pm.dpm.forced_level = level;
- return 0;
- }
|