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 | { |
Markus Elfring | 1353875 | 2016-10-11 08:37:10 -0300 | [diff] [blame] | 110 | if (!cropcap) |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 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 | |
Markus Elfring | 1353875 | 2016-10-11 08:37:10 -0300 | [diff] [blame] | 152 | if (!mode) |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 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 | { |
Markus Elfring | 1353875 | 2016-10-11 08:37:10 -0300 | [diff] [blame] | 169 | if (!mode_info) |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 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; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 230 | int enc_out_index; |
| 231 | int sd_index; |
Markus Elfring | 630bf79 | 2016-10-12 05:16:23 -0300 | [diff] [blame] | 232 | int ret; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 233 | |
| 234 | if (index >= cfg->num_outputs) |
| 235 | return -EINVAL; |
| 236 | |
| 237 | mutex_lock(&vpbe_dev->lock); |
| 238 | |
| 239 | sd_index = vpbe_dev->current_sd_index; |
| 240 | enc_out_index = cfg->outputs[index].output.index; |
| 241 | /* |
| 242 | * Currently we switch the encoder based on output selected |
| 243 | * by the application. If media controller is implemented later |
| 244 | * there is will be an API added to setup_link between venc |
| 245 | * and external encoder. So in that case below comparison always |
| 246 | * match and encoder will not be switched. But if application |
| 247 | * chose not to use media controller, then this provides current |
| 248 | * way of switching encoder at the venc output. |
| 249 | */ |
| 250 | if (strcmp(curr_enc_info->module_name, |
| 251 | cfg->outputs[index].subdev_name)) { |
| 252 | /* Need to switch the encoder at the output */ |
| 253 | sd_index = vpbe_find_encoder_sd_index(cfg, index); |
| 254 | if (sd_index < 0) { |
| 255 | ret = -EINVAL; |
Markus Elfring | 15a7831 | 2016-10-12 05:10:19 -0300 | [diff] [blame] | 256 | goto unlock; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 257 | } |
| 258 | |
Markus Elfring | 2eaa68f | 2016-11-06 17:40:20 -0200 | [diff] [blame^] | 259 | ret = venc_device->setup_if_config(cfg->outputs[index].if_params); |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 260 | if (ret) |
Markus Elfring | 15a7831 | 2016-10-12 05:10:19 -0300 | [diff] [blame] | 261 | goto unlock; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | /* Set output at the encoder */ |
| 265 | ret = v4l2_subdev_call(vpbe_dev->encoders[sd_index], video, |
| 266 | s_routing, 0, enc_out_index, 0); |
| 267 | if (ret) |
Markus Elfring | 15a7831 | 2016-10-12 05:10:19 -0300 | [diff] [blame] | 268 | goto unlock; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 269 | |
| 270 | /* |
| 271 | * It is assumed that venc or extenal encoder will set a default |
| 272 | * mode in the sub device. For external encoder or LCD pannel output, |
| 273 | * we also need to set up the lcd port for the required mode. So setup |
| 274 | * the lcd port for the default mode that is configured in the board |
| 275 | * arch/arm/mach-davinci/board-dm355-evm.setup file for the external |
| 276 | * encoder. |
| 277 | */ |
| 278 | ret = vpbe_get_mode_info(vpbe_dev, |
Manjunath Hadli | 9a7f95a | 2011-04-30 03:01:40 -0300 | [diff] [blame] | 279 | cfg->outputs[index].default_mode, index); |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 280 | if (!ret) { |
| 281 | struct osd_state *osd_device = vpbe_dev->osd_device; |
| 282 | |
| 283 | osd_device->ops.set_left_margin(osd_device, |
| 284 | vpbe_dev->current_timings.left_margin); |
| 285 | osd_device->ops.set_top_margin(osd_device, |
| 286 | vpbe_dev->current_timings.upper_margin); |
| 287 | vpbe_dev->current_sd_index = sd_index; |
| 288 | vpbe_dev->current_out_index = index; |
| 289 | } |
Markus Elfring | 15a7831 | 2016-10-12 05:10:19 -0300 | [diff] [blame] | 290 | unlock: |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 291 | mutex_unlock(&vpbe_dev->lock); |
| 292 | return ret; |
| 293 | } |
| 294 | |
| 295 | static int vpbe_set_default_output(struct vpbe_device *vpbe_dev) |
| 296 | { |
| 297 | struct vpbe_config *cfg = vpbe_dev->cfg; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 298 | int i; |
| 299 | |
| 300 | for (i = 0; i < cfg->num_outputs; i++) { |
| 301 | if (!strcmp(def_output, |
| 302 | cfg->outputs[i].output.name)) { |
Markus Elfring | 837fdcf | 2016-10-12 04:54:26 -0300 | [diff] [blame] | 303 | int ret = vpbe_set_output(vpbe_dev, i); |
| 304 | |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 305 | if (!ret) |
| 306 | vpbe_dev->current_out_index = i; |
| 307 | return ret; |
| 308 | } |
| 309 | } |
Markus Elfring | 837fdcf | 2016-10-12 04:54:26 -0300 | [diff] [blame] | 310 | return 0; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | /** |
| 314 | * vpbe_get_output - Get output |
| 315 | * @vpbe_dev - vpbe device ptr |
| 316 | * |
| 317 | * return current vpbe output to the the index |
| 318 | */ |
| 319 | static unsigned int vpbe_get_output(struct vpbe_device *vpbe_dev) |
| 320 | { |
| 321 | return vpbe_dev->current_out_index; |
| 322 | } |
| 323 | |
| 324 | /** |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 325 | * vpbe_s_dv_timings - Set the given preset timings in the encoder |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 326 | * |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 327 | * Sets the timings if supported by the current encoder. Return the status. |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 328 | * 0 - success & -EINVAL on error |
| 329 | */ |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 330 | static int vpbe_s_dv_timings(struct vpbe_device *vpbe_dev, |
| 331 | struct v4l2_dv_timings *dv_timings) |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 332 | { |
| 333 | struct vpbe_config *cfg = vpbe_dev->cfg; |
| 334 | int out_index = vpbe_dev->current_out_index; |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 335 | struct vpbe_output *output = &cfg->outputs[out_index]; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 336 | int sd_index = vpbe_dev->current_sd_index; |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 337 | int ret, i; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 338 | |
| 339 | |
| 340 | if (!(cfg->outputs[out_index].output.capabilities & |
Lad, Prabhakar | e32087b | 2012-10-03 02:25:42 -0300 | [diff] [blame] | 341 | V4L2_OUT_CAP_DV_TIMINGS)) |
Prabhakar Lad | f9cc70b | 2014-10-12 17:40:45 -0300 | [diff] [blame] | 342 | return -ENODATA; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 343 | |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 344 | for (i = 0; i < output->num_modes; i++) { |
Hans Verkuil | ef2d41b | 2013-02-15 15:06:28 -0300 | [diff] [blame] | 345 | if (output->modes[i].timings_type == VPBE_ENC_DV_TIMINGS && |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 346 | !memcmp(&output->modes[i].dv_timings, |
| 347 | dv_timings, sizeof(*dv_timings))) |
| 348 | break; |
| 349 | } |
| 350 | if (i >= output->num_modes) |
| 351 | return -EINVAL; |
| 352 | vpbe_dev->current_timings = output->modes[i]; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 353 | mutex_lock(&vpbe_dev->lock); |
| 354 | |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 355 | ret = v4l2_subdev_call(vpbe_dev->encoders[sd_index], video, |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 356 | s_dv_timings, dv_timings); |
Markus Elfring | 1353875 | 2016-10-11 08:37:10 -0300 | [diff] [blame] | 357 | if (!ret && vpbe_dev->amp) { |
Manjunath Hadli | 9a7f95a | 2011-04-30 03:01:40 -0300 | [diff] [blame] | 358 | /* Call amplifier subdevice */ |
| 359 | ret = v4l2_subdev_call(vpbe_dev->amp, video, |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 360 | s_dv_timings, dv_timings); |
Manjunath Hadli | 9a7f95a | 2011-04-30 03:01:40 -0300 | [diff] [blame] | 361 | } |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 362 | /* set the lcd controller output for the given mode */ |
| 363 | if (!ret) { |
| 364 | struct osd_state *osd_device = vpbe_dev->osd_device; |
| 365 | |
| 366 | osd_device->ops.set_left_margin(osd_device, |
| 367 | vpbe_dev->current_timings.left_margin); |
| 368 | osd_device->ops.set_top_margin(osd_device, |
| 369 | vpbe_dev->current_timings.upper_margin); |
| 370 | } |
| 371 | mutex_unlock(&vpbe_dev->lock); |
| 372 | |
| 373 | return ret; |
| 374 | } |
| 375 | |
| 376 | /** |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 377 | * vpbe_g_dv_timings - Get the timings in the current encoder |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 378 | * |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 379 | * Get the timings in the current encoder. Return the status. 0 - success |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 380 | * -EINVAL on error |
| 381 | */ |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 382 | static int vpbe_g_dv_timings(struct vpbe_device *vpbe_dev, |
| 383 | struct v4l2_dv_timings *dv_timings) |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 384 | { |
Prabhakar Lad | f9cc70b | 2014-10-12 17:40:45 -0300 | [diff] [blame] | 385 | struct vpbe_config *cfg = vpbe_dev->cfg; |
| 386 | int out_index = vpbe_dev->current_out_index; |
| 387 | |
| 388 | if (!(cfg->outputs[out_index].output.capabilities & |
| 389 | V4L2_OUT_CAP_DV_TIMINGS)) |
| 390 | return -ENODATA; |
| 391 | |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 392 | if (vpbe_dev->current_timings.timings_type & |
Hans Verkuil | ef2d41b | 2013-02-15 15:06:28 -0300 | [diff] [blame] | 393 | VPBE_ENC_DV_TIMINGS) { |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 394 | *dv_timings = vpbe_dev->current_timings.dv_timings; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 395 | return 0; |
| 396 | } |
| 397 | |
| 398 | return -EINVAL; |
| 399 | } |
| 400 | |
| 401 | /** |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 402 | * vpbe_enum_dv_timings - Enumerate the dv timings in the current encoder |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 403 | * |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 404 | * Get the timings in the current encoder. Return the status. 0 - success |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 405 | * -EINVAL on error |
| 406 | */ |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 407 | static int vpbe_enum_dv_timings(struct vpbe_device *vpbe_dev, |
| 408 | struct v4l2_enum_dv_timings *timings) |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 409 | { |
| 410 | struct vpbe_config *cfg = vpbe_dev->cfg; |
| 411 | int out_index = vpbe_dev->current_out_index; |
| 412 | struct vpbe_output *output = &cfg->outputs[out_index]; |
| 413 | int j = 0; |
| 414 | int i; |
| 415 | |
Lad, Prabhakar | e32087b | 2012-10-03 02:25:42 -0300 | [diff] [blame] | 416 | if (!(output->output.capabilities & V4L2_OUT_CAP_DV_TIMINGS)) |
Prabhakar Lad | f9cc70b | 2014-10-12 17:40:45 -0300 | [diff] [blame] | 417 | return -ENODATA; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 418 | |
| 419 | for (i = 0; i < output->num_modes; i++) { |
Hans Verkuil | ef2d41b | 2013-02-15 15:06:28 -0300 | [diff] [blame] | 420 | if (output->modes[i].timings_type == VPBE_ENC_DV_TIMINGS) { |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 421 | if (j == timings->index) |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 422 | break; |
| 423 | j++; |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | if (i == output->num_modes) |
| 428 | return -EINVAL; |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 429 | timings->timings = output->modes[i].dv_timings; |
| 430 | return 0; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | /** |
| 434 | * vpbe_s_std - Set the given standard in the encoder |
| 435 | * |
| 436 | * Sets the standard if supported by the current encoder. Return the status. |
| 437 | * 0 - success & -EINVAL on error |
| 438 | */ |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 439 | 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] | 440 | { |
| 441 | struct vpbe_config *cfg = vpbe_dev->cfg; |
| 442 | int out_index = vpbe_dev->current_out_index; |
| 443 | int sd_index = vpbe_dev->current_sd_index; |
| 444 | int ret; |
| 445 | |
| 446 | if (!(cfg->outputs[out_index].output.capabilities & |
| 447 | V4L2_OUT_CAP_STD)) |
Prabhakar Lad | f9cc70b | 2014-10-12 17:40:45 -0300 | [diff] [blame] | 448 | return -ENODATA; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 449 | |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 450 | ret = vpbe_get_std_info(vpbe_dev, std_id); |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 451 | if (ret) |
| 452 | return ret; |
| 453 | |
| 454 | mutex_lock(&vpbe_dev->lock); |
| 455 | |
| 456 | ret = v4l2_subdev_call(vpbe_dev->encoders[sd_index], video, |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 457 | s_std_output, std_id); |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 458 | /* set the lcd controller output for the given mode */ |
| 459 | if (!ret) { |
| 460 | struct osd_state *osd_device = vpbe_dev->osd_device; |
| 461 | |
| 462 | osd_device->ops.set_left_margin(osd_device, |
| 463 | vpbe_dev->current_timings.left_margin); |
| 464 | osd_device->ops.set_top_margin(osd_device, |
| 465 | vpbe_dev->current_timings.upper_margin); |
| 466 | } |
| 467 | mutex_unlock(&vpbe_dev->lock); |
| 468 | |
| 469 | return ret; |
| 470 | } |
| 471 | |
| 472 | /** |
| 473 | * vpbe_g_std - Get the standard in the current encoder |
| 474 | * |
| 475 | * Get the standard in the current encoder. Return the status. 0 - success |
| 476 | * -EINVAL on error |
| 477 | */ |
| 478 | static int vpbe_g_std(struct vpbe_device *vpbe_dev, v4l2_std_id *std_id) |
| 479 | { |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 480 | struct vpbe_enc_mode_info *cur_timings = &vpbe_dev->current_timings; |
Prabhakar Lad | f9cc70b | 2014-10-12 17:40:45 -0300 | [diff] [blame] | 481 | struct vpbe_config *cfg = vpbe_dev->cfg; |
| 482 | int out_index = vpbe_dev->current_out_index; |
| 483 | |
| 484 | if (!(cfg->outputs[out_index].output.capabilities & V4L2_OUT_CAP_STD)) |
| 485 | return -ENODATA; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 486 | |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 487 | if (cur_timings->timings_type & VPBE_ENC_STD) { |
| 488 | *std_id = cur_timings->std_id; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 489 | return 0; |
| 490 | } |
| 491 | |
| 492 | return -EINVAL; |
| 493 | } |
| 494 | |
| 495 | /** |
| 496 | * vpbe_set_mode - Set mode in the current encoder using mode info |
| 497 | * |
| 498 | * Use the mode string to decide what timings to set in the encoder |
| 499 | * This is typically useful when fbset command is used to change the current |
| 500 | * timings by specifying a string to indicate the timings. |
| 501 | */ |
| 502 | static int vpbe_set_mode(struct vpbe_device *vpbe_dev, |
| 503 | struct vpbe_enc_mode_info *mode_info) |
| 504 | { |
| 505 | struct vpbe_enc_mode_info *preset_mode = NULL; |
| 506 | struct vpbe_config *cfg = vpbe_dev->cfg; |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 507 | struct v4l2_dv_timings dv_timings; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 508 | struct osd_state *osd_device; |
| 509 | int out_index = vpbe_dev->current_out_index; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 510 | int i; |
| 511 | |
Markus Elfring | 1353875 | 2016-10-11 08:37:10 -0300 | [diff] [blame] | 512 | if (!mode_info || !mode_info->name) |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 513 | return -EINVAL; |
| 514 | |
| 515 | for (i = 0; i < cfg->outputs[out_index].num_modes; i++) { |
| 516 | if (!strcmp(mode_info->name, |
| 517 | cfg->outputs[out_index].modes[i].name)) { |
| 518 | preset_mode = &cfg->outputs[out_index].modes[i]; |
| 519 | /* |
| 520 | * it may be one of the 3 timings type. Check and |
| 521 | * invoke right API |
| 522 | */ |
| 523 | if (preset_mode->timings_type & VPBE_ENC_STD) |
| 524 | return vpbe_s_std(vpbe_dev, |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 525 | preset_mode->std_id); |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 526 | if (preset_mode->timings_type & |
Hans Verkuil | ef2d41b | 2013-02-15 15:06:28 -0300 | [diff] [blame] | 527 | VPBE_ENC_DV_TIMINGS) { |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 528 | dv_timings = |
| 529 | preset_mode->dv_timings; |
| 530 | return vpbe_s_dv_timings(vpbe_dev, &dv_timings); |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 531 | } |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | /* Only custom timing should reach here */ |
Markus Elfring | 1353875 | 2016-10-11 08:37:10 -0300 | [diff] [blame] | 536 | if (!preset_mode) |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 537 | return -EINVAL; |
| 538 | |
| 539 | mutex_lock(&vpbe_dev->lock); |
| 540 | |
| 541 | osd_device = vpbe_dev->osd_device; |
| 542 | vpbe_dev->current_timings = *preset_mode; |
| 543 | osd_device->ops.set_left_margin(osd_device, |
| 544 | vpbe_dev->current_timings.left_margin); |
| 545 | osd_device->ops.set_top_margin(osd_device, |
| 546 | vpbe_dev->current_timings.upper_margin); |
| 547 | |
| 548 | mutex_unlock(&vpbe_dev->lock); |
Markus Elfring | ca7948aa | 2016-10-12 04:51:29 -0300 | [diff] [blame] | 549 | return 0; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | static int vpbe_set_default_mode(struct vpbe_device *vpbe_dev) |
| 553 | { |
| 554 | int ret; |
| 555 | |
| 556 | ret = vpbe_get_std_info_by_name(vpbe_dev, def_mode); |
| 557 | if (ret) |
| 558 | return ret; |
| 559 | |
| 560 | /* set the default mode in the encoder */ |
| 561 | return vpbe_set_mode(vpbe_dev, &vpbe_dev->current_timings); |
| 562 | } |
| 563 | |
| 564 | static int platform_device_get(struct device *dev, void *data) |
| 565 | { |
| 566 | struct platform_device *pdev = to_platform_device(dev); |
| 567 | struct vpbe_device *vpbe_dev = data; |
| 568 | |
Markus Elfring | 1353875 | 2016-10-11 08:37:10 -0300 | [diff] [blame] | 569 | if (strstr(pdev->name, "vpbe-osd")) |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 570 | vpbe_dev->osd_device = platform_get_drvdata(pdev); |
Markus Elfring | 1353875 | 2016-10-11 08:37:10 -0300 | [diff] [blame] | 571 | if (strstr(pdev->name, "vpbe-venc")) |
Manjunath Hadli | 9a7f95a | 2011-04-30 03:01:40 -0300 | [diff] [blame] | 572 | vpbe_dev->venc_device = dev_get_platdata(&pdev->dev); |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 573 | |
| 574 | return 0; |
| 575 | } |
| 576 | |
| 577 | /** |
| 578 | * vpbe_initialize() - Initialize the vpbe display controller |
| 579 | * @vpbe_dev - vpbe device ptr |
| 580 | * |
| 581 | * Master frame buffer device drivers calls this to initialize vpbe |
| 582 | * display controller. This will then registers v4l2 device and the sub |
| 583 | * devices and sets a current encoder sub device for display. v4l2 display |
| 584 | * device driver is the master and frame buffer display device driver is |
| 585 | * the slave. Frame buffer display driver checks the initialized during |
| 586 | * probe and exit if not initialized. Returns status. |
| 587 | */ |
| 588 | static int vpbe_initialize(struct device *dev, struct vpbe_device *vpbe_dev) |
| 589 | { |
| 590 | struct encoder_config_info *enc_info; |
Manjunath Hadli | 9a7f95a | 2011-04-30 03:01:40 -0300 | [diff] [blame] | 591 | struct amp_config_info *amp_info; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 592 | struct v4l2_subdev **enc_subdev; |
| 593 | struct osd_state *osd_device; |
| 594 | struct i2c_adapter *i2c_adap; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 595 | int num_encoders; |
| 596 | int ret = 0; |
| 597 | int err; |
| 598 | int i; |
| 599 | |
| 600 | /* |
| 601 | * v4l2 abd FBDev frame buffer devices will get the vpbe_dev pointer |
| 602 | * from the platform device by iteration of platform drivers and |
| 603 | * matching with device name |
| 604 | */ |
Markus Elfring | 1353875 | 2016-10-11 08:37:10 -0300 | [diff] [blame] | 605 | if (!vpbe_dev || !dev) { |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 606 | printk(KERN_ERR "Null device pointers.\n"); |
| 607 | return -ENODEV; |
| 608 | } |
| 609 | |
| 610 | if (vpbe_dev->initialized) |
| 611 | return 0; |
| 612 | |
| 613 | mutex_lock(&vpbe_dev->lock); |
| 614 | |
| 615 | if (strcmp(vpbe_dev->cfg->module_name, "dm644x-vpbe-display") != 0) { |
| 616 | /* We have dac clock available for platform */ |
| 617 | vpbe_dev->dac_clk = clk_get(vpbe_dev->pdev, "vpss_dac"); |
| 618 | if (IS_ERR(vpbe_dev->dac_clk)) { |
| 619 | ret = PTR_ERR(vpbe_dev->dac_clk); |
Peter Senna Tschudin | ac0fe5b | 2012-09-14 12:46:52 -0300 | [diff] [blame] | 620 | goto fail_mutex_unlock; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 621 | } |
Murali Karicheri | 1f5a5e6 | 2012-10-22 11:41:36 -0300 | [diff] [blame] | 622 | if (clk_prepare_enable(vpbe_dev->dac_clk)) { |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 623 | ret = -ENODEV; |
Sudip Mukherjee | 47efeb5 | 2014-11-06 10:04:27 -0300 | [diff] [blame] | 624 | clk_put(vpbe_dev->dac_clk); |
Peter Senna Tschudin | ac0fe5b | 2012-09-14 12:46:52 -0300 | [diff] [blame] | 625 | goto fail_mutex_unlock; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 626 | } |
| 627 | } |
| 628 | |
| 629 | /* first enable vpss clocks */ |
| 630 | vpss_enable_clock(VPSS_VPBE_CLOCK, 1); |
| 631 | |
| 632 | /* First register a v4l2 device */ |
| 633 | ret = v4l2_device_register(dev, &vpbe_dev->v4l2_dev); |
| 634 | if (ret) { |
| 635 | v4l2_err(dev->driver, |
| 636 | "Unable to register v4l2 device.\n"); |
Peter Senna Tschudin | ac0fe5b | 2012-09-14 12:46:52 -0300 | [diff] [blame] | 637 | goto fail_clk_put; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 638 | } |
| 639 | v4l2_info(&vpbe_dev->v4l2_dev, "vpbe v4l2 device registered\n"); |
| 640 | |
| 641 | err = bus_for_each_dev(&platform_bus_type, NULL, vpbe_dev, |
| 642 | platform_device_get); |
Wei Yongjun | 5d97046a3 | 2012-10-22 01:36:13 -0300 | [diff] [blame] | 643 | if (err < 0) { |
| 644 | ret = err; |
| 645 | goto fail_dev_unregister; |
| 646 | } |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 647 | |
| 648 | vpbe_dev->venc = venc_sub_dev_init(&vpbe_dev->v4l2_dev, |
| 649 | vpbe_dev->cfg->venc.module_name); |
| 650 | /* register venc sub device */ |
Markus Elfring | 1353875 | 2016-10-11 08:37:10 -0300 | [diff] [blame] | 651 | if (!vpbe_dev->venc) { |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 652 | v4l2_err(&vpbe_dev->v4l2_dev, |
| 653 | "vpbe unable to init venc sub device\n"); |
| 654 | ret = -ENODEV; |
Peter Senna Tschudin | ac0fe5b | 2012-09-14 12:46:52 -0300 | [diff] [blame] | 655 | goto fail_dev_unregister; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 656 | } |
| 657 | /* initialize osd device */ |
| 658 | osd_device = vpbe_dev->osd_device; |
Markus Elfring | 1353875 | 2016-10-11 08:37:10 -0300 | [diff] [blame] | 659 | if (osd_device->ops.initialize) { |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 660 | err = osd_device->ops.initialize(osd_device); |
| 661 | if (err) { |
| 662 | v4l2_err(&vpbe_dev->v4l2_dev, |
| 663 | "unable to initialize the OSD device"); |
| 664 | err = -ENOMEM; |
Peter Senna Tschudin | ac0fe5b | 2012-09-14 12:46:52 -0300 | [diff] [blame] | 665 | goto fail_dev_unregister; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 666 | } |
| 667 | } |
| 668 | |
| 669 | /* |
| 670 | * Register any external encoders that are configured. At index 0 we |
| 671 | * store venc sd index. |
| 672 | */ |
| 673 | num_encoders = vpbe_dev->cfg->num_ext_encoders + 1; |
Markus Elfring | f42afd2 | 2016-10-11 04:40:41 -0300 | [diff] [blame] | 674 | vpbe_dev->encoders = kmalloc_array(num_encoders, |
| 675 | sizeof(*vpbe_dev->encoders), |
| 676 | GFP_KERNEL); |
Markus Elfring | 1353875 | 2016-10-11 08:37:10 -0300 | [diff] [blame] | 677 | if (!vpbe_dev->encoders) { |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 678 | ret = -ENOMEM; |
Peter Senna Tschudin | ac0fe5b | 2012-09-14 12:46:52 -0300 | [diff] [blame] | 679 | goto fail_dev_unregister; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | i2c_adap = i2c_get_adapter(vpbe_dev->cfg->i2c_adapter_id); |
| 683 | for (i = 0; i < (vpbe_dev->cfg->num_ext_encoders + 1); i++) { |
| 684 | if (i == 0) { |
| 685 | /* venc is at index 0 */ |
| 686 | enc_subdev = &vpbe_dev->encoders[i]; |
| 687 | *enc_subdev = vpbe_dev->venc; |
| 688 | continue; |
| 689 | } |
| 690 | enc_info = &vpbe_dev->cfg->ext_encoders[i]; |
| 691 | if (enc_info->is_i2c) { |
| 692 | enc_subdev = &vpbe_dev->encoders[i]; |
| 693 | *enc_subdev = v4l2_i2c_new_subdev_board( |
| 694 | &vpbe_dev->v4l2_dev, i2c_adap, |
| 695 | &enc_info->board_info, NULL); |
| 696 | if (*enc_subdev) |
| 697 | v4l2_info(&vpbe_dev->v4l2_dev, |
| 698 | "v4l2 sub device %s registered\n", |
| 699 | enc_info->module_name); |
| 700 | else { |
Mauro Carvalho Chehab | ded026e | 2016-10-18 17:44:08 -0200 | [diff] [blame] | 701 | v4l2_err(&vpbe_dev->v4l2_dev, "encoder %s failed to register", |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 702 | enc_info->module_name); |
| 703 | ret = -ENODEV; |
Peter Senna Tschudin | ac0fe5b | 2012-09-14 12:46:52 -0300 | [diff] [blame] | 704 | goto fail_kfree_encoders; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 705 | } |
| 706 | } else |
Mauro Carvalho Chehab | ded026e | 2016-10-18 17:44:08 -0200 | [diff] [blame] | 707 | v4l2_warn(&vpbe_dev->v4l2_dev, "non-i2c encoders currently not supported"); |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 708 | } |
Manjunath Hadli | 9a7f95a | 2011-04-30 03:01:40 -0300 | [diff] [blame] | 709 | /* Add amplifier subdevice for dm365 */ |
| 710 | if ((strcmp(vpbe_dev->cfg->module_name, "dm365-vpbe-display") == 0) && |
Markus Elfring | 1353875 | 2016-10-11 08:37:10 -0300 | [diff] [blame] | 711 | vpbe_dev->cfg->amp) { |
Manjunath Hadli | 9a7f95a | 2011-04-30 03:01:40 -0300 | [diff] [blame] | 712 | amp_info = vpbe_dev->cfg->amp; |
| 713 | if (amp_info->is_i2c) { |
| 714 | vpbe_dev->amp = v4l2_i2c_new_subdev_board( |
| 715 | &vpbe_dev->v4l2_dev, i2c_adap, |
| 716 | &_info->board_info, NULL); |
| 717 | if (!vpbe_dev->amp) { |
| 718 | v4l2_err(&vpbe_dev->v4l2_dev, |
| 719 | "amplifier %s failed to register", |
| 720 | amp_info->module_name); |
| 721 | ret = -ENODEV; |
Peter Senna Tschudin | ac0fe5b | 2012-09-14 12:46:52 -0300 | [diff] [blame] | 722 | goto fail_kfree_encoders; |
Manjunath Hadli | 9a7f95a | 2011-04-30 03:01:40 -0300 | [diff] [blame] | 723 | } |
| 724 | v4l2_info(&vpbe_dev->v4l2_dev, |
| 725 | "v4l2 sub device %s registered\n", |
| 726 | amp_info->module_name); |
| 727 | } else { |
| 728 | vpbe_dev->amp = NULL; |
Mauro Carvalho Chehab | ded026e | 2016-10-18 17:44:08 -0200 | [diff] [blame] | 729 | v4l2_warn(&vpbe_dev->v4l2_dev, "non-i2c amplifiers currently not supported"); |
Manjunath Hadli | 9a7f95a | 2011-04-30 03:01:40 -0300 | [diff] [blame] | 730 | } |
| 731 | } else { |
| 732 | vpbe_dev->amp = NULL; |
| 733 | } |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 734 | |
| 735 | /* set the current encoder and output to that of venc by default */ |
| 736 | vpbe_dev->current_sd_index = 0; |
| 737 | vpbe_dev->current_out_index = 0; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 738 | |
| 739 | mutex_unlock(&vpbe_dev->lock); |
| 740 | |
| 741 | printk(KERN_NOTICE "Setting default output to %s\n", def_output); |
| 742 | ret = vpbe_set_default_output(vpbe_dev); |
| 743 | if (ret) { |
| 744 | v4l2_err(&vpbe_dev->v4l2_dev, "Failed to set default output %s", |
| 745 | def_output); |
| 746 | return ret; |
| 747 | } |
| 748 | |
| 749 | printk(KERN_NOTICE "Setting default mode to %s\n", def_mode); |
| 750 | ret = vpbe_set_default_mode(vpbe_dev); |
| 751 | if (ret) { |
| 752 | v4l2_err(&vpbe_dev->v4l2_dev, "Failed to set default mode %s", |
| 753 | def_mode); |
| 754 | return ret; |
| 755 | } |
| 756 | vpbe_dev->initialized = 1; |
| 757 | /* TBD handling of bootargs for default output and mode */ |
| 758 | return 0; |
| 759 | |
Peter Senna Tschudin | ac0fe5b | 2012-09-14 12:46:52 -0300 | [diff] [blame] | 760 | fail_kfree_encoders: |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 761 | kfree(vpbe_dev->encoders); |
Peter Senna Tschudin | ac0fe5b | 2012-09-14 12:46:52 -0300 | [diff] [blame] | 762 | fail_dev_unregister: |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 763 | v4l2_device_unregister(&vpbe_dev->v4l2_dev); |
Peter Senna Tschudin | ac0fe5b | 2012-09-14 12:46:52 -0300 | [diff] [blame] | 764 | fail_clk_put: |
Murali Karicheri | 1f5a5e6 | 2012-10-22 11:41:36 -0300 | [diff] [blame] | 765 | if (strcmp(vpbe_dev->cfg->module_name, "dm644x-vpbe-display") != 0) { |
| 766 | clk_disable_unprepare(vpbe_dev->dac_clk); |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 767 | clk_put(vpbe_dev->dac_clk); |
Murali Karicheri | 1f5a5e6 | 2012-10-22 11:41:36 -0300 | [diff] [blame] | 768 | } |
Peter Senna Tschudin | ac0fe5b | 2012-09-14 12:46:52 -0300 | [diff] [blame] | 769 | fail_mutex_unlock: |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 770 | mutex_unlock(&vpbe_dev->lock); |
| 771 | return ret; |
| 772 | } |
| 773 | |
| 774 | /** |
| 775 | * vpbe_deinitialize() - de-initialize the vpbe display controller |
| 776 | * @dev - Master and slave device ptr |
| 777 | * |
| 778 | * vpbe_master and slave frame buffer devices calls this to de-initialize |
| 779 | * the display controller. It is called when master and slave device |
| 780 | * driver modules are removed and no longer requires the display controller. |
| 781 | */ |
| 782 | static void vpbe_deinitialize(struct device *dev, struct vpbe_device *vpbe_dev) |
| 783 | { |
| 784 | v4l2_device_unregister(&vpbe_dev->v4l2_dev); |
Murali Karicheri | 1f5a5e6 | 2012-10-22 11:41:36 -0300 | [diff] [blame] | 785 | if (strcmp(vpbe_dev->cfg->module_name, "dm644x-vpbe-display") != 0) { |
| 786 | clk_disable_unprepare(vpbe_dev->dac_clk); |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 787 | clk_put(vpbe_dev->dac_clk); |
Murali Karicheri | 1f5a5e6 | 2012-10-22 11:41:36 -0300 | [diff] [blame] | 788 | } |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 789 | |
Manjunath Hadli | 9a7f95a | 2011-04-30 03:01:40 -0300 | [diff] [blame] | 790 | kfree(vpbe_dev->amp); |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 791 | kfree(vpbe_dev->encoders); |
| 792 | vpbe_dev->initialized = 0; |
| 793 | /* disable vpss clocks */ |
| 794 | vpss_enable_clock(VPSS_VPBE_CLOCK, 0); |
| 795 | } |
| 796 | |
| 797 | static struct vpbe_device_ops vpbe_dev_ops = { |
| 798 | .g_cropcap = vpbe_g_cropcap, |
| 799 | .enum_outputs = vpbe_enum_outputs, |
| 800 | .set_output = vpbe_set_output, |
| 801 | .get_output = vpbe_get_output, |
Hans Verkuil | 3686408 | 2012-10-01 11:39:46 -0300 | [diff] [blame] | 802 | .s_dv_timings = vpbe_s_dv_timings, |
| 803 | .g_dv_timings = vpbe_g_dv_timings, |
| 804 | .enum_dv_timings = vpbe_enum_dv_timings, |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 805 | .s_std = vpbe_s_std, |
| 806 | .g_std = vpbe_g_std, |
| 807 | .initialize = vpbe_initialize, |
| 808 | .deinitialize = vpbe_deinitialize, |
| 809 | .get_mode_info = vpbe_get_current_mode_info, |
| 810 | .set_mode = vpbe_set_mode, |
| 811 | }; |
| 812 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 813 | static int vpbe_probe(struct platform_device *pdev) |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 814 | { |
| 815 | struct vpbe_device *vpbe_dev; |
| 816 | struct vpbe_config *cfg; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 817 | |
Markus Elfring | 1353875 | 2016-10-11 08:37:10 -0300 | [diff] [blame] | 818 | if (!pdev->dev.platform_data) { |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 819 | v4l2_err(pdev->dev.driver, "No platform data\n"); |
| 820 | return -ENODEV; |
| 821 | } |
| 822 | cfg = pdev->dev.platform_data; |
| 823 | |
| 824 | if (!cfg->module_name[0] || |
| 825 | !cfg->osd.module_name[0] || |
| 826 | !cfg->venc.module_name[0]) { |
Mauro Carvalho Chehab | ded026e | 2016-10-18 17:44:08 -0200 | [diff] [blame] | 827 | v4l2_err(pdev->dev.driver, "vpbe display module names not defined\n"); |
Markus Elfring | 9d2fe9a | 2016-10-11 08:43:25 -0300 | [diff] [blame] | 828 | return -EINVAL; |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | vpbe_dev = kzalloc(sizeof(*vpbe_dev), GFP_KERNEL); |
Markus Elfring | 2ac0989 | 2016-10-11 04:56:13 -0300 | [diff] [blame] | 832 | if (!vpbe_dev) |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 833 | return -ENOMEM; |
Markus Elfring | 2ac0989 | 2016-10-11 04:56:13 -0300 | [diff] [blame] | 834 | |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 835 | vpbe_dev->cfg = cfg; |
| 836 | vpbe_dev->ops = vpbe_dev_ops; |
| 837 | vpbe_dev->pdev = &pdev->dev; |
| 838 | |
| 839 | if (cfg->outputs->num_modes > 0) |
| 840 | vpbe_dev->current_timings = vpbe_dev->cfg->outputs[0].modes[0]; |
Julia Lawall | 75e5ac7 | 2011-12-23 13:39:32 -0300 | [diff] [blame] | 841 | else { |
| 842 | kfree(vpbe_dev); |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 843 | return -ENODEV; |
Julia Lawall | 75e5ac7 | 2011-12-23 13:39:32 -0300 | [diff] [blame] | 844 | } |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 845 | |
| 846 | /* set the driver data in platform device */ |
| 847 | platform_set_drvdata(pdev, vpbe_dev); |
| 848 | mutex_init(&vpbe_dev->lock); |
| 849 | |
| 850 | return 0; |
| 851 | } |
| 852 | |
| 853 | static int vpbe_remove(struct platform_device *device) |
| 854 | { |
| 855 | struct vpbe_device *vpbe_dev = platform_get_drvdata(device); |
| 856 | |
| 857 | kfree(vpbe_dev); |
| 858 | |
| 859 | return 0; |
| 860 | } |
| 861 | |
| 862 | static struct platform_driver vpbe_driver = { |
| 863 | .driver = { |
| 864 | .name = "vpbe_controller", |
Manjunath Hadli | 66715cd | 2011-06-17 04:01:32 -0300 | [diff] [blame] | 865 | }, |
| 866 | .probe = vpbe_probe, |
| 867 | .remove = vpbe_remove, |
| 868 | }; |
| 869 | |
Axel Lin | 1d6629b | 2012-01-10 03:21:49 -0300 | [diff] [blame] | 870 | module_platform_driver(vpbe_driver); |