2 tea6415c - i2c-driver for the tea6415c by SGS Thomson
4 Copyright (C) 1998-2003 Michael Hunold <michael@mihu.de>
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.
11 For detailed informations download the specifications directly
12 from SGS Thomson at http://www.st.com
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.
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.
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.
29 #include <linux/module.h>
30 #include <linux/ioctl.h>
31 #include <linux/i2c.h>
35 static int debug
= 0; /* insmod parameter */
36 module_param(debug
, int, 0644);
37 MODULE_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)
41 #define TEA6415C_NUM_INPUTS 8
42 #define TEA6415C_NUM_OUTPUTS 6
44 /* addresses to scan, found only at 0x03 and/or 0x43 (7-bit) */
45 static unsigned short normal_i2c
[] = { I2C_TEA6415C_1
, I2C_TEA6415C_2
, I2C_CLIENT_END
};
46 static unsigned short normal_i2c_range
[] = { I2C_CLIENT_END
};
48 /* magic definition of all other variables and things */
51 static struct i2c_driver driver
;
52 static struct i2c_client client_template
;
54 /* unique ID allocation */
55 static int tea6415c_id
= 0;
57 /* this function is called by i2c_probe */
58 static int detect(struct i2c_adapter
*adapter
, int address
, int kind
)
60 struct i2c_client
*client
= NULL
;
63 /* let's see whether this adapter can support what we need */
64 if (0 == i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_WRITE_BYTE
)) {
68 /* allocate memory for client structure */
69 client
= kmalloc(sizeof(struct i2c_client
), GFP_KERNEL
);
74 /* fill client structure */
75 memcpy(client
, &client_template
, sizeof(struct i2c_client
));
76 client
->id
= tea6415c_id
++;
77 client
->addr
= address
;
78 client
->adapter
= adapter
;
80 /* tell the i2c layer a new client has arrived */
81 if (0 != (err
= i2c_attach_client(client
))) {
86 printk("tea6415c: detected @ 0x%02x on adapter %s\n", address
, &client
->adapter
->name
[0]);
91 static int attach(struct i2c_adapter
*adapter
)
93 /* let's see whether this is a know adapter we can attach to */
94 if (adapter
->id
!= I2C_ALGO_SAA7146
) {
95 dprintk("refusing to probe on unknown adapter [name='%s',id=0x%x]\n", adapter
->name
, adapter
->id
);
99 return i2c_probe(adapter
, &addr_data
, &detect
);
102 static int detach(struct i2c_client
*client
)
104 int ret
= i2c_detach_client(client
);
109 /* makes a connection between the input-pin 'i' and the output-pin 'o'
110 for the tea6415c-client 'client' */
111 static int switch_matrix(struct i2c_client
*client
, int i
, int o
)
116 dprintk("adr:0x%02x, i:%d, o:%d\n", client
->addr
, i
, o
);
118 /* check if the pins are valid */
119 if (0 == ((1 == i
|| 3 == i
|| 5 == i
|| 6 == i
|| 8 == i
|| 10 == i
|| 20 == i
|| 11 == i
)
120 && (18 == o
|| 17 == o
|| 16 == o
|| 15 == o
|| 14 == o
|| 13 == o
)))
123 /* to understand this, have a look at the tea6415c-specs (p.5) */
172 ret
= i2c_smbus_write_byte(client
, byte
);
174 dprintk("i2c_smbus_write_byte() failed, ret:%d\n", ret
);
181 static int command(struct i2c_client
*client
, unsigned int cmd
, void *arg
)
183 struct tea6415c_multiplex
*v
= (struct tea6415c_multiplex
*)arg
;
187 case TEA6415C_SWITCH
:
188 result
= switch_matrix(client
, v
->in
, v
->out
);
197 static struct i2c_driver driver
= {
198 .owner
= THIS_MODULE
,
200 .id
= I2C_DRIVERID_TEA6415C
,
201 .flags
= I2C_DF_NOTIFY
,
202 .attach_adapter
= attach
,
203 .detach_client
= detach
,
207 static struct i2c_client client_template
= {
208 I2C_DEVNAME("tea6415c"),
212 static int __init
this_module_init(void)
214 return i2c_add_driver(&driver
);
217 static void __exit
this_module_exit(void)
219 i2c_del_driver(&driver
);
222 module_init(this_module_init
);
223 module_exit(this_module_exit
);
225 MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
226 MODULE_DESCRIPTION("tea6415c driver");
227 MODULE_LICENSE("GPL");