2 * arch/powerpc/sysdev/qe_lib/ucc_fast.c
4 * QE UCC Fast API Set - UCC Fast specific routines implementations.
6 * Copyright (C) 2006 Freescale Semicondutor, Inc. All rights reserved.
8 * Authors: Shlomi Gridish <gridish@freescale.com>
9 * Li Yang <leoli@freescale.com>
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/errno.h>
19 #include <linux/slab.h>
20 #include <linux/stddef.h>
21 #include <linux/interrupt.h>
24 #include <asm/immap_qe.h>
28 #include <asm/ucc_fast.h>
30 #define uccf_printk(level, format, arg...) \
31 printk(level format "\n", ## arg)
33 #define uccf_dbg(format, arg...) \
34 uccf_printk(KERN_DEBUG , format , ## arg)
35 #define uccf_err(format, arg...) \
36 uccf_printk(KERN_ERR , format , ## arg)
37 #define uccf_info(format, arg...) \
38 uccf_printk(KERN_INFO , format , ## arg)
39 #define uccf_warn(format, arg...) \
40 uccf_printk(KERN_WARNING , format , ## arg)
42 #ifdef UCCF_VERBOSE_DEBUG
43 #define uccf_vdbg uccf_dbg
45 #define uccf_vdbg(fmt, args...) do { } while (0)
46 #endif /* UCCF_VERBOSE_DEBUG */
48 void ucc_fast_dump_regs(struct ucc_fast_private * uccf)
50 uccf_info("UCC%d Fast registers:", uccf->uf_info->ucc_num);
51 uccf_info("Base address: 0x%08x", (u32) uccf->uf_regs);
53 uccf_info("gumr : addr - 0x%08x, val - 0x%08x",
54 (u32) & uccf->uf_regs->gumr, in_be32(&uccf->uf_regs->gumr));
55 uccf_info("upsmr : addr - 0x%08x, val - 0x%08x",
56 (u32) & uccf->uf_regs->upsmr, in_be32(&uccf->uf_regs->upsmr));
57 uccf_info("utodr : addr - 0x%08x, val - 0x%04x",
58 (u32) & uccf->uf_regs->utodr, in_be16(&uccf->uf_regs->utodr));
59 uccf_info("udsr : addr - 0x%08x, val - 0x%04x",
60 (u32) & uccf->uf_regs->udsr, in_be16(&uccf->uf_regs->udsr));
61 uccf_info("ucce : addr - 0x%08x, val - 0x%08x",
62 (u32) & uccf->uf_regs->ucce, in_be32(&uccf->uf_regs->ucce));
63 uccf_info("uccm : addr - 0x%08x, val - 0x%08x",
64 (u32) & uccf->uf_regs->uccm, in_be32(&uccf->uf_regs->uccm));
65 uccf_info("uccs : addr - 0x%08x, val - 0x%02x",
66 (u32) & uccf->uf_regs->uccs, uccf->uf_regs->uccs);
67 uccf_info("urfb : addr - 0x%08x, val - 0x%08x",
68 (u32) & uccf->uf_regs->urfb, in_be32(&uccf->uf_regs->urfb));
69 uccf_info("urfs : addr - 0x%08x, val - 0x%04x",
70 (u32) & uccf->uf_regs->urfs, in_be16(&uccf->uf_regs->urfs));
71 uccf_info("urfet : addr - 0x%08x, val - 0x%04x",
72 (u32) & uccf->uf_regs->urfet, in_be16(&uccf->uf_regs->urfet));
73 uccf_info("urfset: addr - 0x%08x, val - 0x%04x",
74 (u32) & uccf->uf_regs->urfset,
75 in_be16(&uccf->uf_regs->urfset));
76 uccf_info("utfb : addr - 0x%08x, val - 0x%08x",
77 (u32) & uccf->uf_regs->utfb, in_be32(&uccf->uf_regs->utfb));
78 uccf_info("utfs : addr - 0x%08x, val - 0x%04x",
79 (u32) & uccf->uf_regs->utfs, in_be16(&uccf->uf_regs->utfs));
80 uccf_info("utfet : addr - 0x%08x, val - 0x%04x",
81 (u32) & uccf->uf_regs->utfet, in_be16(&uccf->uf_regs->utfet));
82 uccf_info("utftt : addr - 0x%08x, val - 0x%04x",
83 (u32) & uccf->uf_regs->utftt, in_be16(&uccf->uf_regs->utftt));
84 uccf_info("utpt : addr - 0x%08x, val - 0x%04x",
85 (u32) & uccf->uf_regs->utpt, in_be16(&uccf->uf_regs->utpt));
86 uccf_info("urtry : addr - 0x%08x, val - 0x%08x",
87 (u32) & uccf->uf_regs->urtry, in_be32(&uccf->uf_regs->urtry));
88 uccf_info("guemr : addr - 0x%08x, val - 0x%02x",
89 (u32) & uccf->uf_regs->guemr, uccf->uf_regs->guemr);
92 u32 ucc_fast_get_qe_cr_subblock(int uccf_num)
95 case 0: return QE_CR_SUBBLOCK_UCCFAST1;
96 case 1: return QE_CR_SUBBLOCK_UCCFAST2;
97 case 2: return QE_CR_SUBBLOCK_UCCFAST3;
98 case 3: return QE_CR_SUBBLOCK_UCCFAST4;
99 case 4: return QE_CR_SUBBLOCK_UCCFAST5;
100 case 5: return QE_CR_SUBBLOCK_UCCFAST6;
101 case 6: return QE_CR_SUBBLOCK_UCCFAST7;
102 case 7: return QE_CR_SUBBLOCK_UCCFAST8;
103 default: return QE_CR_SUBBLOCK_INVALID;
107 void ucc_fast_transmit_on_demand(struct ucc_fast_private * uccf)
109 out_be16(&uccf->uf_regs->utodr, UCC_FAST_TOD);
112 void ucc_fast_enable(struct ucc_fast_private * uccf, enum comm_dir mode)
114 struct ucc_fast *uf_regs;
117 uf_regs = uccf->uf_regs;
119 /* Enable reception and/or transmission on this UCC. */
120 gumr = in_be32(&uf_regs->gumr);
121 if (mode & COMM_DIR_TX) {
122 gumr |= UCC_FAST_GUMR_ENT;
123 uccf->enabled_tx = 1;
125 if (mode & COMM_DIR_RX) {
126 gumr |= UCC_FAST_GUMR_ENR;
127 uccf->enabled_rx = 1;
129 out_be32(&uf_regs->gumr, gumr);
132 void ucc_fast_disable(struct ucc_fast_private * uccf, enum comm_dir mode)
134 struct ucc_fast *uf_regs;
137 uf_regs = uccf->uf_regs;
139 /* Disable reception and/or transmission on this UCC. */
140 gumr = in_be32(&uf_regs->gumr);
141 if (mode & COMM_DIR_TX) {
142 gumr &= ~UCC_FAST_GUMR_ENT;
143 uccf->enabled_tx = 0;
145 if (mode & COMM_DIR_RX) {
146 gumr &= ~UCC_FAST_GUMR_ENR;
147 uccf->enabled_rx = 0;
149 out_be32(&uf_regs->gumr, gumr);
152 int ucc_fast_init(struct ucc_fast_info * uf_info, struct ucc_fast_private ** uccf_ret)
154 struct ucc_fast_private *uccf;
155 struct ucc_fast *uf_regs;
159 uccf_vdbg("%s: IN", __FUNCTION__);
164 /* check if the UCC port number is in range. */
165 if ((uf_info->ucc_num < 0) || (uf_info->ucc_num > UCC_MAX_NUM - 1)) {
166 uccf_err("ucc_fast_init: Illegal UCC number!");
170 /* Check that 'max_rx_buf_length' is properly aligned (4). */
171 if (uf_info->max_rx_buf_length & (UCC_FAST_MRBLR_ALIGNMENT - 1)) {
172 uccf_err("ucc_fast_init: max_rx_buf_length not aligned.");
176 /* Validate Virtual Fifo register values */
177 if (uf_info->urfs < UCC_FAST_URFS_MIN_VAL) {
179 ("ucc_fast_init: Virtual Fifo register urfs too small.");
183 if (uf_info->urfs & (UCC_FAST_VIRT_FIFO_REGS_ALIGNMENT - 1)) {
185 ("ucc_fast_init: Virtual Fifo register urfs not aligned.");
189 if (uf_info->urfet & (UCC_FAST_VIRT_FIFO_REGS_ALIGNMENT - 1)) {
191 ("ucc_fast_init: Virtual Fifo register urfet not aligned.");
195 if (uf_info->urfset & (UCC_FAST_VIRT_FIFO_REGS_ALIGNMENT - 1)) {
197 ("ucc_fast_init: Virtual Fifo register urfset not aligned.");
201 if (uf_info->utfs & (UCC_FAST_VIRT_FIFO_REGS_ALIGNMENT - 1)) {
203 ("ucc_fast_init: Virtual Fifo register utfs not aligned.");
207 if (uf_info->utfet & (UCC_FAST_VIRT_FIFO_REGS_ALIGNMENT - 1)) {
209 ("ucc_fast_init: Virtual Fifo register utfet not aligned.");
213 if (uf_info->utftt & (UCC_FAST_VIRT_FIFO_REGS_ALIGNMENT - 1)) {
215 ("ucc_fast_init: Virtual Fifo register utftt not aligned.");
219 uccf = kzalloc(sizeof(struct ucc_fast_private), GFP_KERNEL);
222 ("ucc_fast_init: No memory for UCC slow data structure!");
226 /* Fill fast UCC structure */
227 uccf->uf_info = uf_info;
228 /* Set the PHY base address */
230 (struct ucc_fast *) ioremap(uf_info->regs, sizeof(struct ucc_fast));
231 if (uccf->uf_regs == NULL) {
233 ("ucc_fast_init: No memory map for UCC slow controller!");
237 uccf->enabled_tx = 0;
238 uccf->enabled_rx = 0;
239 uccf->stopped_tx = 0;
240 uccf->stopped_rx = 0;
241 uf_regs = uccf->uf_regs;
242 uccf->p_ucce = (u32 *) & (uf_regs->ucce);
243 uccf->p_uccm = (u32 *) & (uf_regs->uccm);
247 uccf->rx_discarded = 0;
248 #endif /* STATISTICS */
250 /* Init Guemr register */
251 if ((ret = ucc_init_guemr((struct ucc_common *) (uf_regs)))) {
252 uccf_err("ucc_fast_init: Could not init the guemr register.");
257 /* Set UCC to fast type */
258 if ((ret = ucc_set_type(uf_info->ucc_num,
259 (struct ucc_common *) (uf_regs),
260 UCC_SPEED_TYPE_FAST))) {
261 uccf_err("ucc_fast_init: Could not set type to fast.");
266 uccf->mrblr = uf_info->max_rx_buf_length;
269 /* For more details see the hardware spec. */
270 /* gumr starts as zero. */
272 gumr |= UCC_FAST_GUMR_TCI;
273 gumr |= uf_info->ttx_trx;
275 gumr |= UCC_FAST_GUMR_CDP;
277 gumr |= UCC_FAST_GUMR_CTSP;
279 gumr |= UCC_FAST_GUMR_CDS;
281 gumr |= UCC_FAST_GUMR_CTSS;
283 gumr |= UCC_FAST_GUMR_TXSY;
285 gumr |= UCC_FAST_GUMR_RSYN;
286 gumr |= uf_info->synl;
288 gumr |= UCC_FAST_GUMR_RTSM;
289 gumr |= uf_info->renc;
291 gumr |= UCC_FAST_GUMR_REVD;
292 gumr |= uf_info->tenc;
293 gumr |= uf_info->tcrc;
294 gumr |= uf_info->mode;
295 out_be32(&uf_regs->gumr, gumr);
297 /* Allocate memory for Tx Virtual Fifo */
298 uccf->ucc_fast_tx_virtual_fifo_base_offset =
299 qe_muram_alloc(uf_info->utfs, UCC_FAST_VIRT_FIFO_REGS_ALIGNMENT);
300 if (IS_MURAM_ERR(uccf->ucc_fast_tx_virtual_fifo_base_offset)) {
302 ("ucc_fast_init: Can not allocate MURAM memory for "
303 "struct ucc_fastx_virtual_fifo_base_offset.");
304 uccf->ucc_fast_tx_virtual_fifo_base_offset = 0;
309 /* Allocate memory for Rx Virtual Fifo */
310 uccf->ucc_fast_rx_virtual_fifo_base_offset =
311 qe_muram_alloc(uf_info->urfs +
313 UCC_FAST_RECEIVE_VIRTUAL_FIFO_SIZE_FUDGE_FACTOR,
314 UCC_FAST_VIRT_FIFO_REGS_ALIGNMENT);
315 if (IS_MURAM_ERR(uccf->ucc_fast_rx_virtual_fifo_base_offset)) {
317 ("ucc_fast_init: Can not allocate MURAM memory for "
318 "ucc_fast_rx_virtual_fifo_base_offset.");
319 uccf->ucc_fast_rx_virtual_fifo_base_offset = 0;
324 /* Set Virtual Fifo registers */
325 out_be16(&uf_regs->urfs, uf_info->urfs);
326 out_be16(&uf_regs->urfet, uf_info->urfet);
327 out_be16(&uf_regs->urfset, uf_info->urfset);
328 out_be16(&uf_regs->utfs, uf_info->utfs);
329 out_be16(&uf_regs->utfet, uf_info->utfet);
330 out_be16(&uf_regs->utftt, uf_info->utftt);
331 /* utfb, urfb are offsets from MURAM base */
332 out_be32(&uf_regs->utfb, uccf->ucc_fast_tx_virtual_fifo_base_offset);
333 out_be32(&uf_regs->urfb, uccf->ucc_fast_rx_virtual_fifo_base_offset);
337 ucc_set_qe_mux_grant(uf_info->ucc_num, uf_info->grant_support);
338 /* Breakpoint Support */
339 ucc_set_qe_mux_bkpt(uf_info->ucc_num, uf_info->brkpt_support);
340 /* Set Tsa or NMSI mode. */
341 ucc_set_qe_mux_tsa(uf_info->ucc_num, uf_info->tsa);
342 /* If NMSI (not Tsa), set Tx and Rx clock. */
344 /* Rx clock routing */
345 if (uf_info->rx_clock != QE_CLK_NONE) {
346 if (ucc_set_qe_mux_rxtx
347 (uf_info->ucc_num, uf_info->rx_clock,
350 ("ucc_fast_init: Illegal value for parameter 'RxClock'.");
355 /* Tx clock routing */
356 if (uf_info->tx_clock != QE_CLK_NONE) {
357 if (ucc_set_qe_mux_rxtx
358 (uf_info->ucc_num, uf_info->tx_clock,
361 ("ucc_fast_init: Illegal value for parameter 'TxClock'.");
368 /* Set interrupt mask register at UCC level. */
369 out_be32(&uf_regs->uccm, uf_info->uccm_mask);
371 /* First, clear anything pending at UCC level,
372 * otherwise, old garbage may come through
373 * as soon as the dam is opened
376 out_be32(&uf_regs->ucce, 0xffffffff);
382 void ucc_fast_free(struct ucc_fast_private * uccf)
387 if (uccf->ucc_fast_tx_virtual_fifo_base_offset)
388 qe_muram_free(uccf->ucc_fast_tx_virtual_fifo_base_offset);
390 if (uccf->ucc_fast_rx_virtual_fifo_base_offset)
391 qe_muram_free(uccf->ucc_fast_rx_virtual_fifo_base_offset);