core.c 14 KB

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