Skip to contentSkip to conversation

board: atmel: add SAMA5D2 ICP board

PATCH New Eugen.Hristev at microchip.com 2 participants 4 messages Apr 8, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 board: atmel: add SAMA5D2 ICP board

From: Eugen Hristev <[email protected]>

The SAMA5D2 ICP Board features the SAMA5D27 SoC, together with QSPI Flash, Wilc3000 wireless device and EtherCat support.

---
 arch/arm/dts/Makefile                 |   3 +
 arch/arm/dts/at91-sama5d2_icp.dts     | 100 +++++++++++++++++
 arch/arm/mach-at91/Kconfig            |  12 +++
 board/atmel/sama5d2_icp/Kconfig       |  15 +++
 board/atmel/sama5d2_icp/MAINTAINERS   |   7 ++
 board/atmel/sama5d2_icp/Makefile      |   7 ++
 board/atmel/sama5d2_icp/sama5d2_icp.c | 197 ++++++++++++++++++++++++++++++++++
 configs/sama5d2_icp_mmc_defconfig     |  72 +++++++++++++
 include/configs/sama5d2_icp.h         |  70 ++++++++++++
 9 files changed, 483 insertions(+)
 create mode 100644 arch/arm/dts/at91-sama5d2_icp.dts
 create mode 100644 board/atmel/sama5d2_icp/Kconfig
 create mode 100644 board/atmel/sama5d2_icp/MAINTAINERS
 create mode 100644 board/atmel/sama5d2_icp/Makefile
 create mode 100644 board/atmel/sama5d2_icp/sama5d2_icp.c
 create mode 100644 configs/sama5d2_icp_mmc_defconfig
 create mode 100644 include/configs/sama5d2_icp.h
arch/arm/dts/Makefile +3 -0
index 930b7e0..a3bfb11 100644
@@ -643,6 +643,9 @@ dtb-$(CONFIG_TARGET_SAMA5D2_XPLAINED) += \
 dtb-$(CONFIG_TARGET_SAMA5D27_SOM1_EK) += \
 	at91-sama5d27_som1_ek.dtb
 
+dtb-$(CONFIG_TARGET_SAMA5D2_ICP) += \
+	at91-sama5d2_icp.dtb
+
 dtb-$(CONFIG_TARGET_SAMA5D3XEK) += \
 	sama5d31ek.dtb \
 	sama5d33ek.dtb \
arch/arm/dts/at91-sama5d2_icp.dts new file +100 -0

100 lines not on this page · raw message

arch/arm/mach-at91/Kconfig +12 -0
index a089e94..c3b21b7 100644
@@ -180,6 +180,17 @@ config TARGET_SAMA5D27_SOM1_EK
 	  processor-based SAMA5D2 MPU with up to 1 Gbit DDR2-SDRAM
 	  in a single package.
 
+config TARGET_SAMA5D2_ICP
+	bool "SAMA5D2 Industrial Connectivity Platform (ICP)"
+	select CPU_V7A
+	select SUPPORT_SPL
+	select BOARD_EARLY_INIT_F
+	select BOARD_LATE_INIT
+	help
+	  The SAMA5D2 ICP embeds SAMA5D27 rev. C SoC, together with
+	  a 64Mbit QSPI flash, 3xMikrobus connectors, 4xUSB ,
+	  EtherCat and WILC3000 devices on board.
+
 config TARGET_SAMA5D3_XPLAINED
 	bool "SAMA5D3 Xplained board"
 	select BOARD_EARLY_INIT_F
@@ -281,6 +292,7 @@ source "board/atmel/at91sam9x5ek/Kconfig"
 source "board/atmel/sama5d2_ptc_ek/Kconfig"
 source "board/atmel/sama5d2_xplained/Kconfig"
 source "board/atmel/sama5d27_som1_ek/Kconfig"
+source "board/atmel/sama5d2_icp/Kconfig"
 source "board/atmel/sama5d3_xplained/Kconfig"
 source "board/atmel/sama5d3xek/Kconfig"
 source "board/atmel/sama5d4_xplained/Kconfig"
board/atmel/sama5d2_icp/Kconfig new file +15 -0
new file mode 100644
index 0000000..3859845
@@ -0,0 +1,15 @@
+if TARGET_SAMA5D2_ICP
+
+config SYS_BOARD
+	default "sama5d2_icp"
+
+config SYS_VENDOR
+	default "atmel"
+
+config SYS_SOC
+	default "at91"
+
+config SYS_CONFIG_NAME
+	default "sama5d2_icp"
+
+endif
board/atmel/sama5d2_icp/MAINTAINERS new file +7 -0
new file mode 100644
index 0000000..db984b6
@@ -0,0 +1,7 @@
+SAMA5D2 ICP BOARD
+M:     Eugen Hristev <[email protected]>
+S:     Maintained
+F:     board/atmel/sama5d2_icp/
+F:     include/configs/sama5d2_icp.h
+F:     configs/sama5d2_icp_mmc_defconfig
+
board/atmel/sama5d2_icp/Makefile new file +7 -0
new file mode 100644
index 0000000..fd7e870
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier:     GPL-2.0+
+#
+# Copyright (C) 2018 Microchip Technology Inc.
+#                   Eugen Hristev <[email protected]>
+#
+
+obj-y += sama5d2_icp.o
board/atmel/sama5d2_icp/sama5d2_icp.c new file +197 -0

197 lines not on this page · raw message

configs/sama5d2_icp_mmc_defconfig new file +72 -0

72 lines not on this page · raw message

include/configs/sama5d2_icp.h new file +70 -0

70 lines not on this page · raw message

Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 board: atmel: add SAMA5D2 ICP board

Quoted 59 lines · Eugen.Hristev at microchip.com

From: Eugen Hristev <[email protected]>

The SAMA5D2 ICP Board features the SAMA5D27 SoC, together with QSPI Flash, Wilc3000 wireless device and EtherCat support.

---
  arch/arm/dts/Makefile                 |   3 +
  arch/arm/dts/at91-sama5d2_icp.dts     | 100 +++++++++++++++++
  arch/arm/mach-at91/Kconfig            |  12 +++
  board/atmel/sama5d2_icp/Kconfig       |  15 +++
  board/atmel/sama5d2_icp/MAINTAINERS   |   7 ++
  board/atmel/sama5d2_icp/Makefile      |   7 ++
  board/atmel/sama5d2_icp/sama5d2_icp.c | 197 ++++++++++++++++++++++++++++++++++
  configs/sama5d2_icp_mmc_defconfig     |  72 +++++++++++++
  include/configs/sama5d2_icp.h         |  70 ++++++++++++
  9 files changed, 483 insertions(+)

create mode 100644 arch/arm/dts/at91-sama5d2_icp.dts create mode 100644 board/atmel/sama5d2_icp/Kconfig create mode 100644 board/atmel/sama5d2_icp/MAINTAINERS create mode 100644 board/atmel/sama5d2_icp/Makefile create mode 100644 board/atmel/sama5d2_icp/sama5d2_icp.c create mode 100644 configs/sama5d2_icp_mmc_defconfig create mode 100644 include/configs/sama5d2_icp.h

arch/arm/dts/Makefile +3 -0
index 930b7e0..a3bfb11 100644
@@ -643,6 +643,9 @@ dtb-$(CONFIG_TARGET_SAMA5D2_XPLAINED) += \
  dtb-$(CONFIG_TARGET_SAMA5D27_SOM1_EK) += \
  	at91-sama5d27_som1_ek.dtb
 
+dtb-$(CONFIG_TARGET_SAMA5D2_ICP) += \
+	at91-sama5d2_icp.dtb
+
  dtb-$(CONFIG_TARGET_SAMA5D3XEK) += \
  	sama5d31ek.dtb \
  	sama5d33ek.dtb \
arch/arm/dts/at91-sama5d2_icp.dts new file +13 -0
new file mode 100644
index 0000000..8830b05
@@ -0,0 +1,100 @@
+// SPDX-License-Identifier: GPL-2.0+ OR X11
+/*
+ * at91-sama5d2_icp.dts - Device Tree file for SAMA5D2 ICP board
+ *			SAMA5D2 Industrial Connectivity Board
+ *
+ *  Copyright (c) 2018, Microchip Technology Inc.
+ *                2018, Eugen Hristev <[email protected]>
+ */
+/dts-v1/;
+#include "sama5d2.dtsi"
+#include "sama5d2-pinfunc.h"
+
+/ {

arch/arm/dts/at91-sama5d2_icp.dts line 23

Quoted 10 lines
arch/arm/dts/at91-sama5d2_icp.dts new file +10 -0
+	model = "Microchip SAMA5D2 ICP";
+	compatible = "atmel,sama5d2-icp", "atmel,sama5d27", "atmel,sama5d2", "atmel,sama5";
+
+	aliases {
+		serial0 = &uart0;
+		i2c1	= &i2c1;
+	};
+
+	chosen {
+		u-boot,dm-pre-reloc;

Please move all U-Boot specific DT properties into a separate foo-u-boot.dtsi file. That makes it easier to sync the dts files with the Linux versions.

arch/arm/dts/at91-sama5d2_icp.dts line 34

Quoted 11 lines
arch/arm/dts/at91-sama5d2_icp.dts new file +11 -0
+		stdout-path = "serial0:115200n8";
+	};
+
+	ahb {
+
+		sdmmc0: sdio-host at a0000000 {
+			bus-width = <4>;
+			pinctrl-names = "default";
+			pinctrl-0 = <&pinctrl_sdmmc0_default>;
+			status = "okay";
+			u-boot,dm-pre-reloc;

Here as well.

arch/arm/dts/at91-sama5d2_icp.dts line 41

Quoted 7 lines
arch/arm/dts/at91-sama5d2_icp.dts new file +7 -0
+		};
+
+		apb {
+			uart0: serial at f801c000 { /* mikrobus1 uart */
+				pinctrl-names = "default";
+				pinctrl-0 = <&pinctrl_mikrobus1_uart>;
+				u-boot,dm-pre-reloc;

etc.

Quoted 157 lines
arch/arm/dts/at91-sama5d2_icp.dts new file +59 -0
+				status = "okay";
+			};
+
+			i2c1: i2c at fc028000 {
+				dmas = <0>, <0>;
+				pinctrl-names = "default";
+				pinctrl-0 = <&pinctrl_i2c1_default>;
+				status = "okay";
+
+				eeprom at 50 {
+					compatible = "atmel,24c32";
+					reg = <0x50>;
+					pagesize = <16>;
+				};
+
+				eeprom at 52 {
+					compatible = "atmel,24c32";
+					reg = <0x52>;
+					pagesize = <16>;
+				};
+
+				eeprom at 53 {
+					compatible = "atmel,24c32";
+					reg = <0x53>;
+					pagesize = <16>;
+				};
+			};
+			pioA: gpio at fc038000 {
+				status = "okay";
+				pinctrl {
+					pinctrl_i2c1_default: i2c1_default {
+						pinmux = <PIN_PD19__TWD1>,
+							 <PIN_PD20__TWCK1>;
+						bias-disable;
+					};
+
+					pinctrl_sdmmc0_default: sdmmc0_default {
+						pinmux = <PIN_PA1__SDMMC0_CMD>,
+							 <PIN_PA2__SDMMC0_DAT0>,
+							 <PIN_PA3__SDMMC0_DAT1>,
+							 <PIN_PA4__SDMMC0_DAT2>,
+							 <PIN_PA5__SDMMC0_DAT3>,
+							 <PIN_PA0__SDMMC0_CK>,
+							 <PIN_PA13__SDMMC0_CD>;
+						bias-disable;
+						u-boot,dm-pre-reloc;
+					};
+
+					pinctrl_mikrobus1_uart: mikrobus1_uart {
+						pinmux = <PIN_PB26__URXD0>,
+							 <PIN_PB27__UTXD0>;
+						bias-disable;
+						u-boot,dm-pre-reloc;
+					};
+				};
+			};
+		};
+	};
+};
arch/arm/mach-at91/Kconfig +12 -0
index a089e94..c3b21b7 100644
@@ -180,6 +180,17 @@ config TARGET_SAMA5D27_SOM1_EK
  	  processor-based SAMA5D2 MPU with up to 1 Gbit DDR2-SDRAM
  	  in a single package.
 
+config TARGET_SAMA5D2_ICP
+	bool "SAMA5D2 Industrial Connectivity Platform (ICP)"
+	select CPU_V7A
+	select SUPPORT_SPL
+	select BOARD_EARLY_INIT_F
+	select BOARD_LATE_INIT
+	help
+	  The SAMA5D2 ICP embeds SAMA5D27 rev. C SoC, together with
+	  a 64Mbit QSPI flash, 3xMikrobus connectors, 4xUSB ,
+	  EtherCat and WILC3000 devices on board.
+
  config TARGET_SAMA5D3_XPLAINED
  	bool "SAMA5D3 Xplained board"
  	select BOARD_EARLY_INIT_F
@@ -281,6 +292,7 @@ source "board/atmel/at91sam9x5ek/Kconfig"
  source "board/atmel/sama5d2_ptc_ek/Kconfig"
  source "board/atmel/sama5d2_xplained/Kconfig"
  source "board/atmel/sama5d27_som1_ek/Kconfig"
+source "board/atmel/sama5d2_icp/Kconfig"
  source "board/atmel/sama5d3_xplained/Kconfig"
  source "board/atmel/sama5d3xek/Kconfig"
  source "board/atmel/sama5d4_xplained/Kconfig"
board/atmel/sama5d2_icp/Kconfig new file +15 -0
new file mode 100644
index 0000000..3859845
@@ -0,0 +1,15 @@
+if TARGET_SAMA5D2_ICP
+
+config SYS_BOARD
+	default "sama5d2_icp"
+
+config SYS_VENDOR
+	default "atmel"
+
+config SYS_SOC
+	default "at91"
+
+config SYS_CONFIG_NAME
+	default "sama5d2_icp"
+
+endif
board/atmel/sama5d2_icp/MAINTAINERS new file +7 -0
new file mode 100644
index 0000000..db984b6
@@ -0,0 +1,7 @@
+SAMA5D2 ICP BOARD
+M:     Eugen Hristev <[email protected]>
+S:     Maintained
+F:     board/atmel/sama5d2_icp/
+F:     include/configs/sama5d2_icp.h
+F:     configs/sama5d2_icp_mmc_defconfig
+
board/atmel/sama5d2_icp/Makefile new file +7 -0
new file mode 100644
index 0000000..fd7e870
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier:     GPL-2.0+
+#
+# Copyright (C) 2018 Microchip Technology Inc.
+#                   Eugen Hristev <[email protected]>
+#
+
+obj-y += sama5d2_icp.o
board/atmel/sama5d2_icp/sama5d2_icp.c new file +15 -0
new file mode 100644
index 0000000..667d14c
@@ -0,0 +1,197 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018 Microchip Technology, Inc.
+ *		      Eugen Hristev <[email protected]>
+ */
+
+#include <common.h>
+#include <debug_uart.h>
+#include <asm/io.h>
+#include <asm/arch/at91_common.h>
+#include <asm/arch/atmel_pio4.h>
+#include <asm/arch/atmel_mpddrc.h>
+#include <asm/arch/atmel_sdhci.h>
+#include <asm/arch/clk.h>
+#include <asm/arch/gpio.h>

board/atmel/sama5d2_icp/sama5d2_icp.c line 25

Quoted 10 lines
board/atmel/sama5d2_icp/sama5d2_icp.c new file +10 -0
+#include <asm/arch/sama5d2.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#ifdef CONFIG_BOARD_LATE_INIT
+int board_late_init(void)
+{
+	return 0;
+}
+#endif

You have selected BOARD_LATE_INIT for this board. So no need for these ifdef's here.

Quoted 15 lines
board/atmel/sama5d2_icp/sama5d2_icp.c new file +15 -0
+
+#ifdef CONFIG_DEBUG_UART_BOARD_INIT
+static void board_uart0_hw_init(void)
+{
+	atmel_pio4_set_c_periph(AT91_PIO_PORTB, 26, ATMEL_PIO_PUEN_MASK); /* URXD0 */
+	atmel_pio4_set_c_periph(AT91_PIO_PORTB, 27, 0);	/* UTXD0 */
+
+	at91_periph_clk_enable(ATMEL_ID_UART0);
+}
+
+void board_debug_uart_init(void)
+{
+	board_uart0_hw_init();
+}
+#endif

board/atmel/sama5d2_icp/sama5d2_icp.c line 50

Quoted 10 lines
board/atmel/sama5d2_icp/sama5d2_icp.c new file +10 -0
+
+#ifdef CONFIG_BOARD_EARLY_INIT_F
+int board_early_init_f(void)
+{
+#ifdef CONFIG_DEBUG_UART
+	debug_uart_init();
+#endif
+	return 0;
+}
+#endif

Same for BOARD_EARLY_INIT_F.

BTW: Do you really need to enable DEBUG_UART for all the at91 platforms in the defconfig?

Quoted 17 lines
board/atmel/sama5d2_icp/sama5d2_icp.c new file +17 -0
+
+int board_init(void)
+{
+	/* address of boot parameters */
+	gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
+
+	return 0;
+}
+
+int dram_init(void)
+{
+	gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
+				    CONFIG_SYS_SDRAM_SIZE);
+	return 0;
+}
+
+#define MAC24AA_MAC_OFFSET	0xfa

board/atmel/sama5d2_icp/sama5d2_icp.c line 77

Quoted 10 lines
board/atmel/sama5d2_icp/sama5d2_icp.c new file +10 -0
+
+#ifdef CONFIG_MISC_INIT_R
+int misc_init_r(void)
+{
+#ifdef CONFIG_I2C_EEPROM
+	at91_set_ethaddr(MAC24AA_MAC_OFFSET);
+#endif
+	return 0;
+}
+#endif

I would also remove these #ifdef's above to make the code less ugly.

Quoted 131 lines
board/atmel/sama5d2_icp/sama5d2_icp.c new file +120 -0
+
+/* SPL */
+#ifdef CONFIG_SPL_BUILD
+
+#ifdef CONFIG_SD_BOOT
+void spl_mmc_init(void)
+{
+	atmel_pio4_set_a_periph(AT91_PIO_PORTA, 1, 0);	/* CMD */
+	atmel_pio4_set_a_periph(AT91_PIO_PORTA, 2, 0);	/* DAT0 */
+	atmel_pio4_set_a_periph(AT91_PIO_PORTA, 3, 0);	/* DAT1 */
+	atmel_pio4_set_a_periph(AT91_PIO_PORTA, 4, 0);	/* DAT2 */
+	atmel_pio4_set_a_periph(AT91_PIO_PORTA, 5, 0);	/* DAT3 */
+	atmel_pio4_set_a_periph(AT91_PIO_PORTA, 0, 0);	/* CK */
+	atmel_pio4_set_a_periph(AT91_PIO_PORTA, 13, 0);	/* CD */
+
+	at91_periph_clk_enable(ATMEL_ID_SDMMC0);
+}
+#endif
+
+void spl_board_init(void)
+{
+#ifdef CONFIG_SD_BOOT
+	spl_mmc_init();
+#endif
+}
+
+void spl_display_print(void)
+{
+}
+
+static void ddrc_conf(struct atmel_mpddrc_config *ddrc)
+{
+	ddrc->md = (ATMEL_MPDDRC_MD_DBW_32_BITS | ATMEL_MPDDRC_MD_DDR3_SDRAM);
+
+	ddrc->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
+		    ATMEL_MPDDRC_CR_NR_ROW_14 |
+		    ATMEL_MPDDRC_CR_CAS_DDR_CAS5 |
+		    ATMEL_MPDDRC_CR_DIC_DS |
+		    ATMEL_MPDDRC_CR_NB_8BANKS |
+		    ATMEL_MPDDRC_CR_DECOD_INTERLEAVED |
+		    ATMEL_MPDDRC_CR_UNAL_SUPPORTED);
+
+	ddrc->rtr = 0x298;
+
+	ddrc->tpr0 = ((6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET) |
+		      (3 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET) |
+		      (3 << ATMEL_MPDDRC_TPR0_TWR_OFFSET) |
+		      (9 << ATMEL_MPDDRC_TPR0_TRC_OFFSET) |
+		      (3 << ATMEL_MPDDRC_TPR0_TRP_OFFSET) |
+		      (4 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET) |
+		      (4 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET) |
+		      (4 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET));
+
+	ddrc->tpr1 = ((27 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET) |
+		      (29 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET) |
+		      (0 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET) |
+		      (10 << ATMEL_MPDDRC_TPR1_TXP_OFFSET));
+
+	ddrc->tpr2 = ((0 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET) |
+		      (0 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET) |
+		      (0 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET) |
+		      (4 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET) |
+		      (7 << ATMEL_MPDDRC_TPR2_TFAW_OFFSET));
+}
+
+void mem_init(void)
+{
+	struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
+	struct atmel_mpddr *mpddrc = (struct atmel_mpddr *)ATMEL_BASE_MPDDRC;
+	struct atmel_mpddrc_config ddrc_config;
+	u32 reg;
+
+	ddrc_conf(&ddrc_config);
+
+	at91_periph_clk_enable(ATMEL_ID_MPDDRC);
+	writel(AT91_PMC_DDR, &pmc->scer);
+
+	reg = readl(&mpddrc->io_calibr);
+	reg &= ~ATMEL_MPDDRC_IO_CALIBR_RDIV;
+	reg |= ATMEL_MPDDRC_IO_CALIBR_DDR3_RZQ_55;
+	reg &= ~ATMEL_MPDDRC_IO_CALIBR_TZQIO;
+	reg |= ATMEL_MPDDRC_IO_CALIBR_TZQIO_(100);
+	writel(reg, &mpddrc->io_calibr);
+
+	writel(ATMEL_MPDDRC_RD_DATA_PATH_SHIFT_ONE_CYCLE,
+	       &mpddrc->rd_data_path);
+
+	ddr3_init(ATMEL_BASE_MPDDRC, ATMEL_BASE_DDRCS, &ddrc_config);
+
+	writel(0x5355, &mpddrc->cal_mr4);
+	writel(64, &mpddrc->tim_cal);
+}
+
+void at91_pmc_init(void)
+{
+	u32 tmp;
+
+	/*
+	 * while coming from the ROM code, we run on PLLA @ 492 MHz / 164 MHz
+	 * so we need to slow down and configure MCKR accordingly.
+	 * This is why we have a special flavor of the switching function.
+	 */
+	tmp = AT91_PMC_MCKR_PLLADIV_2 |
+	      AT91_PMC_MCKR_MDIV_3 |
+	      AT91_PMC_MCKR_CSS_MAIN;
+	at91_mck_init_down(tmp);
+
+	tmp = AT91_PMC_PLLAR_29 |
+	      AT91_PMC_PLLXR_PLLCOUNT(0x3f) |
+	      AT91_PMC_PLLXR_MUL(82) |
+	      AT91_PMC_PLLXR_DIV(1);
+	at91_plla_init(tmp);
+
+	tmp = AT91_PMC_MCKR_H32MXDIV |
+	      AT91_PMC_MCKR_PLLADIV_2 |
+	      AT91_PMC_MCKR_MDIV_3 |
+	      AT91_PMC_MCKR_CSS_PLLA;
+	at91_mck_init(tmp);
+}
+#endif
configs/sama5d2_icp_mmc_defconfig new file +5 -0
new file mode 100644
index 0000000..8d609ca
@@ -0,0 +1,72 @@
+CONFIG_ARM=y
+CONFIG_ARCH_AT91=y
+CONFIG_SYS_TEXT_BASE=0x26f00000
+CONFIG_TARGET_SAMA5D2_ICP=y
+CONFIG_SPL_GPIO_SUPPORT=y

configs/sama5d2_icp_mmc_defconfig line 15

Quoted 10 lines
configs/sama5d2_icp_mmc_defconfig new file +10 -0
+CONFIG_SPL_LIBCOMMON_SUPPORT=y
+CONFIG_SPL_LIBGENERIC_SUPPORT=y
+CONFIG_SYS_MALLOC_F_LEN=0x2000
+CONFIG_SPL_MMC_SUPPORT=y
+CONFIG_SPL_SERIAL_SUPPORT=y
+CONFIG_SPL_DRIVERS_MISC_SUPPORT=y
+CONFIG_SPL=y
+CONFIG_DEBUG_UART_BOARD_INIT=y
+CONFIG_DEBUG_UART_BASE=0xf801c000
+CONFIG_DEBUG_UART_CLOCK=83000000

See above. Do you really need DEBUG_UART in the default defconfig?

Quoted 124 lines
configs/sama5d2_icp_mmc_defconfig new file +57 -0
+CONFIG_SPL_FAT_SUPPORT=y
+CONFIG_SPL_LIBDISK_SUPPORT=y
+CONFIG_DEFAULT_DEVICE_TREE="at91-sama5d2_icp"
+CONFIG_DEBUG_UART=y
+CONFIG_ENV_VARS_UBOOT_CONFIG=y
+CONFIG_FIT=y
+CONFIG_SYS_EXTRA_OPTIONS="SAMA5D2"
+CONFIG_SD_BOOT=y
+CONFIG_BOOTDELAY=3
+CONFIG_USE_BOOTARGS=y
+# CONFIG_DISPLAY_BOARDINFO is not set
+CONFIG_SPL_SEPARATE_BSS=y
+CONFIG_SPL_DISPLAY_PRINT=y
+# CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR is not set
+CONFIG_SPL_RAM_SUPPORT=y
+CONFIG_HUSH_PARSER=y
+CONFIG_CMD_BOOTZ=y
+# CONFIG_CMD_IMI is not set
+# CONFIG_CMD_FLASH is not set
+CONFIG_CMD_I2C=y
+# CONFIG_CMD_LOADS is not set
+CONFIG_CMD_MMC=y
+CONFIG_CMD_DHCP=y
+CONFIG_CMD_PING=y
+CONFIG_CMD_EXT4=y
+CONFIG_CMD_FAT=y
+CONFIG_OF_CONTROL=y
+CONFIG_SPL_OF_CONTROL=y
+CONFIG_OF_SPL_REMOVE_PROPS="interrupts interrupt-parent dmas dma-names"
+CONFIG_ENV_IS_IN_FAT=y
+CONFIG_DM=y
+CONFIG_SPL_DM=y
+CONFIG_SPL_DM_SEQ_ALIAS=y
+CONFIG_CLK=y
+CONFIG_SPL_CLK=y
+CONFIG_CLK_AT91=y
+CONFIG_AT91_UTMI=y
+CONFIG_AT91_H32MX=y
+CONFIG_AT91_GENERIC_CLK=y
+CONFIG_DM_GPIO=y
+CONFIG_ATMEL_PIO4=y
+CONFIG_DM_I2C=y
+CONFIG_SYS_I2C_AT91=y
+CONFIG_I2C_EEPROM=y
+CONFIG_DM_MMC=y
+CONFIG_MMC_SDHCI=y
+CONFIG_MMC_SDHCI_ATMEL=y
+CONFIG_PINCTRL=y
+CONFIG_SPL_PINCTRL=y
+CONFIG_PINCTRL_AT91PIO4=y
+CONFIG_DM_SERIAL=y
+CONFIG_DEBUG_UART_ATMEL=y
+CONFIG_DEBUG_UART_ANNOUNCE=y
+CONFIG_ATMEL_USART=y
+CONFIG_TIMER=y
+CONFIG_SPL_TIMER=y
+CONFIG_ATMEL_PIT_TIMER=y
include/configs/sama5d2_icp.h new file +60 -0
new file mode 100644
index 0000000..f947a3c
@@ -0,0 +1,70 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Configuration file for the SAMA5D2 ICP Board.
+ *
+ * Copyright (C) 2018 Microchip Corporation
+ *		      Eugen Hristev <[email protected]>
+ */
+
+#ifndef __CONFIG_H
+#define __CONFIG_H
+
+#include "at91-sama5_common.h"
+
+#undef CONFIG_SYS_AT91_MAIN_CLOCK
+#define CONFIG_SYS_AT91_MAIN_CLOCK      12000000 /* from 12 MHz crystal */
+
+#define CONFIG_MISC_INIT_R
+
+/* SDRAM */
+#define CONFIG_NR_DRAM_BANKS		1
+#define CONFIG_SYS_SDRAM_BASE		0x20000000
+#define CONFIG_SYS_SDRAM_SIZE		0x20000000
+
+#ifdef CONFIG_SPL_BUILD
+#define CONFIG_SYS_INIT_SP_ADDR		0x218000
+#else
+#define CONFIG_SYS_INIT_SP_ADDR \
+	(CONFIG_SYS_SDRAM_BASE + 16 * 1024 - GENERATED_GBL_DATA_SIZE)
+#endif
+
+#define CONFIG_SYS_LOAD_ADDR		0x22000000 /* load address */
+
+/* NAND flash */
+#undef CONFIG_CMD_NAND
+
+/* SPI flash */
+#define CONFIG_SF_DEFAULT_SPEED		66000000
+
+#undef CONFIG_BOOTCOMMAND
+#ifdef CONFIG_SD_BOOT
+/* u-boot env in sd/mmc card */
+#define FAT_ENV_INTERFACE	"mmc"
+#define FAT_ENV_DEVICE_AND_PART	"0"
+#define FAT_ENV_FILE		"uboot.env"
+#define CONFIG_ENV_SIZE		0x4000
+/* bootstrap + u-boot + env in sd card */
+#define CONFIG_BOOTCOMMAND	"fatload mmc 0:1 0x21000000 at91-sama5d2_icp.dtb; " \
+				"fatload mmc 0:1 0x22000000 zImage; " \
+				"bootz 0x22000000 - 0x21000000"
+#undef CONFIG_BOOTARGS
+#define CONFIG_BOOTARGS \
+	"console=ttyS0,115200 earlyprintk root=/dev/mmcblk0p2 rw rootwait"
+#endif
+
+/* SPL */
+#define CONFIG_SPL_TEXT_BASE		0x200000
+#define CONFIG_SPL_MAX_SIZE		0x10000
+#define CONFIG_SPL_BSS_START_ADDR	0x20000000
+#define CONFIG_SPL_BSS_MAX_SIZE		0x80000
+#define CONFIG_SYS_SPL_MALLOC_START	0x20080000

include/configs/sama5d2_icp.h line 70

Quoted 10 lines
include/configs/sama5d2_icp.h new file +10 -0
+#define CONFIG_SYS_SPL_MALLOC_SIZE	0x80000
+
+#define CONFIG_SYS_MONITOR_LEN		(512 << 10)
+
+#ifdef CONFIG_SD_BOOT
+#define CONFIG_SYS_MMCSD_FS_BOOT_PARTITION	1
+#define CONFIG_SPL_FS_LOAD_PAYLOAD_NAME		"u-boot.img"
+#endif
+
+#endif

Thanks,
Stefan

#2 lore raw

PATCH 1/1 board: atmel: add SAMA5D2 ICP board

Hi Stefan,

Thanks for reviewing,

Quoted 69 lines · Stefan Roese
Quoted 67 lines · Eugen.Hristev at microchip.com

From: Eugen Hristev <[email protected]>

The SAMA5D2 ICP Board features the SAMA5D27 SoC, together with QSPI Flash, Wilc3000 wireless device and EtherCat support.

---
  arch/arm/dts/Makefile                 |   3 + arch/arm/dts/at91-sama5d2_icp.dts     | 100 +++++++++++++++++ arch/arm/mach-at91/Kconfig            |  12 +++ board/atmel/sama5d2_icp/Kconfig       |  15 +++ board/atmel/sama5d2_icp/MAINTAINERS   |   7 ++ board/atmel/sama5d2_icp/Makefile      |   7 ++ board/atmel/sama5d2_icp/sama5d2_icp.c | 197
++++++++++++++++++++++++++++++++++
  configs/sama5d2_icp_mmc_defconfig     |  72 +++++++++++++ include/configs/sama5d2_icp.h         |  70 ++++++++++++

  9 files changed, 483 insertions(+)

  create mode 100644 arch/arm/dts/at91-sama5d2_icp.dts create mode 100644 board/atmel/sama5d2_icp/Kconfig create mode 100644 board/atmel/sama5d2_icp/MAINTAINERS create mode 100644 board/atmel/sama5d2_icp/Makefile create mode 100644 board/atmel/sama5d2_icp/sama5d2_icp.c create mode 100644 configs/sama5d2_icp_mmc_defconfig create mode 100644 include/configs/sama5d2_icp.h

arch/arm/dts/Makefile +0 -0
index 930b7e0..a3bfb11 100644
@@ -643,6 +643,9 @@ dtb-$(CONFIG_TARGET_SAMA5D2_XPLAINED) += \
   dtb-$(CONFIG_TARGET_SAMA5D27_SOM1_EK) += \

      at91-sama5d27_som1_ek.dtb

arch/arm/dts/Makefile +3 -0
+dtb-$(CONFIG_TARGET_SAMA5D2_ICP) += \
+    at91-sama5d2_icp.dtb
+

  dtb-$(CONFIG_TARGET_SAMA5D3XEK) += \
      sama5d31ek.dtb \
      sama5d33ek.dtb \

arch/arm/dts/at91-sama5d2_icp.dts new file +15 -0
new file mode 100644
index 0000000..8830b05
@@ -0,0 +1,100 @@
+// SPDX-License-Identifier: GPL-2.0+ OR X11
+/*
+ * at91-sama5d2_icp.dts - Device Tree file for SAMA5D2 ICP board
+ *            SAMA5D2 Industrial Connectivity Board
+ *
+ *  Copyright (c) 2018, Microchip Technology Inc.
+ *                2018, Eugen Hristev <[email protected]>
+ */
+/dts-v1/;
+#include "sama5d2.dtsi"
+#include "sama5d2-pinfunc.h"
+
+/ {
+    model = "Microchip SAMA5D2 ICP";
+    compatible = "atmel,sama5d2-icp", "atmel,sama5d27", 

"atmel,sama5d2", "atmel,sama5";
+
+    aliases {
+        serial0 = &uart0;
+        i2c1    = &i2c1;

Quoted 8 lines
Quoted 4 lines

+    };
+
+    chosen {
+        u-boot,dm-pre-reloc;

Please move all U-Boot specific DT properties into a separate foo-u-boot.dtsi file. That makes it easier to sync the dts files with the Linux versions.

This means that I would have to make a prerequisite patch that modifies the current "sama5d2.dtsi" file ? Since this is the base include which I am using for this board.

Or you mean some kind of small file just for this board that will only add pre-reloc properties ?

Quoted 190 lines

arch/arm/dts/at91-sama5d2_icp.dts line 34

Quoted 12 lines

+        stdout-path = "serial0:115200n8";
+    };

arch/arm/dts/at91-sama5d2_icp.dts new file +9 -0
+
+    ahb {
+
+        sdmmc0: sdio-host at a0000000 {
+            bus-width = <4>;
+            pinctrl-names = "default";
+            pinctrl-0 = <&pinctrl_sdmmc0_default>;
+            status = "okay";
+            u-boot,dm-pre-reloc;

Here as well.

Quoted 7 lines

+        };
+
+        apb {
+            uart0: serial at f801c000 { /* mikrobus1 uart */ +                pinctrl-names = "default";
+                pinctrl-0 = <&pinctrl_mikrobus1_uart>; +                u-boot,dm-pre-reloc;

etc.

Quoted 165 lines

+                status = "okay";
+            };

arch/arm/dts/at91-sama5d2_icp.dts new file +57 -0
+
+            i2c1: i2c at fc028000 {
+                dmas = <0>, <0>;
+                pinctrl-names = "default";
+                pinctrl-0 = <&pinctrl_i2c1_default>;
+                status = "okay";
+
+                eeprom at 50 {
+                    compatible = "atmel,24c32";
+                    reg = <0x50>;
+                    pagesize = <16>;
+                };
+
+                eeprom at 52 {
+                    compatible = "atmel,24c32";
+                    reg = <0x52>;
+                    pagesize = <16>;
+                };
+
+                eeprom at 53 {
+                    compatible = "atmel,24c32";
+                    reg = <0x53>;
+                    pagesize = <16>;
+                };
+            };
+            pioA: gpio at fc038000 {
+                status = "okay";
+                pinctrl {
+                    pinctrl_i2c1_default: i2c1_default {
+                        pinmux = <PIN_PD19__TWD1>,
+                             <PIN_PD20__TWCK1>;
+                        bias-disable;
+                    };
+
+                    pinctrl_sdmmc0_default: sdmmc0_default {
+                        pinmux = <PIN_PA1__SDMMC0_CMD>,
+                             <PIN_PA2__SDMMC0_DAT0>,
+                             <PIN_PA3__SDMMC0_DAT1>,
+                             <PIN_PA4__SDMMC0_DAT2>,
+                             <PIN_PA5__SDMMC0_DAT3>,
+                             <PIN_PA0__SDMMC0_CK>,
+                             <PIN_PA13__SDMMC0_CD>;
+                        bias-disable;
+                        u-boot,dm-pre-reloc;
+                    };
+
+                    pinctrl_mikrobus1_uart: mikrobus1_uart {
+                        pinmux = <PIN_PB26__URXD0>,
+                             <PIN_PB27__UTXD0>;
+                        bias-disable;
+                        u-boot,dm-pre-reloc;
+                    };
+                };
+            };
+        };
+    };
+};
arch/arm/mach-at91/Kconfig +0 -0
index a089e94..c3b21b7 100644
@@ -180,6 +180,17 @@ config TARGET_SAMA5D27_SOM1_EK

        processor-based SAMA5D2 MPU with up to 1 Gbit DDR2-SDRAM in a single package.

arch/arm/mach-at91/Kconfig +11 -0
+config TARGET_SAMA5D2_ICP
+    bool "SAMA5D2 Industrial Connectivity Platform (ICP)"
+    select CPU_V7A
+    select SUPPORT_SPL
+    select BOARD_EARLY_INIT_F
+    select BOARD_LATE_INIT
+    help
+      The SAMA5D2 ICP embeds SAMA5D27 rev. C SoC, together with
+      a 64Mbit QSPI flash, 3xMikrobus connectors, 4xUSB ,
+      EtherCat and WILC3000 devices on board.
+

  config TARGET_SAMA5D3_XPLAINED
      bool "SAMA5D3 Xplained board"
      select BOARD_EARLY_INIT_F

arch/arm/mach-at91/Kconfig +0 -0
@@ -281,6 +292,7 @@ source "board/atmel/at91sam9x5ek/Kconfig"

  source "board/atmel/sama5d2_ptc_ek/Kconfig"
  source "board/atmel/sama5d2_xplained/Kconfig"
  source "board/atmel/sama5d27_som1_ek/Kconfig"
+source "board/atmel/sama5d2_icp/Kconfig"
  source "board/atmel/sama5d3_xplained/Kconfig"
  source "board/atmel/sama5d3xek/Kconfig"
  source "board/atmel/sama5d4_xplained/Kconfig"

board/atmel/sama5d2_icp/Kconfig new file +15 -0
new file mode 100644
index 0000000..3859845
@@ -0,0 +1,15 @@
+if TARGET_SAMA5D2_ICP
+
+config SYS_BOARD
+    default "sama5d2_icp"
+
+config SYS_VENDOR
+    default "atmel"
+
+config SYS_SOC
+    default "at91"
+
+config SYS_CONFIG_NAME
+    default "sama5d2_icp"
+
+endif
board/atmel/sama5d2_icp/MAINTAINERS new file +7 -0
new file mode 100644
index 0000000..db984b6
@@ -0,0 +1,7 @@
+SAMA5D2 ICP BOARD
+M:     Eugen Hristev <[email protected]>
+S:     Maintained
+F:     board/atmel/sama5d2_icp/
+F:     include/configs/sama5d2_icp.h
+F:     configs/sama5d2_icp_mmc_defconfig
+
board/atmel/sama5d2_icp/Makefile new file +7 -0
new file mode 100644
index 0000000..fd7e870
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier:     GPL-2.0+
+#
+# Copyright (C) 2018 Microchip Technology Inc.
+#                   Eugen Hristev <[email protected]>
+#
+
+obj-y += sama5d2_icp.o
board/atmel/sama5d2_icp/sama5d2_icp.c new file +20 -0
new file mode 100644
index 0000000..667d14c
@@ -0,0 +1,197 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018 Microchip Technology, Inc.
+ *              Eugen Hristev <[email protected]>
+ */
+
+#include <common.h>
+#include <debug_uart.h>
+#include <asm/io.h>
+#include <asm/arch/at91_common.h>
+#include <asm/arch/atmel_pio4.h>
+#include <asm/arch/atmel_mpddrc.h>
+#include <asm/arch/atmel_sdhci.h>
+#include <asm/arch/clk.h>
+#include <asm/arch/gpio.h>
+#include <asm/arch/sama5d2.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#ifdef CONFIG_BOARD_LATE_INIT
Quoted 9 lines

board/atmel/sama5d2_icp/sama5d2_icp.c line 25

Quoted 5 lines
board/atmel/sama5d2_icp/sama5d2_icp.c new file +5 -0
+int board_late_init(void)
+{
+    return 0;
+}
+#endif

You have selected BOARD_LATE_INIT for this board. So no need for these ifdef's here.

True, but if LATE_INIT is removed, this can stop compiling correctly.

Quoted 29 lines
Quoted 16 lines
board/atmel/sama5d2_icp/sama5d2_icp.c new file +5 -0
+
+#ifdef CONFIG_DEBUG_UART_BOARD_INIT
+static void board_uart0_hw_init(void)
+{
+    atmel_pio4_set_c_periph(AT91_PIO_PORTB, 26, ATMEL_PIO_PUEN_MASK); 

/* URXD0 */
+    atmel_pio4_set_c_periph(AT91_PIO_PORTB, 27, 0);    /* UTXD0 */

board/atmel/sama5d2_icp/sama5d2_icp.c new file +9 -0
+
+    at91_periph_clk_enable(ATMEL_ID_UART0);
+}
+
+void board_debug_uart_init(void)
+{
+    board_uart0_hw_init();
+}
+#endif

board/atmel/sama5d2_icp/sama5d2_icp.c line 50

Quoted 10 lines
board/atmel/sama5d2_icp/sama5d2_icp.c new file +10 -0
+
+#ifdef CONFIG_BOARD_EARLY_INIT_F
+int board_early_init_f(void)
+{
+#ifdef CONFIG_DEBUG_UART
+    debug_uart_init();
+#endif
+    return 0;
+}
+#endif

Same for BOARD_EARLY_INIT_F.

Quoted 2 lines

BTW: Do you really need to enable DEBUG_UART for all the at91 platforms in the defconfig?

These are evaluation kits which people use for various testing, etc. Just showing <debug uart> before the U-boot banner (relocation) is very useful for people having issues with the DM Uart (this early one will work with directly setting the pinout and clk ..., no DTB extract yet) -> it means u-boot starts

Quoted 23 lines
Quoted 23 lines
board/atmel/sama5d2_icp/sama5d2_icp.c new file +22 -0
+
+int board_init(void)
+{
+    /* address of boot parameters */
+    gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
+
+    return 0;
+}
+
+int dram_init(void)
+{
+    gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
+                    CONFIG_SYS_SDRAM_SIZE);
+    return 0;
+}
+
+#define MAC24AA_MAC_OFFSET    0xfa
+
+#ifdef CONFIG_MISC_INIT_R
+int misc_init_r(void)
+{
+#ifdef CONFIG_I2C_EEPROM
Quoted 8 lines

board/atmel/sama5d2_icp/sama5d2_icp.c line 50

Quoted 5 lines

+    at91_set_ethaddr(MAC24AA_MAC_OFFSET);

board/atmel/sama5d2_icp/sama5d2_icp.c new file +4 -0
+#endif
+    return 0;
+}
+#endif

I would also remove these #ifdef's above to make the code less ugly.

It would break the build if the board removes the I2C support... you still think it's better to not use the ifdefs ?

Quoted 289 lines
Quoted 136 lines
board/atmel/sama5d2_icp/sama5d2_icp.c new file +33 -0
+
+/* SPL */
+#ifdef CONFIG_SPL_BUILD
+
+#ifdef CONFIG_SD_BOOT
+void spl_mmc_init(void)
+{
+    atmel_pio4_set_a_periph(AT91_PIO_PORTA, 1, 0);    /* CMD */
+    atmel_pio4_set_a_periph(AT91_PIO_PORTA, 2, 0);    /* DAT0 */
+    atmel_pio4_set_a_periph(AT91_PIO_PORTA, 3, 0);    /* DAT1 */
+    atmel_pio4_set_a_periph(AT91_PIO_PORTA, 4, 0);    /* DAT2 */
+    atmel_pio4_set_a_periph(AT91_PIO_PORTA, 5, 0);    /* DAT3 */
+    atmel_pio4_set_a_periph(AT91_PIO_PORTA, 0, 0);    /* CK */
+    atmel_pio4_set_a_periph(AT91_PIO_PORTA, 13, 0);    /* CD */
+
+    at91_periph_clk_enable(ATMEL_ID_SDMMC0);
+}
+#endif
+
+void spl_board_init(void)
+{
+#ifdef CONFIG_SD_BOOT
+    spl_mmc_init();
+#endif
+}
+
+void spl_display_print(void)
+{
+}
+
+static void ddrc_conf(struct atmel_mpddrc_config *ddrc)
+{
+    ddrc->md = (ATMEL_MPDDRC_MD_DBW_32_BITS | 

ATMEL_MPDDRC_MD_DDR3_SDRAM);

board/atmel/sama5d2_icp/sama5d2_icp.c new file +36 -0
+
+    ddrc->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
+            ATMEL_MPDDRC_CR_NR_ROW_14 |
+            ATMEL_MPDDRC_CR_CAS_DDR_CAS5 |
+            ATMEL_MPDDRC_CR_DIC_DS |
+            ATMEL_MPDDRC_CR_NB_8BANKS |
+            ATMEL_MPDDRC_CR_DECOD_INTERLEAVED |
+            ATMEL_MPDDRC_CR_UNAL_SUPPORTED);
+
+    ddrc->rtr = 0x298;
+
+    ddrc->tpr0 = ((6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET) |
+              (3 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET) |
+              (3 << ATMEL_MPDDRC_TPR0_TWR_OFFSET) |
+              (9 << ATMEL_MPDDRC_TPR0_TRC_OFFSET) |
+              (3 << ATMEL_MPDDRC_TPR0_TRP_OFFSET) |
+              (4 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET) |
+              (4 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET) |
+              (4 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET));
+
+    ddrc->tpr1 = ((27 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET) |
+              (29 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET) |
+              (0 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET) |
+              (10 << ATMEL_MPDDRC_TPR1_TXP_OFFSET));
+
+    ddrc->tpr2 = ((0 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET) |
+              (0 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET) |
+              (0 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET) |
+              (4 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET) |
+              (7 << ATMEL_MPDDRC_TPR2_TFAW_OFFSET));
+}
+
+void mem_init(void)
+{
+    struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
+    struct atmel_mpddr *mpddrc = (struct atmel_mpddr 

*)ATMEL_BASE_MPDDRC;
+    struct atmel_mpddrc_config ddrc_config;
+    u32 reg;

board/atmel/sama5d2_icp/sama5d2_icp.c new file +28 -0
+
+    ddrc_conf(&ddrc_config);
+
+    at91_periph_clk_enable(ATMEL_ID_MPDDRC);
+    writel(AT91_PMC_DDR, &pmc->scer);
+
+    reg = readl(&mpddrc->io_calibr);
+    reg &= ~ATMEL_MPDDRC_IO_CALIBR_RDIV;
+    reg |= ATMEL_MPDDRC_IO_CALIBR_DDR3_RZQ_55;
+    reg &= ~ATMEL_MPDDRC_IO_CALIBR_TZQIO;
+    reg |= ATMEL_MPDDRC_IO_CALIBR_TZQIO_(100);
+    writel(reg, &mpddrc->io_calibr);
+
+    writel(ATMEL_MPDDRC_RD_DATA_PATH_SHIFT_ONE_CYCLE,
+           &mpddrc->rd_data_path);
+
+    ddr3_init(ATMEL_BASE_MPDDRC, ATMEL_BASE_DDRCS, &ddrc_config);
+
+    writel(0x5355, &mpddrc->cal_mr4);
+    writel(64, &mpddrc->tim_cal);
+}
+
+void at91_pmc_init(void)
+{
+    u32 tmp;
+
+    /*
+     * while coming from the ROM code, we run on PLLA @ 492 MHz / 164 

MHz
+     * so we need to slow down and configure MCKR accordingly. +     * This is why we have a special flavor of the switching function. +     */
+    tmp = AT91_PMC_MCKR_PLLADIV_2 |
+          AT91_PMC_MCKR_MDIV_3 |
+          AT91_PMC_MCKR_CSS_MAIN;
+    at91_mck_init_down(tmp);

board/atmel/sama5d2_icp/sama5d2_icp.c new file +14 -0
+
+    tmp = AT91_PMC_PLLAR_29 |
+          AT91_PMC_PLLXR_PLLCOUNT(0x3f) |
+          AT91_PMC_PLLXR_MUL(82) |
+          AT91_PMC_PLLXR_DIV(1);
+    at91_plla_init(tmp);
+
+    tmp = AT91_PMC_MCKR_H32MXDIV |
+          AT91_PMC_MCKR_PLLADIV_2 |
+          AT91_PMC_MCKR_MDIV_3 |
+          AT91_PMC_MCKR_CSS_PLLA;
+    at91_mck_init(tmp);
+}
+#endif
configs/sama5d2_icp_mmc_defconfig new file +5 -0
new file mode 100644
index 0000000..8d609ca
@@ -0,0 +1,72 @@
+CONFIG_ARM=y
+CONFIG_ARCH_AT91=y
+CONFIG_SYS_TEXT_BASE=0x26f00000
+CONFIG_TARGET_SAMA5D2_ICP=y
+CONFIG_SPL_GPIO_SUPPORT=y

configs/sama5d2_icp_mmc_defconfig line 15

Quoted 10 lines
configs/sama5d2_icp_mmc_defconfig new file +10 -0
+CONFIG_SPL_LIBCOMMON_SUPPORT=y
+CONFIG_SPL_LIBGENERIC_SUPPORT=y
+CONFIG_SYS_MALLOC_F_LEN=0x2000
+CONFIG_SPL_MMC_SUPPORT=y
+CONFIG_SPL_SERIAL_SUPPORT=y
+CONFIG_SPL_DRIVERS_MISC_SUPPORT=y
+CONFIG_SPL=y
+CONFIG_DEBUG_UART_BOARD_INIT=y
+CONFIG_DEBUG_UART_BASE=0xf801c000
+CONFIG_DEBUG_UART_CLOCK=83000000

See above. Do you really need DEBUG_UART in the default defconfig?

Quoted 127 lines
configs/sama5d2_icp_mmc_defconfig new file +57 -0
+CONFIG_SPL_FAT_SUPPORT=y
+CONFIG_SPL_LIBDISK_SUPPORT=y
+CONFIG_DEFAULT_DEVICE_TREE="at91-sama5d2_icp"
+CONFIG_DEBUG_UART=y
+CONFIG_ENV_VARS_UBOOT_CONFIG=y
+CONFIG_FIT=y
+CONFIG_SYS_EXTRA_OPTIONS="SAMA5D2"
+CONFIG_SD_BOOT=y
+CONFIG_BOOTDELAY=3
+CONFIG_USE_BOOTARGS=y
+# CONFIG_DISPLAY_BOARDINFO is not set
+CONFIG_SPL_SEPARATE_BSS=y
+CONFIG_SPL_DISPLAY_PRINT=y
+# CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR is not set
+CONFIG_SPL_RAM_SUPPORT=y
+CONFIG_HUSH_PARSER=y
+CONFIG_CMD_BOOTZ=y
+# CONFIG_CMD_IMI is not set
+# CONFIG_CMD_FLASH is not set
+CONFIG_CMD_I2C=y
+# CONFIG_CMD_LOADS is not set
+CONFIG_CMD_MMC=y
+CONFIG_CMD_DHCP=y
+CONFIG_CMD_PING=y
+CONFIG_CMD_EXT4=y
+CONFIG_CMD_FAT=y
+CONFIG_OF_CONTROL=y
+CONFIG_SPL_OF_CONTROL=y
+CONFIG_OF_SPL_REMOVE_PROPS="interrupts interrupt-parent dmas dma-names"
+CONFIG_ENV_IS_IN_FAT=y
+CONFIG_DM=y
+CONFIG_SPL_DM=y
+CONFIG_SPL_DM_SEQ_ALIAS=y
+CONFIG_CLK=y
+CONFIG_SPL_CLK=y
+CONFIG_CLK_AT91=y
+CONFIG_AT91_UTMI=y
+CONFIG_AT91_H32MX=y
+CONFIG_AT91_GENERIC_CLK=y
+CONFIG_DM_GPIO=y
+CONFIG_ATMEL_PIO4=y
+CONFIG_DM_I2C=y
+CONFIG_SYS_I2C_AT91=y
+CONFIG_I2C_EEPROM=y
+CONFIG_DM_MMC=y
+CONFIG_MMC_SDHCI=y
+CONFIG_MMC_SDHCI_ATMEL=y
+CONFIG_PINCTRL=y
+CONFIG_SPL_PINCTRL=y
+CONFIG_PINCTRL_AT91PIO4=y
+CONFIG_DM_SERIAL=y
+CONFIG_DEBUG_UART_ATMEL=y
+CONFIG_DEBUG_UART_ANNOUNCE=y
+CONFIG_ATMEL_USART=y
+CONFIG_TIMER=y
+CONFIG_SPL_TIMER=y
+CONFIG_ATMEL_PIT_TIMER=y
include/configs/sama5d2_icp.h new file +15 -0
new file mode 100644
index 0000000..f947a3c
@@ -0,0 +1,70 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Configuration file for the SAMA5D2 ICP Board.
+ *
+ * Copyright (C) 2018 Microchip Corporation
+ *              Eugen Hristev <[email protected]>
+ */
+
+#ifndef __CONFIG_H
+#define __CONFIG_H
+
+#include "at91-sama5_common.h"
+
+#undef CONFIG_SYS_AT91_MAIN_CLOCK
+#define CONFIG_SYS_AT91_MAIN_CLOCK      12000000 /* from 12 MHz 

crystal */

include/configs/sama5d2_icp.h new file +32 -0
+
+#define CONFIG_MISC_INIT_R
+
+/* SDRAM */
+#define CONFIG_NR_DRAM_BANKS        1
+#define CONFIG_SYS_SDRAM_BASE        0x20000000
+#define CONFIG_SYS_SDRAM_SIZE        0x20000000
+
+#ifdef CONFIG_SPL_BUILD
+#define CONFIG_SYS_INIT_SP_ADDR        0x218000
+#else
+#define CONFIG_SYS_INIT_SP_ADDR \
+    (CONFIG_SYS_SDRAM_BASE + 16 * 1024 - GENERATED_GBL_DATA_SIZE)
+#endif
+
+#define CONFIG_SYS_LOAD_ADDR        0x22000000 /* load address */
+
+/* NAND flash */
+#undef CONFIG_CMD_NAND
+
+/* SPI flash */
+#define CONFIG_SF_DEFAULT_SPEED        66000000
+
+#undef CONFIG_BOOTCOMMAND
+#ifdef CONFIG_SD_BOOT
+/* u-boot env in sd/mmc card */
+#define FAT_ENV_INTERFACE    "mmc"
+#define FAT_ENV_DEVICE_AND_PART    "0"
+#define FAT_ENV_FILE        "uboot.env"
+#define CONFIG_ENV_SIZE        0x4000
+/* bootstrap + u-boot + env in sd card */
+#define CONFIG_BOOTCOMMAND    "fatload mmc 0:1 0x21000000 

at91-sama5d2_icp.dtb; " \
+                "fatload mmc 0:1 0x22000000 zImage; " \
+                "bootz 0x22000000 - 0x21000000"

include/configs/sama5d2_icp.h new file +11 -0
+#undef CONFIG_BOOTARGS
+#define CONFIG_BOOTARGS \
+    "console=ttyS0,115200 earlyprintk root=/dev/mmcblk0p2 rw rootwait"
+#endif
+
+/* SPL */
+#define CONFIG_SPL_TEXT_BASE        0x200000
+#define CONFIG_SPL_MAX_SIZE        0x10000
+#define CONFIG_SPL_BSS_START_ADDR    0x20000000
+#define CONFIG_SPL_BSS_MAX_SIZE        0x80000
+#define CONFIG_SYS_SPL_MALLOC_START    0x20080000

include/configs/sama5d2_icp.h line 70

Quoted 10 lines
include/configs/sama5d2_icp.h new file +10 -0
+#define CONFIG_SYS_SPL_MALLOC_SIZE    0x80000
+
+#define CONFIG_SYS_MONITOR_LEN        (512 << 10)
+
+#ifdef CONFIG_SD_BOOT
+#define CONFIG_SYS_MMCSD_FS_BOOT_PARTITION    1
+#define CONFIG_SPL_FS_LOAD_PAYLOAD_NAME        "u-boot.img"
+#endif
+
+#endif

Thanks,
Stefan

#3 lore raw

PATCH 1/1 board: atmel: add SAMA5D2 ICP board

Hi Eugen,

Quoted 86 lines · Eugen.Hristev at microchip.com

Hi Stefan,

Thanks for reviewing,

Quoted 69 lines · Stefan Roese
Quoted 67 lines · Eugen.Hristev at microchip.com

From: Eugen Hristev <[email protected]>

The SAMA5D2 ICP Board features the SAMA5D27 SoC, together with QSPI Flash, Wilc3000 wireless device and EtherCat support.

---
   arch/arm/dts/Makefile                 |   3 +
   arch/arm/dts/at91-sama5d2_icp.dts     | 100 +++++++++++++++++
   arch/arm/mach-at91/Kconfig            |  12 +++
   board/atmel/sama5d2_icp/Kconfig       |  15 +++
   board/atmel/sama5d2_icp/MAINTAINERS   |   7 ++
   board/atmel/sama5d2_icp/Makefile      |   7 ++
   board/atmel/sama5d2_icp/sama5d2_icp.c | 197
++++++++++++++++++++++++++++++++++
   configs/sama5d2_icp_mmc_defconfig     |  72 +++++++++++++
   include/configs/sama5d2_icp.h         |  70 ++++++++++++
   9 files changed, 483 insertions(+)

  create mode 100644 arch/arm/dts/at91-sama5d2_icp.dts create mode 100644 board/atmel/sama5d2_icp/Kconfig create mode 100644 board/atmel/sama5d2_icp/MAINTAINERS create mode 100644 board/atmel/sama5d2_icp/Makefile create mode 100644 board/atmel/sama5d2_icp/sama5d2_icp.c create mode 100644 configs/sama5d2_icp_mmc_defconfig create mode 100644 include/configs/sama5d2_icp.h

arch/arm/dts/Makefile +3 -0
index 930b7e0..a3bfb11 100644
@@ -643,6 +643,9 @@ dtb-$(CONFIG_TARGET_SAMA5D2_XPLAINED) += \
   dtb-$(CONFIG_TARGET_SAMA5D27_SOM1_EK) += \
       at91-sama5d27_som1_ek.dtb
+dtb-$(CONFIG_TARGET_SAMA5D2_ICP) += \
+    at91-sama5d2_icp.dtb
+
   dtb-$(CONFIG_TARGET_SAMA5D3XEK) += \
       sama5d31ek.dtb \
       sama5d33ek.dtb \
arch/arm/dts/at91-sama5d2_icp.dts new file +15 -0
new file mode 100644
index 0000000..8830b05
@@ -0,0 +1,100 @@
+// SPDX-License-Identifier: GPL-2.0+ OR X11
+/*
+ * at91-sama5d2_icp.dts - Device Tree file for SAMA5D2 ICP board
+ *            SAMA5D2 Industrial Connectivity Board
+ *
+ *  Copyright (c) 2018, Microchip Technology Inc.
+ *                2018, Eugen Hristev <[email protected]>
+ */
+/dts-v1/;
+#include "sama5d2.dtsi"
+#include "sama5d2-pinfunc.h"
+
+/ {
+    model = "Microchip SAMA5D2 ICP";
+    compatible = "atmel,sama5d2-icp", "atmel,sama5d27",

"atmel,sama5d2", "atmel,sama5";
+
+    aliases {
+        serial0 = &uart0;
+        i2c1    = &i2c1;

Quoted 8 lines
Quoted 4 lines

+    };
+
+    chosen {
+        u-boot,dm-pre-reloc;

Please move all U-Boot specific DT properties into a separate foo-u-boot.dtsi file. That makes it easier to sync the dts files with the Linux versions.

Quoted 2 lines

This means that I would have to make a prerequisite patch that modifies the current "sama5d2.dtsi" file ?

If this file also has some U-Boot properties, then those should be moved to a separate file as well (please see my answer below).

Quoted 5 lines

Since this is the base include which I
am using for this board.

Or you mean some kind of small file just for this board that will only add pre-reloc properties ?

Yes. Just add the file "at91-sama5d2_icp-u-boot.dtsi" with the U-Boot specific properties and it will get included automatically by the build system (no need to manually include it). Take a look at this file for example:

arch/arm/dts/socfpga_cyclone5_socrates-u-boot.dtsi

Quoted 200 lines
Quoted 191 lines

arch/arm/dts/at91-sama5d2_icp.dts line 34

Quoted 13 lines

+        stdout-path = "serial0:115200n8";
+    };

arch/arm/dts/at91-sama5d2_icp.dts new file +9 -0
+
+    ahb {
+
+        sdmmc0: sdio-host at a0000000 {
+            bus-width = <4>;
+            pinctrl-names = "default";
+            pinctrl-0 = <&pinctrl_sdmmc0_default>;
+            status = "okay";
+            u-boot,dm-pre-reloc;

Here as well.

Quoted 7 lines

+        };
+
+        apb {
+            uart0: serial at f801c000 { /* mikrobus1 uart */ +                pinctrl-names = "default";
+                pinctrl-0 = <&pinctrl_mikrobus1_uart>; +                u-boot,dm-pre-reloc;

etc.

Quoted 165 lines

+                status = "okay";
+            };

arch/arm/dts/at91-sama5d2_icp.dts new file +57 -0
+
+            i2c1: i2c at fc028000 {
+                dmas = <0>, <0>;
+                pinctrl-names = "default";
+                pinctrl-0 = <&pinctrl_i2c1_default>;
+                status = "okay";
+
+                eeprom at 50 {
+                    compatible = "atmel,24c32";
+                    reg = <0x50>;
+                    pagesize = <16>;
+                };
+
+                eeprom at 52 {
+                    compatible = "atmel,24c32";
+                    reg = <0x52>;
+                    pagesize = <16>;
+                };
+
+                eeprom at 53 {
+                    compatible = "atmel,24c32";
+                    reg = <0x53>;
+                    pagesize = <16>;
+                };
+            };
+            pioA: gpio at fc038000 {
+                status = "okay";
+                pinctrl {
+                    pinctrl_i2c1_default: i2c1_default {
+                        pinmux = <PIN_PD19__TWD1>,
+                             <PIN_PD20__TWCK1>;
+                        bias-disable;
+                    };
+
+                    pinctrl_sdmmc0_default: sdmmc0_default {
+                        pinmux = <PIN_PA1__SDMMC0_CMD>,
+                             <PIN_PA2__SDMMC0_DAT0>,
+                             <PIN_PA3__SDMMC0_DAT1>,
+                             <PIN_PA4__SDMMC0_DAT2>,
+                             <PIN_PA5__SDMMC0_DAT3>,
+                             <PIN_PA0__SDMMC0_CK>,
+                             <PIN_PA13__SDMMC0_CD>;
+                        bias-disable;
+                        u-boot,dm-pre-reloc;
+                    };
+
+                    pinctrl_mikrobus1_uart: mikrobus1_uart {
+                        pinmux = <PIN_PB26__URXD0>,
+                             <PIN_PB27__UTXD0>;
+                        bias-disable;
+                        u-boot,dm-pre-reloc;
+                    };
+                };
+            };
+        };
+    };
+};
arch/arm/mach-at91/Kconfig +12 -0
index a089e94..c3b21b7 100644
@@ -180,6 +180,17 @@ config TARGET_SAMA5D27_SOM1_EK
         processor-based SAMA5D2 MPU with up to 1 Gbit DDR2-SDRAM
         in a single package.
+config TARGET_SAMA5D2_ICP
+    bool "SAMA5D2 Industrial Connectivity Platform (ICP)"
+    select CPU_V7A
+    select SUPPORT_SPL
+    select BOARD_EARLY_INIT_F
+    select BOARD_LATE_INIT
+    help
+      The SAMA5D2 ICP embeds SAMA5D27 rev. C SoC, together with
+      a 64Mbit QSPI flash, 3xMikrobus connectors, 4xUSB ,
+      EtherCat and WILC3000 devices on board.
+
   config TARGET_SAMA5D3_XPLAINED
       bool "SAMA5D3 Xplained board"
       select BOARD_EARLY_INIT_F
@@ -281,6 +292,7 @@ source "board/atmel/at91sam9x5ek/Kconfig"
   source "board/atmel/sama5d2_ptc_ek/Kconfig"
   source "board/atmel/sama5d2_xplained/Kconfig"
   source "board/atmel/sama5d27_som1_ek/Kconfig"
+source "board/atmel/sama5d2_icp/Kconfig"
   source "board/atmel/sama5d3_xplained/Kconfig"
   source "board/atmel/sama5d3xek/Kconfig"
   source "board/atmel/sama5d4_xplained/Kconfig"
board/atmel/sama5d2_icp/Kconfig new file +15 -0
new file mode 100644
index 0000000..3859845
@@ -0,0 +1,15 @@
+if TARGET_SAMA5D2_ICP
+
+config SYS_BOARD
+    default "sama5d2_icp"
+
+config SYS_VENDOR
+    default "atmel"
+
+config SYS_SOC
+    default "at91"
+
+config SYS_CONFIG_NAME
+    default "sama5d2_icp"
+
+endif
board/atmel/sama5d2_icp/MAINTAINERS new file +7 -0
new file mode 100644
index 0000000..db984b6
@@ -0,0 +1,7 @@
+SAMA5D2 ICP BOARD
+M:     Eugen Hristev <[email protected]>
+S:     Maintained
+F:     board/atmel/sama5d2_icp/
+F:     include/configs/sama5d2_icp.h
+F:     configs/sama5d2_icp_mmc_defconfig
+
board/atmel/sama5d2_icp/Makefile new file +7 -0
new file mode 100644
index 0000000..fd7e870
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier:     GPL-2.0+
+#
+# Copyright (C) 2018 Microchip Technology Inc.
+#                   Eugen Hristev <[email protected]>
+#
+
+obj-y += sama5d2_icp.o
board/atmel/sama5d2_icp/sama5d2_icp.c new file +20 -0
new file mode 100644
index 0000000..667d14c
@@ -0,0 +1,197 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018 Microchip Technology, Inc.
+ *              Eugen Hristev <[email protected]>
+ */
+
+#include <common.h>
+#include <debug_uart.h>
+#include <asm/io.h>
+#include <asm/arch/at91_common.h>
+#include <asm/arch/atmel_pio4.h>
+#include <asm/arch/atmel_mpddrc.h>
+#include <asm/arch/atmel_sdhci.h>
+#include <asm/arch/clk.h>
+#include <asm/arch/gpio.h>
+#include <asm/arch/sama5d2.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#ifdef CONFIG_BOARD_LATE_INIT
Quoted 9 lines

board/atmel/sama5d2_icp/sama5d2_icp.c line 25

Quoted 5 lines
board/atmel/sama5d2_icp/sama5d2_icp.c new file +5 -0
+int board_late_init(void)
+{
+    return 0;
+}
+#endif

You have selected BOARD_LATE_INIT for this board. So no need for these ifdef's here.

Quoted 1 line

True, but if LATE_INIT is removed, this can stop compiling correctly.

Then don't remove it. ;)

I would guess that we have tons of board ports that won't compile if the wrong defines are set or unset. My preference is to make the code clean and add only the absolute minimum of #ifdef's.

An exception would be, if the code needs to support multiple board variants, one with the option enabled and one with the option disabled. Then such an #ifdef might make sense. But in the above case, I think it should be removed.

Quoted 29 lines
Quoted 29 lines
Quoted 16 lines
board/atmel/sama5d2_icp/sama5d2_icp.c new file +5 -0
+
+#ifdef CONFIG_DEBUG_UART_BOARD_INIT
+static void board_uart0_hw_init(void)
+{
+    atmel_pio4_set_c_periph(AT91_PIO_PORTB, 26, ATMEL_PIO_PUEN_MASK);

/* URXD0 */
+    atmel_pio4_set_c_periph(AT91_PIO_PORTB, 27, 0);    /* UTXD0 */

board/atmel/sama5d2_icp/sama5d2_icp.c new file +9 -0
+
+    at91_periph_clk_enable(ATMEL_ID_UART0);
+}
+
+void board_debug_uart_init(void)
+{
+    board_uart0_hw_init();
+}
+#endif

board/atmel/sama5d2_icp/sama5d2_icp.c line 50

Quoted 10 lines
board/atmel/sama5d2_icp/sama5d2_icp.c new file +10 -0
+
+#ifdef CONFIG_BOARD_EARLY_INIT_F
+int board_early_init_f(void)
+{
+#ifdef CONFIG_DEBUG_UART
+    debug_uart_init();
+#endif
+    return 0;
+}
+#endif

Same for BOARD_EARLY_INIT_F.

Quoted 8 lines
Quoted 2 lines

BTW: Do you really need to enable DEBUG_UART for all the at91 platforms in the defconfig?

These are evaluation kits which people use for various testing, etc. Just showing <debug uart> before the U-boot banner (relocation) is very useful for people having issues with the DM Uart (this early one will work with directly setting the pinout and clk ..., no DTB extract yet) -> it means u-boot starts

I see. With this explanation this makes perfect sense. Thanks.

Quoted 32 lines
Quoted 23 lines
Quoted 23 lines
board/atmel/sama5d2_icp/sama5d2_icp.c new file +22 -0
+
+int board_init(void)
+{
+    /* address of boot parameters */
+    gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
+
+    return 0;
+}
+
+int dram_init(void)
+{
+    gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
+                    CONFIG_SYS_SDRAM_SIZE);
+    return 0;
+}
+
+#define MAC24AA_MAC_OFFSET    0xfa
+
+#ifdef CONFIG_MISC_INIT_R
+int misc_init_r(void)
+{
+#ifdef CONFIG_I2C_EEPROM
Quoted 8 lines

board/atmel/sama5d2_icp/sama5d2_icp.c line 50

Quoted 5 lines

+    at91_set_ethaddr(MAC24AA_MAC_OFFSET);

board/atmel/sama5d2_icp/sama5d2_icp.c new file +4 -0
+#endif
+    return 0;
+}
+#endif

I would also remove these #ifdef's above to make the code less ugly.

Quoted 2 lines

It would break the build if the board removes the I2C support... you still think it's better to not use the ifdefs ?

Again, please read my thinking about these #ifdef's above. I would vote to remove them if there is no board configuration that needs to run without those defines.

Thanks,
Stefan