radeon_atombios.c 103 KB

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