radeon_atombios.c 86 KB

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