xref: /linux/drivers/dma/bestcomm/ata.c (revision 20bed0d6ff62d985fe8222958825504b8aad4e88)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Bestcomm ATA task driver
4  *
5  * Patterned after bestcomm/fec.c by Dale Farnsworth <dfarnsworth@mvista.com>
6  *                                   2003-2004 (c) MontaVista, Software, Inc.
7  *
8  * Copyright (C) 2006-2007 Sylvain Munaut <tnt@246tNt.com>
9  * Copyright (C) 2006      Freescale - John Rigby
10  */
11 
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/types.h>
15 #include <asm/io.h>
16 
17 #include <linux/fsl/bestcomm/bestcomm.h>
18 #include <linux/fsl/bestcomm/bestcomm_priv.h>
19 #include <linux/fsl/bestcomm/ata.h>
20 
21 
22 /* ======================================================================== */
23 /* Task image/var/inc                                                       */
24 /* ======================================================================== */
25 
26 /* ata task image */
27 extern u32 bcom_ata_task[];
28 
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 */
36 };
37 
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;
46 };
47 
48 
49 /* ======================================================================== */
50 /* Task support code                                                        */
51 /* ======================================================================== */
52 
53 struct bcom_task *
54 bcom_ata_init(int queue_len, int maxbufsize)
55 {
56 	struct bcom_task *tsk;
57 	struct bcom_ata_var *var;
58 
59 	/* Prefetch breaks ATA DMA.  Turn it off for ATA DMA */
60 	bcom_disable_prefetch();
61 
62 	tsk = bcom_task_alloc(queue_len, sizeof(struct bcom_ata_bd), 0);
63 	if (!tsk)
64 		return NULL;
65 
66 	tsk->flags = BCOM_FLAGS_NONE;
67 
68 	bcom_ata_reset_bd(tsk);
69 
70 	var = (struct bcom_ata_var *) bcom_task_var(tsk->tasknum);
71 
72 	if (bcom_load_image(tsk->tasknum, bcom_ata_task)) {
73 		bcom_task_free(tsk);
74 		return NULL;
75 	}
76 
77 	var->enable	= bcom_eng->regs_base +
78 				offsetof(struct mpc52xx_sdma, tcr[tsk->tasknum]);
79 	var->bd_base	= tsk->bd_pa;
80 	var->bd_last	= tsk->bd_pa + ((tsk->num_bd-1) * tsk->bd_size);
81 	var->bd_start	= tsk->bd_pa;
82 	var->buffer_size = maxbufsize;
83 
84 	/* Configure some stuff */
85 	bcom_set_task_pragma(tsk->tasknum, BCOM_ATA_PRAGMA);
86 	bcom_set_task_auto_start(tsk->tasknum, tsk->tasknum);
87 
88 	out_8(&bcom_eng->regs->ipr[BCOM_INITIATOR_ATA_RX], BCOM_IPR_ATA_RX);
89 	out_8(&bcom_eng->regs->ipr[BCOM_INITIATOR_ATA_TX], BCOM_IPR_ATA_TX);
90 
91 	out_be32(&bcom_eng->regs->IntPend, 1<<tsk->tasknum); /* Clear ints */
92 
93 	return tsk;
94 }
95 EXPORT_SYMBOL_GPL(bcom_ata_init);
96 
97 void bcom_ata_rx_prepare(struct bcom_task *tsk)
98 {
99 	struct bcom_ata_inc *inc;
100 
101 	inc = (struct bcom_ata_inc *) bcom_task_inc(tsk->tasknum);
102 
103 	inc->incr_bytes	= -(s16)sizeof(u32);
104 	inc->incr_src	= 0;
105 	inc->incr_dst	= sizeof(u32);
106 
107 	bcom_set_initiator(tsk->tasknum, BCOM_INITIATOR_ATA_RX);
108 }
109 EXPORT_SYMBOL_GPL(bcom_ata_rx_prepare);
110 
111 void bcom_ata_tx_prepare(struct bcom_task *tsk)
112 {
113 	struct bcom_ata_inc *inc;
114 
115 	inc = (struct bcom_ata_inc *) bcom_task_inc(tsk->tasknum);
116 
117 	inc->incr_bytes	= -(s16)sizeof(u32);
118 	inc->incr_src	= sizeof(u32);
119 	inc->incr_dst	= 0;
120 
121 	bcom_set_initiator(tsk->tasknum, BCOM_INITIATOR_ATA_TX);
122 }
123 EXPORT_SYMBOL_GPL(bcom_ata_tx_prepare);
124 
125 void bcom_ata_reset_bd(struct bcom_task *tsk)
126 {
127 	struct bcom_ata_var *var;
128 
129 	/* Reset all BD */
130 	memset_io(tsk->bd, 0x00, tsk->num_bd * tsk->bd_size);
131 
132 	tsk->index = 0;
133 	tsk->outdex = 0;
134 
135 	var = (struct bcom_ata_var *) bcom_task_var(tsk->tasknum);
136 	var->bd_start = var->bd_base;
137 }
138 EXPORT_SYMBOL_GPL(bcom_ata_reset_bd);
139 
140 void bcom_ata_release(struct bcom_task *tsk)
141 {
142 	/* Nothing special for the ATA tasks */
143 	bcom_task_free(tsk);
144 }
145 EXPORT_SYMBOL_GPL(bcom_ata_release);
146 
147 
148 MODULE_DESCRIPTION("BestComm ATA task driver");
149 MODULE_AUTHOR("John Rigby");
150 MODULE_LICENSE("GPL v2");
151