meye.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. /*
  2. * Motion Eye video4linux driver for Sony Vaio PictureBook
  3. *
  4. * Copyright (C) 2001-2004 Stelian Pop <stelian@popies.net>
  5. *
  6. * Copyright (C) 2001-2002 Alcôve <www.alcove.com>
  7. *
  8. * Copyright (C) 2000 Andrew Tridgell <tridge@valinux.com>
  9. *
  10. * Earlier work by Werner Almesberger, Paul `Rusty' Russell and Paul Mackerras.
  11. *
  12. * Some parts borrowed from various video4linux drivers, especially
  13. * bttv-driver.c and zoran.c, see original files for credits.
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  28. */
  29. #ifndef _MEYE_PRIV_H_
  30. #define _MEYE_PRIV_H_
  31. #define MEYE_DRIVER_MAJORVERSION 1
  32. #define MEYE_DRIVER_MINORVERSION 14
  33. #define MEYE_DRIVER_VERSION __stringify(MEYE_DRIVER_MAJORVERSION) "." \
  34. __stringify(MEYE_DRIVER_MINORVERSION)
  35. #include <linux/types.h>
  36. #include <linux/pci.h>
  37. #include <linux/kfifo.h>
  38. #include <media/v4l2-ctrls.h>
  39. /****************************************************************************/
  40. /* Motion JPEG chip registers */
  41. /****************************************************************************/
  42. /* Motion JPEG chip PCI configuration registers */
  43. #define MCHIP_PCI_POWER_CSR 0x54
  44. #define MCHIP_PCI_MCORE_STATUS 0x60 /* see HIC_STATUS */
  45. #define MCHIP_PCI_HOSTUSEREQ_SET 0x64
  46. #define MCHIP_PCI_HOSTUSEREQ_CLR 0x68
  47. #define MCHIP_PCI_LOWPOWER_SET 0x6c
  48. #define MCHIP_PCI_LOWPOWER_CLR 0x70
  49. #define MCHIP_PCI_SOFTRESET_SET 0x74
  50. /* Motion JPEG chip memory mapped registers */
  51. #define MCHIP_MM_REGS 0x200 /* 512 bytes */
  52. #define MCHIP_REG_TIMEOUT 1000 /* reg access, ~us */
  53. #define MCHIP_MCC_VRJ_TIMEOUT 1000 /* MCC & VRJ access */
  54. #define MCHIP_MM_PCI_MODE 0x00 /* PCI access mode */
  55. #define MCHIP_MM_PCI_MODE_RETRY 0x00000001 /* retry mode */
  56. #define MCHIP_MM_PCI_MODE_MASTER 0x00000002 /* master access */
  57. #define MCHIP_MM_PCI_MODE_READ_LINE 0x00000004 /* read line */
  58. #define MCHIP_MM_INTA 0x04 /* Int status/mask */
  59. #define MCHIP_MM_INTA_MCC 0x00000001 /* MCC interrupt */
  60. #define MCHIP_MM_INTA_VRJ 0x00000002 /* VRJ interrupt */
  61. #define MCHIP_MM_INTA_HIC_1 0x00000004 /* one frame done */
  62. #define MCHIP_MM_INTA_HIC_1_MASK 0x00000400 /* 1: enable */
  63. #define MCHIP_MM_INTA_HIC_END 0x00000008 /* all frames done */
  64. #define MCHIP_MM_INTA_HIC_END_MASK 0x00000800
  65. #define MCHIP_MM_INTA_JPEG 0x00000010 /* decompress. error */
  66. #define MCHIP_MM_INTA_JPEG_MASK 0x00001000
  67. #define MCHIP_MM_INTA_CAPTURE 0x00000020 /* capture end */
  68. #define MCHIP_MM_INTA_PCI_ERR 0x00000040 /* PCI error */
  69. #define MCHIP_MM_INTA_PCI_ERR_MASK 0x00004000
  70. #define MCHIP_MM_PT_ADDR 0x08 /* page table address*/
  71. /* n*4kB */
  72. #define MCHIP_NB_PAGES 1024 /* pages for display */
  73. #define MCHIP_NB_PAGES_MJPEG 256 /* pages for mjpeg */
  74. #define MCHIP_MM_FIR(n) (0x0c+(n)*4) /* Frame info 0-3 */
  75. #define MCHIP_MM_FIR_RDY 0x00000001 /* frame ready */
  76. #define MCHIP_MM_FIR_FAILFR_MASK 0xf8000000 /* # of failed frames */
  77. #define MCHIP_MM_FIR_FAILFR_SHIFT 27
  78. /* continuous comp/decomp mode */
  79. #define MCHIP_MM_FIR_C_ENDL_MASK 0x000007fe /* end DW [10] */
  80. #define MCHIP_MM_FIR_C_ENDL_SHIFT 1
  81. #define MCHIP_MM_FIR_C_ENDP_MASK 0x0007f800 /* end page [8] */
  82. #define MCHIP_MM_FIR_C_ENDP_SHIFT 11
  83. #define MCHIP_MM_FIR_C_STARTP_MASK 0x07f80000 /* start page [8] */
  84. #define MCHIP_MM_FIR_C_STARTP_SHIFT 19
  85. /* continuous picture output mode */
  86. #define MCHIP_MM_FIR_O_STARTP_MASK 0x7ffe0000 /* start page [10] */
  87. #define MCHIP_MM_FIR_O_STARTP_SHIFT 17
  88. #define MCHIP_MM_FIFO_DATA 0x1c /* PCI TGT FIFO data */
  89. #define MCHIP_MM_FIFO_STATUS 0x20 /* PCI TGT FIFO stat */
  90. #define MCHIP_MM_FIFO_MASK 0x00000003
  91. #define MCHIP_MM_FIFO_WAIT_OR_READY 0x00000002 /* Bits common to WAIT & READY*/
  92. #define MCHIP_MM_FIFO_IDLE 0x0 /* HIC idle */
  93. #define MCHIP_MM_FIFO_IDLE1 0x1 /* idem ??? */
  94. #define MCHIP_MM_FIFO_WAIT 0x2 /* wait request */
  95. #define MCHIP_MM_FIFO_READY 0x3 /* data ready */
  96. #define MCHIP_HIC_HOST_USEREQ 0x40 /* host uses MCORE */
  97. #define MCHIP_HIC_TP_BUSY 0x44 /* taking picture */
  98. #define MCHIP_HIC_PIC_SAVED 0x48 /* pic in SDRAM */
  99. #define MCHIP_HIC_LOWPOWER 0x4c /* clock stopped */
  100. #define MCHIP_HIC_CTL 0x50 /* HIC control */
  101. #define MCHIP_HIC_CTL_SOFT_RESET 0x00000001 /* MCORE reset */
  102. #define MCHIP_HIC_CTL_MCORE_RDY 0x00000002 /* MCORE ready */
  103. #define MCHIP_HIC_CMD 0x54 /* HIC command */
  104. #define MCHIP_HIC_CMD_BITS 0x00000003 /* cmd width=[1:0]*/
  105. #define MCHIP_HIC_CMD_NOOP 0x0
  106. #define MCHIP_HIC_CMD_START 0x1
  107. #define MCHIP_HIC_CMD_STOP 0x2
  108. #define MCHIP_HIC_MODE 0x58
  109. #define MCHIP_HIC_MODE_NOOP 0x0
  110. #define MCHIP_HIC_MODE_STILL_CAP 0x1 /* still pic capt */
  111. #define MCHIP_HIC_MODE_DISPLAY 0x2 /* display */
  112. #define MCHIP_HIC_MODE_STILL_COMP 0x3 /* still pic comp. */
  113. #define MCHIP_HIC_MODE_STILL_DECOMP 0x4 /* still pic decomp. */
  114. #define MCHIP_HIC_MODE_CONT_COMP 0x5 /* cont capt+comp */
  115. #define MCHIP_HIC_MODE_CONT_DECOMP 0x6 /* cont decomp+disp */
  116. #define MCHIP_HIC_MODE_STILL_OUT 0x7 /* still pic output */
  117. #define MCHIP_HIC_MODE_CONT_OUT 0x8 /* cont output */
  118. #define MCHIP_HIC_STATUS 0x5c
  119. #define MCHIP_HIC_STATUS_MCC_RDY 0x00000001 /* MCC reg acc ok */
  120. #define MCHIP_HIC_STATUS_VRJ_RDY 0x00000002 /* VRJ reg acc ok */
  121. #define MCHIP_HIC_STATUS_IDLE 0x00000003
  122. #define MCHIP_HIC_STATUS_CAPDIS 0x00000004 /* cap/disp in prog */
  123. #define MCHIP_HIC_STATUS_COMPDEC 0x00000008 /* (de)comp in prog */
  124. #define MCHIP_HIC_STATUS_BUSY 0x00000010 /* HIC busy */
  125. #define MCHIP_HIC_S_RATE 0x60 /* MJPEG # frames */
  126. #define MCHIP_HIC_PCI_VFMT 0x64 /* video format */
  127. #define MCHIP_HIC_PCI_VFMT_YVYU 0x00000001 /* 0: V Y' U Y */
  128. /* 1: Y' V Y U */
  129. #define MCHIP_MCC_CMD 0x80 /* MCC commands */
  130. #define MCHIP_MCC_CMD_INITIAL 0x0 /* idle ? */
  131. #define MCHIP_MCC_CMD_IIC_START_SET 0x1
  132. #define MCHIP_MCC_CMD_IIC_END_SET 0x2
  133. #define MCHIP_MCC_CMD_FM_WRITE 0x3 /* frame memory */
  134. #define MCHIP_MCC_CMD_FM_READ 0x4
  135. #define MCHIP_MCC_CMD_FM_STOP 0x5
  136. #define MCHIP_MCC_CMD_CAPTURE 0x6
  137. #define MCHIP_MCC_CMD_DISPLAY 0x7
  138. #define MCHIP_MCC_CMD_END_DISP 0x8
  139. #define MCHIP_MCC_CMD_STILL_COMP 0x9
  140. #define MCHIP_MCC_CMD_STILL_DECOMP 0xa
  141. #define MCHIP_MCC_CMD_STILL_OUTPUT 0xb
  142. #define MCHIP_MCC_CMD_CONT_OUTPUT 0xc
  143. #define MCHIP_MCC_CMD_CONT_COMP 0xd
  144. #define MCHIP_MCC_CMD_CONT_DECOMP 0xe
  145. #define MCHIP_MCC_CMD_RESET 0xf /* MCC reset */
  146. #define MCHIP_MCC_IIC_WR 0x84
  147. #define MCHIP_MCC_MCC_WR 0x88
  148. #define MCHIP_MCC_MCC_RD 0x8c
  149. #define MCHIP_MCC_STATUS 0x90
  150. #define MCHIP_MCC_STATUS_CAPT 0x00000001 /* capturing */
  151. #define MCHIP_MCC_STATUS_DISP 0x00000002 /* displaying */
  152. #define MCHIP_MCC_STATUS_COMP 0x00000004 /* compressing */
  153. #define MCHIP_MCC_STATUS_DECOMP 0x00000008 /* decompressing */
  154. #define MCHIP_MCC_STATUS_MCC_WR 0x00000010 /* register ready */
  155. #define MCHIP_MCC_STATUS_MCC_RD 0x00000020 /* register ready */
  156. #define MCHIP_MCC_STATUS_IIC_WR 0x00000040 /* register ready */
  157. #define MCHIP_MCC_STATUS_OUTPUT 0x00000080 /* output in prog */
  158. #define MCHIP_MCC_SIG_POLARITY 0x94
  159. #define MCHIP_MCC_SIG_POL_VS_H 0x00000001 /* VS active-high */
  160. #define MCHIP_MCC_SIG_POL_HS_H 0x00000002 /* HS active-high */
  161. #define MCHIP_MCC_SIG_POL_DOE_H 0x00000004 /* DOE active-high */
  162. #define MCHIP_MCC_IRQ 0x98
  163. #define MCHIP_MCC_IRQ_CAPDIS_STRT 0x00000001 /* cap/disp started */
  164. #define MCHIP_MCC_IRQ_CAPDIS_STRT_MASK 0x00000010
  165. #define MCHIP_MCC_IRQ_CAPDIS_END 0x00000002 /* cap/disp ended */
  166. #define MCHIP_MCC_IRQ_CAPDIS_END_MASK 0x00000020
  167. #define MCHIP_MCC_IRQ_COMPDEC_STRT 0x00000004 /* (de)comp started */
  168. #define MCHIP_MCC_IRQ_COMPDEC_STRT_MASK 0x00000040
  169. #define MCHIP_MCC_IRQ_COMPDEC_END 0x00000008 /* (de)comp ended */
  170. #define MCHIP_MCC_IRQ_COMPDEC_END_MASK 0x00000080
  171. #define MCHIP_MCC_HSTART 0x9c /* video in */
  172. #define MCHIP_MCC_VSTART 0xa0
  173. #define MCHIP_MCC_HCOUNT 0xa4
  174. #define MCHIP_MCC_VCOUNT 0xa8
  175. #define MCHIP_MCC_R_XBASE 0xac /* capt/disp */
  176. #define MCHIP_MCC_R_YBASE 0xb0
  177. #define MCHIP_MCC_R_XRANGE 0xb4
  178. #define MCHIP_MCC_R_YRANGE 0xb8
  179. #define MCHIP_MCC_B_XBASE 0xbc /* comp/decomp */
  180. #define MCHIP_MCC_B_YBASE 0xc0
  181. #define MCHIP_MCC_B_XRANGE 0xc4
  182. #define MCHIP_MCC_B_YRANGE 0xc8
  183. #define MCHIP_MCC_R_SAMPLING 0xcc /* 1: 1:4 */
  184. #define MCHIP_VRJ_CMD 0x100 /* VRJ commands */
  185. /* VRJ registers (see table 12.2.4) */
  186. #define MCHIP_VRJ_COMPRESSED_DATA 0x1b0
  187. #define MCHIP_VRJ_PIXEL_DATA 0x1b8
  188. #define MCHIP_VRJ_BUS_MODE 0x100
  189. #define MCHIP_VRJ_SIGNAL_ACTIVE_LEVEL 0x108
  190. #define MCHIP_VRJ_PDAT_USE 0x110
  191. #define MCHIP_VRJ_MODE_SPECIFY 0x118
  192. #define MCHIP_VRJ_LIMIT_COMPRESSED_LO 0x120
  193. #define MCHIP_VRJ_LIMIT_COMPRESSED_HI 0x124
  194. #define MCHIP_VRJ_COMP_DATA_FORMAT 0x128
  195. #define MCHIP_VRJ_TABLE_DATA 0x140
  196. #define MCHIP_VRJ_RESTART_INTERVAL 0x148
  197. #define MCHIP_VRJ_NUM_LINES 0x150
  198. #define MCHIP_VRJ_NUM_PIXELS 0x158
  199. #define MCHIP_VRJ_NUM_COMPONENTS 0x160
  200. #define MCHIP_VRJ_SOF1 0x168
  201. #define MCHIP_VRJ_SOF2 0x170
  202. #define MCHIP_VRJ_SOF3 0x178
  203. #define MCHIP_VRJ_SOF4 0x180
  204. #define MCHIP_VRJ_SOS 0x188
  205. #define MCHIP_VRJ_SOFT_RESET 0x190
  206. #define MCHIP_VRJ_STATUS 0x1c0
  207. #define MCHIP_VRJ_STATUS_BUSY 0x00001
  208. #define MCHIP_VRJ_STATUS_COMP_ACCESS 0x00002
  209. #define MCHIP_VRJ_STATUS_PIXEL_ACCESS 0x00004
  210. #define MCHIP_VRJ_STATUS_ERROR 0x00008
  211. #define MCHIP_VRJ_IRQ_FLAG 0x1c8
  212. #define MCHIP_VRJ_ERROR_REPORT 0x1d8
  213. #define MCHIP_VRJ_START_COMMAND 0x1a0
  214. /****************************************************************************/
  215. /* Driver definitions. */
  216. /****************************************************************************/
  217. /* Sony Programmable I/O Controller for accessing the camera commands */
  218. #include <linux/sony-laptop.h>
  219. /* private API definitions */
  220. #include <linux/meye.h>
  221. #include <linux/mutex.h>
  222. /* Enable jpg software correction */
  223. #define MEYE_JPEG_CORRECTION 1
  224. /* Maximum size of a buffer */
  225. #define MEYE_MAX_BUFSIZE 614400 /* 640 * 480 * 2 */
  226. /* Maximum number of buffers */
  227. #define MEYE_MAX_BUFNBRS 32
  228. /* State of a buffer */
  229. #define MEYE_BUF_UNUSED 0 /* not used */
  230. #define MEYE_BUF_USING 1 /* currently grabbing / playing */
  231. #define MEYE_BUF_DONE 2 /* done */
  232. /* grab buffer */
  233. struct meye_grab_buffer {
  234. int state; /* state of buffer */
  235. unsigned long size; /* size of jpg frame */
  236. struct timeval timestamp; /* timestamp */
  237. unsigned long sequence; /* sequence number */
  238. };
  239. /* size of kfifos containings buffer indices */
  240. #define MEYE_QUEUE_SIZE MEYE_MAX_BUFNBRS
  241. /* Motion Eye device structure */
  242. struct meye {
  243. struct v4l2_device v4l2_dev; /* Main v4l2_device struct */
  244. struct v4l2_ctrl_handler hdl;
  245. struct pci_dev *mchip_dev; /* pci device */
  246. u8 mchip_irq; /* irq */
  247. u8 mchip_mode; /* actual mchip mode: HIC_MODE... */
  248. u8 mchip_fnum; /* current mchip frame number */
  249. unsigned char __iomem *mchip_mmregs;/* mchip: memory mapped registers */
  250. u8 *mchip_ptable[MCHIP_NB_PAGES];/* mchip: ptable */
  251. void *mchip_ptable_toc; /* mchip: ptable toc */
  252. dma_addr_t mchip_dmahandle; /* mchip: dma handle to ptable toc */
  253. unsigned char *grab_fbuffer; /* capture framebuffer */
  254. unsigned char *grab_temp; /* temporary buffer */
  255. /* list of buffers */
  256. struct meye_grab_buffer grab_buffer[MEYE_MAX_BUFNBRS];
  257. int vma_use_count[MEYE_MAX_BUFNBRS]; /* mmap count */
  258. struct mutex lock; /* mutex for open/mmap... */
  259. struct kfifo grabq; /* queue for buffers to be grabbed */
  260. spinlock_t grabq_lock; /* lock protecting the queue */
  261. struct kfifo doneq; /* queue for grabbed buffers */
  262. spinlock_t doneq_lock; /* lock protecting the queue */
  263. wait_queue_head_t proc_list; /* wait queue */
  264. struct video_device vdev; /* video device parameters */
  265. u16 brightness;
  266. u16 hue;
  267. u16 contrast;
  268. u16 colour;
  269. struct meye_params params; /* additional parameters */
  270. unsigned long in_use; /* set to 1 if the device is in use */
  271. #ifdef CONFIG_PM
  272. u8 pm_mchip_mode; /* old mchip mode */
  273. #endif
  274. };
  275. #endif