bt832.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. #if 0
  109. // Full 30/25 Frame rate
  110. printk("Full 30/25 Frame rate\n");
  111. buf[0]=BT832_VP_CONTROL0; // Reg.39
  112. buf[1]= 0x00;
  113. if (2 != (rc = i2c_master_send(i2c_client_s,buf,2)))
  114. printk("bt832: i2c i/o error FFR: rc == %d (should be 2)\n",rc);
  115. bt832_hexdump(i2c_client_s,buf);
  116. #endif
  117. #if 1
  118. // for testing (even works when no camera attached)
  119. printk("bt832: *** Generate NTSC M Bars *****\n");
  120. buf[0]=BT832_VP_TESTCONTROL0; // Reg. 42
  121. buf[1]=3; // Generate NTSC System M bars, Generate Frame timing internally
  122. if (2 != (rc = i2c_master_send(i2c_client_s,buf,2)))
  123. printk("bt832: i2c i/o error MBAR: rc == %d (should be 2)\n",rc);
  124. #endif
  125. printk("Bt832: Camera Present: %s\n",
  126. (buf[1+BT832_CAM_STATUS] & BT832_56_CAMERA_PRESENT) ? "yes":"no");
  127. bt832_hexdump(i2c_client_s,buf);
  128. kfree(buf);
  129. return 1;
  130. }
  131. static int bt832_attach(struct i2c_adapter *adap, int addr, int kind)
  132. {
  133. struct bt832 *t;
  134. printk("bt832_attach\n");
  135. client_template.adapter = adap;
  136. client_template.addr = addr;
  137. printk("bt832: chip found @ 0x%x\n", addr<<1);
  138. if (NULL == (t = kmalloc(sizeof(*t), GFP_KERNEL)))
  139. return -ENOMEM;
  140. memset(t,0,sizeof(*t));
  141. t->client = client_template;
  142. i2c_set_clientdata(&t->client, t);
  143. i2c_attach_client(&t->client);
  144. if(! bt832_init(&t->client)) {
  145. bt832_detach(&t->client);
  146. return -1;
  147. }
  148. return 0;
  149. }
  150. static int bt832_probe(struct i2c_adapter *adap)
  151. {
  152. #ifdef I2C_CLASS_TV_ANALOG
  153. if (adap->class & I2C_CLASS_TV_ANALOG)
  154. return i2c_probe(adap, &addr_data, bt832_attach);
  155. #else
  156. if (adap->id == (I2C_ALGO_BIT | I2C_HW_B_BT848))
  157. return i2c_probe(adap, &addr_data, bt832_attach);
  158. #endif
  159. return 0;
  160. }
  161. static int bt832_detach(struct i2c_client *client)
  162. {
  163. struct bt832 *t = i2c_get_clientdata(client);
  164. printk("bt832: detach.\n");
  165. i2c_detach_client(client);
  166. kfree(t);
  167. return 0;
  168. }
  169. static int
  170. bt832_command(struct i2c_client *client, unsigned int cmd, void *arg)
  171. {
  172. struct bt832 *t = i2c_get_clientdata(client);
  173. printk("bt832: command %x\n",cmd);
  174. switch (cmd) {
  175. case BT832_HEXDUMP: {
  176. unsigned char *buf;
  177. buf=kmalloc(65,GFP_KERNEL);
  178. bt832_hexdump(&t->client,buf);
  179. kfree(buf);
  180. }
  181. break;
  182. case BT832_REATTACH:
  183. printk("bt832: re-attach\n");
  184. i2c_del_driver(&driver);
  185. i2c_add_driver(&driver);
  186. break;
  187. }
  188. return 0;
  189. }
  190. /* ----------------------------------------------------------------------- */
  191. static struct i2c_driver driver = {
  192. .owner = THIS_MODULE,
  193. .name = "i2c bt832 driver",
  194. .id = -1, /* FIXME */
  195. .flags = I2C_DF_NOTIFY,
  196. .attach_adapter = bt832_probe,
  197. .detach_client = bt832_detach,
  198. .command = bt832_command,
  199. };
  200. static struct i2c_client client_template =
  201. {
  202. I2C_DEVNAME("bt832"),
  203. .flags = I2C_CLIENT_ALLOW_USE,
  204. .driver = &driver,
  205. };
  206. static int __init bt832_init_module(void)
  207. {
  208. return i2c_add_driver(&driver);
  209. }
  210. static void __exit bt832_cleanup_module(void)
  211. {
  212. i2c_del_driver(&driver);
  213. }
  214. module_init(bt832_init_module);
  215. module_exit(bt832_cleanup_module);
  216. /*
  217. * Overrides for Emacs so that we follow Linus's tabbing style.
  218. * ---------------------------------------------------------------------------
  219. * Local variables:
  220. * c-basic-offset: 8
  221. * End:
  222. */