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