1 // SPDX-License-Identifier: GPL-2.0-or-later
3 tea6420 - i2c-driver for the tea6420 by SGS Thomson
5 Copyright (C) 1998-2003 Michael Hunold <michael@mihu.de>
6 Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl>
8 The tea6420 is a bus controlled audio-matrix with 5 stereo inputs,
9 4 stereo outputs and gain control for each output.
10 It is cascadable, i.e. it can be found at the addresses 0x98
11 and 0x9a on the i2c-bus.
13 For detailed information download the specifications directly
14 from SGS Thomson at http://www.st.com
19 #include <linux/module.h>
20 #include <linux/ioctl.h>
21 #include <linux/slab.h>
22 #include <linux/i2c.h>
23 #include <media/v4l2-device.h>
26 MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
27 MODULE_DESCRIPTION("tea6420 driver");
28 MODULE_LICENSE("GPL");
31 module_param(debug
, int, 0644);
33 MODULE_PARM_DESC(debug
, "Debug level (0-1)");
36 /* make a connection between the input 'i' and the output 'o'
37 with gain 'g' (note: i = 6 means 'mute') */
38 static int tea6420_s_routing(struct v4l2_subdev
*sd
,
39 u32 i
, u32 o
, u32 config
)
41 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
42 int g
= (o
>> 4) & 0xf;
47 v4l2_dbg(1, debug
, sd
, "i=%d, o=%d, g=%d\n", i
, o
, g
);
49 /* check if the parameters are valid */
50 if (i
< 1 || i
> 6 || o
< 1 || o
> 4 || g
< 0 || g
> 6 || g
% 2 != 0)
53 byte
= ((o
- 1) << 5);
56 /* to understand this, have a look at the tea6420-specs (p.5) */
71 ret
= i2c_smbus_write_byte(client
, byte
);
73 v4l2_dbg(1, debug
, sd
,
74 "i2c_smbus_write_byte() failed, ret:%d\n", ret
);
80 /* ----------------------------------------------------------------------- */
82 static const struct v4l2_subdev_audio_ops tea6420_audio_ops
= {
83 .s_routing
= tea6420_s_routing
,
86 static const struct v4l2_subdev_ops tea6420_ops
= {
87 .audio
= &tea6420_audio_ops
,
90 static int tea6420_probe(struct i2c_client
*client
,
91 const struct i2c_device_id
*id
)
93 struct v4l2_subdev
*sd
;
96 /* let's see whether this adapter can support what we need */
97 if (!i2c_check_functionality(client
->adapter
, I2C_FUNC_SMBUS_WRITE_BYTE
))
100 v4l_info(client
, "chip found @ 0x%x (%s)\n",
101 client
->addr
<< 1, client
->adapter
->name
);
103 sd
= devm_kzalloc(&client
->dev
, sizeof(*sd
), GFP_KERNEL
);
106 v4l2_i2c_subdev_init(sd
, client
, &tea6420_ops
);
108 /* set initial values: set "mute"-input to all outputs at gain 0 */
110 for (i
= 1; i
< 5; i
++)
111 err
+= tea6420_s_routing(sd
, 6, i
, 0);
113 v4l_dbg(1, debug
, client
, "could not initialize tea6420\n");
119 static int tea6420_remove(struct i2c_client
*client
)
121 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
123 v4l2_device_unregister_subdev(sd
);
127 static const struct i2c_device_id tea6420_id
[] = {
131 MODULE_DEVICE_TABLE(i2c
, tea6420_id
);
133 static struct i2c_driver tea6420_driver
= {
137 .probe
= tea6420_probe
,
138 .remove
= tea6420_remove
,
139 .id_table
= tea6420_id
,
142 module_i2c_driver(tea6420_driver
);