blob: e5c5fcf27b97df40f76af5cd5496fa645d42ef88 [file] [log] [blame]
wdenk121cb962002-10-07 19:37:29 +00001/*
2 * This file is based on "arch/ppc/8260_io/commproc.c" - here is it's
3 * copyright notice:
4 *
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)
9 * 2.3.99 Updates
10 *
11 * In addition to the individual control of the communication
12 * channels, there are a few functions that globally affect the
13 * communication processor.
14 *
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.
19 */
20#include <common.h>
21#include <asm/cpm_8260.h>
22
wdenk121cb962002-10-07 19:37:29 +000023void
24m8260_cpm_reset(void)
25{
26 DECLARE_GLOBAL_DATA_PTR;
27
28 volatile immap_t *immr = (immap_t *)CFG_IMMR;
29 volatile ulong count;
30
31 /* Reclaim the DP memory for our use.
32 */
33 gd->dp_alloc_base = CPM_DATAONLY_BASE;
34 gd->dp_alloc_top = gd->dp_alloc_base + CPM_DATAONLY_SIZE;
35
36 /*
37 * Reset CPM
38 */
39 immr->im_cpm.cp_cpcr = CPM_CR_RST;
40 count = 0;
41 do { /* Spin until command processed */
42 __asm__ __volatile__ ("eieio");
43 } while ((immr->im_cpm.cp_cpcr & CPM_CR_FLG) && ++count < 1000000);
44
45#ifdef CONFIG_HARD_I2C
46 *((unsigned short*)(&immr->im_dprambase[PROFF_I2C_BASE])) = 0;
47#endif
48}
49
50/* Allocate some memory from the dual ported ram.
51 * To help protocols with object alignment restrictions, we do that
52 * if they ask.
53 */
54uint
55m8260_cpm_dpalloc(uint size, uint align)
56{
57 DECLARE_GLOBAL_DATA_PTR;
58
59 volatile immap_t *immr = (immap_t *)CFG_IMMR;
60 uint retloc;
61 uint align_mask, off;
62 uint savebase;
63
64 align_mask = align - 1;
65 savebase = gd->dp_alloc_base;
66
67 if ((off = (gd->dp_alloc_base & align_mask)) != 0)
68 gd->dp_alloc_base += (align - off);
69
70 if ((off = size & align_mask) != 0)
71 size += align - off;
72
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!");
76 }
77
78 retloc = gd->dp_alloc_base;
79 gd->dp_alloc_base += size;
80
81 memset((void *)&immr->im_dprambase[retloc], 0, size);
82
83 return(retloc);
84}
85
86/* We also own one page of host buffer space for the allocation of
87 * UART "fifos" and the like.
88 */
89uint
90m8260_cpm_hostalloc(uint size, uint align)
91{
92 /* the host might not even have RAM yet - just use dual port RAM */
93 return (m8260_cpm_dpalloc(size, align));
94}
95
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
102 * is given to us.
103 * Baud rate clocks are zero-based in the driver code (as that maps
104 * to port numbers). Documentation uses 1-based numbering.
105 */
106#define BRG_INT_CLK gd->brg_clk
wdenk8564acf2003-07-14 22:13:32 +0000107#define BRG_UART_CLK (BRG_INT_CLK / 16)
wdenk121cb962002-10-07 19:37:29 +0000108
wdenk8564acf2003-07-14 22:13:32 +0000109/* This function is used by UARTs, or anything else that uses a 16x
wdenk121cb962002-10-07 19:37:29 +0000110 * oversampled clock.
111 */
112void
113m8260_cpm_setbrg(uint brg, uint rate)
114{
115 DECLARE_GLOBAL_DATA_PTR;
116
117 volatile immap_t *immr = (immap_t *)CFG_IMMR;
118 volatile uint *bp;
wdenk8564acf2003-07-14 22:13:32 +0000119 uint cd = BRG_UART_CLK / rate;
wdenk121cb962002-10-07 19:37:29 +0000120
wdenk8564acf2003-07-14 22:13:32 +0000121 if ((BRG_UART_CLK % rate) < (rate / 2))
122 cd--;
wdenk121cb962002-10-07 19:37:29 +0000123 if (brg < 4) {
124 bp = (uint *)&immr->im_brgc1;
125 }
126 else {
127 bp = (uint *)&immr->im_brgc5;
128 brg -= 4;
129 }
130 bp += brg;
wdenk8564acf2003-07-14 22:13:32 +0000131 *bp = (cd << 1) | CPM_BRG_EN;
wdenk121cb962002-10-07 19:37:29 +0000132}
133
134/* This function is used to set high speed synchronous baud rate
135 * clocks.
136 */
137void
138m8260_cpm_fastbrg(uint brg, uint rate, int div16)
139{
140 DECLARE_GLOBAL_DATA_PTR;
141
142 volatile immap_t *immr = (immap_t *)CFG_IMMR;
143 volatile uint *bp;
144
145 /* This is good enough to get SMCs running.....
146 */
147 if (brg < 4) {
148 bp = (uint *)&immr->im_brgc1;
149 }
150 else {
151 bp = (uint *)&immr->im_brgc5;
152 brg -= 4;
153 }
154 bp += brg;
155 *bp = (((((BRG_INT_CLK+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN;
156 if (div16)
157 *bp |= CPM_BRG_DIV16;
158}
159
160/* This function is used to set baud rate generators using an external
161 * clock source and 16x oversampling.
162 */
163
164void
165m8260_cpm_extcbrg(uint brg, uint rate, uint extclk, int pinsel)
166{
167 volatile immap_t *immr = (immap_t *)CFG_IMMR;
168 volatile uint *bp;
169
170 if (brg < 4) {
171 bp = (uint *)&immr->im_brgc1;
172 }
173 else {
174 bp = (uint *)&immr->im_brgc5;
175 brg -= 4;
176 }
177 bp += brg;
178 *bp = ((((((extclk/16)+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN;
179 if (pinsel == 0)
180 *bp |= CPM_BRG_EXTC_CLK3_9;
181 else
182 *bp |= CPM_BRG_EXTC_CLK5_15;
183}
184
wdenkd1cbe852003-06-28 17:24:46 +0000185#if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER)
wdenk121cb962002-10-07 19:37:29 +0000186
187void post_word_store (ulong a)
188{
189 volatile ulong *save_addr =
190 (volatile ulong *)(CFG_IMMR + CPM_POST_WORD_ADDR);
191
192 *save_addr = a;
193}
194
195ulong post_word_load (void)
196{
197 volatile ulong *save_addr =
198 (volatile ulong *)(CFG_IMMR + CPM_POST_WORD_ADDR);
199
200 return *save_addr;
201}
202
wdenkd1cbe852003-06-28 17:24:46 +0000203#endif /* CONFIG_POST || CONFIG_LOGBUFFER*/
wdenkbdccc4f2003-08-05 17:43:17 +0000204
205#ifdef CONFIG_BOOTCOUNT_LIMIT
206
207void bootcount_store (ulong a)
208{
209 volatile ulong *save_addr =
210 (volatile ulong *)(CFG_IMMR + CPM_BOOTCOUNT_ADDR);
211
212 save_addr[0] = a;
213 save_addr[1] = BOOTCOUNT_MAGIC;
214}
215
216ulong bootcount_load (void)
217{
218 volatile ulong *save_addr =
219 (volatile ulong *)(CFG_IMMR + CPM_BOOTCOUNT_ADDR);
220
221 if (save_addr[1] != BOOTCOUNT_MAGIC)
222 return 0;
223 else
224 return save_addr[0];
225}
226
227#endif /* CONFIG_BOOTCOUNT_LIMIT */