1 /* Interface for accessing Gaisler AMBA Plug&Play Bus.
2 * The AHB bus can be interfaced with a simpler bus -
3 * the APB bus, also freely available in GRLIB at
7 * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com.
9 * See file CREDITS for list of people who contributed to this
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 /* Default location of Plug&Play info
33 * normally 0xfffff000 for AHB masters
34 * and 0xfffff800 for AHB slaves.
35 * Normally no need to change this.
37 #define LEON3_IO_AREA 0xfff00000
38 #define LEON3_CONF_AREA 0xff000
39 #define LEON3_AHB_SLAVE_CONF_AREA (1 << 11)
41 /* Max devices this software will support */
42 #define LEON3_AHB_MASTERS 16
43 #define LEON3_AHB_SLAVES 16
44 /*#define LEON3_APB_MASTERS 1*//* Number of APB buses that has Plug&Play */
45 #define LEON3_APB_SLAVES 16 /* Total number of APB slaves per APB bus */
48 #define VENDOR_GAISLER 1
49 #define VENDOR_PENDER 2
51 #define VENDOR_ASTRIUM 6
52 #define VENDOR_OPENCHIP 7
53 #define VENDOR_OPENCORES 8
54 #define VENDOR_CONTRIB 9
55 #define VENDOR_EONIC 11
56 #define VENDOR_RADIONOR 15
57 #define VENDOR_GLEICHMANN 16
58 #define VENDOR_MENTA 17
60 #define VENDOR_EMBEDDIT 234
61 #define VENDOR_CAL 202
63 /* Gaisler Research device id's */
64 #define GAISLER_LEON3 0x003
65 #define GAISLER_LEON3DSU 0x004
66 #define GAISLER_ETHAHB 0x005
67 #define GAISLER_APBMST 0x006
68 #define GAISLER_AHBUART 0x007
69 #define GAISLER_SRCTRL 0x008
70 #define GAISLER_SDCTRL 0x009
71 #define GAISLER_APBUART 0x00C
72 #define GAISLER_IRQMP 0x00D
73 #define GAISLER_AHBRAM 0x00E
74 #define GAISLER_GPTIMER 0x011
75 #define GAISLER_PCITRG 0x012
76 #define GAISLER_PCISBRG 0x013
77 #define GAISLER_PCIFBRG 0x014
78 #define GAISLER_PCITRACE 0x015
79 #define GAISLER_PCIDMA 0x016
80 #define GAISLER_AHBTRACE 0x017
81 #define GAISLER_ETHDSU 0x018
82 #define GAISLER_PIOPORT 0x01A
83 #define GAISLER_AHBJTAG 0x01c
84 #define GAISLER_SPW 0x01f
85 #define GAISLER_ATACTRL 0x024
86 #define GAISLER_VGA 0x061
87 #define GAISLER_KBD 0X060
88 #define GAISLER_ETHMAC 0x01D
89 #define GAISLER_DDRSPA 0x025
90 #define GAISLER_EHCI 0x026
91 #define GAISLER_UHCI 0x027
92 #define GAISLER_SPW2 0x029
93 #define GAISLER_DDR2SPA 0x02E
94 #define GAISLER_AHBSTAT 0x052
95 #define GAISLER_FTMCTRL 0x054
97 #define GAISLER_L2TIME 0xffd /* internal device: leon2 timer */
98 #define GAISLER_L2C 0xffe /* internal device: leon2compat */
99 #define GAISLER_PLUGPLAY 0xfff /* internal device: plug & play configarea */
101 /* European Space Agency device id's */
102 #define ESA_LEON2 0x2
103 #define ESA_MCTRL 0xF
105 /* Opencores device id's */
106 #define OPENCORES_PCIBR 0x4
107 #define OPENCORES_ETHMAC 0x5
113 * Macros for manipulating Configuration registers
117 #define amba_vendor(x) (((x) >> 24) & 0xff)
119 #define amba_device(x) (((x) >> 12) & 0xfff)
121 #define amba_membar_start(mbar) \
122 (((mbar) & 0xfff00000) & (((mbar) & 0xfff0) << 16))
124 #define amba_iobar_start(base, iobar) \
125 ((base) | ((((iobar) & 0xfff00000)>>12) & (((iobar) & 0xfff0)<<4)) )
127 #define amba_irq(conf) ((conf) & 0xf)
129 #define amba_ver(conf) (((conf)>>5) & 0x1f)
131 #define amba_membar_type(mbar) ((mbar) & 0xf)
133 #define amba_membar_mask(mbar) (((mbar)>>4) & 0xfff)
135 #define AMBA_TYPE_APBIO 0x1
136 #define AMBA_TYPE_MEM 0x2
137 #define AMBA_TYPE_AHBIO 0x3
139 #define AMBA_TYPE_AHBIO_ADDR(addr) (LEON3_IO_AREA | ((addr) >> 12))
141 #ifndef __ASSEMBLER__
144 * Types and structure used for AMBA Plug & Play bus scanning
147 /* AMBA Plug&Play AHB information layout */
150 unsigned int userdef[3];
151 unsigned int bars[4];
154 /* Prototypes for scanning AMBA Plug&Play bus for AMBA
157 * iii) APB Slaves (APB MST is a AHB Slave)
163 unsigned int address;
169 unsigned int userdef[3];
170 unsigned int address[4];
173 /* AMBA Plug&Play AHB Masters & Slaves information locations
174 * Max devices is 64 supported by HW, however often only 8
178 ahbctrl_pp_dev masters[64];
179 ahbctrl_pp_dev slaves[64];
182 /* AMBA Plug&Play AHB information layout */
188 /* All functions return the number of found devices
189 * 0 = no devices found
192 /****************************** APB SLAVES ******************************/
193 int ambapp_apb_count(unsigned int vendor, unsigned int driver);
195 int ambapp_apb_first(unsigned int vendor,
196 unsigned int driver, ambapp_apbdev * dev);
198 int ambapp_apb_next(unsigned int vendor,
199 unsigned int driver, ambapp_apbdev * dev, int index);
201 int ambapp_apbs_first(unsigned int vendor,
202 unsigned int driver, ambapp_apbdev * dev, int max_cnt);
204 /****************************** AHB MASTERS ******************************/
205 int ambapp_ahbmst_count(unsigned int vendor, unsigned int driver);
207 int ambapp_ahbmst_first(unsigned int vendor,
208 unsigned int driver, ambapp_ahbdev * dev);
210 int ambapp_ahbmst_next(unsigned int vendor,
211 unsigned int driver, ambapp_ahbdev * dev, int index);
213 int ambapp_ahbmsts_first(unsigned int vendor,
214 unsigned int driver, ambapp_ahbdev * dev, int max_cnt);
216 /****************************** AHB SLAVES ******************************/
217 int ambapp_ahbslv_count(unsigned int vendor, unsigned int driver);
219 int ambapp_ahbslv_first(unsigned int vendor,
220 unsigned int driver, ambapp_ahbdev * dev);
222 int ambapp_ahbslv_next(unsigned int vendor,
223 unsigned int driver, ambapp_ahbdev * dev, int index);
225 int ambapp_ahbslvs_first(unsigned int vendor,
226 unsigned int driver, ambapp_ahbdev * dev, int max_cnt);
228 /*************************** AHB/APB only regs functions *************************
229 * During start up, no memory is available we can use the simplified functions
230 * to get to the memory controller.
232 * Functions uses no stack/memory, only registers.
234 unsigned int ambapp_apb_next_nomem(register unsigned int vendor, /* Plug&Play Vendor ID */
235 register unsigned int driver, /* Plug&Play Device ID */
238 ahbctrl_pp_dev *ambapp_ahb_next_nomem(register unsigned int vendor, /* Plug&Play Vendor ID */
239 register unsigned int driver, /* Plug&Play Device ID */
240 register unsigned int opts, /* scan for AHB 1=slave, 0=masters */
243 unsigned int ambapp_ahb_get_info(ahbctrl_pp_dev * ahb, int info);
245 /*************************** AMBA Plug&Play device register MAPS *****************/
248 * The following defines the bits in the LEON UART Status Registers.
251 #define LEON_REG_UART_STATUS_DR 0x00000001 /* Data Ready */
252 #define LEON_REG_UART_STATUS_TSE 0x00000002 /* TX Send Register Empty */
253 #define LEON_REG_UART_STATUS_THE 0x00000004 /* TX Hold Register Empty */
254 #define LEON_REG_UART_STATUS_BR 0x00000008 /* Break Error */
255 #define LEON_REG_UART_STATUS_OE 0x00000010 /* RX Overrun Error */
256 #define LEON_REG_UART_STATUS_PE 0x00000020 /* RX Parity Error */
257 #define LEON_REG_UART_STATUS_FE 0x00000040 /* RX Framing Error */
258 #define LEON_REG_UART_STATUS_ERR 0x00000078 /* Error Mask */
261 * The following defines the bits in the LEON UART Ctrl Registers.
264 #define LEON_REG_UART_CTRL_RE 0x00000001 /* Receiver enable */
265 #define LEON_REG_UART_CTRL_TE 0x00000002 /* Transmitter enable */
266 #define LEON_REG_UART_CTRL_RI 0x00000004 /* Receiver interrupt enable */
267 #define LEON_REG_UART_CTRL_TI 0x00000008 /* Transmitter interrupt enable */
268 #define LEON_REG_UART_CTRL_PS 0x00000010 /* Parity select */
269 #define LEON_REG_UART_CTRL_PE 0x00000020 /* Parity enable */
270 #define LEON_REG_UART_CTRL_FL 0x00000040 /* Flow control enable */
271 #define LEON_REG_UART_CTRL_LB 0x00000080 /* Loop Back enable */
272 #define LEON_REG_UART_CTRL_DBG (1<<11) /* Debug Bit used by GRMON */
274 #define LEON3_GPTIMER_EN 1
275 #define LEON3_GPTIMER_RL 2
276 #define LEON3_GPTIMER_LD 4
277 #define LEON3_GPTIMER_IRQEN 8
280 * The following defines the bits in the LEON PS/2 Status Registers.
283 #define LEON_REG_PS2_STATUS_DR 0x00000001 /* Data Ready */
284 #define LEON_REG_PS2_STATUS_PE 0x00000002 /* Parity error */
285 #define LEON_REG_PS2_STATUS_FE 0x00000004 /* Framing error */
286 #define LEON_REG_PS2_STATUS_KI 0x00000008 /* Keyboard inhibit */
289 * The following defines the bits in the LEON PS/2 Ctrl Registers.
292 #define LEON_REG_PS2_CTRL_RE 0x00000001 /* Receiver enable */
293 #define LEON_REG_PS2_CTRL_TE 0x00000002 /* Transmitter enable */
294 #define LEON_REG_PS2_CTRL_RI 0x00000004 /* Keyboard receive interrupt */
295 #define LEON_REG_PS2_CTRL_TI 0x00000008 /* Keyboard transmit interrupt */
298 volatile unsigned int ilevel;
299 volatile unsigned int ipend;
300 volatile unsigned int iforce;
301 volatile unsigned int iclear;
302 volatile unsigned int mstatus;
303 volatile unsigned int notused[11];
304 volatile unsigned int cpu_mask[16];
305 volatile unsigned int cpu_force[16];
309 volatile unsigned int data;
310 volatile unsigned int status;
311 volatile unsigned int ctrl;
312 volatile unsigned int scaler;
313 } ambapp_dev_apbuart;
316 volatile unsigned int val;
317 volatile unsigned int rld;
318 volatile unsigned int ctrl;
319 volatile unsigned int unused;
320 } ambapp_dev_gptimer_element;
322 #define LEON3_GPTIMER_CTRL_EN 0x1 /* Timer enable */
323 #define LEON3_GPTIMER_CTRL_RS 0x2 /* Timer reStart */
324 #define LEON3_GPTIMER_CTRL_LD 0x4 /* Timer reLoad */
325 #define LEON3_GPTIMER_CTRL_IE 0x8 /* interrupt enable */
326 #define LEON3_GPTIMER_CTRL_IP 0x10 /* interrupt flag/pending */
327 #define LEON3_GPTIMER_CTRL_CH 0x20 /* Chain with previous timer */
330 volatile unsigned int scalar;
331 volatile unsigned int scalar_reload;
332 volatile unsigned int config;
333 volatile unsigned int unused;
334 volatile ambapp_dev_gptimer_element e[8];
335 } ambapp_dev_gptimer;
338 volatile unsigned int iodata;
339 volatile unsigned int ioout;
340 volatile unsigned int iodir;
341 volatile unsigned int irqmask;
342 volatile unsigned int irqpol;
343 volatile unsigned int irqedge;
347 volatile unsigned int write;
348 volatile unsigned int dummy;
349 volatile unsigned int txcolor;
350 volatile unsigned int bgcolor;
351 } ambapp_dev_textvga;
354 volatile unsigned int data;
355 volatile unsigned int status;
356 volatile unsigned int ctrl;
360 unsigned int mcfg1, mcfg2, mcfg3;
371 } ambapp_dev_ddr2spa;