Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright (C) 2005-2006 Micronas USA Inc.
0004  */
0005 
0006 #include <linux/module.h>
0007 #include <linux/init.h>
0008 #include <linux/i2c.h>
0009 #include <linux/videodev2.h>
0010 #include <media/v4l2-device.h>
0011 #include <media/i2c/uda1342.h>
0012 #include <linux/slab.h>
0013 
0014 static int write_reg(struct i2c_client *client, int reg, int value)
0015 {
0016     /* UDA1342 wants MSB first, but SMBus sends LSB first */
0017     i2c_smbus_write_word_data(client, reg, swab16(value));
0018     return 0;
0019 }
0020 
0021 static int uda1342_s_routing(struct v4l2_subdev *sd,
0022         u32 input, u32 output, u32 config)
0023 {
0024     struct i2c_client *client = v4l2_get_subdevdata(sd);
0025 
0026     switch (input) {
0027     case UDA1342_IN1:
0028         write_reg(client, 0x00, 0x1241); /* select input 1 */
0029         break;
0030     case UDA1342_IN2:
0031         write_reg(client, 0x00, 0x1441); /* select input 2 */
0032         break;
0033     default:
0034         v4l2_err(sd, "input %d not supported\n", input);
0035         break;
0036     }
0037     return 0;
0038 }
0039 
0040 static const struct v4l2_subdev_audio_ops uda1342_audio_ops = {
0041     .s_routing = uda1342_s_routing,
0042 };
0043 
0044 static const struct v4l2_subdev_ops uda1342_ops = {
0045     .audio = &uda1342_audio_ops,
0046 };
0047 
0048 static int uda1342_probe(struct i2c_client *client,
0049                  const struct i2c_device_id *id)
0050 {
0051     struct i2c_adapter *adapter = client->adapter;
0052     struct v4l2_subdev *sd;
0053 
0054     if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA))
0055         return -ENODEV;
0056 
0057     dev_dbg(&client->dev, "initializing UDA1342 at address %d on %s\n",
0058         client->addr, adapter->name);
0059 
0060     sd = devm_kzalloc(&client->dev, sizeof(*sd), GFP_KERNEL);
0061     if (sd == NULL)
0062         return -ENOMEM;
0063 
0064     v4l2_i2c_subdev_init(sd, client, &uda1342_ops);
0065 
0066     write_reg(client, 0x00, 0x8000); /* reset registers */
0067     write_reg(client, 0x00, 0x1241); /* select input 1 */
0068 
0069     v4l_info(client, "chip found @ 0x%02x (%s)\n",
0070             client->addr << 1, client->adapter->name);
0071 
0072     return 0;
0073 }
0074 
0075 static int uda1342_remove(struct i2c_client *client)
0076 {
0077     struct v4l2_subdev *sd = i2c_get_clientdata(client);
0078 
0079     v4l2_device_unregister_subdev(sd);
0080     return 0;
0081 }
0082 
0083 static const struct i2c_device_id uda1342_id[] = {
0084     { "uda1342", 0 },
0085     { }
0086 };
0087 MODULE_DEVICE_TABLE(i2c, uda1342_id);
0088 
0089 static struct i2c_driver uda1342_driver = {
0090     .driver = {
0091         .name   = "uda1342",
0092     },
0093     .probe      = uda1342_probe,
0094     .remove     = uda1342_remove,
0095     .id_table   = uda1342_id,
0096 };
0097 
0098 module_i2c_driver(uda1342_driver);
0099 
0100 MODULE_LICENSE("GPL v2");