tilcdc_drv.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  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 "tilcdc_drv.h"
  20. #include "tilcdc_regs.h"
  21. #include "tilcdc_tfp410.h"
  22. #include "tilcdc_panel.h"
  23. #include "tilcdc_external.h"
  24. #include "drm_fb_helper.h"
  25. static LIST_HEAD(module_list);
  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. static struct of_device_id tilcdc_of_match[];
  39. static struct drm_framebuffer *tilcdc_fb_create(struct drm_device *dev,
  40. struct drm_file *file_priv, const struct drm_mode_fb_cmd2 *mode_cmd)
  41. {
  42. return drm_fb_cma_create(dev, file_priv, mode_cmd);
  43. }
  44. static void tilcdc_fb_output_poll_changed(struct drm_device *dev)
  45. {
  46. struct tilcdc_drm_private *priv = dev->dev_private;
  47. drm_fbdev_cma_hotplug_event(priv->fbdev);
  48. }
  49. static const struct drm_mode_config_funcs mode_config_funcs = {
  50. .fb_create = tilcdc_fb_create,
  51. .output_poll_changed = tilcdc_fb_output_poll_changed,
  52. };
  53. static int modeset_init(struct drm_device *dev)
  54. {
  55. struct tilcdc_drm_private *priv = dev->dev_private;
  56. struct tilcdc_module *mod;
  57. drm_mode_config_init(dev);
  58. priv->crtc = tilcdc_crtc_create(dev);
  59. list_for_each_entry(mod, &module_list, list) {
  60. DBG("loading module: %s", mod->name);
  61. mod->funcs->modeset_init(mod, dev);
  62. }
  63. dev->mode_config.min_width = 0;
  64. dev->mode_config.min_height = 0;
  65. dev->mode_config.max_width = tilcdc_crtc_max_width(priv->crtc);
  66. dev->mode_config.max_height = 2048;
  67. dev->mode_config.funcs = &mode_config_funcs;
  68. return 0;
  69. }
  70. #ifdef CONFIG_CPU_FREQ
  71. static int cpufreq_transition(struct notifier_block *nb,
  72. unsigned long val, void *data)
  73. {
  74. struct tilcdc_drm_private *priv = container_of(nb,
  75. struct tilcdc_drm_private, freq_transition);
  76. if (val == CPUFREQ_POSTCHANGE) {
  77. if (priv->lcd_fck_rate != clk_get_rate(priv->clk)) {
  78. priv->lcd_fck_rate = clk_get_rate(priv->clk);
  79. tilcdc_crtc_update_clk(priv->crtc);
  80. }
  81. }
  82. return 0;
  83. }
  84. #endif
  85. /*
  86. * DRM operations:
  87. */
  88. static int tilcdc_unload(struct drm_device *dev)
  89. {
  90. struct tilcdc_drm_private *priv = dev->dev_private;
  91. tilcdc_remove_external_encoders(dev);
  92. drm_fbdev_cma_fini(priv->fbdev);
  93. drm_kms_helper_poll_fini(dev);
  94. drm_mode_config_cleanup(dev);
  95. drm_vblank_cleanup(dev);
  96. pm_runtime_get_sync(dev->dev);
  97. drm_irq_uninstall(dev);
  98. pm_runtime_put_sync(dev->dev);
  99. #ifdef CONFIG_CPU_FREQ
  100. cpufreq_unregister_notifier(&priv->freq_transition,
  101. CPUFREQ_TRANSITION_NOTIFIER);
  102. #endif
  103. if (priv->clk)
  104. clk_put(priv->clk);
  105. if (priv->mmio)
  106. iounmap(priv->mmio);
  107. flush_workqueue(priv->wq);
  108. destroy_workqueue(priv->wq);
  109. dev->dev_private = NULL;
  110. pm_runtime_disable(dev->dev);
  111. kfree(priv);
  112. return 0;
  113. }
  114. static int tilcdc_load(struct drm_device *dev, unsigned long flags)
  115. {
  116. struct platform_device *pdev = dev->platformdev;
  117. struct device_node *node = pdev->dev.of_node;
  118. struct tilcdc_drm_private *priv;
  119. struct tilcdc_module *mod;
  120. struct resource *res;
  121. u32 bpp = 0;
  122. int ret;
  123. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  124. if (!priv) {
  125. dev_err(dev->dev, "failed to allocate private data\n");
  126. return -ENOMEM;
  127. }
  128. dev->dev_private = priv;
  129. priv->is_componentized =
  130. tilcdc_get_external_components(dev->dev, NULL) > 0;
  131. priv->wq = alloc_ordered_workqueue("tilcdc", 0);
  132. if (!priv->wq) {
  133. ret = -ENOMEM;
  134. goto fail_free_priv;
  135. }
  136. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  137. if (!res) {
  138. dev_err(dev->dev, "failed to get memory resource\n");
  139. ret = -EINVAL;
  140. goto fail_free_wq;
  141. }
  142. priv->mmio = ioremap_nocache(res->start, resource_size(res));
  143. if (!priv->mmio) {
  144. dev_err(dev->dev, "failed to ioremap\n");
  145. ret = -ENOMEM;
  146. goto fail_free_wq;
  147. }
  148. priv->clk = clk_get(dev->dev, "fck");
  149. if (IS_ERR(priv->clk)) {
  150. dev_err(dev->dev, "failed to get functional clock\n");
  151. ret = -ENODEV;
  152. goto fail_iounmap;
  153. }
  154. #ifdef CONFIG_CPU_FREQ
  155. priv->lcd_fck_rate = clk_get_rate(priv->clk);
  156. priv->freq_transition.notifier_call = cpufreq_transition;
  157. ret = cpufreq_register_notifier(&priv->freq_transition,
  158. CPUFREQ_TRANSITION_NOTIFIER);
  159. if (ret) {
  160. dev_err(dev->dev, "failed to register cpufreq notifier\n");
  161. goto fail_put_clk;
  162. }
  163. #endif
  164. if (of_property_read_u32(node, "max-bandwidth", &priv->max_bandwidth))
  165. priv->max_bandwidth = TILCDC_DEFAULT_MAX_BANDWIDTH;
  166. DBG("Maximum Bandwidth Value %d", priv->max_bandwidth);
  167. if (of_property_read_u32(node, "ti,max-width", &priv->max_width))
  168. priv->max_width = TILCDC_DEFAULT_MAX_WIDTH;
  169. DBG("Maximum Horizontal Pixel Width Value %dpixels", priv->max_width);
  170. if (of_property_read_u32(node, "ti,max-pixelclock",
  171. &priv->max_pixelclock))
  172. priv->max_pixelclock = TILCDC_DEFAULT_MAX_PIXELCLOCK;
  173. DBG("Maximum Pixel Clock Value %dKHz", priv->max_pixelclock);
  174. pm_runtime_enable(dev->dev);
  175. pm_runtime_irq_safe(dev->dev);
  176. /* Determine LCD IP Version */
  177. pm_runtime_get_sync(dev->dev);
  178. switch (tilcdc_read(dev, LCDC_PID_REG)) {
  179. case 0x4c100102:
  180. priv->rev = 1;
  181. break;
  182. case 0x4f200800:
  183. case 0x4f201000:
  184. priv->rev = 2;
  185. break;
  186. default:
  187. dev_warn(dev->dev, "Unknown PID Reg value 0x%08x, "
  188. "defaulting to LCD revision 1\n",
  189. tilcdc_read(dev, LCDC_PID_REG));
  190. priv->rev = 1;
  191. break;
  192. }
  193. pm_runtime_put_sync(dev->dev);
  194. ret = modeset_init(dev);
  195. if (ret < 0) {
  196. dev_err(dev->dev, "failed to initialize mode setting\n");
  197. goto fail_cpufreq_unregister;
  198. }
  199. platform_set_drvdata(pdev, dev);
  200. if (priv->is_componentized) {
  201. ret = component_bind_all(dev->dev, dev);
  202. if (ret < 0)
  203. goto fail_mode_config_cleanup;
  204. ret = tilcdc_add_external_encoders(dev, &bpp);
  205. if (ret < 0)
  206. goto fail_component_cleanup;
  207. }
  208. if ((priv->num_encoders == 0) || (priv->num_connectors == 0)) {
  209. dev_err(dev->dev, "no encoders/connectors found\n");
  210. ret = -ENXIO;
  211. goto fail_external_cleanup;
  212. }
  213. ret = drm_vblank_init(dev, 1);
  214. if (ret < 0) {
  215. dev_err(dev->dev, "failed to initialize vblank\n");
  216. goto fail_external_cleanup;
  217. }
  218. pm_runtime_get_sync(dev->dev);
  219. ret = drm_irq_install(dev, platform_get_irq(dev->platformdev, 0));
  220. pm_runtime_put_sync(dev->dev);
  221. if (ret < 0) {
  222. dev_err(dev->dev, "failed to install IRQ handler\n");
  223. goto fail_vblank_cleanup;
  224. }
  225. list_for_each_entry(mod, &module_list, list) {
  226. DBG("%s: preferred_bpp: %d", mod->name, mod->preferred_bpp);
  227. bpp = mod->preferred_bpp;
  228. if (bpp > 0)
  229. break;
  230. }
  231. drm_helper_disable_unused_functions(dev);
  232. priv->fbdev = drm_fbdev_cma_init(dev, bpp,
  233. dev->mode_config.num_crtc,
  234. dev->mode_config.num_connector);
  235. if (IS_ERR(priv->fbdev)) {
  236. ret = PTR_ERR(priv->fbdev);
  237. goto fail_irq_uninstall;
  238. }
  239. drm_kms_helper_poll_init(dev);
  240. return 0;
  241. fail_irq_uninstall:
  242. pm_runtime_get_sync(dev->dev);
  243. drm_irq_uninstall(dev);
  244. pm_runtime_put_sync(dev->dev);
  245. fail_vblank_cleanup:
  246. drm_vblank_cleanup(dev);
  247. fail_mode_config_cleanup:
  248. drm_mode_config_cleanup(dev);
  249. fail_component_cleanup:
  250. if (priv->is_componentized)
  251. component_unbind_all(dev->dev, dev);
  252. fail_external_cleanup:
  253. tilcdc_remove_external_encoders(dev);
  254. fail_cpufreq_unregister:
  255. pm_runtime_disable(dev->dev);
  256. #ifdef CONFIG_CPU_FREQ
  257. cpufreq_unregister_notifier(&priv->freq_transition,
  258. CPUFREQ_TRANSITION_NOTIFIER);
  259. #endif
  260. fail_put_clk:
  261. clk_put(priv->clk);
  262. fail_iounmap:
  263. iounmap(priv->mmio);
  264. fail_free_wq:
  265. flush_workqueue(priv->wq);
  266. destroy_workqueue(priv->wq);
  267. fail_free_priv:
  268. dev->dev_private = NULL;
  269. kfree(priv);
  270. return ret;
  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, unsigned int pipe)
  330. {
  331. enable_vblank(dev, true);
  332. return 0;
  333. }
  334. static void tilcdc_disable_vblank(struct drm_device *dev, unsigned int pipe)
  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. .lastclose = tilcdc_lastclose,
  442. .set_busid = drm_platform_set_busid,
  443. .irq_handler = tilcdc_irq,
  444. .irq_preinstall = tilcdc_irq_preinstall,
  445. .irq_postinstall = tilcdc_irq_postinstall,
  446. .irq_uninstall = tilcdc_irq_uninstall,
  447. .get_vblank_counter = drm_vblank_no_hw_counter,
  448. .enable_vblank = tilcdc_enable_vblank,
  449. .disable_vblank = tilcdc_disable_vblank,
  450. .gem_free_object = drm_gem_cma_free_object,
  451. .gem_vm_ops = &drm_gem_cma_vm_ops,
  452. .dumb_create = drm_gem_cma_dumb_create,
  453. .dumb_map_offset = drm_gem_cma_dumb_map_offset,
  454. .dumb_destroy = drm_gem_dumb_destroy,
  455. #ifdef CONFIG_DEBUG_FS
  456. .debugfs_init = tilcdc_debugfs_init,
  457. .debugfs_cleanup = tilcdc_debugfs_cleanup,
  458. #endif
  459. .fops = &fops,
  460. .name = "tilcdc",
  461. .desc = "TI LCD Controller DRM",
  462. .date = "20121205",
  463. .major = 1,
  464. .minor = 0,
  465. };
  466. /*
  467. * Power management:
  468. */
  469. #ifdef CONFIG_PM_SLEEP
  470. static int tilcdc_pm_suspend(struct device *dev)
  471. {
  472. struct drm_device *ddev = dev_get_drvdata(dev);
  473. struct tilcdc_drm_private *priv = ddev->dev_private;
  474. unsigned i, n = 0;
  475. drm_kms_helper_poll_disable(ddev);
  476. /* Save register state: */
  477. for (i = 0; i < ARRAY_SIZE(registers); i++)
  478. if (registers[i].save && (priv->rev >= registers[i].rev))
  479. priv->saved_register[n++] = tilcdc_read(ddev, registers[i].reg);
  480. return 0;
  481. }
  482. static int tilcdc_pm_resume(struct device *dev)
  483. {
  484. struct drm_device *ddev = dev_get_drvdata(dev);
  485. struct tilcdc_drm_private *priv = ddev->dev_private;
  486. unsigned i, n = 0;
  487. /* Restore register state: */
  488. for (i = 0; i < ARRAY_SIZE(registers); i++)
  489. if (registers[i].save && (priv->rev >= registers[i].rev))
  490. tilcdc_write(ddev, registers[i].reg, priv->saved_register[n++]);
  491. drm_kms_helper_poll_enable(ddev);
  492. return 0;
  493. }
  494. #endif
  495. static const struct dev_pm_ops tilcdc_pm_ops = {
  496. SET_SYSTEM_SLEEP_PM_OPS(tilcdc_pm_suspend, tilcdc_pm_resume)
  497. };
  498. /*
  499. * Platform driver:
  500. */
  501. static int tilcdc_bind(struct device *dev)
  502. {
  503. return drm_platform_init(&tilcdc_driver, to_platform_device(dev));
  504. }
  505. static void tilcdc_unbind(struct device *dev)
  506. {
  507. drm_put_dev(dev_get_drvdata(dev));
  508. }
  509. static const struct component_master_ops tilcdc_comp_ops = {
  510. .bind = tilcdc_bind,
  511. .unbind = tilcdc_unbind,
  512. };
  513. static int tilcdc_pdev_probe(struct platform_device *pdev)
  514. {
  515. struct component_match *match = NULL;
  516. int ret;
  517. /* bail out early if no DT data: */
  518. if (!pdev->dev.of_node) {
  519. dev_err(&pdev->dev, "device-tree data is missing\n");
  520. return -ENXIO;
  521. }
  522. ret = tilcdc_get_external_components(&pdev->dev, &match);
  523. if (ret < 0)
  524. return ret;
  525. else if (ret == 0)
  526. return drm_platform_init(&tilcdc_driver, pdev);
  527. else
  528. return component_master_add_with_match(&pdev->dev,
  529. &tilcdc_comp_ops,
  530. match);
  531. }
  532. static int tilcdc_pdev_remove(struct platform_device *pdev)
  533. {
  534. struct drm_device *ddev = dev_get_drvdata(&pdev->dev);
  535. struct tilcdc_drm_private *priv = ddev->dev_private;
  536. /* Check if a subcomponent has already triggered the unloading. */
  537. if (!priv)
  538. return 0;
  539. if (priv->is_componentized)
  540. component_master_del(&pdev->dev, &tilcdc_comp_ops);
  541. else
  542. drm_put_dev(platform_get_drvdata(pdev));
  543. return 0;
  544. }
  545. static struct of_device_id tilcdc_of_match[] = {
  546. { .compatible = "ti,am33xx-tilcdc", },
  547. { },
  548. };
  549. MODULE_DEVICE_TABLE(of, tilcdc_of_match);
  550. static struct platform_driver tilcdc_platform_driver = {
  551. .probe = tilcdc_pdev_probe,
  552. .remove = tilcdc_pdev_remove,
  553. .driver = {
  554. .name = "tilcdc",
  555. .pm = &tilcdc_pm_ops,
  556. .of_match_table = tilcdc_of_match,
  557. },
  558. };
  559. static int __init tilcdc_drm_init(void)
  560. {
  561. DBG("init");
  562. tilcdc_tfp410_init();
  563. tilcdc_panel_init();
  564. return platform_driver_register(&tilcdc_platform_driver);
  565. }
  566. static void __exit tilcdc_drm_fini(void)
  567. {
  568. DBG("fini");
  569. platform_driver_unregister(&tilcdc_platform_driver);
  570. tilcdc_panel_fini();
  571. tilcdc_tfp410_fini();
  572. }
  573. module_init(tilcdc_drm_init);
  574. module_exit(tilcdc_drm_fini);
  575. MODULE_AUTHOR("Rob Clark <robdclark@gmail.com");
  576. MODULE_DESCRIPTION("TI LCD Controller DRM Driver");
  577. MODULE_LICENSE("GPL");