Linux 4.16.11
[linux/fpc-iii.git] / drivers / media / platform / davinci / vpbe.c
blob7f64625625790577ec945459355bc350ba0b4132
1 /*
2 * Copyright (C) 2010 Texas Instruments Inc
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.
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.
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>
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>
33 #define VPBE_DEFAULT_OUTPUT "Composite"
34 #define VPBE_DEFAULT_MODE "ntsc"
36 static char *def_output = VPBE_DEFAULT_OUTPUT;
37 static char *def_mode = VPBE_DEFAULT_MODE;
38 static int debug;
40 module_param(def_output, charp, S_IRUGO);
41 module_param(def_mode, charp, S_IRUGO);
42 module_param(debug, int, 0644);
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");
48 MODULE_DESCRIPTION("TI DMXXX VPBE Display controller");
49 MODULE_LICENSE("GPL");
50 MODULE_AUTHOR("Texas Instruments");
52 /**
53 * vpbe_current_encoder_info - Get config info for current encoder
54 * @vpbe_dev - vpbe device ptr
56 * Return ptr to current encoder config info
58 static struct encoder_config_info*
59 vpbe_current_encoder_info(struct vpbe_device *vpbe_dev)
61 struct vpbe_config *cfg = vpbe_dev->cfg;
62 int index = vpbe_dev->current_sd_index;
64 return ((index == 0) ? &cfg->venc :
65 &cfg->ext_encoders[index-1]);
68 /**
69 * vpbe_find_encoder_sd_index - Given a name find encoder sd index
71 * @vpbe_config - ptr to vpbe cfg
72 * @output_index - index used by application
74 * Return sd index of the encoder
76 static int vpbe_find_encoder_sd_index(struct vpbe_config *cfg,
77 int index)
79 char *encoder_name = cfg->outputs[index].subdev_name;
80 int i;
82 /* Venc is always first */
83 if (!strcmp(encoder_name, cfg->venc.module_name))
84 return 0;
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;
92 return -EINVAL;
95 /**
96 * vpbe_g_cropcap - Get crop capabilities of the display
97 * @vpbe_dev - vpbe device ptr
98 * @cropcap - cropcap is a ptr to struct v4l2_cropcap
100 * Update the crop capabilities in crop cap for current
101 * mode
103 static int vpbe_g_cropcap(struct vpbe_device *vpbe_dev,
104 struct v4l2_cropcap *cropcap)
106 if (!cropcap)
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;
114 return 0;
118 * vpbe_enum_outputs - enumerate outputs
119 * @vpbe_dev - vpbe device ptr
120 * @output - ptr to v4l2_output structure
122 * Enumerates the outputs available at the vpbe display
123 * returns the status, -EINVAL if end of output list
125 static int vpbe_enum_outputs(struct vpbe_device *vpbe_dev,
126 struct v4l2_output *output)
128 struct vpbe_config *cfg = vpbe_dev->cfg;
129 int temp_index = output->index;
131 if (temp_index >= cfg->num_outputs)
132 return -EINVAL;
134 *output = cfg->outputs[temp_index].output;
135 output->index = temp_index;
137 return 0;
140 static int vpbe_get_mode_info(struct vpbe_device *vpbe_dev, char *mode,
141 int output_index)
143 struct vpbe_config *cfg = vpbe_dev->cfg;
144 struct vpbe_enc_mode_info var;
145 int curr_output = output_index;
146 int i;
148 if (!mode)
149 return -EINVAL;
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;
159 return -EINVAL;
162 static int vpbe_get_current_mode_info(struct vpbe_device *vpbe_dev,
163 struct vpbe_enc_mode_info *mode_info)
165 if (!mode_info)
166 return -EINVAL;
168 *mode_info = vpbe_dev->current_timings;
170 return 0;
173 /* Get std by std id */
174 static int vpbe_get_std_info(struct vpbe_device *vpbe_dev,
175 v4l2_std_id std_id)
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;
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) &&
185 (var.std_id & std_id)) {
186 vpbe_dev->current_timings = var;
187 return 0;
191 return -EINVAL;
194 static int vpbe_get_std_info_by_name(struct vpbe_device *vpbe_dev,
195 char *std_name)
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;
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;
210 return -EINVAL;
214 * vpbe_set_output - Set output
215 * @vpbe_dev - vpbe device ptr
216 * @index - index of output
218 * Set vpbe output to the output specified by the index
220 static int vpbe_set_output(struct vpbe_device *vpbe_dev, int index)
222 struct encoder_config_info *curr_enc_info =
223 vpbe_current_encoder_info(vpbe_dev);
224 struct vpbe_config *cfg = vpbe_dev->cfg;
225 struct venc_platform_data *venc_device = vpbe_dev->venc_device;
226 int enc_out_index;
227 int sd_index;
228 int ret;
230 if (index >= cfg->num_outputs)
231 return -EINVAL;
233 mutex_lock(&vpbe_dev->lock);
235 sd_index = vpbe_dev->current_sd_index;
236 enc_out_index = cfg->outputs[index].output.index;
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.
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;
252 goto unlock;
255 ret = venc_device->setup_if_config(cfg->outputs[index].if_params);
256 if (ret)
257 goto unlock;
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)
264 goto unlock;
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.
274 ret = vpbe_get_mode_info(vpbe_dev,
275 cfg->outputs[index].default_mode, index);
276 if (!ret) {
277 struct osd_state *osd_device = vpbe_dev->osd_device;
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;
286 unlock:
287 mutex_unlock(&vpbe_dev->lock);
288 return ret;
291 static int vpbe_set_default_output(struct vpbe_device *vpbe_dev)
293 struct vpbe_config *cfg = vpbe_dev->cfg;
294 int i;
296 for (i = 0; i < cfg->num_outputs; i++) {
297 if (!strcmp(def_output,
298 cfg->outputs[i].output.name)) {
299 int ret = vpbe_set_output(vpbe_dev, i);
301 if (!ret)
302 vpbe_dev->current_out_index = i;
303 return ret;
306 return 0;
310 * vpbe_get_output - Get output
311 * @vpbe_dev - vpbe device ptr
313 * return current vpbe output to the the index
315 static unsigned int vpbe_get_output(struct vpbe_device *vpbe_dev)
317 return vpbe_dev->current_out_index;
321 * vpbe_s_dv_timings - Set the given preset timings in the encoder
323 * Sets the timings if supported by the current encoder. Return the status.
324 * 0 - success & -EINVAL on error
326 static int vpbe_s_dv_timings(struct vpbe_device *vpbe_dev,
327 struct v4l2_dv_timings *dv_timings)
329 struct vpbe_config *cfg = vpbe_dev->cfg;
330 int out_index = vpbe_dev->current_out_index;
331 struct vpbe_output *output = &cfg->outputs[out_index];
332 int sd_index = vpbe_dev->current_sd_index;
333 int ret, i;
336 if (!(cfg->outputs[out_index].output.capabilities &
337 V4L2_OUT_CAP_DV_TIMINGS))
338 return -ENODATA;
340 for (i = 0; i < output->num_modes; i++) {
341 if (output->modes[i].timings_type == VPBE_ENC_DV_TIMINGS &&
342 !memcmp(&output->modes[i].dv_timings,
343 dv_timings, sizeof(*dv_timings)))
344 break;
346 if (i >= output->num_modes)
347 return -EINVAL;
348 vpbe_dev->current_timings = output->modes[i];
349 mutex_lock(&vpbe_dev->lock);
351 ret = v4l2_subdev_call(vpbe_dev->encoders[sd_index], video,
352 s_dv_timings, dv_timings);
353 if (!ret && vpbe_dev->amp) {
354 /* Call amplifier subdevice */
355 ret = v4l2_subdev_call(vpbe_dev->amp, video,
356 s_dv_timings, dv_timings);
358 /* set the lcd controller output for the given mode */
359 if (!ret) {
360 struct osd_state *osd_device = vpbe_dev->osd_device;
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);
367 mutex_unlock(&vpbe_dev->lock);
369 return ret;
373 * vpbe_g_dv_timings - Get the timings in the current encoder
375 * Get the timings in the current encoder. Return the status. 0 - success
376 * -EINVAL on error
378 static int vpbe_g_dv_timings(struct vpbe_device *vpbe_dev,
379 struct v4l2_dv_timings *dv_timings)
381 struct vpbe_config *cfg = vpbe_dev->cfg;
382 int out_index = vpbe_dev->current_out_index;
384 if (!(cfg->outputs[out_index].output.capabilities &
385 V4L2_OUT_CAP_DV_TIMINGS))
386 return -ENODATA;
388 if (vpbe_dev->current_timings.timings_type &
389 VPBE_ENC_DV_TIMINGS) {
390 *dv_timings = vpbe_dev->current_timings.dv_timings;
391 return 0;
394 return -EINVAL;
398 * vpbe_enum_dv_timings - Enumerate the dv timings in the current encoder
400 * Get the timings in the current encoder. Return the status. 0 - success
401 * -EINVAL on error
403 static int vpbe_enum_dv_timings(struct vpbe_device *vpbe_dev,
404 struct v4l2_enum_dv_timings *timings)
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;
412 if (!(output->output.capabilities & V4L2_OUT_CAP_DV_TIMINGS))
413 return -ENODATA;
415 for (i = 0; i < output->num_modes; i++) {
416 if (output->modes[i].timings_type == VPBE_ENC_DV_TIMINGS) {
417 if (j == timings->index)
418 break;
419 j++;
423 if (i == output->num_modes)
424 return -EINVAL;
425 timings->timings = output->modes[i].dv_timings;
426 return 0;
430 * vpbe_s_std - Set the given standard in the encoder
432 * Sets the standard if supported by the current encoder. Return the status.
433 * 0 - success & -EINVAL on error
435 static int vpbe_s_std(struct vpbe_device *vpbe_dev, v4l2_std_id std_id)
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;
442 if (!(cfg->outputs[out_index].output.capabilities &
443 V4L2_OUT_CAP_STD))
444 return -ENODATA;
446 ret = vpbe_get_std_info(vpbe_dev, std_id);
447 if (ret)
448 return ret;
450 mutex_lock(&vpbe_dev->lock);
452 ret = v4l2_subdev_call(vpbe_dev->encoders[sd_index], video,
453 s_std_output, std_id);
454 /* set the lcd controller output for the given mode */
455 if (!ret) {
456 struct osd_state *osd_device = vpbe_dev->osd_device;
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);
463 mutex_unlock(&vpbe_dev->lock);
465 return ret;
469 * vpbe_g_std - Get the standard in the current encoder
471 * Get the standard in the current encoder. Return the status. 0 - success
472 * -EINVAL on error
474 static int vpbe_g_std(struct vpbe_device *vpbe_dev, v4l2_std_id *std_id)
476 struct vpbe_enc_mode_info *cur_timings = &vpbe_dev->current_timings;
477 struct vpbe_config *cfg = vpbe_dev->cfg;
478 int out_index = vpbe_dev->current_out_index;
480 if (!(cfg->outputs[out_index].output.capabilities & V4L2_OUT_CAP_STD))
481 return -ENODATA;
483 if (cur_timings->timings_type & VPBE_ENC_STD) {
484 *std_id = cur_timings->std_id;
485 return 0;
488 return -EINVAL;
492 * vpbe_set_mode - Set mode in the current encoder using mode info
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.
498 static int vpbe_set_mode(struct vpbe_device *vpbe_dev,
499 struct vpbe_enc_mode_info *mode_info)
501 struct vpbe_enc_mode_info *preset_mode = NULL;
502 struct vpbe_config *cfg = vpbe_dev->cfg;
503 struct v4l2_dv_timings dv_timings;
504 struct osd_state *osd_device;
505 int out_index = vpbe_dev->current_out_index;
506 int i;
508 if (!mode_info || !mode_info->name)
509 return -EINVAL;
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];
516 * it may be one of the 3 timings type. Check and
517 * invoke right API
519 if (preset_mode->timings_type & VPBE_ENC_STD)
520 return vpbe_s_std(vpbe_dev,
521 preset_mode->std_id);
522 if (preset_mode->timings_type &
523 VPBE_ENC_DV_TIMINGS) {
524 dv_timings =
525 preset_mode->dv_timings;
526 return vpbe_s_dv_timings(vpbe_dev, &dv_timings);
531 /* Only custom timing should reach here */
532 if (!preset_mode)
533 return -EINVAL;
535 mutex_lock(&vpbe_dev->lock);
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);
544 mutex_unlock(&vpbe_dev->lock);
545 return 0;
548 static int vpbe_set_default_mode(struct vpbe_device *vpbe_dev)
550 int ret;
552 ret = vpbe_get_std_info_by_name(vpbe_dev, def_mode);
553 if (ret)
554 return ret;
556 /* set the default mode in the encoder */
557 return vpbe_set_mode(vpbe_dev, &vpbe_dev->current_timings);
560 static int platform_device_get(struct device *dev, void *data)
562 struct platform_device *pdev = to_platform_device(dev);
563 struct vpbe_device *vpbe_dev = data;
565 if (strstr(pdev->name, "vpbe-osd"))
566 vpbe_dev->osd_device = platform_get_drvdata(pdev);
567 if (strstr(pdev->name, "vpbe-venc"))
568 vpbe_dev->venc_device = dev_get_platdata(&pdev->dev);
570 return 0;
574 * vpbe_initialize() - Initialize the vpbe display controller
575 * @vpbe_dev - vpbe device ptr
577 * Master frame buffer device drivers calls this to initialize vpbe
578 * display controller. This will then registers v4l2 device and the sub
579 * devices and sets a current encoder sub device for display. v4l2 display
580 * device driver is the master and frame buffer display device driver is
581 * the slave. Frame buffer display driver checks the initialized during
582 * probe and exit if not initialized. Returns status.
584 static int vpbe_initialize(struct device *dev, struct vpbe_device *vpbe_dev)
586 struct encoder_config_info *enc_info;
587 struct amp_config_info *amp_info;
588 struct v4l2_subdev **enc_subdev;
589 struct osd_state *osd_device;
590 struct i2c_adapter *i2c_adap;
591 int num_encoders;
592 int ret = 0;
593 int err;
594 int i;
597 * v4l2 abd FBDev frame buffer devices will get the vpbe_dev pointer
598 * from the platform device by iteration of platform drivers and
599 * matching with device name
601 if (!vpbe_dev || !dev) {
602 printk(KERN_ERR "Null device pointers.\n");
603 return -ENODEV;
606 if (vpbe_dev->initialized)
607 return 0;
609 mutex_lock(&vpbe_dev->lock);
611 if (strcmp(vpbe_dev->cfg->module_name, "dm644x-vpbe-display") != 0) {
612 /* We have dac clock available for platform */
613 vpbe_dev->dac_clk = clk_get(vpbe_dev->pdev, "vpss_dac");
614 if (IS_ERR(vpbe_dev->dac_clk)) {
615 ret = PTR_ERR(vpbe_dev->dac_clk);
616 goto fail_mutex_unlock;
618 if (clk_prepare_enable(vpbe_dev->dac_clk)) {
619 ret = -ENODEV;
620 clk_put(vpbe_dev->dac_clk);
621 goto fail_mutex_unlock;
625 /* first enable vpss clocks */
626 vpss_enable_clock(VPSS_VPBE_CLOCK, 1);
628 /* First register a v4l2 device */
629 ret = v4l2_device_register(dev, &vpbe_dev->v4l2_dev);
630 if (ret) {
631 v4l2_err(dev->driver,
632 "Unable to register v4l2 device.\n");
633 goto fail_clk_put;
635 v4l2_info(&vpbe_dev->v4l2_dev, "vpbe v4l2 device registered\n");
637 err = bus_for_each_dev(&platform_bus_type, NULL, vpbe_dev,
638 platform_device_get);
639 if (err < 0) {
640 ret = err;
641 goto fail_dev_unregister;
644 vpbe_dev->venc = venc_sub_dev_init(&vpbe_dev->v4l2_dev,
645 vpbe_dev->cfg->venc.module_name);
646 /* register venc sub device */
647 if (!vpbe_dev->venc) {
648 v4l2_err(&vpbe_dev->v4l2_dev,
649 "vpbe unable to init venc sub device\n");
650 ret = -ENODEV;
651 goto fail_dev_unregister;
653 /* initialize osd device */
654 osd_device = vpbe_dev->osd_device;
655 if (osd_device->ops.initialize) {
656 err = osd_device->ops.initialize(osd_device);
657 if (err) {
658 v4l2_err(&vpbe_dev->v4l2_dev,
659 "unable to initialize the OSD device");
660 err = -ENOMEM;
661 goto fail_dev_unregister;
666 * Register any external encoders that are configured. At index 0 we
667 * store venc sd index.
669 num_encoders = vpbe_dev->cfg->num_ext_encoders + 1;
670 vpbe_dev->encoders = kmalloc_array(num_encoders,
671 sizeof(*vpbe_dev->encoders),
672 GFP_KERNEL);
673 if (!vpbe_dev->encoders) {
674 ret = -ENOMEM;
675 goto fail_dev_unregister;
678 i2c_adap = i2c_get_adapter(vpbe_dev->cfg->i2c_adapter_id);
679 for (i = 0; i < (vpbe_dev->cfg->num_ext_encoders + 1); i++) {
680 if (i == 0) {
681 /* venc is at index 0 */
682 enc_subdev = &vpbe_dev->encoders[i];
683 *enc_subdev = vpbe_dev->venc;
684 continue;
686 enc_info = &vpbe_dev->cfg->ext_encoders[i];
687 if (enc_info->is_i2c) {
688 enc_subdev = &vpbe_dev->encoders[i];
689 *enc_subdev = v4l2_i2c_new_subdev_board(
690 &vpbe_dev->v4l2_dev, i2c_adap,
691 &enc_info->board_info, NULL);
692 if (*enc_subdev)
693 v4l2_info(&vpbe_dev->v4l2_dev,
694 "v4l2 sub device %s registered\n",
695 enc_info->module_name);
696 else {
697 v4l2_err(&vpbe_dev->v4l2_dev, "encoder %s failed to register",
698 enc_info->module_name);
699 ret = -ENODEV;
700 goto fail_kfree_encoders;
702 } else
703 v4l2_warn(&vpbe_dev->v4l2_dev, "non-i2c encoders currently not supported");
705 /* Add amplifier subdevice for dm365 */
706 if ((strcmp(vpbe_dev->cfg->module_name, "dm365-vpbe-display") == 0) &&
707 vpbe_dev->cfg->amp) {
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 &amp_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;
718 goto fail_kfree_encoders;
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 currently not supported");
727 } else {
728 vpbe_dev->amp = NULL;
731 /* set the current encoder and output to that of venc by default */
732 vpbe_dev->current_sd_index = 0;
733 vpbe_dev->current_out_index = 0;
735 mutex_unlock(&vpbe_dev->lock);
737 printk(KERN_NOTICE "Setting default output to %s\n", def_output);
738 ret = vpbe_set_default_output(vpbe_dev);
739 if (ret) {
740 v4l2_err(&vpbe_dev->v4l2_dev, "Failed to set default output %s",
741 def_output);
742 return ret;
745 printk(KERN_NOTICE "Setting default mode to %s\n", def_mode);
746 ret = vpbe_set_default_mode(vpbe_dev);
747 if (ret) {
748 v4l2_err(&vpbe_dev->v4l2_dev, "Failed to set default mode %s",
749 def_mode);
750 return ret;
752 vpbe_dev->initialized = 1;
753 /* TBD handling of bootargs for default output and mode */
754 return 0;
756 fail_kfree_encoders:
757 kfree(vpbe_dev->encoders);
758 fail_dev_unregister:
759 v4l2_device_unregister(&vpbe_dev->v4l2_dev);
760 fail_clk_put:
761 if (strcmp(vpbe_dev->cfg->module_name, "dm644x-vpbe-display") != 0) {
762 clk_disable_unprepare(vpbe_dev->dac_clk);
763 clk_put(vpbe_dev->dac_clk);
765 fail_mutex_unlock:
766 mutex_unlock(&vpbe_dev->lock);
767 return ret;
771 * vpbe_deinitialize() - de-initialize the vpbe display controller
772 * @dev - Master and slave device ptr
774 * vpbe_master and slave frame buffer devices calls this to de-initialize
775 * the display controller. It is called when master and slave device
776 * driver modules are removed and no longer requires the display controller.
778 static void vpbe_deinitialize(struct device *dev, struct vpbe_device *vpbe_dev)
780 v4l2_device_unregister(&vpbe_dev->v4l2_dev);
781 if (strcmp(vpbe_dev->cfg->module_name, "dm644x-vpbe-display") != 0) {
782 clk_disable_unprepare(vpbe_dev->dac_clk);
783 clk_put(vpbe_dev->dac_clk);
786 kfree(vpbe_dev->amp);
787 kfree(vpbe_dev->encoders);
788 vpbe_dev->initialized = 0;
789 /* disable vpss clocks */
790 vpss_enable_clock(VPSS_VPBE_CLOCK, 0);
793 static const struct vpbe_device_ops vpbe_dev_ops = {
794 .g_cropcap = vpbe_g_cropcap,
795 .enum_outputs = vpbe_enum_outputs,
796 .set_output = vpbe_set_output,
797 .get_output = vpbe_get_output,
798 .s_dv_timings = vpbe_s_dv_timings,
799 .g_dv_timings = vpbe_g_dv_timings,
800 .enum_dv_timings = vpbe_enum_dv_timings,
801 .s_std = vpbe_s_std,
802 .g_std = vpbe_g_std,
803 .initialize = vpbe_initialize,
804 .deinitialize = vpbe_deinitialize,
805 .get_mode_info = vpbe_get_current_mode_info,
806 .set_mode = vpbe_set_mode,
809 static int vpbe_probe(struct platform_device *pdev)
811 struct vpbe_device *vpbe_dev;
812 struct vpbe_config *cfg;
814 if (!pdev->dev.platform_data) {
815 v4l2_err(pdev->dev.driver, "No platform data\n");
816 return -ENODEV;
818 cfg = pdev->dev.platform_data;
820 if (!cfg->module_name[0] ||
821 !cfg->osd.module_name[0] ||
822 !cfg->venc.module_name[0]) {
823 v4l2_err(pdev->dev.driver, "vpbe display module names not defined\n");
824 return -EINVAL;
827 vpbe_dev = kzalloc(sizeof(*vpbe_dev), GFP_KERNEL);
828 if (!vpbe_dev)
829 return -ENOMEM;
831 vpbe_dev->cfg = cfg;
832 vpbe_dev->ops = vpbe_dev_ops;
833 vpbe_dev->pdev = &pdev->dev;
835 if (cfg->outputs->num_modes > 0)
836 vpbe_dev->current_timings = vpbe_dev->cfg->outputs[0].modes[0];
837 else {
838 kfree(vpbe_dev);
839 return -ENODEV;
842 /* set the driver data in platform device */
843 platform_set_drvdata(pdev, vpbe_dev);
844 mutex_init(&vpbe_dev->lock);
846 return 0;
849 static int vpbe_remove(struct platform_device *device)
851 struct vpbe_device *vpbe_dev = platform_get_drvdata(device);
853 kfree(vpbe_dev);
855 return 0;
858 static struct platform_driver vpbe_driver = {
859 .driver = {
860 .name = "vpbe_controller",
862 .probe = vpbe_probe,
863 .remove = vpbe_remove,
866 module_platform_driver(vpbe_driver);