tilcdc_drv.c 19 KB

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