aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/tea6415c.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/media/video/tea6415c.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/media/video/tea6415c.c')
-rw-r--r--drivers/media/video/tea6415c.c223
1 files changed, 223 insertions, 0 deletions
diff --git a/drivers/media/video/tea6415c.c b/drivers/media/video/tea6415c.c
new file mode 100644
index 000000000000..3ec39550bf46
--- /dev/null
+++ b/drivers/media/video/tea6415c.c
@@ -0,0 +1,223 @@
1 /*
2 tea6415c - i2c-driver for the tea6415c by SGS Thomson
3
4 Copyright (C) 1998-2003 Michael Hunold <michael@mihu.de>
5
6 The tea6415c is a bus controlled video-matrix-switch
7 with 8 inputs and 6 outputs.
8 It is cascadable, i.e. it can be found at the addresses
9 0x86 and 0x06 on the i2c-bus.
10
11 For detailed informations download the specifications directly
12 from SGS Thomson at http://www.st.com
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License vs published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 675 Mvss Ave, Cambridge, MA 02139, USA.
27 */
28
29#include <linux/module.h>
30#include <linux/ioctl.h>
31#include <linux/i2c.h>
32
33#include "tea6415c.h"
34
35static int debug = 0; /* insmod parameter */
36module_param(debug, int, 0644);
37MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off).");
38#define dprintk(args...) \
39 do { if (debug) { printk("%s: %s()[%d]: ",__stringify(KBUILD_MODNAME), __FUNCTION__, __LINE__); printk(args); } } while (0)
40
41#define TEA6415C_NUM_INPUTS 8
42#define TEA6415C_NUM_OUTPUTS 6
43
44/* addresses to scan, found only at 0x03 and/or 0x43 (7-bit) */
45static unsigned short normal_i2c[] = { I2C_TEA6415C_1, I2C_TEA6415C_2, I2C_CLIENT_END };
46static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
47
48/* magic definition of all other variables and things */
49I2C_CLIENT_INSMOD;
50
51static struct i2c_driver driver;
52static struct i2c_client client_template;
53
54/* this function is called by i2c_probe */
55static int detect(struct i2c_adapter *adapter, int address, int kind)
56{
57 struct i2c_client *client = NULL;
58 int err = 0;
59
60 /* let's see whether this adapter can support what we need */
61 if (0 == i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE)) {
62 return 0;
63 }
64
65 /* allocate memory for client structure */
66 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
67 if (0 == client) {
68 return -ENOMEM;
69 }
70
71 /* fill client structure */
72 memcpy(client, &client_template, sizeof(struct i2c_client));
73 client->addr = address;
74 client->adapter = adapter;
75
76 /* tell the i2c layer a new client has arrived */
77 if (0 != (err = i2c_attach_client(client))) {
78 kfree(client);
79 return err;
80 }
81
82 printk("tea6415c: detected @ 0x%02x on adapter %s\n", address, &client->adapter->name[0]);
83
84 return 0;
85}
86
87static int attach(struct i2c_adapter *adapter)
88{
89 /* let's see whether this is a know adapter we can attach to */
90 if (adapter->id != I2C_ALGO_SAA7146) {
91 dprintk("refusing to probe on unknown adapter [name='%s',id=0x%x]\n", adapter->name, adapter->id);
92 return -ENODEV;
93 }
94
95 return i2c_probe(adapter, &addr_data, &detect);
96}
97
98static int detach(struct i2c_client *client)
99{
100 int ret = i2c_detach_client(client);
101 kfree(client);
102 return ret;
103}
104
105/* makes a connection between the input-pin 'i' and the output-pin 'o'
106 for the tea6415c-client 'client' */
107static int switch_matrix(struct i2c_client *client, int i, int o)
108{
109 u8 byte = 0;
110 int ret;
111
112 dprintk("adr:0x%02x, i:%d, o:%d\n", client->addr, i, o);
113
114 /* check if the pins are valid */
115 if (0 == ((1 == i || 3 == i || 5 == i || 6 == i || 8 == i || 10 == i || 20 == i || 11 == i)
116 && (18 == o || 17 == o || 16 == o || 15 == o || 14 == o || 13 == o)))
117 return -1;
118
119 /* to understand this, have a look at the tea6415c-specs (p.5) */
120 switch (o) {
121 case 18:
122 byte = 0x00;
123 break;
124 case 14:
125 byte = 0x20;
126 break;
127 case 16:
128 byte = 0x10;
129 break;
130 case 17:
131 byte = 0x08;
132 break;
133 case 15:
134 byte = 0x18;
135 break;
136 case 13:
137 byte = 0x28;
138 break;
139 };
140
141 switch (i) {
142 case 5:
143 byte |= 0x00;
144 break;
145 case 8:
146 byte |= 0x04;
147 break;
148 case 3:
149 byte |= 0x02;
150 break;
151 case 20:
152 byte |= 0x06;
153 break;
154 case 6:
155 byte |= 0x01;
156 break;
157 case 10:
158 byte |= 0x05;
159 break;
160 case 1:
161 byte |= 0x03;
162 break;
163 case 11:
164 byte |= 0x07;
165 break;
166 };
167
168 ret = i2c_smbus_write_byte(client, byte);
169 if (ret) {
170 dprintk("i2c_smbus_write_byte() failed, ret:%d\n", ret);
171 return -EIO;
172 }
173
174 return ret;
175}
176
177static int command(struct i2c_client *client, unsigned int cmd, void *arg)
178{
179 struct tea6415c_multiplex *v = (struct tea6415c_multiplex *)arg;
180 int result = 0;
181
182 switch (cmd) {
183 case TEA6415C_SWITCH:
184 result = switch_matrix(client, v->in, v->out);
185 break;
186 default:
187 return -ENOIOCTLCMD;
188 }
189
190 return result;
191}
192
193static struct i2c_driver driver = {
194 .owner = THIS_MODULE,
195 .name = "tea6415c",
196 .id = I2C_DRIVERID_TEA6415C,
197 .flags = I2C_DF_NOTIFY,
198 .attach_adapter = attach,
199 .detach_client = detach,
200 .command = command,
201};
202
203static struct i2c_client client_template = {
204 I2C_DEVNAME("tea6415c"),
205 .driver = &driver,
206};
207
208static int __init this_module_init(void)
209{
210 return i2c_add_driver(&driver);
211}
212
213static void __exit this_module_exit(void)
214{
215 i2c_del_driver(&driver);
216}
217
218module_init(this_module_init);
219module_exit(this_module_exit);
220
221MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
222MODULE_DESCRIPTION("tea6415c driver");
223MODULE_LICENSE("GPL");