venc.c 24 KB

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