1 /* Driver for Bt832 CMOS Camera Video Processor
2 i2c-addresses: 0x88 or 0x8a
4 The BT832 interfaces to a Quartzsight Digital Camera (352x288, 25 or 30 fps)
5 via a 9 pin connector ( 4-wire SDATA, 2-wire i2c, SCLK, VCC, GND).
6 It outputs an 8-bit 4:2:2 YUV or YCrCb video signal which can be directly
7 connected to bt848/bt878 GPIO pins on this purpose.
8 (see: VLSI Vision Ltd. www.vvl.co.uk for camera datasheets)
11 - Pixelview Rev.4E: 0x8a
12 GPIO 0x400000 toggles Bt832 RESET, and the chip changes to i2c 0x88 !
14 (c) Gunther Mayer, 2002
17 - detect chip and hexdump
18 - reset chip and leave low power mode
19 - detect camera present
22 - make it work (find correct setup for Bt832 and Bt878)
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/i2c.h>
28 #include <linux/types.h>
29 #include <linux/videodev.h>
30 #include <linux/init.h>
31 #include <linux/errno.h>
32 #include <linux/slab.h>
35 #include "audiochip.h"
39 MODULE_LICENSE("GPL");
41 /* Addresses to scan */
42 static unsigned short normal_i2c
[] = {I2C_CLIENT_END
};
43 static unsigned short normal_i2c_range
[] = {I2C_BT832_ALT1
>>1,I2C_BT832_ALT2
>>1,I2C_CLIENT_END
};
46 /* ---------------------------------------------------------------------- */
48 #define dprintk if (debug) printk
50 static int bt832_detach(struct i2c_client
*client
);
53 static struct i2c_driver driver
;
54 static struct i2c_client client_template
;
57 struct i2c_client client
;
60 int bt832_hexdump(struct i2c_client
*i2c_client_s
, unsigned char *buf
)
63 buf
[0]=0x80; // start at register 0 with auto-increment
64 if (1 != (rc
= i2c_master_send(i2c_client_s
,buf
,1)))
65 printk("bt832: i2c i/o error: rc == %d (should be 1)\n",rc
);
69 if (65 != (rc
=i2c_master_recv(i2c_client_s
,buf
,65)))
70 printk("bt832: i2c i/o error: rc == %d (should be 65)\n",rc
);
72 // Note: On READ the first byte is the current index
73 // (e.g. 0x80, what we just wrote)
77 printk("BT832 hexdump:\n");
80 if(((i
-1)%8)==0) printk(" ");
81 if(((i
-1)%16)==0) printk("\n");
83 printk(" %02x",buf
[i
]);
90 // Return: 1 (is a bt832), 0 (No bt832 here)
91 int bt832_init(struct i2c_client
*i2c_client_s
)
96 buf
=kmalloc(65,GFP_KERNEL
);
97 bt832_hexdump(i2c_client_s
,buf
);
99 if(buf
[0x40] != 0x31) {
100 printk("bt832: this i2c chip is no bt832 (id=%02x). Detaching.\n",buf
[0x40]);
105 printk("Write 0 tp VPSTATUS\n");
106 buf
[0]=BT832_VP_STATUS
; // Reg.52
108 if (2 != (rc
= i2c_master_send(i2c_client_s
,buf
,2)))
109 printk("bt832: i2c i/o error VPS: rc == %d (should be 2)\n",rc
);
111 bt832_hexdump(i2c_client_s
,buf
);
114 // Leave low power mode:
115 printk("Bt832: leave low power mode.\n");
116 buf
[0]=BT832_CAM_SETUP0
; //0x39 57
118 if (2 != (rc
= i2c_master_send(i2c_client_s
,buf
,2)))
119 printk("bt832: i2c i/o error LLPM: rc == %d (should be 2)\n",rc
);
121 bt832_hexdump(i2c_client_s
,buf
);
123 printk("Write 0 tp VPSTATUS\n");
124 buf
[0]=BT832_VP_STATUS
; // Reg.52
126 if (2 != (rc
= i2c_master_send(i2c_client_s
,buf
,2)))
127 printk("bt832: i2c i/o error VPS: rc == %d (should be 2)\n",rc
);
129 bt832_hexdump(i2c_client_s
,buf
);
133 printk("Enable Output\n");
134 buf
[0]=BT832_VP_CONTROL1
; // Reg.40
135 buf
[1]= 0x27 & (~0x01); // Default | !skip
136 if (2 != (rc
= i2c_master_send(i2c_client_s
,buf
,2)))
137 printk("bt832: i2c i/o error EO: rc == %d (should be 2)\n",rc
);
139 bt832_hexdump(i2c_client_s
,buf
);
142 // Full 30/25 Frame rate
143 printk("Full 30/25 Frame rate\n");
144 buf
[0]=BT832_VP_CONTROL0
; // Reg.39
146 if (2 != (rc
= i2c_master_send(i2c_client_s
,buf
,2)))
147 printk("bt832: i2c i/o error FFR: rc == %d (should be 2)\n",rc
);
149 bt832_hexdump(i2c_client_s
,buf
);
153 // for testing (even works when no camera attached)
154 printk("bt832: *** Generate NTSC M Bars *****\n");
155 buf
[0]=BT832_VP_TESTCONTROL0
; // Reg. 42
156 buf
[1]=3; // Generate NTSC System M bars, Generate Frame timing internally
157 if (2 != (rc
= i2c_master_send(i2c_client_s
,buf
,2)))
158 printk("bt832: i2c i/o error MBAR: rc == %d (should be 2)\n",rc
);
161 printk("Bt832: Camera Present: %s\n",
162 (buf
[1+BT832_CAM_STATUS
] & BT832_56_CAMERA_PRESENT
) ? "yes":"no");
164 bt832_hexdump(i2c_client_s
,buf
);
171 static int bt832_attach(struct i2c_adapter
*adap
, int addr
,
172 unsigned short flags
, int kind
)
176 printk("bt832_attach\n");
178 client_template
.adapter
= adap
;
179 client_template
.addr
= addr
;
181 printk("bt832: chip found @ 0x%x\n", addr
<<1);
183 if (NULL
== (t
= kmalloc(sizeof(*t
), GFP_KERNEL
)))
185 memset(t
,0,sizeof(*t
));
186 t
->client
= client_template
;
188 i2c_attach_client(&t
->client
);
190 if(! bt832_init(&t
->client
)) {
191 bt832_detach(&t
->client
);
198 static int bt832_probe(struct i2c_adapter
*adap
)
200 if (adap
->class & I2C_CLASS_TV_ANALOG
)
201 return i2c_probe(adap
, &addr_data
, bt832_attach
);
205 static int bt832_detach(struct i2c_client
*client
)
207 struct bt832
*t
= (struct bt832
*)client
->data
;
209 printk("bt832: detach.\n");
210 i2c_detach_client(client
);
216 bt832_command(struct i2c_client
*client
, unsigned int cmd
, void *arg
)
218 struct bt832
*t
= (struct bt832
*)client
->data
;
220 printk("bt832: command %x\n",cmd
);
223 case BT832_HEXDUMP
: {
225 buf
=kmalloc(65,GFP_KERNEL
);
226 bt832_hexdump(&t
->client
,buf
);
231 printk("bt832: re-attach\n");
232 i2c_del_driver(&driver
);
233 i2c_add_driver(&driver
);
239 /* ----------------------------------------------------------------------- */
241 static struct i2c_driver driver
= {
242 .owner
= THIS_MODULE
,
243 .name
= "i2c bt832 driver",
244 .id
= -1, /* FIXME */
245 .flags
= I2C_DF_NOTIFY
,
246 .attach_adapter
= bt832_probe
,
247 .detach_client
= bt832_detach
,
248 .command
= bt832_command
,
250 static struct i2c_client client_template
=
253 .flags
= I2C_CLIENT_ALLOW_USE
,
258 int bt832_init_module(void)
260 i2c_add_driver(&driver
);
264 static void bt832_cleanup_module(void)
266 i2c_del_driver(&driver
);
269 module_init(bt832_init_module
);
270 module_exit(bt832_cleanup_module
);