venc.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  1. /*
  2. * linux/drivers/video/omap2/dss/venc.c
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
  6. *
  7. * VENC settings from TI's DSS driver
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License version 2 as published by
  11. * the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. * more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along with
  19. * this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #define DSS_SUBSYS_NAME "VENC"
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/clk.h>
  25. #include <linux/err.h>
  26. #include <linux/io.h>
  27. #include <linux/mutex.h>
  28. #include <linux/completion.h>
  29. #include <linux/delay.h>
  30. #include <linux/string.h>
  31. #include <linux/seq_file.h>
  32. #include <linux/platform_device.h>
  33. #include <linux/regulator/consumer.h>
  34. #include <linux/pm_runtime.h>
  35. #include <video/omapdss.h>
  36. #include <plat/cpu.h>
  37. #include "dss.h"
  38. #include "dss_features.h"
  39. /* Venc registers */
  40. #define VENC_REV_ID 0x00
  41. #define VENC_STATUS 0x04
  42. #define VENC_F_CONTROL 0x08
  43. #define VENC_VIDOUT_CTRL 0x10
  44. #define VENC_SYNC_CTRL 0x14
  45. #define VENC_LLEN 0x1C
  46. #define VENC_FLENS 0x20
  47. #define VENC_HFLTR_CTRL 0x24
  48. #define VENC_CC_CARR_WSS_CARR 0x28
  49. #define VENC_C_PHASE 0x2C
  50. #define VENC_GAIN_U 0x30
  51. #define VENC_GAIN_V 0x34
  52. #define VENC_GAIN_Y 0x38
  53. #define VENC_BLACK_LEVEL 0x3C
  54. #define VENC_BLANK_LEVEL 0x40
  55. #define VENC_X_COLOR 0x44
  56. #define VENC_M_CONTROL 0x48
  57. #define VENC_BSTAMP_WSS_DATA 0x4C
  58. #define VENC_S_CARR 0x50
  59. #define VENC_LINE21 0x54
  60. #define VENC_LN_SEL 0x58
  61. #define VENC_L21__WC_CTL 0x5C
  62. #define VENC_HTRIGGER_VTRIGGER 0x60
  63. #define VENC_SAVID__EAVID 0x64
  64. #define VENC_FLEN__FAL 0x68
  65. #define VENC_LAL__PHASE_RESET 0x6C
  66. #define VENC_HS_INT_START_STOP_X 0x70
  67. #define VENC_HS_EXT_START_STOP_X 0x74
  68. #define VENC_VS_INT_START_X 0x78
  69. #define VENC_VS_INT_STOP_X__VS_INT_START_Y 0x7C
  70. #define VENC_VS_INT_STOP_Y__VS_EXT_START_X 0x80
  71. #define VENC_VS_EXT_STOP_X__VS_EXT_START_Y 0x84
  72. #define VENC_VS_EXT_STOP_Y 0x88
  73. #define VENC_AVID_START_STOP_X 0x90
  74. #define VENC_AVID_START_STOP_Y 0x94
  75. #define VENC_FID_INT_START_X__FID_INT_START_Y 0xA0
  76. #define VENC_FID_INT_OFFSET_Y__FID_EXT_START_X 0xA4
  77. #define VENC_FID_EXT_START_Y__FID_EXT_OFFSET_Y 0xA8
  78. #define VENC_TVDETGP_INT_START_STOP_X 0xB0
  79. #define VENC_TVDETGP_INT_START_STOP_Y 0xB4
  80. #define VENC_GEN_CTRL 0xB8
  81. #define VENC_OUTPUT_CONTROL 0xC4
  82. #define VENC_OUTPUT_TEST 0xC8
  83. #define VENC_DAC_B__DAC_C 0xC8
  84. struct venc_config {
  85. u32 f_control;
  86. u32 vidout_ctrl;
  87. u32 sync_ctrl;
  88. u32 llen;
  89. u32 flens;
  90. u32 hfltr_ctrl;
  91. u32 cc_carr_wss_carr;
  92. u32 c_phase;
  93. u32 gain_u;
  94. u32 gain_v;
  95. u32 gain_y;
  96. u32 black_level;
  97. u32 blank_level;
  98. u32 x_color;
  99. u32 m_control;
  100. u32 bstamp_wss_data;
  101. u32 s_carr;
  102. u32 line21;
  103. u32 ln_sel;
  104. u32 l21__wc_ctl;
  105. u32 htrigger_vtrigger;
  106. u32 savid__eavid;
  107. u32 flen__fal;
  108. u32 lal__phase_reset;
  109. u32 hs_int_start_stop_x;
  110. u32 hs_ext_start_stop_x;
  111. u32 vs_int_start_x;
  112. u32 vs_int_stop_x__vs_int_start_y;
  113. u32 vs_int_stop_y__vs_ext_start_x;
  114. u32 vs_ext_stop_x__vs_ext_start_y;
  115. u32 vs_ext_stop_y;
  116. u32 avid_start_stop_x;
  117. u32 avid_start_stop_y;
  118. u32 fid_int_start_x__fid_int_start_y;
  119. u32 fid_int_offset_y__fid_ext_start_x;
  120. u32 fid_ext_start_y__fid_ext_offset_y;
  121. u32 tvdetgp_int_start_stop_x;
  122. u32 tvdetgp_int_start_stop_y;
  123. u32 gen_ctrl;
  124. };
  125. /* from TRM */
  126. static const struct venc_config venc_config_pal_trm = {
  127. .f_control = 0,
  128. .vidout_ctrl = 1,
  129. .sync_ctrl = 0x40,
  130. .llen = 0x35F, /* 863 */
  131. .flens = 0x270, /* 624 */
  132. .hfltr_ctrl = 0,
  133. .cc_carr_wss_carr = 0x2F7225ED,
  134. .c_phase = 0,
  135. .gain_u = 0x111,
  136. .gain_v = 0x181,
  137. .gain_y = 0x140,
  138. .black_level = 0x3B,
  139. .blank_level = 0x3B,
  140. .x_color = 0x7,
  141. .m_control = 0x2,
  142. .bstamp_wss_data = 0x3F,
  143. .s_carr = 0x2A098ACB,
  144. .line21 = 0,
  145. .ln_sel = 0x01290015,
  146. .l21__wc_ctl = 0x0000F603,
  147. .htrigger_vtrigger = 0,
  148. .savid__eavid = 0x06A70108,
  149. .flen__fal = 0x00180270,
  150. .lal__phase_reset = 0x00040135,
  151. .hs_int_start_stop_x = 0x00880358,
  152. .hs_ext_start_stop_x = 0x000F035F,
  153. .vs_int_start_x = 0x01A70000,
  154. .vs_int_stop_x__vs_int_start_y = 0x000001A7,
  155. .vs_int_stop_y__vs_ext_start_x = 0x01AF0000,
  156. .vs_ext_stop_x__vs_ext_start_y = 0x000101AF,
  157. .vs_ext_stop_y = 0x00000025,
  158. .avid_start_stop_x = 0x03530083,
  159. .avid_start_stop_y = 0x026C002E,
  160. .fid_int_start_x__fid_int_start_y = 0x0001008A,
  161. .fid_int_offset_y__fid_ext_start_x = 0x002E0138,
  162. .fid_ext_start_y__fid_ext_offset_y = 0x01380001,
  163. .tvdetgp_int_start_stop_x = 0x00140001,
  164. .tvdetgp_int_start_stop_y = 0x00010001,
  165. .gen_ctrl = 0x00FF0000,
  166. };
  167. /* from TRM */
  168. static const struct venc_config venc_config_ntsc_trm = {
  169. .f_control = 0,
  170. .vidout_ctrl = 1,
  171. .sync_ctrl = 0x8040,
  172. .llen = 0x359,
  173. .flens = 0x20C,
  174. .hfltr_ctrl = 0,
  175. .cc_carr_wss_carr = 0x043F2631,
  176. .c_phase = 0,
  177. .gain_u = 0x102,
  178. .gain_v = 0x16C,
  179. .gain_y = 0x12F,
  180. .black_level = 0x43,
  181. .blank_level = 0x38,
  182. .x_color = 0x7,
  183. .m_control = 0x1,
  184. .bstamp_wss_data = 0x38,
  185. .s_carr = 0x21F07C1F,
  186. .line21 = 0,
  187. .ln_sel = 0x01310011,
  188. .l21__wc_ctl = 0x0000F003,
  189. .htrigger_vtrigger = 0,
  190. .savid__eavid = 0x069300F4,
  191. .flen__fal = 0x0016020C,
  192. .lal__phase_reset = 0x00060107,
  193. .hs_int_start_stop_x = 0x008E0350,
  194. .hs_ext_start_stop_x = 0x000F0359,
  195. .vs_int_start_x = 0x01A00000,
  196. .vs_int_stop_x__vs_int_start_y = 0x020701A0,
  197. .vs_int_stop_y__vs_ext_start_x = 0x01AC0024,
  198. .vs_ext_stop_x__vs_ext_start_y = 0x020D01AC,
  199. .vs_ext_stop_y = 0x00000006,
  200. .avid_start_stop_x = 0x03480078,
  201. .avid_start_stop_y = 0x02060024,
  202. .fid_int_start_x__fid_int_start_y = 0x0001008A,
  203. .fid_int_offset_y__fid_ext_start_x = 0x01AC0106,
  204. .fid_ext_start_y__fid_ext_offset_y = 0x01060006,
  205. .tvdetgp_int_start_stop_x = 0x00140001,
  206. .tvdetgp_int_start_stop_y = 0x00010001,
  207. .gen_ctrl = 0x00F90000,
  208. };
  209. static const struct venc_config venc_config_pal_bdghi = {
  210. .f_control = 0,
  211. .vidout_ctrl = 0,
  212. .sync_ctrl = 0,
  213. .hfltr_ctrl = 0,
  214. .x_color = 0,
  215. .line21 = 0,
  216. .ln_sel = 21,
  217. .htrigger_vtrigger = 0,
  218. .tvdetgp_int_start_stop_x = 0x00140001,
  219. .tvdetgp_int_start_stop_y = 0x00010001,
  220. .gen_ctrl = 0x00FB0000,
  221. .llen = 864-1,
  222. .flens = 625-1,
  223. .cc_carr_wss_carr = 0x2F7625ED,
  224. .c_phase = 0xDF,
  225. .gain_u = 0x111,
  226. .gain_v = 0x181,
  227. .gain_y = 0x140,
  228. .black_level = 0x3e,
  229. .blank_level = 0x3e,
  230. .m_control = 0<<2 | 1<<1,
  231. .bstamp_wss_data = 0x42,
  232. .s_carr = 0x2a098acb,
  233. .l21__wc_ctl = 0<<13 | 0x16<<8 | 0<<0,
  234. .savid__eavid = 0x06A70108,
  235. .flen__fal = 23<<16 | 624<<0,
  236. .lal__phase_reset = 2<<17 | 310<<0,
  237. .hs_int_start_stop_x = 0x00920358,
  238. .hs_ext_start_stop_x = 0x000F035F,
  239. .vs_int_start_x = 0x1a7<<16,
  240. .vs_int_stop_x__vs_int_start_y = 0x000601A7,
  241. .vs_int_stop_y__vs_ext_start_x = 0x01AF0036,
  242. .vs_ext_stop_x__vs_ext_start_y = 0x27101af,
  243. .vs_ext_stop_y = 0x05,
  244. .avid_start_stop_x = 0x03530082,
  245. .avid_start_stop_y = 0x0270002E,
  246. .fid_int_start_x__fid_int_start_y = 0x0005008A,
  247. .fid_int_offset_y__fid_ext_start_x = 0x002E0138,
  248. .fid_ext_start_y__fid_ext_offset_y = 0x01380005,
  249. };
  250. const struct omap_video_timings omap_dss_pal_timings = {
  251. .x_res = 720,
  252. .y_res = 574,
  253. .pixel_clock = 13500,
  254. .hsw = 64,
  255. .hfp = 12,
  256. .hbp = 68,
  257. .vsw = 5,
  258. .vfp = 5,
  259. .vbp = 41,
  260. };
  261. EXPORT_SYMBOL(omap_dss_pal_timings);
  262. const struct omap_video_timings omap_dss_ntsc_timings = {
  263. .x_res = 720,
  264. .y_res = 482,
  265. .pixel_clock = 13500,
  266. .hsw = 64,
  267. .hfp = 16,
  268. .hbp = 58,
  269. .vsw = 6,
  270. .vfp = 6,
  271. .vbp = 31,
  272. };
  273. EXPORT_SYMBOL(omap_dss_ntsc_timings);
  274. static struct {
  275. struct platform_device *pdev;
  276. void __iomem *base;
  277. struct mutex venc_lock;
  278. u32 wss_data;
  279. struct regulator *vdda_dac_reg;
  280. struct clk *tv_dac_clk;
  281. } venc;
  282. static inline void venc_write_reg(int idx, u32 val)
  283. {
  284. __raw_writel(val, venc.base + idx);
  285. }
  286. static inline u32 venc_read_reg(int idx)
  287. {
  288. u32 l = __raw_readl(venc.base + idx);
  289. return l;
  290. }
  291. static void venc_write_config(const struct venc_config *config)
  292. {
  293. DSSDBG("write venc conf\n");
  294. venc_write_reg(VENC_LLEN, config->llen);
  295. venc_write_reg(VENC_FLENS, config->flens);
  296. venc_write_reg(VENC_CC_CARR_WSS_CARR, config->cc_carr_wss_carr);
  297. venc_write_reg(VENC_C_PHASE, config->c_phase);
  298. venc_write_reg(VENC_GAIN_U, config->gain_u);
  299. venc_write_reg(VENC_GAIN_V, config->gain_v);
  300. venc_write_reg(VENC_GAIN_Y, config->gain_y);
  301. venc_write_reg(VENC_BLACK_LEVEL, config->black_level);
  302. venc_write_reg(VENC_BLANK_LEVEL, config->blank_level);
  303. venc_write_reg(VENC_M_CONTROL, config->m_control);
  304. venc_write_reg(VENC_BSTAMP_WSS_DATA, config->bstamp_wss_data |
  305. venc.wss_data);
  306. venc_write_reg(VENC_S_CARR, config->s_carr);
  307. venc_write_reg(VENC_L21__WC_CTL, config->l21__wc_ctl);
  308. venc_write_reg(VENC_SAVID__EAVID, config->savid__eavid);
  309. venc_write_reg(VENC_FLEN__FAL, config->flen__fal);
  310. venc_write_reg(VENC_LAL__PHASE_RESET, config->lal__phase_reset);
  311. venc_write_reg(VENC_HS_INT_START_STOP_X, config->hs_int_start_stop_x);
  312. venc_write_reg(VENC_HS_EXT_START_STOP_X, config->hs_ext_start_stop_x);
  313. venc_write_reg(VENC_VS_INT_START_X, config->vs_int_start_x);
  314. venc_write_reg(VENC_VS_INT_STOP_X__VS_INT_START_Y,
  315. config->vs_int_stop_x__vs_int_start_y);
  316. venc_write_reg(VENC_VS_INT_STOP_Y__VS_EXT_START_X,
  317. config->vs_int_stop_y__vs_ext_start_x);
  318. venc_write_reg(VENC_VS_EXT_STOP_X__VS_EXT_START_Y,
  319. config->vs_ext_stop_x__vs_ext_start_y);
  320. venc_write_reg(VENC_VS_EXT_STOP_Y, config->vs_ext_stop_y);
  321. venc_write_reg(VENC_AVID_START_STOP_X, config->avid_start_stop_x);
  322. venc_write_reg(VENC_AVID_START_STOP_Y, config->avid_start_stop_y);
  323. venc_write_reg(VENC_FID_INT_START_X__FID_INT_START_Y,
  324. config->fid_int_start_x__fid_int_start_y);
  325. venc_write_reg(VENC_FID_INT_OFFSET_Y__FID_EXT_START_X,
  326. config->fid_int_offset_y__fid_ext_start_x);
  327. venc_write_reg(VENC_FID_EXT_START_Y__FID_EXT_OFFSET_Y,
  328. config->fid_ext_start_y__fid_ext_offset_y);
  329. venc_write_reg(VENC_DAC_B__DAC_C, venc_read_reg(VENC_DAC_B__DAC_C));
  330. venc_write_reg(VENC_VIDOUT_CTRL, config->vidout_ctrl);
  331. venc_write_reg(VENC_HFLTR_CTRL, config->hfltr_ctrl);
  332. venc_write_reg(VENC_X_COLOR, config->x_color);
  333. venc_write_reg(VENC_LINE21, config->line21);
  334. venc_write_reg(VENC_LN_SEL, config->ln_sel);
  335. venc_write_reg(VENC_HTRIGGER_VTRIGGER, config->htrigger_vtrigger);
  336. venc_write_reg(VENC_TVDETGP_INT_START_STOP_X,
  337. config->tvdetgp_int_start_stop_x);
  338. venc_write_reg(VENC_TVDETGP_INT_START_STOP_Y,
  339. config->tvdetgp_int_start_stop_y);
  340. venc_write_reg(VENC_GEN_CTRL, config->gen_ctrl);
  341. venc_write_reg(VENC_F_CONTROL, config->f_control);
  342. venc_write_reg(VENC_SYNC_CTRL, config->sync_ctrl);
  343. }
  344. static void venc_reset(void)
  345. {
  346. int t = 1000;
  347. venc_write_reg(VENC_F_CONTROL, 1<<8);
  348. while (venc_read_reg(VENC_F_CONTROL) & (1<<8)) {
  349. if (--t == 0) {
  350. DSSERR("Failed to reset venc\n");
  351. return;
  352. }
  353. }
  354. #ifdef CONFIG_OMAP2_DSS_SLEEP_AFTER_VENC_RESET
  355. /* the magical sleep that makes things work */
  356. /* XXX more info? What bug this circumvents? */
  357. msleep(20);
  358. #endif
  359. }
  360. static int venc_runtime_get(void)
  361. {
  362. int r;
  363. DSSDBG("venc_runtime_get\n");
  364. r = pm_runtime_get_sync(&venc.pdev->dev);
  365. WARN_ON(r < 0);
  366. return r < 0 ? r : 0;
  367. }
  368. static void venc_runtime_put(void)
  369. {
  370. int r;
  371. DSSDBG("venc_runtime_put\n");
  372. r = pm_runtime_put(&venc.pdev->dev);
  373. WARN_ON(r < 0);
  374. }
  375. static const struct venc_config *venc_timings_to_config(
  376. struct omap_video_timings *timings)
  377. {
  378. if (memcmp(&omap_dss_pal_timings, timings, sizeof(*timings)) == 0)
  379. return &venc_config_pal_trm;
  380. if (memcmp(&omap_dss_ntsc_timings, timings, sizeof(*timings)) == 0)
  381. return &venc_config_ntsc_trm;
  382. BUG();
  383. }
  384. static void venc_power_on(struct omap_dss_device *dssdev)
  385. {
  386. u32 l;
  387. venc_reset();
  388. venc_write_config(venc_timings_to_config(&dssdev->panel.timings));
  389. dss_set_venc_output(dssdev->phy.venc.type);
  390. dss_set_dac_pwrdn_bgz(1);
  391. l = 0;
  392. if (dssdev->phy.venc.type == OMAP_DSS_VENC_TYPE_COMPOSITE)
  393. l |= 1 << 1;
  394. else /* S-Video */
  395. l |= (1 << 0) | (1 << 2);
  396. if (dssdev->phy.venc.invert_polarity == false)
  397. l |= 1 << 3;
  398. venc_write_reg(VENC_OUTPUT_CONTROL, l);
  399. dispc_set_digit_size(dssdev->panel.timings.x_res,
  400. dssdev->panel.timings.y_res/2);
  401. regulator_enable(venc.vdda_dac_reg);
  402. if (dssdev->platform_enable)
  403. dssdev->platform_enable(dssdev);
  404. dssdev->manager->enable(dssdev->manager);
  405. }
  406. static void venc_power_off(struct omap_dss_device *dssdev)
  407. {
  408. venc_write_reg(VENC_OUTPUT_CONTROL, 0);
  409. dss_set_dac_pwrdn_bgz(0);
  410. dssdev->manager->disable(dssdev->manager);
  411. if (dssdev->platform_disable)
  412. dssdev->platform_disable(dssdev);
  413. regulator_disable(venc.vdda_dac_reg);
  414. }
  415. unsigned long venc_get_pixel_clock(void)
  416. {
  417. /* VENC Pixel Clock in Mhz */
  418. return 13500000;
  419. }
  420. /* driver */
  421. static int venc_panel_probe(struct omap_dss_device *dssdev)
  422. {
  423. dssdev->panel.timings = omap_dss_pal_timings;
  424. return 0;
  425. }
  426. static void venc_panel_remove(struct omap_dss_device *dssdev)
  427. {
  428. }
  429. static int venc_panel_enable(struct omap_dss_device *dssdev)
  430. {
  431. int r = 0;
  432. DSSDBG("venc_enable_display\n");
  433. mutex_lock(&venc.venc_lock);
  434. r = omap_dss_start_device(dssdev);
  435. if (r) {
  436. DSSERR("failed to start device\n");
  437. goto err0;
  438. }
  439. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
  440. r = -EINVAL;
  441. goto err1;
  442. }
  443. r = venc_runtime_get();
  444. if (r)
  445. goto err1;
  446. venc_power_on(dssdev);
  447. venc.wss_data = 0;
  448. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  449. mutex_unlock(&venc.venc_lock);
  450. return 0;
  451. err1:
  452. omap_dss_stop_device(dssdev);
  453. err0:
  454. mutex_unlock(&venc.venc_lock);
  455. return r;
  456. }
  457. static void venc_panel_disable(struct omap_dss_device *dssdev)
  458. {
  459. DSSDBG("venc_disable_display\n");
  460. mutex_lock(&venc.venc_lock);
  461. if (dssdev->state == OMAP_DSS_DISPLAY_DISABLED)
  462. goto end;
  463. if (dssdev->state == OMAP_DSS_DISPLAY_SUSPENDED) {
  464. /* suspended is the same as disabled with venc */
  465. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  466. goto end;
  467. }
  468. venc_power_off(dssdev);
  469. venc_runtime_put();
  470. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  471. omap_dss_stop_device(dssdev);
  472. end:
  473. mutex_unlock(&venc.venc_lock);
  474. }
  475. static int venc_panel_suspend(struct omap_dss_device *dssdev)
  476. {
  477. venc_panel_disable(dssdev);
  478. return 0;
  479. }
  480. static int venc_panel_resume(struct omap_dss_device *dssdev)
  481. {
  482. return venc_panel_enable(dssdev);
  483. }
  484. static void venc_get_timings(struct omap_dss_device *dssdev,
  485. struct omap_video_timings *timings)
  486. {
  487. *timings = dssdev->panel.timings;
  488. }
  489. static void venc_set_timings(struct omap_dss_device *dssdev,
  490. struct omap_video_timings *timings)
  491. {
  492. DSSDBG("venc_set_timings\n");
  493. /* Reset WSS data when the TV standard changes. */
  494. if (memcmp(&dssdev->panel.timings, timings, sizeof(*timings)))
  495. venc.wss_data = 0;
  496. dssdev->panel.timings = *timings;
  497. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
  498. /* turn the venc off and on to get new timings to use */
  499. venc_panel_disable(dssdev);
  500. venc_panel_enable(dssdev);
  501. }
  502. }
  503. static int venc_check_timings(struct omap_dss_device *dssdev,
  504. struct omap_video_timings *timings)
  505. {
  506. DSSDBG("venc_check_timings\n");
  507. if (memcmp(&omap_dss_pal_timings, timings, sizeof(*timings)) == 0)
  508. return 0;
  509. if (memcmp(&omap_dss_ntsc_timings, timings, sizeof(*timings)) == 0)
  510. return 0;
  511. return -EINVAL;
  512. }
  513. static u32 venc_get_wss(struct omap_dss_device *dssdev)
  514. {
  515. /* Invert due to VENC_L21_WC_CTL:INV=1 */
  516. return (venc.wss_data >> 8) ^ 0xfffff;
  517. }
  518. static int venc_set_wss(struct omap_dss_device *dssdev, u32 wss)
  519. {
  520. const struct venc_config *config;
  521. int r;
  522. DSSDBG("venc_set_wss\n");
  523. mutex_lock(&venc.venc_lock);
  524. config = venc_timings_to_config(&dssdev->panel.timings);
  525. /* Invert due to VENC_L21_WC_CTL:INV=1 */
  526. venc.wss_data = (wss ^ 0xfffff) << 8;
  527. r = venc_runtime_get();
  528. if (r)
  529. goto err;
  530. venc_write_reg(VENC_BSTAMP_WSS_DATA, config->bstamp_wss_data |
  531. venc.wss_data);
  532. venc_runtime_put();
  533. err:
  534. mutex_unlock(&venc.venc_lock);
  535. return r;
  536. }
  537. static struct omap_dss_driver venc_driver = {
  538. .probe = venc_panel_probe,
  539. .remove = venc_panel_remove,
  540. .enable = venc_panel_enable,
  541. .disable = venc_panel_disable,
  542. .suspend = venc_panel_suspend,
  543. .resume = venc_panel_resume,
  544. .get_resolution = omapdss_default_get_resolution,
  545. .get_recommended_bpp = omapdss_default_get_recommended_bpp,
  546. .get_timings = venc_get_timings,
  547. .set_timings = venc_set_timings,
  548. .check_timings = venc_check_timings,
  549. .get_wss = venc_get_wss,
  550. .set_wss = venc_set_wss,
  551. .driver = {
  552. .name = "venc",
  553. .owner = THIS_MODULE,
  554. },
  555. };
  556. /* driver end */
  557. int venc_init_display(struct omap_dss_device *dssdev)
  558. {
  559. DSSDBG("init_display\n");
  560. if (venc.vdda_dac_reg == NULL) {
  561. struct regulator *vdda_dac;
  562. vdda_dac = regulator_get(&venc.pdev->dev, "vdda_dac");
  563. if (IS_ERR(vdda_dac)) {
  564. DSSERR("can't get VDDA_DAC regulator\n");
  565. return PTR_ERR(vdda_dac);
  566. }
  567. venc.vdda_dac_reg = vdda_dac;
  568. }
  569. return 0;
  570. }
  571. void venc_dump_regs(struct seq_file *s)
  572. {
  573. #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, venc_read_reg(r))
  574. if (venc_runtime_get())
  575. return;
  576. DUMPREG(VENC_F_CONTROL);
  577. DUMPREG(VENC_VIDOUT_CTRL);
  578. DUMPREG(VENC_SYNC_CTRL);
  579. DUMPREG(VENC_LLEN);
  580. DUMPREG(VENC_FLENS);
  581. DUMPREG(VENC_HFLTR_CTRL);
  582. DUMPREG(VENC_CC_CARR_WSS_CARR);
  583. DUMPREG(VENC_C_PHASE);
  584. DUMPREG(VENC_GAIN_U);
  585. DUMPREG(VENC_GAIN_V);
  586. DUMPREG(VENC_GAIN_Y);
  587. DUMPREG(VENC_BLACK_LEVEL);
  588. DUMPREG(VENC_BLANK_LEVEL);
  589. DUMPREG(VENC_X_COLOR);
  590. DUMPREG(VENC_M_CONTROL);
  591. DUMPREG(VENC_BSTAMP_WSS_DATA);
  592. DUMPREG(VENC_S_CARR);
  593. DUMPREG(VENC_LINE21);
  594. DUMPREG(VENC_LN_SEL);
  595. DUMPREG(VENC_L21__WC_CTL);
  596. DUMPREG(VENC_HTRIGGER_VTRIGGER);
  597. DUMPREG(VENC_SAVID__EAVID);
  598. DUMPREG(VENC_FLEN__FAL);
  599. DUMPREG(VENC_LAL__PHASE_RESET);
  600. DUMPREG(VENC_HS_INT_START_STOP_X);
  601. DUMPREG(VENC_HS_EXT_START_STOP_X);
  602. DUMPREG(VENC_VS_INT_START_X);
  603. DUMPREG(VENC_VS_INT_STOP_X__VS_INT_START_Y);
  604. DUMPREG(VENC_VS_INT_STOP_Y__VS_EXT_START_X);
  605. DUMPREG(VENC_VS_EXT_STOP_X__VS_EXT_START_Y);
  606. DUMPREG(VENC_VS_EXT_STOP_Y);
  607. DUMPREG(VENC_AVID_START_STOP_X);
  608. DUMPREG(VENC_AVID_START_STOP_Y);
  609. DUMPREG(VENC_FID_INT_START_X__FID_INT_START_Y);
  610. DUMPREG(VENC_FID_INT_OFFSET_Y__FID_EXT_START_X);
  611. DUMPREG(VENC_FID_EXT_START_Y__FID_EXT_OFFSET_Y);
  612. DUMPREG(VENC_TVDETGP_INT_START_STOP_X);
  613. DUMPREG(VENC_TVDETGP_INT_START_STOP_Y);
  614. DUMPREG(VENC_GEN_CTRL);
  615. DUMPREG(VENC_OUTPUT_CONTROL);
  616. DUMPREG(VENC_OUTPUT_TEST);
  617. venc_runtime_put();
  618. #undef DUMPREG
  619. }
  620. static int venc_get_clocks(struct platform_device *pdev)
  621. {
  622. struct clk *clk;
  623. if (dss_has_feature(FEAT_VENC_REQUIRES_TV_DAC_CLK)) {
  624. clk = clk_get(&pdev->dev, "tv_dac_clk");
  625. if (IS_ERR(clk)) {
  626. DSSERR("can't get tv_dac_clk\n");
  627. return PTR_ERR(clk);
  628. }
  629. } else {
  630. clk = NULL;
  631. }
  632. venc.tv_dac_clk = clk;
  633. return 0;
  634. }
  635. static void venc_put_clocks(void)
  636. {
  637. if (venc.tv_dac_clk)
  638. clk_put(venc.tv_dac_clk);
  639. }
  640. /* VENC HW IP initialisation */
  641. static int omap_venchw_probe(struct platform_device *pdev)
  642. {
  643. u8 rev_id;
  644. struct resource *venc_mem;
  645. int r;
  646. venc.pdev = pdev;
  647. mutex_init(&venc.venc_lock);
  648. venc.wss_data = 0;
  649. venc_mem = platform_get_resource(venc.pdev, IORESOURCE_MEM, 0);
  650. if (!venc_mem) {
  651. DSSERR("can't get IORESOURCE_MEM VENC\n");
  652. r = -EINVAL;
  653. goto err_ioremap;
  654. }
  655. venc.base = ioremap(venc_mem->start, resource_size(venc_mem));
  656. if (!venc.base) {
  657. DSSERR("can't ioremap VENC\n");
  658. r = -ENOMEM;
  659. goto err_ioremap;
  660. }
  661. r = venc_get_clocks(pdev);
  662. if (r)
  663. goto err_get_clk;
  664. pm_runtime_enable(&pdev->dev);
  665. r = venc_runtime_get();
  666. if (r)
  667. goto err_get_venc;
  668. rev_id = (u8)(venc_read_reg(VENC_REV_ID) & 0xff);
  669. dev_dbg(&pdev->dev, "OMAP VENC rev %d\n", rev_id);
  670. venc_runtime_put();
  671. return omap_dss_register_driver(&venc_driver);
  672. err_get_venc:
  673. pm_runtime_disable(&pdev->dev);
  674. venc_put_clocks();
  675. err_get_clk:
  676. iounmap(venc.base);
  677. err_ioremap:
  678. return r;
  679. }
  680. static int omap_venchw_remove(struct platform_device *pdev)
  681. {
  682. if (venc.vdda_dac_reg != NULL) {
  683. regulator_put(venc.vdda_dac_reg);
  684. venc.vdda_dac_reg = NULL;
  685. }
  686. omap_dss_unregister_driver(&venc_driver);
  687. pm_runtime_disable(&pdev->dev);
  688. venc_put_clocks();
  689. iounmap(venc.base);
  690. return 0;
  691. }
  692. static int venc_runtime_suspend(struct device *dev)
  693. {
  694. if (venc.tv_dac_clk)
  695. clk_disable(venc.tv_dac_clk);
  696. dispc_runtime_put();
  697. dss_runtime_put();
  698. return 0;
  699. }
  700. static int venc_runtime_resume(struct device *dev)
  701. {
  702. int r;
  703. r = dss_runtime_get();
  704. if (r < 0)
  705. goto err_get_dss;
  706. r = dispc_runtime_get();
  707. if (r < 0)
  708. goto err_get_dispc;
  709. if (venc.tv_dac_clk)
  710. clk_enable(venc.tv_dac_clk);
  711. return 0;
  712. err_get_dispc:
  713. dss_runtime_put();
  714. err_get_dss:
  715. return r;
  716. }
  717. static const struct dev_pm_ops venc_pm_ops = {
  718. .runtime_suspend = venc_runtime_suspend,
  719. .runtime_resume = venc_runtime_resume,
  720. };
  721. static struct platform_driver omap_venchw_driver = {
  722. .probe = omap_venchw_probe,
  723. .remove = omap_venchw_remove,
  724. .driver = {
  725. .name = "omapdss_venc",
  726. .owner = THIS_MODULE,
  727. .pm = &venc_pm_ops,
  728. },
  729. };
  730. int venc_init_platform_driver(void)
  731. {
  732. if (cpu_is_omap44xx())
  733. return 0;
  734. return platform_driver_register(&omap_venchw_driver);
  735. }
  736. void venc_uninit_platform_driver(void)
  737. {
  738. if (cpu_is_omap44xx())
  739. return;
  740. return platform_driver_unregister(&omap_venchw_driver);
  741. }