core.c 14 KB

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