0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/module.h>
0013 #include <linux/kernel.h>
0014 #include <linux/i2c.h>
0015 #include <linux/slab.h>
0016 #include <linux/videodev2.h>
0017 #include <media/v4l2-device.h>
0018
0019 MODULE_DESCRIPTION("i2c device driver for cs3308 8-channel volume control");
0020 MODULE_AUTHOR("Devin Heitmueller");
0021 MODULE_LICENSE("GPL");
0022
0023 static inline int cs3308_write(struct v4l2_subdev *sd, u8 reg, u8 value)
0024 {
0025 struct i2c_client *client = v4l2_get_subdevdata(sd);
0026
0027 return i2c_smbus_write_byte_data(client, reg, value);
0028 }
0029
0030 static inline int cs3308_read(struct v4l2_subdev *sd, u8 reg)
0031 {
0032 struct i2c_client *client = v4l2_get_subdevdata(sd);
0033
0034 return i2c_smbus_read_byte_data(client, reg);
0035 }
0036
0037 #ifdef CONFIG_VIDEO_ADV_DEBUG
0038 static int cs3308_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
0039 {
0040 reg->val = cs3308_read(sd, reg->reg & 0xffff);
0041 reg->size = 1;
0042 return 0;
0043 }
0044
0045 static int cs3308_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
0046 {
0047 cs3308_write(sd, reg->reg & 0xffff, reg->val & 0xff);
0048 return 0;
0049 }
0050 #endif
0051
0052
0053
0054 static const struct v4l2_subdev_core_ops cs3308_core_ops = {
0055 #ifdef CONFIG_VIDEO_ADV_DEBUG
0056 .g_register = cs3308_g_register,
0057 .s_register = cs3308_s_register,
0058 #endif
0059 };
0060
0061 static const struct v4l2_subdev_ops cs3308_ops = {
0062 .core = &cs3308_core_ops,
0063 };
0064
0065
0066
0067 static int cs3308_probe(struct i2c_client *client,
0068 const struct i2c_device_id *id)
0069 {
0070 struct v4l2_subdev *sd;
0071 unsigned i;
0072
0073
0074 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
0075 return -EIO;
0076
0077 if ((i2c_smbus_read_byte_data(client, 0x1c) & 0xf0) != 0xe0)
0078 return -ENODEV;
0079
0080 v4l_info(client, "chip found @ 0x%x (%s)\n",
0081 client->addr << 1, client->adapter->name);
0082
0083 sd = kzalloc(sizeof(struct v4l2_subdev), GFP_KERNEL);
0084 if (sd == NULL)
0085 return -ENOMEM;
0086
0087 v4l2_i2c_subdev_init(sd, client, &cs3308_ops);
0088
0089
0090 cs3308_write(sd, 0x0d, 0x00);
0091 cs3308_write(sd, 0x0e, 0x00);
0092 cs3308_write(sd, 0x0b, 0x00);
0093
0094 for (i = 1; i <= 8; i++)
0095 cs3308_write(sd, i, 0xd2);
0096 cs3308_write(sd, 0x0a, 0x00);
0097 return 0;
0098 }
0099
0100
0101
0102 static int cs3308_remove(struct i2c_client *client)
0103 {
0104 struct v4l2_subdev *sd = i2c_get_clientdata(client);
0105
0106 v4l2_device_unregister_subdev(sd);
0107 kfree(sd);
0108 return 0;
0109 }
0110
0111
0112
0113 static const struct i2c_device_id cs3308_id[] = {
0114 { "cs3308", 0 },
0115 { }
0116 };
0117 MODULE_DEVICE_TABLE(i2c, cs3308_id);
0118
0119 static struct i2c_driver cs3308_driver = {
0120 .driver = {
0121 .name = "cs3308",
0122 },
0123 .probe = cs3308_probe,
0124 .remove = cs3308_remove,
0125 .id_table = cs3308_id,
0126 };
0127
0128 module_i2c_driver(cs3308_driver);