blob: 95215a0b82924b5e8590cae66c702eb04f257931 [file] [log] [blame]
wdenk42d1f032003-10-15 23:53:47 +00001/*
2 * Adapted for Motorola MPC8560 chips
3 * Xianghua Xiao <x.xiao@motorola.com>
4 *
Stefan Roesea47a12b2010-04-15 16:07:28 +02005 * This file is based on "arch/powerpc/8260_io/commproc.c" - here is it's
wdenk42d1f032003-10-15 23:53:47 +00006 * 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 Glass8ad92112020-05-10 11:40:07 -060025#include <asm-offsets.h>
wdenk42d1f032003-10-15 23:53:47 +000026#include <asm/cpm_85xx.h>
27
Wolfgang Denkd87080b2006-03-31 18:32:53 +020028DECLARE_GLOBAL_DATA_PTR;
29
wdenk42d1f032003-10-15 23:53:47 +000030/*
31 * because we have stack and init data in dual port ram
32 * we must reduce the size
33 */
34#undef CPM_DATAONLY_SIZE
35#define CPM_DATAONLY_SIZE ((uint)(8 * 1024) - CPM_DATAONLY_BASE)
36
37void
38m8560_cpm_reset(void)
39{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020040 volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
wdenk42d1f032003-10-15 23:53:47 +000041 volatile ulong count;
42
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020043 gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
wdenk42d1f032003-10-15 23:53:47 +000044
45 /* Reclaim the DP memory for our use.
46 */
Simon Glass6bb9ba72012-12-13 20:48:58 +000047 gd->arch.dp_alloc_base = CPM_DATAONLY_BASE;
48 gd->arch.dp_alloc_top = gd->arch.dp_alloc_base + CPM_DATAONLY_SIZE;
wdenk42d1f032003-10-15 23:53:47 +000049
50 /*
51 * Reset CPM
52 */
Kumar Galaaafeefb2007-11-28 00:36:33 -060053 cpm->im_cpm_cp.cpcr = CPM_CR_RST;
wdenk42d1f032003-10-15 23:53:47 +000054 count = 0;
55 do { /* Spin until command processed */
56 __asm__ __volatile__ ("eieio");
Kumar Galaaafeefb2007-11-28 00:36:33 -060057 } while ((cpm->im_cpm_cp.cpcr & CPM_CR_FLG) && ++count < 1000000);
wdenk42d1f032003-10-15 23:53:47 +000058}
59
60/* Allocate some memory from the dual ported ram.
61 * To help protocols with object alignment restrictions, we do that
62 * if they ask.
63 */
64uint
65m8560_cpm_dpalloc(uint size, uint align)
66{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020067 volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
wdenk42d1f032003-10-15 23:53:47 +000068 uint retloc;
69 uint align_mask, off;
70 uint savebase;
71
72 align_mask = align - 1;
Simon Glass6bb9ba72012-12-13 20:48:58 +000073 savebase = gd->arch.dp_alloc_base;
wdenk42d1f032003-10-15 23:53:47 +000074
Simon Glass6bb9ba72012-12-13 20:48:58 +000075 off = gd->arch.dp_alloc_base & align_mask;
76 if (off != 0)
77 gd->arch.dp_alloc_base += (align - off);
wdenk42d1f032003-10-15 23:53:47 +000078
79 if ((off = size & align_mask) != 0)
80 size += align - off;
81
Simon Glass6bb9ba72012-12-13 20:48:58 +000082 if ((gd->arch.dp_alloc_base + size) >= gd->arch.dp_alloc_top) {
83 gd->arch.dp_alloc_base = savebase;
wdenk42d1f032003-10-15 23:53:47 +000084 panic("m8560_cpm_dpalloc: ran out of dual port ram!");
85 }
86
Simon Glass6bb9ba72012-12-13 20:48:58 +000087 retloc = gd->arch.dp_alloc_base;
88 gd->arch.dp_alloc_base += size;
wdenk42d1f032003-10-15 23:53:47 +000089
Kumar Galaaafeefb2007-11-28 00:36:33 -060090 memset((void *)&(cpm->im_dprambase[retloc]), 0, size);
wdenk42d1f032003-10-15 23:53:47 +000091
92 return(retloc);
93}
94
95/* We also own one page of host buffer space for the allocation of
96 * UART "fifos" and the like.
97 */
98uint
99m8560_cpm_hostalloc(uint size, uint align)
100{
101 /* the host might not even have RAM yet - just use dual port RAM */
102 return (m8560_cpm_dpalloc(size, align));
103}
104
105/* Set a baud rate generator. This needs lots of work. There are
106 * eight BRGs, which can be connected to the CPM channels or output
107 * as clocks. The BRGs are in two different block of internal
108 * memory mapped space.
109 * The baud rate clock is the system clock divided by something.
110 * It was set up long ago during the initial boot phase and is
111 * is given to us.
112 * Baud rate clocks are zero-based in the driver code (as that maps
113 * to port numbers). Documentation uses 1-based numbering.
114 */
Simon Glass1206c182012-12-13 20:48:44 +0000115#define BRG_INT_CLK gd->arch.brg_clk
wdenk42d1f032003-10-15 23:53:47 +0000116#define BRG_UART_CLK ((BRG_INT_CLK + 15) / 16)
117
118/* This function is used by UARTS, or anything else that uses a 16x
119 * oversampled clock.
120 */
121void
122m8560_cpm_setbrg(uint brg, uint rate)
123{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200124 volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
wdenk42d1f032003-10-15 23:53:47 +0000125 volatile uint *bp;
126
127 /* This is good enough to get SMCs running.....
128 */
129 if (brg < 4) {
Kumar Galaaafeefb2007-11-28 00:36:33 -0600130 bp = (uint *)&(cpm->im_cpm_brg1.brgc1);
wdenk42d1f032003-10-15 23:53:47 +0000131 }
132 else {
Kumar Galaaafeefb2007-11-28 00:36:33 -0600133 bp = (uint *)&(cpm->im_cpm_brg2.brgc5);
wdenk42d1f032003-10-15 23:53:47 +0000134 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 */
143void
144m8560_cpm_fastbrg(uint brg, uint rate, int div16)
145{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200146 volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
wdenk42d1f032003-10-15 23:53:47 +0000147 volatile uint *bp;
148
149 /* This is good enough to get SMCs running.....
150 */
151 if (brg < 4) {
Kumar Galaaafeefb2007-11-28 00:36:33 -0600152 bp = (uint *)&(cpm->im_cpm_brg1.brgc1);
wdenk42d1f032003-10-15 23:53:47 +0000153 }
154 else {
Kumar Galaaafeefb2007-11-28 00:36:33 -0600155 bp = (uint *)&(cpm->im_cpm_brg2.brgc5);
wdenk42d1f032003-10-15 23:53:47 +0000156 brg -= 4;
157 }
158 bp += brg;
159 *bp = (((((BRG_INT_CLK+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN;
160 if (div16)
161 *bp |= CPM_BRG_DIV16;
162}
163
164/* This function is used to set baud rate generators using an external
165 * clock source and 16x oversampling.
166 */
167
168void
169m8560_cpm_extcbrg(uint brg, uint rate, uint extclk, int pinsel)
170{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200171 volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
wdenk42d1f032003-10-15 23:53:47 +0000172 volatile uint *bp;
173
174 if (brg < 4) {
Kumar Galaaafeefb2007-11-28 00:36:33 -0600175 bp = (uint *)&(cpm->im_cpm_brg1.brgc1);
wdenk42d1f032003-10-15 23:53:47 +0000176 }
177 else {
Kumar Galaaafeefb2007-11-28 00:36:33 -0600178 bp = (uint *)&(cpm->im_cpm_brg2.brgc5);
wdenk42d1f032003-10-15 23:53:47 +0000179 brg -= 4;
180 }
181 bp += brg;
182 *bp = ((((((extclk/16)+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN;
183 if (pinsel == 0)
184 *bp |= CPM_BRG_EXTC_CLK3_9;
185 else
186 *bp |= CPM_BRG_EXTC_CLK5_15;
187}