radeon_connectors.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  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 "drm_edid.h"
  28. #include "drm_crtc_helper.h"
  29. #include "radeon_drm.h"
  30. #include "radeon.h"
  31. extern void
  32. radeon_combios_connected_scratch_regs(struct drm_connector *connector,
  33. struct drm_encoder *encoder,
  34. bool connected);
  35. extern void
  36. radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
  37. struct drm_encoder *encoder,
  38. bool connected);
  39. static void
  40. radeon_connector_update_scratch_regs(struct drm_connector *connector, enum drm_connector_status status)
  41. {
  42. struct drm_device *dev = connector->dev;
  43. struct radeon_device *rdev = dev->dev_private;
  44. struct drm_encoder *best_encoder = NULL;
  45. struct drm_encoder *encoder = NULL;
  46. struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
  47. struct drm_mode_object *obj;
  48. bool connected;
  49. int i;
  50. best_encoder = connector_funcs->best_encoder(connector);
  51. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  52. if (connector->encoder_ids[i] == 0)
  53. break;
  54. obj = drm_mode_object_find(connector->dev,
  55. connector->encoder_ids[i],
  56. DRM_MODE_OBJECT_ENCODER);
  57. if (!obj)
  58. continue;
  59. encoder = obj_to_encoder(obj);
  60. if ((encoder == best_encoder) && (status == connector_status_connected))
  61. connected = true;
  62. else
  63. connected = false;
  64. if (rdev->is_atom_bios)
  65. radeon_atombios_connected_scratch_regs(connector, encoder, connected);
  66. else
  67. radeon_combios_connected_scratch_regs(connector, encoder, connected);
  68. }
  69. }
  70. struct drm_encoder *radeon_best_single_encoder(struct drm_connector *connector)
  71. {
  72. int enc_id = connector->encoder_ids[0];
  73. struct drm_mode_object *obj;
  74. struct drm_encoder *encoder;
  75. /* pick the encoder ids */
  76. if (enc_id) {
  77. obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
  78. if (!obj)
  79. return NULL;
  80. encoder = obj_to_encoder(obj);
  81. return encoder;
  82. }
  83. return NULL;
  84. }
  85. /*
  86. * radeon_connector_analog_encoder_conflict_solve
  87. * - search for other connectors sharing this encoder
  88. * if priority is true, then set them disconnected if this is connected
  89. * if priority is false, set us disconnected if they are connected
  90. */
  91. static enum drm_connector_status
  92. radeon_connector_analog_encoder_conflict_solve(struct drm_connector *connector,
  93. struct drm_encoder *encoder,
  94. enum drm_connector_status current_status,
  95. bool priority)
  96. {
  97. struct drm_device *dev = connector->dev;
  98. struct drm_connector *conflict;
  99. int i;
  100. list_for_each_entry(conflict, &dev->mode_config.connector_list, head) {
  101. if (conflict == connector)
  102. continue;
  103. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  104. if (conflict->encoder_ids[i] == 0)
  105. break;
  106. /* if the IDs match */
  107. if (conflict->encoder_ids[i] == encoder->base.id) {
  108. if (conflict->status != connector_status_connected)
  109. continue;
  110. if (priority == true) {
  111. DRM_INFO("1: conflicting encoders switching off %s\n", drm_get_connector_name(conflict));
  112. DRM_INFO("in favor of %s\n", drm_get_connector_name(connector));
  113. conflict->status = connector_status_disconnected;
  114. radeon_connector_update_scratch_regs(conflict, connector_status_disconnected);
  115. } else {
  116. DRM_INFO("2: conflicting encoders switching off %s\n", drm_get_connector_name(connector));
  117. DRM_INFO("in favor of %s\n", drm_get_connector_name(conflict));
  118. current_status = connector_status_disconnected;
  119. }
  120. break;
  121. }
  122. }
  123. }
  124. return current_status;
  125. }
  126. static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encoder)
  127. {
  128. struct drm_device *dev = encoder->dev;
  129. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  130. struct drm_display_mode *mode = NULL;
  131. struct radeon_native_mode *native_mode = &radeon_encoder->native_mode;
  132. if (native_mode->panel_xres != 0 &&
  133. native_mode->panel_yres != 0 &&
  134. native_mode->dotclock != 0) {
  135. mode = drm_mode_create(dev);
  136. mode->hdisplay = native_mode->panel_xres;
  137. mode->vdisplay = native_mode->panel_yres;
  138. mode->htotal = mode->hdisplay + native_mode->hblank;
  139. mode->hsync_start = mode->hdisplay + native_mode->hoverplus;
  140. mode->hsync_end = mode->hsync_start + native_mode->hsync_width;
  141. mode->vtotal = mode->vdisplay + native_mode->vblank;
  142. mode->vsync_start = mode->vdisplay + native_mode->voverplus;
  143. mode->vsync_end = mode->vsync_start + native_mode->vsync_width;
  144. mode->clock = native_mode->dotclock;
  145. mode->flags = 0;
  146. mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
  147. drm_mode_set_name(mode);
  148. DRM_DEBUG("Adding native panel mode %s\n", mode->name);
  149. }
  150. return mode;
  151. }
  152. int radeon_connector_set_property(struct drm_connector *connector, struct drm_property *property,
  153. uint64_t val)
  154. {
  155. return 0;
  156. }
  157. static int radeon_lvds_get_modes(struct drm_connector *connector)
  158. {
  159. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  160. struct drm_encoder *encoder;
  161. int ret = 0;
  162. struct drm_display_mode *mode;
  163. if (radeon_connector->ddc_bus) {
  164. ret = radeon_ddc_get_modes(radeon_connector);
  165. if (ret > 0) {
  166. return ret;
  167. }
  168. }
  169. encoder = radeon_best_single_encoder(connector);
  170. if (!encoder)
  171. return 0;
  172. /* we have no EDID modes */
  173. mode = radeon_fp_native_mode(encoder);
  174. if (mode) {
  175. ret = 1;
  176. drm_mode_probed_add(connector, mode);
  177. }
  178. return ret;
  179. }
  180. static int radeon_lvds_mode_valid(struct drm_connector *connector,
  181. struct drm_display_mode *mode)
  182. {
  183. return MODE_OK;
  184. }
  185. static enum drm_connector_status radeon_lvds_detect(struct drm_connector *connector)
  186. {
  187. enum drm_connector_status ret = connector_status_connected;
  188. /* check acpi lid status ??? */
  189. radeon_connector_update_scratch_regs(connector, ret);
  190. return ret;
  191. }
  192. static void radeon_connector_destroy(struct drm_connector *connector)
  193. {
  194. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  195. if (radeon_connector->ddc_bus)
  196. radeon_i2c_destroy(radeon_connector->ddc_bus);
  197. kfree(radeon_connector->con_priv);
  198. drm_sysfs_connector_remove(connector);
  199. drm_connector_cleanup(connector);
  200. kfree(connector);
  201. }
  202. struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs = {
  203. .get_modes = radeon_lvds_get_modes,
  204. .mode_valid = radeon_lvds_mode_valid,
  205. .best_encoder = radeon_best_single_encoder,
  206. };
  207. struct drm_connector_funcs radeon_lvds_connector_funcs = {
  208. .dpms = drm_helper_connector_dpms,
  209. .detect = radeon_lvds_detect,
  210. .fill_modes = drm_helper_probe_single_connector_modes,
  211. .destroy = radeon_connector_destroy,
  212. .set_property = radeon_connector_set_property,
  213. };
  214. static int radeon_vga_get_modes(struct drm_connector *connector)
  215. {
  216. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  217. int ret;
  218. ret = radeon_ddc_get_modes(radeon_connector);
  219. return ret;
  220. }
  221. static int radeon_vga_mode_valid(struct drm_connector *connector,
  222. struct drm_display_mode *mode)
  223. {
  224. return MODE_OK;
  225. }
  226. static enum drm_connector_status radeon_vga_detect(struct drm_connector *connector)
  227. {
  228. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  229. struct drm_encoder *encoder;
  230. struct drm_encoder_helper_funcs *encoder_funcs;
  231. bool dret;
  232. enum drm_connector_status ret = connector_status_disconnected;
  233. encoder = radeon_best_single_encoder(connector);
  234. if (!encoder)
  235. ret = connector_status_disconnected;
  236. radeon_i2c_do_lock(radeon_connector, 1);
  237. dret = radeon_ddc_probe(radeon_connector);
  238. radeon_i2c_do_lock(radeon_connector, 0);
  239. if (dret)
  240. ret = connector_status_connected;
  241. else {
  242. encoder_funcs = encoder->helper_private;
  243. ret = encoder_funcs->detect(encoder, connector);
  244. }
  245. if (ret == connector_status_connected)
  246. ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
  247. radeon_connector_update_scratch_regs(connector, ret);
  248. return ret;
  249. }
  250. struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs = {
  251. .get_modes = radeon_vga_get_modes,
  252. .mode_valid = radeon_vga_mode_valid,
  253. .best_encoder = radeon_best_single_encoder,
  254. };
  255. struct drm_connector_funcs radeon_vga_connector_funcs = {
  256. .dpms = drm_helper_connector_dpms,
  257. .detect = radeon_vga_detect,
  258. .fill_modes = drm_helper_probe_single_connector_modes,
  259. .destroy = radeon_connector_destroy,
  260. .set_property = radeon_connector_set_property,
  261. };
  262. static struct drm_display_mode tv_fixed_mode = {
  263. DRM_MODE("800x600", DRM_MODE_TYPE_DEFAULT, 38250, 800, 832,
  264. 912, 1024, 0, 600, 603, 607, 624, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC),
  265. };
  266. static int radeon_tv_get_modes(struct drm_connector *connector)
  267. {
  268. struct drm_device *dev = connector->dev;
  269. struct drm_display_mode *tv_mode;
  270. tv_mode = drm_mode_duplicate(dev, &tv_fixed_mode);
  271. tv_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
  272. drm_mode_probed_add(connector, tv_mode);
  273. return 1;
  274. }
  275. static int radeon_tv_mode_valid(struct drm_connector *connector,
  276. struct drm_display_mode *mode)
  277. {
  278. return MODE_OK;
  279. }
  280. static enum drm_connector_status radeon_tv_detect(struct drm_connector *connector)
  281. {
  282. struct drm_encoder *encoder;
  283. struct drm_encoder_helper_funcs *encoder_funcs;
  284. int ret;
  285. encoder = radeon_best_single_encoder(connector);
  286. if (!encoder)
  287. ret = connector_status_disconnected;
  288. else {
  289. encoder_funcs = encoder->helper_private;
  290. ret = encoder_funcs->detect(encoder, connector);
  291. }
  292. if (ret == connector_status_connected)
  293. ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false);
  294. radeon_connector_update_scratch_regs(connector, ret);
  295. return ret;
  296. }
  297. struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs = {
  298. .get_modes = radeon_tv_get_modes,
  299. .mode_valid = radeon_tv_mode_valid,
  300. .best_encoder = radeon_best_single_encoder,
  301. };
  302. struct drm_connector_funcs radeon_tv_connector_funcs = {
  303. .dpms = drm_helper_connector_dpms,
  304. .detect = radeon_tv_detect,
  305. .fill_modes = drm_helper_probe_single_connector_modes,
  306. .destroy = radeon_connector_destroy,
  307. .set_property = radeon_connector_set_property,
  308. };
  309. static int radeon_dvi_get_modes(struct drm_connector *connector)
  310. {
  311. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  312. int ret;
  313. ret = radeon_ddc_get_modes(radeon_connector);
  314. return ret;
  315. }
  316. /*
  317. * DVI is complicated
  318. * Do a DDC probe, if DDC probe passes, get the full EDID so
  319. * we can do analog/digital monitor detection at this point.
  320. * If the monitor is an analog monitor or we got no DDC,
  321. * we need to find the DAC encoder object for this connector.
  322. * If we got no DDC, we do load detection on the DAC encoder object.
  323. * If we got analog DDC or load detection passes on the DAC encoder
  324. * we have to check if this analog encoder is shared with anyone else (TV)
  325. * if its shared we have to set the other connector to disconnected.
  326. */
  327. static enum drm_connector_status radeon_dvi_detect(struct drm_connector *connector)
  328. {
  329. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  330. struct drm_encoder *encoder = NULL;
  331. struct drm_encoder_helper_funcs *encoder_funcs;
  332. struct drm_mode_object *obj;
  333. int i;
  334. enum drm_connector_status ret = connector_status_disconnected;
  335. bool dret;
  336. radeon_i2c_do_lock(radeon_connector, 1);
  337. dret = radeon_ddc_probe(radeon_connector);
  338. radeon_i2c_do_lock(radeon_connector, 0);
  339. if (dret) {
  340. radeon_i2c_do_lock(radeon_connector, 1);
  341. radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
  342. radeon_i2c_do_lock(radeon_connector, 0);
  343. if (!radeon_connector->edid) {
  344. DRM_ERROR("DDC responded but not EDID found for %s\n",
  345. drm_get_connector_name(connector));
  346. } else {
  347. radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
  348. /* if this isn't a digital monitor
  349. then we need to make sure we don't have any
  350. TV conflicts */
  351. ret = connector_status_connected;
  352. }
  353. }
  354. if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
  355. goto out;
  356. /* find analog encoder */
  357. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  358. if (connector->encoder_ids[i] == 0)
  359. break;
  360. obj = drm_mode_object_find(connector->dev,
  361. connector->encoder_ids[i],
  362. DRM_MODE_OBJECT_ENCODER);
  363. if (!obj)
  364. continue;
  365. encoder = obj_to_encoder(obj);
  366. encoder_funcs = encoder->helper_private;
  367. if (encoder_funcs->detect) {
  368. if (ret != connector_status_connected) {
  369. ret = encoder_funcs->detect(encoder, connector);
  370. if (ret == connector_status_connected) {
  371. radeon_connector->use_digital = false;
  372. }
  373. }
  374. break;
  375. }
  376. }
  377. if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) &&
  378. encoder) {
  379. ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
  380. }
  381. out:
  382. /* updated in get modes as well since we need to know if it's analog or digital */
  383. radeon_connector_update_scratch_regs(connector, ret);
  384. return ret;
  385. }
  386. /* okay need to be smart in here about which encoder to pick */
  387. struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)
  388. {
  389. int enc_id = connector->encoder_ids[0];
  390. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  391. struct drm_mode_object *obj;
  392. struct drm_encoder *encoder;
  393. int i;
  394. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  395. if (connector->encoder_ids[i] == 0)
  396. break;
  397. obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
  398. if (!obj)
  399. continue;
  400. encoder = obj_to_encoder(obj);
  401. if (radeon_connector->use_digital == true) {
  402. if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
  403. return encoder;
  404. } else {
  405. if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
  406. encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
  407. return encoder;
  408. }
  409. }
  410. /* see if we have a default encoder TODO */
  411. /* then check use digitial */
  412. /* pick the first one */
  413. if (enc_id) {
  414. obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
  415. if (!obj)
  416. return NULL;
  417. encoder = obj_to_encoder(obj);
  418. return encoder;
  419. }
  420. return NULL;
  421. }
  422. struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs = {
  423. .get_modes = radeon_dvi_get_modes,
  424. .mode_valid = radeon_vga_mode_valid,
  425. .best_encoder = radeon_dvi_encoder,
  426. };
  427. struct drm_connector_funcs radeon_dvi_connector_funcs = {
  428. .dpms = drm_helper_connector_dpms,
  429. .detect = radeon_dvi_detect,
  430. .fill_modes = drm_helper_probe_single_connector_modes,
  431. .set_property = radeon_connector_set_property,
  432. .destroy = radeon_connector_destroy,
  433. };
  434. void
  435. radeon_add_atom_connector(struct drm_device *dev,
  436. uint32_t connector_id,
  437. uint32_t supported_device,
  438. int connector_type,
  439. struct radeon_i2c_bus_rec *i2c_bus,
  440. bool linkb,
  441. uint32_t igp_lane_info)
  442. {
  443. struct drm_connector *connector;
  444. struct radeon_connector *radeon_connector;
  445. struct radeon_connector_atom_dig *radeon_dig_connector;
  446. uint32_t subpixel_order = SubPixelNone;
  447. /* fixme - tv/cv/din */
  448. if (connector_type == DRM_MODE_CONNECTOR_Unknown)
  449. return;
  450. /* see if we already added it */
  451. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  452. radeon_connector = to_radeon_connector(connector);
  453. if (radeon_connector->connector_id == connector_id) {
  454. radeon_connector->devices |= supported_device;
  455. return;
  456. }
  457. }
  458. radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
  459. if (!radeon_connector)
  460. return;
  461. connector = &radeon_connector->base;
  462. radeon_connector->connector_id = connector_id;
  463. radeon_connector->devices = supported_device;
  464. switch (connector_type) {
  465. case DRM_MODE_CONNECTOR_VGA:
  466. drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
  467. drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
  468. if (i2c_bus->valid) {
  469. radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA");
  470. if (!radeon_connector->ddc_bus)
  471. goto failed;
  472. }
  473. break;
  474. case DRM_MODE_CONNECTOR_DVIA:
  475. drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
  476. drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
  477. if (i2c_bus->valid) {
  478. radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
  479. if (!radeon_connector->ddc_bus)
  480. goto failed;
  481. }
  482. break;
  483. case DRM_MODE_CONNECTOR_DVII:
  484. case DRM_MODE_CONNECTOR_DVID:
  485. radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
  486. if (!radeon_dig_connector)
  487. goto failed;
  488. radeon_dig_connector->linkb = linkb;
  489. radeon_dig_connector->igp_lane_info = igp_lane_info;
  490. radeon_connector->con_priv = radeon_dig_connector;
  491. drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
  492. drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
  493. if (i2c_bus->valid) {
  494. radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
  495. if (!radeon_connector->ddc_bus)
  496. goto failed;
  497. }
  498. subpixel_order = SubPixelHorizontalRGB;
  499. break;
  500. case DRM_MODE_CONNECTOR_HDMIA:
  501. case DRM_MODE_CONNECTOR_HDMIB:
  502. radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
  503. if (!radeon_dig_connector)
  504. goto failed;
  505. radeon_dig_connector->linkb = linkb;
  506. radeon_dig_connector->igp_lane_info = igp_lane_info;
  507. radeon_connector->con_priv = radeon_dig_connector;
  508. drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
  509. drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
  510. if (i2c_bus->valid) {
  511. radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "HDMI");
  512. if (!radeon_connector->ddc_bus)
  513. goto failed;
  514. }
  515. subpixel_order = SubPixelHorizontalRGB;
  516. break;
  517. case DRM_MODE_CONNECTOR_DisplayPort:
  518. radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
  519. if (!radeon_dig_connector)
  520. goto failed;
  521. radeon_dig_connector->linkb = linkb;
  522. radeon_dig_connector->igp_lane_info = igp_lane_info;
  523. radeon_connector->con_priv = radeon_dig_connector;
  524. drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
  525. drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
  526. if (i2c_bus->valid) {
  527. radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DP");
  528. if (!radeon_connector->ddc_bus)
  529. goto failed;
  530. }
  531. subpixel_order = SubPixelHorizontalRGB;
  532. break;
  533. case DRM_MODE_CONNECTOR_SVIDEO:
  534. case DRM_MODE_CONNECTOR_Composite:
  535. case DRM_MODE_CONNECTOR_9PinDIN:
  536. if (radeon_tv == 1) {
  537. drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
  538. drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
  539. }
  540. break;
  541. case DRM_MODE_CONNECTOR_LVDS:
  542. radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
  543. if (!radeon_dig_connector)
  544. goto failed;
  545. radeon_dig_connector->linkb = linkb;
  546. radeon_dig_connector->igp_lane_info = igp_lane_info;
  547. radeon_connector->con_priv = radeon_dig_connector;
  548. drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
  549. drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
  550. if (i2c_bus->valid) {
  551. radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS");
  552. if (!radeon_connector->ddc_bus)
  553. goto failed;
  554. }
  555. subpixel_order = SubPixelHorizontalRGB;
  556. break;
  557. }
  558. connector->display_info.subpixel_order = subpixel_order;
  559. drm_sysfs_connector_add(connector);
  560. return;
  561. failed:
  562. if (radeon_connector->ddc_bus)
  563. radeon_i2c_destroy(radeon_connector->ddc_bus);
  564. drm_connector_cleanup(connector);
  565. kfree(connector);
  566. }
  567. void
  568. radeon_add_legacy_connector(struct drm_device *dev,
  569. uint32_t connector_id,
  570. uint32_t supported_device,
  571. int connector_type,
  572. struct radeon_i2c_bus_rec *i2c_bus)
  573. {
  574. struct drm_connector *connector;
  575. struct radeon_connector *radeon_connector;
  576. uint32_t subpixel_order = SubPixelNone;
  577. /* fixme - tv/cv/din */
  578. if (connector_type == DRM_MODE_CONNECTOR_Unknown)
  579. return;
  580. /* see if we already added it */
  581. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  582. radeon_connector = to_radeon_connector(connector);
  583. if (radeon_connector->connector_id == connector_id) {
  584. radeon_connector->devices |= supported_device;
  585. return;
  586. }
  587. }
  588. radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
  589. if (!radeon_connector)
  590. return;
  591. connector = &radeon_connector->base;
  592. radeon_connector->connector_id = connector_id;
  593. radeon_connector->devices = supported_device;
  594. switch (connector_type) {
  595. case DRM_MODE_CONNECTOR_VGA:
  596. drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
  597. drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
  598. if (i2c_bus->valid) {
  599. radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA");
  600. if (!radeon_connector->ddc_bus)
  601. goto failed;
  602. }
  603. break;
  604. case DRM_MODE_CONNECTOR_DVIA:
  605. drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
  606. drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
  607. if (i2c_bus->valid) {
  608. radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
  609. if (!radeon_connector->ddc_bus)
  610. goto failed;
  611. }
  612. break;
  613. case DRM_MODE_CONNECTOR_DVII:
  614. case DRM_MODE_CONNECTOR_DVID:
  615. drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
  616. drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
  617. if (i2c_bus->valid) {
  618. radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
  619. if (!radeon_connector->ddc_bus)
  620. goto failed;
  621. }
  622. subpixel_order = SubPixelHorizontalRGB;
  623. break;
  624. case DRM_MODE_CONNECTOR_SVIDEO:
  625. case DRM_MODE_CONNECTOR_Composite:
  626. case DRM_MODE_CONNECTOR_9PinDIN:
  627. if (radeon_tv == 1) {
  628. drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
  629. drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
  630. }
  631. break;
  632. case DRM_MODE_CONNECTOR_LVDS:
  633. drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
  634. drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
  635. if (i2c_bus->valid) {
  636. radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS");
  637. if (!radeon_connector->ddc_bus)
  638. goto failed;
  639. }
  640. subpixel_order = SubPixelHorizontalRGB;
  641. break;
  642. }
  643. connector->display_info.subpixel_order = subpixel_order;
  644. drm_sysfs_connector_add(connector);
  645. return;
  646. failed:
  647. if (radeon_connector->ddc_bus)
  648. radeon_i2c_destroy(radeon_connector->ddc_bus);
  649. drm_connector_cleanup(connector);
  650. kfree(connector);
  651. }