radeon_atombios.c 42 KB

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