Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 Simon Guinot <sguinot@lacie.com> |
| 3 | * |
| 4 | * Based on Kirkwood support: |
| 5 | * (C) Copyright 2009 |
| 6 | * Marvell Semiconductor <www.marvell.com> |
| 7 | * Written-by: Prafulla Wadaskar <prafulla@marvell.com> |
| 8 | * |
| 9 | * See file CREDITS for list of people who contributed to this |
| 10 | * project. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License as |
| 14 | * published by the Free Software Foundation; either version 2 of |
| 15 | * the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | */ |
| 22 | |
| 23 | #include <common.h> |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 24 | #include <command.h> |
Simon Guinot | 1dd67e6 | 2013-06-18 15:14:48 +0200 | [diff] [blame] | 25 | #include <i2c.h> |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 26 | #include <asm/arch/cpu.h> |
| 27 | #include <asm/arch/kirkwood.h> |
| 28 | #include <asm/arch/mpp.h> |
| 29 | #include <asm/arch/gpio.h> |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 30 | |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 31 | #include "net2big_v2.h" |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 32 | #include "../common/common.h" |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 33 | |
| 34 | DECLARE_GLOBAL_DATA_PTR; |
| 35 | |
| 36 | int board_early_init_f(void) |
| 37 | { |
| 38 | /* GPIO configuration */ |
| 39 | kw_config_gpio(NET2BIG_V2_OE_VAL_LOW, NET2BIG_V2_OE_VAL_HIGH, |
| 40 | NET2BIG_V2_OE_LOW, NET2BIG_V2_OE_HIGH); |
| 41 | |
| 42 | /* Multi-Purpose Pins Functionality configuration */ |
Albert ARIBAUD | 4d42431 | 2012-11-26 11:27:36 +0000 | [diff] [blame] | 43 | static const u32 kwmpp_config[] = { |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 44 | MPP0_SPI_SCn, |
| 45 | MPP1_SPI_MOSI, |
| 46 | MPP2_SPI_SCK, |
| 47 | MPP3_SPI_MISO, |
| 48 | MPP6_SYSRST_OUTn, |
| 49 | MPP7_GPO, /* Request power-off */ |
| 50 | MPP8_TW_SDA, |
| 51 | MPP9_TW_SCK, |
| 52 | MPP10_UART0_TXD, |
| 53 | MPP11_UART0_RXD, |
| 54 | MPP13_GPIO, /* Rear power switch (on|auto) */ |
| 55 | MPP14_GPIO, /* USB fuse alarm */ |
| 56 | MPP15_GPIO, /* Rear power switch (auto|off) */ |
| 57 | MPP16_GPIO, /* SATA HDD1 power */ |
| 58 | MPP17_GPIO, /* SATA HDD2 power */ |
| 59 | MPP20_SATA1_ACTn, |
| 60 | MPP21_SATA0_ACTn, |
| 61 | MPP24_GPIO, /* USB mode select */ |
| 62 | MPP26_GPIO, /* USB device vbus */ |
| 63 | MPP28_GPIO, /* USB enable host vbus */ |
| 64 | MPP29_GPIO, /* GPIO extension ALE */ |
| 65 | MPP34_GPIO, /* Rear Push button 0=on 1=off */ |
| 66 | MPP35_GPIO, /* Inhibit switch power-off */ |
| 67 | MPP36_GPIO, /* SATA HDD1 presence */ |
| 68 | MPP37_GPIO, /* SATA HDD2 presence */ |
| 69 | MPP40_GPIO, /* eSATA presence */ |
| 70 | MPP44_GPIO, /* GPIO extension (data 0) */ |
| 71 | MPP45_GPIO, /* GPIO extension (data 1) */ |
| 72 | MPP46_GPIO, /* GPIO extension (data 2) */ |
| 73 | MPP47_GPIO, /* GPIO extension (addr 0) */ |
| 74 | MPP48_GPIO, /* GPIO extension (addr 1) */ |
| 75 | MPP49_GPIO, /* GPIO extension (addr 2) */ |
| 76 | 0 |
| 77 | }; |
| 78 | |
Valentin Longchamp | 7d0d502 | 2012-06-01 01:31:00 +0000 | [diff] [blame] | 79 | kirkwood_mpp_conf(kwmpp_config, NULL); |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | int board_init(void) |
| 85 | { |
| 86 | /* Machine number */ |
| 87 | gd->bd->bi_arch_number = MACH_TYPE_NET2BIG_V2; |
| 88 | |
| 89 | /* Boot parameters address */ |
| 90 | gd->bd->bi_boot_params = kw_sdram_bar(0) + 0x100; |
| 91 | |
| 92 | return 0; |
| 93 | } |
| 94 | |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 95 | #if defined(CONFIG_MISC_INIT_R) |
Simon Guinot | 1dd67e6 | 2013-06-18 15:14:48 +0200 | [diff] [blame] | 96 | |
| 97 | #if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_G762_ADDR) |
| 98 | /* |
| 99 | * Start I2C fan (GMT G762 controller) |
| 100 | */ |
| 101 | static void init_fan(void) |
| 102 | { |
| 103 | u8 data; |
| 104 | |
| 105 | i2c_set_bus_num(0); |
| 106 | |
| 107 | /* Enable open-loop and PWM modes */ |
| 108 | data = 0x20; |
| 109 | if (i2c_write(CONFIG_SYS_I2C_G762_ADDR, |
| 110 | G762_REG_FAN_CMD1, 1, &data, 1) != 0) |
| 111 | goto err; |
| 112 | data = 0; |
| 113 | if (i2c_write(CONFIG_SYS_I2C_G762_ADDR, |
| 114 | G762_REG_SET_CNT, 1, &data, 1) != 0) |
| 115 | goto err; |
| 116 | /* |
| 117 | * RPM to PWM (set_out register) fan speed conversion array: |
| 118 | * 0 0x00 |
| 119 | * 1500 0x04 |
| 120 | * 2800 0x08 |
| 121 | * 3400 0x0C |
| 122 | * 3700 0x10 |
| 123 | * 4400 0x20 |
| 124 | * 4700 0x30 |
| 125 | * 4800 0x50 |
| 126 | * 5200 0x80 |
| 127 | * 5400 0xC0 |
| 128 | * 5500 0xFF |
| 129 | * |
| 130 | * Start fan at low speed (2800 RPM): |
| 131 | */ |
| 132 | data = 0x08; |
| 133 | if (i2c_write(CONFIG_SYS_I2C_G762_ADDR, |
| 134 | G762_REG_SET_OUT, 1, &data, 1) != 0) |
| 135 | goto err; |
| 136 | |
| 137 | return; |
| 138 | err: |
| 139 | printf("Error: failed to start I2C fan @%02x\n", |
| 140 | CONFIG_SYS_I2C_G762_ADDR); |
| 141 | } |
| 142 | #else |
| 143 | static void init_fan(void) {} |
| 144 | #endif /* CONFIG_CMD_I2C && CONFIG_SYS_I2C_G762_ADDR */ |
| 145 | |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 146 | int misc_init_r(void) |
| 147 | { |
Simon Guinot | 1dd67e6 | 2013-06-18 15:14:48 +0200 | [diff] [blame] | 148 | init_fan(); |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 149 | #if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR) |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 150 | if (!getenv("ethaddr")) { |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 151 | uchar mac[6]; |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 152 | if (lacie_read_mac_address(mac) == 0) |
| 153 | eth_setenv_enetaddr("ethaddr", mac); |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 154 | } |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 155 | #endif |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 156 | return 0; |
| 157 | } |
Simon Guinot | 1dd67e6 | 2013-06-18 15:14:48 +0200 | [diff] [blame] | 158 | #endif /* CONFIG_MISC_INIT_R */ |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 159 | |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 160 | #if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R) |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 161 | /* Configure and initialize PHY */ |
| 162 | void reset_phy(void) |
| 163 | { |
Simon Guinot | 0473b68 | 2012-06-05 13:16:00 +0000 | [diff] [blame] | 164 | mv_phy_88e1116_init("egiga0", 8); |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 165 | } |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 166 | #endif |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 167 | |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 168 | #if defined(CONFIG_KIRKWOOD_GPIO) |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 169 | /* Return GPIO push button status */ |
| 170 | static int |
| 171 | do_read_push_button(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 172 | { |
| 173 | return !kw_gpio_get_value(NET2BIG_V2_GPIO_PUSH_BUTTON); |
| 174 | } |
| 175 | |
| 176 | U_BOOT_CMD(button, 1, 1, do_read_push_button, |
| 177 | "Return GPIO push button status 0=off 1=on", ""); |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 178 | #endif |