tilcdc_drv.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. /*
  2. * Copyright (C) 2012 Texas Instruments
  3. * Author: Rob Clark <robdclark@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published by
  7. * the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /* LCDC DRM driver, based on da8xx-fb */
  18. #include <linux/component.h>
  19. #include <linux/pinctrl/consumer.h>
  20. #include <linux/suspend.h>
  21. #include <drm/drm_atomic.h>
  22. #include <drm/drm_atomic_helper.h>
  23. #include <drm/drm_fb_helper.h>
  24. #include "tilcdc_drv.h"
  25. #include "tilcdc_regs.h"
  26. #include "tilcdc_tfp410.h"
  27. #include "tilcdc_panel.h"
  28. #include "tilcdc_external.h"
  29. static LIST_HEAD(module_list);
  30. static const u32 tilcdc_rev1_formats[] = { DRM_FORMAT_RGB565 };
  31. static const u32 tilcdc_straight_formats[] = { DRM_FORMAT_RGB565,
  32. DRM_FORMAT_BGR888,
  33. DRM_FORMAT_XBGR8888 };
  34. static const u32 tilcdc_crossed_formats[] = { DRM_FORMAT_BGR565,
  35. DRM_FORMAT_RGB888,
  36. DRM_FORMAT_XRGB8888 };
  37. static const u32 tilcdc_legacy_formats[] = { DRM_FORMAT_RGB565,
  38. DRM_FORMAT_RGB888,
  39. DRM_FORMAT_XRGB8888 };
  40. void tilcdc_module_init(struct tilcdc_module *mod, const char *name,
  41. const struct tilcdc_module_ops *funcs)
  42. {
  43. mod->name = name;
  44. mod->funcs = funcs;
  45. INIT_LIST_HEAD(&mod->list);
  46. list_add(&mod->list, &module_list);
  47. }
  48. void tilcdc_module_cleanup(struct tilcdc_module *mod)
  49. {
  50. list_del(&mod->list);
  51. }
  52. static struct of_device_id tilcdc_of_match[];
  53. static struct drm_framebuffer *tilcdc_fb_create(struct drm_device *dev,
  54. struct drm_file *file_priv, const struct drm_mode_fb_cmd2 *mode_cmd)
  55. {
  56. return drm_fb_cma_create(dev, file_priv, mode_cmd);
  57. }
  58. static void tilcdc_fb_output_poll_changed(struct drm_device *dev)
  59. {
  60. struct tilcdc_drm_private *priv = dev->dev_private;
  61. drm_fbdev_cma_hotplug_event(priv->fbdev);
  62. }
  63. static int tilcdc_atomic_check(struct drm_device *dev,
  64. struct drm_atomic_state *state)
  65. {
  66. int ret;
  67. ret = drm_atomic_helper_check_modeset(dev, state);
  68. if (ret)
  69. return ret;
  70. ret = drm_atomic_helper_check_planes(dev, state);
  71. if (ret)
  72. return ret;
  73. /*
  74. * tilcdc ->atomic_check can update ->mode_changed if pixel format
  75. * changes, hence will we check modeset changes again.
  76. */
  77. ret = drm_atomic_helper_check_modeset(dev, state);
  78. if (ret)
  79. return ret;
  80. return ret;
  81. }
  82. static int tilcdc_commit(struct drm_device *dev,
  83. struct drm_atomic_state *state,
  84. bool async)
  85. {
  86. int ret;
  87. ret = drm_atomic_helper_prepare_planes(dev, state);
  88. if (ret)
  89. return ret;
  90. ret = drm_atomic_helper_swap_state(state, true);
  91. if (ret) {
  92. drm_atomic_helper_cleanup_planes(dev, state);
  93. return ret;
  94. }
  95. /*
  96. * Everything below can be run asynchronously without the need to grab
  97. * any modeset locks at all under one condition: It must be guaranteed
  98. * that the asynchronous work has either been cancelled (if the driver
  99. * supports it, which at least requires that the framebuffers get
  100. * cleaned up with drm_atomic_helper_cleanup_planes()) or completed
  101. * before the new state gets committed on the software side with
  102. * drm_atomic_helper_swap_state().
  103. *
  104. * This scheme allows new atomic state updates to be prepared and
  105. * checked in parallel to the asynchronous completion of the previous
  106. * update. Which is important since compositors need to figure out the
  107. * composition of the next frame right after having submitted the
  108. * current layout.
  109. */
  110. drm_atomic_helper_commit_modeset_disables(dev, state);
  111. drm_atomic_helper_commit_planes(dev, state, 0);
  112. drm_atomic_helper_commit_modeset_enables(dev, state);
  113. drm_atomic_helper_wait_for_vblanks(dev, state);
  114. drm_atomic_helper_cleanup_planes(dev, state);
  115. return 0;
  116. }
  117. static const struct drm_mode_config_funcs mode_config_funcs = {
  118. .fb_create = tilcdc_fb_create,
  119. .output_poll_changed = tilcdc_fb_output_poll_changed,
  120. .atomic_check = tilcdc_atomic_check,
  121. .atomic_commit = tilcdc_commit,
  122. };
  123. static void modeset_init(struct drm_device *dev)
  124. {
  125. struct tilcdc_drm_private *priv = dev->dev_private;
  126. struct tilcdc_module *mod;
  127. list_for_each_entry(mod, &module_list, list) {
  128. DBG("loading module: %s", mod->name);
  129. mod->funcs->modeset_init(mod, dev);
  130. }
  131. dev->mode_config.min_width = 0;
  132. dev->mode_config.min_height = 0;
  133. dev->mode_config.max_width = tilcdc_crtc_max_width(priv->crtc);
  134. dev->mode_config.max_height = 2048;
  135. dev->mode_config.funcs = &mode_config_funcs;
  136. }
  137. #ifdef CONFIG_CPU_FREQ
  138. static int cpufreq_transition(struct notifier_block *nb,
  139. unsigned long val, void *data)
  140. {
  141. struct tilcdc_drm_private *priv = container_of(nb,
  142. struct tilcdc_drm_private, freq_transition);
  143. if (val == CPUFREQ_POSTCHANGE)
  144. tilcdc_crtc_update_clk(priv->crtc);
  145. return 0;
  146. }
  147. #endif
  148. /*
  149. * DRM operations:
  150. */
  151. static void tilcdc_fini(struct drm_device *dev)
  152. {
  153. struct tilcdc_drm_private *priv = dev->dev_private;
  154. if (priv->crtc)
  155. tilcdc_crtc_shutdown(priv->crtc);
  156. if (priv->is_registered)
  157. drm_dev_unregister(dev);
  158. drm_kms_helper_poll_fini(dev);
  159. if (priv->fbdev)
  160. drm_fbdev_cma_fini(priv->fbdev);
  161. drm_irq_uninstall(dev);
  162. drm_mode_config_cleanup(dev);
  163. tilcdc_remove_external_device(dev);
  164. #ifdef CONFIG_CPU_FREQ
  165. if (priv->freq_transition.notifier_call)
  166. cpufreq_unregister_notifier(&priv->freq_transition,
  167. CPUFREQ_TRANSITION_NOTIFIER);
  168. #endif
  169. if (priv->clk)
  170. clk_put(priv->clk);
  171. if (priv->mmio)
  172. iounmap(priv->mmio);
  173. if (priv->wq) {
  174. flush_workqueue(priv->wq);
  175. destroy_workqueue(priv->wq);
  176. }
  177. dev->dev_private = NULL;
  178. pm_runtime_disable(dev->dev);
  179. drm_dev_unref(dev);
  180. }
  181. static int tilcdc_init(struct drm_driver *ddrv, struct device *dev)
  182. {
  183. struct drm_device *ddev;
  184. struct platform_device *pdev = to_platform_device(dev);
  185. struct device_node *node = dev->of_node;
  186. struct tilcdc_drm_private *priv;
  187. struct resource *res;
  188. u32 bpp = 0;
  189. int ret;
  190. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  191. if (!priv) {
  192. dev_err(dev, "failed to allocate private data\n");
  193. return -ENOMEM;
  194. }
  195. ddev = drm_dev_alloc(ddrv, dev);
  196. if (IS_ERR(ddev))
  197. return PTR_ERR(ddev);
  198. ddev->dev_private = priv;
  199. platform_set_drvdata(pdev, ddev);
  200. drm_mode_config_init(ddev);
  201. priv->is_componentized =
  202. tilcdc_get_external_components(dev, NULL) > 0;
  203. priv->wq = alloc_ordered_workqueue("tilcdc", 0);
  204. if (!priv->wq) {
  205. ret = -ENOMEM;
  206. goto init_failed;
  207. }
  208. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  209. if (!res) {
  210. dev_err(dev, "failed to get memory resource\n");
  211. ret = -EINVAL;
  212. goto init_failed;
  213. }
  214. priv->mmio = ioremap_nocache(res->start, resource_size(res));
  215. if (!priv->mmio) {
  216. dev_err(dev, "failed to ioremap\n");
  217. ret = -ENOMEM;
  218. goto init_failed;
  219. }
  220. priv->clk = clk_get(dev, "fck");
  221. if (IS_ERR(priv->clk)) {
  222. dev_err(dev, "failed to get functional clock\n");
  223. ret = -ENODEV;
  224. goto init_failed;
  225. }
  226. #ifdef CONFIG_CPU_FREQ
  227. priv->freq_transition.notifier_call = cpufreq_transition;
  228. ret = cpufreq_register_notifier(&priv->freq_transition,
  229. CPUFREQ_TRANSITION_NOTIFIER);
  230. if (ret) {
  231. dev_err(dev, "failed to register cpufreq notifier\n");
  232. priv->freq_transition.notifier_call = NULL;
  233. goto init_failed;
  234. }
  235. #endif
  236. if (of_property_read_u32(node, "max-bandwidth", &priv->max_bandwidth))
  237. priv->max_bandwidth = TILCDC_DEFAULT_MAX_BANDWIDTH;
  238. DBG("Maximum Bandwidth Value %d", priv->max_bandwidth);
  239. if (of_property_read_u32(node, "max-width", &priv->max_width))
  240. priv->max_width = TILCDC_DEFAULT_MAX_WIDTH;
  241. DBG("Maximum Horizontal Pixel Width Value %dpixels", priv->max_width);
  242. if (of_property_read_u32(node, "max-pixelclock",
  243. &priv->max_pixelclock))
  244. priv->max_pixelclock = TILCDC_DEFAULT_MAX_PIXELCLOCK;
  245. DBG("Maximum Pixel Clock Value %dKHz", priv->max_pixelclock);
  246. pm_runtime_enable(dev);
  247. /* Determine LCD IP Version */
  248. pm_runtime_get_sync(dev);
  249. switch (tilcdc_read(ddev, LCDC_PID_REG)) {
  250. case 0x4c100102:
  251. priv->rev = 1;
  252. break;
  253. case 0x4f200800:
  254. case 0x4f201000:
  255. priv->rev = 2;
  256. break;
  257. default:
  258. dev_warn(dev, "Unknown PID Reg value 0x%08x, "
  259. "defaulting to LCD revision 1\n",
  260. tilcdc_read(ddev, LCDC_PID_REG));
  261. priv->rev = 1;
  262. break;
  263. }
  264. pm_runtime_put_sync(dev);
  265. if (priv->rev == 1) {
  266. DBG("Revision 1 LCDC supports only RGB565 format");
  267. priv->pixelformats = tilcdc_rev1_formats;
  268. priv->num_pixelformats = ARRAY_SIZE(tilcdc_rev1_formats);
  269. bpp = 16;
  270. } else {
  271. const char *str = "\0";
  272. of_property_read_string(node, "blue-and-red-wiring", &str);
  273. if (0 == strcmp(str, "crossed")) {
  274. DBG("Configured for crossed blue and red wires");
  275. priv->pixelformats = tilcdc_crossed_formats;
  276. priv->num_pixelformats =
  277. ARRAY_SIZE(tilcdc_crossed_formats);
  278. bpp = 32; /* Choose bpp with RGB support for fbdef */
  279. } else if (0 == strcmp(str, "straight")) {
  280. DBG("Configured for straight blue and red wires");
  281. priv->pixelformats = tilcdc_straight_formats;
  282. priv->num_pixelformats =
  283. ARRAY_SIZE(tilcdc_straight_formats);
  284. bpp = 16; /* Choose bpp with RGB support for fbdef */
  285. } else {
  286. DBG("Blue and red wiring '%s' unknown, use legacy mode",
  287. str);
  288. priv->pixelformats = tilcdc_legacy_formats;
  289. priv->num_pixelformats =
  290. ARRAY_SIZE(tilcdc_legacy_formats);
  291. bpp = 16; /* This is just a guess */
  292. }
  293. }
  294. ret = tilcdc_crtc_create(ddev);
  295. if (ret < 0) {
  296. dev_err(dev, "failed to create crtc\n");
  297. goto init_failed;
  298. }
  299. modeset_init(ddev);
  300. if (priv->is_componentized) {
  301. ret = component_bind_all(dev, ddev);
  302. if (ret < 0)
  303. goto init_failed;
  304. ret = tilcdc_add_component_encoder(ddev);
  305. if (ret < 0)
  306. goto init_failed;
  307. } else {
  308. ret = tilcdc_attach_external_device(ddev);
  309. if (ret)
  310. goto init_failed;
  311. }
  312. if (!priv->external_connector &&
  313. ((priv->num_encoders == 0) || (priv->num_connectors == 0))) {
  314. dev_err(dev, "no encoders/connectors found\n");
  315. ret = -ENXIO;
  316. goto init_failed;
  317. }
  318. ret = drm_vblank_init(ddev, 1);
  319. if (ret < 0) {
  320. dev_err(dev, "failed to initialize vblank\n");
  321. goto init_failed;
  322. }
  323. ret = drm_irq_install(ddev, platform_get_irq(pdev, 0));
  324. if (ret < 0) {
  325. dev_err(dev, "failed to install IRQ handler\n");
  326. goto init_failed;
  327. }
  328. drm_mode_config_reset(ddev);
  329. priv->fbdev = drm_fbdev_cma_init(ddev, bpp,
  330. ddev->mode_config.num_connector);
  331. if (IS_ERR(priv->fbdev)) {
  332. ret = PTR_ERR(priv->fbdev);
  333. goto init_failed;
  334. }
  335. drm_kms_helper_poll_init(ddev);
  336. ret = drm_dev_register(ddev, 0);
  337. if (ret)
  338. goto init_failed;
  339. priv->is_registered = true;
  340. return 0;
  341. init_failed:
  342. tilcdc_fini(ddev);
  343. return ret;
  344. }
  345. static void tilcdc_lastclose(struct drm_device *dev)
  346. {
  347. struct tilcdc_drm_private *priv = dev->dev_private;
  348. drm_fbdev_cma_restore_mode(priv->fbdev);
  349. }
  350. static irqreturn_t tilcdc_irq(int irq, void *arg)
  351. {
  352. struct drm_device *dev = arg;
  353. struct tilcdc_drm_private *priv = dev->dev_private;
  354. return tilcdc_crtc_irq(priv->crtc);
  355. }
  356. #if defined(CONFIG_DEBUG_FS)
  357. static const struct {
  358. const char *name;
  359. uint8_t rev;
  360. uint8_t save;
  361. uint32_t reg;
  362. } registers[] = {
  363. #define REG(rev, save, reg) { #reg, rev, save, reg }
  364. /* exists in revision 1: */
  365. REG(1, false, LCDC_PID_REG),
  366. REG(1, true, LCDC_CTRL_REG),
  367. REG(1, false, LCDC_STAT_REG),
  368. REG(1, true, LCDC_RASTER_CTRL_REG),
  369. REG(1, true, LCDC_RASTER_TIMING_0_REG),
  370. REG(1, true, LCDC_RASTER_TIMING_1_REG),
  371. REG(1, true, LCDC_RASTER_TIMING_2_REG),
  372. REG(1, true, LCDC_DMA_CTRL_REG),
  373. REG(1, true, LCDC_DMA_FB_BASE_ADDR_0_REG),
  374. REG(1, true, LCDC_DMA_FB_CEILING_ADDR_0_REG),
  375. REG(1, true, LCDC_DMA_FB_BASE_ADDR_1_REG),
  376. REG(1, true, LCDC_DMA_FB_CEILING_ADDR_1_REG),
  377. /* new in revision 2: */
  378. REG(2, false, LCDC_RAW_STAT_REG),
  379. REG(2, false, LCDC_MASKED_STAT_REG),
  380. REG(2, true, LCDC_INT_ENABLE_SET_REG),
  381. REG(2, false, LCDC_INT_ENABLE_CLR_REG),
  382. REG(2, false, LCDC_END_OF_INT_IND_REG),
  383. REG(2, true, LCDC_CLK_ENABLE_REG),
  384. #undef REG
  385. };
  386. #endif
  387. #ifdef CONFIG_DEBUG_FS
  388. static int tilcdc_regs_show(struct seq_file *m, void *arg)
  389. {
  390. struct drm_info_node *node = (struct drm_info_node *) m->private;
  391. struct drm_device *dev = node->minor->dev;
  392. struct tilcdc_drm_private *priv = dev->dev_private;
  393. unsigned i;
  394. pm_runtime_get_sync(dev->dev);
  395. seq_printf(m, "revision: %d\n", priv->rev);
  396. for (i = 0; i < ARRAY_SIZE(registers); i++)
  397. if (priv->rev >= registers[i].rev)
  398. seq_printf(m, "%s:\t %08x\n", registers[i].name,
  399. tilcdc_read(dev, registers[i].reg));
  400. pm_runtime_put_sync(dev->dev);
  401. return 0;
  402. }
  403. static int tilcdc_mm_show(struct seq_file *m, void *arg)
  404. {
  405. struct drm_info_node *node = (struct drm_info_node *) m->private;
  406. struct drm_device *dev = node->minor->dev;
  407. struct drm_printer p = drm_seq_file_printer(m);
  408. drm_mm_print(&dev->vma_offset_manager->vm_addr_space_mm, &p);
  409. return 0;
  410. }
  411. static struct drm_info_list tilcdc_debugfs_list[] = {
  412. { "regs", tilcdc_regs_show, 0 },
  413. { "mm", tilcdc_mm_show, 0 },
  414. { "fb", drm_fb_cma_debugfs_show, 0 },
  415. };
  416. static int tilcdc_debugfs_init(struct drm_minor *minor)
  417. {
  418. struct drm_device *dev = minor->dev;
  419. struct tilcdc_module *mod;
  420. int ret;
  421. ret = drm_debugfs_create_files(tilcdc_debugfs_list,
  422. ARRAY_SIZE(tilcdc_debugfs_list),
  423. minor->debugfs_root, minor);
  424. list_for_each_entry(mod, &module_list, list)
  425. if (mod->funcs->debugfs_init)
  426. mod->funcs->debugfs_init(mod, minor);
  427. if (ret) {
  428. dev_err(dev->dev, "could not install tilcdc_debugfs_list\n");
  429. return ret;
  430. }
  431. return ret;
  432. }
  433. #endif
  434. DEFINE_DRM_GEM_CMA_FOPS(fops);
  435. static struct drm_driver tilcdc_driver = {
  436. .driver_features = (DRIVER_HAVE_IRQ | DRIVER_GEM | DRIVER_MODESET |
  437. DRIVER_PRIME | DRIVER_ATOMIC),
  438. .lastclose = tilcdc_lastclose,
  439. .irq_handler = tilcdc_irq,
  440. .gem_free_object_unlocked = drm_gem_cma_free_object,
  441. .gem_vm_ops = &drm_gem_cma_vm_ops,
  442. .dumb_create = drm_gem_cma_dumb_create,
  443. .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
  444. .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
  445. .gem_prime_import = drm_gem_prime_import,
  446. .gem_prime_export = drm_gem_prime_export,
  447. .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table,
  448. .gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table,
  449. .gem_prime_vmap = drm_gem_cma_prime_vmap,
  450. .gem_prime_vunmap = drm_gem_cma_prime_vunmap,
  451. .gem_prime_mmap = drm_gem_cma_prime_mmap,
  452. #ifdef CONFIG_DEBUG_FS
  453. .debugfs_init = tilcdc_debugfs_init,
  454. #endif
  455. .fops = &fops,
  456. .name = "tilcdc",
  457. .desc = "TI LCD Controller DRM",
  458. .date = "20121205",
  459. .major = 1,
  460. .minor = 0,
  461. };
  462. /*
  463. * Power management:
  464. */
  465. #ifdef CONFIG_PM_SLEEP
  466. static int tilcdc_pm_suspend(struct device *dev)
  467. {
  468. struct drm_device *ddev = dev_get_drvdata(dev);
  469. struct tilcdc_drm_private *priv = ddev->dev_private;
  470. priv->saved_state = drm_atomic_helper_suspend(ddev);
  471. /* Select sleep pin state */
  472. pinctrl_pm_select_sleep_state(dev);
  473. return 0;
  474. }
  475. static int tilcdc_pm_resume(struct device *dev)
  476. {
  477. struct drm_device *ddev = dev_get_drvdata(dev);
  478. struct tilcdc_drm_private *priv = ddev->dev_private;
  479. int ret = 0;
  480. /* Select default pin state */
  481. pinctrl_pm_select_default_state(dev);
  482. if (priv->saved_state)
  483. ret = drm_atomic_helper_resume(ddev, priv->saved_state);
  484. return ret;
  485. }
  486. #endif
  487. static const struct dev_pm_ops tilcdc_pm_ops = {
  488. SET_SYSTEM_SLEEP_PM_OPS(tilcdc_pm_suspend, tilcdc_pm_resume)
  489. };
  490. /*
  491. * Platform driver:
  492. */
  493. static int tilcdc_bind(struct device *dev)
  494. {
  495. return tilcdc_init(&tilcdc_driver, dev);
  496. }
  497. static void tilcdc_unbind(struct device *dev)
  498. {
  499. struct drm_device *ddev = dev_get_drvdata(dev);
  500. /* Check if a subcomponent has already triggered the unloading. */
  501. if (!ddev->dev_private)
  502. return;
  503. tilcdc_fini(dev_get_drvdata(dev));
  504. }
  505. static const struct component_master_ops tilcdc_comp_ops = {
  506. .bind = tilcdc_bind,
  507. .unbind = tilcdc_unbind,
  508. };
  509. static int tilcdc_pdev_probe(struct platform_device *pdev)
  510. {
  511. struct component_match *match = NULL;
  512. int ret;
  513. /* bail out early if no DT data: */
  514. if (!pdev->dev.of_node) {
  515. dev_err(&pdev->dev, "device-tree data is missing\n");
  516. return -ENXIO;
  517. }
  518. ret = tilcdc_get_external_components(&pdev->dev, &match);
  519. if (ret < 0)
  520. return ret;
  521. else if (ret == 0)
  522. return tilcdc_init(&tilcdc_driver, &pdev->dev);
  523. else
  524. return component_master_add_with_match(&pdev->dev,
  525. &tilcdc_comp_ops,
  526. match);
  527. }
  528. static int tilcdc_pdev_remove(struct platform_device *pdev)
  529. {
  530. int ret;
  531. ret = tilcdc_get_external_components(&pdev->dev, NULL);
  532. if (ret < 0)
  533. return ret;
  534. else if (ret == 0)
  535. tilcdc_fini(platform_get_drvdata(pdev));
  536. else
  537. component_master_del(&pdev->dev, &tilcdc_comp_ops);
  538. return 0;
  539. }
  540. static struct of_device_id tilcdc_of_match[] = {
  541. { .compatible = "ti,am33xx-tilcdc", },
  542. { .compatible = "ti,da850-tilcdc", },
  543. { },
  544. };
  545. MODULE_DEVICE_TABLE(of, tilcdc_of_match);
  546. static struct platform_driver tilcdc_platform_driver = {
  547. .probe = tilcdc_pdev_probe,
  548. .remove = tilcdc_pdev_remove,
  549. .driver = {
  550. .name = "tilcdc",
  551. .pm = &tilcdc_pm_ops,
  552. .of_match_table = tilcdc_of_match,
  553. },
  554. };
  555. static int __init tilcdc_drm_init(void)
  556. {
  557. DBG("init");
  558. tilcdc_tfp410_init();
  559. tilcdc_panel_init();
  560. return platform_driver_register(&tilcdc_platform_driver);
  561. }
  562. static void __exit tilcdc_drm_fini(void)
  563. {
  564. DBG("fini");
  565. platform_driver_unregister(&tilcdc_platform_driver);
  566. tilcdc_panel_fini();
  567. tilcdc_tfp410_fini();
  568. }
  569. module_init(tilcdc_drm_init);
  570. module_exit(tilcdc_drm_fini);
  571. MODULE_AUTHOR("Rob Clark <robdclark@gmail.com");
  572. MODULE_DESCRIPTION("TI LCD Controller DRM Driver");
  573. MODULE_LICENSE("GPL");