exynos_drm_vidi.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. /* exynos_drm_vidi.c
  2. *
  3. * Copyright (C) 2012 Samsung Electronics Co.Ltd
  4. * Authors:
  5. * Inki Dae <inki.dae@samsung.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. *
  12. */
  13. #include <drm/drmP.h>
  14. #include <linux/kernel.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/component.h>
  17. #include <drm/exynos_drm.h>
  18. #include <drm/drm_edid.h>
  19. #include <drm/drm_crtc_helper.h>
  20. #include "exynos_drm_drv.h"
  21. #include "exynos_drm_crtc.h"
  22. #include "exynos_drm_encoder.h"
  23. #include "exynos_drm_vidi.h"
  24. /* vidi has totally three virtual windows. */
  25. #define WINDOWS_NR 3
  26. #define ctx_from_connector(c) container_of(c, struct vidi_context, \
  27. connector)
  28. struct vidi_win_data {
  29. unsigned int offset_x;
  30. unsigned int offset_y;
  31. unsigned int ovl_width;
  32. unsigned int ovl_height;
  33. unsigned int fb_width;
  34. unsigned int fb_height;
  35. unsigned int bpp;
  36. dma_addr_t dma_addr;
  37. unsigned int buf_offsize;
  38. unsigned int line_size; /* bytes */
  39. bool enabled;
  40. };
  41. struct vidi_context {
  42. struct exynos_drm_manager manager;
  43. struct exynos_drm_display display;
  44. struct platform_device *pdev;
  45. struct drm_device *drm_dev;
  46. struct drm_crtc *crtc;
  47. struct drm_encoder *encoder;
  48. struct drm_connector connector;
  49. struct vidi_win_data win_data[WINDOWS_NR];
  50. struct edid *raw_edid;
  51. unsigned int clkdiv;
  52. unsigned int default_win;
  53. unsigned long irq_flags;
  54. unsigned int connected;
  55. bool vblank_on;
  56. bool suspended;
  57. bool direct_vblank;
  58. struct work_struct work;
  59. struct mutex lock;
  60. int pipe;
  61. };
  62. static inline struct vidi_context *manager_to_vidi(struct exynos_drm_manager *m)
  63. {
  64. return container_of(m, struct vidi_context, manager);
  65. }
  66. static inline struct vidi_context *display_to_vidi(struct exynos_drm_display *d)
  67. {
  68. return container_of(d, struct vidi_context, display);
  69. }
  70. static const char fake_edid_info[] = {
  71. 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x4c, 0x2d, 0x05, 0x05,
  72. 0x00, 0x00, 0x00, 0x00, 0x30, 0x12, 0x01, 0x03, 0x80, 0x10, 0x09, 0x78,
  73. 0x0a, 0xee, 0x91, 0xa3, 0x54, 0x4c, 0x99, 0x26, 0x0f, 0x50, 0x54, 0xbd,
  74. 0xee, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  75. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x66, 0x21, 0x50, 0xb0, 0x51, 0x00,
  76. 0x1b, 0x30, 0x40, 0x70, 0x36, 0x00, 0xa0, 0x5a, 0x00, 0x00, 0x00, 0x1e,
  77. 0x01, 0x1d, 0x00, 0x72, 0x51, 0xd0, 0x1e, 0x20, 0x6e, 0x28, 0x55, 0x00,
  78. 0xa0, 0x5a, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x18,
  79. 0x4b, 0x1a, 0x44, 0x17, 0x00, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  80. 0x00, 0x00, 0x00, 0xfc, 0x00, 0x53, 0x41, 0x4d, 0x53, 0x55, 0x4e, 0x47,
  81. 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0xbc, 0x02, 0x03, 0x1e, 0xf1,
  82. 0x46, 0x84, 0x05, 0x03, 0x10, 0x20, 0x22, 0x23, 0x09, 0x07, 0x07, 0x83,
  83. 0x01, 0x00, 0x00, 0xe2, 0x00, 0x0f, 0x67, 0x03, 0x0c, 0x00, 0x10, 0x00,
  84. 0xb8, 0x2d, 0x01, 0x1d, 0x80, 0x18, 0x71, 0x1c, 0x16, 0x20, 0x58, 0x2c,
  85. 0x25, 0x00, 0xa0, 0x5a, 0x00, 0x00, 0x00, 0x9e, 0x8c, 0x0a, 0xd0, 0x8a,
  86. 0x20, 0xe0, 0x2d, 0x10, 0x10, 0x3e, 0x96, 0x00, 0xa0, 0x5a, 0x00, 0x00,
  87. 0x00, 0x18, 0x02, 0x3a, 0x80, 0x18, 0x71, 0x38, 0x2d, 0x40, 0x58, 0x2c,
  88. 0x45, 0x00, 0xa0, 0x5a, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00,
  89. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  90. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  91. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  92. 0x00, 0x00, 0x00, 0x06
  93. };
  94. static void vidi_apply(struct exynos_drm_manager *mgr)
  95. {
  96. struct vidi_context *ctx = manager_to_vidi(mgr);
  97. struct exynos_drm_manager_ops *mgr_ops = mgr->ops;
  98. struct vidi_win_data *win_data;
  99. int i;
  100. for (i = 0; i < WINDOWS_NR; i++) {
  101. win_data = &ctx->win_data[i];
  102. if (win_data->enabled && (mgr_ops && mgr_ops->win_commit))
  103. mgr_ops->win_commit(mgr, i);
  104. }
  105. if (mgr_ops && mgr_ops->commit)
  106. mgr_ops->commit(mgr);
  107. }
  108. static void vidi_commit(struct exynos_drm_manager *mgr)
  109. {
  110. struct vidi_context *ctx = manager_to_vidi(mgr);
  111. if (ctx->suspended)
  112. return;
  113. }
  114. static int vidi_enable_vblank(struct exynos_drm_manager *mgr)
  115. {
  116. struct vidi_context *ctx = manager_to_vidi(mgr);
  117. if (ctx->suspended)
  118. return -EPERM;
  119. if (!test_and_set_bit(0, &ctx->irq_flags))
  120. ctx->vblank_on = true;
  121. ctx->direct_vblank = true;
  122. /*
  123. * in case of page flip request, vidi_finish_pageflip function
  124. * will not be called because direct_vblank is true and then
  125. * that function will be called by manager_ops->win_commit callback
  126. */
  127. schedule_work(&ctx->work);
  128. return 0;
  129. }
  130. static void vidi_disable_vblank(struct exynos_drm_manager *mgr)
  131. {
  132. struct vidi_context *ctx = manager_to_vidi(mgr);
  133. if (ctx->suspended)
  134. return;
  135. if (test_and_clear_bit(0, &ctx->irq_flags))
  136. ctx->vblank_on = false;
  137. }
  138. static void vidi_win_mode_set(struct exynos_drm_manager *mgr,
  139. struct exynos_drm_overlay *overlay)
  140. {
  141. struct vidi_context *ctx = manager_to_vidi(mgr);
  142. struct vidi_win_data *win_data;
  143. int win;
  144. unsigned long offset;
  145. if (!overlay) {
  146. DRM_ERROR("overlay is NULL\n");
  147. return;
  148. }
  149. win = overlay->zpos;
  150. if (win == DEFAULT_ZPOS)
  151. win = ctx->default_win;
  152. if (win < 0 || win >= WINDOWS_NR)
  153. return;
  154. offset = overlay->fb_x * (overlay->bpp >> 3);
  155. offset += overlay->fb_y * overlay->pitch;
  156. DRM_DEBUG_KMS("offset = 0x%lx, pitch = %x\n", offset, overlay->pitch);
  157. win_data = &ctx->win_data[win];
  158. win_data->offset_x = overlay->crtc_x;
  159. win_data->offset_y = overlay->crtc_y;
  160. win_data->ovl_width = overlay->crtc_width;
  161. win_data->ovl_height = overlay->crtc_height;
  162. win_data->fb_width = overlay->fb_width;
  163. win_data->fb_height = overlay->fb_height;
  164. win_data->dma_addr = overlay->dma_addr[0] + offset;
  165. win_data->bpp = overlay->bpp;
  166. win_data->buf_offsize = (overlay->fb_width - overlay->crtc_width) *
  167. (overlay->bpp >> 3);
  168. win_data->line_size = overlay->crtc_width * (overlay->bpp >> 3);
  169. /*
  170. * some parts of win_data should be transferred to user side
  171. * through specific ioctl.
  172. */
  173. DRM_DEBUG_KMS("offset_x = %d, offset_y = %d\n",
  174. win_data->offset_x, win_data->offset_y);
  175. DRM_DEBUG_KMS("ovl_width = %d, ovl_height = %d\n",
  176. win_data->ovl_width, win_data->ovl_height);
  177. DRM_DEBUG_KMS("paddr = 0x%lx\n", (unsigned long)win_data->dma_addr);
  178. DRM_DEBUG_KMS("fb_width = %d, crtc_width = %d\n",
  179. overlay->fb_width, overlay->crtc_width);
  180. }
  181. static void vidi_win_commit(struct exynos_drm_manager *mgr, int zpos)
  182. {
  183. struct vidi_context *ctx = manager_to_vidi(mgr);
  184. struct vidi_win_data *win_data;
  185. int win = zpos;
  186. if (ctx->suspended)
  187. return;
  188. if (win == DEFAULT_ZPOS)
  189. win = ctx->default_win;
  190. if (win < 0 || win >= WINDOWS_NR)
  191. return;
  192. win_data = &ctx->win_data[win];
  193. win_data->enabled = true;
  194. DRM_DEBUG_KMS("dma_addr = %pad\n", &win_data->dma_addr);
  195. if (ctx->vblank_on)
  196. schedule_work(&ctx->work);
  197. }
  198. static void vidi_win_disable(struct exynos_drm_manager *mgr, int zpos)
  199. {
  200. struct vidi_context *ctx = manager_to_vidi(mgr);
  201. struct vidi_win_data *win_data;
  202. int win = zpos;
  203. if (win == DEFAULT_ZPOS)
  204. win = ctx->default_win;
  205. if (win < 0 || win >= WINDOWS_NR)
  206. return;
  207. win_data = &ctx->win_data[win];
  208. win_data->enabled = false;
  209. /* TODO. */
  210. }
  211. static int vidi_power_on(struct exynos_drm_manager *mgr, bool enable)
  212. {
  213. struct vidi_context *ctx = manager_to_vidi(mgr);
  214. DRM_DEBUG_KMS("%s\n", __FILE__);
  215. if (enable != false && enable != true)
  216. return -EINVAL;
  217. if (enable) {
  218. ctx->suspended = false;
  219. /* if vblank was enabled status, enable it again. */
  220. if (test_and_clear_bit(0, &ctx->irq_flags))
  221. vidi_enable_vblank(mgr);
  222. vidi_apply(mgr);
  223. } else {
  224. ctx->suspended = true;
  225. }
  226. return 0;
  227. }
  228. static void vidi_dpms(struct exynos_drm_manager *mgr, int mode)
  229. {
  230. struct vidi_context *ctx = manager_to_vidi(mgr);
  231. DRM_DEBUG_KMS("%d\n", mode);
  232. mutex_lock(&ctx->lock);
  233. switch (mode) {
  234. case DRM_MODE_DPMS_ON:
  235. vidi_power_on(mgr, true);
  236. break;
  237. case DRM_MODE_DPMS_STANDBY:
  238. case DRM_MODE_DPMS_SUSPEND:
  239. case DRM_MODE_DPMS_OFF:
  240. vidi_power_on(mgr, false);
  241. break;
  242. default:
  243. DRM_DEBUG_KMS("unspecified mode %d\n", mode);
  244. break;
  245. }
  246. mutex_unlock(&ctx->lock);
  247. }
  248. static int vidi_mgr_initialize(struct exynos_drm_manager *mgr,
  249. struct drm_device *drm_dev)
  250. {
  251. struct vidi_context *ctx = manager_to_vidi(mgr);
  252. struct exynos_drm_private *priv = drm_dev->dev_private;
  253. mgr->drm_dev = ctx->drm_dev = drm_dev;
  254. mgr->pipe = ctx->pipe = priv->pipe++;
  255. return 0;
  256. }
  257. static struct exynos_drm_manager_ops vidi_manager_ops = {
  258. .dpms = vidi_dpms,
  259. .commit = vidi_commit,
  260. .enable_vblank = vidi_enable_vblank,
  261. .disable_vblank = vidi_disable_vblank,
  262. .win_mode_set = vidi_win_mode_set,
  263. .win_commit = vidi_win_commit,
  264. .win_disable = vidi_win_disable,
  265. };
  266. static void vidi_fake_vblank_handler(struct work_struct *work)
  267. {
  268. struct vidi_context *ctx = container_of(work, struct vidi_context,
  269. work);
  270. if (ctx->pipe < 0)
  271. return;
  272. /* refresh rate is about 50Hz. */
  273. usleep_range(16000, 20000);
  274. mutex_lock(&ctx->lock);
  275. if (ctx->direct_vblank) {
  276. drm_handle_vblank(ctx->drm_dev, ctx->pipe);
  277. ctx->direct_vblank = false;
  278. mutex_unlock(&ctx->lock);
  279. return;
  280. }
  281. mutex_unlock(&ctx->lock);
  282. exynos_drm_crtc_finish_pageflip(ctx->drm_dev, ctx->pipe);
  283. }
  284. static int vidi_show_connection(struct device *dev,
  285. struct device_attribute *attr, char *buf)
  286. {
  287. struct vidi_context *ctx = dev_get_drvdata(dev);
  288. int rc;
  289. mutex_lock(&ctx->lock);
  290. rc = sprintf(buf, "%d\n", ctx->connected);
  291. mutex_unlock(&ctx->lock);
  292. return rc;
  293. }
  294. static int vidi_store_connection(struct device *dev,
  295. struct device_attribute *attr,
  296. const char *buf, size_t len)
  297. {
  298. struct vidi_context *ctx = dev_get_drvdata(dev);
  299. int ret;
  300. ret = kstrtoint(buf, 0, &ctx->connected);
  301. if (ret)
  302. return ret;
  303. if (ctx->connected > 1)
  304. return -EINVAL;
  305. /* use fake edid data for test. */
  306. if (!ctx->raw_edid)
  307. ctx->raw_edid = (struct edid *)fake_edid_info;
  308. /* if raw_edid isn't same as fake data then it can't be tested. */
  309. if (ctx->raw_edid != (struct edid *)fake_edid_info) {
  310. DRM_DEBUG_KMS("edid data is not fake data.\n");
  311. return -EINVAL;
  312. }
  313. DRM_DEBUG_KMS("requested connection.\n");
  314. drm_helper_hpd_irq_event(ctx->drm_dev);
  315. return len;
  316. }
  317. static DEVICE_ATTR(connection, 0644, vidi_show_connection,
  318. vidi_store_connection);
  319. int vidi_connection_ioctl(struct drm_device *drm_dev, void *data,
  320. struct drm_file *file_priv)
  321. {
  322. struct vidi_context *ctx = NULL;
  323. struct drm_encoder *encoder;
  324. struct exynos_drm_display *display;
  325. struct drm_exynos_vidi_connection *vidi = data;
  326. if (!vidi) {
  327. DRM_DEBUG_KMS("user data for vidi is null.\n");
  328. return -EINVAL;
  329. }
  330. if (vidi->connection > 1) {
  331. DRM_DEBUG_KMS("connection should be 0 or 1.\n");
  332. return -EINVAL;
  333. }
  334. list_for_each_entry(encoder, &drm_dev->mode_config.encoder_list,
  335. head) {
  336. display = exynos_drm_get_display(encoder);
  337. if (display->type == EXYNOS_DISPLAY_TYPE_VIDI) {
  338. ctx = display_to_vidi(display);
  339. break;
  340. }
  341. }
  342. if (!ctx) {
  343. DRM_DEBUG_KMS("not found virtual device type encoder.\n");
  344. return -EINVAL;
  345. }
  346. if (ctx->connected == vidi->connection) {
  347. DRM_DEBUG_KMS("same connection request.\n");
  348. return -EINVAL;
  349. }
  350. if (vidi->connection) {
  351. struct edid *raw_edid = (struct edid *)(uint32_t)vidi->edid;
  352. if (!drm_edid_is_valid(raw_edid)) {
  353. DRM_DEBUG_KMS("edid data is invalid.\n");
  354. return -EINVAL;
  355. }
  356. ctx->raw_edid = drm_edid_duplicate(raw_edid);
  357. if (!ctx->raw_edid) {
  358. DRM_DEBUG_KMS("failed to allocate raw_edid.\n");
  359. return -ENOMEM;
  360. }
  361. } else {
  362. /*
  363. * with connection = 0, free raw_edid
  364. * only if raw edid data isn't same as fake data.
  365. */
  366. if (ctx->raw_edid && ctx->raw_edid !=
  367. (struct edid *)fake_edid_info) {
  368. kfree(ctx->raw_edid);
  369. ctx->raw_edid = NULL;
  370. }
  371. }
  372. ctx->connected = vidi->connection;
  373. drm_helper_hpd_irq_event(ctx->drm_dev);
  374. return 0;
  375. }
  376. static enum drm_connector_status vidi_detect(struct drm_connector *connector,
  377. bool force)
  378. {
  379. struct vidi_context *ctx = ctx_from_connector(connector);
  380. /*
  381. * connection request would come from user side
  382. * to do hotplug through specific ioctl.
  383. */
  384. return ctx->connected ? connector_status_connected :
  385. connector_status_disconnected;
  386. }
  387. static void vidi_connector_destroy(struct drm_connector *connector)
  388. {
  389. }
  390. static struct drm_connector_funcs vidi_connector_funcs = {
  391. .dpms = drm_helper_connector_dpms,
  392. .fill_modes = drm_helper_probe_single_connector_modes,
  393. .detect = vidi_detect,
  394. .destroy = vidi_connector_destroy,
  395. };
  396. static int vidi_get_modes(struct drm_connector *connector)
  397. {
  398. struct vidi_context *ctx = ctx_from_connector(connector);
  399. struct edid *edid;
  400. int edid_len;
  401. /*
  402. * the edid data comes from user side and it would be set
  403. * to ctx->raw_edid through specific ioctl.
  404. */
  405. if (!ctx->raw_edid) {
  406. DRM_DEBUG_KMS("raw_edid is null.\n");
  407. return -EFAULT;
  408. }
  409. edid_len = (1 + ctx->raw_edid->extensions) * EDID_LENGTH;
  410. edid = kmemdup(ctx->raw_edid, edid_len, GFP_KERNEL);
  411. if (!edid) {
  412. DRM_DEBUG_KMS("failed to allocate edid\n");
  413. return -ENOMEM;
  414. }
  415. drm_mode_connector_update_edid_property(connector, edid);
  416. return drm_add_edid_modes(connector, edid);
  417. }
  418. static struct drm_encoder *vidi_best_encoder(struct drm_connector *connector)
  419. {
  420. struct vidi_context *ctx = ctx_from_connector(connector);
  421. return ctx->encoder;
  422. }
  423. static struct drm_connector_helper_funcs vidi_connector_helper_funcs = {
  424. .get_modes = vidi_get_modes,
  425. .best_encoder = vidi_best_encoder,
  426. };
  427. static int vidi_create_connector(struct exynos_drm_display *display,
  428. struct drm_encoder *encoder)
  429. {
  430. struct vidi_context *ctx = display_to_vidi(display);
  431. struct drm_connector *connector = &ctx->connector;
  432. int ret;
  433. ctx->encoder = encoder;
  434. connector->polled = DRM_CONNECTOR_POLL_HPD;
  435. ret = drm_connector_init(ctx->drm_dev, connector,
  436. &vidi_connector_funcs, DRM_MODE_CONNECTOR_VIRTUAL);
  437. if (ret) {
  438. DRM_ERROR("Failed to initialize connector with drm\n");
  439. return ret;
  440. }
  441. drm_connector_helper_add(connector, &vidi_connector_helper_funcs);
  442. drm_connector_register(connector);
  443. drm_mode_connector_attach_encoder(connector, encoder);
  444. return 0;
  445. }
  446. static struct exynos_drm_display_ops vidi_display_ops = {
  447. .create_connector = vidi_create_connector,
  448. };
  449. static int vidi_bind(struct device *dev, struct device *master, void *data)
  450. {
  451. struct vidi_context *ctx = dev_get_drvdata(dev);
  452. struct drm_device *drm_dev = data;
  453. struct drm_crtc *crtc = ctx->crtc;
  454. int ret;
  455. vidi_mgr_initialize(&ctx->manager, drm_dev);
  456. ret = exynos_drm_crtc_create(&ctx->manager);
  457. if (ret) {
  458. DRM_ERROR("failed to create crtc.\n");
  459. return ret;
  460. }
  461. ret = exynos_drm_create_enc_conn(drm_dev, &ctx->display);
  462. if (ret) {
  463. crtc->funcs->destroy(crtc);
  464. DRM_ERROR("failed to create encoder and connector.\n");
  465. return ret;
  466. }
  467. return 0;
  468. }
  469. static void vidi_unbind(struct device *dev, struct device *master, void *data)
  470. {
  471. }
  472. static const struct component_ops vidi_component_ops = {
  473. .bind = vidi_bind,
  474. .unbind = vidi_unbind,
  475. };
  476. static int vidi_probe(struct platform_device *pdev)
  477. {
  478. struct vidi_context *ctx;
  479. int ret;
  480. ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
  481. if (!ctx)
  482. return -ENOMEM;
  483. ctx->manager.type = EXYNOS_DISPLAY_TYPE_VIDI;
  484. ctx->manager.ops = &vidi_manager_ops;
  485. ctx->display.type = EXYNOS_DISPLAY_TYPE_VIDI;
  486. ctx->display.ops = &vidi_display_ops;
  487. ctx->default_win = 0;
  488. ctx->pdev = pdev;
  489. ret = exynos_drm_component_add(&pdev->dev, EXYNOS_DEVICE_TYPE_CRTC,
  490. ctx->manager.type);
  491. if (ret)
  492. return ret;
  493. ret = exynos_drm_component_add(&pdev->dev, EXYNOS_DEVICE_TYPE_CONNECTOR,
  494. ctx->display.type);
  495. if (ret)
  496. goto err_del_crtc_component;
  497. INIT_WORK(&ctx->work, vidi_fake_vblank_handler);
  498. mutex_init(&ctx->lock);
  499. platform_set_drvdata(pdev, ctx);
  500. ret = device_create_file(&pdev->dev, &dev_attr_connection);
  501. if (ret < 0) {
  502. DRM_ERROR("failed to create connection sysfs.\n");
  503. goto err_del_conn_component;
  504. }
  505. ret = component_add(&pdev->dev, &vidi_component_ops);
  506. if (ret)
  507. goto err_remove_file;
  508. return ret;
  509. err_remove_file:
  510. device_remove_file(&pdev->dev, &dev_attr_connection);
  511. err_del_conn_component:
  512. exynos_drm_component_del(&pdev->dev, EXYNOS_DEVICE_TYPE_CONNECTOR);
  513. err_del_crtc_component:
  514. exynos_drm_component_del(&pdev->dev, EXYNOS_DEVICE_TYPE_CRTC);
  515. return ret;
  516. }
  517. static int vidi_remove(struct platform_device *pdev)
  518. {
  519. struct vidi_context *ctx = platform_get_drvdata(pdev);
  520. if (ctx->raw_edid != (struct edid *)fake_edid_info) {
  521. kfree(ctx->raw_edid);
  522. ctx->raw_edid = NULL;
  523. return -EINVAL;
  524. }
  525. component_del(&pdev->dev, &vidi_component_ops);
  526. exynos_drm_component_del(&pdev->dev, EXYNOS_DEVICE_TYPE_CONNECTOR);
  527. exynos_drm_component_del(&pdev->dev, EXYNOS_DEVICE_TYPE_CRTC);
  528. return 0;
  529. }
  530. struct platform_driver vidi_driver = {
  531. .probe = vidi_probe,
  532. .remove = vidi_remove,
  533. .driver = {
  534. .name = "exynos-drm-vidi",
  535. .owner = THIS_MODULE,
  536. },
  537. };
  538. int exynos_drm_probe_vidi(void)
  539. {
  540. struct platform_device *pdev;
  541. int ret;
  542. pdev = platform_device_register_simple("exynos-drm-vidi", -1, NULL, 0);
  543. if (IS_ERR(pdev))
  544. return PTR_ERR(pdev);
  545. ret = platform_driver_register(&vidi_driver);
  546. if (ret) {
  547. platform_device_unregister(pdev);
  548. return ret;
  549. }
  550. return ret;
  551. }
  552. static int exynos_drm_remove_vidi_device(struct device *dev, void *data)
  553. {
  554. platform_device_unregister(to_platform_device(dev));
  555. return 0;
  556. }
  557. void exynos_drm_remove_vidi(void)
  558. {
  559. int ret = driver_for_each_device(&vidi_driver.driver, NULL, NULL,
  560. exynos_drm_remove_vidi_device);
  561. /* silence compiler warning */
  562. (void)ret;
  563. platform_driver_unregister(&vidi_driver);
  564. }