tilcdc_drv.c 17 KB

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