Merge tag 'regmap-fix-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux/fpc-iii.git] / drivers / media / i2c / uda1342.c
blobb0a9c6d7163fe21197b96aaab92c4bf688022b4f
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2005-2006 Micronas USA Inc.
4 */
6 #include <linux/module.h>
7 #include <linux/init.h>
8 #include <linux/i2c.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));
18 return 0;
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);
26 switch (input) {
27 case UDA1342_IN1:
28 write_reg(client, 0x00, 0x1241); /* select input 1 */
29 break;
30 case UDA1342_IN2:
31 write_reg(client, 0x00, 0x1441); /* select input 2 */
32 break;
33 default:
34 v4l2_err(sd, "input %d not supported\n", input);
35 break;
37 return 0;
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))
55 return -ENODEV;
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);
61 if (sd == NULL)
62 return -ENOMEM;
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);
72 return 0;
75 static int uda1342_remove(struct i2c_client *client)
77 struct v4l2_subdev *sd = i2c_get_clientdata(client);
79 v4l2_device_unregister_subdev(sd);
80 return 0;
83 static const struct i2c_device_id uda1342_id[] = {
84 { "uda1342", 0 },
85 { }
87 MODULE_DEVICE_TABLE(i2c, uda1342_id);
89 static struct i2c_driver uda1342_driver = {
90 .driver = {
91 .name = "uda1342",
93 .probe = uda1342_probe,
94 .remove = uda1342_remove,
95 .id_table = uda1342_id,
98 module_i2c_driver(uda1342_driver);
100 MODULE_LICENSE("GPL v2");