radeon_atombios.c 94 KB

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