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 <asm/segment.h>
47 #include <linux/types.h>
49 #include <linux/videodev.h>
50 #include <asm/uaccess.h>
52 MODULE_DESCRIPTION("Brooktree-856A video encoder driver");
53 MODULE_AUTHOR("Mike Bernson & Dave Perks");
54 MODULE_LICENSE("GPL");
56 #include <linux/i2c.h>
57 #include <linux/i2c-dev.h>
59 #define I2C_NAME(s) (s)->name
61 #include <linux/video_encoder.h>
64 module_param(debug, int, 0);
65 MODULE_PARM_DESC(debug, "Debug level (0-1)");
67 #define dprintk(num, format, args...) \
70 printk(format, ##args); \
73 /* ----------------------------------------------------------------------- */
75 #define REG_OFFSET 0xCE
78 unsigned char reg[32];
88 #define I2C_BT856 0x88
90 /* ----------------------------------------------------------------------- */
93 bt856_write (struct i2c_client *client,
97 struct bt856 *encoder = i2c_get_clientdata(client);
99 encoder->reg[reg - REG_OFFSET] = value;
100 return i2c_smbus_write_byte_data(client, reg, value);
104 bt856_setbit (struct i2c_client *client,
109 struct bt856 *encoder = i2c_get_clientdata(client);
111 return bt856_write(client, reg,
113 reg[reg - REG_OFFSET] & ~(1 << bit)) |
114 (value ? (1 << bit) : 0));
118 bt856_dump (struct i2c_client *client)
121 struct bt856 *encoder = i2c_get_clientdata(client);
123 printk(KERN_INFO "%s: register dump:", I2C_NAME(client));
124 for (i = 0xd6; i <= 0xde; i += 2)
125 printk(" %02x", encoder->reg[i - REG_OFFSET]);
129 /* ----------------------------------------------------------------------- */
132 bt856_command (struct i2c_client *client,
136 struct bt856 *encoder = i2c_get_clientdata(client);
141 /* This is just for testing!!! */
142 dprintk(1, KERN_INFO "bt856: init\n");
143 bt856_write(client, 0xdc, 0x18);
144 bt856_write(client, 0xda, 0);
145 bt856_write(client, 0xde, 0);
147 bt856_setbit(client, 0xdc, 3, 1);
148 //bt856_setbit(client, 0xdc, 6, 0);
149 bt856_setbit(client, 0xdc, 4, 1);
151 switch (encoder->norm) {
153 case VIDEO_MODE_NTSC:
154 bt856_setbit(client, 0xdc, 2, 0);
158 bt856_setbit(client, 0xdc, 2, 1);
162 bt856_setbit(client, 0xdc, 1, 1);
163 bt856_setbit(client, 0xde, 4, 0);
164 bt856_setbit(client, 0xde, 3, 1);
169 case ENCODER_GET_CAPABILITIES:
171 struct video_encoder_capability *cap = arg;
173 dprintk(1, KERN_INFO "%s: get capabilities\n",
176 cap->flags = VIDEO_ENCODER_PAL |
184 case ENCODER_SET_NORM:
188 dprintk(1, KERN_INFO "%s: set norm %d\n", I2C_NAME(client),
193 case VIDEO_MODE_NTSC:
194 bt856_setbit(client, 0xdc, 2, 0);
198 bt856_setbit(client, 0xdc, 2, 1);
199 bt856_setbit(client, 0xda, 0, 0);
200 //bt856_setbit(client, 0xda, 0, 1);
207 encoder->norm = *iarg;
213 case ENCODER_SET_INPUT:
217 dprintk(1, KERN_INFO "%s: set input %d\n", I2C_NAME(client),
220 /* We only have video bus.
221 * iarg = 0: input is from bt819
222 * iarg = 1: input is from ZR36060 */
227 bt856_setbit(client, 0xde, 4, 0);
228 bt856_setbit(client, 0xde, 3, 1);
229 bt856_setbit(client, 0xdc, 3, 1);
230 bt856_setbit(client, 0xdc, 6, 0);
233 bt856_setbit(client, 0xde, 4, 0);
234 bt856_setbit(client, 0xde, 3, 1);
235 bt856_setbit(client, 0xdc, 3, 1);
236 bt856_setbit(client, 0xdc, 6, 1);
239 bt856_setbit(client, 0xdc, 3, 0);
240 bt856_setbit(client, 0xde, 4, 1);
252 case ENCODER_SET_OUTPUT:
256 dprintk(1, KERN_INFO "%s: set output %d\n", I2C_NAME(client),
259 /* not much choice of outputs */
266 case ENCODER_ENABLE_OUTPUT:
270 encoder->enable = !!*iarg;
272 dprintk(1, KERN_INFO "%s: enable output %d\n",
273 I2C_NAME(client), encoder->enable);
284 /* ----------------------------------------------------------------------- */
288 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
290 static unsigned short normal_i2c[] = { I2C_BT856 >> 1, I2C_CLIENT_END };
292 static unsigned short ignore = I2C_CLIENT_END;
294 static struct i2c_client_address_data addr_data = {
295 .normal_i2c = normal_i2c,
301 static struct i2c_driver i2c_driver_bt856;
304 bt856_detect_client (struct i2c_adapter *adapter,
309 struct i2c_client *client;
310 struct bt856 *encoder;
314 "bt856.c: detecting bt856 client on address 0x%x\n",
317 /* Check if the adapter supports the needed features */
318 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
321 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
324 memset(client, 0, sizeof(struct i2c_client));
325 client->addr = address;
326 client->adapter = adapter;
327 client->driver = &i2c_driver_bt856;
328 client->flags = I2C_CLIENT_ALLOW_USE;
329 strlcpy(I2C_NAME(client), "bt856", sizeof(I2C_NAME(client)));
331 encoder = kmalloc(sizeof(struct bt856), GFP_KERNEL);
332 if (encoder == NULL) {
336 memset(encoder, 0, sizeof(struct bt856));
337 encoder->norm = VIDEO_MODE_NTSC;
339 i2c_set_clientdata(client, encoder);
341 i = i2c_attach_client(client);
348 bt856_write(client, 0xdc, 0x18);
349 bt856_write(client, 0xda, 0);
350 bt856_write(client, 0xde, 0);
352 bt856_setbit(client, 0xdc, 3, 1);
353 //bt856_setbit(client, 0xdc, 6, 0);
354 bt856_setbit(client, 0xdc, 4, 1);
356 switch (encoder->norm) {
358 case VIDEO_MODE_NTSC:
359 bt856_setbit(client, 0xdc, 2, 0);
363 bt856_setbit(client, 0xdc, 2, 1);
367 bt856_setbit(client, 0xdc, 1, 1);
368 bt856_setbit(client, 0xde, 4, 0);
369 bt856_setbit(client, 0xde, 3, 1);
374 dprintk(1, KERN_INFO "%s_attach: at address 0x%x\n", I2C_NAME(client),
381 bt856_attach_adapter (struct i2c_adapter *adapter)
385 "bt856.c: starting probe for adapter %s (0x%x)\n",
386 I2C_NAME(adapter), adapter->id);
387 return i2c_probe(adapter, &addr_data, &bt856_detect_client);
391 bt856_detach_client (struct i2c_client *client)
393 struct bt856 *encoder = i2c_get_clientdata(client);
396 err = i2c_detach_client(client);
407 /* ----------------------------------------------------------------------- */
409 static struct i2c_driver i2c_driver_bt856 = {
410 .owner = THIS_MODULE,
413 .id = I2C_DRIVERID_BT856,
414 .flags = I2C_DF_NOTIFY,
416 .attach_adapter = bt856_attach_adapter,
417 .detach_client = bt856_detach_client,
418 .command = bt856_command,
424 return i2c_add_driver(&i2c_driver_bt856);
430 i2c_del_driver(&i2c_driver_bt856);
433 module_init(bt856_init);
434 module_exit(bt856_exit);