2 * Copyright (C) 2005-2006 Micronas USA Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License (Version 2) as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
18 #include <linux/module.h>
19 #include <linux/init.h>
20 #include <linux/i2c.h>
21 #include <linux/videodev2.h>
22 #include <media/tvaudio.h>
23 #include <media/v4l2-common.h>
27 static int write_reg(struct i2c_client *client, int reg, int value)
29 /* UDA1342 wants MSB first, but SMBus sends LSB first */
30 i2c_smbus_write_word_data(client, reg, swab16(value));
34 static int wis_uda1342_command(struct i2c_client *client,
35 unsigned int cmd, void *arg)
43 case TVAUDIO_INPUT_TUNER:
44 write_reg(client, 0x00, 0x1441); /* select input 2 */
46 case TVAUDIO_INPUT_EXTERN:
47 write_reg(client, 0x00, 0x1241); /* select input 1 */
50 printk(KERN_ERR "wis-uda1342: input %d not supported\n",
62 static struct i2c_driver wis_uda1342_driver;
64 static struct i2c_client wis_uda1342_client_templ = {
65 .name = "UDA1342 (WIS)",
66 .driver = &wis_uda1342_driver,
69 static int wis_uda1342_detect(struct i2c_adapter *adapter, int addr, int kind)
71 struct i2c_client *client;
73 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA))
76 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
79 memcpy(client, &wis_uda1342_client_templ,
80 sizeof(wis_uda1342_client_templ));
81 client->adapter = adapter;
85 "wis-uda1342: initializing UDA1342 at address %d on %s\n",
88 write_reg(client, 0x00, 0x8000); /* reset registers */
89 write_reg(client, 0x00, 0x1241); /* select input 1 */
91 i2c_attach_client(client);
95 static int wis_uda1342_detach(struct i2c_client *client)
99 r = i2c_detach_client(client);
107 static struct i2c_driver wis_uda1342_driver = {
109 .name = "WIS UDA1342 I2C driver",
111 .id = I2C_DRIVERID_WIS_UDA1342,
112 .detach_client = wis_uda1342_detach,
113 .command = wis_uda1342_command,
116 static int __init wis_uda1342_init(void)
120 r = i2c_add_driver(&wis_uda1342_driver);
123 return wis_i2c_add_driver(wis_uda1342_driver.id, wis_uda1342_detect);
126 static void __exit wis_uda1342_cleanup(void)
128 wis_i2c_del_driver(wis_uda1342_detect);
129 i2c_del_driver(&wis_uda1342_driver);
132 module_init(wis_uda1342_init);
133 module_exit(wis_uda1342_cleanup);
135 MODULE_LICENSE("GPL v2");