radeon_atombios.c 100 KB

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