radeon_atombios.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583
  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. /* from radeon_legacy_encoder.c */
  49. extern void
  50. radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_id,
  51. uint32_t supported_device);
  52. union atom_supported_devices {
  53. struct _ATOM_SUPPORTED_DEVICES_INFO info;
  54. struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2;
  55. struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1;
  56. };
  57. static inline struct radeon_i2c_bus_rec radeon_lookup_gpio(struct drm_device
  58. *dev, uint8_t id)
  59. {
  60. struct radeon_device *rdev = dev->dev_private;
  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. memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
  68. i2c.valid = false;
  69. atom_parse_data_header(ctx, index, NULL, NULL, NULL, &data_offset);
  70. i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
  71. gpio = i2c_info->asGPIO_Info[id];
  72. i2c.mask_clk_reg = le16_to_cpu(gpio.usClkMaskRegisterIndex) * 4;
  73. i2c.mask_data_reg = le16_to_cpu(gpio.usDataMaskRegisterIndex) * 4;
  74. i2c.en_clk_reg = le16_to_cpu(gpio.usClkEnRegisterIndex) * 4;
  75. i2c.en_data_reg = le16_to_cpu(gpio.usDataEnRegisterIndex) * 4;
  76. i2c.y_clk_reg = le16_to_cpu(gpio.usClkY_RegisterIndex) * 4;
  77. i2c.y_data_reg = le16_to_cpu(gpio.usDataY_RegisterIndex) * 4;
  78. i2c.a_clk_reg = le16_to_cpu(gpio.usClkA_RegisterIndex) * 4;
  79. i2c.a_data_reg = le16_to_cpu(gpio.usDataA_RegisterIndex) * 4;
  80. i2c.mask_clk_mask = (1 << gpio.ucClkMaskShift);
  81. i2c.mask_data_mask = (1 << gpio.ucDataMaskShift);
  82. i2c.en_clk_mask = (1 << gpio.ucClkEnShift);
  83. i2c.en_data_mask = (1 << gpio.ucDataEnShift);
  84. i2c.y_clk_mask = (1 << gpio.ucClkY_Shift);
  85. i2c.y_data_mask = (1 << gpio.ucDataY_Shift);
  86. i2c.a_clk_mask = (1 << gpio.ucClkA_Shift);
  87. i2c.a_data_mask = (1 << gpio.ucDataA_Shift);
  88. i2c.valid = true;
  89. return i2c;
  90. }
  91. static bool radeon_atom_apply_quirks(struct drm_device *dev,
  92. uint32_t supported_device,
  93. int *connector_type,
  94. struct radeon_i2c_bus_rec *i2c_bus,
  95. uint16_t *line_mux)
  96. {
  97. /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
  98. if ((dev->pdev->device == 0x791e) &&
  99. (dev->pdev->subsystem_vendor == 0x1043) &&
  100. (dev->pdev->subsystem_device == 0x826d)) {
  101. if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
  102. (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
  103. *connector_type = DRM_MODE_CONNECTOR_DVID;
  104. }
  105. /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
  106. if ((dev->pdev->device == 0x7941) &&
  107. (dev->pdev->subsystem_vendor == 0x147b) &&
  108. (dev->pdev->subsystem_device == 0x2412)) {
  109. if (*connector_type == DRM_MODE_CONNECTOR_DVII)
  110. return false;
  111. }
  112. /* Falcon NW laptop lists vga ddc line for LVDS */
  113. if ((dev->pdev->device == 0x5653) &&
  114. (dev->pdev->subsystem_vendor == 0x1462) &&
  115. (dev->pdev->subsystem_device == 0x0291)) {
  116. if (*connector_type == DRM_MODE_CONNECTOR_LVDS) {
  117. i2c_bus->valid = false;
  118. *line_mux = 53;
  119. }
  120. }
  121. /* Funky macbooks */
  122. if ((dev->pdev->device == 0x71C5) &&
  123. (dev->pdev->subsystem_vendor == 0x106b) &&
  124. (dev->pdev->subsystem_device == 0x0080)) {
  125. if ((supported_device == ATOM_DEVICE_CRT1_SUPPORT) ||
  126. (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
  127. return false;
  128. }
  129. /* ASUS HD 3600 XT board lists the DVI port as HDMI */
  130. if ((dev->pdev->device == 0x9598) &&
  131. (dev->pdev->subsystem_vendor == 0x1043) &&
  132. (dev->pdev->subsystem_device == 0x01da)) {
  133. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  134. *connector_type = DRM_MODE_CONNECTOR_DVII;
  135. }
  136. }
  137. /* ASUS HD 3450 board lists the DVI port as HDMI */
  138. if ((dev->pdev->device == 0x95C5) &&
  139. (dev->pdev->subsystem_vendor == 0x1043) &&
  140. (dev->pdev->subsystem_device == 0x01e2)) {
  141. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  142. *connector_type = DRM_MODE_CONNECTOR_DVII;
  143. }
  144. }
  145. /* some BIOSes seem to report DAC on HDMI - usually this is a board with
  146. * HDMI + VGA reporting as HDMI
  147. */
  148. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  149. if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) {
  150. *connector_type = DRM_MODE_CONNECTOR_VGA;
  151. *line_mux = 0;
  152. }
  153. }
  154. /* Acer laptop reports DVI-D as DVI-I */
  155. if ((dev->pdev->device == 0x95c4) &&
  156. (dev->pdev->subsystem_vendor == 0x1025) &&
  157. (dev->pdev->subsystem_device == 0x013c)) {
  158. if ((*connector_type == DRM_MODE_CONNECTOR_DVII) &&
  159. (supported_device == ATOM_DEVICE_DFP1_SUPPORT))
  160. *connector_type = DRM_MODE_CONNECTOR_DVID;
  161. }
  162. return true;
  163. }
  164. const int supported_devices_connector_convert[] = {
  165. DRM_MODE_CONNECTOR_Unknown,
  166. DRM_MODE_CONNECTOR_VGA,
  167. DRM_MODE_CONNECTOR_DVII,
  168. DRM_MODE_CONNECTOR_DVID,
  169. DRM_MODE_CONNECTOR_DVIA,
  170. DRM_MODE_CONNECTOR_SVIDEO,
  171. DRM_MODE_CONNECTOR_Composite,
  172. DRM_MODE_CONNECTOR_LVDS,
  173. DRM_MODE_CONNECTOR_Unknown,
  174. DRM_MODE_CONNECTOR_Unknown,
  175. DRM_MODE_CONNECTOR_HDMIA,
  176. DRM_MODE_CONNECTOR_HDMIB,
  177. DRM_MODE_CONNECTOR_Unknown,
  178. DRM_MODE_CONNECTOR_Unknown,
  179. DRM_MODE_CONNECTOR_9PinDIN,
  180. DRM_MODE_CONNECTOR_DisplayPort
  181. };
  182. const uint16_t supported_devices_connector_object_id_convert[] = {
  183. CONNECTOR_OBJECT_ID_NONE,
  184. CONNECTOR_OBJECT_ID_VGA,
  185. CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I, /* not all boards support DL */
  186. CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D, /* not all boards support DL */
  187. CONNECTOR_OBJECT_ID_VGA, /* technically DVI-A */
  188. CONNECTOR_OBJECT_ID_COMPOSITE,
  189. CONNECTOR_OBJECT_ID_SVIDEO,
  190. CONNECTOR_OBJECT_ID_LVDS,
  191. CONNECTOR_OBJECT_ID_9PIN_DIN,
  192. CONNECTOR_OBJECT_ID_9PIN_DIN,
  193. CONNECTOR_OBJECT_ID_DISPLAYPORT,
  194. CONNECTOR_OBJECT_ID_HDMI_TYPE_A,
  195. CONNECTOR_OBJECT_ID_HDMI_TYPE_B,
  196. CONNECTOR_OBJECT_ID_SVIDEO
  197. };
  198. const int object_connector_convert[] = {
  199. DRM_MODE_CONNECTOR_Unknown,
  200. DRM_MODE_CONNECTOR_DVII,
  201. DRM_MODE_CONNECTOR_DVII,
  202. DRM_MODE_CONNECTOR_DVID,
  203. DRM_MODE_CONNECTOR_DVID,
  204. DRM_MODE_CONNECTOR_VGA,
  205. DRM_MODE_CONNECTOR_Composite,
  206. DRM_MODE_CONNECTOR_SVIDEO,
  207. DRM_MODE_CONNECTOR_Unknown,
  208. DRM_MODE_CONNECTOR_Unknown,
  209. DRM_MODE_CONNECTOR_9PinDIN,
  210. DRM_MODE_CONNECTOR_Unknown,
  211. DRM_MODE_CONNECTOR_HDMIA,
  212. DRM_MODE_CONNECTOR_HDMIB,
  213. DRM_MODE_CONNECTOR_LVDS,
  214. DRM_MODE_CONNECTOR_9PinDIN,
  215. DRM_MODE_CONNECTOR_Unknown,
  216. DRM_MODE_CONNECTOR_Unknown,
  217. DRM_MODE_CONNECTOR_Unknown,
  218. DRM_MODE_CONNECTOR_DisplayPort
  219. };
  220. bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
  221. {
  222. struct radeon_device *rdev = dev->dev_private;
  223. struct radeon_mode_info *mode_info = &rdev->mode_info;
  224. struct atom_context *ctx = mode_info->atom_context;
  225. int index = GetIndexIntoMasterTable(DATA, Object_Header);
  226. uint16_t size, data_offset;
  227. uint8_t frev, crev, line_mux = 0;
  228. ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
  229. ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
  230. ATOM_OBJECT_HEADER *obj_header;
  231. int i, j, path_size, device_support;
  232. int connector_type;
  233. uint16_t igp_lane_info, conn_id, connector_object_id;
  234. bool linkb;
  235. struct radeon_i2c_bus_rec ddc_bus;
  236. atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
  237. if (data_offset == 0)
  238. return false;
  239. if (crev < 2)
  240. return false;
  241. obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
  242. path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
  243. (ctx->bios + data_offset +
  244. le16_to_cpu(obj_header->usDisplayPathTableOffset));
  245. con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
  246. (ctx->bios + data_offset +
  247. le16_to_cpu(obj_header->usConnectorObjectTableOffset));
  248. device_support = le16_to_cpu(obj_header->usDeviceSupport);
  249. path_size = 0;
  250. for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
  251. uint8_t *addr = (uint8_t *) path_obj->asDispPath;
  252. ATOM_DISPLAY_OBJECT_PATH *path;
  253. addr += path_size;
  254. path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
  255. path_size += le16_to_cpu(path->usSize);
  256. linkb = false;
  257. if (device_support & le16_to_cpu(path->usDeviceTag)) {
  258. uint8_t con_obj_id, con_obj_num, con_obj_type;
  259. con_obj_id =
  260. (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
  261. >> OBJECT_ID_SHIFT;
  262. con_obj_num =
  263. (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
  264. >> ENUM_ID_SHIFT;
  265. con_obj_type =
  266. (le16_to_cpu(path->usConnObjectId) &
  267. OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
  268. /* TODO CV support */
  269. if (le16_to_cpu(path->usDeviceTag) ==
  270. ATOM_DEVICE_CV_SUPPORT)
  271. continue;
  272. /* IGP chips */
  273. if ((rdev->flags & RADEON_IS_IGP) &&
  274. (con_obj_id ==
  275. CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
  276. uint16_t igp_offset = 0;
  277. ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
  278. index =
  279. GetIndexIntoMasterTable(DATA,
  280. IntegratedSystemInfo);
  281. atom_parse_data_header(ctx, index, &size, &frev,
  282. &crev, &igp_offset);
  283. if (crev >= 2) {
  284. igp_obj =
  285. (ATOM_INTEGRATED_SYSTEM_INFO_V2
  286. *) (ctx->bios + igp_offset);
  287. if (igp_obj) {
  288. uint32_t slot_config, ct;
  289. if (con_obj_num == 1)
  290. slot_config =
  291. igp_obj->
  292. ulDDISlot1Config;
  293. else
  294. slot_config =
  295. igp_obj->
  296. ulDDISlot2Config;
  297. ct = (slot_config >> 16) & 0xff;
  298. connector_type =
  299. object_connector_convert
  300. [ct];
  301. connector_object_id = ct;
  302. igp_lane_info =
  303. slot_config & 0xffff;
  304. } else
  305. continue;
  306. } else
  307. continue;
  308. } else {
  309. igp_lane_info = 0;
  310. connector_type =
  311. object_connector_convert[con_obj_id];
  312. connector_object_id = con_obj_id;
  313. }
  314. if (connector_type == DRM_MODE_CONNECTOR_Unknown)
  315. continue;
  316. for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2);
  317. j++) {
  318. uint8_t enc_obj_id, enc_obj_num, enc_obj_type;
  319. enc_obj_id =
  320. (le16_to_cpu(path->usGraphicObjIds[j]) &
  321. OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
  322. enc_obj_num =
  323. (le16_to_cpu(path->usGraphicObjIds[j]) &
  324. ENUM_ID_MASK) >> ENUM_ID_SHIFT;
  325. enc_obj_type =
  326. (le16_to_cpu(path->usGraphicObjIds[j]) &
  327. OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
  328. /* FIXME: add support for router objects */
  329. if (enc_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
  330. if (enc_obj_num == 2)
  331. linkb = true;
  332. else
  333. linkb = false;
  334. radeon_add_atom_encoder(dev,
  335. enc_obj_id,
  336. le16_to_cpu
  337. (path->
  338. usDeviceTag));
  339. }
  340. }
  341. /* look up gpio for ddc */
  342. if ((le16_to_cpu(path->usDeviceTag) &
  343. (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT))
  344. == 0) {
  345. for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
  346. if (le16_to_cpu(path->usConnObjectId) ==
  347. le16_to_cpu(con_obj->asObjects[j].
  348. usObjectID)) {
  349. ATOM_COMMON_RECORD_HEADER
  350. *record =
  351. (ATOM_COMMON_RECORD_HEADER
  352. *)
  353. (ctx->bios + data_offset +
  354. le16_to_cpu(con_obj->
  355. asObjects[j].
  356. usRecordOffset));
  357. ATOM_I2C_RECORD *i2c_record;
  358. while (record->ucRecordType > 0
  359. && record->
  360. ucRecordType <=
  361. ATOM_MAX_OBJECT_RECORD_NUMBER) {
  362. switch (record->
  363. ucRecordType) {
  364. case ATOM_I2C_RECORD_TYPE:
  365. i2c_record =
  366. (ATOM_I2C_RECORD
  367. *) record;
  368. line_mux =
  369. i2c_record->
  370. sucI2cId.
  371. bfI2C_LineMux;
  372. break;
  373. }
  374. record =
  375. (ATOM_COMMON_RECORD_HEADER
  376. *) ((char *)record
  377. +
  378. record->
  379. ucRecordSize);
  380. }
  381. break;
  382. }
  383. }
  384. } else
  385. line_mux = 0;
  386. if ((le16_to_cpu(path->usDeviceTag) ==
  387. ATOM_DEVICE_TV1_SUPPORT)
  388. || (le16_to_cpu(path->usDeviceTag) ==
  389. ATOM_DEVICE_TV2_SUPPORT)
  390. || (le16_to_cpu(path->usDeviceTag) ==
  391. ATOM_DEVICE_CV_SUPPORT))
  392. ddc_bus.valid = false;
  393. else
  394. ddc_bus = radeon_lookup_gpio(dev, line_mux);
  395. conn_id = le16_to_cpu(path->usConnObjectId);
  396. if (!radeon_atom_apply_quirks
  397. (dev, le16_to_cpu(path->usDeviceTag), &connector_type,
  398. &ddc_bus, &conn_id))
  399. continue;
  400. radeon_add_atom_connector(dev,
  401. conn_id,
  402. le16_to_cpu(path->
  403. usDeviceTag),
  404. connector_type, &ddc_bus,
  405. linkb, igp_lane_info,
  406. connector_object_id);
  407. }
  408. }
  409. radeon_link_encoder_connector(dev);
  410. return true;
  411. }
  412. static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
  413. int connector_type,
  414. uint16_t devices)
  415. {
  416. struct radeon_device *rdev = dev->dev_private;
  417. if (rdev->flags & RADEON_IS_IGP) {
  418. return supported_devices_connector_object_id_convert
  419. [connector_type];
  420. } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) ||
  421. (connector_type == DRM_MODE_CONNECTOR_DVID)) &&
  422. (devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  423. struct radeon_mode_info *mode_info = &rdev->mode_info;
  424. struct atom_context *ctx = mode_info->atom_context;
  425. int index = GetIndexIntoMasterTable(DATA, XTMDS_Info);
  426. uint16_t size, data_offset;
  427. uint8_t frev, crev;
  428. ATOM_XTMDS_INFO *xtmds;
  429. atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
  430. xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset);
  431. if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) {
  432. if (connector_type == DRM_MODE_CONNECTOR_DVII)
  433. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
  434. else
  435. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
  436. } else {
  437. if (connector_type == DRM_MODE_CONNECTOR_DVII)
  438. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  439. else
  440. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
  441. }
  442. } else {
  443. return supported_devices_connector_object_id_convert
  444. [connector_type];
  445. }
  446. }
  447. struct bios_connector {
  448. bool valid;
  449. uint16_t line_mux;
  450. uint16_t devices;
  451. int connector_type;
  452. struct radeon_i2c_bus_rec ddc_bus;
  453. };
  454. bool radeon_get_atom_connector_info_from_supported_devices_table(struct
  455. drm_device
  456. *dev)
  457. {
  458. struct radeon_device *rdev = dev->dev_private;
  459. struct radeon_mode_info *mode_info = &rdev->mode_info;
  460. struct atom_context *ctx = mode_info->atom_context;
  461. int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
  462. uint16_t size, data_offset;
  463. uint8_t frev, crev;
  464. uint16_t device_support;
  465. uint8_t dac;
  466. union atom_supported_devices *supported_devices;
  467. int i, j;
  468. struct bios_connector bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
  469. atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
  470. supported_devices =
  471. (union atom_supported_devices *)(ctx->bios + data_offset);
  472. device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
  473. for (i = 0; i < ATOM_MAX_SUPPORTED_DEVICE; i++) {
  474. ATOM_CONNECTOR_INFO_I2C ci =
  475. supported_devices->info.asConnInfo[i];
  476. bios_connectors[i].valid = false;
  477. if (!(device_support & (1 << i))) {
  478. continue;
  479. }
  480. if (i == ATOM_DEVICE_CV_INDEX) {
  481. DRM_DEBUG("Skipping Component Video\n");
  482. continue;
  483. }
  484. bios_connectors[i].connector_type =
  485. supported_devices_connector_convert[ci.sucConnectorInfo.
  486. sbfAccess.
  487. bfConnectorType];
  488. if (bios_connectors[i].connector_type ==
  489. DRM_MODE_CONNECTOR_Unknown)
  490. continue;
  491. dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
  492. if ((rdev->family == CHIP_RS690) ||
  493. (rdev->family == CHIP_RS740)) {
  494. if ((i == ATOM_DEVICE_DFP2_INDEX)
  495. && (ci.sucI2cId.sbfAccess.bfI2C_LineMux == 2))
  496. bios_connectors[i].line_mux =
  497. ci.sucI2cId.sbfAccess.bfI2C_LineMux + 1;
  498. else if ((i == ATOM_DEVICE_DFP3_INDEX)
  499. && (ci.sucI2cId.sbfAccess.bfI2C_LineMux == 1))
  500. bios_connectors[i].line_mux =
  501. ci.sucI2cId.sbfAccess.bfI2C_LineMux + 1;
  502. else
  503. bios_connectors[i].line_mux =
  504. ci.sucI2cId.sbfAccess.bfI2C_LineMux;
  505. } else
  506. bios_connectors[i].line_mux =
  507. ci.sucI2cId.sbfAccess.bfI2C_LineMux;
  508. /* give tv unique connector ids */
  509. if (i == ATOM_DEVICE_TV1_INDEX) {
  510. bios_connectors[i].ddc_bus.valid = false;
  511. bios_connectors[i].line_mux = 50;
  512. } else if (i == ATOM_DEVICE_TV2_INDEX) {
  513. bios_connectors[i].ddc_bus.valid = false;
  514. bios_connectors[i].line_mux = 51;
  515. } else if (i == ATOM_DEVICE_CV_INDEX) {
  516. bios_connectors[i].ddc_bus.valid = false;
  517. bios_connectors[i].line_mux = 52;
  518. } else
  519. bios_connectors[i].ddc_bus =
  520. radeon_lookup_gpio(dev,
  521. bios_connectors[i].line_mux);
  522. /* Always set the connector type to VGA for CRT1/CRT2. if they are
  523. * shared with a DVI port, we'll pick up the DVI connector when we
  524. * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
  525. */
  526. if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
  527. bios_connectors[i].connector_type =
  528. DRM_MODE_CONNECTOR_VGA;
  529. if (!radeon_atom_apply_quirks
  530. (dev, (1 << i), &bios_connectors[i].connector_type,
  531. &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux))
  532. continue;
  533. bios_connectors[i].valid = true;
  534. bios_connectors[i].devices = (1 << i);
  535. if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
  536. radeon_add_atom_encoder(dev,
  537. radeon_get_encoder_id(dev,
  538. (1 << i),
  539. dac),
  540. (1 << i));
  541. else
  542. radeon_add_legacy_encoder(dev,
  543. radeon_get_encoder_id(dev,
  544. (1 <<
  545. i),
  546. dac),
  547. (1 << i));
  548. }
  549. /* combine shared connectors */
  550. for (i = 0; i < ATOM_MAX_SUPPORTED_DEVICE; i++) {
  551. if (bios_connectors[i].valid) {
  552. for (j = 0; j < ATOM_MAX_SUPPORTED_DEVICE; j++) {
  553. if (bios_connectors[j].valid && (i != j)) {
  554. if (bios_connectors[i].line_mux ==
  555. bios_connectors[j].line_mux) {
  556. if (((bios_connectors[i].
  557. devices &
  558. (ATOM_DEVICE_DFP_SUPPORT))
  559. && (bios_connectors[j].
  560. devices &
  561. (ATOM_DEVICE_CRT_SUPPORT)))
  562. ||
  563. ((bios_connectors[j].
  564. devices &
  565. (ATOM_DEVICE_DFP_SUPPORT))
  566. && (bios_connectors[i].
  567. devices &
  568. (ATOM_DEVICE_CRT_SUPPORT)))) {
  569. bios_connectors[i].
  570. devices |=
  571. bios_connectors[j].
  572. devices;
  573. bios_connectors[i].
  574. connector_type =
  575. DRM_MODE_CONNECTOR_DVII;
  576. bios_connectors[j].
  577. valid = false;
  578. }
  579. }
  580. }
  581. }
  582. }
  583. }
  584. /* add the connectors */
  585. for (i = 0; i < ATOM_MAX_SUPPORTED_DEVICE; i++) {
  586. if (bios_connectors[i].valid) {
  587. uint16_t connector_object_id =
  588. atombios_get_connector_object_id(dev,
  589. bios_connectors[i].connector_type,
  590. bios_connectors[i].devices);
  591. radeon_add_atom_connector(dev,
  592. bios_connectors[i].line_mux,
  593. bios_connectors[i].devices,
  594. bios_connectors[i].
  595. connector_type,
  596. &bios_connectors[i].ddc_bus,
  597. false, 0,
  598. connector_object_id);
  599. }
  600. }
  601. radeon_link_encoder_connector(dev);
  602. return true;
  603. }
  604. union firmware_info {
  605. ATOM_FIRMWARE_INFO info;
  606. ATOM_FIRMWARE_INFO_V1_2 info_12;
  607. ATOM_FIRMWARE_INFO_V1_3 info_13;
  608. ATOM_FIRMWARE_INFO_V1_4 info_14;
  609. };
  610. bool radeon_atom_get_clock_info(struct drm_device *dev)
  611. {
  612. struct radeon_device *rdev = dev->dev_private;
  613. struct radeon_mode_info *mode_info = &rdev->mode_info;
  614. int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
  615. union firmware_info *firmware_info;
  616. uint8_t frev, crev;
  617. struct radeon_pll *p1pll = &rdev->clock.p1pll;
  618. struct radeon_pll *p2pll = &rdev->clock.p2pll;
  619. struct radeon_pll *spll = &rdev->clock.spll;
  620. struct radeon_pll *mpll = &rdev->clock.mpll;
  621. uint16_t data_offset;
  622. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
  623. &crev, &data_offset);
  624. firmware_info =
  625. (union firmware_info *)(mode_info->atom_context->bios +
  626. data_offset);
  627. if (firmware_info) {
  628. /* pixel clocks */
  629. p1pll->reference_freq =
  630. le16_to_cpu(firmware_info->info.usReferenceClock);
  631. p1pll->reference_div = 0;
  632. if (crev < 2)
  633. p1pll->pll_out_min =
  634. le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
  635. else
  636. p1pll->pll_out_min =
  637. le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
  638. p1pll->pll_out_max =
  639. le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
  640. if (p1pll->pll_out_min == 0) {
  641. if (ASIC_IS_AVIVO(rdev))
  642. p1pll->pll_out_min = 64800;
  643. else
  644. p1pll->pll_out_min = 20000;
  645. } else if (p1pll->pll_out_min > 64800) {
  646. /* Limiting the pll output range is a good thing generally as
  647. * it limits the number of possible pll combinations for a given
  648. * frequency presumably to the ones that work best on each card.
  649. * However, certain duallink DVI monitors seem to like
  650. * pll combinations that would be limited by this at least on
  651. * pre-DCE 3.0 r6xx hardware. This might need to be adjusted per
  652. * family.
  653. */
  654. p1pll->pll_out_min = 64800;
  655. }
  656. p1pll->pll_in_min =
  657. le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
  658. p1pll->pll_in_max =
  659. le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
  660. *p2pll = *p1pll;
  661. /* system clock */
  662. spll->reference_freq =
  663. le16_to_cpu(firmware_info->info.usReferenceClock);
  664. spll->reference_div = 0;
  665. spll->pll_out_min =
  666. le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
  667. spll->pll_out_max =
  668. le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
  669. /* ??? */
  670. if (spll->pll_out_min == 0) {
  671. if (ASIC_IS_AVIVO(rdev))
  672. spll->pll_out_min = 64800;
  673. else
  674. spll->pll_out_min = 20000;
  675. }
  676. spll->pll_in_min =
  677. le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
  678. spll->pll_in_max =
  679. le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
  680. /* memory clock */
  681. mpll->reference_freq =
  682. le16_to_cpu(firmware_info->info.usReferenceClock);
  683. mpll->reference_div = 0;
  684. mpll->pll_out_min =
  685. le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
  686. mpll->pll_out_max =
  687. le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
  688. /* ??? */
  689. if (mpll->pll_out_min == 0) {
  690. if (ASIC_IS_AVIVO(rdev))
  691. mpll->pll_out_min = 64800;
  692. else
  693. mpll->pll_out_min = 20000;
  694. }
  695. mpll->pll_in_min =
  696. le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
  697. mpll->pll_in_max =
  698. le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
  699. rdev->clock.default_sclk =
  700. le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
  701. rdev->clock.default_mclk =
  702. le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
  703. return true;
  704. }
  705. return false;
  706. }
  707. bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
  708. struct radeon_encoder_int_tmds *tmds)
  709. {
  710. struct drm_device *dev = encoder->base.dev;
  711. struct radeon_device *rdev = dev->dev_private;
  712. struct radeon_mode_info *mode_info = &rdev->mode_info;
  713. int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
  714. uint16_t data_offset;
  715. struct _ATOM_TMDS_INFO *tmds_info;
  716. uint8_t frev, crev;
  717. uint16_t maxfreq;
  718. int i;
  719. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
  720. &crev, &data_offset);
  721. tmds_info =
  722. (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
  723. data_offset);
  724. if (tmds_info) {
  725. maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
  726. for (i = 0; i < 4; i++) {
  727. tmds->tmds_pll[i].freq =
  728. le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
  729. tmds->tmds_pll[i].value =
  730. tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
  731. tmds->tmds_pll[i].value |=
  732. (tmds_info->asMiscInfo[i].
  733. ucPLL_VCO_Gain & 0x3f) << 6;
  734. tmds->tmds_pll[i].value |=
  735. (tmds_info->asMiscInfo[i].
  736. ucPLL_DutyCycle & 0xf) << 12;
  737. tmds->tmds_pll[i].value |=
  738. (tmds_info->asMiscInfo[i].
  739. ucPLL_VoltageSwing & 0xf) << 16;
  740. DRM_DEBUG("TMDS PLL From ATOMBIOS %u %x\n",
  741. tmds->tmds_pll[i].freq,
  742. tmds->tmds_pll[i].value);
  743. if (maxfreq == tmds->tmds_pll[i].freq) {
  744. tmds->tmds_pll[i].freq = 0xffffffff;
  745. break;
  746. }
  747. }
  748. return true;
  749. }
  750. return false;
  751. }
  752. static struct radeon_atom_ss *radeon_atombios_get_ss_info(struct
  753. radeon_encoder
  754. *encoder,
  755. int id)
  756. {
  757. struct drm_device *dev = encoder->base.dev;
  758. struct radeon_device *rdev = dev->dev_private;
  759. struct radeon_mode_info *mode_info = &rdev->mode_info;
  760. int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
  761. uint16_t data_offset;
  762. struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
  763. uint8_t frev, crev;
  764. struct radeon_atom_ss *ss = NULL;
  765. if (id > ATOM_MAX_SS_ENTRY)
  766. return NULL;
  767. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
  768. &crev, &data_offset);
  769. ss_info =
  770. (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
  771. if (ss_info) {
  772. ss =
  773. kzalloc(sizeof(struct radeon_atom_ss), GFP_KERNEL);
  774. if (!ss)
  775. return NULL;
  776. ss->percentage = le16_to_cpu(ss_info->asSS_Info[id].usSpreadSpectrumPercentage);
  777. ss->type = ss_info->asSS_Info[id].ucSpreadSpectrumType;
  778. ss->step = ss_info->asSS_Info[id].ucSS_Step;
  779. ss->delay = ss_info->asSS_Info[id].ucSS_Delay;
  780. ss->range = ss_info->asSS_Info[id].ucSS_Range;
  781. ss->refdiv = ss_info->asSS_Info[id].ucRecommendedRef_Div;
  782. }
  783. return ss;
  784. }
  785. union lvds_info {
  786. struct _ATOM_LVDS_INFO info;
  787. struct _ATOM_LVDS_INFO_V12 info_12;
  788. };
  789. struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
  790. radeon_encoder
  791. *encoder)
  792. {
  793. struct drm_device *dev = encoder->base.dev;
  794. struct radeon_device *rdev = dev->dev_private;
  795. struct radeon_mode_info *mode_info = &rdev->mode_info;
  796. int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
  797. uint16_t data_offset, misc;
  798. union lvds_info *lvds_info;
  799. uint8_t frev, crev;
  800. struct radeon_encoder_atom_dig *lvds = NULL;
  801. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
  802. &crev, &data_offset);
  803. lvds_info =
  804. (union lvds_info *)(mode_info->atom_context->bios + data_offset);
  805. if (lvds_info) {
  806. lvds =
  807. kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
  808. if (!lvds)
  809. return NULL;
  810. lvds->native_mode.clock =
  811. le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
  812. lvds->native_mode.hdisplay =
  813. le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
  814. lvds->native_mode.vdisplay =
  815. le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
  816. lvds->native_mode.htotal = lvds->native_mode.hdisplay +
  817. le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
  818. lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
  819. le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
  820. lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
  821. le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
  822. lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
  823. le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
  824. lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
  825. le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
  826. lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
  827. le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
  828. lvds->panel_pwr_delay =
  829. le16_to_cpu(lvds_info->info.usOffDelayInMs);
  830. lvds->lvds_misc = lvds_info->info.ucLVDS_Misc;
  831. misc = le16_to_cpu(lvds_info->info.sLCDTiming.susModeMiscInfo.usAccess);
  832. if (misc & ATOM_VSYNC_POLARITY)
  833. lvds->native_mode.flags |= DRM_MODE_FLAG_NVSYNC;
  834. if (misc & ATOM_HSYNC_POLARITY)
  835. lvds->native_mode.flags |= DRM_MODE_FLAG_NHSYNC;
  836. if (misc & ATOM_COMPOSITESYNC)
  837. lvds->native_mode.flags |= DRM_MODE_FLAG_CSYNC;
  838. if (misc & ATOM_INTERLACE)
  839. lvds->native_mode.flags |= DRM_MODE_FLAG_INTERLACE;
  840. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  841. lvds->native_mode.flags |= DRM_MODE_FLAG_DBLSCAN;
  842. /* set crtc values */
  843. drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
  844. lvds->ss = radeon_atombios_get_ss_info(encoder, lvds_info->info.ucSS_Id);
  845. encoder->native_mode = lvds->native_mode;
  846. }
  847. return lvds;
  848. }
  849. struct radeon_encoder_primary_dac *
  850. radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
  851. {
  852. struct drm_device *dev = encoder->base.dev;
  853. struct radeon_device *rdev = dev->dev_private;
  854. struct radeon_mode_info *mode_info = &rdev->mode_info;
  855. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  856. uint16_t data_offset;
  857. struct _COMPASSIONATE_DATA *dac_info;
  858. uint8_t frev, crev;
  859. uint8_t bg, dac;
  860. struct radeon_encoder_primary_dac *p_dac = NULL;
  861. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev, &crev, &data_offset);
  862. dac_info = (struct _COMPASSIONATE_DATA *)(mode_info->atom_context->bios + data_offset);
  863. if (dac_info) {
  864. p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
  865. if (!p_dac)
  866. return NULL;
  867. bg = dac_info->ucDAC1_BG_Adjustment;
  868. dac = dac_info->ucDAC1_DAC_Adjustment;
  869. p_dac->ps2_pdac_adj = (bg << 8) | (dac);
  870. }
  871. return p_dac;
  872. }
  873. bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
  874. struct drm_display_mode *mode)
  875. {
  876. struct radeon_mode_info *mode_info = &rdev->mode_info;
  877. ATOM_ANALOG_TV_INFO *tv_info;
  878. ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
  879. ATOM_DTD_FORMAT *dtd_timings;
  880. int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
  881. u8 frev, crev;
  882. u16 data_offset, misc;
  883. atom_parse_data_header(mode_info->atom_context, data_index, NULL, &frev, &crev, &data_offset);
  884. switch (crev) {
  885. case 1:
  886. tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
  887. if (index > MAX_SUPPORTED_TV_TIMING)
  888. return false;
  889. mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
  890. mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
  891. mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
  892. mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
  893. le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
  894. mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
  895. mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
  896. mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
  897. mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
  898. le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
  899. mode->flags = 0;
  900. misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
  901. if (misc & ATOM_VSYNC_POLARITY)
  902. mode->flags |= DRM_MODE_FLAG_NVSYNC;
  903. if (misc & ATOM_HSYNC_POLARITY)
  904. mode->flags |= DRM_MODE_FLAG_NHSYNC;
  905. if (misc & ATOM_COMPOSITESYNC)
  906. mode->flags |= DRM_MODE_FLAG_CSYNC;
  907. if (misc & ATOM_INTERLACE)
  908. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  909. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  910. mode->flags |= DRM_MODE_FLAG_DBLSCAN;
  911. mode->clock = le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
  912. if (index == 1) {
  913. /* PAL timings appear to have wrong values for totals */
  914. mode->crtc_htotal -= 1;
  915. mode->crtc_vtotal -= 1;
  916. }
  917. break;
  918. case 2:
  919. tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
  920. if (index > MAX_SUPPORTED_TV_TIMING_V1_2)
  921. return false;
  922. dtd_timings = &tv_info_v1_2->aModeTimings[index];
  923. mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
  924. le16_to_cpu(dtd_timings->usHBlanking_Time);
  925. mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
  926. mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
  927. le16_to_cpu(dtd_timings->usHSyncOffset);
  928. mode->crtc_hsync_end = mode->crtc_hsync_start +
  929. le16_to_cpu(dtd_timings->usHSyncWidth);
  930. mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
  931. le16_to_cpu(dtd_timings->usVBlanking_Time);
  932. mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
  933. mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
  934. le16_to_cpu(dtd_timings->usVSyncOffset);
  935. mode->crtc_vsync_end = mode->crtc_vsync_start +
  936. le16_to_cpu(dtd_timings->usVSyncWidth);
  937. mode->flags = 0;
  938. misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
  939. if (misc & ATOM_VSYNC_POLARITY)
  940. mode->flags |= DRM_MODE_FLAG_NVSYNC;
  941. if (misc & ATOM_HSYNC_POLARITY)
  942. mode->flags |= DRM_MODE_FLAG_NHSYNC;
  943. if (misc & ATOM_COMPOSITESYNC)
  944. mode->flags |= DRM_MODE_FLAG_CSYNC;
  945. if (misc & ATOM_INTERLACE)
  946. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  947. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  948. mode->flags |= DRM_MODE_FLAG_DBLSCAN;
  949. mode->clock = le16_to_cpu(dtd_timings->usPixClk) * 10;
  950. break;
  951. }
  952. return true;
  953. }
  954. struct radeon_encoder_tv_dac *
  955. radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
  956. {
  957. struct drm_device *dev = encoder->base.dev;
  958. struct radeon_device *rdev = dev->dev_private;
  959. struct radeon_mode_info *mode_info = &rdev->mode_info;
  960. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  961. uint16_t data_offset;
  962. struct _COMPASSIONATE_DATA *dac_info;
  963. uint8_t frev, crev;
  964. uint8_t bg, dac;
  965. struct radeon_encoder_tv_dac *tv_dac = NULL;
  966. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev, &crev, &data_offset);
  967. dac_info = (struct _COMPASSIONATE_DATA *)(mode_info->atom_context->bios + data_offset);
  968. if (dac_info) {
  969. tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
  970. if (!tv_dac)
  971. return NULL;
  972. bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
  973. dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
  974. tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
  975. bg = dac_info->ucDAC2_PAL_BG_Adjustment;
  976. dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
  977. tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
  978. bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
  979. dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
  980. tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
  981. }
  982. return tv_dac;
  983. }
  984. void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
  985. {
  986. DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
  987. int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
  988. args.ucEnable = enable;
  989. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  990. }
  991. void radeon_atom_static_pwrmgt_setup(struct radeon_device *rdev, int enable)
  992. {
  993. ENABLE_ASIC_STATIC_PWR_MGT_PS_ALLOCATION args;
  994. int index = GetIndexIntoMasterTable(COMMAND, EnableASIC_StaticPwrMgt);
  995. args.ucEnable = enable;
  996. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  997. }
  998. uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
  999. {
  1000. GET_ENGINE_CLOCK_PS_ALLOCATION args;
  1001. int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
  1002. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1003. return args.ulReturnEngineClock;
  1004. }
  1005. uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
  1006. {
  1007. GET_MEMORY_CLOCK_PS_ALLOCATION args;
  1008. int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
  1009. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1010. return args.ulReturnMemoryClock;
  1011. }
  1012. void radeon_atom_set_engine_clock(struct radeon_device *rdev,
  1013. uint32_t eng_clock)
  1014. {
  1015. SET_ENGINE_CLOCK_PS_ALLOCATION args;
  1016. int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
  1017. args.ulTargetEngineClock = eng_clock; /* 10 khz */
  1018. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1019. }
  1020. void radeon_atom_set_memory_clock(struct radeon_device *rdev,
  1021. uint32_t mem_clock)
  1022. {
  1023. SET_MEMORY_CLOCK_PS_ALLOCATION args;
  1024. int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
  1025. if (rdev->flags & RADEON_IS_IGP)
  1026. return;
  1027. args.ulTargetMemoryClock = mem_clock; /* 10 khz */
  1028. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1029. }
  1030. void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
  1031. {
  1032. struct radeon_device *rdev = dev->dev_private;
  1033. uint32_t bios_2_scratch, bios_6_scratch;
  1034. if (rdev->family >= CHIP_R600) {
  1035. bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
  1036. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  1037. } else {
  1038. bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
  1039. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  1040. }
  1041. /* let the bios control the backlight */
  1042. bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
  1043. /* tell the bios not to handle mode switching */
  1044. bios_6_scratch |= (ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH | ATOM_S6_ACC_MODE);
  1045. if (rdev->family >= CHIP_R600) {
  1046. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  1047. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  1048. } else {
  1049. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  1050. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  1051. }
  1052. }
  1053. void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
  1054. {
  1055. uint32_t scratch_reg;
  1056. int i;
  1057. if (rdev->family >= CHIP_R600)
  1058. scratch_reg = R600_BIOS_0_SCRATCH;
  1059. else
  1060. scratch_reg = RADEON_BIOS_0_SCRATCH;
  1061. for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
  1062. rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
  1063. }
  1064. void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
  1065. {
  1066. uint32_t scratch_reg;
  1067. int i;
  1068. if (rdev->family >= CHIP_R600)
  1069. scratch_reg = R600_BIOS_0_SCRATCH;
  1070. else
  1071. scratch_reg = RADEON_BIOS_0_SCRATCH;
  1072. for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
  1073. WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
  1074. }
  1075. void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
  1076. {
  1077. struct drm_device *dev = encoder->dev;
  1078. struct radeon_device *rdev = dev->dev_private;
  1079. uint32_t bios_6_scratch;
  1080. if (rdev->family >= CHIP_R600)
  1081. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  1082. else
  1083. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  1084. if (lock)
  1085. bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
  1086. else
  1087. bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
  1088. if (rdev->family >= CHIP_R600)
  1089. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  1090. else
  1091. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  1092. }
  1093. /* at some point we may want to break this out into individual functions */
  1094. void
  1095. radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
  1096. struct drm_encoder *encoder,
  1097. bool connected)
  1098. {
  1099. struct drm_device *dev = connector->dev;
  1100. struct radeon_device *rdev = dev->dev_private;
  1101. struct radeon_connector *radeon_connector =
  1102. to_radeon_connector(connector);
  1103. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1104. uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
  1105. if (rdev->family >= CHIP_R600) {
  1106. bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
  1107. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  1108. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  1109. } else {
  1110. bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
  1111. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  1112. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  1113. }
  1114. if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
  1115. (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
  1116. if (connected) {
  1117. DRM_DEBUG("TV1 connected\n");
  1118. bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
  1119. bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
  1120. } else {
  1121. DRM_DEBUG("TV1 disconnected\n");
  1122. bios_0_scratch &= ~ATOM_S0_TV1_MASK;
  1123. bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
  1124. bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
  1125. }
  1126. }
  1127. if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
  1128. (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
  1129. if (connected) {
  1130. DRM_DEBUG("CV connected\n");
  1131. bios_3_scratch |= ATOM_S3_CV_ACTIVE;
  1132. bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
  1133. } else {
  1134. DRM_DEBUG("CV disconnected\n");
  1135. bios_0_scratch &= ~ATOM_S0_CV_MASK;
  1136. bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
  1137. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
  1138. }
  1139. }
  1140. if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
  1141. (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
  1142. if (connected) {
  1143. DRM_DEBUG("LCD1 connected\n");
  1144. bios_0_scratch |= ATOM_S0_LCD1;
  1145. bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
  1146. bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
  1147. } else {
  1148. DRM_DEBUG("LCD1 disconnected\n");
  1149. bios_0_scratch &= ~ATOM_S0_LCD1;
  1150. bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
  1151. bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
  1152. }
  1153. }
  1154. if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
  1155. (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
  1156. if (connected) {
  1157. DRM_DEBUG("CRT1 connected\n");
  1158. bios_0_scratch |= ATOM_S0_CRT1_COLOR;
  1159. bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
  1160. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
  1161. } else {
  1162. DRM_DEBUG("CRT1 disconnected\n");
  1163. bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
  1164. bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
  1165. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
  1166. }
  1167. }
  1168. if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
  1169. (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
  1170. if (connected) {
  1171. DRM_DEBUG("CRT2 connected\n");
  1172. bios_0_scratch |= ATOM_S0_CRT2_COLOR;
  1173. bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
  1174. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
  1175. } else {
  1176. DRM_DEBUG("CRT2 disconnected\n");
  1177. bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
  1178. bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
  1179. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
  1180. }
  1181. }
  1182. if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
  1183. (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
  1184. if (connected) {
  1185. DRM_DEBUG("DFP1 connected\n");
  1186. bios_0_scratch |= ATOM_S0_DFP1;
  1187. bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
  1188. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
  1189. } else {
  1190. DRM_DEBUG("DFP1 disconnected\n");
  1191. bios_0_scratch &= ~ATOM_S0_DFP1;
  1192. bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
  1193. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
  1194. }
  1195. }
  1196. if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
  1197. (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  1198. if (connected) {
  1199. DRM_DEBUG("DFP2 connected\n");
  1200. bios_0_scratch |= ATOM_S0_DFP2;
  1201. bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
  1202. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
  1203. } else {
  1204. DRM_DEBUG("DFP2 disconnected\n");
  1205. bios_0_scratch &= ~ATOM_S0_DFP2;
  1206. bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
  1207. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
  1208. }
  1209. }
  1210. if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
  1211. (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
  1212. if (connected) {
  1213. DRM_DEBUG("DFP3 connected\n");
  1214. bios_0_scratch |= ATOM_S0_DFP3;
  1215. bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
  1216. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
  1217. } else {
  1218. DRM_DEBUG("DFP3 disconnected\n");
  1219. bios_0_scratch &= ~ATOM_S0_DFP3;
  1220. bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
  1221. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
  1222. }
  1223. }
  1224. if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
  1225. (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
  1226. if (connected) {
  1227. DRM_DEBUG("DFP4 connected\n");
  1228. bios_0_scratch |= ATOM_S0_DFP4;
  1229. bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
  1230. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
  1231. } else {
  1232. DRM_DEBUG("DFP4 disconnected\n");
  1233. bios_0_scratch &= ~ATOM_S0_DFP4;
  1234. bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
  1235. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
  1236. }
  1237. }
  1238. if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
  1239. (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
  1240. if (connected) {
  1241. DRM_DEBUG("DFP5 connected\n");
  1242. bios_0_scratch |= ATOM_S0_DFP5;
  1243. bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
  1244. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
  1245. } else {
  1246. DRM_DEBUG("DFP5 disconnected\n");
  1247. bios_0_scratch &= ~ATOM_S0_DFP5;
  1248. bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
  1249. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
  1250. }
  1251. }
  1252. if (rdev->family >= CHIP_R600) {
  1253. WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
  1254. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  1255. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  1256. } else {
  1257. WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
  1258. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  1259. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  1260. }
  1261. }
  1262. void
  1263. radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
  1264. {
  1265. struct drm_device *dev = encoder->dev;
  1266. struct radeon_device *rdev = dev->dev_private;
  1267. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1268. uint32_t bios_3_scratch;
  1269. if (rdev->family >= CHIP_R600)
  1270. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  1271. else
  1272. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  1273. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  1274. bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
  1275. bios_3_scratch |= (crtc << 18);
  1276. }
  1277. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  1278. bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
  1279. bios_3_scratch |= (crtc << 24);
  1280. }
  1281. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  1282. bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
  1283. bios_3_scratch |= (crtc << 16);
  1284. }
  1285. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  1286. bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
  1287. bios_3_scratch |= (crtc << 20);
  1288. }
  1289. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  1290. bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
  1291. bios_3_scratch |= (crtc << 17);
  1292. }
  1293. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  1294. bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
  1295. bios_3_scratch |= (crtc << 19);
  1296. }
  1297. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  1298. bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
  1299. bios_3_scratch |= (crtc << 23);
  1300. }
  1301. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  1302. bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
  1303. bios_3_scratch |= (crtc << 25);
  1304. }
  1305. if (rdev->family >= CHIP_R600)
  1306. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  1307. else
  1308. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  1309. }
  1310. void
  1311. radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
  1312. {
  1313. struct drm_device *dev = encoder->dev;
  1314. struct radeon_device *rdev = dev->dev_private;
  1315. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1316. uint32_t bios_2_scratch;
  1317. if (rdev->family >= CHIP_R600)
  1318. bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
  1319. else
  1320. bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
  1321. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  1322. if (on)
  1323. bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
  1324. else
  1325. bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
  1326. }
  1327. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  1328. if (on)
  1329. bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
  1330. else
  1331. bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
  1332. }
  1333. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  1334. if (on)
  1335. bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
  1336. else
  1337. bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
  1338. }
  1339. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  1340. if (on)
  1341. bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
  1342. else
  1343. bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
  1344. }
  1345. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  1346. if (on)
  1347. bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
  1348. else
  1349. bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
  1350. }
  1351. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  1352. if (on)
  1353. bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
  1354. else
  1355. bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
  1356. }
  1357. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  1358. if (on)
  1359. bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
  1360. else
  1361. bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
  1362. }
  1363. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  1364. if (on)
  1365. bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
  1366. else
  1367. bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
  1368. }
  1369. if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
  1370. if (on)
  1371. bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
  1372. else
  1373. bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
  1374. }
  1375. if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
  1376. if (on)
  1377. bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
  1378. else
  1379. bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
  1380. }
  1381. if (rdev->family >= CHIP_R600)
  1382. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  1383. else
  1384. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  1385. }