2 * This file is based on "arch/ppc/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>
26 DECLARE_GLOBAL_DATA_PTR;
28 volatile immap_t *immr = (immap_t *)CFG_IMMR;
31 /* Reclaim the DP memory for our use.
33 gd->dp_alloc_base = CPM_DATAONLY_BASE;
34 gd->dp_alloc_top = gd->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 DECLARE_GLOBAL_DATA_PTR;
59 volatile immap_t *immr = (immap_t *)CFG_IMMR;
64 align_mask = align - 1;
65 savebase = gd->dp_alloc_base;
67 if ((off = (gd->dp_alloc_base & align_mask)) != 0)
68 gd->dp_alloc_base += (align - off);
70 if ((off = size & align_mask) != 0)
73 if ((gd->dp_alloc_base + size) >= gd->dp_alloc_top) {
74 gd->dp_alloc_base = savebase;
75 panic("m8260_cpm_dpalloc: ran out of dual port ram!");
78 retloc = gd->dp_alloc_base;
79 gd->dp_alloc_base += size;
81 memset((void *)&immr->im_dprambase[retloc], 0, size);
86 /* We also own one page of host buffer space for the allocation of
87 * UART "fifos" and the like.
90 m8260_cpm_hostalloc(uint size, uint align)
92 /* the host might not even have RAM yet - just use dual port RAM */
93 return (m8260_cpm_dpalloc(size, align));
96 /* Set a baud rate generator. This needs lots of work. There are
97 * eight BRGs, which can be connected to the CPM channels or output
98 * as clocks. The BRGs are in two different block of internal
99 * memory mapped space.
100 * The baud rate clock is the system clock divided by something.
101 * It was set up long ago during the initial boot phase and is
103 * Baud rate clocks are zero-based in the driver code (as that maps
104 * to port numbers). Documentation uses 1-based numbering.
106 #define BRG_INT_CLK gd->brg_clk
107 #define BRG_UART_CLK (BRG_INT_CLK / 16)
109 /* This function is used by UARTs, or anything else that uses a 16x
113 m8260_cpm_setbrg(uint brg, uint rate)
115 DECLARE_GLOBAL_DATA_PTR;
117 volatile immap_t *immr = (immap_t *)CFG_IMMR;
119 uint cd = BRG_UART_CLK / rate;
121 if ((BRG_UART_CLK % rate) < (rate / 2))
124 bp = (uint *)&immr->im_brgc1;
127 bp = (uint *)&immr->im_brgc5;
131 *bp = (cd << 1) | CPM_BRG_EN;
134 /* This function is used to set high speed synchronous baud rate
138 m8260_cpm_fastbrg(uint brg, uint rate, int div16)
140 DECLARE_GLOBAL_DATA_PTR;
142 volatile immap_t *immr = (immap_t *)CFG_IMMR;
145 /* This is good enough to get SMCs running.....
148 bp = (uint *)&immr->im_brgc1;
151 bp = (uint *)&immr->im_brgc5;
155 *bp = (((((BRG_INT_CLK+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN;
157 *bp |= CPM_BRG_DIV16;
160 /* This function is used to set baud rate generators using an external
161 * clock source and 16x oversampling.
165 m8260_cpm_extcbrg(uint brg, uint rate, uint extclk, int pinsel)
167 volatile immap_t *immr = (immap_t *)CFG_IMMR;
171 bp = (uint *)&immr->im_brgc1;
174 bp = (uint *)&immr->im_brgc5;
178 *bp = ((((((extclk/16)+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN;
180 *bp |= CPM_BRG_EXTC_CLK3_9;
182 *bp |= CPM_BRG_EXTC_CLK5_15;
185 #if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER)
187 void post_word_store (ulong a)
189 volatile ulong *save_addr =
190 (volatile ulong *)(CFG_IMMR + CPM_POST_WORD_ADDR);
195 ulong post_word_load (void)
197 volatile ulong *save_addr =
198 (volatile ulong *)(CFG_IMMR + CPM_POST_WORD_ADDR);
203 #endif /* CONFIG_POST || CONFIG_LOGBUFFER*/
205 #ifdef CONFIG_BOOTCOUNT_LIMIT
207 void bootcount_store (ulong a)
209 volatile ulong *save_addr =
210 (volatile ulong *)(CFG_IMMR + CPM_BOOTCOUNT_ADDR);
213 save_addr[1] = BOOTCOUNT_MAGIC;
216 ulong bootcount_load (void)
218 volatile ulong *save_addr =
219 (volatile ulong *)(CFG_IMMR + CPM_BOOTCOUNT_ADDR);
221 if (save_addr[1] != BOOTCOUNT_MAGIC)
227 #endif /* CONFIG_BOOTCOUNT_LIMIT */