exynos_drm_vidi.c 17 KB

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