Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 33 | #include <media/audiochip.h> |
Mauro Carvalho Chehab | 0680481 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 34 | #include <media/v4l2-common.h> |
| 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include "bttv.h" |
| 37 | #include "bt832.h" |
| 38 | |
| 39 | MODULE_LICENSE("GPL"); |
| 40 | |
| 41 | /* Addresses to scan */ |
Mauro Carvalho Chehab | f5bec39 | 2005-06-23 22:05:13 -0700 | [diff] [blame] | 42 | static unsigned short normal_i2c[] = { I2C_BT832_ALT1>>1, I2C_BT832_ALT2>>1, |
| 43 | I2C_CLIENT_END }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | I2C_CLIENT_INSMOD; |
| 45 | |
Mauro Carvalho Chehab | a5ed425 | 2006-01-13 14:10:19 -0200 | [diff] [blame] | 46 | int debug; /* debug output */ |
Mauro Carvalho Chehab | 0680481 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 47 | module_param(debug, int, 0644); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Mauro Carvalho Chehab | 0680481 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 49 | /* ---------------------------------------------------------------------- */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | static int bt832_detach(struct i2c_client *client); |
| 52 | |
| 53 | |
| 54 | static struct i2c_driver driver; |
| 55 | static struct i2c_client client_template; |
| 56 | |
| 57 | struct bt832 { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 58 | struct i2c_client client; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | int bt832_hexdump(struct i2c_client *i2c_client_s, unsigned char *buf) |
| 62 | { |
| 63 | int i,rc; |
| 64 | buf[0]=0x80; // start at register 0 with auto-increment |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 65 | if (1 != (rc = i2c_master_send(i2c_client_s,buf,1))) |
Mauro Carvalho Chehab | 0680481 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 66 | v4l_err(i2c_client_s,"i2c i/o error: rc == %d (should be 1)\n",rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 68 | for(i=0;i<65;i++) |
| 69 | buf[i]=0; |
| 70 | if (65 != (rc=i2c_master_recv(i2c_client_s,buf,65))) |
Mauro Carvalho Chehab | 0680481 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 71 | v4l_err(i2c_client_s,"i2c i/o error: rc == %d (should be 65)\n",rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 73 | // Note: On READ the first byte is the current index |
| 74 | // (e.g. 0x80, what we just wrote) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Mauro Carvalho Chehab | 0680481 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 76 | if(debug>1) { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 77 | int i; |
Mauro Carvalho Chehab | f167cb4 | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 78 | v4l_dbg(2, debug,i2c_client_s,"hexdump:"); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 79 | for(i=1;i<65;i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | if(i!=1) { |
Mauro Carvalho Chehab | 0680481 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 81 | if(((i-1)%8)==0) printk(" "); |
| 82 | if(((i-1)%16)==0) { |
| 83 | printk("\n"); |
Mauro Carvalho Chehab | f167cb4 | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 84 | v4l_dbg(2, debug,i2c_client_s,"hexdump:"); |
Mauro Carvalho Chehab | 0680481 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 85 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | } |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 87 | printk(" %02x",buf[i]); |
| 88 | } |
| 89 | printk("\n"); |
| 90 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | // Return: 1 (is a bt832), 0 (No bt832 here) |
| 95 | int bt832_init(struct i2c_client *i2c_client_s) |
| 96 | { |
| 97 | unsigned char *buf; |
| 98 | int rc; |
| 99 | |
| 100 | buf=kmalloc(65,GFP_KERNEL); |
| 101 | bt832_hexdump(i2c_client_s,buf); |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | if(buf[0x40] != 0x31) { |
Mauro Carvalho Chehab | 0680481 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 104 | v4l_err(i2c_client_s,"This i2c chip is no bt832 (id=%02x). Detaching.\n",buf[0x40]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | kfree(buf); |
| 106 | return 0; |
| 107 | } |
| 108 | |
Mauro Carvalho Chehab | 0680481 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 109 | v4l_err(i2c_client_s,"Write 0 tp VPSTATUS\n"); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 110 | buf[0]=BT832_VP_STATUS; // Reg.52 |
| 111 | buf[1]= 0x00; |
| 112 | if (2 != (rc = i2c_master_send(i2c_client_s,buf,2))) |
Mauro Carvalho Chehab | 0680481 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 113 | v4l_err(i2c_client_s,"i2c i/o error VPS: rc == %d (should be 2)\n",rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 115 | bt832_hexdump(i2c_client_s,buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
| 117 | |
| 118 | // Leave low power mode: |
Mauro Carvalho Chehab | 0680481 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 119 | v4l_err(i2c_client_s,"leave low power mode.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | buf[0]=BT832_CAM_SETUP0; //0x39 57 |
| 121 | buf[1]=0x08; |
| 122 | if (2 != (rc = i2c_master_send(i2c_client_s,buf,2))) |
Mauro Carvalho Chehab | 0680481 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 123 | v4l_err(i2c_client_s,"i2c i/o error LLPM: rc == %d (should be 2)\n",rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 125 | bt832_hexdump(i2c_client_s,buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
Mauro Carvalho Chehab | 0680481 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 127 | v4l_info(i2c_client_s,"Write 0 tp VPSTATUS\n"); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 128 | buf[0]=BT832_VP_STATUS; // Reg.52 |
| 129 | buf[1]= 0x00; |
| 130 | if (2 != (rc = i2c_master_send(i2c_client_s,buf,2))) |
Mauro Carvalho Chehab | 0680481 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 131 | v4l_err(i2c_client_s,"i2c i/o error VPS: rc == %d (should be 2)\n",rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 133 | bt832_hexdump(i2c_client_s,buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
| 135 | |
| 136 | // Enable Output |
Mauro Carvalho Chehab | 0680481 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 137 | v4l_info(i2c_client_s,"Enable Output\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | buf[0]=BT832_VP_CONTROL1; // Reg.40 |
| 139 | buf[1]= 0x27 & (~0x01); // Default | !skip |
| 140 | if (2 != (rc = i2c_master_send(i2c_client_s,buf,2))) |
Mauro Carvalho Chehab | 0680481 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 141 | v4l_err(i2c_client_s,"i2c i/o error EO: rc == %d (should be 2)\n",rc); |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 142 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 143 | bt832_hexdump(i2c_client_s,buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | // for testing (even works when no camera attached) |
Mauro Carvalho Chehab | 0680481 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 147 | v4l_info(i2c_client_s,"*** Generate NTSC M Bars *****\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | buf[0]=BT832_VP_TESTCONTROL0; // Reg. 42 |
| 149 | buf[1]=3; // Generate NTSC System M bars, Generate Frame timing internally |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 150 | if (2 != (rc = i2c_master_send(i2c_client_s,buf,2))) |
Mauro Carvalho Chehab | 0680481 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 151 | v4l_info(i2c_client_s,"i2c i/o error MBAR: rc == %d (should be 2)\n",rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
Mauro Carvalho Chehab | 0680481 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 153 | v4l_info(i2c_client_s,"Camera Present: %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | (buf[1+BT832_CAM_STATUS] & BT832_56_CAMERA_PRESENT) ? "yes":"no"); |
| 155 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 156 | bt832_hexdump(i2c_client_s,buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | kfree(buf); |
| 158 | return 1; |
| 159 | } |
| 160 | |
| 161 | |
| 162 | |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 163 | static int bt832_attach(struct i2c_adapter *adap, int addr, int kind) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | { |
| 165 | struct bt832 *t; |
| 166 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 167 | client_template.adapter = adap; |
| 168 | client_template.addr = addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
Panagiotis Issaris | 7408187 | 2006-01-11 19:40:56 -0200 | [diff] [blame] | 170 | if (NULL == (t = kzalloc(sizeof(*t), GFP_KERNEL))) |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 171 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | t->client = client_template; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 173 | i2c_set_clientdata(&t->client, t); |
| 174 | i2c_attach_client(&t->client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Mauro Carvalho Chehab | 0680481 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 176 | v4l_info(&t->client,"chip found @ 0x%x\n", addr<<1); |
| 177 | |
| 178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | if(! bt832_init(&t->client)) { |
| 180 | bt832_detach(&t->client); |
| 181 | return -1; |
| 182 | } |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | static int bt832_probe(struct i2c_adapter *adap) |
| 188 | { |
| 189 | if (adap->class & I2C_CLASS_TV_ANALOG) |
| 190 | return i2c_probe(adap, &addr_data, bt832_attach); |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | static int bt832_detach(struct i2c_client *client) |
| 195 | { |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 196 | struct bt832 *t = i2c_get_clientdata(client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
Mauro Carvalho Chehab | 0680481 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 198 | v4l_info(&t->client,"dettach\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | i2c_detach_client(client); |
| 200 | kfree(t); |
| 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | static int |
| 205 | bt832_command(struct i2c_client *client, unsigned int cmd, void *arg) |
| 206 | { |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 207 | struct bt832 *t = i2c_get_clientdata(client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
Mauro Carvalho Chehab | 0680481 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 209 | if (debug>1) |
| 210 | v4l_i2c_print_ioctl(&t->client,cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 212 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | case BT832_HEXDUMP: { |
| 214 | unsigned char *buf; |
| 215 | buf=kmalloc(65,GFP_KERNEL); |
| 216 | bt832_hexdump(&t->client,buf); |
| 217 | kfree(buf); |
| 218 | } |
| 219 | break; |
| 220 | case BT832_REATTACH: |
Mauro Carvalho Chehab | 0680481 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 221 | v4l_info(&t->client,"re-attach\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | i2c_del_driver(&driver); |
| 223 | i2c_add_driver(&driver); |
| 224 | break; |
| 225 | } |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | /* ----------------------------------------------------------------------- */ |
| 230 | |
| 231 | static struct i2c_driver driver = { |
Laurent Riffard | 604f28e | 2005-11-26 20:43:39 +0100 | [diff] [blame] | 232 | .driver = { |
Mauro Carvalho Chehab | 0680481 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 233 | .name = "bt832", |
Laurent Riffard | 604f28e | 2005-11-26 20:43:39 +0100 | [diff] [blame] | 234 | }, |
Mauro Carvalho Chehab | 0680481 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 235 | .id = 0, /* FIXME */ |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 236 | .attach_adapter = bt832_probe, |
| 237 | .detach_client = bt832_detach, |
| 238 | .command = bt832_command, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | }; |
| 240 | static struct i2c_client client_template = |
| 241 | { |
Jean Delvare | fae91e7 | 2005-08-15 19:57:04 +0200 | [diff] [blame] | 242 | .name = "bt832", |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 243 | .driver = &driver, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | }; |
| 245 | |
| 246 | |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 247 | static int __init bt832_init_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | { |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 249 | return i2c_add_driver(&driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 252 | static void __exit bt832_cleanup_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | { |
| 254 | i2c_del_driver(&driver); |
| 255 | } |
| 256 | |
| 257 | module_init(bt832_init_module); |
| 258 | module_exit(bt832_cleanup_module); |
| 259 | |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 260 | /* |
| 261 | * Overrides for Emacs so that we follow Linus's tabbing style. |
| 262 | * --------------------------------------------------------------------------- |
| 263 | * Local variables: |
| 264 | * c-basic-offset: 8 |
| 265 | * End: |
| 266 | */ |