source: rtems/c/src/lib/libcpu/powerpc/mpc8260/cpm/brg.c @ 21e1c44

4.104.114.84.95
Last change on this file since 21e1c44 was 21e1c44, checked in by Joel Sherrill <joel.sherrill@…>, on 09/04/03 at 18:53:10

2003-09-04 Joel Sherrill <joel@…>

  • mpc6xx/clock/c_clock.c, mpc6xx/clock/c_clock.h, mpc6xx/exceptions/raw_exception.c, mpc6xx/exceptions/raw_exception.h, mpc6xx/mmu/bat.c, mpc6xx/mmu/bat.h, mpc6xx/mmu/mmuAsm.S, mpc6xx/timer/timer.c, mpc8260/clock/clock.c, mpc8260/console-generic/console-generic.c, mpc8260/cpm/brg.c, mpc8260/exceptions/raw_exception.c, mpc8260/exceptions/raw_exception.h, mpc8260/include/cpm.h, mpc8260/include/mmu.h, mpc8260/mmu/mmu.c, mpc8260/timer/timer.c, mpc8xx/clock/clock.c, mpc8xx/console-generic/console-generic.c, mpc8xx/exceptions/raw_exception.c, mpc8xx/exceptions/raw_exception.h, mpc8xx/include/cpm.h, mpc8xx/include/mmu.h, mpc8xx/mmu/mmu.c, mpc8xx/timer/timer.c, ppc403/clock/clock.c, ppc403/console/console.c.polled, ppc403/timer/timer.c, rtems/powerpc/debugmod.h, shared/include/byteorder.h, shared/include/cpuIdent.c, shared/include/cpuIdent.h, shared/include/io.h, shared/include/mmu.h, shared/include/page.h, shared/include/pgtable.h, shared/include/spr.h: URL for license changed.
  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 *  Baud rate generator management functions.
3 *
4 *  This file contains routines for allocating baud rate generators
5 *  and clock sources to the SCCs and FCCs on the MPC8260.  The
6 *  allocation is a little more complex on this processor because
7 *  there are restrictions on which brgs and clks can be assigned to
8 *  a particular port.  Rather than coming up with a fixed assignment
9 *  these routines try to allocate resources sensibly.
10 *
11 *  *** All attempts to allocate a BRG or CLK line should be made via
12 *      calls to these routines or they simply won't work.
13 *
14 *  Author: Andy Dachs <a.dachs@sstl.co.uk>
15 *  Copyright Surrey Satellite Technology Limited (SSTL), 2001
16 *
17 *  Derived in part from work by:
18 *
19 *    Author: Jay Monkman (jmonkman@frasca.com)
20 *    Copyright (C) 1998 by Frasca International, Inc.
21 *  and
22 *    W. Eric Norum
23 *    Saskatchewan Accelerator Laboratory
24 *    University of Saskatchewan
25 *    Saskatoon, Saskatchewan, CANADA
26 *    eric@skatter.usask.ca
27 *
28 *  The license and distribution terms for this file may be
29 *  found in the file LICENSE in this distribution or at
30 *
31 *  http://www.rtems.com/license/LICENSE.
32 *
33 *  $Id$
34 */
35
36#include <rtems.h>
37#include <mpc8260.h>
38#include <mpc8260/cpm.h>
39#include <rtems/bspIo.h>
40
41#define NUM_BRGS 8
42#define NUM_CLKS 20
43
44/* Used to track the usage of the baud rate generators */
45/* (initialised to zeros) */
46static unsigned long brg_spd[NUM_BRGS];
47static unsigned int brg_use_count[NUM_BRGS];
48
49
50/* Used to track the usage of the clock inputs */
51/* (initialised to zeros) */
52static unsigned int clk_use_count[NUM_BRGS];
53
54
55extern rtems_cpu_table Cpu_table;
56
57/*
58 * Compute baud-rate-generator configuration register value
59 */
60int
61m8xx_get_brg_cd (int baud)
62{
63  int divisor;
64  int div16 = 0;
65
66  divisor = ((Cpu_table.serial_per_sec) + (baud / 2)) / baud;
67  if (divisor > 4096) {
68    div16 = 1;
69    divisor = (divisor + 8) / 16;
70  }
71  return M8260_BRG_EN | M8260_BRG_EXTC_BRGCLK |
72    ((divisor - 1) << 1) | div16;
73}
74
75
76/*
77 *  Allocates an existing brg if one is already programmed for the same
78 *  baud rate.  Otherwise a new brg is assigned
79 *  AFD: on the mpc8260 only some combinations of SCC/SMC and BRG are allowed
80 *  so add a mask which specifies which of the BRGs we can choose from
81 */
82int
83m8xx_get_brg(unsigned brgmask, int baud)
84{
85  int i;
86
87  /* first try to find a BRG that is already at the right speed */
88  for ( i = 0; i < NUM_BRGS; i++ ) {
89    if( (1 << i) & brgmask )            /* is this brg allowed? */
90      if ( brg_spd[i] == baud ) {
91        break;
92    }
93  }
94
95  if ( i == NUM_BRGS ) { /* I guess we didn't find one */
96    for ( i = 0; i < NUM_BRGS; i++ ) {
97      if (((1<<i) & brgmask) && (brg_use_count[i] == 0)) {
98         break;
99      }
100    }
101  }
102  if (i != NUM_BRGS) {
103    brg_use_count[i]++;
104    brg_spd[i]=baud;
105    switch (i) {
106        case 0:
107                m8260.brgc1 = M8260_BRG_RST;
108                m8260.brgc1 = m8xx_get_brg_cd(baud);
109                break;
110        case 1:
111                m8260.brgc2 = M8260_BRG_RST;
112                m8260.brgc2 = m8xx_get_brg_cd(baud);
113                break;
114        case 2:
115                m8260.brgc3 = M8260_BRG_RST;
116                m8260.brgc3 = m8xx_get_brg_cd(baud);
117                break;
118        case 3:
119                m8260.brgc4 = M8260_BRG_RST;
120                m8260.brgc4 = m8xx_get_brg_cd(baud);
121                break;
122        case 4:
123                m8260.brgc5 = M8260_BRG_RST;
124                m8260.brgc5 = m8xx_get_brg_cd(baud);
125                break;
126        case 5:
127                m8260.brgc6 = M8260_BRG_RST;
128                m8260.brgc6 = m8xx_get_brg_cd(baud);
129                break;
130        case 6:
131                m8260.brgc7 = M8260_BRG_RST;
132                m8260.brgc7 = m8xx_get_brg_cd(baud);
133                break;
134        case 7:
135                m8260.brgc8 = M8260_BRG_RST;
136                m8260.brgc8 = m8xx_get_brg_cd(baud);
137                break;
138    }
139    return i;
140  }
141
142  else {
143    printk( "Could not assign a brg for %d\n", baud );
144    return -1;
145  }
146}
147
148
149/*
150 * When the brg is no longer needed call this routine to free the
151 * resource for re--use.
152 */
153void
154m8xx_free_brg( int brg_num )
155{
156  if( (brg_num>=0) && (brg_num<NUM_BRGS) )
157     if(brg_use_count[brg_num] > 0 )
158       brg_use_count[brg_num]--;
159}
160
161
162void m8xx_dump_brgs( void )
163{
164  int i;
165  for(i=0; i<NUM_BRGS; i++ )
166    printk( "Brg[%d]: %d %d\n", i, brg_use_count[i], brg_spd[i] );
167}
168
169
170/*
171 * Reserve one of a range of clock inputs
172 */
173int
174m8xx_get_clk( unsigned clkmask )
175{
176  int i;
177
178  for ( i = 0; i < NUM_CLKS; i++ ) {
179    if (((1<<i) & clkmask) && (clk_use_count[i] == 0)) {
180       break;
181    }
182  }
183
184  if (i != NUM_CLKS) {
185    clk_use_count[i]++;
186    return i;
187  } else {
188    printk( "Could not assign clock in the range %X\n", clkmask );
189    return -1;
190  }
191}
192
193
194/*
195 * When the clock is no longer needed call this routine to free the
196 * resource for re--use.
197 */
198void
199m8xx_free_clk( int clk_num )
200{
201  if( (clk_num>=0) && (clk_num<NUM_BRGS) )
202     if(clk_use_count[clk_num] > 0 )
203       clk_use_count[clk_num]--;
204}
Note: See TracBrowser for help on using the repository browser.