radeon_atombios.c 104 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198
  1. /*
  2. * Copyright 2007-8 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  19. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. * OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors: Dave Airlie
  24. * Alex Deucher
  25. */
  26. #include <drm/drmP.h>
  27. #include <drm/radeon_drm.h>
  28. #include "radeon.h"
  29. #include "atom.h"
  30. #include "atom-bits.h"
  31. /* from radeon_encoder.c */
  32. extern uint32_t
  33. radeon_get_encoder_enum(struct drm_device *dev, uint32_t supported_device,
  34. uint8_t dac);
  35. extern void radeon_link_encoder_connector(struct drm_device *dev);
  36. extern void
  37. radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_enum,
  38. uint32_t supported_device, u16 caps);
  39. /* from radeon_connector.c */
  40. extern void
  41. radeon_add_atom_connector(struct drm_device *dev,
  42. uint32_t connector_id,
  43. uint32_t supported_device,
  44. int connector_type,
  45. struct radeon_i2c_bus_rec *i2c_bus,
  46. uint32_t igp_lane_info,
  47. uint16_t connector_object_id,
  48. struct radeon_hpd *hpd,
  49. struct radeon_router *router);
  50. /* from radeon_legacy_encoder.c */
  51. extern void
  52. radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_enum,
  53. uint32_t supported_device);
  54. /* local */
  55. static int radeon_atom_get_max_vddc(struct radeon_device *rdev, u8 voltage_type,
  56. u16 voltage_id, u16 *voltage);
  57. union atom_supported_devices {
  58. struct _ATOM_SUPPORTED_DEVICES_INFO info;
  59. struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2;
  60. struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1;
  61. };
  62. static void radeon_lookup_i2c_gpio_quirks(struct radeon_device *rdev,
  63. ATOM_GPIO_I2C_ASSIGMENT *gpio,
  64. u8 index)
  65. {
  66. /* r4xx mask is technically not used by the hw, so patch in the legacy mask bits */
  67. if ((rdev->family == CHIP_R420) ||
  68. (rdev->family == CHIP_R423) ||
  69. (rdev->family == CHIP_RV410)) {
  70. if ((le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x0018) ||
  71. (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x0019) ||
  72. (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x001a)) {
  73. gpio->ucClkMaskShift = 0x19;
  74. gpio->ucDataMaskShift = 0x18;
  75. }
  76. }
  77. /* some evergreen boards have bad data for this entry */
  78. if (ASIC_IS_DCE4(rdev)) {
  79. if ((index == 7) &&
  80. (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1936) &&
  81. (gpio->sucI2cId.ucAccess == 0)) {
  82. gpio->sucI2cId.ucAccess = 0x97;
  83. gpio->ucDataMaskShift = 8;
  84. gpio->ucDataEnShift = 8;
  85. gpio->ucDataY_Shift = 8;
  86. gpio->ucDataA_Shift = 8;
  87. }
  88. }
  89. /* some DCE3 boards have bad data for this entry */
  90. if (ASIC_IS_DCE3(rdev)) {
  91. if ((index == 4) &&
  92. (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1fda) &&
  93. (gpio->sucI2cId.ucAccess == 0x94))
  94. gpio->sucI2cId.ucAccess = 0x14;
  95. }
  96. }
  97. static struct radeon_i2c_bus_rec radeon_get_bus_rec_for_i2c_gpio(ATOM_GPIO_I2C_ASSIGMENT *gpio)
  98. {
  99. struct radeon_i2c_bus_rec i2c;
  100. memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
  101. i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
  102. i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
  103. i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
  104. i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
  105. i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
  106. i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
  107. i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
  108. i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
  109. i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
  110. i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
  111. i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
  112. i2c.en_data_mask = (1 << gpio->ucDataEnShift);
  113. i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
  114. i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
  115. i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
  116. i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
  117. if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
  118. i2c.hw_capable = true;
  119. else
  120. i2c.hw_capable = false;
  121. if (gpio->sucI2cId.ucAccess == 0xa0)
  122. i2c.mm_i2c = true;
  123. else
  124. i2c.mm_i2c = false;
  125. i2c.i2c_id = gpio->sucI2cId.ucAccess;
  126. if (i2c.mask_clk_reg)
  127. i2c.valid = true;
  128. else
  129. i2c.valid = false;
  130. return i2c;
  131. }
  132. static struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_device *rdev,
  133. uint8_t id)
  134. {
  135. struct atom_context *ctx = rdev->mode_info.atom_context;
  136. ATOM_GPIO_I2C_ASSIGMENT *gpio;
  137. struct radeon_i2c_bus_rec i2c;
  138. int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
  139. struct _ATOM_GPIO_I2C_INFO *i2c_info;
  140. uint16_t data_offset, size;
  141. int i, num_indices;
  142. memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
  143. i2c.valid = false;
  144. if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
  145. i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
  146. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  147. sizeof(ATOM_GPIO_I2C_ASSIGMENT);
  148. for (i = 0; i < num_indices; i++) {
  149. gpio = &i2c_info->asGPIO_Info[i];
  150. radeon_lookup_i2c_gpio_quirks(rdev, gpio, i);
  151. if (gpio->sucI2cId.ucAccess == id) {
  152. i2c = radeon_get_bus_rec_for_i2c_gpio(gpio);
  153. break;
  154. }
  155. }
  156. }
  157. return i2c;
  158. }
  159. void radeon_atombios_i2c_init(struct radeon_device *rdev)
  160. {
  161. struct atom_context *ctx = rdev->mode_info.atom_context;
  162. ATOM_GPIO_I2C_ASSIGMENT *gpio;
  163. struct radeon_i2c_bus_rec i2c;
  164. int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
  165. struct _ATOM_GPIO_I2C_INFO *i2c_info;
  166. uint16_t data_offset, size;
  167. int i, num_indices;
  168. char stmp[32];
  169. if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
  170. i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
  171. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  172. sizeof(ATOM_GPIO_I2C_ASSIGMENT);
  173. for (i = 0; i < num_indices; i++) {
  174. gpio = &i2c_info->asGPIO_Info[i];
  175. radeon_lookup_i2c_gpio_quirks(rdev, gpio, i);
  176. i2c = radeon_get_bus_rec_for_i2c_gpio(gpio);
  177. if (i2c.valid) {
  178. sprintf(stmp, "0x%x", i2c.i2c_id);
  179. rdev->i2c_bus[i] = radeon_i2c_create(rdev->ddev, &i2c, stmp);
  180. }
  181. }
  182. }
  183. }
  184. static struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev,
  185. u8 id)
  186. {
  187. struct atom_context *ctx = rdev->mode_info.atom_context;
  188. struct radeon_gpio_rec gpio;
  189. int index = GetIndexIntoMasterTable(DATA, GPIO_Pin_LUT);
  190. struct _ATOM_GPIO_PIN_LUT *gpio_info;
  191. ATOM_GPIO_PIN_ASSIGNMENT *pin;
  192. u16 data_offset, size;
  193. int i, num_indices;
  194. memset(&gpio, 0, sizeof(struct radeon_gpio_rec));
  195. gpio.valid = false;
  196. if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
  197. gpio_info = (struct _ATOM_GPIO_PIN_LUT *)(ctx->bios + data_offset);
  198. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  199. sizeof(ATOM_GPIO_PIN_ASSIGNMENT);
  200. for (i = 0; i < num_indices; i++) {
  201. pin = &gpio_info->asGPIO_Pin[i];
  202. if (id == pin->ucGPIO_ID) {
  203. gpio.id = pin->ucGPIO_ID;
  204. gpio.reg = le16_to_cpu(pin->usGpioPin_AIndex) * 4;
  205. gpio.mask = (1 << pin->ucGpioPinBitShift);
  206. gpio.valid = true;
  207. break;
  208. }
  209. }
  210. }
  211. return gpio;
  212. }
  213. static struct radeon_hpd radeon_atom_get_hpd_info_from_gpio(struct radeon_device *rdev,
  214. struct radeon_gpio_rec *gpio)
  215. {
  216. struct radeon_hpd hpd;
  217. u32 reg;
  218. memset(&hpd, 0, sizeof(struct radeon_hpd));
  219. if (ASIC_IS_DCE6(rdev))
  220. reg = SI_DC_GPIO_HPD_A;
  221. else if (ASIC_IS_DCE4(rdev))
  222. reg = EVERGREEN_DC_GPIO_HPD_A;
  223. else
  224. reg = AVIVO_DC_GPIO_HPD_A;
  225. hpd.gpio = *gpio;
  226. if (gpio->reg == reg) {
  227. switch(gpio->mask) {
  228. case (1 << 0):
  229. hpd.hpd = RADEON_HPD_1;
  230. break;
  231. case (1 << 8):
  232. hpd.hpd = RADEON_HPD_2;
  233. break;
  234. case (1 << 16):
  235. hpd.hpd = RADEON_HPD_3;
  236. break;
  237. case (1 << 24):
  238. hpd.hpd = RADEON_HPD_4;
  239. break;
  240. case (1 << 26):
  241. hpd.hpd = RADEON_HPD_5;
  242. break;
  243. case (1 << 28):
  244. hpd.hpd = RADEON_HPD_6;
  245. break;
  246. default:
  247. hpd.hpd = RADEON_HPD_NONE;
  248. break;
  249. }
  250. } else
  251. hpd.hpd = RADEON_HPD_NONE;
  252. return hpd;
  253. }
  254. static bool radeon_atom_apply_quirks(struct drm_device *dev,
  255. uint32_t supported_device,
  256. int *connector_type,
  257. struct radeon_i2c_bus_rec *i2c_bus,
  258. uint16_t *line_mux,
  259. struct radeon_hpd *hpd)
  260. {
  261. /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
  262. if ((dev->pdev->device == 0x791e) &&
  263. (dev->pdev->subsystem_vendor == 0x1043) &&
  264. (dev->pdev->subsystem_device == 0x826d)) {
  265. if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
  266. (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
  267. *connector_type = DRM_MODE_CONNECTOR_DVID;
  268. }
  269. /* Asrock RS600 board lists the DVI port as HDMI */
  270. if ((dev->pdev->device == 0x7941) &&
  271. (dev->pdev->subsystem_vendor == 0x1849) &&
  272. (dev->pdev->subsystem_device == 0x7941)) {
  273. if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
  274. (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
  275. *connector_type = DRM_MODE_CONNECTOR_DVID;
  276. }
  277. /* MSI K9A2GM V2/V3 board has no HDMI or DVI */
  278. if ((dev->pdev->device == 0x796e) &&
  279. (dev->pdev->subsystem_vendor == 0x1462) &&
  280. (dev->pdev->subsystem_device == 0x7302)) {
  281. if ((supported_device == ATOM_DEVICE_DFP2_SUPPORT) ||
  282. (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
  283. return false;
  284. }
  285. /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
  286. if ((dev->pdev->device == 0x7941) &&
  287. (dev->pdev->subsystem_vendor == 0x147b) &&
  288. (dev->pdev->subsystem_device == 0x2412)) {
  289. if (*connector_type == DRM_MODE_CONNECTOR_DVII)
  290. return false;
  291. }
  292. /* Falcon NW laptop lists vga ddc line for LVDS */
  293. if ((dev->pdev->device == 0x5653) &&
  294. (dev->pdev->subsystem_vendor == 0x1462) &&
  295. (dev->pdev->subsystem_device == 0x0291)) {
  296. if (*connector_type == DRM_MODE_CONNECTOR_LVDS) {
  297. i2c_bus->valid = false;
  298. *line_mux = 53;
  299. }
  300. }
  301. /* HIS X1300 is DVI+VGA, not DVI+DVI */
  302. if ((dev->pdev->device == 0x7146) &&
  303. (dev->pdev->subsystem_vendor == 0x17af) &&
  304. (dev->pdev->subsystem_device == 0x2058)) {
  305. if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
  306. return false;
  307. }
  308. /* Gigabyte X1300 is DVI+VGA, not DVI+DVI */
  309. if ((dev->pdev->device == 0x7142) &&
  310. (dev->pdev->subsystem_vendor == 0x1458) &&
  311. (dev->pdev->subsystem_device == 0x2134)) {
  312. if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
  313. return false;
  314. }
  315. /* Funky macbooks */
  316. if ((dev->pdev->device == 0x71C5) &&
  317. (dev->pdev->subsystem_vendor == 0x106b) &&
  318. (dev->pdev->subsystem_device == 0x0080)) {
  319. if ((supported_device == ATOM_DEVICE_CRT1_SUPPORT) ||
  320. (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
  321. return false;
  322. if (supported_device == ATOM_DEVICE_CRT2_SUPPORT)
  323. *line_mux = 0x90;
  324. }
  325. /* mac rv630, rv730, others */
  326. if ((supported_device == ATOM_DEVICE_TV1_SUPPORT) &&
  327. (*connector_type == DRM_MODE_CONNECTOR_DVII)) {
  328. *connector_type = DRM_MODE_CONNECTOR_9PinDIN;
  329. *line_mux = CONNECTOR_7PIN_DIN_ENUM_ID1;
  330. }
  331. /* ASUS HD 3600 XT board lists the DVI port as HDMI */
  332. if ((dev->pdev->device == 0x9598) &&
  333. (dev->pdev->subsystem_vendor == 0x1043) &&
  334. (dev->pdev->subsystem_device == 0x01da)) {
  335. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  336. *connector_type = DRM_MODE_CONNECTOR_DVII;
  337. }
  338. }
  339. /* ASUS HD 3600 board lists the DVI port as HDMI */
  340. if ((dev->pdev->device == 0x9598) &&
  341. (dev->pdev->subsystem_vendor == 0x1043) &&
  342. (dev->pdev->subsystem_device == 0x01e4)) {
  343. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  344. *connector_type = DRM_MODE_CONNECTOR_DVII;
  345. }
  346. }
  347. /* ASUS HD 3450 board lists the DVI port as HDMI */
  348. if ((dev->pdev->device == 0x95C5) &&
  349. (dev->pdev->subsystem_vendor == 0x1043) &&
  350. (dev->pdev->subsystem_device == 0x01e2)) {
  351. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  352. *connector_type = DRM_MODE_CONNECTOR_DVII;
  353. }
  354. }
  355. /* some BIOSes seem to report DAC on HDMI - usually this is a board with
  356. * HDMI + VGA reporting as HDMI
  357. */
  358. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  359. if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) {
  360. *connector_type = DRM_MODE_CONNECTOR_VGA;
  361. *line_mux = 0;
  362. }
  363. }
  364. /* Acer laptop (Acer TravelMate 5730/5730G) has an HDMI port
  365. * on the laptop and a DVI port on the docking station and
  366. * both share the same encoder, hpd pin, and ddc line.
  367. * So while the bios table is technically correct,
  368. * we drop the DVI port here since xrandr has no concept of
  369. * encoders and will try and drive both connectors
  370. * with different crtcs which isn't possible on the hardware
  371. * side and leaves no crtcs for LVDS or VGA.
  372. */
  373. if (((dev->pdev->device == 0x95c4) || (dev->pdev->device == 0x9591)) &&
  374. (dev->pdev->subsystem_vendor == 0x1025) &&
  375. (dev->pdev->subsystem_device == 0x013c)) {
  376. if ((*connector_type == DRM_MODE_CONNECTOR_DVII) &&
  377. (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
  378. /* actually it's a DVI-D port not DVI-I */
  379. *connector_type = DRM_MODE_CONNECTOR_DVID;
  380. return false;
  381. }
  382. }
  383. /* XFX Pine Group device rv730 reports no VGA DDC lines
  384. * even though they are wired up to record 0x93
  385. */
  386. if ((dev->pdev->device == 0x9498) &&
  387. (dev->pdev->subsystem_vendor == 0x1682) &&
  388. (dev->pdev->subsystem_device == 0x2452) &&
  389. (i2c_bus->valid == false) &&
  390. !(supported_device & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT))) {
  391. struct radeon_device *rdev = dev->dev_private;
  392. *i2c_bus = radeon_lookup_i2c_gpio(rdev, 0x93);
  393. }
  394. /* Fujitsu D3003-S2 board lists DVI-I as DVI-D and VGA */
  395. if (((dev->pdev->device == 0x9802) || (dev->pdev->device == 0x9806)) &&
  396. (dev->pdev->subsystem_vendor == 0x1734) &&
  397. (dev->pdev->subsystem_device == 0x11bd)) {
  398. if (*connector_type == DRM_MODE_CONNECTOR_VGA) {
  399. *connector_type = DRM_MODE_CONNECTOR_DVII;
  400. *line_mux = 0x3103;
  401. } else if (*connector_type == DRM_MODE_CONNECTOR_DVID) {
  402. *connector_type = DRM_MODE_CONNECTOR_DVII;
  403. }
  404. }
  405. return true;
  406. }
  407. const int supported_devices_connector_convert[] = {
  408. DRM_MODE_CONNECTOR_Unknown,
  409. DRM_MODE_CONNECTOR_VGA,
  410. DRM_MODE_CONNECTOR_DVII,
  411. DRM_MODE_CONNECTOR_DVID,
  412. DRM_MODE_CONNECTOR_DVIA,
  413. DRM_MODE_CONNECTOR_SVIDEO,
  414. DRM_MODE_CONNECTOR_Composite,
  415. DRM_MODE_CONNECTOR_LVDS,
  416. DRM_MODE_CONNECTOR_Unknown,
  417. DRM_MODE_CONNECTOR_Unknown,
  418. DRM_MODE_CONNECTOR_HDMIA,
  419. DRM_MODE_CONNECTOR_HDMIB,
  420. DRM_MODE_CONNECTOR_Unknown,
  421. DRM_MODE_CONNECTOR_Unknown,
  422. DRM_MODE_CONNECTOR_9PinDIN,
  423. DRM_MODE_CONNECTOR_DisplayPort
  424. };
  425. const uint16_t supported_devices_connector_object_id_convert[] = {
  426. CONNECTOR_OBJECT_ID_NONE,
  427. CONNECTOR_OBJECT_ID_VGA,
  428. CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I, /* not all boards support DL */
  429. CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D, /* not all boards support DL */
  430. CONNECTOR_OBJECT_ID_VGA, /* technically DVI-A */
  431. CONNECTOR_OBJECT_ID_COMPOSITE,
  432. CONNECTOR_OBJECT_ID_SVIDEO,
  433. CONNECTOR_OBJECT_ID_LVDS,
  434. CONNECTOR_OBJECT_ID_9PIN_DIN,
  435. CONNECTOR_OBJECT_ID_9PIN_DIN,
  436. CONNECTOR_OBJECT_ID_DISPLAYPORT,
  437. CONNECTOR_OBJECT_ID_HDMI_TYPE_A,
  438. CONNECTOR_OBJECT_ID_HDMI_TYPE_B,
  439. CONNECTOR_OBJECT_ID_SVIDEO
  440. };
  441. const int object_connector_convert[] = {
  442. DRM_MODE_CONNECTOR_Unknown,
  443. DRM_MODE_CONNECTOR_DVII,
  444. DRM_MODE_CONNECTOR_DVII,
  445. DRM_MODE_CONNECTOR_DVID,
  446. DRM_MODE_CONNECTOR_DVID,
  447. DRM_MODE_CONNECTOR_VGA,
  448. DRM_MODE_CONNECTOR_Composite,
  449. DRM_MODE_CONNECTOR_SVIDEO,
  450. DRM_MODE_CONNECTOR_Unknown,
  451. DRM_MODE_CONNECTOR_Unknown,
  452. DRM_MODE_CONNECTOR_9PinDIN,
  453. DRM_MODE_CONNECTOR_Unknown,
  454. DRM_MODE_CONNECTOR_HDMIA,
  455. DRM_MODE_CONNECTOR_HDMIB,
  456. DRM_MODE_CONNECTOR_LVDS,
  457. DRM_MODE_CONNECTOR_9PinDIN,
  458. DRM_MODE_CONNECTOR_Unknown,
  459. DRM_MODE_CONNECTOR_Unknown,
  460. DRM_MODE_CONNECTOR_Unknown,
  461. DRM_MODE_CONNECTOR_DisplayPort,
  462. DRM_MODE_CONNECTOR_eDP,
  463. DRM_MODE_CONNECTOR_Unknown
  464. };
  465. bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
  466. {
  467. struct radeon_device *rdev = dev->dev_private;
  468. struct radeon_mode_info *mode_info = &rdev->mode_info;
  469. struct atom_context *ctx = mode_info->atom_context;
  470. int index = GetIndexIntoMasterTable(DATA, Object_Header);
  471. u16 size, data_offset;
  472. u8 frev, crev;
  473. ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
  474. ATOM_ENCODER_OBJECT_TABLE *enc_obj;
  475. ATOM_OBJECT_TABLE *router_obj;
  476. ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
  477. ATOM_OBJECT_HEADER *obj_header;
  478. int i, j, k, path_size, device_support;
  479. int connector_type;
  480. u16 igp_lane_info, conn_id, connector_object_id;
  481. struct radeon_i2c_bus_rec ddc_bus;
  482. struct radeon_router router;
  483. struct radeon_gpio_rec gpio;
  484. struct radeon_hpd hpd;
  485. if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
  486. return false;
  487. if (crev < 2)
  488. return false;
  489. obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
  490. path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
  491. (ctx->bios + data_offset +
  492. le16_to_cpu(obj_header->usDisplayPathTableOffset));
  493. con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
  494. (ctx->bios + data_offset +
  495. le16_to_cpu(obj_header->usConnectorObjectTableOffset));
  496. enc_obj = (ATOM_ENCODER_OBJECT_TABLE *)
  497. (ctx->bios + data_offset +
  498. le16_to_cpu(obj_header->usEncoderObjectTableOffset));
  499. router_obj = (ATOM_OBJECT_TABLE *)
  500. (ctx->bios + data_offset +
  501. le16_to_cpu(obj_header->usRouterObjectTableOffset));
  502. device_support = le16_to_cpu(obj_header->usDeviceSupport);
  503. path_size = 0;
  504. for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
  505. uint8_t *addr = (uint8_t *) path_obj->asDispPath;
  506. ATOM_DISPLAY_OBJECT_PATH *path;
  507. addr += path_size;
  508. path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
  509. path_size += le16_to_cpu(path->usSize);
  510. if (device_support & le16_to_cpu(path->usDeviceTag)) {
  511. uint8_t con_obj_id, con_obj_num, con_obj_type;
  512. con_obj_id =
  513. (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
  514. >> OBJECT_ID_SHIFT;
  515. con_obj_num =
  516. (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
  517. >> ENUM_ID_SHIFT;
  518. con_obj_type =
  519. (le16_to_cpu(path->usConnObjectId) &
  520. OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
  521. /* TODO CV support */
  522. if (le16_to_cpu(path->usDeviceTag) ==
  523. ATOM_DEVICE_CV_SUPPORT)
  524. continue;
  525. /* IGP chips */
  526. if ((rdev->flags & RADEON_IS_IGP) &&
  527. (con_obj_id ==
  528. CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
  529. uint16_t igp_offset = 0;
  530. ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
  531. index =
  532. GetIndexIntoMasterTable(DATA,
  533. IntegratedSystemInfo);
  534. if (atom_parse_data_header(ctx, index, &size, &frev,
  535. &crev, &igp_offset)) {
  536. if (crev >= 2) {
  537. igp_obj =
  538. (ATOM_INTEGRATED_SYSTEM_INFO_V2
  539. *) (ctx->bios + igp_offset);
  540. if (igp_obj) {
  541. uint32_t slot_config, ct;
  542. if (con_obj_num == 1)
  543. slot_config =
  544. igp_obj->
  545. ulDDISlot1Config;
  546. else
  547. slot_config =
  548. igp_obj->
  549. ulDDISlot2Config;
  550. ct = (slot_config >> 16) & 0xff;
  551. connector_type =
  552. object_connector_convert
  553. [ct];
  554. connector_object_id = ct;
  555. igp_lane_info =
  556. slot_config & 0xffff;
  557. } else
  558. continue;
  559. } else
  560. continue;
  561. } else {
  562. igp_lane_info = 0;
  563. connector_type =
  564. object_connector_convert[con_obj_id];
  565. connector_object_id = con_obj_id;
  566. }
  567. } else {
  568. igp_lane_info = 0;
  569. connector_type =
  570. object_connector_convert[con_obj_id];
  571. connector_object_id = con_obj_id;
  572. }
  573. if (connector_type == DRM_MODE_CONNECTOR_Unknown)
  574. continue;
  575. router.ddc_valid = false;
  576. router.cd_valid = false;
  577. for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2); j++) {
  578. uint8_t grph_obj_id, grph_obj_num, grph_obj_type;
  579. grph_obj_id =
  580. (le16_to_cpu(path->usGraphicObjIds[j]) &
  581. OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
  582. grph_obj_num =
  583. (le16_to_cpu(path->usGraphicObjIds[j]) &
  584. ENUM_ID_MASK) >> ENUM_ID_SHIFT;
  585. grph_obj_type =
  586. (le16_to_cpu(path->usGraphicObjIds[j]) &
  587. OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
  588. if (grph_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
  589. for (k = 0; k < enc_obj->ucNumberOfObjects; k++) {
  590. u16 encoder_obj = le16_to_cpu(enc_obj->asObjects[k].usObjectID);
  591. if (le16_to_cpu(path->usGraphicObjIds[j]) == encoder_obj) {
  592. ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
  593. (ctx->bios + data_offset +
  594. le16_to_cpu(enc_obj->asObjects[k].usRecordOffset));
  595. ATOM_ENCODER_CAP_RECORD *cap_record;
  596. u16 caps = 0;
  597. while (record->ucRecordSize > 0 &&
  598. record->ucRecordType > 0 &&
  599. record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
  600. switch (record->ucRecordType) {
  601. case ATOM_ENCODER_CAP_RECORD_TYPE:
  602. cap_record =(ATOM_ENCODER_CAP_RECORD *)
  603. record;
  604. caps = le16_to_cpu(cap_record->usEncoderCap);
  605. break;
  606. }
  607. record = (ATOM_COMMON_RECORD_HEADER *)
  608. ((char *)record + record->ucRecordSize);
  609. }
  610. radeon_add_atom_encoder(dev,
  611. encoder_obj,
  612. le16_to_cpu
  613. (path->
  614. usDeviceTag),
  615. caps);
  616. }
  617. }
  618. } else if (grph_obj_type == GRAPH_OBJECT_TYPE_ROUTER) {
  619. for (k = 0; k < router_obj->ucNumberOfObjects; k++) {
  620. u16 router_obj_id = le16_to_cpu(router_obj->asObjects[k].usObjectID);
  621. if (le16_to_cpu(path->usGraphicObjIds[j]) == router_obj_id) {
  622. ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
  623. (ctx->bios + data_offset +
  624. le16_to_cpu(router_obj->asObjects[k].usRecordOffset));
  625. ATOM_I2C_RECORD *i2c_record;
  626. ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
  627. ATOM_ROUTER_DDC_PATH_SELECT_RECORD *ddc_path;
  628. ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *cd_path;
  629. ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *router_src_dst_table =
  630. (ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *)
  631. (ctx->bios + data_offset +
  632. le16_to_cpu(router_obj->asObjects[k].usSrcDstTableOffset));
  633. int enum_id;
  634. router.router_id = router_obj_id;
  635. for (enum_id = 0; enum_id < router_src_dst_table->ucNumberOfDst;
  636. enum_id++) {
  637. if (le16_to_cpu(path->usConnObjectId) ==
  638. le16_to_cpu(router_src_dst_table->usDstObjectID[enum_id]))
  639. break;
  640. }
  641. while (record->ucRecordSize > 0 &&
  642. record->ucRecordType > 0 &&
  643. record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
  644. switch (record->ucRecordType) {
  645. case ATOM_I2C_RECORD_TYPE:
  646. i2c_record =
  647. (ATOM_I2C_RECORD *)
  648. record;
  649. i2c_config =
  650. (ATOM_I2C_ID_CONFIG_ACCESS *)
  651. &i2c_record->sucI2cId;
  652. router.i2c_info =
  653. radeon_lookup_i2c_gpio(rdev,
  654. i2c_config->
  655. ucAccess);
  656. router.i2c_addr = i2c_record->ucI2CAddr >> 1;
  657. break;
  658. case ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE:
  659. ddc_path = (ATOM_ROUTER_DDC_PATH_SELECT_RECORD *)
  660. record;
  661. router.ddc_valid = true;
  662. router.ddc_mux_type = ddc_path->ucMuxType;
  663. router.ddc_mux_control_pin = ddc_path->ucMuxControlPin;
  664. router.ddc_mux_state = ddc_path->ucMuxState[enum_id];
  665. break;
  666. case ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD_TYPE:
  667. cd_path = (ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *)
  668. record;
  669. router.cd_valid = true;
  670. router.cd_mux_type = cd_path->ucMuxType;
  671. router.cd_mux_control_pin = cd_path->ucMuxControlPin;
  672. router.cd_mux_state = cd_path->ucMuxState[enum_id];
  673. break;
  674. }
  675. record = (ATOM_COMMON_RECORD_HEADER *)
  676. ((char *)record + record->ucRecordSize);
  677. }
  678. }
  679. }
  680. }
  681. }
  682. /* look up gpio for ddc, hpd */
  683. ddc_bus.valid = false;
  684. hpd.hpd = RADEON_HPD_NONE;
  685. if ((le16_to_cpu(path->usDeviceTag) &
  686. (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) == 0) {
  687. for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
  688. if (le16_to_cpu(path->usConnObjectId) ==
  689. le16_to_cpu(con_obj->asObjects[j].
  690. usObjectID)) {
  691. ATOM_COMMON_RECORD_HEADER
  692. *record =
  693. (ATOM_COMMON_RECORD_HEADER
  694. *)
  695. (ctx->bios + data_offset +
  696. le16_to_cpu(con_obj->
  697. asObjects[j].
  698. usRecordOffset));
  699. ATOM_I2C_RECORD *i2c_record;
  700. ATOM_HPD_INT_RECORD *hpd_record;
  701. ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
  702. while (record->ucRecordSize > 0 &&
  703. record->ucRecordType > 0 &&
  704. record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
  705. switch (record->ucRecordType) {
  706. case ATOM_I2C_RECORD_TYPE:
  707. i2c_record =
  708. (ATOM_I2C_RECORD *)
  709. record;
  710. i2c_config =
  711. (ATOM_I2C_ID_CONFIG_ACCESS *)
  712. &i2c_record->sucI2cId;
  713. ddc_bus = radeon_lookup_i2c_gpio(rdev,
  714. i2c_config->
  715. ucAccess);
  716. break;
  717. case ATOM_HPD_INT_RECORD_TYPE:
  718. hpd_record =
  719. (ATOM_HPD_INT_RECORD *)
  720. record;
  721. gpio = radeon_lookup_gpio(rdev,
  722. hpd_record->ucHPDIntGPIOID);
  723. hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
  724. hpd.plugged_state = hpd_record->ucPlugged_PinState;
  725. break;
  726. }
  727. record =
  728. (ATOM_COMMON_RECORD_HEADER
  729. *) ((char *)record
  730. +
  731. record->
  732. ucRecordSize);
  733. }
  734. break;
  735. }
  736. }
  737. }
  738. /* needed for aux chan transactions */
  739. ddc_bus.hpd = hpd.hpd;
  740. conn_id = le16_to_cpu(path->usConnObjectId);
  741. if (!radeon_atom_apply_quirks
  742. (dev, le16_to_cpu(path->usDeviceTag), &connector_type,
  743. &ddc_bus, &conn_id, &hpd))
  744. continue;
  745. radeon_add_atom_connector(dev,
  746. conn_id,
  747. le16_to_cpu(path->
  748. usDeviceTag),
  749. connector_type, &ddc_bus,
  750. igp_lane_info,
  751. connector_object_id,
  752. &hpd,
  753. &router);
  754. }
  755. }
  756. radeon_link_encoder_connector(dev);
  757. return true;
  758. }
  759. static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
  760. int connector_type,
  761. uint16_t devices)
  762. {
  763. struct radeon_device *rdev = dev->dev_private;
  764. if (rdev->flags & RADEON_IS_IGP) {
  765. return supported_devices_connector_object_id_convert
  766. [connector_type];
  767. } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) ||
  768. (connector_type == DRM_MODE_CONNECTOR_DVID)) &&
  769. (devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  770. struct radeon_mode_info *mode_info = &rdev->mode_info;
  771. struct atom_context *ctx = mode_info->atom_context;
  772. int index = GetIndexIntoMasterTable(DATA, XTMDS_Info);
  773. uint16_t size, data_offset;
  774. uint8_t frev, crev;
  775. ATOM_XTMDS_INFO *xtmds;
  776. if (atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset)) {
  777. xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset);
  778. if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) {
  779. if (connector_type == DRM_MODE_CONNECTOR_DVII)
  780. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
  781. else
  782. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
  783. } else {
  784. if (connector_type == DRM_MODE_CONNECTOR_DVII)
  785. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  786. else
  787. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
  788. }
  789. } else
  790. return supported_devices_connector_object_id_convert
  791. [connector_type];
  792. } else {
  793. return supported_devices_connector_object_id_convert
  794. [connector_type];
  795. }
  796. }
  797. struct bios_connector {
  798. bool valid;
  799. uint16_t line_mux;
  800. uint16_t devices;
  801. int connector_type;
  802. struct radeon_i2c_bus_rec ddc_bus;
  803. struct radeon_hpd hpd;
  804. };
  805. bool radeon_get_atom_connector_info_from_supported_devices_table(struct
  806. drm_device
  807. *dev)
  808. {
  809. struct radeon_device *rdev = dev->dev_private;
  810. struct radeon_mode_info *mode_info = &rdev->mode_info;
  811. struct atom_context *ctx = mode_info->atom_context;
  812. int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
  813. uint16_t size, data_offset;
  814. uint8_t frev, crev;
  815. uint16_t device_support;
  816. uint8_t dac;
  817. union atom_supported_devices *supported_devices;
  818. int i, j, max_device;
  819. struct bios_connector *bios_connectors;
  820. size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE;
  821. struct radeon_router router;
  822. router.ddc_valid = false;
  823. router.cd_valid = false;
  824. bios_connectors = kzalloc(bc_size, GFP_KERNEL);
  825. if (!bios_connectors)
  826. return false;
  827. if (!atom_parse_data_header(ctx, index, &size, &frev, &crev,
  828. &data_offset)) {
  829. kfree(bios_connectors);
  830. return false;
  831. }
  832. supported_devices =
  833. (union atom_supported_devices *)(ctx->bios + data_offset);
  834. device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
  835. if (frev > 1)
  836. max_device = ATOM_MAX_SUPPORTED_DEVICE;
  837. else
  838. max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO;
  839. for (i = 0; i < max_device; i++) {
  840. ATOM_CONNECTOR_INFO_I2C ci =
  841. supported_devices->info.asConnInfo[i];
  842. bios_connectors[i].valid = false;
  843. if (!(device_support & (1 << i))) {
  844. continue;
  845. }
  846. if (i == ATOM_DEVICE_CV_INDEX) {
  847. DRM_DEBUG_KMS("Skipping Component Video\n");
  848. continue;
  849. }
  850. bios_connectors[i].connector_type =
  851. supported_devices_connector_convert[ci.sucConnectorInfo.
  852. sbfAccess.
  853. bfConnectorType];
  854. if (bios_connectors[i].connector_type ==
  855. DRM_MODE_CONNECTOR_Unknown)
  856. continue;
  857. dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
  858. bios_connectors[i].line_mux =
  859. ci.sucI2cId.ucAccess;
  860. /* give tv unique connector ids */
  861. if (i == ATOM_DEVICE_TV1_INDEX) {
  862. bios_connectors[i].ddc_bus.valid = false;
  863. bios_connectors[i].line_mux = 50;
  864. } else if (i == ATOM_DEVICE_TV2_INDEX) {
  865. bios_connectors[i].ddc_bus.valid = false;
  866. bios_connectors[i].line_mux = 51;
  867. } else if (i == ATOM_DEVICE_CV_INDEX) {
  868. bios_connectors[i].ddc_bus.valid = false;
  869. bios_connectors[i].line_mux = 52;
  870. } else
  871. bios_connectors[i].ddc_bus =
  872. radeon_lookup_i2c_gpio(rdev,
  873. bios_connectors[i].line_mux);
  874. if ((crev > 1) && (frev > 1)) {
  875. u8 isb = supported_devices->info_2d1.asIntSrcInfo[i].ucIntSrcBitmap;
  876. switch (isb) {
  877. case 0x4:
  878. bios_connectors[i].hpd.hpd = RADEON_HPD_1;
  879. break;
  880. case 0xa:
  881. bios_connectors[i].hpd.hpd = RADEON_HPD_2;
  882. break;
  883. default:
  884. bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
  885. break;
  886. }
  887. } else {
  888. if (i == ATOM_DEVICE_DFP1_INDEX)
  889. bios_connectors[i].hpd.hpd = RADEON_HPD_1;
  890. else if (i == ATOM_DEVICE_DFP2_INDEX)
  891. bios_connectors[i].hpd.hpd = RADEON_HPD_2;
  892. else
  893. bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
  894. }
  895. /* Always set the connector type to VGA for CRT1/CRT2. if they are
  896. * shared with a DVI port, we'll pick up the DVI connector when we
  897. * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
  898. */
  899. if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
  900. bios_connectors[i].connector_type =
  901. DRM_MODE_CONNECTOR_VGA;
  902. if (!radeon_atom_apply_quirks
  903. (dev, (1 << i), &bios_connectors[i].connector_type,
  904. &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux,
  905. &bios_connectors[i].hpd))
  906. continue;
  907. bios_connectors[i].valid = true;
  908. bios_connectors[i].devices = (1 << i);
  909. if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
  910. radeon_add_atom_encoder(dev,
  911. radeon_get_encoder_enum(dev,
  912. (1 << i),
  913. dac),
  914. (1 << i),
  915. 0);
  916. else
  917. radeon_add_legacy_encoder(dev,
  918. radeon_get_encoder_enum(dev,
  919. (1 << i),
  920. dac),
  921. (1 << i));
  922. }
  923. /* combine shared connectors */
  924. for (i = 0; i < max_device; i++) {
  925. if (bios_connectors[i].valid) {
  926. for (j = 0; j < max_device; j++) {
  927. if (bios_connectors[j].valid && (i != j)) {
  928. if (bios_connectors[i].line_mux ==
  929. bios_connectors[j].line_mux) {
  930. /* make sure not to combine LVDS */
  931. if (bios_connectors[i].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  932. bios_connectors[i].line_mux = 53;
  933. bios_connectors[i].ddc_bus.valid = false;
  934. continue;
  935. }
  936. if (bios_connectors[j].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  937. bios_connectors[j].line_mux = 53;
  938. bios_connectors[j].ddc_bus.valid = false;
  939. continue;
  940. }
  941. /* combine analog and digital for DVI-I */
  942. if (((bios_connectors[i].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
  943. (bios_connectors[j].devices & (ATOM_DEVICE_CRT_SUPPORT))) ||
  944. ((bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
  945. (bios_connectors[i].devices & (ATOM_DEVICE_CRT_SUPPORT)))) {
  946. bios_connectors[i].devices |=
  947. bios_connectors[j].devices;
  948. bios_connectors[i].connector_type =
  949. DRM_MODE_CONNECTOR_DVII;
  950. if (bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT))
  951. bios_connectors[i].hpd =
  952. bios_connectors[j].hpd;
  953. bios_connectors[j].valid = false;
  954. }
  955. }
  956. }
  957. }
  958. }
  959. }
  960. /* add the connectors */
  961. for (i = 0; i < max_device; i++) {
  962. if (bios_connectors[i].valid) {
  963. uint16_t connector_object_id =
  964. atombios_get_connector_object_id(dev,
  965. bios_connectors[i].connector_type,
  966. bios_connectors[i].devices);
  967. radeon_add_atom_connector(dev,
  968. bios_connectors[i].line_mux,
  969. bios_connectors[i].devices,
  970. bios_connectors[i].
  971. connector_type,
  972. &bios_connectors[i].ddc_bus,
  973. 0,
  974. connector_object_id,
  975. &bios_connectors[i].hpd,
  976. &router);
  977. }
  978. }
  979. radeon_link_encoder_connector(dev);
  980. kfree(bios_connectors);
  981. return true;
  982. }
  983. union firmware_info {
  984. ATOM_FIRMWARE_INFO info;
  985. ATOM_FIRMWARE_INFO_V1_2 info_12;
  986. ATOM_FIRMWARE_INFO_V1_3 info_13;
  987. ATOM_FIRMWARE_INFO_V1_4 info_14;
  988. ATOM_FIRMWARE_INFO_V2_1 info_21;
  989. ATOM_FIRMWARE_INFO_V2_2 info_22;
  990. };
  991. bool radeon_atom_get_clock_info(struct drm_device *dev)
  992. {
  993. struct radeon_device *rdev = dev->dev_private;
  994. struct radeon_mode_info *mode_info = &rdev->mode_info;
  995. int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
  996. union firmware_info *firmware_info;
  997. uint8_t frev, crev;
  998. struct radeon_pll *p1pll = &rdev->clock.p1pll;
  999. struct radeon_pll *p2pll = &rdev->clock.p2pll;
  1000. struct radeon_pll *dcpll = &rdev->clock.dcpll;
  1001. struct radeon_pll *spll = &rdev->clock.spll;
  1002. struct radeon_pll *mpll = &rdev->clock.mpll;
  1003. uint16_t data_offset;
  1004. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1005. &frev, &crev, &data_offset)) {
  1006. firmware_info =
  1007. (union firmware_info *)(mode_info->atom_context->bios +
  1008. data_offset);
  1009. /* pixel clocks */
  1010. p1pll->reference_freq =
  1011. le16_to_cpu(firmware_info->info.usReferenceClock);
  1012. p1pll->reference_div = 0;
  1013. if (crev < 2)
  1014. p1pll->pll_out_min =
  1015. le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
  1016. else
  1017. p1pll->pll_out_min =
  1018. le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
  1019. p1pll->pll_out_max =
  1020. le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
  1021. if (crev >= 4) {
  1022. p1pll->lcd_pll_out_min =
  1023. le16_to_cpu(firmware_info->info_14.usLcdMinPixelClockPLL_Output) * 100;
  1024. if (p1pll->lcd_pll_out_min == 0)
  1025. p1pll->lcd_pll_out_min = p1pll->pll_out_min;
  1026. p1pll->lcd_pll_out_max =
  1027. le16_to_cpu(firmware_info->info_14.usLcdMaxPixelClockPLL_Output) * 100;
  1028. if (p1pll->lcd_pll_out_max == 0)
  1029. p1pll->lcd_pll_out_max = p1pll->pll_out_max;
  1030. } else {
  1031. p1pll->lcd_pll_out_min = p1pll->pll_out_min;
  1032. p1pll->lcd_pll_out_max = p1pll->pll_out_max;
  1033. }
  1034. if (p1pll->pll_out_min == 0) {
  1035. if (ASIC_IS_AVIVO(rdev))
  1036. p1pll->pll_out_min = 64800;
  1037. else
  1038. p1pll->pll_out_min = 20000;
  1039. }
  1040. p1pll->pll_in_min =
  1041. le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
  1042. p1pll->pll_in_max =
  1043. le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
  1044. *p2pll = *p1pll;
  1045. /* system clock */
  1046. if (ASIC_IS_DCE4(rdev))
  1047. spll->reference_freq =
  1048. le16_to_cpu(firmware_info->info_21.usCoreReferenceClock);
  1049. else
  1050. spll->reference_freq =
  1051. le16_to_cpu(firmware_info->info.usReferenceClock);
  1052. spll->reference_div = 0;
  1053. spll->pll_out_min =
  1054. le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
  1055. spll->pll_out_max =
  1056. le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
  1057. /* ??? */
  1058. if (spll->pll_out_min == 0) {
  1059. if (ASIC_IS_AVIVO(rdev))
  1060. spll->pll_out_min = 64800;
  1061. else
  1062. spll->pll_out_min = 20000;
  1063. }
  1064. spll->pll_in_min =
  1065. le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
  1066. spll->pll_in_max =
  1067. le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
  1068. /* memory clock */
  1069. if (ASIC_IS_DCE4(rdev))
  1070. mpll->reference_freq =
  1071. le16_to_cpu(firmware_info->info_21.usMemoryReferenceClock);
  1072. else
  1073. mpll->reference_freq =
  1074. le16_to_cpu(firmware_info->info.usReferenceClock);
  1075. mpll->reference_div = 0;
  1076. mpll->pll_out_min =
  1077. le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
  1078. mpll->pll_out_max =
  1079. le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
  1080. /* ??? */
  1081. if (mpll->pll_out_min == 0) {
  1082. if (ASIC_IS_AVIVO(rdev))
  1083. mpll->pll_out_min = 64800;
  1084. else
  1085. mpll->pll_out_min = 20000;
  1086. }
  1087. mpll->pll_in_min =
  1088. le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
  1089. mpll->pll_in_max =
  1090. le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
  1091. rdev->clock.default_sclk =
  1092. le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
  1093. rdev->clock.default_mclk =
  1094. le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
  1095. if (ASIC_IS_DCE4(rdev)) {
  1096. rdev->clock.default_dispclk =
  1097. le32_to_cpu(firmware_info->info_21.ulDefaultDispEngineClkFreq);
  1098. if (rdev->clock.default_dispclk == 0) {
  1099. if (ASIC_IS_DCE5(rdev))
  1100. rdev->clock.default_dispclk = 54000; /* 540 Mhz */
  1101. else
  1102. rdev->clock.default_dispclk = 60000; /* 600 Mhz */
  1103. }
  1104. rdev->clock.dp_extclk =
  1105. le16_to_cpu(firmware_info->info_21.usUniphyDPModeExtClkFreq);
  1106. }
  1107. *dcpll = *p1pll;
  1108. rdev->clock.max_pixel_clock = le16_to_cpu(firmware_info->info.usMaxPixelClock);
  1109. if (rdev->clock.max_pixel_clock == 0)
  1110. rdev->clock.max_pixel_clock = 40000;
  1111. /* not technically a clock, but... */
  1112. rdev->mode_info.firmware_flags =
  1113. le16_to_cpu(firmware_info->info.usFirmwareCapability.susAccess);
  1114. return true;
  1115. }
  1116. return false;
  1117. }
  1118. union igp_info {
  1119. struct _ATOM_INTEGRATED_SYSTEM_INFO info;
  1120. struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
  1121. struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 info_6;
  1122. struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_7 info_7;
  1123. };
  1124. bool radeon_atombios_sideport_present(struct radeon_device *rdev)
  1125. {
  1126. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1127. int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
  1128. union igp_info *igp_info;
  1129. u8 frev, crev;
  1130. u16 data_offset;
  1131. /* sideport is AMD only */
  1132. if (rdev->family == CHIP_RS600)
  1133. return false;
  1134. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1135. &frev, &crev, &data_offset)) {
  1136. igp_info = (union igp_info *)(mode_info->atom_context->bios +
  1137. data_offset);
  1138. switch (crev) {
  1139. case 1:
  1140. if (le32_to_cpu(igp_info->info.ulBootUpMemoryClock))
  1141. return true;
  1142. break;
  1143. case 2:
  1144. if (le32_to_cpu(igp_info->info_2.ulBootUpSidePortClock))
  1145. return true;
  1146. break;
  1147. default:
  1148. DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
  1149. break;
  1150. }
  1151. }
  1152. return false;
  1153. }
  1154. bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
  1155. struct radeon_encoder_int_tmds *tmds)
  1156. {
  1157. struct drm_device *dev = encoder->base.dev;
  1158. struct radeon_device *rdev = dev->dev_private;
  1159. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1160. int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
  1161. uint16_t data_offset;
  1162. struct _ATOM_TMDS_INFO *tmds_info;
  1163. uint8_t frev, crev;
  1164. uint16_t maxfreq;
  1165. int i;
  1166. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1167. &frev, &crev, &data_offset)) {
  1168. tmds_info =
  1169. (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
  1170. data_offset);
  1171. maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
  1172. for (i = 0; i < 4; i++) {
  1173. tmds->tmds_pll[i].freq =
  1174. le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
  1175. tmds->tmds_pll[i].value =
  1176. tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
  1177. tmds->tmds_pll[i].value |=
  1178. (tmds_info->asMiscInfo[i].
  1179. ucPLL_VCO_Gain & 0x3f) << 6;
  1180. tmds->tmds_pll[i].value |=
  1181. (tmds_info->asMiscInfo[i].
  1182. ucPLL_DutyCycle & 0xf) << 12;
  1183. tmds->tmds_pll[i].value |=
  1184. (tmds_info->asMiscInfo[i].
  1185. ucPLL_VoltageSwing & 0xf) << 16;
  1186. DRM_DEBUG_KMS("TMDS PLL From ATOMBIOS %u %x\n",
  1187. tmds->tmds_pll[i].freq,
  1188. tmds->tmds_pll[i].value);
  1189. if (maxfreq == tmds->tmds_pll[i].freq) {
  1190. tmds->tmds_pll[i].freq = 0xffffffff;
  1191. break;
  1192. }
  1193. }
  1194. return true;
  1195. }
  1196. return false;
  1197. }
  1198. bool radeon_atombios_get_ppll_ss_info(struct radeon_device *rdev,
  1199. struct radeon_atom_ss *ss,
  1200. int id)
  1201. {
  1202. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1203. int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
  1204. uint16_t data_offset, size;
  1205. struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
  1206. uint8_t frev, crev;
  1207. int i, num_indices;
  1208. memset(ss, 0, sizeof(struct radeon_atom_ss));
  1209. if (atom_parse_data_header(mode_info->atom_context, index, &size,
  1210. &frev, &crev, &data_offset)) {
  1211. ss_info =
  1212. (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
  1213. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1214. sizeof(ATOM_SPREAD_SPECTRUM_ASSIGNMENT);
  1215. for (i = 0; i < num_indices; i++) {
  1216. if (ss_info->asSS_Info[i].ucSS_Id == id) {
  1217. ss->percentage =
  1218. le16_to_cpu(ss_info->asSS_Info[i].usSpreadSpectrumPercentage);
  1219. ss->type = ss_info->asSS_Info[i].ucSpreadSpectrumType;
  1220. ss->step = ss_info->asSS_Info[i].ucSS_Step;
  1221. ss->delay = ss_info->asSS_Info[i].ucSS_Delay;
  1222. ss->range = ss_info->asSS_Info[i].ucSS_Range;
  1223. ss->refdiv = ss_info->asSS_Info[i].ucRecommendedRef_Div;
  1224. return true;
  1225. }
  1226. }
  1227. }
  1228. return false;
  1229. }
  1230. static void radeon_atombios_get_igp_ss_overrides(struct radeon_device *rdev,
  1231. struct radeon_atom_ss *ss,
  1232. int id)
  1233. {
  1234. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1235. int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
  1236. u16 data_offset, size;
  1237. union igp_info *igp_info;
  1238. u8 frev, crev;
  1239. u16 percentage = 0, rate = 0;
  1240. /* get any igp specific overrides */
  1241. if (atom_parse_data_header(mode_info->atom_context, index, &size,
  1242. &frev, &crev, &data_offset)) {
  1243. igp_info = (union igp_info *)
  1244. (mode_info->atom_context->bios + data_offset);
  1245. switch (crev) {
  1246. case 6:
  1247. switch (id) {
  1248. case ASIC_INTERNAL_SS_ON_TMDS:
  1249. percentage = le16_to_cpu(igp_info->info_6.usDVISSPercentage);
  1250. rate = le16_to_cpu(igp_info->info_6.usDVISSpreadRateIn10Hz);
  1251. break;
  1252. case ASIC_INTERNAL_SS_ON_HDMI:
  1253. percentage = le16_to_cpu(igp_info->info_6.usHDMISSPercentage);
  1254. rate = le16_to_cpu(igp_info->info_6.usHDMISSpreadRateIn10Hz);
  1255. break;
  1256. case ASIC_INTERNAL_SS_ON_LVDS:
  1257. percentage = le16_to_cpu(igp_info->info_6.usLvdsSSPercentage);
  1258. rate = le16_to_cpu(igp_info->info_6.usLvdsSSpreadRateIn10Hz);
  1259. break;
  1260. }
  1261. break;
  1262. case 7:
  1263. switch (id) {
  1264. case ASIC_INTERNAL_SS_ON_TMDS:
  1265. percentage = le16_to_cpu(igp_info->info_7.usDVISSPercentage);
  1266. rate = le16_to_cpu(igp_info->info_7.usDVISSpreadRateIn10Hz);
  1267. break;
  1268. case ASIC_INTERNAL_SS_ON_HDMI:
  1269. percentage = le16_to_cpu(igp_info->info_7.usHDMISSPercentage);
  1270. rate = le16_to_cpu(igp_info->info_7.usHDMISSpreadRateIn10Hz);
  1271. break;
  1272. case ASIC_INTERNAL_SS_ON_LVDS:
  1273. percentage = le16_to_cpu(igp_info->info_7.usLvdsSSPercentage);
  1274. rate = le16_to_cpu(igp_info->info_7.usLvdsSSpreadRateIn10Hz);
  1275. break;
  1276. }
  1277. break;
  1278. default:
  1279. DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
  1280. break;
  1281. }
  1282. if (percentage)
  1283. ss->percentage = percentage;
  1284. if (rate)
  1285. ss->rate = rate;
  1286. }
  1287. }
  1288. union asic_ss_info {
  1289. struct _ATOM_ASIC_INTERNAL_SS_INFO info;
  1290. struct _ATOM_ASIC_INTERNAL_SS_INFO_V2 info_2;
  1291. struct _ATOM_ASIC_INTERNAL_SS_INFO_V3 info_3;
  1292. };
  1293. bool radeon_atombios_get_asic_ss_info(struct radeon_device *rdev,
  1294. struct radeon_atom_ss *ss,
  1295. int id, u32 clock)
  1296. {
  1297. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1298. int index = GetIndexIntoMasterTable(DATA, ASIC_InternalSS_Info);
  1299. uint16_t data_offset, size;
  1300. union asic_ss_info *ss_info;
  1301. uint8_t frev, crev;
  1302. int i, num_indices;
  1303. memset(ss, 0, sizeof(struct radeon_atom_ss));
  1304. if (atom_parse_data_header(mode_info->atom_context, index, &size,
  1305. &frev, &crev, &data_offset)) {
  1306. ss_info =
  1307. (union asic_ss_info *)(mode_info->atom_context->bios + data_offset);
  1308. switch (frev) {
  1309. case 1:
  1310. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1311. sizeof(ATOM_ASIC_SS_ASSIGNMENT);
  1312. for (i = 0; i < num_indices; i++) {
  1313. if ((ss_info->info.asSpreadSpectrum[i].ucClockIndication == id) &&
  1314. (clock <= le32_to_cpu(ss_info->info.asSpreadSpectrum[i].ulTargetClockRange))) {
  1315. ss->percentage =
  1316. le16_to_cpu(ss_info->info.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
  1317. ss->type = ss_info->info.asSpreadSpectrum[i].ucSpreadSpectrumMode;
  1318. ss->rate = le16_to_cpu(ss_info->info.asSpreadSpectrum[i].usSpreadRateInKhz);
  1319. return true;
  1320. }
  1321. }
  1322. break;
  1323. case 2:
  1324. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1325. sizeof(ATOM_ASIC_SS_ASSIGNMENT_V2);
  1326. for (i = 0; i < num_indices; i++) {
  1327. if ((ss_info->info_2.asSpreadSpectrum[i].ucClockIndication == id) &&
  1328. (clock <= le32_to_cpu(ss_info->info_2.asSpreadSpectrum[i].ulTargetClockRange))) {
  1329. ss->percentage =
  1330. le16_to_cpu(ss_info->info_2.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
  1331. ss->type = ss_info->info_2.asSpreadSpectrum[i].ucSpreadSpectrumMode;
  1332. ss->rate = le16_to_cpu(ss_info->info_2.asSpreadSpectrum[i].usSpreadRateIn10Hz);
  1333. return true;
  1334. }
  1335. }
  1336. break;
  1337. case 3:
  1338. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1339. sizeof(ATOM_ASIC_SS_ASSIGNMENT_V3);
  1340. for (i = 0; i < num_indices; i++) {
  1341. if ((ss_info->info_3.asSpreadSpectrum[i].ucClockIndication == id) &&
  1342. (clock <= le32_to_cpu(ss_info->info_3.asSpreadSpectrum[i].ulTargetClockRange))) {
  1343. ss->percentage =
  1344. le16_to_cpu(ss_info->info_3.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
  1345. ss->type = ss_info->info_3.asSpreadSpectrum[i].ucSpreadSpectrumMode;
  1346. ss->rate = le16_to_cpu(ss_info->info_3.asSpreadSpectrum[i].usSpreadRateIn10Hz);
  1347. if (rdev->flags & RADEON_IS_IGP)
  1348. radeon_atombios_get_igp_ss_overrides(rdev, ss, id);
  1349. return true;
  1350. }
  1351. }
  1352. break;
  1353. default:
  1354. DRM_ERROR("Unsupported ASIC_InternalSS_Info table: %d %d\n", frev, crev);
  1355. break;
  1356. }
  1357. }
  1358. return false;
  1359. }
  1360. union lvds_info {
  1361. struct _ATOM_LVDS_INFO info;
  1362. struct _ATOM_LVDS_INFO_V12 info_12;
  1363. };
  1364. struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
  1365. radeon_encoder
  1366. *encoder)
  1367. {
  1368. struct drm_device *dev = encoder->base.dev;
  1369. struct radeon_device *rdev = dev->dev_private;
  1370. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1371. int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
  1372. uint16_t data_offset, misc;
  1373. union lvds_info *lvds_info;
  1374. uint8_t frev, crev;
  1375. struct radeon_encoder_atom_dig *lvds = NULL;
  1376. int encoder_enum = (encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
  1377. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1378. &frev, &crev, &data_offset)) {
  1379. lvds_info =
  1380. (union lvds_info *)(mode_info->atom_context->bios + data_offset);
  1381. lvds =
  1382. kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
  1383. if (!lvds)
  1384. return NULL;
  1385. lvds->native_mode.clock =
  1386. le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
  1387. lvds->native_mode.hdisplay =
  1388. le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
  1389. lvds->native_mode.vdisplay =
  1390. le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
  1391. lvds->native_mode.htotal = lvds->native_mode.hdisplay +
  1392. le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
  1393. lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
  1394. le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
  1395. lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
  1396. le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
  1397. lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
  1398. le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
  1399. lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
  1400. le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncOffset);
  1401. lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
  1402. le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
  1403. lvds->panel_pwr_delay =
  1404. le16_to_cpu(lvds_info->info.usOffDelayInMs);
  1405. lvds->lcd_misc = lvds_info->info.ucLVDS_Misc;
  1406. misc = le16_to_cpu(lvds_info->info.sLCDTiming.susModeMiscInfo.usAccess);
  1407. if (misc & ATOM_VSYNC_POLARITY)
  1408. lvds->native_mode.flags |= DRM_MODE_FLAG_NVSYNC;
  1409. if (misc & ATOM_HSYNC_POLARITY)
  1410. lvds->native_mode.flags |= DRM_MODE_FLAG_NHSYNC;
  1411. if (misc & ATOM_COMPOSITESYNC)
  1412. lvds->native_mode.flags |= DRM_MODE_FLAG_CSYNC;
  1413. if (misc & ATOM_INTERLACE)
  1414. lvds->native_mode.flags |= DRM_MODE_FLAG_INTERLACE;
  1415. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  1416. lvds->native_mode.flags |= DRM_MODE_FLAG_DBLSCAN;
  1417. lvds->native_mode.width_mm = le16_to_cpu(lvds_info->info.sLCDTiming.usImageHSize);
  1418. lvds->native_mode.height_mm = le16_to_cpu(lvds_info->info.sLCDTiming.usImageVSize);
  1419. /* set crtc values */
  1420. drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
  1421. lvds->lcd_ss_id = lvds_info->info.ucSS_Id;
  1422. encoder->native_mode = lvds->native_mode;
  1423. if (encoder_enum == 2)
  1424. lvds->linkb = true;
  1425. else
  1426. lvds->linkb = false;
  1427. /* parse the lcd record table */
  1428. if (le16_to_cpu(lvds_info->info.usModePatchTableOffset)) {
  1429. ATOM_FAKE_EDID_PATCH_RECORD *fake_edid_record;
  1430. ATOM_PANEL_RESOLUTION_PATCH_RECORD *panel_res_record;
  1431. bool bad_record = false;
  1432. u8 *record;
  1433. if ((frev == 1) && (crev < 2))
  1434. /* absolute */
  1435. record = (u8 *)(mode_info->atom_context->bios +
  1436. le16_to_cpu(lvds_info->info.usModePatchTableOffset));
  1437. else
  1438. /* relative */
  1439. record = (u8 *)(mode_info->atom_context->bios +
  1440. data_offset +
  1441. le16_to_cpu(lvds_info->info.usModePatchTableOffset));
  1442. while (*record != ATOM_RECORD_END_TYPE) {
  1443. switch (*record) {
  1444. case LCD_MODE_PATCH_RECORD_MODE_TYPE:
  1445. record += sizeof(ATOM_PATCH_RECORD_MODE);
  1446. break;
  1447. case LCD_RTS_RECORD_TYPE:
  1448. record += sizeof(ATOM_LCD_RTS_RECORD);
  1449. break;
  1450. case LCD_CAP_RECORD_TYPE:
  1451. record += sizeof(ATOM_LCD_MODE_CONTROL_CAP);
  1452. break;
  1453. case LCD_FAKE_EDID_PATCH_RECORD_TYPE:
  1454. fake_edid_record = (ATOM_FAKE_EDID_PATCH_RECORD *)record;
  1455. if (fake_edid_record->ucFakeEDIDLength) {
  1456. struct edid *edid;
  1457. int edid_size =
  1458. max((int)EDID_LENGTH, (int)fake_edid_record->ucFakeEDIDLength);
  1459. edid = kmalloc(edid_size, GFP_KERNEL);
  1460. if (edid) {
  1461. memcpy((u8 *)edid, (u8 *)&fake_edid_record->ucFakeEDIDString[0],
  1462. fake_edid_record->ucFakeEDIDLength);
  1463. if (drm_edid_is_valid(edid)) {
  1464. rdev->mode_info.bios_hardcoded_edid = edid;
  1465. rdev->mode_info.bios_hardcoded_edid_size = edid_size;
  1466. } else
  1467. kfree(edid);
  1468. }
  1469. }
  1470. record += sizeof(ATOM_FAKE_EDID_PATCH_RECORD);
  1471. break;
  1472. case LCD_PANEL_RESOLUTION_RECORD_TYPE:
  1473. panel_res_record = (ATOM_PANEL_RESOLUTION_PATCH_RECORD *)record;
  1474. lvds->native_mode.width_mm = panel_res_record->usHSize;
  1475. lvds->native_mode.height_mm = panel_res_record->usVSize;
  1476. record += sizeof(ATOM_PANEL_RESOLUTION_PATCH_RECORD);
  1477. break;
  1478. default:
  1479. DRM_ERROR("Bad LCD record %d\n", *record);
  1480. bad_record = true;
  1481. break;
  1482. }
  1483. if (bad_record)
  1484. break;
  1485. }
  1486. }
  1487. }
  1488. return lvds;
  1489. }
  1490. struct radeon_encoder_primary_dac *
  1491. radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
  1492. {
  1493. struct drm_device *dev = encoder->base.dev;
  1494. struct radeon_device *rdev = dev->dev_private;
  1495. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1496. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  1497. uint16_t data_offset;
  1498. struct _COMPASSIONATE_DATA *dac_info;
  1499. uint8_t frev, crev;
  1500. uint8_t bg, dac;
  1501. struct radeon_encoder_primary_dac *p_dac = NULL;
  1502. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1503. &frev, &crev, &data_offset)) {
  1504. dac_info = (struct _COMPASSIONATE_DATA *)
  1505. (mode_info->atom_context->bios + data_offset);
  1506. p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
  1507. if (!p_dac)
  1508. return NULL;
  1509. bg = dac_info->ucDAC1_BG_Adjustment;
  1510. dac = dac_info->ucDAC1_DAC_Adjustment;
  1511. p_dac->ps2_pdac_adj = (bg << 8) | (dac);
  1512. }
  1513. return p_dac;
  1514. }
  1515. bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
  1516. struct drm_display_mode *mode)
  1517. {
  1518. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1519. ATOM_ANALOG_TV_INFO *tv_info;
  1520. ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
  1521. ATOM_DTD_FORMAT *dtd_timings;
  1522. int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
  1523. u8 frev, crev;
  1524. u16 data_offset, misc;
  1525. if (!atom_parse_data_header(mode_info->atom_context, data_index, NULL,
  1526. &frev, &crev, &data_offset))
  1527. return false;
  1528. switch (crev) {
  1529. case 1:
  1530. tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
  1531. if (index >= MAX_SUPPORTED_TV_TIMING)
  1532. return false;
  1533. mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
  1534. mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
  1535. mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
  1536. mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
  1537. le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
  1538. mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
  1539. mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
  1540. mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
  1541. mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
  1542. le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
  1543. mode->flags = 0;
  1544. misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
  1545. if (misc & ATOM_VSYNC_POLARITY)
  1546. mode->flags |= DRM_MODE_FLAG_NVSYNC;
  1547. if (misc & ATOM_HSYNC_POLARITY)
  1548. mode->flags |= DRM_MODE_FLAG_NHSYNC;
  1549. if (misc & ATOM_COMPOSITESYNC)
  1550. mode->flags |= DRM_MODE_FLAG_CSYNC;
  1551. if (misc & ATOM_INTERLACE)
  1552. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  1553. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  1554. mode->flags |= DRM_MODE_FLAG_DBLSCAN;
  1555. mode->clock = le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
  1556. if (index == 1) {
  1557. /* PAL timings appear to have wrong values for totals */
  1558. mode->crtc_htotal -= 1;
  1559. mode->crtc_vtotal -= 1;
  1560. }
  1561. break;
  1562. case 2:
  1563. tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
  1564. if (index >= MAX_SUPPORTED_TV_TIMING_V1_2)
  1565. return false;
  1566. dtd_timings = &tv_info_v1_2->aModeTimings[index];
  1567. mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
  1568. le16_to_cpu(dtd_timings->usHBlanking_Time);
  1569. mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
  1570. mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
  1571. le16_to_cpu(dtd_timings->usHSyncOffset);
  1572. mode->crtc_hsync_end = mode->crtc_hsync_start +
  1573. le16_to_cpu(dtd_timings->usHSyncWidth);
  1574. mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
  1575. le16_to_cpu(dtd_timings->usVBlanking_Time);
  1576. mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
  1577. mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
  1578. le16_to_cpu(dtd_timings->usVSyncOffset);
  1579. mode->crtc_vsync_end = mode->crtc_vsync_start +
  1580. le16_to_cpu(dtd_timings->usVSyncWidth);
  1581. mode->flags = 0;
  1582. misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
  1583. if (misc & ATOM_VSYNC_POLARITY)
  1584. mode->flags |= DRM_MODE_FLAG_NVSYNC;
  1585. if (misc & ATOM_HSYNC_POLARITY)
  1586. mode->flags |= DRM_MODE_FLAG_NHSYNC;
  1587. if (misc & ATOM_COMPOSITESYNC)
  1588. mode->flags |= DRM_MODE_FLAG_CSYNC;
  1589. if (misc & ATOM_INTERLACE)
  1590. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  1591. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  1592. mode->flags |= DRM_MODE_FLAG_DBLSCAN;
  1593. mode->clock = le16_to_cpu(dtd_timings->usPixClk) * 10;
  1594. break;
  1595. }
  1596. return true;
  1597. }
  1598. enum radeon_tv_std
  1599. radeon_atombios_get_tv_info(struct radeon_device *rdev)
  1600. {
  1601. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1602. int index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
  1603. uint16_t data_offset;
  1604. uint8_t frev, crev;
  1605. struct _ATOM_ANALOG_TV_INFO *tv_info;
  1606. enum radeon_tv_std tv_std = TV_STD_NTSC;
  1607. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1608. &frev, &crev, &data_offset)) {
  1609. tv_info = (struct _ATOM_ANALOG_TV_INFO *)
  1610. (mode_info->atom_context->bios + data_offset);
  1611. switch (tv_info->ucTV_BootUpDefaultStandard) {
  1612. case ATOM_TV_NTSC:
  1613. tv_std = TV_STD_NTSC;
  1614. DRM_DEBUG_KMS("Default TV standard: NTSC\n");
  1615. break;
  1616. case ATOM_TV_NTSCJ:
  1617. tv_std = TV_STD_NTSC_J;
  1618. DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
  1619. break;
  1620. case ATOM_TV_PAL:
  1621. tv_std = TV_STD_PAL;
  1622. DRM_DEBUG_KMS("Default TV standard: PAL\n");
  1623. break;
  1624. case ATOM_TV_PALM:
  1625. tv_std = TV_STD_PAL_M;
  1626. DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
  1627. break;
  1628. case ATOM_TV_PALN:
  1629. tv_std = TV_STD_PAL_N;
  1630. DRM_DEBUG_KMS("Default TV standard: PAL-N\n");
  1631. break;
  1632. case ATOM_TV_PALCN:
  1633. tv_std = TV_STD_PAL_CN;
  1634. DRM_DEBUG_KMS("Default TV standard: PAL-CN\n");
  1635. break;
  1636. case ATOM_TV_PAL60:
  1637. tv_std = TV_STD_PAL_60;
  1638. DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
  1639. break;
  1640. case ATOM_TV_SECAM:
  1641. tv_std = TV_STD_SECAM;
  1642. DRM_DEBUG_KMS("Default TV standard: SECAM\n");
  1643. break;
  1644. default:
  1645. tv_std = TV_STD_NTSC;
  1646. DRM_DEBUG_KMS("Unknown TV standard; defaulting to NTSC\n");
  1647. break;
  1648. }
  1649. }
  1650. return tv_std;
  1651. }
  1652. struct radeon_encoder_tv_dac *
  1653. radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
  1654. {
  1655. struct drm_device *dev = encoder->base.dev;
  1656. struct radeon_device *rdev = dev->dev_private;
  1657. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1658. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  1659. uint16_t data_offset;
  1660. struct _COMPASSIONATE_DATA *dac_info;
  1661. uint8_t frev, crev;
  1662. uint8_t bg, dac;
  1663. struct radeon_encoder_tv_dac *tv_dac = NULL;
  1664. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1665. &frev, &crev, &data_offset)) {
  1666. dac_info = (struct _COMPASSIONATE_DATA *)
  1667. (mode_info->atom_context->bios + data_offset);
  1668. tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
  1669. if (!tv_dac)
  1670. return NULL;
  1671. bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
  1672. dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
  1673. tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
  1674. bg = dac_info->ucDAC2_PAL_BG_Adjustment;
  1675. dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
  1676. tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
  1677. bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
  1678. dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
  1679. tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
  1680. tv_dac->tv_std = radeon_atombios_get_tv_info(rdev);
  1681. }
  1682. return tv_dac;
  1683. }
  1684. static const char *thermal_controller_names[] = {
  1685. "NONE",
  1686. "lm63",
  1687. "adm1032",
  1688. "adm1030",
  1689. "max6649",
  1690. "lm64",
  1691. "f75375",
  1692. "asc7xxx",
  1693. };
  1694. static const char *pp_lib_thermal_controller_names[] = {
  1695. "NONE",
  1696. "lm63",
  1697. "adm1032",
  1698. "adm1030",
  1699. "max6649",
  1700. "lm64",
  1701. "f75375",
  1702. "RV6xx",
  1703. "RV770",
  1704. "adt7473",
  1705. "NONE",
  1706. "External GPIO",
  1707. "Evergreen",
  1708. "emc2103",
  1709. "Sumo",
  1710. "Northern Islands",
  1711. "Southern Islands",
  1712. "lm96163",
  1713. };
  1714. union power_info {
  1715. struct _ATOM_POWERPLAY_INFO info;
  1716. struct _ATOM_POWERPLAY_INFO_V2 info_2;
  1717. struct _ATOM_POWERPLAY_INFO_V3 info_3;
  1718. struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
  1719. struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
  1720. struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
  1721. };
  1722. union pplib_clock_info {
  1723. struct _ATOM_PPLIB_R600_CLOCK_INFO r600;
  1724. struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780;
  1725. struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen;
  1726. struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo;
  1727. struct _ATOM_PPLIB_SI_CLOCK_INFO si;
  1728. };
  1729. union pplib_power_state {
  1730. struct _ATOM_PPLIB_STATE v1;
  1731. struct _ATOM_PPLIB_STATE_V2 v2;
  1732. };
  1733. static void radeon_atombios_parse_misc_flags_1_3(struct radeon_device *rdev,
  1734. int state_index,
  1735. u32 misc, u32 misc2)
  1736. {
  1737. rdev->pm.power_state[state_index].misc = misc;
  1738. rdev->pm.power_state[state_index].misc2 = misc2;
  1739. /* order matters! */
  1740. if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
  1741. rdev->pm.power_state[state_index].type =
  1742. POWER_STATE_TYPE_POWERSAVE;
  1743. if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
  1744. rdev->pm.power_state[state_index].type =
  1745. POWER_STATE_TYPE_BATTERY;
  1746. if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
  1747. rdev->pm.power_state[state_index].type =
  1748. POWER_STATE_TYPE_BATTERY;
  1749. if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
  1750. rdev->pm.power_state[state_index].type =
  1751. POWER_STATE_TYPE_BALANCED;
  1752. if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
  1753. rdev->pm.power_state[state_index].type =
  1754. POWER_STATE_TYPE_PERFORMANCE;
  1755. rdev->pm.power_state[state_index].flags &=
  1756. ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1757. }
  1758. if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
  1759. rdev->pm.power_state[state_index].type =
  1760. POWER_STATE_TYPE_BALANCED;
  1761. if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
  1762. rdev->pm.power_state[state_index].type =
  1763. POWER_STATE_TYPE_DEFAULT;
  1764. rdev->pm.default_power_state_index = state_index;
  1765. rdev->pm.power_state[state_index].default_clock_mode =
  1766. &rdev->pm.power_state[state_index].clock_info[0];
  1767. } else if (state_index == 0) {
  1768. rdev->pm.power_state[state_index].clock_info[0].flags |=
  1769. RADEON_PM_MODE_NO_DISPLAY;
  1770. }
  1771. }
  1772. static int radeon_atombios_parse_power_table_1_3(struct radeon_device *rdev)
  1773. {
  1774. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1775. u32 misc, misc2 = 0;
  1776. int num_modes = 0, i;
  1777. int state_index = 0;
  1778. struct radeon_i2c_bus_rec i2c_bus;
  1779. union power_info *power_info;
  1780. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  1781. u16 data_offset;
  1782. u8 frev, crev;
  1783. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  1784. &frev, &crev, &data_offset))
  1785. return state_index;
  1786. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  1787. /* add the i2c bus for thermal/fan chip */
  1788. if ((power_info->info.ucOverdriveThermalController > 0) &&
  1789. (power_info->info.ucOverdriveThermalController < ARRAY_SIZE(thermal_controller_names))) {
  1790. DRM_INFO("Possible %s thermal controller at 0x%02x\n",
  1791. thermal_controller_names[power_info->info.ucOverdriveThermalController],
  1792. power_info->info.ucOverdriveControllerAddress >> 1);
  1793. i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine);
  1794. rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  1795. if (rdev->pm.i2c_bus) {
  1796. struct i2c_board_info info = { };
  1797. const char *name = thermal_controller_names[power_info->info.
  1798. ucOverdriveThermalController];
  1799. info.addr = power_info->info.ucOverdriveControllerAddress >> 1;
  1800. strlcpy(info.type, name, sizeof(info.type));
  1801. i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
  1802. }
  1803. }
  1804. num_modes = power_info->info.ucNumOfPowerModeEntries;
  1805. if (num_modes > ATOM_MAX_NUMBEROF_POWER_BLOCK)
  1806. num_modes = ATOM_MAX_NUMBEROF_POWER_BLOCK;
  1807. rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) * num_modes, GFP_KERNEL);
  1808. if (!rdev->pm.power_state)
  1809. return state_index;
  1810. /* last mode is usually default, array is low to high */
  1811. for (i = 0; i < num_modes; i++) {
  1812. rdev->pm.power_state[state_index].clock_info =
  1813. kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
  1814. if (!rdev->pm.power_state[state_index].clock_info)
  1815. return state_index;
  1816. rdev->pm.power_state[state_index].num_clock_modes = 1;
  1817. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
  1818. switch (frev) {
  1819. case 1:
  1820. rdev->pm.power_state[state_index].clock_info[0].mclk =
  1821. le16_to_cpu(power_info->info.asPowerPlayInfo[i].usMemoryClock);
  1822. rdev->pm.power_state[state_index].clock_info[0].sclk =
  1823. le16_to_cpu(power_info->info.asPowerPlayInfo[i].usEngineClock);
  1824. /* skip invalid modes */
  1825. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  1826. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  1827. continue;
  1828. rdev->pm.power_state[state_index].pcie_lanes =
  1829. power_info->info.asPowerPlayInfo[i].ucNumPciELanes;
  1830. misc = le32_to_cpu(power_info->info.asPowerPlayInfo[i].ulMiscInfo);
  1831. if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
  1832. (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
  1833. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1834. VOLTAGE_GPIO;
  1835. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
  1836. radeon_lookup_gpio(rdev,
  1837. power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex);
  1838. if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
  1839. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1840. true;
  1841. else
  1842. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1843. false;
  1844. } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
  1845. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1846. VOLTAGE_VDDC;
  1847. rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
  1848. power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex;
  1849. }
  1850. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1851. radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, 0);
  1852. state_index++;
  1853. break;
  1854. case 2:
  1855. rdev->pm.power_state[state_index].clock_info[0].mclk =
  1856. le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMemoryClock);
  1857. rdev->pm.power_state[state_index].clock_info[0].sclk =
  1858. le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulEngineClock);
  1859. /* skip invalid modes */
  1860. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  1861. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  1862. continue;
  1863. rdev->pm.power_state[state_index].pcie_lanes =
  1864. power_info->info_2.asPowerPlayInfo[i].ucNumPciELanes;
  1865. misc = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo);
  1866. misc2 = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo2);
  1867. if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
  1868. (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
  1869. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1870. VOLTAGE_GPIO;
  1871. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
  1872. radeon_lookup_gpio(rdev,
  1873. power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex);
  1874. if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
  1875. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1876. true;
  1877. else
  1878. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1879. false;
  1880. } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
  1881. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1882. VOLTAGE_VDDC;
  1883. rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
  1884. power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex;
  1885. }
  1886. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1887. radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2);
  1888. state_index++;
  1889. break;
  1890. case 3:
  1891. rdev->pm.power_state[state_index].clock_info[0].mclk =
  1892. le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMemoryClock);
  1893. rdev->pm.power_state[state_index].clock_info[0].sclk =
  1894. le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulEngineClock);
  1895. /* skip invalid modes */
  1896. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  1897. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  1898. continue;
  1899. rdev->pm.power_state[state_index].pcie_lanes =
  1900. power_info->info_3.asPowerPlayInfo[i].ucNumPciELanes;
  1901. misc = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo);
  1902. misc2 = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo2);
  1903. if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
  1904. (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
  1905. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1906. VOLTAGE_GPIO;
  1907. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
  1908. radeon_lookup_gpio(rdev,
  1909. power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex);
  1910. if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
  1911. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1912. true;
  1913. else
  1914. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1915. false;
  1916. } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
  1917. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1918. VOLTAGE_VDDC;
  1919. rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
  1920. power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex;
  1921. if (misc2 & ATOM_PM_MISCINFO2_VDDCI_DYNAMIC_VOLTAGE_EN) {
  1922. rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_enabled =
  1923. true;
  1924. rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_id =
  1925. power_info->info_3.asPowerPlayInfo[i].ucVDDCI_VoltageDropIndex;
  1926. }
  1927. }
  1928. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1929. radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2);
  1930. state_index++;
  1931. break;
  1932. }
  1933. }
  1934. /* last mode is usually default */
  1935. if (rdev->pm.default_power_state_index == -1) {
  1936. rdev->pm.power_state[state_index - 1].type =
  1937. POWER_STATE_TYPE_DEFAULT;
  1938. rdev->pm.default_power_state_index = state_index - 1;
  1939. rdev->pm.power_state[state_index - 1].default_clock_mode =
  1940. &rdev->pm.power_state[state_index - 1].clock_info[0];
  1941. rdev->pm.power_state[state_index].flags &=
  1942. ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1943. rdev->pm.power_state[state_index].misc = 0;
  1944. rdev->pm.power_state[state_index].misc2 = 0;
  1945. }
  1946. return state_index;
  1947. }
  1948. static void radeon_atombios_add_pplib_thermal_controller(struct radeon_device *rdev,
  1949. ATOM_PPLIB_THERMALCONTROLLER *controller)
  1950. {
  1951. struct radeon_i2c_bus_rec i2c_bus;
  1952. /* add the i2c bus for thermal/fan chip */
  1953. if (controller->ucType > 0) {
  1954. if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV6xx) {
  1955. DRM_INFO("Internal thermal controller %s fan control\n",
  1956. (controller->ucFanParameters &
  1957. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1958. rdev->pm.int_thermal_type = THERMAL_TYPE_RV6XX;
  1959. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV770) {
  1960. DRM_INFO("Internal thermal controller %s fan control\n",
  1961. (controller->ucFanParameters &
  1962. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1963. rdev->pm.int_thermal_type = THERMAL_TYPE_RV770;
  1964. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EVERGREEN) {
  1965. DRM_INFO("Internal thermal controller %s fan control\n",
  1966. (controller->ucFanParameters &
  1967. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1968. rdev->pm.int_thermal_type = THERMAL_TYPE_EVERGREEN;
  1969. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SUMO) {
  1970. DRM_INFO("Internal thermal controller %s fan control\n",
  1971. (controller->ucFanParameters &
  1972. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1973. rdev->pm.int_thermal_type = THERMAL_TYPE_SUMO;
  1974. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_NISLANDS) {
  1975. DRM_INFO("Internal thermal controller %s fan control\n",
  1976. (controller->ucFanParameters &
  1977. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1978. rdev->pm.int_thermal_type = THERMAL_TYPE_NI;
  1979. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SISLANDS) {
  1980. DRM_INFO("Internal thermal controller %s fan control\n",
  1981. (controller->ucFanParameters &
  1982. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1983. rdev->pm.int_thermal_type = THERMAL_TYPE_SI;
  1984. } else if ((controller->ucType ==
  1985. ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO) ||
  1986. (controller->ucType ==
  1987. ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL) ||
  1988. (controller->ucType ==
  1989. ATOM_PP_THERMALCONTROLLER_EMC2103_WITH_INTERNAL)) {
  1990. DRM_INFO("Special thermal controller config\n");
  1991. } else if (controller->ucType < ARRAY_SIZE(pp_lib_thermal_controller_names)) {
  1992. DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
  1993. pp_lib_thermal_controller_names[controller->ucType],
  1994. controller->ucI2cAddress >> 1,
  1995. (controller->ucFanParameters &
  1996. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1997. i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine);
  1998. rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  1999. if (rdev->pm.i2c_bus) {
  2000. struct i2c_board_info info = { };
  2001. const char *name = pp_lib_thermal_controller_names[controller->ucType];
  2002. info.addr = controller->ucI2cAddress >> 1;
  2003. strlcpy(info.type, name, sizeof(info.type));
  2004. i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
  2005. }
  2006. } else {
  2007. DRM_INFO("Unknown thermal controller type %d at 0x%02x %s fan control\n",
  2008. controller->ucType,
  2009. controller->ucI2cAddress >> 1,
  2010. (controller->ucFanParameters &
  2011. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  2012. }
  2013. }
  2014. }
  2015. static void radeon_atombios_get_default_voltages(struct radeon_device *rdev,
  2016. u16 *vddc, u16 *vddci)
  2017. {
  2018. struct radeon_mode_info *mode_info = &rdev->mode_info;
  2019. int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
  2020. u8 frev, crev;
  2021. u16 data_offset;
  2022. union firmware_info *firmware_info;
  2023. *vddc = 0;
  2024. *vddci = 0;
  2025. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  2026. &frev, &crev, &data_offset)) {
  2027. firmware_info =
  2028. (union firmware_info *)(mode_info->atom_context->bios +
  2029. data_offset);
  2030. *vddc = le16_to_cpu(firmware_info->info_14.usBootUpVDDCVoltage);
  2031. if ((frev == 2) && (crev >= 2))
  2032. *vddci = le16_to_cpu(firmware_info->info_22.usBootUpVDDCIVoltage);
  2033. }
  2034. }
  2035. static void radeon_atombios_parse_pplib_non_clock_info(struct radeon_device *rdev,
  2036. int state_index, int mode_index,
  2037. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info)
  2038. {
  2039. int j;
  2040. u32 misc = le32_to_cpu(non_clock_info->ulCapsAndSettings);
  2041. u32 misc2 = le16_to_cpu(non_clock_info->usClassification);
  2042. u16 vddc, vddci;
  2043. radeon_atombios_get_default_voltages(rdev, &vddc, &vddci);
  2044. rdev->pm.power_state[state_index].misc = misc;
  2045. rdev->pm.power_state[state_index].misc2 = misc2;
  2046. rdev->pm.power_state[state_index].pcie_lanes =
  2047. ((misc & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >>
  2048. ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
  2049. switch (misc2 & ATOM_PPLIB_CLASSIFICATION_UI_MASK) {
  2050. case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY:
  2051. rdev->pm.power_state[state_index].type =
  2052. POWER_STATE_TYPE_BATTERY;
  2053. break;
  2054. case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED:
  2055. rdev->pm.power_state[state_index].type =
  2056. POWER_STATE_TYPE_BALANCED;
  2057. break;
  2058. case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE:
  2059. rdev->pm.power_state[state_index].type =
  2060. POWER_STATE_TYPE_PERFORMANCE;
  2061. break;
  2062. case ATOM_PPLIB_CLASSIFICATION_UI_NONE:
  2063. if (misc2 & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
  2064. rdev->pm.power_state[state_index].type =
  2065. POWER_STATE_TYPE_PERFORMANCE;
  2066. break;
  2067. }
  2068. rdev->pm.power_state[state_index].flags = 0;
  2069. if (misc & ATOM_PPLIB_SINGLE_DISPLAY_ONLY)
  2070. rdev->pm.power_state[state_index].flags |=
  2071. RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  2072. if (misc2 & ATOM_PPLIB_CLASSIFICATION_BOOT) {
  2073. rdev->pm.power_state[state_index].type =
  2074. POWER_STATE_TYPE_DEFAULT;
  2075. rdev->pm.default_power_state_index = state_index;
  2076. rdev->pm.power_state[state_index].default_clock_mode =
  2077. &rdev->pm.power_state[state_index].clock_info[mode_index - 1];
  2078. if (ASIC_IS_DCE5(rdev) && !(rdev->flags & RADEON_IS_IGP)) {
  2079. /* NI chips post without MC ucode, so default clocks are strobe mode only */
  2080. rdev->pm.default_sclk = rdev->pm.power_state[state_index].clock_info[0].sclk;
  2081. rdev->pm.default_mclk = rdev->pm.power_state[state_index].clock_info[0].mclk;
  2082. rdev->pm.default_vddc = rdev->pm.power_state[state_index].clock_info[0].voltage.voltage;
  2083. rdev->pm.default_vddci = rdev->pm.power_state[state_index].clock_info[0].voltage.vddci;
  2084. } else {
  2085. /* patch the table values with the default slck/mclk from firmware info */
  2086. for (j = 0; j < mode_index; j++) {
  2087. rdev->pm.power_state[state_index].clock_info[j].mclk =
  2088. rdev->clock.default_mclk;
  2089. rdev->pm.power_state[state_index].clock_info[j].sclk =
  2090. rdev->clock.default_sclk;
  2091. if (vddc)
  2092. rdev->pm.power_state[state_index].clock_info[j].voltage.voltage =
  2093. vddc;
  2094. }
  2095. }
  2096. }
  2097. }
  2098. static bool radeon_atombios_parse_pplib_clock_info(struct radeon_device *rdev,
  2099. int state_index, int mode_index,
  2100. union pplib_clock_info *clock_info)
  2101. {
  2102. u32 sclk, mclk;
  2103. u16 vddc;
  2104. if (rdev->flags & RADEON_IS_IGP) {
  2105. if (rdev->family >= CHIP_PALM) {
  2106. sclk = le16_to_cpu(clock_info->sumo.usEngineClockLow);
  2107. sclk |= clock_info->sumo.ucEngineClockHigh << 16;
  2108. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  2109. } else {
  2110. sclk = le16_to_cpu(clock_info->rs780.usLowEngineClockLow);
  2111. sclk |= clock_info->rs780.ucLowEngineClockHigh << 16;
  2112. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  2113. }
  2114. } else if (ASIC_IS_DCE6(rdev)) {
  2115. sclk = le16_to_cpu(clock_info->si.usEngineClockLow);
  2116. sclk |= clock_info->si.ucEngineClockHigh << 16;
  2117. mclk = le16_to_cpu(clock_info->si.usMemoryClockLow);
  2118. mclk |= clock_info->si.ucMemoryClockHigh << 16;
  2119. rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
  2120. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  2121. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
  2122. VOLTAGE_SW;
  2123. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
  2124. le16_to_cpu(clock_info->si.usVDDC);
  2125. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.vddci =
  2126. le16_to_cpu(clock_info->si.usVDDCI);
  2127. } else if (ASIC_IS_DCE4(rdev)) {
  2128. sclk = le16_to_cpu(clock_info->evergreen.usEngineClockLow);
  2129. sclk |= clock_info->evergreen.ucEngineClockHigh << 16;
  2130. mclk = le16_to_cpu(clock_info->evergreen.usMemoryClockLow);
  2131. mclk |= clock_info->evergreen.ucMemoryClockHigh << 16;
  2132. rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
  2133. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  2134. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
  2135. VOLTAGE_SW;
  2136. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
  2137. le16_to_cpu(clock_info->evergreen.usVDDC);
  2138. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.vddci =
  2139. le16_to_cpu(clock_info->evergreen.usVDDCI);
  2140. } else {
  2141. sclk = le16_to_cpu(clock_info->r600.usEngineClockLow);
  2142. sclk |= clock_info->r600.ucEngineClockHigh << 16;
  2143. mclk = le16_to_cpu(clock_info->r600.usMemoryClockLow);
  2144. mclk |= clock_info->r600.ucMemoryClockHigh << 16;
  2145. rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
  2146. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  2147. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
  2148. VOLTAGE_SW;
  2149. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
  2150. le16_to_cpu(clock_info->r600.usVDDC);
  2151. }
  2152. /* patch up vddc if necessary */
  2153. switch (rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage) {
  2154. case ATOM_VIRTUAL_VOLTAGE_ID0:
  2155. case ATOM_VIRTUAL_VOLTAGE_ID1:
  2156. case ATOM_VIRTUAL_VOLTAGE_ID2:
  2157. case ATOM_VIRTUAL_VOLTAGE_ID3:
  2158. if (radeon_atom_get_max_vddc(rdev, VOLTAGE_TYPE_VDDC,
  2159. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage,
  2160. &vddc) == 0)
  2161. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage = vddc;
  2162. break;
  2163. default:
  2164. break;
  2165. }
  2166. if (rdev->flags & RADEON_IS_IGP) {
  2167. /* skip invalid modes */
  2168. if (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0)
  2169. return false;
  2170. } else {
  2171. /* skip invalid modes */
  2172. if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
  2173. (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
  2174. return false;
  2175. }
  2176. return true;
  2177. }
  2178. static int radeon_atombios_parse_power_table_4_5(struct radeon_device *rdev)
  2179. {
  2180. struct radeon_mode_info *mode_info = &rdev->mode_info;
  2181. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
  2182. union pplib_power_state *power_state;
  2183. int i, j;
  2184. int state_index = 0, mode_index = 0;
  2185. union pplib_clock_info *clock_info;
  2186. bool valid;
  2187. union power_info *power_info;
  2188. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  2189. u16 data_offset;
  2190. u8 frev, crev;
  2191. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  2192. &frev, &crev, &data_offset))
  2193. return state_index;
  2194. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  2195. radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
  2196. rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) *
  2197. power_info->pplib.ucNumStates, GFP_KERNEL);
  2198. if (!rdev->pm.power_state)
  2199. return state_index;
  2200. /* first mode is usually default, followed by low to high */
  2201. for (i = 0; i < power_info->pplib.ucNumStates; i++) {
  2202. mode_index = 0;
  2203. power_state = (union pplib_power_state *)
  2204. (mode_info->atom_context->bios + data_offset +
  2205. le16_to_cpu(power_info->pplib.usStateArrayOffset) +
  2206. i * power_info->pplib.ucStateEntrySize);
  2207. non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
  2208. (mode_info->atom_context->bios + data_offset +
  2209. le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset) +
  2210. (power_state->v1.ucNonClockStateIndex *
  2211. power_info->pplib.ucNonClockSize));
  2212. rdev->pm.power_state[i].clock_info = kzalloc(sizeof(struct radeon_pm_clock_info) *
  2213. ((power_info->pplib.ucStateEntrySize - 1) ?
  2214. (power_info->pplib.ucStateEntrySize - 1) : 1),
  2215. GFP_KERNEL);
  2216. if (!rdev->pm.power_state[i].clock_info)
  2217. return state_index;
  2218. if (power_info->pplib.ucStateEntrySize - 1) {
  2219. for (j = 0; j < (power_info->pplib.ucStateEntrySize - 1); j++) {
  2220. clock_info = (union pplib_clock_info *)
  2221. (mode_info->atom_context->bios + data_offset +
  2222. le16_to_cpu(power_info->pplib.usClockInfoArrayOffset) +
  2223. (power_state->v1.ucClockStateIndices[j] *
  2224. power_info->pplib.ucClockInfoSize));
  2225. valid = radeon_atombios_parse_pplib_clock_info(rdev,
  2226. state_index, mode_index,
  2227. clock_info);
  2228. if (valid)
  2229. mode_index++;
  2230. }
  2231. } else {
  2232. rdev->pm.power_state[state_index].clock_info[0].mclk =
  2233. rdev->clock.default_mclk;
  2234. rdev->pm.power_state[state_index].clock_info[0].sclk =
  2235. rdev->clock.default_sclk;
  2236. mode_index++;
  2237. }
  2238. rdev->pm.power_state[state_index].num_clock_modes = mode_index;
  2239. if (mode_index) {
  2240. radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
  2241. non_clock_info);
  2242. state_index++;
  2243. }
  2244. }
  2245. /* if multiple clock modes, mark the lowest as no display */
  2246. for (i = 0; i < state_index; i++) {
  2247. if (rdev->pm.power_state[i].num_clock_modes > 1)
  2248. rdev->pm.power_state[i].clock_info[0].flags |=
  2249. RADEON_PM_MODE_NO_DISPLAY;
  2250. }
  2251. /* first mode is usually default */
  2252. if (rdev->pm.default_power_state_index == -1) {
  2253. rdev->pm.power_state[0].type =
  2254. POWER_STATE_TYPE_DEFAULT;
  2255. rdev->pm.default_power_state_index = 0;
  2256. rdev->pm.power_state[0].default_clock_mode =
  2257. &rdev->pm.power_state[0].clock_info[0];
  2258. }
  2259. return state_index;
  2260. }
  2261. static int radeon_atombios_parse_power_table_6(struct radeon_device *rdev)
  2262. {
  2263. struct radeon_mode_info *mode_info = &rdev->mode_info;
  2264. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
  2265. union pplib_power_state *power_state;
  2266. int i, j, non_clock_array_index, clock_array_index;
  2267. int state_index = 0, mode_index = 0;
  2268. union pplib_clock_info *clock_info;
  2269. struct _StateArray *state_array;
  2270. struct _ClockInfoArray *clock_info_array;
  2271. struct _NonClockInfoArray *non_clock_info_array;
  2272. bool valid;
  2273. union power_info *power_info;
  2274. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  2275. u16 data_offset;
  2276. u8 frev, crev;
  2277. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  2278. &frev, &crev, &data_offset))
  2279. return state_index;
  2280. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  2281. radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
  2282. state_array = (struct _StateArray *)
  2283. (mode_info->atom_context->bios + data_offset +
  2284. le16_to_cpu(power_info->pplib.usStateArrayOffset));
  2285. clock_info_array = (struct _ClockInfoArray *)
  2286. (mode_info->atom_context->bios + data_offset +
  2287. le16_to_cpu(power_info->pplib.usClockInfoArrayOffset));
  2288. non_clock_info_array = (struct _NonClockInfoArray *)
  2289. (mode_info->atom_context->bios + data_offset +
  2290. le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset));
  2291. rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) *
  2292. state_array->ucNumEntries, GFP_KERNEL);
  2293. if (!rdev->pm.power_state)
  2294. return state_index;
  2295. for (i = 0; i < state_array->ucNumEntries; i++) {
  2296. mode_index = 0;
  2297. power_state = (union pplib_power_state *)&state_array->states[i];
  2298. /* XXX this might be an inagua bug... */
  2299. non_clock_array_index = i; /* power_state->v2.nonClockInfoIndex */
  2300. non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
  2301. &non_clock_info_array->nonClockInfo[non_clock_array_index];
  2302. rdev->pm.power_state[i].clock_info = kzalloc(sizeof(struct radeon_pm_clock_info) *
  2303. (power_state->v2.ucNumDPMLevels ?
  2304. power_state->v2.ucNumDPMLevels : 1),
  2305. GFP_KERNEL);
  2306. if (!rdev->pm.power_state[i].clock_info)
  2307. return state_index;
  2308. if (power_state->v2.ucNumDPMLevels) {
  2309. for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) {
  2310. clock_array_index = power_state->v2.clockInfoIndex[j];
  2311. /* XXX this might be an inagua bug... */
  2312. if (clock_array_index >= clock_info_array->ucNumEntries)
  2313. continue;
  2314. clock_info = (union pplib_clock_info *)
  2315. &clock_info_array->clockInfo[clock_array_index * clock_info_array->ucEntrySize];
  2316. valid = radeon_atombios_parse_pplib_clock_info(rdev,
  2317. state_index, mode_index,
  2318. clock_info);
  2319. if (valid)
  2320. mode_index++;
  2321. }
  2322. } else {
  2323. rdev->pm.power_state[state_index].clock_info[0].mclk =
  2324. rdev->clock.default_mclk;
  2325. rdev->pm.power_state[state_index].clock_info[0].sclk =
  2326. rdev->clock.default_sclk;
  2327. mode_index++;
  2328. }
  2329. rdev->pm.power_state[state_index].num_clock_modes = mode_index;
  2330. if (mode_index) {
  2331. radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
  2332. non_clock_info);
  2333. state_index++;
  2334. }
  2335. }
  2336. /* if multiple clock modes, mark the lowest as no display */
  2337. for (i = 0; i < state_index; i++) {
  2338. if (rdev->pm.power_state[i].num_clock_modes > 1)
  2339. rdev->pm.power_state[i].clock_info[0].flags |=
  2340. RADEON_PM_MODE_NO_DISPLAY;
  2341. }
  2342. /* first mode is usually default */
  2343. if (rdev->pm.default_power_state_index == -1) {
  2344. rdev->pm.power_state[0].type =
  2345. POWER_STATE_TYPE_DEFAULT;
  2346. rdev->pm.default_power_state_index = 0;
  2347. rdev->pm.power_state[0].default_clock_mode =
  2348. &rdev->pm.power_state[0].clock_info[0];
  2349. }
  2350. return state_index;
  2351. }
  2352. void radeon_atombios_get_power_modes(struct radeon_device *rdev)
  2353. {
  2354. struct radeon_mode_info *mode_info = &rdev->mode_info;
  2355. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  2356. u16 data_offset;
  2357. u8 frev, crev;
  2358. int state_index = 0;
  2359. rdev->pm.default_power_state_index = -1;
  2360. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  2361. &frev, &crev, &data_offset)) {
  2362. switch (frev) {
  2363. case 1:
  2364. case 2:
  2365. case 3:
  2366. state_index = radeon_atombios_parse_power_table_1_3(rdev);
  2367. break;
  2368. case 4:
  2369. case 5:
  2370. state_index = radeon_atombios_parse_power_table_4_5(rdev);
  2371. break;
  2372. case 6:
  2373. state_index = radeon_atombios_parse_power_table_6(rdev);
  2374. break;
  2375. default:
  2376. break;
  2377. }
  2378. } else {
  2379. rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state), GFP_KERNEL);
  2380. if (rdev->pm.power_state) {
  2381. rdev->pm.power_state[0].clock_info =
  2382. kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
  2383. if (rdev->pm.power_state[0].clock_info) {
  2384. /* add the default mode */
  2385. rdev->pm.power_state[state_index].type =
  2386. POWER_STATE_TYPE_DEFAULT;
  2387. rdev->pm.power_state[state_index].num_clock_modes = 1;
  2388. rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
  2389. rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
  2390. rdev->pm.power_state[state_index].default_clock_mode =
  2391. &rdev->pm.power_state[state_index].clock_info[0];
  2392. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
  2393. rdev->pm.power_state[state_index].pcie_lanes = 16;
  2394. rdev->pm.default_power_state_index = state_index;
  2395. rdev->pm.power_state[state_index].flags = 0;
  2396. state_index++;
  2397. }
  2398. }
  2399. }
  2400. rdev->pm.num_power_states = state_index;
  2401. rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
  2402. rdev->pm.current_clock_mode_index = 0;
  2403. if (rdev->pm.default_power_state_index >= 0)
  2404. rdev->pm.current_vddc =
  2405. rdev->pm.power_state[rdev->pm.default_power_state_index].clock_info[0].voltage.voltage;
  2406. else
  2407. rdev->pm.current_vddc = 0;
  2408. }
  2409. void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
  2410. {
  2411. DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
  2412. int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
  2413. args.ucEnable = enable;
  2414. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2415. }
  2416. uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
  2417. {
  2418. GET_ENGINE_CLOCK_PS_ALLOCATION args;
  2419. int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
  2420. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2421. return le32_to_cpu(args.ulReturnEngineClock);
  2422. }
  2423. uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
  2424. {
  2425. GET_MEMORY_CLOCK_PS_ALLOCATION args;
  2426. int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
  2427. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2428. return le32_to_cpu(args.ulReturnMemoryClock);
  2429. }
  2430. void radeon_atom_set_engine_clock(struct radeon_device *rdev,
  2431. uint32_t eng_clock)
  2432. {
  2433. SET_ENGINE_CLOCK_PS_ALLOCATION args;
  2434. int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
  2435. args.ulTargetEngineClock = cpu_to_le32(eng_clock); /* 10 khz */
  2436. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2437. }
  2438. void radeon_atom_set_memory_clock(struct radeon_device *rdev,
  2439. uint32_t mem_clock)
  2440. {
  2441. SET_MEMORY_CLOCK_PS_ALLOCATION args;
  2442. int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
  2443. if (rdev->flags & RADEON_IS_IGP)
  2444. return;
  2445. args.ulTargetMemoryClock = cpu_to_le32(mem_clock); /* 10 khz */
  2446. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2447. }
  2448. union set_voltage {
  2449. struct _SET_VOLTAGE_PS_ALLOCATION alloc;
  2450. struct _SET_VOLTAGE_PARAMETERS v1;
  2451. struct _SET_VOLTAGE_PARAMETERS_V2 v2;
  2452. struct _SET_VOLTAGE_PARAMETERS_V1_3 v3;
  2453. };
  2454. void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type)
  2455. {
  2456. union set_voltage args;
  2457. int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
  2458. u8 frev, crev, volt_index = voltage_level;
  2459. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  2460. return;
  2461. /* 0xff01 is a flag rather then an actual voltage */
  2462. if (voltage_level == 0xff01)
  2463. return;
  2464. switch (crev) {
  2465. case 1:
  2466. args.v1.ucVoltageType = voltage_type;
  2467. args.v1.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_ALL_SOURCE;
  2468. args.v1.ucVoltageIndex = volt_index;
  2469. break;
  2470. case 2:
  2471. args.v2.ucVoltageType = voltage_type;
  2472. args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE;
  2473. args.v2.usVoltageLevel = cpu_to_le16(voltage_level);
  2474. break;
  2475. case 3:
  2476. args.v3.ucVoltageType = voltage_type;
  2477. args.v3.ucVoltageMode = ATOM_SET_VOLTAGE;
  2478. args.v3.usVoltageLevel = cpu_to_le16(voltage_level);
  2479. break;
  2480. default:
  2481. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  2482. return;
  2483. }
  2484. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2485. }
  2486. static int radeon_atom_get_max_vddc(struct radeon_device *rdev, u8 voltage_type,
  2487. u16 voltage_id, u16 *voltage)
  2488. {
  2489. union set_voltage args;
  2490. int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
  2491. u8 frev, crev;
  2492. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  2493. return -EINVAL;
  2494. switch (crev) {
  2495. case 1:
  2496. return -EINVAL;
  2497. case 2:
  2498. args.v2.ucVoltageType = SET_VOLTAGE_GET_MAX_VOLTAGE;
  2499. args.v2.ucVoltageMode = 0;
  2500. args.v2.usVoltageLevel = 0;
  2501. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2502. *voltage = le16_to_cpu(args.v2.usVoltageLevel);
  2503. break;
  2504. case 3:
  2505. args.v3.ucVoltageType = voltage_type;
  2506. args.v3.ucVoltageMode = ATOM_GET_VOLTAGE_LEVEL;
  2507. args.v3.usVoltageLevel = cpu_to_le16(voltage_id);
  2508. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2509. *voltage = le16_to_cpu(args.v3.usVoltageLevel);
  2510. break;
  2511. default:
  2512. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  2513. return -EINVAL;
  2514. }
  2515. return 0;
  2516. }
  2517. void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
  2518. {
  2519. struct radeon_device *rdev = dev->dev_private;
  2520. uint32_t bios_2_scratch, bios_6_scratch;
  2521. if (rdev->family >= CHIP_R600) {
  2522. bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
  2523. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  2524. } else {
  2525. bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
  2526. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  2527. }
  2528. /* let the bios control the backlight */
  2529. bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
  2530. /* tell the bios not to handle mode switching */
  2531. bios_6_scratch |= ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH;
  2532. if (rdev->family >= CHIP_R600) {
  2533. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  2534. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  2535. } else {
  2536. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  2537. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  2538. }
  2539. }
  2540. void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
  2541. {
  2542. uint32_t scratch_reg;
  2543. int i;
  2544. if (rdev->family >= CHIP_R600)
  2545. scratch_reg = R600_BIOS_0_SCRATCH;
  2546. else
  2547. scratch_reg = RADEON_BIOS_0_SCRATCH;
  2548. for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
  2549. rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
  2550. }
  2551. void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
  2552. {
  2553. uint32_t scratch_reg;
  2554. int i;
  2555. if (rdev->family >= CHIP_R600)
  2556. scratch_reg = R600_BIOS_0_SCRATCH;
  2557. else
  2558. scratch_reg = RADEON_BIOS_0_SCRATCH;
  2559. for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
  2560. WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
  2561. }
  2562. void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
  2563. {
  2564. struct drm_device *dev = encoder->dev;
  2565. struct radeon_device *rdev = dev->dev_private;
  2566. uint32_t bios_6_scratch;
  2567. if (rdev->family >= CHIP_R600)
  2568. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  2569. else
  2570. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  2571. if (lock) {
  2572. bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
  2573. bios_6_scratch &= ~ATOM_S6_ACC_MODE;
  2574. } else {
  2575. bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
  2576. bios_6_scratch |= ATOM_S6_ACC_MODE;
  2577. }
  2578. if (rdev->family >= CHIP_R600)
  2579. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  2580. else
  2581. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  2582. }
  2583. /* at some point we may want to break this out into individual functions */
  2584. void
  2585. radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
  2586. struct drm_encoder *encoder,
  2587. bool connected)
  2588. {
  2589. struct drm_device *dev = connector->dev;
  2590. struct radeon_device *rdev = dev->dev_private;
  2591. struct radeon_connector *radeon_connector =
  2592. to_radeon_connector(connector);
  2593. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2594. uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
  2595. if (rdev->family >= CHIP_R600) {
  2596. bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
  2597. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  2598. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  2599. } else {
  2600. bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
  2601. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  2602. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  2603. }
  2604. if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
  2605. (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
  2606. if (connected) {
  2607. DRM_DEBUG_KMS("TV1 connected\n");
  2608. bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
  2609. bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
  2610. } else {
  2611. DRM_DEBUG_KMS("TV1 disconnected\n");
  2612. bios_0_scratch &= ~ATOM_S0_TV1_MASK;
  2613. bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
  2614. bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
  2615. }
  2616. }
  2617. if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
  2618. (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
  2619. if (connected) {
  2620. DRM_DEBUG_KMS("CV connected\n");
  2621. bios_3_scratch |= ATOM_S3_CV_ACTIVE;
  2622. bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
  2623. } else {
  2624. DRM_DEBUG_KMS("CV disconnected\n");
  2625. bios_0_scratch &= ~ATOM_S0_CV_MASK;
  2626. bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
  2627. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
  2628. }
  2629. }
  2630. if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
  2631. (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
  2632. if (connected) {
  2633. DRM_DEBUG_KMS("LCD1 connected\n");
  2634. bios_0_scratch |= ATOM_S0_LCD1;
  2635. bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
  2636. bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
  2637. } else {
  2638. DRM_DEBUG_KMS("LCD1 disconnected\n");
  2639. bios_0_scratch &= ~ATOM_S0_LCD1;
  2640. bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
  2641. bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
  2642. }
  2643. }
  2644. if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
  2645. (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
  2646. if (connected) {
  2647. DRM_DEBUG_KMS("CRT1 connected\n");
  2648. bios_0_scratch |= ATOM_S0_CRT1_COLOR;
  2649. bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
  2650. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
  2651. } else {
  2652. DRM_DEBUG_KMS("CRT1 disconnected\n");
  2653. bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
  2654. bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
  2655. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
  2656. }
  2657. }
  2658. if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
  2659. (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
  2660. if (connected) {
  2661. DRM_DEBUG_KMS("CRT2 connected\n");
  2662. bios_0_scratch |= ATOM_S0_CRT2_COLOR;
  2663. bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
  2664. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
  2665. } else {
  2666. DRM_DEBUG_KMS("CRT2 disconnected\n");
  2667. bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
  2668. bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
  2669. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
  2670. }
  2671. }
  2672. if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
  2673. (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
  2674. if (connected) {
  2675. DRM_DEBUG_KMS("DFP1 connected\n");
  2676. bios_0_scratch |= ATOM_S0_DFP1;
  2677. bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
  2678. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
  2679. } else {
  2680. DRM_DEBUG_KMS("DFP1 disconnected\n");
  2681. bios_0_scratch &= ~ATOM_S0_DFP1;
  2682. bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
  2683. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
  2684. }
  2685. }
  2686. if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
  2687. (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  2688. if (connected) {
  2689. DRM_DEBUG_KMS("DFP2 connected\n");
  2690. bios_0_scratch |= ATOM_S0_DFP2;
  2691. bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
  2692. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
  2693. } else {
  2694. DRM_DEBUG_KMS("DFP2 disconnected\n");
  2695. bios_0_scratch &= ~ATOM_S0_DFP2;
  2696. bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
  2697. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
  2698. }
  2699. }
  2700. if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
  2701. (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
  2702. if (connected) {
  2703. DRM_DEBUG_KMS("DFP3 connected\n");
  2704. bios_0_scratch |= ATOM_S0_DFP3;
  2705. bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
  2706. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
  2707. } else {
  2708. DRM_DEBUG_KMS("DFP3 disconnected\n");
  2709. bios_0_scratch &= ~ATOM_S0_DFP3;
  2710. bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
  2711. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
  2712. }
  2713. }
  2714. if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
  2715. (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
  2716. if (connected) {
  2717. DRM_DEBUG_KMS("DFP4 connected\n");
  2718. bios_0_scratch |= ATOM_S0_DFP4;
  2719. bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
  2720. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
  2721. } else {
  2722. DRM_DEBUG_KMS("DFP4 disconnected\n");
  2723. bios_0_scratch &= ~ATOM_S0_DFP4;
  2724. bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
  2725. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
  2726. }
  2727. }
  2728. if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
  2729. (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
  2730. if (connected) {
  2731. DRM_DEBUG_KMS("DFP5 connected\n");
  2732. bios_0_scratch |= ATOM_S0_DFP5;
  2733. bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
  2734. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
  2735. } else {
  2736. DRM_DEBUG_KMS("DFP5 disconnected\n");
  2737. bios_0_scratch &= ~ATOM_S0_DFP5;
  2738. bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
  2739. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
  2740. }
  2741. }
  2742. if ((radeon_encoder->devices & ATOM_DEVICE_DFP6_SUPPORT) &&
  2743. (radeon_connector->devices & ATOM_DEVICE_DFP6_SUPPORT)) {
  2744. if (connected) {
  2745. DRM_DEBUG_KMS("DFP6 connected\n");
  2746. bios_0_scratch |= ATOM_S0_DFP6;
  2747. bios_3_scratch |= ATOM_S3_DFP6_ACTIVE;
  2748. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP6;
  2749. } else {
  2750. DRM_DEBUG_KMS("DFP6 disconnected\n");
  2751. bios_0_scratch &= ~ATOM_S0_DFP6;
  2752. bios_3_scratch &= ~ATOM_S3_DFP6_ACTIVE;
  2753. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP6;
  2754. }
  2755. }
  2756. if (rdev->family >= CHIP_R600) {
  2757. WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
  2758. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  2759. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  2760. } else {
  2761. WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
  2762. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  2763. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  2764. }
  2765. }
  2766. void
  2767. radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
  2768. {
  2769. struct drm_device *dev = encoder->dev;
  2770. struct radeon_device *rdev = dev->dev_private;
  2771. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2772. uint32_t bios_3_scratch;
  2773. if (ASIC_IS_DCE4(rdev))
  2774. return;
  2775. if (rdev->family >= CHIP_R600)
  2776. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  2777. else
  2778. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  2779. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  2780. bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
  2781. bios_3_scratch |= (crtc << 18);
  2782. }
  2783. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  2784. bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
  2785. bios_3_scratch |= (crtc << 24);
  2786. }
  2787. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  2788. bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
  2789. bios_3_scratch |= (crtc << 16);
  2790. }
  2791. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  2792. bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
  2793. bios_3_scratch |= (crtc << 20);
  2794. }
  2795. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  2796. bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
  2797. bios_3_scratch |= (crtc << 17);
  2798. }
  2799. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  2800. bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
  2801. bios_3_scratch |= (crtc << 19);
  2802. }
  2803. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  2804. bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
  2805. bios_3_scratch |= (crtc << 23);
  2806. }
  2807. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  2808. bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
  2809. bios_3_scratch |= (crtc << 25);
  2810. }
  2811. if (rdev->family >= CHIP_R600)
  2812. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  2813. else
  2814. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  2815. }
  2816. void
  2817. radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
  2818. {
  2819. struct drm_device *dev = encoder->dev;
  2820. struct radeon_device *rdev = dev->dev_private;
  2821. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2822. uint32_t bios_2_scratch;
  2823. if (ASIC_IS_DCE4(rdev))
  2824. return;
  2825. if (rdev->family >= CHIP_R600)
  2826. bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
  2827. else
  2828. bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
  2829. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  2830. if (on)
  2831. bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
  2832. else
  2833. bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
  2834. }
  2835. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  2836. if (on)
  2837. bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
  2838. else
  2839. bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
  2840. }
  2841. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  2842. if (on)
  2843. bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
  2844. else
  2845. bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
  2846. }
  2847. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  2848. if (on)
  2849. bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
  2850. else
  2851. bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
  2852. }
  2853. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  2854. if (on)
  2855. bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
  2856. else
  2857. bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
  2858. }
  2859. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  2860. if (on)
  2861. bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
  2862. else
  2863. bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
  2864. }
  2865. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  2866. if (on)
  2867. bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
  2868. else
  2869. bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
  2870. }
  2871. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  2872. if (on)
  2873. bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
  2874. else
  2875. bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
  2876. }
  2877. if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
  2878. if (on)
  2879. bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
  2880. else
  2881. bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
  2882. }
  2883. if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
  2884. if (on)
  2885. bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
  2886. else
  2887. bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
  2888. }
  2889. if (rdev->family >= CHIP_R600)
  2890. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  2891. else
  2892. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  2893. }