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>
24 * because we have stack and init data in dual port ram
25 * we must reduce the size
27 #undef CPM_DATAONLY_SIZE
28 #define CPM_DATAONLY_SIZE ((uint)(8 * 1024) - CPM_DATAONLY_BASE)
33 DECLARE_GLOBAL_DATA_PTR;
35 volatile immap_t *immr = (immap_t *)CFG_IMMR;
38 /* Reclaim the DP memory for our use.
40 gd->dp_alloc_base = CPM_DATAONLY_BASE;
41 gd->dp_alloc_top = gd->dp_alloc_base + CPM_DATAONLY_SIZE;
46 immr->im_cpm.cp_cpcr = CPM_CR_RST;
48 do { /* Spin until command processed */
49 __asm__ __volatile__ ("eieio");
50 } while ((immr->im_cpm.cp_cpcr & CPM_CR_FLG) && ++count < 1000000);
52 #ifdef CONFIG_HARD_I2C
53 *((unsigned short*)(&immr->im_dprambase[PROFF_I2C_BASE])) = 0;
57 /* Allocate some memory from the dual ported ram.
58 * To help protocols with object alignment restrictions, we do that
62 m8260_cpm_dpalloc(uint size, uint align)
64 DECLARE_GLOBAL_DATA_PTR;
66 volatile immap_t *immr = (immap_t *)CFG_IMMR;
71 align_mask = align - 1;
72 savebase = gd->dp_alloc_base;
74 if ((off = (gd->dp_alloc_base & align_mask)) != 0)
75 gd->dp_alloc_base += (align - off);
77 if ((off = size & align_mask) != 0)
80 if ((gd->dp_alloc_base + size) >= gd->dp_alloc_top) {
81 gd->dp_alloc_base = savebase;
82 panic("m8260_cpm_dpalloc: ran out of dual port ram!");
85 retloc = gd->dp_alloc_base;
86 gd->dp_alloc_base += size;
88 memset((void *)&immr->im_dprambase[retloc], 0, size);
93 /* We also own one page of host buffer space for the allocation of
94 * UART "fifos" and the like.
97 m8260_cpm_hostalloc(uint size, uint align)
99 /* the host might not even have RAM yet - just use dual port RAM */
100 return (m8260_cpm_dpalloc(size, align));
103 /* Set a baud rate generator. This needs lots of work. There are
104 * eight BRGs, which can be connected to the CPM channels or output
105 * as clocks. The BRGs are in two different block of internal
106 * memory mapped space.
107 * The baud rate clock is the system clock divided by something.
108 * It was set up long ago during the initial boot phase and is
110 * Baud rate clocks are zero-based in the driver code (as that maps
111 * to port numbers). Documentation uses 1-based numbering.
113 #define BRG_INT_CLK gd->brg_clk
114 #define BRG_UART_CLK (BRG_INT_CLK / 16)
116 /* This function is used by UARTs, or anything else that uses a 16x
120 m8260_cpm_setbrg(uint brg, uint rate)
122 DECLARE_GLOBAL_DATA_PTR;
124 volatile immap_t *immr = (immap_t *)CFG_IMMR;
126 uint cd = BRG_UART_CLK / rate;
128 if ((BRG_UART_CLK % rate) < (rate / 2))
131 bp = (uint *)&immr->im_brgc1;
134 bp = (uint *)&immr->im_brgc5;
138 *bp = (cd << 1) | CPM_BRG_EN;
141 /* This function is used to set high speed synchronous baud rate
145 m8260_cpm_fastbrg(uint brg, uint rate, int div16)
147 DECLARE_GLOBAL_DATA_PTR;
149 volatile immap_t *immr = (immap_t *)CFG_IMMR;
152 /* This is good enough to get SMCs running.....
155 bp = (uint *)&immr->im_brgc1;
158 bp = (uint *)&immr->im_brgc5;
162 *bp = (((((BRG_INT_CLK+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN;
164 *bp |= CPM_BRG_DIV16;
167 /* This function is used to set baud rate generators using an external
168 * clock source and 16x oversampling.
172 m8260_cpm_extcbrg(uint brg, uint rate, uint extclk, int pinsel)
174 volatile immap_t *immr = (immap_t *)CFG_IMMR;
178 bp = (uint *)&immr->im_brgc1;
181 bp = (uint *)&immr->im_brgc5;
185 *bp = ((((((extclk/16)+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN;
187 *bp |= CPM_BRG_EXTC_CLK3_9;
189 *bp |= CPM_BRG_EXTC_CLK5_15;
192 #if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER)
194 void post_word_store (ulong a)
196 volatile ulong *save_addr =
197 (volatile ulong *)(CFG_IMMR + CPM_POST_WORD_ADDR);
202 ulong post_word_load (void)
204 volatile ulong *save_addr =
205 (volatile ulong *)(CFG_IMMR + CPM_POST_WORD_ADDR);
210 #endif /* CONFIG_POST || CONFIG_LOGBUFFER*/
212 #ifdef CONFIG_BOOTCOUNT_LIMIT
214 void bootcount_store (ulong a)
216 volatile ulong *save_addr =
217 (volatile ulong *)(CFG_IMMR + CPM_BOOTCOUNT_ADDR);
220 save_addr[1] = BOOTCOUNT_MAGIC;
223 ulong bootcount_load (void)
225 volatile ulong *save_addr =
226 (volatile ulong *)(CFG_IMMR + CPM_BOOTCOUNT_ADDR);
228 if (save_addr[1] != BOOTCOUNT_MAGIC)
234 #endif /* CONFIG_BOOTCOUNT_LIMIT */