1 /* 2 * Novena board support 3 * 4 * Copyright (C) 2014 Marek Vasut <marex@denx.de> 5 * 6 * SPDX-License-Identifier: GPL-2.0+ 7 */ 8 9 #include <common.h> 10 #include <asm/errno.h> 11 #include <asm/gpio.h> 12 #include <asm/io.h> 13 #include <asm/arch/clock.h> 14 #include <asm/arch/crm_regs.h> 15 #include <asm/arch/imx-regs.h> 16 #include <asm/arch/iomux.h> 17 #include <asm/arch/mxc_hdmi.h> 18 #include <asm/arch/sys_proto.h> 19 #include <asm/imx-common/boot_mode.h> 20 #include <asm/imx-common/iomux-v3.h> 21 #include <asm/imx-common/mxc_i2c.h> 22 #include <asm/imx-common/sata.h> 23 #include <asm/imx-common/video.h> 24 #include <fsl_esdhc.h> 25 #include <i2c.h> 26 #include <input.h> 27 #include <ipu_pixfmt.h> 28 #include <linux/fb.h> 29 #include <linux/input.h> 30 #include <malloc.h> 31 #include <micrel.h> 32 #include <miiphy.h> 33 #include <mmc.h> 34 #include <netdev.h> 35 #include <power/pmic.h> 36 #include <power/pfuze100_pmic.h> 37 #include <stdio_dev.h> 38 39 #include "novena.h" 40 41 DECLARE_GLOBAL_DATA_PTR; 42 43 /* 44 * GPIO button 45 */ 46 #ifdef CONFIG_KEYBOARD 47 static struct input_config button_input; 48 49 static int novena_gpio_button_read_keys(struct input_config *input) 50 { 51 int key = KEY_ENTER; 52 if (gpio_get_value(NOVENA_BUTTON_GPIO)) 53 return 0; 54 input_send_keycodes(&button_input, &key, 1); 55 return 1; 56 } 57 58 static int novena_gpio_button_getc(struct stdio_dev *dev) 59 { 60 return input_getc(&button_input); 61 } 62 63 static int novena_gpio_button_tstc(struct stdio_dev *dev) 64 { 65 return input_tstc(&button_input); 66 } 67 68 static int novena_gpio_button_init(struct stdio_dev *dev) 69 { 70 gpio_direction_input(NOVENA_BUTTON_GPIO); 71 input_set_delays(&button_input, 250, 250); 72 return 0; 73 } 74 75 int drv_keyboard_init(void) 76 { 77 int error; 78 struct stdio_dev dev = { 79 .name = "button", 80 .flags = DEV_FLAGS_INPUT, 81 .start = novena_gpio_button_init, 82 .getc = novena_gpio_button_getc, 83 .tstc = novena_gpio_button_tstc, 84 }; 85 86 error = input_init(&button_input, 0); 87 if (error) { 88 debug("%s: Cannot set up input\n", __func__); 89 return -1; 90 } 91 input_add_tables(&button_input, false); 92 button_input.read_keys = novena_gpio_button_read_keys; 93 94 error = input_stdio_register(&dev); 95 if (error) 96 return error; 97 98 return 0; 99 } 100 #endif 101 102 /* 103 * SDHC 104 */ 105 #ifdef CONFIG_FSL_ESDHC 106 static struct fsl_esdhc_cfg usdhc_cfg[] = { 107 { USDHC3_BASE_ADDR, 0, 4 }, /* Micro SD */ 108 { USDHC2_BASE_ADDR, 0, 4 }, /* Big SD */ 109 }; 110 111 int board_mmc_getcd(struct mmc *mmc) 112 { 113 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv; 114 115 /* There is no CD for a microSD card, assume always present. */ 116 if (cfg->esdhc_base == USDHC3_BASE_ADDR) 117 return 1; 118 else 119 return !gpio_get_value(NOVENA_SD_CD); 120 } 121 122 int board_mmc_getwp(struct mmc *mmc) 123 { 124 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv; 125 126 /* There is no WP for a microSD card, assume always read-write. */ 127 if (cfg->esdhc_base == USDHC3_BASE_ADDR) 128 return 0; 129 else 130 return gpio_get_value(NOVENA_SD_WP); 131 } 132 133 134 int board_mmc_init(bd_t *bis) 135 { 136 s32 status = 0; 137 int index; 138 139 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK); 140 usdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK); 141 142 /* Big SD write-protect and card-detect */ 143 gpio_direction_input(NOVENA_SD_WP); 144 gpio_direction_input(NOVENA_SD_CD); 145 146 for (index = 0; index < ARRAY_SIZE(usdhc_cfg); index++) { 147 status = fsl_esdhc_initialize(bis, &usdhc_cfg[index]); 148 if (status) 149 return status; 150 } 151 152 return status; 153 } 154 #endif 155 156 int board_early_init_f(void) 157 { 158 #if defined(CONFIG_VIDEO_IPUV3) 159 setup_display_clock(); 160 #endif 161 162 return 0; 163 } 164 165 int board_init(void) 166 { 167 /* address of boot parameters */ 168 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; 169 170 #ifdef CONFIG_CMD_SATA 171 setup_sata(); 172 #endif 173 174 return 0; 175 } 176 177 int board_late_init(void) 178 { 179 #if defined(CONFIG_VIDEO_IPUV3) 180 setup_display_lvds(); 181 #endif 182 return 0; 183 } 184 185 int checkboard(void) 186 { 187 puts("Board: Novena 4x\n"); 188 return 0; 189 } 190 191 int dram_init(void) 192 { 193 gd->ram_size = imx_ddr_size(); 194 return 0; 195 } 196 197 /* setup board specific PMIC */ 198 int power_init_board(void) 199 { 200 struct pmic *p; 201 u32 reg; 202 int ret; 203 204 power_pfuze100_init(1); 205 p = pmic_get("PFUZE100"); 206 if (!p) 207 return -EINVAL; 208 209 ret = pmic_probe(p); 210 if (ret) 211 return ret; 212 213 pmic_reg_read(p, PFUZE100_DEVICEID, ®); 214 printf("PMIC: PFUZE100 ID=0x%02x\n", reg); 215 216 /* Set SWBST to 5.0V and enable (for USB) */ 217 pmic_reg_read(p, PFUZE100_SWBSTCON1, ®); 218 reg &= ~(SWBST_MODE_MASK | SWBST_VOL_MASK); 219 reg |= (SWBST_5_00V | (SWBST_MODE_AUTO << SWBST_MODE_SHIFT)); 220 pmic_reg_write(p, PFUZE100_SWBSTCON1, reg); 221 222 return 0; 223 } 224 225 /* EEPROM configuration data */ 226 struct novena_eeprom_data { 227 uint8_t signature[6]; 228 uint8_t version; 229 uint8_t reserved; 230 uint32_t serial; 231 uint8_t mac[6]; 232 uint16_t features; 233 }; 234 235 int misc_init_r(void) 236 { 237 struct novena_eeprom_data data; 238 uchar *datap = (uchar *)&data; 239 const char *signature = "Novena"; 240 int ret; 241 242 /* If 'ethaddr' is already set, do nothing. */ 243 if (getenv("ethaddr")) 244 return 0; 245 246 /* EEPROM is at bus 2. */ 247 ret = i2c_set_bus_num(2); 248 if (ret) { 249 puts("Cannot select EEPROM I2C bus.\n"); 250 return 0; 251 } 252 253 /* EEPROM is at address 0x56. */ 254 ret = eeprom_read(0x56, 0, datap, sizeof(data)); 255 if (ret) { 256 puts("Cannot read I2C EEPROM.\n"); 257 return 0; 258 } 259 260 /* Check EEPROM signature. */ 261 if (memcmp(data.signature, signature, 6)) { 262 puts("Invalid I2C EEPROM signature.\n"); 263 return 0; 264 } 265 266 /* Set ethernet address from EEPROM. */ 267 eth_setenv_enetaddr("ethaddr", data.mac); 268 269 return ret; 270 } 271