radeon_atombios.c 100 KB

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