xref: /openbmc/linux/drivers/char/xilinx_hwicap/xilinx_hwicap.h (revision cf40a76e7d5874bb25f4404eecc58a2e033af885)
1ef141a0bSStephen Neuendorffer /*****************************************************************************
2ef141a0bSStephen Neuendorffer  *
3ef141a0bSStephen Neuendorffer  *     Author: Xilinx, Inc.
4ef141a0bSStephen Neuendorffer  *
5ef141a0bSStephen Neuendorffer  *     This program is free software; you can redistribute it and/or modify it
6ef141a0bSStephen Neuendorffer  *     under the terms of the GNU General Public License as published by the
7ef141a0bSStephen Neuendorffer  *     Free Software Foundation; either version 2 of the License, or (at your
8ef141a0bSStephen Neuendorffer  *     option) any later version.
9ef141a0bSStephen Neuendorffer  *
10ef141a0bSStephen Neuendorffer  *     XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS"
11ef141a0bSStephen Neuendorffer  *     AS A COURTESY TO YOU, SOLELY FOR USE IN DEVELOPING PROGRAMS AND
12ef141a0bSStephen Neuendorffer  *     SOLUTIONS FOR XILINX DEVICES.  BY PROVIDING THIS DESIGN, CODE,
13ef141a0bSStephen Neuendorffer  *     OR INFORMATION AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE,
14ef141a0bSStephen Neuendorffer  *     APPLICATION OR STANDARD, XILINX IS MAKING NO REPRESENTATION
15ef141a0bSStephen Neuendorffer  *     THAT THIS IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT,
16ef141a0bSStephen Neuendorffer  *     AND YOU ARE RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE
17ef141a0bSStephen Neuendorffer  *     FOR YOUR IMPLEMENTATION.  XILINX EXPRESSLY DISCLAIMS ANY
18ef141a0bSStephen Neuendorffer  *     WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE
19ef141a0bSStephen Neuendorffer  *     IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR
20ef141a0bSStephen Neuendorffer  *     REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF
21ef141a0bSStephen Neuendorffer  *     INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22ef141a0bSStephen Neuendorffer  *     FOR A PARTICULAR PURPOSE.
23ef141a0bSStephen Neuendorffer  *
24ef141a0bSStephen Neuendorffer  *     (c) Copyright 2003-2007 Xilinx Inc.
25ef141a0bSStephen Neuendorffer  *     All rights reserved.
26ef141a0bSStephen Neuendorffer  *
27ef141a0bSStephen Neuendorffer  *     You should have received a copy of the GNU General Public License along
28ef141a0bSStephen Neuendorffer  *     with this program; if not, write to the Free Software Foundation, Inc.,
29ef141a0bSStephen Neuendorffer  *     675 Mass Ave, Cambridge, MA 02139, USA.
30ef141a0bSStephen Neuendorffer  *
31ef141a0bSStephen Neuendorffer  *****************************************************************************/
32ef141a0bSStephen Neuendorffer 
33ef141a0bSStephen Neuendorffer #ifndef XILINX_HWICAP_H_	/* prevent circular inclusions */
34ef141a0bSStephen Neuendorffer #define XILINX_HWICAP_H_	/* by using protection macros */
35ef141a0bSStephen Neuendorffer 
36ef141a0bSStephen Neuendorffer #include <linux/types.h>
37ef141a0bSStephen Neuendorffer #include <linux/cdev.h>
38ef141a0bSStephen Neuendorffer #include <linux/platform_device.h>
39ef141a0bSStephen Neuendorffer 
401dd24daeSMichal Simek #include <linux/io.h>
41ef141a0bSStephen Neuendorffer 
42ef141a0bSStephen Neuendorffer struct hwicap_drvdata {
43ef141a0bSStephen Neuendorffer 	u32 write_buffer_in_use;  /* Always in [0,3] */
44ef141a0bSStephen Neuendorffer 	u8 write_buffer[4];
45ef141a0bSStephen Neuendorffer 	u32 read_buffer_in_use;	  /* Always in [0,3] */
46ef141a0bSStephen Neuendorffer 	u8 read_buffer[4];
47f62f2fddSStephen Neuendorffer 	resource_size_t mem_start;/* phys. address of the control registers */
48f62f2fddSStephen Neuendorffer 	resource_size_t mem_end;  /* phys. address of the control registers */
49f62f2fddSStephen Neuendorffer 	resource_size_t mem_size;
50ef141a0bSStephen Neuendorffer 	void __iomem *base_address;/* virt. address of the control registers */
51ef141a0bSStephen Neuendorffer 
52ef141a0bSStephen Neuendorffer 	struct device *dev;
53ef141a0bSStephen Neuendorffer 	struct cdev cdev;	/* Char device structure */
54ef141a0bSStephen Neuendorffer 	dev_t devt;
55ef141a0bSStephen Neuendorffer 
56ef141a0bSStephen Neuendorffer 	const struct hwicap_driver_config *config;
57ef141a0bSStephen Neuendorffer 	const struct config_registers *config_regs;
58ef141a0bSStephen Neuendorffer 	void *private_data;
59ef141a0bSStephen Neuendorffer 	bool is_open;
60f62f2fddSStephen Neuendorffer 	struct mutex sem;
61ef141a0bSStephen Neuendorffer };
62ef141a0bSStephen Neuendorffer 
63ef141a0bSStephen Neuendorffer struct hwicap_driver_config {
646b06fdbaSStephen Neuendorffer 	/* Read configuration data given by size into the data buffer.
65*5cb95faeSNava kishore Manne 	 * Return 0 if successful.
66*5cb95faeSNava kishore Manne 	 */
67ef141a0bSStephen Neuendorffer 	int (*get_configuration)(struct hwicap_drvdata *drvdata, u32 *data,
68ef141a0bSStephen Neuendorffer 			u32 size);
696b06fdbaSStephen Neuendorffer 	/* Write configuration data given by size from the data buffer.
70*5cb95faeSNava kishore Manne 	 * Return 0 if successful.
71*5cb95faeSNava kishore Manne 	 */
72ef141a0bSStephen Neuendorffer 	int (*set_configuration)(struct hwicap_drvdata *drvdata, u32 *data,
73ef141a0bSStephen Neuendorffer 			u32 size);
746b06fdbaSStephen Neuendorffer 	/* Get the status register, bit pattern given by:
756b06fdbaSStephen Neuendorffer 	 * D8 - 0 = configuration error
766b06fdbaSStephen Neuendorffer 	 * D7 - 1 = alignment found
776b06fdbaSStephen Neuendorffer 	 * D6 - 1 = readback in progress
786b06fdbaSStephen Neuendorffer 	 * D5 - 0 = abort in progress
796b06fdbaSStephen Neuendorffer 	 * D4 - Always 1
806b06fdbaSStephen Neuendorffer 	 * D3 - Always 1
816b06fdbaSStephen Neuendorffer 	 * D2 - Always 1
826b06fdbaSStephen Neuendorffer 	 * D1 - Always 1
836b06fdbaSStephen Neuendorffer 	 * D0 - 1 = operation completed
846b06fdbaSStephen Neuendorffer 	 */
856b06fdbaSStephen Neuendorffer 	u32 (*get_status)(struct hwicap_drvdata *drvdata);
866b06fdbaSStephen Neuendorffer 	/* Reset the hw */
87ef141a0bSStephen Neuendorffer 	void (*reset)(struct hwicap_drvdata *drvdata);
88ef141a0bSStephen Neuendorffer };
89ef141a0bSStephen Neuendorffer 
9084524cf4SMichal Simek /* Number of times to poll the done register. This has to be large
9184524cf4SMichal Simek  * enough to allow an entire configuration to complete. If an entire
9284524cf4SMichal Simek  * page (4kb) is configured at once, that could take up to 4k cycles
9384524cf4SMichal Simek  * with a byte-wide icap interface. In most cases, this driver is
9484524cf4SMichal Simek  * used with a much smaller fifo, but this should be sufficient in the
9584524cf4SMichal Simek  * worst case.
9684524cf4SMichal Simek  */
971790625fSDaniel Borkmann #define XHI_MAX_RETRIES     5000
98ef141a0bSStephen Neuendorffer 
99ef141a0bSStephen Neuendorffer /************ Constant Definitions *************/
100ef141a0bSStephen Neuendorffer 
101ef141a0bSStephen Neuendorffer #define XHI_PAD_FRAMES              0x1
102ef141a0bSStephen Neuendorffer 
103ef141a0bSStephen Neuendorffer /* Mask for calculating configuration packet headers */
104ef141a0bSStephen Neuendorffer #define XHI_WORD_COUNT_MASK_TYPE_1  0x7FFUL
105ef141a0bSStephen Neuendorffer #define XHI_WORD_COUNT_MASK_TYPE_2  0x1FFFFFUL
106ef141a0bSStephen Neuendorffer #define XHI_TYPE_MASK               0x7
107ef141a0bSStephen Neuendorffer #define XHI_REGISTER_MASK           0xF
108ef141a0bSStephen Neuendorffer #define XHI_OP_MASK                 0x3
109ef141a0bSStephen Neuendorffer 
110ef141a0bSStephen Neuendorffer #define XHI_TYPE_SHIFT              29
111ef141a0bSStephen Neuendorffer #define XHI_REGISTER_SHIFT          13
112ef141a0bSStephen Neuendorffer #define XHI_OP_SHIFT                27
113ef141a0bSStephen Neuendorffer 
114ef141a0bSStephen Neuendorffer #define XHI_TYPE_1                  1
115ef141a0bSStephen Neuendorffer #define XHI_TYPE_2                  2
116ef141a0bSStephen Neuendorffer #define XHI_OP_WRITE                2
117ef141a0bSStephen Neuendorffer #define XHI_OP_READ                 1
118ef141a0bSStephen Neuendorffer 
119ef141a0bSStephen Neuendorffer /* Address Block Types */
120ef141a0bSStephen Neuendorffer #define XHI_FAR_CLB_BLOCK           0
121ef141a0bSStephen Neuendorffer #define XHI_FAR_BRAM_BLOCK          1
122ef141a0bSStephen Neuendorffer #define XHI_FAR_BRAM_INT_BLOCK      2
123ef141a0bSStephen Neuendorffer 
124ef141a0bSStephen Neuendorffer struct config_registers {
125ef141a0bSStephen Neuendorffer 	u32 CRC;
126ef141a0bSStephen Neuendorffer 	u32 FAR;
127ef141a0bSStephen Neuendorffer 	u32 FDRI;
128ef141a0bSStephen Neuendorffer 	u32 FDRO;
129ef141a0bSStephen Neuendorffer 	u32 CMD;
130ef141a0bSStephen Neuendorffer 	u32 CTL;
131ef141a0bSStephen Neuendorffer 	u32 MASK;
132ef141a0bSStephen Neuendorffer 	u32 STAT;
133ef141a0bSStephen Neuendorffer 	u32 LOUT;
134ef141a0bSStephen Neuendorffer 	u32 COR;
135ef141a0bSStephen Neuendorffer 	u32 MFWR;
136ef141a0bSStephen Neuendorffer 	u32 FLR;
137ef141a0bSStephen Neuendorffer 	u32 KEY;
138ef141a0bSStephen Neuendorffer 	u32 CBC;
139ef141a0bSStephen Neuendorffer 	u32 IDCODE;
140ef141a0bSStephen Neuendorffer 	u32 AXSS;
141ef141a0bSStephen Neuendorffer 	u32 C0R_1;
142ef141a0bSStephen Neuendorffer 	u32 CSOB;
143ef141a0bSStephen Neuendorffer 	u32 WBSTAR;
144ef141a0bSStephen Neuendorffer 	u32 TIMER;
145ef141a0bSStephen Neuendorffer 	u32 BOOTSTS;
146ef141a0bSStephen Neuendorffer 	u32 CTL_1;
147ef141a0bSStephen Neuendorffer };
148ef141a0bSStephen Neuendorffer 
149ef141a0bSStephen Neuendorffer /* Configuration Commands */
150ef141a0bSStephen Neuendorffer #define XHI_CMD_NULL                0
151ef141a0bSStephen Neuendorffer #define XHI_CMD_WCFG                1
152ef141a0bSStephen Neuendorffer #define XHI_CMD_MFW                 2
153ef141a0bSStephen Neuendorffer #define XHI_CMD_DGHIGH              3
154ef141a0bSStephen Neuendorffer #define XHI_CMD_RCFG                4
155ef141a0bSStephen Neuendorffer #define XHI_CMD_START               5
156ef141a0bSStephen Neuendorffer #define XHI_CMD_RCAP                6
157ef141a0bSStephen Neuendorffer #define XHI_CMD_RCRC                7
158ef141a0bSStephen Neuendorffer #define XHI_CMD_AGHIGH              8
159ef141a0bSStephen Neuendorffer #define XHI_CMD_SWITCH              9
160ef141a0bSStephen Neuendorffer #define XHI_CMD_GRESTORE            10
161ef141a0bSStephen Neuendorffer #define XHI_CMD_SHUTDOWN            11
162ef141a0bSStephen Neuendorffer #define XHI_CMD_GCAPTURE            12
163ef141a0bSStephen Neuendorffer #define XHI_CMD_DESYNCH             13
164ef141a0bSStephen Neuendorffer #define XHI_CMD_IPROG               15 /* Only in Virtex5 */
165ef141a0bSStephen Neuendorffer #define XHI_CMD_CRCC                16 /* Only in Virtex5 */
166ef141a0bSStephen Neuendorffer #define XHI_CMD_LTIMER              17 /* Only in Virtex5 */
167ef141a0bSStephen Neuendorffer 
168ef141a0bSStephen Neuendorffer /* Packet constants */
169ef141a0bSStephen Neuendorffer #define XHI_SYNC_PACKET             0xAA995566UL
170ef141a0bSStephen Neuendorffer #define XHI_DUMMY_PACKET            0xFFFFFFFFUL
171ef141a0bSStephen Neuendorffer #define XHI_NOOP_PACKET             (XHI_TYPE_1 << XHI_TYPE_SHIFT)
172ef141a0bSStephen Neuendorffer #define XHI_TYPE_2_READ ((XHI_TYPE_2 << XHI_TYPE_SHIFT) | \
173ef141a0bSStephen Neuendorffer 			(XHI_OP_READ << XHI_OP_SHIFT))
174ef141a0bSStephen Neuendorffer 
175ef141a0bSStephen Neuendorffer #define XHI_TYPE_2_WRITE ((XHI_TYPE_2 << XHI_TYPE_SHIFT) | \
176ef141a0bSStephen Neuendorffer 			(XHI_OP_WRITE << XHI_OP_SHIFT))
177ef141a0bSStephen Neuendorffer 
178ef141a0bSStephen Neuendorffer #define XHI_TYPE2_CNT_MASK          0x07FFFFFF
179ef141a0bSStephen Neuendorffer 
180ef141a0bSStephen Neuendorffer #define XHI_TYPE_1_PACKET_MAX_WORDS 2047UL
181ef141a0bSStephen Neuendorffer #define XHI_TYPE_1_HEADER_BYTES     4
182ef141a0bSStephen Neuendorffer #define XHI_TYPE_2_HEADER_BYTES     8
183ef141a0bSStephen Neuendorffer 
184ef141a0bSStephen Neuendorffer /* Constant to use for CRC check when CRC has been disabled */
185ef141a0bSStephen Neuendorffer #define XHI_DISABLED_AUTO_CRC       0x0000DEFCUL
186ef141a0bSStephen Neuendorffer 
1876b06fdbaSStephen Neuendorffer /* Meanings of the bits returned by get_status */
1886b06fdbaSStephen Neuendorffer #define XHI_SR_CFGERR_N_MASK 0x00000100 /* Config Error Mask */
1896b06fdbaSStephen Neuendorffer #define XHI_SR_DALIGN_MASK 0x00000080 /* Data Alignment Mask */
1906b06fdbaSStephen Neuendorffer #define XHI_SR_RIP_MASK 0x00000040 /* Read back Mask */
1916b06fdbaSStephen Neuendorffer #define XHI_SR_IN_ABORT_N_MASK 0x00000020 /* Select Map Abort Mask */
1926b06fdbaSStephen Neuendorffer #define XHI_SR_DONE_MASK 0x00000001 /* Done bit Mask  */
1936b06fdbaSStephen Neuendorffer 
194ef141a0bSStephen Neuendorffer /**
195f62f2fddSStephen Neuendorffer  * hwicap_type_1_read - Generates a Type 1 read packet header.
196f62f2fddSStephen Neuendorffer  * @reg: is the address of the register to be read back.
197ef141a0bSStephen Neuendorffer  *
198ef2b56dfSNava kishore Manne  * Return:
199ef141a0bSStephen Neuendorffer  * Generates a Type 1 read packet header, which is used to indirectly
200ef141a0bSStephen Neuendorffer  * read registers in the configuration logic.  This packet must then
201ef141a0bSStephen Neuendorffer  * be sent through the icap device, and a return packet received with
202ef141a0bSStephen Neuendorffer  * the information.
203ef2b56dfSNava kishore Manne  */
hwicap_type_1_read(u32 reg)204f62f2fddSStephen Neuendorffer static inline u32 hwicap_type_1_read(u32 reg)
205ef141a0bSStephen Neuendorffer {
206ef141a0bSStephen Neuendorffer 	return (XHI_TYPE_1 << XHI_TYPE_SHIFT) |
207f62f2fddSStephen Neuendorffer 		(reg << XHI_REGISTER_SHIFT) |
208ef141a0bSStephen Neuendorffer 		(XHI_OP_READ << XHI_OP_SHIFT);
209ef141a0bSStephen Neuendorffer }
210ef141a0bSStephen Neuendorffer 
211ef141a0bSStephen Neuendorffer /**
212f62f2fddSStephen Neuendorffer  * hwicap_type_1_write - Generates a Type 1 write packet header
213f62f2fddSStephen Neuendorffer  * @reg: is the address of the register to be read back.
214ef2b56dfSNava kishore Manne  *
215ef2b56dfSNava kishore Manne  * Return: Type 1 write packet header
216ef2b56dfSNava kishore Manne  */
hwicap_type_1_write(u32 reg)217f62f2fddSStephen Neuendorffer static inline u32 hwicap_type_1_write(u32 reg)
218ef141a0bSStephen Neuendorffer {
219ef141a0bSStephen Neuendorffer 	return (XHI_TYPE_1 << XHI_TYPE_SHIFT) |
220f62f2fddSStephen Neuendorffer 		(reg << XHI_REGISTER_SHIFT) |
221ef141a0bSStephen Neuendorffer 		(XHI_OP_WRITE << XHI_OP_SHIFT);
222ef141a0bSStephen Neuendorffer }
223ef141a0bSStephen Neuendorffer 
224ef141a0bSStephen Neuendorffer #endif
225