/* * Baud rate generator management functions. * * This file contains routines for allocating baud rate generators * and clock sources to the SCCs and FCCs on the MPC8260. The * allocation is a little more complex on this processor because * there are restrictions on which brgs and clks can be assigned to * a particular port. Rather than coming up with a fixed assignment * these routines try to allocate resources sensibly. * * *** All attempts to allocate a BRG or CLK line should be made via * calls to these routines or they simply won't work. */ /* * Author: Andy Dachs * Copyright Surrey Satellite Technology Limited (SSTL), 2001 * * Derived in part from work by: * * Author: Jay Monkman (jmonkman@frasca.com) * Copyright (C) 1998 by Frasca International, Inc. * and * W. Eric Norum * Saskatchewan Accelerator Laboratory * University of Saskatchewan * Saskatoon, Saskatchewan, CANADA * eric@skatter.usask.ca * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at * http://www.rtems.org/license/LICENSE. */ #include #include #include #include #define NUM_BRGS 8 #define NUM_CLKS 20 /* Used to track the usage of the baud rate generators */ /* (initialised to zeros) */ static unsigned long brg_spd[NUM_BRGS]; static unsigned int brg_use_count[NUM_BRGS]; /* Used to track the usage of the clock inputs */ /* (initialised to zeros) */ static unsigned int clk_use_count[NUM_BRGS]; /* * Compute baud-rate-generator configuration register value */ int m8xx_get_brg_cd (int baud) { int divisor; int div16 = 0; divisor = ((bsp_serial_per_sec) + (baud / 2)) / baud; if (divisor > 4096) { div16 = 1; divisor = (divisor + 8) / 16; } return M8260_BRG_EN | M8260_BRG_EXTC_BRGCLK | ((divisor - 1) << 1) | div16; } /* * Allocates an existing brg if one is already programmed for the same * baud rate. Otherwise a new brg is assigned * AFD: on the mpc8260 only some combinations of SCC/SMC and BRG are allowed * so add a mask which specifies which of the BRGs we can choose from */ int m8xx_get_brg(unsigned brgmask, int baud) { int i; /* first try to find a BRG that is already at the right speed */ for ( i = 0; i < NUM_BRGS; i++ ) { if ( (1 << i) & brgmask ) /* is this brg allowed? */ if ( brg_spd[i] == baud ) { break; } } if ( i == NUM_BRGS ) { /* I guess we didn't find one */ for ( i = 0; i < NUM_BRGS; i++ ) { if (((1<=0) && (brg_num 0 ) brg_use_count[brg_num]--; } #ifdef DEBUG_BRG static void m8xx_dump_brgs( void ) { int i; for (i=0; i=0) && (clk_num 0 ) clk_use_count[clk_num]--; }