venc.c 23 KB

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