This source file includes following definitions.
- to_saa7146_dev
- SAA7146_IER_DISABLE
- SAA7146_IER_ENABLE
1
2 #ifndef __SAA7146__
3 #define __SAA7146__
4
5 #include <linux/delay.h>
6 #include <linux/slab.h>
7 #include <linux/pci.h>
8 #include <linux/init.h>
9 #include <linux/interrupt.h>
10 #include <linux/kmod.h>
11 #include <linux/i2c.h>
12 #include <asm/io.h>
13 #include <linux/stringify.h>
14 #include <linux/mutex.h>
15 #include <linux/scatterlist.h>
16 #include <media/v4l2-device.h>
17 #include <media/v4l2-ctrls.h>
18
19 #include <linux/vmalloc.h>
20 #include <linux/mm.h>
21
22 #define saa7146_write(sxy,adr,dat) writel((dat),(sxy->mem+(adr)))
23 #define saa7146_read(sxy,adr) readl(sxy->mem+(adr))
24
25 extern unsigned int saa7146_debug;
26
27 #ifndef DEBUG_VARIABLE
28 #define DEBUG_VARIABLE saa7146_debug
29 #endif
30
31 #define ERR(fmt, ...) pr_err("%s: " fmt, __func__, ##__VA_ARGS__)
32
33 #define _DBG(mask, fmt, ...) \
34 do { \
35 if (DEBUG_VARIABLE & mask) \
36 pr_debug("%s(): " fmt, __func__, ##__VA_ARGS__); \
37 } while (0)
38
39
40 #define DEB_S(fmt, ...) _DBG(0x01, fmt, ##__VA_ARGS__)
41
42 #define DEB_D(fmt, ...) _DBG(0x02, fmt, ##__VA_ARGS__)
43
44 #define DEB_EE(fmt, ...) _DBG(0x04, fmt, ##__VA_ARGS__)
45
46 #define DEB_I2C(fmt, ...) _DBG(0x08, fmt, ##__VA_ARGS__)
47
48 #define DEB_VBI(fmt, ...) _DBG(0x10, fmt, ##__VA_ARGS__)
49
50 #define DEB_INT(fmt, ...) _DBG(0x20, fmt, ##__VA_ARGS__)
51
52 #define DEB_CAP(fmt, ...) _DBG(0x40, fmt, ##__VA_ARGS__)
53
54 #define SAA7146_ISR_CLEAR(x,y) \
55 saa7146_write(x, ISR, (y));
56
57 struct module;
58
59 struct saa7146_dev;
60 struct saa7146_extension;
61 struct saa7146_vv;
62
63
64 struct saa7146_pgtable {
65 unsigned int size;
66 __le32 *cpu;
67 dma_addr_t dma;
68
69 unsigned long offset;
70
71 struct scatterlist *slist;
72 int nents;
73 };
74
75 struct saa7146_pci_extension_data {
76 struct saa7146_extension *ext;
77 void *ext_priv;
78 };
79
80 #define MAKE_EXTENSION_PCI(x_var, x_vendor, x_device) \
81 { \
82 .vendor = PCI_VENDOR_ID_PHILIPS, \
83 .device = PCI_DEVICE_ID_PHILIPS_SAA7146, \
84 .subvendor = x_vendor, \
85 .subdevice = x_device, \
86 .driver_data = (unsigned long)& x_var, \
87 }
88
89 struct saa7146_extension
90 {
91 char name[32];
92 #define SAA7146_USE_I2C_IRQ 0x1
93 #define SAA7146_I2C_SHORT_DELAY 0x2
94 int flags;
95
96
97
98 struct module *module;
99 struct pci_driver driver;
100 const struct pci_device_id *pci_tbl;
101
102
103 int (*probe)(struct saa7146_dev *);
104 int (*attach)(struct saa7146_dev *, struct saa7146_pci_extension_data *);
105 int (*detach)(struct saa7146_dev*);
106
107 u32 irq_mask;
108 void (*irq_func)(struct saa7146_dev*, u32* irq_mask);
109 };
110
111 struct saa7146_dma
112 {
113 dma_addr_t dma_handle;
114 __le32 *cpu_addr;
115 };
116
117 struct saa7146_dev
118 {
119 struct module *module;
120
121 struct v4l2_device v4l2_dev;
122 struct v4l2_ctrl_handler ctrl_handler;
123
124
125 spinlock_t slock;
126 struct mutex v4l2_lock;
127
128 unsigned char __iomem *mem;
129 u32 revision;
130
131
132 char name[32];
133 struct pci_dev *pci;
134 u32 int_todo;
135 spinlock_t int_slock;
136
137
138 struct saa7146_extension *ext;
139 void *ext_priv;
140 struct saa7146_ext_vv *ext_vv_data;
141
142
143 struct saa7146_vv *vv_data;
144 void (*vv_callback)(struct saa7146_dev *dev, unsigned long status);
145
146
147 struct mutex i2c_lock;
148
149 u32 i2c_bitrate;
150 struct saa7146_dma d_i2c;
151 wait_queue_head_t i2c_wq;
152 int i2c_op;
153
154
155 struct saa7146_dma d_rps0;
156 struct saa7146_dma d_rps1;
157 };
158
159 static inline struct saa7146_dev *to_saa7146_dev(struct v4l2_device *v4l2_dev)
160 {
161 return container_of(v4l2_dev, struct saa7146_dev, v4l2_dev);
162 }
163
164
165 int saa7146_i2c_adapter_prepare(struct saa7146_dev *dev, struct i2c_adapter *i2c_adapter, u32 bitrate);
166
167
168 int saa7146_register_extension(struct saa7146_extension*);
169 int saa7146_unregister_extension(struct saa7146_extension*);
170 struct saa7146_format* saa7146_format_by_fourcc(struct saa7146_dev *dev, int fourcc);
171 int saa7146_pgtable_alloc(struct pci_dev *pci, struct saa7146_pgtable *pt);
172 void saa7146_pgtable_free(struct pci_dev *pci, struct saa7146_pgtable *pt);
173 int saa7146_pgtable_build_single(struct pci_dev *pci, struct saa7146_pgtable *pt, struct scatterlist *list, int length );
174 void *saa7146_vmalloc_build_pgtable(struct pci_dev *pci, long length, struct saa7146_pgtable *pt);
175 void saa7146_vfree_destroy_pgtable(struct pci_dev *pci, void *mem, struct saa7146_pgtable *pt);
176 void saa7146_setgpio(struct saa7146_dev *dev, int port, u32 data);
177 int saa7146_wait_for_debi_done(struct saa7146_dev *dev, int nobusyloop);
178
179
180 #define SAA7146_I2C_MEM ( 1*PAGE_SIZE)
181 #define SAA7146_RPS_MEM ( 1*PAGE_SIZE)
182
183
184 #define SAA7146_I2C_TIMEOUT 100
185 #define SAA7146_I2C_RETRIES 3
186 #define SAA7146_I2C_DELAY 5
187
188
189 #define ME1 0x0000000800
190 #define PV1 0x0000000008
191
192
193 #define SAA7146_GPIO_INPUT 0x00
194 #define SAA7146_GPIO_IRQHI 0x10
195 #define SAA7146_GPIO_IRQLO 0x20
196 #define SAA7146_GPIO_IRQHL 0x30
197 #define SAA7146_GPIO_OUTLO 0x40
198 #define SAA7146_GPIO_OUTHI 0x50
199
200
201 #define DEBINOSWAP 0x000e0000
202
203
204 #define CMD_NOP 0x00000000
205 #define CMD_CLR_EVENT 0x00000000
206 #define CMD_SET_EVENT 0x10000000
207 #define CMD_PAUSE 0x20000000
208 #define CMD_CHECK_LATE 0x30000000
209 #define CMD_UPLOAD 0x40000000
210 #define CMD_STOP 0x50000000
211 #define CMD_INTERRUPT 0x60000000
212 #define CMD_JUMP 0x80000000
213 #define CMD_WR_REG 0x90000000
214 #define CMD_RD_REG 0xa0000000
215 #define CMD_WR_REG_MASK 0xc0000000
216
217 #define CMD_OAN MASK_27
218 #define CMD_INV MASK_26
219 #define CMD_SIG4 MASK_25
220 #define CMD_SIG3 MASK_24
221 #define CMD_SIG2 MASK_23
222 #define CMD_SIG1 MASK_22
223 #define CMD_SIG0 MASK_21
224 #define CMD_O_FID_B MASK_14
225 #define CMD_E_FID_B MASK_13
226 #define CMD_O_FID_A MASK_12
227 #define CMD_E_FID_A MASK_11
228
229
230 #define EVT_HS (1<<15)
231 #define EVT_VBI_B (1<<9)
232 #define RPS_OAN (1<<27)
233 #define RPS_INV (1<<26)
234 #define GPIO3_MSK 0xFF000000
235
236
237 #define MASK_00 0x00000001
238 #define MASK_01 0x00000002
239 #define MASK_02 0x00000004
240 #define MASK_03 0x00000008
241 #define MASK_04 0x00000010
242 #define MASK_05 0x00000020
243 #define MASK_06 0x00000040
244 #define MASK_07 0x00000080
245 #define MASK_08 0x00000100
246 #define MASK_09 0x00000200
247 #define MASK_10 0x00000400
248 #define MASK_11 0x00000800
249 #define MASK_12 0x00001000
250 #define MASK_13 0x00002000
251 #define MASK_14 0x00004000
252 #define MASK_15 0x00008000
253 #define MASK_16 0x00010000
254 #define MASK_17 0x00020000
255 #define MASK_18 0x00040000
256 #define MASK_19 0x00080000
257 #define MASK_20 0x00100000
258 #define MASK_21 0x00200000
259 #define MASK_22 0x00400000
260 #define MASK_23 0x00800000
261 #define MASK_24 0x01000000
262 #define MASK_25 0x02000000
263 #define MASK_26 0x04000000
264 #define MASK_27 0x08000000
265 #define MASK_28 0x10000000
266 #define MASK_29 0x20000000
267 #define MASK_30 0x40000000
268 #define MASK_31 0x80000000
269
270 #define MASK_B0 0x000000ff
271 #define MASK_B1 0x0000ff00
272 #define MASK_B2 0x00ff0000
273 #define MASK_B3 0xff000000
274
275 #define MASK_W0 0x0000ffff
276 #define MASK_W1 0xffff0000
277
278 #define MASK_PA 0xfffffffc
279 #define MASK_PR 0xfffffffe
280 #define MASK_ER 0xffffffff
281
282 #define MASK_NONE 0x00000000
283
284
285 #define BASE_ODD1 0x00
286 #define BASE_EVEN1 0x04
287 #define PROT_ADDR1 0x08
288 #define PITCH1 0x0C
289 #define BASE_PAGE1 0x10
290 #define NUM_LINE_BYTE1 0x14
291
292 #define BASE_ODD2 0x18
293 #define BASE_EVEN2 0x1C
294 #define PROT_ADDR2 0x20
295 #define PITCH2 0x24
296 #define BASE_PAGE2 0x28
297 #define NUM_LINE_BYTE2 0x2C
298
299 #define BASE_ODD3 0x30
300 #define BASE_EVEN3 0x34
301 #define PROT_ADDR3 0x38
302 #define PITCH3 0x3C
303 #define BASE_PAGE3 0x40
304 #define NUM_LINE_BYTE3 0x44
305
306 #define PCI_BT_V1 0x48
307 #define PCI_BT_V2 0x49
308 #define PCI_BT_V3 0x4A
309 #define PCI_BT_DEBI 0x4B
310 #define PCI_BT_A 0x4C
311
312 #define DD1_INIT 0x50
313
314 #define DD1_STREAM_B 0x54
315 #define DD1_STREAM_A 0x56
316
317 #define BRS_CTRL 0x58
318 #define HPS_CTRL 0x5C
319 #define HPS_V_SCALE 0x60
320 #define HPS_V_GAIN 0x64
321 #define HPS_H_PRESCALE 0x68
322 #define HPS_H_SCALE 0x6C
323 #define BCS_CTRL 0x70
324 #define CHROMA_KEY_RANGE 0x74
325 #define CLIP_FORMAT_CTRL 0x78
326
327 #define DEBI_CONFIG 0x7C
328 #define DEBI_COMMAND 0x80
329 #define DEBI_PAGE 0x84
330 #define DEBI_AD 0x88
331
332 #define I2C_TRANSFER 0x8C
333 #define I2C_STATUS 0x90
334
335 #define BASE_A1_IN 0x94
336 #define PROT_A1_IN 0x98
337 #define PAGE_A1_IN 0x9C
338
339 #define BASE_A1_OUT 0xA0
340 #define PROT_A1_OUT 0xA4
341 #define PAGE_A1_OUT 0xA8
342
343 #define BASE_A2_IN 0xAC
344 #define PROT_A2_IN 0xB0
345 #define PAGE_A2_IN 0xB4
346
347 #define BASE_A2_OUT 0xB8
348 #define PROT_A2_OUT 0xBC
349 #define PAGE_A2_OUT 0xC0
350
351 #define RPS_PAGE0 0xC4
352 #define RPS_PAGE1 0xC8
353
354 #define RPS_THRESH0 0xCC
355 #define RPS_THRESH1 0xD0
356
357 #define RPS_TOV0 0xD4
358 #define RPS_TOV1 0xD8
359
360 #define IER 0xDC
361
362 #define GPIO_CTRL 0xE0
363
364 #define EC1SSR 0xE4
365 #define EC2SSR 0xE8
366 #define ECT1R 0xEC
367 #define ECT2R 0xF0
368
369 #define ACON1 0xF4
370 #define ACON2 0xF8
371
372 #define MC1 0xFC
373 #define MC2 0x100
374
375 #define RPS_ADDR0 0x104
376 #define RPS_ADDR1 0x108
377
378 #define ISR 0x10C
379 #define PSR 0x110
380 #define SSR 0x114
381
382 #define EC1R 0x118
383 #define EC2R 0x11C
384
385 #define PCI_VDP1 0x120
386 #define PCI_VDP2 0x124
387 #define PCI_VDP3 0x128
388 #define PCI_ADP1 0x12C
389 #define PCI_ADP2 0x130
390 #define PCI_ADP3 0x134
391 #define PCI_ADP4 0x138
392 #define PCI_DMA_DDP 0x13C
393
394 #define LEVEL_REP 0x140,
395 #define A_TIME_SLOT1 0x180,
396 #define A_TIME_SLOT2 0x1C0,
397
398
399 #define SPCI_PPEF 0x80000000
400 #define SPCI_PABO 0x40000000
401 #define SPCI_PPED 0x20000000
402 #define SPCI_RPS_I1 0x10000000
403 #define SPCI_RPS_I0 0x08000000
404 #define SPCI_RPS_LATE1 0x04000000
405 #define SPCI_RPS_LATE0 0x02000000
406 #define SPCI_RPS_E1 0x01000000
407 #define SPCI_RPS_E0 0x00800000
408 #define SPCI_RPS_TO1 0x00400000
409 #define SPCI_RPS_TO0 0x00200000
410 #define SPCI_UPLD 0x00100000
411 #define SPCI_DEBI_S 0x00080000
412 #define SPCI_DEBI_E 0x00040000
413 #define SPCI_IIC_S 0x00020000
414 #define SPCI_IIC_E 0x00010000
415 #define SPCI_A2_IN 0x00008000
416 #define SPCI_A2_OUT 0x00004000
417 #define SPCI_A1_IN 0x00002000
418 #define SPCI_A1_OUT 0x00001000
419 #define SPCI_AFOU 0x00000800
420 #define SPCI_V_PE 0x00000400
421 #define SPCI_VFOU 0x00000200
422 #define SPCI_FIDA 0x00000100
423 #define SPCI_FIDB 0x00000080
424 #define SPCI_PIN3 0x00000040
425 #define SPCI_PIN2 0x00000020
426 #define SPCI_PIN1 0x00000010
427 #define SPCI_PIN0 0x00000008
428 #define SPCI_ECS 0x00000004
429 #define SPCI_EC3S 0x00000002
430 #define SPCI_EC0S 0x00000001
431
432
433 #define SAA7146_I2C_ABORT (1<<7)
434 #define SAA7146_I2C_SPERR (1<<6)
435 #define SAA7146_I2C_APERR (1<<5)
436 #define SAA7146_I2C_DTERR (1<<4)
437 #define SAA7146_I2C_DRERR (1<<3)
438 #define SAA7146_I2C_AL (1<<2)
439 #define SAA7146_I2C_ERR (1<<1)
440 #define SAA7146_I2C_BUSY (1<<0)
441
442 #define SAA7146_I2C_START (0x3)
443 #define SAA7146_I2C_CONT (0x2)
444 #define SAA7146_I2C_STOP (0x1)
445 #define SAA7146_I2C_NOP (0x0)
446
447 #define SAA7146_I2C_BUS_BIT_RATE_6400 (0x500)
448 #define SAA7146_I2C_BUS_BIT_RATE_3200 (0x100)
449 #define SAA7146_I2C_BUS_BIT_RATE_480 (0x400)
450 #define SAA7146_I2C_BUS_BIT_RATE_320 (0x600)
451 #define SAA7146_I2C_BUS_BIT_RATE_240 (0x700)
452 #define SAA7146_I2C_BUS_BIT_RATE_120 (0x000)
453 #define SAA7146_I2C_BUS_BIT_RATE_80 (0x200)
454 #define SAA7146_I2C_BUS_BIT_RATE_60 (0x300)
455
456 static inline void SAA7146_IER_DISABLE(struct saa7146_dev *x, unsigned y)
457 {
458 unsigned long flags;
459 spin_lock_irqsave(&x->int_slock, flags);
460 saa7146_write(x, IER, saa7146_read(x, IER) & ~y);
461 spin_unlock_irqrestore(&x->int_slock, flags);
462 }
463
464 static inline void SAA7146_IER_ENABLE(struct saa7146_dev *x, unsigned y)
465 {
466 unsigned long flags;
467 spin_lock_irqsave(&x->int_slock, flags);
468 saa7146_write(x, IER, saa7146_read(x, IER) | y);
469 spin_unlock_irqrestore(&x->int_slock, flags);
470 }
471
472 #endif