wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Adapted for Motorola MPC8560 chips |
| 3 | * Xianghua Xiao <x.xiao@motorola.com> |
| 4 | * |
Stefan Roese | 88fbf93 | 2010-04-15 16:07:28 +0200 | [diff] [blame] | 5 | * This file is based on "arch/powerpc/8260_io/commproc.c" - here is it's |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 6 | * copyright notice: |
| 7 | * |
| 8 | * General Purpose functions for the global management of the |
| 9 | * 8220 Communication Processor Module. |
| 10 | * Copyright (c) 1999 Dan Malek (dmalek@jlc.net) |
| 11 | * Copyright (c) 2000 MontaVista Software, Inc (source@mvista.com) |
| 12 | * 2.3.99 Updates |
| 13 | * Copyright (c) 2003 Motorola,Inc. |
| 14 | * |
| 15 | * In addition to the individual control of the communication |
| 16 | * channels, there are a few functions that globally affect the |
| 17 | * communication processor. |
| 18 | * |
| 19 | * Buffer descriptors must be allocated from the dual ported memory |
| 20 | * space. The allocator for that is here. When the communication |
| 21 | * process is reset, we reclaim the memory available. There is |
| 22 | * currently no deallocator for this memory. |
| 23 | */ |
| 24 | #include <common.h> |
Simon Glass | 40d9b24 | 2020-05-10 11:40:07 -0600 | [diff] [blame] | 25 | #include <asm-offsets.h> |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 26 | #include <asm/cpm_85xx.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 27 | #include <asm/global_data.h> |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 28 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 29 | DECLARE_GLOBAL_DATA_PTR; |
| 30 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 31 | /* |
| 32 | * because we have stack and init data in dual port ram |
| 33 | * we must reduce the size |
| 34 | */ |
| 35 | #undef CPM_DATAONLY_SIZE |
| 36 | #define CPM_DATAONLY_SIZE ((uint)(8 * 1024) - CPM_DATAONLY_BASE) |
| 37 | |
| 38 | void |
| 39 | m8560_cpm_reset(void) |
| 40 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 41 | volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 42 | volatile ulong count; |
| 43 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 44 | gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 45 | |
| 46 | /* Reclaim the DP memory for our use. |
| 47 | */ |
Simon Glass | 9398008 | 2012-12-13 20:48:58 +0000 | [diff] [blame] | 48 | gd->arch.dp_alloc_base = CPM_DATAONLY_BASE; |
| 49 | gd->arch.dp_alloc_top = gd->arch.dp_alloc_base + CPM_DATAONLY_SIZE; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 50 | |
| 51 | /* |
| 52 | * Reset CPM |
| 53 | */ |
Kumar Gala | cd113a0 | 2007-11-28 00:36:33 -0600 | [diff] [blame] | 54 | cpm->im_cpm_cp.cpcr = CPM_CR_RST; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 55 | count = 0; |
| 56 | do { /* Spin until command processed */ |
| 57 | __asm__ __volatile__ ("eieio"); |
Kumar Gala | cd113a0 | 2007-11-28 00:36:33 -0600 | [diff] [blame] | 58 | } while ((cpm->im_cpm_cp.cpcr & CPM_CR_FLG) && ++count < 1000000); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /* Allocate some memory from the dual ported ram. |
| 62 | * To help protocols with object alignment restrictions, we do that |
| 63 | * if they ask. |
| 64 | */ |
| 65 | uint |
| 66 | m8560_cpm_dpalloc(uint size, uint align) |
| 67 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 68 | volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 69 | uint retloc; |
| 70 | uint align_mask, off; |
| 71 | uint savebase; |
| 72 | |
| 73 | align_mask = align - 1; |
Simon Glass | 9398008 | 2012-12-13 20:48:58 +0000 | [diff] [blame] | 74 | savebase = gd->arch.dp_alloc_base; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 75 | |
Simon Glass | 9398008 | 2012-12-13 20:48:58 +0000 | [diff] [blame] | 76 | off = gd->arch.dp_alloc_base & align_mask; |
| 77 | if (off != 0) |
| 78 | gd->arch.dp_alloc_base += (align - off); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 79 | |
| 80 | if ((off = size & align_mask) != 0) |
| 81 | size += align - off; |
| 82 | |
Simon Glass | 9398008 | 2012-12-13 20:48:58 +0000 | [diff] [blame] | 83 | if ((gd->arch.dp_alloc_base + size) >= gd->arch.dp_alloc_top) { |
| 84 | gd->arch.dp_alloc_base = savebase; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 85 | panic("m8560_cpm_dpalloc: ran out of dual port ram!"); |
| 86 | } |
| 87 | |
Simon Glass | 9398008 | 2012-12-13 20:48:58 +0000 | [diff] [blame] | 88 | retloc = gd->arch.dp_alloc_base; |
| 89 | gd->arch.dp_alloc_base += size; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 90 | |
Kumar Gala | cd113a0 | 2007-11-28 00:36:33 -0600 | [diff] [blame] | 91 | memset((void *)&(cpm->im_dprambase[retloc]), 0, size); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 92 | |
| 93 | return(retloc); |
| 94 | } |
| 95 | |
| 96 | /* We also own one page of host buffer space for the allocation of |
| 97 | * UART "fifos" and the like. |
| 98 | */ |
| 99 | uint |
| 100 | m8560_cpm_hostalloc(uint size, uint align) |
| 101 | { |
| 102 | /* the host might not even have RAM yet - just use dual port RAM */ |
| 103 | return (m8560_cpm_dpalloc(size, align)); |
| 104 | } |
| 105 | |
| 106 | /* Set a baud rate generator. This needs lots of work. There are |
| 107 | * eight BRGs, which can be connected to the CPM channels or output |
| 108 | * as clocks. The BRGs are in two different block of internal |
| 109 | * memory mapped space. |
| 110 | * The baud rate clock is the system clock divided by something. |
| 111 | * It was set up long ago during the initial boot phase and is |
| 112 | * is given to us. |
| 113 | * Baud rate clocks are zero-based in the driver code (as that maps |
| 114 | * to port numbers). Documentation uses 1-based numbering. |
| 115 | */ |
Simon Glass | 34a194f | 2012-12-13 20:48:44 +0000 | [diff] [blame] | 116 | #define BRG_INT_CLK gd->arch.brg_clk |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 117 | #define BRG_UART_CLK ((BRG_INT_CLK + 15) / 16) |
| 118 | |
| 119 | /* This function is used by UARTS, or anything else that uses a 16x |
| 120 | * oversampled clock. |
| 121 | */ |
| 122 | void |
| 123 | m8560_cpm_setbrg(uint brg, uint rate) |
| 124 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 125 | volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 126 | volatile uint *bp; |
| 127 | |
| 128 | /* This is good enough to get SMCs running..... |
| 129 | */ |
| 130 | if (brg < 4) { |
Kumar Gala | cd113a0 | 2007-11-28 00:36:33 -0600 | [diff] [blame] | 131 | bp = (uint *)&(cpm->im_cpm_brg1.brgc1); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 132 | } |
| 133 | else { |
Kumar Gala | cd113a0 | 2007-11-28 00:36:33 -0600 | [diff] [blame] | 134 | bp = (uint *)&(cpm->im_cpm_brg2.brgc5); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 135 | brg -= 4; |
| 136 | } |
| 137 | bp += brg; |
| 138 | *bp = (((((BRG_UART_CLK+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN; |
| 139 | } |
| 140 | |
| 141 | /* This function is used to set high speed synchronous baud rate |
| 142 | * clocks. |
| 143 | */ |
| 144 | void |
| 145 | m8560_cpm_fastbrg(uint brg, uint rate, int div16) |
| 146 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 147 | volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 148 | volatile uint *bp; |
| 149 | |
| 150 | /* This is good enough to get SMCs running..... |
| 151 | */ |
| 152 | if (brg < 4) { |
Kumar Gala | cd113a0 | 2007-11-28 00:36:33 -0600 | [diff] [blame] | 153 | bp = (uint *)&(cpm->im_cpm_brg1.brgc1); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 154 | } |
| 155 | else { |
Kumar Gala | cd113a0 | 2007-11-28 00:36:33 -0600 | [diff] [blame] | 156 | bp = (uint *)&(cpm->im_cpm_brg2.brgc5); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 157 | brg -= 4; |
| 158 | } |
| 159 | bp += brg; |
| 160 | *bp = (((((BRG_INT_CLK+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN; |
| 161 | if (div16) |
| 162 | *bp |= CPM_BRG_DIV16; |
| 163 | } |
| 164 | |
| 165 | /* This function is used to set baud rate generators using an external |
| 166 | * clock source and 16x oversampling. |
| 167 | */ |
| 168 | |
| 169 | void |
| 170 | m8560_cpm_extcbrg(uint brg, uint rate, uint extclk, int pinsel) |
| 171 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 172 | volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 173 | volatile uint *bp; |
| 174 | |
| 175 | if (brg < 4) { |
Kumar Gala | cd113a0 | 2007-11-28 00:36:33 -0600 | [diff] [blame] | 176 | bp = (uint *)&(cpm->im_cpm_brg1.brgc1); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 177 | } |
| 178 | else { |
Kumar Gala | cd113a0 | 2007-11-28 00:36:33 -0600 | [diff] [blame] | 179 | bp = (uint *)&(cpm->im_cpm_brg2.brgc5); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 180 | brg -= 4; |
| 181 | } |
| 182 | bp += brg; |
| 183 | *bp = ((((((extclk/16)+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN; |
| 184 | if (pinsel == 0) |
| 185 | *bp |= CPM_BRG_EXTC_CLK3_9; |
| 186 | else |
| 187 | *bp |= CPM_BRG_EXTC_CLK5_15; |
| 188 | } |