radeon_atombios.c 102 KB

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