1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2005-2006 Micronas USA Inc.
6 #include <linux/module.h>
7 #include <linux/init.h>
9 #include <linux/videodev2.h>
10 #include <media/v4l2-device.h>
11 #include <media/i2c/uda1342.h>
12 #include <linux/slab.h>
14 static int write_reg(struct i2c_client
*client
, int reg
, int value
)
16 /* UDA1342 wants MSB first, but SMBus sends LSB first */
17 i2c_smbus_write_word_data(client
, reg
, swab16(value
));
21 static int uda1342_s_routing(struct v4l2_subdev
*sd
,
22 u32 input
, u32 output
, u32 config
)
24 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
28 write_reg(client
, 0x00, 0x1241); /* select input 1 */
31 write_reg(client
, 0x00, 0x1441); /* select input 2 */
34 v4l2_err(sd
, "input %d not supported\n", input
);
40 static const struct v4l2_subdev_audio_ops uda1342_audio_ops
= {
41 .s_routing
= uda1342_s_routing
,
44 static const struct v4l2_subdev_ops uda1342_ops
= {
45 .audio
= &uda1342_audio_ops
,
48 static int uda1342_probe(struct i2c_client
*client
,
49 const struct i2c_device_id
*id
)
51 struct i2c_adapter
*adapter
= client
->adapter
;
52 struct v4l2_subdev
*sd
;
54 if (!i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_WORD_DATA
))
57 dev_dbg(&client
->dev
, "initializing UDA1342 at address %d on %s\n",
58 client
->addr
, adapter
->name
);
60 sd
= devm_kzalloc(&client
->dev
, sizeof(*sd
), GFP_KERNEL
);
64 v4l2_i2c_subdev_init(sd
, client
, &uda1342_ops
);
66 write_reg(client
, 0x00, 0x8000); /* reset registers */
67 write_reg(client
, 0x00, 0x1241); /* select input 1 */
69 v4l_info(client
, "chip found @ 0x%02x (%s)\n",
70 client
->addr
<< 1, client
->adapter
->name
);
75 static int uda1342_remove(struct i2c_client
*client
)
77 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
79 v4l2_device_unregister_subdev(sd
);
83 static const struct i2c_device_id uda1342_id
[] = {
87 MODULE_DEVICE_TABLE(i2c
, uda1342_id
);
89 static struct i2c_driver uda1342_driver
= {
93 .probe
= uda1342_probe
,
94 .remove
= uda1342_remove
,
95 .id_table
= uda1342_id
,
98 module_i2c_driver(uda1342_driver
);
100 MODULE_LICENSE("GPL v2");