[U-Boot] [PATCH] ARM: imx6: Add DHCOM i.MX6 PDK board support

Marek Vasut marex at denx.de
Mon Oct 9 19:49:34 UTC 2017


On 10/09/2017 09:28 PM, Stefano Babic wrote:
> Hi Marek,

Hi,

clip please ...

[...]

>> +static int setup_dhcom_mac_from_fuse(void)
>> +{
>> +	unsigned char enetaddr[6];
>> +	u32 fuseval[2];
>> +	int ret;
>> +
>> +	ret = eth_env_get_enetaddr("ethaddr", enetaddr);
>> +	if (ret)	/* ethaddr is already set */
>> +		return 0;
>> +
>> +	ret = fuse_read(4, 2, &fuseval[0]);
>> +	if (ret) {
>> +		printf("Error reading the eFUSE0 with MAC address\n");
>> +		return ret;
>> +	}
>> +
>> +	ret = fuse_read(4, 3, &fuseval[1]);
>> +	if (ret) {
>> +		printf("Error reading the eFUSE1 with MAC address\n");
>> +		return ret;
>> +	}
>> +
>> +	enetaddr[0] = fuseval[1] >> 8;
>> +	enetaddr[1] = fuseval[1] >> 0;
>> +	enetaddr[2] = fuseval[0] >> 24;
>> +	enetaddr[3] = fuseval[0] >> 16;
>> +	enetaddr[4] = fuseval[0] >> 8;
>> +	enetaddr[5] = fuseval[0] >> 0;
>> +
> 
> 
> Is the first part different as imx_get_mac_from_fuse() ?  It looks like
> to me that MAC is stored as usually in bank 4, address 2.
> 
> If yes, you can call the function instead reading yourself from fuses.

Cool, that's what I was looking for, thanks.

>> +	if (is_valid_ethaddr(enetaddr)) {
>> +		eth_env_set_enetaddr("ethaddr", enetaddr);
>> +		return 0;
>> +	}
>> +
>> +	ret = i2c_set_bus_num(2);
>> +	if (ret) {
>> +		printf("Error switching I2C bus!\n");
>> +		return ret;
>> +	}
>> +
>> +	ret = i2c_read(EEPROM_I2C_ADDRESS, 0xfa, 0x1, enetaddr, 0x6);
>> +	if (ret) {
>> +		printf("Error reading configuration EEPROM!\n");
>> +		return ret;
>> +	}
>> +
>> +	if (is_valid_ethaddr(enetaddr))
>> +		eth_env_set_enetaddr("ethaddr", enetaddr);
>> +
>> +	return 0;
>> +}
>> +
>> +int board_early_init_f(void)
>> +{
>> +#ifdef CONFIG_USB_EHCI_MX6
>> +	setup_usb();
>> +#endif
>> +
>> +	return 0;
>> +}
>> +
>> +#ifdef CONFIG_MXC_SPI
>> +int board_spi_cs_gpio(unsigned bus, unsigned cs)
>> +{
>> +	if (bus == 0 && cs == 0)
>> +		return IMX_GPIO_NR(2, 30);
>> +	else
>> +		return -1;
>> +}
>> +#endif
>> +
>> +int board_init(void)
>> +{
>> +	struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
>> +
>> +	/* address of boot parameters */
>> +	gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
>> +
>> +	/* Enable eim_slow clocks */
>> +	setbits_le32(&mxc_ccm->CCGR6, 0x1 << MXC_CCM_CCGR6_EMI_SLOW_OFFSET);
>> +
>> +#ifdef CONFIG_SYS_I2C_MXC
>> +	if (is_mx6dq()) {
>> +		setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, &dh6dq_i2c_pad_info0);
>> +		setup_i2c(1, CONFIG_SYS_I2C_SPEED, 0x7f, &dh6dq_i2c_pad_info1);
>> +		setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, &dh6dq_i2c_pad_info2);
>> +	} else {
>> +		setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, &dh6sdl_i2c_pad_info0);
>> +		setup_i2c(1, CONFIG_SYS_I2C_SPEED, 0x7f, &dh6sdl_i2c_pad_info1);
>> +		setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, &dh6sdl_i2c_pad_info2);
>> +	}
>> +#endif
>> +
>> +#ifdef CONFIG_SATA
>> +	setup_sata();
>> +#endif
>> +
>> +	setup_dhcom_mac_from_fuse();
>> +
>> +	return 0;
>> +}
>> +
>> +#ifdef CONFIG_CMD_BMODE
>> +static const struct boot_mode board_boot_modes[] = {
>> +	/* 4 bit bus width */
>> +	{"sd2",	 MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
>> +	{"sd3",	 MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
>> +	/* 8 bit bus width */
>> +	{"emmc", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)},
>> +	{NULL,	 0},
>> +};
>> +#endif
>> +
>> +#define HW_CODE_BIT_0	IMX_GPIO_NR(2, 19)
>> +#define HW_CODE_BIT_1	IMX_GPIO_NR(6, 6)
>> +#define HW_CODE_BIT_2	IMX_GPIO_NR(2, 16)
>> +
>> +static int board_get_hwcode(void)
>> +{
>> +	int hw_code;
>> +
>> +	gpio_direction_input(HW_CODE_BIT_0);
>> +	gpio_direction_input(HW_CODE_BIT_1);
>> +	gpio_direction_input(HW_CODE_BIT_2);
>> +
>> +	/* HW 100 + HW 200 = 00b; HW 300 = 01b */
>> +	hw_code = ((gpio_get_value(HW_CODE_BIT_2) << 2) |
>> +		   (gpio_get_value(HW_CODE_BIT_1) << 1) |
>> +		    gpio_get_value(HW_CODE_BIT_0)) + 2;
>> +
>> +	return hw_code;
>> +}
>> +
>> +int board_late_init(void)
>> +{
>> +	u32 hw_code, cpu_rev;
>> +	char buf[16];
>> +
>> +	cpu_rev = get_cpu_rev();
>> +	hw_code = board_get_hwcode();
>> +
>> +	switch (cpu_rev >> 12) {
> 
> Nitpick: there is a macro for it, get_cpu_type()

Fixed

>> +	case MXC_CPU_MX6SOLO:
>> +		snprintf(buf, sizeof(buf), "imx6s-dhcom%1d", hw_code);
>> +		break;
>> +	case MXC_CPU_MX6DL:
>> +		snprintf(buf, sizeof(buf), "imx6dl-dhcom%1d", hw_code);
>> +		break;
>> +	case MXC_CPU_MX6D:
>> +		snprintf(buf, sizeof(buf), "imx6d-dhcom%1d", hw_code);
>> +		break;
>> +	case MXC_CPU_MX6Q:
>> +		snprintf(buf, sizeof(buf), "imx6q-dhcom%1d", hw_code);
>> +		break;
>> +	default:
>> +		snprintf(buf, sizeof(buf), "UNKNOWN%1d", hw_code);
>> +		break;
>> +	}
>> +
>> +	env_set("dhcom", buf);
>> +
>> +#ifdef CONFIG_CMD_BMODE
>> +	add_board_boot_modes(board_boot_modes);
>> +#endif
>> +	return 0;
>> +}

[...]
-- 
Best regards,
Marek Vasut


More information about the U-Boot mailing list