radeon_atombios.c 101 KB

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