venc.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983
  1. /*
  2. * Copyright (C) 2009 Nokia Corporation
  3. * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
  4. *
  5. * VENC settings from TI's DSS driver
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #define DSS_SUBSYS_NAME "VENC"
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include <linux/clk.h>
  23. #include <linux/err.h>
  24. #include <linux/io.h>
  25. #include <linux/mutex.h>
  26. #include <linux/completion.h>
  27. #include <linux/delay.h>
  28. #include <linux/string.h>
  29. #include <linux/seq_file.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/regulator/consumer.h>
  32. #include <linux/pm_runtime.h>
  33. #include <linux/of.h>
  34. #include <linux/of_graph.h>
  35. #include <linux/component.h>
  36. #include <linux/sys_soc.h>
  37. #include "omapdss.h"
  38. #include "dss.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. enum venc_videomode {
  251. VENC_MODE_UNKNOWN,
  252. VENC_MODE_PAL,
  253. VENC_MODE_NTSC,
  254. };
  255. static const struct videomode omap_dss_pal_vm = {
  256. .hactive = 720,
  257. .vactive = 574,
  258. .pixelclock = 13500000,
  259. .hsync_len = 64,
  260. .hfront_porch = 12,
  261. .hback_porch = 68,
  262. .vsync_len = 5,
  263. .vfront_porch = 5,
  264. .vback_porch = 41,
  265. .flags = DISPLAY_FLAGS_INTERLACED | DISPLAY_FLAGS_HSYNC_LOW |
  266. DISPLAY_FLAGS_VSYNC_LOW | DISPLAY_FLAGS_DE_HIGH |
  267. DISPLAY_FLAGS_PIXDATA_POSEDGE |
  268. DISPLAY_FLAGS_SYNC_NEGEDGE,
  269. };
  270. static const struct videomode omap_dss_ntsc_vm = {
  271. .hactive = 720,
  272. .vactive = 482,
  273. .pixelclock = 13500000,
  274. .hsync_len = 64,
  275. .hfront_porch = 16,
  276. .hback_porch = 58,
  277. .vsync_len = 6,
  278. .vfront_porch = 6,
  279. .vback_porch = 31,
  280. .flags = DISPLAY_FLAGS_INTERLACED | DISPLAY_FLAGS_HSYNC_LOW |
  281. DISPLAY_FLAGS_VSYNC_LOW | DISPLAY_FLAGS_DE_HIGH |
  282. DISPLAY_FLAGS_PIXDATA_POSEDGE |
  283. DISPLAY_FLAGS_SYNC_NEGEDGE,
  284. };
  285. static enum venc_videomode venc_get_videomode(const struct videomode *vm)
  286. {
  287. if (!(vm->flags & DISPLAY_FLAGS_INTERLACED))
  288. return VENC_MODE_UNKNOWN;
  289. if (vm->pixelclock == omap_dss_pal_vm.pixelclock &&
  290. vm->hactive == omap_dss_pal_vm.hactive &&
  291. vm->vactive == omap_dss_pal_vm.vactive)
  292. return VENC_MODE_PAL;
  293. if (vm->pixelclock == omap_dss_ntsc_vm.pixelclock &&
  294. vm->hactive == omap_dss_ntsc_vm.hactive &&
  295. vm->vactive == omap_dss_ntsc_vm.vactive)
  296. return VENC_MODE_NTSC;
  297. return VENC_MODE_UNKNOWN;
  298. }
  299. struct venc_device {
  300. struct platform_device *pdev;
  301. void __iomem *base;
  302. struct mutex venc_lock;
  303. u32 wss_data;
  304. struct regulator *vdda_dac_reg;
  305. struct dss_device *dss;
  306. struct dss_debugfs_entry *debugfs;
  307. struct clk *tv_dac_clk;
  308. struct videomode vm;
  309. enum omap_dss_venc_type type;
  310. bool invert_polarity;
  311. bool requires_tv_dac_clk;
  312. struct omap_dss_device output;
  313. };
  314. #define dssdev_to_venc(dssdev) container_of(dssdev, struct venc_device, output)
  315. static inline void venc_write_reg(struct venc_device *venc, int idx, u32 val)
  316. {
  317. __raw_writel(val, venc->base + idx);
  318. }
  319. static inline u32 venc_read_reg(struct venc_device *venc, int idx)
  320. {
  321. u32 l = __raw_readl(venc->base + idx);
  322. return l;
  323. }
  324. static void venc_write_config(struct venc_device *venc,
  325. const struct venc_config *config)
  326. {
  327. DSSDBG("write venc conf\n");
  328. venc_write_reg(venc, VENC_LLEN, config->llen);
  329. venc_write_reg(venc, VENC_FLENS, config->flens);
  330. venc_write_reg(venc, VENC_CC_CARR_WSS_CARR, config->cc_carr_wss_carr);
  331. venc_write_reg(venc, VENC_C_PHASE, config->c_phase);
  332. venc_write_reg(venc, VENC_GAIN_U, config->gain_u);
  333. venc_write_reg(venc, VENC_GAIN_V, config->gain_v);
  334. venc_write_reg(venc, VENC_GAIN_Y, config->gain_y);
  335. venc_write_reg(venc, VENC_BLACK_LEVEL, config->black_level);
  336. venc_write_reg(venc, VENC_BLANK_LEVEL, config->blank_level);
  337. venc_write_reg(venc, VENC_M_CONTROL, config->m_control);
  338. venc_write_reg(venc, VENC_BSTAMP_WSS_DATA, config->bstamp_wss_data |
  339. venc->wss_data);
  340. venc_write_reg(venc, VENC_S_CARR, config->s_carr);
  341. venc_write_reg(venc, VENC_L21__WC_CTL, config->l21__wc_ctl);
  342. venc_write_reg(venc, VENC_SAVID__EAVID, config->savid__eavid);
  343. venc_write_reg(venc, VENC_FLEN__FAL, config->flen__fal);
  344. venc_write_reg(venc, VENC_LAL__PHASE_RESET, config->lal__phase_reset);
  345. venc_write_reg(venc, VENC_HS_INT_START_STOP_X,
  346. config->hs_int_start_stop_x);
  347. venc_write_reg(venc, VENC_HS_EXT_START_STOP_X,
  348. config->hs_ext_start_stop_x);
  349. venc_write_reg(venc, VENC_VS_INT_START_X, config->vs_int_start_x);
  350. venc_write_reg(venc, VENC_VS_INT_STOP_X__VS_INT_START_Y,
  351. config->vs_int_stop_x__vs_int_start_y);
  352. venc_write_reg(venc, VENC_VS_INT_STOP_Y__VS_EXT_START_X,
  353. config->vs_int_stop_y__vs_ext_start_x);
  354. venc_write_reg(venc, VENC_VS_EXT_STOP_X__VS_EXT_START_Y,
  355. config->vs_ext_stop_x__vs_ext_start_y);
  356. venc_write_reg(venc, VENC_VS_EXT_STOP_Y, config->vs_ext_stop_y);
  357. venc_write_reg(venc, VENC_AVID_START_STOP_X, config->avid_start_stop_x);
  358. venc_write_reg(venc, VENC_AVID_START_STOP_Y, config->avid_start_stop_y);
  359. venc_write_reg(venc, VENC_FID_INT_START_X__FID_INT_START_Y,
  360. config->fid_int_start_x__fid_int_start_y);
  361. venc_write_reg(venc, VENC_FID_INT_OFFSET_Y__FID_EXT_START_X,
  362. config->fid_int_offset_y__fid_ext_start_x);
  363. venc_write_reg(venc, VENC_FID_EXT_START_Y__FID_EXT_OFFSET_Y,
  364. config->fid_ext_start_y__fid_ext_offset_y);
  365. venc_write_reg(venc, VENC_DAC_B__DAC_C,
  366. venc_read_reg(venc, VENC_DAC_B__DAC_C));
  367. venc_write_reg(venc, VENC_VIDOUT_CTRL, config->vidout_ctrl);
  368. venc_write_reg(venc, VENC_HFLTR_CTRL, config->hfltr_ctrl);
  369. venc_write_reg(venc, VENC_X_COLOR, config->x_color);
  370. venc_write_reg(venc, VENC_LINE21, config->line21);
  371. venc_write_reg(venc, VENC_LN_SEL, config->ln_sel);
  372. venc_write_reg(venc, VENC_HTRIGGER_VTRIGGER, config->htrigger_vtrigger);
  373. venc_write_reg(venc, VENC_TVDETGP_INT_START_STOP_X,
  374. config->tvdetgp_int_start_stop_x);
  375. venc_write_reg(venc, VENC_TVDETGP_INT_START_STOP_Y,
  376. config->tvdetgp_int_start_stop_y);
  377. venc_write_reg(venc, VENC_GEN_CTRL, config->gen_ctrl);
  378. venc_write_reg(venc, VENC_F_CONTROL, config->f_control);
  379. venc_write_reg(venc, VENC_SYNC_CTRL, config->sync_ctrl);
  380. }
  381. static void venc_reset(struct venc_device *venc)
  382. {
  383. int t = 1000;
  384. venc_write_reg(venc, VENC_F_CONTROL, 1<<8);
  385. while (venc_read_reg(venc, VENC_F_CONTROL) & (1<<8)) {
  386. if (--t == 0) {
  387. DSSERR("Failed to reset venc\n");
  388. return;
  389. }
  390. }
  391. #ifdef CONFIG_OMAP2_DSS_SLEEP_AFTER_VENC_RESET
  392. /* the magical sleep that makes things work */
  393. /* XXX more info? What bug this circumvents? */
  394. msleep(20);
  395. #endif
  396. }
  397. static int venc_runtime_get(struct venc_device *venc)
  398. {
  399. int r;
  400. DSSDBG("venc_runtime_get\n");
  401. r = pm_runtime_get_sync(&venc->pdev->dev);
  402. WARN_ON(r < 0);
  403. return r < 0 ? r : 0;
  404. }
  405. static void venc_runtime_put(struct venc_device *venc)
  406. {
  407. int r;
  408. DSSDBG("venc_runtime_put\n");
  409. r = pm_runtime_put_sync(&venc->pdev->dev);
  410. WARN_ON(r < 0 && r != -ENOSYS);
  411. }
  412. static const struct venc_config *venc_timings_to_config(const struct videomode *vm)
  413. {
  414. switch (venc_get_videomode(vm)) {
  415. default:
  416. WARN_ON_ONCE(1);
  417. case VENC_MODE_PAL:
  418. return &venc_config_pal_trm;
  419. case VENC_MODE_NTSC:
  420. return &venc_config_ntsc_trm;
  421. }
  422. }
  423. static int venc_power_on(struct venc_device *venc)
  424. {
  425. u32 l;
  426. int r;
  427. r = venc_runtime_get(venc);
  428. if (r)
  429. goto err0;
  430. venc_reset(venc);
  431. venc_write_config(venc, venc_timings_to_config(&venc->vm));
  432. dss_set_venc_output(venc->dss, venc->type);
  433. dss_set_dac_pwrdn_bgz(venc->dss, 1);
  434. l = 0;
  435. if (venc->type == OMAP_DSS_VENC_TYPE_COMPOSITE)
  436. l |= 1 << 1;
  437. else /* S-Video */
  438. l |= (1 << 0) | (1 << 2);
  439. if (venc->invert_polarity == false)
  440. l |= 1 << 3;
  441. venc_write_reg(venc, VENC_OUTPUT_CONTROL, l);
  442. r = regulator_enable(venc->vdda_dac_reg);
  443. if (r)
  444. goto err1;
  445. r = dss_mgr_enable(&venc->output);
  446. if (r)
  447. goto err2;
  448. return 0;
  449. err2:
  450. regulator_disable(venc->vdda_dac_reg);
  451. err1:
  452. venc_write_reg(venc, VENC_OUTPUT_CONTROL, 0);
  453. dss_set_dac_pwrdn_bgz(venc->dss, 0);
  454. venc_runtime_put(venc);
  455. err0:
  456. return r;
  457. }
  458. static void venc_power_off(struct venc_device *venc)
  459. {
  460. venc_write_reg(venc, VENC_OUTPUT_CONTROL, 0);
  461. dss_set_dac_pwrdn_bgz(venc->dss, 0);
  462. dss_mgr_disable(&venc->output);
  463. regulator_disable(venc->vdda_dac_reg);
  464. venc_runtime_put(venc);
  465. }
  466. static int venc_display_enable(struct omap_dss_device *dssdev)
  467. {
  468. struct venc_device *venc = dssdev_to_venc(dssdev);
  469. int r;
  470. DSSDBG("venc_display_enable\n");
  471. mutex_lock(&venc->venc_lock);
  472. if (!dssdev->dispc_channel_connected) {
  473. DSSERR("Failed to enable display: no output/manager\n");
  474. r = -ENODEV;
  475. goto err0;
  476. }
  477. r = venc_power_on(venc);
  478. if (r)
  479. goto err0;
  480. venc->wss_data = 0;
  481. mutex_unlock(&venc->venc_lock);
  482. return 0;
  483. err0:
  484. mutex_unlock(&venc->venc_lock);
  485. return r;
  486. }
  487. static void venc_display_disable(struct omap_dss_device *dssdev)
  488. {
  489. struct venc_device *venc = dssdev_to_venc(dssdev);
  490. DSSDBG("venc_display_disable\n");
  491. mutex_lock(&venc->venc_lock);
  492. venc_power_off(venc);
  493. mutex_unlock(&venc->venc_lock);
  494. }
  495. static void venc_get_timings(struct omap_dss_device *dssdev,
  496. struct videomode *vm)
  497. {
  498. struct venc_device *venc = dssdev_to_venc(dssdev);
  499. mutex_lock(&venc->venc_lock);
  500. *vm = venc->vm;
  501. mutex_unlock(&venc->venc_lock);
  502. }
  503. static void venc_set_timings(struct omap_dss_device *dssdev,
  504. const struct videomode *vm)
  505. {
  506. struct venc_device *venc = dssdev_to_venc(dssdev);
  507. DSSDBG("venc_set_timings\n");
  508. mutex_lock(&venc->venc_lock);
  509. /* Reset WSS data when the TV standard changes. */
  510. if (memcmp(&venc->vm, vm, sizeof(*vm)))
  511. venc->wss_data = 0;
  512. venc->vm = *vm;
  513. dispc_set_tv_pclk(venc->dss->dispc, 13500000);
  514. mutex_unlock(&venc->venc_lock);
  515. }
  516. static int venc_check_timings(struct omap_dss_device *dssdev,
  517. struct videomode *vm)
  518. {
  519. DSSDBG("venc_check_timings\n");
  520. switch (venc_get_videomode(vm)) {
  521. case VENC_MODE_PAL:
  522. *vm = omap_dss_pal_vm;
  523. return 0;
  524. case VENC_MODE_NTSC:
  525. *vm = omap_dss_ntsc_vm;
  526. return 0;
  527. default:
  528. return -EINVAL;
  529. }
  530. }
  531. static int venc_dump_regs(struct seq_file *s, void *p)
  532. {
  533. struct venc_device *venc = s->private;
  534. #define DUMPREG(venc, r) \
  535. seq_printf(s, "%-35s %08x\n", #r, venc_read_reg(venc, r))
  536. if (venc_runtime_get(venc))
  537. return 0;
  538. DUMPREG(venc, VENC_F_CONTROL);
  539. DUMPREG(venc, VENC_VIDOUT_CTRL);
  540. DUMPREG(venc, VENC_SYNC_CTRL);
  541. DUMPREG(venc, VENC_LLEN);
  542. DUMPREG(venc, VENC_FLENS);
  543. DUMPREG(venc, VENC_HFLTR_CTRL);
  544. DUMPREG(venc, VENC_CC_CARR_WSS_CARR);
  545. DUMPREG(venc, VENC_C_PHASE);
  546. DUMPREG(venc, VENC_GAIN_U);
  547. DUMPREG(venc, VENC_GAIN_V);
  548. DUMPREG(venc, VENC_GAIN_Y);
  549. DUMPREG(venc, VENC_BLACK_LEVEL);
  550. DUMPREG(venc, VENC_BLANK_LEVEL);
  551. DUMPREG(venc, VENC_X_COLOR);
  552. DUMPREG(venc, VENC_M_CONTROL);
  553. DUMPREG(venc, VENC_BSTAMP_WSS_DATA);
  554. DUMPREG(venc, VENC_S_CARR);
  555. DUMPREG(venc, VENC_LINE21);
  556. DUMPREG(venc, VENC_LN_SEL);
  557. DUMPREG(venc, VENC_L21__WC_CTL);
  558. DUMPREG(venc, VENC_HTRIGGER_VTRIGGER);
  559. DUMPREG(venc, VENC_SAVID__EAVID);
  560. DUMPREG(venc, VENC_FLEN__FAL);
  561. DUMPREG(venc, VENC_LAL__PHASE_RESET);
  562. DUMPREG(venc, VENC_HS_INT_START_STOP_X);
  563. DUMPREG(venc, VENC_HS_EXT_START_STOP_X);
  564. DUMPREG(venc, VENC_VS_INT_START_X);
  565. DUMPREG(venc, VENC_VS_INT_STOP_X__VS_INT_START_Y);
  566. DUMPREG(venc, VENC_VS_INT_STOP_Y__VS_EXT_START_X);
  567. DUMPREG(venc, VENC_VS_EXT_STOP_X__VS_EXT_START_Y);
  568. DUMPREG(venc, VENC_VS_EXT_STOP_Y);
  569. DUMPREG(venc, VENC_AVID_START_STOP_X);
  570. DUMPREG(venc, VENC_AVID_START_STOP_Y);
  571. DUMPREG(venc, VENC_FID_INT_START_X__FID_INT_START_Y);
  572. DUMPREG(venc, VENC_FID_INT_OFFSET_Y__FID_EXT_START_X);
  573. DUMPREG(venc, VENC_FID_EXT_START_Y__FID_EXT_OFFSET_Y);
  574. DUMPREG(venc, VENC_TVDETGP_INT_START_STOP_X);
  575. DUMPREG(venc, VENC_TVDETGP_INT_START_STOP_Y);
  576. DUMPREG(venc, VENC_GEN_CTRL);
  577. DUMPREG(venc, VENC_OUTPUT_CONTROL);
  578. DUMPREG(venc, VENC_OUTPUT_TEST);
  579. venc_runtime_put(venc);
  580. #undef DUMPREG
  581. return 0;
  582. }
  583. static int venc_get_clocks(struct venc_device *venc)
  584. {
  585. struct clk *clk;
  586. if (venc->requires_tv_dac_clk) {
  587. clk = devm_clk_get(&venc->pdev->dev, "tv_dac_clk");
  588. if (IS_ERR(clk)) {
  589. DSSERR("can't get tv_dac_clk\n");
  590. return PTR_ERR(clk);
  591. }
  592. } else {
  593. clk = NULL;
  594. }
  595. venc->tv_dac_clk = clk;
  596. return 0;
  597. }
  598. static int venc_connect(struct omap_dss_device *src,
  599. struct omap_dss_device *dst)
  600. {
  601. int r;
  602. r = omapdss_device_connect(dst->dss, dst, dst->next);
  603. if (r)
  604. return r;
  605. dst->dispc_channel_connected = true;
  606. return 0;
  607. }
  608. static void venc_disconnect(struct omap_dss_device *src,
  609. struct omap_dss_device *dst)
  610. {
  611. dst->dispc_channel_connected = false;
  612. omapdss_device_disconnect(dst, dst->next);
  613. }
  614. static const struct omap_dss_device_ops venc_ops = {
  615. .connect = venc_connect,
  616. .disconnect = venc_disconnect,
  617. .enable = venc_display_enable,
  618. .disable = venc_display_disable,
  619. .check_timings = venc_check_timings,
  620. .get_timings = venc_get_timings,
  621. .set_timings = venc_set_timings,
  622. };
  623. /* -----------------------------------------------------------------------------
  624. * Component Bind & Unbind
  625. */
  626. static int venc_bind(struct device *dev, struct device *master, void *data)
  627. {
  628. struct dss_device *dss = dss_get_device(master);
  629. struct venc_device *venc = dev_get_drvdata(dev);
  630. u8 rev_id;
  631. int r;
  632. venc->dss = dss;
  633. r = venc_runtime_get(venc);
  634. if (r)
  635. return r;
  636. rev_id = (u8)(venc_read_reg(venc, VENC_REV_ID) & 0xff);
  637. dev_dbg(dev, "OMAP VENC rev %d\n", rev_id);
  638. venc_runtime_put(venc);
  639. venc->debugfs = dss_debugfs_create_file(dss, "venc", venc_dump_regs,
  640. venc);
  641. return 0;
  642. }
  643. static void venc_unbind(struct device *dev, struct device *master, void *data)
  644. {
  645. struct venc_device *venc = dev_get_drvdata(dev);
  646. dss_debugfs_remove_file(venc->debugfs);
  647. }
  648. static const struct component_ops venc_component_ops = {
  649. .bind = venc_bind,
  650. .unbind = venc_unbind,
  651. };
  652. /* -----------------------------------------------------------------------------
  653. * Probe & Remove, Suspend & Resume
  654. */
  655. static int venc_init_output(struct venc_device *venc)
  656. {
  657. struct omap_dss_device *out = &venc->output;
  658. int r;
  659. out->dev = &venc->pdev->dev;
  660. out->id = OMAP_DSS_OUTPUT_VENC;
  661. out->output_type = OMAP_DISPLAY_TYPE_VENC;
  662. out->name = "venc.0";
  663. out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT;
  664. out->ops = &venc_ops;
  665. out->owner = THIS_MODULE;
  666. out->of_ports = BIT(0);
  667. out->next = omapdss_of_find_connected_device(out->dev->of_node, 0);
  668. if (IS_ERR(out->next)) {
  669. if (PTR_ERR(out->next) != -EPROBE_DEFER)
  670. dev_err(out->dev, "failed to find video sink\n");
  671. return PTR_ERR(out->next);
  672. }
  673. r = omapdss_output_validate(out);
  674. if (r) {
  675. omapdss_device_put(out->next);
  676. out->next = NULL;
  677. return r;
  678. }
  679. omapdss_device_register(out);
  680. return 0;
  681. }
  682. static void venc_uninit_output(struct venc_device *venc)
  683. {
  684. if (venc->output.next)
  685. omapdss_device_put(venc->output.next);
  686. omapdss_device_unregister(&venc->output);
  687. }
  688. static int venc_probe_of(struct venc_device *venc)
  689. {
  690. struct device_node *node = venc->pdev->dev.of_node;
  691. struct device_node *ep;
  692. u32 channels;
  693. int r;
  694. ep = of_graph_get_endpoint_by_regs(node, 0, 0);
  695. if (!ep)
  696. return 0;
  697. venc->invert_polarity = of_property_read_bool(ep, "ti,invert-polarity");
  698. r = of_property_read_u32(ep, "ti,channels", &channels);
  699. if (r) {
  700. dev_err(&venc->pdev->dev,
  701. "failed to read property 'ti,channels': %d\n", r);
  702. goto err;
  703. }
  704. switch (channels) {
  705. case 1:
  706. venc->type = OMAP_DSS_VENC_TYPE_COMPOSITE;
  707. break;
  708. case 2:
  709. venc->type = OMAP_DSS_VENC_TYPE_SVIDEO;
  710. break;
  711. default:
  712. dev_err(&venc->pdev->dev, "bad channel propert '%d'\n",
  713. channels);
  714. r = -EINVAL;
  715. goto err;
  716. }
  717. of_node_put(ep);
  718. return 0;
  719. err:
  720. of_node_put(ep);
  721. return r;
  722. }
  723. static const struct soc_device_attribute venc_soc_devices[] = {
  724. { .machine = "OMAP3[45]*" },
  725. { .machine = "AM35*" },
  726. { /* sentinel */ }
  727. };
  728. static int venc_probe(struct platform_device *pdev)
  729. {
  730. struct venc_device *venc;
  731. struct resource *venc_mem;
  732. int r;
  733. venc = kzalloc(sizeof(*venc), GFP_KERNEL);
  734. if (!venc)
  735. return -ENOMEM;
  736. venc->pdev = pdev;
  737. platform_set_drvdata(pdev, venc);
  738. /* The OMAP34xx, OMAP35xx and AM35xx VENC require the TV DAC clock. */
  739. if (soc_device_match(venc_soc_devices))
  740. venc->requires_tv_dac_clk = true;
  741. mutex_init(&venc->venc_lock);
  742. venc->wss_data = 0;
  743. venc->vm = omap_dss_pal_vm;
  744. venc_mem = platform_get_resource(venc->pdev, IORESOURCE_MEM, 0);
  745. venc->base = devm_ioremap_resource(&pdev->dev, venc_mem);
  746. if (IS_ERR(venc->base)) {
  747. r = PTR_ERR(venc->base);
  748. goto err_free;
  749. }
  750. venc->vdda_dac_reg = devm_regulator_get(&pdev->dev, "vdda");
  751. if (IS_ERR(venc->vdda_dac_reg)) {
  752. r = PTR_ERR(venc->vdda_dac_reg);
  753. if (r != -EPROBE_DEFER)
  754. DSSERR("can't get VDDA_DAC regulator\n");
  755. goto err_free;
  756. }
  757. r = venc_get_clocks(venc);
  758. if (r)
  759. goto err_free;
  760. r = venc_probe_of(venc);
  761. if (r)
  762. goto err_free;
  763. pm_runtime_enable(&pdev->dev);
  764. r = venc_init_output(venc);
  765. if (r)
  766. goto err_pm_disable;
  767. r = component_add(&pdev->dev, &venc_component_ops);
  768. if (r)
  769. goto err_uninit_output;
  770. return 0;
  771. err_uninit_output:
  772. venc_uninit_output(venc);
  773. err_pm_disable:
  774. pm_runtime_disable(&pdev->dev);
  775. err_free:
  776. kfree(venc);
  777. return r;
  778. }
  779. static int venc_remove(struct platform_device *pdev)
  780. {
  781. struct venc_device *venc = platform_get_drvdata(pdev);
  782. component_del(&pdev->dev, &venc_component_ops);
  783. venc_uninit_output(venc);
  784. pm_runtime_disable(&pdev->dev);
  785. kfree(venc);
  786. return 0;
  787. }
  788. static int venc_runtime_suspend(struct device *dev)
  789. {
  790. struct venc_device *venc = dev_get_drvdata(dev);
  791. if (venc->tv_dac_clk)
  792. clk_disable_unprepare(venc->tv_dac_clk);
  793. return 0;
  794. }
  795. static int venc_runtime_resume(struct device *dev)
  796. {
  797. struct venc_device *venc = dev_get_drvdata(dev);
  798. if (venc->tv_dac_clk)
  799. clk_prepare_enable(venc->tv_dac_clk);
  800. return 0;
  801. }
  802. static const struct dev_pm_ops venc_pm_ops = {
  803. .runtime_suspend = venc_runtime_suspend,
  804. .runtime_resume = venc_runtime_resume,
  805. };
  806. static const struct of_device_id venc_of_match[] = {
  807. { .compatible = "ti,omap2-venc", },
  808. { .compatible = "ti,omap3-venc", },
  809. { .compatible = "ti,omap4-venc", },
  810. {},
  811. };
  812. struct platform_driver omap_venchw_driver = {
  813. .probe = venc_probe,
  814. .remove = venc_remove,
  815. .driver = {
  816. .name = "omapdss_venc",
  817. .pm = &venc_pm_ops,
  818. .of_match_table = venc_of_match,
  819. .suppress_bind_attrs = true,
  820. },
  821. };