treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / media / i2c / cs3308.c
blobebe55e261bff22227c58278a16b7d3647066c4e6
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Cirrus Logic cs3308 8-Channel Analog Volume Control
5 * Copyright (C) 2010 Devin Heitmueller <dheitmueller@kernellabs.com>
6 * Copyright (C) 2012 Steven Toth <stoth@kernellabs.com>
8 * Derived from cs5345.c Copyright (C) 2007 Hans Verkuil
9 */
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/i2c.h>
15 #include <linux/slab.h>
16 #include <linux/videodev2.h>
17 #include <media/v4l2-device.h>
19 MODULE_DESCRIPTION("i2c device driver for cs3308 8-channel volume control");
20 MODULE_AUTHOR("Devin Heitmueller");
21 MODULE_LICENSE("GPL");
23 static inline int cs3308_write(struct v4l2_subdev *sd, u8 reg, u8 value)
25 struct i2c_client *client = v4l2_get_subdevdata(sd);
27 return i2c_smbus_write_byte_data(client, reg, value);
30 static inline int cs3308_read(struct v4l2_subdev *sd, u8 reg)
32 struct i2c_client *client = v4l2_get_subdevdata(sd);
34 return i2c_smbus_read_byte_data(client, reg);
37 #ifdef CONFIG_VIDEO_ADV_DEBUG
38 static int cs3308_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
40 reg->val = cs3308_read(sd, reg->reg & 0xffff);
41 reg->size = 1;
42 return 0;
45 static int cs3308_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
47 cs3308_write(sd, reg->reg & 0xffff, reg->val & 0xff);
48 return 0;
50 #endif
52 /* ----------------------------------------------------------------------- */
54 static const struct v4l2_subdev_core_ops cs3308_core_ops = {
55 #ifdef CONFIG_VIDEO_ADV_DEBUG
56 .g_register = cs3308_g_register,
57 .s_register = cs3308_s_register,
58 #endif
61 static const struct v4l2_subdev_ops cs3308_ops = {
62 .core = &cs3308_core_ops,
65 /* ----------------------------------------------------------------------- */
67 static int cs3308_probe(struct i2c_client *client,
68 const struct i2c_device_id *id)
70 struct v4l2_subdev *sd;
71 unsigned i;
73 /* Check if the adapter supports the needed features */
74 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
75 return -EIO;
77 if ((i2c_smbus_read_byte_data(client, 0x1c) & 0xf0) != 0xe0)
78 return -ENODEV;
80 v4l_info(client, "chip found @ 0x%x (%s)\n",
81 client->addr << 1, client->adapter->name);
83 sd = kzalloc(sizeof(struct v4l2_subdev), GFP_KERNEL);
84 if (sd == NULL)
85 return -ENOMEM;
87 v4l2_i2c_subdev_init(sd, client, &cs3308_ops);
89 /* Set some reasonable defaults */
90 cs3308_write(sd, 0x0d, 0x00); /* Power up all channels */
91 cs3308_write(sd, 0x0e, 0x00); /* Master Power */
92 cs3308_write(sd, 0x0b, 0x00); /* Device Configuration */
93 /* Set volume for each channel */
94 for (i = 1; i <= 8; i++)
95 cs3308_write(sd, i, 0xd2);
96 cs3308_write(sd, 0x0a, 0x00); /* Unmute all channels */
97 return 0;
100 /* ----------------------------------------------------------------------- */
102 static int cs3308_remove(struct i2c_client *client)
104 struct v4l2_subdev *sd = i2c_get_clientdata(client);
106 v4l2_device_unregister_subdev(sd);
107 kfree(sd);
108 return 0;
111 /* ----------------------------------------------------------------------- */
113 static const struct i2c_device_id cs3308_id[] = {
114 { "cs3308", 0 },
117 MODULE_DEVICE_TABLE(i2c, cs3308_id);
119 static struct i2c_driver cs3308_driver = {
120 .driver = {
121 .name = "cs3308",
123 .probe = cs3308_probe,
124 .remove = cs3308_remove,
125 .id_table = cs3308_id,
128 module_i2c_driver(cs3308_driver);