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 + 15) / 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;
127 /* This is good enough to get SMCs running.....
130 bp = (uint *)&immr->im_brgc1;
133 bp = (uint *)&immr->im_brgc5;
137 *bp = (((((BRG_UART_CLK+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN;
140 /* This function is used to set high speed synchronous baud rate
144 m8260_cpm_fastbrg(uint brg, uint rate, int div16)
146 DECLARE_GLOBAL_DATA_PTR;
148 volatile immap_t *immr = (immap_t *)CFG_IMMR;
151 /* This is good enough to get SMCs running.....
154 bp = (uint *)&immr->im_brgc1;
157 bp = (uint *)&immr->im_brgc5;
161 *bp = (((((BRG_INT_CLK+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN;
163 *bp |= CPM_BRG_DIV16;
166 /* This function is used to set baud rate generators using an external
167 * clock source and 16x oversampling.
171 m8260_cpm_extcbrg(uint brg, uint rate, uint extclk, int pinsel)
173 volatile immap_t *immr = (immap_t *)CFG_IMMR;
177 bp = (uint *)&immr->im_brgc1;
180 bp = (uint *)&immr->im_brgc5;
184 *bp = ((((((extclk/16)+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN;
186 *bp |= CPM_BRG_EXTC_CLK3_9;
188 *bp |= CPM_BRG_EXTC_CLK5_15;
193 void post_word_store (ulong a)
195 volatile ulong *save_addr =
196 (volatile ulong *)(CFG_IMMR + CPM_POST_WORD_ADDR);
201 ulong post_word_load (void)
203 volatile ulong *save_addr =
204 (volatile ulong *)(CFG_IMMR + CPM_POST_WORD_ADDR);
209 #endif /* CONFIG_POST */