bt832.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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 <media/v4l2-common.h>
  29. #include "bttv.h"
  30. #include "bt832.h"
  31. MODULE_LICENSE("GPL");
  32. /* Addresses to scan */
  33. static unsigned short normal_i2c[] = { I2C_BT832_ALT1>>1, I2C_BT832_ALT2>>1,
  34. I2C_CLIENT_END };
  35. I2C_CLIENT_INSMOD;
  36. int debug; /* debug output */
  37. module_param(debug, int, 0644);
  38. /* ---------------------------------------------------------------------- */
  39. static int bt832_detach(struct i2c_client *client);
  40. static struct i2c_driver driver;
  41. static struct i2c_client client_template;
  42. struct bt832 {
  43. struct i2c_client client;
  44. };
  45. int bt832_hexdump(struct i2c_client *i2c_client_s, unsigned char *buf)
  46. {
  47. int i,rc;
  48. buf[0]=0x80; // start at register 0 with auto-increment
  49. if (1 != (rc = i2c_master_send(i2c_client_s,buf,1)))
  50. v4l_err(i2c_client_s,"i2c i/o error: rc == %d (should be 1)\n",rc);
  51. for(i=0;i<65;i++)
  52. buf[i]=0;
  53. if (65 != (rc=i2c_master_recv(i2c_client_s,buf,65)))
  54. v4l_err(i2c_client_s,"i2c i/o error: rc == %d (should be 65)\n",rc);
  55. // Note: On READ the first byte is the current index
  56. // (e.g. 0x80, what we just wrote)
  57. if(debug>1) {
  58. int i;
  59. v4l_dbg(2, debug,i2c_client_s,"hexdump:");
  60. for(i=1;i<65;i++) {
  61. if(i!=1) {
  62. if(((i-1)%8)==0) printk(" ");
  63. if(((i-1)%16)==0) {
  64. printk("\n");
  65. v4l_dbg(2, debug,i2c_client_s,"hexdump:");
  66. }
  67. }
  68. printk(" %02x",buf[i]);
  69. }
  70. printk("\n");
  71. }
  72. return 0;
  73. }
  74. // Return: 1 (is a bt832), 0 (No bt832 here)
  75. int bt832_init(struct i2c_client *i2c_client_s)
  76. {
  77. unsigned char *buf;
  78. int rc;
  79. buf=kmalloc(65,GFP_KERNEL);
  80. bt832_hexdump(i2c_client_s,buf);
  81. if(buf[0x40] != 0x31) {
  82. v4l_err(i2c_client_s,"This i2c chip is no bt832 (id=%02x). Detaching.\n",buf[0x40]);
  83. kfree(buf);
  84. return 0;
  85. }
  86. v4l_err(i2c_client_s,"Write 0 tp VPSTATUS\n");
  87. buf[0]=BT832_VP_STATUS; // Reg.52
  88. buf[1]= 0x00;
  89. if (2 != (rc = i2c_master_send(i2c_client_s,buf,2)))
  90. v4l_err(i2c_client_s,"i2c i/o error VPS: rc == %d (should be 2)\n",rc);
  91. bt832_hexdump(i2c_client_s,buf);
  92. // Leave low power mode:
  93. v4l_err(i2c_client_s,"leave low power mode.\n");
  94. buf[0]=BT832_CAM_SETUP0; //0x39 57
  95. buf[1]=0x08;
  96. if (2 != (rc = i2c_master_send(i2c_client_s,buf,2)))
  97. v4l_err(i2c_client_s,"i2c i/o error LLPM: rc == %d (should be 2)\n",rc);
  98. bt832_hexdump(i2c_client_s,buf);
  99. v4l_info(i2c_client_s,"Write 0 tp VPSTATUS\n");
  100. buf[0]=BT832_VP_STATUS; // Reg.52
  101. buf[1]= 0x00;
  102. if (2 != (rc = i2c_master_send(i2c_client_s,buf,2)))
  103. v4l_err(i2c_client_s,"i2c i/o error VPS: rc == %d (should be 2)\n",rc);
  104. bt832_hexdump(i2c_client_s,buf);
  105. // Enable Output
  106. v4l_info(i2c_client_s,"Enable Output\n");
  107. buf[0]=BT832_VP_CONTROL1; // Reg.40
  108. buf[1]= 0x27 & (~0x01); // Default | !skip
  109. if (2 != (rc = i2c_master_send(i2c_client_s,buf,2)))
  110. v4l_err(i2c_client_s,"i2c i/o error EO: rc == %d (should be 2)\n",rc);
  111. bt832_hexdump(i2c_client_s,buf);
  112. // for testing (even works when no camera attached)
  113. v4l_info(i2c_client_s,"*** Generate NTSC M Bars *****\n");
  114. buf[0]=BT832_VP_TESTCONTROL0; // Reg. 42
  115. buf[1]=3; // Generate NTSC System M bars, Generate Frame timing internally
  116. if (2 != (rc = i2c_master_send(i2c_client_s,buf,2)))
  117. v4l_info(i2c_client_s,"i2c i/o error MBAR: rc == %d (should be 2)\n",rc);
  118. v4l_info(i2c_client_s,"Camera Present: %s\n",
  119. (buf[1+BT832_CAM_STATUS] & BT832_56_CAMERA_PRESENT) ? "yes":"no");
  120. bt832_hexdump(i2c_client_s,buf);
  121. kfree(buf);
  122. return 1;
  123. }
  124. static int bt832_attach(struct i2c_adapter *adap, int addr, int kind)
  125. {
  126. struct bt832 *t;
  127. client_template.adapter = adap;
  128. client_template.addr = addr;
  129. if (NULL == (t = kzalloc(sizeof(*t), GFP_KERNEL)))
  130. return -ENOMEM;
  131. t->client = client_template;
  132. i2c_set_clientdata(&t->client, t);
  133. i2c_attach_client(&t->client);
  134. v4l_info(&t->client,"chip found @ 0x%x\n", addr<<1);
  135. if(! bt832_init(&t->client)) {
  136. bt832_detach(&t->client);
  137. return -1;
  138. }
  139. return 0;
  140. }
  141. static int bt832_probe(struct i2c_adapter *adap)
  142. {
  143. if (adap->class & I2C_CLASS_TV_ANALOG)
  144. return i2c_probe(adap, &addr_data, bt832_attach);
  145. return 0;
  146. }
  147. static int bt832_detach(struct i2c_client *client)
  148. {
  149. struct bt832 *t = i2c_get_clientdata(client);
  150. v4l_info(&t->client,"dettach\n");
  151. i2c_detach_client(client);
  152. kfree(t);
  153. return 0;
  154. }
  155. static int
  156. bt832_command(struct i2c_client *client, unsigned int cmd, void *arg)
  157. {
  158. struct bt832 *t = i2c_get_clientdata(client);
  159. if (debug>1)
  160. v4l_i2c_print_ioctl(&t->client,cmd);
  161. switch (cmd) {
  162. case BT832_HEXDUMP: {
  163. unsigned char *buf;
  164. buf=kmalloc(65,GFP_KERNEL);
  165. bt832_hexdump(&t->client,buf);
  166. kfree(buf);
  167. }
  168. break;
  169. case BT832_REATTACH:
  170. v4l_info(&t->client,"re-attach\n");
  171. i2c_del_driver(&driver);
  172. i2c_add_driver(&driver);
  173. break;
  174. }
  175. return 0;
  176. }
  177. /* ----------------------------------------------------------------------- */
  178. static struct i2c_driver driver = {
  179. .driver = {
  180. .name = "bt832",
  181. },
  182. .id = 0, /* FIXME */
  183. .attach_adapter = bt832_probe,
  184. .detach_client = bt832_detach,
  185. .command = bt832_command,
  186. };
  187. static struct i2c_client client_template =
  188. {
  189. .name = "bt832",
  190. .driver = &driver,
  191. };
  192. static int __init bt832_init_module(void)
  193. {
  194. return i2c_add_driver(&driver);
  195. }
  196. static void __exit bt832_cleanup_module(void)
  197. {
  198. i2c_del_driver(&driver);
  199. }
  200. module_init(bt832_init_module);
  201. module_exit(bt832_cleanup_module);
  202. /*
  203. * Overrides for Emacs so that we follow Linus's tabbing style.
  204. * ---------------------------------------------------------------------------
  205. * Local variables:
  206. * c-basic-offset: 8
  207. * End:
  208. */