Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005-2006 Micronas USA Inc. |
| 3 | * |
| 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. |
| 7 | * |
| 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. |
| 12 | * |
| 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. |
| 16 | */ |
| 17 | |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/init.h> |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 20 | #include <linux/i2c.h> |
Ross Cohen | df20d69 | 2008-09-29 22:36:24 -0400 | [diff] [blame] | 21 | #include <linux/videodev2.h> |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 22 | #include <media/tvaudio.h> |
| 23 | #include <media/v4l2-common.h> |
| 24 | |
| 25 | #include "wis-i2c.h" |
| 26 | |
| 27 | static int write_reg(struct i2c_client *client, int reg, int value) |
| 28 | { |
| 29 | /* UDA1342 wants MSB first, but SMBus sends LSB first */ |
| 30 | i2c_smbus_write_word_data(client, reg, swab16(value)); |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | static int wis_uda1342_command(struct i2c_client *client, |
| 35 | unsigned int cmd, void *arg) |
| 36 | { |
| 37 | switch (cmd) { |
| 38 | case VIDIOC_S_AUDIO: |
| 39 | { |
| 40 | int *inp = arg; |
| 41 | |
| 42 | switch (*inp) { |
| 43 | case TVAUDIO_INPUT_TUNER: |
| 44 | write_reg(client, 0x00, 0x1441); /* select input 2 */ |
| 45 | break; |
| 46 | case TVAUDIO_INPUT_EXTERN: |
| 47 | write_reg(client, 0x00, 0x1241); /* select input 1 */ |
| 48 | break; |
| 49 | default: |
| 50 | printk(KERN_ERR "wis-uda1342: input %d not supported\n", |
| 51 | *inp); |
| 52 | break; |
| 53 | } |
| 54 | break; |
| 55 | } |
| 56 | default: |
| 57 | break; |
| 58 | } |
| 59 | return 0; |
| 60 | } |
| 61 | |
Jean Delvare | 7400516 | 2009-04-21 21:47:22 +0200 | [diff] [blame] | 62 | static int wis_uda1342_probe(struct i2c_client *client, |
| 63 | const struct i2c_device_id *id) |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 64 | { |
Jean Delvare | 7400516 | 2009-04-21 21:47:22 +0200 | [diff] [blame] | 65 | struct i2c_adapter *adapter = client->adapter; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 66 | |
| 67 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) |
Jean Delvare | 7400516 | 2009-04-21 21:47:22 +0200 | [diff] [blame] | 68 | return -ENODEV; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 69 | |
| 70 | printk(KERN_DEBUG |
| 71 | "wis-uda1342: initializing UDA1342 at address %d on %s\n", |
Jean Delvare | 7400516 | 2009-04-21 21:47:22 +0200 | [diff] [blame] | 72 | client->addr, adapter->name); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 73 | |
| 74 | write_reg(client, 0x00, 0x8000); /* reset registers */ |
| 75 | write_reg(client, 0x00, 0x1241); /* select input 1 */ |
| 76 | |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 77 | return 0; |
| 78 | } |
| 79 | |
Jean Delvare | 7400516 | 2009-04-21 21:47:22 +0200 | [diff] [blame] | 80 | static int wis_uda1342_remove(struct i2c_client *client) |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 81 | { |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 82 | return 0; |
| 83 | } |
| 84 | |
Jean Delvare | 7400516 | 2009-04-21 21:47:22 +0200 | [diff] [blame] | 85 | static struct i2c_device_id wis_uda1342_id[] = { |
| 86 | { "wis_uda1342", 0 }, |
| 87 | { } |
| 88 | }; |
| 89 | |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 90 | static struct i2c_driver wis_uda1342_driver = { |
| 91 | .driver = { |
| 92 | .name = "WIS UDA1342 I2C driver", |
| 93 | }, |
Jean Delvare | 7400516 | 2009-04-21 21:47:22 +0200 | [diff] [blame] | 94 | .probe = wis_uda1342_probe, |
| 95 | .remove = wis_uda1342_remove, |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 96 | .command = wis_uda1342_command, |
Jean Delvare | 7400516 | 2009-04-21 21:47:22 +0200 | [diff] [blame] | 97 | .id_table = wis_uda1342_id, |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | static int __init wis_uda1342_init(void) |
| 101 | { |
Jean Delvare | 7400516 | 2009-04-21 21:47:22 +0200 | [diff] [blame] | 102 | return i2c_add_driver(&wis_uda1342_driver); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | static void __exit wis_uda1342_cleanup(void) |
| 106 | { |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 107 | i2c_del_driver(&wis_uda1342_driver); |
| 108 | } |
| 109 | |
| 110 | module_init(wis_uda1342_init); |
| 111 | module_exit(wis_uda1342_cleanup); |
| 112 | |
| 113 | MODULE_LICENSE("GPL v2"); |