bt832.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /* Driver for Bt832 CMOS Camera Video Processor
  2. i2c-addresses: 0x88 or 0x8a
  3. The BT832 interfaces to a Quartzsight Digital Camera (352x288, 25 or 30 fps)
  4. via a 9 pin connector ( 4-wire SDATA, 2-wire i2c, SCLK, VCC, GND).
  5. It outputs an 8-bit 4:2:2 YUV or YCrCb video signal which can be directly
  6. connected to bt848/bt878 GPIO pins on this purpose.
  7. (see: VLSI Vision Ltd. www.vvl.co.uk for camera datasheets)
  8. Supported Cards:
  9. - Pixelview Rev.4E: 0x8a
  10. GPIO 0x400000 toggles Bt832 RESET, and the chip changes to i2c 0x88 !
  11. (c) Gunther Mayer, 2002
  12. STATUS:
  13. - detect chip and hexdump
  14. - reset chip and leave low power mode
  15. - detect camera present
  16. TODO:
  17. - make it work (find correct setup for Bt832 and Bt878)
  18. */
  19. #include <linux/module.h>
  20. #include <linux/kernel.h>
  21. #include <linux/i2c.h>
  22. #include <linux/types.h>
  23. #include <linux/videodev.h>
  24. #include <linux/init.h>
  25. #include <linux/errno.h>
  26. #include <linux/slab.h>
  27. #include <media/audiochip.h>
  28. #include "bttv.h"
  29. #include "bt832.h"
  30. MODULE_LICENSE("GPL");
  31. /* Addresses to scan */
  32. static unsigned short normal_i2c[] = { I2C_BT832_ALT1>>1, I2C_BT832_ALT2>>1,
  33. I2C_CLIENT_END };
  34. I2C_CLIENT_INSMOD;
  35. /* ---------------------------------------------------------------------- */
  36. #define dprintk if (debug) printk
  37. static int bt832_detach(struct i2c_client *client);
  38. static struct i2c_driver driver;
  39. static struct i2c_client client_template;
  40. struct bt832 {
  41. struct i2c_client client;
  42. };
  43. int bt832_hexdump(struct i2c_client *i2c_client_s, unsigned char *buf)
  44. {
  45. int i,rc;
  46. buf[0]=0x80; // start at register 0 with auto-increment
  47. if (1 != (rc = i2c_master_send(i2c_client_s,buf,1)))
  48. printk("bt832: i2c i/o error: rc == %d (should be 1)\n",rc);
  49. for(i=0;i<65;i++)
  50. buf[i]=0;
  51. if (65 != (rc=i2c_master_recv(i2c_client_s,buf,65)))
  52. printk("bt832: i2c i/o error: rc == %d (should be 65)\n",rc);
  53. // Note: On READ the first byte is the current index
  54. // (e.g. 0x80, what we just wrote)
  55. if(1) {
  56. int i;
  57. printk("BT832 hexdump:\n");
  58. for(i=1;i<65;i++) {
  59. if(i!=1) {
  60. if(((i-1)%8)==0) printk(" ");
  61. if(((i-1)%16)==0) printk("\n");
  62. }
  63. printk(" %02x",buf[i]);
  64. }
  65. printk("\n");
  66. }
  67. return 0;
  68. }
  69. // Return: 1 (is a bt832), 0 (No bt832 here)
  70. int bt832_init(struct i2c_client *i2c_client_s)
  71. {
  72. unsigned char *buf;
  73. int rc;
  74. buf=kmalloc(65,GFP_KERNEL);
  75. bt832_hexdump(i2c_client_s,buf);
  76. if(buf[0x40] != 0x31) {
  77. printk("bt832: this i2c chip is no bt832 (id=%02x). Detaching.\n",buf[0x40]);
  78. kfree(buf);
  79. return 0;
  80. }
  81. printk("Write 0 tp VPSTATUS\n");
  82. buf[0]=BT832_VP_STATUS; // Reg.52
  83. buf[1]= 0x00;
  84. if (2 != (rc = i2c_master_send(i2c_client_s,buf,2)))
  85. printk("bt832: i2c i/o error VPS: rc == %d (should be 2)\n",rc);
  86. bt832_hexdump(i2c_client_s,buf);
  87. // Leave low power mode:
  88. printk("Bt832: leave low power mode.\n");
  89. buf[0]=BT832_CAM_SETUP0; //0x39 57
  90. buf[1]=0x08;
  91. if (2 != (rc = i2c_master_send(i2c_client_s,buf,2)))
  92. printk("bt832: i2c i/o error LLPM: rc == %d (should be 2)\n",rc);
  93. bt832_hexdump(i2c_client_s,buf);
  94. printk("Write 0 tp VPSTATUS\n");
  95. buf[0]=BT832_VP_STATUS; // Reg.52
  96. buf[1]= 0x00;
  97. if (2 != (rc = i2c_master_send(i2c_client_s,buf,2)))
  98. printk("bt832: i2c i/o error VPS: rc == %d (should be 2)\n",rc);
  99. bt832_hexdump(i2c_client_s,buf);
  100. // Enable Output
  101. printk("Enable Output\n");
  102. buf[0]=BT832_VP_CONTROL1; // Reg.40
  103. buf[1]= 0x27 & (~0x01); // Default | !skip
  104. if (2 != (rc = i2c_master_send(i2c_client_s,buf,2)))
  105. printk("bt832: i2c i/o error EO: rc == %d (should be 2)\n",rc);
  106. bt832_hexdump(i2c_client_s,buf);
  107. // for testing (even works when no camera attached)
  108. printk("bt832: *** Generate NTSC M Bars *****\n");
  109. buf[0]=BT832_VP_TESTCONTROL0; // Reg. 42
  110. buf[1]=3; // Generate NTSC System M bars, Generate Frame timing internally
  111. if (2 != (rc = i2c_master_send(i2c_client_s,buf,2)))
  112. printk("bt832: i2c i/o error MBAR: rc == %d (should be 2)\n",rc);
  113. printk("Bt832: Camera Present: %s\n",
  114. (buf[1+BT832_CAM_STATUS] & BT832_56_CAMERA_PRESENT) ? "yes":"no");
  115. bt832_hexdump(i2c_client_s,buf);
  116. kfree(buf);
  117. return 1;
  118. }
  119. static int bt832_attach(struct i2c_adapter *adap, int addr, int kind)
  120. {
  121. struct bt832 *t;
  122. printk("bt832_attach\n");
  123. client_template.adapter = adap;
  124. client_template.addr = addr;
  125. printk("bt832: chip found @ 0x%x\n", addr<<1);
  126. if (NULL == (t = kmalloc(sizeof(*t), GFP_KERNEL)))
  127. return -ENOMEM;
  128. memset(t,0,sizeof(*t));
  129. t->client = client_template;
  130. i2c_set_clientdata(&t->client, t);
  131. i2c_attach_client(&t->client);
  132. if(! bt832_init(&t->client)) {
  133. bt832_detach(&t->client);
  134. return -1;
  135. }
  136. return 0;
  137. }
  138. static int bt832_probe(struct i2c_adapter *adap)
  139. {
  140. if (adap->class & I2C_CLASS_TV_ANALOG)
  141. return i2c_probe(adap, &addr_data, bt832_attach);
  142. return 0;
  143. }
  144. static int bt832_detach(struct i2c_client *client)
  145. {
  146. struct bt832 *t = i2c_get_clientdata(client);
  147. printk("bt832: detach.\n");
  148. i2c_detach_client(client);
  149. kfree(t);
  150. return 0;
  151. }
  152. static int
  153. bt832_command(struct i2c_client *client, unsigned int cmd, void *arg)
  154. {
  155. struct bt832 *t = i2c_get_clientdata(client);
  156. printk("bt832: command %x\n",cmd);
  157. switch (cmd) {
  158. case BT832_HEXDUMP: {
  159. unsigned char *buf;
  160. buf=kmalloc(65,GFP_KERNEL);
  161. bt832_hexdump(&t->client,buf);
  162. kfree(buf);
  163. }
  164. break;
  165. case BT832_REATTACH:
  166. printk("bt832: re-attach\n");
  167. i2c_del_driver(&driver);
  168. i2c_add_driver(&driver);
  169. break;
  170. }
  171. return 0;
  172. }
  173. /* ----------------------------------------------------------------------- */
  174. static struct i2c_driver driver = {
  175. .driver = {
  176. .name = "i2c bt832 driver",
  177. },
  178. .id = -1, /* FIXME */
  179. .attach_adapter = bt832_probe,
  180. .detach_client = bt832_detach,
  181. .command = bt832_command,
  182. };
  183. static struct i2c_client client_template =
  184. {
  185. .name = "bt832",
  186. .driver = &driver,
  187. };
  188. static int __init bt832_init_module(void)
  189. {
  190. return i2c_add_driver(&driver);
  191. }
  192. static void __exit bt832_cleanup_module(void)
  193. {
  194. i2c_del_driver(&driver);
  195. }
  196. module_init(bt832_init_module);
  197. module_exit(bt832_cleanup_module);
  198. /*
  199. * Overrides for Emacs so that we follow Linus's tabbing style.
  200. * ---------------------------------------------------------------------------
  201. * Local variables:
  202. * c-basic-offset: 8
  203. * End:
  204. */