tilcdc_drv.c 17 KB

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