wdenk | 121cb96 | 2002-10-07 19:37:29 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 23 | /* |
| 24 | * because we have stack and init data in dual port ram |
| 25 | * we must reduce the size |
| 26 | */ |
| 27 | #undef CPM_DATAONLY_SIZE |
| 28 | #define CPM_DATAONLY_SIZE ((uint)(8 * 1024) - CPM_DATAONLY_BASE) |
| 29 | |
| 30 | void |
| 31 | m8260_cpm_reset(void) |
| 32 | { |
| 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
| 35 | volatile immap_t *immr = (immap_t *)CFG_IMMR; |
| 36 | volatile ulong count; |
| 37 | |
| 38 | /* Reclaim the DP memory for our use. |
| 39 | */ |
| 40 | gd->dp_alloc_base = CPM_DATAONLY_BASE; |
| 41 | gd->dp_alloc_top = gd->dp_alloc_base + CPM_DATAONLY_SIZE; |
| 42 | |
| 43 | /* |
| 44 | * Reset CPM |
| 45 | */ |
| 46 | immr->im_cpm.cp_cpcr = CPM_CR_RST; |
| 47 | count = 0; |
| 48 | do { /* Spin until command processed */ |
| 49 | __asm__ __volatile__ ("eieio"); |
| 50 | } while ((immr->im_cpm.cp_cpcr & CPM_CR_FLG) && ++count < 1000000); |
| 51 | |
| 52 | #ifdef CONFIG_HARD_I2C |
| 53 | *((unsigned short*)(&immr->im_dprambase[PROFF_I2C_BASE])) = 0; |
| 54 | #endif |
| 55 | } |
| 56 | |
| 57 | /* Allocate some memory from the dual ported ram. |
| 58 | * To help protocols with object alignment restrictions, we do that |
| 59 | * if they ask. |
| 60 | */ |
| 61 | uint |
| 62 | m8260_cpm_dpalloc(uint size, uint align) |
| 63 | { |
| 64 | DECLARE_GLOBAL_DATA_PTR; |
| 65 | |
| 66 | volatile immap_t *immr = (immap_t *)CFG_IMMR; |
| 67 | uint retloc; |
| 68 | uint align_mask, off; |
| 69 | uint savebase; |
| 70 | |
| 71 | align_mask = align - 1; |
| 72 | savebase = gd->dp_alloc_base; |
| 73 | |
| 74 | if ((off = (gd->dp_alloc_base & align_mask)) != 0) |
| 75 | gd->dp_alloc_base += (align - off); |
| 76 | |
| 77 | if ((off = size & align_mask) != 0) |
| 78 | size += align - off; |
| 79 | |
| 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!"); |
| 83 | } |
| 84 | |
| 85 | retloc = gd->dp_alloc_base; |
| 86 | gd->dp_alloc_base += size; |
| 87 | |
| 88 | memset((void *)&immr->im_dprambase[retloc], 0, size); |
| 89 | |
| 90 | return(retloc); |
| 91 | } |
| 92 | |
| 93 | /* We also own one page of host buffer space for the allocation of |
| 94 | * UART "fifos" and the like. |
| 95 | */ |
| 96 | uint |
| 97 | m8260_cpm_hostalloc(uint size, uint align) |
| 98 | { |
| 99 | /* the host might not even have RAM yet - just use dual port RAM */ |
| 100 | return (m8260_cpm_dpalloc(size, align)); |
| 101 | } |
| 102 | |
| 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 |
| 109 | * is given to us. |
| 110 | * Baud rate clocks are zero-based in the driver code (as that maps |
| 111 | * to port numbers). Documentation uses 1-based numbering. |
| 112 | */ |
| 113 | #define BRG_INT_CLK gd->brg_clk |
| 114 | #define BRG_UART_CLK ((BRG_INT_CLK + 15) / 16) |
| 115 | |
| 116 | /* This function is used by UARTS, or anything else that uses a 16x |
| 117 | * oversampled clock. |
| 118 | */ |
| 119 | void |
| 120 | m8260_cpm_setbrg(uint brg, uint rate) |
| 121 | { |
| 122 | DECLARE_GLOBAL_DATA_PTR; |
| 123 | |
| 124 | volatile immap_t *immr = (immap_t *)CFG_IMMR; |
| 125 | volatile uint *bp; |
| 126 | |
| 127 | /* This is good enough to get SMCs running..... |
| 128 | */ |
| 129 | if (brg < 4) { |
| 130 | bp = (uint *)&immr->im_brgc1; |
| 131 | } |
| 132 | else { |
| 133 | bp = (uint *)&immr->im_brgc5; |
| 134 | brg -= 4; |
| 135 | } |
| 136 | bp += brg; |
| 137 | *bp = (((((BRG_UART_CLK+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN; |
| 138 | } |
| 139 | |
| 140 | /* This function is used to set high speed synchronous baud rate |
| 141 | * clocks. |
| 142 | */ |
| 143 | void |
| 144 | m8260_cpm_fastbrg(uint brg, uint rate, int div16) |
| 145 | { |
| 146 | DECLARE_GLOBAL_DATA_PTR; |
| 147 | |
| 148 | volatile immap_t *immr = (immap_t *)CFG_IMMR; |
| 149 | volatile uint *bp; |
| 150 | |
| 151 | /* This is good enough to get SMCs running..... |
| 152 | */ |
| 153 | if (brg < 4) { |
| 154 | bp = (uint *)&immr->im_brgc1; |
| 155 | } |
| 156 | else { |
| 157 | bp = (uint *)&immr->im_brgc5; |
| 158 | brg -= 4; |
| 159 | } |
| 160 | bp += brg; |
| 161 | *bp = (((((BRG_INT_CLK+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN; |
| 162 | if (div16) |
| 163 | *bp |= CPM_BRG_DIV16; |
| 164 | } |
| 165 | |
| 166 | /* This function is used to set baud rate generators using an external |
| 167 | * clock source and 16x oversampling. |
| 168 | */ |
| 169 | |
| 170 | void |
| 171 | m8260_cpm_extcbrg(uint brg, uint rate, uint extclk, int pinsel) |
| 172 | { |
| 173 | volatile immap_t *immr = (immap_t *)CFG_IMMR; |
| 174 | volatile uint *bp; |
| 175 | |
| 176 | if (brg < 4) { |
| 177 | bp = (uint *)&immr->im_brgc1; |
| 178 | } |
| 179 | else { |
| 180 | bp = (uint *)&immr->im_brgc5; |
| 181 | brg -= 4; |
| 182 | } |
| 183 | bp += brg; |
| 184 | *bp = ((((((extclk/16)+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN; |
| 185 | if (pinsel == 0) |
| 186 | *bp |= CPM_BRG_EXTC_CLK3_9; |
| 187 | else |
| 188 | *bp |= CPM_BRG_EXTC_CLK5_15; |
| 189 | } |
| 190 | |
| 191 | #ifdef CONFIG_POST |
| 192 | |
| 193 | void post_word_store (ulong a) |
| 194 | { |
| 195 | volatile ulong *save_addr = |
| 196 | (volatile ulong *)(CFG_IMMR + CPM_POST_WORD_ADDR); |
| 197 | |
| 198 | *save_addr = a; |
| 199 | } |
| 200 | |
| 201 | ulong post_word_load (void) |
| 202 | { |
| 203 | volatile ulong *save_addr = |
| 204 | (volatile ulong *)(CFG_IMMR + CPM_POST_WORD_ADDR); |
| 205 | |
| 206 | return *save_addr; |
| 207 | } |
| 208 | |
| 209 | #endif /* CONFIG_POST */ |