core.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  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. r = dpi_init(pdev);
  429. if (r) {
  430. DSSERR("Failed to initialize dpi\n");
  431. goto fail0;
  432. }
  433. r = dispc_init();
  434. if (r) {
  435. DSSERR("Failed to initialize dispc\n");
  436. goto fail0;
  437. }
  438. #ifdef CONFIG_OMAP2_DSS_VENC
  439. r = venc_init(pdev);
  440. if (r) {
  441. DSSERR("Failed to initialize venc\n");
  442. goto fail0;
  443. }
  444. #endif
  445. if (cpu_is_omap34xx()) {
  446. #ifdef CONFIG_OMAP2_DSS_SDI
  447. r = sdi_init(skip_init);
  448. if (r) {
  449. DSSERR("Failed to initialize SDI\n");
  450. goto fail0;
  451. }
  452. #endif
  453. #ifdef CONFIG_OMAP2_DSS_DSI
  454. r = dsi_init(pdev);
  455. if (r) {
  456. DSSERR("Failed to initialize DSI\n");
  457. goto fail0;
  458. }
  459. #endif
  460. }
  461. #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_OMAP2_DSS_DEBUG_SUPPORT)
  462. r = dss_initialize_debugfs();
  463. if (r)
  464. goto fail0;
  465. #endif
  466. for (i = 0; i < pdata->num_devices; ++i) {
  467. struct omap_dss_device *dssdev = pdata->devices[i];
  468. r = omap_dss_register_device(dssdev);
  469. if (r)
  470. DSSERR("device reg failed %d\n", i);
  471. if (def_disp_name && strcmp(def_disp_name, dssdev->name) == 0)
  472. pdata->default_device = dssdev;
  473. }
  474. dss_clk_disable_all();
  475. return 0;
  476. /* XXX fail correctly */
  477. fail0:
  478. return r;
  479. }
  480. static int omap_dss_remove(struct platform_device *pdev)
  481. {
  482. struct omap_dss_board_info *pdata = pdev->dev.platform_data;
  483. int i;
  484. int c;
  485. #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_OMAP2_DSS_DEBUG_SUPPORT)
  486. dss_uninitialize_debugfs();
  487. #endif
  488. #ifdef CONFIG_OMAP2_DSS_VENC
  489. venc_exit();
  490. #endif
  491. dispc_exit();
  492. dpi_exit();
  493. #ifdef CONFIG_OMAP2_DSS_RFBI
  494. rfbi_exit();
  495. #endif
  496. if (cpu_is_omap34xx()) {
  497. #ifdef CONFIG_OMAP2_DSS_DSI
  498. dsi_exit();
  499. #endif
  500. #ifdef CONFIG_OMAP2_DSS_SDI
  501. sdi_exit();
  502. #endif
  503. }
  504. dss_exit();
  505. /* these should be removed at some point */
  506. c = core.dss_ick->usecount;
  507. if (c > 0) {
  508. DSSERR("warning: dss_ick usecount %d, disabling\n", c);
  509. while (c-- > 0)
  510. clk_disable(core.dss_ick);
  511. }
  512. c = core.dss1_fck->usecount;
  513. if (c > 0) {
  514. DSSERR("warning: dss1_fck usecount %d, disabling\n", c);
  515. while (c-- > 0)
  516. clk_disable(core.dss1_fck);
  517. }
  518. c = core.dss2_fck->usecount;
  519. if (c > 0) {
  520. DSSERR("warning: dss2_fck usecount %d, disabling\n", c);
  521. while (c-- > 0)
  522. clk_disable(core.dss2_fck);
  523. }
  524. c = core.dss_54m_fck->usecount;
  525. if (c > 0) {
  526. DSSERR("warning: dss_54m_fck usecount %d, disabling\n", c);
  527. while (c-- > 0)
  528. clk_disable(core.dss_54m_fck);
  529. }
  530. if (core.dss_96m_fck) {
  531. c = core.dss_96m_fck->usecount;
  532. if (c > 0) {
  533. DSSERR("warning: dss_96m_fck usecount %d, disabling\n",
  534. c);
  535. while (c-- > 0)
  536. clk_disable(core.dss_96m_fck);
  537. }
  538. }
  539. dss_put_clocks();
  540. dss_uninit_overlays(pdev);
  541. dss_uninit_overlay_managers(pdev);
  542. for (i = 0; i < pdata->num_devices; ++i)
  543. omap_dss_unregister_device(pdata->devices[i]);
  544. return 0;
  545. }
  546. static void omap_dss_shutdown(struct platform_device *pdev)
  547. {
  548. DSSDBG("shutdown\n");
  549. dss_disable_all_devices();
  550. }
  551. static int omap_dss_suspend(struct platform_device *pdev, pm_message_t state)
  552. {
  553. DSSDBG("suspend %d\n", state.event);
  554. return dss_suspend_all_devices();
  555. }
  556. static int omap_dss_resume(struct platform_device *pdev)
  557. {
  558. DSSDBG("resume\n");
  559. return dss_resume_all_devices();
  560. }
  561. static struct platform_driver omap_dss_driver = {
  562. .probe = omap_dss_probe,
  563. .remove = omap_dss_remove,
  564. .shutdown = omap_dss_shutdown,
  565. .suspend = omap_dss_suspend,
  566. .resume = omap_dss_resume,
  567. .driver = {
  568. .name = "omapdss",
  569. .owner = THIS_MODULE,
  570. },
  571. };
  572. /* BUS */
  573. static int dss_bus_match(struct device *dev, struct device_driver *driver)
  574. {
  575. struct omap_dss_device *dssdev = to_dss_device(dev);
  576. DSSDBG("bus_match. dev %s/%s, drv %s\n",
  577. dev_name(dev), dssdev->driver_name, driver->name);
  578. return strcmp(dssdev->driver_name, driver->name) == 0;
  579. }
  580. static ssize_t device_name_show(struct device *dev,
  581. struct device_attribute *attr, char *buf)
  582. {
  583. struct omap_dss_device *dssdev = to_dss_device(dev);
  584. return snprintf(buf, PAGE_SIZE, "%s\n",
  585. dssdev->name ?
  586. dssdev->name : "");
  587. }
  588. static struct device_attribute default_dev_attrs[] = {
  589. __ATTR(name, S_IRUGO, device_name_show, NULL),
  590. __ATTR_NULL,
  591. };
  592. static ssize_t driver_name_show(struct device_driver *drv, char *buf)
  593. {
  594. struct omap_dss_driver *dssdrv = to_dss_driver(drv);
  595. return snprintf(buf, PAGE_SIZE, "%s\n",
  596. dssdrv->driver.name ?
  597. dssdrv->driver.name : "");
  598. }
  599. static struct driver_attribute default_drv_attrs[] = {
  600. __ATTR(name, S_IRUGO, driver_name_show, NULL),
  601. __ATTR_NULL,
  602. };
  603. static struct bus_type dss_bus_type = {
  604. .name = "omapdss",
  605. .match = dss_bus_match,
  606. .dev_attrs = default_dev_attrs,
  607. .drv_attrs = default_drv_attrs,
  608. };
  609. static void dss_bus_release(struct device *dev)
  610. {
  611. DSSDBG("bus_release\n");
  612. }
  613. static struct device dss_bus = {
  614. .release = dss_bus_release,
  615. };
  616. struct bus_type *dss_get_bus(void)
  617. {
  618. return &dss_bus_type;
  619. }
  620. /* DRIVER */
  621. static int dss_driver_probe(struct device *dev)
  622. {
  623. int r;
  624. struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
  625. struct omap_dss_device *dssdev = to_dss_device(dev);
  626. struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
  627. bool force;
  628. DSSDBG("driver_probe: dev %s/%s, drv %s\n",
  629. dev_name(dev), dssdev->driver_name,
  630. dssdrv->driver.name);
  631. dss_init_device(core.pdev, dssdev);
  632. force = pdata->default_device == dssdev;
  633. dss_recheck_connections(dssdev, force);
  634. r = dssdrv->probe(dssdev);
  635. if (r) {
  636. DSSERR("driver probe failed: %d\n", r);
  637. dss_uninit_device(core.pdev, dssdev);
  638. return r;
  639. }
  640. DSSDBG("probe done for device %s\n", dev_name(dev));
  641. dssdev->driver = dssdrv;
  642. return 0;
  643. }
  644. static int dss_driver_remove(struct device *dev)
  645. {
  646. struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
  647. struct omap_dss_device *dssdev = to_dss_device(dev);
  648. DSSDBG("driver_remove: dev %s/%s\n", dev_name(dev),
  649. dssdev->driver_name);
  650. dssdrv->remove(dssdev);
  651. dss_uninit_device(core.pdev, dssdev);
  652. dssdev->driver = NULL;
  653. return 0;
  654. }
  655. int omap_dss_register_driver(struct omap_dss_driver *dssdriver)
  656. {
  657. dssdriver->driver.bus = &dss_bus_type;
  658. dssdriver->driver.probe = dss_driver_probe;
  659. dssdriver->driver.remove = dss_driver_remove;
  660. if (dssdriver->get_resolution == NULL)
  661. dssdriver->get_resolution = omapdss_default_get_resolution;
  662. if (dssdriver->get_recommended_bpp == NULL)
  663. dssdriver->get_recommended_bpp =
  664. omapdss_default_get_recommended_bpp;
  665. return driver_register(&dssdriver->driver);
  666. }
  667. EXPORT_SYMBOL(omap_dss_register_driver);
  668. void omap_dss_unregister_driver(struct omap_dss_driver *dssdriver)
  669. {
  670. driver_unregister(&dssdriver->driver);
  671. }
  672. EXPORT_SYMBOL(omap_dss_unregister_driver);
  673. /* DEVICE */
  674. static void reset_device(struct device *dev, int check)
  675. {
  676. u8 *dev_p = (u8 *)dev;
  677. u8 *dev_end = dev_p + sizeof(*dev);
  678. void *saved_pdata;
  679. saved_pdata = dev->platform_data;
  680. if (check) {
  681. /*
  682. * Check if there is any other setting than platform_data
  683. * in struct device; warn that these will be reset by our
  684. * init.
  685. */
  686. dev->platform_data = NULL;
  687. while (dev_p < dev_end) {
  688. if (*dev_p) {
  689. WARN("%s: struct device fields will be "
  690. "discarded\n",
  691. __func__);
  692. break;
  693. }
  694. dev_p++;
  695. }
  696. }
  697. memset(dev, 0, sizeof(*dev));
  698. dev->platform_data = saved_pdata;
  699. }
  700. static void omap_dss_dev_release(struct device *dev)
  701. {
  702. reset_device(dev, 0);
  703. }
  704. int omap_dss_register_device(struct omap_dss_device *dssdev)
  705. {
  706. static int dev_num;
  707. WARN_ON(!dssdev->driver_name);
  708. reset_device(&dssdev->dev, 1);
  709. dssdev->dev.bus = &dss_bus_type;
  710. dssdev->dev.parent = &dss_bus;
  711. dssdev->dev.release = omap_dss_dev_release;
  712. dev_set_name(&dssdev->dev, "display%d", dev_num++);
  713. return device_register(&dssdev->dev);
  714. }
  715. void omap_dss_unregister_device(struct omap_dss_device *dssdev)
  716. {
  717. device_unregister(&dssdev->dev);
  718. }
  719. /* BUS */
  720. static int omap_dss_bus_register(void)
  721. {
  722. int r;
  723. r = bus_register(&dss_bus_type);
  724. if (r) {
  725. DSSERR("bus register failed\n");
  726. return r;
  727. }
  728. dev_set_name(&dss_bus, "omapdss");
  729. r = device_register(&dss_bus);
  730. if (r) {
  731. DSSERR("bus driver register failed\n");
  732. bus_unregister(&dss_bus_type);
  733. return r;
  734. }
  735. return 0;
  736. }
  737. /* INIT */
  738. #ifdef CONFIG_OMAP2_DSS_MODULE
  739. static void omap_dss_bus_unregister(void)
  740. {
  741. device_unregister(&dss_bus);
  742. bus_unregister(&dss_bus_type);
  743. }
  744. static int __init omap_dss_init(void)
  745. {
  746. int r;
  747. r = omap_dss_bus_register();
  748. if (r)
  749. return r;
  750. r = platform_driver_register(&omap_dss_driver);
  751. if (r) {
  752. omap_dss_bus_unregister();
  753. return r;
  754. }
  755. return 0;
  756. }
  757. static void __exit omap_dss_exit(void)
  758. {
  759. if (core.vdds_dsi_reg != NULL) {
  760. regulator_put(core.vdds_dsi_reg);
  761. core.vdds_dsi_reg = NULL;
  762. }
  763. if (core.vdds_sdi_reg != NULL) {
  764. regulator_put(core.vdds_sdi_reg);
  765. core.vdds_sdi_reg = NULL;
  766. }
  767. if (core.vdda_dac_reg != NULL) {
  768. regulator_put(core.vdda_dac_reg);
  769. core.vdda_dac_reg = NULL;
  770. }
  771. platform_driver_unregister(&omap_dss_driver);
  772. omap_dss_bus_unregister();
  773. }
  774. module_init(omap_dss_init);
  775. module_exit(omap_dss_exit);
  776. #else
  777. static int __init omap_dss_init(void)
  778. {
  779. return omap_dss_bus_register();
  780. }
  781. static int __init omap_dss_init2(void)
  782. {
  783. return platform_driver_register(&omap_dss_driver);
  784. }
  785. core_initcall(omap_dss_init);
  786. device_initcall(omap_dss_init2);
  787. #endif
  788. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
  789. MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
  790. MODULE_LICENSE("GPL v2");