Chaithrika U S | 63a8e71 | 2009-06-09 05:54:02 -0300 | [diff] [blame] | 1 | /* |
| 2 | * vpif - DM646x Video Port Interface driver |
| 3 | * VPIF is a receiver and transmitter for video data. It has two channels(0, 1) |
| 4 | * that receiveing video byte stream and two channels(2, 3) for video output. |
| 5 | * The hardware supports SDTV, HDTV formats, raw data capture. |
| 6 | * Currently, the driver supports NTSC and PAL standards. |
| 7 | * |
| 8 | * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation version 2. |
| 13 | * |
| 14 | * This program is distributed .as is. WITHOUT ANY WARRANTY of any |
| 15 | * kind, whether express or implied; without even the implied warranty |
| 16 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | */ |
| 19 | |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/module.h> |
Muralidharan Karicheri | d28a6df | 2009-09-16 14:31:20 -0300 | [diff] [blame] | 22 | #include <linux/platform_device.h> |
| 23 | #include <linux/spinlock.h> |
Chaithrika U S | 63a8e71 | 2009-06-09 05:54:02 -0300 | [diff] [blame] | 24 | #include <linux/kernel.h> |
Muralidharan Karicheri | d28a6df | 2009-09-16 14:31:20 -0300 | [diff] [blame] | 25 | #include <linux/io.h> |
| 26 | #include <mach/hardware.h> |
Chaithrika U S | 63a8e71 | 2009-06-09 05:54:02 -0300 | [diff] [blame] | 27 | |
| 28 | #include "vpif.h" |
| 29 | |
| 30 | MODULE_DESCRIPTION("TI DaVinci Video Port Interface driver"); |
| 31 | MODULE_LICENSE("GPL"); |
| 32 | |
| 33 | #define VPIF_CH0_MAX_MODES (22) |
| 34 | #define VPIF_CH1_MAX_MODES (02) |
| 35 | #define VPIF_CH2_MAX_MODES (15) |
| 36 | #define VPIF_CH3_MAX_MODES (02) |
| 37 | |
Muralidharan Karicheri | d28a6df | 2009-09-16 14:31:20 -0300 | [diff] [blame] | 38 | static resource_size_t res_len; |
| 39 | static struct resource *res; |
| 40 | spinlock_t vpif_lock; |
| 41 | |
| 42 | void __iomem *vpif_base; |
| 43 | |
Mats Randgaard | aa44440 | 2010-12-16 12:17:42 -0300 | [diff] [blame^] | 44 | /** |
| 45 | * ch_params: video standard configuration parameters for vpif |
| 46 | * The table must include all presets from supported subdevices. |
| 47 | */ |
| 48 | const struct vpif_channel_config_params ch_params[] = { |
| 49 | /* SDTV formats */ |
| 50 | { |
| 51 | .name = "NTSC_M", |
| 52 | .width = 720, |
| 53 | .height = 480, |
| 54 | .frm_fmt = 0, |
| 55 | .ycmux_mode = 1, |
| 56 | .eav2sav = 268, |
| 57 | .sav2eav = 1440, |
| 58 | .l1 = 1, |
| 59 | .l3 = 23, |
| 60 | .l5 = 263, |
| 61 | .l7 = 266, |
| 62 | .l9 = 286, |
| 63 | .l11 = 525, |
| 64 | .vsize = 525, |
| 65 | .capture_format = 0, |
| 66 | .vbi_supported = 1, |
| 67 | .hd_sd = 0, |
| 68 | .stdid = V4L2_STD_525_60, |
| 69 | }, |
| 70 | { |
| 71 | .name = "PAL_BDGHIK", |
| 72 | .width = 720, |
| 73 | .height = 576, |
| 74 | .frm_fmt = 0, |
| 75 | .ycmux_mode = 1, |
| 76 | .eav2sav = 280, |
| 77 | .sav2eav = 1440, |
| 78 | .l1 = 1, |
| 79 | .l3 = 23, |
| 80 | .l5 = 311, |
| 81 | .l7 = 313, |
| 82 | .l9 = 336, |
| 83 | .l11 = 624, |
| 84 | .vsize = 625, |
| 85 | .capture_format = 0, |
| 86 | .vbi_supported = 1, |
| 87 | .hd_sd = 0, |
| 88 | .stdid = V4L2_STD_625_50, |
| 89 | }, |
| 90 | }; |
| 91 | |
| 92 | const unsigned int vpif_ch_params_count = ARRAY_SIZE(ch_params); |
| 93 | |
Chaithrika U S | 63a8e71 | 2009-06-09 05:54:02 -0300 | [diff] [blame] | 94 | static inline void vpif_wr_bit(u32 reg, u32 bit, u32 val) |
| 95 | { |
| 96 | if (val) |
| 97 | vpif_set_bit(reg, bit); |
| 98 | else |
| 99 | vpif_clr_bit(reg, bit); |
| 100 | } |
| 101 | |
| 102 | /* This structure is used to keep track of VPIF size register's offsets */ |
| 103 | struct vpif_registers { |
| 104 | u32 h_cfg, v_cfg_00, v_cfg_01, v_cfg_02, v_cfg, ch_ctrl; |
| 105 | u32 line_offset, vanc0_strt, vanc0_size, vanc1_strt; |
| 106 | u32 vanc1_size, width_mask, len_mask; |
| 107 | u8 max_modes; |
| 108 | }; |
| 109 | |
| 110 | static const struct vpif_registers vpifregs[VPIF_NUM_CHANNELS] = { |
| 111 | /* Channel0 */ |
| 112 | { |
| 113 | VPIF_CH0_H_CFG, VPIF_CH0_V_CFG_00, VPIF_CH0_V_CFG_01, |
| 114 | VPIF_CH0_V_CFG_02, VPIF_CH0_V_CFG_03, VPIF_CH0_CTRL, |
| 115 | VPIF_CH0_IMG_ADD_OFST, 0, 0, 0, 0, 0x1FFF, 0xFFF, |
| 116 | VPIF_CH0_MAX_MODES, |
| 117 | }, |
| 118 | /* Channel1 */ |
| 119 | { |
| 120 | VPIF_CH1_H_CFG, VPIF_CH1_V_CFG_00, VPIF_CH1_V_CFG_01, |
| 121 | VPIF_CH1_V_CFG_02, VPIF_CH1_V_CFG_03, VPIF_CH1_CTRL, |
| 122 | VPIF_CH1_IMG_ADD_OFST, 0, 0, 0, 0, 0x1FFF, 0xFFF, |
| 123 | VPIF_CH1_MAX_MODES, |
| 124 | }, |
| 125 | /* Channel2 */ |
| 126 | { |
| 127 | VPIF_CH2_H_CFG, VPIF_CH2_V_CFG_00, VPIF_CH2_V_CFG_01, |
| 128 | VPIF_CH2_V_CFG_02, VPIF_CH2_V_CFG_03, VPIF_CH2_CTRL, |
| 129 | VPIF_CH2_IMG_ADD_OFST, VPIF_CH2_VANC0_STRT, VPIF_CH2_VANC0_SIZE, |
| 130 | VPIF_CH2_VANC1_STRT, VPIF_CH2_VANC1_SIZE, 0x7FF, 0x7FF, |
| 131 | VPIF_CH2_MAX_MODES |
| 132 | }, |
| 133 | /* Channel3 */ |
| 134 | { |
| 135 | VPIF_CH3_H_CFG, VPIF_CH3_V_CFG_00, VPIF_CH3_V_CFG_01, |
| 136 | VPIF_CH3_V_CFG_02, VPIF_CH3_V_CFG_03, VPIF_CH3_CTRL, |
| 137 | VPIF_CH3_IMG_ADD_OFST, VPIF_CH3_VANC0_STRT, VPIF_CH3_VANC0_SIZE, |
| 138 | VPIF_CH3_VANC1_STRT, VPIF_CH3_VANC1_SIZE, 0x7FF, 0x7FF, |
| 139 | VPIF_CH3_MAX_MODES |
| 140 | }, |
| 141 | }; |
| 142 | |
| 143 | /* vpif_set_mode_info: |
| 144 | * This function is used to set horizontal and vertical config parameters |
| 145 | * As per the standard in the channel, configure the values of L1, L3, |
| 146 | * L5, L7 L9, L11 in VPIF Register , also write width and height |
| 147 | */ |
| 148 | static void vpif_set_mode_info(const struct vpif_channel_config_params *config, |
| 149 | u8 channel_id, u8 config_channel_id) |
| 150 | { |
| 151 | u32 value; |
| 152 | |
| 153 | value = (config->eav2sav & vpifregs[config_channel_id].width_mask); |
| 154 | value <<= VPIF_CH_LEN_SHIFT; |
| 155 | value |= (config->sav2eav & vpifregs[config_channel_id].width_mask); |
| 156 | regw(value, vpifregs[channel_id].h_cfg); |
| 157 | |
| 158 | value = (config->l1 & vpifregs[config_channel_id].len_mask); |
| 159 | value <<= VPIF_CH_LEN_SHIFT; |
| 160 | value |= (config->l3 & vpifregs[config_channel_id].len_mask); |
| 161 | regw(value, vpifregs[channel_id].v_cfg_00); |
| 162 | |
| 163 | value = (config->l5 & vpifregs[config_channel_id].len_mask); |
| 164 | value <<= VPIF_CH_LEN_SHIFT; |
| 165 | value |= (config->l7 & vpifregs[config_channel_id].len_mask); |
| 166 | regw(value, vpifregs[channel_id].v_cfg_01); |
| 167 | |
| 168 | value = (config->l9 & vpifregs[config_channel_id].len_mask); |
| 169 | value <<= VPIF_CH_LEN_SHIFT; |
| 170 | value |= (config->l11 & vpifregs[config_channel_id].len_mask); |
| 171 | regw(value, vpifregs[channel_id].v_cfg_02); |
| 172 | |
| 173 | value = (config->vsize & vpifregs[config_channel_id].len_mask); |
| 174 | regw(value, vpifregs[channel_id].v_cfg); |
| 175 | } |
| 176 | |
| 177 | /* config_vpif_params |
| 178 | * Function to set the parameters of a channel |
| 179 | * Mainly modifies the channel ciontrol register |
| 180 | * It sets frame format, yc mux mode |
| 181 | */ |
| 182 | static void config_vpif_params(struct vpif_params *vpifparams, |
| 183 | u8 channel_id, u8 found) |
| 184 | { |
| 185 | const struct vpif_channel_config_params *config = &vpifparams->std_info; |
| 186 | u32 value, ch_nip, reg; |
| 187 | u8 start, end; |
| 188 | int i; |
| 189 | |
| 190 | start = channel_id; |
| 191 | end = channel_id + found; |
| 192 | |
| 193 | for (i = start; i < end; i++) { |
| 194 | reg = vpifregs[i].ch_ctrl; |
| 195 | if (channel_id < 2) |
| 196 | ch_nip = VPIF_CAPTURE_CH_NIP; |
| 197 | else |
| 198 | ch_nip = VPIF_DISPLAY_CH_NIP; |
| 199 | |
| 200 | vpif_wr_bit(reg, ch_nip, config->frm_fmt); |
| 201 | vpif_wr_bit(reg, VPIF_CH_YC_MUX_BIT, config->ycmux_mode); |
| 202 | vpif_wr_bit(reg, VPIF_CH_INPUT_FIELD_FRAME_BIT, |
| 203 | vpifparams->video_params.storage_mode); |
| 204 | |
| 205 | /* Set raster scanning SDR Format */ |
| 206 | vpif_clr_bit(reg, VPIF_CH_SDR_FMT_BIT); |
| 207 | vpif_wr_bit(reg, VPIF_CH_DATA_MODE_BIT, config->capture_format); |
| 208 | |
| 209 | if (channel_id > 1) /* Set the Pixel enable bit */ |
| 210 | vpif_set_bit(reg, VPIF_DISPLAY_PIX_EN_BIT); |
| 211 | else if (config->capture_format) { |
| 212 | /* Set the polarity of various pins */ |
| 213 | vpif_wr_bit(reg, VPIF_CH_FID_POLARITY_BIT, |
Muralidharan Karicheri | d28a6df | 2009-09-16 14:31:20 -0300 | [diff] [blame] | 214 | vpifparams->iface.fid_pol); |
Chaithrika U S | 63a8e71 | 2009-06-09 05:54:02 -0300 | [diff] [blame] | 215 | vpif_wr_bit(reg, VPIF_CH_V_VALID_POLARITY_BIT, |
Muralidharan Karicheri | d28a6df | 2009-09-16 14:31:20 -0300 | [diff] [blame] | 216 | vpifparams->iface.vd_pol); |
Chaithrika U S | 63a8e71 | 2009-06-09 05:54:02 -0300 | [diff] [blame] | 217 | vpif_wr_bit(reg, VPIF_CH_H_VALID_POLARITY_BIT, |
Muralidharan Karicheri | d28a6df | 2009-09-16 14:31:20 -0300 | [diff] [blame] | 218 | vpifparams->iface.hd_pol); |
Chaithrika U S | 63a8e71 | 2009-06-09 05:54:02 -0300 | [diff] [blame] | 219 | |
| 220 | value = regr(reg); |
| 221 | /* Set data width */ |
| 222 | value &= ((~(unsigned int)(0x3)) << |
| 223 | VPIF_CH_DATA_WIDTH_BIT); |
Muralidharan Karicheri | d28a6df | 2009-09-16 14:31:20 -0300 | [diff] [blame] | 224 | value |= ((vpifparams->params.data_sz) << |
Chaithrika U S | 63a8e71 | 2009-06-09 05:54:02 -0300 | [diff] [blame] | 225 | VPIF_CH_DATA_WIDTH_BIT); |
| 226 | regw(value, reg); |
| 227 | } |
| 228 | |
| 229 | /* Write the pitch in the driver */ |
| 230 | regw((vpifparams->video_params.hpitch), |
| 231 | vpifregs[i].line_offset); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | /* vpif_set_video_params |
| 236 | * This function is used to set video parameters in VPIF register |
| 237 | */ |
| 238 | int vpif_set_video_params(struct vpif_params *vpifparams, u8 channel_id) |
| 239 | { |
| 240 | const struct vpif_channel_config_params *config = &vpifparams->std_info; |
| 241 | int found = 1; |
| 242 | |
| 243 | vpif_set_mode_info(config, channel_id, channel_id); |
| 244 | if (!config->ycmux_mode) { |
| 245 | /* YC are on separate channels (HDTV formats) */ |
| 246 | vpif_set_mode_info(config, channel_id + 1, channel_id); |
| 247 | found = 2; |
| 248 | } |
| 249 | |
| 250 | config_vpif_params(vpifparams, channel_id, found); |
| 251 | |
| 252 | regw(0x80, VPIF_REQ_SIZE); |
| 253 | regw(0x01, VPIF_EMULATION_CTRL); |
| 254 | |
| 255 | return found; |
| 256 | } |
| 257 | EXPORT_SYMBOL(vpif_set_video_params); |
| 258 | |
| 259 | void vpif_set_vbi_display_params(struct vpif_vbi_params *vbiparams, |
| 260 | u8 channel_id) |
| 261 | { |
| 262 | u32 value; |
| 263 | |
| 264 | value = 0x3F8 & (vbiparams->hstart0); |
| 265 | value |= 0x3FFFFFF & ((vbiparams->vstart0) << 16); |
| 266 | regw(value, vpifregs[channel_id].vanc0_strt); |
| 267 | |
| 268 | value = 0x3F8 & (vbiparams->hstart1); |
| 269 | value |= 0x3FFFFFF & ((vbiparams->vstart1) << 16); |
| 270 | regw(value, vpifregs[channel_id].vanc1_strt); |
| 271 | |
| 272 | value = 0x3F8 & (vbiparams->hsize0); |
| 273 | value |= 0x3FFFFFF & ((vbiparams->vsize0) << 16); |
| 274 | regw(value, vpifregs[channel_id].vanc0_size); |
| 275 | |
| 276 | value = 0x3F8 & (vbiparams->hsize1); |
| 277 | value |= 0x3FFFFFF & ((vbiparams->vsize1) << 16); |
| 278 | regw(value, vpifregs[channel_id].vanc1_size); |
| 279 | |
| 280 | } |
| 281 | EXPORT_SYMBOL(vpif_set_vbi_display_params); |
| 282 | |
| 283 | int vpif_channel_getfid(u8 channel_id) |
| 284 | { |
| 285 | return (regr(vpifregs[channel_id].ch_ctrl) & VPIF_CH_FID_MASK) |
| 286 | >> VPIF_CH_FID_SHIFT; |
| 287 | } |
| 288 | EXPORT_SYMBOL(vpif_channel_getfid); |
| 289 | |
Muralidharan Karicheri | d28a6df | 2009-09-16 14:31:20 -0300 | [diff] [blame] | 290 | static int __init vpif_probe(struct platform_device *pdev) |
Chaithrika U S | 63a8e71 | 2009-06-09 05:54:02 -0300 | [diff] [blame] | 291 | { |
Muralidharan Karicheri | d28a6df | 2009-09-16 14:31:20 -0300 | [diff] [blame] | 292 | int status = 0; |
| 293 | |
| 294 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 295 | if (!res) |
| 296 | return -ENOENT; |
| 297 | |
| 298 | res_len = res->end - res->start + 1; |
| 299 | |
| 300 | res = request_mem_region(res->start, res_len, res->name); |
| 301 | if (!res) |
| 302 | return -EBUSY; |
| 303 | |
| 304 | vpif_base = ioremap(res->start, res_len); |
| 305 | if (!vpif_base) { |
| 306 | status = -EBUSY; |
| 307 | goto fail; |
| 308 | } |
| 309 | |
| 310 | spin_lock_init(&vpif_lock); |
| 311 | dev_info(&pdev->dev, "vpif probe success\n"); |
| 312 | return 0; |
| 313 | |
| 314 | fail: |
| 315 | release_mem_region(res->start, res_len); |
| 316 | return status; |
Chaithrika U S | 63a8e71 | 2009-06-09 05:54:02 -0300 | [diff] [blame] | 317 | } |
Muralidharan Karicheri | d28a6df | 2009-09-16 14:31:20 -0300 | [diff] [blame] | 318 | |
Uwe Kleine-König | 0b0a860 | 2009-12-10 17:02:16 -0300 | [diff] [blame] | 319 | static int __devexit vpif_remove(struct platform_device *pdev) |
Muralidharan Karicheri | d28a6df | 2009-09-16 14:31:20 -0300 | [diff] [blame] | 320 | { |
| 321 | iounmap(vpif_base); |
| 322 | release_mem_region(res->start, res_len); |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | static struct platform_driver vpif_driver = { |
| 327 | .driver = { |
| 328 | .name = "vpif", |
| 329 | .owner = THIS_MODULE, |
| 330 | }, |
| 331 | .remove = __devexit_p(vpif_remove), |
| 332 | .probe = vpif_probe, |
| 333 | }; |
| 334 | |
| 335 | static void vpif_exit(void) |
| 336 | { |
| 337 | platform_driver_unregister(&vpif_driver); |
| 338 | } |
| 339 | |
| 340 | static int __init vpif_init(void) |
| 341 | { |
| 342 | return platform_driver_register(&vpif_driver); |
| 343 | } |
| 344 | subsys_initcall(vpif_init); |
| 345 | module_exit(vpif_exit); |
| 346 | |