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

4.115
Last change on this file since cfaa366 was cfaa366, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 17:55:58

General - Remove extraneous blank line in license message

Many files had an extra blank line in the license text
found in the file header. This patch removes that line.

The script that did this also turned off execute permission
when it was turned on incorrectly.

  • 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 *  http://www.rtems.com/license/LICENSE.
31 *
32 *  $Id$
33 */
34
35#include <rtems.h>
36#include <mpc8260.h>
37#include <mpc8260/cpm.h>
38#include <rtems/bspIo.h>
39
40#define NUM_BRGS 8
41#define NUM_CLKS 20
42
43/* Used to track the usage of the baud rate generators */
44/* (initialised to zeros) */
45static unsigned long brg_spd[NUM_BRGS];
46static unsigned int brg_use_count[NUM_BRGS];
47
48
49/* Used to track the usage of the clock inputs */
50/* (initialised to zeros) */
51static unsigned int clk_use_count[NUM_BRGS];
52
53/*
54 * Compute baud-rate-generator configuration register value
55 */
56int
57m8xx_get_brg_cd (int baud)
58{
59  int divisor;
60  int div16 = 0;
61  extern uint32_t bsp_serial_per_sec;
62
63  divisor = ((bsp_serial_per_sec) + (baud / 2)) / baud;
64  if (divisor > 4096) {
65    div16 = 1;
66    divisor = (divisor + 8) / 16;
67  }
68  return M8260_BRG_EN | M8260_BRG_EXTC_BRGCLK |
69    ((divisor - 1) << 1) | div16;
70}
71
72
73/*
74 *  Allocates an existing brg if one is already programmed for the same
75 *  baud rate.  Otherwise a new brg is assigned
76 *  AFD: on the mpc8260 only some combinations of SCC/SMC and BRG are allowed
77 *  so add a mask which specifies which of the BRGs we can choose from
78 */
79int
80m8xx_get_brg(unsigned brgmask, int baud)
81{
82  int i;
83
84  /* first try to find a BRG that is already at the right speed */
85  for ( i = 0; i < NUM_BRGS; i++ ) {
86    if( (1 << i) & brgmask )            /* is this brg allowed? */
87      if ( brg_spd[i] == baud ) {
88        break;
89    }
90  }
91
92  if ( i == NUM_BRGS ) { /* I guess we didn't find one */
93    for ( i = 0; i < NUM_BRGS; i++ ) {
94      if (((1<<i) & brgmask) && (brg_use_count[i] == 0)) {
95         break;
96      }
97    }
98  }
99  if (i != NUM_BRGS) {
100    brg_use_count[i]++;
101    brg_spd[i]=baud;
102    switch (i) {
103        case 0:
104                m8260.brgc1 = M8260_BRG_RST;
105                m8260.brgc1 = m8xx_get_brg_cd(baud);
106                break;
107        case 1:
108                m8260.brgc2 = M8260_BRG_RST;
109                m8260.brgc2 = m8xx_get_brg_cd(baud);
110                break;
111        case 2:
112                m8260.brgc3 = M8260_BRG_RST;
113                m8260.brgc3 = m8xx_get_brg_cd(baud);
114                break;
115        case 3:
116                m8260.brgc4 = M8260_BRG_RST;
117                m8260.brgc4 = m8xx_get_brg_cd(baud);
118                break;
119        case 4:
120                m8260.brgc5 = M8260_BRG_RST;
121                m8260.brgc5 = m8xx_get_brg_cd(baud);
122                break;
123        case 5:
124                m8260.brgc6 = M8260_BRG_RST;
125                m8260.brgc6 = m8xx_get_brg_cd(baud);
126                break;
127        case 6:
128                m8260.brgc7 = M8260_BRG_RST;
129                m8260.brgc7 = m8xx_get_brg_cd(baud);
130                break;
131        case 7:
132                m8260.brgc8 = M8260_BRG_RST;
133                m8260.brgc8 = m8xx_get_brg_cd(baud);
134                break;
135    }
136    return i;
137  }
138
139  else {
140    printk( "Could not assign a brg for %d\n", baud );
141    return -1;
142  }
143}
144
145
146/*
147 * When the brg is no longer needed call this routine to free the
148 * resource for re--use.
149 */
150void
151m8xx_free_brg( int brg_num )
152{
153  if( (brg_num>=0) && (brg_num<NUM_BRGS) )
154     if(brg_use_count[brg_num] > 0 )
155       brg_use_count[brg_num]--;
156}
157
158
159void m8xx_dump_brgs( void )
160{
161  int i;
162  for(i=0; i<NUM_BRGS; i++ )
163    printk( "Brg[%d]: %d %d\n", i, brg_use_count[i], brg_spd[i] );
164}
165
166
167/*
168 * Reserve one of a range of clock inputs
169 */
170int
171m8xx_get_clk( unsigned clkmask )
172{
173  int i;
174
175  for ( i = 0; i < NUM_CLKS; i++ ) {
176    if (((1<<i) & clkmask) && (clk_use_count[i] == 0)) {
177       break;
178    }
179  }
180
181  if (i != NUM_CLKS) {
182    clk_use_count[i]++;
183    return i;
184  } else {
185    printk( "Could not assign clock in the range %X\n", clkmask );
186    return -1;
187  }
188}
189
190
191/*
192 * When the clock is no longer needed call this routine to free the
193 * resource for re--use.
194 */
195void
196m8xx_free_clk( int clk_num )
197{
198  if( (clk_num>=0) && (clk_num<NUM_BRGS) )
199     if(clk_use_count[clk_num] > 0 )
200       clk_use_count[clk_num]--;
201}
Note: See TracBrowser for help on using the repository browser.