tilcdc_drv.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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 "tilcdc_drv.h"
  19. #include "tilcdc_regs.h"
  20. #include "tilcdc_tfp410.h"
  21. #include "tilcdc_slave.h"
  22. #include "tilcdc_panel.h"
  23. #include "drm_fb_helper.h"
  24. static LIST_HEAD(module_list);
  25. static bool slave_probing;
  26. void tilcdc_module_init(struct tilcdc_module *mod, const char *name,
  27. const struct tilcdc_module_ops *funcs)
  28. {
  29. mod->name = name;
  30. mod->funcs = funcs;
  31. INIT_LIST_HEAD(&mod->list);
  32. list_add(&mod->list, &module_list);
  33. }
  34. void tilcdc_module_cleanup(struct tilcdc_module *mod)
  35. {
  36. list_del(&mod->list);
  37. }
  38. void tilcdc_slave_probedefer(bool defered)
  39. {
  40. slave_probing = defered;
  41. }
  42. static struct of_device_id tilcdc_of_match[];
  43. static struct drm_framebuffer *tilcdc_fb_create(struct drm_device *dev,
  44. struct drm_file *file_priv, struct drm_mode_fb_cmd2 *mode_cmd)
  45. {
  46. return drm_fb_cma_create(dev, file_priv, mode_cmd);
  47. }
  48. static void tilcdc_fb_output_poll_changed(struct drm_device *dev)
  49. {
  50. struct tilcdc_drm_private *priv = dev->dev_private;
  51. drm_fbdev_cma_hotplug_event(priv->fbdev);
  52. }
  53. static const struct drm_mode_config_funcs mode_config_funcs = {
  54. .fb_create = tilcdc_fb_create,
  55. .output_poll_changed = tilcdc_fb_output_poll_changed,
  56. };
  57. static int modeset_init(struct drm_device *dev)
  58. {
  59. struct tilcdc_drm_private *priv = dev->dev_private;
  60. struct tilcdc_module *mod;
  61. drm_mode_config_init(dev);
  62. priv->crtc = tilcdc_crtc_create(dev);
  63. list_for_each_entry(mod, &module_list, list) {
  64. DBG("loading module: %s", mod->name);
  65. mod->funcs->modeset_init(mod, dev);
  66. }
  67. if ((priv->num_encoders == 0) || (priv->num_connectors == 0)) {
  68. /* oh nos! */
  69. dev_err(dev->dev, "no encoders/connectors found\n");
  70. drm_mode_config_cleanup(dev);
  71. return -ENXIO;
  72. }
  73. dev->mode_config.min_width = 0;
  74. dev->mode_config.min_height = 0;
  75. dev->mode_config.max_width = tilcdc_crtc_max_width(priv->crtc);
  76. dev->mode_config.max_height = 2048;
  77. dev->mode_config.funcs = &mode_config_funcs;
  78. return 0;
  79. }
  80. #ifdef CONFIG_CPU_FREQ
  81. static int cpufreq_transition(struct notifier_block *nb,
  82. unsigned long val, void *data)
  83. {
  84. struct tilcdc_drm_private *priv = container_of(nb,
  85. struct tilcdc_drm_private, freq_transition);
  86. if (val == CPUFREQ_POSTCHANGE) {
  87. if (priv->lcd_fck_rate != clk_get_rate(priv->clk)) {
  88. priv->lcd_fck_rate = clk_get_rate(priv->clk);
  89. tilcdc_crtc_update_clk(priv->crtc);
  90. }
  91. }
  92. return 0;
  93. }
  94. #endif
  95. /*
  96. * DRM operations:
  97. */
  98. static int tilcdc_unload(struct drm_device *dev)
  99. {
  100. struct tilcdc_drm_private *priv = dev->dev_private;
  101. drm_fbdev_cma_fini(priv->fbdev);
  102. drm_kms_helper_poll_fini(dev);
  103. drm_mode_config_cleanup(dev);
  104. drm_vblank_cleanup(dev);
  105. pm_runtime_get_sync(dev->dev);
  106. drm_irq_uninstall(dev);
  107. pm_runtime_put_sync(dev->dev);
  108. #ifdef CONFIG_CPU_FREQ
  109. cpufreq_unregister_notifier(&priv->freq_transition,
  110. CPUFREQ_TRANSITION_NOTIFIER);
  111. #endif
  112. if (priv->clk)
  113. clk_put(priv->clk);
  114. if (priv->mmio)
  115. iounmap(priv->mmio);
  116. flush_workqueue(priv->wq);
  117. destroy_workqueue(priv->wq);
  118. dev->dev_private = NULL;
  119. pm_runtime_disable(dev->dev);
  120. kfree(priv);
  121. return 0;
  122. }
  123. static int tilcdc_load(struct drm_device *dev, unsigned long flags)
  124. {
  125. struct platform_device *pdev = dev->platformdev;
  126. struct device_node *node = pdev->dev.of_node;
  127. struct tilcdc_drm_private *priv;
  128. struct tilcdc_module *mod;
  129. struct resource *res;
  130. u32 bpp = 0;
  131. int ret;
  132. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  133. if (!priv) {
  134. dev_err(dev->dev, "failed to allocate private data\n");
  135. return -ENOMEM;
  136. }
  137. dev->dev_private = priv;
  138. priv->wq = alloc_ordered_workqueue("tilcdc", 0);
  139. if (!priv->wq) {
  140. ret = -ENOMEM;
  141. goto fail_free_priv;
  142. }
  143. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  144. if (!res) {
  145. dev_err(dev->dev, "failed to get memory resource\n");
  146. ret = -EINVAL;
  147. goto fail_free_wq;
  148. }
  149. priv->mmio = ioremap_nocache(res->start, resource_size(res));
  150. if (!priv->mmio) {
  151. dev_err(dev->dev, "failed to ioremap\n");
  152. ret = -ENOMEM;
  153. goto fail_free_wq;
  154. }
  155. priv->clk = clk_get(dev->dev, "fck");
  156. if (IS_ERR(priv->clk)) {
  157. dev_err(dev->dev, "failed to get functional clock\n");
  158. ret = -ENODEV;
  159. goto fail_iounmap;
  160. }
  161. priv->disp_clk = clk_get(dev->dev, "dpll_disp_ck");
  162. if (IS_ERR(priv->clk)) {
  163. dev_err(dev->dev, "failed to get display clock\n");
  164. ret = -ENODEV;
  165. goto fail_put_clk;
  166. }
  167. #ifdef CONFIG_CPU_FREQ
  168. priv->lcd_fck_rate = clk_get_rate(priv->clk);
  169. priv->freq_transition.notifier_call = cpufreq_transition;
  170. ret = cpufreq_register_notifier(&priv->freq_transition,
  171. CPUFREQ_TRANSITION_NOTIFIER);
  172. if (ret) {
  173. dev_err(dev->dev, "failed to register cpufreq notifier\n");
  174. goto fail_put_disp_clk;
  175. }
  176. #endif
  177. if (of_property_read_u32(node, "max-bandwidth", &priv->max_bandwidth))
  178. priv->max_bandwidth = TILCDC_DEFAULT_MAX_BANDWIDTH;
  179. DBG("Maximum Bandwidth Value %d", priv->max_bandwidth);
  180. if (of_property_read_u32(node, "ti,max-width", &priv->max_width))
  181. priv->max_width = TILCDC_DEFAULT_MAX_WIDTH;
  182. DBG("Maximum Horizontal Pixel Width Value %dpixels", priv->max_width);
  183. if (of_property_read_u32(node, "ti,max-pixelclock",
  184. &priv->max_pixelclock))
  185. priv->max_pixelclock = TILCDC_DEFAULT_MAX_PIXELCLOCK;
  186. DBG("Maximum Pixel Clock Value %dKHz", priv->max_pixelclock);
  187. pm_runtime_enable(dev->dev);
  188. /* Determine LCD IP Version */
  189. pm_runtime_get_sync(dev->dev);
  190. switch (tilcdc_read(dev, LCDC_PID_REG)) {
  191. case 0x4c100102:
  192. priv->rev = 1;
  193. break;
  194. case 0x4f200800:
  195. case 0x4f201000:
  196. priv->rev = 2;
  197. break;
  198. default:
  199. dev_warn(dev->dev, "Unknown PID Reg value 0x%08x, "
  200. "defaulting to LCD revision 1\n",
  201. tilcdc_read(dev, LCDC_PID_REG));
  202. priv->rev = 1;
  203. break;
  204. }
  205. pm_runtime_put_sync(dev->dev);
  206. ret = modeset_init(dev);
  207. if (ret < 0) {
  208. dev_err(dev->dev, "failed to initialize mode setting\n");
  209. goto fail_cpufreq_unregister;
  210. }
  211. ret = drm_vblank_init(dev, 1);
  212. if (ret < 0) {
  213. dev_err(dev->dev, "failed to initialize vblank\n");
  214. goto fail_mode_config_cleanup;
  215. }
  216. pm_runtime_get_sync(dev->dev);
  217. ret = drm_irq_install(dev, platform_get_irq(dev->platformdev, 0));
  218. pm_runtime_put_sync(dev->dev);
  219. if (ret < 0) {
  220. dev_err(dev->dev, "failed to install IRQ handler\n");
  221. goto fail_vblank_cleanup;
  222. }
  223. platform_set_drvdata(pdev, dev);
  224. list_for_each_entry(mod, &module_list, list) {
  225. DBG("%s: preferred_bpp: %d", mod->name, mod->preferred_bpp);
  226. bpp = mod->preferred_bpp;
  227. if (bpp > 0)
  228. break;
  229. }
  230. priv->fbdev = drm_fbdev_cma_init(dev, bpp,
  231. dev->mode_config.num_crtc,
  232. dev->mode_config.num_connector);
  233. if (IS_ERR(priv->fbdev)) {
  234. ret = PTR_ERR(priv->fbdev);
  235. goto fail_irq_uninstall;
  236. }
  237. drm_kms_helper_poll_init(dev);
  238. return 0;
  239. fail_irq_uninstall:
  240. pm_runtime_get_sync(dev->dev);
  241. drm_irq_uninstall(dev);
  242. pm_runtime_put_sync(dev->dev);
  243. fail_vblank_cleanup:
  244. drm_vblank_cleanup(dev);
  245. fail_mode_config_cleanup:
  246. drm_mode_config_cleanup(dev);
  247. fail_cpufreq_unregister:
  248. pm_runtime_disable(dev->dev);
  249. #ifdef CONFIG_CPU_FREQ
  250. cpufreq_unregister_notifier(&priv->freq_transition,
  251. CPUFREQ_TRANSITION_NOTIFIER);
  252. fail_put_disp_clk:
  253. clk_put(priv->disp_clk);
  254. #endif
  255. fail_put_clk:
  256. clk_put(priv->clk);
  257. fail_iounmap:
  258. iounmap(priv->mmio);
  259. fail_free_wq:
  260. flush_workqueue(priv->wq);
  261. destroy_workqueue(priv->wq);
  262. fail_free_priv:
  263. dev->dev_private = NULL;
  264. kfree(priv);
  265. return ret;
  266. }
  267. static void tilcdc_preclose(struct drm_device *dev, struct drm_file *file)
  268. {
  269. struct tilcdc_drm_private *priv = dev->dev_private;
  270. tilcdc_crtc_cancel_page_flip(priv->crtc, file);
  271. }
  272. static void tilcdc_lastclose(struct drm_device *dev)
  273. {
  274. struct tilcdc_drm_private *priv = dev->dev_private;
  275. drm_fbdev_cma_restore_mode(priv->fbdev);
  276. }
  277. static irqreturn_t tilcdc_irq(int irq, void *arg)
  278. {
  279. struct drm_device *dev = arg;
  280. struct tilcdc_drm_private *priv = dev->dev_private;
  281. return tilcdc_crtc_irq(priv->crtc);
  282. }
  283. static void tilcdc_irq_preinstall(struct drm_device *dev)
  284. {
  285. tilcdc_clear_irqstatus(dev, 0xffffffff);
  286. }
  287. static int tilcdc_irq_postinstall(struct drm_device *dev)
  288. {
  289. struct tilcdc_drm_private *priv = dev->dev_private;
  290. /* enable FIFO underflow irq: */
  291. if (priv->rev == 1)
  292. tilcdc_set(dev, LCDC_RASTER_CTRL_REG, LCDC_V1_UNDERFLOW_INT_ENA);
  293. else
  294. tilcdc_set(dev, LCDC_INT_ENABLE_SET_REG, LCDC_V2_UNDERFLOW_INT_ENA);
  295. return 0;
  296. }
  297. static void tilcdc_irq_uninstall(struct drm_device *dev)
  298. {
  299. struct tilcdc_drm_private *priv = dev->dev_private;
  300. /* disable irqs that we might have enabled: */
  301. if (priv->rev == 1) {
  302. tilcdc_clear(dev, LCDC_RASTER_CTRL_REG,
  303. LCDC_V1_UNDERFLOW_INT_ENA | LCDC_V1_PL_INT_ENA);
  304. tilcdc_clear(dev, LCDC_DMA_CTRL_REG, LCDC_V1_END_OF_FRAME_INT_ENA);
  305. } else {
  306. tilcdc_clear(dev, LCDC_INT_ENABLE_SET_REG,
  307. LCDC_V2_UNDERFLOW_INT_ENA | LCDC_V2_PL_INT_ENA |
  308. LCDC_V2_END_OF_FRAME0_INT_ENA | LCDC_V2_END_OF_FRAME1_INT_ENA |
  309. LCDC_FRAME_DONE);
  310. }
  311. }
  312. static void enable_vblank(struct drm_device *dev, bool enable)
  313. {
  314. struct tilcdc_drm_private *priv = dev->dev_private;
  315. u32 reg, mask;
  316. if (priv->rev == 1) {
  317. reg = LCDC_DMA_CTRL_REG;
  318. mask = LCDC_V1_END_OF_FRAME_INT_ENA;
  319. } else {
  320. reg = LCDC_INT_ENABLE_SET_REG;
  321. mask = LCDC_V2_END_OF_FRAME0_INT_ENA |
  322. LCDC_V2_END_OF_FRAME1_INT_ENA | LCDC_FRAME_DONE;
  323. }
  324. if (enable)
  325. tilcdc_set(dev, reg, mask);
  326. else
  327. tilcdc_clear(dev, reg, mask);
  328. }
  329. static int tilcdc_enable_vblank(struct drm_device *dev, int crtc)
  330. {
  331. enable_vblank(dev, true);
  332. return 0;
  333. }
  334. static void tilcdc_disable_vblank(struct drm_device *dev, int crtc)
  335. {
  336. enable_vblank(dev, false);
  337. }
  338. #if defined(CONFIG_DEBUG_FS) || defined(CONFIG_PM_SLEEP)
  339. static const struct {
  340. const char *name;
  341. uint8_t rev;
  342. uint8_t save;
  343. uint32_t reg;
  344. } registers[] = {
  345. #define REG(rev, save, reg) { #reg, rev, save, reg }
  346. /* exists in revision 1: */
  347. REG(1, false, LCDC_PID_REG),
  348. REG(1, true, LCDC_CTRL_REG),
  349. REG(1, false, LCDC_STAT_REG),
  350. REG(1, true, LCDC_RASTER_CTRL_REG),
  351. REG(1, true, LCDC_RASTER_TIMING_0_REG),
  352. REG(1, true, LCDC_RASTER_TIMING_1_REG),
  353. REG(1, true, LCDC_RASTER_TIMING_2_REG),
  354. REG(1, true, LCDC_DMA_CTRL_REG),
  355. REG(1, true, LCDC_DMA_FB_BASE_ADDR_0_REG),
  356. REG(1, true, LCDC_DMA_FB_CEILING_ADDR_0_REG),
  357. REG(1, true, LCDC_DMA_FB_BASE_ADDR_1_REG),
  358. REG(1, true, LCDC_DMA_FB_CEILING_ADDR_1_REG),
  359. /* new in revision 2: */
  360. REG(2, false, LCDC_RAW_STAT_REG),
  361. REG(2, false, LCDC_MASKED_STAT_REG),
  362. REG(2, false, LCDC_INT_ENABLE_SET_REG),
  363. REG(2, false, LCDC_INT_ENABLE_CLR_REG),
  364. REG(2, false, LCDC_END_OF_INT_IND_REG),
  365. REG(2, true, LCDC_CLK_ENABLE_REG),
  366. REG(2, true, LCDC_INT_ENABLE_SET_REG),
  367. #undef REG
  368. };
  369. #endif
  370. #ifdef CONFIG_DEBUG_FS
  371. static int tilcdc_regs_show(struct seq_file *m, void *arg)
  372. {
  373. struct drm_info_node *node = (struct drm_info_node *) m->private;
  374. struct drm_device *dev = node->minor->dev;
  375. struct tilcdc_drm_private *priv = dev->dev_private;
  376. unsigned i;
  377. pm_runtime_get_sync(dev->dev);
  378. seq_printf(m, "revision: %d\n", priv->rev);
  379. for (i = 0; i < ARRAY_SIZE(registers); i++)
  380. if (priv->rev >= registers[i].rev)
  381. seq_printf(m, "%s:\t %08x\n", registers[i].name,
  382. tilcdc_read(dev, registers[i].reg));
  383. pm_runtime_put_sync(dev->dev);
  384. return 0;
  385. }
  386. static int tilcdc_mm_show(struct seq_file *m, void *arg)
  387. {
  388. struct drm_info_node *node = (struct drm_info_node *) m->private;
  389. struct drm_device *dev = node->minor->dev;
  390. return drm_mm_dump_table(m, &dev->vma_offset_manager->vm_addr_space_mm);
  391. }
  392. static struct drm_info_list tilcdc_debugfs_list[] = {
  393. { "regs", tilcdc_regs_show, 0 },
  394. { "mm", tilcdc_mm_show, 0 },
  395. { "fb", drm_fb_cma_debugfs_show, 0 },
  396. };
  397. static int tilcdc_debugfs_init(struct drm_minor *minor)
  398. {
  399. struct drm_device *dev = minor->dev;
  400. struct tilcdc_module *mod;
  401. int ret;
  402. ret = drm_debugfs_create_files(tilcdc_debugfs_list,
  403. ARRAY_SIZE(tilcdc_debugfs_list),
  404. minor->debugfs_root, minor);
  405. list_for_each_entry(mod, &module_list, list)
  406. if (mod->funcs->debugfs_init)
  407. mod->funcs->debugfs_init(mod, minor);
  408. if (ret) {
  409. dev_err(dev->dev, "could not install tilcdc_debugfs_list\n");
  410. return ret;
  411. }
  412. return ret;
  413. }
  414. static void tilcdc_debugfs_cleanup(struct drm_minor *minor)
  415. {
  416. struct tilcdc_module *mod;
  417. drm_debugfs_remove_files(tilcdc_debugfs_list,
  418. ARRAY_SIZE(tilcdc_debugfs_list), minor);
  419. list_for_each_entry(mod, &module_list, list)
  420. if (mod->funcs->debugfs_cleanup)
  421. mod->funcs->debugfs_cleanup(mod, minor);
  422. }
  423. #endif
  424. static const struct file_operations fops = {
  425. .owner = THIS_MODULE,
  426. .open = drm_open,
  427. .release = drm_release,
  428. .unlocked_ioctl = drm_ioctl,
  429. #ifdef CONFIG_COMPAT
  430. .compat_ioctl = drm_compat_ioctl,
  431. #endif
  432. .poll = drm_poll,
  433. .read = drm_read,
  434. .llseek = no_llseek,
  435. .mmap = drm_gem_cma_mmap,
  436. };
  437. static struct drm_driver tilcdc_driver = {
  438. .driver_features = DRIVER_HAVE_IRQ | DRIVER_GEM | DRIVER_MODESET,
  439. .load = tilcdc_load,
  440. .unload = tilcdc_unload,
  441. .preclose = tilcdc_preclose,
  442. .lastclose = tilcdc_lastclose,
  443. .set_busid = drm_platform_set_busid,
  444. .irq_handler = tilcdc_irq,
  445. .irq_preinstall = tilcdc_irq_preinstall,
  446. .irq_postinstall = tilcdc_irq_postinstall,
  447. .irq_uninstall = tilcdc_irq_uninstall,
  448. .get_vblank_counter = drm_vblank_count,
  449. .enable_vblank = tilcdc_enable_vblank,
  450. .disable_vblank = tilcdc_disable_vblank,
  451. .gem_free_object = drm_gem_cma_free_object,
  452. .gem_vm_ops = &drm_gem_cma_vm_ops,
  453. .dumb_create = drm_gem_cma_dumb_create,
  454. .dumb_map_offset = drm_gem_cma_dumb_map_offset,
  455. .dumb_destroy = drm_gem_dumb_destroy,
  456. #ifdef CONFIG_DEBUG_FS
  457. .debugfs_init = tilcdc_debugfs_init,
  458. .debugfs_cleanup = tilcdc_debugfs_cleanup,
  459. #endif
  460. .fops = &fops,
  461. .name = "tilcdc",
  462. .desc = "TI LCD Controller DRM",
  463. .date = "20121205",
  464. .major = 1,
  465. .minor = 0,
  466. };
  467. /*
  468. * Power management:
  469. */
  470. #ifdef CONFIG_PM_SLEEP
  471. static int tilcdc_pm_suspend(struct device *dev)
  472. {
  473. struct drm_device *ddev = dev_get_drvdata(dev);
  474. struct tilcdc_drm_private *priv = ddev->dev_private;
  475. unsigned i, n = 0;
  476. drm_kms_helper_poll_disable(ddev);
  477. /* Save register state: */
  478. for (i = 0; i < ARRAY_SIZE(registers); i++)
  479. if (registers[i].save && (priv->rev >= registers[i].rev))
  480. priv->saved_register[n++] = tilcdc_read(ddev, registers[i].reg);
  481. return 0;
  482. }
  483. static int tilcdc_pm_resume(struct device *dev)
  484. {
  485. struct drm_device *ddev = dev_get_drvdata(dev);
  486. struct tilcdc_drm_private *priv = ddev->dev_private;
  487. unsigned i, n = 0;
  488. /* Restore register state: */
  489. for (i = 0; i < ARRAY_SIZE(registers); i++)
  490. if (registers[i].save && (priv->rev >= registers[i].rev))
  491. tilcdc_write(ddev, registers[i].reg, priv->saved_register[n++]);
  492. drm_kms_helper_poll_enable(ddev);
  493. return 0;
  494. }
  495. #endif
  496. static const struct dev_pm_ops tilcdc_pm_ops = {
  497. SET_SYSTEM_SLEEP_PM_OPS(tilcdc_pm_suspend, tilcdc_pm_resume)
  498. };
  499. /*
  500. * Platform driver:
  501. */
  502. static int tilcdc_pdev_probe(struct platform_device *pdev)
  503. {
  504. /* bail out early if no DT data: */
  505. if (!pdev->dev.of_node) {
  506. dev_err(&pdev->dev, "device-tree data is missing\n");
  507. return -ENXIO;
  508. }
  509. /* defer probing if slave is in deferred probing */
  510. if (slave_probing == true)
  511. return -EPROBE_DEFER;
  512. return drm_platform_init(&tilcdc_driver, pdev);
  513. }
  514. static int tilcdc_pdev_remove(struct platform_device *pdev)
  515. {
  516. drm_put_dev(platform_get_drvdata(pdev));
  517. return 0;
  518. }
  519. static struct of_device_id tilcdc_of_match[] = {
  520. { .compatible = "ti,am33xx-tilcdc", },
  521. { },
  522. };
  523. MODULE_DEVICE_TABLE(of, tilcdc_of_match);
  524. static struct platform_driver tilcdc_platform_driver = {
  525. .probe = tilcdc_pdev_probe,
  526. .remove = tilcdc_pdev_remove,
  527. .driver = {
  528. .name = "tilcdc",
  529. .pm = &tilcdc_pm_ops,
  530. .of_match_table = tilcdc_of_match,
  531. },
  532. };
  533. static int __init tilcdc_drm_init(void)
  534. {
  535. DBG("init");
  536. tilcdc_tfp410_init();
  537. tilcdc_slave_init();
  538. tilcdc_panel_init();
  539. return platform_driver_register(&tilcdc_platform_driver);
  540. }
  541. static void __exit tilcdc_drm_fini(void)
  542. {
  543. DBG("fini");
  544. platform_driver_unregister(&tilcdc_platform_driver);
  545. tilcdc_panel_fini();
  546. tilcdc_slave_fini();
  547. tilcdc_tfp410_fini();
  548. }
  549. module_init(tilcdc_drm_init);
  550. module_exit(tilcdc_drm_fini);
  551. MODULE_AUTHOR("Rob Clark <robdclark@gmail.com");
  552. MODULE_DESCRIPTION("TI LCD Controller DRM Driver");
  553. MODULE_LICENSE("GPL");