core.c 15 KB

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