2 * Marvell camera core structures.
4 * Copyright 2011 Jonathan Corbet corbet@lwn.net
8 * Tracking of streaming I/O buffers.
9 * FIXME doesn't belong in this file
11 struct mcam_sio_buffer {
12 struct list_head list;
13 struct v4l2_buffer v4lbuf;
14 char *buffer; /* Where it lives in kernel space */
16 struct mcam_camera *cam;
20 S_NOTREADY, /* Not yet initialized */
21 S_IDLE, /* Just hanging around */
22 S_FLAKED, /* Some sort of problem */
23 S_SINGLEREAD, /* In read() */
24 S_SPECREAD, /* Speculative read (for future read()) */
25 S_STREAMING /* Streaming data */
27 #define MAX_DMA_BUFS 3
30 * A description of one of our devices.
31 * Locking: controlled by s_mutex. Certain fields, however, require
32 * the dev_lock spinlock; they are marked as such by comments.
33 * dev_lock is also required for access to device registers.
37 * These fields should be set by the platform code prior to
38 * calling mcam_register().
40 struct i2c_adapter i2c_adapter;
41 unsigned char __iomem *regs;
43 struct device *dev; /* For messages, dma alloc */
45 short int clock_speed; /* Sensor clock speed, default 30 */
46 short int use_smbus; /* SMBUS or straight I2c? */
49 * Callbacks from the core to the platform code.
51 void (*plat_power_up) (struct mcam_camera *cam);
52 void (*plat_power_down) (struct mcam_camera *cam);
55 * Everything below here is private to the mcam core and
56 * should not be touched by the platform code.
58 struct v4l2_device v4l2_dev;
59 enum mcam_state state;
60 unsigned long flags; /* Buffer status, mainly (dev_lock) */
61 int users; /* How many open FDs */
62 struct file *owner; /* Who has data access (v4l2) */
65 * Subsystem structures.
67 struct video_device vdev;
68 struct v4l2_subdev *sensor;
69 unsigned short sensor_addr;
71 struct list_head dev_list; /* link to other devices */
74 unsigned int nbufs; /* How many are alloc'd */
75 int next_buf; /* Next to consume (dev_lock) */
76 unsigned int dma_buf_size; /* allocated size */
77 void *dma_bufs[MAX_DMA_BUFS]; /* Internal buffer addresses */
78 dma_addr_t dma_handles[MAX_DMA_BUFS]; /* Buffer bus addresses */
79 unsigned int specframes; /* Unconsumed spec frames (dev_lock) */
80 unsigned int sequence; /* Frame sequence number */
81 unsigned int buf_seq[MAX_DMA_BUFS]; /* Sequence for individual buffers */
83 /* Streaming buffers */
84 unsigned int n_sbufs; /* How many we have */
85 struct mcam_sio_buffer *sb_bufs; /* The array of housekeeping structs */
86 struct list_head sb_avail; /* Available for data (we own) (dev_lock) */
87 struct list_head sb_full; /* With data (user space owns) (dev_lock) */
88 struct tasklet_struct s_tasklet;
90 /* Current operating parameters */
91 u32 sensor_type; /* Currently ov7670 only */
92 struct v4l2_pix_format pix_format;
93 enum v4l2_mbus_pixelcode mbus_code;
96 struct mutex s_mutex; /* Access to this structure */
99 wait_queue_head_t iowait; /* Waiting on frame data */
104 * Register I/O functions. These are here because the platform code
105 * may legitimately need to mess with the register space.
108 * Device register I/O
110 static inline void mcam_reg_write(struct mcam_camera *cam, unsigned int reg,
113 iowrite32(val, cam->regs + reg);
116 static inline unsigned int mcam_reg_read(struct mcam_camera *cam,
119 return ioread32(cam->regs + reg);
123 static inline void mcam_reg_write_mask(struct mcam_camera *cam, unsigned int reg,
124 unsigned int val, unsigned int mask)
126 unsigned int v = mcam_reg_read(cam, reg);
128 v = (v & ~mask) | (val & mask);
129 mcam_reg_write(cam, reg, v);
132 static inline void mcam_reg_clear_bit(struct mcam_camera *cam,
133 unsigned int reg, unsigned int val)
135 mcam_reg_write_mask(cam, reg, 0, val);
138 static inline void mcam_reg_set_bit(struct mcam_camera *cam,
139 unsigned int reg, unsigned int val)
141 mcam_reg_write_mask(cam, reg, val, val);
145 * Functions for use by platform code.
147 int mccic_register(struct mcam_camera *cam);
148 int mccic_irq(struct mcam_camera *cam, unsigned int irqs);
149 void mccic_shutdown(struct mcam_camera *cam);
151 void mccic_suspend(struct mcam_camera *cam);
152 int mccic_resume(struct mcam_camera *cam);
156 * Register definitions for the m88alp01 camera interface. Offsets in bytes
157 * as given in the spec.
159 #define REG_Y0BAR 0x00
160 #define REG_Y1BAR 0x04
161 #define REG_Y2BAR 0x08
164 #define REG_IMGPITCH 0x24 /* Image pitch register */
165 #define IMGP_YP_SHFT 2 /* Y pitch params */
166 #define IMGP_YP_MASK 0x00003ffc /* Y pitch field */
167 #define IMGP_UVP_SHFT 18 /* UV pitch (planar) */
168 #define IMGP_UVP_MASK 0x3ffc0000
169 #define REG_IRQSTATRAW 0x28 /* RAW IRQ Status */
170 #define IRQ_EOF0 0x00000001 /* End of frame 0 */
171 #define IRQ_EOF1 0x00000002 /* End of frame 1 */
172 #define IRQ_EOF2 0x00000004 /* End of frame 2 */
173 #define IRQ_SOF0 0x00000008 /* Start of frame 0 */
174 #define IRQ_SOF1 0x00000010 /* Start of frame 1 */
175 #define IRQ_SOF2 0x00000020 /* Start of frame 2 */
176 #define IRQ_OVERFLOW 0x00000040 /* FIFO overflow */
177 #define IRQ_TWSIW 0x00010000 /* TWSI (smbus) write */
178 #define IRQ_TWSIR 0x00020000 /* TWSI read */
179 #define IRQ_TWSIE 0x00040000 /* TWSI error */
180 #define TWSIIRQS (IRQ_TWSIW|IRQ_TWSIR|IRQ_TWSIE)
181 #define FRAMEIRQS (IRQ_EOF0|IRQ_EOF1|IRQ_EOF2|IRQ_SOF0|IRQ_SOF1|IRQ_SOF2)
182 #define ALLIRQS (TWSIIRQS|FRAMEIRQS|IRQ_OVERFLOW)
183 #define REG_IRQMASK 0x2c /* IRQ mask - same bits as IRQSTAT */
184 #define REG_IRQSTAT 0x30 /* IRQ status / clear */
186 #define REG_IMGSIZE 0x34 /* Image size */
187 #define IMGSZ_V_MASK 0x1fff0000
188 #define IMGSZ_V_SHIFT 16
189 #define IMGSZ_H_MASK 0x00003fff
190 #define REG_IMGOFFSET 0x38 /* IMage offset */
192 #define REG_CTRL0 0x3c /* Control 0 */
193 #define C0_ENABLE 0x00000001 /* Makes the whole thing go */
195 /* Mask for all the format bits */
196 #define C0_DF_MASK 0x00fffffc /* Bits 2-23 */
199 #define C0_RGB4_RGBX 0x00000000
200 #define C0_RGB4_XRGB 0x00000004
201 #define C0_RGB4_BGRX 0x00000008
202 #define C0_RGB4_XBGR 0x0000000c
203 #define C0_RGB5_RGGB 0x00000000
204 #define C0_RGB5_GRBG 0x00000004
205 #define C0_RGB5_GBRG 0x00000008
206 #define C0_RGB5_BGGR 0x0000000c
208 /* Spec has two fields for DIN and DOUT, but they must match, so
209 combine them here. */
210 #define C0_DF_YUV 0x00000000 /* Data is YUV */
211 #define C0_DF_RGB 0x000000a0 /* ... RGB */
212 #define C0_DF_BAYER 0x00000140 /* ... Bayer */
213 /* 8-8-8 must be missing from the below - ask */
214 #define C0_RGBF_565 0x00000000
215 #define C0_RGBF_444 0x00000800
216 #define C0_RGB_BGR 0x00001000 /* Blue comes first */
217 #define C0_YUV_PLANAR 0x00000000 /* YUV 422 planar format */
218 #define C0_YUV_PACKED 0x00008000 /* YUV 422 packed */
219 #define C0_YUV_420PL 0x0000a000 /* YUV 420 planar */
220 /* Think that 420 packed must be 111 - ask */
221 #define C0_YUVE_YUYV 0x00000000 /* Y1CbY0Cr */
222 #define C0_YUVE_YVYU 0x00010000 /* Y1CrY0Cb */
223 #define C0_YUVE_VYUY 0x00020000 /* CrY1CbY0 */
224 #define C0_YUVE_UYVY 0x00030000 /* CbY1CrY0 */
225 #define C0_YUVE_XYUV 0x00000000 /* 420: .YUV */
226 #define C0_YUVE_XYVU 0x00010000 /* 420: .YVU */
227 #define C0_YUVE_XUVY 0x00020000 /* 420: .UVY */
228 #define C0_YUVE_XVUY 0x00030000 /* 420: .VUY */
229 /* Bayer bits 18,19 if needed */
230 #define C0_HPOL_LOW 0x01000000 /* HSYNC polarity active low */
231 #define C0_VPOL_LOW 0x02000000 /* VSYNC polarity active low */
232 #define C0_VCLK_LOW 0x04000000 /* VCLK on falling edge */
233 #define C0_DOWNSCALE 0x08000000 /* Enable downscaler */
234 #define C0_SIFM_MASK 0xc0000000 /* SIF mode bits */
235 #define C0_SIF_HVSYNC 0x00000000 /* Use H/VSYNC */
236 #define CO_SOF_NOSYNC 0x40000000 /* Use inband active signaling */
239 #define REG_CTRL1 0x40 /* Control 1 */
240 #define C1_444ALPHA 0x00f00000 /* Alpha field in RGB444 */
241 #define C1_ALPHA_SHFT 20
242 #define C1_DMAB32 0x00000000 /* 32-byte DMA burst */
243 #define C1_DMAB16 0x02000000 /* 16-byte DMA burst */
244 #define C1_DMAB64 0x04000000 /* 64-byte DMA burst */
245 #define C1_DMAB_MASK 0x06000000
246 #define C1_TWOBUFS 0x08000000 /* Use only two DMA buffers */
247 #define C1_PWRDWN 0x10000000 /* Power down */
249 #define REG_CLKCTRL 0x88 /* Clock control */
250 #define CLK_DIV_MASK 0x0000ffff /* Upper bits RW "reserved" */
252 /* This appears to be a Cafe-only register */
253 #define REG_UBAR 0xc4 /* Upper base address register */
256 * Useful stuff that probably belongs somewhere global.
258 #define VGA_WIDTH 640
259 #define VGA_HEIGHT 480