core.c 14 KB

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