1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * OMAP2+ DMA driver
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 2003 - 2008 Nokia Corporation
6*4882a593Smuzhiyun * Author: Juha Yrjölä <juha.yrjola@nokia.com>
7*4882a593Smuzhiyun * DMA channel linking for 1610 by Samuel Ortiz <samuel.ortiz@nokia.com>
8*4882a593Smuzhiyun * Graphics DMA and LCD DMA graphics tranformations
9*4882a593Smuzhiyun * by Imre Deak <imre.deak@nokia.com>
10*4882a593Smuzhiyun * OMAP2/3 support Copyright (C) 2004-2007 Texas Instruments, Inc.
11*4882a593Smuzhiyun * Some functions based on earlier dma-omap.c Copyright (C) 2001 RidgeRun, Inc.
12*4882a593Smuzhiyun *
13*4882a593Smuzhiyun * Copyright (C) 2009 Texas Instruments
14*4882a593Smuzhiyun * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
15*4882a593Smuzhiyun *
16*4882a593Smuzhiyun * Copyright (C) 2010 Texas Instruments Incorporated - https://www.ti.com/
17*4882a593Smuzhiyun * Converted DMA library into platform driver
18*4882a593Smuzhiyun * - G, Manjunath Kondaiah <manjugk@ti.com>
19*4882a593Smuzhiyun */
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun #include <linux/err.h>
22*4882a593Smuzhiyun #include <linux/io.h>
23*4882a593Smuzhiyun #include <linux/slab.h>
24*4882a593Smuzhiyun #include <linux/module.h>
25*4882a593Smuzhiyun #include <linux/init.h>
26*4882a593Smuzhiyun #include <linux/device.h>
27*4882a593Smuzhiyun #include <linux/dma-mapping.h>
28*4882a593Smuzhiyun #include <linux/dmaengine.h>
29*4882a593Smuzhiyun #include <linux/of.h>
30*4882a593Smuzhiyun #include <linux/omap-dma.h>
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun #include "soc.h"
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun static const struct omap_dma_reg reg_map[] = {
35*4882a593Smuzhiyun [REVISION] = { 0x0000, 0x00, OMAP_DMA_REG_32BIT },
36*4882a593Smuzhiyun [GCR] = { 0x0078, 0x00, OMAP_DMA_REG_32BIT },
37*4882a593Smuzhiyun [IRQSTATUS_L0] = { 0x0008, 0x00, OMAP_DMA_REG_32BIT },
38*4882a593Smuzhiyun [IRQSTATUS_L1] = { 0x000c, 0x00, OMAP_DMA_REG_32BIT },
39*4882a593Smuzhiyun [IRQSTATUS_L2] = { 0x0010, 0x00, OMAP_DMA_REG_32BIT },
40*4882a593Smuzhiyun [IRQSTATUS_L3] = { 0x0014, 0x00, OMAP_DMA_REG_32BIT },
41*4882a593Smuzhiyun [IRQENABLE_L0] = { 0x0018, 0x00, OMAP_DMA_REG_32BIT },
42*4882a593Smuzhiyun [IRQENABLE_L1] = { 0x001c, 0x00, OMAP_DMA_REG_32BIT },
43*4882a593Smuzhiyun [IRQENABLE_L2] = { 0x0020, 0x00, OMAP_DMA_REG_32BIT },
44*4882a593Smuzhiyun [IRQENABLE_L3] = { 0x0024, 0x00, OMAP_DMA_REG_32BIT },
45*4882a593Smuzhiyun [SYSSTATUS] = { 0x0028, 0x00, OMAP_DMA_REG_32BIT },
46*4882a593Smuzhiyun [OCP_SYSCONFIG] = { 0x002c, 0x00, OMAP_DMA_REG_32BIT },
47*4882a593Smuzhiyun [CAPS_0] = { 0x0064, 0x00, OMAP_DMA_REG_32BIT },
48*4882a593Smuzhiyun [CAPS_2] = { 0x006c, 0x00, OMAP_DMA_REG_32BIT },
49*4882a593Smuzhiyun [CAPS_3] = { 0x0070, 0x00, OMAP_DMA_REG_32BIT },
50*4882a593Smuzhiyun [CAPS_4] = { 0x0074, 0x00, OMAP_DMA_REG_32BIT },
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun /* Common register offsets */
53*4882a593Smuzhiyun [CCR] = { 0x0080, 0x60, OMAP_DMA_REG_32BIT },
54*4882a593Smuzhiyun [CLNK_CTRL] = { 0x0084, 0x60, OMAP_DMA_REG_32BIT },
55*4882a593Smuzhiyun [CICR] = { 0x0088, 0x60, OMAP_DMA_REG_32BIT },
56*4882a593Smuzhiyun [CSR] = { 0x008c, 0x60, OMAP_DMA_REG_32BIT },
57*4882a593Smuzhiyun [CSDP] = { 0x0090, 0x60, OMAP_DMA_REG_32BIT },
58*4882a593Smuzhiyun [CEN] = { 0x0094, 0x60, OMAP_DMA_REG_32BIT },
59*4882a593Smuzhiyun [CFN] = { 0x0098, 0x60, OMAP_DMA_REG_32BIT },
60*4882a593Smuzhiyun [CSEI] = { 0x00a4, 0x60, OMAP_DMA_REG_32BIT },
61*4882a593Smuzhiyun [CSFI] = { 0x00a8, 0x60, OMAP_DMA_REG_32BIT },
62*4882a593Smuzhiyun [CDEI] = { 0x00ac, 0x60, OMAP_DMA_REG_32BIT },
63*4882a593Smuzhiyun [CDFI] = { 0x00b0, 0x60, OMAP_DMA_REG_32BIT },
64*4882a593Smuzhiyun [CSAC] = { 0x00b4, 0x60, OMAP_DMA_REG_32BIT },
65*4882a593Smuzhiyun [CDAC] = { 0x00b8, 0x60, OMAP_DMA_REG_32BIT },
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun /* Channel specific register offsets */
68*4882a593Smuzhiyun [CSSA] = { 0x009c, 0x60, OMAP_DMA_REG_32BIT },
69*4882a593Smuzhiyun [CDSA] = { 0x00a0, 0x60, OMAP_DMA_REG_32BIT },
70*4882a593Smuzhiyun [CCEN] = { 0x00bc, 0x60, OMAP_DMA_REG_32BIT },
71*4882a593Smuzhiyun [CCFN] = { 0x00c0, 0x60, OMAP_DMA_REG_32BIT },
72*4882a593Smuzhiyun [COLOR] = { 0x00c4, 0x60, OMAP_DMA_REG_32BIT },
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun /* OMAP4 specific registers */
75*4882a593Smuzhiyun [CDP] = { 0x00d0, 0x60, OMAP_DMA_REG_32BIT },
76*4882a593Smuzhiyun [CNDP] = { 0x00d4, 0x60, OMAP_DMA_REG_32BIT },
77*4882a593Smuzhiyun [CCDN] = { 0x00d8, 0x60, OMAP_DMA_REG_32BIT },
78*4882a593Smuzhiyun };
79*4882a593Smuzhiyun
configure_dma_errata(void)80*4882a593Smuzhiyun static unsigned configure_dma_errata(void)
81*4882a593Smuzhiyun {
82*4882a593Smuzhiyun unsigned errata = 0;
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun /*
85*4882a593Smuzhiyun * Errata applicable for OMAP2430ES1.0 and all omap2420
86*4882a593Smuzhiyun *
87*4882a593Smuzhiyun * I.
88*4882a593Smuzhiyun * Erratum ID: Not Available
89*4882a593Smuzhiyun * Inter Frame DMA buffering issue DMA will wrongly
90*4882a593Smuzhiyun * buffer elements if packing and bursting is enabled. This might
91*4882a593Smuzhiyun * result in data gets stalled in FIFO at the end of the block.
92*4882a593Smuzhiyun * Workaround: DMA channels must have BUFFERING_DISABLED bit set to
93*4882a593Smuzhiyun * guarantee no data will stay in the DMA FIFO in case inter frame
94*4882a593Smuzhiyun * buffering occurs
95*4882a593Smuzhiyun *
96*4882a593Smuzhiyun * II.
97*4882a593Smuzhiyun * Erratum ID: Not Available
98*4882a593Smuzhiyun * DMA may hang when several channels are used in parallel
99*4882a593Smuzhiyun * In the following configuration, DMA channel hanging can occur:
100*4882a593Smuzhiyun * a. Channel i, hardware synchronized, is enabled
101*4882a593Smuzhiyun * b. Another channel (Channel x), software synchronized, is enabled.
102*4882a593Smuzhiyun * c. Channel i is disabled before end of transfer
103*4882a593Smuzhiyun * d. Channel i is reenabled.
104*4882a593Smuzhiyun * e. Steps 1 to 4 are repeated a certain number of times.
105*4882a593Smuzhiyun * f. A third channel (Channel y), software synchronized, is enabled.
106*4882a593Smuzhiyun * Channel x and Channel y may hang immediately after step 'f'.
107*4882a593Smuzhiyun * Workaround:
108*4882a593Smuzhiyun * For any channel used - make sure NextLCH_ID is set to the value j.
109*4882a593Smuzhiyun */
110*4882a593Smuzhiyun if (cpu_is_omap2420() || (cpu_is_omap2430() &&
111*4882a593Smuzhiyun (omap_type() == OMAP2430_REV_ES1_0))) {
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun SET_DMA_ERRATA(DMA_ERRATA_IFRAME_BUFFERING);
114*4882a593Smuzhiyun SET_DMA_ERRATA(DMA_ERRATA_PARALLEL_CHANNELS);
115*4882a593Smuzhiyun }
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun /*
118*4882a593Smuzhiyun * Erratum ID: i378: OMAP2+: sDMA Channel is not disabled
119*4882a593Smuzhiyun * after a transaction error.
120*4882a593Smuzhiyun * Workaround: SW should explicitely disable the channel.
121*4882a593Smuzhiyun */
122*4882a593Smuzhiyun if (cpu_class_is_omap2())
123*4882a593Smuzhiyun SET_DMA_ERRATA(DMA_ERRATA_i378);
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun /*
126*4882a593Smuzhiyun * Erratum ID: i541: sDMA FIFO draining does not finish
127*4882a593Smuzhiyun * If sDMA channel is disabled on the fly, sDMA enters standby even
128*4882a593Smuzhiyun * through FIFO Drain is still in progress
129*4882a593Smuzhiyun * Workaround: Put sDMA in NoStandby more before a logical channel is
130*4882a593Smuzhiyun * disabled, then put it back to SmartStandby right after the channel
131*4882a593Smuzhiyun * finishes FIFO draining.
132*4882a593Smuzhiyun */
133*4882a593Smuzhiyun if (cpu_is_omap34xx())
134*4882a593Smuzhiyun SET_DMA_ERRATA(DMA_ERRATA_i541);
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun /*
137*4882a593Smuzhiyun * Erratum ID: i88 : Special programming model needed to disable DMA
138*4882a593Smuzhiyun * before end of block.
139*4882a593Smuzhiyun * Workaround: software must ensure that the DMA is configured in No
140*4882a593Smuzhiyun * Standby mode(DMAx_OCP_SYSCONFIG.MIDLEMODE = "01")
141*4882a593Smuzhiyun */
142*4882a593Smuzhiyun if (omap_type() == OMAP3430_REV_ES1_0)
143*4882a593Smuzhiyun SET_DMA_ERRATA(DMA_ERRATA_i88);
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun /*
146*4882a593Smuzhiyun * Erratum 3.2/3.3: sometimes 0 is returned if CSAC/CDAC is
147*4882a593Smuzhiyun * read before the DMA controller finished disabling the channel.
148*4882a593Smuzhiyun */
149*4882a593Smuzhiyun SET_DMA_ERRATA(DMA_ERRATA_3_3);
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun /*
152*4882a593Smuzhiyun * Erratum ID: Not Available
153*4882a593Smuzhiyun * A bug in ROM code leaves IRQ status for channels 0 and 1 uncleared
154*4882a593Smuzhiyun * after secure sram context save and restore.
155*4882a593Smuzhiyun * Work around: Hence we need to manually clear those IRQs to avoid
156*4882a593Smuzhiyun * spurious interrupts. This affects only secure devices.
157*4882a593Smuzhiyun */
158*4882a593Smuzhiyun if (cpu_is_omap34xx() && (omap_type() != OMAP2_DEVICE_TYPE_GP))
159*4882a593Smuzhiyun SET_DMA_ERRATA(DMA_ROMCODE_BUG);
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun return errata;
162*4882a593Smuzhiyun }
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun static const struct dma_slave_map omap24xx_sdma_dt_map[] = {
165*4882a593Smuzhiyun /* external DMA requests when tusb6010 is used */
166*4882a593Smuzhiyun { "musb-hdrc.1.auto", "dmareq0", SDMA_FILTER_PARAM(2) },
167*4882a593Smuzhiyun { "musb-hdrc.1.auto", "dmareq1", SDMA_FILTER_PARAM(3) },
168*4882a593Smuzhiyun { "musb-hdrc.1.auto", "dmareq2", SDMA_FILTER_PARAM(14) }, /* OMAP2420 only */
169*4882a593Smuzhiyun { "musb-hdrc.1.auto", "dmareq3", SDMA_FILTER_PARAM(15) }, /* OMAP2420 only */
170*4882a593Smuzhiyun { "musb-hdrc.1.auto", "dmareq4", SDMA_FILTER_PARAM(16) }, /* OMAP2420 only */
171*4882a593Smuzhiyun { "musb-hdrc.1.auto", "dmareq5", SDMA_FILTER_PARAM(64) }, /* OMAP2420 only */
172*4882a593Smuzhiyun };
173*4882a593Smuzhiyun
174*4882a593Smuzhiyun static struct omap_dma_dev_attr dma_attr = {
175*4882a593Smuzhiyun .dev_caps = RESERVE_CHANNEL | DMA_LINKED_LCH | GLOBAL_PRIORITY |
176*4882a593Smuzhiyun IS_CSSA_32 | IS_CDSA_32,
177*4882a593Smuzhiyun .lch_count = 32,
178*4882a593Smuzhiyun };
179*4882a593Smuzhiyun
180*4882a593Smuzhiyun struct omap_system_dma_plat_info dma_plat_info = {
181*4882a593Smuzhiyun .reg_map = reg_map,
182*4882a593Smuzhiyun .channel_stride = 0x60,
183*4882a593Smuzhiyun .dma_attr = &dma_attr,
184*4882a593Smuzhiyun };
185*4882a593Smuzhiyun
186*4882a593Smuzhiyun /* One time initializations */
omap2_system_dma_init(void)187*4882a593Smuzhiyun static int __init omap2_system_dma_init(void)
188*4882a593Smuzhiyun {
189*4882a593Smuzhiyun dma_plat_info.errata = configure_dma_errata();
190*4882a593Smuzhiyun
191*4882a593Smuzhiyun if (soc_is_omap24xx()) {
192*4882a593Smuzhiyun /* DMA slave map for drivers not yet converted to DT */
193*4882a593Smuzhiyun dma_plat_info.slave_map = omap24xx_sdma_dt_map;
194*4882a593Smuzhiyun dma_plat_info.slavecnt = ARRAY_SIZE(omap24xx_sdma_dt_map);
195*4882a593Smuzhiyun }
196*4882a593Smuzhiyun
197*4882a593Smuzhiyun if (!soc_is_omap242x())
198*4882a593Smuzhiyun dma_attr.dev_caps |= IS_RW_PRIORITY;
199*4882a593Smuzhiyun
200*4882a593Smuzhiyun if (soc_is_omap34xx() && (omap_type() != OMAP2_DEVICE_TYPE_GP))
201*4882a593Smuzhiyun dma_attr.dev_caps |= HS_CHANNELS_RESERVED;
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun return 0;
204*4882a593Smuzhiyun }
205*4882a593Smuzhiyun omap_arch_initcall(omap2_system_dma_init);
206