⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tvp5150_ti.c

📁 tvp5150数据手册和TI的C文件,对tvp5150驱动开发有帮助
💻 C
📖 第 1 页 / 共 4 页
字号:
856 
857         switch (cmd) {
858 
859         case 0:
860         case VIDIOC_INT_RESET:
861                 tvp5150_reset(c);
862                 break;
863         case VIDIOC_S_STD:
864                 if (decoder->norm == *(v4l2_std_id *)arg)
865                         break;
866                 return tvp5150_set_std(c, *(v4l2_std_id *)arg);
867         case VIDIOC_G_STD:
868                 *(v4l2_std_id *)arg = decoder->norm;
869                 break;
870 
871         case VIDIOC_G_SLICED_VBI_CAP:
872         {
873                 struct v4l2_sliced_vbi_cap *cap = arg;
874                 tvp5150_dbg(1, "VIDIOC_G_SLICED_VBI_CAP\n");
875 
876                 tvp5150_vbi_get_cap(vbi_ram_default, cap);
877                 break;
878         }
879         case VIDIOC_S_FMT:
880         {
881                 struct v4l2_format *fmt;
882                 struct v4l2_sliced_vbi_format *svbi;
883                 int i;
884 
885                 fmt = arg;
886                 if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
887                         return -EINVAL;
888                 svbi = &fmt->fmt.sliced;
889                 if (svbi->service_set != 0) {
890                         for (i = 0; i <= 23; i++) {
891                                 svbi->service_lines[1][i] = 0;
892 
893                                 svbi->service_lines[0][i]=tvp5150_set_vbi(c,
894                                          vbi_ram_default,
895                                          svbi->service_lines[0][i],0xf0,i,3);
896                         }
897                         /* Enables FIFO */
898                         tvp5150_write(c, TVP5150_FIFO_OUT_CTRL,1);
899                 } else {
900                         /* Disables FIFO*/
901                         tvp5150_write(c, TVP5150_FIFO_OUT_CTRL,0);
902 
903                         /* Disable Full Field */
904                         tvp5150_write(c, TVP5150_FULL_FIELD_ENA, 0);
905 
906                         /* Disable Line modes */
907                         for (i=TVP5150_LINE_MODE_INI; i<=TVP5150_LINE_MODE_END; i++)
908                                 tvp5150_write(c, i, 0xff);
909                 }
910                 break;
911         }
912         case VIDIOC_G_FMT:
913         {
914                 struct v4l2_format *fmt;
915                 struct v4l2_sliced_vbi_format *svbi;
916 
917                 int i, mask=0;
918 
919                 fmt = arg;
920                 if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
921                         return -EINVAL;
922                 svbi = &fmt->fmt.sliced;
923                 memset(svbi, 0, sizeof(*svbi));
924 
925                 for (i = 0; i <= 23; i++) {
926                         svbi->service_lines[0][i]=tvp5150_get_vbi(c,
927                                 vbi_ram_default,i);
928                         mask|=svbi->service_lines[0][i];
929                 }
930                 svbi->service_set=mask;
931                 break;
932         }
933 
934 #ifdef CONFIG_VIDEO_ADV_DEBUG
935         case VIDIOC_INT_G_REGISTER:
936         {
937                 struct v4l2_register *reg = arg;
938 
939                 if (reg->i2c_id != I2C_DRIVERID_TVP5150)
940                         return -EINVAL;
941                 reg->val = tvp5150_read(c, reg->reg & 0xff);
942                 break;
943         }
944 
945         case VIDIOC_INT_S_REGISTER:
946         {
947                 struct v4l2_register *reg = arg;
948 
949                 if (reg->i2c_id != I2C_DRIVERID_TVP5150)
950                         return -EINVAL;
951                 if (!capable(CAP_SYS_ADMIN))
952                         return -EPERM;
953                 tvp5150_write(c, reg->reg & 0xff, reg->val & 0xff);
954                 break;
955         }
956 #endif
957 
958         case VIDIOC_LOG_STATUS:
959                 dump_reg(c);
960                 break;
961 
962         case VIDIOC_G_TUNER:
963                 {
964                         struct v4l2_tuner *vt = arg;
965                         int status = tvp5150_read(c, 0x88);
966 
967                         vt->signal = ((status & 0x04) && (status & 0x02)) ? 0xffff : 0x0;
968                         break;
969                 }
970         case VIDIOC_QUERYCTRL:
971                 {
972                         struct v4l2_queryctrl *qc = arg;
973                         int i;
974 
975                         tvp5150_dbg(1, "VIDIOC_QUERYCTRL called\n");
976 
977                         for (i = 0; i < ARRAY_SIZE(tvp5150_qctrl); i++)
978                                 if (qc->id && qc->id == tvp5150_qctrl[i].id) {
979                                         memcpy(qc, &(tvp5150_qctrl[i]),
980                                                sizeof(*qc));
981                                         return 0;
982                                 }
983 
984                         return -EINVAL;
985                 }
986         case VIDIOC_G_CTRL:
987                 {
988                         struct v4l2_control *ctrl = arg;
989                         tvp5150_dbg(1, "VIDIOC_G_CTRL called\n");
990 
991                         return tvp5150_get_ctrl(c, ctrl);
992                 }
993         case VIDIOC_S_CTRL:
994                 {
995                         struct v4l2_control *ctrl = arg;
996                         u8 i, n;
997                         n = sizeof(tvp5150_qctrl) / sizeof(tvp5150_qctrl[0]);
998                         for (i = 0; i < n; i++)
999                                 if (ctrl->id == tvp5150_qctrl[i].id) {
1000                                         if (ctrl->value <
1001                                             tvp5150_qctrl[i].minimum
1002                                             || ctrl->value >
1003                                             tvp5150_qctrl[i].maximum)
1004                                                 return -ERANGE;
1005                                         tvp5150_dbg(1,
1006                                                 "VIDIOC_S_CTRL: id=%d, value=%d\n",
1007                                                 ctrl->id, ctrl->value);
1008                                         return tvp5150_set_ctrl(c, ctrl);
1009                                 }
1010                         return -EINVAL;
1011                 }
1012 
1013         default:
1014                 return -EINVAL;
1015         }
1016 
1017         return 0;
1018 }
1019 
1020 /****************************************************************************
1021                         I2C Client & Driver
1022  ****************************************************************************/
1023 static struct i2c_driver driver;
1024 
1025 static struct i2c_client client_template = {
1026         .name = "(unset)",
1027         .driver = &driver,
1028 };
1029 
1030 static int tvp5150_detect_client(struct i2c_adapter *adapter,
1031                                  int address, int kind)
1032 {
1033         struct i2c_client *c;
1034         struct tvp5150 *core;
1035         int rv;
1036 
1037         if (debug)
1038                 printk( KERN_INFO
1039                 "tvp5150.c: detecting tvp5150 client on address 0x%x\n",
1040                 address << 1);
1041 
1042         client_template.adapter = adapter;
1043         client_template.addr = address;
1044 
1045         /* Check if the adapter supports the needed features */
1046         if (!i2c_check_functionality
1047             (adapter,
1048              I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
1049                 return 0;
1050 
1051         c = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
1052         if (c == 0)
1053                 return -ENOMEM;
1054         memcpy(c, &client_template, sizeof(struct i2c_client));
1055 
1056         core = kzalloc(sizeof(struct tvp5150), GFP_KERNEL);
1057         if (core == 0) {
1058                 kfree(c);
1059                 return -ENOMEM;
1060         }
1061         i2c_set_clientdata(c, core);
1062 
1063         rv = i2c_attach_client(c);
1064 
1065         core->norm = V4L2_STD_ALL;      /* Default is autodetect */
1066         core->input = 2;
1067         core->enable = 1;
1068         core->bright = 32768;
1069         core->contrast = 32768;
1070         core->hue = 32768;
1071         core->sat = 32768;
1072 
1073         if (rv) {
1074                 kfree(c);
1075                 kfree(core);
1076                 return rv;
1077         }
1078 
1079         if (debug > 1)
1080                 dump_reg(c);
1081         return 0;
1082 }
1083 
1084 static int tvp5150_attach_adapter(struct i2c_adapter *adapter)
1085 {
1086         if (debug)
1087                 printk( KERN_INFO
1088                 "tvp5150.c: starting probe for adapter %s (0x%x)\n",
1089                 adapter->name, adapter->id);
1090         return i2c_probe(adapter, &addr_data, &tvp5150_detect_client);
1091 }
1092 
1093 static int tvp5150_detach_client(struct i2c_client *c)
1094 {
1095         struct tvp5150 *decoder = i2c_get_clientdata(c);
1096         int err;
1097 
1098         tvp5150_dbg(1,
1099                 "tvp5150.c: removing tvp5150 adapter on address 0x%x\n",
1100                 c->addr << 1);
1101 
1102         err = i2c_detach_client(c);
1103         if (err) {
1104                 return err;
1105         }
1106 
1107         kfree(decoder);
1108         kfree(c);
1109 
1110         return 0;
1111 }
1112 
1113 /* ----------------------------------------------------------------------- */
1114 
1115 static struct i2c_driver driver = {
1116         .driver = {
1117                 .name = "tvp5150",
1118         },
1119         .id = I2C_DRIVERID_TVP5150,
1120 
1121         .attach_adapter = tvp5150_attach_adapter,
1122         .detach_client = tvp5150_detach_client,
1123 
1124         .command = tvp5150_command,
1125 };
1126 
1127 static int __init tvp5150_init(void)
1128 {
1129         return i2c_add_driver(&driver);
1130 }
1131 
1132 static void __exit tvp5150_exit(void)
1133 {
1134         i2c_del_driver(&driver);
1135 }
1136 
1137 module_init(tvp5150_init);
1138 module_exit(tvp5150_exit);
1139 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -