radeon_atombios.c 48 KB

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