radeon_atombios.c 98 KB

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