2 * This file is based on "arch/powerpc/8260_io/commproc.c" - here is it's
5 * General Purpose functions for the global management of the
6 * 8260 Communication Processor Module.
7 * Copyright (c) 1999 Dan Malek (dmalek@jlc.net)
8 * Copyright (c) 2000 MontaVista Software, Inc (source@mvista.com)
11 * In addition to the individual control of the communication
12 * channels, there are a few functions that globally affect the
13 * communication processor.
15 * Buffer descriptors must be allocated from the dual ported memory
16 * space. The allocator for that is here. When the communication
17 * process is reset, we reclaim the memory available. There is
18 * currently no deallocator for this memory.
21 #include <asm/cpm_8260.h>
23 DECLARE_GLOBAL_DATA_PTR;
28 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
31 /* Reclaim the DP memory for our use.
33 gd->arch.dp_alloc_base = CPM_DATAONLY_BASE;
34 gd->arch.dp_alloc_top = gd->arch.dp_alloc_base + CPM_DATAONLY_SIZE;
39 immr->im_cpm.cp_cpcr = CPM_CR_RST;
41 do { /* Spin until command processed */
42 __asm__ __volatile__ ("eieio");
43 } while ((immr->im_cpm.cp_cpcr & CPM_CR_FLG) && ++count < 1000000);
45 #ifdef CONFIG_HARD_I2C
46 *((unsigned short*)(&immr->im_dprambase[PROFF_I2C_BASE])) = 0;
50 /* Allocate some memory from the dual ported ram.
51 * To help protocols with object alignment restrictions, we do that
55 m8260_cpm_dpalloc(uint size, uint align)
57 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
62 align_mask = align - 1;
63 savebase = gd->arch.dp_alloc_base;
65 off = gd->arch.dp_alloc_base & align_mask;
67 gd->arch.dp_alloc_base += (align - off);
69 if ((off = size & align_mask) != 0)
72 if ((gd->arch.dp_alloc_base + size) >= gd->arch.dp_alloc_top) {
73 gd->arch.dp_alloc_base = savebase;
74 panic("m8260_cpm_dpalloc: ran out of dual port ram!");
77 retloc = gd->arch.dp_alloc_base;
78 gd->arch.dp_alloc_base += size;
80 memset((void *)&immr->im_dprambase[retloc], 0, size);
85 /* We also own one page of host buffer space for the allocation of
86 * UART "fifos" and the like.
89 m8260_cpm_hostalloc(uint size, uint align)
91 /* the host might not even have RAM yet - just use dual port RAM */
92 return (m8260_cpm_dpalloc(size, align));
95 /* Set a baud rate generator. This needs lots of work. There are
96 * eight BRGs, which can be connected to the CPM channels or output
97 * as clocks. The BRGs are in two different block of internal
98 * memory mapped space.
99 * The baud rate clock is the system clock divided by something.
100 * It was set up long ago during the initial boot phase and is
102 * Baud rate clocks are zero-based in the driver code (as that maps
103 * to port numbers). Documentation uses 1-based numbering.
105 #define BRG_INT_CLK gd->arch.brg_clk
106 #define BRG_UART_CLK (BRG_INT_CLK / 16)
108 /* This function is used by UARTs, or anything else that uses a 16x
112 m8260_cpm_setbrg(uint brg, uint rate)
114 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
116 uint cd = BRG_UART_CLK / rate;
118 if ((BRG_UART_CLK % rate) < (rate / 2))
121 bp = (uint *)&immr->im_brgc1;
124 bp = (uint *)&immr->im_brgc5;
128 *bp = (cd << 1) | CPM_BRG_EN;
131 /* This function is used to set high speed synchronous baud rate
135 m8260_cpm_fastbrg(uint brg, uint rate, int div16)
137 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
140 /* This is good enough to get SMCs running.....
143 bp = (uint *)&immr->im_brgc1;
146 bp = (uint *)&immr->im_brgc5;
150 *bp = (((((BRG_INT_CLK+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN;
152 *bp |= CPM_BRG_DIV16;
155 /* This function is used to set baud rate generators using an external
156 * clock source and 16x oversampling.
160 m8260_cpm_extcbrg(uint brg, uint rate, uint extclk, int pinsel)
162 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
166 bp = (uint *)&immr->im_brgc1;
169 bp = (uint *)&immr->im_brgc5;
173 *bp = ((((((extclk/16)+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN;
175 *bp |= CPM_BRG_EXTC_CLK3_9;
177 *bp |= CPM_BRG_EXTC_CLK5_15;