venc.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958
  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 "dss.h"
  37. #include "dss_features.h"
  38. /* Venc registers */
  39. #define VENC_REV_ID 0x00
  40. #define VENC_STATUS 0x04
  41. #define VENC_F_CONTROL 0x08
  42. #define VENC_VIDOUT_CTRL 0x10
  43. #define VENC_SYNC_CTRL 0x14
  44. #define VENC_LLEN 0x1C
  45. #define VENC_FLENS 0x20
  46. #define VENC_HFLTR_CTRL 0x24
  47. #define VENC_CC_CARR_WSS_CARR 0x28
  48. #define VENC_C_PHASE 0x2C
  49. #define VENC_GAIN_U 0x30
  50. #define VENC_GAIN_V 0x34
  51. #define VENC_GAIN_Y 0x38
  52. #define VENC_BLACK_LEVEL 0x3C
  53. #define VENC_BLANK_LEVEL 0x40
  54. #define VENC_X_COLOR 0x44
  55. #define VENC_M_CONTROL 0x48
  56. #define VENC_BSTAMP_WSS_DATA 0x4C
  57. #define VENC_S_CARR 0x50
  58. #define VENC_LINE21 0x54
  59. #define VENC_LN_SEL 0x58
  60. #define VENC_L21__WC_CTL 0x5C
  61. #define VENC_HTRIGGER_VTRIGGER 0x60
  62. #define VENC_SAVID__EAVID 0x64
  63. #define VENC_FLEN__FAL 0x68
  64. #define VENC_LAL__PHASE_RESET 0x6C
  65. #define VENC_HS_INT_START_STOP_X 0x70
  66. #define VENC_HS_EXT_START_STOP_X 0x74
  67. #define VENC_VS_INT_START_X 0x78
  68. #define VENC_VS_INT_STOP_X__VS_INT_START_Y 0x7C
  69. #define VENC_VS_INT_STOP_Y__VS_EXT_START_X 0x80
  70. #define VENC_VS_EXT_STOP_X__VS_EXT_START_Y 0x84
  71. #define VENC_VS_EXT_STOP_Y 0x88
  72. #define VENC_AVID_START_STOP_X 0x90
  73. #define VENC_AVID_START_STOP_Y 0x94
  74. #define VENC_FID_INT_START_X__FID_INT_START_Y 0xA0
  75. #define VENC_FID_INT_OFFSET_Y__FID_EXT_START_X 0xA4
  76. #define VENC_FID_EXT_START_Y__FID_EXT_OFFSET_Y 0xA8
  77. #define VENC_TVDETGP_INT_START_STOP_X 0xB0
  78. #define VENC_TVDETGP_INT_START_STOP_Y 0xB4
  79. #define VENC_GEN_CTRL 0xB8
  80. #define VENC_OUTPUT_CONTROL 0xC4
  81. #define VENC_OUTPUT_TEST 0xC8
  82. #define VENC_DAC_B__DAC_C 0xC8
  83. struct venc_config {
  84. u32 f_control;
  85. u32 vidout_ctrl;
  86. u32 sync_ctrl;
  87. u32 llen;
  88. u32 flens;
  89. u32 hfltr_ctrl;
  90. u32 cc_carr_wss_carr;
  91. u32 c_phase;
  92. u32 gain_u;
  93. u32 gain_v;
  94. u32 gain_y;
  95. u32 black_level;
  96. u32 blank_level;
  97. u32 x_color;
  98. u32 m_control;
  99. u32 bstamp_wss_data;
  100. u32 s_carr;
  101. u32 line21;
  102. u32 ln_sel;
  103. u32 l21__wc_ctl;
  104. u32 htrigger_vtrigger;
  105. u32 savid__eavid;
  106. u32 flen__fal;
  107. u32 lal__phase_reset;
  108. u32 hs_int_start_stop_x;
  109. u32 hs_ext_start_stop_x;
  110. u32 vs_int_start_x;
  111. u32 vs_int_stop_x__vs_int_start_y;
  112. u32 vs_int_stop_y__vs_ext_start_x;
  113. u32 vs_ext_stop_x__vs_ext_start_y;
  114. u32 vs_ext_stop_y;
  115. u32 avid_start_stop_x;
  116. u32 avid_start_stop_y;
  117. u32 fid_int_start_x__fid_int_start_y;
  118. u32 fid_int_offset_y__fid_ext_start_x;
  119. u32 fid_ext_start_y__fid_ext_offset_y;
  120. u32 tvdetgp_int_start_stop_x;
  121. u32 tvdetgp_int_start_stop_y;
  122. u32 gen_ctrl;
  123. };
  124. /* from TRM */
  125. static const struct venc_config venc_config_pal_trm = {
  126. .f_control = 0,
  127. .vidout_ctrl = 1,
  128. .sync_ctrl = 0x40,
  129. .llen = 0x35F, /* 863 */
  130. .flens = 0x270, /* 624 */
  131. .hfltr_ctrl = 0,
  132. .cc_carr_wss_carr = 0x2F7225ED,
  133. .c_phase = 0,
  134. .gain_u = 0x111,
  135. .gain_v = 0x181,
  136. .gain_y = 0x140,
  137. .black_level = 0x3B,
  138. .blank_level = 0x3B,
  139. .x_color = 0x7,
  140. .m_control = 0x2,
  141. .bstamp_wss_data = 0x3F,
  142. .s_carr = 0x2A098ACB,
  143. .line21 = 0,
  144. .ln_sel = 0x01290015,
  145. .l21__wc_ctl = 0x0000F603,
  146. .htrigger_vtrigger = 0,
  147. .savid__eavid = 0x06A70108,
  148. .flen__fal = 0x00180270,
  149. .lal__phase_reset = 0x00040135,
  150. .hs_int_start_stop_x = 0x00880358,
  151. .hs_ext_start_stop_x = 0x000F035F,
  152. .vs_int_start_x = 0x01A70000,
  153. .vs_int_stop_x__vs_int_start_y = 0x000001A7,
  154. .vs_int_stop_y__vs_ext_start_x = 0x01AF0000,
  155. .vs_ext_stop_x__vs_ext_start_y = 0x000101AF,
  156. .vs_ext_stop_y = 0x00000025,
  157. .avid_start_stop_x = 0x03530083,
  158. .avid_start_stop_y = 0x026C002E,
  159. .fid_int_start_x__fid_int_start_y = 0x0001008A,
  160. .fid_int_offset_y__fid_ext_start_x = 0x002E0138,
  161. .fid_ext_start_y__fid_ext_offset_y = 0x01380001,
  162. .tvdetgp_int_start_stop_x = 0x00140001,
  163. .tvdetgp_int_start_stop_y = 0x00010001,
  164. .gen_ctrl = 0x00FF0000,
  165. };
  166. /* from TRM */
  167. static const struct venc_config venc_config_ntsc_trm = {
  168. .f_control = 0,
  169. .vidout_ctrl = 1,
  170. .sync_ctrl = 0x8040,
  171. .llen = 0x359,
  172. .flens = 0x20C,
  173. .hfltr_ctrl = 0,
  174. .cc_carr_wss_carr = 0x043F2631,
  175. .c_phase = 0,
  176. .gain_u = 0x102,
  177. .gain_v = 0x16C,
  178. .gain_y = 0x12F,
  179. .black_level = 0x43,
  180. .blank_level = 0x38,
  181. .x_color = 0x7,
  182. .m_control = 0x1,
  183. .bstamp_wss_data = 0x38,
  184. .s_carr = 0x21F07C1F,
  185. .line21 = 0,
  186. .ln_sel = 0x01310011,
  187. .l21__wc_ctl = 0x0000F003,
  188. .htrigger_vtrigger = 0,
  189. .savid__eavid = 0x069300F4,
  190. .flen__fal = 0x0016020C,
  191. .lal__phase_reset = 0x00060107,
  192. .hs_int_start_stop_x = 0x008E0350,
  193. .hs_ext_start_stop_x = 0x000F0359,
  194. .vs_int_start_x = 0x01A00000,
  195. .vs_int_stop_x__vs_int_start_y = 0x020701A0,
  196. .vs_int_stop_y__vs_ext_start_x = 0x01AC0024,
  197. .vs_ext_stop_x__vs_ext_start_y = 0x020D01AC,
  198. .vs_ext_stop_y = 0x00000006,
  199. .avid_start_stop_x = 0x03480078,
  200. .avid_start_stop_y = 0x02060024,
  201. .fid_int_start_x__fid_int_start_y = 0x0001008A,
  202. .fid_int_offset_y__fid_ext_start_x = 0x01AC0106,
  203. .fid_ext_start_y__fid_ext_offset_y = 0x01060006,
  204. .tvdetgp_int_start_stop_x = 0x00140001,
  205. .tvdetgp_int_start_stop_y = 0x00010001,
  206. .gen_ctrl = 0x00F90000,
  207. };
  208. static const struct venc_config venc_config_pal_bdghi = {
  209. .f_control = 0,
  210. .vidout_ctrl = 0,
  211. .sync_ctrl = 0,
  212. .hfltr_ctrl = 0,
  213. .x_color = 0,
  214. .line21 = 0,
  215. .ln_sel = 21,
  216. .htrigger_vtrigger = 0,
  217. .tvdetgp_int_start_stop_x = 0x00140001,
  218. .tvdetgp_int_start_stop_y = 0x00010001,
  219. .gen_ctrl = 0x00FB0000,
  220. .llen = 864-1,
  221. .flens = 625-1,
  222. .cc_carr_wss_carr = 0x2F7625ED,
  223. .c_phase = 0xDF,
  224. .gain_u = 0x111,
  225. .gain_v = 0x181,
  226. .gain_y = 0x140,
  227. .black_level = 0x3e,
  228. .blank_level = 0x3e,
  229. .m_control = 0<<2 | 1<<1,
  230. .bstamp_wss_data = 0x42,
  231. .s_carr = 0x2a098acb,
  232. .l21__wc_ctl = 0<<13 | 0x16<<8 | 0<<0,
  233. .savid__eavid = 0x06A70108,
  234. .flen__fal = 23<<16 | 624<<0,
  235. .lal__phase_reset = 2<<17 | 310<<0,
  236. .hs_int_start_stop_x = 0x00920358,
  237. .hs_ext_start_stop_x = 0x000F035F,
  238. .vs_int_start_x = 0x1a7<<16,
  239. .vs_int_stop_x__vs_int_start_y = 0x000601A7,
  240. .vs_int_stop_y__vs_ext_start_x = 0x01AF0036,
  241. .vs_ext_stop_x__vs_ext_start_y = 0x27101af,
  242. .vs_ext_stop_y = 0x05,
  243. .avid_start_stop_x = 0x03530082,
  244. .avid_start_stop_y = 0x0270002E,
  245. .fid_int_start_x__fid_int_start_y = 0x0005008A,
  246. .fid_int_offset_y__fid_ext_start_x = 0x002E0138,
  247. .fid_ext_start_y__fid_ext_offset_y = 0x01380005,
  248. };
  249. const struct omap_video_timings omap_dss_pal_timings = {
  250. .x_res = 720,
  251. .y_res = 574,
  252. .pixel_clock = 13500,
  253. .hsw = 64,
  254. .hfp = 12,
  255. .hbp = 68,
  256. .vsw = 5,
  257. .vfp = 5,
  258. .vbp = 41,
  259. .interlace = true,
  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. .interlace = true,
  273. };
  274. EXPORT_SYMBOL(omap_dss_ntsc_timings);
  275. static struct {
  276. struct platform_device *pdev;
  277. void __iomem *base;
  278. struct mutex venc_lock;
  279. u32 wss_data;
  280. struct regulator *vdda_dac_reg;
  281. struct clk *tv_dac_clk;
  282. struct omap_video_timings timings;
  283. enum omap_dss_venc_type type;
  284. bool invert_polarity;
  285. struct omap_dss_output output;
  286. } venc;
  287. static inline void venc_write_reg(int idx, u32 val)
  288. {
  289. __raw_writel(val, venc.base + idx);
  290. }
  291. static inline u32 venc_read_reg(int idx)
  292. {
  293. u32 l = __raw_readl(venc.base + idx);
  294. return l;
  295. }
  296. static void venc_write_config(const struct venc_config *config)
  297. {
  298. DSSDBG("write venc conf\n");
  299. venc_write_reg(VENC_LLEN, config->llen);
  300. venc_write_reg(VENC_FLENS, config->flens);
  301. venc_write_reg(VENC_CC_CARR_WSS_CARR, config->cc_carr_wss_carr);
  302. venc_write_reg(VENC_C_PHASE, config->c_phase);
  303. venc_write_reg(VENC_GAIN_U, config->gain_u);
  304. venc_write_reg(VENC_GAIN_V, config->gain_v);
  305. venc_write_reg(VENC_GAIN_Y, config->gain_y);
  306. venc_write_reg(VENC_BLACK_LEVEL, config->black_level);
  307. venc_write_reg(VENC_BLANK_LEVEL, config->blank_level);
  308. venc_write_reg(VENC_M_CONTROL, config->m_control);
  309. venc_write_reg(VENC_BSTAMP_WSS_DATA, config->bstamp_wss_data |
  310. venc.wss_data);
  311. venc_write_reg(VENC_S_CARR, config->s_carr);
  312. venc_write_reg(VENC_L21__WC_CTL, config->l21__wc_ctl);
  313. venc_write_reg(VENC_SAVID__EAVID, config->savid__eavid);
  314. venc_write_reg(VENC_FLEN__FAL, config->flen__fal);
  315. venc_write_reg(VENC_LAL__PHASE_RESET, config->lal__phase_reset);
  316. venc_write_reg(VENC_HS_INT_START_STOP_X, config->hs_int_start_stop_x);
  317. venc_write_reg(VENC_HS_EXT_START_STOP_X, config->hs_ext_start_stop_x);
  318. venc_write_reg(VENC_VS_INT_START_X, config->vs_int_start_x);
  319. venc_write_reg(VENC_VS_INT_STOP_X__VS_INT_START_Y,
  320. config->vs_int_stop_x__vs_int_start_y);
  321. venc_write_reg(VENC_VS_INT_STOP_Y__VS_EXT_START_X,
  322. config->vs_int_stop_y__vs_ext_start_x);
  323. venc_write_reg(VENC_VS_EXT_STOP_X__VS_EXT_START_Y,
  324. config->vs_ext_stop_x__vs_ext_start_y);
  325. venc_write_reg(VENC_VS_EXT_STOP_Y, config->vs_ext_stop_y);
  326. venc_write_reg(VENC_AVID_START_STOP_X, config->avid_start_stop_x);
  327. venc_write_reg(VENC_AVID_START_STOP_Y, config->avid_start_stop_y);
  328. venc_write_reg(VENC_FID_INT_START_X__FID_INT_START_Y,
  329. config->fid_int_start_x__fid_int_start_y);
  330. venc_write_reg(VENC_FID_INT_OFFSET_Y__FID_EXT_START_X,
  331. config->fid_int_offset_y__fid_ext_start_x);
  332. venc_write_reg(VENC_FID_EXT_START_Y__FID_EXT_OFFSET_Y,
  333. config->fid_ext_start_y__fid_ext_offset_y);
  334. venc_write_reg(VENC_DAC_B__DAC_C, venc_read_reg(VENC_DAC_B__DAC_C));
  335. venc_write_reg(VENC_VIDOUT_CTRL, config->vidout_ctrl);
  336. venc_write_reg(VENC_HFLTR_CTRL, config->hfltr_ctrl);
  337. venc_write_reg(VENC_X_COLOR, config->x_color);
  338. venc_write_reg(VENC_LINE21, config->line21);
  339. venc_write_reg(VENC_LN_SEL, config->ln_sel);
  340. venc_write_reg(VENC_HTRIGGER_VTRIGGER, config->htrigger_vtrigger);
  341. venc_write_reg(VENC_TVDETGP_INT_START_STOP_X,
  342. config->tvdetgp_int_start_stop_x);
  343. venc_write_reg(VENC_TVDETGP_INT_START_STOP_Y,
  344. config->tvdetgp_int_start_stop_y);
  345. venc_write_reg(VENC_GEN_CTRL, config->gen_ctrl);
  346. venc_write_reg(VENC_F_CONTROL, config->f_control);
  347. venc_write_reg(VENC_SYNC_CTRL, config->sync_ctrl);
  348. }
  349. static void venc_reset(void)
  350. {
  351. int t = 1000;
  352. venc_write_reg(VENC_F_CONTROL, 1<<8);
  353. while (venc_read_reg(VENC_F_CONTROL) & (1<<8)) {
  354. if (--t == 0) {
  355. DSSERR("Failed to reset venc\n");
  356. return;
  357. }
  358. }
  359. #ifdef CONFIG_OMAP2_DSS_SLEEP_AFTER_VENC_RESET
  360. /* the magical sleep that makes things work */
  361. /* XXX more info? What bug this circumvents? */
  362. msleep(20);
  363. #endif
  364. }
  365. static int venc_runtime_get(void)
  366. {
  367. int r;
  368. DSSDBG("venc_runtime_get\n");
  369. r = pm_runtime_get_sync(&venc.pdev->dev);
  370. WARN_ON(r < 0);
  371. return r < 0 ? r : 0;
  372. }
  373. static void venc_runtime_put(void)
  374. {
  375. int r;
  376. DSSDBG("venc_runtime_put\n");
  377. r = pm_runtime_put_sync(&venc.pdev->dev);
  378. WARN_ON(r < 0 && r != -ENOSYS);
  379. }
  380. static const struct venc_config *venc_timings_to_config(
  381. struct omap_video_timings *timings)
  382. {
  383. if (memcmp(&omap_dss_pal_timings, timings, sizeof(*timings)) == 0)
  384. return &venc_config_pal_trm;
  385. if (memcmp(&omap_dss_ntsc_timings, timings, sizeof(*timings)) == 0)
  386. return &venc_config_ntsc_trm;
  387. BUG();
  388. return NULL;
  389. }
  390. static int venc_power_on(struct omap_dss_device *dssdev)
  391. {
  392. struct omap_overlay_manager *mgr = dssdev->output->manager;
  393. u32 l;
  394. int r;
  395. r = venc_runtime_get();
  396. if (r)
  397. goto err0;
  398. venc_reset();
  399. venc_write_config(venc_timings_to_config(&venc.timings));
  400. dss_set_venc_output(venc.type);
  401. dss_set_dac_pwrdn_bgz(1);
  402. l = 0;
  403. if (venc.type == OMAP_DSS_VENC_TYPE_COMPOSITE)
  404. l |= 1 << 1;
  405. else /* S-Video */
  406. l |= (1 << 0) | (1 << 2);
  407. if (venc.invert_polarity == false)
  408. l |= 1 << 3;
  409. venc_write_reg(VENC_OUTPUT_CONTROL, l);
  410. dss_mgr_set_timings(mgr, &venc.timings);
  411. r = regulator_enable(venc.vdda_dac_reg);
  412. if (r)
  413. goto err1;
  414. r = dss_mgr_enable(mgr);
  415. if (r)
  416. goto err2;
  417. return 0;
  418. err2:
  419. regulator_disable(venc.vdda_dac_reg);
  420. err1:
  421. venc_write_reg(VENC_OUTPUT_CONTROL, 0);
  422. dss_set_dac_pwrdn_bgz(0);
  423. venc_runtime_put();
  424. err0:
  425. return r;
  426. }
  427. static void venc_power_off(struct omap_dss_device *dssdev)
  428. {
  429. struct omap_overlay_manager *mgr = dssdev->output->manager;
  430. venc_write_reg(VENC_OUTPUT_CONTROL, 0);
  431. dss_set_dac_pwrdn_bgz(0);
  432. dss_mgr_disable(mgr);
  433. regulator_disable(venc.vdda_dac_reg);
  434. venc_runtime_put();
  435. }
  436. unsigned long venc_get_pixel_clock(void)
  437. {
  438. /* VENC Pixel Clock in Mhz */
  439. return 13500000;
  440. }
  441. int omapdss_venc_display_enable(struct omap_dss_device *dssdev)
  442. {
  443. struct omap_dss_output *out = dssdev->output;
  444. int r;
  445. DSSDBG("venc_display_enable\n");
  446. mutex_lock(&venc.venc_lock);
  447. if (out == NULL || out->manager == NULL) {
  448. DSSERR("Failed to enable display: no output/manager\n");
  449. r = -ENODEV;
  450. goto err0;
  451. }
  452. r = omap_dss_start_device(dssdev);
  453. if (r) {
  454. DSSERR("failed to start device\n");
  455. goto err0;
  456. }
  457. if (dssdev->platform_enable)
  458. dssdev->platform_enable(dssdev);
  459. r = venc_power_on(dssdev);
  460. if (r)
  461. goto err1;
  462. venc.wss_data = 0;
  463. mutex_unlock(&venc.venc_lock);
  464. return 0;
  465. err1:
  466. if (dssdev->platform_disable)
  467. dssdev->platform_disable(dssdev);
  468. omap_dss_stop_device(dssdev);
  469. err0:
  470. mutex_unlock(&venc.venc_lock);
  471. return r;
  472. }
  473. void omapdss_venc_display_disable(struct omap_dss_device *dssdev)
  474. {
  475. DSSDBG("venc_display_disable\n");
  476. mutex_lock(&venc.venc_lock);
  477. venc_power_off(dssdev);
  478. omap_dss_stop_device(dssdev);
  479. if (dssdev->platform_disable)
  480. dssdev->platform_disable(dssdev);
  481. mutex_unlock(&venc.venc_lock);
  482. }
  483. void omapdss_venc_set_timings(struct omap_dss_device *dssdev,
  484. struct omap_video_timings *timings)
  485. {
  486. DSSDBG("venc_set_timings\n");
  487. mutex_lock(&venc.venc_lock);
  488. /* Reset WSS data when the TV standard changes. */
  489. if (memcmp(&venc.timings, timings, sizeof(*timings)))
  490. venc.wss_data = 0;
  491. venc.timings = *timings;
  492. mutex_unlock(&venc.venc_lock);
  493. }
  494. int omapdss_venc_check_timings(struct omap_dss_device *dssdev,
  495. struct omap_video_timings *timings)
  496. {
  497. DSSDBG("venc_check_timings\n");
  498. if (memcmp(&omap_dss_pal_timings, timings, sizeof(*timings)) == 0)
  499. return 0;
  500. if (memcmp(&omap_dss_ntsc_timings, timings, sizeof(*timings)) == 0)
  501. return 0;
  502. return -EINVAL;
  503. }
  504. u32 omapdss_venc_get_wss(struct omap_dss_device *dssdev)
  505. {
  506. /* Invert due to VENC_L21_WC_CTL:INV=1 */
  507. return (venc.wss_data >> 8) ^ 0xfffff;
  508. }
  509. int omapdss_venc_set_wss(struct omap_dss_device *dssdev, u32 wss)
  510. {
  511. const struct venc_config *config;
  512. int r;
  513. DSSDBG("venc_set_wss\n");
  514. mutex_lock(&venc.venc_lock);
  515. config = venc_timings_to_config(&venc.timings);
  516. /* Invert due to VENC_L21_WC_CTL:INV=1 */
  517. venc.wss_data = (wss ^ 0xfffff) << 8;
  518. r = venc_runtime_get();
  519. if (r)
  520. goto err;
  521. venc_write_reg(VENC_BSTAMP_WSS_DATA, config->bstamp_wss_data |
  522. venc.wss_data);
  523. venc_runtime_put();
  524. err:
  525. mutex_unlock(&venc.venc_lock);
  526. return r;
  527. }
  528. void omapdss_venc_set_type(struct omap_dss_device *dssdev,
  529. enum omap_dss_venc_type type)
  530. {
  531. mutex_lock(&venc.venc_lock);
  532. venc.type = type;
  533. mutex_unlock(&venc.venc_lock);
  534. }
  535. void omapdss_venc_invert_vid_out_polarity(struct omap_dss_device *dssdev,
  536. bool invert_polarity)
  537. {
  538. mutex_lock(&venc.venc_lock);
  539. venc.invert_polarity = invert_polarity;
  540. mutex_unlock(&venc.venc_lock);
  541. }
  542. static int __init venc_init_display(struct omap_dss_device *dssdev)
  543. {
  544. DSSDBG("init_display\n");
  545. if (venc.vdda_dac_reg == NULL) {
  546. struct regulator *vdda_dac;
  547. vdda_dac = regulator_get(&venc.pdev->dev, "vdda_dac");
  548. if (IS_ERR(vdda_dac)) {
  549. DSSERR("can't get VDDA_DAC regulator\n");
  550. return PTR_ERR(vdda_dac);
  551. }
  552. venc.vdda_dac_reg = vdda_dac;
  553. }
  554. return 0;
  555. }
  556. static void venc_dump_regs(struct seq_file *s)
  557. {
  558. #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, venc_read_reg(r))
  559. if (venc_runtime_get())
  560. return;
  561. DUMPREG(VENC_F_CONTROL);
  562. DUMPREG(VENC_VIDOUT_CTRL);
  563. DUMPREG(VENC_SYNC_CTRL);
  564. DUMPREG(VENC_LLEN);
  565. DUMPREG(VENC_FLENS);
  566. DUMPREG(VENC_HFLTR_CTRL);
  567. DUMPREG(VENC_CC_CARR_WSS_CARR);
  568. DUMPREG(VENC_C_PHASE);
  569. DUMPREG(VENC_GAIN_U);
  570. DUMPREG(VENC_GAIN_V);
  571. DUMPREG(VENC_GAIN_Y);
  572. DUMPREG(VENC_BLACK_LEVEL);
  573. DUMPREG(VENC_BLANK_LEVEL);
  574. DUMPREG(VENC_X_COLOR);
  575. DUMPREG(VENC_M_CONTROL);
  576. DUMPREG(VENC_BSTAMP_WSS_DATA);
  577. DUMPREG(VENC_S_CARR);
  578. DUMPREG(VENC_LINE21);
  579. DUMPREG(VENC_LN_SEL);
  580. DUMPREG(VENC_L21__WC_CTL);
  581. DUMPREG(VENC_HTRIGGER_VTRIGGER);
  582. DUMPREG(VENC_SAVID__EAVID);
  583. DUMPREG(VENC_FLEN__FAL);
  584. DUMPREG(VENC_LAL__PHASE_RESET);
  585. DUMPREG(VENC_HS_INT_START_STOP_X);
  586. DUMPREG(VENC_HS_EXT_START_STOP_X);
  587. DUMPREG(VENC_VS_INT_START_X);
  588. DUMPREG(VENC_VS_INT_STOP_X__VS_INT_START_Y);
  589. DUMPREG(VENC_VS_INT_STOP_Y__VS_EXT_START_X);
  590. DUMPREG(VENC_VS_EXT_STOP_X__VS_EXT_START_Y);
  591. DUMPREG(VENC_VS_EXT_STOP_Y);
  592. DUMPREG(VENC_AVID_START_STOP_X);
  593. DUMPREG(VENC_AVID_START_STOP_Y);
  594. DUMPREG(VENC_FID_INT_START_X__FID_INT_START_Y);
  595. DUMPREG(VENC_FID_INT_OFFSET_Y__FID_EXT_START_X);
  596. DUMPREG(VENC_FID_EXT_START_Y__FID_EXT_OFFSET_Y);
  597. DUMPREG(VENC_TVDETGP_INT_START_STOP_X);
  598. DUMPREG(VENC_TVDETGP_INT_START_STOP_Y);
  599. DUMPREG(VENC_GEN_CTRL);
  600. DUMPREG(VENC_OUTPUT_CONTROL);
  601. DUMPREG(VENC_OUTPUT_TEST);
  602. venc_runtime_put();
  603. #undef DUMPREG
  604. }
  605. static int venc_get_clocks(struct platform_device *pdev)
  606. {
  607. struct clk *clk;
  608. if (dss_has_feature(FEAT_VENC_REQUIRES_TV_DAC_CLK)) {
  609. clk = clk_get(&pdev->dev, "tv_dac_clk");
  610. if (IS_ERR(clk)) {
  611. DSSERR("can't get tv_dac_clk\n");
  612. return PTR_ERR(clk);
  613. }
  614. } else {
  615. clk = NULL;
  616. }
  617. venc.tv_dac_clk = clk;
  618. return 0;
  619. }
  620. static void venc_put_clocks(void)
  621. {
  622. if (venc.tv_dac_clk)
  623. clk_put(venc.tv_dac_clk);
  624. }
  625. static struct omap_dss_device * __init venc_find_dssdev(struct platform_device *pdev)
  626. {
  627. struct omap_dss_board_info *pdata = pdev->dev.platform_data;
  628. const char *def_disp_name = omapdss_get_default_display_name();
  629. struct omap_dss_device *def_dssdev;
  630. int i;
  631. def_dssdev = NULL;
  632. for (i = 0; i < pdata->num_devices; ++i) {
  633. struct omap_dss_device *dssdev = pdata->devices[i];
  634. if (dssdev->type != OMAP_DISPLAY_TYPE_VENC)
  635. continue;
  636. if (def_dssdev == NULL)
  637. def_dssdev = dssdev;
  638. if (def_disp_name != NULL &&
  639. strcmp(dssdev->name, def_disp_name) == 0) {
  640. def_dssdev = dssdev;
  641. break;
  642. }
  643. }
  644. return def_dssdev;
  645. }
  646. static void __init venc_probe_pdata(struct platform_device *vencdev)
  647. {
  648. struct omap_dss_device *plat_dssdev;
  649. struct omap_dss_device *dssdev;
  650. int r;
  651. plat_dssdev = venc_find_dssdev(vencdev);
  652. if (!plat_dssdev)
  653. return;
  654. dssdev = dss_alloc_and_init_device(&vencdev->dev);
  655. if (!dssdev)
  656. return;
  657. dss_copy_device_pdata(dssdev, plat_dssdev);
  658. dssdev->channel = OMAP_DSS_CHANNEL_DIGIT;
  659. r = venc_init_display(dssdev);
  660. if (r) {
  661. DSSERR("device %s init failed: %d\n", dssdev->name, r);
  662. dss_put_device(dssdev);
  663. return;
  664. }
  665. r = omapdss_output_set_device(&venc.output, dssdev);
  666. if (r) {
  667. DSSERR("failed to connect output to new device: %s\n",
  668. dssdev->name);
  669. dss_put_device(dssdev);
  670. return;
  671. }
  672. r = dss_add_device(dssdev);
  673. if (r) {
  674. DSSERR("device %s register failed: %d\n", dssdev->name, r);
  675. omapdss_output_unset_device(&venc.output);
  676. dss_put_device(dssdev);
  677. return;
  678. }
  679. }
  680. static void __init venc_init_output(struct platform_device *pdev)
  681. {
  682. struct omap_dss_output *out = &venc.output;
  683. out->pdev = pdev;
  684. out->id = OMAP_DSS_OUTPUT_VENC;
  685. out->type = OMAP_DISPLAY_TYPE_VENC;
  686. dss_register_output(out);
  687. }
  688. static void __exit venc_uninit_output(struct platform_device *pdev)
  689. {
  690. struct omap_dss_output *out = &venc.output;
  691. dss_unregister_output(out);
  692. }
  693. /* VENC HW IP initialisation */
  694. static int __init omap_venchw_probe(struct platform_device *pdev)
  695. {
  696. u8 rev_id;
  697. struct resource *venc_mem;
  698. int r;
  699. venc.pdev = pdev;
  700. mutex_init(&venc.venc_lock);
  701. venc.wss_data = 0;
  702. venc_mem = platform_get_resource(venc.pdev, IORESOURCE_MEM, 0);
  703. if (!venc_mem) {
  704. DSSERR("can't get IORESOURCE_MEM VENC\n");
  705. return -EINVAL;
  706. }
  707. venc.base = devm_ioremap(&pdev->dev, venc_mem->start,
  708. resource_size(venc_mem));
  709. if (!venc.base) {
  710. DSSERR("can't ioremap VENC\n");
  711. return -ENOMEM;
  712. }
  713. r = venc_get_clocks(pdev);
  714. if (r)
  715. return r;
  716. pm_runtime_enable(&pdev->dev);
  717. r = venc_runtime_get();
  718. if (r)
  719. goto err_runtime_get;
  720. rev_id = (u8)(venc_read_reg(VENC_REV_ID) & 0xff);
  721. dev_dbg(&pdev->dev, "OMAP VENC rev %d\n", rev_id);
  722. venc_runtime_put();
  723. r = venc_panel_init();
  724. if (r)
  725. goto err_panel_init;
  726. dss_debugfs_create_file("venc", venc_dump_regs);
  727. venc_init_output(pdev);
  728. venc_probe_pdata(pdev);
  729. return 0;
  730. err_panel_init:
  731. err_runtime_get:
  732. pm_runtime_disable(&pdev->dev);
  733. venc_put_clocks();
  734. return r;
  735. }
  736. static int __exit omap_venchw_remove(struct platform_device *pdev)
  737. {
  738. dss_unregister_child_devices(&pdev->dev);
  739. if (venc.vdda_dac_reg != NULL) {
  740. regulator_put(venc.vdda_dac_reg);
  741. venc.vdda_dac_reg = NULL;
  742. }
  743. venc_panel_exit();
  744. venc_uninit_output(pdev);
  745. pm_runtime_disable(&pdev->dev);
  746. venc_put_clocks();
  747. return 0;
  748. }
  749. static int venc_runtime_suspend(struct device *dev)
  750. {
  751. if (venc.tv_dac_clk)
  752. clk_disable_unprepare(venc.tv_dac_clk);
  753. dispc_runtime_put();
  754. return 0;
  755. }
  756. static int venc_runtime_resume(struct device *dev)
  757. {
  758. int r;
  759. r = dispc_runtime_get();
  760. if (r < 0)
  761. return r;
  762. if (venc.tv_dac_clk)
  763. clk_prepare_enable(venc.tv_dac_clk);
  764. return 0;
  765. }
  766. static const struct dev_pm_ops venc_pm_ops = {
  767. .runtime_suspend = venc_runtime_suspend,
  768. .runtime_resume = venc_runtime_resume,
  769. };
  770. static struct platform_driver omap_venchw_driver = {
  771. .remove = __exit_p(omap_venchw_remove),
  772. .driver = {
  773. .name = "omapdss_venc",
  774. .owner = THIS_MODULE,
  775. .pm = &venc_pm_ops,
  776. },
  777. };
  778. int __init venc_init_platform_driver(void)
  779. {
  780. return platform_driver_probe(&omap_venchw_driver, omap_venchw_probe);
  781. }
  782. void __exit venc_uninit_platform_driver(void)
  783. {
  784. platform_driver_unregister(&omap_venchw_driver);
  785. }