radeon_atombios.c 72 KB

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