/*
 * Copyright (C) 2016 Gianluca Renzi, Eurek Elettronica S.R.L.
 * Copyright (C) 2014 Raphaël Poggi
 * Copyright (C) 2012 Steffen Trumtrar, Pengutronix
 *
 * based on arch/arm/boards/freescale-mx6-arm2/board.c
 *
 * 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.
 */

#include <common.h>
#include <init.h>
#include <environment.h>
#include <mach/imx6-regs.h>
#include <fec.h>
#include <gpio.h>
#include <mach/bbu.h>
#include <asm/armlinux.h>
#include <generated/mach-types.h>
#include <partition.h>
#include <linux/phy.h>
#include <asm/io.h>
#include <asm/mmu.h>
#include <mach/generic.h>
#include <linux/sizes.h>
#include <net.h>
#include <linux/micrel_phy.h>
#include <mach/imx6.h>
#include <mach/devices-imx6.h>
#include <mach/iomux-mx6.h>
#include <spi/spi.h>
#include <mach/spi.h>
#include <mach/usb.h>

static iomux_v3_cfg_t ek360_led[] = {
	MX6Q_PAD_DISP0_DAT17__GPIO_5_11 | MUX_PAD_CTRL(NO_PAD_CTRL),
};

static int ek360_led_setup(void)
{
	mxc_iomux_v3_setup_multiple_pads(ek360_led, ARRAY_SIZE(ek360_led));
	gpio_direction_output(IMX_GPIO_NR(5, 11) , 0); /* Led On */
	return 0;
}
fs_initcall(ek360_led_setup);

static void ek360_epit_init(void)
{
	writel(0x0000000, MX6_EPIT1_BASE_ADDR);
	writel(0x142000F, MX6_EPIT1_BASE_ADDR);
	writel(0x30000, MX6_EPIT1_BASE_ADDR + 0x8);
	writel(0x0, MX6_EPIT1_BASE_ADDR + 0xC);
}

static int ek360_devices_init(void)
{
	if (!of_machine_is_compatible("eurek,ek360"))
		return 0;

	ek360_epit_init();

	armlinux_set_bootparams((void *)0x10000100);
	barebox_set_hostname("ek360");

	gpio_set_value(IMX_GPIO_NR(5, 11), 1); /* Led Off */
	return 0;
}
device_initcall(ek360_devices_init);

static int ek360_coredevices_init(void)
{
	if (!of_machine_is_compatible("eurek,ek360"))
		return 0;

	return 0;
}
coredevice_initcall(ek360_coredevices_init);
