bt832.c 6.8 KB

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