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