2 * arch/powerpc/sysdev/qe_lib/ucc.c
4 * QE UCC API Set - UCC specific routines implementations.
6 * Copyright (C) 2006 Freescale Semiconductor, 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/errno.h>
18 #include <linux/stddef.h>
19 #include <linux/spinlock.h>
20 #include <linux/export.h>
24 #include <soc/fsl/qe/immap_qe.h>
25 #include <soc/fsl/qe/qe.h>
26 #include <soc/fsl/qe/ucc.h>
29 #define RX_SYNC_SHIFT_BASE 30
30 #define TX_SYNC_SHIFT_BASE 14
31 #define RX_CLK_SHIFT_BASE 28
32 #define TX_CLK_SHIFT_BASE 12
34 int ucc_set_qe_mux_mii_mng(unsigned int ucc_num
)
38 if (ucc_num
> UCC_MAX_NUM
- 1)
41 spin_lock_irqsave(&cmxgcr_lock
, flags
);
42 clrsetbits_be32(&qe_immr
->qmx
.cmxgcr
, QE_CMXGCR_MII_ENET_MNG
,
43 ucc_num
<< QE_CMXGCR_MII_ENET_MNG_SHIFT
);
44 spin_unlock_irqrestore(&cmxgcr_lock
, flags
);
48 EXPORT_SYMBOL(ucc_set_qe_mux_mii_mng
);
50 /* Configure the UCC to either Slow or Fast.
52 * A given UCC can be figured to support either "slow" devices (e.g. UART)
53 * or "fast" devices (e.g. Ethernet).
55 * 'ucc_num' is the UCC number, from 0 - 7.
57 * This function also sets the UCC_GUEMR_SET_RESERVED3 bit because that bit
58 * must always be set to 1.
60 int ucc_set_type(unsigned int ucc_num
, enum ucc_speed_type speed
)
64 /* The GUEMR register is at the same location for both slow and fast
65 devices, so we just use uccX.slow.guemr. */
67 case 0: guemr
= &qe_immr
->ucc1
.slow
.guemr
;
69 case 1: guemr
= &qe_immr
->ucc2
.slow
.guemr
;
71 case 2: guemr
= &qe_immr
->ucc3
.slow
.guemr
;
73 case 3: guemr
= &qe_immr
->ucc4
.slow
.guemr
;
75 case 4: guemr
= &qe_immr
->ucc5
.slow
.guemr
;
77 case 5: guemr
= &qe_immr
->ucc6
.slow
.guemr
;
79 case 6: guemr
= &qe_immr
->ucc7
.slow
.guemr
;
81 case 7: guemr
= &qe_immr
->ucc8
.slow
.guemr
;
87 clrsetbits_8(guemr
, UCC_GUEMR_MODE_MASK
,
88 UCC_GUEMR_SET_RESERVED3
| speed
);
93 static void get_cmxucr_reg(unsigned int ucc_num
, __be32 __iomem
**cmxucr
,
94 unsigned int *reg_num
, unsigned int *shift
)
96 unsigned int cmx
= ((ucc_num
& 1) << 1) + (ucc_num
> 3);
99 *cmxucr
= &qe_immr
->qmx
.cmxucr
[cmx
];
100 *shift
= 16 - 8 * (ucc_num
& 2);
103 int ucc_mux_set_grant_tsa_bkpt(unsigned int ucc_num
, int set
, u32 mask
)
105 __be32 __iomem
*cmxucr
;
106 unsigned int reg_num
;
109 /* check if the UCC number is in range. */
110 if (ucc_num
> UCC_MAX_NUM
- 1)
113 get_cmxucr_reg(ucc_num
, &cmxucr
, ®_num
, &shift
);
116 setbits32(cmxucr
, mask
<< shift
);
118 clrbits32(cmxucr
, mask
<< shift
);
123 int ucc_set_qe_mux_rxtx(unsigned int ucc_num
, enum qe_clock clock
,
126 __be32 __iomem
*cmxucr
;
127 unsigned int reg_num
;
131 /* check if the UCC number is in range. */
132 if (ucc_num
> UCC_MAX_NUM
- 1)
135 /* The communications direction must be RX or TX */
136 if (!((mode
== COMM_DIR_RX
) || (mode
== COMM_DIR_TX
)))
139 get_cmxucr_reg(ucc_num
, &cmxucr
, ®_num
, &shift
);
144 case QE_BRG1
: clock_bits
= 1; break;
145 case QE_BRG2
: clock_bits
= 2; break;
146 case QE_BRG7
: clock_bits
= 3; break;
147 case QE_BRG8
: clock_bits
= 4; break;
148 case QE_CLK9
: clock_bits
= 5; break;
149 case QE_CLK10
: clock_bits
= 6; break;
150 case QE_CLK11
: clock_bits
= 7; break;
151 case QE_CLK12
: clock_bits
= 8; break;
152 case QE_CLK15
: clock_bits
= 9; break;
153 case QE_CLK16
: clock_bits
= 10; break;
159 case QE_BRG5
: clock_bits
= 1; break;
160 case QE_BRG6
: clock_bits
= 2; break;
161 case QE_BRG7
: clock_bits
= 3; break;
162 case QE_BRG8
: clock_bits
= 4; break;
163 case QE_CLK13
: clock_bits
= 5; break;
164 case QE_CLK14
: clock_bits
= 6; break;
165 case QE_CLK19
: clock_bits
= 7; break;
166 case QE_CLK20
: clock_bits
= 8; break;
167 case QE_CLK15
: clock_bits
= 9; break;
168 case QE_CLK16
: clock_bits
= 10; break;
174 case QE_BRG9
: clock_bits
= 1; break;
175 case QE_BRG10
: clock_bits
= 2; break;
176 case QE_BRG15
: clock_bits
= 3; break;
177 case QE_BRG16
: clock_bits
= 4; break;
178 case QE_CLK3
: clock_bits
= 5; break;
179 case QE_CLK4
: clock_bits
= 6; break;
180 case QE_CLK17
: clock_bits
= 7; break;
181 case QE_CLK18
: clock_bits
= 8; break;
182 case QE_CLK7
: clock_bits
= 9; break;
183 case QE_CLK8
: clock_bits
= 10; break;
184 case QE_CLK16
: clock_bits
= 11; break;
190 case QE_BRG13
: clock_bits
= 1; break;
191 case QE_BRG14
: clock_bits
= 2; break;
192 case QE_BRG15
: clock_bits
= 3; break;
193 case QE_BRG16
: clock_bits
= 4; break;
194 case QE_CLK5
: clock_bits
= 5; break;
195 case QE_CLK6
: clock_bits
= 6; break;
196 case QE_CLK21
: clock_bits
= 7; break;
197 case QE_CLK22
: clock_bits
= 8; break;
198 case QE_CLK7
: clock_bits
= 9; break;
199 case QE_CLK8
: clock_bits
= 10; break;
200 case QE_CLK16
: clock_bits
= 11; break;
207 /* Check for invalid combination of clock and UCC number */
211 if (mode
== COMM_DIR_RX
)
214 clrsetbits_be32(cmxucr
, QE_CMXUCR_TX_CLK_SRC_MASK
<< shift
,
215 clock_bits
<< shift
);
220 static int ucc_get_tdm_common_clk(u32 tdm_num
, enum qe_clock clock
)
222 int clock_bits
= -EINVAL
;
225 * for TDM[0, 1, 2, 3], TX and RX use common
226 * clock source BRG3,4 and CLK1,2
227 * for TDM[4, 5, 6, 7], TX and RX use common
228 * clock source BRG12,13 and CLK23,24
280 static int ucc_get_tdm_rx_clk(u32 tdm_num
, enum qe_clock clock
)
282 int clock_bits
= -EINVAL
;
386 static int ucc_get_tdm_tx_clk(u32 tdm_num
, enum qe_clock clock
)
388 int clock_bits
= -EINVAL
;
492 /* tdm_num: TDM A-H port num is 0-7 */
493 static int ucc_get_tdm_rxtx_clk(enum comm_dir mode
, u32 tdm_num
,
498 clock_bits
= ucc_get_tdm_common_clk(tdm_num
, clock
);
501 if (mode
== COMM_DIR_RX
)
502 clock_bits
= ucc_get_tdm_rx_clk(tdm_num
, clock
);
503 if (mode
== COMM_DIR_TX
)
504 clock_bits
= ucc_get_tdm_tx_clk(tdm_num
, clock
);
508 static u32
ucc_get_tdm_clk_shift(enum comm_dir mode
, u32 tdm_num
)
512 shift
= (mode
== COMM_DIR_RX
) ? RX_CLK_SHIFT_BASE
: TX_CLK_SHIFT_BASE
;
514 shift
-= tdm_num
* 4;
516 shift
-= (tdm_num
- 4) * 4;
521 int ucc_set_tdm_rxtx_clk(u32 tdm_num
, enum qe_clock clock
,
526 struct qe_mux __iomem
*qe_mux_reg
;
527 __be32 __iomem
*cmxs1cr
;
529 qe_mux_reg
= &qe_immr
->qmx
;
531 if (tdm_num
> 7 || tdm_num
< 0)
534 /* The communications direction must be RX or TX */
535 if (mode
!= COMM_DIR_RX
&& mode
!= COMM_DIR_TX
)
538 clock_bits
= ucc_get_tdm_rxtx_clk(mode
, tdm_num
, clock
);
542 shift
= ucc_get_tdm_clk_shift(mode
, tdm_num
);
544 cmxs1cr
= (tdm_num
< 4) ? &qe_mux_reg
->cmxsi1cr_l
:
545 &qe_mux_reg
->cmxsi1cr_h
;
547 qe_clrsetbits32(cmxs1cr
, QE_CMXUCR_TX_CLK_SRC_MASK
<< shift
,
548 clock_bits
<< shift
);
553 static int ucc_get_tdm_sync_source(u32 tdm_num
, enum qe_clock clock
,
556 int source
= -EINVAL
;
558 if (mode
== COMM_DIR_RX
&& clock
== QE_RSYNC_PIN
) {
562 if (mode
== COMM_DIR_TX
&& clock
== QE_TSYNC_PIN
) {
625 static u32
ucc_get_tdm_sync_shift(enum comm_dir mode
, u32 tdm_num
)
629 shift
= (mode
== COMM_DIR_RX
) ? RX_SYNC_SHIFT_BASE
: RX_SYNC_SHIFT_BASE
;
630 shift
-= tdm_num
* 2;
635 int ucc_set_tdm_rxtx_sync(u32 tdm_num
, enum qe_clock clock
,
640 struct qe_mux
*qe_mux_reg
;
642 qe_mux_reg
= &qe_immr
->qmx
;
644 if (tdm_num
>= UCC_TDM_NUM
)
647 /* The communications direction must be RX or TX */
648 if (mode
!= COMM_DIR_RX
&& mode
!= COMM_DIR_TX
)
651 source
= ucc_get_tdm_sync_source(tdm_num
, clock
, mode
);
655 shift
= ucc_get_tdm_sync_shift(mode
, tdm_num
);
657 qe_clrsetbits32(&qe_mux_reg
->cmxsi1syr
,
658 QE_CMXUCR_TX_CLK_SRC_MASK
<< shift
,