core.c 13 KB

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