Stefano Babic | 18db74a | 2012-02-07 23:29:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 |
| 3 | * Stefano Babic, DENX Software Engineering, sbabic@denx.de. |
| 4 | * |
| 5 | * Copyright (C) 2009 TechNexion Ltd. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc. |
| 20 | */ |
| 21 | |
| 22 | #include <common.h> |
| 23 | #include <netdev.h> |
| 24 | #include <fpga.h> |
| 25 | #include <asm/io.h> |
| 26 | #include <asm/arch/mem.h> |
| 27 | #include <asm/arch/mux.h> |
| 28 | #include <asm/arch/sys_proto.h> |
| 29 | #include <asm/omap_gpio.h> |
| 30 | #include <asm/arch/mmc_host_def.h> |
| 31 | #include <i2c.h> |
| 32 | #include <spartan3.h> |
| 33 | #include <asm/gpio.h> |
| 34 | #ifdef CONFIG_USB_EHCI |
| 35 | #include <usb.h> |
| 36 | #include <asm/ehci-omap.h> |
| 37 | #endif |
| 38 | #include "mt_ventoux.h" |
| 39 | |
| 40 | DECLARE_GLOBAL_DATA_PTR; |
| 41 | |
Stefano Babic | 63f9315 | 2012-08-29 01:22:04 +0000 | [diff] [blame] | 42 | #define BUZZER 140 |
| 43 | #define SPEAKER 141 |
| 44 | |
Stefano Babic | 18db74a | 2012-02-07 23:29:34 +0000 | [diff] [blame] | 45 | #ifndef CONFIG_FPGA |
| 46 | #error "The Teejet mt_ventoux must have CONFIG_FPGA enabled" |
| 47 | #endif |
| 48 | |
| 49 | #define FPGA_RESET 62 |
| 50 | #define FPGA_PROG 116 |
| 51 | #define FPGA_CCLK 117 |
| 52 | #define FPGA_DIN 118 |
| 53 | #define FPGA_INIT 119 |
| 54 | #define FPGA_DONE 154 |
| 55 | |
| 56 | /* Timing definitions for FPGA */ |
| 57 | static const u32 gpmc_fpga[] = { |
| 58 | FPGA_GPMC_CONFIG1, |
| 59 | FPGA_GPMC_CONFIG2, |
| 60 | FPGA_GPMC_CONFIG3, |
| 61 | FPGA_GPMC_CONFIG4, |
| 62 | FPGA_GPMC_CONFIG5, |
| 63 | FPGA_GPMC_CONFIG6, |
| 64 | }; |
| 65 | |
| 66 | #ifdef CONFIG_USB_EHCI |
| 67 | static struct omap_usbhs_board_data usbhs_bdata = { |
| 68 | .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY, |
| 69 | .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY, |
| 70 | .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED, |
| 71 | }; |
| 72 | |
| 73 | int ehci_hcd_init(void) |
| 74 | { |
| 75 | return omap_ehci_hcd_init(&usbhs_bdata); |
| 76 | } |
| 77 | |
| 78 | int ehci_hcd_stop(void) |
| 79 | { |
| 80 | return omap_ehci_hcd_stop(); |
| 81 | } |
| 82 | #endif |
| 83 | |
| 84 | |
| 85 | static inline void fpga_reset(int nassert) |
| 86 | { |
| 87 | gpio_set_value(FPGA_RESET, !nassert); |
| 88 | } |
| 89 | |
| 90 | int fpga_pgm_fn(int nassert, int nflush, int cookie) |
| 91 | { |
| 92 | debug("%s:%d: FPGA PROGRAM ", __func__, __LINE__); |
| 93 | |
| 94 | gpio_set_value(FPGA_PROG, !nassert); |
| 95 | |
| 96 | return nassert; |
| 97 | } |
| 98 | |
| 99 | int fpga_init_fn(int cookie) |
| 100 | { |
| 101 | return !gpio_get_value(FPGA_INIT); |
| 102 | } |
| 103 | |
| 104 | int fpga_done_fn(int cookie) |
| 105 | { |
| 106 | return gpio_get_value(FPGA_DONE); |
| 107 | } |
| 108 | |
| 109 | int fpga_pre_config_fn(int cookie) |
| 110 | { |
| 111 | debug("%s:%d: FPGA pre-configuration\n", __func__, __LINE__); |
| 112 | |
| 113 | /* Setting GPIOs for programming Mode */ |
| 114 | gpio_request(FPGA_RESET, "FPGA_RESET"); |
| 115 | gpio_direction_output(FPGA_RESET, 1); |
| 116 | gpio_request(FPGA_PROG, "FPGA_PROG"); |
| 117 | gpio_direction_output(FPGA_PROG, 1); |
| 118 | gpio_request(FPGA_CCLK, "FPGA_CCLK"); |
| 119 | gpio_direction_output(FPGA_CCLK, 1); |
| 120 | gpio_request(FPGA_DIN, "FPGA_DIN"); |
| 121 | gpio_direction_output(FPGA_DIN, 0); |
| 122 | gpio_request(FPGA_INIT, "FPGA_INIT"); |
| 123 | gpio_direction_input(FPGA_INIT); |
| 124 | gpio_request(FPGA_DONE, "FPGA_DONE"); |
| 125 | gpio_direction_input(FPGA_DONE); |
| 126 | |
| 127 | /* Be sure that signal are deasserted */ |
| 128 | gpio_set_value(FPGA_RESET, 1); |
| 129 | gpio_set_value(FPGA_PROG, 1); |
| 130 | |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | int fpga_post_config_fn(int cookie) |
| 135 | { |
| 136 | debug("%s:%d: FPGA post-configuration\n", __func__, __LINE__); |
| 137 | |
| 138 | fpga_reset(TRUE); |
| 139 | udelay(100); |
| 140 | fpga_reset(FALSE); |
| 141 | |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | /* Write program to the FPGA */ |
| 146 | int fpga_wr_fn(int nassert_write, int flush, int cookie) |
| 147 | { |
| 148 | gpio_set_value(FPGA_DIN, nassert_write); |
| 149 | |
| 150 | return nassert_write; |
| 151 | } |
| 152 | |
| 153 | int fpga_clk_fn(int assert_clk, int flush, int cookie) |
| 154 | { |
| 155 | gpio_set_value(FPGA_CCLK, assert_clk); |
| 156 | |
| 157 | return assert_clk; |
| 158 | } |
| 159 | |
| 160 | Xilinx_Spartan3_Slave_Serial_fns mt_ventoux_fpga_fns = { |
| 161 | fpga_pre_config_fn, |
| 162 | fpga_pgm_fn, |
| 163 | fpga_clk_fn, |
| 164 | fpga_init_fn, |
| 165 | fpga_done_fn, |
| 166 | fpga_wr_fn, |
| 167 | fpga_post_config_fn, |
| 168 | }; |
| 169 | |
| 170 | Xilinx_desc fpga = XILINX_XC6SLX4_DESC(slave_serial, |
| 171 | (void *)&mt_ventoux_fpga_fns, 0); |
| 172 | |
| 173 | /* Initialize the FPGA */ |
| 174 | static void mt_ventoux_init_fpga(void) |
| 175 | { |
| 176 | fpga_pre_config_fn(0); |
| 177 | |
| 178 | /* Setting CS1 for FPGA access */ |
| 179 | enable_gpmc_cs_config(gpmc_fpga, &gpmc_cfg->cs[1], |
| 180 | FPGA_BASE_ADDR, GPMC_SIZE_128M); |
| 181 | |
| 182 | fpga_init(); |
| 183 | fpga_add(fpga_xilinx, &fpga); |
| 184 | } |
| 185 | |
| 186 | /* |
| 187 | * Routine: board_init |
| 188 | * Description: Early hardware init. |
| 189 | */ |
| 190 | int board_init(void) |
| 191 | { |
| 192 | gpmc_init(); /* in SRAM or SDRAM, finish GPMC */ |
| 193 | |
| 194 | /* boot param addr */ |
| 195 | gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100); |
| 196 | |
| 197 | mt_ventoux_init_fpga(); |
| 198 | |
Stefano Babic | 63f9315 | 2012-08-29 01:22:04 +0000 | [diff] [blame] | 199 | /* GPIO_140: speaker #mute */ |
| 200 | MUX_VAL(CP(MCBSP3_DX), (IEN | PTU | EN | M4)) |
| 201 | /* GPIO_141: Buzz Hi */ |
| 202 | MUX_VAL(CP(MCBSP3_DR), (IEN | PTU | EN | M4)) |
| 203 | |
| 204 | /* Turning off the buzzer */ |
| 205 | gpio_request(BUZZER, "BUZZER_MUTE"); |
| 206 | gpio_request(SPEAKER, "SPEAKER"); |
| 207 | gpio_direction_output(BUZZER, 0); |
| 208 | gpio_direction_output(SPEAKER, 0); |
| 209 | |
Stefano Babic | 18db74a | 2012-02-07 23:29:34 +0000 | [diff] [blame] | 210 | return 0; |
| 211 | } |
| 212 | |
Stefano Babic | 85d9c7a | 2012-08-29 01:22:03 +0000 | [diff] [blame] | 213 | int misc_init_r(void) |
| 214 | { |
| 215 | char *eth_addr; |
| 216 | |
| 217 | dieid_num_r(); |
| 218 | |
| 219 | eth_addr = getenv("ethaddr"); |
| 220 | if (eth_addr) |
| 221 | return 0; |
| 222 | |
| 223 | #ifndef CONFIG_SPL_BUILD |
| 224 | TAM3517_READ_MAC_FROM_EEPROM; |
| 225 | #endif |
| 226 | return 0; |
| 227 | } |
| 228 | |
Stefano Babic | 18db74a | 2012-02-07 23:29:34 +0000 | [diff] [blame] | 229 | /* |
| 230 | * Routine: set_muxconf_regs |
| 231 | * Description: Setting up the configuration Mux registers specific to the |
| 232 | * hardware. Many pins need to be moved from protect to primary |
| 233 | * mode. |
| 234 | */ |
| 235 | void set_muxconf_regs(void) |
| 236 | { |
| 237 | MUX_MT_VENTOUX(); |
| 238 | } |
| 239 | |
| 240 | /* |
| 241 | * Initializes on-chip ethernet controllers. |
| 242 | * to override, implement board_eth_init() |
| 243 | */ |
| 244 | int board_eth_init(bd_t *bis) |
| 245 | { |
| 246 | davinci_emac_initialize(); |
| 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | #if defined(CONFIG_OMAP_HSMMC) && \ |
| 251 | !defined(CONFIG_SPL_BUILD) |
| 252 | int board_mmc_init(bd_t *bis) |
| 253 | { |
Jonathan Solnit | a9b0556 | 2012-02-24 11:30:18 +0000 | [diff] [blame] | 254 | return omap_mmc_init(0, 0, 0); |
Stefano Babic | 18db74a | 2012-02-07 23:29:34 +0000 | [diff] [blame] | 255 | } |
| 256 | #endif |