radeon_atombios.c 101 KB

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