exynos_drm_vidi.c 17 KB

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