radeon_atombios.c 85 KB

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