radeon_atombios.c 42 KB

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