core.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980
  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 <plat/display.h>
  34. #include <plat/clock.h>
  35. #include "dss.h"
  36. static struct {
  37. struct platform_device *pdev;
  38. int ctx_id;
  39. struct clk *dss_ick;
  40. struct clk *dss1_fck;
  41. struct clk *dss2_fck;
  42. struct clk *dss_54m_fck;
  43. struct clk *dss_96m_fck;
  44. unsigned num_clks_enabled;
  45. struct regulator *vdds_dsi_reg;
  46. struct regulator *vdds_sdi_reg;
  47. struct regulator *vdda_dac_reg;
  48. } core;
  49. static void dss_clk_enable_all_no_ctx(void);
  50. static void dss_clk_disable_all_no_ctx(void);
  51. static void dss_clk_enable_no_ctx(enum dss_clock clks);
  52. static void dss_clk_disable_no_ctx(enum dss_clock clks);
  53. static char *def_disp_name;
  54. module_param_named(def_disp, def_disp_name, charp, 0);
  55. MODULE_PARM_DESC(def_disp_name, "default display name");
  56. #ifdef DEBUG
  57. unsigned int dss_debug;
  58. module_param_named(debug, dss_debug, bool, 0644);
  59. #endif
  60. /* CONTEXT */
  61. static int dss_get_ctx_id(void)
  62. {
  63. struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
  64. int r;
  65. if (!pdata->get_last_off_on_transaction_id)
  66. return 0;
  67. r = pdata->get_last_off_on_transaction_id(&core.pdev->dev);
  68. if (r < 0) {
  69. dev_err(&core.pdev->dev, "getting transaction ID failed, "
  70. "will force context restore\n");
  71. r = -1;
  72. }
  73. return r;
  74. }
  75. int dss_need_ctx_restore(void)
  76. {
  77. int id = dss_get_ctx_id();
  78. if (id < 0 || id != core.ctx_id) {
  79. DSSDBG("ctx id %d -> id %d\n",
  80. core.ctx_id, id);
  81. core.ctx_id = id;
  82. return 1;
  83. } else {
  84. return 0;
  85. }
  86. }
  87. static void save_all_ctx(void)
  88. {
  89. DSSDBG("save context\n");
  90. dss_clk_enable_no_ctx(DSS_CLK_ICK | DSS_CLK_FCK1);
  91. dss_save_context();
  92. dispc_save_context();
  93. #ifdef CONFIG_OMAP2_DSS_DSI
  94. dsi_save_context();
  95. #endif
  96. dss_clk_disable_no_ctx(DSS_CLK_ICK | DSS_CLK_FCK1);
  97. }
  98. static void restore_all_ctx(void)
  99. {
  100. DSSDBG("restore context\n");
  101. dss_clk_enable_all_no_ctx();
  102. dss_restore_context();
  103. dispc_restore_context();
  104. #ifdef CONFIG_OMAP2_DSS_DSI
  105. dsi_restore_context();
  106. #endif
  107. dss_clk_disable_all_no_ctx();
  108. }
  109. #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_OMAP2_DSS_DEBUG_SUPPORT)
  110. /* CLOCKS */
  111. static void core_dump_clocks(struct seq_file *s)
  112. {
  113. int i;
  114. struct clk *clocks[5] = {
  115. core.dss_ick,
  116. core.dss1_fck,
  117. core.dss2_fck,
  118. core.dss_54m_fck,
  119. core.dss_96m_fck
  120. };
  121. seq_printf(s, "- CORE -\n");
  122. seq_printf(s, "internal clk count\t\t%u\n", core.num_clks_enabled);
  123. for (i = 0; i < 5; i++) {
  124. if (!clocks[i])
  125. continue;
  126. seq_printf(s, "%-15s\t%lu\t%d\n",
  127. clocks[i]->name,
  128. clk_get_rate(clocks[i]),
  129. clocks[i]->usecount);
  130. }
  131. }
  132. #endif /* defined(CONFIG_DEBUG_FS) && defined(CONFIG_OMAP2_DSS_DEBUG_SUPPORT) */
  133. static int dss_get_clock(struct clk **clock, const char *clk_name)
  134. {
  135. struct clk *clk;
  136. clk = clk_get(&core.pdev->dev, clk_name);
  137. if (IS_ERR(clk)) {
  138. DSSERR("can't get clock %s", clk_name);
  139. return PTR_ERR(clk);
  140. }
  141. *clock = clk;
  142. DSSDBG("clk %s, rate %ld\n", clk_name, clk_get_rate(clk));
  143. return 0;
  144. }
  145. static int dss_get_clocks(void)
  146. {
  147. int r;
  148. core.dss_ick = NULL;
  149. core.dss1_fck = NULL;
  150. core.dss2_fck = NULL;
  151. core.dss_54m_fck = NULL;
  152. core.dss_96m_fck = NULL;
  153. r = dss_get_clock(&core.dss_ick, "ick");
  154. if (r)
  155. goto err;
  156. r = dss_get_clock(&core.dss1_fck, "dss1_fck");
  157. if (r)
  158. goto err;
  159. r = dss_get_clock(&core.dss2_fck, "dss2_fck");
  160. if (r)
  161. goto err;
  162. r = dss_get_clock(&core.dss_54m_fck, "tv_fck");
  163. if (r)
  164. goto err;
  165. r = dss_get_clock(&core.dss_96m_fck, "video_fck");
  166. if (r)
  167. goto err;
  168. return 0;
  169. err:
  170. if (core.dss_ick)
  171. clk_put(core.dss_ick);
  172. if (core.dss1_fck)
  173. clk_put(core.dss1_fck);
  174. if (core.dss2_fck)
  175. clk_put(core.dss2_fck);
  176. if (core.dss_54m_fck)
  177. clk_put(core.dss_54m_fck);
  178. if (core.dss_96m_fck)
  179. clk_put(core.dss_96m_fck);
  180. return r;
  181. }
  182. static void dss_put_clocks(void)
  183. {
  184. if (core.dss_96m_fck)
  185. clk_put(core.dss_96m_fck);
  186. clk_put(core.dss_54m_fck);
  187. clk_put(core.dss1_fck);
  188. clk_put(core.dss2_fck);
  189. clk_put(core.dss_ick);
  190. }
  191. unsigned long dss_clk_get_rate(enum dss_clock clk)
  192. {
  193. switch (clk) {
  194. case DSS_CLK_ICK:
  195. return clk_get_rate(core.dss_ick);
  196. case DSS_CLK_FCK1:
  197. return clk_get_rate(core.dss1_fck);
  198. case DSS_CLK_FCK2:
  199. return clk_get_rate(core.dss2_fck);
  200. case DSS_CLK_54M:
  201. return clk_get_rate(core.dss_54m_fck);
  202. case DSS_CLK_96M:
  203. return clk_get_rate(core.dss_96m_fck);
  204. }
  205. BUG();
  206. return 0;
  207. }
  208. static unsigned count_clk_bits(enum dss_clock clks)
  209. {
  210. unsigned num_clks = 0;
  211. if (clks & DSS_CLK_ICK)
  212. ++num_clks;
  213. if (clks & DSS_CLK_FCK1)
  214. ++num_clks;
  215. if (clks & DSS_CLK_FCK2)
  216. ++num_clks;
  217. if (clks & DSS_CLK_54M)
  218. ++num_clks;
  219. if (clks & DSS_CLK_96M)
  220. ++num_clks;
  221. return num_clks;
  222. }
  223. static void dss_clk_enable_no_ctx(enum dss_clock clks)
  224. {
  225. unsigned num_clks = count_clk_bits(clks);
  226. if (clks & DSS_CLK_ICK)
  227. clk_enable(core.dss_ick);
  228. if (clks & DSS_CLK_FCK1)
  229. clk_enable(core.dss1_fck);
  230. if (clks & DSS_CLK_FCK2)
  231. clk_enable(core.dss2_fck);
  232. if (clks & DSS_CLK_54M)
  233. clk_enable(core.dss_54m_fck);
  234. if (clks & DSS_CLK_96M)
  235. clk_enable(core.dss_96m_fck);
  236. core.num_clks_enabled += num_clks;
  237. }
  238. void dss_clk_enable(enum dss_clock clks)
  239. {
  240. bool check_ctx = core.num_clks_enabled == 0;
  241. dss_clk_enable_no_ctx(clks);
  242. if (check_ctx && cpu_is_omap34xx() && dss_need_ctx_restore())
  243. restore_all_ctx();
  244. }
  245. static void dss_clk_disable_no_ctx(enum dss_clock clks)
  246. {
  247. unsigned num_clks = count_clk_bits(clks);
  248. if (clks & DSS_CLK_ICK)
  249. clk_disable(core.dss_ick);
  250. if (clks & DSS_CLK_FCK1)
  251. clk_disable(core.dss1_fck);
  252. if (clks & DSS_CLK_FCK2)
  253. clk_disable(core.dss2_fck);
  254. if (clks & DSS_CLK_54M)
  255. clk_disable(core.dss_54m_fck);
  256. if (clks & DSS_CLK_96M)
  257. clk_disable(core.dss_96m_fck);
  258. core.num_clks_enabled -= num_clks;
  259. }
  260. void dss_clk_disable(enum dss_clock clks)
  261. {
  262. if (cpu_is_omap34xx()) {
  263. unsigned num_clks = count_clk_bits(clks);
  264. BUG_ON(core.num_clks_enabled < num_clks);
  265. if (core.num_clks_enabled == num_clks)
  266. save_all_ctx();
  267. }
  268. dss_clk_disable_no_ctx(clks);
  269. }
  270. static void dss_clk_enable_all_no_ctx(void)
  271. {
  272. enum dss_clock clks;
  273. clks = DSS_CLK_ICK | DSS_CLK_FCK1 | DSS_CLK_FCK2 | DSS_CLK_54M;
  274. if (cpu_is_omap34xx())
  275. clks |= DSS_CLK_96M;
  276. dss_clk_enable_no_ctx(clks);
  277. }
  278. static void dss_clk_disable_all_no_ctx(void)
  279. {
  280. enum dss_clock clks;
  281. clks = DSS_CLK_ICK | DSS_CLK_FCK1 | DSS_CLK_FCK2 | DSS_CLK_54M;
  282. if (cpu_is_omap34xx())
  283. clks |= DSS_CLK_96M;
  284. dss_clk_disable_no_ctx(clks);
  285. }
  286. static void dss_clk_disable_all(void)
  287. {
  288. enum dss_clock clks;
  289. clks = DSS_CLK_ICK | DSS_CLK_FCK1 | DSS_CLK_FCK2 | DSS_CLK_54M;
  290. if (cpu_is_omap34xx())
  291. clks |= DSS_CLK_96M;
  292. dss_clk_disable(clks);
  293. }
  294. /* REGULATORS */
  295. struct regulator *dss_get_vdds_dsi(void)
  296. {
  297. struct regulator *reg;
  298. if (core.vdds_dsi_reg != NULL)
  299. return core.vdds_dsi_reg;
  300. reg = regulator_get(&core.pdev->dev, "vdds_dsi");
  301. if (!IS_ERR(reg))
  302. core.vdds_dsi_reg = reg;
  303. return reg;
  304. }
  305. struct regulator *dss_get_vdds_sdi(void)
  306. {
  307. struct regulator *reg;
  308. if (core.vdds_sdi_reg != NULL)
  309. return core.vdds_sdi_reg;
  310. reg = regulator_get(&core.pdev->dev, "vdds_sdi");
  311. if (!IS_ERR(reg))
  312. core.vdds_sdi_reg = reg;
  313. return reg;
  314. }
  315. struct regulator *dss_get_vdda_dac(void)
  316. {
  317. struct regulator *reg;
  318. if (core.vdda_dac_reg != NULL)
  319. return core.vdda_dac_reg;
  320. reg = regulator_get(&core.pdev->dev, "vdda_dac");
  321. if (!IS_ERR(reg))
  322. core.vdda_dac_reg = reg;
  323. return reg;
  324. }
  325. /* DEBUGFS */
  326. #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_OMAP2_DSS_DEBUG_SUPPORT)
  327. static void dss_debug_dump_clocks(struct seq_file *s)
  328. {
  329. core_dump_clocks(s);
  330. dss_dump_clocks(s);
  331. dispc_dump_clocks(s);
  332. #ifdef CONFIG_OMAP2_DSS_DSI
  333. dsi_dump_clocks(s);
  334. #endif
  335. }
  336. static int dss_debug_show(struct seq_file *s, void *unused)
  337. {
  338. void (*func)(struct seq_file *) = s->private;
  339. func(s);
  340. return 0;
  341. }
  342. static int dss_debug_open(struct inode *inode, struct file *file)
  343. {
  344. return single_open(file, dss_debug_show, inode->i_private);
  345. }
  346. static const struct file_operations dss_debug_fops = {
  347. .open = dss_debug_open,
  348. .read = seq_read,
  349. .llseek = seq_lseek,
  350. .release = single_release,
  351. };
  352. static struct dentry *dss_debugfs_dir;
  353. static int dss_initialize_debugfs(void)
  354. {
  355. dss_debugfs_dir = debugfs_create_dir("omapdss", NULL);
  356. if (IS_ERR(dss_debugfs_dir)) {
  357. int err = PTR_ERR(dss_debugfs_dir);
  358. dss_debugfs_dir = NULL;
  359. return err;
  360. }
  361. debugfs_create_file("clk", S_IRUGO, dss_debugfs_dir,
  362. &dss_debug_dump_clocks, &dss_debug_fops);
  363. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  364. debugfs_create_file("dispc_irq", S_IRUGO, dss_debugfs_dir,
  365. &dispc_dump_irqs, &dss_debug_fops);
  366. #endif
  367. #if defined(CONFIG_OMAP2_DSS_DSI) && defined(CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS)
  368. debugfs_create_file("dsi_irq", S_IRUGO, dss_debugfs_dir,
  369. &dsi_dump_irqs, &dss_debug_fops);
  370. #endif
  371. debugfs_create_file("dss", S_IRUGO, dss_debugfs_dir,
  372. &dss_dump_regs, &dss_debug_fops);
  373. debugfs_create_file("dispc", S_IRUGO, dss_debugfs_dir,
  374. &dispc_dump_regs, &dss_debug_fops);
  375. #ifdef CONFIG_OMAP2_DSS_RFBI
  376. debugfs_create_file("rfbi", S_IRUGO, dss_debugfs_dir,
  377. &rfbi_dump_regs, &dss_debug_fops);
  378. #endif
  379. #ifdef CONFIG_OMAP2_DSS_DSI
  380. debugfs_create_file("dsi", S_IRUGO, dss_debugfs_dir,
  381. &dsi_dump_regs, &dss_debug_fops);
  382. #endif
  383. #ifdef CONFIG_OMAP2_DSS_VENC
  384. debugfs_create_file("venc", S_IRUGO, dss_debugfs_dir,
  385. &venc_dump_regs, &dss_debug_fops);
  386. #endif
  387. return 0;
  388. }
  389. static void dss_uninitialize_debugfs(void)
  390. {
  391. if (dss_debugfs_dir)
  392. debugfs_remove_recursive(dss_debugfs_dir);
  393. }
  394. #endif /* CONFIG_DEBUG_FS && CONFIG_OMAP2_DSS_DEBUG_SUPPORT */
  395. /* PLATFORM DEVICE */
  396. static int omap_dss_probe(struct platform_device *pdev)
  397. {
  398. struct omap_dss_board_info *pdata = pdev->dev.platform_data;
  399. int skip_init = 0;
  400. int r;
  401. int i;
  402. core.pdev = pdev;
  403. dss_init_overlay_managers(pdev);
  404. dss_init_overlays(pdev);
  405. r = dss_get_clocks();
  406. if (r)
  407. goto fail0;
  408. dss_clk_enable_all_no_ctx();
  409. core.ctx_id = dss_get_ctx_id();
  410. DSSDBG("initial ctx id %u\n", core.ctx_id);
  411. #ifdef CONFIG_FB_OMAP_BOOTLOADER_INIT
  412. /* DISPC_CONTROL */
  413. if (omap_readl(0x48050440) & 1) /* LCD enabled? */
  414. skip_init = 1;
  415. #endif
  416. r = dss_init(skip_init);
  417. if (r) {
  418. DSSERR("Failed to initialize DSS\n");
  419. goto fail0;
  420. }
  421. #ifdef CONFIG_OMAP2_DSS_RFBI
  422. r = rfbi_init();
  423. if (r) {
  424. DSSERR("Failed to initialize rfbi\n");
  425. goto fail0;
  426. }
  427. #endif
  428. #ifdef CONFIG_OMAP2_DSS_DPI
  429. r = dpi_init(pdev);
  430. if (r) {
  431. DSSERR("Failed to initialize dpi\n");
  432. goto fail0;
  433. }
  434. #endif
  435. r = dispc_init();
  436. if (r) {
  437. DSSERR("Failed to initialize dispc\n");
  438. goto fail0;
  439. }
  440. #ifdef CONFIG_OMAP2_DSS_VENC
  441. r = venc_init(pdev);
  442. if (r) {
  443. DSSERR("Failed to initialize venc\n");
  444. goto fail0;
  445. }
  446. #endif
  447. if (cpu_is_omap34xx()) {
  448. #ifdef CONFIG_OMAP2_DSS_SDI
  449. r = sdi_init(skip_init);
  450. if (r) {
  451. DSSERR("Failed to initialize SDI\n");
  452. goto fail0;
  453. }
  454. #endif
  455. #ifdef CONFIG_OMAP2_DSS_DSI
  456. r = dsi_init(pdev);
  457. if (r) {
  458. DSSERR("Failed to initialize DSI\n");
  459. goto fail0;
  460. }
  461. #endif
  462. }
  463. #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_OMAP2_DSS_DEBUG_SUPPORT)
  464. r = dss_initialize_debugfs();
  465. if (r)
  466. goto fail0;
  467. #endif
  468. for (i = 0; i < pdata->num_devices; ++i) {
  469. struct omap_dss_device *dssdev = pdata->devices[i];
  470. r = omap_dss_register_device(dssdev);
  471. if (r)
  472. DSSERR("device reg failed %d\n", i);
  473. if (def_disp_name && strcmp(def_disp_name, dssdev->name) == 0)
  474. pdata->default_device = dssdev;
  475. }
  476. dss_clk_disable_all();
  477. return 0;
  478. /* XXX fail correctly */
  479. fail0:
  480. return r;
  481. }
  482. static int omap_dss_remove(struct platform_device *pdev)
  483. {
  484. struct omap_dss_board_info *pdata = pdev->dev.platform_data;
  485. int i;
  486. int c;
  487. #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_OMAP2_DSS_DEBUG_SUPPORT)
  488. dss_uninitialize_debugfs();
  489. #endif
  490. #ifdef CONFIG_OMAP2_DSS_VENC
  491. venc_exit();
  492. #endif
  493. dispc_exit();
  494. #ifdef CONFIG_OMAP2_DSS_DPI
  495. dpi_exit();
  496. #endif
  497. #ifdef CONFIG_OMAP2_DSS_RFBI
  498. rfbi_exit();
  499. #endif
  500. if (cpu_is_omap34xx()) {
  501. #ifdef CONFIG_OMAP2_DSS_DSI
  502. dsi_exit();
  503. #endif
  504. #ifdef CONFIG_OMAP2_DSS_SDI
  505. sdi_exit();
  506. #endif
  507. }
  508. dss_exit();
  509. /* these should be removed at some point */
  510. c = core.dss_ick->usecount;
  511. if (c > 0) {
  512. DSSERR("warning: dss_ick usecount %d, disabling\n", c);
  513. while (c-- > 0)
  514. clk_disable(core.dss_ick);
  515. }
  516. c = core.dss1_fck->usecount;
  517. if (c > 0) {
  518. DSSERR("warning: dss1_fck usecount %d, disabling\n", c);
  519. while (c-- > 0)
  520. clk_disable(core.dss1_fck);
  521. }
  522. c = core.dss2_fck->usecount;
  523. if (c > 0) {
  524. DSSERR("warning: dss2_fck usecount %d, disabling\n", c);
  525. while (c-- > 0)
  526. clk_disable(core.dss2_fck);
  527. }
  528. c = core.dss_54m_fck->usecount;
  529. if (c > 0) {
  530. DSSERR("warning: dss_54m_fck usecount %d, disabling\n", c);
  531. while (c-- > 0)
  532. clk_disable(core.dss_54m_fck);
  533. }
  534. if (core.dss_96m_fck) {
  535. c = core.dss_96m_fck->usecount;
  536. if (c > 0) {
  537. DSSERR("warning: dss_96m_fck usecount %d, disabling\n",
  538. c);
  539. while (c-- > 0)
  540. clk_disable(core.dss_96m_fck);
  541. }
  542. }
  543. dss_put_clocks();
  544. dss_uninit_overlays(pdev);
  545. dss_uninit_overlay_managers(pdev);
  546. for (i = 0; i < pdata->num_devices; ++i)
  547. omap_dss_unregister_device(pdata->devices[i]);
  548. return 0;
  549. }
  550. static void omap_dss_shutdown(struct platform_device *pdev)
  551. {
  552. DSSDBG("shutdown\n");
  553. dss_disable_all_devices();
  554. }
  555. static int omap_dss_suspend(struct platform_device *pdev, pm_message_t state)
  556. {
  557. DSSDBG("suspend %d\n", state.event);
  558. return dss_suspend_all_devices();
  559. }
  560. static int omap_dss_resume(struct platform_device *pdev)
  561. {
  562. DSSDBG("resume\n");
  563. return dss_resume_all_devices();
  564. }
  565. static struct platform_driver omap_dss_driver = {
  566. .probe = omap_dss_probe,
  567. .remove = omap_dss_remove,
  568. .shutdown = omap_dss_shutdown,
  569. .suspend = omap_dss_suspend,
  570. .resume = omap_dss_resume,
  571. .driver = {
  572. .name = "omapdss",
  573. .owner = THIS_MODULE,
  574. },
  575. };
  576. /* BUS */
  577. static int dss_bus_match(struct device *dev, struct device_driver *driver)
  578. {
  579. struct omap_dss_device *dssdev = to_dss_device(dev);
  580. DSSDBG("bus_match. dev %s/%s, drv %s\n",
  581. dev_name(dev), dssdev->driver_name, driver->name);
  582. return strcmp(dssdev->driver_name, driver->name) == 0;
  583. }
  584. static ssize_t device_name_show(struct device *dev,
  585. struct device_attribute *attr, char *buf)
  586. {
  587. struct omap_dss_device *dssdev = to_dss_device(dev);
  588. return snprintf(buf, PAGE_SIZE, "%s\n",
  589. dssdev->name ?
  590. dssdev->name : "");
  591. }
  592. static struct device_attribute default_dev_attrs[] = {
  593. __ATTR(name, S_IRUGO, device_name_show, NULL),
  594. __ATTR_NULL,
  595. };
  596. static ssize_t driver_name_show(struct device_driver *drv, char *buf)
  597. {
  598. struct omap_dss_driver *dssdrv = to_dss_driver(drv);
  599. return snprintf(buf, PAGE_SIZE, "%s\n",
  600. dssdrv->driver.name ?
  601. dssdrv->driver.name : "");
  602. }
  603. static struct driver_attribute default_drv_attrs[] = {
  604. __ATTR(name, S_IRUGO, driver_name_show, NULL),
  605. __ATTR_NULL,
  606. };
  607. static struct bus_type dss_bus_type = {
  608. .name = "omapdss",
  609. .match = dss_bus_match,
  610. .dev_attrs = default_dev_attrs,
  611. .drv_attrs = default_drv_attrs,
  612. };
  613. static void dss_bus_release(struct device *dev)
  614. {
  615. DSSDBG("bus_release\n");
  616. }
  617. static struct device dss_bus = {
  618. .release = dss_bus_release,
  619. };
  620. struct bus_type *dss_get_bus(void)
  621. {
  622. return &dss_bus_type;
  623. }
  624. /* DRIVER */
  625. static int dss_driver_probe(struct device *dev)
  626. {
  627. int r;
  628. struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
  629. struct omap_dss_device *dssdev = to_dss_device(dev);
  630. struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
  631. bool force;
  632. DSSDBG("driver_probe: dev %s/%s, drv %s\n",
  633. dev_name(dev), dssdev->driver_name,
  634. dssdrv->driver.name);
  635. dss_init_device(core.pdev, dssdev);
  636. force = pdata->default_device == dssdev;
  637. dss_recheck_connections(dssdev, force);
  638. r = dssdrv->probe(dssdev);
  639. if (r) {
  640. DSSERR("driver probe failed: %d\n", r);
  641. dss_uninit_device(core.pdev, dssdev);
  642. return r;
  643. }
  644. DSSDBG("probe done for device %s\n", dev_name(dev));
  645. dssdev->driver = dssdrv;
  646. return 0;
  647. }
  648. static int dss_driver_remove(struct device *dev)
  649. {
  650. struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
  651. struct omap_dss_device *dssdev = to_dss_device(dev);
  652. DSSDBG("driver_remove: dev %s/%s\n", dev_name(dev),
  653. dssdev->driver_name);
  654. dssdrv->remove(dssdev);
  655. dss_uninit_device(core.pdev, dssdev);
  656. dssdev->driver = NULL;
  657. return 0;
  658. }
  659. int omap_dss_register_driver(struct omap_dss_driver *dssdriver)
  660. {
  661. dssdriver->driver.bus = &dss_bus_type;
  662. dssdriver->driver.probe = dss_driver_probe;
  663. dssdriver->driver.remove = dss_driver_remove;
  664. if (dssdriver->get_resolution == NULL)
  665. dssdriver->get_resolution = omapdss_default_get_resolution;
  666. if (dssdriver->get_recommended_bpp == NULL)
  667. dssdriver->get_recommended_bpp =
  668. omapdss_default_get_recommended_bpp;
  669. return driver_register(&dssdriver->driver);
  670. }
  671. EXPORT_SYMBOL(omap_dss_register_driver);
  672. void omap_dss_unregister_driver(struct omap_dss_driver *dssdriver)
  673. {
  674. driver_unregister(&dssdriver->driver);
  675. }
  676. EXPORT_SYMBOL(omap_dss_unregister_driver);
  677. /* DEVICE */
  678. static void reset_device(struct device *dev, int check)
  679. {
  680. u8 *dev_p = (u8 *)dev;
  681. u8 *dev_end = dev_p + sizeof(*dev);
  682. void *saved_pdata;
  683. saved_pdata = dev->platform_data;
  684. if (check) {
  685. /*
  686. * Check if there is any other setting than platform_data
  687. * in struct device; warn that these will be reset by our
  688. * init.
  689. */
  690. dev->platform_data = NULL;
  691. while (dev_p < dev_end) {
  692. if (*dev_p) {
  693. WARN("%s: struct device fields will be "
  694. "discarded\n",
  695. __func__);
  696. break;
  697. }
  698. dev_p++;
  699. }
  700. }
  701. memset(dev, 0, sizeof(*dev));
  702. dev->platform_data = saved_pdata;
  703. }
  704. static void omap_dss_dev_release(struct device *dev)
  705. {
  706. reset_device(dev, 0);
  707. }
  708. int omap_dss_register_device(struct omap_dss_device *dssdev)
  709. {
  710. static int dev_num;
  711. WARN_ON(!dssdev->driver_name);
  712. reset_device(&dssdev->dev, 1);
  713. dssdev->dev.bus = &dss_bus_type;
  714. dssdev->dev.parent = &dss_bus;
  715. dssdev->dev.release = omap_dss_dev_release;
  716. dev_set_name(&dssdev->dev, "display%d", dev_num++);
  717. return device_register(&dssdev->dev);
  718. }
  719. void omap_dss_unregister_device(struct omap_dss_device *dssdev)
  720. {
  721. device_unregister(&dssdev->dev);
  722. }
  723. /* BUS */
  724. static int omap_dss_bus_register(void)
  725. {
  726. int r;
  727. r = bus_register(&dss_bus_type);
  728. if (r) {
  729. DSSERR("bus register failed\n");
  730. return r;
  731. }
  732. dev_set_name(&dss_bus, "omapdss");
  733. r = device_register(&dss_bus);
  734. if (r) {
  735. DSSERR("bus driver register failed\n");
  736. bus_unregister(&dss_bus_type);
  737. return r;
  738. }
  739. return 0;
  740. }
  741. /* INIT */
  742. #ifdef CONFIG_OMAP2_DSS_MODULE
  743. static void omap_dss_bus_unregister(void)
  744. {
  745. device_unregister(&dss_bus);
  746. bus_unregister(&dss_bus_type);
  747. }
  748. static int __init omap_dss_init(void)
  749. {
  750. int r;
  751. r = omap_dss_bus_register();
  752. if (r)
  753. return r;
  754. r = platform_driver_register(&omap_dss_driver);
  755. if (r) {
  756. omap_dss_bus_unregister();
  757. return r;
  758. }
  759. return 0;
  760. }
  761. static void __exit omap_dss_exit(void)
  762. {
  763. if (core.vdds_dsi_reg != NULL) {
  764. regulator_put(core.vdds_dsi_reg);
  765. core.vdds_dsi_reg = NULL;
  766. }
  767. if (core.vdds_sdi_reg != NULL) {
  768. regulator_put(core.vdds_sdi_reg);
  769. core.vdds_sdi_reg = NULL;
  770. }
  771. if (core.vdda_dac_reg != NULL) {
  772. regulator_put(core.vdda_dac_reg);
  773. core.vdda_dac_reg = NULL;
  774. }
  775. platform_driver_unregister(&omap_dss_driver);
  776. omap_dss_bus_unregister();
  777. }
  778. module_init(omap_dss_init);
  779. module_exit(omap_dss_exit);
  780. #else
  781. static int __init omap_dss_init(void)
  782. {
  783. return omap_dss_bus_register();
  784. }
  785. static int __init omap_dss_init2(void)
  786. {
  787. return platform_driver_register(&omap_dss_driver);
  788. }
  789. core_initcall(omap_dss_init);
  790. device_initcall(omap_dss_init2);
  791. #endif
  792. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
  793. MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
  794. MODULE_LICENSE("GPL v2");