radeon_atombios.c 74 KB

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