diff options
| author | Wolfgang Denk <wd@denx.de> | 2011-08-04 23:05:07 +0200 | 
|---|---|---|
| committer | Wolfgang Denk <wd@denx.de> | 2011-08-04 23:05:07 +0200 | 
| commit | fb6440ee9b110b759ef61fd80bbd0df1bbf0f37b (patch) | |
| tree | dbde38784fb8b48c7f9b14e70a947fab3a1f3bab /tools/omap/clocks_get_m_n.c | |
| parent | 01b0f50060923e89693bf155c677e4f665916b3f (diff) | |
| parent | b608b95753873a5073f550cca002c4bebf1a18f5 (diff) | |
| download | olio-uboot-2014.01-fb6440ee9b110b759ef61fd80bbd0df1bbf0f37b.tar.xz olio-uboot-2014.01-fb6440ee9b110b759ef61fd80bbd0df1bbf0f37b.zip | |
Merge branch 'master' of git://git.denx.de/u-boot-arm
* 'master' of git://git.denx.de/u-boot-arm:
  drivers/rtc: add Marvell Integrated RTC
  Armada100: Add Board Support for Marvell GuruPlug-Display
  Armada100: MFP macro naming correction
  arm: auto gen asm-offsets.h for mb86r0x
  spear: fix build errors for spear3xx/spear600 platforms
  cosmetic: arm: lib/board.c: Coding Style cleanup
  ARM: versatile: fix board support
  SMDKV310: Enable device tree support
  SMDKV310: MMC_SPL: Fix building when using "make O="
  arm: a320: enable tagged list support
  arm: a320: fix multiline comment style
  ARMv7: u8500_href: Add missing header to fix compiler warning
  Removed unused define, CONFIG_ARMV7.
  avr32: add grasshopper (ICnova AP7000) board
  AT91/SPI: fix atmel_dataflash_spi.c to allow building without warnings
  MAKEALL: remove AT91 boards that are in boards.cfg
  AT91: Makes AT91SAM9263-EK build correctly against u-boot-atmel/master
  AT91: Makes AT91SAM9263 SoC build correctly against u-boot-atmel/master
  AT91: Board fix for AT91SAM9261-EK
  AT91: SoC fix at91sam9261_matrix.h
  AT91: Makes AT91SAM9RL-EK build correctly against u-boot-atmel/master
  AT91: Makes AT91SAM9RL SoC build correctly against u-boot-atmel/master
  AT91: change common at91sam9261 files to compile with new scheme
  AT91: fix mistake in at91sam9260_devices.c(spi1_hw_init)
  a/a/c/arm920t/at91/reset.c: drop obsolete CONFIG_AT91RM9200_USART
  README: fix arm920t/at91 path
  net/eth.c: drop obsolete at91rm9200 support
  README.at91-soc: remove AT91(RM9200) joining notice
  a/a/c/arm920t/cpu.c: remove CONFIG_AT91_LEGACY warning
  MAKEALL: remove obsolete at91rm9200 soc
  ARM: remove obsolete at91rm9200
  omap4: clock init support for omap4460
  omap4: support TPS programming
  omap: reuse omap3 gpio support in omap4
  omap4: sdram init changes for omap4460
  omap4: add omap4460 revision detection
  mkimage: Add OMAP boot image support
  omap: add MMC and FAT support to SPL
  omap: add basic SPL support
  armv7: start.S: fixes and enhancements for SPL
  omap4: automatic sdram detection
  omap4: calculate EMIF register values
  omap4: add sdram init support
  omap4: add clock support
  omap4: add OMAP4430 revision check
  omap4: cleanup pin mux data
  omap4: utility function to identify the context of hw init
  DA8xx: fix LPSC constants
  DA8xx: switch an enum to defines for consistency
  DA8xx: add MMC/SD controller addresses
  DaVinci EMAC: declare function for all DA8xx CPUs
  DA8xx: add generic GPIO driver
  DaVinci: rename gpio_defs.h to gpio.h
  omap3evm: eth: Include functions only when necessary
  omap3evm: Update ethernet reset sequence for Rev.G board
  omap3evm: eth: split function setup_net_chip
  omap3: Include array definition only when it is used
  omap730p2: fix build breaks
  omap2420h4: fix build breaks
  omap1610inn: fix build breaks
  omap1510inn: fix build breaks
  omap5912osk: fix build breaks
  omap1610h2: fix build breaks
Diffstat (limited to 'tools/omap/clocks_get_m_n.c')
| -rw-r--r-- | tools/omap/clocks_get_m_n.c | 197 | 
1 files changed, 197 insertions, 0 deletions
| diff --git a/tools/omap/clocks_get_m_n.c b/tools/omap/clocks_get_m_n.c new file mode 100644 index 000000000..cfc176042 --- /dev/null +++ b/tools/omap/clocks_get_m_n.c @@ -0,0 +1,197 @@ +/* + * Program for finding M & N values for DPLLs + * To be run on Host PC + * + * (C) Copyright 2010 + * Texas Instruments, <www.ti.com> + * + * Aneesh V <aneesh@ti.com> + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ +#include <stdlib.h> +#include <stdio.h> +typedef unsigned int u32; +#define MAX_N	127 + +/* + * get_m_n_optimized() - Finds optimal DPLL multiplier(M) and divider(N) + * values based on the reference frequency, required output frequency, + * maximum tolerance for output frequency etc. + * + * target_freq_khz - output frequency required in KHz + * ref_freq_khz - reference(input) frequency in KHz + * m - pointer to computed M value + * n - pointer to computed N value + * tolerance_khz - tolerance for the output frequency. When the algorithm + * succeeds in finding vialble M and N values the corresponding output + * frequency will be in the range: + *	[target_freq_khz - tolerance_khz, target_freq_khz] + * + * Formula: + *	Fdpll = (2 * M * Fref) / (N + 1) + * + * Considerations for lock-time: + *	- Smaller the N, better lock-time, especially lock-time will be + *	- For acceptable lock-times: + *		Fref / (M + 1) >= 1 MHz + * + * Considerations for power: + *	- The difference in power for different N values giving the same + *	  output is negligible. So, we optimize for lock-time + * + * Hard-constraints: + *	- N can not be greater than 127(7 bit field for representing N) + * + * Usage: + *	$ gcc clocks_get_m_n.c + *	$ ./a.out + */ +int get_m_n_optimized(u32 target_freq_khz, u32 ref_freq_khz, u32 *m, u32 *n, +			u32 tolerance_khz) +{ +	u32 min_freq = target_freq_khz - tolerance_khz; +	u32 max_freq = target_freq_khz; +	u32 freq, freq_old; +	*n = 1; +	while (1) { +		*m = min_freq / ref_freq_khz / 2 * (*n) ; +		freq_old = 0; +		while (1) { +			freq = ref_freq_khz * 2 * (*m) / (*n); +			if (abs(target_freq_khz - freq_old) <= +				abs(target_freq_khz - freq)) { +				freq = freq_old; +				(*m)--; +				break; +			} +			(*m)++; +			freq_old = freq; +		} +		if (freq >= min_freq && freq <= max_freq) +			break; +		(*n)++; +		if ((*n) > MAX_N + 1) { +			printf("ref %d m %d n %d target %d : ", +				ref_freq_khz, *m, *n, target_freq_khz); +			printf("can not find m & n - please consider" +				" increasing tolerance\n"); +			return -1; +		} +	} +	(*n)--; +	printf("ref %d m %d n %d target %d locked %d\n", +		ref_freq_khz, *m, *n, target_freq_khz, freq); +	if ((ref_freq_khz / (*n + 1)) < 1000) { +		printf("\tREFCLK - CLKINP/(N+1) is less than 1 MHz - less than" +			" ideal, locking time will be high!\n"); +	} +	return 0; +} + +void main(void) +{ +	u32 m, n; +	printf("\nMPU - 2000000\n"); +	get_m_n_optimized(2000000, 12000, &m, &n, 0); +	get_m_n_optimized(2000000, 13000, &m, &n, 0); +	get_m_n_optimized(2000000, 16800, &m, &n, 800); +	get_m_n_optimized(2000000, 19200, &m, &n, 0); +	get_m_n_optimized(2000000, 26000, &m, &n, 0); +	get_m_n_optimized(2000000, 27000, &m, &n, 0); +	get_m_n_optimized(2000000, 38400, &m, &n, 0); + +	printf("\nMPU - 1200000\n"); +	get_m_n_optimized(1200000, 12000, &m, &n, 0); +	get_m_n_optimized(1200000, 13000, &m, &n, 0); +	get_m_n_optimized(1200000, 16800, &m, &n, 800); +	get_m_n_optimized(1200000, 19200, &m, &n, 0); +	get_m_n_optimized(1200000, 26000, &m, &n, 0); +	get_m_n_optimized(1200000, 27000, &m, &n, 0); +	get_m_n_optimized(1200000, 38400, &m, &n, 0); + +	printf("\nMPU - 1584000\n"); +	get_m_n_optimized(1584000, 12000, &m, &n, 0); +	get_m_n_optimized(1584000, 13000, &m, &n, 0); +	get_m_n_optimized(1584000, 16800, &m, &n, 400); +	get_m_n_optimized(1584000, 19200, &m, &n, 0); +	get_m_n_optimized(1584000, 26000, &m, &n, 0); +	get_m_n_optimized(1584000, 27000, &m, &n, 0); +	get_m_n_optimized(1584000, 38400, &m, &n, 0); + +	printf("\nCore 1600000\n"); +	get_m_n_optimized(1600000, 12000, &m, &n, 0); +	get_m_n_optimized(1600000, 13000, &m, &n, 0); +	get_m_n_optimized(1600000, 16800, &m, &n, 200); +	get_m_n_optimized(1600000, 19200, &m, &n, 0); +	get_m_n_optimized(1600000, 26000, &m, &n, 0); +	get_m_n_optimized(1600000, 27000, &m, &n, 0); +	get_m_n_optimized(1600000, 38400, &m, &n, 0); + +	printf("\nPER 1536000\n"); +	get_m_n_optimized(1536000, 12000, &m, &n, 0); +	get_m_n_optimized(1536000, 13000, &m, &n, 0); +	get_m_n_optimized(1536000, 16800, &m, &n, 0); +	get_m_n_optimized(1536000, 19200, &m, &n, 0); +	get_m_n_optimized(1536000, 26000, &m, &n, 0); +	get_m_n_optimized(1536000, 27000, &m, &n, 0); +	get_m_n_optimized(1536000, 38400, &m, &n, 0); + +	printf("\nIVA 1862000\n"); +	get_m_n_optimized(1862000, 12000, &m, &n, 0); +	get_m_n_optimized(1862000, 13000, &m, &n, 0); +	get_m_n_optimized(1862000, 16800, &m, &n, 0); +	get_m_n_optimized(1862000, 19200, &m, &n, 900); +	get_m_n_optimized(1862000, 26000, &m, &n, 0); +	get_m_n_optimized(1862000, 27000, &m, &n, 0); +	get_m_n_optimized(1862000, 38400, &m, &n, 800); + +	printf("\nABE 196608 sys clk\n"); +	get_m_n_optimized(196608, 12000, &m, &n, 700); +	get_m_n_optimized(196608, 13000, &m, &n, 200); +	get_m_n_optimized(196608, 16800, &m, &n, 700); +	get_m_n_optimized(196608, 19200, &m, &n, 400); +	get_m_n_optimized(196608, 26000, &m, &n, 200); +	get_m_n_optimized(196608, 27000, &m, &n, 900); +	get_m_n_optimized(196608, 38400, &m, &n, 0); + +	printf("\nABE 196608 32K\n"); +	get_m_n_optimized(196608000/4, 32768, &m, &n, 0); + +	printf("\nUSB 1920000\n"); +	get_m_n_optimized(1920000, 12000, &m, &n, 0); +	get_m_n_optimized(1920000, 13000, &m, &n, 0); +	get_m_n_optimized(1920000, 16800, &m, &n, 0); +	get_m_n_optimized(1920000, 19200, &m, &n, 0); +	get_m_n_optimized(1920000, 26000, &m, &n, 0); +	get_m_n_optimized(1920000, 27000, &m, &n, 0); +	get_m_n_optimized(1920000, 38400, &m, &n, 0); + +	printf("\nCore ES1 1523712\n"); +	get_m_n_optimized(1524000, 12000, &m, &n, 100); +	get_m_n_optimized(1524000, 13000, &m, &n, 0); +	get_m_n_optimized(1524000, 16800, &m, &n, 0); +	get_m_n_optimized(1524000, 19200, &m, &n, 0); +	get_m_n_optimized(1524000, 26000, &m, &n, 0); +	get_m_n_optimized(1524000, 27000, &m, &n, 0); + +	/* exact recommendation for SDPs */ +	get_m_n_optimized(1523712, 38400, &m, &n, 0); + +} |