summaryrefslogtreecommitdiff
path: root/arch/arm/mach-tegra/nvrm/io/ap15/ap15rm_dma_hw_private.c
blob: 7346d84d53fc59f3048095c5d645724b9da56514 (plain)
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/*
 * Copyright (c) 2007-2009 NVIDIA Corporation.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * Neither the name of the NVIDIA Corporation nor the names of its contributors
 * may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */

/** 
 * @file
 * @brief <b>nVIDIA Driver Development Kit: 
 *           DMA Resource manager private API for Hw access </b>
 *
 * @b Description: Implements the private interface of the nnvrm dma to access
 * the hw apb/ahb dma register.
 *
 * This files implements the API for accessing the register of the Dma 
 * controller and configure the dma transfers for Ap15.
 */

#include "nvrm_dma.h"
#include "rm_dma_hw_private.h"
#include "ap20/arapbdma.h"
#include "ap20/arapbdmachan.h"
#include "nvrm_drf.h"
#include "nvassert.h"
#include "nvrm_hardware_access.h"

#define APBDMACHAN_READ32(pVirtBaseAdd, reg) \
        NV_READ32((pVirtBaseAdd) + ((APBDMACHAN_CHANNEL_0_##reg##_0)/4))
#define APBDMACHAN_WRITE32(pVirtBaseAdd, reg, val) \
    do { \
        NV_WRITE32(((pVirtBaseAdd) + ((APBDMACHAN_CHANNEL_0_##reg##_0)/4)), (val)); \
    } while(0)

static const NvU32 s_I2s_Trigger[] = {
        APBDMACHAN_CHANNEL_0_CSR_0_REQ_SEL_I2S_1,
        APBDMACHAN_CHANNEL_0_CSR_0_REQ_SEL_I2S2_1,
};

static const NvU32 s_Uart_Trigger[] = {
        APBDMACHAN_CHANNEL_0_CSR_0_REQ_SEL_UART_A,
        APBDMACHAN_CHANNEL_0_CSR_0_REQ_SEL_UART_B,
        APBDMACHAN_CHANNEL_0_CSR_0_REQ_SEL_UART_C,
        APBDMACHAN_CHANNEL_0_CSR_0_REQ_SEL_UART_D,
        APBDMACHAN_CHANNEL_0_CSR_0_REQ_SEL_UART_E
};

static const NvU32 s_Slink_Trigger[] = {
        APBDMACHAN_CHANNEL_0_CSR_0_REQ_SEL_SL2B1,
        APBDMACHAN_CHANNEL_0_CSR_0_REQ_SEL_SL2B2,
        APBDMACHAN_CHANNEL_0_CSR_0_REQ_SEL_SL2B3,
        APBDMACHAN_CHANNEL_0_CSR_0_REQ_SEL_SL2B4,
};

static const NvU32 s_I2c_Trigger[] = {
        APBDMACHAN_CHANNEL_0_CSR_0_REQ_SEL_I2C,
        APBDMACHAN_CHANNEL_0_CSR_0_REQ_SEL_I2C2,
        APBDMACHAN_CHANNEL_0_CSR_0_REQ_SEL_I2C3,
};

static void
ConfigureDmaRequestor(
    DmaChanRegisters *pDmaChRegs,
    NvRmDmaModuleID DmaReqModuleId,
    NvU32 DmaReqInstId)
{
    // Check for the dma module Id and based on the dma module Id, decide
    // the trigger requestor source.
    switch (DmaReqModuleId)
    {
        /// Specifies the dma module Id for memory
        case NvRmDmaModuleID_Memory:
            // Dma transfer will be from memory to memory.
            // Use the reset value only for the ahb data transfer.
            break;


        case NvRmDmaModuleID_I2s:
            // Dma requestor is the I2s controller.
            NV_ASSERT(DmaReqInstId < NV_ARRAY_SIZE(s_I2s_Trigger));
            pDmaChRegs->ControlReg = NV_FLD_SET_DRF_NUM(APBDMACHAN_CHANNEL_0,
                                     CSR, REQ_SEL, s_I2s_Trigger[DmaReqInstId],
                                     pDmaChRegs->ControlReg);
            pDmaChRegs->ControlReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0,
                                            CSR, FLOW, ENABLE, pDmaChRegs->ControlReg);
            pDmaChRegs->ApbSequenceReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0,
                                            APB_SEQ, APB_BUS_WIDTH, BUS_WIDTH_32,
                                            pDmaChRegs->ApbSequenceReg);
            break;

        case NvRmDmaModuleID_Uart:
            // Dma requestor is the uart.
            NV_ASSERT(DmaReqInstId < NV_ARRAY_SIZE(s_Uart_Trigger));
            pDmaChRegs->ControlReg = NV_FLD_SET_DRF_NUM(APBDMACHAN_CHANNEL_0,
                                     CSR, REQ_SEL, s_Uart_Trigger[DmaReqInstId],
                                     pDmaChRegs->ControlReg);
            pDmaChRegs->ControlReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, 
                                        CSR, FLOW, ENABLE, pDmaChRegs->ControlReg);
            pDmaChRegs->ApbSequenceReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, 
                                        APB_SEQ, APB_BUS_WIDTH, BUS_WIDTH_8,
                                        pDmaChRegs->ApbSequenceReg);
            break;

        case NvRmDmaModuleID_Vfir:
            // Dma requestor is the vfir.
            NV_ASSERT(DmaReqInstId < 1);
            pDmaChRegs->ControlReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0,
                                            CSR, REQ_SEL, UART_B, pDmaChRegs->ControlReg);
            pDmaChRegs->ControlReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, 
                                            CSR, FLOW, ENABLE, pDmaChRegs->ControlReg);
            pDmaChRegs->ApbSequenceReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, 
                                            APB_SEQ, APB_BUS_WIDTH, BUS_WIDTH_32,
                                            pDmaChRegs->ApbSequenceReg);
            break;

        case NvRmDmaModuleID_Mipi:
            // Dma requestor is the Mipi controller.
            NV_ASSERT(DmaReqInstId < 1);
            pDmaChRegs->ControlReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, 
                                            CSR, REQ_SEL, MIPI, pDmaChRegs->ControlReg);
            pDmaChRegs->ControlReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, 
                                            CSR, FLOW, ENABLE, pDmaChRegs->ControlReg);
            pDmaChRegs->ApbSequenceReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, 
                                            APB_SEQ, APB_BUS_WIDTH, BUS_WIDTH_32,
                                            pDmaChRegs->ApbSequenceReg);
            break;

        case NvRmDmaModuleID_Spi:
            // Dma requestor is the Spi controller.
            NV_ASSERT(DmaReqInstId < 1);
            pDmaChRegs->ControlReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, 
                                            CSR, REQ_SEL, SPI, pDmaChRegs->ControlReg);
            pDmaChRegs->ControlReg = NV_FLD_SET_DRF_NUM(APBDMACHAN_CHANNEL_0, 
                                            CSR, TRIG_SEL, 0, pDmaChRegs->ControlReg);
            pDmaChRegs->ControlReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, 
                                            CSR, FLOW, ENABLE, pDmaChRegs->ControlReg);
            pDmaChRegs->ApbSequenceReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, 
                                            APB_SEQ, APB_BUS_WIDTH, BUS_WIDTH_32,
                                            pDmaChRegs->ApbSequenceReg);
            break;

        case NvRmDmaModuleID_Slink:
            // Dma requestor is the Slink controller.
            NV_ASSERT(DmaReqInstId < NV_ARRAY_SIZE(s_Slink_Trigger));
            pDmaChRegs->ControlReg = NV_FLD_SET_DRF_NUM(APBDMACHAN_CHANNEL_0,
                                     CSR, REQ_SEL, s_Slink_Trigger[DmaReqInstId],
                                     pDmaChRegs->ControlReg);
            
            pDmaChRegs->ControlReg = NV_FLD_SET_DRF_NUM(APBDMACHAN_CHANNEL_0, 
                                            CSR, TRIG_SEL, 0, pDmaChRegs->ControlReg);
            pDmaChRegs->ControlReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, 
                                            CSR, FLOW, ENABLE, pDmaChRegs->ControlReg);
            pDmaChRegs->ApbSequenceReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, 
                                            APB_SEQ, APB_BUS_WIDTH, BUS_WIDTH_32,
                                            pDmaChRegs->ApbSequenceReg);
            break;

        case NvRmDmaModuleID_Spdif:
            // Dma requestor is the Spdif controller.
            NV_ASSERT(DmaReqInstId < 1);
            pDmaChRegs->ControlReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, 
                                            CSR, REQ_SEL, SPD_I, pDmaChRegs->ControlReg);
            pDmaChRegs->ControlReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, 
                                            CSR, FLOW, ENABLE, pDmaChRegs->ControlReg);
            pDmaChRegs->ApbSequenceReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, 
                                            APB_SEQ, APB_BUS_WIDTH, BUS_WIDTH_32,
                                            pDmaChRegs->ApbSequenceReg);
            break;

        case NvRmDmaModuleID_I2c:
            // Dma requestor is the I2c controller.
            NV_ASSERT(DmaReqInstId < NV_ARRAY_SIZE(s_I2c_Trigger));
            pDmaChRegs->ControlReg = NV_FLD_SET_DRF_NUM(APBDMACHAN_CHANNEL_0,
                                     CSR, REQ_SEL, s_I2c_Trigger[DmaReqInstId],
                                     pDmaChRegs->ControlReg);

            pDmaChRegs->ControlReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, 
                                            CSR, FLOW, ENABLE, pDmaChRegs->ControlReg);
            pDmaChRegs->ApbSequenceReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, 
                                            APB_SEQ, APB_BUS_WIDTH, BUS_WIDTH_32,
                                            pDmaChRegs->ApbSequenceReg);
            break;
        
        case NvRmDmaModuleID_Dvc:
            // Dma requestor is the I2c controller.
            NV_ASSERT(DmaReqInstId < 1);
            pDmaChRegs->ControlReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, 
                                            CSR, REQ_SEL, DVC_I2C, pDmaChRegs->ControlReg);
            pDmaChRegs->ControlReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, 
                                            CSR, FLOW, ENABLE, pDmaChRegs->ControlReg);
            pDmaChRegs->ApbSequenceReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, 
                                            APB_SEQ, APB_BUS_WIDTH, BUS_WIDTH_32,
                                            pDmaChRegs->ApbSequenceReg);
            break;


        default:
            NV_ASSERT(!"Invalid module");
    }
}

/**
 * Configure the Apb dma register as per clients information.
 * This function do the register setting based on device Id and will  be stored
 * in the dma handle. This information will be used when there is dma transfer
 * request and want to configure the dma controller registers.
 */
static void 
InitApbDmaRegisters(
    DmaChanRegisters *pDmaChRegs,
    NvRmDmaModuleID DmaReqModuleId,
    NvU32 DmaReqInstId)
{
    pDmaChRegs->pHwDmaChanReg = NULL;

    //  Set the dma register of dma handle to their power on reset values.
    pDmaChRegs->ControlReg = NV_RESETVAL(APBDMACHAN_CHANNEL_0, CSR);
    pDmaChRegs->AhbSequenceReg = NV_RESETVAL(APBDMACHAN_CHANNEL_0, AHB_SEQ);
    pDmaChRegs->ApbSequenceReg = NV_RESETVAL(APBDMACHAN_CHANNEL_0,APB_SEQ);

    // Configure the dma register for the OnceMode
    pDmaChRegs->ControlReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, CSR, 
                                ONCE, SINGLE_BLOCK, pDmaChRegs->ControlReg);

    // Configure the dma register for  enabling the interrupt so that it will generate the interrupt
    // after transfer completes.
    pDmaChRegs->ControlReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, CSR, 
                                IE_EOC, ENABLE, pDmaChRegs->ControlReg);

    // Configure the dma register for  interrupting the cpu only.
    pDmaChRegs->AhbSequenceReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, 
                                AHB_SEQ, INTR_ENB, CPU, pDmaChRegs->AhbSequenceReg);

    // Configure the dma registers as per requestor information.
    ConfigureDmaRequestor(pDmaChRegs, DmaReqModuleId, DmaReqInstId);
}

/**
 * Set the data transfer mode for the dma transfer.
 */
static void 
SetApbDmaTransferMode(
    DmaChanRegisters *pDmaChRegs,
    NvBool IsContinuousMode,
    NvBool IsDoubleBuffMode)
{
    // Configure the dma register for the Continuous Mode
    if (IsContinuousMode)
        pDmaChRegs->ControlReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, 
                                    CSR, ONCE, MULTIPLE_BLOCK, pDmaChRegs->ControlReg);
    else
        pDmaChRegs->ControlReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, 
                                    CSR, ONCE, SINGLE_BLOCK, pDmaChRegs->ControlReg);

    // Configure the dma register for the double buffering Mode
    if (IsDoubleBuffMode)
        pDmaChRegs->AhbSequenceReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, 
                                    AHB_SEQ, DBL_BUF, RELOAD_FOR_2X_BLOCKS, 
                                    pDmaChRegs->AhbSequenceReg);
    else
        pDmaChRegs->AhbSequenceReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0, 
                                    AHB_SEQ, DBL_BUF, RELOAD_FOR_1X_BLOCKS, 
                                    pDmaChRegs->AhbSequenceReg);
}

/**
 * Set the Apb dma direction of data transfer.
 */
static void 
SetApbDmaDirection(
    DmaChanRegisters *pDmaChRegs,
    NvBool IsSourceAddPerType)
{
    if (IsSourceAddPerType)
        pDmaChRegs->ControlReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0,
                                    CSR, DIR, AHB_WRITE, pDmaChRegs->ControlReg);
    else
        pDmaChRegs->ControlReg = NV_FLD_SET_DRF_DEF(APBDMACHAN_CHANNEL_0,
                                    CSR, DIR, AHB_READ, pDmaChRegs->ControlReg);
}

void NvRmPrivDmaInitAp15DmaHwInterfaces(DmaHwInterface *pApbDmaInterface)
{

    pApbDmaInterface->DmaHwInitRegistersFxn = InitApbDmaRegisters;
    pApbDmaInterface->DmaHwSetTransferModeFxn = SetApbDmaTransferMode;
    pApbDmaInterface->DmaHwSetDirectionFxn = SetApbDmaDirection;
}