radeon_atombios.c 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778
  1. /*
  2. * Copyright 2007-8 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  19. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. * OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors: Dave Airlie
  24. * Alex Deucher
  25. */
  26. #include "drmP.h"
  27. #include "radeon_drm.h"
  28. #include "radeon.h"
  29. #include "atom.h"
  30. #include "atom-bits.h"
  31. /* from radeon_encoder.c */
  32. extern uint32_t
  33. radeon_get_encoder_id(struct drm_device *dev, uint32_t supported_device,
  34. uint8_t dac);
  35. extern void radeon_link_encoder_connector(struct drm_device *dev);
  36. extern void
  37. radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_id,
  38. uint32_t supported_device);
  39. /* from radeon_connector.c */
  40. extern void
  41. radeon_add_atom_connector(struct drm_device *dev,
  42. uint32_t connector_id,
  43. uint32_t supported_device,
  44. int connector_type,
  45. struct radeon_i2c_bus_rec *i2c_bus,
  46. bool linkb, uint32_t igp_lane_info,
  47. uint16_t connector_object_id,
  48. struct radeon_hpd *hpd);
  49. /* from radeon_legacy_encoder.c */
  50. extern void
  51. radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_id,
  52. uint32_t supported_device);
  53. union atom_supported_devices {
  54. struct _ATOM_SUPPORTED_DEVICES_INFO info;
  55. struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2;
  56. struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1;
  57. };
  58. static inline struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_device *rdev,
  59. uint8_t id)
  60. {
  61. struct atom_context *ctx = rdev->mode_info.atom_context;
  62. ATOM_GPIO_I2C_ASSIGMENT *gpio;
  63. struct radeon_i2c_bus_rec i2c;
  64. int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
  65. struct _ATOM_GPIO_I2C_INFO *i2c_info;
  66. uint16_t data_offset;
  67. int i;
  68. memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
  69. i2c.valid = false;
  70. atom_parse_data_header(ctx, index, NULL, NULL, NULL, &data_offset);
  71. i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
  72. for (i = 0; i < ATOM_MAX_SUPPORTED_DEVICE; i++) {
  73. gpio = &i2c_info->asGPIO_Info[i];
  74. if (gpio->sucI2cId.ucAccess == id) {
  75. i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
  76. i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
  77. i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
  78. i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
  79. i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
  80. i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
  81. i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
  82. i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
  83. i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
  84. i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
  85. i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
  86. i2c.en_data_mask = (1 << gpio->ucDataEnShift);
  87. i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
  88. i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
  89. i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
  90. i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
  91. if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
  92. i2c.hw_capable = true;
  93. else
  94. i2c.hw_capable = false;
  95. if (gpio->sucI2cId.ucAccess == 0xa0)
  96. i2c.mm_i2c = true;
  97. else
  98. i2c.mm_i2c = false;
  99. i2c.i2c_id = gpio->sucI2cId.ucAccess;
  100. i2c.valid = true;
  101. break;
  102. }
  103. }
  104. return i2c;
  105. }
  106. static inline struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev,
  107. u8 id)
  108. {
  109. struct atom_context *ctx = rdev->mode_info.atom_context;
  110. struct radeon_gpio_rec gpio;
  111. int index = GetIndexIntoMasterTable(DATA, GPIO_Pin_LUT);
  112. struct _ATOM_GPIO_PIN_LUT *gpio_info;
  113. ATOM_GPIO_PIN_ASSIGNMENT *pin;
  114. u16 data_offset, size;
  115. int i, num_indices;
  116. memset(&gpio, 0, sizeof(struct radeon_gpio_rec));
  117. gpio.valid = false;
  118. atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset);
  119. gpio_info = (struct _ATOM_GPIO_PIN_LUT *)(ctx->bios + data_offset);
  120. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) / sizeof(ATOM_GPIO_PIN_ASSIGNMENT);
  121. for (i = 0; i < num_indices; i++) {
  122. pin = &gpio_info->asGPIO_Pin[i];
  123. if (id == pin->ucGPIO_ID) {
  124. gpio.id = pin->ucGPIO_ID;
  125. gpio.reg = pin->usGpioPin_AIndex * 4;
  126. gpio.mask = (1 << pin->ucGpioPinBitShift);
  127. gpio.valid = true;
  128. break;
  129. }
  130. }
  131. return gpio;
  132. }
  133. static struct radeon_hpd radeon_atom_get_hpd_info_from_gpio(struct radeon_device *rdev,
  134. struct radeon_gpio_rec *gpio)
  135. {
  136. struct radeon_hpd hpd;
  137. hpd.gpio = *gpio;
  138. if (gpio->reg == AVIVO_DC_GPIO_HPD_A) {
  139. switch(gpio->mask) {
  140. case (1 << 0):
  141. hpd.hpd = RADEON_HPD_1;
  142. break;
  143. case (1 << 8):
  144. hpd.hpd = RADEON_HPD_2;
  145. break;
  146. case (1 << 16):
  147. hpd.hpd = RADEON_HPD_3;
  148. break;
  149. case (1 << 24):
  150. hpd.hpd = RADEON_HPD_4;
  151. break;
  152. case (1 << 26):
  153. hpd.hpd = RADEON_HPD_5;
  154. break;
  155. case (1 << 28):
  156. hpd.hpd = RADEON_HPD_6;
  157. break;
  158. default:
  159. hpd.hpd = RADEON_HPD_NONE;
  160. break;
  161. }
  162. } else
  163. hpd.hpd = RADEON_HPD_NONE;
  164. return hpd;
  165. }
  166. static bool radeon_atom_apply_quirks(struct drm_device *dev,
  167. uint32_t supported_device,
  168. int *connector_type,
  169. struct radeon_i2c_bus_rec *i2c_bus,
  170. uint16_t *line_mux,
  171. struct radeon_hpd *hpd)
  172. {
  173. /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
  174. if ((dev->pdev->device == 0x791e) &&
  175. (dev->pdev->subsystem_vendor == 0x1043) &&
  176. (dev->pdev->subsystem_device == 0x826d)) {
  177. if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
  178. (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
  179. *connector_type = DRM_MODE_CONNECTOR_DVID;
  180. }
  181. /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
  182. if ((dev->pdev->device == 0x7941) &&
  183. (dev->pdev->subsystem_vendor == 0x147b) &&
  184. (dev->pdev->subsystem_device == 0x2412)) {
  185. if (*connector_type == DRM_MODE_CONNECTOR_DVII)
  186. return false;
  187. }
  188. /* Falcon NW laptop lists vga ddc line for LVDS */
  189. if ((dev->pdev->device == 0x5653) &&
  190. (dev->pdev->subsystem_vendor == 0x1462) &&
  191. (dev->pdev->subsystem_device == 0x0291)) {
  192. if (*connector_type == DRM_MODE_CONNECTOR_LVDS) {
  193. i2c_bus->valid = false;
  194. *line_mux = 53;
  195. }
  196. }
  197. /* HIS X1300 is DVI+VGA, not DVI+DVI */
  198. if ((dev->pdev->device == 0x7146) &&
  199. (dev->pdev->subsystem_vendor == 0x17af) &&
  200. (dev->pdev->subsystem_device == 0x2058)) {
  201. if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
  202. return false;
  203. }
  204. /* Gigabyte X1300 is DVI+VGA, not DVI+DVI */
  205. if ((dev->pdev->device == 0x7142) &&
  206. (dev->pdev->subsystem_vendor == 0x1458) &&
  207. (dev->pdev->subsystem_device == 0x2134)) {
  208. if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
  209. return false;
  210. }
  211. /* Funky macbooks */
  212. if ((dev->pdev->device == 0x71C5) &&
  213. (dev->pdev->subsystem_vendor == 0x106b) &&
  214. (dev->pdev->subsystem_device == 0x0080)) {
  215. if ((supported_device == ATOM_DEVICE_CRT1_SUPPORT) ||
  216. (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
  217. return false;
  218. }
  219. /* ASUS HD 3600 XT board lists the DVI port as HDMI */
  220. if ((dev->pdev->device == 0x9598) &&
  221. (dev->pdev->subsystem_vendor == 0x1043) &&
  222. (dev->pdev->subsystem_device == 0x01da)) {
  223. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  224. *connector_type = DRM_MODE_CONNECTOR_DVII;
  225. }
  226. }
  227. /* ASUS HD 3450 board lists the DVI port as HDMI */
  228. if ((dev->pdev->device == 0x95C5) &&
  229. (dev->pdev->subsystem_vendor == 0x1043) &&
  230. (dev->pdev->subsystem_device == 0x01e2)) {
  231. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  232. *connector_type = DRM_MODE_CONNECTOR_DVII;
  233. }
  234. }
  235. /* some BIOSes seem to report DAC on HDMI - usually this is a board with
  236. * HDMI + VGA reporting as HDMI
  237. */
  238. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  239. if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) {
  240. *connector_type = DRM_MODE_CONNECTOR_VGA;
  241. *line_mux = 0;
  242. }
  243. }
  244. /* Acer laptop reports DVI-D as DVI-I */
  245. if ((dev->pdev->device == 0x95c4) &&
  246. (dev->pdev->subsystem_vendor == 0x1025) &&
  247. (dev->pdev->subsystem_device == 0x013c)) {
  248. if ((*connector_type == DRM_MODE_CONNECTOR_DVII) &&
  249. (supported_device == ATOM_DEVICE_DFP1_SUPPORT))
  250. *connector_type = DRM_MODE_CONNECTOR_DVID;
  251. }
  252. return true;
  253. }
  254. const int supported_devices_connector_convert[] = {
  255. DRM_MODE_CONNECTOR_Unknown,
  256. DRM_MODE_CONNECTOR_VGA,
  257. DRM_MODE_CONNECTOR_DVII,
  258. DRM_MODE_CONNECTOR_DVID,
  259. DRM_MODE_CONNECTOR_DVIA,
  260. DRM_MODE_CONNECTOR_SVIDEO,
  261. DRM_MODE_CONNECTOR_Composite,
  262. DRM_MODE_CONNECTOR_LVDS,
  263. DRM_MODE_CONNECTOR_Unknown,
  264. DRM_MODE_CONNECTOR_Unknown,
  265. DRM_MODE_CONNECTOR_HDMIA,
  266. DRM_MODE_CONNECTOR_HDMIB,
  267. DRM_MODE_CONNECTOR_Unknown,
  268. DRM_MODE_CONNECTOR_Unknown,
  269. DRM_MODE_CONNECTOR_9PinDIN,
  270. DRM_MODE_CONNECTOR_DisplayPort
  271. };
  272. const uint16_t supported_devices_connector_object_id_convert[] = {
  273. CONNECTOR_OBJECT_ID_NONE,
  274. CONNECTOR_OBJECT_ID_VGA,
  275. CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I, /* not all boards support DL */
  276. CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D, /* not all boards support DL */
  277. CONNECTOR_OBJECT_ID_VGA, /* technically DVI-A */
  278. CONNECTOR_OBJECT_ID_COMPOSITE,
  279. CONNECTOR_OBJECT_ID_SVIDEO,
  280. CONNECTOR_OBJECT_ID_LVDS,
  281. CONNECTOR_OBJECT_ID_9PIN_DIN,
  282. CONNECTOR_OBJECT_ID_9PIN_DIN,
  283. CONNECTOR_OBJECT_ID_DISPLAYPORT,
  284. CONNECTOR_OBJECT_ID_HDMI_TYPE_A,
  285. CONNECTOR_OBJECT_ID_HDMI_TYPE_B,
  286. CONNECTOR_OBJECT_ID_SVIDEO
  287. };
  288. const int object_connector_convert[] = {
  289. DRM_MODE_CONNECTOR_Unknown,
  290. DRM_MODE_CONNECTOR_DVII,
  291. DRM_MODE_CONNECTOR_DVII,
  292. DRM_MODE_CONNECTOR_DVID,
  293. DRM_MODE_CONNECTOR_DVID,
  294. DRM_MODE_CONNECTOR_VGA,
  295. DRM_MODE_CONNECTOR_Composite,
  296. DRM_MODE_CONNECTOR_SVIDEO,
  297. DRM_MODE_CONNECTOR_Unknown,
  298. DRM_MODE_CONNECTOR_Unknown,
  299. DRM_MODE_CONNECTOR_9PinDIN,
  300. DRM_MODE_CONNECTOR_Unknown,
  301. DRM_MODE_CONNECTOR_HDMIA,
  302. DRM_MODE_CONNECTOR_HDMIB,
  303. DRM_MODE_CONNECTOR_LVDS,
  304. DRM_MODE_CONNECTOR_9PinDIN,
  305. DRM_MODE_CONNECTOR_Unknown,
  306. DRM_MODE_CONNECTOR_Unknown,
  307. DRM_MODE_CONNECTOR_Unknown,
  308. DRM_MODE_CONNECTOR_DisplayPort,
  309. DRM_MODE_CONNECTOR_eDP,
  310. DRM_MODE_CONNECTOR_Unknown
  311. };
  312. bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
  313. {
  314. struct radeon_device *rdev = dev->dev_private;
  315. struct radeon_mode_info *mode_info = &rdev->mode_info;
  316. struct atom_context *ctx = mode_info->atom_context;
  317. int index = GetIndexIntoMasterTable(DATA, Object_Header);
  318. u16 size, data_offset;
  319. u8 frev, crev;
  320. ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
  321. ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
  322. ATOM_OBJECT_HEADER *obj_header;
  323. int i, j, path_size, device_support;
  324. int connector_type;
  325. u16 igp_lane_info, conn_id, connector_object_id;
  326. bool linkb;
  327. struct radeon_i2c_bus_rec ddc_bus;
  328. struct radeon_gpio_rec gpio;
  329. struct radeon_hpd hpd;
  330. atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
  331. if (data_offset == 0)
  332. return false;
  333. if (crev < 2)
  334. return false;
  335. obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
  336. path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
  337. (ctx->bios + data_offset +
  338. le16_to_cpu(obj_header->usDisplayPathTableOffset));
  339. con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
  340. (ctx->bios + data_offset +
  341. le16_to_cpu(obj_header->usConnectorObjectTableOffset));
  342. device_support = le16_to_cpu(obj_header->usDeviceSupport);
  343. path_size = 0;
  344. for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
  345. uint8_t *addr = (uint8_t *) path_obj->asDispPath;
  346. ATOM_DISPLAY_OBJECT_PATH *path;
  347. addr += path_size;
  348. path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
  349. path_size += le16_to_cpu(path->usSize);
  350. linkb = false;
  351. if (device_support & le16_to_cpu(path->usDeviceTag)) {
  352. uint8_t con_obj_id, con_obj_num, con_obj_type;
  353. con_obj_id =
  354. (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
  355. >> OBJECT_ID_SHIFT;
  356. con_obj_num =
  357. (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
  358. >> ENUM_ID_SHIFT;
  359. con_obj_type =
  360. (le16_to_cpu(path->usConnObjectId) &
  361. OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
  362. /* TODO CV support */
  363. if (le16_to_cpu(path->usDeviceTag) ==
  364. ATOM_DEVICE_CV_SUPPORT)
  365. continue;
  366. /* IGP chips */
  367. if ((rdev->flags & RADEON_IS_IGP) &&
  368. (con_obj_id ==
  369. CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
  370. uint16_t igp_offset = 0;
  371. ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
  372. index =
  373. GetIndexIntoMasterTable(DATA,
  374. IntegratedSystemInfo);
  375. atom_parse_data_header(ctx, index, &size, &frev,
  376. &crev, &igp_offset);
  377. if (crev >= 2) {
  378. igp_obj =
  379. (ATOM_INTEGRATED_SYSTEM_INFO_V2
  380. *) (ctx->bios + igp_offset);
  381. if (igp_obj) {
  382. uint32_t slot_config, ct;
  383. if (con_obj_num == 1)
  384. slot_config =
  385. igp_obj->
  386. ulDDISlot1Config;
  387. else
  388. slot_config =
  389. igp_obj->
  390. ulDDISlot2Config;
  391. ct = (slot_config >> 16) & 0xff;
  392. connector_type =
  393. object_connector_convert
  394. [ct];
  395. connector_object_id = ct;
  396. igp_lane_info =
  397. slot_config & 0xffff;
  398. } else
  399. continue;
  400. } else
  401. continue;
  402. } else {
  403. igp_lane_info = 0;
  404. connector_type =
  405. object_connector_convert[con_obj_id];
  406. connector_object_id = con_obj_id;
  407. }
  408. if (connector_type == DRM_MODE_CONNECTOR_Unknown)
  409. continue;
  410. for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2);
  411. j++) {
  412. uint8_t enc_obj_id, enc_obj_num, enc_obj_type;
  413. enc_obj_id =
  414. (le16_to_cpu(path->usGraphicObjIds[j]) &
  415. OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
  416. enc_obj_num =
  417. (le16_to_cpu(path->usGraphicObjIds[j]) &
  418. ENUM_ID_MASK) >> ENUM_ID_SHIFT;
  419. enc_obj_type =
  420. (le16_to_cpu(path->usGraphicObjIds[j]) &
  421. OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
  422. /* FIXME: add support for router objects */
  423. if (enc_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
  424. if (enc_obj_num == 2)
  425. linkb = true;
  426. else
  427. linkb = false;
  428. radeon_add_atom_encoder(dev,
  429. enc_obj_id,
  430. le16_to_cpu
  431. (path->
  432. usDeviceTag));
  433. }
  434. }
  435. /* look up gpio for ddc, hpd */
  436. if ((le16_to_cpu(path->usDeviceTag) &
  437. (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) == 0) {
  438. for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
  439. if (le16_to_cpu(path->usConnObjectId) ==
  440. le16_to_cpu(con_obj->asObjects[j].
  441. usObjectID)) {
  442. ATOM_COMMON_RECORD_HEADER
  443. *record =
  444. (ATOM_COMMON_RECORD_HEADER
  445. *)
  446. (ctx->bios + data_offset +
  447. le16_to_cpu(con_obj->
  448. asObjects[j].
  449. usRecordOffset));
  450. ATOM_I2C_RECORD *i2c_record;
  451. ATOM_HPD_INT_RECORD *hpd_record;
  452. ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
  453. hpd.hpd = RADEON_HPD_NONE;
  454. while (record->ucRecordType > 0
  455. && record->
  456. ucRecordType <=
  457. ATOM_MAX_OBJECT_RECORD_NUMBER) {
  458. switch (record->ucRecordType) {
  459. case ATOM_I2C_RECORD_TYPE:
  460. i2c_record =
  461. (ATOM_I2C_RECORD *)
  462. record;
  463. i2c_config =
  464. (ATOM_I2C_ID_CONFIG_ACCESS *)
  465. &i2c_record->sucI2cId;
  466. ddc_bus = radeon_lookup_i2c_gpio(rdev,
  467. i2c_config->
  468. ucAccess);
  469. break;
  470. case ATOM_HPD_INT_RECORD_TYPE:
  471. hpd_record =
  472. (ATOM_HPD_INT_RECORD *)
  473. record;
  474. gpio = radeon_lookup_gpio(rdev,
  475. hpd_record->ucHPDIntGPIOID);
  476. hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
  477. hpd.plugged_state = hpd_record->ucPlugged_PinState;
  478. break;
  479. }
  480. record =
  481. (ATOM_COMMON_RECORD_HEADER
  482. *) ((char *)record
  483. +
  484. record->
  485. ucRecordSize);
  486. }
  487. break;
  488. }
  489. }
  490. } else {
  491. hpd.hpd = RADEON_HPD_NONE;
  492. ddc_bus.valid = false;
  493. }
  494. conn_id = le16_to_cpu(path->usConnObjectId);
  495. if (!radeon_atom_apply_quirks
  496. (dev, le16_to_cpu(path->usDeviceTag), &connector_type,
  497. &ddc_bus, &conn_id, &hpd))
  498. continue;
  499. radeon_add_atom_connector(dev,
  500. conn_id,
  501. le16_to_cpu(path->
  502. usDeviceTag),
  503. connector_type, &ddc_bus,
  504. linkb, igp_lane_info,
  505. connector_object_id,
  506. &hpd);
  507. }
  508. }
  509. radeon_link_encoder_connector(dev);
  510. return true;
  511. }
  512. static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
  513. int connector_type,
  514. uint16_t devices)
  515. {
  516. struct radeon_device *rdev = dev->dev_private;
  517. if (rdev->flags & RADEON_IS_IGP) {
  518. return supported_devices_connector_object_id_convert
  519. [connector_type];
  520. } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) ||
  521. (connector_type == DRM_MODE_CONNECTOR_DVID)) &&
  522. (devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  523. struct radeon_mode_info *mode_info = &rdev->mode_info;
  524. struct atom_context *ctx = mode_info->atom_context;
  525. int index = GetIndexIntoMasterTable(DATA, XTMDS_Info);
  526. uint16_t size, data_offset;
  527. uint8_t frev, crev;
  528. ATOM_XTMDS_INFO *xtmds;
  529. atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
  530. xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset);
  531. if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) {
  532. if (connector_type == DRM_MODE_CONNECTOR_DVII)
  533. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
  534. else
  535. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
  536. } else {
  537. if (connector_type == DRM_MODE_CONNECTOR_DVII)
  538. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  539. else
  540. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
  541. }
  542. } else {
  543. return supported_devices_connector_object_id_convert
  544. [connector_type];
  545. }
  546. }
  547. struct bios_connector {
  548. bool valid;
  549. uint16_t line_mux;
  550. uint16_t devices;
  551. int connector_type;
  552. struct radeon_i2c_bus_rec ddc_bus;
  553. struct radeon_hpd hpd;
  554. };
  555. bool radeon_get_atom_connector_info_from_supported_devices_table(struct
  556. drm_device
  557. *dev)
  558. {
  559. struct radeon_device *rdev = dev->dev_private;
  560. struct radeon_mode_info *mode_info = &rdev->mode_info;
  561. struct atom_context *ctx = mode_info->atom_context;
  562. int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
  563. uint16_t size, data_offset;
  564. uint8_t frev, crev;
  565. uint16_t device_support;
  566. uint8_t dac;
  567. union atom_supported_devices *supported_devices;
  568. int i, j, max_device;
  569. struct bios_connector bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
  570. atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
  571. supported_devices =
  572. (union atom_supported_devices *)(ctx->bios + data_offset);
  573. device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
  574. if (frev > 1)
  575. max_device = ATOM_MAX_SUPPORTED_DEVICE;
  576. else
  577. max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO;
  578. for (i = 0; i < max_device; i++) {
  579. ATOM_CONNECTOR_INFO_I2C ci =
  580. supported_devices->info.asConnInfo[i];
  581. bios_connectors[i].valid = false;
  582. if (!(device_support & (1 << i))) {
  583. continue;
  584. }
  585. if (i == ATOM_DEVICE_CV_INDEX) {
  586. DRM_DEBUG("Skipping Component Video\n");
  587. continue;
  588. }
  589. bios_connectors[i].connector_type =
  590. supported_devices_connector_convert[ci.sucConnectorInfo.
  591. sbfAccess.
  592. bfConnectorType];
  593. if (bios_connectors[i].connector_type ==
  594. DRM_MODE_CONNECTOR_Unknown)
  595. continue;
  596. dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
  597. bios_connectors[i].line_mux =
  598. ci.sucI2cId.ucAccess;
  599. /* give tv unique connector ids */
  600. if (i == ATOM_DEVICE_TV1_INDEX) {
  601. bios_connectors[i].ddc_bus.valid = false;
  602. bios_connectors[i].line_mux = 50;
  603. } else if (i == ATOM_DEVICE_TV2_INDEX) {
  604. bios_connectors[i].ddc_bus.valid = false;
  605. bios_connectors[i].line_mux = 51;
  606. } else if (i == ATOM_DEVICE_CV_INDEX) {
  607. bios_connectors[i].ddc_bus.valid = false;
  608. bios_connectors[i].line_mux = 52;
  609. } else
  610. bios_connectors[i].ddc_bus =
  611. radeon_lookup_i2c_gpio(rdev,
  612. bios_connectors[i].line_mux);
  613. if ((crev > 1) && (frev > 1)) {
  614. u8 isb = supported_devices->info_2d1.asIntSrcInfo[i].ucIntSrcBitmap;
  615. switch (isb) {
  616. case 0x4:
  617. bios_connectors[i].hpd.hpd = RADEON_HPD_1;
  618. break;
  619. case 0xa:
  620. bios_connectors[i].hpd.hpd = RADEON_HPD_2;
  621. break;
  622. default:
  623. bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
  624. break;
  625. }
  626. } else {
  627. if (i == ATOM_DEVICE_DFP1_INDEX)
  628. bios_connectors[i].hpd.hpd = RADEON_HPD_1;
  629. else if (i == ATOM_DEVICE_DFP2_INDEX)
  630. bios_connectors[i].hpd.hpd = RADEON_HPD_2;
  631. else
  632. bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
  633. }
  634. /* Always set the connector type to VGA for CRT1/CRT2. if they are
  635. * shared with a DVI port, we'll pick up the DVI connector when we
  636. * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
  637. */
  638. if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
  639. bios_connectors[i].connector_type =
  640. DRM_MODE_CONNECTOR_VGA;
  641. if (!radeon_atom_apply_quirks
  642. (dev, (1 << i), &bios_connectors[i].connector_type,
  643. &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux,
  644. &bios_connectors[i].hpd))
  645. continue;
  646. bios_connectors[i].valid = true;
  647. bios_connectors[i].devices = (1 << i);
  648. if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
  649. radeon_add_atom_encoder(dev,
  650. radeon_get_encoder_id(dev,
  651. (1 << i),
  652. dac),
  653. (1 << i));
  654. else
  655. radeon_add_legacy_encoder(dev,
  656. radeon_get_encoder_id(dev,
  657. (1 << i),
  658. dac),
  659. (1 << i));
  660. }
  661. /* combine shared connectors */
  662. for (i = 0; i < max_device; i++) {
  663. if (bios_connectors[i].valid) {
  664. for (j = 0; j < max_device; j++) {
  665. if (bios_connectors[j].valid && (i != j)) {
  666. if (bios_connectors[i].line_mux ==
  667. bios_connectors[j].line_mux) {
  668. /* make sure not to combine LVDS */
  669. if (bios_connectors[i].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  670. bios_connectors[i].line_mux = 53;
  671. bios_connectors[i].ddc_bus.valid = false;
  672. continue;
  673. }
  674. if (bios_connectors[j].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  675. bios_connectors[j].line_mux = 53;
  676. bios_connectors[j].ddc_bus.valid = false;
  677. continue;
  678. }
  679. /* combine analog and digital for DVI-I */
  680. if (((bios_connectors[i].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
  681. (bios_connectors[j].devices & (ATOM_DEVICE_CRT_SUPPORT))) ||
  682. ((bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
  683. (bios_connectors[i].devices & (ATOM_DEVICE_CRT_SUPPORT)))) {
  684. bios_connectors[i].devices |=
  685. bios_connectors[j].devices;
  686. bios_connectors[i].connector_type =
  687. DRM_MODE_CONNECTOR_DVII;
  688. if (bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT))
  689. bios_connectors[i].hpd =
  690. bios_connectors[j].hpd;
  691. bios_connectors[j].valid = false;
  692. }
  693. }
  694. }
  695. }
  696. }
  697. }
  698. /* add the connectors */
  699. for (i = 0; i < max_device; i++) {
  700. if (bios_connectors[i].valid) {
  701. uint16_t connector_object_id =
  702. atombios_get_connector_object_id(dev,
  703. bios_connectors[i].connector_type,
  704. bios_connectors[i].devices);
  705. radeon_add_atom_connector(dev,
  706. bios_connectors[i].line_mux,
  707. bios_connectors[i].devices,
  708. bios_connectors[i].
  709. connector_type,
  710. &bios_connectors[i].ddc_bus,
  711. false, 0,
  712. connector_object_id,
  713. &bios_connectors[i].hpd);
  714. }
  715. }
  716. radeon_link_encoder_connector(dev);
  717. return true;
  718. }
  719. union firmware_info {
  720. ATOM_FIRMWARE_INFO info;
  721. ATOM_FIRMWARE_INFO_V1_2 info_12;
  722. ATOM_FIRMWARE_INFO_V1_3 info_13;
  723. ATOM_FIRMWARE_INFO_V1_4 info_14;
  724. };
  725. bool radeon_atom_get_clock_info(struct drm_device *dev)
  726. {
  727. struct radeon_device *rdev = dev->dev_private;
  728. struct radeon_mode_info *mode_info = &rdev->mode_info;
  729. int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
  730. union firmware_info *firmware_info;
  731. uint8_t frev, crev;
  732. struct radeon_pll *p1pll = &rdev->clock.p1pll;
  733. struct radeon_pll *p2pll = &rdev->clock.p2pll;
  734. struct radeon_pll *spll = &rdev->clock.spll;
  735. struct radeon_pll *mpll = &rdev->clock.mpll;
  736. uint16_t data_offset;
  737. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
  738. &crev, &data_offset);
  739. firmware_info =
  740. (union firmware_info *)(mode_info->atom_context->bios +
  741. data_offset);
  742. if (firmware_info) {
  743. /* pixel clocks */
  744. p1pll->reference_freq =
  745. le16_to_cpu(firmware_info->info.usReferenceClock);
  746. p1pll->reference_div = 0;
  747. if (crev < 2)
  748. p1pll->pll_out_min =
  749. le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
  750. else
  751. p1pll->pll_out_min =
  752. le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
  753. p1pll->pll_out_max =
  754. le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
  755. if (p1pll->pll_out_min == 0) {
  756. if (ASIC_IS_AVIVO(rdev))
  757. p1pll->pll_out_min = 64800;
  758. else
  759. p1pll->pll_out_min = 20000;
  760. } else if (p1pll->pll_out_min > 64800) {
  761. /* Limiting the pll output range is a good thing generally as
  762. * it limits the number of possible pll combinations for a given
  763. * frequency presumably to the ones that work best on each card.
  764. * However, certain duallink DVI monitors seem to like
  765. * pll combinations that would be limited by this at least on
  766. * pre-DCE 3.0 r6xx hardware. This might need to be adjusted per
  767. * family.
  768. */
  769. if (!radeon_new_pll)
  770. p1pll->pll_out_min = 64800;
  771. }
  772. p1pll->pll_in_min =
  773. le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
  774. p1pll->pll_in_max =
  775. le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
  776. *p2pll = *p1pll;
  777. /* system clock */
  778. spll->reference_freq =
  779. le16_to_cpu(firmware_info->info.usReferenceClock);
  780. spll->reference_div = 0;
  781. spll->pll_out_min =
  782. le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
  783. spll->pll_out_max =
  784. le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
  785. /* ??? */
  786. if (spll->pll_out_min == 0) {
  787. if (ASIC_IS_AVIVO(rdev))
  788. spll->pll_out_min = 64800;
  789. else
  790. spll->pll_out_min = 20000;
  791. }
  792. spll->pll_in_min =
  793. le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
  794. spll->pll_in_max =
  795. le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
  796. /* memory clock */
  797. mpll->reference_freq =
  798. le16_to_cpu(firmware_info->info.usReferenceClock);
  799. mpll->reference_div = 0;
  800. mpll->pll_out_min =
  801. le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
  802. mpll->pll_out_max =
  803. le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
  804. /* ??? */
  805. if (mpll->pll_out_min == 0) {
  806. if (ASIC_IS_AVIVO(rdev))
  807. mpll->pll_out_min = 64800;
  808. else
  809. mpll->pll_out_min = 20000;
  810. }
  811. mpll->pll_in_min =
  812. le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
  813. mpll->pll_in_max =
  814. le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
  815. rdev->clock.default_sclk =
  816. le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
  817. rdev->clock.default_mclk =
  818. le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
  819. return true;
  820. }
  821. return false;
  822. }
  823. bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
  824. struct radeon_encoder_int_tmds *tmds)
  825. {
  826. struct drm_device *dev = encoder->base.dev;
  827. struct radeon_device *rdev = dev->dev_private;
  828. struct radeon_mode_info *mode_info = &rdev->mode_info;
  829. int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
  830. uint16_t data_offset;
  831. struct _ATOM_TMDS_INFO *tmds_info;
  832. uint8_t frev, crev;
  833. uint16_t maxfreq;
  834. int i;
  835. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
  836. &crev, &data_offset);
  837. tmds_info =
  838. (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
  839. data_offset);
  840. if (tmds_info) {
  841. maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
  842. for (i = 0; i < 4; i++) {
  843. tmds->tmds_pll[i].freq =
  844. le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
  845. tmds->tmds_pll[i].value =
  846. tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
  847. tmds->tmds_pll[i].value |=
  848. (tmds_info->asMiscInfo[i].
  849. ucPLL_VCO_Gain & 0x3f) << 6;
  850. tmds->tmds_pll[i].value |=
  851. (tmds_info->asMiscInfo[i].
  852. ucPLL_DutyCycle & 0xf) << 12;
  853. tmds->tmds_pll[i].value |=
  854. (tmds_info->asMiscInfo[i].
  855. ucPLL_VoltageSwing & 0xf) << 16;
  856. DRM_DEBUG("TMDS PLL From ATOMBIOS %u %x\n",
  857. tmds->tmds_pll[i].freq,
  858. tmds->tmds_pll[i].value);
  859. if (maxfreq == tmds->tmds_pll[i].freq) {
  860. tmds->tmds_pll[i].freq = 0xffffffff;
  861. break;
  862. }
  863. }
  864. return true;
  865. }
  866. return false;
  867. }
  868. static struct radeon_atom_ss *radeon_atombios_get_ss_info(struct
  869. radeon_encoder
  870. *encoder,
  871. int id)
  872. {
  873. struct drm_device *dev = encoder->base.dev;
  874. struct radeon_device *rdev = dev->dev_private;
  875. struct radeon_mode_info *mode_info = &rdev->mode_info;
  876. int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
  877. uint16_t data_offset;
  878. struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
  879. uint8_t frev, crev;
  880. struct radeon_atom_ss *ss = NULL;
  881. int i;
  882. if (id > ATOM_MAX_SS_ENTRY)
  883. return NULL;
  884. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
  885. &crev, &data_offset);
  886. ss_info =
  887. (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
  888. if (ss_info) {
  889. ss =
  890. kzalloc(sizeof(struct radeon_atom_ss), GFP_KERNEL);
  891. if (!ss)
  892. return NULL;
  893. for (i = 0; i < ATOM_MAX_SS_ENTRY; i++) {
  894. if (ss_info->asSS_Info[i].ucSS_Id == id) {
  895. ss->percentage =
  896. le16_to_cpu(ss_info->asSS_Info[i].usSpreadSpectrumPercentage);
  897. ss->type = ss_info->asSS_Info[i].ucSpreadSpectrumType;
  898. ss->step = ss_info->asSS_Info[i].ucSS_Step;
  899. ss->delay = ss_info->asSS_Info[i].ucSS_Delay;
  900. ss->range = ss_info->asSS_Info[i].ucSS_Range;
  901. ss->refdiv = ss_info->asSS_Info[i].ucRecommendedRef_Div;
  902. break;
  903. }
  904. }
  905. }
  906. return ss;
  907. }
  908. union lvds_info {
  909. struct _ATOM_LVDS_INFO info;
  910. struct _ATOM_LVDS_INFO_V12 info_12;
  911. };
  912. struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
  913. radeon_encoder
  914. *encoder)
  915. {
  916. struct drm_device *dev = encoder->base.dev;
  917. struct radeon_device *rdev = dev->dev_private;
  918. struct radeon_mode_info *mode_info = &rdev->mode_info;
  919. int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
  920. uint16_t data_offset, misc;
  921. union lvds_info *lvds_info;
  922. uint8_t frev, crev;
  923. struct radeon_encoder_atom_dig *lvds = NULL;
  924. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
  925. &crev, &data_offset);
  926. lvds_info =
  927. (union lvds_info *)(mode_info->atom_context->bios + data_offset);
  928. if (lvds_info) {
  929. lvds =
  930. kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
  931. if (!lvds)
  932. return NULL;
  933. lvds->native_mode.clock =
  934. le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
  935. lvds->native_mode.hdisplay =
  936. le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
  937. lvds->native_mode.vdisplay =
  938. le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
  939. lvds->native_mode.htotal = lvds->native_mode.hdisplay +
  940. le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
  941. lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
  942. le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
  943. lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
  944. le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
  945. lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
  946. le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
  947. lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
  948. le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
  949. lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
  950. le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
  951. lvds->panel_pwr_delay =
  952. le16_to_cpu(lvds_info->info.usOffDelayInMs);
  953. lvds->lvds_misc = lvds_info->info.ucLVDS_Misc;
  954. misc = le16_to_cpu(lvds_info->info.sLCDTiming.susModeMiscInfo.usAccess);
  955. if (misc & ATOM_VSYNC_POLARITY)
  956. lvds->native_mode.flags |= DRM_MODE_FLAG_NVSYNC;
  957. if (misc & ATOM_HSYNC_POLARITY)
  958. lvds->native_mode.flags |= DRM_MODE_FLAG_NHSYNC;
  959. if (misc & ATOM_COMPOSITESYNC)
  960. lvds->native_mode.flags |= DRM_MODE_FLAG_CSYNC;
  961. if (misc & ATOM_INTERLACE)
  962. lvds->native_mode.flags |= DRM_MODE_FLAG_INTERLACE;
  963. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  964. lvds->native_mode.flags |= DRM_MODE_FLAG_DBLSCAN;
  965. /* set crtc values */
  966. drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
  967. lvds->ss = radeon_atombios_get_ss_info(encoder, lvds_info->info.ucSS_Id);
  968. encoder->native_mode = lvds->native_mode;
  969. }
  970. return lvds;
  971. }
  972. struct radeon_encoder_primary_dac *
  973. radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
  974. {
  975. struct drm_device *dev = encoder->base.dev;
  976. struct radeon_device *rdev = dev->dev_private;
  977. struct radeon_mode_info *mode_info = &rdev->mode_info;
  978. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  979. uint16_t data_offset;
  980. struct _COMPASSIONATE_DATA *dac_info;
  981. uint8_t frev, crev;
  982. uint8_t bg, dac;
  983. struct radeon_encoder_primary_dac *p_dac = NULL;
  984. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev, &crev, &data_offset);
  985. dac_info = (struct _COMPASSIONATE_DATA *)(mode_info->atom_context->bios + data_offset);
  986. if (dac_info) {
  987. p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
  988. if (!p_dac)
  989. return NULL;
  990. bg = dac_info->ucDAC1_BG_Adjustment;
  991. dac = dac_info->ucDAC1_DAC_Adjustment;
  992. p_dac->ps2_pdac_adj = (bg << 8) | (dac);
  993. }
  994. return p_dac;
  995. }
  996. bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
  997. struct drm_display_mode *mode)
  998. {
  999. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1000. ATOM_ANALOG_TV_INFO *tv_info;
  1001. ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
  1002. ATOM_DTD_FORMAT *dtd_timings;
  1003. int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
  1004. u8 frev, crev;
  1005. u16 data_offset, misc;
  1006. atom_parse_data_header(mode_info->atom_context, data_index, NULL, &frev, &crev, &data_offset);
  1007. switch (crev) {
  1008. case 1:
  1009. tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
  1010. if (index > MAX_SUPPORTED_TV_TIMING)
  1011. return false;
  1012. mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
  1013. mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
  1014. mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
  1015. mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
  1016. le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
  1017. mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
  1018. mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
  1019. mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
  1020. mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
  1021. le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
  1022. mode->flags = 0;
  1023. misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
  1024. if (misc & ATOM_VSYNC_POLARITY)
  1025. mode->flags |= DRM_MODE_FLAG_NVSYNC;
  1026. if (misc & ATOM_HSYNC_POLARITY)
  1027. mode->flags |= DRM_MODE_FLAG_NHSYNC;
  1028. if (misc & ATOM_COMPOSITESYNC)
  1029. mode->flags |= DRM_MODE_FLAG_CSYNC;
  1030. if (misc & ATOM_INTERLACE)
  1031. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  1032. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  1033. mode->flags |= DRM_MODE_FLAG_DBLSCAN;
  1034. mode->clock = le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
  1035. if (index == 1) {
  1036. /* PAL timings appear to have wrong values for totals */
  1037. mode->crtc_htotal -= 1;
  1038. mode->crtc_vtotal -= 1;
  1039. }
  1040. break;
  1041. case 2:
  1042. tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
  1043. if (index > MAX_SUPPORTED_TV_TIMING_V1_2)
  1044. return false;
  1045. dtd_timings = &tv_info_v1_2->aModeTimings[index];
  1046. mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
  1047. le16_to_cpu(dtd_timings->usHBlanking_Time);
  1048. mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
  1049. mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
  1050. le16_to_cpu(dtd_timings->usHSyncOffset);
  1051. mode->crtc_hsync_end = mode->crtc_hsync_start +
  1052. le16_to_cpu(dtd_timings->usHSyncWidth);
  1053. mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
  1054. le16_to_cpu(dtd_timings->usVBlanking_Time);
  1055. mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
  1056. mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
  1057. le16_to_cpu(dtd_timings->usVSyncOffset);
  1058. mode->crtc_vsync_end = mode->crtc_vsync_start +
  1059. le16_to_cpu(dtd_timings->usVSyncWidth);
  1060. mode->flags = 0;
  1061. misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
  1062. if (misc & ATOM_VSYNC_POLARITY)
  1063. mode->flags |= DRM_MODE_FLAG_NVSYNC;
  1064. if (misc & ATOM_HSYNC_POLARITY)
  1065. mode->flags |= DRM_MODE_FLAG_NHSYNC;
  1066. if (misc & ATOM_COMPOSITESYNC)
  1067. mode->flags |= DRM_MODE_FLAG_CSYNC;
  1068. if (misc & ATOM_INTERLACE)
  1069. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  1070. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  1071. mode->flags |= DRM_MODE_FLAG_DBLSCAN;
  1072. mode->clock = le16_to_cpu(dtd_timings->usPixClk) * 10;
  1073. break;
  1074. }
  1075. return true;
  1076. }
  1077. enum radeon_tv_std
  1078. radeon_atombios_get_tv_info(struct radeon_device *rdev)
  1079. {
  1080. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1081. int index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
  1082. uint16_t data_offset;
  1083. uint8_t frev, crev;
  1084. struct _ATOM_ANALOG_TV_INFO *tv_info;
  1085. enum radeon_tv_std tv_std = TV_STD_NTSC;
  1086. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev, &crev, &data_offset);
  1087. tv_info = (struct _ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
  1088. switch (tv_info->ucTV_BootUpDefaultStandard) {
  1089. case ATOM_TV_NTSC:
  1090. tv_std = TV_STD_NTSC;
  1091. DRM_INFO("Default TV standard: NTSC\n");
  1092. break;
  1093. case ATOM_TV_NTSCJ:
  1094. tv_std = TV_STD_NTSC_J;
  1095. DRM_INFO("Default TV standard: NTSC-J\n");
  1096. break;
  1097. case ATOM_TV_PAL:
  1098. tv_std = TV_STD_PAL;
  1099. DRM_INFO("Default TV standard: PAL\n");
  1100. break;
  1101. case ATOM_TV_PALM:
  1102. tv_std = TV_STD_PAL_M;
  1103. DRM_INFO("Default TV standard: PAL-M\n");
  1104. break;
  1105. case ATOM_TV_PALN:
  1106. tv_std = TV_STD_PAL_N;
  1107. DRM_INFO("Default TV standard: PAL-N\n");
  1108. break;
  1109. case ATOM_TV_PALCN:
  1110. tv_std = TV_STD_PAL_CN;
  1111. DRM_INFO("Default TV standard: PAL-CN\n");
  1112. break;
  1113. case ATOM_TV_PAL60:
  1114. tv_std = TV_STD_PAL_60;
  1115. DRM_INFO("Default TV standard: PAL-60\n");
  1116. break;
  1117. case ATOM_TV_SECAM:
  1118. tv_std = TV_STD_SECAM;
  1119. DRM_INFO("Default TV standard: SECAM\n");
  1120. break;
  1121. default:
  1122. tv_std = TV_STD_NTSC;
  1123. DRM_INFO("Unknown TV standard; defaulting to NTSC\n");
  1124. break;
  1125. }
  1126. return tv_std;
  1127. }
  1128. struct radeon_encoder_tv_dac *
  1129. radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
  1130. {
  1131. struct drm_device *dev = encoder->base.dev;
  1132. struct radeon_device *rdev = dev->dev_private;
  1133. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1134. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  1135. uint16_t data_offset;
  1136. struct _COMPASSIONATE_DATA *dac_info;
  1137. uint8_t frev, crev;
  1138. uint8_t bg, dac;
  1139. struct radeon_encoder_tv_dac *tv_dac = NULL;
  1140. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev, &crev, &data_offset);
  1141. dac_info = (struct _COMPASSIONATE_DATA *)(mode_info->atom_context->bios + data_offset);
  1142. if (dac_info) {
  1143. tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
  1144. if (!tv_dac)
  1145. return NULL;
  1146. bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
  1147. dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
  1148. tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
  1149. bg = dac_info->ucDAC2_PAL_BG_Adjustment;
  1150. dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
  1151. tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
  1152. bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
  1153. dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
  1154. tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
  1155. tv_dac->tv_std = radeon_atombios_get_tv_info(rdev);
  1156. }
  1157. return tv_dac;
  1158. }
  1159. void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
  1160. {
  1161. DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
  1162. int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
  1163. args.ucEnable = enable;
  1164. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1165. }
  1166. void radeon_atom_static_pwrmgt_setup(struct radeon_device *rdev, int enable)
  1167. {
  1168. ENABLE_ASIC_STATIC_PWR_MGT_PS_ALLOCATION args;
  1169. int index = GetIndexIntoMasterTable(COMMAND, EnableASIC_StaticPwrMgt);
  1170. args.ucEnable = enable;
  1171. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1172. }
  1173. uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
  1174. {
  1175. GET_ENGINE_CLOCK_PS_ALLOCATION args;
  1176. int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
  1177. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1178. return args.ulReturnEngineClock;
  1179. }
  1180. uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
  1181. {
  1182. GET_MEMORY_CLOCK_PS_ALLOCATION args;
  1183. int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
  1184. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1185. return args.ulReturnMemoryClock;
  1186. }
  1187. void radeon_atom_set_engine_clock(struct radeon_device *rdev,
  1188. uint32_t eng_clock)
  1189. {
  1190. SET_ENGINE_CLOCK_PS_ALLOCATION args;
  1191. int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
  1192. args.ulTargetEngineClock = eng_clock; /* 10 khz */
  1193. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1194. }
  1195. void radeon_atom_set_memory_clock(struct radeon_device *rdev,
  1196. uint32_t mem_clock)
  1197. {
  1198. SET_MEMORY_CLOCK_PS_ALLOCATION args;
  1199. int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
  1200. if (rdev->flags & RADEON_IS_IGP)
  1201. return;
  1202. args.ulTargetMemoryClock = mem_clock; /* 10 khz */
  1203. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1204. }
  1205. void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
  1206. {
  1207. struct radeon_device *rdev = dev->dev_private;
  1208. uint32_t bios_2_scratch, bios_6_scratch;
  1209. if (rdev->family >= CHIP_R600) {
  1210. bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
  1211. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  1212. } else {
  1213. bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
  1214. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  1215. }
  1216. /* let the bios control the backlight */
  1217. bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
  1218. /* tell the bios not to handle mode switching */
  1219. bios_6_scratch |= (ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH | ATOM_S6_ACC_MODE);
  1220. if (rdev->family >= CHIP_R600) {
  1221. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  1222. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  1223. } else {
  1224. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  1225. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  1226. }
  1227. }
  1228. void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
  1229. {
  1230. uint32_t scratch_reg;
  1231. int i;
  1232. if (rdev->family >= CHIP_R600)
  1233. scratch_reg = R600_BIOS_0_SCRATCH;
  1234. else
  1235. scratch_reg = RADEON_BIOS_0_SCRATCH;
  1236. for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
  1237. rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
  1238. }
  1239. void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
  1240. {
  1241. uint32_t scratch_reg;
  1242. int i;
  1243. if (rdev->family >= CHIP_R600)
  1244. scratch_reg = R600_BIOS_0_SCRATCH;
  1245. else
  1246. scratch_reg = RADEON_BIOS_0_SCRATCH;
  1247. for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
  1248. WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
  1249. }
  1250. void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
  1251. {
  1252. struct drm_device *dev = encoder->dev;
  1253. struct radeon_device *rdev = dev->dev_private;
  1254. uint32_t bios_6_scratch;
  1255. if (rdev->family >= CHIP_R600)
  1256. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  1257. else
  1258. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  1259. if (lock)
  1260. bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
  1261. else
  1262. bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
  1263. if (rdev->family >= CHIP_R600)
  1264. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  1265. else
  1266. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  1267. }
  1268. /* at some point we may want to break this out into individual functions */
  1269. void
  1270. radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
  1271. struct drm_encoder *encoder,
  1272. bool connected)
  1273. {
  1274. struct drm_device *dev = connector->dev;
  1275. struct radeon_device *rdev = dev->dev_private;
  1276. struct radeon_connector *radeon_connector =
  1277. to_radeon_connector(connector);
  1278. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1279. uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
  1280. if (rdev->family >= CHIP_R600) {
  1281. bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
  1282. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  1283. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  1284. } else {
  1285. bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
  1286. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  1287. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  1288. }
  1289. if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
  1290. (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
  1291. if (connected) {
  1292. DRM_DEBUG("TV1 connected\n");
  1293. bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
  1294. bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
  1295. } else {
  1296. DRM_DEBUG("TV1 disconnected\n");
  1297. bios_0_scratch &= ~ATOM_S0_TV1_MASK;
  1298. bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
  1299. bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
  1300. }
  1301. }
  1302. if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
  1303. (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
  1304. if (connected) {
  1305. DRM_DEBUG("CV connected\n");
  1306. bios_3_scratch |= ATOM_S3_CV_ACTIVE;
  1307. bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
  1308. } else {
  1309. DRM_DEBUG("CV disconnected\n");
  1310. bios_0_scratch &= ~ATOM_S0_CV_MASK;
  1311. bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
  1312. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
  1313. }
  1314. }
  1315. if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
  1316. (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
  1317. if (connected) {
  1318. DRM_DEBUG("LCD1 connected\n");
  1319. bios_0_scratch |= ATOM_S0_LCD1;
  1320. bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
  1321. bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
  1322. } else {
  1323. DRM_DEBUG("LCD1 disconnected\n");
  1324. bios_0_scratch &= ~ATOM_S0_LCD1;
  1325. bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
  1326. bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
  1327. }
  1328. }
  1329. if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
  1330. (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
  1331. if (connected) {
  1332. DRM_DEBUG("CRT1 connected\n");
  1333. bios_0_scratch |= ATOM_S0_CRT1_COLOR;
  1334. bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
  1335. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
  1336. } else {
  1337. DRM_DEBUG("CRT1 disconnected\n");
  1338. bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
  1339. bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
  1340. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
  1341. }
  1342. }
  1343. if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
  1344. (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
  1345. if (connected) {
  1346. DRM_DEBUG("CRT2 connected\n");
  1347. bios_0_scratch |= ATOM_S0_CRT2_COLOR;
  1348. bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
  1349. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
  1350. } else {
  1351. DRM_DEBUG("CRT2 disconnected\n");
  1352. bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
  1353. bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
  1354. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
  1355. }
  1356. }
  1357. if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
  1358. (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
  1359. if (connected) {
  1360. DRM_DEBUG("DFP1 connected\n");
  1361. bios_0_scratch |= ATOM_S0_DFP1;
  1362. bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
  1363. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
  1364. } else {
  1365. DRM_DEBUG("DFP1 disconnected\n");
  1366. bios_0_scratch &= ~ATOM_S0_DFP1;
  1367. bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
  1368. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
  1369. }
  1370. }
  1371. if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
  1372. (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  1373. if (connected) {
  1374. DRM_DEBUG("DFP2 connected\n");
  1375. bios_0_scratch |= ATOM_S0_DFP2;
  1376. bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
  1377. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
  1378. } else {
  1379. DRM_DEBUG("DFP2 disconnected\n");
  1380. bios_0_scratch &= ~ATOM_S0_DFP2;
  1381. bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
  1382. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
  1383. }
  1384. }
  1385. if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
  1386. (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
  1387. if (connected) {
  1388. DRM_DEBUG("DFP3 connected\n");
  1389. bios_0_scratch |= ATOM_S0_DFP3;
  1390. bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
  1391. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
  1392. } else {
  1393. DRM_DEBUG("DFP3 disconnected\n");
  1394. bios_0_scratch &= ~ATOM_S0_DFP3;
  1395. bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
  1396. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
  1397. }
  1398. }
  1399. if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
  1400. (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
  1401. if (connected) {
  1402. DRM_DEBUG("DFP4 connected\n");
  1403. bios_0_scratch |= ATOM_S0_DFP4;
  1404. bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
  1405. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
  1406. } else {
  1407. DRM_DEBUG("DFP4 disconnected\n");
  1408. bios_0_scratch &= ~ATOM_S0_DFP4;
  1409. bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
  1410. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
  1411. }
  1412. }
  1413. if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
  1414. (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
  1415. if (connected) {
  1416. DRM_DEBUG("DFP5 connected\n");
  1417. bios_0_scratch |= ATOM_S0_DFP5;
  1418. bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
  1419. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
  1420. } else {
  1421. DRM_DEBUG("DFP5 disconnected\n");
  1422. bios_0_scratch &= ~ATOM_S0_DFP5;
  1423. bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
  1424. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
  1425. }
  1426. }
  1427. if (rdev->family >= CHIP_R600) {
  1428. WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
  1429. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  1430. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  1431. } else {
  1432. WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
  1433. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  1434. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  1435. }
  1436. }
  1437. void
  1438. radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
  1439. {
  1440. struct drm_device *dev = encoder->dev;
  1441. struct radeon_device *rdev = dev->dev_private;
  1442. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1443. uint32_t bios_3_scratch;
  1444. if (rdev->family >= CHIP_R600)
  1445. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  1446. else
  1447. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  1448. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  1449. bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
  1450. bios_3_scratch |= (crtc << 18);
  1451. }
  1452. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  1453. bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
  1454. bios_3_scratch |= (crtc << 24);
  1455. }
  1456. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  1457. bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
  1458. bios_3_scratch |= (crtc << 16);
  1459. }
  1460. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  1461. bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
  1462. bios_3_scratch |= (crtc << 20);
  1463. }
  1464. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  1465. bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
  1466. bios_3_scratch |= (crtc << 17);
  1467. }
  1468. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  1469. bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
  1470. bios_3_scratch |= (crtc << 19);
  1471. }
  1472. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  1473. bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
  1474. bios_3_scratch |= (crtc << 23);
  1475. }
  1476. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  1477. bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
  1478. bios_3_scratch |= (crtc << 25);
  1479. }
  1480. if (rdev->family >= CHIP_R600)
  1481. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  1482. else
  1483. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  1484. }
  1485. void
  1486. radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
  1487. {
  1488. struct drm_device *dev = encoder->dev;
  1489. struct radeon_device *rdev = dev->dev_private;
  1490. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1491. uint32_t bios_2_scratch;
  1492. if (rdev->family >= CHIP_R600)
  1493. bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
  1494. else
  1495. bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
  1496. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  1497. if (on)
  1498. bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
  1499. else
  1500. bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
  1501. }
  1502. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  1503. if (on)
  1504. bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
  1505. else
  1506. bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
  1507. }
  1508. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  1509. if (on)
  1510. bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
  1511. else
  1512. bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
  1513. }
  1514. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  1515. if (on)
  1516. bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
  1517. else
  1518. bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
  1519. }
  1520. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  1521. if (on)
  1522. bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
  1523. else
  1524. bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
  1525. }
  1526. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  1527. if (on)
  1528. bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
  1529. else
  1530. bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
  1531. }
  1532. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  1533. if (on)
  1534. bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
  1535. else
  1536. bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
  1537. }
  1538. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  1539. if (on)
  1540. bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
  1541. else
  1542. bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
  1543. }
  1544. if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
  1545. if (on)
  1546. bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
  1547. else
  1548. bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
  1549. }
  1550. if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
  1551. if (on)
  1552. bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
  1553. else
  1554. bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
  1555. }
  1556. if (rdev->family >= CHIP_R600)
  1557. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  1558. else
  1559. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  1560. }