xref: /openbmc/linux/drivers/media/rc/img-ir/img-ir.h (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
1*2874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2160a8f8aSJames Hogan /*
3160a8f8aSJames Hogan  * ImgTec IR Decoder found in PowerDown Controller.
4160a8f8aSJames Hogan  *
5160a8f8aSJames Hogan  * Copyright 2010-2014 Imagination Technologies Ltd.
6160a8f8aSJames Hogan  */
7160a8f8aSJames Hogan 
8160a8f8aSJames Hogan #ifndef _IMG_IR_H_
9160a8f8aSJames Hogan #define _IMG_IR_H_
10160a8f8aSJames Hogan 
11160a8f8aSJames Hogan #include <linux/io.h>
12160a8f8aSJames Hogan #include <linux/spinlock.h>
13160a8f8aSJames Hogan 
14160a8f8aSJames Hogan #include "img-ir-raw.h"
15160a8f8aSJames Hogan #include "img-ir-hw.h"
16160a8f8aSJames Hogan 
17160a8f8aSJames Hogan /* registers */
18160a8f8aSJames Hogan 
19160a8f8aSJames Hogan /* relative to the start of the IR block of registers */
20160a8f8aSJames Hogan #define IMG_IR_CONTROL		0x00
21160a8f8aSJames Hogan #define IMG_IR_STATUS		0x04
22160a8f8aSJames Hogan #define IMG_IR_DATA_LW		0x08
23160a8f8aSJames Hogan #define IMG_IR_DATA_UP		0x0c
24160a8f8aSJames Hogan #define IMG_IR_LEAD_SYMB_TIMING	0x10
25160a8f8aSJames Hogan #define IMG_IR_S00_SYMB_TIMING	0x14
26160a8f8aSJames Hogan #define IMG_IR_S01_SYMB_TIMING	0x18
27160a8f8aSJames Hogan #define IMG_IR_S10_SYMB_TIMING	0x1c
28160a8f8aSJames Hogan #define IMG_IR_S11_SYMB_TIMING	0x20
29160a8f8aSJames Hogan #define IMG_IR_FREE_SYMB_TIMING	0x24
30160a8f8aSJames Hogan #define IMG_IR_POW_MOD_PARAMS	0x28
31160a8f8aSJames Hogan #define IMG_IR_POW_MOD_ENABLE	0x2c
32160a8f8aSJames Hogan #define IMG_IR_IRQ_MSG_DATA_LW	0x30
33160a8f8aSJames Hogan #define IMG_IR_IRQ_MSG_DATA_UP	0x34
34160a8f8aSJames Hogan #define IMG_IR_IRQ_MSG_MASK_LW	0x38
35160a8f8aSJames Hogan #define IMG_IR_IRQ_MSG_MASK_UP	0x3c
36160a8f8aSJames Hogan #define IMG_IR_IRQ_ENABLE	0x40
37160a8f8aSJames Hogan #define IMG_IR_IRQ_STATUS	0x44
38160a8f8aSJames Hogan #define IMG_IR_IRQ_CLEAR	0x48
39160a8f8aSJames Hogan #define IMG_IR_IRCORE_ID	0xf0
40160a8f8aSJames Hogan #define IMG_IR_CORE_REV		0xf4
41160a8f8aSJames Hogan #define IMG_IR_CORE_DES1	0xf8
42160a8f8aSJames Hogan #define IMG_IR_CORE_DES2	0xfc
43160a8f8aSJames Hogan 
44160a8f8aSJames Hogan 
45160a8f8aSJames Hogan /* field masks */
46160a8f8aSJames Hogan 
47160a8f8aSJames Hogan /* IMG_IR_CONTROL */
48160a8f8aSJames Hogan #define IMG_IR_DECODEN		0x40000000
49160a8f8aSJames Hogan #define IMG_IR_CODETYPE		0x30000000
50160a8f8aSJames Hogan #define IMG_IR_CODETYPE_SHIFT		28
51160a8f8aSJames Hogan #define IMG_IR_HDRTOG		0x08000000
52160a8f8aSJames Hogan #define IMG_IR_LDRDEC		0x04000000
53160a8f8aSJames Hogan #define IMG_IR_DECODINPOL	0x02000000	/* active high */
54160a8f8aSJames Hogan #define IMG_IR_BITORIEN		0x01000000	/* MSB first */
55160a8f8aSJames Hogan #define IMG_IR_D1VALIDSEL	0x00008000
56160a8f8aSJames Hogan #define IMG_IR_BITINV		0x00000040	/* don't invert */
57160a8f8aSJames Hogan #define IMG_IR_DECODEND2	0x00000010
58160a8f8aSJames Hogan #define IMG_IR_BITORIEND2	0x00000002	/* MSB first */
59160a8f8aSJames Hogan #define IMG_IR_BITINVD2		0x00000001	/* don't invert */
60160a8f8aSJames Hogan 
61160a8f8aSJames Hogan /* IMG_IR_STATUS */
62160a8f8aSJames Hogan #define IMG_IR_RXDVALD2		0x00001000
63160a8f8aSJames Hogan #define IMG_IR_IRRXD		0x00000400
64160a8f8aSJames Hogan #define IMG_IR_TOGSTATE		0x00000200
65160a8f8aSJames Hogan #define IMG_IR_RXDVAL		0x00000040
66160a8f8aSJames Hogan #define IMG_IR_RXDLEN		0x0000003f
67160a8f8aSJames Hogan #define IMG_IR_RXDLEN_SHIFT		0
68160a8f8aSJames Hogan 
69160a8f8aSJames Hogan /* IMG_IR_LEAD_SYMB_TIMING, IMG_IR_Sxx_SYMB_TIMING */
70160a8f8aSJames Hogan #define IMG_IR_PD_MAX		0xff000000
71160a8f8aSJames Hogan #define IMG_IR_PD_MAX_SHIFT		24
72160a8f8aSJames Hogan #define IMG_IR_PD_MIN		0x00ff0000
73160a8f8aSJames Hogan #define IMG_IR_PD_MIN_SHIFT		16
74160a8f8aSJames Hogan #define IMG_IR_W_MAX		0x0000ff00
75160a8f8aSJames Hogan #define IMG_IR_W_MAX_SHIFT		8
76160a8f8aSJames Hogan #define IMG_IR_W_MIN		0x000000ff
77160a8f8aSJames Hogan #define IMG_IR_W_MIN_SHIFT		0
78160a8f8aSJames Hogan 
79160a8f8aSJames Hogan /* IMG_IR_FREE_SYMB_TIMING */
80160a8f8aSJames Hogan #define IMG_IR_MAXLEN		0x0007e000
81160a8f8aSJames Hogan #define IMG_IR_MAXLEN_SHIFT		13
82160a8f8aSJames Hogan #define IMG_IR_MINLEN		0x00001f00
83160a8f8aSJames Hogan #define IMG_IR_MINLEN_SHIFT		8
84160a8f8aSJames Hogan #define IMG_IR_FT_MIN		0x000000ff
85160a8f8aSJames Hogan #define IMG_IR_FT_MIN_SHIFT		0
86160a8f8aSJames Hogan 
87160a8f8aSJames Hogan /* IMG_IR_POW_MOD_PARAMS */
88160a8f8aSJames Hogan #define IMG_IR_PERIOD_LEN	0x3f000000
89160a8f8aSJames Hogan #define IMG_IR_PERIOD_LEN_SHIFT		24
90160a8f8aSJames Hogan #define IMG_IR_PERIOD_DUTY	0x003f0000
91160a8f8aSJames Hogan #define IMG_IR_PERIOD_DUTY_SHIFT	16
92160a8f8aSJames Hogan #define IMG_IR_STABLE_STOP	0x00003f00
93160a8f8aSJames Hogan #define IMG_IR_STABLE_STOP_SHIFT	8
94160a8f8aSJames Hogan #define IMG_IR_STABLE_START	0x0000003f
95160a8f8aSJames Hogan #define IMG_IR_STABLE_START_SHIFT	0
96160a8f8aSJames Hogan 
97160a8f8aSJames Hogan /* IMG_IR_POW_MOD_ENABLE */
98160a8f8aSJames Hogan #define IMG_IR_POWER_OUT_EN	0x00000002
99160a8f8aSJames Hogan #define IMG_IR_POWER_MOD_EN	0x00000001
100160a8f8aSJames Hogan 
101160a8f8aSJames Hogan /* IMG_IR_IRQ_ENABLE, IMG_IR_IRQ_STATUS, IMG_IR_IRQ_CLEAR */
102160a8f8aSJames Hogan #define IMG_IR_IRQ_DEC2_ERR	0x00000080
103160a8f8aSJames Hogan #define IMG_IR_IRQ_DEC_ERR	0x00000040
104160a8f8aSJames Hogan #define IMG_IR_IRQ_ACT_LEVEL	0x00000020
105160a8f8aSJames Hogan #define IMG_IR_IRQ_FALL_EDGE	0x00000010
106160a8f8aSJames Hogan #define IMG_IR_IRQ_RISE_EDGE	0x00000008
107160a8f8aSJames Hogan #define IMG_IR_IRQ_DATA_MATCH	0x00000004
108160a8f8aSJames Hogan #define IMG_IR_IRQ_DATA2_VALID	0x00000002
109160a8f8aSJames Hogan #define IMG_IR_IRQ_DATA_VALID	0x00000001
110160a8f8aSJames Hogan #define IMG_IR_IRQ_ALL		0x000000ff
111160a8f8aSJames Hogan #define IMG_IR_IRQ_EDGE		(IMG_IR_IRQ_FALL_EDGE | IMG_IR_IRQ_RISE_EDGE)
112160a8f8aSJames Hogan 
113160a8f8aSJames Hogan /* IMG_IR_CORE_ID */
114160a8f8aSJames Hogan #define IMG_IR_CORE_ID		0x00ff0000
115160a8f8aSJames Hogan #define IMG_IR_CORE_ID_SHIFT		16
116160a8f8aSJames Hogan #define IMG_IR_CORE_CONFIG	0x0000ffff
117160a8f8aSJames Hogan #define IMG_IR_CORE_CONFIG_SHIFT	0
118160a8f8aSJames Hogan 
119160a8f8aSJames Hogan /* IMG_IR_CORE_REV */
120160a8f8aSJames Hogan #define IMG_IR_DESIGNER		0xff000000
121160a8f8aSJames Hogan #define IMG_IR_DESIGNER_SHIFT		24
122160a8f8aSJames Hogan #define IMG_IR_MAJOR_REV	0x00ff0000
123160a8f8aSJames Hogan #define IMG_IR_MAJOR_REV_SHIFT		16
124160a8f8aSJames Hogan #define IMG_IR_MINOR_REV	0x0000ff00
125160a8f8aSJames Hogan #define IMG_IR_MINOR_REV_SHIFT		8
126160a8f8aSJames Hogan #define IMG_IR_MAINT_REV	0x000000ff
127160a8f8aSJames Hogan #define IMG_IR_MAINT_REV_SHIFT		0
128160a8f8aSJames Hogan 
129160a8f8aSJames Hogan struct device;
130160a8f8aSJames Hogan struct clk;
131160a8f8aSJames Hogan 
132160a8f8aSJames Hogan /**
133160a8f8aSJames Hogan  * struct img_ir_priv - Private driver data.
134160a8f8aSJames Hogan  * @dev:		Platform device.
135160a8f8aSJames Hogan  * @irq:		IRQ number.
136160a8f8aSJames Hogan  * @clk:		Input clock.
137cc4e8c3dSSifan Naeem  * @sys_clk:		System clock.
138160a8f8aSJames Hogan  * @reg_base:		Iomem base address of IR register block.
139160a8f8aSJames Hogan  * @lock:		Protects IR registers and variables in this struct.
140160a8f8aSJames Hogan  * @raw:		Driver data for raw decoder.
141160a8f8aSJames Hogan  * @hw:			Driver data for hardware decoder.
142160a8f8aSJames Hogan  */
143160a8f8aSJames Hogan struct img_ir_priv {
144160a8f8aSJames Hogan 	struct device		*dev;
145160a8f8aSJames Hogan 	int			irq;
146160a8f8aSJames Hogan 	struct clk		*clk;
147cc4e8c3dSSifan Naeem 	struct clk		*sys_clk;
148160a8f8aSJames Hogan 	void __iomem		*reg_base;
149160a8f8aSJames Hogan 	spinlock_t		lock;
150160a8f8aSJames Hogan 
151160a8f8aSJames Hogan 	struct img_ir_priv_raw	raw;
152160a8f8aSJames Hogan 	struct img_ir_priv_hw	hw;
153160a8f8aSJames Hogan };
154160a8f8aSJames Hogan 
155160a8f8aSJames Hogan /* Hardware access */
156160a8f8aSJames Hogan 
img_ir_write(struct img_ir_priv * priv,unsigned int reg_offs,unsigned int data)157160a8f8aSJames Hogan static inline void img_ir_write(struct img_ir_priv *priv,
158160a8f8aSJames Hogan 				unsigned int reg_offs, unsigned int data)
159160a8f8aSJames Hogan {
160160a8f8aSJames Hogan 	iowrite32(data, priv->reg_base + reg_offs);
161160a8f8aSJames Hogan }
162160a8f8aSJames Hogan 
img_ir_read(struct img_ir_priv * priv,unsigned int reg_offs)163160a8f8aSJames Hogan static inline unsigned int img_ir_read(struct img_ir_priv *priv,
164160a8f8aSJames Hogan 				       unsigned int reg_offs)
165160a8f8aSJames Hogan {
166160a8f8aSJames Hogan 	return ioread32(priv->reg_base + reg_offs);
167160a8f8aSJames Hogan }
168160a8f8aSJames Hogan 
169160a8f8aSJames Hogan #endif /* _IMG_IR_H_ */
170