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
6 * (C) Copyright 2009, 2015
7 * Daniel Hellstrom, Cobham Gaisler, daniel@gaisler.com.
9 * SPDX-License-Identifier: GPL-2.0+
15 #include <ambapp_ids.h>
18 /* Structures used to access Plug&Play information directly */
19 struct ambapp_pnp_ahb {
20 const unsigned int id; /* VENDOR, DEVICE, VER, IRQ, */
21 const unsigned int custom[3];
22 const unsigned int mbar[4]; /* MASK, ADDRESS, TYPE,
23 * CACHABLE/PREFETCHABLE */
26 struct ambapp_pnp_apb {
27 const unsigned int id; /* VENDOR, DEVICE, VER, IRQ, */
28 const unsigned int iobar; /* MASK, ADDRESS, TYPE,
29 * CACHABLE/PREFETCHABLE */
32 /* AMBA Plug&Play AHB Masters & Slaves information locations
33 * Max devices is 64 supported by HW, however often only 16
36 struct ambapp_pnp_info {
37 struct ambapp_pnp_ahb masters[64];
38 struct ambapp_pnp_ahb slaves[63];
39 const unsigned int unused[4];
40 const unsigned int systemid[4];
43 /* Describes a AMBA PnP bus */
45 int buses; /* Number of buses */
46 unsigned int ioareas[6]; /* PnP I/O AREAs of AHB buses */
47 unsigned int freq; /* Frequency of bus0 [Hz] */
50 /* Processor Local AMBA bus */
51 extern struct ambapp_bus ambapp_plb;
53 /* Get Bus frequency of a certain AMBA bus */
54 extern unsigned int ambapp_bus_freq(
55 struct ambapp_bus *abus,
59 /* AMBA PnP information of a APB Device */
70 /* AMBA PnP information of a AHB Device */
76 unsigned int userdef[3];
77 unsigned int address[4];
83 /* Scan AMBA Bus for AHB Bridges */
84 extern void ambapp_bus_init(
87 struct ambapp_bus *abus);
89 /* Find APB Slave device by index using breath first search.
91 * When vendor and device are both set to zero, any device
92 * with a non-zero device ID will match the search. It may be
93 * useful when processing all devices on a AMBA bus.
95 extern int ambapp_apb_find(
96 struct ambapp_bus *abus,
103 /* Find AHB Master device by index using breath first search.
105 * When vendor and device are both set to zero, any device
106 * with a non-zero device ID will match the search. It may be
107 * useful when processing all devices on a AMBA bus.
109 extern int ambapp_ahbmst_find(
110 struct ambapp_bus *abus,
117 /* Find AHB Slave device by index using breath first search.
119 * When vendor and device are both set to zero, any device
120 * with a non-zero device ID will match the search. It may be
121 * useful when processing all devices on a AMBA bus.
123 extern int ambapp_ahbslv_find(
124 struct ambapp_bus *abus,
131 /* Return number of APB Slave devices of a certain ID (VENDOR:DEVICE)
132 * zero is returned if no devices was found.
134 extern int ambapp_apb_count(struct ambapp_bus *abus, int vendor, int device);
136 /* Return number of AHB Master devices of a certain ID (VENDOR:DEVICE)
137 * zero is returned if no devices was found.
139 extern int ambapp_ahbmst_count(struct ambapp_bus *abus, int vendor, int device);
141 /* Return number of AHB Slave devices of a certain ID (VENDOR:DEVICE)
142 * zero is returned if no devices was found.
144 extern int ambapp_ahbslv_count(struct ambapp_bus *abus, int vendor, int device);
146 #ifdef CONFIG_CMD_AMBAPP
148 /* AMBA Plug&Play relocation & initialization */
149 int ambapp_init_reloc(void);
151 /* AMBA Plug&Play Name of Vendors and devices */
153 /* Return name of device */
154 char *ambapp_device_id2str(int vendor, int id);
156 /* Return name of vendor */
157 char *ambapp_vendor_id2str(int vendor);
159 /* Return description of a device */
160 char *ambapp_device_id2desc(int vendor, int id);
164 #endif /* defined(__ASSEMBLER__) */
166 #define AMBA_DEFAULT_IOAREA 0xfff00000
167 #define AMBA_CONF_AREA 0xff000
168 #define AMBA_AHB_SLAVE_CONF_AREA 0x800
171 #define DEV_AHB_MST 1
172 #define DEV_AHB_SLV 2
173 #define DEV_APB_SLV 3
175 #define AMBA_TYPE_APBIO 0x1
176 #define AMBA_TYPE_MEM 0x2
177 #define AMBA_TYPE_AHBIO 0x3
179 /* ID layout for APB and AHB devices */
180 #define AMBA_PNP_ID(vendor, device) (((vendor)<<24) | ((device)<<12))
182 /* APB Slave PnP layout definitions */
183 #define AMBA_APB_ID_OFS (0*4)
184 #define AMBA_APB_IOBAR_OFS (1*4)
185 #define AMBA_APB_CONF_LENGH (2*4)
187 /* AHB Master/Slave layout PnP definitions */
188 #define AMBA_AHB_ID_OFS (0*4)
189 #define AMBA_AHB_CUSTOM0_OFS (1*4)
190 #define AMBA_AHB_CUSTOM1_OFS (2*4)
191 #define AMBA_AHB_CUSTOM2_OFS (3*4)
192 #define AMBA_AHB_MBAR0_OFS (4*4)
193 #define AMBA_AHB_MBAR1_OFS (5*4)
194 #define AMBA_AHB_MBAR2_OFS (6*4)
195 #define AMBA_AHB_MBAR3_OFS (7*4)
196 #define AMBA_AHB_CONF_LENGH (8*4)
198 /* Macros for extracting information from AMBA PnP information
202 #define amba_vendor(x) (((x) >> 24) & 0xff)
204 #define amba_device(x) (((x) >> 12) & 0xfff)
206 #define amba_irq(conf) ((conf) & 0x1f)
208 #define amba_ver(conf) (((conf)>>5) & 0x1f)
210 #define amba_iobar_start(base, iobar) \
211 ((base) | ((((iobar) & 0xfff00000)>>12) & (((iobar) & 0xfff0)<<4)))
213 #define amba_membar_start(mbar) \
214 (((mbar) & 0xfff00000) & (((mbar) & 0xfff0) << 16))
216 #define amba_membar_type(mbar) ((mbar) & 0xf)
218 #define amba_membar_mask(mbar) (((mbar) >> 4) & 0xfff)
220 #define amba_ahbio_adr(addr, base_ioarea) \
221 ((unsigned int)(base_ioarea) | ((addr) >> 12))
223 #define amba_apb_mask(iobar) ((~(amba_membar_mask(iobar)<<8) & 0x000fffff) + 1)
225 /*************************** AMBA Plug&Play device register MAPS *****************/
228 * The following defines the bits in the LEON UART Status Registers.
231 #define LEON_REG_UART_STATUS_DR 0x00000001 /* Data Ready */
232 #define LEON_REG_UART_STATUS_TSE 0x00000002 /* TX Send Register Empty */
233 #define LEON_REG_UART_STATUS_THE 0x00000004 /* TX Hold Register Empty */
234 #define LEON_REG_UART_STATUS_BR 0x00000008 /* Break Error */
235 #define LEON_REG_UART_STATUS_OE 0x00000010 /* RX Overrun Error */
236 #define LEON_REG_UART_STATUS_PE 0x00000020 /* RX Parity Error */
237 #define LEON_REG_UART_STATUS_FE 0x00000040 /* RX Framing Error */
238 #define LEON_REG_UART_STATUS_ERR 0x00000078 /* Error Mask */
241 * The following defines the bits in the LEON UART Ctrl Registers.
244 #define LEON_REG_UART_CTRL_RE 0x00000001 /* Receiver enable */
245 #define LEON_REG_UART_CTRL_TE 0x00000002 /* Transmitter enable */
246 #define LEON_REG_UART_CTRL_RI 0x00000004 /* Receiver interrupt enable */
247 #define LEON_REG_UART_CTRL_TI 0x00000008 /* Transmitter interrupt enable */
248 #define LEON_REG_UART_CTRL_PS 0x00000010 /* Parity select */
249 #define LEON_REG_UART_CTRL_PE 0x00000020 /* Parity enable */
250 #define LEON_REG_UART_CTRL_FL 0x00000040 /* Flow control enable */
251 #define LEON_REG_UART_CTRL_LB 0x00000080 /* Loop Back enable */
252 #define LEON_REG_UART_CTRL_DBG (1<<11) /* Debug Bit used by GRMON */
254 #define LEON3_GPTIMER_EN 1
255 #define LEON3_GPTIMER_RL 2
256 #define LEON3_GPTIMER_LD 4
257 #define LEON3_GPTIMER_IRQEN 8
260 * The following defines the bits in the LEON PS/2 Status Registers.
263 #define LEON_REG_PS2_STATUS_DR 0x00000001 /* Data Ready */
264 #define LEON_REG_PS2_STATUS_PE 0x00000002 /* Parity error */
265 #define LEON_REG_PS2_STATUS_FE 0x00000004 /* Framing error */
266 #define LEON_REG_PS2_STATUS_KI 0x00000008 /* Keyboard inhibit */
269 * The following defines the bits in the LEON PS/2 Ctrl Registers.
272 #define LEON_REG_PS2_CTRL_RE 0x00000001 /* Receiver enable */
273 #define LEON_REG_PS2_CTRL_TE 0x00000002 /* Transmitter enable */
274 #define LEON_REG_PS2_CTRL_RI 0x00000004 /* Keyboard receive interrupt */
275 #define LEON_REG_PS2_CTRL_TI 0x00000008 /* Keyboard transmit interrupt */
277 #ifndef __ASSEMBLER__
280 volatile unsigned int ilevel;
281 volatile unsigned int ipend;
282 volatile unsigned int iforce;
283 volatile unsigned int iclear;
284 volatile unsigned int mstatus;
285 volatile unsigned int notused[11];
286 volatile unsigned int cpu_mask[16];
287 volatile unsigned int cpu_force[16];
291 volatile unsigned int data;
292 volatile unsigned int status;
293 volatile unsigned int ctrl;
294 volatile unsigned int scaler;
295 } ambapp_dev_apbuart;
298 volatile unsigned int val;
299 volatile unsigned int rld;
300 volatile unsigned int ctrl;
301 volatile unsigned int unused;
302 } ambapp_dev_gptimer_element;
304 #define LEON3_GPTIMER_CTRL_EN 0x1 /* Timer enable */
305 #define LEON3_GPTIMER_CTRL_RS 0x2 /* Timer reStart */
306 #define LEON3_GPTIMER_CTRL_LD 0x4 /* Timer reLoad */
307 #define LEON3_GPTIMER_CTRL_IE 0x8 /* interrupt enable */
308 #define LEON3_GPTIMER_CTRL_IP 0x10 /* interrupt flag/pending */
309 #define LEON3_GPTIMER_CTRL_CH 0x20 /* Chain with previous timer */
312 volatile unsigned int scalar;
313 volatile unsigned int scalar_reload;
314 volatile unsigned int config;
315 volatile unsigned int unused;
316 volatile ambapp_dev_gptimer_element e[8];
317 } ambapp_dev_gptimer;
320 volatile unsigned int iodata;
321 volatile unsigned int ioout;
322 volatile unsigned int iodir;
323 volatile unsigned int irqmask;
324 volatile unsigned int irqpol;
325 volatile unsigned int irqedge;
329 volatile unsigned int write;
330 volatile unsigned int dummy;
331 volatile unsigned int txcolor;
332 volatile unsigned int bgcolor;
333 } ambapp_dev_textvga;
336 volatile unsigned int data;
337 volatile unsigned int status;
338 volatile unsigned int ctrl;
342 unsigned int mcfg1, mcfg2, mcfg3;
353 } ambapp_dev_ddr2spa;