0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #include <linux/module.h>
0020 #include <linux/ioctl.h>
0021 #include <linux/slab.h>
0022 #include <linux/i2c.h>
0023 #include <media/v4l2-device.h>
0024 #include "tea6415c.h"
0025
0026 MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
0027 MODULE_DESCRIPTION("tea6415c driver");
0028 MODULE_LICENSE("GPL");
0029
0030 static int debug;
0031 module_param(debug, int, 0644);
0032
0033 MODULE_PARM_DESC(debug, "Debug level (0-1)");
0034
0035
0036
0037 static int tea6415c_s_routing(struct v4l2_subdev *sd,
0038 u32 i, u32 o, u32 config)
0039 {
0040 struct i2c_client *client = v4l2_get_subdevdata(sd);
0041 u8 byte = 0;
0042 int ret;
0043
0044 v4l2_dbg(1, debug, sd, "i=%d, o=%d\n", i, o);
0045
0046
0047 if (0 == ((1 == i || 3 == i || 5 == i || 6 == i || 8 == i || 10 == i || 20 == i || 11 == i)
0048 && (18 == o || 17 == o || 16 == o || 15 == o || 14 == o || 13 == o)))
0049 return -EINVAL;
0050
0051
0052 switch (o) {
0053 case 18:
0054 byte = 0x00;
0055 break;
0056 case 14:
0057 byte = 0x20;
0058 break;
0059 case 16:
0060 byte = 0x10;
0061 break;
0062 case 17:
0063 byte = 0x08;
0064 break;
0065 case 15:
0066 byte = 0x18;
0067 break;
0068 case 13:
0069 byte = 0x28;
0070 break;
0071 }
0072
0073 switch (i) {
0074 case 5:
0075 byte |= 0x00;
0076 break;
0077 case 8:
0078 byte |= 0x04;
0079 break;
0080 case 3:
0081 byte |= 0x02;
0082 break;
0083 case 20:
0084 byte |= 0x06;
0085 break;
0086 case 6:
0087 byte |= 0x01;
0088 break;
0089 case 10:
0090 byte |= 0x05;
0091 break;
0092 case 1:
0093 byte |= 0x03;
0094 break;
0095 case 11:
0096 byte |= 0x07;
0097 break;
0098 }
0099
0100 ret = i2c_smbus_write_byte(client, byte);
0101 if (ret) {
0102 v4l2_dbg(1, debug, sd,
0103 "i2c_smbus_write_byte() failed, ret:%d\n", ret);
0104 return -EIO;
0105 }
0106 return ret;
0107 }
0108
0109
0110
0111 static const struct v4l2_subdev_video_ops tea6415c_video_ops = {
0112 .s_routing = tea6415c_s_routing,
0113 };
0114
0115 static const struct v4l2_subdev_ops tea6415c_ops = {
0116 .video = &tea6415c_video_ops,
0117 };
0118
0119 static int tea6415c_probe(struct i2c_client *client,
0120 const struct i2c_device_id *id)
0121 {
0122 struct v4l2_subdev *sd;
0123
0124
0125 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WRITE_BYTE))
0126 return -EIO;
0127
0128 v4l_info(client, "chip found @ 0x%x (%s)\n",
0129 client->addr << 1, client->adapter->name);
0130 sd = devm_kzalloc(&client->dev, sizeof(*sd), GFP_KERNEL);
0131 if (sd == NULL)
0132 return -ENOMEM;
0133 v4l2_i2c_subdev_init(sd, client, &tea6415c_ops);
0134 return 0;
0135 }
0136
0137 static int tea6415c_remove(struct i2c_client *client)
0138 {
0139 struct v4l2_subdev *sd = i2c_get_clientdata(client);
0140
0141 v4l2_device_unregister_subdev(sd);
0142 return 0;
0143 }
0144
0145 static const struct i2c_device_id tea6415c_id[] = {
0146 { "tea6415c", 0 },
0147 { }
0148 };
0149 MODULE_DEVICE_TABLE(i2c, tea6415c_id);
0150
0151 static struct i2c_driver tea6415c_driver = {
0152 .driver = {
0153 .name = "tea6415c",
0154 },
0155 .probe = tea6415c_probe,
0156 .remove = tea6415c_remove,
0157 .id_table = tea6415c_id,
0158 };
0159
0160 module_i2c_driver(tea6415c_driver);