exynos_drm_vidi.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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. return 0;
  246. }
  247. static struct exynos_drm_manager_ops vidi_manager_ops = {
  248. .dpms = vidi_dpms,
  249. .commit = vidi_commit,
  250. .enable_vblank = vidi_enable_vblank,
  251. .disable_vblank = vidi_disable_vblank,
  252. .win_mode_set = vidi_win_mode_set,
  253. .win_commit = vidi_win_commit,
  254. .win_disable = vidi_win_disable,
  255. };
  256. static struct exynos_drm_manager vidi_manager = {
  257. .type = EXYNOS_DISPLAY_TYPE_VIDI,
  258. .ops = &vidi_manager_ops,
  259. };
  260. static void vidi_fake_vblank_handler(struct work_struct *work)
  261. {
  262. struct vidi_context *ctx = container_of(work, struct vidi_context,
  263. work);
  264. if (ctx->pipe < 0)
  265. return;
  266. /* refresh rate is about 50Hz. */
  267. usleep_range(16000, 20000);
  268. mutex_lock(&ctx->lock);
  269. if (ctx->direct_vblank) {
  270. drm_handle_vblank(ctx->drm_dev, ctx->pipe);
  271. ctx->direct_vblank = false;
  272. mutex_unlock(&ctx->lock);
  273. return;
  274. }
  275. mutex_unlock(&ctx->lock);
  276. exynos_drm_crtc_finish_pageflip(ctx->drm_dev, ctx->pipe);
  277. }
  278. static int vidi_show_connection(struct device *dev,
  279. struct device_attribute *attr, char *buf)
  280. {
  281. int rc;
  282. struct exynos_drm_manager *mgr = get_vidi_mgr(dev);
  283. struct vidi_context *ctx = mgr->ctx;
  284. mutex_lock(&ctx->lock);
  285. rc = sprintf(buf, "%d\n", ctx->connected);
  286. mutex_unlock(&ctx->lock);
  287. return rc;
  288. }
  289. static int vidi_store_connection(struct device *dev,
  290. struct device_attribute *attr,
  291. const char *buf, size_t len)
  292. {
  293. struct exynos_drm_manager *mgr = get_vidi_mgr(dev);
  294. struct vidi_context *ctx = mgr->ctx;
  295. int ret;
  296. ret = kstrtoint(buf, 0, &ctx->connected);
  297. if (ret)
  298. return ret;
  299. if (ctx->connected > 1)
  300. return -EINVAL;
  301. /* use fake edid data for test. */
  302. if (!ctx->raw_edid)
  303. ctx->raw_edid = (struct edid *)fake_edid_info;
  304. /* if raw_edid isn't same as fake data then it can't be tested. */
  305. if (ctx->raw_edid != (struct edid *)fake_edid_info) {
  306. DRM_DEBUG_KMS("edid data is not fake data.\n");
  307. return -EINVAL;
  308. }
  309. DRM_DEBUG_KMS("requested connection.\n");
  310. drm_helper_hpd_irq_event(ctx->drm_dev);
  311. return len;
  312. }
  313. static DEVICE_ATTR(connection, 0644, vidi_show_connection,
  314. vidi_store_connection);
  315. int vidi_connection_ioctl(struct drm_device *drm_dev, void *data,
  316. struct drm_file *file_priv)
  317. {
  318. struct vidi_context *ctx = NULL;
  319. struct drm_encoder *encoder;
  320. struct exynos_drm_display *display;
  321. struct drm_exynos_vidi_connection *vidi = data;
  322. if (!vidi) {
  323. DRM_DEBUG_KMS("user data for vidi is null.\n");
  324. return -EINVAL;
  325. }
  326. if (vidi->connection > 1) {
  327. DRM_DEBUG_KMS("connection should be 0 or 1.\n");
  328. return -EINVAL;
  329. }
  330. list_for_each_entry(encoder, &drm_dev->mode_config.encoder_list,
  331. head) {
  332. display = exynos_drm_get_display(encoder);
  333. if (display->type == EXYNOS_DISPLAY_TYPE_VIDI) {
  334. ctx = display->ctx;
  335. break;
  336. }
  337. }
  338. if (!ctx) {
  339. DRM_DEBUG_KMS("not found virtual device type encoder.\n");
  340. return -EINVAL;
  341. }
  342. if (ctx->connected == vidi->connection) {
  343. DRM_DEBUG_KMS("same connection request.\n");
  344. return -EINVAL;
  345. }
  346. if (vidi->connection) {
  347. struct edid *raw_edid = (struct edid *)(uint32_t)vidi->edid;
  348. if (!drm_edid_is_valid(raw_edid)) {
  349. DRM_DEBUG_KMS("edid data is invalid.\n");
  350. return -EINVAL;
  351. }
  352. ctx->raw_edid = drm_edid_duplicate(raw_edid);
  353. if (!ctx->raw_edid) {
  354. DRM_DEBUG_KMS("failed to allocate raw_edid.\n");
  355. return -ENOMEM;
  356. }
  357. } else {
  358. /*
  359. * with connection = 0, free raw_edid
  360. * only if raw edid data isn't same as fake data.
  361. */
  362. if (ctx->raw_edid && ctx->raw_edid !=
  363. (struct edid *)fake_edid_info) {
  364. kfree(ctx->raw_edid);
  365. ctx->raw_edid = NULL;
  366. }
  367. }
  368. ctx->connected = vidi->connection;
  369. drm_helper_hpd_irq_event(ctx->drm_dev);
  370. return 0;
  371. }
  372. static enum drm_connector_status vidi_detect(struct drm_connector *connector,
  373. bool force)
  374. {
  375. struct vidi_context *ctx = ctx_from_connector(connector);
  376. /*
  377. * connection request would come from user side
  378. * to do hotplug through specific ioctl.
  379. */
  380. return ctx->connected ? connector_status_connected :
  381. connector_status_disconnected;
  382. }
  383. static void vidi_connector_destroy(struct drm_connector *connector)
  384. {
  385. }
  386. static struct drm_connector_funcs vidi_connector_funcs = {
  387. .dpms = drm_helper_connector_dpms,
  388. .fill_modes = drm_helper_probe_single_connector_modes,
  389. .detect = vidi_detect,
  390. .destroy = vidi_connector_destroy,
  391. };
  392. static int vidi_get_modes(struct drm_connector *connector)
  393. {
  394. struct vidi_context *ctx = ctx_from_connector(connector);
  395. struct edid *edid;
  396. int edid_len;
  397. /*
  398. * the edid data comes from user side and it would be set
  399. * to ctx->raw_edid through specific ioctl.
  400. */
  401. if (!ctx->raw_edid) {
  402. DRM_DEBUG_KMS("raw_edid is null.\n");
  403. return -EFAULT;
  404. }
  405. edid_len = (1 + ctx->raw_edid->extensions) * EDID_LENGTH;
  406. edid = kmemdup(ctx->raw_edid, edid_len, GFP_KERNEL);
  407. if (!edid) {
  408. DRM_DEBUG_KMS("failed to allocate edid\n");
  409. return -ENOMEM;
  410. }
  411. drm_mode_connector_update_edid_property(connector, edid);
  412. return drm_add_edid_modes(connector, edid);
  413. }
  414. static struct drm_encoder *vidi_best_encoder(struct drm_connector *connector)
  415. {
  416. struct vidi_context *ctx = ctx_from_connector(connector);
  417. return ctx->encoder;
  418. }
  419. static struct drm_connector_helper_funcs vidi_connector_helper_funcs = {
  420. .get_modes = vidi_get_modes,
  421. .best_encoder = vidi_best_encoder,
  422. };
  423. static int vidi_create_connector(struct exynos_drm_display *display,
  424. struct drm_encoder *encoder)
  425. {
  426. struct vidi_context *ctx = display->ctx;
  427. struct drm_connector *connector = &ctx->connector;
  428. int ret;
  429. ctx->encoder = encoder;
  430. connector->polled = DRM_CONNECTOR_POLL_HPD;
  431. ret = drm_connector_init(ctx->drm_dev, connector,
  432. &vidi_connector_funcs, DRM_MODE_CONNECTOR_VIRTUAL);
  433. if (ret) {
  434. DRM_ERROR("Failed to initialize connector with drm\n");
  435. return ret;
  436. }
  437. drm_connector_helper_add(connector, &vidi_connector_helper_funcs);
  438. drm_connector_register(connector);
  439. drm_mode_connector_attach_encoder(connector, encoder);
  440. return 0;
  441. }
  442. static struct exynos_drm_display_ops vidi_display_ops = {
  443. .create_connector = vidi_create_connector,
  444. };
  445. static struct exynos_drm_display vidi_display = {
  446. .type = EXYNOS_DISPLAY_TYPE_VIDI,
  447. .ops = &vidi_display_ops,
  448. };
  449. static int vidi_subdrv_probe(struct drm_device *drm_dev, struct device *dev)
  450. {
  451. struct exynos_drm_manager *mgr = get_vidi_mgr(dev);
  452. struct vidi_context *ctx = mgr->ctx;
  453. struct drm_crtc *crtc = ctx->crtc;
  454. int ret;
  455. vidi_mgr_initialize(mgr, drm_dev);
  456. ret = exynos_drm_crtc_create(&vidi_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, &vidi_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 int vidi_probe(struct platform_device *pdev)
  470. {
  471. struct exynos_drm_subdrv *subdrv;
  472. struct vidi_context *ctx;
  473. int ret;
  474. ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
  475. if (!ctx)
  476. return -ENOMEM;
  477. ctx->default_win = 0;
  478. INIT_WORK(&ctx->work, vidi_fake_vblank_handler);
  479. vidi_manager.ctx = ctx;
  480. vidi_display.ctx = ctx;
  481. mutex_init(&ctx->lock);
  482. platform_set_drvdata(pdev, &vidi_manager);
  483. subdrv = &ctx->subdrv;
  484. subdrv->dev = &pdev->dev;
  485. subdrv->probe = vidi_subdrv_probe;
  486. ret = exynos_drm_subdrv_register(subdrv);
  487. if (ret < 0) {
  488. dev_err(&pdev->dev, "failed to register drm vidi device\n");
  489. return ret;
  490. }
  491. ret = device_create_file(&pdev->dev, &dev_attr_connection);
  492. if (ret < 0) {
  493. exynos_drm_subdrv_unregister(subdrv);
  494. DRM_INFO("failed to create connection sysfs.\n");
  495. }
  496. return 0;
  497. }
  498. static int vidi_remove(struct platform_device *pdev)
  499. {
  500. struct exynos_drm_manager *mgr = platform_get_drvdata(pdev);
  501. struct vidi_context *ctx = mgr->ctx;
  502. if (ctx->raw_edid != (struct edid *)fake_edid_info) {
  503. kfree(ctx->raw_edid);
  504. ctx->raw_edid = NULL;
  505. return -EINVAL;
  506. }
  507. return 0;
  508. }
  509. struct platform_driver vidi_driver = {
  510. .probe = vidi_probe,
  511. .remove = vidi_remove,
  512. .driver = {
  513. .name = "exynos-drm-vidi",
  514. .owner = THIS_MODULE,
  515. },
  516. };
  517. int exynos_drm_probe_vidi(void)
  518. {
  519. struct platform_device *pdev;
  520. int ret;
  521. pdev = platform_device_register_simple("exynos-drm-vidi", -1, NULL, 0);
  522. if (IS_ERR(pdev))
  523. return PTR_ERR(pdev);
  524. ret = platform_driver_register(&vidi_driver);
  525. if (ret) {
  526. platform_device_unregister(pdev);
  527. return ret;
  528. }
  529. return ret;
  530. }
  531. void exynos_drm_remove_vidi(void)
  532. {
  533. struct vidi_context *ctx = vidi_manager.ctx;
  534. struct exynos_drm_subdrv *subdrv = &ctx->subdrv;
  535. struct platform_device *pdev = to_platform_device(subdrv->dev);
  536. platform_driver_unregister(&vidi_driver);
  537. platform_device_unregister(pdev);
  538. }