Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / dma / bestcomm / ata.c
blob502a45d76adca6b4b68a496cc0f41b7942e502ff
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Bestcomm ATA task driver
5 * Patterned after bestcomm/fec.c by Dale Farnsworth <dfarnsworth@mvista.com>
6 * 2003-2004 (c) MontaVista, Software, Inc.
8 * Copyright (C) 2006-2007 Sylvain Munaut <tnt@246tNt.com>
9 * Copyright (C) 2006 Freescale - John Rigby
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/types.h>
15 #include <asm/io.h>
17 #include <linux/fsl/bestcomm/bestcomm.h>
18 #include <linux/fsl/bestcomm/bestcomm_priv.h>
19 #include <linux/fsl/bestcomm/ata.h>
22 /* ======================================================================== */
23 /* Task image/var/inc */
24 /* ======================================================================== */
26 /* ata task image */
27 extern u32 bcom_ata_task[];
29 /* ata task vars that need to be set before enabling the task */
30 struct bcom_ata_var {
31 u32 enable; /* (u16*) address of task's control register */
32 u32 bd_base; /* (struct bcom_bd*) beginning of ring buffer */
33 u32 bd_last; /* (struct bcom_bd*) end of ring buffer */
34 u32 bd_start; /* (struct bcom_bd*) current bd */
35 u32 buffer_size; /* size of receive buffer */
38 /* ata task incs that need to be set before enabling the task */
39 struct bcom_ata_inc {
40 u16 pad0;
41 s16 incr_bytes;
42 u16 pad1;
43 s16 incr_dst;
44 u16 pad2;
45 s16 incr_src;
49 /* ======================================================================== */
50 /* Task support code */
51 /* ======================================================================== */
53 struct bcom_task *
54 bcom_ata_init(int queue_len, int maxbufsize)
56 struct bcom_task *tsk;
57 struct bcom_ata_var *var;
58 struct bcom_ata_inc *inc;
60 /* Prefetch breaks ATA DMA. Turn it off for ATA DMA */
61 bcom_disable_prefetch();
63 tsk = bcom_task_alloc(queue_len, sizeof(struct bcom_ata_bd), 0);
64 if (!tsk)
65 return NULL;
67 tsk->flags = BCOM_FLAGS_NONE;
69 bcom_ata_reset_bd(tsk);
71 var = (struct bcom_ata_var *) bcom_task_var(tsk->tasknum);
72 inc = (struct bcom_ata_inc *) bcom_task_inc(tsk->tasknum);
74 if (bcom_load_image(tsk->tasknum, bcom_ata_task)) {
75 bcom_task_free(tsk);
76 return NULL;
79 var->enable = bcom_eng->regs_base +
80 offsetof(struct mpc52xx_sdma, tcr[tsk->tasknum]);
81 var->bd_base = tsk->bd_pa;
82 var->bd_last = tsk->bd_pa + ((tsk->num_bd-1) * tsk->bd_size);
83 var->bd_start = tsk->bd_pa;
84 var->buffer_size = maxbufsize;
86 /* Configure some stuff */
87 bcom_set_task_pragma(tsk->tasknum, BCOM_ATA_PRAGMA);
88 bcom_set_task_auto_start(tsk->tasknum, tsk->tasknum);
90 out_8(&bcom_eng->regs->ipr[BCOM_INITIATOR_ATA_RX], BCOM_IPR_ATA_RX);
91 out_8(&bcom_eng->regs->ipr[BCOM_INITIATOR_ATA_TX], BCOM_IPR_ATA_TX);
93 out_be32(&bcom_eng->regs->IntPend, 1<<tsk->tasknum); /* Clear ints */
95 return tsk;
97 EXPORT_SYMBOL_GPL(bcom_ata_init);
99 void bcom_ata_rx_prepare(struct bcom_task *tsk)
101 struct bcom_ata_inc *inc;
103 inc = (struct bcom_ata_inc *) bcom_task_inc(tsk->tasknum);
105 inc->incr_bytes = -(s16)sizeof(u32);
106 inc->incr_src = 0;
107 inc->incr_dst = sizeof(u32);
109 bcom_set_initiator(tsk->tasknum, BCOM_INITIATOR_ATA_RX);
111 EXPORT_SYMBOL_GPL(bcom_ata_rx_prepare);
113 void bcom_ata_tx_prepare(struct bcom_task *tsk)
115 struct bcom_ata_inc *inc;
117 inc = (struct bcom_ata_inc *) bcom_task_inc(tsk->tasknum);
119 inc->incr_bytes = -(s16)sizeof(u32);
120 inc->incr_src = sizeof(u32);
121 inc->incr_dst = 0;
123 bcom_set_initiator(tsk->tasknum, BCOM_INITIATOR_ATA_TX);
125 EXPORT_SYMBOL_GPL(bcom_ata_tx_prepare);
127 void bcom_ata_reset_bd(struct bcom_task *tsk)
129 struct bcom_ata_var *var;
131 /* Reset all BD */
132 memset_io(tsk->bd, 0x00, tsk->num_bd * tsk->bd_size);
134 tsk->index = 0;
135 tsk->outdex = 0;
137 var = (struct bcom_ata_var *) bcom_task_var(tsk->tasknum);
138 var->bd_start = var->bd_base;
140 EXPORT_SYMBOL_GPL(bcom_ata_reset_bd);
142 void bcom_ata_release(struct bcom_task *tsk)
144 /* Nothing special for the ATA tasks */
145 bcom_task_free(tsk);
147 EXPORT_SYMBOL_GPL(bcom_ata_release);
150 MODULE_DESCRIPTION("BestComm ATA task driver");
151 MODULE_AUTHOR("John Rigby");
152 MODULE_LICENSE("GPL v2");