core.c 14 KB

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