Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * Motion Eye video4linux driver for Sony Vaio PictureBook
0004  *
0005  * Copyright (C) 2001-2004 Stelian Pop <stelian@popies.net>
0006  *
0007  * Copyright (C) 2001-2002 AlcĂ´ve <www.alcove.com>
0008  *
0009  * Copyright (C) 2000 Andrew Tridgell <tridge@valinux.com>
0010  *
0011  * Earlier work by Werner Almesberger, Paul `Rusty' Russell and Paul Mackerras.
0012  *
0013  * Some parts borrowed from various video4linux drivers, especially
0014  * bttv-driver.c and zoran.c, see original files for credits.
0015  */
0016 
0017 #ifndef _MEYE_PRIV_H_
0018 #define _MEYE_PRIV_H_
0019 
0020 #define MEYE_DRIVER_MAJORVERSION     1
0021 #define MEYE_DRIVER_MINORVERSION    14
0022 
0023 #define MEYE_DRIVER_VERSION __stringify(MEYE_DRIVER_MAJORVERSION) "." \
0024                 __stringify(MEYE_DRIVER_MINORVERSION)
0025 
0026 #include <linux/types.h>
0027 #include <linux/pci.h>
0028 #include <linux/kfifo.h>
0029 #include <media/v4l2-ctrls.h>
0030 
0031 /****************************************************************************/
0032 /* Motion JPEG chip registers                                               */
0033 /****************************************************************************/
0034 
0035 /* Motion JPEG chip PCI configuration registers */
0036 #define MCHIP_PCI_POWER_CSR     0x54
0037 #define MCHIP_PCI_MCORE_STATUS      0x60        /* see HIC_STATUS   */
0038 #define MCHIP_PCI_HOSTUSEREQ_SET    0x64
0039 #define MCHIP_PCI_HOSTUSEREQ_CLR    0x68
0040 #define MCHIP_PCI_LOWPOWER_SET      0x6c
0041 #define MCHIP_PCI_LOWPOWER_CLR      0x70
0042 #define MCHIP_PCI_SOFTRESET_SET     0x74
0043 
0044 /* Motion JPEG chip memory mapped registers */
0045 #define MCHIP_MM_REGS           0x200       /* 512 bytes        */
0046 #define MCHIP_REG_TIMEOUT       1000        /* reg access, ~us  */
0047 #define MCHIP_MCC_VRJ_TIMEOUT       1000        /* MCC & VRJ access */
0048 
0049 #define MCHIP_MM_PCI_MODE       0x00        /* PCI access mode */
0050 #define MCHIP_MM_PCI_MODE_RETRY     0x00000001  /* retry mode */
0051 #define MCHIP_MM_PCI_MODE_MASTER    0x00000002  /* master access */
0052 #define MCHIP_MM_PCI_MODE_READ_LINE 0x00000004  /* read line */
0053 
0054 #define MCHIP_MM_INTA           0x04        /* Int status/mask */
0055 #define MCHIP_MM_INTA_MCC       0x00000001  /* MCC interrupt */
0056 #define MCHIP_MM_INTA_VRJ       0x00000002  /* VRJ interrupt */
0057 #define MCHIP_MM_INTA_HIC_1     0x00000004  /* one frame done */
0058 #define MCHIP_MM_INTA_HIC_1_MASK    0x00000400  /* 1: enable */
0059 #define MCHIP_MM_INTA_HIC_END       0x00000008  /* all frames done */
0060 #define MCHIP_MM_INTA_HIC_END_MASK  0x00000800
0061 #define MCHIP_MM_INTA_JPEG      0x00000010  /* decompress. error */
0062 #define MCHIP_MM_INTA_JPEG_MASK     0x00001000
0063 #define MCHIP_MM_INTA_CAPTURE       0x00000020  /* capture end */
0064 #define MCHIP_MM_INTA_PCI_ERR       0x00000040  /* PCI error */
0065 #define MCHIP_MM_INTA_PCI_ERR_MASK  0x00004000
0066 
0067 #define MCHIP_MM_PT_ADDR        0x08        /* page table address*/
0068                             /* n*4kB */
0069 #define MCHIP_NB_PAGES          1024        /* pages for display */
0070 #define MCHIP_NB_PAGES_MJPEG        256     /* pages for mjpeg */
0071 
0072 #define MCHIP_MM_FIR(n)         (0x0c+(n)*4)    /* Frame info 0-3 */
0073 #define MCHIP_MM_FIR_RDY        0x00000001  /* frame ready */
0074 #define MCHIP_MM_FIR_FAILFR_MASK    0xf8000000  /* # of failed frames */
0075 #define MCHIP_MM_FIR_FAILFR_SHIFT   27
0076 
0077     /* continuous comp/decomp mode */
0078 #define MCHIP_MM_FIR_C_ENDL_MASK    0x000007fe  /* end DW [10] */
0079 #define MCHIP_MM_FIR_C_ENDL_SHIFT   1
0080 #define MCHIP_MM_FIR_C_ENDP_MASK    0x0007f800  /* end page [8] */
0081 #define MCHIP_MM_FIR_C_ENDP_SHIFT   11
0082 #define MCHIP_MM_FIR_C_STARTP_MASK  0x07f80000  /* start page [8] */
0083 #define MCHIP_MM_FIR_C_STARTP_SHIFT 19
0084 
0085     /* continuous picture output mode */
0086 #define MCHIP_MM_FIR_O_STARTP_MASK  0x7ffe0000  /* start page [10] */
0087 #define MCHIP_MM_FIR_O_STARTP_SHIFT 17
0088 
0089 #define MCHIP_MM_FIFO_DATA      0x1c        /* PCI TGT FIFO data */
0090 #define MCHIP_MM_FIFO_STATUS        0x20        /* PCI TGT FIFO stat */
0091 #define MCHIP_MM_FIFO_MASK      0x00000003
0092 #define MCHIP_MM_FIFO_WAIT_OR_READY 0x00000002      /* Bits common to WAIT & READY*/
0093 #define MCHIP_MM_FIFO_IDLE      0x0     /* HIC idle */
0094 #define MCHIP_MM_FIFO_IDLE1     0x1     /* idem ??? */
0095 #define MCHIP_MM_FIFO_WAIT      0x2     /* wait request */
0096 #define MCHIP_MM_FIFO_READY     0x3     /* data ready */
0097 
0098 #define MCHIP_HIC_HOST_USEREQ       0x40        /* host uses MCORE */
0099 
0100 #define MCHIP_HIC_TP_BUSY       0x44        /* taking picture */
0101 
0102 #define MCHIP_HIC_PIC_SAVED     0x48        /* pic in SDRAM */
0103 
0104 #define MCHIP_HIC_LOWPOWER      0x4c        /* clock stopped */
0105 
0106 #define MCHIP_HIC_CTL           0x50        /* HIC control */
0107 #define MCHIP_HIC_CTL_SOFT_RESET    0x00000001  /* MCORE reset */
0108 #define MCHIP_HIC_CTL_MCORE_RDY     0x00000002  /* MCORE ready */
0109 
0110 #define MCHIP_HIC_CMD           0x54        /* HIC command */
0111 #define MCHIP_HIC_CMD_BITS      0x00000003      /* cmd width=[1:0]*/
0112 #define MCHIP_HIC_CMD_NOOP      0x0
0113 #define MCHIP_HIC_CMD_START     0x1
0114 #define MCHIP_HIC_CMD_STOP      0x2
0115 
0116 #define MCHIP_HIC_MODE          0x58
0117 #define MCHIP_HIC_MODE_NOOP     0x0
0118 #define MCHIP_HIC_MODE_STILL_CAP    0x1     /* still pic capt */
0119 #define MCHIP_HIC_MODE_DISPLAY      0x2     /* display */
0120 #define MCHIP_HIC_MODE_STILL_COMP   0x3     /* still pic comp. */
0121 #define MCHIP_HIC_MODE_STILL_DECOMP 0x4     /* still pic decomp. */
0122 #define MCHIP_HIC_MODE_CONT_COMP    0x5     /* cont capt+comp */
0123 #define MCHIP_HIC_MODE_CONT_DECOMP  0x6     /* cont decomp+disp */
0124 #define MCHIP_HIC_MODE_STILL_OUT    0x7     /* still pic output */
0125 #define MCHIP_HIC_MODE_CONT_OUT     0x8     /* cont output */
0126 
0127 #define MCHIP_HIC_STATUS        0x5c
0128 #define MCHIP_HIC_STATUS_MCC_RDY    0x00000001  /* MCC reg acc ok */
0129 #define MCHIP_HIC_STATUS_VRJ_RDY    0x00000002  /* VRJ reg acc ok */
0130 #define MCHIP_HIC_STATUS_IDLE           0x00000003
0131 #define MCHIP_HIC_STATUS_CAPDIS     0x00000004  /* cap/disp in prog */
0132 #define MCHIP_HIC_STATUS_COMPDEC    0x00000008  /* (de)comp in prog */
0133 #define MCHIP_HIC_STATUS_BUSY       0x00000010  /* HIC busy */
0134 
0135 #define MCHIP_HIC_S_RATE        0x60        /* MJPEG # frames */
0136 
0137 #define MCHIP_HIC_PCI_VFMT      0x64        /* video format */
0138 #define MCHIP_HIC_PCI_VFMT_YVYU     0x00000001  /* 0: V Y' U Y */
0139                             /* 1: Y' V Y U */
0140 
0141 #define MCHIP_MCC_CMD           0x80        /* MCC commands */
0142 #define MCHIP_MCC_CMD_INITIAL       0x0     /* idle ? */
0143 #define MCHIP_MCC_CMD_IIC_START_SET 0x1
0144 #define MCHIP_MCC_CMD_IIC_END_SET   0x2
0145 #define MCHIP_MCC_CMD_FM_WRITE      0x3     /* frame memory */
0146 #define MCHIP_MCC_CMD_FM_READ       0x4
0147 #define MCHIP_MCC_CMD_FM_STOP       0x5
0148 #define MCHIP_MCC_CMD_CAPTURE       0x6
0149 #define MCHIP_MCC_CMD_DISPLAY       0x7
0150 #define MCHIP_MCC_CMD_END_DISP      0x8
0151 #define MCHIP_MCC_CMD_STILL_COMP    0x9
0152 #define MCHIP_MCC_CMD_STILL_DECOMP  0xa
0153 #define MCHIP_MCC_CMD_STILL_OUTPUT  0xb
0154 #define MCHIP_MCC_CMD_CONT_OUTPUT   0xc
0155 #define MCHIP_MCC_CMD_CONT_COMP     0xd
0156 #define MCHIP_MCC_CMD_CONT_DECOMP   0xe
0157 #define MCHIP_MCC_CMD_RESET     0xf     /* MCC reset */
0158 
0159 #define MCHIP_MCC_IIC_WR        0x84
0160 
0161 #define MCHIP_MCC_MCC_WR        0x88
0162 
0163 #define MCHIP_MCC_MCC_RD        0x8c
0164 
0165 #define MCHIP_MCC_STATUS        0x90
0166 #define MCHIP_MCC_STATUS_CAPT       0x00000001  /* capturing */
0167 #define MCHIP_MCC_STATUS_DISP       0x00000002  /* displaying */
0168 #define MCHIP_MCC_STATUS_COMP       0x00000004  /* compressing */
0169 #define MCHIP_MCC_STATUS_DECOMP     0x00000008  /* decompressing */
0170 #define MCHIP_MCC_STATUS_MCC_WR     0x00000010  /* register ready */
0171 #define MCHIP_MCC_STATUS_MCC_RD     0x00000020  /* register ready */
0172 #define MCHIP_MCC_STATUS_IIC_WR     0x00000040  /* register ready */
0173 #define MCHIP_MCC_STATUS_OUTPUT     0x00000080  /* output in prog */
0174 
0175 #define MCHIP_MCC_SIG_POLARITY      0x94
0176 #define MCHIP_MCC_SIG_POL_VS_H      0x00000001  /* VS active-high */
0177 #define MCHIP_MCC_SIG_POL_HS_H      0x00000002  /* HS active-high */
0178 #define MCHIP_MCC_SIG_POL_DOE_H     0x00000004  /* DOE active-high */
0179 
0180 #define MCHIP_MCC_IRQ           0x98
0181 #define MCHIP_MCC_IRQ_CAPDIS_STRT   0x00000001  /* cap/disp started */
0182 #define MCHIP_MCC_IRQ_CAPDIS_STRT_MASK  0x00000010
0183 #define MCHIP_MCC_IRQ_CAPDIS_END    0x00000002  /* cap/disp ended */
0184 #define MCHIP_MCC_IRQ_CAPDIS_END_MASK   0x00000020
0185 #define MCHIP_MCC_IRQ_COMPDEC_STRT  0x00000004  /* (de)comp started */
0186 #define MCHIP_MCC_IRQ_COMPDEC_STRT_MASK 0x00000040
0187 #define MCHIP_MCC_IRQ_COMPDEC_END   0x00000008  /* (de)comp ended */
0188 #define MCHIP_MCC_IRQ_COMPDEC_END_MASK  0x00000080
0189 
0190 #define MCHIP_MCC_HSTART        0x9c        /* video in */
0191 #define MCHIP_MCC_VSTART        0xa0
0192 #define MCHIP_MCC_HCOUNT        0xa4
0193 #define MCHIP_MCC_VCOUNT        0xa8
0194 #define MCHIP_MCC_R_XBASE       0xac        /* capt/disp */
0195 #define MCHIP_MCC_R_YBASE       0xb0
0196 #define MCHIP_MCC_R_XRANGE      0xb4
0197 #define MCHIP_MCC_R_YRANGE      0xb8
0198 #define MCHIP_MCC_B_XBASE       0xbc        /* comp/decomp */
0199 #define MCHIP_MCC_B_YBASE       0xc0
0200 #define MCHIP_MCC_B_XRANGE      0xc4
0201 #define MCHIP_MCC_B_YRANGE      0xc8
0202 
0203 #define MCHIP_MCC_R_SAMPLING        0xcc        /* 1: 1:4 */
0204 
0205 #define MCHIP_VRJ_CMD           0x100       /* VRJ commands */
0206 
0207 /* VRJ registers (see table 12.2.4) */
0208 #define MCHIP_VRJ_COMPRESSED_DATA   0x1b0
0209 #define MCHIP_VRJ_PIXEL_DATA        0x1b8
0210 
0211 #define MCHIP_VRJ_BUS_MODE      0x100
0212 #define MCHIP_VRJ_SIGNAL_ACTIVE_LEVEL   0x108
0213 #define MCHIP_VRJ_PDAT_USE      0x110
0214 #define MCHIP_VRJ_MODE_SPECIFY      0x118
0215 #define MCHIP_VRJ_LIMIT_COMPRESSED_LO   0x120
0216 #define MCHIP_VRJ_LIMIT_COMPRESSED_HI   0x124
0217 #define MCHIP_VRJ_COMP_DATA_FORMAT  0x128
0218 #define MCHIP_VRJ_TABLE_DATA        0x140
0219 #define MCHIP_VRJ_RESTART_INTERVAL  0x148
0220 #define MCHIP_VRJ_NUM_LINES     0x150
0221 #define MCHIP_VRJ_NUM_PIXELS        0x158
0222 #define MCHIP_VRJ_NUM_COMPONENTS    0x160
0223 #define MCHIP_VRJ_SOF1          0x168
0224 #define MCHIP_VRJ_SOF2          0x170
0225 #define MCHIP_VRJ_SOF3          0x178
0226 #define MCHIP_VRJ_SOF4          0x180
0227 #define MCHIP_VRJ_SOS           0x188
0228 #define MCHIP_VRJ_SOFT_RESET        0x190
0229 
0230 #define MCHIP_VRJ_STATUS        0x1c0
0231 #define MCHIP_VRJ_STATUS_BUSY       0x00001
0232 #define MCHIP_VRJ_STATUS_COMP_ACCESS    0x00002
0233 #define MCHIP_VRJ_STATUS_PIXEL_ACCESS   0x00004
0234 #define MCHIP_VRJ_STATUS_ERROR      0x00008
0235 
0236 #define MCHIP_VRJ_IRQ_FLAG      0x1c8
0237 #define MCHIP_VRJ_ERROR_REPORT      0x1d8
0238 
0239 #define MCHIP_VRJ_START_COMMAND     0x1a0
0240 
0241 /****************************************************************************/
0242 /* Driver definitions.                                                      */
0243 /****************************************************************************/
0244 
0245 /* Sony Programmable I/O Controller for accessing the camera commands */
0246 #include <linux/sony-laptop.h>
0247 
0248 /* private API definitions */
0249 #include <linux/meye.h>
0250 #include <linux/mutex.h>
0251 
0252 
0253 /* Enable jpg software correction */
0254 #define MEYE_JPEG_CORRECTION    1
0255 
0256 /* Maximum size of a buffer */
0257 #define MEYE_MAX_BUFSIZE    614400  /* 640 * 480 * 2 */
0258 
0259 /* Maximum number of buffers */
0260 #define MEYE_MAX_BUFNBRS    32
0261 
0262 /* State of a buffer */
0263 #define MEYE_BUF_UNUSED 0   /* not used */
0264 #define MEYE_BUF_USING  1   /* currently grabbing / playing */
0265 #define MEYE_BUF_DONE   2   /* done */
0266 
0267 /* grab buffer */
0268 struct meye_grab_buffer {
0269     int state;          /* state of buffer */
0270     unsigned long size;     /* size of jpg frame */
0271     u64 ts;             /* timestamp */
0272     unsigned long sequence;     /* sequence number */
0273 };
0274 
0275 /* size of kfifos containing buffer indices */
0276 #define MEYE_QUEUE_SIZE MEYE_MAX_BUFNBRS
0277 
0278 /* Motion Eye device structure */
0279 struct meye {
0280     struct v4l2_device v4l2_dev;    /* Main v4l2_device struct */
0281     struct v4l2_ctrl_handler hdl;
0282     struct pci_dev *mchip_dev;  /* pci device */
0283     u8 mchip_irq;           /* irq */
0284     u8 mchip_mode;          /* actual mchip mode: HIC_MODE... */
0285     u8 mchip_fnum;          /* current mchip frame number */
0286     unsigned char __iomem *mchip_mmregs;/* mchip: memory mapped registers */
0287     u8 *mchip_ptable[MCHIP_NB_PAGES];/* mchip: ptable */
0288     void *mchip_ptable_toc;     /* mchip: ptable toc */
0289     dma_addr_t mchip_dmahandle; /* mchip: dma handle to ptable toc */
0290     unsigned char *grab_fbuffer;    /* capture framebuffer */
0291     unsigned char *grab_temp;   /* temporary buffer */
0292                     /* list of buffers */
0293     struct meye_grab_buffer grab_buffer[MEYE_MAX_BUFNBRS];
0294     int vma_use_count[MEYE_MAX_BUFNBRS]; /* mmap count */
0295     struct mutex lock;      /* mutex for open/mmap... */
0296     struct kfifo grabq;     /* queue for buffers to be grabbed */
0297     spinlock_t grabq_lock;      /* lock protecting the queue */
0298     struct kfifo doneq;     /* queue for grabbed buffers */
0299     spinlock_t doneq_lock;      /* lock protecting the queue */
0300     wait_queue_head_t proc_list;    /* wait queue */
0301     struct video_device vdev;   /* video device parameters */
0302     u16 brightness;
0303     u16 hue;
0304     u16 contrast;
0305     u16 colour;
0306     struct meye_params params;  /* additional parameters */
0307     unsigned long in_use;       /* set to 1 if the device is in use */
0308     u8 pm_mchip_mode;       /* old mchip mode */
0309 };
0310 
0311 #endif