cpu.c

来自「U-boot源码 ARM7启动代码」· C语言 代码 · 共 733 行 · 第 1/2 页

C
733
字号
		return fdt_setprop(blob, nodeoffset, name, bd->bi_enet3addr, 6);	}	return 0;}#endifstatic int fdt_set_busfreq(void *blob, int nodeoffset, const char *name, bd_t *bd){	u32  tmp;	/* Create or update the property */	tmp = cpu_to_be32(bd->bi_busfreq);	return fdt_setprop(blob, nodeoffset, name, &tmp, sizeof(tmp));}static int fdt_set_tbfreq(void *blob, int nodeoffset, const char *name, bd_t *bd){	u32  tmp;	/* Create or update the property */	tmp = cpu_to_be32(OF_TBCLK);	return fdt_setprop(blob, nodeoffset, name, &tmp, sizeof(tmp));}static int fdt_set_clockfreq(void *blob, int nodeoffset, const char *name, bd_t *bd){	u32  tmp;	/* Create or update the property */	tmp = cpu_to_be32(gd->core_clk);	return fdt_setprop(blob, nodeoffset, name, &tmp, sizeof(tmp));}#ifdef CONFIG_QEstatic int fdt_set_qe_busfreq(void *blob, int nodeoffset, const char *name, bd_t *bd){	u32  tmp;	/* Create or update the property */	tmp = cpu_to_be32(gd->qe_clk);	return fdt_setprop(blob, nodeoffset, name, &tmp, sizeof(tmp));}static int fdt_set_qe_brgfreq(void *blob, int nodeoffset, const char *name, bd_t *bd){	u32  tmp;	/* Create or update the property */	tmp = cpu_to_be32(gd->brg_clk);	return fdt_setprop(blob, nodeoffset, name, &tmp, sizeof(tmp));}#endif/* * Fixups to the fdt. */static const struct {	char *node;	char *prop;	int (*set_fn)(void *blob, int nodeoffset, const char *name, bd_t *bd);} fixup_props[] = {	{	"/cpus/" OF_CPU,		"timebase-frequency",		fdt_set_tbfreq	},	{	"/cpus/" OF_CPU,		"bus-frequency",		fdt_set_busfreq	},	{	"/cpus/" OF_CPU,		"clock-frequency",		fdt_set_clockfreq	},	{	"/" OF_SOC,		"bus-frequency",		fdt_set_busfreq	},	{	"/" OF_SOC "/serial@4500",		"clock-frequency",		fdt_set_busfreq	},	{	"/" OF_SOC "/serial@4600",		"clock-frequency",		fdt_set_busfreq	},#ifdef CONFIG_TSEC1	{	"/" OF_SOC "/ethernet@24000",		"mac-address",		fdt_set_eth0	},	{	"/" OF_SOC "/ethernet@24000",		"local-mac-address",		fdt_set_eth0	},#endif#ifdef CONFIG_TSEC2	{	"/" OF_SOC "/ethernet@25000",		"mac-address",		fdt_set_eth1	},	{	"/" OF_SOC "/ethernet@25000",		"local-mac-address",		fdt_set_eth1	},#endif#ifdef CONFIG_QE	{	"/" OF_QE,		"brg-frequency",		fdt_set_qe_brgfreq	},	{	"/" OF_QE,		"bus-frequency",		fdt_set_qe_busfreq	},#ifdef CONFIG_UEC_ETH1#if CFG_UEC1_UCC_NUM == 0  /* UCC1 */	{	"/" OF_QE "/ucc@2000",		"mac-address",		fdt_set_eth0	},	{	"/" OF_QE "/ucc@2000",		"local-mac-address",		fdt_set_eth0	},#elif CFG_UEC1_UCC_NUM == 2  /* UCC3 */	{	"/" OF_QE "/ucc@2200",		"mac-address",		fdt_set_eth0	},	{	"/" OF_QE "/ucc@2200",		"local-mac-address",		fdt_set_eth0	},#endif#endif /* CONFIG_UEC_ETH1 */#ifdef CONFIG_UEC_ETH2#if CFG_UEC2_UCC_NUM == 1  /* UCC2 */	{	"/" OF_QE "/ucc@3000",		"mac-address",		fdt_set_eth1	},	{	"/" OF_QE "/ucc@3000",		"local-mac-address",		fdt_set_eth1	},#elif CFG_UEC2_UCC_NUM == 3  /* UCC4 */	{	"/" OF_QE "/ucc@3200",		"mac-address",		fdt_set_eth1	},	{	"/" OF_QE "/ucc@3200",		"local-mac-address",		fdt_set_eth1	},#endif#endif /* CONFIG_UEC_ETH2 */#endif /* CONFIG_QE */};voidft_cpu_setup(void *blob, bd_t *bd){	int nodeoffset;	int err;	int j;	int tmp[2];	for (j = 0; j < (sizeof(fixup_props) / sizeof(fixup_props[0])); j++) {		nodeoffset = fdt_path_offset(blob, fixup_props[j].node);		if (nodeoffset >= 0) {			err = fixup_props[j].set_fn(blob, nodeoffset,						    fixup_props[j].prop, bd);			if (err < 0)				debug("Problem setting %s = %s: %s\n",				      fixup_props[j].node, fixup_props[j].prop,				      fdt_strerror(err));		} else {			debug("Couldn't find %s: %s\n",			      fixup_props[j].node, fdt_strerror(nodeoffset));		}	}	/* update, or add and update /memory node */	nodeoffset = fdt_path_offset(blob, "/memory");	if (nodeoffset < 0) {		nodeoffset = fdt_add_subnode(blob, 0, "memory");		if (nodeoffset < 0)			debug("failed to add /memory node: %s\n",			      fdt_strerror(nodeoffset));	}	if (nodeoffset >= 0) {		fdt_setprop(blob, nodeoffset, "device_type",			    "memory", sizeof("memory"));		tmp[0] = cpu_to_be32(bd->bi_memstart);		tmp[1] = cpu_to_be32(bd->bi_memsize);		fdt_setprop(blob, nodeoffset, "reg", tmp, sizeof(tmp));	}}#elif defined(CONFIG_OF_FLAT_TREE)voidft_cpu_setup(void *blob, bd_t *bd){	u32 *p;	int len;	ulong clock;	clock = bd->bi_busfreq;	p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len);	if (p != NULL)		*p = cpu_to_be32(clock);	p = ft_get_prop(blob, "/" OF_SOC "/bus-frequency", &len);	if (p != NULL)		*p = cpu_to_be32(clock);	p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len);	if (p != NULL)		*p = cpu_to_be32(clock);	p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len);	if (p != NULL)		*p = cpu_to_be32(clock);#ifdef CONFIG_TSEC1	p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/mac-address", &len);	if (p != NULL)		memcpy(p, bd->bi_enetaddr, 6);	p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/local-mac-address", &len);	if (p != NULL)		memcpy(p, bd->bi_enetaddr, 6);#endif#ifdef CONFIG_TSEC2	p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/mac-address", &len);	if (p != NULL)		memcpy(p, bd->bi_enet1addr, 6);	p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/local-mac-address", &len);	if (p != NULL)		memcpy(p, bd->bi_enet1addr, 6);#endif#ifdef CONFIG_UEC_ETH1#if CFG_UEC1_UCC_NUM == 0  /* UCC1 */	p = ft_get_prop(blob, "/" OF_QE "/ucc@2000/mac-address", &len);	if (p != NULL)		memcpy(p, bd->bi_enetaddr, 6);	p = ft_get_prop(blob, "/" OF_QE "/ucc@2000/local-mac-address", &len);	if (p != NULL)		memcpy(p, bd->bi_enetaddr, 6);#elif CFG_UEC1_UCC_NUM == 2  /* UCC3 */	p = ft_get_prop(blob, "/" OF_QE "/ucc@2200/mac-address", &len);	if (p != NULL)		memcpy(p, bd->bi_enetaddr, 6);	p = ft_get_prop(blob, "/" OF_QE "/ucc@2200/local-mac-address", &len);	if (p != NULL)		memcpy(p, bd->bi_enetaddr, 6);#endif#endif#ifdef CONFIG_UEC_ETH2#if CFG_UEC2_UCC_NUM == 1  /* UCC2 */	p = ft_get_prop(blob, "/" OF_QE "/ucc@3000/mac-address", &len);	if (p != NULL)		memcpy(p, bd->bi_enet1addr, 6);	p = ft_get_prop(blob, "/" OF_QE "/ucc@3000/local-mac-address", &len);	if (p != NULL)		memcpy(p, bd->bi_enet1addr, 6);#elif CFG_UEC2_UCC_NUM == 3  /* UCC4 */	p = ft_get_prop(blob, "/" OF_QE "/ucc@3200/mac-address", &len);	if (p != NULL)		memcpy(p, bd->bi_enet1addr, 6);	p = ft_get_prop(blob, "/" OF_QE "/ucc@3200/local-mac-address", &len);	if (p != NULL)		memcpy(p, bd->bi_enet1addr, 6);#endif#endif}#endif#if defined(CONFIG_DDR_ECC)void dma_init(void){	volatile immap_t *immap = (immap_t *)CFG_IMMR;	volatile dma83xx_t *dma = &immap->dma;	volatile u32 status = swab32(dma->dmasr0);	volatile u32 dmamr0 = swab32(dma->dmamr0);	debug("DMA-init\n");	/* initialize DMASARn, DMADAR and DMAABCRn */	dma->dmadar0 = (u32)0;	dma->dmasar0 = (u32)0;	dma->dmabcr0 = 0;	__asm__ __volatile__ ("sync");	__asm__ __volatile__ ("isync");	/* clear CS bit */	dmamr0 &= ~DMA_CHANNEL_START;	dma->dmamr0 = swab32(dmamr0);	__asm__ __volatile__ ("sync");	__asm__ __volatile__ ("isync");	/* while the channel is busy, spin */	while(status & DMA_CHANNEL_BUSY) {		status = swab32(dma->dmasr0);	}	debug("DMA-init end\n");}uint dma_check(void){	volatile immap_t *immap = (immap_t *)CFG_IMMR;	volatile dma83xx_t *dma = &immap->dma;	volatile u32 status = swab32(dma->dmasr0);	volatile u32 byte_count = swab32(dma->dmabcr0);	/* while the channel is busy, spin */	while (status & DMA_CHANNEL_BUSY) {		status = swab32(dma->dmasr0);	}	if (status & DMA_CHANNEL_TRANSFER_ERROR) {		printf ("DMA Error: status = %x @ %d\n", status, byte_count);	}	return status;}int dma_xfer(void *dest, u32 count, void *src){	volatile immap_t *immap = (immap_t *)CFG_IMMR;	volatile dma83xx_t *dma = &immap->dma;	volatile u32 dmamr0;	/* initialize DMASARn, DMADAR and DMAABCRn */	dma->dmadar0 = swab32((u32)dest);	dma->dmasar0 = swab32((u32)src);	dma->dmabcr0 = swab32(count);	__asm__ __volatile__ ("sync");	__asm__ __volatile__ ("isync");	/* init direct transfer, clear CS bit */	dmamr0 = (DMA_CHANNEL_TRANSFER_MODE_DIRECT |			DMA_CHANNEL_SOURCE_ADDRESS_HOLD_8B |			DMA_CHANNEL_SOURCE_ADRESSS_HOLD_EN);	dma->dmamr0 = swab32(dmamr0);	__asm__ __volatile__ ("sync");	__asm__ __volatile__ ("isync");	/* set CS to start DMA transfer */	dmamr0 |= DMA_CHANNEL_START;	dma->dmamr0 = swab32(dmamr0);	__asm__ __volatile__ ("sync");	__asm__ __volatile__ ("isync");	return ((int)dma_check());}#endif /*CONFIG_DDR_ECC*/

⌨️ 快捷键说明

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