162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci*Copyright (C) 2004 Konrad Eisele (eiselekd@web.de,konrad@gaisler.com), Gaisler Research
462306a36Sopenharmony_ci*Copyright (C) 2004 Stefan Holst (mail@s-holst.de), Uni-Stuttgart
562306a36Sopenharmony_ci*Copyright (C) 2009 Daniel Hellstrom (daniel@gaisler.com),Konrad Eisele (konrad@gaisler.com) Aeroflex Gaisler AB
662306a36Sopenharmony_ci*/
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#ifndef LEON_AMBA_H_INCLUDE
962306a36Sopenharmony_ci#define LEON_AMBA_H_INCLUDE
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#ifndef __ASSEMBLY__
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_cistruct amba_prom_registers {
1462306a36Sopenharmony_ci	unsigned int phys_addr;	/* The physical address of this register */
1562306a36Sopenharmony_ci	unsigned int reg_size;	/* How many bytes does this register take up? */
1662306a36Sopenharmony_ci};
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci#endif
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci/*
2162306a36Sopenharmony_ci *  The following defines the bits in the LEON UART Status Registers.
2262306a36Sopenharmony_ci */
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci#define LEON_REG_UART_STATUS_DR   0x00000001	/* Data Ready */
2562306a36Sopenharmony_ci#define LEON_REG_UART_STATUS_TSE  0x00000002	/* TX Send Register Empty */
2662306a36Sopenharmony_ci#define LEON_REG_UART_STATUS_THE  0x00000004	/* TX Hold Register Empty */
2762306a36Sopenharmony_ci#define LEON_REG_UART_STATUS_BR   0x00000008	/* Break Error */
2862306a36Sopenharmony_ci#define LEON_REG_UART_STATUS_OE   0x00000010	/* RX Overrun Error */
2962306a36Sopenharmony_ci#define LEON_REG_UART_STATUS_PE   0x00000020	/* RX Parity Error */
3062306a36Sopenharmony_ci#define LEON_REG_UART_STATUS_FE   0x00000040	/* RX Framing Error */
3162306a36Sopenharmony_ci#define LEON_REG_UART_STATUS_ERR  0x00000078	/* Error Mask */
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci/*
3462306a36Sopenharmony_ci *  The following defines the bits in the LEON UART Ctrl Registers.
3562306a36Sopenharmony_ci */
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci#define LEON_REG_UART_CTRL_RE     0x00000001	/* Receiver enable */
3862306a36Sopenharmony_ci#define LEON_REG_UART_CTRL_TE     0x00000002	/* Transmitter enable */
3962306a36Sopenharmony_ci#define LEON_REG_UART_CTRL_RI     0x00000004	/* Receiver interrupt enable */
4062306a36Sopenharmony_ci#define LEON_REG_UART_CTRL_TI     0x00000008	/* Transmitter irq */
4162306a36Sopenharmony_ci#define LEON_REG_UART_CTRL_PS     0x00000010	/* Parity select */
4262306a36Sopenharmony_ci#define LEON_REG_UART_CTRL_PE     0x00000020	/* Parity enable */
4362306a36Sopenharmony_ci#define LEON_REG_UART_CTRL_FL     0x00000040	/* Flow control enable */
4462306a36Sopenharmony_ci#define LEON_REG_UART_CTRL_LB     0x00000080	/* Loop Back enable */
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci#define LEON3_GPTIMER_EN 1
4762306a36Sopenharmony_ci#define LEON3_GPTIMER_RL 2
4862306a36Sopenharmony_ci#define LEON3_GPTIMER_LD 4
4962306a36Sopenharmony_ci#define LEON3_GPTIMER_IRQEN 8
5062306a36Sopenharmony_ci#define LEON3_GPTIMER_SEPIRQ 8
5162306a36Sopenharmony_ci#define LEON3_GPTIMER_TIMERS 0x7
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci#define LEON23_REG_TIMER_CONTROL_EN    0x00000001 /* 1 = enable counting */
5462306a36Sopenharmony_ci/* 0 = hold scalar and counter */
5562306a36Sopenharmony_ci#define LEON23_REG_TIMER_CONTROL_RL    0x00000002 /* 1 = reload at 0 */
5662306a36Sopenharmony_ci						  /* 0 = stop at 0 */
5762306a36Sopenharmony_ci#define LEON23_REG_TIMER_CONTROL_LD    0x00000004 /* 1 = load counter */
5862306a36Sopenharmony_ci						  /* 0 = no function */
5962306a36Sopenharmony_ci#define LEON23_REG_TIMER_CONTROL_IQ    0x00000008 /* 1 = irq enable */
6062306a36Sopenharmony_ci						  /* 0 = no function */
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci/*
6362306a36Sopenharmony_ci *  The following defines the bits in the LEON PS/2 Status Registers.
6462306a36Sopenharmony_ci */
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci#define LEON_REG_PS2_STATUS_DR   0x00000001	/* Data Ready */
6762306a36Sopenharmony_ci#define LEON_REG_PS2_STATUS_PE   0x00000002	/* Parity error */
6862306a36Sopenharmony_ci#define LEON_REG_PS2_STATUS_FE   0x00000004	/* Framing error */
6962306a36Sopenharmony_ci#define LEON_REG_PS2_STATUS_KI   0x00000008	/* Keyboard inhibit */
7062306a36Sopenharmony_ci#define LEON_REG_PS2_STATUS_RF   0x00000010	/* RX buffer full */
7162306a36Sopenharmony_ci#define LEON_REG_PS2_STATUS_TF   0x00000020	/* TX buffer full */
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci/*
7462306a36Sopenharmony_ci *  The following defines the bits in the LEON PS/2 Ctrl Registers.
7562306a36Sopenharmony_ci */
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci#define LEON_REG_PS2_CTRL_RE 0x00000001	/* Receiver enable */
7862306a36Sopenharmony_ci#define LEON_REG_PS2_CTRL_TE 0x00000002	/* Transmitter enable */
7962306a36Sopenharmony_ci#define LEON_REG_PS2_CTRL_RI 0x00000004	/* Keyboard receive irq  */
8062306a36Sopenharmony_ci#define LEON_REG_PS2_CTRL_TI 0x00000008	/* Keyboard transmit irq */
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci#define LEON3_IRQMPSTATUS_CPUNR     28
8362306a36Sopenharmony_ci#define LEON3_IRQMPSTATUS_BROADCAST 27
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci#define GPTIMER_CONFIG_IRQNT(a)          (((a) >> 3) & 0x1f)
8662306a36Sopenharmony_ci#define GPTIMER_CONFIG_ISSEP(a)          ((a) & (1 << 8))
8762306a36Sopenharmony_ci#define GPTIMER_CONFIG_NTIMERS(a)        ((a) & (0x7))
8862306a36Sopenharmony_ci#define LEON3_GPTIMER_CTRL_PENDING       0x10
8962306a36Sopenharmony_ci#define LEON3_GPTIMER_CONFIG_NRTIMERS(c) ((c)->config & 0x7)
9062306a36Sopenharmony_ci#define LEON3_GPTIMER_CTRL_ISPENDING(r)  (((r)&LEON3_GPTIMER_CTRL_PENDING) ? 1 : 0)
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci#ifndef __ASSEMBLY__
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_cistruct leon3_irqctrl_regs_map {
9562306a36Sopenharmony_ci	u32 ilevel;
9662306a36Sopenharmony_ci	u32 ipend;
9762306a36Sopenharmony_ci	u32 iforce;
9862306a36Sopenharmony_ci	u32 iclear;
9962306a36Sopenharmony_ci	u32 mpstatus;
10062306a36Sopenharmony_ci	u32 mpbroadcast;
10162306a36Sopenharmony_ci	u32 notused02;
10262306a36Sopenharmony_ci	u32 notused03;
10362306a36Sopenharmony_ci	u32 ampctrl;
10462306a36Sopenharmony_ci	u32 icsel[2];
10562306a36Sopenharmony_ci	u32 notused13;
10662306a36Sopenharmony_ci	u32 notused20;
10762306a36Sopenharmony_ci	u32 notused21;
10862306a36Sopenharmony_ci	u32 notused22;
10962306a36Sopenharmony_ci	u32 notused23;
11062306a36Sopenharmony_ci	u32 mask[16];
11162306a36Sopenharmony_ci	u32 force[16];
11262306a36Sopenharmony_ci	/* Extended IRQ registers */
11362306a36Sopenharmony_ci	u32 intid[16];	/* 0xc0 */
11462306a36Sopenharmony_ci	u32 unused[(0x1000-0x100)/4];
11562306a36Sopenharmony_ci};
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_cistruct leon3_apbuart_regs_map {
11862306a36Sopenharmony_ci	u32 data;
11962306a36Sopenharmony_ci	u32 status;
12062306a36Sopenharmony_ci	u32 ctrl;
12162306a36Sopenharmony_ci	u32 scaler;
12262306a36Sopenharmony_ci};
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_cistruct leon3_gptimerelem_regs_map {
12562306a36Sopenharmony_ci	u32 val;
12662306a36Sopenharmony_ci	u32 rld;
12762306a36Sopenharmony_ci	u32 ctrl;
12862306a36Sopenharmony_ci	u32 unused;
12962306a36Sopenharmony_ci};
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_cistruct leon3_gptimer_regs_map {
13262306a36Sopenharmony_ci	u32 scalar;
13362306a36Sopenharmony_ci	u32 scalar_reload;
13462306a36Sopenharmony_ci	u32 config;
13562306a36Sopenharmony_ci	u32 unused;
13662306a36Sopenharmony_ci	struct leon3_gptimerelem_regs_map e[8];
13762306a36Sopenharmony_ci};
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci/*
14062306a36Sopenharmony_ci *  Types and structure used for AMBA Plug & Play bus scanning
14162306a36Sopenharmony_ci */
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_ci#define AMBA_MAXAPB_DEVS 64
14462306a36Sopenharmony_ci#define AMBA_MAXAPB_DEVS_PERBUS 16
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_cistruct amba_device_table {
14762306a36Sopenharmony_ci	int devnr;		   /* number of devices on AHB or APB bus */
14862306a36Sopenharmony_ci	unsigned int *addr[16];    /* addresses to the devices configuration tables */
14962306a36Sopenharmony_ci	unsigned int allocbits[1]; /* 0=unallocated, 1=allocated driver */
15062306a36Sopenharmony_ci};
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_cistruct amba_apbslv_device_table {
15362306a36Sopenharmony_ci	int devnr;		                  /* number of devices on AHB or APB bus */
15462306a36Sopenharmony_ci	unsigned int *addr[AMBA_MAXAPB_DEVS];     /* addresses to the devices configuration tables */
15562306a36Sopenharmony_ci	unsigned int apbmst[AMBA_MAXAPB_DEVS];    /* apb master if a entry is a apb slave */
15662306a36Sopenharmony_ci	unsigned int apbmstidx[AMBA_MAXAPB_DEVS]; /* apb master idx if a entry is a apb slave */
15762306a36Sopenharmony_ci	unsigned int allocbits[4];                /* 0=unallocated, 1=allocated driver */
15862306a36Sopenharmony_ci};
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_cistruct amba_confarea_type {
16162306a36Sopenharmony_ci	struct amba_confarea_type *next;/* next bus in chain */
16262306a36Sopenharmony_ci	struct amba_device_table ahbmst;
16362306a36Sopenharmony_ci	struct amba_device_table ahbslv;
16462306a36Sopenharmony_ci	struct amba_apbslv_device_table apbslv;
16562306a36Sopenharmony_ci	unsigned int apbmst;
16662306a36Sopenharmony_ci};
16762306a36Sopenharmony_ci
16862306a36Sopenharmony_ci/* collect apb slaves */
16962306a36Sopenharmony_cistruct amba_apb_device {
17062306a36Sopenharmony_ci	unsigned int start, irq, bus_id;
17162306a36Sopenharmony_ci	struct amba_confarea_type *bus;
17262306a36Sopenharmony_ci};
17362306a36Sopenharmony_ci
17462306a36Sopenharmony_ci/* collect ahb slaves */
17562306a36Sopenharmony_cistruct amba_ahb_device {
17662306a36Sopenharmony_ci	unsigned int start[4], irq, bus_id;
17762306a36Sopenharmony_ci	struct amba_confarea_type *bus;
17862306a36Sopenharmony_ci};
17962306a36Sopenharmony_ci
18062306a36Sopenharmony_cistruct device_node;
18162306a36Sopenharmony_civoid _amba_init(struct device_node *dp, struct device_node ***nextp);
18262306a36Sopenharmony_ci
18362306a36Sopenharmony_ciextern unsigned long amba_system_id;
18462306a36Sopenharmony_ciextern struct leon3_irqctrl_regs_map *leon3_irqctrl_regs;
18562306a36Sopenharmony_ciextern struct leon3_gptimer_regs_map *leon3_gptimer_regs;
18662306a36Sopenharmony_ciextern struct amba_apb_device leon_percpu_timer_dev[16];
18762306a36Sopenharmony_ciextern int leondebug_irq_disable;
18862306a36Sopenharmony_ciextern int leon_debug_irqout;
18962306a36Sopenharmony_ciextern unsigned long leon3_gptimer_irq;
19062306a36Sopenharmony_ciextern unsigned int sparc_leon_eirq;
19162306a36Sopenharmony_ci
19262306a36Sopenharmony_ci#endif /* __ASSEMBLY__ */
19362306a36Sopenharmony_ci
19462306a36Sopenharmony_ci#define LEON3_IO_AREA 0xfff00000
19562306a36Sopenharmony_ci#define LEON3_CONF_AREA 0xff000
19662306a36Sopenharmony_ci#define LEON3_AHB_SLAVE_CONF_AREA (1 << 11)
19762306a36Sopenharmony_ci
19862306a36Sopenharmony_ci#define LEON3_AHB_CONF_WORDS 8
19962306a36Sopenharmony_ci#define LEON3_APB_CONF_WORDS 2
20062306a36Sopenharmony_ci#define LEON3_AHB_MASTERS 16
20162306a36Sopenharmony_ci#define LEON3_AHB_SLAVES 16
20262306a36Sopenharmony_ci#define LEON3_APB_SLAVES 16
20362306a36Sopenharmony_ci#define LEON3_APBUARTS 8
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_ci/* Vendor codes */
20662306a36Sopenharmony_ci#define VENDOR_GAISLER   1
20762306a36Sopenharmony_ci#define VENDOR_PENDER    2
20862306a36Sopenharmony_ci#define VENDOR_ESA       4
20962306a36Sopenharmony_ci#define VENDOR_OPENCORES 8
21062306a36Sopenharmony_ci
21162306a36Sopenharmony_ci/* Gaisler Research device id's */
21262306a36Sopenharmony_ci#define GAISLER_LEON3    0x003
21362306a36Sopenharmony_ci#define GAISLER_LEON3DSU 0x004
21462306a36Sopenharmony_ci#define GAISLER_ETHAHB   0x005
21562306a36Sopenharmony_ci#define GAISLER_APBMST   0x006
21662306a36Sopenharmony_ci#define GAISLER_AHBUART  0x007
21762306a36Sopenharmony_ci#define GAISLER_SRCTRL   0x008
21862306a36Sopenharmony_ci#define GAISLER_SDCTRL   0x009
21962306a36Sopenharmony_ci#define GAISLER_APBUART  0x00C
22062306a36Sopenharmony_ci#define GAISLER_IRQMP    0x00D
22162306a36Sopenharmony_ci#define GAISLER_AHBRAM   0x00E
22262306a36Sopenharmony_ci#define GAISLER_GPTIMER  0x011
22362306a36Sopenharmony_ci#define GAISLER_PCITRG   0x012
22462306a36Sopenharmony_ci#define GAISLER_PCISBRG  0x013
22562306a36Sopenharmony_ci#define GAISLER_PCIFBRG  0x014
22662306a36Sopenharmony_ci#define GAISLER_PCITRACE 0x015
22762306a36Sopenharmony_ci#define GAISLER_PCIDMA   0x016
22862306a36Sopenharmony_ci#define GAISLER_AHBTRACE 0x017
22962306a36Sopenharmony_ci#define GAISLER_ETHDSU   0x018
23062306a36Sopenharmony_ci#define GAISLER_PIOPORT  0x01A
23162306a36Sopenharmony_ci#define GAISLER_GRGPIO   0x01A
23262306a36Sopenharmony_ci#define GAISLER_AHBJTAG  0x01c
23362306a36Sopenharmony_ci#define GAISLER_ETHMAC   0x01D
23462306a36Sopenharmony_ci#define GAISLER_AHB2AHB  0x020
23562306a36Sopenharmony_ci#define GAISLER_USBDC    0x021
23662306a36Sopenharmony_ci#define GAISLER_ATACTRL  0x024
23762306a36Sopenharmony_ci#define GAISLER_DDRSPA   0x025
23862306a36Sopenharmony_ci#define GAISLER_USBEHC   0x026
23962306a36Sopenharmony_ci#define GAISLER_USBUHC   0x027
24062306a36Sopenharmony_ci#define GAISLER_I2CMST   0x028
24162306a36Sopenharmony_ci#define GAISLER_SPICTRL  0x02D
24262306a36Sopenharmony_ci#define GAISLER_DDR2SPA  0x02E
24362306a36Sopenharmony_ci#define GAISLER_SPIMCTRL 0x045
24462306a36Sopenharmony_ci#define GAISLER_LEON4    0x048
24562306a36Sopenharmony_ci#define GAISLER_LEON4DSU 0x049
24662306a36Sopenharmony_ci#define GAISLER_AHBSTAT  0x052
24762306a36Sopenharmony_ci#define GAISLER_FTMCTRL  0x054
24862306a36Sopenharmony_ci#define GAISLER_KBD      0x060
24962306a36Sopenharmony_ci#define GAISLER_VGA      0x061
25062306a36Sopenharmony_ci#define GAISLER_SVGA     0x063
25162306a36Sopenharmony_ci#define GAISLER_GRSYSMON 0x066
25262306a36Sopenharmony_ci#define GAISLER_GRACECTRL 0x067
25362306a36Sopenharmony_ci
25462306a36Sopenharmony_ci#define GAISLER_L2TIME   0xffd	/* internal device: leon2 timer */
25562306a36Sopenharmony_ci#define GAISLER_L2C      0xffe	/* internal device: leon2compat */
25662306a36Sopenharmony_ci#define GAISLER_PLUGPLAY 0xfff	/* internal device: plug & play configarea */
25762306a36Sopenharmony_ci
25862306a36Sopenharmony_ci/* Chip IDs */
25962306a36Sopenharmony_ci#define AEROFLEX_UT699    0x0699
26062306a36Sopenharmony_ci#define LEON4_NEXTREME1   0x0102
26162306a36Sopenharmony_ci#define GAISLER_GR712RC   0x0712
26262306a36Sopenharmony_ci
26362306a36Sopenharmony_ci#define amba_vendor(x) (((x) >> 24) & 0xff)
26462306a36Sopenharmony_ci
26562306a36Sopenharmony_ci#define amba_device(x) (((x) >> 12) & 0xfff)
26662306a36Sopenharmony_ci
26762306a36Sopenharmony_ci#endif
268