-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdm845v2.c
259 lines (187 loc) · 7.35 KB
/
sdm845v2.c
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
Module Name:
sdm845v2.c
Abstract:
This module contains support for the Qualcomm SDM 845 serial UART with
adjusted baud rate divider settings.
--*/
#include "common.h"
#include "sdm845.h"
BOOLEAN
SDM845v2SetBaud (
_Inout_ PCPPORT Port,
ULONG Rate
)
/*++
Routine Description:
Set the baud rate for the UART hardware and record it in the port object.
Arguments:
Port - Supplies the address of the port object that describes the UART.
Rate - Supplies the desired baud rate in bits per second.
Return Value:
TRUE if the baud rate was programmed, FALSE if it was not.
--*/
{
UINT32 DivisorLatch = 0;
UINT32 ValueTempMask = 0;
if ((Port == NULL) || (Port->Address == NULL)) {
return FALSE;
}
DivisorLatch = UART_DM_READ_REG(Port->Address + GENI4_CFG,
HWIO_GENI_SER_M_CLK_CFG_OFFS);
if (DivisorLatch == 0x11) {
return FALSE;
}
//
// Clock rate is 7.372 mhz.
//
switch (Rate) {
case 7200:
DivisorLatch = 0x40;
break;
case 9600:
DivisorLatch = 0x30;
break;
case 14400:
DivisorLatch = 0x20;
break;
case 19200:
DivisorLatch = 0x18;
break;
case 28800:
DivisorLatch = 0x10;
break;
case 38400:
DivisorLatch = 0xC;
break;
case 57600:
DivisorLatch = 0x8;
break;
case 115200:
DivisorLatch = 0x4;
break;
default:
DivisorLatch = 0x1;
break;
}
ValueTempMask = (DivisorLatch << (HWIO_GENI_SER_M_CLK_CFG_CLK_DIV_VALUE_SHFT)) |
HWIO_GENI_SER_M_CLK_CFG_SER_CLK_EN_BMSK;
UART_DM_WRITE_REG(Port->Address + GENI4_CFG,
HWIO_GENI_SER_M_CLK_CFG_OFFS,
ValueTempMask);
UART_DM_WRITE_REG(Port->Address + GENI4_CFG,
HWIO_GENI_SER_S_CLK_CFG_OFFS,
ValueTempMask);
Port->BaudRate = Rate;
return TRUE;
}
BOOLEAN
SDM845v2ReinitializePort (
_Inout_ PCPPORT Port
)
/*++
Routine Description:
This routine performs the re-initialization of an SDM845 serial UART.
Arguments:
Port - Supplies a pointer to a CPPORT object which will be filled in as
part of the port initialization.
Return Value:
TRUE if the port has been successfully initialized, FALSE otherwise.
--*/
{
ULONG ConfigMask;
ULONG Retries;
//
// Wait for the state machine to clear up.
//
Retries = 0;
while ((UART_DM_READ_REG(Port->Address + GENI4_CFG, HWIO_GENI_STATUS_OFFS) &
HWIO_GENI_STATUS_M_GENI_CMD_ACTIVE_BMSK)) {
Retries += 1;
if (Retries >= MAX_RETRIES) {
return FALSE;
}
}
UART_DM_WRITE_REG(Port->Address + GENI4_CFG, HWIO_GENI_DFS_IF_CFG_OFFS, 0x0);
ConfigMask = (HWIO_DMA_GENERAL_CFG_AHB_SEC_SLV_CLK_CGC_ON_BMSK << HWIO_DMA_GENERAL_CFG_AHB_SEC_SLV_CLK_CGC_ON_SHFT) |
(HWIO_DMA_GENERAL_CFG_DMA_AHB_SLV_CLK_CGC_ON_BMSK << HWIO_DMA_GENERAL_CFG_DMA_AHB_SLV_CLK_CGC_ON_SHFT) |
(HWIO_DMA_GENERAL_CFG_DMA_TX_CLK_CGC_ON_BMSK << HWIO_DMA_GENERAL_CFG_DMA_TX_CLK_CGC_ON_SHFT) |
(HWIO_DMA_GENERAL_CFG_DMA_RX_CLK_CGC_ON_BMSK << HWIO_DMA_GENERAL_CFG_DMA_RX_CLK_CGC_ON_SHFT);
UART_DM_WRITE_REG(Port->Address + QUPV3_SE_DMA, HWIO_DMA_GENERAL_CFG_OFFS, ConfigMask);
UART_DM_WRITE_REG(Port->Address + GENI4_CFG, HWIO_GENI_CGC_CTRL_OFFS, 0x7F);
UART_DM_WRITE_REG(Port->Address + GENI4_CFG, HWIO_GENI_FORCE_DEFAULT_REG_OFFS, 0x1);
UART_DM_WRITE_REG(Port->Address + GENI4_CFG, HWIO_GENI_OUTPUT_CTRL_OFFS, 0x7F);
UART_DM_WRITE_REG(Port->Address + GENI4_IMAGE_REGS, HWIO_GENI_DMA_MODE_EN_OFFS, 0);
UART_DM_WRITE_REG(Port->Address + QUPV3_SE_DMA, HWIO_SE_IRQ_EN_OFFS, 0xFFFFFFFF);
UART_DM_WRITE_REG(Port->Address + QUPV3_SE_DMA, HWIO_SE_GSI_EVENT_EN_OFFS, 0);
UART_DM_WRITE_REG(Port->Address + GENI4_DATA, HWIO_GENI_M_IRQ_ENABLE_OFFS, 0xB300005F);
UART_DM_WRITE_REG(Port->Address + GENI4_DATA, HWIO_GENI_S_IRQ_ENABLE_OFFS, 0xB3007E5F);
//
// Get TX FIFO width.
//
ConfigMask = UART_DM_READ_REG(Port->Address + QUPV3_SE_DMA, HWIO_SE_HW_PARAM_0_OFFS);
ConfigMask = (ConfigMask & TX_FIFO_DEPTH_MASK) >> TX_FIFO_DEPTH_SHIFT;
UART_DM_WRITE_REG(Port->Address + GENI4_DATA, HWIO_GENI_TX_WATERMARK_REG_OFFS, 4);
//
// Get RX FIFO width.
//
ConfigMask = UART_DM_READ_REG(Port->Address + QUPV3_SE_DMA, HWIO_SE_HW_PARAM_1_OFFS);
ConfigMask = (ConfigMask & RX_FIFO_DEPTH_MASK) >> RX_FIFO_DEPTH_SHIFT;
UART_DM_WRITE_REG(Port->Address + GENI4_DATA, HWIO_GENI_RX_WATERMARK_REG_OFFS, (ConfigMask - 8));
UART_DM_WRITE_REG(Port->Address + GENI4_DATA, HWIO_GENI_RX_RFR_WATERMARK_REG_OFFS, (ConfigMask - 4));
SDM845v2SetBaud(Port, Port->BaudRate);
UART_DM_WRITE_REG(Port->Address + GENI4_IMAGE_REGS, HWIO_UART_TX_WORD_LEN_OFFS, 0x8);
UART_DM_WRITE_REG(Port->Address + GENI4_IMAGE_REGS, HWIO_UART_RX_WORD_LEN_OFFS, 0x8);
UART_DM_WRITE_REG(Port->Address + GENI4_IMAGE_REGS, HWIO_UART_TX_PARITY_CFG_OFFS, 0x0);
UART_DM_WRITE_REG(Port->Address + GENI4_IMAGE_REGS, HWIO_UART_TX_TRANS_CFG_OFFS, 0x2);
UART_DM_WRITE_REG(Port->Address + GENI4_IMAGE_REGS, HWIO_UART_RX_PARITY_CFG_OFFS, 0x0);
UART_DM_WRITE_REG(Port->Address + GENI4_IMAGE_REGS, HWIO_UART_RX_TRANS_CFG_OFFS, 0x0);
UART_DM_WRITE_REG(Port->Address + GENI4_IMAGE_REGS, HWIO_UART_TX_STOP_BIT_LEN_OFFS, 0x0);
UART_DM_WRITE_REG(Port->Address + GENI4_IMAGE_REGS, HWIO_UART_RX_STALE_CNT_OFFS, (0x16 * 10));
UART_DM_WRITE_REG(Port->Address + GENI4_DATA, HWIO_GENI_S_CMD0_OFFS, 0x8000000);
return TRUE;
}
BOOLEAN
SDM845v2InitializePort (
_In_opt_ _Null_terminated_ PCHAR LoadOptions,
_Inout_ PCPPORT Port,
BOOLEAN MemoryMapped,
UCHAR AccessSize,
UCHAR BitWidth
)
/*++
Routine Description:
This routine performs the initialization of an SDM845 serial UART.
Arguments:
LoadOptions - Optional load option string. Currently unused.
Port - Supplies a pointer to a CPPORT object which will be filled in as
part of the port initialization.
MemoryMapped - Supplies a boolean which indicates if the UART is accessed
through memory-mapped registers or legacy port I/O.
AccessSize - Supplies an ACPI Generic Access Size value which indicates the
type of bus access that should be performed when accessing the UART.
BitWidth - Supplies a number indicating how wide the UART's registers are.
Return Value:
TRUE if the port has been successfully initialized, FALSE otherwise.
--*/
{
UNREFERENCED_PARAMETER(LoadOptions);
UNREFERENCED_PARAMETER(AccessSize);
UNREFERENCED_PARAMETER(BitWidth);
if (MemoryMapped == FALSE) {
return FALSE;
}
Port->Flags = 0;
return SDM845v2ReinitializePort(Port);
}
// -------------------------------------------------------------------- Globals
UART_HARDWARE_DRIVER SDM845v2HardwareDriver = {
SDM845v2InitializePort,
SDM845v2SetBaud,
SDM845GetByte,
SDM845PutByte,
SDM845RxReady,
NULL,
NULL
};