Skip to contentSkip to conversation

MX51 Support in u-boot

U-Boot Superseded Stefano Babic 5 participants 41 messages Jan 11, 2010 – Jan 18, 2010

Subsystems (5)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

Hi all,

the next patchset adds support for the Freescale MX51 processor. Fred Fan has already sent a patchset sometimes ago.

In agreement with Fred, I rearranged the patches after the first review, adding support for network (FEC) and SD controller. In the meantime, Freescale has published documentation on this board and has renamed it mx51evk (mx51 Evaluation Kit).

Stefano

[PATCH 1/9] mkimage: Add Freescale imx Boot Image support (imximage) [PATCH 2/9] MX51: Add initial support for the Freescale MX51 [PATCH 3/9] MX51: Add register definitions
[PATCH 4/9] MX51: Add pin and multiplexer definitions. [PATCH 5/9] serial_mxc: add support for MX51 processor [PATCH 6/9] fec_mxc: add support for MX51 processor [PATCH 7/9] fsl_esdhc: add support for mx51 processor [PATCH 8/9] mmc: check correctness of the voltage mask in ocr [PATCH 9/9] Add initial support for Freescale mx51evk board

#1 lore raw

PATCH 1/9 mkimage: Add Freescale imx Boot Image support (imximage)

This patch adds support for "imximage" (MX Boot Image) to the mkimage utility. The imximage is used on the Freescales's MX.51 processors.

Further details under doc/README.imximage.

This patch was tested on a Freescale mx51evk board.

---
 common/image.c      |    1 +
 doc/README.imximage |   73 +++++++++++++
 include/image.h     |    1 +
 tools/Makefile      |    2 +
 tools/imximage.c    |  289 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/imximage.h    |  107 +++++++++++++++++++
 tools/mkimage.c     |    2 +
 tools/mkimage.h     |    1 +
 8 files changed, 476 insertions(+), 0 deletions(-)
 create mode 100644 doc/README.imximage
 create mode 100644 tools/imximage.c
 create mode 100644 tools/imximage.h
common/image.c +1 -0
index 82e7aa4..9e49713 100644
@@ -140,6 +140,7 @@ static table_entry_t uimage_type[] = {
 	{	IH_TYPE_STANDALONE, "standalone", "Standalone Program", },
 	{	IH_TYPE_FLATDT,     "flat_dt",    "Flat Device Tree",	},
 	{	IH_TYPE_KWBIMAGE,   "kwbimage",   "Kirkwood Boot Image",},
+	{	IH_TYPE_IMXIMAGE,   "imximage",   "Freescale i.MX Boot Image",},
 	{	-1,		    "",		  "",			},
 };
 
doc/README.imximage new file +73 -0

73 lines not on this page · raw message

include/image.h +1 -0
index d2e78fe..3e959de 100644
@@ -156,6 +156,7 @@
 #define IH_TYPE_FILESYSTEM	7	/* Filesystem Image (any type)	*/
 #define IH_TYPE_FLATDT		8	/* Binary Flat Device Tree Blob	*/
 #define IH_TYPE_KWBIMAGE	9	/* Kirkwood Boot Image		*/
+#define IH_TYPE_IMXIMAGE	10	/* Freescale IMXBoot Image	*/
 
 /*
  * Compression Types
tools/Makefile +2 -0
index 5b8c3c3..afc1d44 100644
@@ -73,6 +73,7 @@ OBJ_FILES-$(CONFIG_CMD_NET) += gen_eth_addr.o
 OBJ_FILES-$(CONFIG_CMD_LOADS) += img2srec.o
 OBJ_FILES-$(CONFIG_INCA_IP) += inca-swap-bytes.o
 NOPED_OBJ_FILES-y += kwbimage.o
+NOPED_OBJ_FILES-y += imximage.o
 NOPED_OBJ_FILES-y += mkimage.o
 OBJ_FILES-$(CONFIG_NETCONSOLE) += ncb.o
 NOPED_OBJ_FILES-y += os_support.o
@@ -159,6 +160,7 @@ $(obj)mkimage$(SFX):	$(obj)crc32.o \
 			$(obj)fit_image.o \
 			$(obj)image.o \
 			$(obj)kwbimage.o \
+			$(obj)imximage.o \
 			$(obj)md5.o \
 			$(obj)mkimage.o \
 			$(obj)os_support.o \
tools/imximage.c new file +289 -0

289 lines not on this page · raw message

tools/imximage.h new file +107 -0

107 lines not on this page · raw message

tools/mkimage.c +2 -0
index 1bed933..8b5d7f5 100644
@@ -150,6 +150,8 @@ main (int argc, char **argv)
 
 	/* Init Kirkwood Boot image generation/list support */
 	init_kwb_image_type ();
+	/* Init Freescale imx.51 Boot image generation/list support */
+	init_imx_image_type ();
 	/* Init FIT image generation/list support */
 	init_fit_image_type ();
 	/* Init Default image generation/list support */
tools/mkimage.h +1 -0
index ec67336..9033a7d 100644
@@ -140,6 +140,7 @@ void mkimage_register (struct image_type_params *tparams);
  * Supported image types init functions
  */
 void init_kwb_image_type (void);
+void init_imx_image_type (void);
 void init_default_image_type (void);
 void init_fit_image_type (void);
 
Signature · 1 line
1.6.3.3
#2 lore raw

PATCH 2/9 MX51: Add initial support for the Freescale MX51

The patch add initial support for the Freescale i.MX51 processor (family arm cortex_a8).

Signed-off-by Fred Fan fanyefeng at gmail.com
---
 cpu/arm_cortexa8/mx51/Makefile        |   48 +++++
 cpu/arm_cortexa8/mx51/clock.c         |  282 +++++++++++++++++++++++++++++
 cpu/arm_cortexa8/mx51/iomux.c         |  205 +++++++++++++++++++++
 cpu/arm_cortexa8/mx51/lowlevel_init.S |  320 +++++++++++++++++++++++++++++++++
 cpu/arm_cortexa8/mx51/soc.c           |   78 ++++++++
 cpu/arm_cortexa8/mx51/timer.c         |  122 +++++++++++++
 cpu/arm_cortexa8/mx51/u-boot.lds      |   61 +++++++
 7 files changed, 1116 insertions(+), 0 deletions(-)
 create mode 100644 cpu/arm_cortexa8/mx51/Makefile
 create mode 100644 cpu/arm_cortexa8/mx51/clock.c
 create mode 100644 cpu/arm_cortexa8/mx51/iomux.c
 create mode 100644 cpu/arm_cortexa8/mx51/lowlevel_init.S
 create mode 100644 cpu/arm_cortexa8/mx51/soc.c
 create mode 100644 cpu/arm_cortexa8/mx51/timer.c
 create mode 100644 cpu/arm_cortexa8/mx51/u-boot.lds
cpu/arm_cortexa8/mx51/Makefile new file +48 -0
new file mode 100644
index 0000000..4d82293
@@ -0,0 +1,48 @@
+#
+# (C) Copyright 2000-2006
+# Wolfgang Denk, DENX Software Engineering, wd at denx.de.
+#
+# (C) Copyright 2009 Freescale Semiconductor, Inc.
+#
+# 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 $(TOPDIR)/config.mk
+
+LIB	= $(obj)lib$(SOC).a
+
+COBJS	= soc.o clock.o iomux.o timer.o
+SOBJS = lowlevel_init.o
+
+SRCS	:= $(SOBJS:.o=.S) $(COBJS:.o=.c)
+OBJS	:= $(addprefix $(obj),$(SOBJS) $(COBJS))
+
+all:	$(obj).depend $(LIB)
+
+$(LIB):	$(OBJS)
+	$(AR) $(ARFLAGS) $@ $(OBJS)
+
+#########################################################################
+
+# defines $(obj).depend target
+include $(SRCTREE)/rules.mk
+
+sinclude $(obj).depend
+
+#########################################################################
cpu/arm_cortexa8/mx51/clock.c new file +282 -0

282 lines not on this page · raw message

cpu/arm_cortexa8/mx51/iomux.c new file +205 -0

205 lines not on this page · raw message

cpu/arm_cortexa8/mx51/lowlevel_init.S new file +320 -0

320 lines not on this page · raw message

cpu/arm_cortexa8/mx51/soc.c new file +78 -0

78 lines not on this page · raw message

cpu/arm_cortexa8/mx51/timer.c new file +122 -0

122 lines not on this page · raw message

cpu/arm_cortexa8/mx51/u-boot.lds new file +61 -0

61 lines not on this page · raw message

Signature · 1 line
1.6.3.3
#3 lore raw

PATCH 3/9 MX51: Add register definitions

The patch add header files to support the Freescale i.MX51 processor, setting definitions for internal registers.

Signed-off-by Fred Fan fanyefeng at gmail.com
---
 include/asm-arm/arch-mx51/crm_regs.h |  182 +++++++++++++++++++++
 include/asm-arm/arch-mx51/imx-regs.h |  298 ++++++++++++++++++++++++++++++++++
 2 files changed, 480 insertions(+), 0 deletions(-)
 create mode 100644 include/asm-arm/arch-mx51/crm_regs.h
 create mode 100644 include/asm-arm/arch-mx51/imx-regs.h
include/asm-arm/arch-mx51/crm_regs.h new file +182 -0
new file mode 100644
index 0000000..92da560
@@ -0,0 +1,182 @@
+/*
+ * Copyright 2009 Freescale Semiconductor, Inc. All Rights Reserved.
+ */
+
+/*
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+#ifndef __ARCH_ARM_MACH_MX51_CRM_REGS_H__
+#define __ARCH_ARM_MACH_MX51_CRM_REGS_H__
+
+#define MXC_CCM_BASE	CCM_BASE_ADDR
+
+/* DPLL register mapping structure */
+struct mxc_pll_reg {
+	unsigned int ctrl;
+	unsigned int config;
+	unsigned int op;
+	unsigned int mfd;
+	unsigned int mfn;
+	unsigned int mfn_minus;
+	unsigned int mfn_plus;
+	unsigned int hfs_op;
+	unsigned int hfs_mfd;
+	unsigned int hfs_mfn;
+	unsigned int mfn_togc;
+	unsigned int destat;
+};
+
+/* Register maping of CCM*/
+struct mxc_ccm_reg {
+	unsigned int ccr;	/* 0x0000 */
+	unsigned int ccdr;
+	unsigned int csr;
+	unsigned int ccsr;
+	unsigned int cacrr;	/* 0x0010*/
+	unsigned int cbcdr;
+	unsigned int cbcmr;
+	unsigned int cscmr1;
+	unsigned int cscmr2;	/* 0x0020 */
+	unsigned int cscdr1;
+	unsigned int cs1cdr;
+	unsigned int cs2cdr;
+	unsigned int cdcdr;	/* 0x0030 */
+	unsigned int chscdr;
+	unsigned int cscdr2;
+	unsigned int cscdr3;
+	unsigned int cscdr4;	/* 0x0040 */
+	unsigned int cwdr;
+	unsigned int cdhipr;
+	unsigned int cdcr;
+	unsigned int ctor;	/* 0x0050 */
+	unsigned int clpcr;
+	unsigned int cisr;
+	unsigned int cimr;
+	unsigned int ccosr;	/* 0x0060 */
+	unsigned int cgpr;
+	unsigned int CCGR0;
+	unsigned int CCGR1;
+	unsigned int CCGR2;	/* 0x0070 */
+	unsigned int CCGR3;
+	unsigned int CCGR4;
+	unsigned int CCGR5;
+	unsigned int CCGR6;	/* 0x0080 */
+	unsigned int cmeor;
+};
+
+/* Define the bits in register CACRR */
+#define MXC_CCM_CACRR_ARM_PODF_OFFSET	(0)
+#define MXC_CCM_CACRR_ARM_PODF_MASK		(0x7)
+
+/* Define the bits in register CBCDR */
+#define MXC_CCM_CBCDR_EMI_CLK_SEL			(0x1 << 26)
+#define MXC_CCM_CBCDR_PERIPH_CLK_SEL			(0x1 << 25)
+#define MXC_CCM_CBCDR_EMI_PODF_OFFSET		(22)
+#define MXC_CCM_CBCDR_EMI_PODF_MASK			(0x7 << 22)
+#define MXC_CCM_CBCDR_AXI_B_PODF_OFFSET		(19)
+#define MXC_CCM_CBCDR_AXI_B_PODF_MASK		(0x7 << 19)
+#define MXC_CCM_CBCDR_AXI_A_PODF_OFFSET		(16)
+#define MXC_CCM_CBCDR_AXI_A_PODF_MASK		(0x7 << 16)
+#define MXC_CCM_CBCDR_NFC_PODF_OFFSET		(13)
+#define MXC_CCM_CBCDR_NFC_PODF_MASK			(0x7 << 13)
+#define MXC_CCM_CBCDR_AHB_PODF_OFFSET		(10)
+#define MXC_CCM_CBCDR_AHB_PODF_MASK			(0x7 << 10)
+#define MXC_CCM_CBCDR_IPG_PODF_OFFSET		(8)
+#define MXC_CCM_CBCDR_IPG_PODF_MASK			(0x3 << 8)
+#define MXC_CCM_CBCDR_PERCLK_PRED1_OFFSET		(6)
+#define MXC_CCM_CBCDR_PERCLK_PRED1_MASK		(0x3 << 6)
+#define MXC_CCM_CBCDR_PERCLK_PRED2_OFFSET		(3)
+#define MXC_CCM_CBCDR_PERCLK_PRED2_MASK		(0x7 << 3)
+#define MXC_CCM_CBCDR_PERCLK_PODF_OFFSET		(0)
+#define MXC_CCM_CBCDR_PERCLK_PODF_MASK		(0x7)
+
+/* Define the bits in register CSCMR1 */
+#define MXC_CCM_CSCMR1_SSI_EXT2_CLK_SEL_OFFSET		(30)
+#define MXC_CCM_CSCMR1_SSI_EXT2_CLK_SEL_MASK		(0x3 << 30)
+#define MXC_CCM_CSCMR1_SSI_EXT1_CLK_SEL_OFFSET		(28)
+#define MXC_CCM_CSCMR1_SSI_EXT1_CLK_SEL_MASK		(0x3 << 28)
+#define MXC_CCM_CSCMR1_USB_PHY_CLK_SEL_OFFSET		(26)
+#define MXC_CCM_CSCMR1_USB_PHY_CLK_SEL			(0x1 << 26)
+#define MXC_CCM_CSCMR1_UART_CLK_SEL_OFFSET			(24)
+#define MXC_CCM_CSCMR1_UART_CLK_SEL_MASK			(0x3 << 24)
+#define MXC_CCM_CSCMR1_USBOH3_CLK_SEL_OFFSET		(22)
+#define MXC_CCM_CSCMR1_USBOH3_CLK_SEL_MASK			(0x3 << 22)
+#define MXC_CCM_CSCMR1_ESDHC1_MSHC1_CLK_SEL_OFFSET	(20)
+#define MXC_CCM_CSCMR1_ESDHC1_MSHC1_CLK_SEL_MASK		(0x3 << 20)
+#define MXC_CCM_CSCMR1_ESDHC3_CLK_SEL			(0x1 << 19)
+#define MXC_CCM_CSCMR1_ESDHC4_CLK_SEL			(0x1 << 18)
+#define MXC_CCM_CSCMR1_ESDHC2_MSHC2_CLK_SEL_OFFSET	(16)
+#define MXC_CCM_CSCMR1_ESDHC2_MSHC2_CLK_SEL_MASK		(0x3 << 16)
+#define MXC_CCM_CSCMR1_SSI1_CLK_SEL_OFFSET			(14)
+#define MXC_CCM_CSCMR1_SSI1_CLK_SEL_MASK			(0x3 << 14)
+#define MXC_CCM_CSCMR1_SSI2_CLK_SEL_OFFSET			(12)
+#define MXC_CCM_CSCMR1_SSI2_CLK_SEL_MASK			(0x3 << 12)
+#define MXC_CCM_CSCMR1_SSI3_CLK_SEL				(0x1 << 11)
+#define MXC_CCM_CSCMR1_VPU_RCLK_SEL				(0x1 << 10)
+#define MXC_CCM_CSCMR1_SSI_APM_CLK_SEL_OFFSET		(8)
+#define MXC_CCM_CSCMR1_SSI_APM_CLK_SEL_MASK		(0x3 << 8)
+#define MXC_CCM_CSCMR1_TVE_CLK_SEL				(0x1 << 7)
+#define MXC_CCM_CSCMR1_TVE_EXT_CLK_SEL			(0x1 << 6)
+#define MXC_CCM_CSCMR1_CSPI_CLK_SEL_OFFSET			(4)
+#define MXC_CCM_CSCMR1_CSPI_CLK_SEL_MASK			(0x3 << 4)
+#define MXC_CCM_CSCMR1_SPDIF_CLK_SEL_OFFSET			(2)
+#define MXC_CCM_CSCMR1_SPDIF_CLK_SEL_MASK			(0x3 << 2)
+#define MXC_CCM_CSCMR1_SSI_EXT2_COM_CLK_SEL			(0x1 << 1)
+#define MXC_CCM_CSCMR1_SSI_EXT1_COM_CLK_SEL			(0x1)
+
+/* Define the bits in register CSCDR2 */
+#define MXC_CCM_CSCDR2_CSPI_CLK_PRED_OFFSET		(25)
+#define MXC_CCM_CSCDR2_CSPI_CLK_PRED_MASK		(0x7 << 25)
+#define MXC_CCM_CSCDR2_CSPI_CLK_PODF_OFFSET		(19)
+#define MXC_CCM_CSCDR2_CSPI_CLK_PODF_MASK		(0x3F << 19)
+#define MXC_CCM_CSCDR2_SIM_CLK_PRED_OFFSET		(16)
+#define MXC_CCM_CSCDR2_SIM_CLK_PRED_MASK		(0x7 << 16)
+#define MXC_CCM_CSCDR2_SIM_CLK_PODF_OFFSET		(9)
+#define MXC_CCM_CSCDR2_SIM_CLK_PODF_MASK		(0x3F << 9)
+#define MXC_CCM_CSCDR2_SLIMBUS_CLK_PRED_OFFSET	(6)
+#define MXC_CCM_CSCDR2_SLIMBUS_PRED_MASK		(0x7 << 6)
+#define MXC_CCM_CSCDR2_SLIMBUS_PODF_OFFSET		(0)
+#define MXC_CCM_CSCDR2_SLIMBUS_PODF_MASK		(0x3F)
+
+/* Define the bits in register CBCMR */
+#define MXC_CCM_CBCMR_VPU_AXI_CLK_SEL_OFFSET	(14)
+#define MXC_CCM_CBCMR_VPU_AXI_CLK_SEL_MASK		(0x3 << 14)
+#define MXC_CCM_CBCMR_PERIPH_CLK_SEL_OFFSET		(12)
+#define MXC_CCM_CBCMR_PERIPH_CLK_SEL_MASK		(0x3 << 12)
+#define MXC_CCM_CBCMR_DDR_CLK_SEL_OFFSET		(10)
+#define MXC_CCM_CBCMR_DDR_CLK_SEL_MASK		(0x3 << 10)
+#define MXC_CCM_CBCMR_ARM_AXI_CLK_SEL_OFFSET	(8)
+#define MXC_CCM_CBCMR_ARM_AXI_CLK_SEL_MASK		(0x3 << 8)
+#define MXC_CCM_CBCMR_IPU_HSP_CLK_SEL_OFFSET	(6)
+#define MXC_CCM_CBCMR_IPU_HSP_CLK_SEL_MASK		(0x3 << 6)
+#define MXC_CCM_CBCMR_GPU_CLK_SEL_OFFSET		(4)
+#define MXC_CCM_CBCMR_GPU_CLK_SEL_MASK		(0x3 << 4)
+#define MXC_CCM_CBCMR_PERCLK_LP_APM_CLK_SEL		(0x1 << 1)
+#define MXC_CCM_CBCMR_PERCLK_IPG_CLK_SEL		(0x1 << 0)
+
+/* Define the bits in register CSCDR1 */
+#define MXC_CCM_CSCDR1_ESDHC2_MSHC2_CLK_PRED_OFFSET	(22)
+#define MXC_CCM_CSCDR1_ESDHC2_MSHC2_CLK_PRED_MASK		(0x7 << 22)
+#define MXC_CCM_CSCDR1_ESDHC2_MSHC2_CLK_PODF_OFFSET	(19)
+#define MXC_CCM_CSCDR1_ESDHC2_MSHC2_CLK_PODF_MASK		(0x7 << 19)
+#define MXC_CCM_CSCDR1_ESDHC1_MSHC1_CLK_PRED_OFFSET	(16)
+#define MXC_CCM_CSCDR1_ESDHC1_MSHC1_CLK_PRED_MASK		(0x7 << 16)
+#define MXC_CCM_CSCDR1_PGC_CLK_PODF_OFFSET			(14)
+#define MXC_CCM_CSCDR1_PGC_CLK_PODF_MASK			(0x3 << 14)
+#define MXC_CCM_CSCDR1_ESDHC1_MSHC1_CLK_PODF_OFFSET	(11)
+#define MXC_CCM_CSCDR1_ESDHC1_MSHC1_CLK_PODF_MASK		(0x7 << 11)
+#define MXC_CCM_CSCDR1_USBOH3_CLK_PRED_OFFSET		(8)
+#define MXC_CCM_CSCDR1_USBOH3_CLK_PRED_MASK		(0x7 << 8)
+#define MXC_CCM_CSCDR1_USBOH3_CLK_PODF_OFFSET		(6)
+#define MXC_CCM_CSCDR1_USBOH3_CLK_PODF_MASK		(0x3 << 6)
+#define MXC_CCM_CSCDR1_UART_CLK_PRED_OFFSET		(3)
+#define MXC_CCM_CSCDR1_UART_CLK_PRED_MASK			(0x7 << 3)
+#define MXC_CCM_CSCDR1_UART_CLK_PODF_OFFSET		(0)
+#define MXC_CCM_CSCDR1_UART_CLK_PODF_MASK			(0x7)
+
+#endif				/* __ARCH_ARM_MACH_MX51_CRM_REGS_H__ */
include/asm-arm/arch-mx51/imx-regs.h new file +298 -0

298 lines not on this page · raw message

Signature · 1 line
1.6.3.3
#4 lore raw

PATCH 4/9 MX51: Add pin and multiplexer definitions.

The patch add header files to support the pin multiplexer of the the Freescale i.MX51 processor.

Signed-off-by Fred Fan fanyefeng at gmail.com
---
 include/asm-arm/arch-mx51/iomux.h     |  240 ++++++++++++++++++++++
 include/asm-arm/arch-mx51/mx51_pins.h |  365 +++++++++++++++++++++++++++++++++
 2 files changed, 605 insertions(+), 0 deletions(-)
 create mode 100644 include/asm-arm/arch-mx51/iomux.h
 create mode 100644 include/asm-arm/arch-mx51/mx51_pins.h
include/asm-arm/arch-mx51/iomux.h new file +240 -0
new file mode 100644
index 0000000..3724bb8
@@ -0,0 +1,240 @@
+/*
+ * Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved.
+ */
+
+/*
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+#ifndef __MACH_MX51_IOMUX_H__
+#define __MACH_MX51_IOMUX_H__
+
+#include <common.h>
+#include <asm/io.h>
+#include <asm/arch/imx-regs.h>
+#include <asm/arch/mx51_pins.h>
+
+/*!
+ * @file iomux.h
+ *
+ * @brief I/O Muxing control definitions and functions
+ *
+ * @ingroup GPIO_MX51
+ */
+
+typedef unsigned int iomux_pin_name_t;
+
+/*!
+ * various IOMUX output functions
+ */
+typedef enum iomux_config {
+	IOMUX_CONFIG_ALT0,	/*!< used as alternate function 0 */
+	IOMUX_CONFIG_ALT1,	/*!< used as alternate function 1 */
+	IOMUX_CONFIG_ALT2,	/*!< used as alternate function 2 */
+	IOMUX_CONFIG_ALT3,	/*!< used as alternate function 3 */
+	IOMUX_CONFIG_ALT4,	/*!< used as alternate function 4 */
+	IOMUX_CONFIG_ALT5,	/*!< used as alternate function 5 */
+	IOMUX_CONFIG_ALT6,	/*!< used as alternate function 6 */
+	IOMUX_CONFIG_ALT7,	/*!< used as alternate function 7 */
+	IOMUX_CONFIG_GPIO,	/*!< added to help user use GPIO mode */
+	IOMUX_CONFIG_SION = 0x1 << 4,	/*!< used as LOOPBACK:MUX SION bit */
+} iomux_pin_cfg_t;
+
+/*!
+ * various IOMUX pad functions
+ */
+typedef enum iomux_pad_config {
+	PAD_CTL_SRE_SLOW = 0x0 << 0,
+	PAD_CTL_SRE_FAST = 0x1 << 0,
+	PAD_CTL_DRV_LOW = 0x0 << 1,
+	PAD_CTL_DRV_MEDIUM = 0x1 << 1,
+	PAD_CTL_DRV_HIGH = 0x2 << 1,
+	PAD_CTL_DRV_MAX = 0x3 << 1,
+	PAD_CTL_ODE_OPENDRAIN_NONE = 0x0 << 3,
+	PAD_CTL_ODE_OPENDRAIN_ENABLE = 0x1 << 3,
+	PAD_CTL_100K_PD = 0x0 << 4,
+	PAD_CTL_47K_PU = 0x1 << 4,
+	PAD_CTL_100K_PU = 0x2 << 4,
+	PAD_CTL_22K_PU = 0x3 << 4,
+	PAD_CTL_PUE_KEEPER = 0x0 << 6,
+	PAD_CTL_PUE_PULL = 0x1 << 6,
+	PAD_CTL_PKE_NONE = 0x0 << 7,
+	PAD_CTL_PKE_ENABLE = 0x1 << 7,
+	PAD_CTL_HYS_NONE = 0x0 << 8,
+	PAD_CTL_HYS_ENABLE = 0x1 << 8,
+	PAD_CTL_DDR_INPUT_CMOS = 0x0 << 9,
+	PAD_CTL_DDR_INPUT_DDR = 0x1 << 9,
+	PAD_CTL_DRV_VOT_LOW = 0x0 << 13,
+	PAD_CTL_DRV_VOT_HIGH = 0x1 << 13,
+} iomux_pad_config_t;
+
+/*!
+ * various IOMUX input select register index
+ */
+typedef enum iomux_input_select {
+	MUX_IN_AUDMUX_P4_INPUT_DA_AMX_SELECT_I = 0,
+	MUX_IN_AUDMUX_P4_INPUT_DB_AMX_SELECT_I,
+	MUX_IN_AUDMUX_P4_INPUT_TXCLK_AMX_SELECT_INPUT,
+	MUX_IN_AUDMUX_P4_INPUT_TXFS_AMX_SELECT_INPUT,
+	MUX_IN_AUDMUX_P5_INPUT_DA_AMX_SELECT_INPUT,
+	MUX_IN_AUDMUX_P5_INPUT_DB_AMX_SELECT_INPUT,
+	MUX_IN_AUDMUX_P5_INPUT_RXCLK_AMX_SELECT_INPUT,
+	MUX_IN_AUDMUX_P5_INPUT_RXFS_AMX_SELECT,
+	MUX_IN_AUDMUX_P5_INPUT_TXCLK_AMX_SELECT_INPUT,
+	MUX_IN_AUDMUX_P5_INPUT_TXFS_AMX_SELECT_INPUT,
+	MUX_IN_AUDMUX_P6_INPUT_DA_AMX_SELECT_INPUT,
+	MUX_IN_AUDMUX_P6_INPUT_DB_AMX_SELECT_INPUT,
+	MUX_IN_AUDMUX_P6_INPUT_RXCLK_AMX_SELECT_INPUT,
+	MUX_IN_AUDMUX_P6_INPUT_RXFS_AMX_SELECT_INPUT,
+	MUX_IN_AUDMUX_P6_INPUT_TXCLK_AMX_SELECT_INPUT,
+	MUX_IN_AUDMUX_P6_INPUT_TXFS_AMX_SELECT_INPUT,
+	MUX_IN_CCM_IPP_DI_CLK_SELECT_INPUT,
+	/* TO2 */
+	MUX_IN_CCM_IPP_DI1_CLK_SELECT_INPUT,
+	MUX_IN_CCM_PLL1_BYPASS_CLK_SELECT_INPUT,
+	MUX_IN_CCM_PLL2_BYPASS_CLK_SELECT_INPUT,
+	MUX_IN_CSPI_IPP_CSPI_CLK_IN_SELECT_INPUT,
+	MUX_IN_CSPI_IPP_IND_MISO_SELECT_INPUT,
+	MUX_IN_CSPI_IPP_IND_MOSI_SELECT_INPUT,
+	MUX_IN_CSPI_IPP_IND_SS_B_1_SELECT_INPUT,
+	MUX_IN_CSPI_IPP_IND_SS_B_2_SELECT_INPUT,
+	MUX_IN_CSPI_IPP_IND_SS_B_3_SELECT_INPUT,
+	MUX_IN_DPLLIP1_L1T_TOG_EN_SELECT_INPUT,
+	/* TO2 */
+	MUX_IN_ECSPI2_IPP_IND_SS_B_1_SELECT_INPUT,
+	MUX_IN_ECSPI2_IPP_IND_SS_B_3_SELECT_INPUT,
+	MUX_IN_EMI_IPP_IND_RDY_INT_SELECT_INPUT,
+	MUX_IN_ESDHC3_IPP_DAT0_IN_SELECT_INPUT,
+	MUX_IN_ESDHC3_IPP_DAT1_IN_SELECT_INPUT,
+	MUX_IN_ESDHC3_IPP_DAT2_IN_SELECT_INPUT,
+	MUX_IN_ESDHC3_IPP_DAT3_IN_SELECT_INPUT,
+	MUX_IN_FEC_FEC_COL_SELECT_INPUT,
+	MUX_IN_FEC_FEC_CRS_SELECT_INPUT,
+	MUX_IN_FEC_FEC_MDI_SELECT_INPUT,
+	MUX_IN_FEC_FEC_RDATA_0_SELECT_INPUT,
+	MUX_IN_FEC_FEC_RDATA_1_SELECT_INPUT,
+	MUX_IN_FEC_FEC_RDATA_2_SELECT_INPUT,
+	MUX_IN_FEC_FEC_RDATA_3_SELECT_INPUT,
+	MUX_IN_FEC_FEC_RX_CLK_SELECT_INPUT,
+	MUX_IN_FEC_FEC_RX_DV_SELECT_INPUT,
+	MUX_IN_FEC_FEC_RX_ER_SELECT_INPUT,
+	MUX_IN_FEC_FEC_TX_CLK_SELECT_INPUT,
+	MUX_IN_GPIO3_IPP_IND_G_IN_1_SELECT_INPUT,
+	MUX_IN_GPIO3_IPP_IND_G_IN_2_SELECT_INPUT,
+	MUX_IN_GPIO3_IPP_IND_G_IN_3_SELECT_INPUT,
+	MUX_IN_GPIO3_IPP_IND_G_IN_4_SELECT_INPUT,
+	MUX_IN_GPIO3_IPP_IND_G_IN_5_SELECT_INPUT,
+	MUX_IN_GPIO3_IPP_IND_G_IN_6_SELECT_INPUT,
+	MUX_IN_GPIO3_IPP_IND_G_IN_7_SELECT_INPUT,
+	MUX_IN_GPIO3_IPP_IND_G_IN_8_SELECT_INPUT,
+	/* TO2 */
+	MUX_IN_GPIO3_IPP_IND_G_IN_12_SELECT_INPUT,
+	MUX_IN_HSC_MIPI_MIX_IPP_IND_SENS1_DATA_EN_SELECT_INPUT,
+	MUX_IN_HSC_MIPI_MIX_IPP_IND_SENS2_DATA_EN_SELECT_INPUT,
+	/* TO2 */
+	MUX_IN_HSC_MIPI_MIX_PAR_VSYNC_SELECT_INPUT,
+	/* TO2 */
+	MUX_IN_HSC_MIPI_MIX_PAR_DI_WAIT_SELECT_INPUT,
+	MUX_IN_HSC_MIPI_MIX_PAR_SISG_TRIG_SELECT_INPUT,
+	MUX_IN_I2C1_IPP_SCL_IN_SELECT_INPUT,
+	MUX_IN_I2C1_IPP_SDA_IN_SELECT_INPUT,
+	MUX_IN_I2C2_IPP_SCL_IN_SELECT_INPUT,
+	MUX_IN_I2C2_IPP_SDA_IN_SELECT_INPUT,
+
+	MUX_IN_IPU_IPP_DI_0_IND_DISPB_SD_D_SELECT_INPUT,
+
+	MUX_IN_IPU_IPP_DI_1_IND_DISPB_SD_D_SELECT_INPUT,
+
+	MUX_IN_KPP_IPP_IND_COL_6_SELECT_INPUT,
+	MUX_IN_KPP_IPP_IND_COL_7_SELECT_INPUT,
+	MUX_IN_KPP_IPP_IND_ROW_4_SELECT_INPUT,
+	MUX_IN_KPP_IPP_IND_ROW_5_SELECT_INPUT,
+	MUX_IN_KPP_IPP_IND_ROW_6_SELECT_INPUT,
+	MUX_IN_KPP_IPP_IND_ROW_7_SELECT_INPUT,
+	MUX_IN_UART1_IPP_UART_RTS_B_SELECT_INPUT,
+	MUX_IN_UART1_IPP_UART_RXD_MUX_SELECT_INPUT,
+	MUX_IN_UART2_IPP_UART_RTS_B_SELECT_INPUT,
+	MUX_IN_UART2_IPP_UART_RXD_MUX_SELECT_INPUT,
+	MUX_IN_UART3_IPP_UART_RTS_B_SELECT_INPUT,
+	MUX_IN_UART3_IPP_UART_RXD_MUX_SELECT_INPUT,
+	MUX_IN_USBOH3_IPP_IND_UH3_CLK_SELECT_INPUT,
+	MUX_IN_USBOH3_IPP_IND_UH3_DATA_0_SELECT_INPUT,
+	MUX_IN_USBOH3_IPP_IND_UH3_DATA_1_SELECT_INPUT,
+	MUX_IN_USBOH3_IPP_IND_UH3_DATA_2_SELECT_INPUT,
+	MUX_IN_USBOH3_IPP_IND_UH3_DATA_3_SELECT_INPUT,
+	MUX_IN_USBOH3_IPP_IND_UH3_DATA_4_SELECT_INPUT,
+	MUX_IN_USBOH3_IPP_IND_UH3_DATA_5_SELECT_INPUT,
+	MUX_IN_USBOH3_IPP_IND_UH3_DATA_6_SELECT_INPUT,
+	MUX_IN_USBOH3_IPP_IND_UH3_DATA_7_SELECT_INPUT,
+	MUX_IN_USBOH3_IPP_IND_UH3_DIR_SELECT_INPUT,
+	MUX_IN_USBOH3_IPP_IND_UH3_NXT_SELECT_INPUT,
+	MUX_IN_USBOH3_IPP_IND_UH3_STP_SELECT_INPUT,
+	MUX_INPUT_NUM_MUX,
+} iomux_input_select_t;
+
+/*!
+ * various IOMUX input functions
+ */
+typedef enum iomux_input_config {
+	INPUT_CTL_PATH0 = 0x0,
+	INPUT_CTL_PATH1,
+	INPUT_CTL_PATH2,
+	INPUT_CTL_PATH3,
+	INPUT_CTL_PATH4,
+	INPUT_CTL_PATH5,
+	INPUT_CTL_PATH6,
+	INPUT_CTL_PATH7,
+} iomux_input_config_t;
+
+/*!
+ * Request ownership for an IO pin. This function has to be the first one
+ * being called before that pin is used. The caller has to check the
+ * return value to make sure it returns 0.
+ *
+ * @param  pin		a name defined by \b iomux_pin_name_t
+ * @param  config	config as defined in \b #iomux_pin_ocfg_t
+ *
+ * @return		0 if successful; Non-zero otherwise
+ */
+void mxc_request_iomux(iomux_pin_name_t pin, iomux_pin_cfg_t config);
+
+/*!
+ * Release ownership for an IO pin
+ *
+ * @param  pin		a name defined by \b iomux_pin_name_t
+ * @param  config	config as defined in \b #iomux_pin_ocfg_t
+ */
+void mxc_free_iomux(iomux_pin_name_t pin, iomux_pin_cfg_t config);
+
+/*!
+ * This function configures the pad value for a IOMUX pin.
+ *
+ * @param  pin          a pin number as defined in \b #iomux_pin_name_t
+ * @param  config      the ORed value of elements defined in
+ *                             \b #iomux_pad_config_t
+ */
+void mxc_iomux_set_pad(iomux_pin_name_t pin, u32 config);
+
+/*!
+ * This function gets the current pad value for a IOMUX pin.
+ *
+ * @param  pin          a pin number as defined in \b #iomux_pin_name_t
+ * @return		current pad value
+ */
+unsigned int mxc_iomux_get_pad(iomux_pin_name_t pin);
+
+/*!
+ * This function configures input path.
+ *
+ * @param  input        index of input select register as defined in
+ *                              \b #iomux_input_select_t
+ * @param  config       the binary value of elements defined in
+ *				\b #iomux_input_config_t
+ */
+void mxc_iomux_set_input(iomux_input_select_t input, u32 config);
+
+#endif				/*  __MACH_MX51_IOMUX_H__ */
include/asm-arm/arch-mx51/mx51_pins.h new file +365 -0

365 lines not on this page · raw message

Signature · 1 line
1.6.3.3
#5 lore raw

PATCH 5/9 serial_mxc: add support for MX51 processor

The patch adds support for the Freescale mx51 processor.

Signed-off-by Fred Fan fanyefeng at gmail.com
---
 drivers/serial/serial_mxc.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
drivers/serial/serial_mxc.c +11 -1
index acc5b7d..e34733b 100644
@@ -20,6 +20,8 @@
 #include <common.h>
 #ifdef CONFIG_MX31
 #include <asm/arch/mx31.h>
+#elif defined(CONFIG_MX51)
+#include <asm/arch/imx-regs.h>
 #else
 #include <asm/arch/imx-regs.h>
 #include <asm/arch/clock.h>
@@ -49,8 +51,14 @@
 #define UART_PHYS 0x1001b000
 #elif defined(CONFIG_SYS_MX27_UART6)
 #define UART_PHYS 0x1001c000
+#elif defined(CONFIG_SYS_MX51_UART1)
+#define UART_PHYS UART1_BASE_ADDR
+#elif defined(CONFIG_SYS_MX51_UART2)
+#define UART_PHYS UART2_BASE_ADDR
+#elif defined(CONFIG_SYS_MX51_UART3)
+#define UART_PHYS UART3_BASE_ADDR
 #else
-#error "define CONFIG_SYS_MX31_UARTx to use the mx31 UART driver"
+#error "define CONFIG_SYS_MXxx_UARTx to use the mxxx UART driver"
 #endif
 
 /* Register definitions */
@@ -168,6 +176,8 @@ void serial_setbrg (void)
 {
 #ifdef CONFIG_MX31
 	u32 clk = mx31_get_ipg_clk();
+#elif defined(CONFIG_MX51)
+	u32 clk = mxc_get_clock(MXC_UART_CLK);
 #else
 	u32 clk = imx_get_perclk1();
 #endif
Signature · 1 line
1.6.3.3
#6 lore raw

PATCH 6/9 fec_mxc: add support for MX51 processor

The patch add support for the Freescale mx51 processor to the FEC ethernet driver.

---
 drivers/net/fec_mxc.c |   57 ++++++++++++++++++++++++++++++-------------------
 1 files changed, 35 insertions(+), 22 deletions(-)
drivers/net/fec_mxc.c +35 -22
index 19116f2..203832e 100644
@@ -27,8 +27,10 @@
 #include <miiphy.h>
 #include "fec_mxc.h"
 
-#include <asm/arch/clock.h>
 #include <asm/arch/imx-regs.h>
+#ifndef CONFIG_MX51
+#include <asm/arch/clock.h>
+#endif
 #include <asm/io.h>
 #include <asm/errno.h>
 
@@ -108,6 +110,23 @@ static int fec_miiphy_read(char *dev, uint8_t phyAddr, uint8_t regAddr,
 	return 0;
 }
 
+static void fec_mii_setspeed(struct fec_priv *fec)
+{
+#ifdef CONFIG_MX51
+	writel((((mxc_get_clock(MXC_IPG_CLK) + 499999) / 5000000) << 1),
+			&fec->eth->mii_speed);
+#else
+	/*
+	 * Set MII_SPEED = (1/(mii_speed * 2)) * System Clock
+	 * and do not drop the Preamble.
+	 */
+	writel((((imx_get_ahbclk() / 1000000) + 2) / 5) << 1,
+			&fec->eth->mii_speed);
+	debug("fec_init: mii_speed %#lx\n",
+			(((imx_get_ahbclk() / 1000000) + 2) / 5) << 1);
+#endif
+
+}
 static int fec_miiphy_write(char *dev, uint8_t phyAddr, uint8_t regAddr,
 		uint16_t data)
 {
@@ -236,7 +255,7 @@ static int fec_rbd_init(struct fec_priv *fec, int count, int size)
 		fec->rdb_ptr = malloc(size * count + DB_DATA_ALIGNMENT);
 	p = (uint32_t)fec->rdb_ptr;
 	if (!p) {
-		puts("fec_imx27: not enough malloc memory!\n");
+		puts("fec_mxc: not enough malloc memory!\n");
 		return -ENOMEM;
 	}
 	memset((void *)p, 0, size * count + DB_DATA_ALIGNMENT);
@@ -299,6 +318,7 @@ static void fec_rbd_clean(int last, struct fec_bd *pRbd)
 
 static int fec_get_hwaddr(struct eth_device *dev, unsigned char *mac)
 {
+#ifndef CONFIG_MX51
 	struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE;
 	int i;
 
@@ -306,6 +326,9 @@ static int fec_get_hwaddr(struct eth_device *dev, unsigned char *mac)
 		mac[6-1-i] = readl(&iim->iim_bank_area0[IIM0_MAC + i]);
 
 	return is_valid_ether_addr(mac);
+#else
+	return -1;
+#endif
 }
 
 static int fec_set_hwaddr(struct eth_device *dev, unsigned char *mac)
@@ -373,7 +396,7 @@ static int fec_init(struct eth_device *dev, bd_t* bd)
 				sizeof(struct fec_bd) + DB_ALIGNMENT);
 	base = (uint32_t)fec->base_ptr;
 	if (!base) {
-		puts("fec_imx27: not enough malloc memory!\n");
+		puts("fec_mxc: not enough malloc memory!\n");
 		return -ENOMEM;
 	}
 	memset((void *)base, 0, (2 + FEC_RBD_NUM) *
@@ -411,14 +434,8 @@ static int fec_init(struct eth_device *dev, bd_t* bd)
 		 * Frame length=1518; MII mode;
 		 */
 		writel(0x05ee0024, &fec->eth->r_cntrl);	/* FIXME 0x05ee0004 */
-		/*
-		 * Set MII_SPEED = (1/(mii_speed * 2)) * System Clock
-		 * and do not drop the Preamble.
-		 */
-		writel((((imx_get_ahbclk() / 1000000) + 2) / 5) << 1,
-				&fec->eth->mii_speed);
-		debug("fec_init: mii_speed %#lx\n",
-				(((imx_get_ahbclk() / 1000000) + 2) / 5) << 1);
+
+		fec_mii_setspeed(fec);
 	}
 	/*
 	 * Set Opcode/Pause Duration Register
@@ -651,22 +668,24 @@ static int fec_recv(struct eth_device *dev)
 
 static int fec_probe(bd_t *bd)
 {
-	struct pll_regs *pll = (struct pll_regs *)IMX_PLL_BASE;
 	struct eth_device *edev;
 	struct fec_priv *fec = &gfec;
 	unsigned char ethaddr_str[20];
 	unsigned char ethaddr[6];
-	char *tmp = getenv("ethaddr");
+	char *tmp;
 	char *end;
+#ifndef CONFIG_MX51
+	struct pll_regs *pll = (struct pll_regs *)IMX_PLL_BASE;
 
 	/* enable FEC clock */
 	writel(readl(&pll->pccr1) | PCCR1_HCLK_FEC, &pll->pccr1);
 	writel(readl(&pll->pccr0) | PCCR0_FEC_EN, &pll->pccr0);
+#endif
 
 	/* create and fill edev struct */
 	edev = (struct eth_device *)malloc(sizeof(struct eth_device));
 	if (!edev) {
-		puts("fec_imx27: not enough malloc memory!\n");
+		puts("fec_mxc: not enough malloc memory!\n");
 		return -ENOMEM;
 	}
 	edev->priv = fec;
@@ -702,14 +721,7 @@ static int fec_probe(bd_t *bd)
 	 * Frame length=1518; MII mode;
 	 */
 	writel(0x05ee0024, &fec->eth->r_cntrl);	/* FIXME 0x05ee0004 */
-	/*
-	 * Set MII_SPEED = (1/(mii_speed * 2)) * System Clock
-	 * and do not drop the Preamble.
-	 */
-	writel((((imx_get_ahbclk() / 1000000) + 2) / 5) << 1,
-			&fec->eth->mii_speed);
-	debug("fec_init: mii_speed %#lx\n",
-			(((imx_get_ahbclk() / 1000000) + 2) / 5) << 1);
+	fec_mii_setspeed(fec);
 
 	sprintf(edev->name, "FEC_MXC");
 
@@ -717,6 +729,7 @@ static int fec_probe(bd_t *bd)
 
 	eth_register(edev);
 
+	tmp = getenv("ethaddr");
 	if ((NULL != tmp) && (12 <= strlen(tmp))) {
 		int i;
 		/* convert MAC from string to int */
Signature · 1 line
1.6.3.3
#7 lore raw

PATCH 7/9 fsl_esdhc: add support for mx51 processor

The esdhc controller in the mx51 processor is quite the same as the one in some powerpc processors (MPC83xx, MPC85xx). This patches adapts the driver to support the arm mx51.

---
 drivers/mmc/fsl_esdhc.c |   72 +++++++++++++++++++++++++++++++++++++++-------
 include/asm-arm/io.h    |   21 +++++++++++++
 include/fsl_esdhc.h     |    6 +++-
 include/mmc.h           |    1 +
 4 files changed, 88 insertions(+), 12 deletions(-)
drivers/mmc/fsl_esdhc.c +61 -11
index c6e9e6e..5dcf6a8 100644
@@ -37,6 +37,10 @@
 #include <fdt_support.h>
 #include <asm/io.h>
 
+#ifndef CONFIG_PPC
+#define out_be32(a,v)	writel(v,a)
+#define in_be32(a)	__raw_readl(a)
+#endif
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -129,7 +133,7 @@ static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data)
 	out_be32(&regs->blkattr, data->blocks << 16 | data->blocksize);
 
 	/* Calculate the timeout period for data transactions */
-	timeout = __ilog2(mmc->tran_speed/10);
+	timeout = fls(mmc->tran_speed/10) - 1;
 	timeout -= 13;
 
 	if (timeout > 14)
@@ -236,11 +240,18 @@ esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
 
 void set_sysctl(struct mmc *mmc, uint clock)
 {
+#ifdef CONFIG_PPC
 	int sdhc_clk = gd->sdhc_clk;
+#else
+	int sdhc_clk = mxc_get_clock(MXC_IPG_PERCLK);
+#endif
 	int div, pre_div;
 	volatile struct fsl_esdhc *regs = mmc->priv;
 	uint clk;
 
+	if (clock < mmc->f_min)
+		clock = mmc->f_min;
+
 	if (sdhc_clk / 16 > clock) {
 		for (pre_div = 2; pre_div < 256; pre_div *= 2)
 			if ((sdhc_clk / pre_div) <= (clock * 16))
@@ -257,11 +268,14 @@ void set_sysctl(struct mmc *mmc, uint clock)
 
 	clk = (pre_div << 8) | (div << 4);
 
+	/* On imx the clock must be stopped before changing frequency */
+	clrbits_be32(&regs->sysctl, SYSCTL_CKEN);
+
 	clrsetbits_be32(&regs->sysctl, SYSCTL_CLOCK_MASK, clk);
 
 	udelay(10000);
 
-	setbits_be32(&regs->sysctl, SYSCTL_PEREN);
+	setbits_be32(&regs->sysctl, SYSCTL_PEREN | SYSCTL_CKEN);
 }
 
 static void esdhc_set_ios(struct mmc *mmc)
@@ -278,15 +292,26 @@ static void esdhc_set_ios(struct mmc *mmc)
 		setbits_be32(&regs->proctl, PROCTL_DTW_4);
 	else if (mmc->bus_width == 8)
 		setbits_be32(&regs->proctl, PROCTL_DTW_8);
+
 }
 
 static int esdhc_init(struct mmc *mmc)
 {
 	struct fsl_esdhc *regs = mmc->priv;
 	int timeout = 1000;
+	int ret = 0;
 
+#ifdef CONFIG_PPC
 	/* Enable cache snooping */
 	out_be32(&regs->scr, 0x00000040);
+#endif
+
+	/* Reset the entire host controller */
+	out_be32(&regs->sysctl, SYSCTL_RSTA);
+
+	/* Wait until the controller is available */
+	while ((in_be32(&regs->sysctl) & SYSCTL_RSTA) && --timeout)
+		udelay(1000);
 
 	out_be32(&regs->sysctl, SYSCTL_HCKEN | SYSCTL_IPGEN);
 
@@ -299,24 +324,44 @@ static int esdhc_init(struct mmc *mmc)
 	/* Put the PROCTL reg back to the default */
 	out_be32(&regs->proctl, PROCTL_INIT);
 
-	while (!(in_be32(&regs->prsstat) & PRSSTAT_CINS) && --timeout)
-		udelay(1000);
+	/* Set timout to the maximum value */
+	clrsetbits_be32(&regs->sysctl, SYSCTL_TIMEOUT_MASK, 14 << 16);
 
-	if (timeout <= 0)
-		return NO_CARD_ERR;
+	/* Check if there is a callback for detecting the card */
+	if (!mmc->getcd) {
+		timeout = 1000;
+		while (!(in_be32(&regs->prsstat) & PRSSTAT_CINS) && --timeout)
+			udelay(1000);
 
-	return 0;
+		if (timeout <= 0)
+			ret = NO_CARD_ERR;
+	} else {
+		if (mmc->getcd(mmc))
+			ret = NO_CARD_ERR;
+	}
+
+	return ret;
 }
 
-static int esdhc_initialize(bd_t *bis)
+int fsl_esdhc_initialize(bd_t *bis, uint32_t esdhc_addr, int (*getcd)(struct mmc *mmc))
 {
-	struct fsl_esdhc *regs = (struct fsl_esdhc *)CONFIG_SYS_FSL_ESDHC_ADDR;
+#ifdef CONFIG_PPC
+	int sdhc_clk = gd->sdhc_clk;
+#else
+	int sdhc_clk = mxc_get_clock(MXC_IPG_PERCLK);
+#endif
+	struct fsl_esdhc *regs;
 	struct mmc *mmc;
 	u32 caps;
 
 	mmc = malloc(sizeof(struct mmc));
 
 	sprintf(mmc->name, "FSL_ESDHC");
+	if (!esdhc_addr) {
+		regs = (struct fsl_esdhc *)CONFIG_SYS_FSL_ESDHC_ADDR;
+	} else {
+		regs = (struct fsl_esdhc *)esdhc_addr;
+	}
 	mmc->priv = regs;
 	mmc->send_cmd = esdhc_send_cmd;
 	mmc->set_ios = esdhc_set_ios;
@@ -337,7 +382,10 @@ static int esdhc_initialize(bd_t *bis)
 		mmc->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
 
 	mmc->f_min = 400000;
-	mmc->f_max = MIN(gd->sdhc_clk, 50000000);
+	mmc->f_max = MIN(sdhc_clk, 50000000);
+
+	if(getcd)
+		mmc->getcd = getcd;
 
 	mmc_register(mmc);
 
@@ -346,9 +394,10 @@ static int esdhc_initialize(bd_t *bis)
 
 int fsl_esdhc_mmc_init(bd_t *bis)
 {
-	return esdhc_initialize(bis);
+	return fsl_esdhc_initialize(bis, 0, NULL);
 }
 
+#ifdef CONFIG_PPC
 void fdt_fixup_esdhc(void *blob, bd_t *bd)
 {
 	const char *compat = "fsl,esdhc";
@@ -365,3 +414,4 @@ out:
 	do_fixup_by_compat(blob, compat, "status", status,
 			   strlen(status) + 1, 1);
 }
+#endif
include/asm-arm/io.h +21 -0
index fec3a7e..fb104aa 100644
@@ -33,6 +33,27 @@ static inline void sync(void)
 {
 }
 
+/* Clear and set bits in one shot. These macros can be used to clear and
+ * set multiple bits in a register using a single call. These macros can
+ * also be used to set a multiple-bit bit pattern using a mask, by
+ * specifying the mask in the 'clear' parameter and the new bit pattern
+ * in the 'set' parameter.
+ */
+
+#define clrbits(type, addr, clear) \
+	write##type(__raw_read##type(addr) & ~(clear), (addr))
+
+#define setbits(type, addr, set) \
+	write##type(__raw_read##type(addr) | (set), (addr))
+
+#define clrsetbits(type, addr, clear, set) \
+	write##type((__raw_read##type(addr) & ~(clear)) | (set), (addr))
+
+#define clrbits_be32(addr, clear) clrbits(l, addr, clear)
+#define setbits_be32(addr, set) setbits(l, addr, set)
+#define clrsetbits_be32(addr, clear, set) clrsetbits(l, addr, clear, set)
+
+
 /*
  * Given a physical address and a length, return a virtual address
  * that can be used to access the memory range with the caching
include/fsl_esdhc.h +5 -1
index 89b8304..605e065 100644
@@ -32,7 +32,9 @@
 #define SYSCTL			0x0002e02c
 #define SYSCTL_INITA		0x08000000
 #define SYSCTL_TIMEOUT_MASK	0x000f0000
-#define SYSCTL_CLOCK_MASK	0x00000fff
+#define SYSCTL_CLOCK_MASK	0x0000ffff
+#define SYSCTL_RSTA		0x01000000
+#define SYSCTL_CKEN		0x00000008
 #define SYSCTL_PEREN		0x00000004
 #define SYSCTL_HCKEN		0x00000002
 #define SYSCTL_IPGEN		0x00000001
@@ -144,6 +146,8 @@
 
 #ifdef CONFIG_FSL_ESDHC
 int fsl_esdhc_mmc_init(bd_t *bis);
+int fsl_esdhc_initialize(bd_t *bis, uint32_t esdhc_addr,
+	int (*getcd)(struct mmc *mmc));
 void fdt_fixup_esdhc(void *blob, bd_t *bd);
 #else
 static inline int fsl_esdhc_mmc_init(bd_t *bis) { return -ENOSYS; }
include/mmc.h +1 -0
index 2dc69ab..bc29953 100644
@@ -264,6 +264,7 @@ struct mmc {
 			struct mmc_cmd *cmd, struct mmc_data *data);
 	void (*set_ios)(struct mmc *mmc);
 	int (*init)(struct mmc *mmc);
+	int (*getcd)(struct mmc *mmc);
 };
 
 int mmc_register(struct mmc *mmc);
Signature · 1 line
1.6.3.3
#8 lore raw

PATCH 8/9 mmc: check correctness of the voltage mask in ocr

Most cards do not answer if some reserved bits in the ocr are set. However, some controllers can set bit 7 (reserved for low voltages), but how to manage low voltages SD card is not yet specified.

---
 drivers/mmc/mmc.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
drivers/mmc/mmc.c +9 -1
index b69ce15..d91b9b7 100644
@@ -273,7 +273,15 @@ sd_send_op_cond(struct mmc *mmc)
 
 		cmd.cmdidx = SD_CMD_APP_SEND_OP_COND;
 		cmd.resp_type = MMC_RSP_R3;
-		cmd.cmdarg = mmc->voltages;
+
+		/*
+		 * Most cards do not answer if some reserved bits
+		 * in the ocr are set. However, Some controller
+		 * can set bit 7 (reserved for low voltages), but
+		 * how to manage low voltages SD card is not yet
+		 * specified.
+		 */
+		cmd.cmdarg = mmc->voltages & 0xff8000;
 
 		if (mmc->version == SD_VERSION_2)
 			cmd.cmdarg |= OCR_HCS;
Signature · 1 line
1.6.3.3
#9 lore raw

PATCH 9/9 Add initial support for Freescale mx51evk board

The patch adds initial support for the Freescale mx51evk board. Network (FEC) and SD controller (fsl_esdhc) are supported.

Signed-off-by Fred Fan fanyefeng at gmail.com
---
 MAINTAINERS                          |    4 +
 MAKEALL                              |    1 +
 Makefile                             |    8 +
 board/freescale/mx51evk/Makefile     |   48 ++++
 board/freescale/mx51evk/config.mk    |   15 ++
 board/freescale/mx51evk/imximage.cfg |  119 ++++++++++
 board/freescale/mx51evk/mx51evk.c    |  418 ++++++++++++++++++++++++++++++++++
 board/freescale/mx51evk/mx51evk.h    |   49 ++++
 include/configs/mx51evk.h            |  185 +++++++++++++++
 9 files changed, 847 insertions(+), 0 deletions(-)
 create mode 100644 board/freescale/mx51evk/Makefile
 create mode 100644 board/freescale/mx51evk/config.mk
 create mode 100644 board/freescale/mx51evk/imximage.cfg
 create mode 100644 board/freescale/mx51evk/mx51evk.c
 create mode 100644 board/freescale/mx51evk/mx51evk.h
 create mode 100644 include/configs/mx51evk.h
MAINTAINERS +4 -0
index 9734b1d..8637550 100644
@@ -151,6 +151,10 @@ Dave Ellis <[email protected]>
 
 	SXNI855T	MPC8xx
 
+Fred Fan <[email protected]>
+
+	mx51evk		i.MX51
+
 Thomas Frieden <[email protected]>
 
 	AmigaOneG3SE	MPC7xx
MAKEALL +1 -0
index ab1bb6f..485107a 100755
@@ -617,6 +617,7 @@ LIST_ARM11="			\
 #########################################################################
 LIST_ARM_CORTEX_A8="		\
 	devkit8000		\
+	mx51evk			\
 	omap3_beagle		\
 	omap3_overo		\
 	omap3_evm		\
Makefile +8 -0
index ed6156f..01bf9a2 100644
@@ -324,6 +324,10 @@ $(obj)u-boot.img:	$(obj)u-boot.bin
 			sed -e 's/"[	 ]*$$/ for $(BOARD) board"/') \
 		-d $< $@
 
+$(obj)u-boot.imx:       $(obj)u-boot.bin
+		$(obj)tools/mkimage -n $(IMX_CONFIG) -T imximage \
+		-e $(TEXT_BASE) -d $< $@
+
 $(obj)u-boot.kwb:       $(obj)u-boot.bin
 		$(obj)tools/mkimage -n $(KWD_CONFIG) -T kwbimage \
 		-a $(TEXT_BASE) -e $(TEXT_BASE) -d $< $@
@@ -3263,6 +3267,9 @@ mx31pdk_nand_config	: unconfig
 	fi
 	@$(MKCONFIG) -a mx31pdk arm arm1136 mx31pdk freescale mx31
 
+mx51evk_config	: unconfig
+	@$(MKCONFIG) $(@:_config=) arm arm_cortexa8 mx51evk freescale mx51
+
 omap2420h4_config	: unconfig
 	@$(MKCONFIG) $(@:_config=) arm arm1136 omap2420h4 ti omap24xx
 
@@ -3729,6 +3736,7 @@ clobber:	clean
 		$(obj)cscope.* $(obj)*.*~
 	@rm -f $(obj)u-boot $(obj)u-boot.map $(obj)u-boot.hex $(ALL)
 	@rm -f $(obj)u-boot.kwb
+	@rm -f $(obj)u-boot.imx
 	@rm -f $(obj)tools/{env/crc32.c,inca-swap-bytes}
 	@rm -f $(obj)cpu/mpc824x/bedbug_603e.c
 	@rm -f $(obj)include/asm/proc $(obj)include/asm/arch $(obj)include/asm
board/freescale/mx51evk/Makefile new file +48 -0

48 lines not on this page · raw message

board/freescale/mx51evk/config.mk new file +15 -0
new file mode 100644
index 0000000..fecfd5e
@@ -0,0 +1,15 @@
+#
+# Copyright 2009 Freescale Semiconductor, Inc. All Rights Reserved.
+#
+
+#
+# The code contained herein is licensed under the GNU General Public
+# License. You may obtain a copy of the GNU General Public License
+# Version 2 or later at the following locations:
+#
+# http://www.opensource.org/licenses/gpl-license.html
+# http://www.gnu.org/copyleft/gpl.html
+#
+LDSCRIPT = cpu/$(CPU)/$(SOC)/u-boot.lds
+TEXT_BASE = 0x97800000
+IMX_CONFIG = $(SRCTREE)/board/$(BOARDDIR)/imximage.cfg
board/freescale/mx51evk/imximage.cfg new file +119 -0

119 lines not on this page · raw message

board/freescale/mx51evk/mx51evk.c new file +418 -0

418 lines not on this page · raw message

board/freescale/mx51evk/mx51evk.h new file +49 -0

49 lines not on this page · raw message

include/configs/mx51evk.h new file +185 -0

185 lines not on this page · raw message

Signature · 1 line
1.6.3.3
#10 lore raw

PATCH 9/9 Add initial support for Freescale mx51evk board

Hi Stefano,

Quoted 11 lines · Stefano Babic

From: Stefano Babic <[email protected]>
Subject: [U-Boot] [PATCH 9/9] Add initial support for Freescale mx51evk board
To: u-boot at lists.denx.de
Date: Monday, January 11, 2010, 10:26 AM
The patch adds initial support for
the Freescale mx51evk board.
Network (FEC) and SD controller (fsl_esdhc) are supported.

Signed-off-by Fred Fan fanyefeng at gmail.com

+??? puts("Board: MX51 BABBAGE ");

We should use MX51EVK instead.

....

Quoted 14 lines
include/configs/mx51evk.h new file +7 -0
+#define CONFIG_CMD_PING
+#define CONFIG_CMD_DHCP
+#define CONFIG_CMD_MII
+#define CONFIG_CMD_NET
+
+/* allow to overwrite serial and ethaddr */
 
+ * The MX51 3stack board seems to have a hardware

"peculiarity" confirmed under
+ * U-Boot, RedBoot and Linux: the ethernet Rx signal is reaching the CS8900A
+ * controller inverted. The controller is capable of detecting and correcting
+ * this, but it needs 4 network packets for that. Which

Quoted 8 lines

means, at startup, you
+ * will not receive answers to the first 4 packest, unless there have been some
+ * broadcasts on the network, or your board is on a hub. Reducing the ARP
+ * timeout from default 5 seconds to 200ms we speed up the initial TFTP
+ * transfer, should the user wish one, significantly.

These comments do not apply to MX51EVK as there is no CS8900 controller on this board. Please remove.

...

Quoted 4 lines

+#define CONFIG_SYS_LONGHELP???
??? /* undef to save memory */
+#define CONFIG_SYS_PROMPT???
??? "BBG U-Boot > "

'BBG' should be removed as we are no longer using the term Babbage.

I will also send you new optimized values for the DDR settings when I come back to the office.

Regards,

Fabio Estevam

#11 lore raw

PATCH 9/9 Add initial support for Freescale mx51evk board

In reply to Stefano Babic

Hi Stefano,

More comments below.

Quoted 11 lines · Stefano Babic

From: Stefano Babic <[email protected]>
Subject: [U-Boot] [PATCH 9/9] Add initial support for Freescale mx51evk board
To: u-boot at lists.denx.de
Date: Monday, January 11, 2010, 10:26 AM
The patch adds initial support for
the Freescale mx51evk board.
Network (FEC) and SD controller (fsl_esdhc) are supported.

Signed-off-by Fred Fan fanyefeng at gmail.com

---

....

Quoted 18 lines
(quoted diff) +8 -0
+static inline void setup_soc_rev(void)
+{
+??? int reg;
+
+??? reg = __raw_readl(ROM_SI_REV);
+??? switch (reg) {
+??? case 0x02:
+??? ??? system_rev = 0x51000

| CHIP_REV_1_1;
+??? ??? break;
+??? case 0x10:
+??? ??? if
((__raw_readl(GPIO1_BASE_ADDR + 0x0) & (0x1 <<
22)) == 0)
+??? ??? ???
system_rev = 0x51000 | CHIP_REV_2_5;
+??? ??? else
+??? ??? ???

Quoted 8 lines

system_rev = 0x51000 | CHIP_REV_2_0;
+??? ??? break;
+??? default:
+??? ??? system_rev = 0x51000
| CHIP_REV_1_0;
+??? ??? break;
+??? }
+}

Looks like CHIP_REV_3_0 case is missing.

...

Quoted 13 lines
(quoted diff) +2 -0
+/* CPLD offsets */
+#define IO_BOARD_OFFSET???

??? (0x20000)
+#define PBC_ID_AAAA??? ???
(0x20040)
+#define PBC_ID_5555??? ???
(0x20048)
+#define PBC_INT_REST??? ???
(0x20020)
+#define PBC_INT_MASK??? ???
(0x20038)
+#define PBC_SW_RESET??? ???
(0x20060)

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+#endif??? ???

There is no CPLD on MX51EVK board. Please remove these defines.

Quoted 2 lines

??? ??? /*
__BOARD_FREESCALE_BOARD_MX51_BABBAGE_H__ */

Please remove Babbage references.

Regards,

Fabio Estevam

#12 lore raw

PATCH 9/9 Add initial support for Freescale mx51evk board

In reply to Stefano Babic

Dear Stefano Babic,

Makefile $(obj)u-boot.img: $(obj)u-boot.bin · line 329

Quoted 12 lines · In message <[email protected]> you wrote:

The patch adds initial support for the Freescale mx51evk board. Network (FEC) and SD controller (fsl_esdhc) are supported.

Makefile +3 -0
@@ -324,6 +324,10 @@ $(obj)u-boot.img:	$(obj)u-boot.bin
 			sed -e 's/"[	 ]*$$/ for $(BOARD) board"/') \
 		-d $< $@
 
+$(obj)u-boot.imx:       $(obj)u-boot.bin
+		$(obj)tools/mkimage -n $(IMX_CONFIG) -T imximage \
+		-e $(TEXT_BASE) -d $< $@

This actually belongs into the patch that adds the imx image format support.

Makefile $(obj)u-boot.img: $(obj)u-boot.bin · line 333

Quoted 4 lines
Makefile +4 -0
+int dram_init(void)
+{
+	gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
+	gd->bd->bi_dram[0].size = get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);

Line too long. Please check globally.

Makefile $(obj)u-boot.img: $(obj)u-boot.bin

Quoted 7 lines
Makefile +7 -0
+	return 0;
+}
+
+static void setup_uart(void)
+{
+	unsigned int pad = PAD_CTL_HYS_ENABLE | PAD_CTL_PKE_ENABLE |
+			 PAD_CTL_PUE_PULL | PAD_CTL_DRV_HIGH;

Indentation by TAB, please. Please check globally.

Makefile

Quoted 12 lines
Makefile +12 -0
+static void setup_expio(void)
+{
+	u32 reg;
+
+	/* CS5 setup */
+	mxc_request_iomux(MX51_PIN_EIM_CS5, IOMUX_CONFIG_ALT0);
+	writel(0x00410089, WEIM_BASE_ADDR + 0x78 + CSGCR1);
+	writel(0x00000002, WEIM_BASE_ADDR + 0x78 + CSGCR2);
+	/* RWSC=50, RADVA=2, RADVN=6, OEA=0, OEN=0, RCSA=0, RCSN=0 */
+	writel(0x32260000, WEIM_BASE_ADDR + 0x78 + CSRCR1);
+	/* APR = 0 */
+	writel(0x00000000, WEIM_BASE_ADDR + 0x78 + CSRCR2);

What is this magic offset 0x78 here? Please get rid of using base address + offset notation, use C struncts instead (see previous review comments about this). Please fix globally.

Makefile

Quoted 10 lines
Makefile +10 -0
+	/* Reset the XUART and Ethernet controllers */
+	reg = readw(&(mx51_io_board->sw_reset));
+	reg |= 0x9;
+	writew(reg, &(mx51_io_board->sw_reset));
+	reg &= ~0x9;
+	writew(reg, &(mx51_io_board->sw_reset));
+}
+
+static void setup_fec(void)
+{

FEC should only be set up (and eventually only be reset, too), if there is any network support at all on this board.

...

Makefile

Quoted 9 lines
Makefile +9 -0
+int board_mmc_init(bd_t *bis)
+{
+	u32 interface_esdhc = 0;
+	s32 status = 0;
+	u32 esdhc_base_pointer;
+
+	for (interface_esdhc = 0; interface_esdhc < CONFIG_SYS_FSL_ESDHC_NUM; interface_esdhc++) {
+		switch (interface_esdhc) {
+			case 0:

Incorrect indent. And line too loing above, of course.

...

Quoted 2 lines
Makefile +2 -0
+				break;
+			case 1:

...

Makefile

Quoted 2 lines
Makefile +2 -0
+				break;
+			}

Incorrect indent. Default case?

board/freescale/mx51evk/mx51evk.h line 3

Quoted 9 lines
board/freescale/mx51evk/mx51evk.h new file +3 -0
new file mode 100644
index 0000000..fec886d
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2009 Freescale Semiconductor, Inc. All Rights Reserved.
+ */

Please get rid off the "All Rights Reserved."

board/freescale/mx51evk/mx51evk.h line 7

Quoted 4 lines
board/freescale/mx51evk/mx51evk.h new file +4 -0
+/*
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:

As mentioned before, this clause is not acceptable.

Quoted 5 lines
include/configs/mx51evk.h new file +0 -0
new file mode 100644
index 0000000..c8b2970

...

Quoted 2 lines

+ /* High Level Configuration Options */
+#define CONFIG_SYS_APCS_GNU

What's this? It seems to be not used anywhere, nor documented?

Quoted 1 line

+#define CONFIG_L2_OFF

Is this a "High Level Configuration Option"? Move down!

include/configs/mx51evk.h line 157

Quoted 4 lines
include/configs/mx51evk.h new file +4 -0
+#define CONFIG_SYS_MEMTEST_START       CSD0_BASE_ADDR
+#define CONFIG_SYS_MEMTEST_END         0x10000
+
+#define CONFIG_SYS_LOAD_ADDR		CONFIG_LOADADDR

Here and everywhere else: please use TABs for vertical alignment.

include/configs/mx51evk.h line 183

Quoted 3 lines
include/configs/mx51evk.h new file +3 -0
+#define CONFIG_ENV_SECT_SIZE    (128 * 1024)
+#define CONFIG_ENV_SIZE         CONFIG_ENV_SECT_SIZE
+#define CONFIG_ENV_IS_NOWHERE

Seems strange to me to define an environment sector size and an environment size and then to say there is no environment at all?

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Nothing ever becomes real until it is experienced.       - John Keats
#13 lore raw

PATCH 9/9 Add initial support for Freescale mx51evk board

Quoted 2 lines · Wolfgang Denk

Dear Stefano Babic,

Hi Wolfgang,

Quoted 6 lines

Makefile $(obj)u-boot.img: $(obj)u-boot.bin · line 329

Quoted 3 lines

+$(obj)u-boot.imx: $(obj)u-boot.bin

Makefile +2 -0
+		$(obj)tools/mkimage -n $(IMX_CONFIG) -T imximage \
+		-e $(TEXT_BASE) -d $< $@

This actually belongs into the patch that adds the imx image format support.

Correct, thanks for the tip. I move it to the right patch.

Quoted 5 lines

board/freescale/mx51evk/mx51evk.c line 149

Quoted 2 lines
board/freescale/mx51evk/mx51evk.c new file +2 -0
+static void setup_fec(void)
+{

FEC should only be set up (and eventually only be reset, too), if there is any network support at all on this board.

The name is misleading, too. The FEC is not initialized here and the function is responsible only to set the IOMUX pin multiplexer for the network controller. Nothing more. The name shoud be something such as "set_iomux_network".

I can of course surround the function with #ifdef CONFIG_FEC_MXC, but really do I need ? We cannot change how the processor's pins are connected on the board, even if we do not want to add network support for this board. I think it should be ok if the pin multiplexer is always configured, independently if there is a network device or not.

Quoted 3 lines
Quoted 1 line

+#define CONFIG_SYS_APCS_GNU

What's this? It seems to be not used anywhere, nor documented?

I get already rid of the meaningless usage. I forget to drop its define. Thanks !

Quoted 7 lines

include/configs/mx51evk.h line 183

Quoted 4 lines
include/configs/mx51evk.h new file +3 -0
+#define CONFIG_ENV_SECT_SIZE    (128 * 1024)
+#define CONFIG_ENV_SIZE         CONFIG_ENV_SECT_SIZE
+#define CONFIG_ENV_IS_NOWHERE

Seems strange to me to define an environment sector size and an environment size and then to say there is no environment at all?

Right. The mx51evk board has neither NOR nor NAND flash. However, a SPI flash is available and this defines are required when the spi will be supported. At the moment, I can drop them and reinsert later.

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
#14 lore raw

PATCH 9/9 Add initial support for Freescale mx51evk board

Dear Stefano Babic,

Quoted 11 lines · In message <[email protected]> you wrote:
Quoted 6 lines

board/freescale/mx51evk/mx51evk.c line 149

Quoted 3 lines
board/freescale/mx51evk/mx51evk.c new file +2 -0
+static void setup_fec(void)
+{

FEC should only be set up (and eventually only be reset, too), if there is any network support at all on this board.

The name is misleading, too. The FEC is not initialized here and the function is responsible only to set the IOMUX pin multiplexer for the network controller. Nothing more. The name shoud be something such as "set_iomux_network".

Ah, I see.

Quoted 5 lines

I can of course surround the function with #ifdef CONFIG_FEC_MXC, but really do I need ? We cannot change how the processor's pins are connected on the board, even if we do not want to add network support for this board. I think it should be ok if the pin multiplexer is always configured, independently if there is a network device or not.

This is indeed ok.My concern was not to enable peripherals and clocks unless needed. The thing is, such an initial port will be used as reference by all others that will add new boards of the same architecture, and it's easier not to enable interfaces initially (people will notice that - say - Ethenret is not working) then to try to reduce the power consumpion of the device later, not knowing which unused clocks or peripherals might be turned on and sucking off the battery.

Quoted 10 lines
Quoted 6 lines

include/configs/mx51evk.h line 183

Quoted 3 lines
include/configs/mx51evk.h new file +3 -0
+#define CONFIG_ENV_SECT_SIZE    (128 * 1024)
+#define CONFIG_ENV_SIZE         CONFIG_ENV_SECT_SIZE
+#define CONFIG_ENV_IS_NOWHERE

Seems strange to me to define an environment sector size and an environment size and then to say there is no environment at all?

Right. The mx51evk board has neither NOR nor NAND flash. However, a SPI flash is available and this defines are required when the spi will be supported. At the moment, I can drop them and reinsert later.

So at the moment we cannot save the envrionment? Arghhh...

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
It is impractical for  the  standard  to  attempt  to  constrain  the
behavior  of code that does not obey the constraints of the standard.
                                                          - Doug Gwyn
#15 lore raw

PATCH 9/9 Add initial support for Freescale mx51evk board

Quoted 2 lines · Wolfgang Denk

Dear Stefano Babic,

Hi Wolfgang,

Quoted 1 line

So at the moment we cannot save the envrionment? Arghhh...

Yes, I know. I managed to change the mxc_spi driver, but I have really changed a lot of code. I have not only added support for the i.MX51, but I needed to remove the limitations due to the buffer alignment and the fact that transfer of more than one word is broken.
I see a recent thread on this issue. I will send soon a patch to the ML, but as I said I changed a lot of code (I rewrite the transfer functions) and I assume it takes some time before anything is cleared. So it would better to add the patch for the mx51evk as it is (I mean, without the possibility to save the environment) and later add support for it when SPI is working.

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
#16 lore raw

PATCH 7/9 fsl_esdhc: add support for mx51 processor

In reply to Stefano Babic

Dear Stefano Babic,

Quoted 18 lines · In message <[email protected]> you wrote:

The esdhc controller in the mx51 processor is quite the same as the one in some powerpc processors (MPC83xx, MPC85xx). This patches adapts the driver to support the arm mx51.

---
 drivers/mmc/fsl_esdhc.c |   72 +++++++++++++++++++++++++++++++++++++++-------
 include/asm-arm/io.h    |   21 +++++++++++++
 include/fsl_esdhc.h     |    6 +++-
 include/mmc.h           |    1 +
 4 files changed, 88 insertions(+), 12 deletions(-)
drivers/mmc/fsl_esdhc.c +0 -0
index c6e9e6e..5dcf6a8 100644

drivers/mmc/fsl_esdhc.c line 43

Quoted 7 lines
drivers/mmc/fsl_esdhc.c +4 -0
@@ -37,6 +37,10 @@
 #include <fdt_support.h>
 #include <asm/io.h>
 
+#ifndef CONFIG_PPC
+#define out_be32(a,v)	writel(v,a)
+#define in_be32(a)	__raw_readl(a)
+#endif

Are you sure these are correct definitions for all architectures? If so, they should go into a global header file, not here.

drivers/mmc/fsl_esdhc.c static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data) · line 136

Quoted 6 lines
drivers/mmc/fsl_esdhc.c +1 -1
@@ -129,7 +133,7 @@ static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data)
 	out_be32(&regs->blkattr, data->blocks << 16 | data->blocksize);
 
 	/* Calculate the timeout period for data transactions */
-	timeout = __ilog2(mmc->tran_speed/10);
+	timeout = fls(mmc->tran_speed/10) - 1;

What's the reason for this change?

drivers/mmc/fsl_esdhc.c esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data) · line 247

Quoted 9 lines
drivers/mmc/fsl_esdhc.c +4 -0
@@ -236,11 +240,18 @@ esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
 
 void set_sysctl(struct mmc *mmc, uint clock)
 {
+#ifdef CONFIG_PPC
 	int sdhc_clk = gd->sdhc_clk;
+#else
+	int sdhc_clk = mxc_get_clock(MXC_IPG_PERCLK);
+#endif

Can we avoid such #ifdef's here? Why don't we use gd->sdhc_clk everywhere?

drivers/mmc/fsl_esdhc.c esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data) · line 253

Quoted 6 lines
drivers/mmc/fsl_esdhc.c +2 -0
 	int div, pre_div;
 	volatile struct fsl_esdhc *regs = mmc->priv;
 	uint clk;
 
+	if (clock < mmc->f_min)
+		clock = mmc->f_min;

Print warning message ?

drivers/mmc/fsl_esdhc.c void set_sysctl(struct mmc *mmc, uint clock) · line 272

Quoted 6 lines
drivers/mmc/fsl_esdhc.c +2 -0
@@ -257,11 +268,14 @@ void set_sysctl(struct mmc *mmc, uint clock)
 
 	clk = (pre_div << 8) | (div << 4);
 
+	/* On imx the clock must be stopped before changing frequency */
+	clrbits_be32(&regs->sysctl, SYSCTL_CKEN);

Is this compatible with the other architectures?

drivers/mmc/fsl_esdhc.c static void esdhc_set_ios(struct mmc *mmc) · line 296

Quoted 7 lines
drivers/mmc/fsl_esdhc.c +1 -0
 static void esdhc_set_ios(struct mmc *mmc)
@@ -278,15 +292,26 @@ static void esdhc_set_ios(struct mmc *mmc)
 		setbits_be32(&regs->proctl, PROCTL_DTW_4);
 	else if (mmc->bus_width == 8)
 		setbits_be32(&regs->proctl, PROCTL_DTW_8);
+
 }

Please delete this empty line.

drivers/mmc/fsl_esdhc.c static void esdhc_set_ios(struct mmc *mmc) · line 307

Quoted 10 lines
drivers/mmc/fsl_esdhc.c +3 -0
 static int esdhc_init(struct mmc *mmc)
 {
 	struct fsl_esdhc *regs = mmc->priv;
 	int timeout = 1000;
+	int ret = 0;
 
+#ifdef CONFIG_PPC
 	/* Enable cache snooping */
 	out_be32(&regs->scr, 0x00000040);
+#endif

Why only on PPC? [I'm asking again because I don;t want to see so many #ifdef's in such code.]

drivers/mmc/fsl_esdhc.c static void esdhc_set_ios(struct mmc *mmc) · line 314

Quoted 6 lines
drivers/mmc/fsl_esdhc.c +6 -0
+	/* Reset the entire host controller */
+	out_be32(&regs->sysctl, SYSCTL_RSTA);
+
+	/* Wait until the controller is available */
+	while ((in_be32(&regs->sysctl) & SYSCTL_RSTA) && --timeout)
+		udelay(1000);

Has this been tested on non-i.MX51 systems as well?

Quoted 17 lines
drivers/mmc/fsl_esdhc.c +7 -4
@@ -299,24 +324,44 @@ static int esdhc_init(struct mmc *mmc)
 	/* Put the PROCTL reg back to the default */
 	out_be32(&regs->proctl, PROCTL_INIT);
 
-	while (!(in_be32(&regs->prsstat) & PRSSTAT_CINS) && --timeout)
-		udelay(1000);
+	/* Set timout to the maximum value */
+	clrsetbits_be32(&regs->sysctl, SYSCTL_TIMEOUT_MASK, 14 << 16);
 
-	if (timeout <= 0)
-		return NO_CARD_ERR;
+	/* Check if there is a callback for detecting the card */
+	if (!mmc->getcd) {
+		timeout = 1000;
+		while (!(in_be32(&regs->prsstat) & PRSSTAT_CINS) && --timeout)
+			udelay(1000);
 

drivers/mmc/fsl_esdhc.c static int esdhc_init(struct mmc *mmc) · line 344

Quoted 10 lines
drivers/mmc/fsl_esdhc.c +8 -1
-	return 0;
+		if (timeout <= 0)
+			ret = NO_CARD_ERR;
+	} else {
+		if (mmc->getcd(mmc))
+			ret = NO_CARD_ERR;
+	}
+
+	return ret;
 }

These are a lot of changes - how mu of this has actually been tested on non-i.MX51 ?

drivers/mmc/fsl_esdhc.c static int esdhc_init(struct mmc *mmc) · line 352

Quoted 8 lines
drivers/mmc/fsl_esdhc.c +6 -1
+int fsl_esdhc_initialize(bd_t *bis, uint32_t esdhc_addr, int (*getcd)(struct mmc *mmc))
 {
-	struct fsl_esdhc *regs = (struct fsl_esdhc *)CONFIG_SYS_FSL_ESDHC_ADDR;
+#ifdef CONFIG_PPC
+	int sdhc_clk = gd->sdhc_clk;
+#else
+	int sdhc_clk = mxc_get_clock(MXC_IPG_PERCLK);
+#endif

See above.

drivers/mmc/fsl_esdhc.c static int esdhc_init(struct mmc *mmc) · line 364

Quoted 12 lines
drivers/mmc/fsl_esdhc.c +6 -0
+	struct fsl_esdhc *regs;
 	struct mmc *mmc;
 	u32 caps;
 
 	mmc = malloc(sizeof(struct mmc));
 
 	sprintf(mmc->name, "FSL_ESDHC");
+	if (!esdhc_addr) {
+		regs = (struct fsl_esdhc *)CONFIG_SYS_FSL_ESDHC_ADDR;
+	} else {
+		regs = (struct fsl_esdhc *)esdhc_addr;
+	}

Argh... Please don't. Use a common way for configuration, please.

drivers/mmc/fsl_esdhc.c out: · line 417

Quoted 9 lines
drivers/mmc/fsl_esdhc.c +2 -0
+#ifdef CONFIG_PPC
 void fdt_fixup_esdhc(void *blob, bd_t *bd)
 {
 	const char *compat = "fsl,esdhc";
@@ -365,3 +414,4 @@ out:
 	do_fixup_by_compat(blob, compat, "status", status,
 			   strlen(status) + 1, 1);
 }
+#endif

Can we drop this #ifdef ?

include/asm-arm/io.h static inline void sync(void) · line 41

Quoted 12 lines
include/asm-arm/io.h +6 -0
@@ -33,6 +33,27 @@ static inline void sync(void)
 {
 }
 
+/* Clear and set bits in one shot. These macros can be used to clear and
+ * set multiple bits in a register using a single call. These macros can
+ * also be used to set a multiple-bit bit pattern using a mask, by
+ * specifying the mask in the 'clear' parameter and the new bit pattern
+ * in the 'set' parameter.
+ */

Incorrect multiline comment style.

include/asm-arm/io.h static inline void sync(void) · line 54

Quoted 12 lines
include/asm-arm/io.h +12 -0
+#define clrbits(type, addr, clear) \
+	write##type(__raw_read##type(addr) & ~(clear), (addr))
+
+#define setbits(type, addr, set) \
+	write##type(__raw_read##type(addr) | (set), (addr))
+
+#define clrsetbits(type, addr, clear, set) \
+	write##type((__raw_read##type(addr) & ~(clear)) | (set), (addr))
+
+#define clrbits_be32(addr, clear) clrbits(l, addr, clear)
+#define setbits_be32(addr, set) setbits(l, addr, set)
+#define clrsetbits_be32(addr, clear, set) clrsetbits(l, addr, clear, set)

Are these macros really generally applicaple to all ARM systems, including both big and little endian configurations?

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"There are three principal ways to lose money: wine, women,  and  en-
gineers.  While  the first two are more pleasant, the third is by far
the more certain."                      -- Baron Rothschild, ca. 1800
#17 lore raw

PATCH 7/9 fsl_esdhc: add support for mx51 processor

Quoted 2 lines · Wolfgang Denk

Dear Stefano Babic,

Hi Wolfgang,

Quoted 7 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+#ifndef CONFIG_PPC
+#define out_be32(a,v)	writel(v,a)
+#define in_be32(a)	__raw_readl(a)
+#endif

Are you sure these are correct definitions for all architectures? If so, they should go into a global header file, not here.

The main reason for that is to have the same common way to access esdhc registers on the powerpc and on the arm processors. The driver is already implemented for powerpc and use the out_be32() function to access the internal registers (all registers are 32 bit wide). As counterpart on i.MX51, we have the writel() function.

I am not sure which is the best way to do it and I ask you for help. Maybe changing in all code with a "neutral" function (but this is an additional I/O accessor, there are already a lot of them...) and setting it to point to out_be32() in asm-ppc/io.h and to writel() in asm-arm/io.h. I do not know, but it sounds to me pretty bad.

Do you have a hint to manage that ?

Quoted 9 lines

Review static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data) · line 136

Quoted 7 lines
(quoted diff) +1 -1
@@ -129,7 +133,7 @@ static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data)
 	out_be32(&regs->blkattr, data->blocks << 16 | data->blocksize);
 
 	/* Calculate the timeout period for data transactions */
-	timeout = __ilog2(mmc->tran_speed/10);
+	timeout = fls(mmc->tran_speed/10) - 1;

What's the reason for this change?

The only reason is that there is no __ilog2 function for the arm architecture and I preferred to change it in a way that is defined for all architectures, not only powerpc. ilog2 is defined as (fls() - 1) in linux if no architecture specific function is provided. So, even if it is not optimized, the change is suitable for powerpc, too.

Quoted 13 lines

Review esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data) · line 247

Quoted 10 lines
(quoted diff) +4 -0
@@ -236,11 +240,18 @@ esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
 
 void set_sysctl(struct mmc *mmc, uint clock)
 {
+#ifdef CONFIG_PPC
 	int sdhc_clk = gd->sdhc_clk;
+#else
+	int sdhc_clk = mxc_get_clock(MXC_IPG_PERCLK);
+#endif

Can we avoid such #ifdef's here? Why don't we use gd->sdhc_clk everywhere?

Yes, thanks, good tip. I will add the field sdhc_clk to the global data for arm and I will get rid of these unneeded #ifdef.

Quoted 9 lines

Review void set_sysctl(struct mmc *mmc, uint clock) · line 272

Quoted 7 lines
(quoted diff) +2 -0
@@ -257,11 +268,14 @@ void set_sysctl(struct mmc *mmc, uint clock)
 
 	clk = (pre_div << 8) | (div << 4);
 
+	/* On imx the clock must be stopped before changing frequency */
+	clrbits_be32(&regs->sysctl, SYSCTL_CKEN);

Is this compatible with the other architectures?

Zeroing the bit should be ok as described in PowerQuick manual. The controller in the i.MX51 is (quite) the same as in the powerpc (I checked in the MPC8560 manual), with the exception of some registers. It seems that the controller in the i.MX51 is an evolution and some features (as the possibility to enable/disable the clock when no access to the card is required) are added later. Really to be sure I have to protect the setting of this bit (with #ifndef PPC....)

Quoted 7 lines

Review void set_sysctl(struct mmc *mmc, uint clock) · line 276

Quoted 4 lines
(quoted diff) +2 -0
+#ifdef CONFIG_PPC
 	/* Enable cache snooping */
 	out_be32(&regs->scr, 0x00000040);
+#endif

Why only on PPC? [I'm asking again because I don;t want to see so many #ifdef's in such code.]

As I said, the controllers are quite the same but they are not identical. There is not this register on the i.MX51 implementation. Really this has nothing to do with PPC and ARM.

I would prefer to have a general method to ask the controller for its capabilities and setting the bit fields according to the query. However, I have not found a way to to this and I use '#ifdef PPC' to distinguish between the two implementations of the hardware controller.

Quoted 9 lines

Review void set_sysctl(struct mmc *mmc, uint clock)

Quoted 7 lines
(quoted diff) +6 -0
+	/* Reset the entire host controller */
+	out_be32(&regs->sysctl, SYSCTL_RSTA);
+
+	/* Wait until the controller is available */
+	while ((in_be32(&regs->sysctl) & SYSCTL_RSTA) && --timeout)
+		udelay(1000);

Has this been tested on non-i.MX51 systems as well?

No, I could not test on powerpc, but the method is described in powerpc manual, too. In both manuals, the setting of this bit performs a reset of the controller. There is nothing special related to the ARM implementation.

Quoted 18 lines
Quoted 18 lines
(quoted diff) +7 -4
@@ -299,24 +324,44 @@ static int esdhc_init(struct mmc *mmc)
 	/* Put the PROCTL reg back to the default */
 	out_be32(&regs->proctl, PROCTL_INIT);
 
-	while (!(in_be32(&regs->prsstat) & PRSSTAT_CINS) && --timeout)
-		udelay(1000);
+	/* Set timout to the maximum value */
+	clrsetbits_be32(&regs->sysctl, SYSCTL_TIMEOUT_MASK, 14 << 16);
 
-	if (timeout <= 0)
-		return NO_CARD_ERR;
+	/* Check if there is a callback for detecting the card */
+	if (!mmc->getcd) {
+		timeout = 1000;
+		while (!(in_be32(&regs->prsstat) & PRSSTAT_CINS) && --timeout)
+			udelay(1000);
 
Quoted 13 lines

Review static int esdhc_init(struct mmc *mmc) · line 344

Quoted 10 lines
(quoted diff) +8 -1
-	return 0;
+		if (timeout <= 0)
+			ret = NO_CARD_ERR;
+	} else {
+		if (mmc->getcd(mmc))
+			ret = NO_CARD_ERR;
+	}
+
+	return ret;
 }

These are a lot of changes - how mu of this has actually been tested on non-i.MX51 ?

Well, as I said I could not test on PowerQuick, but changes are not related to the architecture.

Let's me explain. The driver up now uses only the internal controller to detect if a SD card is present in the slot. However, this is not a general way. In a lot of cases the pins responsible for this function and connected to the ESDHC controller are required for another peripheral and cannot be used.
In these cases, a GPIO can be used for Card Detection. The change adds only a callback in the case a GPIO is required. If the internal controller can be used (!mmc->getcd), the bits defined in PRSSTAT_CINS are still used as before.
Agree this code was not tested outside the mx51evk, but changes are smaller as we can think.

Quoted 6 lines
Quoted 6 lines
(quoted diff) +1 -0
+	struct fsl_esdhc *regs;
 	struct mmc *mmc;
 	u32 caps;
 
 	mmc = malloc(sizeof(struct mmc));
 
Quoted 8 lines

Review static int esdhc_init(struct mmc *mmc) · line 356

Quoted 6 lines
(quoted diff) +5 -0
 	sprintf(mmc->name, "FSL_ESDHC");
+	if (!esdhc_addr) {
+		regs = (struct fsl_esdhc *)CONFIG_SYS_FSL_ESDHC_ADDR;
+	} else {
+		regs = (struct fsl_esdhc *)esdhc_addr;
+	}

Argh... Please don't. Use a common way for configuration, please.

Well, the main reason for that is to support more than one controller. The MX51 has two ESDHC controllers and both of them are well supported in hardware on the mx51evk. The powerpc implementation supports clearly only one instance. The reason here is not to break the actual implementation on the powerpc boards, allowing in the same time more than one instance on the mx51evk board.

Personally I would prefer to change the powerpc code (but probably should be done in another patch ?), calling fsl_esdhc_mmc_init() in cpu/mpc85xx/cpu.c, cpu/mpc83xx/cpu.c (and in the board related functions, if any) and passing there the HW address of the controller. Something like that (for example, in cpu/mpc85xx/cpu.c:)

cpu/mpc85xx/cpu.c +1 -1
@@ -323,7 +323,7 @@ void upmconfig (uint upm, uint * table, uint size)
 int cpu_mmc_init(bd_t *bis)
 {
 #ifdef CONFIG_FSL_ESDHC
-       return fsl_esdhc_mmc_init(bis);
+       return fsl_esdhc_initialize(bis, CONFIG_SYS_MPC85xx_ESDHC_ADDR,

NULL);

 #else
        return 0;

#endif

Quoted 12 lines

Review out: · line 417

Quoted 10 lines
(quoted diff) +2 -0
+#ifdef CONFIG_PPC
 void fdt_fixup_esdhc(void *blob, bd_t *bd)
 {
 	const char *compat = "fsl,esdhc";
@@ -365,3 +414,4 @@ out:
 	do_fixup_by_compat(blob, compat, "status", status,
 			   strlen(status) + 1, 1);
 }
+#endif

Can we drop this #ifdef ?

Really replacing it with another #ifdef...

I think the code shold be protect with CONFIG_OF_LIBFDT instead of CONFIG_PPC.

Quoted 7 lines
Quoted 7 lines
(quoted diff) +7 -0
+#define clrbits(type, addr, clear) \
+	write##type(__raw_read##type(addr) & ~(clear), (addr))
+
+#define setbits(type, addr, set) \
+	write##type(__raw_read##type(addr) | (set), (addr))
+
+#define clrsetbits(type, addr, clear, set) \
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+	write##type((__raw_read##type(addr) & ~(clear)) | (set), (addr))
+
+#define clrbits_be32(addr, clear) clrbits(l, addr, clear)
+#define setbits_be32(addr, set) setbits(l, addr, set)
+#define clrsetbits_be32(addr, clear, set) clrsetbits(l, addr, clear, set)

Are these macros really generally applicaple to all ARM systems, including both big and little endian configurations?

See above, first issue, it is related. The reason here is to have a general way to add a "native" access method to internal registers for both architectures.

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
#18 lore raw

PATCH 7/9 fsl_esdhc: add support for mx51 processor

Dear Stefano Babic,

Quoted 9 lines · In message <[email protected]> you wrote:
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +4 -0
+#ifndef CONFIG_PPC
+#define out_be32(a,v)	writel(v,a)
+#define in_be32(a)	__raw_readl(a)
+#endif

Are you sure these are correct definitions for all architectures? If so, they should go into a global header file, not here.

Quoted 5 lines

The main reason for that is to have the same common way to access esdhc registers on the powerpc and on the arm processors. The driver is already implemented for powerpc and use the out_be32() function to access the internal registers (all registers are 32 bit wide). As counterpart on i.MX51, we have the writel() function.

But my understanding is that writel() is a little endian I/O operation?

Quoted 7 lines

I am not sure which is the best way to do it and I ask you for help. Maybe changing in all code with a "neutral" function (but this is an additional I/O accessor, there are already a lot of them...) and setting it to point to out_be32() in asm-ppc/io.h and to writel() in asm-arm/io.h. I do not know, but it sounds to me pretty bad.

Do you have a hint to manage that ?

In the long term we indeed want to convert the code (all code, yes) to generic I/O accessors, i. e. ioreadX(), iowriteX().

But that's a bigger task.

My concern here is that defining out_be32() [=explicitely big endian] as writel() [=explicitly little endian] might be plain wrong and thus confusing.

Quoted 11 lines
Quoted 7 lines

Review

Quoted 4 lines
(quoted diff) +2 -0
+#ifdef CONFIG_PPC
 	/* Enable cache snooping */
 	out_be32(&regs->scr, 0x00000040);
+#endif

Why only on PPC? [I'm asking again because I don;t want to see so many #ifdef's in such code.]

As I said, the controllers are quite the same but they are not identical. There is not this register on the i.MX51 implementation. Really this has nothing to do with PPC and ARM.

Then we should not make this depend on CONFIG_PPC.

Quoted 4 lines

I would prefer to have a general method to ask the controller for its capabilities and setting the bit fields according to the query. However, I have not found a way to to this and I use '#ifdef PPC' to distinguish between the two implementations of the hardware controller.

This is not a good idea. We should probably try to find out how the controller versions are named within Freescale (probably they do have internal version IDs attached - we see the same for some NAND controllers) and use these ID's to enable / disable features.

Using CONFIG_PPC here looks wrong to me.

Quoted 10 lines
Quoted 5 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+	/* Wait until the controller is available */
+	while ((in_be32(&regs->sysctl) & SYSCTL_RSTA) && --timeout)
+		udelay(1000);

Has this been tested on non-i.MX51 systems as well?

No, I could not test on powerpc, but the method is described in powerpc manual, too. In both manuals, the setting of this bit performs a reset of the controller. There is nothing special related to the ARM implementation.

I see. Please add the respective PPC custodians on the Cc: list for this patch, then.

Quoted 6 lines
Quoted 2 lines

These are a lot of changes - how mu of this has actually been tested on non-i.MX51 ?

Well, as I said I could not test on PowerQuick, but changes are not related to the architecture.

Quoted 11 lines

Let's me explain. The driver up now uses only the internal controller to detect if a SD card is present in the slot. However, this is not a general way. In a lot of cases the pins responsible for this function and connected to the ESDHC controller are required for another peripheral and cannot be used.
In these cases, a GPIO can be used for Card Detection. The change adds only a callback in the case a GPIO is required. If the internal controller can be used (!mmc->getcd), the bits defined in PRSSTAT_CINS are still used as before.
Agree this code was not tested outside the mx51evk, but changes are smaller as we can think.

OK - but please let's at least trigger the respective code maintainers so they get aware of the changes and test it on their platforms.

Quoted 16 lines
Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +5 -0
 	sprintf(mmc->name, "FSL_ESDHC");
+	if (!esdhc_addr) {
+		regs = (struct fsl_esdhc *)CONFIG_SYS_FSL_ESDHC_ADDR;
+	} else {
+		regs = (struct fsl_esdhc *)esdhc_addr;
+	}

Argh... Please don't. Use a common way for configuration, please.

Well, the main reason for that is to support more than one controller. The MX51 has two ESDHC controllers and both of them are well supported in hardware on the mx51evk. The powerpc implementation supports clearly only one instance. The reason here is not to break the actual implementation on the powerpc boards, allowing in the same time more than one instance on the mx51evk board.

Quoted 5 lines

Personally I would prefer to change the powerpc code (but probably should be done in another patch ?), calling fsl_esdhc_mmc_init() in cpu/mpc85xx/cpu.c, cpu/mpc83xx/cpu.c (and in the board related functions, if any) and passing there the HW address of the controller. Something like that (for example, in cpu/mpc85xx/cpu.c:)

Looks OK to me. Let's ping the respective custodians...

Quoted 12 lines
Quoted 11 lines

Review out: · line 417

Quoted 9 lines
(quoted diff) +2 -0
+#ifdef CONFIG_PPC
 void fdt_fixup_esdhc(void *blob, bd_t *bd)
 {
 	const char *compat = "fsl,esdhc";
@@ -365,3 +414,4 @@ out:
 	do_fixup_by_compat(blob, compat, "status", status,
 			   strlen(status) + 1, 1);
 }
+#endif

Can we drop this #ifdef ?

Quoted 4 lines

Really replacing it with another #ifdef...

I think the code shold be protect with CONFIG_OF_LIBFDT instead of CONFIG_PPC.

OK.

Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
(quoted diff) +7 -0
+#define clrbits(type, addr, clear) \
+	write##type(__raw_read##type(addr) & ~(clear), (addr))
+
+#define setbits(type, addr, set) \
+	write##type(__raw_read##type(addr) | (set), (addr))
+
+#define clrsetbits(type, addr, clear, set) \
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+	write##type((__raw_read##type(addr) & ~(clear)) | (set), (addr))
+
+#define clrbits_be32(addr, clear) clrbits(l, addr, clear)
+#define setbits_be32(addr, set) setbits(l, addr, set)
+#define clrsetbits_be32(addr, clear, set) clrsetbits(l, addr, clear, set)

Are these macros really generally applicaple to all ARM systems, including both big and little endian configurations?

Quoted 3 lines

See above, first issue, it is related. The reason here is to have a general way to add a "native" access method to internal registers for both architectures.

I understand your intentions, but I wonder if the implementation is correct, or if we are mixing big endian and little endian code here in a most confusing way.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Doubt isn't the opposite of faith; it is an element of faith.
- Paul Tillich, German theologian and historian
#19 lore raw

PATCH 6/9 fec_mxc: add support for MX51 processor

In reply to Stefano Babic

Dear Stefano Babic,

Quoted 13 lines · In message <[email protected]> you wrote:

The patch add support for the Freescale mx51 processor to the FEC ethernet driver.

---
 drivers/net/fec_mxc.c |   57 ++++++++++++++++++++++++++++++-------------------
 1 files changed, 35 insertions(+), 22 deletions(-)
drivers/net/fec_mxc.c +0 -0
index 19116f2..203832e 100644

drivers/net/fec_mxc.c line 33

Quoted 8 lines
drivers/net/fec_mxc.c +3 -1
@@ -27,8 +27,10 @@
 #include <miiphy.h>
 #include "fec_mxc.h"
 
-#include <asm/arch/clock.h>
 #include <asm/arch/imx-regs.h>
+#ifndef CONFIG_MX51
+#include <asm/arch/clock.h>
+#endif

Can we not implement the clock stuff for the iMX51 in such a way that we don't need #ifdef's here?

Quoted 6 lines
drivers/net/fec_mxc.c +2 -0
@@ -108,6 +110,23 @@ static int fec_miiphy_read(char *dev, uint8_t phyAddr, uint8_t regAddr,
 	return 0;
 }
 
+static void fec_mii_setspeed(struct fec_priv *fec)
+{

drivers/net/fec_mxc.c static int fec_miiphy_read(char *dev, uint8_t phyAddr, uint8_t regAddr, · line 124

Quoted 10 lines
drivers/net/fec_mxc.c +10 -0
+#ifdef CONFIG_MX51
+	writel((((mxc_get_clock(MXC_IPG_CLK) + 499999) / 5000000) << 1),
+			&fec->eth->mii_speed);
+#else
+	/*
+	 * Set MII_SPEED = (1/(mii_speed * 2)) * System Clock
+	 * and do not drop the Preamble.
+	 */
+	writel((((imx_get_ahbclk() / 1000000) + 2) / 5) << 1,
+			&fec->eth->mii_speed);

What exactly, in addition to the (technically irrelevant) names and the different way how the rounding is implemented, requires the #ifdef here?

The code looks pretty much the same to me. I think we should just use common names for common functions, and get rid of such #ifdef's.

drivers/net/fec_mxc.c static int fec_rbd_init(struct fec_priv *fec, int count, int size) · line 258

Quoted 6 lines
drivers/net/fec_mxc.c +1 -1
@@ -236,7 +255,7 @@ static int fec_rbd_init(struct fec_priv *fec, int count, int size)
 		fec->rdb_ptr = malloc(size * count + DB_DATA_ALIGNMENT);
 	p = (uint32_t)fec->rdb_ptr;
 	if (!p) {
-		puts("fec_imx27: not enough malloc memory!\n");
+		puts("fec_mxc: not enough malloc memory!\n");

Please also drop the '!' while you are changing this line.

Quoted 7 lines
drivers/net/fec_mxc.c +1 -0
 static int fec_get_hwaddr(struct eth_device *dev, unsigned char *mac)
 {
+#ifndef CONFIG_MX51
 	struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE;
 	int i;

drivers/net/fec_mxc.c static int fec_get_hwaddr(struct eth_device *dev, unsigned char *mac) · line 332

Quoted 7 lines
drivers/net/fec_mxc.c +3 -0
@@ -306,6 +326,9 @@ static int fec_get_hwaddr(struct eth_device *dev, unsigned char *mac)
 		mac[6-1-i] = readl(&iim->iim_bank_area0[IIM0_MAC + i]);
 
 	return is_valid_ether_addr(mac);
+#else
+	return -1;
+#endif
 }

General remark: please use positive logic in cases like this, as it results in simpler code which is much easier to read.

Instead of:

	#ifndef CONFIG_MX51
		...
		many
		lines
		of
		code here
		followed
		by
		a
		return ...;
	#else
		return something_else;
	#endif

please write:

	#ifdef CONFIG_MX51
		return something_else;
	#endif

	many
	lines
	of
	code here
	followed by a
	return ...;

Less nesting, shorter lines, easier to read and understand.

But why do we need this #ifdef here? If this function is of no use on i.MX51, then why provide it? And why call such a dummy function at all? Please let's get rid of these #ifdef's.

drivers/net/fec_mxc.c static int fec_init(struct eth_device *dev, bd_t* bd) · line 399

Quoted 7 lines
drivers/net/fec_mxc.c +1 -1
 static int fec_set_hwaddr(struct eth_device *dev, unsigned char *mac)
@@ -373,7 +396,7 @@ static int fec_init(struct eth_device *dev, bd_t* bd)
 				sizeof(struct fec_bd) + DB_ALIGNMENT);
 	base = (uint32_t)fec->base_ptr;
 	if (!base) {
-		puts("fec_imx27: not enough malloc memory!\n");
+		puts("fec_mxc: not enough malloc memory!\n");

See comment above; please apply globally.

Quoted 7 lines
drivers/net/fec_mxc.c +0 -1
 static int fec_probe(bd_t *bd)
 {
-	struct pll_regs *pll = (struct pll_regs *)IMX_PLL_BASE;
 	struct eth_device *edev;
 	struct fec_priv *fec = &gfec;
 	unsigned char ethaddr_str[20];
 	unsigned char ethaddr[6];

drivers/net/fec_mxc.c static int fec_recv(struct eth_device *dev) · line 683

Quoted 10 lines
drivers/net/fec_mxc.c +4 -1
-	char *tmp = getenv("ethaddr");
+	char *tmp;
 	char *end;
+#ifndef CONFIG_MX51
+	struct pll_regs *pll = (struct pll_regs *)IMX_PLL_BASE;
 
 	/* enable FEC clock */
 	writel(readl(&pll->pccr1) | PCCR1_HCLK_FEC, &pll->pccr1);
 	writel(readl(&pll->pccr0) | PCCR0_FEC_EN, &pll->pccr0);
+#endif

Can we implement this clock enable in a way that goes without #ifdef ?

Quoted 25 lines
drivers/net/fec_mxc.c +2 -9
 	/* create and fill edev struct */
 	edev = (struct eth_device *)malloc(sizeof(struct eth_device));
 	if (!edev) {
-		puts("fec_imx27: not enough malloc memory!\n");
+		puts("fec_mxc: not enough malloc memory!\n");
 		return -ENOMEM;
 	}
 	edev->priv = fec;
@@ -702,14 +721,7 @@ static int fec_probe(bd_t *bd)
 	 * Frame length=1518; MII mode;
 	 */
 	writel(0x05ee0024, &fec->eth->r_cntrl);	/* FIXME 0x05ee0004 */
-	/*
-	 * Set MII_SPEED = (1/(mii_speed * 2)) * System Clock
-	 * and do not drop the Preamble.
-	 */
-	writel((((imx_get_ahbclk() / 1000000) + 2) / 5) << 1,
-			&fec->eth->mii_speed);
-	debug("fec_init: mii_speed %#lx\n",
-			(((imx_get_ahbclk() / 1000000) + 2) / 5) << 1);
+	fec_mii_setspeed(fec);
 
 	sprintf(edev->name, "FEC_MXC");
 

drivers/net/fec_mxc.c static int fec_probe(bd_t *bd) · line 735

Quoted 7 lines
drivers/net/fec_mxc.c +1 -0
@@ -717,6 +729,7 @@ static int fec_probe(bd_t *bd)
 
 	eth_register(edev);
 
+	tmp = getenv("ethaddr");
 	if ((NULL != tmp) && (12 <= strlen(tmp))) {
 		int i;
 		/* convert MAC from string to int */

This is wrong and should be fixed. We don't convert to "int" but to "uchar[]"; While we touch this, please dump the code completely and use eth_getenv_enetaddr() instead.

Best regards,

Wolfgang Denk

Signature · 7 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Once upon a time, "PC" meant "personal computer".  Now  it  seems  to
only  mean  "Prisoner  of Bill". Alas! All my PCs run Unix, and those
include Intel, Sparc, and other processors.
          -- Tom "Bring back the non-PC meaning of `PC'" Christiansen
#20 lore raw

PATCH 6/9 fec_mxc: add support for MX51 processor

Quoted 2 lines · Wolfgang Denk

Dear Stefano Babic,

Hi Wolfgang,

Quoted 8 lines

drivers/net/fec_mxc.c line 33

Quoted 5 lines
drivers/net/fec_mxc.c +3 -1
-#include <asm/arch/clock.h>
 #include <asm/arch/imx-regs.h>
+#ifndef CONFIG_MX51
+#include <asm/arch/clock.h>imx_get_ahbclk
+#endif

Can we not implement the clock stuff for the iMX51 in such a way that we don't need #ifdef's here?

Good hint, I do it !

Quoted 5 lines
Quoted 5 lines
drivers/net/fec_mxc.c +0 -0
@@ -108,6 +110,23 @@ static int fec_miiphy_read(char *dev, uint8_t phyAddr, uint8_t regAddr,
 	return 0;
 }
 
Quoted 16 lines

drivers/net/fec_mxc.c static int fec_miiphy_read(char *dev, uint8_t phyAddr, uint8_t regAddr, · line 124

Quoted 12 lines
drivers/net/fec_mxc.c +12 -0
+static void fec_mii_setspeed(struct fec_priv *fec)
+{
+#ifdef CONFIG_MX51
+	writel((((mxc_get_clock(MXC_IPG_CLK) + 499999) / 5000000) << 1),
+			&fec->eth->mii_speed);
+#else
+	/*
+	 * Set MII_SPEED = (1/(mii_speed * 2)) * System Clock
+	 * and do not drop the Preamble.
+	 */
+	writel((((imx_get_ahbclk() / 1000000) + 2) / 5) << 1,
+			&fec->eth->mii_speed);

What exactly, in addition to the (technically irrelevant) names and the different way how the rounding is implemented, requires the #ifdef here?

You are right, there is no technical reason. The only thing here is to get the correct clock source. I will get as in serial_mxc and setting a imx_get_fecclk() for both processors (i.MX27 and i.MX51), removing the ifdef.

Quoted 9 lines
Quoted 9 lines
drivers/net/fec_mxc.c +1 -0
 static int fec_get_hwaddr(struct eth_device *dev, unsigned char *mac)
 {
+#ifndef CONFIG_MX51
 	struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE;
 	int i;
@@ -306,6 +326,9 @@ static int fec_get_hwaddr(struct eth_device *dev, unsigned char *mac)
 		mac[6-1-i] = readl(&iim->iim_bank_area0[IIM0_MAC + i]);
 
Quoted 8 lines

drivers/net/fec_mxc.c static int fec_get_hwaddr(struct eth_device *dev, unsigned char *mac) · line 332

Quoted 5 lines
drivers/net/fec_mxc.c +3 -0
 	return is_valid_ether_addr(mac);
+#else
+	return -1;
+#endif
 }

General remark: please use positive logic in cases like this, as it results in simpler code which is much easier to read.

Understood, thanks.

Quoted 9 lines

drivers/net/fec_mxc.c static int fec_recv(struct eth_device *dev) · line 683

Quoted 7 lines
drivers/net/fec_mxc.c +3 -0
+#ifndef CONFIG_MX51
+	struct pll_regs *pll = (struct pll_regs *)IMX_PLL_BASE;
 
 	/* enable FEC clock */
 	writel(readl(&pll->pccr1) | PCCR1_HCLK_FEC, &pll->pccr1);
 	writel(readl(&pll->pccr0) | PCCR0_FEC_EN, &pll->pccr0);
+#endif

Can we implement this clock enable in a way that goes without #ifdef ?

I think this should be dropped from the driver. The driver should be responsible to set up the FEC controller and nothing else. Enabling the clock should be done in another place (probably in the cpu related part ?), but not here. However, this is related to the i.MX27, I am not sure where we have to move this code.

Quoted 8 lines

drivers/net/fec_mxc.c static int fec_probe(bd_t *bd) · line 735

Quoted 4 lines
drivers/net/fec_mxc.c +1 -0
+	tmp = getenv("ethaddr");
 	if ((NULL != tmp) && (12 <= strlen(tmp))) {
 		int i;
 		/* convert MAC from string to int */

This is wrong and should be fixed. We don't convert to "int" but to "uchar[]"; While we touch this, please dump the code completely and use eth_getenv_enetaddr() instead.

Thanks, understood.

Regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
#21 lore raw

PATCH 6/9 fec_mxc: add support for MX51 processor

Dear Stefano Babic,

Quoted 11 lines · In message <[email protected]> you wrote:
Quoted 10 lines

drivers/net/fec_mxc.c static int fec_recv(struct eth_device *dev) · line 683

Quoted 8 lines
drivers/net/fec_mxc.c +3 -0
+#ifndef CONFIG_MX51
+	struct pll_regs *pll = (struct pll_regs *)IMX_PLL_BASE;
 
 	/* enable FEC clock */
 	writel(readl(&pll->pccr1) | PCCR1_HCLK_FEC, &pll->pccr1);
 	writel(readl(&pll->pccr0) | PCCR0_FEC_EN, &pll->pccr0);
+#endif

Can we implement this clock enable in a way that goes without #ifdef ?

Quoted 5 lines

I think this should be dropped from the driver. The driver should be responsible to set up the FEC controller and nothing else. Enabling the clock should be done in another place (probably in the cpu related part ?), but not here. However, this is related to the i.MX27, I am not sure where we have to move this code.

I'm not sure. Here is where we enable the FEC because we want to use it in a network command, right? Then this is the place to enable the needed clocks, too. These should not be globally enabled and running even if no network access is ever made - this would only increase the power dissipation, which is bad on battery operated devices.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Overdrawn?  But I still have checks left!
#22 lore raw

PATCH 6/9 fec_mxc: add support for MX51 processor

Quoted 1 line · Wolfgang Denk

Dear Stefano Babic,

Hi Wolfgang,

Quoted 3 lines

I'm not sure. Here is where we enable the FEC because we want to use it in a network command, right?

No, the fec_probe() function is called as part of the cpu_eth_init() and sets the callbacks, among the other things. It is called always, independently if we are ready to use a network command or not, it depends only on CONFIG_FEC_MXC.

I do not find very correct that the MAC address is set in this function (and not set anymore). What happens if I set the ethaddr variable ? Changes will be not effective until next reset of the system. It is a different issue, I know, but related to the same function. I had move setting to fec_init(), but this is already implemented (and I can test only on a i.MX51 board).

Quoted 4 lines

Then this is the place to enable the
needed clocks, too. These should not be globally enabled and running even if no network access is ever made - this would only increase the power dissipation, which is bad on battery operated devices.

However, I think it is the actual status in the driver, because the fec_probe is always called. The clock initialization should be moved as part of the fec_init() (that is, edev->init) to reach what you propose.

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
#23 lore raw

PATCH 6/9 fec_mxc: add support for MX51 processor

Stefano,

There is a patch in my mx25 series that factors out a lot of SOC specifics from the fec driver including clocks. It might be useful here.

John

Quoted 44 lines · Stefano Babic
Quoted 1 line · Wolfgang Denk

Dear Stefano Babic,

Hi Wolfgang,

Quoted 3 lines

I'm not sure. Here is where we enable the FEC because we want to use it in a network command, right?

No, the fec_probe() function is called as part of the cpu_eth_init() and sets the callbacks, among the other things. It is called always, independently if we are ready to use a network command or not, it depends only on CONFIG_FEC_MXC.

I do not find very correct that the MAC address is set in this function (and not set anymore). What happens if I set the ethaddr variable ? Changes will be not effective until next reset of the system. It is a different issue, I know, but related to the same function. I had move setting to fec_init(), but this is already implemented (and I can test only on a i.MX51 board).

Quoted 4 lines

Then this is the place to enable the
needed clocks, too. These should not be globally enabled and running even if no network access is ever made - this would only increase the power dissipation, which is bad on battery operated devices.

However, I think it is the actual status in the driver, because the fec_probe is always called. The clock initialization should be moved as part of the fec_init() (that is, edev->init) to reach what you propose.

Best regards,
Stefano Babic

--
=====================================================================
DENX Software Engineering GmbH, ? ? MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 ?Email: office at denx.de
=====================================================================
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#24 lore raw

PATCH 5/9 serial_mxc: add support for MX51 processor

In reply to Stefano Babic

Dear Stefano Babic,

drivers/serial/serial_mxc.c line 59

Quoted 12 lines · In message <[email protected]> you wrote:

The patch adds support for the Freescale mx51 processor.

drivers/serial/serial_mxc.c +6 -0
@@ -49,8 +51,14 @@
 #define UART_PHYS 0x1001b000
 #elif defined(CONFIG_SYS_MX27_UART6)
 #define UART_PHYS 0x1001c000
+#elif defined(CONFIG_SYS_MX51_UART1)
+#define UART_PHYS UART1_BASE_ADDR
+#elif defined(CONFIG_SYS_MX51_UART2)
+#define UART_PHYS UART2_BASE_ADDR
+#elif defined(CONFIG_SYS_MX51_UART3)
+#define UART_PHYS UART3_BASE_ADDR

What happens if - for example - CONFIG_SYS_MX51_UART1 _and_ CONFIG_SYS_MX51_UART2 are defiend? How is CONFIG_SERIAL_MULTI going to be supported?

drivers/serial/serial_mxc.c line 61

Quoted 2 lines
drivers/serial/serial_mxc.c +1 -1
-#error "define CONFIG_SYS_MX31_UARTx to use the mx31 UART driver"
+#error "define CONFIG_SYS_MXxx_UARTx to use the mxxx UART driver"

WHat's "mxxx" supposed to mean? This is not readable.

drivers/serial/serial_mxc.c void serial_setbrg (void) · line 183

Quoted 7 lines
drivers/serial/serial_mxc.c +2 -0
 #ifdef CONFIG_MX31
 	u32 clk = mx31_get_ipg_clk();
+#elif defined(CONFIG_MX51)
+	u32 clk = mxc_get_clock(MXC_UART_CLK);
 #else
 	u32 clk = imx_get_perclk1();
 #endif

Cannot we have a common clock interface?

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"This is a test of the Emergency Broadcast System. If this had been an
actual emergency, do you really think we'd stick around to tell you?"
#25 lore raw

PATCH 5/9 serial_mxc: add support for MX51 processor

Quoted 2 lines · Wolfgang Denk

Dear Stefano Babic,

Hi Wolfgang,

Quoted 6 lines
Quoted 6 lines
drivers/serial/serial_mxc.c +2 -0
@@ -49,8 +51,14 @@
 #define UART_PHYS 0x1001b000
 #elif defined(CONFIG_SYS_MX27_UART6)
 #define UART_PHYS 0x1001c000
+#elif defined(CONFIG_SYS_MX51_UART1)
+#define UART_PHYS UART1_BASE_ADDR
Quoted 8 lines

drivers/serial/serial_mxc.c line 59

Quoted 4 lines
drivers/serial/serial_mxc.c +4 -0
+#elif defined(CONFIG_SYS_MX51_UART2)
+#define UART_PHYS UART2_BASE_ADDR
+#elif defined(CONFIG_SYS_MX51_UART3)
+#define UART_PHYS UART3_BASE_ADDR

What happens if - for example - CONFIG_SYS_MX51_UART1 _and_ CONFIG_SYS_MX51_UART2 are defiend? How is CONFIG_SERIAL_MULTI going to be supported?

The patch adds only support for the i.MX51 and does
I understand what you mean. However, the driver at moment has the same problem with other processors (MX27, MX31). Should be not better to fix this issue with another patch that has nothing to do with i.MX51 ?

Quoted 5 lines

drivers/serial/serial_mxc.c line 61

Quoted 3 lines
drivers/serial/serial_mxc.c +1 -1
-#error "define CONFIG_SYS_MX31_UARTx to use the mx31 UART driver"
+#error "define CONFIG_SYS_MXxx_UARTx to use the mxxx UART driver"

WHat's "mxxx" supposed to mean? This is not readable.

You are right. I want only to get rid of specific processor statement, because according to code this driver runs on several Freescale imx processor. "MXC UART driver" is better defined as what I did.

Quoted 10 lines

drivers/serial/serial_mxc.c void serial_setbrg (void) · line 183

Quoted 8 lines
drivers/serial/serial_mxc.c +2 -0
 #ifdef CONFIG_MX31
 	u32 clk = mx31_get_ipg_clk();
+#elif defined(CONFIG_MX51)
+	u32 clk = mxc_get_clock(MXC_UART_CLK);
 #else
 	u32 clk = imx_get_perclk1();
 #endif

Cannot we have a common clock interface?

There is already a patch by John Rigby to drop them and using a general function for all of them. However, you are reviewing my first patchset. In V2 I have already removed the special implementation for MX51 and I have added the general function imx_get_uartclk(), as John implemented for the other MX processors.

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
#26 lore raw

PATCH 5/9 serial_mxc: add support for MX51 processor

Dear Stefano Babic,

Quoted 6 lines · In message <[email protected]> you wrote:
Quoted 4 lines

What happens if - for example - CONFIG_SYS_MX51_UART1 _and_ CONFIG_SYS_MX51_UART2 are defiend? How is CONFIG_SERIAL_MULTI going to be supported?

The patch adds only support for the i.MX51 and does

Something missing here ???

Quoted 3 lines

I understand what you mean. However, the driver at moment has the same problem with other processors (MX27, MX31). Should be not better to fix this issue with another patch that has nothing to do with i.MX51 ?

That's OK with me. But then, this shouldbe documented so nobody tries to enable more than one serial port.

Quoted 2 lines

There is already a patch by John Rigby to drop them and using a general function for all of them. However, you are reviewing my first patchset.

Sorry, I only noticed this later :-(

Quoted 3 lines

In V2 I have already removed the special implementation for MX51 and I have added the general function imx_get_uartclk(), as John implemented for the other MX processors.

Thanks.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"There are three principal ways to lose money: wine, women,  and  en-
gineers.  While  the first two are more pleasant, the third is by far
the more certain."                      -- Baron Rothschild, ca. 1800
#27 lore raw

PATCH 4/9 MX51: Add pin and multiplexer definitions.

In reply to Stefano Babic

Hi Stefano,

Quoted 20 lines

The patch add header files to support the pin multiplexer of the the Freescale i.MX51 processor.

Signed-off-by Fred Fan fanyefeng at gmail.com
---
 include/asm-arm/arch-mx51/iomux.h     |  240 ++++++++++++++++++++++
 include/asm-arm/arch-mx51/mx51_pins.h |  365 +++++++++++++++++++++++++++++++++
 2 files changed, 605 insertions(+), 0 deletions(-)
 create mode 100644 include/asm-arm/arch-mx51/iomux.h
 create mode 100644 include/asm-arm/arch-mx51/mx51_pins.h
include/asm-arm/arch-mx51/iomux.h new file +2 -0
new file mode 100644
index 0000000..3724bb8
@@ -0,0 +1,240 @@
+/*
+ * Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved.

include/asm-arm/arch-mx51/iomux.h line 12

Quoted 10 lines
include/asm-arm/arch-mx51/iomux.h new file +10 -0
+ */
+
+/*
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */

Ok, please check all your files for such a header and fix it, I will stop here complaining about them ;)

Cheers
Detlev

Signature · 7 lines
Or go for generality ... Add a programming language for extensibility
and write part of the program in that language.
                                    --- GNU Coding Standards
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de
#28 lore raw

PATCH 4/9 MX51: Add pin and multiplexer definitions.

In reply to Stefano Babic

Dear Stefano Babic,

Quoted 2 lines · In message <[email protected]> you wrote:

The patch add header files to support the pin multiplexer of the the Freescale i.MX51 processor.

...

Quoted 17 lines
include/asm-arm/arch-mx51/iomux.h new file +17 -0
+/*!
+ * various IOMUX pad functions
+ */
+typedef enum iomux_pad_config {
+	PAD_CTL_SRE_SLOW = 0x0 << 0,
+	PAD_CTL_SRE_FAST = 0x1 << 0,
+	PAD_CTL_DRV_LOW = 0x0 << 1,
+	PAD_CTL_DRV_MEDIUM = 0x1 << 1,
+	PAD_CTL_DRV_HIGH = 0x2 << 1,
+	PAD_CTL_DRV_MAX = 0x3 << 1,
+	PAD_CTL_ODE_OPENDRAIN_NONE = 0x0 << 3,
+	PAD_CTL_ODE_OPENDRAIN_ENABLE = 0x1 << 3,
+	PAD_CTL_100K_PD = 0x0 << 4,
+	PAD_CTL_47K_PU = 0x1 << 4,
+	PAD_CTL_100K_PU = 0x2 << 4,
+	PAD_CTL_22K_PU = 0x3 << 4,
+	PAD_CTL_PUE_KEEPER = 0x0 << 6,

include/asm-arm/arch-mx51/iomux.h line 73

Quoted 10 lines
include/asm-arm/arch-mx51/iomux.h new file +10 -0
+	PAD_CTL_PUE_PULL = 0x1 << 6,
+	PAD_CTL_PKE_NONE = 0x0 << 7,
+	PAD_CTL_PKE_ENABLE = 0x1 << 7,
+	PAD_CTL_HYS_NONE = 0x0 << 8,
+	PAD_CTL_HYS_ENABLE = 0x1 << 8,
+	PAD_CTL_DDR_INPUT_CMOS = 0x0 << 9,
+	PAD_CTL_DDR_INPUT_DDR = 0x1 << 9,
+	PAD_CTL_DRV_VOT_LOW = 0x0 << 13,
+	PAD_CTL_DRV_VOT_HIGH = 0x1 << 13,
+} iomux_pad_config_t;

Please add comments what these settings actually mean.

Quoted 9 lines
include/asm-arm/arch-mx51/iomux.h new file +9 -0
+/*!
+ * Request ownership for an IO pin. This function has to be the first one
+ * being called before that pin is used. The caller has to check the
+ * return value to make sure it returns 0.
+ *
+ * @param  pin		a name defined by \b iomux_pin_name_t
+ * @param  config	config as defined in \b #iomux_pin_ocfg_t
+ *
+ * @return		0 if successful; Non-zero otherwise

include/asm-arm/arch-mx51/iomux.h line 211

Quoted 10 lines
include/asm-arm/arch-mx51/iomux.h new file +10 -0
+ */
+void mxc_request_iomux(iomux_pin_name_t pin, iomux_pin_cfg_t config);
+
+/*!
+ * Release ownership for an IO pin
+ *
+ * @param  pin		a name defined by \b iomux_pin_name_t
+ * @param  config	config as defined in \b #iomux_pin_ocfg_t
+ */
+void mxc_free_iomux(iomux_pin_name_t pin, iomux_pin_cfg_t config);

Please provide these comments where the code gets implemented, and omit it here where we just have the prototype declarations.

...

include/asm-arm/arch-mx51/mx51_pins.h line 95

Quoted 5 lines
include/asm-arm/arch-mx51/mx51_pins.h new file +5 -0
+#define _MXC_BUILD_GPIO_PIN(gp, gi, ga, mi, pi) \
+    _MXC_BUILD_PIN(gp, gi, ga, mi, pi)
+
+#define _MXC_BUILD_NON_GPIO_PIN(mi, pi) \
+    _MXC_BUILD_PIN(NON_GPIO_PORT, 0, 0, mi, pi)

Indentation by TAB, please. Please fix globally.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
...when fits of creativity run strong, more than  one  programmer  or
writer  has  been  known to abandon the desktop for the more spacious
floor.                                             - Fred Brooks, Jr.
#29 lore raw

PATCH 3/9 MX51: Add register definitions

In reply to Stefano Babic

Hi Stefano,

Quoted 20 lines

The patch add header files to support the Freescale i.MX51 processor, setting definitions for internal registers.

Signed-off-by Fred Fan fanyefeng at gmail.com
---
 include/asm-arm/arch-mx51/crm_regs.h |  182 +++++++++++++++++++++
 include/asm-arm/arch-mx51/imx-regs.h |  298 ++++++++++++++++++++++++++++++++++
 2 files changed, 480 insertions(+), 0 deletions(-)
 create mode 100644 include/asm-arm/arch-mx51/crm_regs.h
 create mode 100644 include/asm-arm/arch-mx51/imx-regs.h
include/asm-arm/arch-mx51/crm_regs.h new file +2 -0
new file mode 100644
index 0000000..92da560
@@ -0,0 +1,182 @@
+/*
+ * Copyright 2009 Freescale Semiconductor, Inc. All Rights Reserved.

include/asm-arm/arch-mx51/crm_regs.h line 12

Quoted 10 lines
include/asm-arm/arch-mx51/crm_regs.h new file +10 -0
+ */
+
+/*
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */

Again we need to state explicitely the version of the GPL.

Quoted 10 lines
include/asm-arm/arch-mx51/crm_regs.h new file +9 -0
+#ifndef __ARCH_ARM_MACH_MX51_CRM_REGS_H__
 
+#define __ARCH_ARM_MACH_MX51_CRM_REGS_H__
+
+#define MXC_CCM_BASE	CCM_BASE_ADDR
+
+/* DPLL register mapping structure */
+struct mxc_pll_reg {
+	unsigned int ctrl;
+	unsigned int config;

include/asm-arm/arch-mx51/crm_regs.h line 31

Quoted 10 lines
include/asm-arm/arch-mx51/crm_regs.h new file +10 -0
+	unsigned int op;
+	unsigned int mfd;
+	unsigned int mfn;
+	unsigned int mfn_minus;
+	unsigned int mfn_plus;
+	unsigned int hfs_op;
+	unsigned int hfs_mfd;
+	unsigned int hfs_mfn;
+	unsigned int mfn_togc;
+	unsigned int destat;

Why not use u32 to explicitely state the width? Same goes for the rest of the file.

Cheers
Detlev

Signature · 6 lines
Zivilisation ist der Zaubertrick, der uns unsere wahre Natur verbirgt.
                                            -- Salman Rushdie
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de
#30 lore raw

PATCH 3/9 MX51: Add register definitions

In reply to Stefano Babic

Dear Stefano Babic,

Quoted 2 lines · In message <[email protected]> you wrote:

The patch add header files to support the Freescale i.MX51 processor, setting definitions for internal registers.

...

include/asm-arm/arch-mx51/crm_regs.h line 79

Quoted 4 lines
include/asm-arm/arch-mx51/crm_regs.h new file +4 -0
+/* Define the bits in register CBCDR */
+#define MXC_CCM_CBCDR_EMI_CLK_SEL			(0x1 << 26)
+#define MXC_CCM_CBCDR_PERIPH_CLK_SEL			(0x1 << 25)
+#define MXC_CCM_CBCDR_EMI_PODF_OFFSET		(22)

Please remove the prens around plain numbers like here...

include/asm-arm/arch-mx51/crm_regs.h line 81

Quoted 2 lines
include/asm-arm/arch-mx51/crm_regs.h new file +2 -0
+#define MXC_CCM_CBCDR_EMI_PODF_MASK			(0x7 << 22)
+#define MXC_CCM_CBCDR_AXI_B_PODF_OFFSET		(19)

... and here ... and everywhere else.

...

include/asm-arm/arch-mx51/imx-regs.h line 163

Quoted 6 lines
include/asm-arm/arch-mx51/imx-regs.h new file +6 -0
+/* WEIM registers */
+#define CSGCR1	0x00
+#define CSGCR2	0x04
+#define CSRCR1	0x08
+#define CSRCR2	0x0C
+#define CSWCR1	0x10

This looks like something that should be converted into a C struct.

include/asm-arm/arch-mx51/imx-regs.h line 181

Quoted 13 lines
include/asm-arm/arch-mx51/imx-regs.h new file +13 -0
+/* ESDCTL */
+#define ESDCTL_ESDCTL0                  0x00
+#define ESDCTL_ESDCFG0                  0x04
+#define ESDCTL_ESDCTL1                  0x08
+#define ESDCTL_ESDCFG1                  0x0C
+#define ESDCTL_ESDMISC                  0x10
+#define ESDCTL_ESDSCR                   0x14
+#define ESDCTL_ESDCDLY1                 0x20
+#define ESDCTL_ESDCDLY2                 0x24
+#define ESDCTL_ESDCDLY3                 0x28
+#define ESDCTL_ESDCDLY4                 0x2C
+#define ESDCTL_ESDCDLY5                 0x30
+#define ESDCTL_ESDCDLYGD                0x34

Ditto.

Quoted 25 lines
include/asm-arm/arch-mx51/imx-regs.h new file +25 -0
+/* CCM */
+#define CLKCTL_CCR              0x00
+#define CLKCTL_CCDR             0x04
+#define CLKCTL_CSR              0x08
+#define CLKCTL_CCSR             0x0C
+#define CLKCTL_CACRR            0x10
+#define CLKCTL_CBCDR            0x14
+#define CLKCTL_CBCMR            0x18
+#define CLKCTL_CSCMR1           0x1C
+#define CLKCTL_CSCMR2           0x20
+#define CLKCTL_CSCDR1           0x24
+#define CLKCTL_CS1CDR           0x28
+#define CLKCTL_CS2CDR           0x2C
+#define CLKCTL_CDCDR            0x30
+#define CLKCTL_CHSCCDR          0x34
+#define CLKCTL_CSCDR2           0x38
+#define CLKCTL_CSCDR3           0x3C
+#define CLKCTL_CSCDR4           0x40
+#define CLKCTL_CWDR             0x44
+#define CLKCTL_CDHIPR           0x48
+#define CLKCTL_CDCR             0x4C
+#define CLKCTL_CTOR             0x50
+#define CLKCTL_CLPCR            0x54
+#define CLKCTL_CISR             0x58
+#define CLKCTL_CIMR             0x5C

include/asm-arm/arch-mx51/imx-regs.h line 217

Quoted 10 lines
include/asm-arm/arch-mx51/imx-regs.h new file +10 -0
+#define CLKCTL_CCOSR            0x60
+#define CLKCTL_CGPR             0x64
+#define CLKCTL_CCGR0            0x68
+#define CLKCTL_CCGR1            0x6C
+#define CLKCTL_CCGR2            0x70
+#define CLKCTL_CCGR3            0x74
+#define CLKCTL_CCGR4            0x78
+#define CLKCTL_CCGR5            0x7C
+#define CLKCTL_CCGR6            0x80
+#define CLKCTL_CMEOR            0x84

And again.

include/asm-arm/arch-mx51/imx-regs.h line 231

Quoted 13 lines
include/asm-arm/arch-mx51/imx-regs.h new file +13 -0
+/* DPLL */
+#define PLL_DP_CTL	0x00
+#define PLL_DP_CONFIG	0x04
+#define PLL_DP_OP	0x08
+#define PLL_DP_MFD	0x0C
+#define PLL_DP_MFN	0x10
+#define PLL_DP_MFNMINUS	0x14
+#define PLL_DP_MFNPLUS	0x18
+#define PLL_DP_HFS_OP	0x1C
+#define PLL_DP_HFS_MFD	0x20
+#define PLL_DP_HFS_MFN	0x24
+#define PLL_DP_TOGC	0x28
+#define PLL_DP_DESTAT	0x2C

And again.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Real computer scientists despise the idea of actual  hardware.  Hard-
ware has limitations, software doesn't. It's a real shame that Turing
machines are so poor at I/O.
#31 lore raw

PATCH 3/9 MX51: Add register definitions

Quoted 2 lines · Wolfgang Denk

Dear Stefano Babic,

Hi Wolfgang,

Quoted 1 line
Quoted 1 line

+#define MXC_CCM_CBCDR_EMI_PODF_OFFSET (22)

Thanks, I do it.

Quoted 8 lines

include/asm-arm/arch-mx51/imx-regs.h line 163

Quoted 6 lines
include/asm-arm/arch-mx51/imx-regs.h new file +6 -0
+/* WEIM registers */
+#define CSGCR1	0x00
+#define CSGCR2	0x04
+#define CSRCR1	0x08
+#define CSRCR2	0x0C
+#define CSWCR1	0x10

This looks like something that should be converted into a C struct.

You are right.

Quoted 4 lines

include/asm-arm/arch-mx51/imx-regs.h line 181

Quoted 2 lines
include/asm-arm/arch-mx51/imx-regs.h new file +2 -0
+#define ESDCTL_ESDCDLY5                 0x30
+#define ESDCTL_ESDCDLYGD                0x34

Ditto.

i can say more: this defines are not used anymore and I can drop them. I have already cleanup the code removing unnecessary defines, but it seems not enough.

Quoted 10 lines

include/asm-arm/arch-mx51/imx-regs.h line 191

Quoted 10 lines
include/asm-arm/arch-mx51/imx-regs.h new file +9 -0
+/* CCM */
+#define CLKCTL_CCR              0x00
+#define CLKCTL_CCDR             0x04
+#define CLKCTL_CSR              0x08
+#define CLKCTL_CCSR             0x0C
+#define CLKCTL_CACRR            0x10
+#define CLKCTL_CBCDR            0x14
+#define CLKCTL_CBCMR            0x18
+#define CLKCTL_CSCMR1           0x1C

They are obsolete,too. There is already a C struct describing them. I drop them.

Quoted 15 lines
Quoted 15 lines
include/asm-arm/arch-mx51/imx-regs.h new file +15 -0
+#define CLKCTL_CCGR0            0x68
+#define CLKCTL_CCGR1            0x6C
+#define CLKCTL_CCGR2            0x70
+#define CLKCTL_CCGR3            0x74
+#define CLKCTL_CCGR4            0x78
+#define CLKCTL_CCGR5            0x7C
+#define CLKCTL_CCGR6            0x80
+#define CLKCTL_CMEOR            0x84
+/* DPLL */
+#define PLL_DP_CTL	0x00
+#define PLL_DP_CONFIG	0x04
+#define PLL_DP_OP	0x08
+#define PLL_DP_MFD	0x0C
+#define PLL_DP_MFN	0x10
+#define PLL_DP_MFNMINUS	0x14
Quoted 8 lines

include/asm-arm/arch-mx51/imx-regs.h line 231

Quoted 6 lines
include/asm-arm/arch-mx51/imx-regs.h new file +6 -0
+#define PLL_DP_MFNPLUS	0x18
+#define PLL_DP_HFS_OP	0x1C
+#define PLL_DP_HFS_MFD	0x20
+#define PLL_DP_HFS_MFN	0x24
+#define PLL_DP_TOGC	0x28
+#define PLL_DP_DESTAT	0x2C

And again.

This is a different fall. These defines are used in the assembly lowlevel_init.S in the first initialization. I cannot remove them. However, only a part of these defines are currently used and I will drop the rest of them.

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
#32 lore raw

PATCH 3/9 MX51: Add register definitions

Dear Stefano,

Quoted 16 lines · In message <[email protected]> you wrote:
Quoted 15 lines

include/asm-arm/arch-mx51/imx-regs.h line 231

Quoted 13 lines
include/asm-arm/arch-mx51/imx-regs.h new file +12 -0
+#define PLL_DP_CTL	0x00
+#define PLL_DP_CONFIG	0x04
+#define PLL_DP_OP	0x08
+#define PLL_DP_MFD	0x0C
+#define PLL_DP_MFN	0x10
+#define PLL_DP_MFNMINUS	0x14
+#define PLL_DP_MFNPLUS	0x18
+#define PLL_DP_HFS_OP	0x1C
+#define PLL_DP_HFS_MFD	0x20
+#define PLL_DP_HFS_MFN	0x24
+#define PLL_DP_TOGC	0x28
+#define PLL_DP_DESTAT	0x2C

And again.

Quoted 4 lines

This is a different fall. These defines are used in the assembly lowlevel_init.S in the first initialization. I cannot remove them. However, only a part of these defines are currently used and I will drop the rest of them.

Such offset definitions should better go into a separate asm-offsets.h file, as we did for the mpc512x (cpu/mpc512x/asm-offsets.h).

If you have some spare cycles, it would be really great if you could try and adapt the Linux method of auto-generating the asm-offsets.h file from the respective C struct declarations - we have a growing number of such cases so that would be really welcome.

Thanks in advance.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
No journaling file system can recover your data if the disk dies.
                                 - Steve Rago in <[email protected]>
#33 lore raw

PATCH 2/9 MX51: Add initial support for the Freescale MX51

In reply to Stefano Babic

Hi Stefano,

Quoted 2 lines

The patch add initial support for the Freescale i.MX51 processor (family arm cortex_a8).

A small comment below.

[...]

Quoted 8 lines
cpu/arm_cortexa8/mx51/iomux.c new file +2 -0
new file mode 100644
index 0000000..a42ec3a
@@ -0,0 +1,205 @@
+/*
+ * Copyright 2009 Freescale Semiconductor, Inc. All Rights Reserved.

cpu/arm_cortexa8/mx51/iomux.c line 12

Quoted 10 lines
cpu/arm_cortexa8/mx51/iomux.c new file +10 -0
+ */
+
+/*
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */

This header is not good enough - it is not clear what actual version of the GPL the code is licensed under. Please replace this with a "standard" header.

Cheers
Detlev

Signature · 7 lines
Emacs seems a more likely candidate  to contain a mail system than the
mail system to contain an Emacs, so this is the way it was done.
                                            -- Bernard S. Greenberg
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de
#34 lore raw

PATCH 2/9 MX51: Add initial support for the Freescale MX51

Quoted 2 lines · Detlev Zundel

Hi Stefano,

Hi Detlev,

Quoted 11 lines
Quoted 11 lines
cpu/arm_cortexa8/mx51/iomux.c new file +8 -0
@@ -0,0 +1,205 @@
+/*
+ * Copyright 2009 Freescale Semiconductor, Inc. All Rights Reserved.
+ */
+
+/*
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
Quoted 8 lines

cpu/arm_cortexa8/mx51/iomux.c line 12

Quoted 4 lines
cpu/arm_cortexa8/mx51/iomux.c new file +4 -0
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */

This header is not good enough - it is not clear what actual version of the GPL the code is licensed under. Please replace this with a "standard" header.

I agree, but the copyright was set by Freescale and Fred in the first review said, he was not the original author of the code. I think I am not allowed to change this part even if I will not change the copyright statement. Of course, if I can, I will replace it with a standard header.

Stefano

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
#35 lore raw

PATCH 2/9 MX51: Add initial support for the Freescale MX51

Hi Stefano,

Quoted 26 lines
Quoted 2 lines · Detlev Zundel

Hi Stefano,

Hi Detlev,

Quoted 11 lines
Quoted 11 lines
cpu/arm_cortexa8/mx51/iomux.c new file +8 -0
@@ -0,0 +1,205 @@
+/*
+ * Copyright 2009 Freescale Semiconductor, Inc. All Rights Reserved.
+ */
+
+/*
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
Quoted 8 lines

cpu/arm_cortexa8/mx51/iomux.c line 12

Quoted 4 lines
cpu/arm_cortexa8/mx51/iomux.c new file +4 -0
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */

This header is not good enough - it is not clear what actual version of the GPL the code is licensed under. Please replace this with a "standard" header.

Quoted 4 lines

I agree, but the copyright was set by Freescale and Fred in the first review said, he was not the original author of the code. I think I am not allowed to change this part even if I will not change the copyright statement. Of course, if I can, I will replace it with a standard header.

Well, I presume that we all agree the text wants to be read to mean "GPLv2 or later", although it does not state that clearly enough. So all I ask for is to make this more explicit - it is _not_ a change of the licensing at all.

Thanks
Detlev

Signature · 7 lines
The fact is, volatile on data structures is a bug. It's a wart in the C 
language. It shouldn't be used.
                                   -- Linus Torvalds 
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de
#36 lore raw

PATCH 2/9 MX51: Add initial support for the Freescale MX51

In reply to Stefano Babic

Hi Stefano,

Quoted 4 lines

The patch add initial support for the Freescale i.MX51 processor (family arm cortex_a8).

Signed-off-by Fred Fan fanyefeng at gmail.com

I just noticed that this format misses the "<>" around the e-mail address, please fix for next round. This also applies to the other patches in this series.

Cheers
Detlev

Signature · 6 lines
"If you think the Y2K crisis is bad - then wait for the year 9999...."
                                          -- Donald Knuth
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de
#37 lore raw

PATCH 2/9 MX51: Add initial support for the Freescale MX51

In reply to Stefano Babic

Dear Stefano Babic,

Quoted 2 lines · In message <[email protected]> you wrote:

The patch add initial support for the Freescale i.MX51 processor (family arm cortex_a8).

...

Quoted 2 lines
cpu/arm_cortexa8/mx51/clock.c new file +0 -0

...

Quoted 3 lines

+/*
+ * Calculate the frequence of this pll.
+ */

Typo: frequency

cpu/arm_cortexa8/mx51/clock.c line 72

Quoted 6 lines
cpu/arm_cortexa8/mx51/clock.c new file +6 -0
+u32 get_mcu_main_clk(void)
+{
+	u32 reg, freq;
+
+	reg = (__raw_readl(&mxc_ccm->cacrr) & MXC_CCM_CACRR_ARM_PODF_MASK) >>
+	    MXC_CCM_CACRR_ARM_PODF_OFFSET;

Indentation not by TAB.

...

cpu/arm_cortexa8/mx51/clock.c line 282

Quoted 7 lines
cpu/arm_cortexa8/mx51/clock.c new file +7 -0
+/***************************************************/
+
+U_BOOT_CMD(
+	mx51clocks,	CONFIG_SYS_MAXARGS,	1,	do_mx51_showclocks,
+	"display mx51 clocks\n",
+	""
+);

It makes little sense to implement arch specific commands that will most probably repeated - I don;t want to see a "mx51clocks" command here, and "mx25clocks", "mx27clocks", "mx31clocks", "mx35clocks", ... commands on other systems. Just name this "clockinfo" (which is more in line with the existing commands as "bdinfo", "reginfo", "flinfo" etc.) or, if you insist, "showclocks" or just "clocks".

...

Quoted 6 lines

+/*!
+ * This function is used to configure a pin through the IOMUX module.
+ * @param pin a pin number as defined in \b #iomux_pin_name_t
+ * @param cfg an output function as defined in \b #iomux_pin_cfg_t
+ *
+ * @return 0 if successful; Non-zero otherwise

Lines too long, please check globally.

And please get rid of the '\b' stuff in the comments (and eventually of the "/*!" things etc., too.).

Quoted 15 lines
cpu/arm_cortexa8/mx51/clock.c new file +15 -0
+void mxc_iomux_set_input(iomux_input_select_t input, u32 config)
+{
+	u32 reg;
+
+	if (is_soc_rev(CHIP_REV_2_0) < 0) {
+		if (input == MUX_IN_IPU_IPP_DI_0_IND_DISPB_SD_D_SELECT_INPUT)
+			input -= 4;
+		else if (input ==
+			 MUX_IN_IPU_IPP_DI_1_IND_DISPB_SD_D_SELECT_INPUT)
+			input -= 3;
+		else if (input >= MUX_IN_KPP_IPP_IND_COL_6_SELECT_INPUT)
+			input -= 2;
+		else if (input >=
+			 MUX_IN_HSC_MIPI_MIX_PAR_SISG_TRIG_SELECT_INPUT)
+			input -= 5;

cpu/arm_cortexa8/mx51/clock.c

Quoted 10 lines
cpu/arm_cortexa8/mx51/clock.c new file +10 -0
+		else if (input >=
+			 MUX_IN_HSC_MIPI_MIX_IPP_IND_SENS1_DATA_EN_SELECT_INPUT)
+			input -= 3;
+		else if (input >= MUX_IN_ECSPI2_IPP_IND_SS_B_3_SELECT_INPUT)
+			input -= 2;
+		else if (input >= MUX_IN_CCM_PLL1_BYPASS_CLK_SELECT_INPUT)
+			input -= 1;
+		reg = IOMUXSW_INPUT_CTL + (input << 2) + INPUT_CTL_START_TO1;
+	} else
+		reg = IOMUXSW_INPUT_CTL + (input << 2) + INPUT_CTL_START;

This is pretty much unreadable, and even more difficult to understand. Add comment to explain the logic, and fix indentation in wrapped lines (use TABs only).

Quoted 6 lines
cpu/arm_cortexa8/mx51/lowlevel_init.S new file +0 -0
new file mode 100644
index 0000000..843a7b8

cpu/arm_cortexa8/mx51/lowlevel_init.S line 32

Quoted 9 lines
cpu/arm_cortexa8/mx51/lowlevel_init.S new file +8 -0
@@ -0,0 +1,320 @@
 
+/*
+ * return soc version
+ * 	0x10:  TO1
+ *	0x20:  TO2
+ *	0x30:  TO3
+ */
+.macro check_soc_version ret, tmp
+.endm

??? Please don;t add dead code.

Quoted 5 lines
cpu/arm_cortexa8/mx51/lowlevel_init.S new file +5 -0
+/*
+ * L2CC Cache setup/invalidation/disable
+ */
+.macro init_l2cc
+	/* explicitly disable L2 cache */

cpu/arm_cortexa8/mx51/lowlevel_init.S line 48

Quoted 10 lines
cpu/arm_cortexa8/mx51/lowlevel_init.S new file +10 -0
+        mrc 15, 0, r0, c1, c0, 1
+        bic r0, r0, #0x2
+        mcr 15, 0, r0, c1, c0, 1
+
+        /* reconfigure L2 cache aux control reg */
+        mov r0, #0xC0                   /* tag RAM */
+        add r0, r0, #0x4                /* data RAM */
+        orr r0, r0, #(1 << 24)          /* disable write allocate delay */
+        orr r0, r0, #(1 << 23)          /* disable write allocate combine */
+        orr r0, r0, #(1 << 22)          /* disable write allocate */

Indentation by TAB only, please. Please check and fix coding style globally, in allpatches.

Quoted 3 lines

+/* MAX (Multi-Layer AHB Crossbar Switch) setup */ +.macro init_max
+.endm /* init_max */

No dead code, please.

Quoted 15 lines
cpu/arm_cortexa8/mx51/lowlevel_init.S new file +15 -0
+/* M4IF setup */
+.macro init_m4if
+	/* VPU and IPU given higher priority (0x4)
+	 * IPU accesses with ID=0x1 given highest priority (=0xA)
+	 */
+	ldr r0, =M4IF_BASE_ADDR
+
+	ldr r1, =0x00000203
+	str r1, [r0, #0x40]
+
+	ldr r1, =0x0
+	str r1, [r0, #0x44]
+
+	ldr r1, =0x00120125
+	str r1, [r0, #0x9C]

cpu/arm_cortexa8/mx51/lowlevel_init.S line 105

Quoted 10 lines
cpu/arm_cortexa8/mx51/lowlevel_init.S new file +10 -0
+
+	ldr r1, =0x001901A3
+	str r1, [r0, #0x48]
+
+/*
+	ldr r1, =0x00000a01
+	str r1, [r0, #0x48]
+	ldr r1, =0x00000404
+	str r1, [r0, #0x40]
+*/

No dead code please. Please fix globally.

cpu/arm_cortexa8/mx51/lowlevel_init.S

Quoted 7 lines
cpu/arm_cortexa8/mx51/lowlevel_init.S new file +7 -0
+#if defined(CONFIG_DISPLAY_CPUINFO)
+int print_cpuinfo(void)
+{
+	printf("CPU:   Freescale i.MX51 family %d.%dV at %d MHz\n",
+	       (get_board_rev() & 0xFF) >> 4,
+	       (get_board_rev() & 0xF),
+		get_mcu_main_clk() / 1000000);

This is wrong. You ar enot printing a _BOARD_ revision here, but a processor revision. Please fix.

cpu/arm_cortexa8/mx51/lowlevel_init.S

Quoted 9 lines
cpu/arm_cortexa8/mx51/lowlevel_init.S new file +9 -0
+ulong get_timer_masked(void)
+{
+	ulong val = __raw_readl(&cur_gpt->counter);
+	val /= (CONFIG_MX51_CLK32 / CONFIG_SYS_HZ);
+	if (val >= lastinc)
+		timestamp += (val - lastinc);
+	else
+		timestamp += ((0xFFFFFFFF / (CONFIG_MX51_CLK32 / CONFIG_SYS_HZ))
+				- lastinc) + val;

Please use braces for multi-line statements.

Quoted 19 lines
cpu/arm_cortexa8/mx51/lowlevel_init.S new file +19 -0
+	lastinc = val;
+	return val;
+}
+
+ulong get_timer(ulong base)
+{
+	return get_timer_masked() - base;
+}
+
+void set_timer(ulong t)
+{
+	timestamp = t;
+}
+
+/* delay x useconds AND perserve advance timstamp value */
+void __udelay(unsigned long usec)
+{
+	unsigned long now, last = readl(&cur_gpt->counter);
+	long tmo = usec * (CONFIG_MX51_CLK32 / 1000) / 1000;

cpu/arm_cortexa8/mx51/lowlevel_init.S

Quoted 10 lines
cpu/arm_cortexa8/mx51/lowlevel_init.S new file +10 -0
+
+	if (!tmo)
+		tmo = 1;
+
+	while (tmo > 0) {
+		now = readl(&cur_gpt->counter);
+		if (last > now)
+			tmo -= 0xFFFFFFFF - last + now;
+		else
+			tmo -= now - last;

Is this correct wrap-around handling?

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
The use of anthropomorphic terminology when  dealing  with  computing
systems is a symptom of professional immaturity.   -- Edsger Dijkstra
#38 lore raw

PATCH 2/9 MX51: Add initial support for the Freescale MX51

Quoted 2 lines · Wolfgang Denk

Dear Stefano Babic,

Hi Wolfgang,

Quoted 6 lines

It makes little sense to implement arch specific commands that will most probably repeated - I don;t want to see a "mx51clocks" command here, and "mx25clocks", "mx27clocks", "mx31clocks", "mx35clocks", ... commands on other systems. Just name this "clockinfo" (which is more in line with the existing commands as "bdinfo", "reginfo", "flinfo" etc.) or, if you insist, "showclocks" or just "clocks".

Understood, you are right, clockinfo is a much more neutral name.

Quoted 9 lines
Quoted 9 lines
cpu/arm_cortexa8/mx51/timer.c new file +9 -0
+/* delay x useconds AND perserve advance timstamp value */
+void __udelay(unsigned long usec)
+{
+	unsigned long now, last = readl(&cur_gpt->counter);
+	long tmo = usec * (CONFIG_MX51_CLK32 / 1000) / 1000;
+
+	if (!tmo)
+		tmo = 1;
+
Quoted 8 lines

cpu/arm_cortexa8/mx51/timer.c line 119

Quoted 6 lines
cpu/arm_cortexa8/mx51/timer.c new file +6 -0
+	while (tmo > 0) {
+		now = readl(&cur_gpt->counter);
+		if (last > now)
+			tmo -= 0xFFFFFFFF - last + now;
+		else
+			tmo -= now - last;

Is this correct wrap-around handling?

Well, the code is quite the same as in omap3. It seems that omap suffers from the same issue. Best thing here should be to read the timer before the loop to get a timestamp and to check in the loop for the wrap-around, resetting the counter if needed.

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
#39 lore raw

PATCH 2/9 MX51: Add initial support for the Freescale MX51

Dear Stefano Babic,

Quoted 16 lines · In message <[email protected]> you wrote:
Quoted 15 lines

cpu/arm_cortexa8/mx51/timer.c line 119

Quoted 13 lines
cpu/arm_cortexa8/mx51/timer.c new file +12 -0
+	unsigned long now, last = readl(&cur_gpt->counter);
+	long tmo = usec * (CONFIG_MX51_CLK32 / 1000) / 1000;
+
+	if (!tmo)
+		tmo = 1;
+
+	while (tmo > 0) {
+		now = readl(&cur_gpt->counter);
+		if (last > now)
+			tmo -= 0xFFFFFFFF - last + now;
+		else
+			tmo -= now - last;

Is this correct wrap-around handling?

Quoted 2 lines

Well, the code is quite the same as in omap3. It seems that omap suffers from the same issue. Best thing here should be to read the timer before

Maybe, I didn;t check. Eventually OMAP can be fixed, too.

Quoted 2 lines

the loop to get a timestamp and to check in the loop for the wrap-around, resetting the counter if needed.

Do we really have to make it such complicated? All this are "usinged int" operations, right? Then let's just make use of the properties of "usinged int" artihmentics...

IMO the code should be rewritten like this:

	unsigned long start, now, timeout;

	start = now = readl(&cur_gpt->counter);

	while ((now - start) < timeout)
		now = readl(&cur_gpt->counter);

This should handle wraparounds nicely.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Lack of skill dictates economy of style.                - Joey Ramone
#40 lore raw

PATCH 1/9 mkimage: Add Freescale imx Boot Image support (imximage)

In reply to Stefano Babic

Hi Stefano,

Quoted 7 lines

This patch adds support for "imximage" (MX Boot Image) to the mkimage utility. The imximage is used on the Freescales's MX.51 processors.

Further details under doc/README.imximage.

This patch was tested on a Freescale mx51evk board.

You should run checkpatch over this. Apart from that some comments below.

[...]

Quoted 45 lines
tools/imximage.c new file +39 -0
new file mode 100644
index 0000000..b40a23b
@@ -0,0 +1,289 @@
+/*
+ * (C) Copyright 2009
+ * Stefano Babic, DENX Software Engineering, sbabic at denx.de.
+ *
+ * (C) Copyright 2008
+ * Marvell Semiconductor <www.marvell.com>
+ * Written-by: Prafulla Wadaskar <[email protected]>
+ *
+ * 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 "mkimage.h"
+#include <image.h>
+#include "imximage.h"
+
+/*
+ * Supported commands for configuration file
+ */
+static table_entry_t imximage_cmds[] = {
+	{CMD_BOOT_FROM,		"BOOT_FROM",		"boot comand",	},
+	{CMD_DATA,		"DATA",			"Reg Write Data", },
+	{-1,		"",			"",	},
+};

tools/imximage.c line 49

Quoted 10 lines
tools/imximage.c new file +10 -0
+
+/*
+ * Supported Boot options for configuration file
+ * this is needed to set the correct flash offset
+ */
+static table_entry_t imximage_bootops[] = {
+	{FLASH_OFFSET_SPI,	"spi",		"SPI Flash",	},
+	{FLASH_OFFSET_NAND,	"nand",		"NAND Flash",	},
+	{FLASH_OFFSET_SD,	"sd",		"SD Card",	},
+       {FLASH_OFFSET_ONENAND,  "onenand",      "OneNAND Flash",},

Indentation not by tabs

Quoted 7 lines
tools/imximage.c new file +7 -0
+	{-1,			"",		"Invalid",	},
+};
+
+
+static struct imx_header imximage_header;
+
+static uint32_t get_cfg_value(char *token, char *name,  int linenr)

tools/imximage.c line 66

Quoted 10 lines
tools/imximage.c new file +10 -0
+{
+	char *endptr;
+	uint32_t value;
+
+	errno = 0;
+	value = strtoul(token, &endptr, 16);
+	if (errno || (token == endptr)) {
+		printf ("Error: %s[%d] - Invalid hex data(%s)\n",
+			name,  linenr, token);
+			exit (EXIT_FAILURE);

Errors should go to stderr

Quoted 30 lines
tools/imximage.c new file +30 -0
+	}
+	return value;
+}
+
+static int imximage_check_image_types (uint8_t type)
+{
+	if (type == IH_TYPE_IMXIMAGE)
+		return EXIT_SUCCESS;
+	else
+		return EXIT_FAILURE;
+}
+
+static int imximage_verify_header (unsigned char *ptr, int image_size,
+			struct mkimage_params *params)
+{
+
+	struct imx_header *imx_hdr = (struct imx_header *) ptr;
+	flash_header_t *hdr = &imx_hdr->fhdr;
+
+	/* Only a few checks can be done: search for magic numbers */
+	if (hdr->app_code_barker != APP_CODE_BARKER)
+		return -FDT_ERR_BADSTRUCTURE;
+
+	if (imx_hdr->dcd_table.preamble.barker != DCD_BARKER)
+		return -FDT_ERR_BADSTRUCTURE;
+
+	return 0;
+}
+
+static void imximage_print_header (const void *ptr)

tools/imximage.c line 106

Quoted 10 lines
tools/imximage.c new file +10 -0
+{
+	struct imx_header *imx_hdr = (struct imx_header *) ptr;
+	flash_header_t *hdr = &imx_hdr->fhdr;
+	uint32_t size;
+	flash_cfg_parms_t *ext_header;
+
+	size = imx_hdr->dcd_table.preamble.length;
+	if (size > (MAX_HW_CFG_SIZE * sizeof(dcd_type_addr_data_t))) {
+		printf ("Image corrupt: DCD size %d exceed maximum %d\n",
+			size / sizeof(dcd_type_addr_data_t), MAX_HW_CFG_SIZE);

stderr

Quoted 17 lines
tools/imximage.c new file +17 -0
+		exit (EXIT_FAILURE);
+	}
+
+	ext_header = (flash_cfg_parms_t *) ((uint32_t)&imx_hdr->dcd_table + sizeof (dcd_preamble_t) +
+		size);
+
+	printf ("Image Type:   Freescale IMX Boot Image\n");
+	printf ("Data Size:    ");
+	genimg_print_size (ext_header->length);
+	printf ("Load Address: %08x\n", (unsigned int)hdr->app_dest_ptr);
+	printf ("Entry Point:  %08x\n", (unsigned int)hdr->app_code_jump_vector);
+}
+
+static uint32_t imximage_parse_cfg_file (struct imx_header *imxhdr, char* name)
+{
+	FILE *fd = NULL;
+	char *line = NULL;

tools/imximage.c line 133

Quoted 10 lines
tools/imximage.c new file +10 -0
+	char * token, *saveptr1, *saveptr2;
+	int lineno = 0;
+	int fld, value;
+	uint32_t len;
+	int dcd_len = 0;
+	dcd_t *dcd = &imxhdr->dcd_table;
+	int32_t cmd;
+
+	if ((fd = fopen (name, "r")) == 0) {
+		printf ("Error:%s - Can't open DCD file\n", name);

stderr and a missing space

Quoted 120 lines
tools/imximage.c new file +120 -0
+		exit (EXIT_FAILURE);
+	}
+
+	/* Very simple parsing, line starting with # are comments and are dropped */
+	while ((getline (&line, &len, fd)) > 0) {
+		lineno++;
+
+		token = strtok_r (line, "\r\n", &saveptr1);
+		if (token == NULL)
+			continue;
+
+		/* Check inside the single line */
+		for (fld = CFG_COMMAND, cmd = CMD_INVALID, line = token; ; line = NULL, fld++) {
+			token = strtok_r (line, " \t", &saveptr2);
+			if (token == NULL)
+				break;
+
+			/* Drop all text starting with '#' as comments */
+			if (token[0] == '#')
+				break;
+
+			/* parse all fields in a single line */
+			switch (fld) {
+			case CFG_COMMAND:
+				cmd = get_table_entry_id (imximage_cmds,
+					"imximage commands", token);
+				if (cmd < 0) {
+					printf ("Error: %s[%d] - Invalid command (%s)\n",
+						name,  lineno, token);
+					exit (EXIT_FAILURE);
+				}
+				break;
+			case CFG_REG_SIZE:
+				switch (cmd) {
+				case CMD_BOOT_FROM:
+					/* Get flash header offset */
+					imxhdr->flash_offset = get_table_entry_id (imximage_bootops,
+						"imximage boot option", token);
+					if (imxhdr->flash_offset == -1) {
+						printf ("Error: %s[%d] - Invalid boot device (%s)\n",
+							name,  lineno, token);
+						exit (EXIT_FAILURE);
+					}
+					break;
+				case CMD_DATA:
+					value = get_cfg_value(token, name, lineno);
+
+					/* Byte, halfword, word */
+					if ((value != 1) && (value != 2) && (value != 4)) {
+						printf ("Error:%s[%d] - Invalid register size %d\n",
+							name, lineno, value);
+						exit (EXIT_FAILURE);
+					}
+					dcd->addr_data[dcd_len].type = value;
+					break;
+				}
+
+			case CFG_REG_ADDRESS:
+				if (cmd == CMD_DATA) {
+					dcd->addr_data[dcd_len].addr = get_cfg_value(token, name, lineno);
+				}
+				break;
+			case CFG_REG_VALUE:
+				if (cmd == CMD_DATA) {
+					dcd->addr_data[dcd_len].value = get_cfg_value(token, name, lineno);
+					dcd_len++;
+				}
+				break;
+			}
+		}
+
+		if (dcd_len > MAX_HW_CFG_SIZE) {
+			printf ("Error:%s[%d] - DCD table exceeds maximum size(%d)\n",
+				name, lineno, MAX_HW_CFG_SIZE);
+		}
+	}
+	dcd->preamble.barker = DCD_BARKER;
+	dcd->preamble.length = dcd_len * sizeof(dcd_type_addr_data_t);
+	fclose (fd);
+
+	return dcd->preamble.length;
+}
+
+static void imximage_set_header (void *ptr, struct stat *sbuf, int ifd,
+				struct mkimage_params *params)
+{
+	struct imx_header *hdr = (struct imx_header *)ptr;
+	flash_header_t *fhdr = &hdr->fhdr;
+	int dcd_len;
+	flash_cfg_parms_t *ext_header;
+	uint32_t base_offset;
+
+	/* Set default offset */
+	hdr->flash_offset = FLASH_OFFSET_STANDARD;
+
+	/* Set magic number */
+	fhdr->app_code_barker = APP_CODE_BARKER;
+
+	/* Parse dcd configuration file */
+	dcd_len = imximage_parse_cfg_file (hdr, params->imagename);
+
+	fhdr->app_dest_ptr = params->addr;
+	fhdr->app_dest_ptr = params->ep - hdr->flash_offset - sizeof(struct imx_header);
+	fhdr->app_code_jump_vector = params->ep;
+
+	base_offset = fhdr->app_dest_ptr + hdr->flash_offset ;
+	fhdr->dcd_ptr_ptr = (uint32_t) ((uint32_t)&fhdr->dcd_ptr -
+		(uint32_t)&fhdr->app_code_jump_vector) + base_offset ;
+
+	fhdr->dcd_ptr = base_offset + ((uint32_t)&hdr->dcd_table - (uint32_t)&hdr->fhdr);
+
+	/* The external flash header must be at the end of the DCD table */
+	ext_header = (flash_cfg_parms_t *) ((uint32_t)&hdr->dcd_table + dcd_len +
+		sizeof(dcd_preamble_t));
+	ext_header->length = sbuf->st_size + hdr->flash_offset + sizeof(struct imx_header);
+
+	/* Security feature are not supported */
+	fhdr->app_code_csf = 0;
+	fhdr->super_root_key = NULL;
+

tools/imximage.c line 263

Quoted 10 lines
tools/imximage.c new file +10 -0
+}
+
+int imximage_check_params (struct mkimage_params *params)
+{
+	if (!params)
+		return CFG_INVALID;
+	if (!strlen (params->imagename)) {
+		printf ("Error:%s - Configuration file not specified, "
+			"it is needed for imximage generation\n",
+			params->cmdname);

stderr and missing space

Apart from those nit-picking comments this looks really good, thanks!
Detlev

Signature · 7 lines
Thanks so much for Emacs.  What a wondrous system -- one of the real
seven wonders of the world.  Forced to choose between Emacs and, say,
any pyramid, I'd take Emacs.       -- Robert Boyer
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de