core.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. /*
  2. * linux/drivers/video/omap2/dss/core.c
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
  6. *
  7. * Some code and ideas taken from drivers/video/omap/ driver
  8. * by Imre Deak.
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License version 2 as published by
  12. * the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  17. * more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along with
  20. * this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. #define DSS_SUBSYS_NAME "CORE"
  23. #include <linux/kernel.h>
  24. #include <linux/module.h>
  25. #include <linux/clk.h>
  26. #include <linux/err.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/seq_file.h>
  29. #include <linux/debugfs.h>
  30. #include <linux/io.h>
  31. #include <linux/device.h>
  32. #include <linux/regulator/consumer.h>
  33. #include <linux/suspend.h>
  34. #include <linux/slab.h>
  35. #include <video/omapdss.h>
  36. #include "dss.h"
  37. #include "dss_features.h"
  38. static struct {
  39. struct platform_device *pdev;
  40. struct regulator *vdds_dsi_reg;
  41. struct regulator *vdds_sdi_reg;
  42. const char *default_display_name;
  43. } core;
  44. static char *def_disp_name;
  45. module_param_named(def_disp, def_disp_name, charp, 0);
  46. MODULE_PARM_DESC(def_disp, "default display name");
  47. #ifdef DEBUG
  48. bool dss_debug;
  49. module_param_named(debug, dss_debug, bool, 0644);
  50. #endif
  51. const char *dss_get_default_display_name(void)
  52. {
  53. return core.default_display_name;
  54. }
  55. /* REGULATORS */
  56. struct regulator *dss_get_vdds_dsi(void)
  57. {
  58. struct regulator *reg;
  59. if (core.vdds_dsi_reg != NULL)
  60. return core.vdds_dsi_reg;
  61. reg = regulator_get(&core.pdev->dev, "vdds_dsi");
  62. if (!IS_ERR(reg))
  63. core.vdds_dsi_reg = reg;
  64. return reg;
  65. }
  66. struct regulator *dss_get_vdds_sdi(void)
  67. {
  68. struct regulator *reg;
  69. if (core.vdds_sdi_reg != NULL)
  70. return core.vdds_sdi_reg;
  71. reg = regulator_get(&core.pdev->dev, "vdds_sdi");
  72. if (!IS_ERR(reg))
  73. core.vdds_sdi_reg = reg;
  74. return reg;
  75. }
  76. int dss_get_ctx_loss_count(struct device *dev)
  77. {
  78. struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
  79. int cnt;
  80. if (!board_data->get_context_loss_count)
  81. return -ENOENT;
  82. cnt = board_data->get_context_loss_count(dev);
  83. WARN_ONCE(cnt < 0, "get_context_loss_count failed: %d\n", cnt);
  84. return cnt;
  85. }
  86. int dss_dsi_enable_pads(int dsi_id, unsigned lane_mask)
  87. {
  88. struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
  89. if (!board_data->dsi_enable_pads)
  90. return -ENOENT;
  91. return board_data->dsi_enable_pads(dsi_id, lane_mask);
  92. }
  93. void dss_dsi_disable_pads(int dsi_id, unsigned lane_mask)
  94. {
  95. struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
  96. if (!board_data->dsi_enable_pads)
  97. return;
  98. return board_data->dsi_disable_pads(dsi_id, lane_mask);
  99. }
  100. int dss_set_min_bus_tput(struct device *dev, unsigned long tput)
  101. {
  102. struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
  103. if (pdata->set_min_bus_tput)
  104. return pdata->set_min_bus_tput(dev, tput);
  105. else
  106. return 0;
  107. }
  108. #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_OMAP2_DSS_DEBUG_SUPPORT)
  109. static int dss_debug_show(struct seq_file *s, void *unused)
  110. {
  111. void (*func)(struct seq_file *) = s->private;
  112. func(s);
  113. return 0;
  114. }
  115. static int dss_debug_open(struct inode *inode, struct file *file)
  116. {
  117. return single_open(file, dss_debug_show, inode->i_private);
  118. }
  119. static const struct file_operations dss_debug_fops = {
  120. .open = dss_debug_open,
  121. .read = seq_read,
  122. .llseek = seq_lseek,
  123. .release = single_release,
  124. };
  125. static struct dentry *dss_debugfs_dir;
  126. static int dss_initialize_debugfs(void)
  127. {
  128. dss_debugfs_dir = debugfs_create_dir("omapdss", NULL);
  129. if (IS_ERR(dss_debugfs_dir)) {
  130. int err = PTR_ERR(dss_debugfs_dir);
  131. dss_debugfs_dir = NULL;
  132. return err;
  133. }
  134. debugfs_create_file("clk", S_IRUGO, dss_debugfs_dir,
  135. &dss_debug_dump_clocks, &dss_debug_fops);
  136. return 0;
  137. }
  138. static void dss_uninitialize_debugfs(void)
  139. {
  140. if (dss_debugfs_dir)
  141. debugfs_remove_recursive(dss_debugfs_dir);
  142. }
  143. int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
  144. {
  145. struct dentry *d;
  146. d = debugfs_create_file(name, S_IRUGO, dss_debugfs_dir,
  147. write, &dss_debug_fops);
  148. if (IS_ERR(d))
  149. return PTR_ERR(d);
  150. return 0;
  151. }
  152. #else /* CONFIG_DEBUG_FS && CONFIG_OMAP2_DSS_DEBUG_SUPPORT */
  153. static inline int dss_initialize_debugfs(void)
  154. {
  155. return 0;
  156. }
  157. static inline void dss_uninitialize_debugfs(void)
  158. {
  159. }
  160. int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
  161. {
  162. return 0;
  163. }
  164. #endif /* CONFIG_DEBUG_FS && CONFIG_OMAP2_DSS_DEBUG_SUPPORT */
  165. /* PLATFORM DEVICE */
  166. static int omap_dss_pm_notif(struct notifier_block *b, unsigned long v, void *d)
  167. {
  168. DSSDBG("pm notif %lu\n", v);
  169. switch (v) {
  170. case PM_SUSPEND_PREPARE:
  171. DSSDBG("suspending displays\n");
  172. return dss_suspend_all_devices();
  173. case PM_POST_SUSPEND:
  174. DSSDBG("resuming displays\n");
  175. return dss_resume_all_devices();
  176. default:
  177. return 0;
  178. }
  179. }
  180. static struct notifier_block omap_dss_pm_notif_block = {
  181. .notifier_call = omap_dss_pm_notif,
  182. };
  183. static int __init omap_dss_probe(struct platform_device *pdev)
  184. {
  185. struct omap_dss_board_info *pdata = pdev->dev.platform_data;
  186. int r;
  187. core.pdev = pdev;
  188. dss_features_init();
  189. dss_apply_init();
  190. dss_init_overlay_managers(pdev);
  191. dss_init_overlays(pdev);
  192. r = dss_initialize_debugfs();
  193. if (r)
  194. goto err_debugfs;
  195. if (def_disp_name)
  196. core.default_display_name = def_disp_name;
  197. else if (pdata->default_device)
  198. core.default_display_name = pdata->default_device->name;
  199. register_pm_notifier(&omap_dss_pm_notif_block);
  200. return 0;
  201. err_debugfs:
  202. return r;
  203. }
  204. static int omap_dss_remove(struct platform_device *pdev)
  205. {
  206. unregister_pm_notifier(&omap_dss_pm_notif_block);
  207. dss_uninitialize_debugfs();
  208. dss_uninit_overlays(pdev);
  209. dss_uninit_overlay_managers(pdev);
  210. return 0;
  211. }
  212. static void omap_dss_shutdown(struct platform_device *pdev)
  213. {
  214. DSSDBG("shutdown\n");
  215. dss_disable_all_devices();
  216. }
  217. static struct platform_driver omap_dss_driver = {
  218. .remove = omap_dss_remove,
  219. .shutdown = omap_dss_shutdown,
  220. .driver = {
  221. .name = "omapdss",
  222. .owner = THIS_MODULE,
  223. },
  224. };
  225. /* BUS */
  226. static int dss_bus_match(struct device *dev, struct device_driver *driver)
  227. {
  228. struct omap_dss_device *dssdev = to_dss_device(dev);
  229. DSSDBG("bus_match. dev %s/%s, drv %s\n",
  230. dev_name(dev), dssdev->driver_name, driver->name);
  231. return strcmp(dssdev->driver_name, driver->name) == 0;
  232. }
  233. static ssize_t device_name_show(struct device *dev,
  234. struct device_attribute *attr, char *buf)
  235. {
  236. struct omap_dss_device *dssdev = to_dss_device(dev);
  237. return snprintf(buf, PAGE_SIZE, "%s\n",
  238. dssdev->name ?
  239. dssdev->name : "");
  240. }
  241. static struct device_attribute default_dev_attrs[] = {
  242. __ATTR(name, S_IRUGO, device_name_show, NULL),
  243. __ATTR_NULL,
  244. };
  245. static ssize_t driver_name_show(struct device_driver *drv, char *buf)
  246. {
  247. struct omap_dss_driver *dssdrv = to_dss_driver(drv);
  248. return snprintf(buf, PAGE_SIZE, "%s\n",
  249. dssdrv->driver.name ?
  250. dssdrv->driver.name : "");
  251. }
  252. static struct driver_attribute default_drv_attrs[] = {
  253. __ATTR(name, S_IRUGO, driver_name_show, NULL),
  254. __ATTR_NULL,
  255. };
  256. static struct bus_type dss_bus_type = {
  257. .name = "omapdss",
  258. .match = dss_bus_match,
  259. .dev_attrs = default_dev_attrs,
  260. .drv_attrs = default_drv_attrs,
  261. };
  262. static void dss_bus_release(struct device *dev)
  263. {
  264. DSSDBG("bus_release\n");
  265. }
  266. static struct device dss_bus = {
  267. .release = dss_bus_release,
  268. };
  269. struct bus_type *dss_get_bus(void)
  270. {
  271. return &dss_bus_type;
  272. }
  273. /* DRIVER */
  274. static int dss_driver_probe(struct device *dev)
  275. {
  276. int r;
  277. struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
  278. struct omap_dss_device *dssdev = to_dss_device(dev);
  279. DSSDBG("driver_probe: dev %s/%s, drv %s\n",
  280. dev_name(dev), dssdev->driver_name,
  281. dssdrv->driver.name);
  282. r = dss_init_device(core.pdev, dssdev);
  283. if (r)
  284. return r;
  285. r = dssdrv->probe(dssdev);
  286. if (r) {
  287. DSSERR("driver probe failed: %d\n", r);
  288. dss_uninit_device(core.pdev, dssdev);
  289. return r;
  290. }
  291. DSSDBG("probe done for device %s\n", dev_name(dev));
  292. dssdev->driver = dssdrv;
  293. return 0;
  294. }
  295. static int dss_driver_remove(struct device *dev)
  296. {
  297. struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
  298. struct omap_dss_device *dssdev = to_dss_device(dev);
  299. DSSDBG("driver_remove: dev %s/%s\n", dev_name(dev),
  300. dssdev->driver_name);
  301. dssdrv->remove(dssdev);
  302. dss_uninit_device(core.pdev, dssdev);
  303. dssdev->driver = NULL;
  304. return 0;
  305. }
  306. int omap_dss_register_driver(struct omap_dss_driver *dssdriver)
  307. {
  308. dssdriver->driver.bus = &dss_bus_type;
  309. dssdriver->driver.probe = dss_driver_probe;
  310. dssdriver->driver.remove = dss_driver_remove;
  311. if (dssdriver->get_resolution == NULL)
  312. dssdriver->get_resolution = omapdss_default_get_resolution;
  313. if (dssdriver->get_recommended_bpp == NULL)
  314. dssdriver->get_recommended_bpp =
  315. omapdss_default_get_recommended_bpp;
  316. if (dssdriver->get_timings == NULL)
  317. dssdriver->get_timings = omapdss_default_get_timings;
  318. return driver_register(&dssdriver->driver);
  319. }
  320. EXPORT_SYMBOL(omap_dss_register_driver);
  321. void omap_dss_unregister_driver(struct omap_dss_driver *dssdriver)
  322. {
  323. driver_unregister(&dssdriver->driver);
  324. }
  325. EXPORT_SYMBOL(omap_dss_unregister_driver);
  326. /* DEVICE */
  327. static void omap_dss_dev_release(struct device *dev)
  328. {
  329. struct omap_dss_device *dssdev = to_dss_device(dev);
  330. kfree(dssdev);
  331. }
  332. static int disp_num_counter;
  333. struct omap_dss_device *dss_alloc_and_init_device(struct device *parent)
  334. {
  335. struct omap_dss_device *dssdev;
  336. dssdev = kzalloc(sizeof(*dssdev), GFP_KERNEL);
  337. if (!dssdev)
  338. return NULL;
  339. dssdev->dev.bus = &dss_bus_type;
  340. dssdev->dev.parent = parent;
  341. dssdev->dev.release = omap_dss_dev_release;
  342. dev_set_name(&dssdev->dev, "display%d", disp_num_counter++);
  343. device_initialize(&dssdev->dev);
  344. return dssdev;
  345. }
  346. int dss_add_device(struct omap_dss_device *dssdev)
  347. {
  348. return device_add(&dssdev->dev);
  349. }
  350. void dss_put_device(struct omap_dss_device *dssdev)
  351. {
  352. put_device(&dssdev->dev);
  353. }
  354. void dss_unregister_device(struct omap_dss_device *dssdev)
  355. {
  356. device_unregister(&dssdev->dev);
  357. }
  358. static int dss_unregister_dss_dev(struct device *dev, void *data)
  359. {
  360. struct omap_dss_device *dssdev = to_dss_device(dev);
  361. dss_unregister_device(dssdev);
  362. return 0;
  363. }
  364. void dss_unregister_child_devices(struct device *parent)
  365. {
  366. device_for_each_child(parent, NULL, dss_unregister_dss_dev);
  367. }
  368. void dss_copy_device_pdata(struct omap_dss_device *dst,
  369. const struct omap_dss_device *src)
  370. {
  371. u8 *d = (u8 *)dst;
  372. u8 *s = (u8 *)src;
  373. size_t dsize = sizeof(struct device);
  374. memcpy(d + dsize, s + dsize, sizeof(struct omap_dss_device) - dsize);
  375. }
  376. /* BUS */
  377. static int __init omap_dss_bus_register(void)
  378. {
  379. int r;
  380. r = bus_register(&dss_bus_type);
  381. if (r) {
  382. DSSERR("bus register failed\n");
  383. return r;
  384. }
  385. dev_set_name(&dss_bus, "omapdss");
  386. r = device_register(&dss_bus);
  387. if (r) {
  388. DSSERR("bus driver register failed\n");
  389. bus_unregister(&dss_bus_type);
  390. return r;
  391. }
  392. return 0;
  393. }
  394. /* INIT */
  395. static int (*dss_output_drv_reg_funcs[])(void) __initdata = {
  396. #ifdef CONFIG_OMAP2_DSS_DPI
  397. dpi_init_platform_driver,
  398. #endif
  399. #ifdef CONFIG_OMAP2_DSS_SDI
  400. sdi_init_platform_driver,
  401. #endif
  402. #ifdef CONFIG_OMAP2_DSS_RFBI
  403. rfbi_init_platform_driver,
  404. #endif
  405. #ifdef CONFIG_OMAP2_DSS_VENC
  406. venc_init_platform_driver,
  407. #endif
  408. #ifdef CONFIG_OMAP2_DSS_DSI
  409. dsi_init_platform_driver,
  410. #endif
  411. #ifdef CONFIG_OMAP4_DSS_HDMI
  412. hdmi_init_platform_driver,
  413. #endif
  414. };
  415. static void (*dss_output_drv_unreg_funcs[])(void) __exitdata = {
  416. #ifdef CONFIG_OMAP2_DSS_DPI
  417. dpi_uninit_platform_driver,
  418. #endif
  419. #ifdef CONFIG_OMAP2_DSS_SDI
  420. sdi_uninit_platform_driver,
  421. #endif
  422. #ifdef CONFIG_OMAP2_DSS_RFBI
  423. rfbi_uninit_platform_driver,
  424. #endif
  425. #ifdef CONFIG_OMAP2_DSS_VENC
  426. venc_uninit_platform_driver,
  427. #endif
  428. #ifdef CONFIG_OMAP2_DSS_DSI
  429. dsi_uninit_platform_driver,
  430. #endif
  431. #ifdef CONFIG_OMAP4_DSS_HDMI
  432. hdmi_uninit_platform_driver,
  433. #endif
  434. };
  435. static bool dss_output_drv_loaded[ARRAY_SIZE(dss_output_drv_reg_funcs)];
  436. static int __init omap_dss_register_drivers(void)
  437. {
  438. int r;
  439. int i;
  440. r = platform_driver_probe(&omap_dss_driver, omap_dss_probe);
  441. if (r)
  442. return r;
  443. r = dss_init_platform_driver();
  444. if (r) {
  445. DSSERR("Failed to initialize DSS platform driver\n");
  446. goto err_dss;
  447. }
  448. r = dispc_init_platform_driver();
  449. if (r) {
  450. DSSERR("Failed to initialize dispc platform driver\n");
  451. goto err_dispc;
  452. }
  453. /*
  454. * It's ok if the output-driver register fails. It happens, for example,
  455. * when there is no output-device (e.g. SDI for OMAP4).
  456. */
  457. for (i = 0; i < ARRAY_SIZE(dss_output_drv_reg_funcs); ++i) {
  458. r = dss_output_drv_reg_funcs[i]();
  459. if (r == 0)
  460. dss_output_drv_loaded[i] = true;
  461. }
  462. return 0;
  463. err_dispc:
  464. dss_uninit_platform_driver();
  465. err_dss:
  466. platform_driver_unregister(&omap_dss_driver);
  467. return r;
  468. }
  469. static void __exit omap_dss_unregister_drivers(void)
  470. {
  471. int i;
  472. for (i = 0; i < ARRAY_SIZE(dss_output_drv_unreg_funcs); ++i) {
  473. if (dss_output_drv_loaded[i])
  474. dss_output_drv_unreg_funcs[i]();
  475. }
  476. dispc_uninit_platform_driver();
  477. dss_uninit_platform_driver();
  478. platform_driver_unregister(&omap_dss_driver);
  479. }
  480. #ifdef CONFIG_OMAP2_DSS_MODULE
  481. static void omap_dss_bus_unregister(void)
  482. {
  483. device_unregister(&dss_bus);
  484. bus_unregister(&dss_bus_type);
  485. }
  486. static int __init omap_dss_init(void)
  487. {
  488. int r;
  489. r = omap_dss_bus_register();
  490. if (r)
  491. return r;
  492. r = omap_dss_register_drivers();
  493. if (r) {
  494. omap_dss_bus_unregister();
  495. return r;
  496. }
  497. return 0;
  498. }
  499. static void __exit omap_dss_exit(void)
  500. {
  501. if (core.vdds_dsi_reg != NULL) {
  502. regulator_put(core.vdds_dsi_reg);
  503. core.vdds_dsi_reg = NULL;
  504. }
  505. if (core.vdds_sdi_reg != NULL) {
  506. regulator_put(core.vdds_sdi_reg);
  507. core.vdds_sdi_reg = NULL;
  508. }
  509. omap_dss_unregister_drivers();
  510. omap_dss_bus_unregister();
  511. }
  512. module_init(omap_dss_init);
  513. module_exit(omap_dss_exit);
  514. #else
  515. static int __init omap_dss_init(void)
  516. {
  517. return omap_dss_bus_register();
  518. }
  519. static int __init omap_dss_init2(void)
  520. {
  521. return omap_dss_register_drivers();
  522. }
  523. core_initcall(omap_dss_init);
  524. device_initcall(omap_dss_init2);
  525. #endif
  526. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
  527. MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
  528. MODULE_LICENSE("GPL v2");