11fdabeddSStefano Babic /*
21fdabeddSStefano Babic  * Copyright (C) 2011
31fdabeddSStefano Babic  * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
41fdabeddSStefano Babic  *
51fdabeddSStefano Babic  * Copyright (C) 2009 TechNexion Ltd.
61fdabeddSStefano Babic  *
71fdabeddSStefano Babic  * This program is free software; you can redistribute it and/or modify
81fdabeddSStefano Babic  * it under the terms of the GNU General Public License as published by
91fdabeddSStefano Babic  * the Free Software Foundation; either version 2 of the License, or
101fdabeddSStefano Babic  * (at your option) any later version.
111fdabeddSStefano Babic  *
121fdabeddSStefano Babic  * This program is distributed in the hope that it will be useful,
131fdabeddSStefano Babic  * but WITHOUT ANY WARRANTY; without even the implied warranty of
141fdabeddSStefano Babic  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
151fdabeddSStefano Babic  * GNU General Public License for more details.
161fdabeddSStefano Babic  *
171fdabeddSStefano Babic  * You should have received a copy of the GNU General Public License
181fdabeddSStefano Babic  * along with this program; if not, write to the Free Software
191fdabeddSStefano Babic  * Foundation, Inc.
201fdabeddSStefano Babic  */
211fdabeddSStefano Babic 
221fdabeddSStefano Babic #include <common.h>
231fdabeddSStefano Babic #include <netdev.h>
241fdabeddSStefano Babic #include <fpga.h>
251fdabeddSStefano Babic #include <asm/io.h>
261fdabeddSStefano Babic #include <asm/arch/mem.h>
271fdabeddSStefano Babic #include <asm/arch/mux.h>
281fdabeddSStefano Babic #include <asm/arch/sys_proto.h>
291fdabeddSStefano Babic #include <asm/omap_gpio.h>
301fdabeddSStefano Babic #include <asm/arch/mmc_host_def.h>
311fdabeddSStefano Babic #include <i2c.h>
321fdabeddSStefano Babic #include <spartan3.h>
331fdabeddSStefano Babic #include <asm/gpio.h>
341fdabeddSStefano Babic #ifdef CONFIG_USB_EHCI
351fdabeddSStefano Babic #include <usb.h>
361fdabeddSStefano Babic #include <asm/ehci-omap.h>
371fdabeddSStefano Babic #endif
381fdabeddSStefano Babic #include "mt_ventoux.h"
391fdabeddSStefano Babic 
401fdabeddSStefano Babic DECLARE_GLOBAL_DATA_PTR;
411fdabeddSStefano Babic 
421fdabeddSStefano Babic #ifndef CONFIG_FPGA
431fdabeddSStefano Babic #error "The Teejet mt_ventoux must have CONFIG_FPGA enabled"
441fdabeddSStefano Babic #endif
451fdabeddSStefano Babic 
461fdabeddSStefano Babic #define FPGA_RESET	62
471fdabeddSStefano Babic #define FPGA_PROG	116
481fdabeddSStefano Babic #define FPGA_CCLK	117
491fdabeddSStefano Babic #define FPGA_DIN	118
501fdabeddSStefano Babic #define FPGA_INIT	119
511fdabeddSStefano Babic #define FPGA_DONE	154
521fdabeddSStefano Babic 
531fdabeddSStefano Babic /* Timing definitions for FPGA */
541fdabeddSStefano Babic static const u32 gpmc_fpga[] = {
551fdabeddSStefano Babic 	FPGA_GPMC_CONFIG1,
561fdabeddSStefano Babic 	FPGA_GPMC_CONFIG2,
571fdabeddSStefano Babic 	FPGA_GPMC_CONFIG3,
581fdabeddSStefano Babic 	FPGA_GPMC_CONFIG4,
591fdabeddSStefano Babic 	FPGA_GPMC_CONFIG5,
601fdabeddSStefano Babic 	FPGA_GPMC_CONFIG6,
611fdabeddSStefano Babic };
621fdabeddSStefano Babic 
631fdabeddSStefano Babic #ifdef CONFIG_USB_EHCI
641fdabeddSStefano Babic static struct omap_usbhs_board_data usbhs_bdata = {
651fdabeddSStefano Babic 	.port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
661fdabeddSStefano Babic 	.port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
671fdabeddSStefano Babic 	.port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED,
681fdabeddSStefano Babic };
691fdabeddSStefano Babic 
701fdabeddSStefano Babic int ehci_hcd_init(void)
711fdabeddSStefano Babic {
721fdabeddSStefano Babic 	return omap_ehci_hcd_init(&usbhs_bdata);
731fdabeddSStefano Babic }
741fdabeddSStefano Babic 
751fdabeddSStefano Babic int ehci_hcd_stop(void)
761fdabeddSStefano Babic {
771fdabeddSStefano Babic 	return omap_ehci_hcd_stop();
781fdabeddSStefano Babic }
791fdabeddSStefano Babic #endif
801fdabeddSStefano Babic 
811fdabeddSStefano Babic 
821fdabeddSStefano Babic static inline void fpga_reset(int nassert)
831fdabeddSStefano Babic {
841fdabeddSStefano Babic 	gpio_set_value(FPGA_RESET, !nassert);
851fdabeddSStefano Babic }
861fdabeddSStefano Babic 
871fdabeddSStefano Babic int fpga_pgm_fn(int nassert, int nflush, int cookie)
881fdabeddSStefano Babic {
891fdabeddSStefano Babic 	debug("%s:%d: FPGA PROGRAM ", __func__, __LINE__);
901fdabeddSStefano Babic 
911fdabeddSStefano Babic 	gpio_set_value(FPGA_PROG, !nassert);
921fdabeddSStefano Babic 
931fdabeddSStefano Babic 	return nassert;
941fdabeddSStefano Babic }
951fdabeddSStefano Babic 
961fdabeddSStefano Babic int fpga_init_fn(int cookie)
971fdabeddSStefano Babic {
981fdabeddSStefano Babic 	return !gpio_get_value(FPGA_INIT);
991fdabeddSStefano Babic }
1001fdabeddSStefano Babic 
1011fdabeddSStefano Babic int fpga_done_fn(int cookie)
1021fdabeddSStefano Babic {
1031fdabeddSStefano Babic 	return gpio_get_value(FPGA_DONE);
1041fdabeddSStefano Babic }
1051fdabeddSStefano Babic 
1061fdabeddSStefano Babic int fpga_pre_config_fn(int cookie)
1071fdabeddSStefano Babic {
1081fdabeddSStefano Babic 	debug("%s:%d: FPGA pre-configuration\n", __func__, __LINE__);
1091fdabeddSStefano Babic 
1101fdabeddSStefano Babic 	/* Setting GPIOs for programming Mode */
1111fdabeddSStefano Babic 	gpio_request(FPGA_RESET, "FPGA_RESET");
1121fdabeddSStefano Babic 	gpio_direction_output(FPGA_RESET, 1);
1131fdabeddSStefano Babic 	gpio_request(FPGA_PROG, "FPGA_PROG");
1141fdabeddSStefano Babic 	gpio_direction_output(FPGA_PROG, 1);
1151fdabeddSStefano Babic 	gpio_request(FPGA_CCLK, "FPGA_CCLK");
1161fdabeddSStefano Babic 	gpio_direction_output(FPGA_CCLK, 1);
1171fdabeddSStefano Babic 	gpio_request(FPGA_DIN, "FPGA_DIN");
1181fdabeddSStefano Babic 	gpio_direction_output(FPGA_DIN, 0);
1191fdabeddSStefano Babic 	gpio_request(FPGA_INIT, "FPGA_INIT");
1201fdabeddSStefano Babic 	gpio_direction_input(FPGA_INIT);
1211fdabeddSStefano Babic 	gpio_request(FPGA_DONE, "FPGA_DONE");
1221fdabeddSStefano Babic 	gpio_direction_input(FPGA_DONE);
1231fdabeddSStefano Babic 
1241fdabeddSStefano Babic 	/* Be sure that signal are deasserted */
1251fdabeddSStefano Babic 	gpio_set_value(FPGA_RESET, 1);
1261fdabeddSStefano Babic 	gpio_set_value(FPGA_PROG, 1);
1271fdabeddSStefano Babic 
1281fdabeddSStefano Babic 	return 0;
1291fdabeddSStefano Babic }
1301fdabeddSStefano Babic 
1311fdabeddSStefano Babic int fpga_post_config_fn(int cookie)
1321fdabeddSStefano Babic {
1331fdabeddSStefano Babic 	debug("%s:%d: FPGA post-configuration\n", __func__, __LINE__);
1341fdabeddSStefano Babic 
1351fdabeddSStefano Babic 	fpga_reset(TRUE);
1361fdabeddSStefano Babic 	udelay(100);
1371fdabeddSStefano Babic 	fpga_reset(FALSE);
1381fdabeddSStefano Babic 
1391fdabeddSStefano Babic 	return 0;
1401fdabeddSStefano Babic }
1411fdabeddSStefano Babic 
1421fdabeddSStefano Babic /* Write program to the FPGA */
1431fdabeddSStefano Babic int fpga_wr_fn(int nassert_write, int flush, int cookie)
1441fdabeddSStefano Babic {
1451fdabeddSStefano Babic 	gpio_set_value(FPGA_DIN, nassert_write);
1461fdabeddSStefano Babic 
1471fdabeddSStefano Babic 	return nassert_write;
1481fdabeddSStefano Babic }
1491fdabeddSStefano Babic 
1501fdabeddSStefano Babic int fpga_clk_fn(int assert_clk, int flush, int cookie)
1511fdabeddSStefano Babic {
1521fdabeddSStefano Babic 	gpio_set_value(FPGA_CCLK, assert_clk);
1531fdabeddSStefano Babic 
1541fdabeddSStefano Babic 	return assert_clk;
1551fdabeddSStefano Babic }
1561fdabeddSStefano Babic 
1571fdabeddSStefano Babic Xilinx_Spartan3_Slave_Serial_fns mt_ventoux_fpga_fns = {
1581fdabeddSStefano Babic 	fpga_pre_config_fn,
1591fdabeddSStefano Babic 	fpga_pgm_fn,
1601fdabeddSStefano Babic 	fpga_clk_fn,
1611fdabeddSStefano Babic 	fpga_init_fn,
1621fdabeddSStefano Babic 	fpga_done_fn,
1631fdabeddSStefano Babic 	fpga_wr_fn,
1641fdabeddSStefano Babic 	fpga_post_config_fn,
1651fdabeddSStefano Babic };
1661fdabeddSStefano Babic 
1671fdabeddSStefano Babic Xilinx_desc fpga = XILINX_XC6SLX4_DESC(slave_serial,
1681fdabeddSStefano Babic 			(void *)&mt_ventoux_fpga_fns, 0);
1691fdabeddSStefano Babic 
1701fdabeddSStefano Babic /* Initialize the FPGA */
1711fdabeddSStefano Babic static void mt_ventoux_init_fpga(void)
1721fdabeddSStefano Babic {
1731fdabeddSStefano Babic 	fpga_pre_config_fn(0);
1741fdabeddSStefano Babic 
1751fdabeddSStefano Babic 	/* Setting CS1 for FPGA access */
1761fdabeddSStefano Babic 	enable_gpmc_cs_config(gpmc_fpga, &gpmc_cfg->cs[1],
1771fdabeddSStefano Babic 		FPGA_BASE_ADDR, GPMC_SIZE_128M);
1781fdabeddSStefano Babic 
1791fdabeddSStefano Babic 	fpga_init();
1801fdabeddSStefano Babic 	fpga_add(fpga_xilinx, &fpga);
1811fdabeddSStefano Babic }
1821fdabeddSStefano Babic 
1831fdabeddSStefano Babic /*
1841fdabeddSStefano Babic  * Routine: board_init
1851fdabeddSStefano Babic  * Description: Early hardware init.
1861fdabeddSStefano Babic  */
1871fdabeddSStefano Babic int board_init(void)
1881fdabeddSStefano Babic {
1891fdabeddSStefano Babic 	gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
1901fdabeddSStefano Babic 
1911fdabeddSStefano Babic 	/* boot param addr */
1921fdabeddSStefano Babic 	gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
1931fdabeddSStefano Babic 
1941fdabeddSStefano Babic 	mt_ventoux_init_fpga();
1951fdabeddSStefano Babic 
1961fdabeddSStefano Babic 	return 0;
1971fdabeddSStefano Babic }
1981fdabeddSStefano Babic 
1991fdabeddSStefano Babic int misc_init_r(void)
2001fdabeddSStefano Babic {
2011fdabeddSStefano Babic 	dieid_num_r();
2021fdabeddSStefano Babic 
2031fdabeddSStefano Babic 	return 0;
2041fdabeddSStefano Babic }
2051fdabeddSStefano Babic 
2061fdabeddSStefano Babic /*
2071fdabeddSStefano Babic  * Routine: set_muxconf_regs
2081fdabeddSStefano Babic  * Description: Setting up the configuration Mux registers specific to the
2091fdabeddSStefano Babic  *		hardware. Many pins need to be moved from protect to primary
2101fdabeddSStefano Babic  *		mode.
2111fdabeddSStefano Babic  */
2121fdabeddSStefano Babic void set_muxconf_regs(void)
2131fdabeddSStefano Babic {
2141fdabeddSStefano Babic 	MUX_MT_VENTOUX();
2151fdabeddSStefano Babic }
2161fdabeddSStefano Babic 
2171fdabeddSStefano Babic /*
2181fdabeddSStefano Babic  * Initializes on-chip ethernet controllers.
2191fdabeddSStefano Babic  * to override, implement board_eth_init()
2201fdabeddSStefano Babic  */
2211fdabeddSStefano Babic int board_eth_init(bd_t *bis)
2221fdabeddSStefano Babic {
2231fdabeddSStefano Babic 	davinci_emac_initialize();
2241fdabeddSStefano Babic 	return 0;
2251fdabeddSStefano Babic }
2261fdabeddSStefano Babic 
2271fdabeddSStefano Babic #if defined(CONFIG_OMAP_HSMMC) && \
2281fdabeddSStefano Babic 	!defined(CONFIG_SPL_BUILD)
2291fdabeddSStefano Babic int board_mmc_init(bd_t *bis)
2301fdabeddSStefano Babic {
231*bbbc1ae9SJonathan Solnit 	return omap_mmc_init(0, 0, 0);
2321fdabeddSStefano Babic }
2331fdabeddSStefano Babic #endif
234