cmd_hitools.c

来自「华为 HI3510 BOOTLOADER HIBOOT 源码包」· C语言 代码 · 共 188 行

C
188
字号
/* * (C) Copyright 2005 * Liu jiandong, Hisilicon company, liujiandong@hisilicon.com * * * 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 <common.h>#include <command.h>#include <linux-adapter.h>#ifdef CMD_HISILICON_TOOLS#define read_ahb_pllc() readl(0x101E0018)static void write_ahb_pllc(unsigned long x){	unsigned long sysctl_base = 0x101E0000;	unsigned long pllc=read_ahb_pllc()&(~0x03FFF);	pllc = pllc | ((x)&0x03FFF);	__asm__ __volatile__(		/* go to flash */		"ldr pc, entry_in_flash \n"		/* loop */		"delay_N: \n"		"lsl r0, #10 \n"		"1: subs r0, r0, #1 \n"		"bne 1b \n"		"mov pc, lr \n"		"run_in_flash: \n"		/* set to slow mode *///		"ldr r0, [%1] \n"//		"bic r0, #0x7 \n"//		"orr r0, #0x3 \n"//		"str r0, [%1] \n"//		"mov r0, #1 \n"//		"bl  delay_N \n"		/* set pllc */		"str %0, [%1, #0x18] \n"		"mov r0, #4 \n"		"bl  delay_N \n"		/* set to normal mode *///		"ldr r0, [%1] \n"//		"orr r0, #0x7 \n"//		"str r0, [%1] \n"//		"mov r0, #1 \n"//		"bl  delay_N \n"		"ldr pc, entry_in_dram \n"		"entry_in_flash: .long 0x34000000 + (run_in_flash - 0xf0500000) \n"		"entry_in_dram:  .long run_in_dram \n"		"run_in_dram: \n"		"nop \n"		:		: "r"(pllc), "r"(sysctl_base)		: "r0","lr" );}static long __pow(long a, unsigned int x){	if(x==0)		return 1;	for(;x!=1;x--)		a = a*a;	return a;}#define PLLC2AHB(__pllc, xtal) ({ unsigned long pllc=__pllc; (((xtal)*(pllc&0x0FF))/(((pllc>>8)&0x0F)*__pow(2,(pllc>>12)&0x03)))/2; })#define AHB2PLLC(__ahb, xtal)  ({unsigned long t=((__ahb)*2)/MHZ; t = (t&0xFF) | (0x00002300); })#include "../drivers/serial_pl011.h"#define CONSOLE_PORT CONFIG_CONS_INDEX#define baudRate CONFIG_BAUDRATEstatic volatile unsigned char *const port[] = CONFIG_PL01x_PORTS;#define NUM_PORTS (sizeof(port)/sizeof(port[0]))#define IO_WRITE(addr, val) writel(val, addr)static int set_baudrate(unsigned long pl011_clock){	unsigned int temp;	unsigned int divider;	unsigned int remainder;	unsigned int fraction;	IO_WRITE (port[CONSOLE_PORT] + UART_PL011_CR, 0x0);	/*	 ** Set baud rate	 **	 ** IBRD = UART_CLK / (16 * BAUD_RATE)	 ** FBRD = ROUND((64 * MOD(UART_CLK,(16 * BAUD_RATE))) / (16 * BAUD_RATE))	 */	temp = 16 * baudRate;	divider = pl011_clock / temp;	remainder = pl011_clock % temp;	temp = (8 * remainder) / baudRate;	fraction = (temp >> 1) + (temp & 1);	IO_WRITE (port[CONSOLE_PORT] + UART_PL011_IBRD, divider);	IO_WRITE (port[CONSOLE_PORT] + UART_PL011_FBRD, fraction);	/*	 ** Set the UART to be 8 bits, 1 stop bit, no parity, fifo enabled.	 */	IO_WRITE (port[CONSOLE_PORT] + UART_PL011_LCRH,		  (UART_PL011_LCRH_WLEN_8 | UART_PL011_LCRH_FEN));	/*	 ** Finally, enable the UART	 */	IO_WRITE (port[CONSOLE_PORT] + UART_PL011_CR,		  (UART_PL011_CR_UARTEN | UART_PL011_CR_TXE |		   UART_PL011_CR_RXE));	return 0;}int do_cmd_ahbfreq( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){	unsigned long ahb=0, xtal=0, t;	const char *s;	s = getenv("xtal");	if(s)		xtal = simple_strtoul(s, NULL, 10);	if(xtal == 0)		xtal = XTAL_CLOCK;	t = PLLC2AHB(read_ahb_pllc(), xtal);	AHB_CLOCK = t;	printf("\rCurrent: AHB-Freq = %lu MHZ, XTAL = %lu\n", t/MHZ, xtal);	if(argc < 2) {		return 0;	}	ahb = simple_strtoul(argv[1], NULL, 10);	if(ahb == 0) {		printf("Usage:\n%s\n", cmdtp->usage);		return 0;	}	if(argc > 2) {		t = simple_strtoul(argv[2], NULL, 10);		if(t) xtal = t;	}	printf(" Set to: AHB-Freq = %lu MHZ, XTAL = %lu, PLLC = 0x%08X\n", ahb/MHZ, xtal, AHB2PLLC(ahb, xtal));	printf("Check AHB frequency ...");	udelay(100000);	write_ahb_pllc(AHB2PLLC(ahb, xtal));	set_baudrate(ahb);	do_cmd_ahbfreq(NULL, 0, 0, NULL);	return 0;}U_BOOT_CMD(	ahbfreq,     2,      1,       do_cmd_ahbfreq,	"ahbfreq freq xtal\n",	"ahbfreq  \n" "    AHB-Freq PLL-IN\n");#endif#include <hisilicon/cmd_zsp.c>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?