12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009 |
- /*
- * Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 and
- * only version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
- #define pr_fmt(fmt) "%s: " fmt, __func__
- #include <linux/bitops.h>
- #include <linux/debugfs.h>
- #include <linux/err.h>
- #include <linux/init.h>
- #include <linux/interrupt.h>
- #include <linux/io.h>
- #include <linux/kernel.h>
- #include <linux/list.h>
- #include <linux/module.h>
- #include <linux/of.h>
- #include <linux/of_device.h>
- #include <linux/platform_device.h>
- #include <linux/pm_opp.h>
- #include <linux/slab.h>
- #include <linux/string.h>
- #include <linux/uaccess.h>
- #include <linux/regulator/driver.h>
- #include <linux/regulator/machine.h>
- #include <linux/regulator/of_regulator.h>
- #include "cpr3-regulator.h"
- #define MSM8953_APSS_FUSE_CORNERS 4
- #define SDM632_POWER_APSS_FUSE_CORNERS 4
- #define SDM632_PERF_APSS_FUSE_CORNERS 4
- /**
- * struct cpr4_apss_fuses - APSS specific fuse data
- * @ro_sel: Ring oscillator select fuse parameter value for each
- * fuse corner
- * @init_voltage: Initial (i.e. open-loop) voltage fuse parameter value
- * for each fuse corner (raw, not converted to a voltage)
- * @target_quot: CPR target quotient fuse parameter value for each fuse
- * corner
- * @quot_offset: CPR target quotient offset fuse parameter value for each
- * fuse corner (raw, not unpacked) used for target quotient
- * interpolation
- * @speed_bin: Application processor speed bin fuse parameter value for
- * the given chip
- * @cpr_fusing_rev: CPR fusing revision fuse parameter value
- * @foundry_id: Foundry identifier fuse parameter value for the given
- * chip
- * @boost_cfg: CPR boost configuration fuse parameter value
- * @boost_voltage: CPR boost voltage fuse parameter value (raw, not
- * converted to a voltage)
- * @aging_init_quot_diff: Initial quotient difference between CPR aging
- * min and max sensors measured at time of manufacturing
- *
- * This struct holds the values for all of the fuses read from memory.
- */
- struct cpr4_apss_fuses {
- u64 *ro_sel;
- u64 *init_voltage;
- u64 *target_quot;
- u64 *quot_offset;
- u64 speed_bin;
- u64 cpr_fusing_rev;
- u64 foundry_id;
- u64 boost_cfg;
- u64 boost_voltage;
- u64 misc;
- u64 aging_init_quot_diff;
- };
- /*
- * fuse combo = fusing revision + 8 * (speed bin)
- * where: fusing revision = 0 - 7 and speed bin = 0 - 7
- */
- #define CPR4_MSM8953_APSS_FUSE_COMBO_COUNT 64
- #define CPR4_SDM632_APSS_FUSE_COMBO_COUNT 64
- /*
- * Constants which define the name of each fuse corner.
- */
- enum cpr4_msm8953_apss_fuse_corner {
- CPR4_MSM8953_APSS_FUSE_CORNER_LOWSVS = 0,
- CPR4_MSM8953_APSS_FUSE_CORNER_SVS = 1,
- CPR4_MSM8953_APSS_FUSE_CORNER_NOM = 2,
- CPR4_MSM8953_APSS_FUSE_CORNER_TURBO_L1 = 3,
- };
- static const char * const cpr4_msm8953_apss_fuse_corner_name[] = {
- [CPR4_MSM8953_APSS_FUSE_CORNER_LOWSVS] = "LowSVS",
- [CPR4_MSM8953_APSS_FUSE_CORNER_SVS] = "SVS",
- [CPR4_MSM8953_APSS_FUSE_CORNER_NOM] = "NOM",
- [CPR4_MSM8953_APSS_FUSE_CORNER_TURBO_L1] = "TURBO_L1",
- };
- enum cpr4_sdm632_power_apss_fuse_corner {
- CPR4_SDM632_POWER_APSS_FUSE_CORNER_LOWSVS = 0,
- CPR4_SDM632_POWER_APSS_FUSE_CORNER_SVS_L1 = 1,
- CPR4_SDM632_POWER_APSS_FUSE_CORNER_NOM = 2,
- CPR4_SDM632_POWER_APSS_FUSE_CORNER_TURBO_L1 = 3,
- };
- static const char * const cpr4_sdm632_power_apss_fuse_corner_name[] = {
- [CPR4_SDM632_POWER_APSS_FUSE_CORNER_LOWSVS] = "LowSVS",
- [CPR4_SDM632_POWER_APSS_FUSE_CORNER_SVS_L1] = "SVS_L1",
- [CPR4_SDM632_POWER_APSS_FUSE_CORNER_NOM] = "NOM",
- [CPR4_SDM632_POWER_APSS_FUSE_CORNER_TURBO_L1] = "TURBO_L1",
- };
- enum cpr4_sdm632_perf_apss_fuse_corner {
- CPR4_SDM632_PERF_APSS_FUSE_CORNER_LOWSVS = 0,
- CPR4_SDM632_PERF_APSS_FUSE_CORNER_SVS_L1 = 1,
- CPR4_SDM632_PERF_APSS_FUSE_CORNER_NOM = 2,
- CPR4_SDM632_PERF_APSS_FUSE_CORNER_TURBO_L1 = 3,
- };
- static const char * const cpr4_sdm632_perf_apss_fuse_corner_name[] = {
- [CPR4_SDM632_PERF_APSS_FUSE_CORNER_LOWSVS] = "LowSVS",
- [CPR4_SDM632_PERF_APSS_FUSE_CORNER_SVS_L1] = "SVS_L1",
- [CPR4_SDM632_PERF_APSS_FUSE_CORNER_NOM] = "NOM",
- [CPR4_SDM632_PERF_APSS_FUSE_CORNER_TURBO_L1] = "TURBO_L1",
- };
- /* APSS cluster thread IDs */
- #define CPR4_APSS_POWER_CLUSTER_ID 0
- #define CPR4_APSS_PERF_CLUSTER_ID 1
- /*
- * MSM8953 APSS fuse parameter locations:
- *
- * Structs are organized with the following dimensions:
- * Outer: 0 to 3 for fuse corners from lowest to highest corner
- * Inner: large enough to hold the longest set of parameter segments which
- * fully defines a fuse parameter, +1 (for NULL termination).
- * Each segment corresponds to a contiguous group of bits from a
- * single fuse row. These segments are concatentated together in
- * order to form the full fuse parameter value. The segments for
- * a given parameter may correspond to different fuse rows.
- */
- static const struct cpr3_fuse_param
- msm8953_apss_ro_sel_param[MSM8953_APSS_FUSE_CORNERS][2] = {
- {{73, 12, 15}, {} },
- {{73, 8, 11}, {} },
- {{73, 4, 7}, {} },
- {{73, 0, 3}, {} },
- };
- static const struct cpr3_fuse_param
- msm8953_apss_init_voltage_param[MSM8953_APSS_FUSE_CORNERS][2] = {
- {{71, 24, 29}, {} },
- {{71, 18, 23}, {} },
- {{71, 12, 17}, {} },
- {{71, 6, 11}, {} },
- };
- static const struct cpr3_fuse_param
- msm8953_apss_target_quot_param[MSM8953_APSS_FUSE_CORNERS][2] = {
- {{72, 44, 55}, {} },
- {{72, 32, 43}, {} },
- {{72, 20, 31}, {} },
- {{72, 8, 19}, {} },
- };
- static const struct cpr3_fuse_param
- msm8953_apss_quot_offset_param[MSM8953_APSS_FUSE_CORNERS][2] = {
- {{} },
- {{71, 46, 52}, {} },
- {{71, 39, 45}, {} },
- {{71, 32, 38}, {} },
- };
- static const struct cpr3_fuse_param msm8953_cpr_fusing_rev_param[] = {
- {71, 53, 55},
- {},
- };
- static const struct cpr3_fuse_param msm8953_apss_speed_bin_param[] = {
- {36, 40, 42},
- {},
- };
- static const struct cpr3_fuse_param msm8953_apss_foundry_id_param[] = {
- {37, 40, 42},
- {},
- };
- static const struct cpr3_fuse_param msm8953_cpr_boost_fuse_cfg_param[] = {
- {36, 43, 45},
- {},
- };
- static const struct cpr3_fuse_param msm8953_apss_boost_fuse_volt_param[] = {
- {71, 0, 5},
- {},
- };
- static const struct cpr3_fuse_param msm8953_misc_fuse_volt_adj_param[] = {
- {36, 54, 54},
- {},
- };
- static const struct cpr3_fuse_param msm8953_apss_aging_init_quot_diff_param[]
- = {
- {72, 0, 7},
- {},
- };
- /*
- * SDM632 APSS fuse parameter locations:
- *
- * Structs are organized with the following dimensions:
- * Outer: 0 to 3 for fuse corners from lowest to highest corner
- * Inner: large enough to hold the longest set of parameter segments which
- * fully defines a fuse parameter, +1 (for NULL termination).
- * Each segment corresponds to a contiguous group of bits from a
- * single fuse row. These segments are concatentated together in
- * order to form the full fuse parameter value. The segments for
- * a given parameter may correspond to different fuse rows.
- */
- static const struct cpr3_fuse_param
- sdm632_apss_ro_sel_param[2][SDM632_POWER_APSS_FUSE_CORNERS][2] = {
- [CPR4_APSS_POWER_CLUSTER_ID] = {
- {{73, 28, 31}, {} },
- {{73, 20, 23}, {} },
- {{73, 16, 19}, {} },
- {{73, 12, 15}, {} },
- },
- [CPR4_APSS_PERF_CLUSTER_ID] = {
- {{73, 28, 31}, {} },
- {{73, 8, 11}, {} },
- {{73, 4, 7}, {} },
- {{73, 0, 3}, {} },
- },
- };
- static const struct cpr3_fuse_param
- sdm632_apss_init_voltage_param[2][SDM632_POWER_APSS_FUSE_CORNERS][2] = {
- [CPR4_APSS_POWER_CLUSTER_ID] = {
- {{74, 18, 23}, {} },
- {{71, 24, 29}, {} },
- {{74, 6, 11}, {} },
- {{74, 0, 5}, {} },
- },
- [CPR4_APSS_PERF_CLUSTER_ID] = {
- {{74, 18, 23}, {} },
- {{71, 18, 23}, {} },
- {{71, 12, 17}, {} },
- {{71, 6, 11}, {} },
- },
- };
- static const struct cpr3_fuse_param
- sdm632_apss_target_quot_param[2][SDM632_POWER_APSS_FUSE_CORNERS][2] = {
- [CPR4_APSS_POWER_CLUSTER_ID] = {
- {{75, 44, 55}, {} },
- {{72, 44, 55}, {} },
- {{75, 20, 31}, {} },
- {{75, 8, 19}, {} },
- },
- [CPR4_APSS_PERF_CLUSTER_ID] = {
- {{75, 44, 55}, {} },
- {{72, 32, 43}, {} },
- {{72, 20, 31}, {} },
- {{72, 8, 19}, {} },
- },
- };
- static const struct cpr3_fuse_param
- sdm632_apss_quot_offset_param[2][SDM632_POWER_APSS_FUSE_CORNERS][2] = {
- [CPR4_APSS_POWER_CLUSTER_ID] = {
- {{} },
- {{71, 46, 52}, {} },
- {{74, 32, 38}, {} },
- {{74, 24, 30}, {} },
- },
- [CPR4_APSS_PERF_CLUSTER_ID] = {
- {{} },
- {{74, 39, 45}, {} },
- {{71, 39, 45}, {} },
- {{71, 32, 38}, {} },
- },
- };
- /*
- * The maximum number of fuse combinations possible for the selected fuse
- * parameters in fuse combo map logic.
- * Here, possible speed-bin values = 8, fuse revision values = 8, and foundry
- * identifier values = 8. Total number of combinations = 512 (i.e., 8 * 8 * 8)
- */
- #define CPR4_APSS_FUSE_COMBO_MAP_MAX_COUNT 512
- /*
- * The number of possible values for misc fuse is
- * 2^(#bits defined for misc fuse)
- */
- #define MSM8953_MISC_FUSE_VAL_COUNT BIT(1)
- /*
- * Open loop voltage fuse reference voltages in microvolts for MSM8953
- */
- static const int msm8953_apss_fuse_ref_volt
- [MSM8953_APSS_FUSE_CORNERS] = {
- 645000,
- 720000,
- 865000,
- 1065000,
- };
- /*
- * Open loop voltage fuse reference voltages in microvolts for SDM632
- */
- static const int
- sdm632_apss_fuse_ref_volt[2][SDM632_POWER_APSS_FUSE_CORNERS] = {
- [CPR4_APSS_POWER_CLUSTER_ID] = {
- 645000,
- 790000,
- 865000,
- 1065000,
- },
- [CPR4_APSS_PERF_CLUSTER_ID] = {
- 645000,
- 790000,
- 865000,
- 1065000,
- },
- };
- #define CPR4_APSS_FUSE_STEP_VOLT 10000
- #define CPR4_APSS_VOLTAGE_FUSE_SIZE 6
- #define CPR4_APSS_QUOT_OFFSET_SCALE 5
- #define MSM8953_APSS_CPR_SENSOR_COUNT 13
- #define SDM632_APSS_CPR_SENSOR_COUNT 16
- #define SDM632_APSS_THREAD0_SENSOR_MIN 0
- #define SDM632_APSS_THREAD0_SENSOR_MAX 6
- #define SDM632_APSS_THREAD1_SENSOR_MIN 7
- #define SDM632_APSS_THREAD1_SENSOR_MAX 15
- #define CPR4_APSS_CPR_CLOCK_RATE 19200000
- #define MSM8953_APSS_MAX_TEMP_POINTS 3
- #define MSM8953_APSS_TEMP_SENSOR_ID_START 4
- #define MSM8953_APSS_TEMP_SENSOR_ID_END 13
- /*
- * Boost voltage fuse reference and ceiling voltages in microvolts for
- * MSM8953.
- */
- #define MSM8953_APSS_BOOST_FUSE_REF_VOLT 1140000
- #define MSM8953_APSS_BOOST_CEILING_VOLT 1140000
- #define MSM8953_APSS_BOOST_FLOOR_VOLT 900000
- #define MAX_BOOST_CONFIG_FUSE_VALUE 8
- #define MSM8953_APSS_CPR_SDELTA_CORE_COUNT 15
- /*
- * Array of integer values mapped to each of the boost config fuse values to
- * indicate boost enable/disable status.
- */
- static bool boost_fuse[MAX_BOOST_CONFIG_FUSE_VALUE] = {0, 1, 1, 1, 1, 1, 1, 1};
- /* CPR Aging parameters for msm8953 */
- #define MSM8953_APSS_AGING_INIT_QUOT_DIFF_SCALE 1
- #define MSM8953_APSS_AGING_INIT_QUOT_DIFF_SIZE 8
- #define MSM8953_APSS_AGING_SENSOR_ID 6
- /* Use a very high value for max aging margin to be applied */
- #define MSM8953_APSS_AGING_MAX_AGE_MARGIN_QUOT (-1000)
- /*
- * SOC IDs
- */
- enum soc_id {
- MSM8953_SOC_ID = 1,
- SDM632_SOC_ID = 2,
- };
- /**
- * cpr4_msm8953_apss_read_fuse_data() - load MSM8953 APSS specific fuse
- * parameter values
- * @vreg: Pointer to the CPR3 regulator
- * @fuse: APSS specific fuse data
- *
- * This function fills cpr4_apss_fuses struct with values read out of hardware
- * fuses.
- *
- * Return: 0 on success, errno on failure
- */
- static int cpr4_msm8953_apss_read_fuse_data(struct cpr3_regulator *vreg,
- struct cpr4_apss_fuses *fuse)
- {
- void __iomem *base = vreg->thread->ctrl->fuse_base;
- int i, rc;
- rc = cpr3_read_fuse_param(base, msm8953_misc_fuse_volt_adj_param,
- &fuse->misc);
- if (rc) {
- cpr3_err(vreg, "Unable to read misc voltage adjustment fuse, rc=%d\n",
- rc);
- return rc;
- }
- cpr3_info(vreg, "CPR misc fuse value = %llu\n", fuse->misc);
- if (fuse->misc >= MSM8953_MISC_FUSE_VAL_COUNT) {
- cpr3_err(vreg, "CPR misc fuse value = %llu, should be < %lu\n",
- fuse->misc, MSM8953_MISC_FUSE_VAL_COUNT);
- return -EINVAL;
- }
- rc = cpr3_read_fuse_param(base, msm8953_apss_aging_init_quot_diff_param,
- &fuse->aging_init_quot_diff);
- if (rc) {
- cpr3_err(vreg, "Unable to read aging initial quotient difference fuse, rc=%d\n",
- rc);
- return rc;
- }
- for (i = 0; i < MSM8953_APSS_FUSE_CORNERS; i++) {
- rc = cpr3_read_fuse_param(base,
- msm8953_apss_init_voltage_param[i],
- &fuse->init_voltage[i]);
- if (rc) {
- cpr3_err(vreg, "Unable to read fuse-corner %d initial voltage fuse, rc=%d\n",
- i, rc);
- return rc;
- }
- rc = cpr3_read_fuse_param(base,
- msm8953_apss_target_quot_param[i],
- &fuse->target_quot[i]);
- if (rc) {
- cpr3_err(vreg, "Unable to read fuse-corner %d target quotient fuse, rc=%d\n",
- i, rc);
- return rc;
- }
- rc = cpr3_read_fuse_param(base,
- msm8953_apss_ro_sel_param[i],
- &fuse->ro_sel[i]);
- if (rc) {
- cpr3_err(vreg, "Unable to read fuse-corner %d RO select fuse, rc=%d\n",
- i, rc);
- return rc;
- }
- rc = cpr3_read_fuse_param(base,
- msm8953_apss_quot_offset_param[i],
- &fuse->quot_offset[i]);
- if (rc) {
- cpr3_err(vreg, "Unable to read fuse-corner %d quotient offset fuse, rc=%d\n",
- i, rc);
- return rc;
- }
- }
- rc = cpr3_read_fuse_param(base, msm8953_cpr_boost_fuse_cfg_param,
- &fuse->boost_cfg);
- if (rc) {
- cpr3_err(vreg, "Unable to read CPR boost config fuse, rc=%d\n",
- rc);
- return rc;
- }
- cpr3_info(vreg, "Voltage boost fuse config = %llu boost = %s\n",
- fuse->boost_cfg, boost_fuse[fuse->boost_cfg]
- ? "enable" : "disable");
- rc = cpr3_read_fuse_param(base,
- msm8953_apss_boost_fuse_volt_param,
- &fuse->boost_voltage);
- if (rc) {
- cpr3_err(vreg, "failed to read boost fuse voltage, rc=%d\n",
- rc);
- return rc;
- }
- vreg->fuse_combo = fuse->cpr_fusing_rev + 8 * fuse->speed_bin;
- if (vreg->fuse_combo >= CPR4_MSM8953_APSS_FUSE_COMBO_COUNT) {
- cpr3_err(vreg, "invalid CPR fuse combo = %d found\n",
- vreg->fuse_combo);
- return -EINVAL;
- }
- return 0;
- }
- /**
- * cpr4_sdm632_apss_read_fuse_data() - load SDM632 APSS specific fuse
- * parameter values
- * @vreg: Pointer to the CPR3 regulator
- * @fuse: APSS specific fuse data
- *
- * This function fills cpr4_apss_fuses struct with values read out of hardware
- * fuses.
- *
- * Return: 0 on success, errno on failure
- */
- static int cpr4_sdm632_apss_read_fuse_data(struct cpr3_regulator *vreg,
- struct cpr4_apss_fuses *fuse)
- {
- void __iomem *base = vreg->thread->ctrl->fuse_base;
- int i, id, rc, fuse_corners;
- id = vreg->thread->thread_id;
- if (id == CPR4_APSS_POWER_CLUSTER_ID)
- fuse_corners = SDM632_POWER_APSS_FUSE_CORNERS;
- else
- fuse_corners = SDM632_PERF_APSS_FUSE_CORNERS;
- for (i = 0; i < fuse_corners; i++) {
- rc = cpr3_read_fuse_param(base,
- sdm632_apss_init_voltage_param[id][i],
- &fuse->init_voltage[i]);
- if (rc) {
- cpr3_err(vreg, "Unable to read fuse-corner %d initial voltage fuse, rc=%d\n",
- i, rc);
- return rc;
- }
- rc = cpr3_read_fuse_param(base,
- sdm632_apss_target_quot_param[id][i],
- &fuse->target_quot[i]);
- if (rc) {
- cpr3_err(vreg, "Unable to read fuse-corner %d target quotient fuse, rc=%d\n",
- i, rc);
- return rc;
- }
- rc = cpr3_read_fuse_param(base,
- sdm632_apss_ro_sel_param[id][i],
- &fuse->ro_sel[i]);
- if (rc) {
- cpr3_err(vreg, "Unable to read fuse-corner %d RO select fuse, rc=%d\n",
- i, rc);
- return rc;
- }
- rc = cpr3_read_fuse_param(base,
- sdm632_apss_quot_offset_param[id][i],
- &fuse->quot_offset[i]);
- if (rc) {
- cpr3_err(vreg, "Unable to read fuse-corner %d quotient offset fuse, rc=%d\n",
- i, rc);
- return rc;
- }
- }
- vreg->fuse_combo = fuse->cpr_fusing_rev + (8 * fuse->speed_bin);
- if (vreg->fuse_combo >= CPR4_SDM632_APSS_FUSE_COMBO_COUNT) {
- cpr3_err(vreg, "invalid CPR fuse combo = %d found\n",
- vreg->fuse_combo);
- return -EINVAL;
- }
- return 0;
- }
- /**
- * cpr4_apss_read_fuse_data() - load APSS specific fuse parameter values
- * @vreg: Pointer to the CPR3 regulator
- *
- * This function allocates a cpr4_apss_fuses struct, fills it with
- * values read out of hardware fuses, and finally copies common fuse values
- * into the CPR3 regulator struct.
- *
- * Return: 0 on success, errno on failure
- */
- static int cpr4_apss_read_fuse_data(struct cpr3_regulator *vreg)
- {
- void __iomem *base = vreg->thread->ctrl->fuse_base;
- struct cpr4_apss_fuses *fuse;
- int rc, fuse_corners;
- enum soc_id soc_revision;
- fuse = devm_kzalloc(vreg->thread->ctrl->dev, sizeof(*fuse), GFP_KERNEL);
- if (!fuse)
- return -ENOMEM;
- soc_revision = vreg->thread->ctrl->soc_revision;
- switch (soc_revision) {
- case MSM8953_SOC_ID:
- fuse_corners = MSM8953_APSS_FUSE_CORNERS;
- break;
- case SDM632_SOC_ID:
- if (vreg->thread->thread_id == CPR4_APSS_POWER_CLUSTER_ID)
- fuse_corners = SDM632_POWER_APSS_FUSE_CORNERS;
- else
- fuse_corners = SDM632_PERF_APSS_FUSE_CORNERS;
- break;
- default:
- cpr3_err(vreg, "unsupported soc id = %d\n", soc_revision);
- return -EINVAL;
- }
- fuse->ro_sel = devm_kcalloc(vreg->thread->ctrl->dev, fuse_corners,
- sizeof(*fuse->ro_sel), GFP_KERNEL);
- fuse->init_voltage = devm_kcalloc(vreg->thread->ctrl->dev, fuse_corners,
- sizeof(*fuse->init_voltage), GFP_KERNEL);
- fuse->target_quot = devm_kcalloc(vreg->thread->ctrl->dev, fuse_corners,
- sizeof(*fuse->target_quot), GFP_KERNEL);
- fuse->quot_offset = devm_kcalloc(vreg->thread->ctrl->dev, fuse_corners,
- sizeof(*fuse->quot_offset), GFP_KERNEL);
- if (!fuse->ro_sel || !fuse->init_voltage || !fuse->target_quot
- || !fuse->quot_offset)
- return -ENOMEM;
- rc = cpr3_read_fuse_param(base, msm8953_apss_speed_bin_param,
- &fuse->speed_bin);
- if (rc) {
- cpr3_err(vreg, "Unable to read speed bin fuse, rc=%d\n", rc);
- return rc;
- }
- rc = cpr3_read_fuse_param(base, msm8953_cpr_fusing_rev_param,
- &fuse->cpr_fusing_rev);
- if (rc) {
- cpr3_err(vreg, "Unable to read CPR fusing revision fuse, rc=%d\n",
- rc);
- return rc;
- }
- rc = cpr3_read_fuse_param(base, msm8953_apss_foundry_id_param,
- &fuse->foundry_id);
- if (rc) {
- cpr3_err(vreg, "Unable to read foundry id fuse, rc=%d\n", rc);
- return rc;
- }
- cpr3_info(vreg, "speed bin = %llu, CPR fusing revision = %llu, foundry id = %llu\n",
- fuse->speed_bin, fuse->cpr_fusing_rev,
- fuse->foundry_id);
- switch (soc_revision) {
- case MSM8953_SOC_ID:
- rc = cpr4_msm8953_apss_read_fuse_data(vreg, fuse);
- if (rc) {
- cpr3_err(vreg, "msm8953 apss fuse data read failed, rc=%d\n",
- rc);
- return rc;
- }
- break;
- case SDM632_SOC_ID:
- rc = cpr4_sdm632_apss_read_fuse_data(vreg, fuse);
- if (rc) {
- cpr3_err(vreg, "sdm632 apss fuse data read failed, rc=%d\n",
- rc);
- return rc;
- }
- break;
- default:
- cpr3_err(vreg, "unsupported soc id = %d\n", soc_revision);
- return -EINVAL;
- }
- vreg->speed_bin_fuse = fuse->speed_bin;
- vreg->cpr_rev_fuse = fuse->cpr_fusing_rev;
- vreg->fuse_corner_count = fuse_corners;
- vreg->platform_fuses = fuse;
- return 0;
- }
- /**
- * cpr4_apss_parse_corner_data() - parse APSS corner data from device tree
- * properties of the CPR3 regulator's device node
- * @vreg: Pointer to the CPR3 regulator
- *
- * Return: 0 on success, errno on failure
- */
- static int cpr4_apss_parse_corner_data(struct cpr3_regulator *vreg)
- {
- int rc;
- rc = cpr3_parse_common_corner_data(vreg);
- if (rc) {
- cpr3_err(vreg, "error reading corner data, rc=%d\n", rc);
- return rc;
- }
- return rc;
- }
- /**
- * cpr4_apss_parse_misc_fuse_voltage_adjustments() - fill an array from a
- * portion of the voltage adjustments specified based on
- * miscellaneous fuse bits.
- * @vreg: Pointer to the CPR3 regulator
- * @volt_adjust: Voltage adjustment output data array which must be
- * of size vreg->corner_count
- *
- * cpr3_parse_common_corner_data() must be called for vreg before this function
- * is called so that speed bin size elements are initialized.
- *
- * Two formats are supported for the device tree property:
- * 1. Length == tuple_list_size * vreg->corner_count
- * (reading begins at index 0)
- * 2. Length == tuple_list_size * vreg->speed_bin_corner_sum
- * (reading begins at index tuple_list_size * vreg->speed_bin_offset)
- *
- * Here, tuple_list_size is the number of possible values for misc fuse.
- * All other property lengths are treated as errors.
- *
- * Return: 0 on success, errno on failure
- */
- static int cpr4_apss_parse_misc_fuse_voltage_adjustments(
- struct cpr3_regulator *vreg, u32 *volt_adjust)
- {
- struct device_node *node = vreg->of_node;
- struct cpr4_apss_fuses *fuse = vreg->platform_fuses;
- int tuple_list_size = MSM8953_MISC_FUSE_VAL_COUNT;
- int i, offset, rc, len = 0;
- const char *prop_name = "qcom,cpr-misc-fuse-voltage-adjustment";
- if (!of_find_property(node, prop_name, &len)) {
- cpr3_err(vreg, "property %s is missing\n", prop_name);
- return -EINVAL;
- }
- if (len == tuple_list_size * vreg->corner_count * sizeof(u32)) {
- offset = 0;
- } else if (vreg->speed_bin_corner_sum > 0 &&
- len == tuple_list_size * vreg->speed_bin_corner_sum
- * sizeof(u32)) {
- offset = tuple_list_size * vreg->speed_bin_offset
- + fuse->misc * vreg->corner_count;
- } else {
- if (vreg->speed_bin_corner_sum > 0)
- cpr3_err(vreg, "property %s has invalid length=%d, should be %zu or %zu\n",
- prop_name, len,
- tuple_list_size * vreg->corner_count
- * sizeof(u32),
- tuple_list_size * vreg->speed_bin_corner_sum
- * sizeof(u32));
- else
- cpr3_err(vreg, "property %s has invalid length=%d, should be %zu\n",
- prop_name, len,
- tuple_list_size * vreg->corner_count
- * sizeof(u32));
- return -EINVAL;
- }
- for (i = 0; i < vreg->corner_count; i++) {
- rc = of_property_read_u32_index(node, prop_name, offset + i,
- &volt_adjust[i]);
- if (rc) {
- cpr3_err(vreg, "error reading property %s, rc=%d\n",
- prop_name, rc);
- return rc;
- }
- }
- return 0;
- }
- /**
- * cpr4_apss_calculate_open_loop_voltages() - calculate the open-loop
- * voltage for each corner of a CPR3 regulator
- * @vreg: Pointer to the CPR3 regulator
- *
- * If open-loop voltage interpolation is allowed in device tree, then
- * this function calculates the open-loop voltage for a given corner using
- * linear interpolation. This interpolation is performed using the processor
- * frequencies of the lower and higher Fmax corners along with their fused
- * open-loop voltages.
- *
- * If open-loop voltage interpolation is not allowed, then this function uses
- * the Fmax fused open-loop voltage for all of the corners associated with a
- * given fuse corner.
- *
- * Return: 0 on success, errno on failure
- */
- static int cpr4_apss_calculate_open_loop_voltages(struct cpr3_regulator *vreg)
- {
- struct device_node *node = vreg->of_node;
- struct cpr4_apss_fuses *fuse = vreg->platform_fuses;
- int i, j, id, rc = 0;
- bool allow_interpolation;
- u64 freq_low, volt_low, freq_high, volt_high;
- const int *ref_volt;
- int *fuse_volt, *misc_adj_volt;
- int *fmax_corner;
- const char * const *corner_name;
- enum soc_id soc_revision;
- fuse_volt = kcalloc(vreg->fuse_corner_count, sizeof(*fuse_volt),
- GFP_KERNEL);
- fmax_corner = kcalloc(vreg->fuse_corner_count, sizeof(*fmax_corner),
- GFP_KERNEL);
- if (!fuse_volt || !fmax_corner) {
- rc = -ENOMEM;
- goto done;
- }
- id = vreg->thread->thread_id;
- soc_revision = vreg->thread->ctrl->soc_revision;
- switch (soc_revision) {
- case MSM8953_SOC_ID:
- ref_volt = msm8953_apss_fuse_ref_volt;
- corner_name = cpr4_msm8953_apss_fuse_corner_name;
- break;
- case SDM632_SOC_ID:
- ref_volt = sdm632_apss_fuse_ref_volt[id];
- if (id == CPR4_APSS_POWER_CLUSTER_ID)
- corner_name = cpr4_sdm632_power_apss_fuse_corner_name;
- else
- corner_name = cpr4_sdm632_perf_apss_fuse_corner_name;
- break;
- default:
- cpr3_err(vreg, "unsupported soc id = %d\n", soc_revision);
- rc = -EINVAL;
- goto done;
- }
- for (i = 0; i < vreg->fuse_corner_count; i++) {
- fuse_volt[i] = cpr3_convert_open_loop_voltage_fuse(ref_volt[i],
- CPR4_APSS_FUSE_STEP_VOLT, fuse->init_voltage[i],
- CPR4_APSS_VOLTAGE_FUSE_SIZE);
- /* Log fused open-loop voltage values for debugging purposes. */
- cpr3_info(vreg, "fused %8s: open-loop=%7d uV\n", corner_name[i],
- fuse_volt[i]);
- }
- rc = cpr3_adjust_fused_open_loop_voltages(vreg, fuse_volt);
- if (rc) {
- cpr3_err(vreg, "fused open-loop voltage adjustment failed, rc=%d\n",
- rc);
- goto done;
- }
- allow_interpolation = of_property_read_bool(node,
- "qcom,allow-voltage-interpolation");
- for (i = 1; i < vreg->fuse_corner_count; i++) {
- if (fuse_volt[i] < fuse_volt[i - 1]) {
- cpr3_info(vreg, "fuse corner %d voltage=%d uV < fuse corner %d voltage=%d uV; overriding: fuse corner %d voltage=%d\n",
- i, fuse_volt[i], i - 1, fuse_volt[i - 1],
- i, fuse_volt[i - 1]);
- fuse_volt[i] = fuse_volt[i - 1];
- }
- }
- if (!allow_interpolation) {
- /* Use fused open-loop voltage for lower frequencies. */
- for (i = 0; i < vreg->corner_count; i++)
- vreg->corner[i].open_loop_volt
- = fuse_volt[vreg->corner[i].cpr_fuse_corner];
- goto done;
- }
- /* Determine highest corner mapped to each fuse corner */
- j = vreg->fuse_corner_count - 1;
- for (i = vreg->corner_count - 1; i >= 0; i--) {
- if (vreg->corner[i].cpr_fuse_corner == j) {
- fmax_corner[j] = i;
- j--;
- }
- }
- if (j >= 0) {
- cpr3_err(vreg, "invalid fuse corner mapping\n");
- rc = -EINVAL;
- goto done;
- }
- /*
- * Interpolation is not possible for corners mapped to the lowest fuse
- * corner so use the fuse corner value directly.
- */
- for (i = 0; i <= fmax_corner[0]; i++)
- vreg->corner[i].open_loop_volt = fuse_volt[0];
- /* Interpolate voltages for the higher fuse corners. */
- for (i = 1; i < vreg->fuse_corner_count; i++) {
- freq_low = vreg->corner[fmax_corner[i - 1]].proc_freq;
- volt_low = fuse_volt[i - 1];
- freq_high = vreg->corner[fmax_corner[i]].proc_freq;
- volt_high = fuse_volt[i];
- for (j = fmax_corner[i - 1] + 1; j <= fmax_corner[i]; j++)
- vreg->corner[j].open_loop_volt = cpr3_interpolate(
- freq_low, volt_low, freq_high, volt_high,
- vreg->corner[j].proc_freq);
- }
- done:
- if (rc == 0) {
- cpr3_debug(vreg, "unadjusted per-corner open-loop voltages:\n");
- for (i = 0; i < vreg->corner_count; i++)
- cpr3_debug(vreg, "open-loop[%2d] = %d uV\n", i,
- vreg->corner[i].open_loop_volt);
- rc = cpr3_adjust_open_loop_voltages(vreg);
- if (rc)
- cpr3_err(vreg, "open-loop voltage adjustment failed, rc=%d\n",
- rc);
- if (of_find_property(node,
- "qcom,cpr-misc-fuse-voltage-adjustment",
- NULL)) {
- misc_adj_volt = kcalloc(vreg->corner_count,
- sizeof(*misc_adj_volt), GFP_KERNEL);
- if (!misc_adj_volt) {
- rc = -ENOMEM;
- goto _exit;
- }
- rc = cpr4_apss_parse_misc_fuse_voltage_adjustments(vreg,
- misc_adj_volt);
- if (rc) {
- cpr3_err(vreg, "qcom,cpr-misc-fuse-voltage-adjustment reading failed, rc=%d\n",
- rc);
- kfree(misc_adj_volt);
- goto _exit;
- }
- for (i = 0; i < vreg->corner_count; i++)
- vreg->corner[i].open_loop_volt
- += misc_adj_volt[i];
- kfree(misc_adj_volt);
- }
- }
- _exit:
- kfree(fuse_volt);
- kfree(fmax_corner);
- return rc;
- }
- /**
- * cpr4_msm8953_apss_set_no_interpolation_quotients() - use the fused target
- * quotient values for lower frequencies.
- * @vreg: Pointer to the CPR3 regulator
- * @volt_adjust: Pointer to array of per-corner closed-loop adjustment
- * voltages
- * @volt_adjust_fuse: Pointer to array of per-fuse-corner closed-loop
- * adjustment voltages
- * @ro_scale: Pointer to array of per-fuse-corner RO scaling factor
- * values with units of QUOT/V
- *
- * Return: 0 on success, errno on failure
- */
- static int cpr4_msm8953_apss_set_no_interpolation_quotients(
- struct cpr3_regulator *vreg, int *volt_adjust,
- int *volt_adjust_fuse, int *ro_scale)
- {
- struct cpr4_apss_fuses *fuse = vreg->platform_fuses;
- u32 quot, ro;
- int quot_adjust;
- int i, fuse_corner;
- for (i = 0; i < vreg->corner_count; i++) {
- fuse_corner = vreg->corner[i].cpr_fuse_corner;
- quot = fuse->target_quot[fuse_corner];
- quot_adjust = cpr3_quot_adjustment(ro_scale[fuse_corner],
- volt_adjust_fuse[fuse_corner] +
- volt_adjust[i]);
- ro = fuse->ro_sel[fuse_corner];
- vreg->corner[i].target_quot[ro] = quot + quot_adjust;
- cpr3_debug(vreg, "corner=%d RO=%u target quot=%u\n",
- i, ro, quot);
- if (quot_adjust)
- cpr3_debug(vreg, "adjusted corner %d RO%u target quot: %u --> %u (%d uV)\n",
- i, ro, quot, vreg->corner[i].target_quot[ro],
- volt_adjust_fuse[fuse_corner] +
- volt_adjust[i]);
- }
- return 0;
- }
- /**
- * cpr4_apss_calculate_target_quotients() - calculate the CPR target
- * quotient for each corner of a CPR3 regulator
- * @vreg: Pointer to the CPR3 regulator
- *
- * If target quotient interpolation is allowed in device tree, then this
- * function calculates the target quotient for a given corner using linear
- * interpolation. This interpolation is performed using the processor
- * frequencies of the lower and higher Fmax corners along with the fused
- * target quotient and quotient offset of the higher Fmax corner.
- *
- * If target quotient interpolation is not allowed, then this function uses
- * the Fmax fused target quotient for all of the corners associated with a
- * given fuse corner.
- *
- * Return: 0 on success, errno on failure
- */
- static int cpr4_apss_calculate_target_quotients(struct cpr3_regulator *vreg)
- {
- struct cpr4_apss_fuses *fuse = vreg->platform_fuses;
- int rc;
- bool allow_interpolation;
- u64 freq_low, freq_high, prev_quot;
- u64 *quot_low;
- u64 *quot_high;
- u32 quot, ro;
- int i, j, fuse_corner, quot_adjust;
- int *fmax_corner;
- int *volt_adjust, *volt_adjust_fuse, *ro_scale;
- int *voltage_adj_misc;
- int lowest_fuse_corner, highest_fuse_corner;
- const char * const *corner_name;
- switch (vreg->thread->ctrl->soc_revision) {
- case MSM8953_SOC_ID:
- corner_name = cpr4_msm8953_apss_fuse_corner_name;
- lowest_fuse_corner = CPR4_MSM8953_APSS_FUSE_CORNER_LOWSVS;
- highest_fuse_corner = CPR4_MSM8953_APSS_FUSE_CORNER_TURBO_L1;
- break;
- case SDM632_SOC_ID:
- if (vreg->thread->thread_id == CPR4_APSS_POWER_CLUSTER_ID) {
- corner_name = cpr4_sdm632_power_apss_fuse_corner_name;
- lowest_fuse_corner =
- CPR4_SDM632_POWER_APSS_FUSE_CORNER_LOWSVS;
- highest_fuse_corner =
- CPR4_SDM632_POWER_APSS_FUSE_CORNER_TURBO_L1;
- } else {
- corner_name = cpr4_sdm632_perf_apss_fuse_corner_name;
- lowest_fuse_corner =
- CPR4_SDM632_PERF_APSS_FUSE_CORNER_LOWSVS;
- highest_fuse_corner =
- CPR4_SDM632_PERF_APSS_FUSE_CORNER_TURBO_L1;
- }
- break;
- default:
- cpr3_err(vreg, "unsupported soc id = %d\n",
- vreg->thread->ctrl->soc_revision);
- return -EINVAL;
- }
- /* Log fused quotient values for debugging purposes. */
- cpr3_info(vreg, "fused %8s: quot[%2llu]=%4llu\n",
- corner_name[lowest_fuse_corner],
- fuse->ro_sel[lowest_fuse_corner],
- fuse->target_quot[lowest_fuse_corner]);
- for (i = lowest_fuse_corner + 1; i <= highest_fuse_corner; i++)
- cpr3_info(vreg, "fused %8s: quot[%2llu]=%4llu, quot_offset[%2llu]=%4llu\n",
- corner_name[i], fuse->ro_sel[i], fuse->target_quot[i],
- fuse->ro_sel[i], fuse->quot_offset[i] *
- CPR4_APSS_QUOT_OFFSET_SCALE);
- allow_interpolation = of_property_read_bool(vreg->of_node,
- "qcom,allow-quotient-interpolation");
- volt_adjust = kcalloc(vreg->corner_count, sizeof(*volt_adjust),
- GFP_KERNEL);
- volt_adjust_fuse = kcalloc(vreg->fuse_corner_count,
- sizeof(*volt_adjust_fuse), GFP_KERNEL);
- ro_scale = kcalloc(vreg->fuse_corner_count, sizeof(*ro_scale),
- GFP_KERNEL);
- fmax_corner = kcalloc(vreg->fuse_corner_count, sizeof(*fmax_corner),
- GFP_KERNEL);
- quot_low = kcalloc(vreg->fuse_corner_count, sizeof(*quot_low),
- GFP_KERNEL);
- quot_high = kcalloc(vreg->fuse_corner_count, sizeof(*quot_high),
- GFP_KERNEL);
- if (!volt_adjust || !volt_adjust_fuse || !ro_scale ||
- !fmax_corner || !quot_low || !quot_high) {
- rc = -ENOMEM;
- goto done;
- }
- rc = cpr3_parse_closed_loop_voltage_adjustments(vreg, &fuse->ro_sel[0],
- volt_adjust, volt_adjust_fuse, ro_scale);
- if (rc) {
- cpr3_err(vreg, "could not load closed-loop voltage adjustments, rc=%d\n",
- rc);
- goto done;
- }
- if (of_find_property(vreg->of_node,
- "qcom,cpr-misc-fuse-voltage-adjustment", NULL)) {
- voltage_adj_misc = kcalloc(vreg->corner_count,
- sizeof(*voltage_adj_misc), GFP_KERNEL);
- if (!voltage_adj_misc) {
- rc = -ENOMEM;
- goto done;
- }
- rc = cpr4_apss_parse_misc_fuse_voltage_adjustments(vreg,
- voltage_adj_misc);
- if (rc) {
- cpr3_err(vreg, "qcom,cpr-misc-fuse-voltage-adjustment reading failed, rc=%d\n",
- rc);
- kfree(voltage_adj_misc);
- goto done;
- }
- for (i = 0; i < vreg->corner_count; i++)
- volt_adjust[i] += voltage_adj_misc[i];
- kfree(voltage_adj_misc);
- }
- if (!allow_interpolation) {
- /* Use fused target quotients for lower frequencies. */
- return cpr4_msm8953_apss_set_no_interpolation_quotients(
- vreg, volt_adjust, volt_adjust_fuse, ro_scale);
- }
- /* Determine highest corner mapped to each fuse corner */
- j = vreg->fuse_corner_count - 1;
- for (i = vreg->corner_count - 1; i >= 0; i--) {
- if (vreg->corner[i].cpr_fuse_corner == j) {
- fmax_corner[j] = i;
- j--;
- }
- }
- if (j >= 0) {
- cpr3_err(vreg, "invalid fuse corner mapping\n");
- rc = -EINVAL;
- goto done;
- }
- /*
- * Interpolation is not possible for corners mapped to the lowest fuse
- * corner so use the fuse corner value directly.
- */
- i = lowest_fuse_corner;
- quot_adjust = cpr3_quot_adjustment(ro_scale[i], volt_adjust_fuse[i]);
- quot = fuse->target_quot[i] + quot_adjust;
- quot_high[i] = quot_low[i] = quot;
- ro = fuse->ro_sel[i];
- if (quot_adjust)
- cpr3_debug(vreg, "adjusted fuse corner %d RO%u target quot: %llu --> %u (%d uV)\n",
- i, ro, fuse->target_quot[i], quot, volt_adjust_fuse[i]);
- for (i = 0; i <= fmax_corner[lowest_fuse_corner]; i++)
- vreg->corner[i].target_quot[ro] = quot;
- for (i = lowest_fuse_corner + 1; i < vreg->fuse_corner_count; i++) {
- quot_high[i] = fuse->target_quot[i];
- if (fuse->ro_sel[i] == fuse->ro_sel[i - 1])
- quot_low[i] = quot_high[i - 1];
- else
- quot_low[i] = quot_high[i]
- - fuse->quot_offset[i]
- * CPR4_APSS_QUOT_OFFSET_SCALE;
- if (quot_high[i] < quot_low[i]) {
- cpr3_debug(vreg, "quot_high[%d]=%llu < quot_low[%d]=%llu; overriding: quot_high[%d]=%llu\n",
- i, quot_high[i], i, quot_low[i],
- i, quot_low[i]);
- quot_high[i] = quot_low[i];
- }
- }
- /* Perform per-fuse-corner target quotient adjustment */
- for (i = 1; i < vreg->fuse_corner_count; i++) {
- quot_adjust = cpr3_quot_adjustment(ro_scale[i],
- volt_adjust_fuse[i]);
- if (quot_adjust) {
- prev_quot = quot_high[i];
- quot_high[i] += quot_adjust;
- cpr3_debug(vreg, "adjusted fuse corner %d RO%llu target quot: %llu --> %llu (%d uV)\n",
- i, fuse->ro_sel[i], prev_quot, quot_high[i],
- volt_adjust_fuse[i]);
- }
- if (fuse->ro_sel[i] == fuse->ro_sel[i - 1])
- quot_low[i] = quot_high[i - 1];
- else
- quot_low[i] += cpr3_quot_adjustment(ro_scale[i],
- volt_adjust_fuse[i - 1]);
- if (quot_high[i] < quot_low[i]) {
- cpr3_debug(vreg, "quot_high[%d]=%llu < quot_low[%d]=%llu after adjustment; overriding: quot_high[%d]=%llu\n",
- i, quot_high[i], i, quot_low[i],
- i, quot_low[i]);
- quot_high[i] = quot_low[i];
- }
- }
- /* Interpolate voltages for the higher fuse corners. */
- for (i = 1; i < vreg->fuse_corner_count; i++) {
- freq_low = vreg->corner[fmax_corner[i - 1]].proc_freq;
- freq_high = vreg->corner[fmax_corner[i]].proc_freq;
- ro = fuse->ro_sel[i];
- for (j = fmax_corner[i - 1] + 1; j <= fmax_corner[i]; j++)
- vreg->corner[j].target_quot[ro] = cpr3_interpolate(
- freq_low, quot_low[i], freq_high, quot_high[i],
- vreg->corner[j].proc_freq);
- }
- /* Perform per-corner target quotient adjustment */
- for (i = 0; i < vreg->corner_count; i++) {
- fuse_corner = vreg->corner[i].cpr_fuse_corner;
- ro = fuse->ro_sel[fuse_corner];
- quot_adjust = cpr3_quot_adjustment(ro_scale[fuse_corner],
- volt_adjust[i]);
- if (quot_adjust) {
- prev_quot = vreg->corner[i].target_quot[ro];
- vreg->corner[i].target_quot[ro] += quot_adjust;
- cpr3_debug(vreg, "adjusted corner %d RO%u target quot: %llu --> %u (%d uV)\n",
- i, ro, prev_quot,
- vreg->corner[i].target_quot[ro],
- volt_adjust[i]);
- }
- }
- /* Ensure that target quotients increase monotonically */
- for (i = 1; i < vreg->corner_count; i++) {
- ro = fuse->ro_sel[vreg->corner[i].cpr_fuse_corner];
- if (fuse->ro_sel[vreg->corner[i - 1].cpr_fuse_corner] == ro
- && vreg->corner[i].target_quot[ro]
- < vreg->corner[i - 1].target_quot[ro]) {
- cpr3_debug(vreg, "adjusted corner %d RO%u target quot=%u < adjusted corner %d RO%u target quot=%u; overriding: corner %d RO%u target quot=%u\n",
- i, ro, vreg->corner[i].target_quot[ro],
- i - 1, ro, vreg->corner[i - 1].target_quot[ro],
- i, ro, vreg->corner[i - 1].target_quot[ro]);
- vreg->corner[i].target_quot[ro]
- = vreg->corner[i - 1].target_quot[ro];
- }
- }
- done:
- kfree(volt_adjust);
- kfree(volt_adjust_fuse);
- kfree(ro_scale);
- kfree(fmax_corner);
- kfree(quot_low);
- kfree(quot_high);
- return rc;
- }
- /**
- * cpr4_apss_print_settings() - print out APSS CPR configuration settings into
- * the kernel log for debugging purposes
- * @vreg: Pointer to the CPR3 regulator
- */
- static void cpr4_apss_print_settings(struct cpr3_regulator *vreg)
- {
- struct cpr3_corner *corner;
- int i;
- cpr3_debug(vreg, "Corner: Frequency (Hz), Fuse Corner, Floor (uV), Open-Loop (uV), Ceiling (uV)\n");
- for (i = 0; i < vreg->corner_count; i++) {
- corner = &vreg->corner[i];
- cpr3_debug(vreg, "%3d: %10u, %2d, %7d, %7d, %7d\n",
- i, corner->proc_freq, corner->cpr_fuse_corner,
- corner->floor_volt, corner->open_loop_volt,
- corner->ceiling_volt);
- }
- if (vreg->thread->ctrl->apm)
- cpr3_debug(vreg, "APM threshold = %d uV, APM adjust = %d uV\n",
- vreg->thread->ctrl->apm_threshold_volt,
- vreg->thread->ctrl->apm_adj_volt);
- }
- /**
- * cpr4_apss_init_thread() - perform steps necessary to initialize the
- * configuration data for a CPR3 thread
- * @thread: Pointer to the CPR3 thread
- *
- * Return: 0 on success, errno on failure
- */
- static int cpr4_apss_init_thread(struct cpr3_thread *thread)
- {
- int rc;
- rc = cpr3_parse_common_thread_data(thread);
- if (rc) {
- cpr3_err(thread->ctrl, "thread %u unable to read CPR thread data from device tree, rc=%d\n",
- thread->thread_id, rc);
- return rc;
- }
- return 0;
- }
- /**
- * cpr4_apss_parse_temp_adj_properties() - parse temperature based
- * adjustment properties from device tree.
- * @ctrl: Pointer to the CPR3 controller
- *
- * Return: 0 on success, errno on failure
- */
- static int cpr4_apss_parse_temp_adj_properties(struct cpr3_controller *ctrl)
- {
- struct device_node *of_node = ctrl->dev->of_node;
- int rc, i, len, temp_point_count;
- if (!of_find_property(of_node, "qcom,cpr-temp-point-map", &len)) {
- /*
- * Temperature based adjustments are not defined. Single
- * temperature band is still valid for per-online-core
- * adjustments.
- */
- ctrl->temp_band_count = 1;
- return 0;
- }
- temp_point_count = len / sizeof(u32);
- if (temp_point_count <= 0
- || temp_point_count > MSM8953_APSS_MAX_TEMP_POINTS) {
- cpr3_err(ctrl, "invalid number of temperature points %d > %d (max)\n",
- temp_point_count, MSM8953_APSS_MAX_TEMP_POINTS);
- return -EINVAL;
- }
- ctrl->temp_points = devm_kcalloc(ctrl->dev, temp_point_count,
- sizeof(*ctrl->temp_points), GFP_KERNEL);
- if (!ctrl->temp_points)
- return -ENOMEM;
- rc = of_property_read_u32_array(of_node, "qcom,cpr-temp-point-map",
- ctrl->temp_points, temp_point_count);
- if (rc) {
- cpr3_err(ctrl, "error reading property qcom,cpr-temp-point-map, rc=%d\n",
- rc);
- return rc;
- }
- for (i = 0; i < temp_point_count; i++)
- cpr3_debug(ctrl, "Temperature Point %d=%d\n", i,
- ctrl->temp_points[i]);
- /*
- * If t1, t2, and t3 are the temperature points, then the temperature
- * bands are: (-inf, t1], (t1, t2], (t2, t3], and (t3, inf).
- */
- ctrl->temp_band_count = temp_point_count + 1;
- cpr3_debug(ctrl, "Number of temp bands =%d\n", ctrl->temp_band_count);
- rc = of_property_read_u32(of_node, "qcom,cpr-initial-temp-band",
- &ctrl->initial_temp_band);
- if (rc) {
- cpr3_err(ctrl, "error reading qcom,cpr-initial-temp-band, rc=%d\n",
- rc);
- return rc;
- }
- if (ctrl->initial_temp_band >= ctrl->temp_band_count) {
- cpr3_err(ctrl, "Initial temperature band value %d should be in range [0 - %d]\n",
- ctrl->initial_temp_band, ctrl->temp_band_count - 1);
- return -EINVAL;
- }
- ctrl->temp_sensor_id_start = MSM8953_APSS_TEMP_SENSOR_ID_START;
- ctrl->temp_sensor_id_end = MSM8953_APSS_TEMP_SENSOR_ID_END;
- ctrl->allow_temp_adj = true;
- return rc;
- }
- /**
- * cpr4_apss_parse_boost_properties() - parse configuration data for boost
- * voltage adjustment for CPR3 regulator from device tree.
- * @vreg: Pointer to the CPR3 regulator
- *
- * Return: 0 on success, errno on failure
- */
- static int cpr4_apss_parse_boost_properties(struct cpr3_regulator *vreg)
- {
- struct cpr3_controller *ctrl = vreg->thread->ctrl;
- struct cpr4_apss_fuses *fuse = vreg->platform_fuses;
- struct cpr3_corner *corner;
- int i, boost_voltage, final_boost_volt, rc = 0;
- int *boost_table = NULL, *boost_temp_adj = NULL;
- int boost_voltage_adjust = 0, boost_num_cores = 0;
- u32 boost_allowed = 0;
- if (!boost_fuse[fuse->boost_cfg])
- /* Voltage boost is disabled in fuse */
- return 0;
- if (of_find_property(vreg->of_node, "qcom,allow-boost", NULL)) {
- rc = cpr3_parse_array_property(vreg, "qcom,allow-boost", 1,
- &boost_allowed);
- if (rc)
- return rc;
- }
- if (!boost_allowed) {
- /* Voltage boost is not enabled for this regulator */
- return 0;
- }
- boost_voltage = cpr3_convert_open_loop_voltage_fuse(
- MSM8953_APSS_BOOST_FUSE_REF_VOLT,
- CPR4_APSS_FUSE_STEP_VOLT,
- fuse->boost_voltage,
- CPR4_APSS_VOLTAGE_FUSE_SIZE);
- /* Log boost voltage value for debugging purposes. */
- cpr3_info(vreg, "Boost open-loop=%7d uV\n", boost_voltage);
- if (of_find_property(vreg->of_node,
- "qcom,cpr-boost-voltage-fuse-adjustment", NULL)) {
- rc = cpr3_parse_array_property(vreg,
- "qcom,cpr-boost-voltage-fuse-adjustment",
- 1, &boost_voltage_adjust);
- if (rc) {
- cpr3_err(vreg, "qcom,cpr-boost-voltage-fuse-adjustment reading failed, rc=%d\n",
- rc);
- return rc;
- }
- boost_voltage += boost_voltage_adjust;
- /* Log boost voltage value for debugging purposes. */
- cpr3_info(vreg, "Adjusted boost open-loop=%7d uV\n",
- boost_voltage);
- }
- /* Limit boost voltage value between ceiling and floor voltage limits */
- boost_voltage = min(boost_voltage, MSM8953_APSS_BOOST_CEILING_VOLT);
- boost_voltage = max(boost_voltage, MSM8953_APSS_BOOST_FLOOR_VOLT);
- /*
- * The boost feature can only be used for the highest voltage corner.
- * Also, keep core-count adjustments disabled when the boost feature
- * is enabled.
- */
- corner = &vreg->corner[vreg->corner_count - 1];
- if (!corner->sdelta) {
- /*
- * If core-count/temp adjustments are not defined, the cpr4
- * sdelta for this corner will not be allocated. Allocate it
- * here for boost configuration.
- */
- corner->sdelta = devm_kzalloc(ctrl->dev,
- sizeof(*corner->sdelta), GFP_KERNEL);
- if (!corner->sdelta)
- return -ENOMEM;
- }
- corner->sdelta->temp_band_count = ctrl->temp_band_count;
- rc = of_property_read_u32(vreg->of_node, "qcom,cpr-num-boost-cores",
- &boost_num_cores);
- if (rc) {
- cpr3_err(vreg, "qcom,cpr-num-boost-cores reading failed, rc=%d\n",
- rc);
- return rc;
- }
- if (boost_num_cores <= 0
- || boost_num_cores > MSM8953_APSS_CPR_SDELTA_CORE_COUNT) {
- cpr3_err(vreg, "Invalid boost number of cores = %d\n",
- boost_num_cores);
- return -EINVAL;
- }
- corner->sdelta->boost_num_cores = boost_num_cores;
- boost_table = devm_kcalloc(ctrl->dev, corner->sdelta->temp_band_count,
- sizeof(*boost_table), GFP_KERNEL);
- if (!boost_table)
- return -ENOMEM;
- if (of_find_property(vreg->of_node,
- "qcom,cpr-boost-temp-adjustment", NULL)) {
- boost_temp_adj = kcalloc(corner->sdelta->temp_band_count,
- sizeof(*boost_temp_adj), GFP_KERNEL);
- if (!boost_temp_adj)
- return -ENOMEM;
- rc = cpr3_parse_array_property(vreg,
- "qcom,cpr-boost-temp-adjustment",
- corner->sdelta->temp_band_count,
- boost_temp_adj);
- if (rc) {
- cpr3_err(vreg, "qcom,cpr-boost-temp-adjustment reading failed, rc=%d\n",
- rc);
- goto done;
- }
- }
- for (i = 0; i < corner->sdelta->temp_band_count; i++) {
- /* Apply static adjustments to boost voltage */
- final_boost_volt = boost_voltage + (boost_temp_adj == NULL
- ? 0 : boost_temp_adj[i]);
- /*
- * Limit final adjusted boost voltage value between ceiling
- * and floor voltage limits
- */
- final_boost_volt = min(final_boost_volt,
- MSM8953_APSS_BOOST_CEILING_VOLT);
- final_boost_volt = max(final_boost_volt,
- MSM8953_APSS_BOOST_FLOOR_VOLT);
- boost_table[i] = (corner->open_loop_volt - final_boost_volt)
- / ctrl->step_volt;
- cpr3_debug(vreg, "Adjusted boost voltage margin for temp band %d = %d steps\n",
- i, boost_table[i]);
- }
- corner->ceiling_volt = MSM8953_APSS_BOOST_CEILING_VOLT;
- corner->sdelta->boost_table = boost_table;
- corner->sdelta->allow_boost = true;
- corner->sdelta->allow_core_count_adj = false;
- vreg->allow_boost = true;
- ctrl->allow_boost = true;
- done:
- kfree(boost_temp_adj);
- return rc;
- }
- /*
- * Constants which define the selection fuse parameters used in fuse combo map
- * logic.
- */
- enum cpr4_apss_fuse_combo_parameters {
- CPR4_APSS_SPEED_BIN = 0,
- CPR4_APSS_CPR_FUSE_REV,
- CPR4_APSS_FOUNDRY_ID,
- CPR4_APSS_FUSE_COMBO_PARAM_COUNT,
- };
- /**
- * cpr4_parse_fuse_combo_map() - parse APSS fuse combo map data from device tree
- * properties of the CPR3 regulator's device node
- * @vreg: Pointer to the CPR3 regulator
- *
- * Return: 0 on success, errno on failure
- */
- static int cpr4_parse_fuse_combo_map(struct cpr3_regulator *vreg)
- {
- struct cpr4_apss_fuses *fuse = vreg->platform_fuses;
- u64 *fuse_val;
- int rc;
- fuse_val = kcalloc(CPR4_APSS_FUSE_COMBO_PARAM_COUNT,
- sizeof(*fuse_val), GFP_KERNEL);
- if (!fuse_val)
- return -ENOMEM;
- fuse_val[CPR4_APSS_SPEED_BIN] = fuse->speed_bin;
- fuse_val[CPR4_APSS_CPR_FUSE_REV] = fuse->cpr_fusing_rev;
- fuse_val[CPR4_APSS_FOUNDRY_ID] = fuse->foundry_id;
- rc = cpr3_parse_fuse_combo_map(vreg, fuse_val,
- CPR4_APSS_FUSE_COMBO_PARAM_COUNT);
- if (rc == -ENODEV) {
- cpr3_debug(vreg, "using legacy fuse combo logic, rc=%d\n",
- rc);
- rc = 0;
- } else if (rc < 0) {
- cpr3_err(vreg, "error reading fuse combo map data, rc=%d\n",
- rc);
- } else if (vreg->fuse_combo >= CPR4_APSS_FUSE_COMBO_MAP_MAX_COUNT) {
- cpr3_err(vreg, "invalid CPR fuse combo = %d found\n",
- vreg->fuse_combo);
- rc = -EINVAL;
- }
- kfree(fuse_val);
- return rc;
- }
- /**
- * cpr4_apss_init_regulator() - perform all steps necessary to initialize the
- * configuration data for a CPR3 regulator
- * @vreg: Pointer to the CPR3 regulator
- *
- * Return: 0 on success, errno on failure
- */
- static int cpr4_apss_init_regulator(struct cpr3_regulator *vreg)
- {
- struct cpr4_apss_fuses *fuse;
- int rc;
- rc = cpr4_apss_read_fuse_data(vreg);
- if (rc) {
- cpr3_err(vreg, "unable to read CPR fuse data, rc=%d\n", rc);
- return rc;
- }
- fuse = vreg->platform_fuses;
- rc = cpr4_parse_fuse_combo_map(vreg);
- if (rc) {
- cpr3_err(vreg, "error while parsing fuse combo map, rc=%d\n",
- rc);
- return rc;
- }
- rc = cpr4_apss_parse_corner_data(vreg);
- if (rc) {
- cpr3_err(vreg, "unable to read CPR corner data from device tree, rc=%d\n",
- rc);
- return rc;
- }
- rc = cpr3_mem_acc_init(vreg);
- if (rc) {
- if (rc != -EPROBE_DEFER)
- cpr3_err(vreg, "unable to initialize mem-acc regulator settings, rc=%d\n",
- rc);
- return rc;
- }
- rc = cpr4_apss_calculate_open_loop_voltages(vreg);
- if (rc) {
- cpr3_err(vreg, "unable to calculate open-loop voltages, rc=%d\n",
- rc);
- return rc;
- }
- rc = cpr3_limit_open_loop_voltages(vreg);
- if (rc) {
- cpr3_err(vreg, "unable to limit open-loop voltages, rc=%d\n",
- rc);
- return rc;
- }
- cpr3_open_loop_voltage_as_ceiling(vreg);
- rc = cpr3_limit_floor_voltages(vreg);
- if (rc) {
- cpr3_err(vreg, "unable to limit floor voltages, rc=%d\n", rc);
- return rc;
- }
- rc = cpr4_apss_calculate_target_quotients(vreg);
- if (rc) {
- cpr3_err(vreg, "unable to calculate target quotients, rc=%d\n",
- rc);
- return rc;
- }
- rc = cpr4_parse_core_count_temp_voltage_adj(vreg, false);
- if (rc) {
- cpr3_err(vreg, "unable to parse temperature and core count voltage adjustments, rc=%d\n",
- rc);
- return rc;
- }
- if (vreg->allow_core_count_adj && (vreg->max_core_count <= 0
- || vreg->max_core_count >
- MSM8953_APSS_CPR_SDELTA_CORE_COUNT)) {
- cpr3_err(vreg, "qcom,max-core-count has invalid value = %d\n",
- vreg->max_core_count);
- return -EINVAL;
- }
- rc = cpr4_apss_parse_boost_properties(vreg);
- if (rc) {
- cpr3_err(vreg, "unable to parse boost adjustments, rc=%d\n",
- rc);
- return rc;
- }
- cpr4_apss_print_settings(vreg);
- return rc;
- }
- /**
- * cpr4_apss_init_aging() - perform APSS CPR4 controller specific
- * aging initializations
- * @ctrl: Pointer to the CPR3 controller
- *
- * Return: 0 on success, errno on failure
- */
- static int cpr4_apss_init_aging(struct cpr3_controller *ctrl)
- {
- struct cpr4_apss_fuses *fuse = NULL;
- struct cpr3_regulator *vreg = NULL;
- u32 aging_ro_scale;
- int i, j, rc;
- for (i = 0; i < ctrl->thread_count; i++) {
- for (j = 0; j < ctrl->thread[i].vreg_count; j++) {
- if (ctrl->thread[i].vreg[j].aging_allowed) {
- ctrl->aging_required = true;
- vreg = &ctrl->thread[i].vreg[j];
- fuse = vreg->platform_fuses;
- break;
- }
- }
- }
- if (!ctrl->aging_required || !fuse)
- return 0;
- rc = cpr3_parse_array_property(vreg, "qcom,cpr-aging-ro-scaling-factor",
- 1, &aging_ro_scale);
- if (rc)
- return rc;
- if (aging_ro_scale == 0) {
- cpr3_err(ctrl, "aging RO scaling factor is invalid: %u\n",
- aging_ro_scale);
- return -EINVAL;
- }
- ctrl->aging_vdd_mode = REGULATOR_MODE_NORMAL;
- ctrl->aging_complete_vdd_mode = REGULATOR_MODE_IDLE;
- ctrl->aging_sensor_count = 1;
- ctrl->aging_sensor = kzalloc(sizeof(*ctrl->aging_sensor), GFP_KERNEL);
- if (!ctrl->aging_sensor)
- return -ENOMEM;
- ctrl->aging_sensor->sensor_id = MSM8953_APSS_AGING_SENSOR_ID;
- ctrl->aging_sensor->ro_scale = aging_ro_scale;
- ctrl->aging_sensor->init_quot_diff
- = cpr3_convert_open_loop_voltage_fuse(0,
- MSM8953_APSS_AGING_INIT_QUOT_DIFF_SCALE,
- fuse->aging_init_quot_diff,
- MSM8953_APSS_AGING_INIT_QUOT_DIFF_SIZE);
- if (ctrl->aging_sensor->init_quot_diff == 0) {
- /*
- * Initial quotient difference value '0' has a special meaning
- * in MSM8953 fusing scheme. Use max age margin quotient
- * difference to consider full aging margin of 15 mV.
- */
- ctrl->aging_sensor->init_quot_diff
- = MSM8953_APSS_AGING_MAX_AGE_MARGIN_QUOT;
- cpr3_debug(ctrl, "Init quotient diff = 0, use max age margin quotient\n");
- }
- cpr3_info(ctrl, "sensor %u aging init quotient diff = %d, aging RO scale = %u QUOT/V\n",
- ctrl->aging_sensor->sensor_id,
- ctrl->aging_sensor->init_quot_diff,
- ctrl->aging_sensor->ro_scale);
- return 0;
- }
- /**
- * cpr4_apss_init_controller() - perform APSS CPR4 controller specific
- * initializations
- * @ctrl: Pointer to the CPR3 controller
- *
- * Return: 0 on success, errno on failure
- */
- static int cpr4_apss_init_controller(struct cpr3_controller *ctrl)
- {
- int i, rc;
- rc = cpr3_parse_common_ctrl_data(ctrl);
- if (rc) {
- if (rc != -EPROBE_DEFER)
- cpr3_err(ctrl, "unable to parse common controller data, rc=%d\n",
- rc);
- return rc;
- }
- rc = of_property_read_u32(ctrl->dev->of_node,
- "qcom,cpr-down-error-step-limit",
- &ctrl->down_error_step_limit);
- if (rc) {
- cpr3_err(ctrl, "error reading qcom,cpr-down-error-step-limit, rc=%d\n",
- rc);
- return rc;
- }
- rc = of_property_read_u32(ctrl->dev->of_node,
- "qcom,cpr-up-error-step-limit",
- &ctrl->up_error_step_limit);
- if (rc) {
- cpr3_err(ctrl, "error reading qcom,cpr-up-error-step-limit, rc=%d\n",
- rc);
- return rc;
- }
- /*
- * Use fixed step quotient if specified otherwise use dynamic
- * calculated per RO step quotient
- */
- of_property_read_u32(ctrl->dev->of_node, "qcom,cpr-step-quot-fixed",
- &ctrl->step_quot_fixed);
- ctrl->use_dynamic_step_quot = ctrl->step_quot_fixed ? false : true;
- ctrl->saw_use_unit_mV = of_property_read_bool(ctrl->dev->of_node,
- "qcom,cpr-saw-use-unit-mV");
- of_property_read_u32(ctrl->dev->of_node,
- "qcom,cpr-voltage-settling-time",
- &ctrl->voltage_settling_time);
- ctrl->vdd_limit_regulator = devm_regulator_get(ctrl->dev, "vdd-limit");
- if (IS_ERR(ctrl->vdd_limit_regulator)) {
- rc = PTR_ERR(ctrl->vdd_limit_regulator);
- if (rc != -EPROBE_DEFER)
- cpr3_err(ctrl, "unable to request vdd-limit regulator, rc=%d\n",
- rc);
- return rc;
- }
- rc = cpr3_apm_init(ctrl);
- if (rc) {
- if (rc != -EPROBE_DEFER)
- cpr3_err(ctrl, "unable to initialize APM settings, rc=%d\n",
- rc);
- return rc;
- }
- rc = cpr4_apss_parse_temp_adj_properties(ctrl);
- if (rc) {
- cpr3_err(ctrl, "unable to parse temperature adjustment properties, rc=%d\n",
- rc);
- return rc;
- }
- switch (ctrl->soc_revision) {
- case MSM8953_SOC_ID:
- ctrl->sensor_count = MSM8953_APSS_CPR_SENSOR_COUNT;
- break;
- case SDM632_SOC_ID:
- ctrl->sensor_count = SDM632_APSS_CPR_SENSOR_COUNT;
- break;
- default:
- cpr3_err(ctrl, "unsupported soc id = %d\n", ctrl->soc_revision);
- return -EINVAL;
- }
- /*
- * MSM8953 APSS only has one thread (0) per controller so the zeroed
- * array does not need further modification.
- */
- ctrl->sensor_owner = devm_kcalloc(ctrl->dev, ctrl->sensor_count,
- sizeof(*ctrl->sensor_owner), GFP_KERNEL);
- if (!ctrl->sensor_owner)
- return -ENOMEM;
- /* Specify sensor ownership for SDM632 APSS CPR */
- if (ctrl->soc_revision == SDM632_SOC_ID) {
- for (i = SDM632_APSS_THREAD0_SENSOR_MIN;
- i <= SDM632_APSS_THREAD0_SENSOR_MAX; i++)
- ctrl->sensor_owner[i] = 0;
- for (i = SDM632_APSS_THREAD1_SENSOR_MIN;
- i <= SDM632_APSS_THREAD1_SENSOR_MAX; i++)
- ctrl->sensor_owner[i] = 1;
- }
- ctrl->cpr_clock_rate = CPR4_APSS_CPR_CLOCK_RATE;
- ctrl->ctrl_type = CPR_CTRL_TYPE_CPR4;
- ctrl->supports_hw_closed_loop = true;
- ctrl->use_hw_closed_loop = of_property_read_bool(ctrl->dev->of_node,
- "qcom,cpr-hw-closed-loop");
- return 0;
- }
- #if CONFIG_PM
- static int cpr4_apss_regulator_suspend(struct device *dev)
- {
- struct cpr3_controller *ctrl = dev_get_drvdata(dev);
- return cpr3_regulator_suspend(ctrl);
- }
- static int cpr4_apss_regulator_resume(struct device *dev)
- {
- struct cpr3_controller *ctrl = dev_get_drvdata(dev);
- return cpr3_regulator_resume(ctrl);
- }
- #else
- #define cpr4_apss_regulator_suspend NULL
- #define cpr4_apss_regulator_resume NULL
- #endif
- static const struct dev_pm_ops cpr4_apss_regulator_pm_ops = {
- .suspend = cpr4_apss_regulator_suspend,
- .resume = cpr4_apss_regulator_resume,
- };
- /* Data corresponds to the SoC revision */
- static const struct of_device_id cpr4_regulator_match_table[] = {
- {
- .compatible = "qcom,cpr4-msm8953-apss-regulator",
- .data = (void *)(uintptr_t)MSM8953_SOC_ID,
- },
- {
- .compatible = "qcom,cpr4-sdm632-apss-regulator",
- .data = (void *)(uintptr_t)SDM632_SOC_ID,
- },
- {}
- };
- static int cpr4_apss_regulator_probe(struct platform_device *pdev)
- {
- struct device *dev = &pdev->dev;
- struct cpr3_controller *ctrl;
- struct cpr3_regulator *vreg;
- const struct of_device_id *match;
- int i, j, rc, max_thread_id;
- if (!dev->of_node) {
- dev_err(dev, "Device tree node is missing\n");
- return -EINVAL;
- }
- ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL);
- if (!ctrl)
- return -ENOMEM;
- ctrl->dev = dev;
- /* Set to false later if anything precludes CPR operation. */
- ctrl->cpr_allowed_hw = true;
- match = of_match_node(cpr4_regulator_match_table, dev->of_node);
- if (match)
- ctrl->soc_revision = (uintptr_t)match->data;
- else
- cpr3_err(ctrl, "could not find compatible string match\n");
- rc = of_property_read_string(dev->of_node, "qcom,cpr-ctrl-name",
- &ctrl->name);
- if (rc) {
- cpr3_err(ctrl, "unable to read qcom,cpr-ctrl-name, rc=%d\n",
- rc);
- return rc;
- }
- rc = cpr3_map_fuse_base(ctrl, pdev);
- if (rc) {
- cpr3_err(ctrl, "could not map fuse base address\n");
- return rc;
- }
- max_thread_id = 0;
- /* SDM632 uses 2 CPR HW threads */
- if (ctrl->soc_revision == SDM632_SOC_ID)
- max_thread_id = 1;
- rc = cpr3_allocate_threads(ctrl, 0, max_thread_id);
- if (rc) {
- cpr3_err(ctrl, "failed to allocate CPR thread array, rc=%d\n",
- rc);
- return rc;
- }
- if (ctrl->thread_count < 1) {
- cpr3_err(ctrl, "thread nodes are missing\n");
- return -EINVAL;
- }
- rc = cpr4_apss_init_controller(ctrl);
- if (rc) {
- if (rc != -EPROBE_DEFER)
- cpr3_err(ctrl, "failed to initialize CPR controller parameters, rc=%d\n",
- rc);
- return rc;
- }
- for (i = 0; i < ctrl->thread_count; i++) {
- rc = cpr4_apss_init_thread(&ctrl->thread[i]);
- if (rc) {
- cpr3_err(ctrl, "thread %u initialization failed, rc=%d\n",
- ctrl->thread[i].thread_id, rc);
- return rc;
- }
- for (j = 0; j < ctrl->thread[i].vreg_count; j++) {
- vreg = &ctrl->thread[i].vreg[j];
- rc = cpr4_apss_init_regulator(vreg);
- if (rc) {
- cpr3_err(vreg, "regulator initialization failed, rc=%d\n",
- rc);
- return rc;
- }
- }
- }
- rc = cpr4_apss_init_aging(ctrl);
- if (rc) {
- cpr3_err(ctrl, "failed to initialize aging configurations, rc=%d\n",
- rc);
- return rc;
- }
- platform_set_drvdata(pdev, ctrl);
- return cpr3_regulator_register(pdev, ctrl);
- }
- static int cpr4_apss_regulator_remove(struct platform_device *pdev)
- {
- struct cpr3_controller *ctrl = platform_get_drvdata(pdev);
- return cpr3_regulator_unregister(ctrl);
- }
- static struct platform_driver cpr4_apss_regulator_driver = {
- .driver = {
- .name = "qcom,cpr4-apss-regulator",
- .of_match_table = cpr4_regulator_match_table,
- .owner = THIS_MODULE,
- .pm = &cpr4_apss_regulator_pm_ops,
- },
- .probe = cpr4_apss_regulator_probe,
- .remove = cpr4_apss_regulator_remove,
- };
- static int cpr4_regulator_init(void)
- {
- return platform_driver_register(&cpr4_apss_regulator_driver);
- }
- static void cpr4_regulator_exit(void)
- {
- platform_driver_unregister(&cpr4_apss_regulator_driver);
- }
- MODULE_DESCRIPTION("CPR4 APSS regulator driver");
- MODULE_LICENSE("GPL v2");
- arch_initcall(cpr4_regulator_init);
- module_exit(cpr4_regulator_exit);
|