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 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/delay.h>
31 #include <linux/errno.h>
33 #include <linux/kernel.h>
34 #include <linux/major.h>
35 #include <linux/slab.h>
37 #include <linux/pci.h>
38 #include <linux/signal.h>
40 #include <asm/pgtable.h>
42 #include <linux/sched.h>
43 #include <linux/types.h>
45 #include <linux/videodev.h>
46 #include <linux/version.h>
47 #include <asm/uaccess.h>
49 #include <linux/i2c.h>
50 #include <linux/video_encoder.h>
52 #define DEBUG(x) x /* Debug driver */
54 /* ----------------------------------------------------------------------- */
56 static unsigned short normal_i2c[] = {34>>1, I2C_CLIENT_END };
57 static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
58 static unsigned short probe[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
59 static unsigned short probe_range[2] = { I2C_CLIENT_END , I2C_CLIENT_END };
60 static unsigned short ignore[2] = { I2C_CLIENT_END , I2C_CLIENT_END };
61 static unsigned short ignore_range[2] = { I2C_CLIENT_END , I2C_CLIENT_END };
62 static unsigned short force[2] = { I2C_CLIENT_END , I2C_CLIENT_END };
64 static struct i2c_client_address_data addr_data = {
65 normal_i2c , normal_i2c_range,
67 ignore , ignore_range,
71 static struct i2c_client client_template;
74 struct i2c_client *client;
76 unsigned char reg[128];
84 struct semaphore lock;
87 #define I2C_BT856 0x88
91 /* ----------------------------------------------------------------------- */
93 static int bt856_setbit(struct bt856 *dev, int subaddr, int bit, int data)
95 return i2c_smbus_write_byte_data(dev->client, subaddr,(dev->reg[subaddr] & ~(1 << bit)) | (data ? (1 << bit) : 0));
98 /* ----------------------------------------------------------------------- */
100 static int bt856_attach(struct i2c_adapter *adap, int addr , unsigned long flags, int kind)
102 struct bt856 *encoder;
103 struct i2c_client *client;
105 client = kmalloc(sizeof(*client), GFP_KERNEL);
108 memset(client, 0, sizeof(*client));
109 client_template.adapter = adap;
110 client_template.addr = addr;
111 memcpy(client, &client_template, sizeof(*client));
113 /* This chip is not on the buz card but at the same address saa7185 */
114 //if (memcmp(device->bus->name, "buz", 3) == 0 || memcmp(device->bus->name, "zr36057", 6) == 0)
117 encoder = kmalloc(sizeof(struct bt856), GFP_KERNEL);
119 if (encoder == NULL) {
125 memset(encoder, 0, sizeof(struct bt856));
126 strlcpy(client->dev.name, "bt856", DEVICE_NAME_SIZE);
127 encoder->client = client;
128 i2c_set_clientdata(client, encoder);
129 encoder->addr = client->addr;
130 encoder->norm = VIDEO_MODE_NTSC;
133 DEBUG(printk(KERN_INFO "%s-bt856: attach\n", encoder->client->dev.name));
135 i2c_smbus_write_byte_data(client, 0xdc, 0x18);
136 encoder->reg[0xdc] = 0x18;
137 i2c_smbus_write_byte_data(client, 0xda, 0);
138 encoder->reg[0xda] = 0;
139 i2c_smbus_write_byte_data(client, 0xde, 0);
140 encoder->reg[0xde] = 0;
142 bt856_setbit(encoder, 0xdc, 3, 1);
143 //bt856_setbit(encoder, 0xdc, 6, 0);
144 bt856_setbit(encoder, 0xdc, 4, 1);
146 switch (encoder->norm) {
148 case VIDEO_MODE_NTSC:
149 bt856_setbit(encoder, 0xdc, 2, 0);
153 bt856_setbit(encoder, 0xdc, 2, 1);
157 bt856_setbit(encoder, 0xdc, 1, 1);
158 bt856_setbit(encoder, 0xde, 4, 0);
159 bt856_setbit(encoder, 0xde, 3, 1);
160 init_MUTEX(&encoder->lock);
161 i2c_attach_client(client);
166 static int bt856_probe(struct i2c_adapter *adap)
168 return i2c_probe(adap, &addr_data , bt856_attach);
171 static int bt856_detach(struct i2c_client *client)
173 i2c_detach_client(client);
174 i2c_get_clientdata(client);
180 static int bt856_command(struct i2c_client *client, unsigned int cmd,
183 struct bt856 *encoder = i2c_get_clientdata(client);
187 case ENCODER_GET_CAPABILITIES:
189 struct video_encoder_capability *cap = arg;
192 (KERN_INFO "%s-bt856: get capabilities\n",
193 encoder->client->dev.name));
197 | VIDEO_ENCODER_NTSC | VIDEO_ENCODER_CCIR;
203 case ENCODER_SET_NORM:
207 DEBUG(printk(KERN_INFO "%s-bt856: set norm %d\n",
208 encoder->client->dev.name, *iarg));
212 case VIDEO_MODE_NTSC:
213 bt856_setbit(encoder, 0xdc, 2, 0);
217 bt856_setbit(encoder, 0xdc, 2, 1);
218 bt856_setbit(encoder, 0xda, 0, 0);
219 //bt856_setbit(encoder, 0xda, 0, 1);
226 encoder->norm = *iarg;
230 case ENCODER_SET_INPUT:
234 DEBUG(printk(KERN_INFO "%s-bt856: set input %d\n",
235 encoder->client->dev.name, *iarg));
237 /* We only have video bus.
238 *iarg = 0: input is from bt819
239 *iarg = 1: input is from ZR36060 */
244 bt856_setbit(encoder, 0xde, 4, 0);
245 bt856_setbit(encoder, 0xde, 3, 1);
246 bt856_setbit(encoder, 0xdc, 3, 1);
247 bt856_setbit(encoder, 0xdc, 6, 0);
250 bt856_setbit(encoder, 0xde, 4, 0);
251 bt856_setbit(encoder, 0xde, 3, 1);
252 bt856_setbit(encoder, 0xdc, 3, 1);
253 bt856_setbit(encoder, 0xdc, 6, 1);
256 bt856_setbit(encoder, 0xdc, 3, 0);
257 bt856_setbit(encoder, 0xde, 4, 1);
266 case ENCODER_SET_OUTPUT:
270 DEBUG(printk(KERN_INFO "%s-bt856: set output %d\n",
271 encoder->client->dev.name, *iarg));
273 /* not much choice of outputs */
280 case ENCODER_ENABLE_OUTPUT:
284 encoder->enable = !!*iarg;
287 (KERN_INFO "%s-bt856: enable output %d\n",
288 encoder->client->dev.name, encoder->enable));
299 /* ----------------------------------------------------------------------- */
301 static struct i2c_driver i2c_driver_bt856 = {
302 .owner = THIS_MODULE,
303 .name = "bt856", /* name */
304 .id = I2C_DRIVERID_BT856, /* ID */
305 .flags = I2C_DF_NOTIFY,
306 .attach_adapter = bt856_probe,
307 .detach_client = bt856_detach,
308 .command = bt856_command
311 static struct i2c_client client_template = {
313 .driver = &i2c_driver_bt856,
315 .name = "bt856_client",
319 static int bt856_init(void)
321 return i2c_add_driver(&i2c_driver_bt856);
324 static void bt856_exit(void)
326 i2c_del_driver(&i2c_driver_bt856);
329 module_init(bt856_init);
330 module_exit(bt856_exit);
331 MODULE_LICENSE("GPL");