radeon_atombios.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298
  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. /* from radeon_legacy_encoder.c */
  48. extern void
  49. radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_id,
  50. uint32_t supported_device);
  51. union atom_supported_devices {
  52. struct _ATOM_SUPPORTED_DEVICES_INFO info;
  53. struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2;
  54. struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1;
  55. };
  56. static inline struct radeon_i2c_bus_rec radeon_lookup_gpio(struct drm_device
  57. *dev, uint8_t id)
  58. {
  59. struct radeon_device *rdev = dev->dev_private;
  60. struct atom_context *ctx = rdev->mode_info.atom_context;
  61. ATOM_GPIO_I2C_ASSIGMENT gpio;
  62. struct radeon_i2c_bus_rec i2c;
  63. int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
  64. struct _ATOM_GPIO_I2C_INFO *i2c_info;
  65. uint16_t data_offset;
  66. memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
  67. i2c.valid = false;
  68. atom_parse_data_header(ctx, index, NULL, NULL, NULL, &data_offset);
  69. i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
  70. gpio = i2c_info->asGPIO_Info[id];
  71. i2c.mask_clk_reg = le16_to_cpu(gpio.usClkMaskRegisterIndex) * 4;
  72. i2c.mask_data_reg = le16_to_cpu(gpio.usDataMaskRegisterIndex) * 4;
  73. i2c.put_clk_reg = le16_to_cpu(gpio.usClkEnRegisterIndex) * 4;
  74. i2c.put_data_reg = le16_to_cpu(gpio.usDataEnRegisterIndex) * 4;
  75. i2c.get_clk_reg = le16_to_cpu(gpio.usClkY_RegisterIndex) * 4;
  76. i2c.get_data_reg = le16_to_cpu(gpio.usDataY_RegisterIndex) * 4;
  77. i2c.a_clk_reg = le16_to_cpu(gpio.usClkA_RegisterIndex) * 4;
  78. i2c.a_data_reg = le16_to_cpu(gpio.usDataA_RegisterIndex) * 4;
  79. i2c.mask_clk_mask = (1 << gpio.ucClkMaskShift);
  80. i2c.mask_data_mask = (1 << gpio.ucDataMaskShift);
  81. i2c.put_clk_mask = (1 << gpio.ucClkEnShift);
  82. i2c.put_data_mask = (1 << gpio.ucDataEnShift);
  83. i2c.get_clk_mask = (1 << gpio.ucClkY_Shift);
  84. i2c.get_data_mask = (1 << gpio.ucDataY_Shift);
  85. i2c.a_clk_mask = (1 << gpio.ucClkA_Shift);
  86. i2c.a_data_mask = (1 << gpio.ucDataA_Shift);
  87. i2c.valid = true;
  88. return i2c;
  89. }
  90. static bool radeon_atom_apply_quirks(struct drm_device *dev,
  91. uint32_t supported_device,
  92. int *connector_type,
  93. struct radeon_i2c_bus_rec *i2c_bus)
  94. {
  95. /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
  96. if ((dev->pdev->device == 0x791e) &&
  97. (dev->pdev->subsystem_vendor == 0x1043) &&
  98. (dev->pdev->subsystem_device == 0x826d)) {
  99. if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
  100. (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
  101. *connector_type = DRM_MODE_CONNECTOR_DVID;
  102. }
  103. /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
  104. if ((dev->pdev->device == 0x7941) &&
  105. (dev->pdev->subsystem_vendor == 0x147b) &&
  106. (dev->pdev->subsystem_device == 0x2412)) {
  107. if (*connector_type == DRM_MODE_CONNECTOR_DVII)
  108. return false;
  109. }
  110. /* Falcon NW laptop lists vga ddc line for LVDS */
  111. if ((dev->pdev->device == 0x5653) &&
  112. (dev->pdev->subsystem_vendor == 0x1462) &&
  113. (dev->pdev->subsystem_device == 0x0291)) {
  114. if (*connector_type == DRM_MODE_CONNECTOR_LVDS)
  115. i2c_bus->valid = false;
  116. }
  117. /* Funky macbooks */
  118. if ((dev->pdev->device == 0x71C5) &&
  119. (dev->pdev->subsystem_vendor == 0x106b) &&
  120. (dev->pdev->subsystem_device == 0x0080)) {
  121. if ((supported_device == ATOM_DEVICE_CRT1_SUPPORT) ||
  122. (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
  123. return false;
  124. }
  125. /* some BIOSes seem to report DAC on HDMI - they hurt me with their lies */
  126. if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) ||
  127. (*connector_type == DRM_MODE_CONNECTOR_HDMIB)) {
  128. if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) {
  129. return false;
  130. }
  131. }
  132. /* ASUS HD 3600 XT board lists the DVI port as HDMI */
  133. if ((dev->pdev->device == 0x9598) &&
  134. (dev->pdev->subsystem_vendor == 0x1043) &&
  135. (dev->pdev->subsystem_device == 0x01da)) {
  136. if (*connector_type == DRM_MODE_CONNECTOR_HDMIB) {
  137. *connector_type = DRM_MODE_CONNECTOR_DVID;
  138. }
  139. }
  140. return true;
  141. }
  142. const int supported_devices_connector_convert[] = {
  143. DRM_MODE_CONNECTOR_Unknown,
  144. DRM_MODE_CONNECTOR_VGA,
  145. DRM_MODE_CONNECTOR_DVII,
  146. DRM_MODE_CONNECTOR_DVID,
  147. DRM_MODE_CONNECTOR_DVIA,
  148. DRM_MODE_CONNECTOR_SVIDEO,
  149. DRM_MODE_CONNECTOR_Composite,
  150. DRM_MODE_CONNECTOR_LVDS,
  151. DRM_MODE_CONNECTOR_Unknown,
  152. DRM_MODE_CONNECTOR_Unknown,
  153. DRM_MODE_CONNECTOR_HDMIA,
  154. DRM_MODE_CONNECTOR_HDMIB,
  155. DRM_MODE_CONNECTOR_Unknown,
  156. DRM_MODE_CONNECTOR_Unknown,
  157. DRM_MODE_CONNECTOR_9PinDIN,
  158. DRM_MODE_CONNECTOR_DisplayPort
  159. };
  160. const int object_connector_convert[] = {
  161. DRM_MODE_CONNECTOR_Unknown,
  162. DRM_MODE_CONNECTOR_DVII,
  163. DRM_MODE_CONNECTOR_DVII,
  164. DRM_MODE_CONNECTOR_DVID,
  165. DRM_MODE_CONNECTOR_DVID,
  166. DRM_MODE_CONNECTOR_VGA,
  167. DRM_MODE_CONNECTOR_Composite,
  168. DRM_MODE_CONNECTOR_SVIDEO,
  169. DRM_MODE_CONNECTOR_Unknown,
  170. DRM_MODE_CONNECTOR_9PinDIN,
  171. DRM_MODE_CONNECTOR_Unknown,
  172. DRM_MODE_CONNECTOR_HDMIA,
  173. DRM_MODE_CONNECTOR_HDMIB,
  174. DRM_MODE_CONNECTOR_HDMIB,
  175. DRM_MODE_CONNECTOR_LVDS,
  176. DRM_MODE_CONNECTOR_9PinDIN,
  177. DRM_MODE_CONNECTOR_Unknown,
  178. DRM_MODE_CONNECTOR_Unknown,
  179. DRM_MODE_CONNECTOR_Unknown,
  180. DRM_MODE_CONNECTOR_DisplayPort
  181. };
  182. bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
  183. {
  184. struct radeon_device *rdev = dev->dev_private;
  185. struct radeon_mode_info *mode_info = &rdev->mode_info;
  186. struct atom_context *ctx = mode_info->atom_context;
  187. int index = GetIndexIntoMasterTable(DATA, Object_Header);
  188. uint16_t size, data_offset;
  189. uint8_t frev, crev, line_mux = 0;
  190. ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
  191. ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
  192. ATOM_OBJECT_HEADER *obj_header;
  193. int i, j, path_size, device_support;
  194. int connector_type;
  195. uint16_t igp_lane_info;
  196. bool linkb;
  197. struct radeon_i2c_bus_rec ddc_bus;
  198. atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
  199. if (data_offset == 0)
  200. return false;
  201. if (crev < 2)
  202. return false;
  203. obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
  204. path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
  205. (ctx->bios + data_offset +
  206. le16_to_cpu(obj_header->usDisplayPathTableOffset));
  207. con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
  208. (ctx->bios + data_offset +
  209. le16_to_cpu(obj_header->usConnectorObjectTableOffset));
  210. device_support = le16_to_cpu(obj_header->usDeviceSupport);
  211. path_size = 0;
  212. for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
  213. uint8_t *addr = (uint8_t *) path_obj->asDispPath;
  214. ATOM_DISPLAY_OBJECT_PATH *path;
  215. addr += path_size;
  216. path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
  217. path_size += le16_to_cpu(path->usSize);
  218. linkb = false;
  219. if (device_support & le16_to_cpu(path->usDeviceTag)) {
  220. uint8_t con_obj_id, con_obj_num, con_obj_type;
  221. con_obj_id =
  222. (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
  223. >> OBJECT_ID_SHIFT;
  224. con_obj_num =
  225. (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
  226. >> ENUM_ID_SHIFT;
  227. con_obj_type =
  228. (le16_to_cpu(path->usConnObjectId) &
  229. OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
  230. if ((le16_to_cpu(path->usDeviceTag) ==
  231. ATOM_DEVICE_TV1_SUPPORT)
  232. || (le16_to_cpu(path->usDeviceTag) ==
  233. ATOM_DEVICE_TV2_SUPPORT)
  234. || (le16_to_cpu(path->usDeviceTag) ==
  235. ATOM_DEVICE_CV_SUPPORT))
  236. continue;
  237. if ((rdev->family == CHIP_RS780) &&
  238. (con_obj_id ==
  239. CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
  240. uint16_t igp_offset = 0;
  241. ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
  242. index =
  243. GetIndexIntoMasterTable(DATA,
  244. IntegratedSystemInfo);
  245. atom_parse_data_header(ctx, index, &size, &frev,
  246. &crev, &igp_offset);
  247. if (crev >= 2) {
  248. igp_obj =
  249. (ATOM_INTEGRATED_SYSTEM_INFO_V2
  250. *) (ctx->bios + igp_offset);
  251. if (igp_obj) {
  252. uint32_t slot_config, ct;
  253. if (con_obj_num == 1)
  254. slot_config =
  255. igp_obj->
  256. ulDDISlot1Config;
  257. else
  258. slot_config =
  259. igp_obj->
  260. ulDDISlot2Config;
  261. ct = (slot_config >> 16) & 0xff;
  262. connector_type =
  263. object_connector_convert
  264. [ct];
  265. igp_lane_info =
  266. slot_config & 0xffff;
  267. } else
  268. continue;
  269. } else
  270. continue;
  271. } else {
  272. igp_lane_info = 0;
  273. connector_type =
  274. object_connector_convert[con_obj_id];
  275. }
  276. if (connector_type == DRM_MODE_CONNECTOR_Unknown)
  277. continue;
  278. for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2);
  279. j++) {
  280. uint8_t enc_obj_id, enc_obj_num, enc_obj_type;
  281. enc_obj_id =
  282. (le16_to_cpu(path->usGraphicObjIds[j]) &
  283. OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
  284. enc_obj_num =
  285. (le16_to_cpu(path->usGraphicObjIds[j]) &
  286. ENUM_ID_MASK) >> ENUM_ID_SHIFT;
  287. enc_obj_type =
  288. (le16_to_cpu(path->usGraphicObjIds[j]) &
  289. OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
  290. /* FIXME: add support for router objects */
  291. if (enc_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
  292. if (enc_obj_num == 2)
  293. linkb = true;
  294. else
  295. linkb = false;
  296. radeon_add_atom_encoder(dev,
  297. enc_obj_id,
  298. le16_to_cpu
  299. (path->
  300. usDeviceTag));
  301. }
  302. }
  303. /* look up gpio for ddc */
  304. if ((le16_to_cpu(path->usDeviceTag) &
  305. (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT))
  306. == 0) {
  307. for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
  308. if (le16_to_cpu(path->usConnObjectId) ==
  309. le16_to_cpu(con_obj->asObjects[j].
  310. usObjectID)) {
  311. ATOM_COMMON_RECORD_HEADER
  312. *record =
  313. (ATOM_COMMON_RECORD_HEADER
  314. *)
  315. (ctx->bios + data_offset +
  316. le16_to_cpu(con_obj->
  317. asObjects[j].
  318. usRecordOffset));
  319. ATOM_I2C_RECORD *i2c_record;
  320. while (record->ucRecordType > 0
  321. && record->
  322. ucRecordType <=
  323. ATOM_MAX_OBJECT_RECORD_NUMBER) {
  324. DRM_ERROR
  325. ("record type %d\n",
  326. record->
  327. ucRecordType);
  328. switch (record->
  329. ucRecordType) {
  330. case ATOM_I2C_RECORD_TYPE:
  331. i2c_record =
  332. (ATOM_I2C_RECORD
  333. *) record;
  334. line_mux =
  335. i2c_record->
  336. sucI2cId.
  337. bfI2C_LineMux;
  338. break;
  339. }
  340. record =
  341. (ATOM_COMMON_RECORD_HEADER
  342. *) ((char *)record
  343. +
  344. record->
  345. ucRecordSize);
  346. }
  347. break;
  348. }
  349. }
  350. } else
  351. line_mux = 0;
  352. if ((le16_to_cpu(path->usDeviceTag) ==
  353. ATOM_DEVICE_TV1_SUPPORT)
  354. || (le16_to_cpu(path->usDeviceTag) ==
  355. ATOM_DEVICE_TV2_SUPPORT)
  356. || (le16_to_cpu(path->usDeviceTag) ==
  357. ATOM_DEVICE_CV_SUPPORT))
  358. ddc_bus.valid = false;
  359. else
  360. ddc_bus = radeon_lookup_gpio(dev, line_mux);
  361. radeon_add_atom_connector(dev,
  362. le16_to_cpu(path->
  363. usConnObjectId),
  364. le16_to_cpu(path->
  365. usDeviceTag),
  366. connector_type, &ddc_bus,
  367. linkb, igp_lane_info);
  368. }
  369. }
  370. radeon_link_encoder_connector(dev);
  371. return true;
  372. }
  373. struct bios_connector {
  374. bool valid;
  375. uint8_t line_mux;
  376. uint16_t devices;
  377. int connector_type;
  378. struct radeon_i2c_bus_rec ddc_bus;
  379. };
  380. bool radeon_get_atom_connector_info_from_supported_devices_table(struct
  381. drm_device
  382. *dev)
  383. {
  384. struct radeon_device *rdev = dev->dev_private;
  385. struct radeon_mode_info *mode_info = &rdev->mode_info;
  386. struct atom_context *ctx = mode_info->atom_context;
  387. int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
  388. uint16_t size, data_offset;
  389. uint8_t frev, crev;
  390. uint16_t device_support;
  391. uint8_t dac;
  392. union atom_supported_devices *supported_devices;
  393. int i, j;
  394. struct bios_connector bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
  395. atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
  396. supported_devices =
  397. (union atom_supported_devices *)(ctx->bios + data_offset);
  398. device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
  399. for (i = 0; i < ATOM_MAX_SUPPORTED_DEVICE; i++) {
  400. ATOM_CONNECTOR_INFO_I2C ci =
  401. supported_devices->info.asConnInfo[i];
  402. bios_connectors[i].valid = false;
  403. if (!(device_support & (1 << i))) {
  404. continue;
  405. }
  406. if (i == ATOM_DEVICE_CV_INDEX) {
  407. DRM_DEBUG("Skipping Component Video\n");
  408. continue;
  409. }
  410. if (i == ATOM_DEVICE_TV1_INDEX) {
  411. DRM_DEBUG("Skipping TV Out\n");
  412. continue;
  413. }
  414. bios_connectors[i].connector_type =
  415. supported_devices_connector_convert[ci.sucConnectorInfo.
  416. sbfAccess.
  417. bfConnectorType];
  418. if (bios_connectors[i].connector_type ==
  419. DRM_MODE_CONNECTOR_Unknown)
  420. continue;
  421. dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
  422. if ((rdev->family == CHIP_RS690) ||
  423. (rdev->family == CHIP_RS740)) {
  424. if ((i == ATOM_DEVICE_DFP2_INDEX)
  425. && (ci.sucI2cId.sbfAccess.bfI2C_LineMux == 2))
  426. bios_connectors[i].line_mux =
  427. ci.sucI2cId.sbfAccess.bfI2C_LineMux + 1;
  428. else if ((i == ATOM_DEVICE_DFP3_INDEX)
  429. && (ci.sucI2cId.sbfAccess.bfI2C_LineMux == 1))
  430. bios_connectors[i].line_mux =
  431. ci.sucI2cId.sbfAccess.bfI2C_LineMux + 1;
  432. else
  433. bios_connectors[i].line_mux =
  434. ci.sucI2cId.sbfAccess.bfI2C_LineMux;
  435. } else
  436. bios_connectors[i].line_mux =
  437. ci.sucI2cId.sbfAccess.bfI2C_LineMux;
  438. /* give tv unique connector ids */
  439. if (i == ATOM_DEVICE_TV1_INDEX) {
  440. bios_connectors[i].ddc_bus.valid = false;
  441. bios_connectors[i].line_mux = 50;
  442. } else if (i == ATOM_DEVICE_TV2_INDEX) {
  443. bios_connectors[i].ddc_bus.valid = false;
  444. bios_connectors[i].line_mux = 51;
  445. } else if (i == ATOM_DEVICE_CV_INDEX) {
  446. bios_connectors[i].ddc_bus.valid = false;
  447. bios_connectors[i].line_mux = 52;
  448. } else
  449. bios_connectors[i].ddc_bus =
  450. radeon_lookup_gpio(dev,
  451. bios_connectors[i].line_mux);
  452. /* Always set the connector type to VGA for CRT1/CRT2. if they are
  453. * shared with a DVI port, we'll pick up the DVI connector when we
  454. * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
  455. */
  456. if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
  457. bios_connectors[i].connector_type =
  458. DRM_MODE_CONNECTOR_VGA;
  459. if (!radeon_atom_apply_quirks
  460. (dev, (1 << i), &bios_connectors[i].connector_type,
  461. &bios_connectors[i].ddc_bus))
  462. continue;
  463. bios_connectors[i].valid = true;
  464. bios_connectors[i].devices = (1 << i);
  465. if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
  466. radeon_add_atom_encoder(dev,
  467. radeon_get_encoder_id(dev,
  468. (1 << i),
  469. dac),
  470. (1 << i));
  471. else
  472. radeon_add_legacy_encoder(dev,
  473. radeon_get_encoder_id(dev,
  474. (1 <<
  475. i),
  476. dac),
  477. (1 << i));
  478. }
  479. /* combine shared connectors */
  480. for (i = 0; i < ATOM_MAX_SUPPORTED_DEVICE; i++) {
  481. if (bios_connectors[i].valid) {
  482. for (j = 0; j < ATOM_MAX_SUPPORTED_DEVICE; j++) {
  483. if (bios_connectors[j].valid && (i != j)) {
  484. if (bios_connectors[i].line_mux ==
  485. bios_connectors[j].line_mux) {
  486. if (((bios_connectors[i].
  487. devices &
  488. (ATOM_DEVICE_DFP_SUPPORT))
  489. && (bios_connectors[j].
  490. devices &
  491. (ATOM_DEVICE_CRT_SUPPORT)))
  492. ||
  493. ((bios_connectors[j].
  494. devices &
  495. (ATOM_DEVICE_DFP_SUPPORT))
  496. && (bios_connectors[i].
  497. devices &
  498. (ATOM_DEVICE_CRT_SUPPORT)))) {
  499. bios_connectors[i].
  500. devices |=
  501. bios_connectors[j].
  502. devices;
  503. bios_connectors[i].
  504. connector_type =
  505. DRM_MODE_CONNECTOR_DVII;
  506. bios_connectors[j].
  507. valid = false;
  508. }
  509. }
  510. }
  511. }
  512. }
  513. }
  514. /* add the connectors */
  515. for (i = 0; i < ATOM_MAX_SUPPORTED_DEVICE; i++) {
  516. if (bios_connectors[i].valid)
  517. radeon_add_atom_connector(dev,
  518. bios_connectors[i].line_mux,
  519. bios_connectors[i].devices,
  520. bios_connectors[i].
  521. connector_type,
  522. &bios_connectors[i].ddc_bus,
  523. false, 0);
  524. }
  525. radeon_link_encoder_connector(dev);
  526. return true;
  527. }
  528. union firmware_info {
  529. ATOM_FIRMWARE_INFO info;
  530. ATOM_FIRMWARE_INFO_V1_2 info_12;
  531. ATOM_FIRMWARE_INFO_V1_3 info_13;
  532. ATOM_FIRMWARE_INFO_V1_4 info_14;
  533. };
  534. bool radeon_atom_get_clock_info(struct drm_device *dev)
  535. {
  536. struct radeon_device *rdev = dev->dev_private;
  537. struct radeon_mode_info *mode_info = &rdev->mode_info;
  538. int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
  539. union firmware_info *firmware_info;
  540. uint8_t frev, crev;
  541. struct radeon_pll *p1pll = &rdev->clock.p1pll;
  542. struct radeon_pll *p2pll = &rdev->clock.p2pll;
  543. struct radeon_pll *spll = &rdev->clock.spll;
  544. struct radeon_pll *mpll = &rdev->clock.mpll;
  545. uint16_t data_offset;
  546. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
  547. &crev, &data_offset);
  548. firmware_info =
  549. (union firmware_info *)(mode_info->atom_context->bios +
  550. data_offset);
  551. if (firmware_info) {
  552. /* pixel clocks */
  553. p1pll->reference_freq =
  554. le16_to_cpu(firmware_info->info.usReferenceClock);
  555. p1pll->reference_div = 0;
  556. p1pll->pll_out_min =
  557. le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
  558. p1pll->pll_out_max =
  559. le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
  560. if (p1pll->pll_out_min == 0) {
  561. if (ASIC_IS_AVIVO(rdev))
  562. p1pll->pll_out_min = 64800;
  563. else
  564. p1pll->pll_out_min = 20000;
  565. }
  566. p1pll->pll_in_min =
  567. le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
  568. p1pll->pll_in_max =
  569. le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
  570. *p2pll = *p1pll;
  571. /* system clock */
  572. spll->reference_freq =
  573. le16_to_cpu(firmware_info->info.usReferenceClock);
  574. spll->reference_div = 0;
  575. spll->pll_out_min =
  576. le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
  577. spll->pll_out_max =
  578. le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
  579. /* ??? */
  580. if (spll->pll_out_min == 0) {
  581. if (ASIC_IS_AVIVO(rdev))
  582. spll->pll_out_min = 64800;
  583. else
  584. spll->pll_out_min = 20000;
  585. }
  586. spll->pll_in_min =
  587. le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
  588. spll->pll_in_max =
  589. le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
  590. /* memory clock */
  591. mpll->reference_freq =
  592. le16_to_cpu(firmware_info->info.usReferenceClock);
  593. mpll->reference_div = 0;
  594. mpll->pll_out_min =
  595. le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
  596. mpll->pll_out_max =
  597. le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
  598. /* ??? */
  599. if (mpll->pll_out_min == 0) {
  600. if (ASIC_IS_AVIVO(rdev))
  601. mpll->pll_out_min = 64800;
  602. else
  603. mpll->pll_out_min = 20000;
  604. }
  605. mpll->pll_in_min =
  606. le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
  607. mpll->pll_in_max =
  608. le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
  609. rdev->clock.default_sclk =
  610. le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
  611. rdev->clock.default_mclk =
  612. le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
  613. return true;
  614. }
  615. return false;
  616. }
  617. struct radeon_encoder_int_tmds *radeon_atombios_get_tmds_info(struct
  618. radeon_encoder
  619. *encoder)
  620. {
  621. struct drm_device *dev = encoder->base.dev;
  622. struct radeon_device *rdev = dev->dev_private;
  623. struct radeon_mode_info *mode_info = &rdev->mode_info;
  624. int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
  625. uint16_t data_offset;
  626. struct _ATOM_TMDS_INFO *tmds_info;
  627. uint8_t frev, crev;
  628. uint16_t maxfreq;
  629. int i;
  630. struct radeon_encoder_int_tmds *tmds = NULL;
  631. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
  632. &crev, &data_offset);
  633. tmds_info =
  634. (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
  635. data_offset);
  636. if (tmds_info) {
  637. tmds =
  638. kzalloc(sizeof(struct radeon_encoder_int_tmds), GFP_KERNEL);
  639. if (!tmds)
  640. return NULL;
  641. maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
  642. for (i = 0; i < 4; i++) {
  643. tmds->tmds_pll[i].freq =
  644. le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
  645. tmds->tmds_pll[i].value =
  646. tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
  647. tmds->tmds_pll[i].value |=
  648. (tmds_info->asMiscInfo[i].
  649. ucPLL_VCO_Gain & 0x3f) << 6;
  650. tmds->tmds_pll[i].value |=
  651. (tmds_info->asMiscInfo[i].
  652. ucPLL_DutyCycle & 0xf) << 12;
  653. tmds->tmds_pll[i].value |=
  654. (tmds_info->asMiscInfo[i].
  655. ucPLL_VoltageSwing & 0xf) << 16;
  656. DRM_DEBUG("TMDS PLL From ATOMBIOS %u %x\n",
  657. tmds->tmds_pll[i].freq,
  658. tmds->tmds_pll[i].value);
  659. if (maxfreq == tmds->tmds_pll[i].freq) {
  660. tmds->tmds_pll[i].freq = 0xffffffff;
  661. break;
  662. }
  663. }
  664. }
  665. return tmds;
  666. }
  667. union lvds_info {
  668. struct _ATOM_LVDS_INFO info;
  669. struct _ATOM_LVDS_INFO_V12 info_12;
  670. };
  671. struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
  672. radeon_encoder
  673. *encoder)
  674. {
  675. struct drm_device *dev = encoder->base.dev;
  676. struct radeon_device *rdev = dev->dev_private;
  677. struct radeon_mode_info *mode_info = &rdev->mode_info;
  678. int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
  679. uint16_t data_offset;
  680. union lvds_info *lvds_info;
  681. uint8_t frev, crev;
  682. struct radeon_encoder_atom_dig *lvds = NULL;
  683. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
  684. &crev, &data_offset);
  685. lvds_info =
  686. (union lvds_info *)(mode_info->atom_context->bios + data_offset);
  687. if (lvds_info) {
  688. lvds =
  689. kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
  690. if (!lvds)
  691. return NULL;
  692. lvds->native_mode.dotclock =
  693. le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
  694. lvds->native_mode.panel_xres =
  695. le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
  696. lvds->native_mode.panel_yres =
  697. le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
  698. lvds->native_mode.hblank =
  699. le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
  700. lvds->native_mode.hoverplus =
  701. le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
  702. lvds->native_mode.hsync_width =
  703. le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
  704. lvds->native_mode.vblank =
  705. le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
  706. lvds->native_mode.voverplus =
  707. le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncOffset);
  708. lvds->native_mode.vsync_width =
  709. le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
  710. lvds->panel_pwr_delay =
  711. le16_to_cpu(lvds_info->info.usOffDelayInMs);
  712. lvds->lvds_misc = lvds_info->info.ucLVDS_Misc;
  713. encoder->native_mode = lvds->native_mode;
  714. }
  715. return lvds;
  716. }
  717. struct radeon_encoder_primary_dac *
  718. radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
  719. {
  720. struct drm_device *dev = encoder->base.dev;
  721. struct radeon_device *rdev = dev->dev_private;
  722. struct radeon_mode_info *mode_info = &rdev->mode_info;
  723. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  724. uint16_t data_offset;
  725. struct _COMPASSIONATE_DATA *dac_info;
  726. uint8_t frev, crev;
  727. uint8_t bg, dac;
  728. int i;
  729. struct radeon_encoder_primary_dac *p_dac = NULL;
  730. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev, &crev, &data_offset);
  731. dac_info = (struct _COMPASSIONATE_DATA *)(mode_info->atom_context->bios + data_offset);
  732. if (dac_info) {
  733. p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
  734. if (!p_dac)
  735. return NULL;
  736. bg = dac_info->ucDAC1_BG_Adjustment;
  737. dac = dac_info->ucDAC1_DAC_Adjustment;
  738. p_dac->ps2_pdac_adj = (bg << 8) | (dac);
  739. }
  740. return p_dac;
  741. }
  742. struct radeon_encoder_tv_dac *
  743. radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
  744. {
  745. struct drm_device *dev = encoder->base.dev;
  746. struct radeon_device *rdev = dev->dev_private;
  747. struct radeon_mode_info *mode_info = &rdev->mode_info;
  748. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  749. uint16_t data_offset;
  750. struct _COMPASSIONATE_DATA *dac_info;
  751. uint8_t frev, crev;
  752. uint8_t bg, dac;
  753. int i;
  754. struct radeon_encoder_tv_dac *tv_dac = NULL;
  755. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev, &crev, &data_offset);
  756. dac_info = (struct _COMPASSIONATE_DATA *)(mode_info->atom_context->bios + data_offset);
  757. if (dac_info) {
  758. tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
  759. if (!tv_dac)
  760. return NULL;
  761. bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
  762. dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
  763. tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
  764. bg = dac_info->ucDAC2_PAL_BG_Adjustment;
  765. dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
  766. tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
  767. bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
  768. dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
  769. tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
  770. }
  771. return tv_dac;
  772. }
  773. void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
  774. {
  775. DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
  776. int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
  777. args.ucEnable = enable;
  778. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  779. }
  780. void radeon_atom_static_pwrmgt_setup(struct radeon_device *rdev, int enable)
  781. {
  782. ENABLE_ASIC_STATIC_PWR_MGT_PS_ALLOCATION args;
  783. int index = GetIndexIntoMasterTable(COMMAND, EnableASIC_StaticPwrMgt);
  784. args.ucEnable = enable;
  785. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  786. }
  787. void radeon_atom_set_engine_clock(struct radeon_device *rdev,
  788. uint32_t eng_clock)
  789. {
  790. SET_ENGINE_CLOCK_PS_ALLOCATION args;
  791. int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
  792. args.ulTargetEngineClock = eng_clock; /* 10 khz */
  793. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  794. }
  795. void radeon_atom_set_memory_clock(struct radeon_device *rdev,
  796. uint32_t mem_clock)
  797. {
  798. SET_MEMORY_CLOCK_PS_ALLOCATION args;
  799. int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
  800. if (rdev->flags & RADEON_IS_IGP)
  801. return;
  802. args.ulTargetMemoryClock = mem_clock; /* 10 khz */
  803. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  804. }
  805. void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
  806. {
  807. struct radeon_device *rdev = dev->dev_private;
  808. uint32_t bios_2_scratch, bios_6_scratch;
  809. if (rdev->family >= CHIP_R600) {
  810. bios_2_scratch = RREG32(R600_BIOS_0_SCRATCH);
  811. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  812. } else {
  813. bios_2_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
  814. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  815. }
  816. /* let the bios control the backlight */
  817. bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
  818. /* tell the bios not to handle mode switching */
  819. bios_6_scratch |= (ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH | ATOM_S6_ACC_MODE);
  820. if (rdev->family >= CHIP_R600) {
  821. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  822. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  823. } else {
  824. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  825. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  826. }
  827. }
  828. void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
  829. {
  830. struct drm_device *dev = encoder->dev;
  831. struct radeon_device *rdev = dev->dev_private;
  832. uint32_t bios_6_scratch;
  833. if (rdev->family >= CHIP_R600)
  834. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  835. else
  836. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  837. if (lock)
  838. bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
  839. else
  840. bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
  841. if (rdev->family >= CHIP_R600)
  842. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  843. else
  844. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  845. }
  846. /* at some point we may want to break this out into individual functions */
  847. void
  848. radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
  849. struct drm_encoder *encoder,
  850. bool connected)
  851. {
  852. struct drm_device *dev = connector->dev;
  853. struct radeon_device *rdev = dev->dev_private;
  854. struct radeon_connector *radeon_connector =
  855. to_radeon_connector(connector);
  856. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  857. uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
  858. if (rdev->family >= CHIP_R600) {
  859. bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
  860. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  861. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  862. } else {
  863. bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
  864. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  865. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  866. }
  867. if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
  868. (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
  869. if (connected) {
  870. DRM_DEBUG("TV1 connected\n");
  871. bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
  872. bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
  873. } else {
  874. DRM_DEBUG("TV1 disconnected\n");
  875. bios_0_scratch &= ~ATOM_S0_TV1_MASK;
  876. bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
  877. bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
  878. }
  879. }
  880. if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
  881. (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
  882. if (connected) {
  883. DRM_DEBUG("CV connected\n");
  884. bios_3_scratch |= ATOM_S3_CV_ACTIVE;
  885. bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
  886. } else {
  887. DRM_DEBUG("CV disconnected\n");
  888. bios_0_scratch &= ~ATOM_S0_CV_MASK;
  889. bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
  890. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
  891. }
  892. }
  893. if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
  894. (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
  895. if (connected) {
  896. DRM_DEBUG("LCD1 connected\n");
  897. bios_0_scratch |= ATOM_S0_LCD1;
  898. bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
  899. bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
  900. } else {
  901. DRM_DEBUG("LCD1 disconnected\n");
  902. bios_0_scratch &= ~ATOM_S0_LCD1;
  903. bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
  904. bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
  905. }
  906. }
  907. if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
  908. (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
  909. if (connected) {
  910. DRM_DEBUG("CRT1 connected\n");
  911. bios_0_scratch |= ATOM_S0_CRT1_COLOR;
  912. bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
  913. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
  914. } else {
  915. DRM_DEBUG("CRT1 disconnected\n");
  916. bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
  917. bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
  918. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
  919. }
  920. }
  921. if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
  922. (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
  923. if (connected) {
  924. DRM_DEBUG("CRT2 connected\n");
  925. bios_0_scratch |= ATOM_S0_CRT2_COLOR;
  926. bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
  927. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
  928. } else {
  929. DRM_DEBUG("CRT2 disconnected\n");
  930. bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
  931. bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
  932. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
  933. }
  934. }
  935. if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
  936. (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
  937. if (connected) {
  938. DRM_DEBUG("DFP1 connected\n");
  939. bios_0_scratch |= ATOM_S0_DFP1;
  940. bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
  941. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
  942. } else {
  943. DRM_DEBUG("DFP1 disconnected\n");
  944. bios_0_scratch &= ~ATOM_S0_DFP1;
  945. bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
  946. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
  947. }
  948. }
  949. if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
  950. (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  951. if (connected) {
  952. DRM_DEBUG("DFP2 connected\n");
  953. bios_0_scratch |= ATOM_S0_DFP2;
  954. bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
  955. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
  956. } else {
  957. DRM_DEBUG("DFP2 disconnected\n");
  958. bios_0_scratch &= ~ATOM_S0_DFP2;
  959. bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
  960. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
  961. }
  962. }
  963. if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
  964. (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
  965. if (connected) {
  966. DRM_DEBUG("DFP3 connected\n");
  967. bios_0_scratch |= ATOM_S0_DFP3;
  968. bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
  969. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
  970. } else {
  971. DRM_DEBUG("DFP3 disconnected\n");
  972. bios_0_scratch &= ~ATOM_S0_DFP3;
  973. bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
  974. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
  975. }
  976. }
  977. if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
  978. (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
  979. if (connected) {
  980. DRM_DEBUG("DFP4 connected\n");
  981. bios_0_scratch |= ATOM_S0_DFP4;
  982. bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
  983. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
  984. } else {
  985. DRM_DEBUG("DFP4 disconnected\n");
  986. bios_0_scratch &= ~ATOM_S0_DFP4;
  987. bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
  988. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
  989. }
  990. }
  991. if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
  992. (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
  993. if (connected) {
  994. DRM_DEBUG("DFP5 connected\n");
  995. bios_0_scratch |= ATOM_S0_DFP5;
  996. bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
  997. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
  998. } else {
  999. DRM_DEBUG("DFP5 disconnected\n");
  1000. bios_0_scratch &= ~ATOM_S0_DFP5;
  1001. bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
  1002. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
  1003. }
  1004. }
  1005. if (rdev->family >= CHIP_R600) {
  1006. WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
  1007. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  1008. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  1009. } else {
  1010. WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
  1011. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  1012. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  1013. }
  1014. }
  1015. void
  1016. radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
  1017. {
  1018. struct drm_device *dev = encoder->dev;
  1019. struct radeon_device *rdev = dev->dev_private;
  1020. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1021. uint32_t bios_3_scratch;
  1022. if (rdev->family >= CHIP_R600)
  1023. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  1024. else
  1025. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  1026. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  1027. bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
  1028. bios_3_scratch |= (crtc << 18);
  1029. }
  1030. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  1031. bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
  1032. bios_3_scratch |= (crtc << 24);
  1033. }
  1034. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  1035. bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
  1036. bios_3_scratch |= (crtc << 16);
  1037. }
  1038. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  1039. bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
  1040. bios_3_scratch |= (crtc << 20);
  1041. }
  1042. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  1043. bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
  1044. bios_3_scratch |= (crtc << 17);
  1045. }
  1046. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  1047. bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
  1048. bios_3_scratch |= (crtc << 19);
  1049. }
  1050. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  1051. bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
  1052. bios_3_scratch |= (crtc << 23);
  1053. }
  1054. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  1055. bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
  1056. bios_3_scratch |= (crtc << 25);
  1057. }
  1058. if (rdev->family >= CHIP_R600)
  1059. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  1060. else
  1061. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  1062. }
  1063. void
  1064. radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
  1065. {
  1066. struct drm_device *dev = encoder->dev;
  1067. struct radeon_device *rdev = dev->dev_private;
  1068. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1069. uint32_t bios_2_scratch;
  1070. if (rdev->family >= CHIP_R600)
  1071. bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
  1072. else
  1073. bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
  1074. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  1075. if (on)
  1076. bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
  1077. else
  1078. bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
  1079. }
  1080. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  1081. if (on)
  1082. bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
  1083. else
  1084. bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
  1085. }
  1086. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  1087. if (on)
  1088. bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
  1089. else
  1090. bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
  1091. }
  1092. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  1093. if (on)
  1094. bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
  1095. else
  1096. bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
  1097. }
  1098. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  1099. if (on)
  1100. bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
  1101. else
  1102. bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
  1103. }
  1104. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  1105. if (on)
  1106. bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
  1107. else
  1108. bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
  1109. }
  1110. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  1111. if (on)
  1112. bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
  1113. else
  1114. bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
  1115. }
  1116. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  1117. if (on)
  1118. bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
  1119. else
  1120. bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
  1121. }
  1122. if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
  1123. if (on)
  1124. bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
  1125. else
  1126. bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
  1127. }
  1128. if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
  1129. if (on)
  1130. bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
  1131. else
  1132. bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
  1133. }
  1134. if (rdev->family >= CHIP_R600)
  1135. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  1136. else
  1137. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  1138. }