]> git.proxmox.com Git - mirror_edk2.git/blame - Omap35xxPkg/Library/OmapDmaLib/OmapDmaLib.c
Omap35xxPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / Omap35xxPkg / Library / OmapDmaLib / OmapDmaLib.c
CommitLineData
7f814ffd 1/** @file\r
81bc205d 2 Abstractions for simple OMAP DMA channel.\r
3402aac7 3\r
7f814ffd 4\r
5 Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
3402aac7 6\r
538311f7 7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
7f814ffd 8\r
9**/\r
10\r
11#include <Base.h>\r
12#include <Library/DebugLib.h>\r
13#include <Library/OmapDmaLib.h>\r
7f814ffd 14#include <Library/IoLib.h>\r
8e7c9e03 15#include <Library/BaseMemoryLib.h>\r
7f814ffd 16#include <Omap3530/Omap3530.h>\r
17\r
7f814ffd 18\r
3402aac7 19/**\r
7f814ffd 20 Configure OMAP DMA Channel\r
3402aac7 21\r
7f814ffd 22 @param Channel DMA Channel to configure\r
3402aac7
RC
23 @param Dma4 Pointer to structure used to initialize DMA registers for the Channel\r
24\r
7f814ffd 25 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.\r
26 @retval EFI_INVALID_PARAMETER Channel is not valid\r
27 @retval EFI_DEVICE_ERROR The system hardware could not map the requested information.\r
3402aac7 28\r
8e7c9e03 29**/\r
30EFI_STATUS\r
31EFIAPI\r
32EnableDmaChannel (\r
33 IN UINTN Channel,\r
34 IN OMAP_DMA4 *DMA4\r
35 )\r
36{\r
37 UINT32 RegVal;\r
38\r
39\r
40 if (Channel > DMA4_MAX_CHANNEL) {\r
41 return EFI_INVALID_PARAMETER;\r
42 }\r
43\r
7f814ffd 44 /* 1) Configure the transfer parameters in the logical DMA registers */\r
45 /*-------------------------------------------------------------------*/\r
46\r
3402aac7
RC
47 /* a) Set the data type CSDP[1:0], the Read/Write Port access type\r
48 CSDP[8:7]/[15:14], the Source/dest endianism CSDP[21]/CSDP[19],\r
7f814ffd 49 write mode CSDP[17:16], source/dest packed or nonpacked CSDP[6]/CSDP[13] */\r
3402aac7 50\r
7f814ffd 51 // Read CSDP\r
52 RegVal = MmioRead32 (DMA4_CSDP (Channel));\r
3402aac7 53\r
7f814ffd 54 // Build reg\r
55 RegVal = ((RegVal & ~ 0x3) | DMA4->DataType );\r
56 RegVal = ((RegVal & ~(0x3 << 7)) | (DMA4->ReadPortAccessType << 7));\r
57 RegVal = ((RegVal & ~(0x3 << 14)) | (DMA4->WritePortAccessType << 14));\r
58 RegVal = ((RegVal & ~(0x1 << 21)) | (DMA4->SourceEndiansim << 21));\r
59 RegVal = ((RegVal & ~(0x1 << 19)) | (DMA4->DestinationEndianism << 19));\r
60 RegVal = ((RegVal & ~(0x3 << 16)) | (DMA4->WriteMode << 16));\r
61 RegVal = ((RegVal & ~(0x1 << 6)) | (DMA4->SourcePacked << 6));\r
62 RegVal = ((RegVal & ~(0x1 << 13)) | (DMA4->DestinationPacked << 13));\r
63 // Write CSDP\r
64 MmioWrite32 (DMA4_CSDP (Channel), RegVal);\r
3402aac7 65\r
7f814ffd 66 /* b) Set the number of element per frame CEN[23:0]*/\r
67 MmioWrite32 (DMA4_CEN (Channel), DMA4->NumberOfElementPerFrame);\r
3402aac7 68\r
7f814ffd 69 /* c) Set the number of frame per block CFN[15:0]*/\r
70 MmioWrite32 (DMA4_CFN (Channel), DMA4->NumberOfFramePerTransferBlock);\r
3402aac7 71\r
7f814ffd 72 /* d) Set the Source/dest start address index CSSA[31:0]/CDSA[31:0]*/\r
73 MmioWrite32 (DMA4_CSSA (Channel), DMA4->SourceStartAddress);\r
74 MmioWrite32 (DMA4_CDSA (Channel), DMA4->DestinationStartAddress);\r
3402aac7 75\r
7f814ffd 76 /* e) Set the Read Port addressing mode CCR[13:12], the Write Port addressing mode CCR[15:14],\r
77 read/write priority CCR[6]/CCR[26]\r
3402aac7 78 I changed LCH CCR[20:19]=00 and CCR[4:0]=00000 to\r
7f814ffd 79 LCH CCR[20:19]= DMA4->WriteRequestNumber and CCR[4:0]=DMA4->ReadRequestNumber\r
80 */\r
3402aac7 81\r
7f814ffd 82 // Read CCR\r
83 RegVal = MmioRead32 (DMA4_CCR (Channel));\r
84\r
85 // Build reg\r
86 RegVal = ((RegVal & ~0x1f) | DMA4->ReadRequestNumber);\r
87 RegVal = ((RegVal & ~(BIT20 | BIT19)) | DMA4->WriteRequestNumber << 19);\r
88 RegVal = ((RegVal & ~(0x3 << 12)) | (DMA4->ReadPortAccessMode << 12));\r
89 RegVal = ((RegVal & ~(0x3 << 14)) | (DMA4->WritePortAccessMode << 14));\r
90 RegVal = ((RegVal & ~(0x1 << 6)) | (DMA4->ReadPriority << 6));\r
91 RegVal = ((RegVal & ~(0x1 << 26)) | (DMA4->WritePriority << 26));\r
3402aac7 92\r
7f814ffd 93 // Write CCR\r
94 MmioWrite32 (DMA4_CCR (Channel), RegVal);\r
3402aac7 95\r
7f814ffd 96 /* f)- Set the source element index CSEI[15:0]*/\r
97 MmioWrite32 (DMA4_CSEI (Channel), DMA4->SourceElementIndex);\r
3402aac7 98\r
7f814ffd 99 /* - Set the source frame index CSFI[15:0]*/\r
100 MmioWrite32 (DMA4_CSFI (Channel), DMA4->SourceFrameIndex);\r
101\r
102\r
103 /* - Set the destination element index CDEI[15:0]*/\r
104 MmioWrite32 (DMA4_CDEI (Channel), DMA4->DestinationElementIndex);\r
105\r
106 /* - Set the destination frame index CDFI[31:0]*/\r
107 MmioWrite32 (DMA4_CDFI (Channel), DMA4->DestinationFrameIndex);\r
3402aac7 108\r
9f6b977f 109 MmioWrite32 (DMA4_CDFI (Channel), DMA4->DestinationFrameIndex);\r
110\r
111 // Enable all the status bits since we are polling\r
112 MmioWrite32 (DMA4_CICR (Channel), DMA4_CICR_ENABLE_ALL);\r
113 MmioWrite32 (DMA4_CSR (Channel), DMA4_CSR_RESET);\r
114\r
7f814ffd 115 /* 2) Start the DMA transfer by Setting the enable bit CCR[7]=1 */\r
116 /*--------------------------------------------------------------*/\r
117 //write enable bit\r
8e7c9e03 118 MmioOr32 (DMA4_CCR(Channel), DMA4_CCR_ENABLE); //Launch transfer\r
119\r
120 return EFI_SUCCESS;\r
121}\r
122\r
3402aac7 123/**\r
7f814ffd 124 Turn of DMA channel configured by EnableDma().\r
3402aac7 125\r
7f814ffd 126 @param Channel DMA Channel to configure\r
9f6b977f 127 @param SuccesMask Bits in DMA4_CSR register indicate EFI_SUCCESS\r
128 @param ErrorMask Bits in DMA4_CSR register indicate EFI_DEVICE_ERROR\r
3402aac7 129\r
7f814ffd 130 @retval EFI_SUCCESS DMA hardware disabled\r
131 @retval EFI_INVALID_PARAMETER Channel is not valid\r
132 @retval EFI_DEVICE_ERROR The system hardware could not map the requested information.\r
3402aac7 133\r
8e7c9e03 134**/\r
135EFI_STATUS\r
136EFIAPI\r
137DisableDmaChannel (\r
138 IN UINTN Channel,\r
139 IN UINT32 SuccessMask,\r
140 IN UINT32 ErrorMask\r
141 )\r
142{\r
143 EFI_STATUS Status = EFI_SUCCESS;\r
144 UINT32 Reg;\r
145\r
146\r
147 if (Channel > DMA4_MAX_CHANNEL) {\r
148 return EFI_INVALID_PARAMETER;\r
149 }\r
150\r
151 do {\r
152 Reg = MmioRead32 (DMA4_CSR(Channel));\r
153 if ((Reg & ErrorMask) != 0) {\r
154 Status = EFI_DEVICE_ERROR;\r
155 DEBUG ((EFI_D_ERROR, "DMA Error (%d) %x\n", Channel, Reg));\r
156 break;\r
157 }\r
158 } while ((Reg & SuccessMask) != SuccessMask);\r
159\r
160\r
161 // Disable all status bits and clear them\r
9f6b977f 162 MmioWrite32 (DMA4_CICR (Channel), 0);\r
8e7c9e03 163 MmioWrite32 (DMA4_CSR (Channel), DMA4_CSR_RESET);\r
164\r
3402aac7 165 MmioAnd32 (DMA4_CCR(0), ~(DMA4_CCR_ENABLE | DMA4_CCR_RD_ACTIVE | DMA4_CCR_WR_ACTIVE));\r
8e7c9e03 166 return Status;\r
167}\r
168\r
169\r
170\r