17 #include <linux/kernel.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>
27 #include <linux/slab.h>
37 #define VPBE_DEFAULT_OUTPUT "Composite"
38 #define VPBE_DEFAULT_MODE "ntsc"
63 vpbe_current_encoder_info(
struct vpbe_device *vpbe_dev)
68 return ((index == 0) ? &cfg->
venc :
80 static int vpbe_find_encoder_sd_index(
struct vpbe_config *cfg,
87 if (!
strcmp(encoder_name, cfg->
venc.module_name))
107 static int vpbe_g_cropcap(
struct vpbe_device *vpbe_dev,
129 static int vpbe_enum_outputs(
struct vpbe_device *vpbe_dev,
133 int temp_index = output->
index;
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,
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)) {
166 static int vpbe_get_current_mode_info(
struct vpbe_device *vpbe_dev,
169 if (
NULL == mode_info)
178 static int vpbe_get_std_info(
struct vpbe_device *vpbe_dev,
186 for (i = 0; i < vpbe_dev->
cfg->outputs[curr_output].num_modes; i++) {
187 var = cfg->
outputs[curr_output].modes[
i];
189 (var.std_id & std_id)) {
198 static int vpbe_get_std_info_by_name(
struct vpbe_device *vpbe_dev,
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)) {
224 static int vpbe_set_output(
struct vpbe_device *vpbe_dev,
int index)
227 vpbe_current_encoder_info(vpbe_dev);
252 cfg->
outputs[index].subdev_name)) {
254 sd_index = vpbe_find_encoder_sd_index(cfg, index);
268 s_routing, 0, enc_out_index, 0);
280 ret = vpbe_get_mode_info(vpbe_dev,
281 cfg->
outputs[index].default_mode, index);
285 osd_device->
ops.set_left_margin(osd_device,
287 osd_device->
ops.set_top_margin(osd_device,
297 static int vpbe_set_default_output(
struct vpbe_device *vpbe_dev)
305 cfg->
outputs[i].output.name)) {
306 ret = vpbe_set_output(vpbe_dev, i);
321 static unsigned int vpbe_get_output(
struct vpbe_device *vpbe_dev)
332 static int vpbe_s_dv_timings(
struct vpbe_device *vpbe_dev,
342 if (!(cfg->
outputs[out_index].output.capabilities &
346 for (i = 0; i < output->
num_modes; i++) {
349 dv_timings,
sizeof(*dv_timings)))
358 s_dv_timings, dv_timings);
359 if (!ret && (vpbe_dev->
amp !=
NULL)) {
362 s_dv_timings, dv_timings);
368 osd_device->
ops.set_left_margin(osd_device,
370 osd_device->
ops.set_top_margin(osd_device,
384 static int vpbe_g_dv_timings(
struct vpbe_device *vpbe_dev,
402 static int vpbe_enum_dv_timings(
struct vpbe_device *vpbe_dev,
411 if (!(output->
output.capabilities & V4L2_OUT_CAP_DV_TIMINGS))
414 for (i = 0; i < output->
num_modes; i++) {
416 if (j == timings->
index)
441 if (!(cfg->
outputs[out_index].output.capabilities &
445 ret = vpbe_get_std_info(vpbe_dev, *std_id);
452 s_std_output, *std_id);
457 osd_device->
ops.set_left_margin(osd_device,
459 osd_device->
ops.set_top_margin(osd_device,
478 *std_id = cur_timings->
std_id;
492 static int vpbe_set_mode(
struct vpbe_device *vpbe_dev,
506 for (i = 0; i < cfg->
outputs[out_index].num_modes; i++) {
508 cfg->
outputs[out_index].modes[i].name)) {
509 preset_mode = &cfg->
outputs[out_index].modes[
i];
515 return vpbe_s_std(vpbe_dev,
521 return vpbe_s_dv_timings(vpbe_dev, &dv_timings);
527 if (preset_mode ==
NULL)
534 osd_device->
ops.set_left_margin(osd_device,
536 osd_device->
ops.set_top_margin(osd_device,
544 static int vpbe_set_default_mode(
struct vpbe_device *vpbe_dev)
548 ret = vpbe_get_std_info_by_name(vpbe_dev, def_mode);
556 static int platform_device_get(
struct device *
dev,
void *
data)
562 vpbe_dev->
osd_device = platform_get_drvdata(pdev);
598 if (
NULL == vpbe_dev ||
NULL == dev) {
608 if (
strcmp(vpbe_dev->
cfg->module_name,
"dm644x-vpbe-display") != 0) {
611 if (IS_ERR(vpbe_dev->
dac_clk)) {
612 ret = PTR_ERR(vpbe_dev->
dac_clk);
613 goto fail_mutex_unlock;
617 goto fail_mutex_unlock;
628 "Unable to register v4l2 device.\n");
634 platform_device_get);
639 vpbe_dev->
cfg->venc.module_name);
643 "vpbe unable to init venc sub device\n");
645 goto fail_dev_unregister;
650 if (
NULL != osd_device->
ops.initialize) {
651 err = osd_device->
ops.initialize(osd_device);
654 "unable to initialize the OSD device");
656 goto fail_dev_unregister;
664 num_encoders = vpbe_dev->
cfg->num_ext_encoders + 1;
670 "unable to allocate memory for encoders sub devices");
672 goto fail_dev_unregister;
676 for (i = 0; i < (vpbe_dev->
cfg->num_ext_encoders + 1); i++) {
680 *enc_subdev = vpbe_dev->
venc;
683 enc_info = &vpbe_dev->
cfg->ext_encoders[
i];
691 "v4l2 sub device %s registered\n",
695 " failed to register",
698 goto fail_kfree_encoders;
702 " currently not supported");
705 if ((
strcmp(vpbe_dev->
cfg->module_name,
"dm365-vpbe-display") == 0) &&
707 amp_info = vpbe_dev->
cfg->amp;
712 if (!vpbe_dev->
amp) {
714 "amplifier %s failed to register",
717 goto fail_kfree_encoders;
720 "v4l2 sub device %s registered\n",
725 " currently not supported");
739 ret = vpbe_set_default_output(vpbe_dev);
747 ret = vpbe_set_default_mode(vpbe_dev);
762 if (
strcmp(vpbe_dev->
cfg->module_name,
"dm644x-vpbe-display") != 0)
780 if (
strcmp(vpbe_dev->
cfg->module_name,
"dm644x-vpbe-display") != 0)
791 .g_cropcap = vpbe_g_cropcap,
792 .enum_outputs = vpbe_enum_outputs,
793 .set_output = vpbe_set_output,
794 .get_output = vpbe_get_output,
795 .s_dv_timings = vpbe_s_dv_timings,
796 .g_dv_timings = vpbe_g_dv_timings,
797 .enum_dv_timings = vpbe_enum_dv_timings,
800 .initialize = vpbe_initialize,
801 .deinitialize = vpbe_deinitialize,
802 .get_mode_info = vpbe_get_current_mode_info,
803 .set_mode = vpbe_set_mode,
812 if (pdev->
dev.platform_data ==
NULL) {
816 cfg = pdev->
dev.platform_data;
819 !cfg->
osd.module_name[0] ||
820 !cfg->
venc.module_name[0]) {
821 v4l2_err(pdev->
dev.driver,
"vpbe display module names not"
826 vpbe_dev = kzalloc(
sizeof(*vpbe_dev),
GFP_KERNEL);
827 if (vpbe_dev ==
NULL) {
828 v4l2_err(pdev->
dev.driver,
"Unable to allocate memory"
829 " for vpbe_device\n");
833 vpbe_dev->
ops = vpbe_dev_ops;
836 if (cfg->
outputs->num_modes > 0)
844 platform_set_drvdata(pdev, vpbe_dev);
852 struct vpbe_device *vpbe_dev = platform_get_drvdata(device);
861 .name =
"vpbe_controller",
865 .remove = vpbe_remove,