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 * 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
17 #include <linux/kernel.h>
18 #include <linux/init.h>
19 #include <linux/module.h>
20 #include <linux/errno.h>
22 #include <linux/string.h>
23 #include <linux/wait.h>
24 #include <linux/time.h>
25 #include <linux/platform_device.h>
27 #include <linux/slab.h>
28 #include <linux/clk.h>
29 #include <linux/err.h>
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>
37 #define VPBE_DEFAULT_OUTPUT "Composite"
38 #define VPBE_DEFAULT_MODE "ntsc"
40 static char *def_output
= VPBE_DEFAULT_OUTPUT
;
41 static char *def_mode
= VPBE_DEFAULT_MODE
;
44 module_param(def_output
, charp
, S_IRUGO
);
45 module_param(def_mode
, charp
, S_IRUGO
);
46 module_param(debug
, int, 0644);
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");
52 MODULE_DESCRIPTION("TI DMXXX VPBE Display controller");
53 MODULE_LICENSE("GPL");
54 MODULE_AUTHOR("Texas Instruments");
57 * vpbe_current_encoder_info - Get config info for current encoder
58 * @vpbe_dev - vpbe device ptr
60 * Return ptr to current encoder config info
62 static struct encoder_config_info
*
63 vpbe_current_encoder_info(struct vpbe_device
*vpbe_dev
)
65 struct vpbe_config
*cfg
= vpbe_dev
->cfg
;
66 int index
= vpbe_dev
->current_sd_index
;
68 return ((index
== 0) ? &cfg
->venc
:
69 &cfg
->ext_encoders
[index
-1]);
73 * vpbe_find_encoder_sd_index - Given a name find encoder sd index
75 * @vpbe_config - ptr to vpbe cfg
76 * @output_index - index used by application
78 * Return sd index of the encoder
80 static int vpbe_find_encoder_sd_index(struct vpbe_config
*cfg
,
83 char *encoder_name
= cfg
->outputs
[index
].subdev_name
;
86 /* Venc is always first */
87 if (!strcmp(encoder_name
, cfg
->venc
.module_name
))
90 for (i
= 0; i
< cfg
->num_ext_encoders
; i
++) {
91 if (!strcmp(encoder_name
,
92 cfg
->ext_encoders
[i
].module_name
))
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
104 * Update the crop capabilities in crop cap for current
107 static int vpbe_g_cropcap(struct vpbe_device
*vpbe_dev
,
108 struct v4l2_cropcap
*cropcap
)
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
;
122 * vpbe_enum_outputs - enumerate outputs
123 * @vpbe_dev - vpbe device ptr
124 * @output - ptr to v4l2_output structure
126 * Enumerates the outputs available at the vpbe display
127 * returns the status, -EINVAL if end of output list
129 static int vpbe_enum_outputs(struct vpbe_device
*vpbe_dev
,
130 struct v4l2_output
*output
)
132 struct vpbe_config
*cfg
= vpbe_dev
->cfg
;
133 int temp_index
= output
->index
;
135 if (temp_index
>= cfg
->num_outputs
)
138 *output
= cfg
->outputs
[temp_index
].output
;
139 output
->index
= temp_index
;
144 static int vpbe_get_mode_info(struct vpbe_device
*vpbe_dev
, char *mode
,
147 struct vpbe_config
*cfg
= vpbe_dev
->cfg
;
148 struct vpbe_enc_mode_info var
;
149 int curr_output
= output_index
;
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
;
166 static int vpbe_get_current_mode_info(struct vpbe_device
*vpbe_dev
,
167 struct vpbe_enc_mode_info
*mode_info
)
169 if (NULL
== mode_info
)
172 *mode_info
= vpbe_dev
->current_timings
;
177 /* Get std by std id */
178 static int vpbe_get_std_info(struct vpbe_device
*vpbe_dev
,
181 struct vpbe_config
*cfg
= vpbe_dev
->cfg
;
182 struct vpbe_enc_mode_info var
;
183 int curr_output
= vpbe_dev
->current_out_index
;
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
) &&
189 (var
.std_id
& std_id
)) {
190 vpbe_dev
->current_timings
= var
;
198 static int vpbe_get_std_info_by_name(struct vpbe_device
*vpbe_dev
,
201 struct vpbe_config
*cfg
= vpbe_dev
->cfg
;
202 struct vpbe_enc_mode_info var
;
203 int curr_output
= vpbe_dev
->current_out_index
;
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
;
218 * vpbe_set_output - Set output
219 * @vpbe_dev - vpbe device ptr
220 * @index - index of output
222 * Set vpbe output to the output specified by the index
224 static int vpbe_set_output(struct vpbe_device
*vpbe_dev
, int index
)
226 struct encoder_config_info
*curr_enc_info
=
227 vpbe_current_encoder_info(vpbe_dev
);
228 struct vpbe_config
*cfg
= vpbe_dev
->cfg
;
229 struct venc_platform_data
*venc_device
= vpbe_dev
->venc_device
;
235 if (index
>= cfg
->num_outputs
)
238 mutex_lock(&vpbe_dev
->lock
);
240 sd_index
= vpbe_dev
->current_sd_index
;
241 enc_out_index
= cfg
->outputs
[index
].output
.index
;
243 * Currently we switch the encoder based on output selected
244 * by the application. If media controller is implemented later
245 * there is will be an API added to setup_link between venc
246 * and external encoder. So in that case below comparison always
247 * match and encoder will not be switched. But if application
248 * chose not to use media controller, then this provides current
249 * way of switching encoder at the venc output.
251 if (strcmp(curr_enc_info
->module_name
,
252 cfg
->outputs
[index
].subdev_name
)) {
253 /* Need to switch the encoder at the output */
254 sd_index
= vpbe_find_encoder_sd_index(cfg
, index
);
260 if_params
= cfg
->outputs
[index
].if_params
;
261 venc_device
->setup_if_config(if_params
);
266 /* Set output at the encoder */
267 ret
= v4l2_subdev_call(vpbe_dev
->encoders
[sd_index
], video
,
268 s_routing
, 0, enc_out_index
, 0);
273 * It is assumed that venc or extenal encoder will set a default
274 * mode in the sub device. For external encoder or LCD pannel output,
275 * we also need to set up the lcd port for the required mode. So setup
276 * the lcd port for the default mode that is configured in the board
277 * arch/arm/mach-davinci/board-dm355-evm.setup file for the external
280 ret
= vpbe_get_mode_info(vpbe_dev
,
281 cfg
->outputs
[index
].default_mode
, index
);
283 struct osd_state
*osd_device
= vpbe_dev
->osd_device
;
285 osd_device
->ops
.set_left_margin(osd_device
,
286 vpbe_dev
->current_timings
.left_margin
);
287 osd_device
->ops
.set_top_margin(osd_device
,
288 vpbe_dev
->current_timings
.upper_margin
);
289 vpbe_dev
->current_sd_index
= sd_index
;
290 vpbe_dev
->current_out_index
= index
;
293 mutex_unlock(&vpbe_dev
->lock
);
297 static int vpbe_set_default_output(struct vpbe_device
*vpbe_dev
)
299 struct vpbe_config
*cfg
= vpbe_dev
->cfg
;
303 for (i
= 0; i
< cfg
->num_outputs
; i
++) {
304 if (!strcmp(def_output
,
305 cfg
->outputs
[i
].output
.name
)) {
306 ret
= vpbe_set_output(vpbe_dev
, i
);
308 vpbe_dev
->current_out_index
= i
;
316 * vpbe_get_output - Get output
317 * @vpbe_dev - vpbe device ptr
319 * return current vpbe output to the the index
321 static unsigned int vpbe_get_output(struct vpbe_device
*vpbe_dev
)
323 return vpbe_dev
->current_out_index
;
327 * vpbe_s_dv_timings - Set the given preset timings in the encoder
329 * Sets the timings if supported by the current encoder. Return the status.
330 * 0 - success & -EINVAL on error
332 static int vpbe_s_dv_timings(struct vpbe_device
*vpbe_dev
,
333 struct v4l2_dv_timings
*dv_timings
)
335 struct vpbe_config
*cfg
= vpbe_dev
->cfg
;
336 int out_index
= vpbe_dev
->current_out_index
;
337 struct vpbe_output
*output
= &cfg
->outputs
[out_index
];
338 int sd_index
= vpbe_dev
->current_sd_index
;
342 if (!(cfg
->outputs
[out_index
].output
.capabilities
&
343 V4L2_OUT_CAP_DV_TIMINGS
))
346 for (i
= 0; i
< output
->num_modes
; i
++) {
347 if (output
->modes
[i
].timings_type
== VPBE_ENC_DV_TIMINGS
&&
348 !memcmp(&output
->modes
[i
].dv_timings
,
349 dv_timings
, sizeof(*dv_timings
)))
352 if (i
>= output
->num_modes
)
354 vpbe_dev
->current_timings
= output
->modes
[i
];
355 mutex_lock(&vpbe_dev
->lock
);
357 ret
= v4l2_subdev_call(vpbe_dev
->encoders
[sd_index
], video
,
358 s_dv_timings
, dv_timings
);
359 if (!ret
&& (vpbe_dev
->amp
!= NULL
)) {
360 /* Call amplifier subdevice */
361 ret
= v4l2_subdev_call(vpbe_dev
->amp
, video
,
362 s_dv_timings
, dv_timings
);
364 /* set the lcd controller output for the given mode */
366 struct osd_state
*osd_device
= vpbe_dev
->osd_device
;
368 osd_device
->ops
.set_left_margin(osd_device
,
369 vpbe_dev
->current_timings
.left_margin
);
370 osd_device
->ops
.set_top_margin(osd_device
,
371 vpbe_dev
->current_timings
.upper_margin
);
373 mutex_unlock(&vpbe_dev
->lock
);
379 * vpbe_g_dv_timings - Get the timings in the current encoder
381 * Get the timings in the current encoder. Return the status. 0 - success
384 static int vpbe_g_dv_timings(struct vpbe_device
*vpbe_dev
,
385 struct v4l2_dv_timings
*dv_timings
)
387 struct vpbe_config
*cfg
= vpbe_dev
->cfg
;
388 int out_index
= vpbe_dev
->current_out_index
;
390 if (!(cfg
->outputs
[out_index
].output
.capabilities
&
391 V4L2_OUT_CAP_DV_TIMINGS
))
394 if (vpbe_dev
->current_timings
.timings_type
&
395 VPBE_ENC_DV_TIMINGS
) {
396 *dv_timings
= vpbe_dev
->current_timings
.dv_timings
;
404 * vpbe_enum_dv_timings - Enumerate the dv timings in the current encoder
406 * Get the timings in the current encoder. Return the status. 0 - success
409 static int vpbe_enum_dv_timings(struct vpbe_device
*vpbe_dev
,
410 struct v4l2_enum_dv_timings
*timings
)
412 struct vpbe_config
*cfg
= vpbe_dev
->cfg
;
413 int out_index
= vpbe_dev
->current_out_index
;
414 struct vpbe_output
*output
= &cfg
->outputs
[out_index
];
418 if (!(output
->output
.capabilities
& V4L2_OUT_CAP_DV_TIMINGS
))
421 for (i
= 0; i
< output
->num_modes
; i
++) {
422 if (output
->modes
[i
].timings_type
== VPBE_ENC_DV_TIMINGS
) {
423 if (j
== timings
->index
)
429 if (i
== output
->num_modes
)
431 timings
->timings
= output
->modes
[i
].dv_timings
;
436 * vpbe_s_std - Set the given standard in the encoder
438 * Sets the standard if supported by the current encoder. Return the status.
439 * 0 - success & -EINVAL on error
441 static int vpbe_s_std(struct vpbe_device
*vpbe_dev
, v4l2_std_id std_id
)
443 struct vpbe_config
*cfg
= vpbe_dev
->cfg
;
444 int out_index
= vpbe_dev
->current_out_index
;
445 int sd_index
= vpbe_dev
->current_sd_index
;
448 if (!(cfg
->outputs
[out_index
].output
.capabilities
&
452 ret
= vpbe_get_std_info(vpbe_dev
, std_id
);
456 mutex_lock(&vpbe_dev
->lock
);
458 ret
= v4l2_subdev_call(vpbe_dev
->encoders
[sd_index
], video
,
459 s_std_output
, std_id
);
460 /* set the lcd controller output for the given mode */
462 struct osd_state
*osd_device
= vpbe_dev
->osd_device
;
464 osd_device
->ops
.set_left_margin(osd_device
,
465 vpbe_dev
->current_timings
.left_margin
);
466 osd_device
->ops
.set_top_margin(osd_device
,
467 vpbe_dev
->current_timings
.upper_margin
);
469 mutex_unlock(&vpbe_dev
->lock
);
475 * vpbe_g_std - Get the standard in the current encoder
477 * Get the standard in the current encoder. Return the status. 0 - success
480 static int vpbe_g_std(struct vpbe_device
*vpbe_dev
, v4l2_std_id
*std_id
)
482 struct vpbe_enc_mode_info
*cur_timings
= &vpbe_dev
->current_timings
;
483 struct vpbe_config
*cfg
= vpbe_dev
->cfg
;
484 int out_index
= vpbe_dev
->current_out_index
;
486 if (!(cfg
->outputs
[out_index
].output
.capabilities
& V4L2_OUT_CAP_STD
))
489 if (cur_timings
->timings_type
& VPBE_ENC_STD
) {
490 *std_id
= cur_timings
->std_id
;
498 * vpbe_set_mode - Set mode in the current encoder using mode info
500 * Use the mode string to decide what timings to set in the encoder
501 * This is typically useful when fbset command is used to change the current
502 * timings by specifying a string to indicate the timings.
504 static int vpbe_set_mode(struct vpbe_device
*vpbe_dev
,
505 struct vpbe_enc_mode_info
*mode_info
)
507 struct vpbe_enc_mode_info
*preset_mode
= NULL
;
508 struct vpbe_config
*cfg
= vpbe_dev
->cfg
;
509 struct v4l2_dv_timings dv_timings
;
510 struct osd_state
*osd_device
;
511 int out_index
= vpbe_dev
->current_out_index
;
515 if ((NULL
== mode_info
) || (NULL
== mode_info
->name
))
518 for (i
= 0; i
< cfg
->outputs
[out_index
].num_modes
; i
++) {
519 if (!strcmp(mode_info
->name
,
520 cfg
->outputs
[out_index
].modes
[i
].name
)) {
521 preset_mode
= &cfg
->outputs
[out_index
].modes
[i
];
523 * it may be one of the 3 timings type. Check and
526 if (preset_mode
->timings_type
& VPBE_ENC_STD
)
527 return vpbe_s_std(vpbe_dev
,
528 preset_mode
->std_id
);
529 if (preset_mode
->timings_type
&
530 VPBE_ENC_DV_TIMINGS
) {
532 preset_mode
->dv_timings
;
533 return vpbe_s_dv_timings(vpbe_dev
, &dv_timings
);
538 /* Only custom timing should reach here */
539 if (preset_mode
== NULL
)
542 mutex_lock(&vpbe_dev
->lock
);
544 osd_device
= vpbe_dev
->osd_device
;
545 vpbe_dev
->current_timings
= *preset_mode
;
546 osd_device
->ops
.set_left_margin(osd_device
,
547 vpbe_dev
->current_timings
.left_margin
);
548 osd_device
->ops
.set_top_margin(osd_device
,
549 vpbe_dev
->current_timings
.upper_margin
);
551 mutex_unlock(&vpbe_dev
->lock
);
556 static int vpbe_set_default_mode(struct vpbe_device
*vpbe_dev
)
560 ret
= vpbe_get_std_info_by_name(vpbe_dev
, def_mode
);
564 /* set the default mode in the encoder */
565 return vpbe_set_mode(vpbe_dev
, &vpbe_dev
->current_timings
);
568 static int platform_device_get(struct device
*dev
, void *data
)
570 struct platform_device
*pdev
= to_platform_device(dev
);
571 struct vpbe_device
*vpbe_dev
= data
;
573 if (strstr(pdev
->name
, "vpbe-osd") != NULL
)
574 vpbe_dev
->osd_device
= platform_get_drvdata(pdev
);
575 if (strstr(pdev
->name
, "vpbe-venc") != NULL
)
576 vpbe_dev
->venc_device
= dev_get_platdata(&pdev
->dev
);
582 * vpbe_initialize() - Initialize the vpbe display controller
583 * @vpbe_dev - vpbe device ptr
585 * Master frame buffer device drivers calls this to initialize vpbe
586 * display controller. This will then registers v4l2 device and the sub
587 * devices and sets a current encoder sub device for display. v4l2 display
588 * device driver is the master and frame buffer display device driver is
589 * the slave. Frame buffer display driver checks the initialized during
590 * probe and exit if not initialized. Returns status.
592 static int vpbe_initialize(struct device
*dev
, struct vpbe_device
*vpbe_dev
)
594 struct encoder_config_info
*enc_info
;
595 struct amp_config_info
*amp_info
;
596 struct v4l2_subdev
**enc_subdev
;
597 struct osd_state
*osd_device
;
598 struct i2c_adapter
*i2c_adap
;
605 * v4l2 abd FBDev frame buffer devices will get the vpbe_dev pointer
606 * from the platform device by iteration of platform drivers and
607 * matching with device name
609 if (NULL
== vpbe_dev
|| NULL
== dev
) {
610 printk(KERN_ERR
"Null device pointers.\n");
614 if (vpbe_dev
->initialized
)
617 mutex_lock(&vpbe_dev
->lock
);
619 if (strcmp(vpbe_dev
->cfg
->module_name
, "dm644x-vpbe-display") != 0) {
620 /* We have dac clock available for platform */
621 vpbe_dev
->dac_clk
= clk_get(vpbe_dev
->pdev
, "vpss_dac");
622 if (IS_ERR(vpbe_dev
->dac_clk
)) {
623 ret
= PTR_ERR(vpbe_dev
->dac_clk
);
624 goto fail_mutex_unlock
;
626 if (clk_prepare_enable(vpbe_dev
->dac_clk
)) {
628 clk_put(vpbe_dev
->dac_clk
);
629 goto fail_mutex_unlock
;
633 /* first enable vpss clocks */
634 vpss_enable_clock(VPSS_VPBE_CLOCK
, 1);
636 /* First register a v4l2 device */
637 ret
= v4l2_device_register(dev
, &vpbe_dev
->v4l2_dev
);
639 v4l2_err(dev
->driver
,
640 "Unable to register v4l2 device.\n");
643 v4l2_info(&vpbe_dev
->v4l2_dev
, "vpbe v4l2 device registered\n");
645 err
= bus_for_each_dev(&platform_bus_type
, NULL
, vpbe_dev
,
646 platform_device_get
);
649 goto fail_dev_unregister
;
652 vpbe_dev
->venc
= venc_sub_dev_init(&vpbe_dev
->v4l2_dev
,
653 vpbe_dev
->cfg
->venc
.module_name
);
654 /* register venc sub device */
655 if (vpbe_dev
->venc
== NULL
) {
656 v4l2_err(&vpbe_dev
->v4l2_dev
,
657 "vpbe unable to init venc sub device\n");
659 goto fail_dev_unregister
;
661 /* initialize osd device */
662 osd_device
= vpbe_dev
->osd_device
;
664 if (NULL
!= osd_device
->ops
.initialize
) {
665 err
= osd_device
->ops
.initialize(osd_device
);
667 v4l2_err(&vpbe_dev
->v4l2_dev
,
668 "unable to initialize the OSD device");
670 goto fail_dev_unregister
;
675 * Register any external encoders that are configured. At index 0 we
676 * store venc sd index.
678 num_encoders
= vpbe_dev
->cfg
->num_ext_encoders
+ 1;
679 vpbe_dev
->encoders
= kmalloc(
680 sizeof(struct v4l2_subdev
*)*num_encoders
,
682 if (NULL
== vpbe_dev
->encoders
) {
683 v4l2_err(&vpbe_dev
->v4l2_dev
,
684 "unable to allocate memory for encoders sub devices");
686 goto fail_dev_unregister
;
689 i2c_adap
= i2c_get_adapter(vpbe_dev
->cfg
->i2c_adapter_id
);
690 for (i
= 0; i
< (vpbe_dev
->cfg
->num_ext_encoders
+ 1); i
++) {
692 /* venc is at index 0 */
693 enc_subdev
= &vpbe_dev
->encoders
[i
];
694 *enc_subdev
= vpbe_dev
->venc
;
697 enc_info
= &vpbe_dev
->cfg
->ext_encoders
[i
];
698 if (enc_info
->is_i2c
) {
699 enc_subdev
= &vpbe_dev
->encoders
[i
];
700 *enc_subdev
= v4l2_i2c_new_subdev_board(
701 &vpbe_dev
->v4l2_dev
, i2c_adap
,
702 &enc_info
->board_info
, NULL
);
704 v4l2_info(&vpbe_dev
->v4l2_dev
,
705 "v4l2 sub device %s registered\n",
706 enc_info
->module_name
);
708 v4l2_err(&vpbe_dev
->v4l2_dev
, "encoder %s"
709 " failed to register",
710 enc_info
->module_name
);
712 goto fail_kfree_encoders
;
715 v4l2_warn(&vpbe_dev
->v4l2_dev
, "non-i2c encoders"
716 " currently not supported");
718 /* Add amplifier subdevice for dm365 */
719 if ((strcmp(vpbe_dev
->cfg
->module_name
, "dm365-vpbe-display") == 0) &&
720 vpbe_dev
->cfg
->amp
!= NULL
) {
721 amp_info
= vpbe_dev
->cfg
->amp
;
722 if (amp_info
->is_i2c
) {
723 vpbe_dev
->amp
= v4l2_i2c_new_subdev_board(
724 &vpbe_dev
->v4l2_dev
, i2c_adap
,
725 &_info
->board_info
, NULL
);
726 if (!vpbe_dev
->amp
) {
727 v4l2_err(&vpbe_dev
->v4l2_dev
,
728 "amplifier %s failed to register",
729 amp_info
->module_name
);
731 goto fail_kfree_encoders
;
733 v4l2_info(&vpbe_dev
->v4l2_dev
,
734 "v4l2 sub device %s registered\n",
735 amp_info
->module_name
);
737 vpbe_dev
->amp
= NULL
;
738 v4l2_warn(&vpbe_dev
->v4l2_dev
, "non-i2c amplifiers"
739 " currently not supported");
742 vpbe_dev
->amp
= NULL
;
745 /* set the current encoder and output to that of venc by default */
746 vpbe_dev
->current_sd_index
= 0;
747 vpbe_dev
->current_out_index
= 0;
749 mutex_unlock(&vpbe_dev
->lock
);
751 printk(KERN_NOTICE
"Setting default output to %s\n", def_output
);
752 ret
= vpbe_set_default_output(vpbe_dev
);
754 v4l2_err(&vpbe_dev
->v4l2_dev
, "Failed to set default output %s",
759 printk(KERN_NOTICE
"Setting default mode to %s\n", def_mode
);
760 ret
= vpbe_set_default_mode(vpbe_dev
);
762 v4l2_err(&vpbe_dev
->v4l2_dev
, "Failed to set default mode %s",
766 vpbe_dev
->initialized
= 1;
767 /* TBD handling of bootargs for default output and mode */
771 kfree(vpbe_dev
->encoders
);
773 v4l2_device_unregister(&vpbe_dev
->v4l2_dev
);
775 if (strcmp(vpbe_dev
->cfg
->module_name
, "dm644x-vpbe-display") != 0) {
776 clk_disable_unprepare(vpbe_dev
->dac_clk
);
777 clk_put(vpbe_dev
->dac_clk
);
780 mutex_unlock(&vpbe_dev
->lock
);
785 * vpbe_deinitialize() - de-initialize the vpbe display controller
786 * @dev - Master and slave device ptr
788 * vpbe_master and slave frame buffer devices calls this to de-initialize
789 * the display controller. It is called when master and slave device
790 * driver modules are removed and no longer requires the display controller.
792 static void vpbe_deinitialize(struct device
*dev
, struct vpbe_device
*vpbe_dev
)
794 v4l2_device_unregister(&vpbe_dev
->v4l2_dev
);
795 if (strcmp(vpbe_dev
->cfg
->module_name
, "dm644x-vpbe-display") != 0) {
796 clk_disable_unprepare(vpbe_dev
->dac_clk
);
797 clk_put(vpbe_dev
->dac_clk
);
800 kfree(vpbe_dev
->amp
);
801 kfree(vpbe_dev
->encoders
);
802 vpbe_dev
->initialized
= 0;
803 /* disable vpss clocks */
804 vpss_enable_clock(VPSS_VPBE_CLOCK
, 0);
807 static struct vpbe_device_ops vpbe_dev_ops
= {
808 .g_cropcap
= vpbe_g_cropcap
,
809 .enum_outputs
= vpbe_enum_outputs
,
810 .set_output
= vpbe_set_output
,
811 .get_output
= vpbe_get_output
,
812 .s_dv_timings
= vpbe_s_dv_timings
,
813 .g_dv_timings
= vpbe_g_dv_timings
,
814 .enum_dv_timings
= vpbe_enum_dv_timings
,
817 .initialize
= vpbe_initialize
,
818 .deinitialize
= vpbe_deinitialize
,
819 .get_mode_info
= vpbe_get_current_mode_info
,
820 .set_mode
= vpbe_set_mode
,
823 static int vpbe_probe(struct platform_device
*pdev
)
825 struct vpbe_device
*vpbe_dev
;
826 struct vpbe_config
*cfg
;
829 if (pdev
->dev
.platform_data
== NULL
) {
830 v4l2_err(pdev
->dev
.driver
, "No platform data\n");
833 cfg
= pdev
->dev
.platform_data
;
835 if (!cfg
->module_name
[0] ||
836 !cfg
->osd
.module_name
[0] ||
837 !cfg
->venc
.module_name
[0]) {
838 v4l2_err(pdev
->dev
.driver
, "vpbe display module names not"
843 vpbe_dev
= kzalloc(sizeof(*vpbe_dev
), GFP_KERNEL
);
844 if (vpbe_dev
== NULL
) {
845 v4l2_err(pdev
->dev
.driver
, "Unable to allocate memory"
846 " for vpbe_device\n");
850 vpbe_dev
->ops
= vpbe_dev_ops
;
851 vpbe_dev
->pdev
= &pdev
->dev
;
853 if (cfg
->outputs
->num_modes
> 0)
854 vpbe_dev
->current_timings
= vpbe_dev
->cfg
->outputs
[0].modes
[0];
860 /* set the driver data in platform device */
861 platform_set_drvdata(pdev
, vpbe_dev
);
862 mutex_init(&vpbe_dev
->lock
);
867 static int vpbe_remove(struct platform_device
*device
)
869 struct vpbe_device
*vpbe_dev
= platform_get_drvdata(device
);
876 static struct platform_driver vpbe_driver
= {
878 .name
= "vpbe_controller",
881 .remove
= vpbe_remove
,
884 module_platform_driver(vpbe_driver
);