radeon_atombios.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466
  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. if (crev < 2)
  563. p1pll->pll_out_min =
  564. le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
  565. else
  566. p1pll->pll_out_min =
  567. le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
  568. p1pll->pll_out_max =
  569. le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
  570. if (p1pll->pll_out_min == 0) {
  571. if (ASIC_IS_AVIVO(rdev))
  572. p1pll->pll_out_min = 64800;
  573. else
  574. p1pll->pll_out_min = 20000;
  575. }
  576. p1pll->pll_in_min =
  577. le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
  578. p1pll->pll_in_max =
  579. le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
  580. *p2pll = *p1pll;
  581. /* system clock */
  582. spll->reference_freq =
  583. le16_to_cpu(firmware_info->info.usReferenceClock);
  584. spll->reference_div = 0;
  585. spll->pll_out_min =
  586. le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
  587. spll->pll_out_max =
  588. le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
  589. /* ??? */
  590. if (spll->pll_out_min == 0) {
  591. if (ASIC_IS_AVIVO(rdev))
  592. spll->pll_out_min = 64800;
  593. else
  594. spll->pll_out_min = 20000;
  595. }
  596. spll->pll_in_min =
  597. le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
  598. spll->pll_in_max =
  599. le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
  600. /* memory clock */
  601. mpll->reference_freq =
  602. le16_to_cpu(firmware_info->info.usReferenceClock);
  603. mpll->reference_div = 0;
  604. mpll->pll_out_min =
  605. le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
  606. mpll->pll_out_max =
  607. le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
  608. /* ??? */
  609. if (mpll->pll_out_min == 0) {
  610. if (ASIC_IS_AVIVO(rdev))
  611. mpll->pll_out_min = 64800;
  612. else
  613. mpll->pll_out_min = 20000;
  614. }
  615. mpll->pll_in_min =
  616. le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
  617. mpll->pll_in_max =
  618. le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
  619. rdev->clock.default_sclk =
  620. le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
  621. rdev->clock.default_mclk =
  622. le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
  623. return true;
  624. }
  625. return false;
  626. }
  627. bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
  628. struct radeon_encoder_int_tmds *tmds)
  629. {
  630. struct drm_device *dev = encoder->base.dev;
  631. struct radeon_device *rdev = dev->dev_private;
  632. struct radeon_mode_info *mode_info = &rdev->mode_info;
  633. int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
  634. uint16_t data_offset;
  635. struct _ATOM_TMDS_INFO *tmds_info;
  636. uint8_t frev, crev;
  637. uint16_t maxfreq;
  638. int i;
  639. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
  640. &crev, &data_offset);
  641. tmds_info =
  642. (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
  643. data_offset);
  644. if (tmds_info) {
  645. maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
  646. for (i = 0; i < 4; i++) {
  647. tmds->tmds_pll[i].freq =
  648. le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
  649. tmds->tmds_pll[i].value =
  650. tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
  651. tmds->tmds_pll[i].value |=
  652. (tmds_info->asMiscInfo[i].
  653. ucPLL_VCO_Gain & 0x3f) << 6;
  654. tmds->tmds_pll[i].value |=
  655. (tmds_info->asMiscInfo[i].
  656. ucPLL_DutyCycle & 0xf) << 12;
  657. tmds->tmds_pll[i].value |=
  658. (tmds_info->asMiscInfo[i].
  659. ucPLL_VoltageSwing & 0xf) << 16;
  660. DRM_DEBUG("TMDS PLL From ATOMBIOS %u %x\n",
  661. tmds->tmds_pll[i].freq,
  662. tmds->tmds_pll[i].value);
  663. if (maxfreq == tmds->tmds_pll[i].freq) {
  664. tmds->tmds_pll[i].freq = 0xffffffff;
  665. break;
  666. }
  667. }
  668. return true;
  669. }
  670. return false;
  671. }
  672. static struct radeon_atom_ss *radeon_atombios_get_ss_info(struct
  673. radeon_encoder
  674. *encoder,
  675. int id)
  676. {
  677. struct drm_device *dev = encoder->base.dev;
  678. struct radeon_device *rdev = dev->dev_private;
  679. struct radeon_mode_info *mode_info = &rdev->mode_info;
  680. int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
  681. uint16_t data_offset;
  682. struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
  683. uint8_t frev, crev;
  684. struct radeon_atom_ss *ss = NULL;
  685. if (id > ATOM_MAX_SS_ENTRY)
  686. return NULL;
  687. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
  688. &crev, &data_offset);
  689. ss_info =
  690. (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
  691. if (ss_info) {
  692. ss =
  693. kzalloc(sizeof(struct radeon_atom_ss), GFP_KERNEL);
  694. if (!ss)
  695. return NULL;
  696. ss->percentage = le16_to_cpu(ss_info->asSS_Info[id].usSpreadSpectrumPercentage);
  697. ss->type = ss_info->asSS_Info[id].ucSpreadSpectrumType;
  698. ss->step = ss_info->asSS_Info[id].ucSS_Step;
  699. ss->delay = ss_info->asSS_Info[id].ucSS_Delay;
  700. ss->range = ss_info->asSS_Info[id].ucSS_Range;
  701. ss->refdiv = ss_info->asSS_Info[id].ucRecommendedRef_Div;
  702. }
  703. return ss;
  704. }
  705. union lvds_info {
  706. struct _ATOM_LVDS_INFO info;
  707. struct _ATOM_LVDS_INFO_V12 info_12;
  708. };
  709. struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
  710. radeon_encoder
  711. *encoder)
  712. {
  713. struct drm_device *dev = encoder->base.dev;
  714. struct radeon_device *rdev = dev->dev_private;
  715. struct radeon_mode_info *mode_info = &rdev->mode_info;
  716. int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
  717. uint16_t data_offset;
  718. union lvds_info *lvds_info;
  719. uint8_t frev, crev;
  720. struct radeon_encoder_atom_dig *lvds = NULL;
  721. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
  722. &crev, &data_offset);
  723. lvds_info =
  724. (union lvds_info *)(mode_info->atom_context->bios + data_offset);
  725. if (lvds_info) {
  726. lvds =
  727. kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
  728. if (!lvds)
  729. return NULL;
  730. lvds->native_mode.clock =
  731. le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
  732. lvds->native_mode.hdisplay =
  733. le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
  734. lvds->native_mode.vdisplay =
  735. le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
  736. lvds->native_mode.htotal = lvds->native_mode.hdisplay +
  737. le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
  738. lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
  739. le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
  740. lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
  741. le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
  742. lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
  743. le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
  744. lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
  745. le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
  746. lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
  747. le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
  748. lvds->panel_pwr_delay =
  749. le16_to_cpu(lvds_info->info.usOffDelayInMs);
  750. lvds->lvds_misc = lvds_info->info.ucLVDS_Misc;
  751. /* set crtc values */
  752. drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
  753. lvds->ss = radeon_atombios_get_ss_info(encoder, lvds_info->info.ucSS_Id);
  754. encoder->native_mode = lvds->native_mode;
  755. }
  756. return lvds;
  757. }
  758. struct radeon_encoder_primary_dac *
  759. radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
  760. {
  761. struct drm_device *dev = encoder->base.dev;
  762. struct radeon_device *rdev = dev->dev_private;
  763. struct radeon_mode_info *mode_info = &rdev->mode_info;
  764. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  765. uint16_t data_offset;
  766. struct _COMPASSIONATE_DATA *dac_info;
  767. uint8_t frev, crev;
  768. uint8_t bg, dac;
  769. struct radeon_encoder_primary_dac *p_dac = NULL;
  770. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev, &crev, &data_offset);
  771. dac_info = (struct _COMPASSIONATE_DATA *)(mode_info->atom_context->bios + data_offset);
  772. if (dac_info) {
  773. p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
  774. if (!p_dac)
  775. return NULL;
  776. bg = dac_info->ucDAC1_BG_Adjustment;
  777. dac = dac_info->ucDAC1_DAC_Adjustment;
  778. p_dac->ps2_pdac_adj = (bg << 8) | (dac);
  779. }
  780. return p_dac;
  781. }
  782. bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
  783. struct drm_display_mode *mode)
  784. {
  785. struct radeon_mode_info *mode_info = &rdev->mode_info;
  786. ATOM_ANALOG_TV_INFO *tv_info;
  787. ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
  788. ATOM_DTD_FORMAT *dtd_timings;
  789. int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
  790. u8 frev, crev;
  791. u16 data_offset, misc;
  792. atom_parse_data_header(mode_info->atom_context, data_index, NULL, &frev, &crev, &data_offset);
  793. switch (crev) {
  794. case 1:
  795. tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
  796. if (index > MAX_SUPPORTED_TV_TIMING)
  797. return false;
  798. mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
  799. mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
  800. mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
  801. mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
  802. le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
  803. mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
  804. mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
  805. mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
  806. mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
  807. le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
  808. mode->flags = 0;
  809. misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
  810. if (misc & ATOM_VSYNC_POLARITY)
  811. mode->flags |= DRM_MODE_FLAG_NVSYNC;
  812. if (misc & ATOM_HSYNC_POLARITY)
  813. mode->flags |= DRM_MODE_FLAG_NHSYNC;
  814. if (misc & ATOM_COMPOSITESYNC)
  815. mode->flags |= DRM_MODE_FLAG_CSYNC;
  816. if (misc & ATOM_INTERLACE)
  817. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  818. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  819. mode->flags |= DRM_MODE_FLAG_DBLSCAN;
  820. mode->clock = le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
  821. if (index == 1) {
  822. /* PAL timings appear to have wrong values for totals */
  823. mode->crtc_htotal -= 1;
  824. mode->crtc_vtotal -= 1;
  825. }
  826. break;
  827. case 2:
  828. tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
  829. if (index > MAX_SUPPORTED_TV_TIMING_V1_2)
  830. return false;
  831. dtd_timings = &tv_info_v1_2->aModeTimings[index];
  832. mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
  833. le16_to_cpu(dtd_timings->usHBlanking_Time);
  834. mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
  835. mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
  836. le16_to_cpu(dtd_timings->usHSyncOffset);
  837. mode->crtc_hsync_end = mode->crtc_hsync_start +
  838. le16_to_cpu(dtd_timings->usHSyncWidth);
  839. mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
  840. le16_to_cpu(dtd_timings->usVBlanking_Time);
  841. mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
  842. mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
  843. le16_to_cpu(dtd_timings->usVSyncOffset);
  844. mode->crtc_vsync_end = mode->crtc_vsync_start +
  845. le16_to_cpu(dtd_timings->usVSyncWidth);
  846. mode->flags = 0;
  847. misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
  848. if (misc & ATOM_VSYNC_POLARITY)
  849. mode->flags |= DRM_MODE_FLAG_NVSYNC;
  850. if (misc & ATOM_HSYNC_POLARITY)
  851. mode->flags |= DRM_MODE_FLAG_NHSYNC;
  852. if (misc & ATOM_COMPOSITESYNC)
  853. mode->flags |= DRM_MODE_FLAG_CSYNC;
  854. if (misc & ATOM_INTERLACE)
  855. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  856. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  857. mode->flags |= DRM_MODE_FLAG_DBLSCAN;
  858. mode->clock = le16_to_cpu(dtd_timings->usPixClk) * 10;
  859. break;
  860. }
  861. return true;
  862. }
  863. struct radeon_encoder_tv_dac *
  864. radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
  865. {
  866. struct drm_device *dev = encoder->base.dev;
  867. struct radeon_device *rdev = dev->dev_private;
  868. struct radeon_mode_info *mode_info = &rdev->mode_info;
  869. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  870. uint16_t data_offset;
  871. struct _COMPASSIONATE_DATA *dac_info;
  872. uint8_t frev, crev;
  873. uint8_t bg, dac;
  874. struct radeon_encoder_tv_dac *tv_dac = NULL;
  875. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev, &crev, &data_offset);
  876. dac_info = (struct _COMPASSIONATE_DATA *)(mode_info->atom_context->bios + data_offset);
  877. if (dac_info) {
  878. tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
  879. if (!tv_dac)
  880. return NULL;
  881. bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
  882. dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
  883. tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
  884. bg = dac_info->ucDAC2_PAL_BG_Adjustment;
  885. dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
  886. tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
  887. bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
  888. dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
  889. tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
  890. }
  891. return tv_dac;
  892. }
  893. void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
  894. {
  895. DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
  896. int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
  897. args.ucEnable = enable;
  898. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  899. }
  900. void radeon_atom_static_pwrmgt_setup(struct radeon_device *rdev, int enable)
  901. {
  902. ENABLE_ASIC_STATIC_PWR_MGT_PS_ALLOCATION args;
  903. int index = GetIndexIntoMasterTable(COMMAND, EnableASIC_StaticPwrMgt);
  904. args.ucEnable = enable;
  905. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  906. }
  907. void radeon_atom_set_engine_clock(struct radeon_device *rdev,
  908. uint32_t eng_clock)
  909. {
  910. SET_ENGINE_CLOCK_PS_ALLOCATION args;
  911. int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
  912. args.ulTargetEngineClock = eng_clock; /* 10 khz */
  913. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  914. }
  915. void radeon_atom_set_memory_clock(struct radeon_device *rdev,
  916. uint32_t mem_clock)
  917. {
  918. SET_MEMORY_CLOCK_PS_ALLOCATION args;
  919. int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
  920. if (rdev->flags & RADEON_IS_IGP)
  921. return;
  922. args.ulTargetMemoryClock = mem_clock; /* 10 khz */
  923. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  924. }
  925. void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
  926. {
  927. struct radeon_device *rdev = dev->dev_private;
  928. uint32_t bios_2_scratch, bios_6_scratch;
  929. if (rdev->family >= CHIP_R600) {
  930. bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
  931. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  932. } else {
  933. bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
  934. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  935. }
  936. /* let the bios control the backlight */
  937. bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
  938. /* tell the bios not to handle mode switching */
  939. bios_6_scratch |= (ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH | ATOM_S6_ACC_MODE);
  940. if (rdev->family >= CHIP_R600) {
  941. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  942. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  943. } else {
  944. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  945. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  946. }
  947. }
  948. void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
  949. {
  950. uint32_t scratch_reg;
  951. int i;
  952. if (rdev->family >= CHIP_R600)
  953. scratch_reg = R600_BIOS_0_SCRATCH;
  954. else
  955. scratch_reg = RADEON_BIOS_0_SCRATCH;
  956. for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
  957. rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
  958. }
  959. void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
  960. {
  961. uint32_t scratch_reg;
  962. int i;
  963. if (rdev->family >= CHIP_R600)
  964. scratch_reg = R600_BIOS_0_SCRATCH;
  965. else
  966. scratch_reg = RADEON_BIOS_0_SCRATCH;
  967. for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
  968. WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
  969. }
  970. void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
  971. {
  972. struct drm_device *dev = encoder->dev;
  973. struct radeon_device *rdev = dev->dev_private;
  974. uint32_t bios_6_scratch;
  975. if (rdev->family >= CHIP_R600)
  976. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  977. else
  978. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  979. if (lock)
  980. bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
  981. else
  982. bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
  983. if (rdev->family >= CHIP_R600)
  984. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  985. else
  986. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  987. }
  988. /* at some point we may want to break this out into individual functions */
  989. void
  990. radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
  991. struct drm_encoder *encoder,
  992. bool connected)
  993. {
  994. struct drm_device *dev = connector->dev;
  995. struct radeon_device *rdev = dev->dev_private;
  996. struct radeon_connector *radeon_connector =
  997. to_radeon_connector(connector);
  998. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  999. uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
  1000. if (rdev->family >= CHIP_R600) {
  1001. bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
  1002. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  1003. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  1004. } else {
  1005. bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
  1006. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  1007. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  1008. }
  1009. if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
  1010. (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
  1011. if (connected) {
  1012. DRM_DEBUG("TV1 connected\n");
  1013. bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
  1014. bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
  1015. } else {
  1016. DRM_DEBUG("TV1 disconnected\n");
  1017. bios_0_scratch &= ~ATOM_S0_TV1_MASK;
  1018. bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
  1019. bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
  1020. }
  1021. }
  1022. if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
  1023. (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
  1024. if (connected) {
  1025. DRM_DEBUG("CV connected\n");
  1026. bios_3_scratch |= ATOM_S3_CV_ACTIVE;
  1027. bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
  1028. } else {
  1029. DRM_DEBUG("CV disconnected\n");
  1030. bios_0_scratch &= ~ATOM_S0_CV_MASK;
  1031. bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
  1032. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
  1033. }
  1034. }
  1035. if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
  1036. (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
  1037. if (connected) {
  1038. DRM_DEBUG("LCD1 connected\n");
  1039. bios_0_scratch |= ATOM_S0_LCD1;
  1040. bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
  1041. bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
  1042. } else {
  1043. DRM_DEBUG("LCD1 disconnected\n");
  1044. bios_0_scratch &= ~ATOM_S0_LCD1;
  1045. bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
  1046. bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
  1047. }
  1048. }
  1049. if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
  1050. (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
  1051. if (connected) {
  1052. DRM_DEBUG("CRT1 connected\n");
  1053. bios_0_scratch |= ATOM_S0_CRT1_COLOR;
  1054. bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
  1055. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
  1056. } else {
  1057. DRM_DEBUG("CRT1 disconnected\n");
  1058. bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
  1059. bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
  1060. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
  1061. }
  1062. }
  1063. if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
  1064. (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
  1065. if (connected) {
  1066. DRM_DEBUG("CRT2 connected\n");
  1067. bios_0_scratch |= ATOM_S0_CRT2_COLOR;
  1068. bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
  1069. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
  1070. } else {
  1071. DRM_DEBUG("CRT2 disconnected\n");
  1072. bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
  1073. bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
  1074. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
  1075. }
  1076. }
  1077. if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
  1078. (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
  1079. if (connected) {
  1080. DRM_DEBUG("DFP1 connected\n");
  1081. bios_0_scratch |= ATOM_S0_DFP1;
  1082. bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
  1083. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
  1084. } else {
  1085. DRM_DEBUG("DFP1 disconnected\n");
  1086. bios_0_scratch &= ~ATOM_S0_DFP1;
  1087. bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
  1088. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
  1089. }
  1090. }
  1091. if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
  1092. (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  1093. if (connected) {
  1094. DRM_DEBUG("DFP2 connected\n");
  1095. bios_0_scratch |= ATOM_S0_DFP2;
  1096. bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
  1097. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
  1098. } else {
  1099. DRM_DEBUG("DFP2 disconnected\n");
  1100. bios_0_scratch &= ~ATOM_S0_DFP2;
  1101. bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
  1102. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
  1103. }
  1104. }
  1105. if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
  1106. (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
  1107. if (connected) {
  1108. DRM_DEBUG("DFP3 connected\n");
  1109. bios_0_scratch |= ATOM_S0_DFP3;
  1110. bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
  1111. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
  1112. } else {
  1113. DRM_DEBUG("DFP3 disconnected\n");
  1114. bios_0_scratch &= ~ATOM_S0_DFP3;
  1115. bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
  1116. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
  1117. }
  1118. }
  1119. if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
  1120. (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
  1121. if (connected) {
  1122. DRM_DEBUG("DFP4 connected\n");
  1123. bios_0_scratch |= ATOM_S0_DFP4;
  1124. bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
  1125. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
  1126. } else {
  1127. DRM_DEBUG("DFP4 disconnected\n");
  1128. bios_0_scratch &= ~ATOM_S0_DFP4;
  1129. bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
  1130. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
  1131. }
  1132. }
  1133. if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
  1134. (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
  1135. if (connected) {
  1136. DRM_DEBUG("DFP5 connected\n");
  1137. bios_0_scratch |= ATOM_S0_DFP5;
  1138. bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
  1139. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
  1140. } else {
  1141. DRM_DEBUG("DFP5 disconnected\n");
  1142. bios_0_scratch &= ~ATOM_S0_DFP5;
  1143. bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
  1144. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
  1145. }
  1146. }
  1147. if (rdev->family >= CHIP_R600) {
  1148. WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
  1149. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  1150. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  1151. } else {
  1152. WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
  1153. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  1154. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  1155. }
  1156. }
  1157. void
  1158. radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
  1159. {
  1160. struct drm_device *dev = encoder->dev;
  1161. struct radeon_device *rdev = dev->dev_private;
  1162. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1163. uint32_t bios_3_scratch;
  1164. if (rdev->family >= CHIP_R600)
  1165. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  1166. else
  1167. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  1168. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  1169. bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
  1170. bios_3_scratch |= (crtc << 18);
  1171. }
  1172. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  1173. bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
  1174. bios_3_scratch |= (crtc << 24);
  1175. }
  1176. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  1177. bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
  1178. bios_3_scratch |= (crtc << 16);
  1179. }
  1180. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  1181. bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
  1182. bios_3_scratch |= (crtc << 20);
  1183. }
  1184. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  1185. bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
  1186. bios_3_scratch |= (crtc << 17);
  1187. }
  1188. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  1189. bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
  1190. bios_3_scratch |= (crtc << 19);
  1191. }
  1192. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  1193. bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
  1194. bios_3_scratch |= (crtc << 23);
  1195. }
  1196. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  1197. bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
  1198. bios_3_scratch |= (crtc << 25);
  1199. }
  1200. if (rdev->family >= CHIP_R600)
  1201. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  1202. else
  1203. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  1204. }
  1205. void
  1206. radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
  1207. {
  1208. struct drm_device *dev = encoder->dev;
  1209. struct radeon_device *rdev = dev->dev_private;
  1210. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1211. uint32_t bios_2_scratch;
  1212. if (rdev->family >= CHIP_R600)
  1213. bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
  1214. else
  1215. bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
  1216. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  1217. if (on)
  1218. bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
  1219. else
  1220. bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
  1221. }
  1222. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  1223. if (on)
  1224. bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
  1225. else
  1226. bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
  1227. }
  1228. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  1229. if (on)
  1230. bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
  1231. else
  1232. bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
  1233. }
  1234. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  1235. if (on)
  1236. bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
  1237. else
  1238. bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
  1239. }
  1240. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  1241. if (on)
  1242. bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
  1243. else
  1244. bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
  1245. }
  1246. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  1247. if (on)
  1248. bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
  1249. else
  1250. bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
  1251. }
  1252. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  1253. if (on)
  1254. bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
  1255. else
  1256. bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
  1257. }
  1258. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  1259. if (on)
  1260. bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
  1261. else
  1262. bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
  1263. }
  1264. if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
  1265. if (on)
  1266. bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
  1267. else
  1268. bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
  1269. }
  1270. if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
  1271. if (on)
  1272. bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
  1273. else
  1274. bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
  1275. }
  1276. if (rdev->family >= CHIP_R600)
  1277. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  1278. else
  1279. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  1280. }