forked from Icenowy/xradio
-
Notifications
You must be signed in to change notification settings - Fork 50
/
hwio.h
229 lines (200 loc) · 8.06 KB
/
hwio.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
* hardware interfaces for XRadio drivers
*
* Copyright (c) 2013, XRadio
* Author: XRadio
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#ifndef XRADIO_HWIO_H_INCLUDED
#define XRADIO_HWIO_H_INCLUDED
/* extern */ struct xradio_common;
/* DPLL initial values */
#define DPLL_INIT_VAL_XRADIO (0x0EC4F121)
/* Hardware Type Definitions */
#define HIF_HW_TYPE_XRADIO (1)
/* boot loader start address in SRAM */
#define DOWNLOAD_BOOT_LOADER_OFFSET (0x00000000)
/* 32K, 0x4000 to 0xDFFF */
#define DOWNLOAD_FIFO_OFFSET (0x00004000)
/* 32K */
#define DOWNLOAD_FIFO_SIZE (0x00008000)
/* 128 bytes, 0xFF80 to 0xFFFF */
#define DOWNLOAD_CTRL_OFFSET (0x0000FF80)
#define DOWNLOAD_CTRL_DATA_DWORDS (32-6)
/* Download control area */
struct download_cntl_t {
/* size of whole firmware file (including Cheksum), host init */
u32 ImageSize;
/* downloading flags */
u32 Flags;
/* No. of bytes put into the download, init & updated by host */
u32 Put;
/* last traced program counter, last ARM reg_pc */
u32 TracePc;
/* No. of bytes read from the download, host init, device updates */
u32 Get;
/* r0, boot losader status, host init to pending, device updates */
u32 Status;
/* Extra debug info, r1 to r14 if status=r0=DOWNLOAD_EXCEPTION */
u32 DebugData[DOWNLOAD_CTRL_DATA_DWORDS];
};
#define DOWNLOAD_IMAGE_SIZE_REG \
(DOWNLOAD_CTRL_OFFSET + offsetof(struct download_cntl_t, ImageSize))
#define DOWNLOAD_FLAGS_REG \
(DOWNLOAD_CTRL_OFFSET + offsetof(struct download_cntl_t, Flags))
#define DOWNLOAD_PUT_REG \
(DOWNLOAD_CTRL_OFFSET + offsetof(struct download_cntl_t, Put))
#define DOWNLOAD_TRACE_PC_REG \
(DOWNLOAD_CTRL_OFFSET + offsetof(struct download_cntl_t, TracePc))
#define DOWNLOAD_GET_REG \
(DOWNLOAD_CTRL_OFFSET + offsetof(struct download_cntl_t, Get))
#define DOWNLOAD_STATUS_REG \
(DOWNLOAD_CTRL_OFFSET + offsetof(struct download_cntl_t, Status))
#define DOWNLOAD_DEBUG_DATA_REG \
(DOWNLOAD_CTRL_OFFSET + offsetof(struct download_cntl_t, DebugData))
#define DOWNLOAD_DEBUG_DATA_LEN (108)
#define DOWNLOAD_BLOCK_SIZE (1024)
/* For boot loader detection */
#define DOWNLOAD_ARE_YOU_HERE (0x87654321)
#define DOWNLOAD_I_AM_HERE (0x12345678)
/* Download error code */
#define DOWNLOAD_PENDING (0xFFFFFFFF)
#define DOWNLOAD_SUCCESS (0)
#define DOWNLOAD_EXCEPTION (1)
#define DOWNLOAD_ERR_MEM_1 (2)
#define DOWNLOAD_ERR_MEM_2 (3)
#define DOWNLOAD_ERR_SOFTWARE (4)
#define DOWNLOAD_ERR_FILE_SIZE (5)
#define DOWNLOAD_ERR_CHECKSUM (6)
#define DOWNLOAD_ERR_OVERFLOW (7)
#define DOWNLOAD_ERR_IMAGE (8)
#define DOWNLOAD_ERR_HOST (9)
#define DOWNLOAD_ERR_ABORT (10)
#define SYS_BASE_ADDR_SILICON (0)
#define AHB_MEMORY_ADDRESS (SYS_BASE_ADDR_SILICON + 0x08000000)
#define PAC_BASE_ADDRESS_SILICON (SYS_BASE_ADDR_SILICON + 0x09000000)
#define PAC_SHARED_MEMORY_SILICON (PAC_BASE_ADDRESS_SILICON)
#define APB_ADDR(addr) (PAC_SHARED_MEMORY_SILICON + (addr))
/* ***************************************************************
*Device register definitions
*************************************************************** */
/* WBF - SPI Register Addresses */
#define HIF_ADDR_ID_BASE (0x0000)
/* 16/32 bits */
#define HIF_CONFIG_REG_ID (0x0000)
/* 16/32 bits */
#define HIF_CONTROL_REG_ID (0x0001)
/* 16 bits, Q mode W/R */
#define HIF_IN_OUT_QUEUE_REG_ID (0x0002)
/* 32 bits, AHB bus R/W */
#define HIF_AHB_DPORT_REG_ID (0x0003)
/* 16/32 bits */
#define HIF_SRAM_BASE_ADDR_REG_ID (0x0004)
/* 32 bits, APB bus R/W */
#define HIF_SRAM_DPORT_REG_ID (0x0005)
/* 32 bits, t_settle/general */
#define HIF_TSET_GEN_R_W_REG_ID (0x0006)
/* 16 bits, Q mode read, no length */
#define HIF_FRAME_OUT_REG_ID (0x0007)
#define HIF_ADDR_ID_MAX (HIF_FRAME_OUT_REG_ID)
/* WBF - Control register bit set */
/* next o/p length, bit 11 to 0 */
#define HIF_CTRL_NEXT_LEN_MASK (0x0FFF)
#define HIF_CTRL_WUP_BIT (BIT(12))
#define HIF_CTRL_RDY_BIT (BIT(13))
#define HIF_CTRL_IRQ_ENABLE (BIT(14))
#define HIF_CTRL_RDY_ENABLE (BIT(15))
#define HIF_CTRL_IRQ_RDY_ENABLE (BIT(14)|BIT(15))
/* SPI Config register bit set */
#define HIF_CONFIG_FRAME_BIT (BIT(2))
#define HIF_CONFIG_WORD_MODE_BITS (BIT(3)|BIT(4))
#define HIF_CONFIG_WORD_MODE_1 (BIT(3))
#define HIF_CONFIG_WORD_MODE_2 (BIT(4))
#define HIF_CONFIG_ERROR_0_BIT (BIT(5))
#define HIF_CONFIG_ERROR_1_BIT (BIT(6))
#define HIF_CONFIG_ERROR_2_BIT (BIT(7))
/* TBD: Sure??? */
#define HIF_CONFIG_CSN_FRAME_BIT (BIT(7))
#define HIF_CONFIG_ERROR_3_BIT (BIT(8))
#define HIF_CONFIG_ERROR_4_BIT (BIT(9))
/* QueueM */
#define HIF_CONFIG_ACCESS_MODE_BIT (BIT(10))
/* AHB bus */
#define HIF_CONFIG_AHB_PFETCH_BIT (BIT(11))
#define HIF_CONFIG_CPU_CLK_DIS_BIT (BIT(12))
/* APB bus */
#define HIF_CONFIG_PFETCH_BIT (BIT(13))
/* cpu reset */
#define HIF_CONFIG_CPU_RESET_BIT (BIT(14))
#define HIF_CONFIG_CLEAR_INT_BIT (BIT(15))
/* For XRADIO the IRQ Enable and Ready Bits are in CONFIG register */
#define HIF_CONF_IRQ_RDY_ENABLE (BIT(16)|BIT(17))
int xradio_data_read(struct xradio_common *hw_priv, void *buf, size_t buf_len);
int xradio_data_write(struct xradio_common *hw_priv, const void *buf, size_t buf_len);
int xradio_reg_read(struct xradio_common *hw_priv, u16 addr, void *buf, size_t buf_len);
int xradio_reg_write(struct xradio_common *hw_priv, u16 addr, const void *buf, size_t buf_len);
int xradio_indirect_read(struct xradio_common *hw_priv, u32 addr, void *buf,
size_t buf_len, u32 prefetch, u16 port_addr);
int xradio_apb_write(struct xradio_common *hw_priv, u32 addr, const void *buf, size_t buf_len);
int xradio_ahb_write(struct xradio_common *hw_priv, u32 addr, const void *buf, size_t buf_len);
static inline int xradio_reg_read_16(struct xradio_common *hw_priv,
u16 addr, u16 *val)
{
int ret = 0;
u32 bigVal = 0;
ret = xradio_reg_read(hw_priv, addr, &bigVal, sizeof(bigVal));
*val = (u16)bigVal;
return ret;
}
static inline int xradio_reg_write_16(struct xradio_common *hw_priv,
u16 addr, u16 val)
{
u32 bigVal = (u32)val;
return xradio_reg_write(hw_priv, addr, &bigVal, sizeof(bigVal));
}
static inline int xradio_reg_read_32(struct xradio_common *hw_priv,
u16 addr, u32 *val)
{
return xradio_reg_read(hw_priv, addr, val, sizeof(val));
}
static inline int xradio_reg_write_32(struct xradio_common *hw_priv,
u16 addr, u32 val)
{
return xradio_reg_write(hw_priv, addr, &val, sizeof(val));
}
static inline int xradio_apb_read(struct xradio_common *hw_priv, u32 addr,
void *buf, size_t buf_len)
{
return xradio_indirect_read(hw_priv, addr, buf, buf_len, HIF_CONFIG_PFETCH_BIT,
HIF_SRAM_DPORT_REG_ID);
}
static inline int xradio_ahb_read(struct xradio_common *hw_priv, u32 addr,
void *buf, size_t buf_len)
{
return xradio_indirect_read(hw_priv, addr, buf, buf_len, HIF_CONFIG_AHB_PFETCH_BIT,
HIF_AHB_DPORT_REG_ID);
}
static inline int xradio_apb_read_32(struct xradio_common *hw_priv,
u32 addr, u32 *val)
{
return xradio_apb_read(hw_priv, addr, val, sizeof(val));
}
static inline int xradio_apb_write_32(struct xradio_common *hw_priv,
u32 addr, u32 val)
{
return xradio_apb_write(hw_priv, addr, &val, sizeof(val));
}
static inline int xradio_ahb_read_32(struct xradio_common *hw_priv,
u32 addr, u32 *val)
{
return xradio_ahb_read(hw_priv, addr, val, sizeof(val));
}
static inline int xradio_ahb_write_32(struct xradio_common *hw_priv,
u32 addr, u32 val)
{
return xradio_ahb_write(hw_priv, addr, &val, sizeof(val));
}
#endif /* XRADIO_HWIO_H_INCLUDED */