radeon_atombios.c 89 KB

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