2 * bt856 - BT856A Digital Video Encoder (Rockwell Part)
4 * Copyright (C) 1999 Mike Bernson <mike@mlb.org>
5 * Copyright (C) 1998 Dave Perks <dperks@ibm.net>
7 * Modifications for LML33/DC10plus unified driver
8 * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
10 * This code was modify/ported from the saa7111 driver written
13 * Changes by Ronald Bultje <rbultje@ronald.bitfreak.net>
14 * - moved over to linux>=2.4.x i2c protocol (9/9/2002)
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 #include <linux/module.h>
32 #include <linux/init.h>
33 #include <linux/delay.h>
34 #include <linux/errno.h>
36 #include <linux/kernel.h>
37 #include <linux/major.h>
38 #include <linux/slab.h>
40 #include <linux/pci.h>
41 #include <linux/signal.h>
43 #include <asm/pgtable.h>
45 #include <linux/sched.h>
46 #include <linux/types.h>
48 #include <linux/videodev.h>
49 #include <asm/uaccess.h>
51 MODULE_DESCRIPTION("Brooktree-856A video encoder driver");
52 MODULE_AUTHOR("Mike Bernson & Dave Perks");
53 MODULE_LICENSE("GPL");
55 #include <linux/i2c.h>
56 #include <linux/i2c-dev.h>
58 #define I2C_NAME(s) (s)->name
60 #include <linux/video_encoder.h>
63 module_param(debug, int, 0);
64 MODULE_PARM_DESC(debug, "Debug level (0-1)");
66 #define dprintk(num, format, args...) \
69 printk(format, ##args); \
72 /* ----------------------------------------------------------------------- */
74 #define REG_OFFSET 0xCE
77 unsigned char reg[32];
87 #define I2C_BT856 0x88
89 /* ----------------------------------------------------------------------- */
92 bt856_write (struct i2c_client *client,
96 struct bt856 *encoder = i2c_get_clientdata(client);
98 encoder->reg[reg - REG_OFFSET] = value;
99 return i2c_smbus_write_byte_data(client, reg, value);
103 bt856_setbit (struct i2c_client *client,
108 struct bt856 *encoder = i2c_get_clientdata(client);
110 return bt856_write(client, reg,
112 reg[reg - REG_OFFSET] & ~(1 << bit)) |
113 (value ? (1 << bit) : 0));
117 bt856_dump (struct i2c_client *client)
120 struct bt856 *encoder = i2c_get_clientdata(client);
122 printk(KERN_INFO "%s: register dump:", I2C_NAME(client));
123 for (i = 0xd6; i <= 0xde; i += 2)
124 printk(" %02x", encoder->reg[i - REG_OFFSET]);
128 /* ----------------------------------------------------------------------- */
131 bt856_command (struct i2c_client *client,
135 struct bt856 *encoder = i2c_get_clientdata(client);
140 /* This is just for testing!!! */
141 dprintk(1, KERN_INFO "bt856: init\n");
142 bt856_write(client, 0xdc, 0x18);
143 bt856_write(client, 0xda, 0);
144 bt856_write(client, 0xde, 0);
146 bt856_setbit(client, 0xdc, 3, 1);
147 //bt856_setbit(client, 0xdc, 6, 0);
148 bt856_setbit(client, 0xdc, 4, 1);
150 switch (encoder->norm) {
152 case VIDEO_MODE_NTSC:
153 bt856_setbit(client, 0xdc, 2, 0);
157 bt856_setbit(client, 0xdc, 2, 1);
161 bt856_setbit(client, 0xdc, 1, 1);
162 bt856_setbit(client, 0xde, 4, 0);
163 bt856_setbit(client, 0xde, 3, 1);
168 case ENCODER_GET_CAPABILITIES:
170 struct video_encoder_capability *cap = arg;
172 dprintk(1, KERN_INFO "%s: get capabilities\n",
175 cap->flags = VIDEO_ENCODER_PAL |
183 case ENCODER_SET_NORM:
187 dprintk(1, KERN_INFO "%s: set norm %d\n", I2C_NAME(client),
192 case VIDEO_MODE_NTSC:
193 bt856_setbit(client, 0xdc, 2, 0);
197 bt856_setbit(client, 0xdc, 2, 1);
198 bt856_setbit(client, 0xda, 0, 0);
199 //bt856_setbit(client, 0xda, 0, 1);
206 encoder->norm = *iarg;
212 case ENCODER_SET_INPUT:
216 dprintk(1, KERN_INFO "%s: set input %d\n", I2C_NAME(client),
219 /* We only have video bus.
220 * iarg = 0: input is from bt819
221 * iarg = 1: input is from ZR36060 */
226 bt856_setbit(client, 0xde, 4, 0);
227 bt856_setbit(client, 0xde, 3, 1);
228 bt856_setbit(client, 0xdc, 3, 1);
229 bt856_setbit(client, 0xdc, 6, 0);
232 bt856_setbit(client, 0xde, 4, 0);
233 bt856_setbit(client, 0xde, 3, 1);
234 bt856_setbit(client, 0xdc, 3, 1);
235 bt856_setbit(client, 0xdc, 6, 1);
238 bt856_setbit(client, 0xdc, 3, 0);
239 bt856_setbit(client, 0xde, 4, 1);
251 case ENCODER_SET_OUTPUT:
255 dprintk(1, KERN_INFO "%s: set output %d\n", I2C_NAME(client),
258 /* not much choice of outputs */
265 case ENCODER_ENABLE_OUTPUT:
269 encoder->enable = !!*iarg;
271 dprintk(1, KERN_INFO "%s: enable output %d\n",
272 I2C_NAME(client), encoder->enable);
283 /* ----------------------------------------------------------------------- */
287 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
289 static unsigned short normal_i2c[] = { I2C_BT856 >> 1, I2C_CLIENT_END };
291 static unsigned short ignore = I2C_CLIENT_END;
293 static struct i2c_client_address_data addr_data = {
294 .normal_i2c = normal_i2c,
299 static struct i2c_driver i2c_driver_bt856;
302 bt856_detect_client (struct i2c_adapter *adapter,
307 struct i2c_client *client;
308 struct bt856 *encoder;
312 "bt856.c: detecting bt856 client on address 0x%x\n",
315 /* Check if the adapter supports the needed features */
316 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
319 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
322 memset(client, 0, sizeof(struct i2c_client));
323 client->addr = address;
324 client->adapter = adapter;
325 client->driver = &i2c_driver_bt856;
326 client->flags = I2C_CLIENT_ALLOW_USE;
327 strlcpy(I2C_NAME(client), "bt856", sizeof(I2C_NAME(client)));
329 encoder = kmalloc(sizeof(struct bt856), GFP_KERNEL);
330 if (encoder == NULL) {
334 memset(encoder, 0, sizeof(struct bt856));
335 encoder->norm = VIDEO_MODE_NTSC;
337 i2c_set_clientdata(client, encoder);
339 i = i2c_attach_client(client);
346 bt856_write(client, 0xdc, 0x18);
347 bt856_write(client, 0xda, 0);
348 bt856_write(client, 0xde, 0);
350 bt856_setbit(client, 0xdc, 3, 1);
351 //bt856_setbit(client, 0xdc, 6, 0);
352 bt856_setbit(client, 0xdc, 4, 1);
354 switch (encoder->norm) {
356 case VIDEO_MODE_NTSC:
357 bt856_setbit(client, 0xdc, 2, 0);
361 bt856_setbit(client, 0xdc, 2, 1);
365 bt856_setbit(client, 0xdc, 1, 1);
366 bt856_setbit(client, 0xde, 4, 0);
367 bt856_setbit(client, 0xde, 3, 1);
372 dprintk(1, KERN_INFO "%s_attach: at address 0x%x\n", I2C_NAME(client),
379 bt856_attach_adapter (struct i2c_adapter *adapter)
383 "bt856.c: starting probe for adapter %s (0x%x)\n",
384 I2C_NAME(adapter), adapter->id);
385 return i2c_probe(adapter, &addr_data, &bt856_detect_client);
389 bt856_detach_client (struct i2c_client *client)
391 struct bt856 *encoder = i2c_get_clientdata(client);
394 err = i2c_detach_client(client);
405 /* ----------------------------------------------------------------------- */
407 static struct i2c_driver i2c_driver_bt856 = {
408 .owner = THIS_MODULE,
411 .id = I2C_DRIVERID_BT856,
412 .flags = I2C_DF_NOTIFY,
414 .attach_adapter = bt856_attach_adapter,
415 .detach_client = bt856_detach_client,
416 .command = bt856_command,
422 return i2c_add_driver(&i2c_driver_bt856);
428 i2c_del_driver(&i2c_driver_bt856);
431 module_init(bt856_init);
432 module_exit(bt856_exit);