xref: /openbmc/linux/drivers/media/rc/img-ir/img-ir.h (revision 160a8f8aec4da4b68842784be3e7296e8c9860dc)
1*160a8f8aSJames Hogan /*
2*160a8f8aSJames Hogan  * ImgTec IR Decoder found in PowerDown Controller.
3*160a8f8aSJames Hogan  *
4*160a8f8aSJames Hogan  * Copyright 2010-2014 Imagination Technologies Ltd.
5*160a8f8aSJames Hogan  */
6*160a8f8aSJames Hogan 
7*160a8f8aSJames Hogan #ifndef _IMG_IR_H_
8*160a8f8aSJames Hogan #define _IMG_IR_H_
9*160a8f8aSJames Hogan 
10*160a8f8aSJames Hogan #include <linux/io.h>
11*160a8f8aSJames Hogan #include <linux/spinlock.h>
12*160a8f8aSJames Hogan 
13*160a8f8aSJames Hogan #include "img-ir-raw.h"
14*160a8f8aSJames Hogan #include "img-ir-hw.h"
15*160a8f8aSJames Hogan 
16*160a8f8aSJames Hogan /* registers */
17*160a8f8aSJames Hogan 
18*160a8f8aSJames Hogan /* relative to the start of the IR block of registers */
19*160a8f8aSJames Hogan #define IMG_IR_CONTROL		0x00
20*160a8f8aSJames Hogan #define IMG_IR_STATUS		0x04
21*160a8f8aSJames Hogan #define IMG_IR_DATA_LW		0x08
22*160a8f8aSJames Hogan #define IMG_IR_DATA_UP		0x0c
23*160a8f8aSJames Hogan #define IMG_IR_LEAD_SYMB_TIMING	0x10
24*160a8f8aSJames Hogan #define IMG_IR_S00_SYMB_TIMING	0x14
25*160a8f8aSJames Hogan #define IMG_IR_S01_SYMB_TIMING	0x18
26*160a8f8aSJames Hogan #define IMG_IR_S10_SYMB_TIMING	0x1c
27*160a8f8aSJames Hogan #define IMG_IR_S11_SYMB_TIMING	0x20
28*160a8f8aSJames Hogan #define IMG_IR_FREE_SYMB_TIMING	0x24
29*160a8f8aSJames Hogan #define IMG_IR_POW_MOD_PARAMS	0x28
30*160a8f8aSJames Hogan #define IMG_IR_POW_MOD_ENABLE	0x2c
31*160a8f8aSJames Hogan #define IMG_IR_IRQ_MSG_DATA_LW	0x30
32*160a8f8aSJames Hogan #define IMG_IR_IRQ_MSG_DATA_UP	0x34
33*160a8f8aSJames Hogan #define IMG_IR_IRQ_MSG_MASK_LW	0x38
34*160a8f8aSJames Hogan #define IMG_IR_IRQ_MSG_MASK_UP	0x3c
35*160a8f8aSJames Hogan #define IMG_IR_IRQ_ENABLE	0x40
36*160a8f8aSJames Hogan #define IMG_IR_IRQ_STATUS	0x44
37*160a8f8aSJames Hogan #define IMG_IR_IRQ_CLEAR	0x48
38*160a8f8aSJames Hogan #define IMG_IR_IRCORE_ID	0xf0
39*160a8f8aSJames Hogan #define IMG_IR_CORE_REV		0xf4
40*160a8f8aSJames Hogan #define IMG_IR_CORE_DES1	0xf8
41*160a8f8aSJames Hogan #define IMG_IR_CORE_DES2	0xfc
42*160a8f8aSJames Hogan 
43*160a8f8aSJames Hogan 
44*160a8f8aSJames Hogan /* field masks */
45*160a8f8aSJames Hogan 
46*160a8f8aSJames Hogan /* IMG_IR_CONTROL */
47*160a8f8aSJames Hogan #define IMG_IR_DECODEN		0x40000000
48*160a8f8aSJames Hogan #define IMG_IR_CODETYPE		0x30000000
49*160a8f8aSJames Hogan #define IMG_IR_CODETYPE_SHIFT		28
50*160a8f8aSJames Hogan #define IMG_IR_HDRTOG		0x08000000
51*160a8f8aSJames Hogan #define IMG_IR_LDRDEC		0x04000000
52*160a8f8aSJames Hogan #define IMG_IR_DECODINPOL	0x02000000	/* active high */
53*160a8f8aSJames Hogan #define IMG_IR_BITORIEN		0x01000000	/* MSB first */
54*160a8f8aSJames Hogan #define IMG_IR_D1VALIDSEL	0x00008000
55*160a8f8aSJames Hogan #define IMG_IR_BITINV		0x00000040	/* don't invert */
56*160a8f8aSJames Hogan #define IMG_IR_DECODEND2	0x00000010
57*160a8f8aSJames Hogan #define IMG_IR_BITORIEND2	0x00000002	/* MSB first */
58*160a8f8aSJames Hogan #define IMG_IR_BITINVD2		0x00000001	/* don't invert */
59*160a8f8aSJames Hogan 
60*160a8f8aSJames Hogan /* IMG_IR_STATUS */
61*160a8f8aSJames Hogan #define IMG_IR_RXDVALD2		0x00001000
62*160a8f8aSJames Hogan #define IMG_IR_IRRXD		0x00000400
63*160a8f8aSJames Hogan #define IMG_IR_TOGSTATE		0x00000200
64*160a8f8aSJames Hogan #define IMG_IR_RXDVAL		0x00000040
65*160a8f8aSJames Hogan #define IMG_IR_RXDLEN		0x0000003f
66*160a8f8aSJames Hogan #define IMG_IR_RXDLEN_SHIFT		0
67*160a8f8aSJames Hogan 
68*160a8f8aSJames Hogan /* IMG_IR_LEAD_SYMB_TIMING, IMG_IR_Sxx_SYMB_TIMING */
69*160a8f8aSJames Hogan #define IMG_IR_PD_MAX		0xff000000
70*160a8f8aSJames Hogan #define IMG_IR_PD_MAX_SHIFT		24
71*160a8f8aSJames Hogan #define IMG_IR_PD_MIN		0x00ff0000
72*160a8f8aSJames Hogan #define IMG_IR_PD_MIN_SHIFT		16
73*160a8f8aSJames Hogan #define IMG_IR_W_MAX		0x0000ff00
74*160a8f8aSJames Hogan #define IMG_IR_W_MAX_SHIFT		8
75*160a8f8aSJames Hogan #define IMG_IR_W_MIN		0x000000ff
76*160a8f8aSJames Hogan #define IMG_IR_W_MIN_SHIFT		0
77*160a8f8aSJames Hogan 
78*160a8f8aSJames Hogan /* IMG_IR_FREE_SYMB_TIMING */
79*160a8f8aSJames Hogan #define IMG_IR_MAXLEN		0x0007e000
80*160a8f8aSJames Hogan #define IMG_IR_MAXLEN_SHIFT		13
81*160a8f8aSJames Hogan #define IMG_IR_MINLEN		0x00001f00
82*160a8f8aSJames Hogan #define IMG_IR_MINLEN_SHIFT		8
83*160a8f8aSJames Hogan #define IMG_IR_FT_MIN		0x000000ff
84*160a8f8aSJames Hogan #define IMG_IR_FT_MIN_SHIFT		0
85*160a8f8aSJames Hogan 
86*160a8f8aSJames Hogan /* IMG_IR_POW_MOD_PARAMS */
87*160a8f8aSJames Hogan #define IMG_IR_PERIOD_LEN	0x3f000000
88*160a8f8aSJames Hogan #define IMG_IR_PERIOD_LEN_SHIFT		24
89*160a8f8aSJames Hogan #define IMG_IR_PERIOD_DUTY	0x003f0000
90*160a8f8aSJames Hogan #define IMG_IR_PERIOD_DUTY_SHIFT	16
91*160a8f8aSJames Hogan #define IMG_IR_STABLE_STOP	0x00003f00
92*160a8f8aSJames Hogan #define IMG_IR_STABLE_STOP_SHIFT	8
93*160a8f8aSJames Hogan #define IMG_IR_STABLE_START	0x0000003f
94*160a8f8aSJames Hogan #define IMG_IR_STABLE_START_SHIFT	0
95*160a8f8aSJames Hogan 
96*160a8f8aSJames Hogan /* IMG_IR_POW_MOD_ENABLE */
97*160a8f8aSJames Hogan #define IMG_IR_POWER_OUT_EN	0x00000002
98*160a8f8aSJames Hogan #define IMG_IR_POWER_MOD_EN	0x00000001
99*160a8f8aSJames Hogan 
100*160a8f8aSJames Hogan /* IMG_IR_IRQ_ENABLE, IMG_IR_IRQ_STATUS, IMG_IR_IRQ_CLEAR */
101*160a8f8aSJames Hogan #define IMG_IR_IRQ_DEC2_ERR	0x00000080
102*160a8f8aSJames Hogan #define IMG_IR_IRQ_DEC_ERR	0x00000040
103*160a8f8aSJames Hogan #define IMG_IR_IRQ_ACT_LEVEL	0x00000020
104*160a8f8aSJames Hogan #define IMG_IR_IRQ_FALL_EDGE	0x00000010
105*160a8f8aSJames Hogan #define IMG_IR_IRQ_RISE_EDGE	0x00000008
106*160a8f8aSJames Hogan #define IMG_IR_IRQ_DATA_MATCH	0x00000004
107*160a8f8aSJames Hogan #define IMG_IR_IRQ_DATA2_VALID	0x00000002
108*160a8f8aSJames Hogan #define IMG_IR_IRQ_DATA_VALID	0x00000001
109*160a8f8aSJames Hogan #define IMG_IR_IRQ_ALL		0x000000ff
110*160a8f8aSJames Hogan #define IMG_IR_IRQ_EDGE		(IMG_IR_IRQ_FALL_EDGE | IMG_IR_IRQ_RISE_EDGE)
111*160a8f8aSJames Hogan 
112*160a8f8aSJames Hogan /* IMG_IR_CORE_ID */
113*160a8f8aSJames Hogan #define IMG_IR_CORE_ID		0x00ff0000
114*160a8f8aSJames Hogan #define IMG_IR_CORE_ID_SHIFT		16
115*160a8f8aSJames Hogan #define IMG_IR_CORE_CONFIG	0x0000ffff
116*160a8f8aSJames Hogan #define IMG_IR_CORE_CONFIG_SHIFT	0
117*160a8f8aSJames Hogan 
118*160a8f8aSJames Hogan /* IMG_IR_CORE_REV */
119*160a8f8aSJames Hogan #define IMG_IR_DESIGNER		0xff000000
120*160a8f8aSJames Hogan #define IMG_IR_DESIGNER_SHIFT		24
121*160a8f8aSJames Hogan #define IMG_IR_MAJOR_REV	0x00ff0000
122*160a8f8aSJames Hogan #define IMG_IR_MAJOR_REV_SHIFT		16
123*160a8f8aSJames Hogan #define IMG_IR_MINOR_REV	0x0000ff00
124*160a8f8aSJames Hogan #define IMG_IR_MINOR_REV_SHIFT		8
125*160a8f8aSJames Hogan #define IMG_IR_MAINT_REV	0x000000ff
126*160a8f8aSJames Hogan #define IMG_IR_MAINT_REV_SHIFT		0
127*160a8f8aSJames Hogan 
128*160a8f8aSJames Hogan struct device;
129*160a8f8aSJames Hogan struct clk;
130*160a8f8aSJames Hogan 
131*160a8f8aSJames Hogan /**
132*160a8f8aSJames Hogan  * struct img_ir_priv - Private driver data.
133*160a8f8aSJames Hogan  * @dev:		Platform device.
134*160a8f8aSJames Hogan  * @irq:		IRQ number.
135*160a8f8aSJames Hogan  * @clk:		Input clock.
136*160a8f8aSJames Hogan  * @reg_base:		Iomem base address of IR register block.
137*160a8f8aSJames Hogan  * @lock:		Protects IR registers and variables in this struct.
138*160a8f8aSJames Hogan  * @raw:		Driver data for raw decoder.
139*160a8f8aSJames Hogan  * @hw:			Driver data for hardware decoder.
140*160a8f8aSJames Hogan  */
141*160a8f8aSJames Hogan struct img_ir_priv {
142*160a8f8aSJames Hogan 	struct device		*dev;
143*160a8f8aSJames Hogan 	int			irq;
144*160a8f8aSJames Hogan 	struct clk		*clk;
145*160a8f8aSJames Hogan 	void __iomem		*reg_base;
146*160a8f8aSJames Hogan 	spinlock_t		lock;
147*160a8f8aSJames Hogan 
148*160a8f8aSJames Hogan 	struct img_ir_priv_raw	raw;
149*160a8f8aSJames Hogan 	struct img_ir_priv_hw	hw;
150*160a8f8aSJames Hogan };
151*160a8f8aSJames Hogan 
152*160a8f8aSJames Hogan /* Hardware access */
153*160a8f8aSJames Hogan 
154*160a8f8aSJames Hogan static inline void img_ir_write(struct img_ir_priv *priv,
155*160a8f8aSJames Hogan 				unsigned int reg_offs, unsigned int data)
156*160a8f8aSJames Hogan {
157*160a8f8aSJames Hogan 	iowrite32(data, priv->reg_base + reg_offs);
158*160a8f8aSJames Hogan }
159*160a8f8aSJames Hogan 
160*160a8f8aSJames Hogan static inline unsigned int img_ir_read(struct img_ir_priv *priv,
161*160a8f8aSJames Hogan 				       unsigned int reg_offs)
162*160a8f8aSJames Hogan {
163*160a8f8aSJames Hogan 	return ioread32(priv->reg_base + reg_offs);
164*160a8f8aSJames Hogan }
165*160a8f8aSJames Hogan 
166*160a8f8aSJames Hogan #endif /* _IMG_IR_H_ */
167