Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / media / i2c / uda1342.c
blob2e4540ee2df2dd81497d033843c164e2b7618599
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)
50 struct i2c_adapter *adapter = client->adapter;
51 struct v4l2_subdev *sd;
53 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA))
54 return -ENODEV;
56 dev_dbg(&client->dev, "initializing UDA1342 at address %d on %s\n",
57 client->addr, adapter->name);
59 sd = devm_kzalloc(&client->dev, sizeof(*sd), GFP_KERNEL);
60 if (sd == NULL)
61 return -ENOMEM;
63 v4l2_i2c_subdev_init(sd, client, &uda1342_ops);
65 write_reg(client, 0x00, 0x8000); /* reset registers */
66 write_reg(client, 0x00, 0x1241); /* select input 1 */
68 v4l_info(client, "chip found @ 0x%02x (%s)\n",
69 client->addr << 1, client->adapter->name);
71 return 0;
74 static void uda1342_remove(struct i2c_client *client)
76 struct v4l2_subdev *sd = i2c_get_clientdata(client);
78 v4l2_device_unregister_subdev(sd);
81 static const struct i2c_device_id uda1342_id[] = {
82 { "uda1342" },
83 { }
85 MODULE_DEVICE_TABLE(i2c, uda1342_id);
87 static struct i2c_driver uda1342_driver = {
88 .driver = {
89 .name = "uda1342",
91 .probe = uda1342_probe,
92 .remove = uda1342_remove,
93 .id_table = uda1342_id,
96 module_i2c_driver(uda1342_driver);
98 MODULE_DESCRIPTION("Philips UDA1342 audio codec driver");
99 MODULE_LICENSE("GPL v2");