tilcdc_drv.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  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. 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. /* Keep HW on while we commit the state. */
  107. pm_runtime_get_sync(dev->dev);
  108. drm_atomic_helper_commit_modeset_disables(dev, state);
  109. drm_atomic_helper_commit_planes(dev, state, 0);
  110. drm_atomic_helper_commit_modeset_enables(dev, state);
  111. /* Now HW should remain on if need becase the crtc is enabled */
  112. pm_runtime_put_sync(dev->dev);
  113. drm_atomic_helper_wait_for_vblanks(dev, state);
  114. drm_atomic_helper_cleanup_planes(dev, state);
  115. drm_atomic_state_free(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 int modeset_init(struct drm_device *dev)
  125. {
  126. struct tilcdc_drm_private *priv = dev->dev_private;
  127. struct tilcdc_module *mod;
  128. drm_mode_config_init(dev);
  129. priv->crtc = tilcdc_crtc_create(dev);
  130. list_for_each_entry(mod, &module_list, list) {
  131. DBG("loading module: %s", mod->name);
  132. mod->funcs->modeset_init(mod, dev);
  133. }
  134. dev->mode_config.min_width = 0;
  135. dev->mode_config.min_height = 0;
  136. dev->mode_config.max_width = tilcdc_crtc_max_width(priv->crtc);
  137. dev->mode_config.max_height = 2048;
  138. dev->mode_config.funcs = &mode_config_funcs;
  139. return 0;
  140. }
  141. #ifdef CONFIG_CPU_FREQ
  142. static int cpufreq_transition(struct notifier_block *nb,
  143. unsigned long val, void *data)
  144. {
  145. struct tilcdc_drm_private *priv = container_of(nb,
  146. struct tilcdc_drm_private, freq_transition);
  147. if (val == CPUFREQ_POSTCHANGE) {
  148. if (priv->lcd_fck_rate != clk_get_rate(priv->clk)) {
  149. priv->lcd_fck_rate = clk_get_rate(priv->clk);
  150. tilcdc_crtc_update_clk(priv->crtc);
  151. }
  152. }
  153. return 0;
  154. }
  155. #endif
  156. /*
  157. * DRM operations:
  158. */
  159. static int tilcdc_unload(struct drm_device *dev)
  160. {
  161. struct tilcdc_drm_private *priv = dev->dev_private;
  162. tilcdc_crtc_disable(priv->crtc);
  163. tilcdc_remove_external_encoders(dev);
  164. drm_fbdev_cma_fini(priv->fbdev);
  165. drm_kms_helper_poll_fini(dev);
  166. drm_mode_config_cleanup(dev);
  167. drm_vblank_cleanup(dev);
  168. drm_irq_uninstall(dev);
  169. #ifdef CONFIG_CPU_FREQ
  170. cpufreq_unregister_notifier(&priv->freq_transition,
  171. CPUFREQ_TRANSITION_NOTIFIER);
  172. #endif
  173. if (priv->clk)
  174. clk_put(priv->clk);
  175. if (priv->mmio)
  176. iounmap(priv->mmio);
  177. flush_workqueue(priv->wq);
  178. destroy_workqueue(priv->wq);
  179. dev->dev_private = NULL;
  180. pm_runtime_disable(dev->dev);
  181. return 0;
  182. }
  183. static int tilcdc_load(struct drm_device *dev, unsigned long flags)
  184. {
  185. struct platform_device *pdev = dev->platformdev;
  186. struct device_node *node = pdev->dev.of_node;
  187. struct tilcdc_drm_private *priv;
  188. struct tilcdc_module *mod;
  189. struct resource *res;
  190. u32 bpp = 0;
  191. int ret;
  192. priv = devm_kzalloc(dev->dev, sizeof(*priv), GFP_KERNEL);
  193. if (!priv) {
  194. dev_err(dev->dev, "failed to allocate private data\n");
  195. return -ENOMEM;
  196. }
  197. dev->dev_private = priv;
  198. priv->is_componentized =
  199. tilcdc_get_external_components(dev->dev, NULL) > 0;
  200. priv->wq = alloc_ordered_workqueue("tilcdc", 0);
  201. if (!priv->wq) {
  202. ret = -ENOMEM;
  203. goto fail_unset_priv;
  204. }
  205. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  206. if (!res) {
  207. dev_err(dev->dev, "failed to get memory resource\n");
  208. ret = -EINVAL;
  209. goto fail_free_wq;
  210. }
  211. priv->mmio = ioremap_nocache(res->start, resource_size(res));
  212. if (!priv->mmio) {
  213. dev_err(dev->dev, "failed to ioremap\n");
  214. ret = -ENOMEM;
  215. goto fail_free_wq;
  216. }
  217. priv->clk = clk_get(dev->dev, "fck");
  218. if (IS_ERR(priv->clk)) {
  219. dev_err(dev->dev, "failed to get functional clock\n");
  220. ret = -ENODEV;
  221. goto fail_iounmap;
  222. }
  223. #ifdef CONFIG_CPU_FREQ
  224. priv->lcd_fck_rate = clk_get_rate(priv->clk);
  225. priv->freq_transition.notifier_call = cpufreq_transition;
  226. ret = cpufreq_register_notifier(&priv->freq_transition,
  227. CPUFREQ_TRANSITION_NOTIFIER);
  228. if (ret) {
  229. dev_err(dev->dev, "failed to register cpufreq notifier\n");
  230. goto fail_put_clk;
  231. }
  232. #endif
  233. if (of_property_read_u32(node, "max-bandwidth", &priv->max_bandwidth))
  234. priv->max_bandwidth = TILCDC_DEFAULT_MAX_BANDWIDTH;
  235. DBG("Maximum Bandwidth Value %d", priv->max_bandwidth);
  236. if (of_property_read_u32(node, "ti,max-width", &priv->max_width))
  237. priv->max_width = TILCDC_DEFAULT_MAX_WIDTH;
  238. DBG("Maximum Horizontal Pixel Width Value %dpixels", priv->max_width);
  239. if (of_property_read_u32(node, "ti,max-pixelclock",
  240. &priv->max_pixelclock))
  241. priv->max_pixelclock = TILCDC_DEFAULT_MAX_PIXELCLOCK;
  242. DBG("Maximum Pixel Clock Value %dKHz", priv->max_pixelclock);
  243. pm_runtime_enable(dev->dev);
  244. /* Determine LCD IP Version */
  245. pm_runtime_get_sync(dev->dev);
  246. switch (tilcdc_read(dev, LCDC_PID_REG)) {
  247. case 0x4c100102:
  248. priv->rev = 1;
  249. break;
  250. case 0x4f200800:
  251. case 0x4f201000:
  252. priv->rev = 2;
  253. break;
  254. default:
  255. dev_warn(dev->dev, "Unknown PID Reg value 0x%08x, "
  256. "defaulting to LCD revision 1\n",
  257. tilcdc_read(dev, LCDC_PID_REG));
  258. priv->rev = 1;
  259. break;
  260. }
  261. pm_runtime_put_sync(dev->dev);
  262. if (priv->rev == 1) {
  263. DBG("Revision 1 LCDC supports only RGB565 format");
  264. priv->pixelformats = tilcdc_rev1_formats;
  265. priv->num_pixelformats = ARRAY_SIZE(tilcdc_rev1_formats);
  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. } else if (0 == strcmp(str, "straight")) {
  275. DBG("Configured for straight blue and red wires");
  276. priv->pixelformats = tilcdc_straight_formats;
  277. priv->num_pixelformats =
  278. ARRAY_SIZE(tilcdc_straight_formats);
  279. } else {
  280. DBG("Blue and red wiring '%s' unknown, use legacy mode",
  281. str);
  282. priv->pixelformats = tilcdc_legacy_formats;
  283. priv->num_pixelformats =
  284. ARRAY_SIZE(tilcdc_legacy_formats);
  285. }
  286. }
  287. ret = modeset_init(dev);
  288. if (ret < 0) {
  289. dev_err(dev->dev, "failed to initialize mode setting\n");
  290. goto fail_cpufreq_unregister;
  291. }
  292. platform_set_drvdata(pdev, dev);
  293. if (priv->is_componentized) {
  294. ret = component_bind_all(dev->dev, dev);
  295. if (ret < 0)
  296. goto fail_mode_config_cleanup;
  297. ret = tilcdc_add_external_encoders(dev, &bpp);
  298. if (ret < 0)
  299. goto fail_component_cleanup;
  300. }
  301. if ((priv->num_encoders == 0) || (priv->num_connectors == 0)) {
  302. dev_err(dev->dev, "no encoders/connectors found\n");
  303. ret = -ENXIO;
  304. goto fail_external_cleanup;
  305. }
  306. ret = drm_vblank_init(dev, 1);
  307. if (ret < 0) {
  308. dev_err(dev->dev, "failed to initialize vblank\n");
  309. goto fail_external_cleanup;
  310. }
  311. ret = drm_irq_install(dev, platform_get_irq(dev->platformdev, 0));
  312. if (ret < 0) {
  313. dev_err(dev->dev, "failed to install IRQ handler\n");
  314. goto fail_vblank_cleanup;
  315. }
  316. list_for_each_entry(mod, &module_list, list) {
  317. DBG("%s: preferred_bpp: %d", mod->name, mod->preferred_bpp);
  318. bpp = mod->preferred_bpp;
  319. if (bpp > 0)
  320. break;
  321. }
  322. drm_mode_config_reset(dev);
  323. priv->fbdev = drm_fbdev_cma_init(dev, bpp,
  324. dev->mode_config.num_crtc,
  325. dev->mode_config.num_connector);
  326. if (IS_ERR(priv->fbdev)) {
  327. ret = PTR_ERR(priv->fbdev);
  328. goto fail_irq_uninstall;
  329. }
  330. drm_kms_helper_poll_init(dev);
  331. return 0;
  332. fail_irq_uninstall:
  333. drm_irq_uninstall(dev);
  334. fail_vblank_cleanup:
  335. drm_vblank_cleanup(dev);
  336. fail_mode_config_cleanup:
  337. drm_mode_config_cleanup(dev);
  338. fail_component_cleanup:
  339. if (priv->is_componentized)
  340. component_unbind_all(dev->dev, dev);
  341. fail_external_cleanup:
  342. tilcdc_remove_external_encoders(dev);
  343. fail_cpufreq_unregister:
  344. pm_runtime_disable(dev->dev);
  345. #ifdef CONFIG_CPU_FREQ
  346. cpufreq_unregister_notifier(&priv->freq_transition,
  347. CPUFREQ_TRANSITION_NOTIFIER);
  348. fail_put_clk:
  349. #endif
  350. clk_put(priv->clk);
  351. fail_iounmap:
  352. iounmap(priv->mmio);
  353. fail_free_wq:
  354. flush_workqueue(priv->wq);
  355. destroy_workqueue(priv->wq);
  356. fail_unset_priv:
  357. dev->dev_private = NULL;
  358. return ret;
  359. }
  360. static void tilcdc_lastclose(struct drm_device *dev)
  361. {
  362. struct tilcdc_drm_private *priv = dev->dev_private;
  363. drm_fbdev_cma_restore_mode(priv->fbdev);
  364. }
  365. static irqreturn_t tilcdc_irq(int irq, void *arg)
  366. {
  367. struct drm_device *dev = arg;
  368. struct tilcdc_drm_private *priv = dev->dev_private;
  369. return tilcdc_crtc_irq(priv->crtc);
  370. }
  371. static int tilcdc_enable_vblank(struct drm_device *dev, unsigned int pipe)
  372. {
  373. return 0;
  374. }
  375. static void tilcdc_disable_vblank(struct drm_device *dev, unsigned int pipe)
  376. {
  377. return;
  378. }
  379. #if defined(CONFIG_DEBUG_FS)
  380. static const struct {
  381. const char *name;
  382. uint8_t rev;
  383. uint8_t save;
  384. uint32_t reg;
  385. } registers[] = {
  386. #define REG(rev, save, reg) { #reg, rev, save, reg }
  387. /* exists in revision 1: */
  388. REG(1, false, LCDC_PID_REG),
  389. REG(1, true, LCDC_CTRL_REG),
  390. REG(1, false, LCDC_STAT_REG),
  391. REG(1, true, LCDC_RASTER_CTRL_REG),
  392. REG(1, true, LCDC_RASTER_TIMING_0_REG),
  393. REG(1, true, LCDC_RASTER_TIMING_1_REG),
  394. REG(1, true, LCDC_RASTER_TIMING_2_REG),
  395. REG(1, true, LCDC_DMA_CTRL_REG),
  396. REG(1, true, LCDC_DMA_FB_BASE_ADDR_0_REG),
  397. REG(1, true, LCDC_DMA_FB_CEILING_ADDR_0_REG),
  398. REG(1, true, LCDC_DMA_FB_BASE_ADDR_1_REG),
  399. REG(1, true, LCDC_DMA_FB_CEILING_ADDR_1_REG),
  400. /* new in revision 2: */
  401. REG(2, false, LCDC_RAW_STAT_REG),
  402. REG(2, false, LCDC_MASKED_STAT_REG),
  403. REG(2, true, LCDC_INT_ENABLE_SET_REG),
  404. REG(2, false, LCDC_INT_ENABLE_CLR_REG),
  405. REG(2, false, LCDC_END_OF_INT_IND_REG),
  406. REG(2, true, LCDC_CLK_ENABLE_REG),
  407. #undef REG
  408. };
  409. #endif
  410. #ifdef CONFIG_DEBUG_FS
  411. static int tilcdc_regs_show(struct seq_file *m, void *arg)
  412. {
  413. struct drm_info_node *node = (struct drm_info_node *) m->private;
  414. struct drm_device *dev = node->minor->dev;
  415. struct tilcdc_drm_private *priv = dev->dev_private;
  416. unsigned i;
  417. pm_runtime_get_sync(dev->dev);
  418. seq_printf(m, "revision: %d\n", priv->rev);
  419. for (i = 0; i < ARRAY_SIZE(registers); i++)
  420. if (priv->rev >= registers[i].rev)
  421. seq_printf(m, "%s:\t %08x\n", registers[i].name,
  422. tilcdc_read(dev, registers[i].reg));
  423. pm_runtime_put_sync(dev->dev);
  424. return 0;
  425. }
  426. static int tilcdc_mm_show(struct seq_file *m, void *arg)
  427. {
  428. struct drm_info_node *node = (struct drm_info_node *) m->private;
  429. struct drm_device *dev = node->minor->dev;
  430. return drm_mm_dump_table(m, &dev->vma_offset_manager->vm_addr_space_mm);
  431. }
  432. static struct drm_info_list tilcdc_debugfs_list[] = {
  433. { "regs", tilcdc_regs_show, 0 },
  434. { "mm", tilcdc_mm_show, 0 },
  435. { "fb", drm_fb_cma_debugfs_show, 0 },
  436. };
  437. static int tilcdc_debugfs_init(struct drm_minor *minor)
  438. {
  439. struct drm_device *dev = minor->dev;
  440. struct tilcdc_module *mod;
  441. int ret;
  442. ret = drm_debugfs_create_files(tilcdc_debugfs_list,
  443. ARRAY_SIZE(tilcdc_debugfs_list),
  444. minor->debugfs_root, minor);
  445. list_for_each_entry(mod, &module_list, list)
  446. if (mod->funcs->debugfs_init)
  447. mod->funcs->debugfs_init(mod, minor);
  448. if (ret) {
  449. dev_err(dev->dev, "could not install tilcdc_debugfs_list\n");
  450. return ret;
  451. }
  452. return ret;
  453. }
  454. static void tilcdc_debugfs_cleanup(struct drm_minor *minor)
  455. {
  456. struct tilcdc_module *mod;
  457. drm_debugfs_remove_files(tilcdc_debugfs_list,
  458. ARRAY_SIZE(tilcdc_debugfs_list), minor);
  459. list_for_each_entry(mod, &module_list, list)
  460. if (mod->funcs->debugfs_cleanup)
  461. mod->funcs->debugfs_cleanup(mod, minor);
  462. }
  463. #endif
  464. static const struct file_operations fops = {
  465. .owner = THIS_MODULE,
  466. .open = drm_open,
  467. .release = drm_release,
  468. .unlocked_ioctl = drm_ioctl,
  469. #ifdef CONFIG_COMPAT
  470. .compat_ioctl = drm_compat_ioctl,
  471. #endif
  472. .poll = drm_poll,
  473. .read = drm_read,
  474. .llseek = no_llseek,
  475. .mmap = drm_gem_cma_mmap,
  476. };
  477. static struct drm_driver tilcdc_driver = {
  478. .driver_features = (DRIVER_HAVE_IRQ | DRIVER_GEM | DRIVER_MODESET |
  479. DRIVER_PRIME | DRIVER_ATOMIC),
  480. .load = tilcdc_load,
  481. .unload = tilcdc_unload,
  482. .lastclose = tilcdc_lastclose,
  483. .irq_handler = tilcdc_irq,
  484. .get_vblank_counter = drm_vblank_no_hw_counter,
  485. .enable_vblank = tilcdc_enable_vblank,
  486. .disable_vblank = tilcdc_disable_vblank,
  487. .gem_free_object_unlocked = drm_gem_cma_free_object,
  488. .gem_vm_ops = &drm_gem_cma_vm_ops,
  489. .dumb_create = drm_gem_cma_dumb_create,
  490. .dumb_map_offset = drm_gem_cma_dumb_map_offset,
  491. .dumb_destroy = drm_gem_dumb_destroy,
  492. .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
  493. .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
  494. .gem_prime_import = drm_gem_prime_import,
  495. .gem_prime_export = drm_gem_prime_export,
  496. .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table,
  497. .gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table,
  498. .gem_prime_vmap = drm_gem_cma_prime_vmap,
  499. .gem_prime_vunmap = drm_gem_cma_prime_vunmap,
  500. .gem_prime_mmap = drm_gem_cma_prime_mmap,
  501. #ifdef CONFIG_DEBUG_FS
  502. .debugfs_init = tilcdc_debugfs_init,
  503. .debugfs_cleanup = tilcdc_debugfs_cleanup,
  504. #endif
  505. .fops = &fops,
  506. .name = "tilcdc",
  507. .desc = "TI LCD Controller DRM",
  508. .date = "20121205",
  509. .major = 1,
  510. .minor = 0,
  511. };
  512. /*
  513. * Power management:
  514. */
  515. #ifdef CONFIG_PM_SLEEP
  516. static int tilcdc_pm_suspend(struct device *dev)
  517. {
  518. struct drm_device *ddev = dev_get_drvdata(dev);
  519. struct tilcdc_drm_private *priv = ddev->dev_private;
  520. priv->saved_state = drm_atomic_helper_suspend(ddev);
  521. /* Select sleep pin state */
  522. pinctrl_pm_select_sleep_state(dev);
  523. return 0;
  524. }
  525. static int tilcdc_pm_resume(struct device *dev)
  526. {
  527. struct drm_device *ddev = dev_get_drvdata(dev);
  528. struct tilcdc_drm_private *priv = ddev->dev_private;
  529. int ret = 0;
  530. /* Select default pin state */
  531. pinctrl_pm_select_default_state(dev);
  532. if (priv->saved_state)
  533. ret = drm_atomic_helper_resume(ddev, priv->saved_state);
  534. return ret;
  535. }
  536. #endif
  537. static const struct dev_pm_ops tilcdc_pm_ops = {
  538. SET_SYSTEM_SLEEP_PM_OPS(tilcdc_pm_suspend, tilcdc_pm_resume)
  539. };
  540. /*
  541. * Platform driver:
  542. */
  543. static int tilcdc_bind(struct device *dev)
  544. {
  545. return drm_platform_init(&tilcdc_driver, to_platform_device(dev));
  546. }
  547. static void tilcdc_unbind(struct device *dev)
  548. {
  549. struct drm_device *ddev = dev_get_drvdata(dev);
  550. /* Check if a subcomponent has already triggered the unloading. */
  551. if (!ddev->dev_private)
  552. return;
  553. drm_put_dev(dev_get_drvdata(dev));
  554. }
  555. static const struct component_master_ops tilcdc_comp_ops = {
  556. .bind = tilcdc_bind,
  557. .unbind = tilcdc_unbind,
  558. };
  559. static int tilcdc_pdev_probe(struct platform_device *pdev)
  560. {
  561. struct component_match *match = NULL;
  562. int ret;
  563. /* bail out early if no DT data: */
  564. if (!pdev->dev.of_node) {
  565. dev_err(&pdev->dev, "device-tree data is missing\n");
  566. return -ENXIO;
  567. }
  568. ret = tilcdc_get_external_components(&pdev->dev, &match);
  569. if (ret < 0)
  570. return ret;
  571. else if (ret == 0)
  572. return drm_platform_init(&tilcdc_driver, pdev);
  573. else
  574. return component_master_add_with_match(&pdev->dev,
  575. &tilcdc_comp_ops,
  576. match);
  577. }
  578. static int tilcdc_pdev_remove(struct platform_device *pdev)
  579. {
  580. int ret;
  581. ret = tilcdc_get_external_components(&pdev->dev, NULL);
  582. if (ret < 0)
  583. return ret;
  584. else if (ret == 0)
  585. drm_put_dev(platform_get_drvdata(pdev));
  586. else
  587. component_master_del(&pdev->dev, &tilcdc_comp_ops);
  588. return 0;
  589. }
  590. static struct of_device_id tilcdc_of_match[] = {
  591. { .compatible = "ti,am33xx-tilcdc", },
  592. { },
  593. };
  594. MODULE_DEVICE_TABLE(of, tilcdc_of_match);
  595. static struct platform_driver tilcdc_platform_driver = {
  596. .probe = tilcdc_pdev_probe,
  597. .remove = tilcdc_pdev_remove,
  598. .driver = {
  599. .name = "tilcdc",
  600. .pm = &tilcdc_pm_ops,
  601. .of_match_table = tilcdc_of_match,
  602. },
  603. };
  604. static int __init tilcdc_drm_init(void)
  605. {
  606. DBG("init");
  607. tilcdc_tfp410_init();
  608. tilcdc_panel_init();
  609. return platform_driver_register(&tilcdc_platform_driver);
  610. }
  611. static void __exit tilcdc_drm_fini(void)
  612. {
  613. DBG("fini");
  614. platform_driver_unregister(&tilcdc_platform_driver);
  615. tilcdc_panel_fini();
  616. tilcdc_tfp410_fini();
  617. }
  618. module_init(tilcdc_drm_init);
  619. module_exit(tilcdc_drm_fini);
  620. MODULE_AUTHOR("Rob Clark <robdclark@gmail.com");
  621. MODULE_DESCRIPTION("TI LCD Controller DRM Driver");
  622. MODULE_LICENSE("GPL");