2 * General Purpose functions for the global management of the
3 * 8260 Communication Processor Module.
8 * 2006 (c) MontaVista Software, Inc.
10 * Merged to arch/powerpc from arch/ppc/syslib/cpm2_common.c
12 * This file is licensed under the terms of the GNU General Public License
13 * version 2. This program is licensed "as is" without any warranty of any
14 * kind, whether express or implied.
19 * In addition to the individual control of the communication
20 * channels, there are a few functions that globally affect the
21 * communication processor.
23 * Buffer descriptors must be allocated from the dual ported memory
24 * space. The allocator for that is here. When the communication
25 * process is reset, we reclaim the memory available. There is
26 * currently no deallocator for this memory.
28 #include <linux/errno.h>
29 #include <linux/sched.h>
30 #include <linux/kernel.h>
31 #include <linux/param.h>
32 #include <linux/string.h>
34 #include <linux/interrupt.h>
35 #include <linux/module.h>
40 #include <asm/mpc8260.h>
42 #include <asm/pgtable.h>
44 #include <asm/rheap.h>
45 #include <asm/fs_pd.h>
47 #include <sysdev/fsl_soc.h>
49 cpm_cpm2_t __iomem *cpmp; /* Pointer to comm processor space */
51 /* We allocate this here because it is used almost exclusively for
52 * the communication processor devices.
54 cpm2_map_t __iomem *cpm2_immr;
55 EXPORT_SYMBOL(cpm2_immr);
57 #define CPM_MAP_SIZE (0x40000) /* 256k - the PQ3 reserve this amount
58 of space for CPM as it is larger
61 void __init cpm2_reset(void)
63 #ifdef CONFIG_PPC_85xx
64 cpm2_immr = ioremap(get_immrbase() + 0x80000, CPM_MAP_SIZE);
66 cpm2_immr = ioremap(get_immrbase(), CPM_MAP_SIZE);
69 /* Tell everyone where the comm processor resides.
71 cpmp = &cpm2_immr->im_cpm;
73 #ifndef CONFIG_PPC_EARLY_DEBUG_CPM
76 cpm_command(CPM_CR_RST, 0);
80 static DEFINE_SPINLOCK(cmd_lock);
82 #define MAX_CR_CMD_LOOPS 10000
84 int cpm_command(u32 command, u8 opcode)
89 spin_lock_irqsave(&cmd_lock, flags);
92 out_be32(&cpmp->cp_cpcr, command | opcode | CPM_CR_FLG);
93 for (i = 0; i < MAX_CR_CMD_LOOPS; i++)
94 if ((in_be32(&cpmp->cp_cpcr) & CPM_CR_FLG) == 0)
97 printk(KERN_ERR "%s(): Not able to issue CPM command\n", __func__);
100 spin_unlock_irqrestore(&cmd_lock, flags);
103 EXPORT_SYMBOL(cpm_command);
105 /* Set a baud rate generator. This needs lots of work. There are
106 * eight BRGs, which can be connected to the CPM channels or output
107 * as clocks. The BRGs are in two different block of internal
108 * memory mapped space.
109 * The baud rate clock is the system clock divided by something.
110 * It was set up long ago during the initial boot phase and is
112 * Baud rate clocks are zero-based in the driver code (as that maps
113 * to port numbers). Documentation uses 1-based numbering.
115 void __cpm2_setbrg(uint brg, uint rate, uint clk, int div16, int src)
120 /* This is good enough to get SMCs running.....
123 bp = cpm2_map_size(im_brgc1, 16);
125 bp = cpm2_map_size(im_brgc5, 16);
129 /* Round the clock divider to the nearest integer. */
130 val = (((clk * 2 / rate) - 1) & ~1) | CPM_BRG_EN | src;
132 val |= CPM_BRG_DIV16;
137 EXPORT_SYMBOL(__cpm2_setbrg);
139 int cpm2_clk_setup(enum cpm_clk_target target, int clock, int mode)
144 cpmux_t __iomem *im_cpmux;
149 {CPM_CLK_FCC1, CPM_BRG5, 0},
150 {CPM_CLK_FCC1, CPM_BRG6, 1},
151 {CPM_CLK_FCC1, CPM_BRG7, 2},
152 {CPM_CLK_FCC1, CPM_BRG8, 3},
153 {CPM_CLK_FCC1, CPM_CLK9, 4},
154 {CPM_CLK_FCC1, CPM_CLK10, 5},
155 {CPM_CLK_FCC1, CPM_CLK11, 6},
156 {CPM_CLK_FCC1, CPM_CLK12, 7},
157 {CPM_CLK_FCC2, CPM_BRG5, 0},
158 {CPM_CLK_FCC2, CPM_BRG6, 1},
159 {CPM_CLK_FCC2, CPM_BRG7, 2},
160 {CPM_CLK_FCC2, CPM_BRG8, 3},
161 {CPM_CLK_FCC2, CPM_CLK13, 4},
162 {CPM_CLK_FCC2, CPM_CLK14, 5},
163 {CPM_CLK_FCC2, CPM_CLK15, 6},
164 {CPM_CLK_FCC2, CPM_CLK16, 7},
165 {CPM_CLK_FCC3, CPM_BRG5, 0},
166 {CPM_CLK_FCC3, CPM_BRG6, 1},
167 {CPM_CLK_FCC3, CPM_BRG7, 2},
168 {CPM_CLK_FCC3, CPM_BRG8, 3},
169 {CPM_CLK_FCC3, CPM_CLK13, 4},
170 {CPM_CLK_FCC3, CPM_CLK14, 5},
171 {CPM_CLK_FCC3, CPM_CLK15, 6},
172 {CPM_CLK_FCC3, CPM_CLK16, 7},
173 {CPM_CLK_SCC1, CPM_BRG1, 0},
174 {CPM_CLK_SCC1, CPM_BRG2, 1},
175 {CPM_CLK_SCC1, CPM_BRG3, 2},
176 {CPM_CLK_SCC1, CPM_BRG4, 3},
177 {CPM_CLK_SCC1, CPM_CLK11, 4},
178 {CPM_CLK_SCC1, CPM_CLK12, 5},
179 {CPM_CLK_SCC1, CPM_CLK3, 6},
180 {CPM_CLK_SCC1, CPM_CLK4, 7},
181 {CPM_CLK_SCC2, CPM_BRG1, 0},
182 {CPM_CLK_SCC2, CPM_BRG2, 1},
183 {CPM_CLK_SCC2, CPM_BRG3, 2},
184 {CPM_CLK_SCC2, CPM_BRG4, 3},
185 {CPM_CLK_SCC2, CPM_CLK11, 4},
186 {CPM_CLK_SCC2, CPM_CLK12, 5},
187 {CPM_CLK_SCC2, CPM_CLK3, 6},
188 {CPM_CLK_SCC2, CPM_CLK4, 7},
189 {CPM_CLK_SCC3, CPM_BRG1, 0},
190 {CPM_CLK_SCC3, CPM_BRG2, 1},
191 {CPM_CLK_SCC3, CPM_BRG3, 2},
192 {CPM_CLK_SCC3, CPM_BRG4, 3},
193 {CPM_CLK_SCC3, CPM_CLK5, 4},
194 {CPM_CLK_SCC3, CPM_CLK6, 5},
195 {CPM_CLK_SCC3, CPM_CLK7, 6},
196 {CPM_CLK_SCC3, CPM_CLK8, 7},
197 {CPM_CLK_SCC4, CPM_BRG1, 0},
198 {CPM_CLK_SCC4, CPM_BRG2, 1},
199 {CPM_CLK_SCC4, CPM_BRG3, 2},
200 {CPM_CLK_SCC4, CPM_BRG4, 3},
201 {CPM_CLK_SCC4, CPM_CLK5, 4},
202 {CPM_CLK_SCC4, CPM_CLK6, 5},
203 {CPM_CLK_SCC4, CPM_CLK7, 6},
204 {CPM_CLK_SCC4, CPM_CLK8, 7},
207 im_cpmux = cpm2_map(im_cpmux);
211 reg = &im_cpmux->cmx_scr;
215 reg = &im_cpmux->cmx_scr;
219 reg = &im_cpmux->cmx_scr;
223 reg = &im_cpmux->cmx_scr;
227 reg = &im_cpmux->cmx_fcr;
231 reg = &im_cpmux->cmx_fcr;
235 reg = &im_cpmux->cmx_fcr;
239 printk(KERN_ERR "cpm2_clock_setup: invalid clock target\n");
243 for (i = 0; i < ARRAY_SIZE(clk_map); i++) {
244 if (clk_map[i][0] == target && clk_map[i][1] == clock) {
245 bits = clk_map[i][2];
249 if (i == ARRAY_SIZE(clk_map))
255 if (mode == CPM_CLK_RTX) {
258 } else if (mode == CPM_CLK_RX) {
263 out_be32(reg, (in_be32(reg) & ~mask) | bits);
265 cpm2_unmap(im_cpmux);
269 int cpm2_smc_clk_setup(enum cpm_clk_target target, int clock)
274 cpmux_t __iomem *im_cpmux;
279 {CPM_CLK_SMC1, CPM_BRG1, 0},
280 {CPM_CLK_SMC1, CPM_BRG7, 1},
281 {CPM_CLK_SMC1, CPM_CLK7, 2},
282 {CPM_CLK_SMC1, CPM_CLK9, 3},
283 {CPM_CLK_SMC2, CPM_BRG2, 0},
284 {CPM_CLK_SMC2, CPM_BRG8, 1},
285 {CPM_CLK_SMC2, CPM_CLK4, 2},
286 {CPM_CLK_SMC2, CPM_CLK15, 3},
289 im_cpmux = cpm2_map(im_cpmux);
293 reg = &im_cpmux->cmx_smr;
298 reg = &im_cpmux->cmx_smr;
303 printk(KERN_ERR "cpm2_smc_clock_setup: invalid clock target\n");
307 for (i = 0; i < ARRAY_SIZE(clk_map); i++) {
308 if (clk_map[i][0] == target && clk_map[i][1] == clock) {
309 bits = clk_map[i][2];
313 if (i == ARRAY_SIZE(clk_map))
319 out_8(reg, (in_8(reg) & ~mask) | bits);
321 cpm2_unmap(im_cpmux);
325 struct cpm2_ioports {
326 u32 dir, par, sor, odr, dat;
330 void cpm2_set_pin(int port, int pin, int flags)
332 struct cpm2_ioports __iomem *iop =
333 (struct cpm2_ioports __iomem *)&cpm2_immr->im_ioport;
335 pin = 1 << (31 - pin);
337 if (flags & CPM_PIN_OUTPUT)
338 setbits32(&iop[port].dir, pin);
340 clrbits32(&iop[port].dir, pin);
342 if (!(flags & CPM_PIN_GPIO))
343 setbits32(&iop[port].par, pin);
345 clrbits32(&iop[port].par, pin);
347 if (flags & CPM_PIN_SECONDARY)
348 setbits32(&iop[port].sor, pin);
350 clrbits32(&iop[port].sor, pin);
352 if (flags & CPM_PIN_OPENDRAIN)
353 setbits32(&iop[port].odr, pin);
355 clrbits32(&iop[port].odr, pin);
358 static int cpm_init_par_io(void)
360 struct device_node *np;
362 for_each_compatible_node(np, NULL, "fsl,cpm2-pario-bank")
363 cpm2_gpiochip_add32(np);
366 arch_initcall(cpm_init_par_io);