2 * arch/powerpc/sysdev/qe_lib/ucc.c
4 * QE UCC API Set - UCC 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>
24 #include <asm/immap_qe.h>
28 static DEFINE_SPINLOCK(ucc_lock);
30 int ucc_set_qe_mux_mii_mng(int ucc_num)
34 spin_lock_irqsave(&ucc_lock, flags);
35 out_be32(&qe_immr->qmx.cmxgcr,
36 ((in_be32(&qe_immr->qmx.cmxgcr) &
37 ~QE_CMXGCR_MII_ENET_MNG) |
38 (ucc_num << QE_CMXGCR_MII_ENET_MNG_SHIFT)));
39 spin_unlock_irqrestore(&ucc_lock, flags);
44 int ucc_set_type(int ucc_num, struct ucc_common *regs,
45 enum ucc_speed_type speed)
49 /* check if the UCC number is in range. */
50 if ((ucc_num > UCC_MAX_NUM - 1) || (ucc_num < 0))
54 guemr &= ~(UCC_GUEMR_MODE_MASK_RX | UCC_GUEMR_MODE_MASK_TX);
56 case UCC_SPEED_TYPE_SLOW:
57 guemr |= (UCC_GUEMR_MODE_SLOW_RX | UCC_GUEMR_MODE_SLOW_TX);
59 case UCC_SPEED_TYPE_FAST:
60 guemr |= (UCC_GUEMR_MODE_FAST_RX | UCC_GUEMR_MODE_FAST_TX);
70 int ucc_init_guemr(struct ucc_common *regs)
77 /* Set bit 3 (which is reserved in the GUEMR register) to 1 */
78 guemr = UCC_GUEMR_SET_RESERVED3;
85 static void get_cmxucr_reg(int ucc_num, volatile u32 ** p_cmxucr, u8 * reg_num,
89 case 0: *p_cmxucr = &(qe_immr->qmx.cmxucr1);
93 case 2: *p_cmxucr = &(qe_immr->qmx.cmxucr1);
97 case 4: *p_cmxucr = &(qe_immr->qmx.cmxucr2);
101 case 6: *p_cmxucr = &(qe_immr->qmx.cmxucr2);
105 case 1: *p_cmxucr = &(qe_immr->qmx.cmxucr3);
109 case 3: *p_cmxucr = &(qe_immr->qmx.cmxucr3);
113 case 5: *p_cmxucr = &(qe_immr->qmx.cmxucr4);
117 case 7: *p_cmxucr = &(qe_immr->qmx.cmxucr4);
126 int ucc_mux_set_grant_tsa_bkpt(int ucc_num, int set, u32 mask)
128 volatile u32 *p_cmxucr;
132 /* check if the UCC number is in range. */
133 if ((ucc_num > UCC_MAX_NUM - 1) || (ucc_num < 0))
136 get_cmxucr_reg(ucc_num, &p_cmxucr, ®_num, &shift);
139 out_be32(p_cmxucr, in_be32(p_cmxucr) | (mask << shift));
141 out_be32(p_cmxucr, in_be32(p_cmxucr) & ~(mask << shift));
146 int ucc_set_qe_mux_rxtx(int ucc_num, enum qe_clock clock, enum comm_dir mode)
148 volatile u32 *p_cmxucr;
155 /* check if the UCC number is in range. */
156 if ((ucc_num > UCC_MAX_NUM - 1) || (ucc_num < 0))
159 if (!((mode == COMM_DIR_RX) || (mode == COMM_DIR_TX))) {
161 "ucc_set_qe_mux_rxtx: bad comm mode type passed.");
165 get_cmxucr_reg(ucc_num, &p_cmxucr, ®_num, &shift);
170 case QE_BRG1: source = 1; break;
171 case QE_BRG2: source = 2; break;
172 case QE_BRG7: source = 3; break;
173 case QE_BRG8: source = 4; break;
174 case QE_CLK9: source = 5; break;
175 case QE_CLK10: source = 6; break;
176 case QE_CLK11: source = 7; break;
177 case QE_CLK12: source = 8; break;
178 case QE_CLK15: source = 9; break;
179 case QE_CLK16: source = 10; break;
180 default: source = -1; break;
185 case QE_BRG5: source = 1; break;
186 case QE_BRG6: source = 2; break;
187 case QE_BRG7: source = 3; break;
188 case QE_BRG8: source = 4; break;
189 case QE_CLK13: source = 5; break;
190 case QE_CLK14: source = 6; break;
191 case QE_CLK19: source = 7; break;
192 case QE_CLK20: source = 8; break;
193 case QE_CLK15: source = 9; break;
194 case QE_CLK16: source = 10; break;
195 default: source = -1; break;
200 case QE_BRG9: source = 1; break;
201 case QE_BRG10: source = 2; break;
202 case QE_BRG15: source = 3; break;
203 case QE_BRG16: source = 4; break;
204 case QE_CLK3: source = 5; break;
205 case QE_CLK4: source = 6; break;
206 case QE_CLK17: source = 7; break;
207 case QE_CLK18: source = 8; break;
208 case QE_CLK7: source = 9; break;
209 case QE_CLK8: source = 10; break;
210 default: source = -1; break;
215 case QE_BRG13: source = 1; break;
216 case QE_BRG14: source = 2; break;
217 case QE_BRG15: source = 3; break;
218 case QE_BRG16: source = 4; break;
219 case QE_CLK5: source = 5; break;
220 case QE_CLK6: source = 6; break;
221 case QE_CLK21: source = 7; break;
222 case QE_CLK22: source = 8; break;
223 case QE_CLK7: source = 9; break;
224 case QE_CLK8: source = 10; break;
225 default: source = -1; break;
235 "ucc_set_qe_mux_rxtx: Bad combination of clock and UCC.");
239 clock_bits = (u32) source;
240 clock_mask = QE_CMXUCR_TX_CLK_SRC_MASK;
241 if (mode == COMM_DIR_RX) {
242 clock_bits <<= 4; /* Rx field is 4 bits to left of Tx field */
243 clock_mask <<= 4; /* Rx field is 4 bits to left of Tx field */
245 clock_bits <<= shift;
246 clock_mask <<= shift;
248 out_be32(p_cmxucr, (in_be32(p_cmxucr) & ~clock_mask) | clock_bits);