radeon_atombios.c 74 KB

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