Linux 4.16.11
[linux/fpc-iii.git] / drivers / media / i2c / cs3308.c
blob7da5f69cace66862fdd966319c418054836d016e
1 /*
2 * Cirrus Logic cs3308 8-Channel Analog Volume Control
4 * Copyright (C) 2010 Devin Heitmueller <dheitmueller@kernellabs.com>
5 * Copyright (C) 2012 Steven Toth <stoth@kernellabs.com>
7 * Derived from cs5345.c Copyright (C) 2007 Hans Verkuil
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
21 #include <linux/module.h>
22 #include <linux/kernel.h>
23 #include <linux/i2c.h>
24 #include <linux/slab.h>
25 #include <linux/videodev2.h>
26 #include <media/v4l2-device.h>
28 MODULE_DESCRIPTION("i2c device driver for cs3308 8-channel volume control");
29 MODULE_AUTHOR("Devin Heitmueller");
30 MODULE_LICENSE("GPL");
32 static inline int cs3308_write(struct v4l2_subdev *sd, u8 reg, u8 value)
34 struct i2c_client *client = v4l2_get_subdevdata(sd);
36 return i2c_smbus_write_byte_data(client, reg, value);
39 static inline int cs3308_read(struct v4l2_subdev *sd, u8 reg)
41 struct i2c_client *client = v4l2_get_subdevdata(sd);
43 return i2c_smbus_read_byte_data(client, reg);
46 #ifdef CONFIG_VIDEO_ADV_DEBUG
47 static int cs3308_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
49 reg->val = cs3308_read(sd, reg->reg & 0xffff);
50 reg->size = 1;
51 return 0;
54 static int cs3308_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
56 cs3308_write(sd, reg->reg & 0xffff, reg->val & 0xff);
57 return 0;
59 #endif
61 /* ----------------------------------------------------------------------- */
63 static const struct v4l2_subdev_core_ops cs3308_core_ops = {
64 #ifdef CONFIG_VIDEO_ADV_DEBUG
65 .g_register = cs3308_g_register,
66 .s_register = cs3308_s_register,
67 #endif
70 static const struct v4l2_subdev_ops cs3308_ops = {
71 .core = &cs3308_core_ops,
74 /* ----------------------------------------------------------------------- */
76 static int cs3308_probe(struct i2c_client *client,
77 const struct i2c_device_id *id)
79 struct v4l2_subdev *sd;
80 unsigned i;
82 /* Check if the adapter supports the needed features */
83 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
84 return -EIO;
86 if ((i2c_smbus_read_byte_data(client, 0x1c) & 0xf0) != 0xe0)
87 return -ENODEV;
89 v4l_info(client, "chip found @ 0x%x (%s)\n",
90 client->addr << 1, client->adapter->name);
92 sd = kzalloc(sizeof(struct v4l2_subdev), GFP_KERNEL);
93 if (sd == NULL)
94 return -ENOMEM;
96 v4l2_i2c_subdev_init(sd, client, &cs3308_ops);
98 /* Set some reasonable defaults */
99 cs3308_write(sd, 0x0d, 0x00); /* Power up all channels */
100 cs3308_write(sd, 0x0e, 0x00); /* Master Power */
101 cs3308_write(sd, 0x0b, 0x00); /* Device Configuration */
102 /* Set volume for each channel */
103 for (i = 1; i <= 8; i++)
104 cs3308_write(sd, i, 0xd2);
105 cs3308_write(sd, 0x0a, 0x00); /* Unmute all channels */
106 return 0;
109 /* ----------------------------------------------------------------------- */
111 static int cs3308_remove(struct i2c_client *client)
113 struct v4l2_subdev *sd = i2c_get_clientdata(client);
115 v4l2_device_unregister_subdev(sd);
116 kfree(sd);
117 return 0;
120 /* ----------------------------------------------------------------------- */
122 static const struct i2c_device_id cs3308_id[] = {
123 { "cs3308", 0 },
126 MODULE_DEVICE_TABLE(i2c, cs3308_id);
128 static struct i2c_driver cs3308_driver = {
129 .driver = {
130 .name = "cs3308",
132 .probe = cs3308_probe,
133 .remove = cs3308_remove,
134 .id_table = cs3308_id,
137 module_i2c_driver(cs3308_driver);