Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 Texas Instruments Inc |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation version 2. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 16 | */ |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/errno.h> |
| 21 | #include <linux/fs.h> |
| 22 | #include <linux/string.h> |
| 23 | #include <linux/wait.h> |
| 24 | #include <linux/time.h> |
| 25 | #include <linux/platform_device.h> |
| 26 | #include <linux/io.h> |
| 27 | #include <linux/slab.h> |
| 28 | #include <linux/clk.h> |
| 29 | #include <linux/err.h> |
| 30 | |
| 31 | #include <media/v4l2-device.h> |
| 32 | #include <media/davinci/vpbe_types.h> |
| 33 | #include <media/davinci/vpbe.h> |
| 34 | #include <media/davinci/vpss.h> |
| 35 | #include <media/davinci/vpbe_venc.h> |
| 36 | |
| 37 | #define VPBE_DEFAULT_OUTPUT "Composite" |
| 38 | #define VPBE_DEFAULT_MODE "ntsc" |
| 39 | |
| 40 | static char *def_output = VPBE_DEFAULT_OUTPUT; |
| 41 | static char *def_mode = VPBE_DEFAULT_MODE; |
| 42 | static int debug; |
| 43 | |
| 44 | module_param(def_output, charp, S_IRUGO); |
| 45 | module_param(def_mode, charp, S_IRUGO); |
| 46 | module_param(debug, int, 0644); |
| 47 | |
| 48 | MODULE_PARM_DESC(def_output, "vpbe output name (default:Composite)"); |
| 49 | MODULE_PARM_DESC(def_mode, "vpbe output mode name (default:ntsc"); |
| 50 | MODULE_PARM_DESC(debug, "Debug level 0-1"); |
| 51 | |
| 52 | MODULE_DESCRIPTION("TI DMXXX VPBE Display controller"); |
| 53 | MODULE_LICENSE("GPL"); |
| 54 | MODULE_AUTHOR("Texas Instruments"); |
| 55 | |
| 56 | /** |
| 57 | * vpbe_current_encoder_info - Get config info for current encoder |
| 58 | * @vpbe_dev - vpbe device ptr |
| 59 | * |
| 60 | * Return ptr to current encoder config info |
| 61 | */ |
| 62 | static struct encoder_config_info* |
| 63 | vpbe_current_encoder_info(struct vpbe_device *vpbe_dev) |
| 64 | { |
| 65 | struct vpbe_config *cfg = vpbe_dev->cfg; |
| 66 | int index = vpbe_dev->current_sd_index; |
| 67 | |
| 68 | return ((index == 0) ? &cfg->venc : |
| 69 | &cfg->ext_encoders[index-1]); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * vpbe_find_encoder_sd_index - Given a name find encoder sd index |
| 74 | * |
| 75 | * @vpbe_config - ptr to vpbe cfg |
| 76 | * @output_index - index used by application |
| 77 | * |
| 78 | * Return sd index of the encoder |
| 79 | */ |
| 80 | static int vpbe_find_encoder_sd_index(struct vpbe_config *cfg, |
| 81 | int index) |
| 82 | { |
| 83 | char *encoder_name = cfg->outputs[index].subdev_name; |
| 84 | int i; |
| 85 | |
| 86 | /* Venc is always first */ |
| 87 | if (!strcmp(encoder_name, cfg->venc.module_name)) |
| 88 | return 0; |
| 89 | |
| 90 | for (i = 0; i < cfg->num_ext_encoders; i++) { |
| 91 | if (!strcmp(encoder_name, |
| 92 | cfg->ext_encoders[i].module_name)) |
| 93 | return i+1; |
| 94 | } |
| 95 | |
| 96 | return -EINVAL; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * vpbe_g_cropcap - Get crop capabilities of the display |
| 101 | * @vpbe_dev - vpbe device ptr |
| 102 | * @cropcap - cropcap is a ptr to struct v4l2_cropcap |
| 103 | * |
| 104 | * Update the crop capabilities in crop cap for current |
| 105 | * mode |
| 106 | */ |
| 107 | static int vpbe_g_cropcap(struct vpbe_device *vpbe_dev, |
| 108 | struct v4l2_cropcap *cropcap) |
| 109 | { |
| 110 | if (NULL == cropcap) |
| 111 | return -EINVAL; |
| 112 | cropcap->bounds.left = 0; |
| 113 | cropcap->bounds.top = 0; |
| 114 | cropcap->bounds.width = vpbe_dev->current_timings.xres; |
| 115 | cropcap->bounds.height = vpbe_dev->current_timings.yres; |
| 116 | cropcap->defrect = cropcap->bounds; |
| 117 | |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * vpbe_enum_outputs - enumerate outputs |
| 123 | * @vpbe_dev - vpbe device ptr |
| 124 | * @output - ptr to v4l2_output structure |
| 125 | * |
| 126 | * Enumerates the outputs available at the vpbe display |
| 127 | * returns the status, -EINVAL if end of output list |
| 128 | */ |
| 129 | static int vpbe_enum_outputs(struct vpbe_device *vpbe_dev, |
| 130 | struct v4l2_output *output) |
| 131 | { |
| 132 | struct vpbe_config *cfg = vpbe_dev->cfg; |
| 133 | int temp_index = output->index; |
| 134 | |
| 135 | if (temp_index >= cfg->num_outputs) |
| 136 | return -EINVAL; |
| 137 | |
| 138 | *output = cfg->outputs[temp_index].output; |
| 139 | output->index = temp_index; |
| 140 | |
| 141 | return 0; |
| 142 | } |
| 143 | |
Manjunath Hadli | 9a7f95a | 2011-04-30 03:01:40 -0300 | [diff] [blame] | 144 | static int vpbe_get_mode_info(struct vpbe_device *vpbe_dev, char *mode, |
| 145 | int output_index) |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 146 | { |
| 147 | struct vpbe_config *cfg = vpbe_dev->cfg; |
| 148 | struct vpbe_enc_mode_info var; |
Manjunath Hadli | 9a7f95a | 2011-04-30 03:01:40 -0300 | [diff] [blame] | 149 | int curr_output = output_index; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 150 | int i; |
| 151 | |
| 152 | if (NULL == mode) |
| 153 | return -EINVAL; |
| 154 | |
| 155 | for (i = 0; i < cfg->outputs[curr_output].num_modes; i++) { |
| 156 | var = cfg->outputs[curr_output].modes[i]; |
| 157 | if (!strcmp(mode, var.name)) { |
| 158 | vpbe_dev->current_timings = var; |
| 159 | return 0; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | return -EINVAL; |
| 164 | } |
| 165 | |
| 166 | static int vpbe_get_current_mode_info(struct vpbe_device *vpbe_dev, |
| 167 | struct vpbe_enc_mode_info *mode_info) |
| 168 | { |
| 169 | if (NULL == mode_info) |
| 170 | return -EINVAL; |
| 171 | |
| 172 | *mode_info = vpbe_dev->current_timings; |
| 173 | |
| 174 | return 0; |
| 175 | } |
| 176 | |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 177 | /* Get std by std id */ |
| 178 | static int vpbe_get_std_info(struct vpbe_device *vpbe_dev, |
| 179 | v4l2_std_id std_id) |
| 180 | { |
| 181 | struct vpbe_config *cfg = vpbe_dev->cfg; |
| 182 | struct vpbe_enc_mode_info var; |
| 183 | int curr_output = vpbe_dev->current_out_index; |
| 184 | int i; |
| 185 | |
| 186 | for (i = 0; i < vpbe_dev->cfg->outputs[curr_output].num_modes; i++) { |
| 187 | var = cfg->outputs[curr_output].modes[i]; |
| 188 | if ((var.timings_type & VPBE_ENC_STD) && |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 189 | (var.std_id & std_id)) { |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 190 | vpbe_dev->current_timings = var; |
| 191 | return 0; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | return -EINVAL; |
| 196 | } |
| 197 | |
| 198 | static int vpbe_get_std_info_by_name(struct vpbe_device *vpbe_dev, |
| 199 | char *std_name) |
| 200 | { |
| 201 | struct vpbe_config *cfg = vpbe_dev->cfg; |
| 202 | struct vpbe_enc_mode_info var; |
| 203 | int curr_output = vpbe_dev->current_out_index; |
| 204 | int i; |
| 205 | |
| 206 | for (i = 0; i < vpbe_dev->cfg->outputs[curr_output].num_modes; i++) { |
| 207 | var = cfg->outputs[curr_output].modes[i]; |
| 208 | if (!strcmp(var.name, std_name)) { |
| 209 | vpbe_dev->current_timings = var; |
| 210 | return 0; |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | return -EINVAL; |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * vpbe_set_output - Set output |
| 219 | * @vpbe_dev - vpbe device ptr |
| 220 | * @index - index of output |
| 221 | * |
| 222 | * Set vpbe output to the output specified by the index |
| 223 | */ |
| 224 | static int vpbe_set_output(struct vpbe_device *vpbe_dev, int index) |
| 225 | { |
| 226 | struct encoder_config_info *curr_enc_info = |
| 227 | vpbe_current_encoder_info(vpbe_dev); |
| 228 | struct vpbe_config *cfg = vpbe_dev->cfg; |
Manjunath Hadli | 9a7f95a | 2011-04-30 03:01:40 -0300 | [diff] [blame] | 229 | struct venc_platform_data *venc_device = vpbe_dev->venc_device; |
| 230 | enum v4l2_mbus_pixelcode if_params; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 231 | int enc_out_index; |
| 232 | int sd_index; |
| 233 | int ret = 0; |
| 234 | |
| 235 | if (index >= cfg->num_outputs) |
| 236 | return -EINVAL; |
| 237 | |
| 238 | mutex_lock(&vpbe_dev->lock); |
| 239 | |
| 240 | sd_index = vpbe_dev->current_sd_index; |
| 241 | enc_out_index = cfg->outputs[index].output.index; |
| 242 | /* |
| 243 | * Currently we switch the encoder based on output selected |
| 244 | * by the application. If media controller is implemented later |
| 245 | * there is will be an API added to setup_link between venc |
| 246 | * and external encoder. So in that case below comparison always |
| 247 | * match and encoder will not be switched. But if application |
| 248 | * chose not to use media controller, then this provides current |
| 249 | * way of switching encoder at the venc output. |
| 250 | */ |
| 251 | if (strcmp(curr_enc_info->module_name, |
| 252 | cfg->outputs[index].subdev_name)) { |
| 253 | /* Need to switch the encoder at the output */ |
| 254 | sd_index = vpbe_find_encoder_sd_index(cfg, index); |
| 255 | if (sd_index < 0) { |
| 256 | ret = -EINVAL; |
| 257 | goto out; |
| 258 | } |
| 259 | |
Manjunath Hadli | 9a7f95a | 2011-04-30 03:01:40 -0300 | [diff] [blame] | 260 | if_params = cfg->outputs[index].if_params; |
| 261 | venc_device->setup_if_config(if_params); |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 262 | if (ret) |
| 263 | goto out; |
| 264 | } |
| 265 | |
| 266 | /* Set output at the encoder */ |
| 267 | ret = v4l2_subdev_call(vpbe_dev->encoders[sd_index], video, |
| 268 | s_routing, 0, enc_out_index, 0); |
| 269 | if (ret) |
| 270 | goto out; |
| 271 | |
| 272 | /* |
| 273 | * It is assumed that venc or extenal encoder will set a default |
| 274 | * mode in the sub device. For external encoder or LCD pannel output, |
| 275 | * we also need to set up the lcd port for the required mode. So setup |
| 276 | * the lcd port for the default mode that is configured in the board |
| 277 | * arch/arm/mach-davinci/board-dm355-evm.setup file for the external |
| 278 | * encoder. |
| 279 | */ |
| 280 | ret = vpbe_get_mode_info(vpbe_dev, |
Manjunath Hadli | 9a7f95a | 2011-04-30 03:01:40 -0300 | [diff] [blame] | 281 | cfg->outputs[index].default_mode, index); |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 282 | if (!ret) { |
| 283 | struct osd_state *osd_device = vpbe_dev->osd_device; |
| 284 | |
| 285 | osd_device->ops.set_left_margin(osd_device, |
| 286 | vpbe_dev->current_timings.left_margin); |
| 287 | osd_device->ops.set_top_margin(osd_device, |
| 288 | vpbe_dev->current_timings.upper_margin); |
| 289 | vpbe_dev->current_sd_index = sd_index; |
| 290 | vpbe_dev->current_out_index = index; |
| 291 | } |
| 292 | out: |
| 293 | mutex_unlock(&vpbe_dev->lock); |
| 294 | return ret; |
| 295 | } |
| 296 | |
| 297 | static int vpbe_set_default_output(struct vpbe_device *vpbe_dev) |
| 298 | { |
| 299 | struct vpbe_config *cfg = vpbe_dev->cfg; |
| 300 | int ret = 0; |
| 301 | int i; |
| 302 | |
| 303 | for (i = 0; i < cfg->num_outputs; i++) { |
| 304 | if (!strcmp(def_output, |
| 305 | cfg->outputs[i].output.name)) { |
| 306 | ret = vpbe_set_output(vpbe_dev, i); |
| 307 | if (!ret) |
| 308 | vpbe_dev->current_out_index = i; |
| 309 | return ret; |
| 310 | } |
| 311 | } |
| 312 | return ret; |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * vpbe_get_output - Get output |
| 317 | * @vpbe_dev - vpbe device ptr |
| 318 | * |
| 319 | * return current vpbe output to the the index |
| 320 | */ |
| 321 | static unsigned int vpbe_get_output(struct vpbe_device *vpbe_dev) |
| 322 | { |
| 323 | return vpbe_dev->current_out_index; |
| 324 | } |
| 325 | |
| 326 | /** |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 327 | * vpbe_s_dv_timings - Set the given preset timings in the encoder |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 328 | * |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 329 | * Sets the timings if supported by the current encoder. Return the status. |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 330 | * 0 - success & -EINVAL on error |
| 331 | */ |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 332 | static int vpbe_s_dv_timings(struct vpbe_device *vpbe_dev, |
| 333 | struct v4l2_dv_timings *dv_timings) |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 334 | { |
| 335 | struct vpbe_config *cfg = vpbe_dev->cfg; |
| 336 | int out_index = vpbe_dev->current_out_index; |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 337 | struct vpbe_output *output = &cfg->outputs[out_index]; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 338 | int sd_index = vpbe_dev->current_sd_index; |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 339 | int ret, i; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 340 | |
| 341 | |
| 342 | if (!(cfg->outputs[out_index].output.capabilities & |
Lad, Prabhakar | e32087b | 2012-10-03 02:25:42 -0300 | [diff] [blame] | 343 | V4L2_OUT_CAP_DV_TIMINGS)) |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 344 | return -EINVAL; |
| 345 | |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 346 | for (i = 0; i < output->num_modes; i++) { |
Hans Verkuil | ef2d41b | 2013-02-15 15:06:28 -0300 | [diff] [blame] | 347 | if (output->modes[i].timings_type == VPBE_ENC_DV_TIMINGS && |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 348 | !memcmp(&output->modes[i].dv_timings, |
| 349 | dv_timings, sizeof(*dv_timings))) |
| 350 | break; |
| 351 | } |
| 352 | if (i >= output->num_modes) |
| 353 | return -EINVAL; |
| 354 | vpbe_dev->current_timings = output->modes[i]; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 355 | mutex_lock(&vpbe_dev->lock); |
| 356 | |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 357 | ret = v4l2_subdev_call(vpbe_dev->encoders[sd_index], video, |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 358 | s_dv_timings, dv_timings); |
Manjunath Hadli | 9a7f95a | 2011-04-30 03:01:40 -0300 | [diff] [blame] | 359 | if (!ret && (vpbe_dev->amp != NULL)) { |
| 360 | /* Call amplifier subdevice */ |
| 361 | ret = v4l2_subdev_call(vpbe_dev->amp, video, |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 362 | s_dv_timings, dv_timings); |
Manjunath Hadli | 9a7f95a | 2011-04-30 03:01:40 -0300 | [diff] [blame] | 363 | } |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 364 | /* set the lcd controller output for the given mode */ |
| 365 | if (!ret) { |
| 366 | struct osd_state *osd_device = vpbe_dev->osd_device; |
| 367 | |
| 368 | osd_device->ops.set_left_margin(osd_device, |
| 369 | vpbe_dev->current_timings.left_margin); |
| 370 | osd_device->ops.set_top_margin(osd_device, |
| 371 | vpbe_dev->current_timings.upper_margin); |
| 372 | } |
| 373 | mutex_unlock(&vpbe_dev->lock); |
| 374 | |
| 375 | return ret; |
| 376 | } |
| 377 | |
| 378 | /** |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 379 | * vpbe_g_dv_timings - Get the timings in the current encoder |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 380 | * |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 381 | * Get the timings in the current encoder. Return the status. 0 - success |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 382 | * -EINVAL on error |
| 383 | */ |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 384 | static int vpbe_g_dv_timings(struct vpbe_device *vpbe_dev, |
| 385 | struct v4l2_dv_timings *dv_timings) |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 386 | { |
| 387 | if (vpbe_dev->current_timings.timings_type & |
Hans Verkuil | ef2d41b | 2013-02-15 15:06:28 -0300 | [diff] [blame] | 388 | VPBE_ENC_DV_TIMINGS) { |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 389 | *dv_timings = vpbe_dev->current_timings.dv_timings; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 390 | return 0; |
| 391 | } |
| 392 | |
| 393 | return -EINVAL; |
| 394 | } |
| 395 | |
| 396 | /** |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 397 | * vpbe_enum_dv_timings - Enumerate the dv timings in the current encoder |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 398 | * |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 399 | * Get the timings in the current encoder. Return the status. 0 - success |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 400 | * -EINVAL on error |
| 401 | */ |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 402 | static int vpbe_enum_dv_timings(struct vpbe_device *vpbe_dev, |
| 403 | struct v4l2_enum_dv_timings *timings) |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 404 | { |
| 405 | struct vpbe_config *cfg = vpbe_dev->cfg; |
| 406 | int out_index = vpbe_dev->current_out_index; |
| 407 | struct vpbe_output *output = &cfg->outputs[out_index]; |
| 408 | int j = 0; |
| 409 | int i; |
| 410 | |
Lad, Prabhakar | e32087b | 2012-10-03 02:25:42 -0300 | [diff] [blame] | 411 | if (!(output->output.capabilities & V4L2_OUT_CAP_DV_TIMINGS)) |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 412 | return -EINVAL; |
| 413 | |
| 414 | for (i = 0; i < output->num_modes; i++) { |
Hans Verkuil | ef2d41b | 2013-02-15 15:06:28 -0300 | [diff] [blame] | 415 | if (output->modes[i].timings_type == VPBE_ENC_DV_TIMINGS) { |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 416 | if (j == timings->index) |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 417 | break; |
| 418 | j++; |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | if (i == output->num_modes) |
| 423 | return -EINVAL; |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 424 | timings->timings = output->modes[i].dv_timings; |
| 425 | return 0; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | /** |
| 429 | * vpbe_s_std - Set the given standard in the encoder |
| 430 | * |
| 431 | * Sets the standard if supported by the current encoder. Return the status. |
| 432 | * 0 - success & -EINVAL on error |
| 433 | */ |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 434 | static int vpbe_s_std(struct vpbe_device *vpbe_dev, v4l2_std_id std_id) |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 435 | { |
| 436 | struct vpbe_config *cfg = vpbe_dev->cfg; |
| 437 | int out_index = vpbe_dev->current_out_index; |
| 438 | int sd_index = vpbe_dev->current_sd_index; |
| 439 | int ret; |
| 440 | |
| 441 | if (!(cfg->outputs[out_index].output.capabilities & |
| 442 | V4L2_OUT_CAP_STD)) |
| 443 | return -EINVAL; |
| 444 | |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 445 | ret = vpbe_get_std_info(vpbe_dev, std_id); |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 446 | if (ret) |
| 447 | return ret; |
| 448 | |
| 449 | mutex_lock(&vpbe_dev->lock); |
| 450 | |
| 451 | ret = v4l2_subdev_call(vpbe_dev->encoders[sd_index], video, |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 452 | s_std_output, std_id); |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 453 | /* set the lcd controller output for the given mode */ |
| 454 | if (!ret) { |
| 455 | struct osd_state *osd_device = vpbe_dev->osd_device; |
| 456 | |
| 457 | osd_device->ops.set_left_margin(osd_device, |
| 458 | vpbe_dev->current_timings.left_margin); |
| 459 | osd_device->ops.set_top_margin(osd_device, |
| 460 | vpbe_dev->current_timings.upper_margin); |
| 461 | } |
| 462 | mutex_unlock(&vpbe_dev->lock); |
| 463 | |
| 464 | return ret; |
| 465 | } |
| 466 | |
| 467 | /** |
| 468 | * vpbe_g_std - Get the standard in the current encoder |
| 469 | * |
| 470 | * Get the standard in the current encoder. Return the status. 0 - success |
| 471 | * -EINVAL on error |
| 472 | */ |
| 473 | static int vpbe_g_std(struct vpbe_device *vpbe_dev, v4l2_std_id *std_id) |
| 474 | { |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 475 | struct vpbe_enc_mode_info *cur_timings = &vpbe_dev->current_timings; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 476 | |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 477 | if (cur_timings->timings_type & VPBE_ENC_STD) { |
| 478 | *std_id = cur_timings->std_id; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 479 | return 0; |
| 480 | } |
| 481 | |
| 482 | return -EINVAL; |
| 483 | } |
| 484 | |
| 485 | /** |
| 486 | * vpbe_set_mode - Set mode in the current encoder using mode info |
| 487 | * |
| 488 | * Use the mode string to decide what timings to set in the encoder |
| 489 | * This is typically useful when fbset command is used to change the current |
| 490 | * timings by specifying a string to indicate the timings. |
| 491 | */ |
| 492 | static int vpbe_set_mode(struct vpbe_device *vpbe_dev, |
| 493 | struct vpbe_enc_mode_info *mode_info) |
| 494 | { |
| 495 | struct vpbe_enc_mode_info *preset_mode = NULL; |
| 496 | struct vpbe_config *cfg = vpbe_dev->cfg; |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 497 | struct v4l2_dv_timings dv_timings; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 498 | struct osd_state *osd_device; |
| 499 | int out_index = vpbe_dev->current_out_index; |
| 500 | int ret = 0; |
| 501 | int i; |
| 502 | |
| 503 | if ((NULL == mode_info) || (NULL == mode_info->name)) |
| 504 | return -EINVAL; |
| 505 | |
| 506 | for (i = 0; i < cfg->outputs[out_index].num_modes; i++) { |
| 507 | if (!strcmp(mode_info->name, |
| 508 | cfg->outputs[out_index].modes[i].name)) { |
| 509 | preset_mode = &cfg->outputs[out_index].modes[i]; |
| 510 | /* |
| 511 | * it may be one of the 3 timings type. Check and |
| 512 | * invoke right API |
| 513 | */ |
| 514 | if (preset_mode->timings_type & VPBE_ENC_STD) |
| 515 | return vpbe_s_std(vpbe_dev, |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 516 | preset_mode->std_id); |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 517 | if (preset_mode->timings_type & |
Hans Verkuil | ef2d41b | 2013-02-15 15:06:28 -0300 | [diff] [blame] | 518 | VPBE_ENC_DV_TIMINGS) { |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 519 | dv_timings = |
| 520 | preset_mode->dv_timings; |
| 521 | return vpbe_s_dv_timings(vpbe_dev, &dv_timings); |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 522 | } |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | /* Only custom timing should reach here */ |
| 527 | if (preset_mode == NULL) |
| 528 | return -EINVAL; |
| 529 | |
| 530 | mutex_lock(&vpbe_dev->lock); |
| 531 | |
| 532 | osd_device = vpbe_dev->osd_device; |
| 533 | vpbe_dev->current_timings = *preset_mode; |
| 534 | osd_device->ops.set_left_margin(osd_device, |
| 535 | vpbe_dev->current_timings.left_margin); |
| 536 | osd_device->ops.set_top_margin(osd_device, |
| 537 | vpbe_dev->current_timings.upper_margin); |
| 538 | |
| 539 | mutex_unlock(&vpbe_dev->lock); |
| 540 | |
| 541 | return ret; |
| 542 | } |
| 543 | |
| 544 | static int vpbe_set_default_mode(struct vpbe_device *vpbe_dev) |
| 545 | { |
| 546 | int ret; |
| 547 | |
| 548 | ret = vpbe_get_std_info_by_name(vpbe_dev, def_mode); |
| 549 | if (ret) |
| 550 | return ret; |
| 551 | |
| 552 | /* set the default mode in the encoder */ |
| 553 | return vpbe_set_mode(vpbe_dev, &vpbe_dev->current_timings); |
| 554 | } |
| 555 | |
| 556 | static int platform_device_get(struct device *dev, void *data) |
| 557 | { |
| 558 | struct platform_device *pdev = to_platform_device(dev); |
| 559 | struct vpbe_device *vpbe_dev = data; |
| 560 | |
Lad, Prabhakar | caff80c | 2012-11-20 07:30:36 -0300 | [diff] [blame] | 561 | if (strstr(pdev->name, "vpbe-osd") != NULL) |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 562 | vpbe_dev->osd_device = platform_get_drvdata(pdev); |
Lad, Prabhakar | caff80c | 2012-11-20 07:30:36 -0300 | [diff] [blame] | 563 | if (strstr(pdev->name, "vpbe-venc") != NULL) |
Manjunath Hadli | 9a7f95a | 2011-04-30 03:01:40 -0300 | [diff] [blame] | 564 | vpbe_dev->venc_device = dev_get_platdata(&pdev->dev); |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 565 | |
| 566 | return 0; |
| 567 | } |
| 568 | |
| 569 | /** |
| 570 | * vpbe_initialize() - Initialize the vpbe display controller |
| 571 | * @vpbe_dev - vpbe device ptr |
| 572 | * |
| 573 | * Master frame buffer device drivers calls this to initialize vpbe |
| 574 | * display controller. This will then registers v4l2 device and the sub |
| 575 | * devices and sets a current encoder sub device for display. v4l2 display |
| 576 | * device driver is the master and frame buffer display device driver is |
| 577 | * the slave. Frame buffer display driver checks the initialized during |
| 578 | * probe and exit if not initialized. Returns status. |
| 579 | */ |
| 580 | static int vpbe_initialize(struct device *dev, struct vpbe_device *vpbe_dev) |
| 581 | { |
| 582 | struct encoder_config_info *enc_info; |
Manjunath Hadli | 9a7f95a | 2011-04-30 03:01:40 -0300 | [diff] [blame] | 583 | struct amp_config_info *amp_info; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 584 | struct v4l2_subdev **enc_subdev; |
| 585 | struct osd_state *osd_device; |
| 586 | struct i2c_adapter *i2c_adap; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 587 | int num_encoders; |
| 588 | int ret = 0; |
| 589 | int err; |
| 590 | int i; |
| 591 | |
| 592 | /* |
| 593 | * v4l2 abd FBDev frame buffer devices will get the vpbe_dev pointer |
| 594 | * from the platform device by iteration of platform drivers and |
| 595 | * matching with device name |
| 596 | */ |
| 597 | if (NULL == vpbe_dev || NULL == dev) { |
| 598 | printk(KERN_ERR "Null device pointers.\n"); |
| 599 | return -ENODEV; |
| 600 | } |
| 601 | |
| 602 | if (vpbe_dev->initialized) |
| 603 | return 0; |
| 604 | |
| 605 | mutex_lock(&vpbe_dev->lock); |
| 606 | |
| 607 | if (strcmp(vpbe_dev->cfg->module_name, "dm644x-vpbe-display") != 0) { |
| 608 | /* We have dac clock available for platform */ |
| 609 | vpbe_dev->dac_clk = clk_get(vpbe_dev->pdev, "vpss_dac"); |
| 610 | if (IS_ERR(vpbe_dev->dac_clk)) { |
| 611 | ret = PTR_ERR(vpbe_dev->dac_clk); |
Peter Senna Tschudin | ac0fe5b | 2012-09-14 12:46:52 -0300 | [diff] [blame] | 612 | goto fail_mutex_unlock; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 613 | } |
Murali Karicheri | 1f5a5e6 | 2012-10-22 11:41:36 -0300 | [diff] [blame] | 614 | if (clk_prepare_enable(vpbe_dev->dac_clk)) { |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 615 | ret = -ENODEV; |
Peter Senna Tschudin | ac0fe5b | 2012-09-14 12:46:52 -0300 | [diff] [blame] | 616 | goto fail_mutex_unlock; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 617 | } |
| 618 | } |
| 619 | |
| 620 | /* first enable vpss clocks */ |
| 621 | vpss_enable_clock(VPSS_VPBE_CLOCK, 1); |
| 622 | |
| 623 | /* First register a v4l2 device */ |
| 624 | ret = v4l2_device_register(dev, &vpbe_dev->v4l2_dev); |
| 625 | if (ret) { |
| 626 | v4l2_err(dev->driver, |
| 627 | "Unable to register v4l2 device.\n"); |
Peter Senna Tschudin | ac0fe5b | 2012-09-14 12:46:52 -0300 | [diff] [blame] | 628 | goto fail_clk_put; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 629 | } |
| 630 | v4l2_info(&vpbe_dev->v4l2_dev, "vpbe v4l2 device registered\n"); |
| 631 | |
| 632 | err = bus_for_each_dev(&platform_bus_type, NULL, vpbe_dev, |
| 633 | platform_device_get); |
Wei Yongjun | 5d97046 | 2012-10-22 01:36:13 -0300 | [diff] [blame] | 634 | if (err < 0) { |
| 635 | ret = err; |
| 636 | goto fail_dev_unregister; |
| 637 | } |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 638 | |
| 639 | vpbe_dev->venc = venc_sub_dev_init(&vpbe_dev->v4l2_dev, |
| 640 | vpbe_dev->cfg->venc.module_name); |
| 641 | /* register venc sub device */ |
| 642 | if (vpbe_dev->venc == NULL) { |
| 643 | v4l2_err(&vpbe_dev->v4l2_dev, |
| 644 | "vpbe unable to init venc sub device\n"); |
| 645 | ret = -ENODEV; |
Peter Senna Tschudin | ac0fe5b | 2012-09-14 12:46:52 -0300 | [diff] [blame] | 646 | goto fail_dev_unregister; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 647 | } |
| 648 | /* initialize osd device */ |
| 649 | osd_device = vpbe_dev->osd_device; |
| 650 | |
| 651 | if (NULL != osd_device->ops.initialize) { |
| 652 | err = osd_device->ops.initialize(osd_device); |
| 653 | if (err) { |
| 654 | v4l2_err(&vpbe_dev->v4l2_dev, |
| 655 | "unable to initialize the OSD device"); |
| 656 | err = -ENOMEM; |
Peter Senna Tschudin | ac0fe5b | 2012-09-14 12:46:52 -0300 | [diff] [blame] | 657 | goto fail_dev_unregister; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 658 | } |
| 659 | } |
| 660 | |
| 661 | /* |
| 662 | * Register any external encoders that are configured. At index 0 we |
| 663 | * store venc sd index. |
| 664 | */ |
| 665 | num_encoders = vpbe_dev->cfg->num_ext_encoders + 1; |
| 666 | vpbe_dev->encoders = kmalloc( |
| 667 | sizeof(struct v4l2_subdev *)*num_encoders, |
| 668 | GFP_KERNEL); |
| 669 | if (NULL == vpbe_dev->encoders) { |
| 670 | v4l2_err(&vpbe_dev->v4l2_dev, |
| 671 | "unable to allocate memory for encoders sub devices"); |
| 672 | ret = -ENOMEM; |
Peter Senna Tschudin | ac0fe5b | 2012-09-14 12:46:52 -0300 | [diff] [blame] | 673 | goto fail_dev_unregister; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | i2c_adap = i2c_get_adapter(vpbe_dev->cfg->i2c_adapter_id); |
| 677 | for (i = 0; i < (vpbe_dev->cfg->num_ext_encoders + 1); i++) { |
| 678 | if (i == 0) { |
| 679 | /* venc is at index 0 */ |
| 680 | enc_subdev = &vpbe_dev->encoders[i]; |
| 681 | *enc_subdev = vpbe_dev->venc; |
| 682 | continue; |
| 683 | } |
| 684 | enc_info = &vpbe_dev->cfg->ext_encoders[i]; |
| 685 | if (enc_info->is_i2c) { |
| 686 | enc_subdev = &vpbe_dev->encoders[i]; |
| 687 | *enc_subdev = v4l2_i2c_new_subdev_board( |
| 688 | &vpbe_dev->v4l2_dev, i2c_adap, |
| 689 | &enc_info->board_info, NULL); |
| 690 | if (*enc_subdev) |
| 691 | v4l2_info(&vpbe_dev->v4l2_dev, |
| 692 | "v4l2 sub device %s registered\n", |
| 693 | enc_info->module_name); |
| 694 | else { |
| 695 | v4l2_err(&vpbe_dev->v4l2_dev, "encoder %s" |
| 696 | " failed to register", |
| 697 | enc_info->module_name); |
| 698 | ret = -ENODEV; |
Peter Senna Tschudin | ac0fe5b | 2012-09-14 12:46:52 -0300 | [diff] [blame] | 699 | goto fail_kfree_encoders; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 700 | } |
| 701 | } else |
| 702 | v4l2_warn(&vpbe_dev->v4l2_dev, "non-i2c encoders" |
| 703 | " currently not supported"); |
| 704 | } |
Manjunath Hadli | 9a7f95a | 2011-04-30 03:01:40 -0300 | [diff] [blame] | 705 | /* Add amplifier subdevice for dm365 */ |
| 706 | if ((strcmp(vpbe_dev->cfg->module_name, "dm365-vpbe-display") == 0) && |
| 707 | vpbe_dev->cfg->amp != NULL) { |
| 708 | amp_info = vpbe_dev->cfg->amp; |
| 709 | if (amp_info->is_i2c) { |
| 710 | vpbe_dev->amp = v4l2_i2c_new_subdev_board( |
| 711 | &vpbe_dev->v4l2_dev, i2c_adap, |
| 712 | &_info->board_info, NULL); |
| 713 | if (!vpbe_dev->amp) { |
| 714 | v4l2_err(&vpbe_dev->v4l2_dev, |
| 715 | "amplifier %s failed to register", |
| 716 | amp_info->module_name); |
| 717 | ret = -ENODEV; |
Peter Senna Tschudin | ac0fe5b | 2012-09-14 12:46:52 -0300 | [diff] [blame] | 718 | goto fail_kfree_encoders; |
Manjunath Hadli | 9a7f95a | 2011-04-30 03:01:40 -0300 | [diff] [blame] | 719 | } |
| 720 | v4l2_info(&vpbe_dev->v4l2_dev, |
| 721 | "v4l2 sub device %s registered\n", |
| 722 | amp_info->module_name); |
| 723 | } else { |
| 724 | vpbe_dev->amp = NULL; |
| 725 | v4l2_warn(&vpbe_dev->v4l2_dev, "non-i2c amplifiers" |
| 726 | " currently not supported"); |
| 727 | } |
| 728 | } else { |
| 729 | vpbe_dev->amp = NULL; |
| 730 | } |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 731 | |
| 732 | /* set the current encoder and output to that of venc by default */ |
| 733 | vpbe_dev->current_sd_index = 0; |
| 734 | vpbe_dev->current_out_index = 0; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 735 | |
| 736 | mutex_unlock(&vpbe_dev->lock); |
| 737 | |
| 738 | printk(KERN_NOTICE "Setting default output to %s\n", def_output); |
| 739 | ret = vpbe_set_default_output(vpbe_dev); |
| 740 | if (ret) { |
| 741 | v4l2_err(&vpbe_dev->v4l2_dev, "Failed to set default output %s", |
| 742 | def_output); |
| 743 | return ret; |
| 744 | } |
| 745 | |
| 746 | printk(KERN_NOTICE "Setting default mode to %s\n", def_mode); |
| 747 | ret = vpbe_set_default_mode(vpbe_dev); |
| 748 | if (ret) { |
| 749 | v4l2_err(&vpbe_dev->v4l2_dev, "Failed to set default mode %s", |
| 750 | def_mode); |
| 751 | return ret; |
| 752 | } |
| 753 | vpbe_dev->initialized = 1; |
| 754 | /* TBD handling of bootargs for default output and mode */ |
| 755 | return 0; |
| 756 | |
Peter Senna Tschudin | ac0fe5b | 2012-09-14 12:46:52 -0300 | [diff] [blame] | 757 | fail_kfree_encoders: |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 758 | kfree(vpbe_dev->encoders); |
Peter Senna Tschudin | ac0fe5b | 2012-09-14 12:46:52 -0300 | [diff] [blame] | 759 | fail_dev_unregister: |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 760 | v4l2_device_unregister(&vpbe_dev->v4l2_dev); |
Peter Senna Tschudin | ac0fe5b | 2012-09-14 12:46:52 -0300 | [diff] [blame] | 761 | fail_clk_put: |
Murali Karicheri | 1f5a5e6 | 2012-10-22 11:41:36 -0300 | [diff] [blame] | 762 | if (strcmp(vpbe_dev->cfg->module_name, "dm644x-vpbe-display") != 0) { |
| 763 | clk_disable_unprepare(vpbe_dev->dac_clk); |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 764 | clk_put(vpbe_dev->dac_clk); |
Murali Karicheri | 1f5a5e6 | 2012-10-22 11:41:36 -0300 | [diff] [blame] | 765 | } |
Peter Senna Tschudin | ac0fe5b | 2012-09-14 12:46:52 -0300 | [diff] [blame] | 766 | fail_mutex_unlock: |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 767 | mutex_unlock(&vpbe_dev->lock); |
| 768 | return ret; |
| 769 | } |
| 770 | |
| 771 | /** |
| 772 | * vpbe_deinitialize() - de-initialize the vpbe display controller |
| 773 | * @dev - Master and slave device ptr |
| 774 | * |
| 775 | * vpbe_master and slave frame buffer devices calls this to de-initialize |
| 776 | * the display controller. It is called when master and slave device |
| 777 | * driver modules are removed and no longer requires the display controller. |
| 778 | */ |
| 779 | static void vpbe_deinitialize(struct device *dev, struct vpbe_device *vpbe_dev) |
| 780 | { |
| 781 | v4l2_device_unregister(&vpbe_dev->v4l2_dev); |
Murali Karicheri | 1f5a5e6 | 2012-10-22 11:41:36 -0300 | [diff] [blame] | 782 | if (strcmp(vpbe_dev->cfg->module_name, "dm644x-vpbe-display") != 0) { |
| 783 | clk_disable_unprepare(vpbe_dev->dac_clk); |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 784 | clk_put(vpbe_dev->dac_clk); |
Murali Karicheri | 1f5a5e6 | 2012-10-22 11:41:36 -0300 | [diff] [blame] | 785 | } |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 786 | |
Manjunath Hadli | 9a7f95a | 2011-04-30 03:01:40 -0300 | [diff] [blame] | 787 | kfree(vpbe_dev->amp); |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 788 | kfree(vpbe_dev->encoders); |
| 789 | vpbe_dev->initialized = 0; |
| 790 | /* disable vpss clocks */ |
| 791 | vpss_enable_clock(VPSS_VPBE_CLOCK, 0); |
| 792 | } |
| 793 | |
| 794 | static struct vpbe_device_ops vpbe_dev_ops = { |
| 795 | .g_cropcap = vpbe_g_cropcap, |
| 796 | .enum_outputs = vpbe_enum_outputs, |
| 797 | .set_output = vpbe_set_output, |
| 798 | .get_output = vpbe_get_output, |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 799 | .s_dv_timings = vpbe_s_dv_timings, |
| 800 | .g_dv_timings = vpbe_g_dv_timings, |
| 801 | .enum_dv_timings = vpbe_enum_dv_timings, |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 802 | .s_std = vpbe_s_std, |
| 803 | .g_std = vpbe_g_std, |
| 804 | .initialize = vpbe_initialize, |
| 805 | .deinitialize = vpbe_deinitialize, |
| 806 | .get_mode_info = vpbe_get_current_mode_info, |
| 807 | .set_mode = vpbe_set_mode, |
| 808 | }; |
| 809 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 810 | static int vpbe_probe(struct platform_device *pdev) |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 811 | { |
| 812 | struct vpbe_device *vpbe_dev; |
| 813 | struct vpbe_config *cfg; |
| 814 | int ret = -EINVAL; |
| 815 | |
| 816 | if (pdev->dev.platform_data == NULL) { |
| 817 | v4l2_err(pdev->dev.driver, "No platform data\n"); |
| 818 | return -ENODEV; |
| 819 | } |
| 820 | cfg = pdev->dev.platform_data; |
| 821 | |
| 822 | if (!cfg->module_name[0] || |
| 823 | !cfg->osd.module_name[0] || |
| 824 | !cfg->venc.module_name[0]) { |
| 825 | v4l2_err(pdev->dev.driver, "vpbe display module names not" |
| 826 | " defined\n"); |
| 827 | return ret; |
| 828 | } |
| 829 | |
| 830 | vpbe_dev = kzalloc(sizeof(*vpbe_dev), GFP_KERNEL); |
| 831 | if (vpbe_dev == NULL) { |
| 832 | v4l2_err(pdev->dev.driver, "Unable to allocate memory" |
| 833 | " for vpbe_device\n"); |
| 834 | return -ENOMEM; |
| 835 | } |
| 836 | vpbe_dev->cfg = cfg; |
| 837 | vpbe_dev->ops = vpbe_dev_ops; |
| 838 | vpbe_dev->pdev = &pdev->dev; |
| 839 | |
| 840 | if (cfg->outputs->num_modes > 0) |
| 841 | vpbe_dev->current_timings = vpbe_dev->cfg->outputs[0].modes[0]; |
Julia Lawall | 75e5ac7 | 2011-12-23 13:39:32 -0300 | [diff] [blame] | 842 | else { |
| 843 | kfree(vpbe_dev); |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 844 | return -ENODEV; |
Julia Lawall | 75e5ac7 | 2011-12-23 13:39:32 -0300 | [diff] [blame] | 845 | } |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 846 | |
| 847 | /* set the driver data in platform device */ |
| 848 | platform_set_drvdata(pdev, vpbe_dev); |
| 849 | mutex_init(&vpbe_dev->lock); |
| 850 | |
| 851 | return 0; |
| 852 | } |
| 853 | |
| 854 | static int vpbe_remove(struct platform_device *device) |
| 855 | { |
| 856 | struct vpbe_device *vpbe_dev = platform_get_drvdata(device); |
| 857 | |
| 858 | kfree(vpbe_dev); |
| 859 | |
| 860 | return 0; |
| 861 | } |
| 862 | |
| 863 | static struct platform_driver vpbe_driver = { |
| 864 | .driver = { |
| 865 | .name = "vpbe_controller", |
| 866 | .owner = THIS_MODULE, |
| 867 | }, |
| 868 | .probe = vpbe_probe, |
| 869 | .remove = vpbe_remove, |
| 870 | }; |
| 871 | |
Axel Lin | 1d6629b | 2012-01-10 03:21:49 -0300 | [diff] [blame] | 872 | module_platform_driver(vpbe_driver); |