radeon_atombios.c 97 KB

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