2 * Driver for MPC52xx processor BestComm General Buffer Descriptor
4 * Copyright (C) 2007 Sylvain Munaut <tnt@246tNt.com>
5 * Copyright (C) 2006 AppSpec Computer Technologies Corp.
6 * Jeff Gibbons <jeff.gibbons@appspec.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published
10 * by the Free Software Foundation.
14 #include <linux/version.h>
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/string.h>
18 #include <linux/types.h>
19 #include <asm/errno.h>
22 #include <asm/mpc52xx.h>
25 #include "bestcomm_priv.h"
29 /* ======================================================================== */
30 /* Task image/var/inc */
31 /* ======================================================================== */
33 /* gen_bd tasks images */
34 extern u32 bcom_gen_bd_rx_task[];
35 extern u32 bcom_gen_bd_tx_task[];
37 /* rx task vars that need to be set before enabling the task */
38 struct bcom_gen_bd_rx_var {
39 u32 enable; /* (u16*) address of task's control register */
40 u32 fifo; /* (u32*) address of gen_bd's fifo */
41 u32 bd_base; /* (struct bcom_bd*) beginning of ring buffer */
42 u32 bd_last; /* (struct bcom_bd*) end of ring buffer */
43 u32 bd_start; /* (struct bcom_bd*) current bd */
44 u32 buffer_size; /* size of receive buffer */
47 /* rx task incs that need to be set before enabling the task */
48 struct bcom_gen_bd_rx_inc {
55 /* tx task vars that need to be set before enabling the task */
56 struct bcom_gen_bd_tx_var {
57 u32 fifo; /* (u32*) address of gen_bd's fifo */
58 u32 enable; /* (u16*) address of task's control register */
59 u32 bd_base; /* (struct bcom_bd*) beginning of ring buffer */
60 u32 bd_last; /* (struct bcom_bd*) end of ring buffer */
61 u32 bd_start; /* (struct bcom_bd*) current bd */
62 u32 buffer_size; /* set by uCode for each packet */
65 /* tx task incs that need to be set before enabling the task */
66 struct bcom_gen_bd_tx_inc {
75 /* private structure */
76 struct bcom_gen_bd_priv {
84 /* ======================================================================== */
85 /* Task support code */
86 /* ======================================================================== */
89 bcom_gen_bd_rx_init(int queue_len, phys_addr_t fifo,
90 int initiator, int ipr, int maxbufsize)
92 struct bcom_task *tsk;
93 struct bcom_gen_bd_priv *priv;
95 tsk = bcom_task_alloc(queue_len, sizeof(struct bcom_gen_bd),
96 sizeof(struct bcom_gen_bd_priv));
100 tsk->flags = BCOM_FLAGS_NONE;
104 priv->initiator = initiator;
106 priv->maxbufsize = maxbufsize;
108 if (bcom_gen_bd_rx_reset(tsk)) {
115 EXPORT_SYMBOL_GPL(bcom_gen_bd_rx_init);
118 bcom_gen_bd_rx_reset(struct bcom_task *tsk)
120 struct bcom_gen_bd_priv *priv = tsk->priv;
121 struct bcom_gen_bd_rx_var *var;
122 struct bcom_gen_bd_rx_inc *inc;
124 /* Shutdown the task */
125 bcom_disable_task(tsk->tasknum);
127 /* Reset the microcode */
128 var = (struct bcom_gen_bd_rx_var *) bcom_task_var(tsk->tasknum);
129 inc = (struct bcom_gen_bd_rx_inc *) bcom_task_inc(tsk->tasknum);
131 if (bcom_load_image(tsk->tasknum, bcom_gen_bd_rx_task))
134 var->enable = bcom_eng->regs_base +
135 offsetof(struct mpc52xx_sdma, tcr[tsk->tasknum]);
136 var->fifo = (u32) priv->fifo;
137 var->bd_base = tsk->bd_pa;
138 var->bd_last = tsk->bd_pa + ((tsk->num_bd-1) * tsk->bd_size);
139 var->bd_start = tsk->bd_pa;
140 var->buffer_size = priv->maxbufsize;
142 inc->incr_bytes = -(s16)sizeof(u32);
143 inc->incr_dst = sizeof(u32);
149 memset(tsk->bd, 0x00, tsk->num_bd * tsk->bd_size);
151 /* Configure some stuff */
152 bcom_set_task_pragma(tsk->tasknum, BCOM_GEN_RX_BD_PRAGMA);
153 bcom_set_task_auto_start(tsk->tasknum, tsk->tasknum);
155 out_8(&bcom_eng->regs->ipr[priv->initiator], priv->ipr);
156 bcom_set_initiator(tsk->tasknum, priv->initiator);
158 out_be32(&bcom_eng->regs->IntPend, 1<<tsk->tasknum); /* Clear ints */
162 EXPORT_SYMBOL_GPL(bcom_gen_bd_rx_reset);
165 bcom_gen_bd_rx_release(struct bcom_task *tsk)
167 /* Nothing special for the GenBD tasks */
170 EXPORT_SYMBOL_GPL(bcom_gen_bd_rx_release);
173 extern struct bcom_task *
174 bcom_gen_bd_tx_init(int queue_len, phys_addr_t fifo,
175 int initiator, int ipr)
177 struct bcom_task *tsk;
178 struct bcom_gen_bd_priv *priv;
180 tsk = bcom_task_alloc(queue_len, sizeof(struct bcom_gen_bd),
181 sizeof(struct bcom_gen_bd_priv));
185 tsk->flags = BCOM_FLAGS_NONE;
189 priv->initiator = initiator;
192 if (bcom_gen_bd_tx_reset(tsk)) {
199 EXPORT_SYMBOL_GPL(bcom_gen_bd_tx_init);
202 bcom_gen_bd_tx_reset(struct bcom_task *tsk)
204 struct bcom_gen_bd_priv *priv = tsk->priv;
205 struct bcom_gen_bd_tx_var *var;
206 struct bcom_gen_bd_tx_inc *inc;
208 /* Shutdown the task */
209 bcom_disable_task(tsk->tasknum);
211 /* Reset the microcode */
212 var = (struct bcom_gen_bd_tx_var *) bcom_task_var(tsk->tasknum);
213 inc = (struct bcom_gen_bd_tx_inc *) bcom_task_inc(tsk->tasknum);
215 if (bcom_load_image(tsk->tasknum, bcom_gen_bd_tx_task))
218 var->enable = bcom_eng->regs_base +
219 offsetof(struct mpc52xx_sdma, tcr[tsk->tasknum]);
220 var->fifo = (u32) priv->fifo;
221 var->bd_base = tsk->bd_pa;
222 var->bd_last = tsk->bd_pa + ((tsk->num_bd-1) * tsk->bd_size);
223 var->bd_start = tsk->bd_pa;
225 inc->incr_bytes = -(s16)sizeof(u32);
226 inc->incr_src = sizeof(u32);
227 inc->incr_src_ma = sizeof(u8);
233 memset(tsk->bd, 0x00, tsk->num_bd * tsk->bd_size);
235 /* Configure some stuff */
236 bcom_set_task_pragma(tsk->tasknum, BCOM_GEN_TX_BD_PRAGMA);
237 bcom_set_task_auto_start(tsk->tasknum, tsk->tasknum);
239 out_8(&bcom_eng->regs->ipr[priv->initiator], priv->ipr);
240 bcom_set_initiator(tsk->tasknum, priv->initiator);
242 out_be32(&bcom_eng->regs->IntPend, 1<<tsk->tasknum); /* Clear ints */
246 EXPORT_SYMBOL_GPL(bcom_gen_bd_tx_reset);
249 bcom_gen_bd_tx_release(struct bcom_task *tsk)
251 /* Nothing special for the GenBD tasks */
254 EXPORT_SYMBOL_GPL(bcom_gen_bd_tx_release);
257 MODULE_DESCRIPTION("BestComm General Buffer Descriptor tasks driver");
258 MODULE_AUTHOR("Jeff Gibbons <jeff.gibbons@appspec.com>");
259 MODULE_LICENSE("GPL v2");