radeon_atombios.c 92 KB

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