venc.c 23 KB

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