[PATCH] v4l: 800: whitespace cleanups
[deliverable/linux.git] / drivers / media / video / bt832.c
CommitLineData
1da177e4
LT
1/* Driver for Bt832 CMOS Camera Video Processor
2 i2c-addresses: 0x88 or 0x8a
3
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)
56fc08ca 9
1da177e4
LT
10 Supported Cards:
11 - Pixelview Rev.4E: 0x8a
12 GPIO 0x400000 toggles Bt832 RESET, and the chip changes to i2c 0x88 !
13
14 (c) Gunther Mayer, 2002
15
16 STATUS:
17 - detect chip and hexdump
18 - reset chip and leave low power mode
19 - detect camera present
20
21 TODO:
22 - make it work (find correct setup for Bt832 and Bt878)
23*/
24
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>
33
56fc08ca
MCC
34#include <media/audiochip.h>
35#include <media/id.h>
1da177e4
LT
36#include "bttv.h"
37#include "bt832.h"
38
39MODULE_LICENSE("GPL");
40
41/* Addresses to scan */
f5bec396
MCC
42static unsigned short normal_i2c[] = { I2C_BT832_ALT1>>1, I2C_BT832_ALT2>>1,
43 I2C_CLIENT_END };
1da177e4
LT
44I2C_CLIENT_INSMOD;
45
46/* ---------------------------------------------------------------------- */
47
48#define dprintk if (debug) printk
49
50static int bt832_detach(struct i2c_client *client);
51
52
53static struct i2c_driver driver;
54static struct i2c_client client_template;
55
56struct bt832 {
4ac97914 57 struct i2c_client client;
1da177e4
LT
58};
59
60int bt832_hexdump(struct i2c_client *i2c_client_s, unsigned char *buf)
61{
62 int i,rc;
63 buf[0]=0x80; // start at register 0 with auto-increment
4ac97914
MCC
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);
1da177e4 66
4ac97914
MCC
67 for(i=0;i<65;i++)
68 buf[i]=0;
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);
1da177e4 71
4ac97914
MCC
72 // Note: On READ the first byte is the current index
73 // (e.g. 0x80, what we just wrote)
1da177e4 74
4ac97914
MCC
75 if(1) {
76 int i;
77 printk("BT832 hexdump:\n");
78 for(i=1;i<65;i++) {
1da177e4
LT
79 if(i!=1) {
80 if(((i-1)%8)==0) printk(" ");
4ac97914 81 if(((i-1)%16)==0) printk("\n");
1da177e4 82 }
4ac97914
MCC
83 printk(" %02x",buf[i]);
84 }
85 printk("\n");
86 }
1da177e4
LT
87 return 0;
88}
89
90// Return: 1 (is a bt832), 0 (No bt832 here)
91int bt832_init(struct i2c_client *i2c_client_s)
92{
93 unsigned char *buf;
94 int rc;
95
96 buf=kmalloc(65,GFP_KERNEL);
97 bt832_hexdump(i2c_client_s,buf);
56fc08ca 98
1da177e4
LT
99 if(buf[0x40] != 0x31) {
100 printk("bt832: this i2c chip is no bt832 (id=%02x). Detaching.\n",buf[0x40]);
101 kfree(buf);
102 return 0;
103 }
104
4ac97914
MCC
105 printk("Write 0 tp VPSTATUS\n");
106 buf[0]=BT832_VP_STATUS; // Reg.52
107 buf[1]= 0x00;
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);
1da177e4 110
4ac97914 111 bt832_hexdump(i2c_client_s,buf);
1da177e4
LT
112
113
114 // Leave low power mode:
115 printk("Bt832: leave low power mode.\n");
116 buf[0]=BT832_CAM_SETUP0; //0x39 57
117 buf[1]=0x08;
118 if (2 != (rc = i2c_master_send(i2c_client_s,buf,2)))
4ac97914 119 printk("bt832: i2c i/o error LLPM: rc == %d (should be 2)\n",rc);
1da177e4 120
4ac97914 121 bt832_hexdump(i2c_client_s,buf);
1da177e4
LT
122
123 printk("Write 0 tp VPSTATUS\n");
4ac97914
MCC
124 buf[0]=BT832_VP_STATUS; // Reg.52
125 buf[1]= 0x00;
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);
1da177e4 128
4ac97914 129 bt832_hexdump(i2c_client_s,buf);
1da177e4
LT
130
131
132 // Enable Output
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)))
4ac97914 137 printk("bt832: i2c i/o error EO: rc == %d (should be 2)\n",rc);
56fc08ca 138
4ac97914 139 bt832_hexdump(i2c_client_s,buf);
1da177e4 140
1da177e4 141
1da177e4
LT
142 // for testing (even works when no camera attached)
143 printk("bt832: *** Generate NTSC M Bars *****\n");
144 buf[0]=BT832_VP_TESTCONTROL0; // Reg. 42
145 buf[1]=3; // Generate NTSC System M bars, Generate Frame timing internally
4ac97914
MCC
146 if (2 != (rc = i2c_master_send(i2c_client_s,buf,2)))
147 printk("bt832: i2c i/o error MBAR: rc == %d (should be 2)\n",rc);
1da177e4
LT
148
149 printk("Bt832: Camera Present: %s\n",
150 (buf[1+BT832_CAM_STATUS] & BT832_56_CAMERA_PRESENT) ? "yes":"no");
151
4ac97914 152 bt832_hexdump(i2c_client_s,buf);
1da177e4
LT
153 kfree(buf);
154 return 1;
155}
156
157
158
56fc08ca 159static int bt832_attach(struct i2c_adapter *adap, int addr, int kind)
1da177e4
LT
160{
161 struct bt832 *t;
162
163 printk("bt832_attach\n");
164
4ac97914
MCC
165 client_template.adapter = adap;
166 client_template.addr = addr;
1da177e4 167
4ac97914 168 printk("bt832: chip found @ 0x%x\n", addr<<1);
1da177e4 169
4ac97914
MCC
170 if (NULL == (t = kmalloc(sizeof(*t), GFP_KERNEL)))
171 return -ENOMEM;
1da177e4
LT
172 memset(t,0,sizeof(*t));
173 t->client = client_template;
4ac97914
MCC
174 i2c_set_clientdata(&t->client, t);
175 i2c_attach_client(&t->client);
1da177e4
LT
176
177 if(! bt832_init(&t->client)) {
178 bt832_detach(&t->client);
179 return -1;
180 }
56fc08ca 181
1da177e4
LT
182 return 0;
183}
184
185static int bt832_probe(struct i2c_adapter *adap)
186{
56fc08ca 187#ifdef I2C_CLASS_TV_ANALOG
1da177e4
LT
188 if (adap->class & I2C_CLASS_TV_ANALOG)
189 return i2c_probe(adap, &addr_data, bt832_attach);
56fc08ca 190#else
c7a46533 191 if (adap->id == I2C_HW_B_BT848)
56fc08ca
MCC
192 return i2c_probe(adap, &addr_data, bt832_attach);
193#endif
1da177e4
LT
194 return 0;
195}
196
197static int bt832_detach(struct i2c_client *client)
198{
56fc08ca 199 struct bt832 *t = i2c_get_clientdata(client);
1da177e4
LT
200
201 printk("bt832: detach.\n");
202 i2c_detach_client(client);
203 kfree(t);
204 return 0;
205}
206
207static int
208bt832_command(struct i2c_client *client, unsigned int cmd, void *arg)
209{
56fc08ca 210 struct bt832 *t = i2c_get_clientdata(client);
1da177e4
LT
211
212 printk("bt832: command %x\n",cmd);
213
4ac97914 214 switch (cmd) {
1da177e4
LT
215 case BT832_HEXDUMP: {
216 unsigned char *buf;
217 buf=kmalloc(65,GFP_KERNEL);
218 bt832_hexdump(&t->client,buf);
219 kfree(buf);
220 }
221 break;
222 case BT832_REATTACH:
223 printk("bt832: re-attach\n");
224 i2c_del_driver(&driver);
225 i2c_add_driver(&driver);
226 break;
227 }
228 return 0;
229}
230
231/* ----------------------------------------------------------------------- */
232
233static struct i2c_driver driver = {
234 .owner = THIS_MODULE,
235 .name = "i2c bt832 driver",
236 .id = -1, /* FIXME */
237 .flags = I2C_DF_NOTIFY,
238 .attach_adapter = bt832_probe,
239 .detach_client = bt832_detach,
240 .command = bt832_command,
241};
242static struct i2c_client client_template =
243{
fae91e72 244 .name = "bt832",
56fc08ca
MCC
245 .flags = I2C_CLIENT_ALLOW_USE,
246 .driver = &driver,
1da177e4
LT
247};
248
249
56fc08ca 250static int __init bt832_init_module(void)
1da177e4 251{
56fc08ca 252 return i2c_add_driver(&driver);
1da177e4
LT
253}
254
56fc08ca 255static void __exit bt832_cleanup_module(void)
1da177e4
LT
256{
257 i2c_del_driver(&driver);
258}
259
260module_init(bt832_init_module);
261module_exit(bt832_cleanup_module);
262
56fc08ca
MCC
263/*
264 * Overrides for Emacs so that we follow Linus's tabbing style.
265 * ---------------------------------------------------------------------------
266 * Local variables:
267 * c-basic-offset: 8
268 * End:
269 */
This page took 0.093325 seconds and 5 git commands to generate.