core.c 14 KB

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