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