blob: 8ce054e42840a4a10a71a14c1df14387f1d3f771 [file] [log] [blame]
Jason Liubc5833c2011-12-29 06:34:19 +00001/*
2 * Copyright (C) 2010-2011 Freescale Semiconductor, Inc.
3 *
4 * See file CREDITS for list of people who contributed to this
5 * project.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (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
Wolfgang Denkf5cdc112012-04-16 23:13:51 +020014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Jason Liubc5833c2011-12-29 06:34:19 +000015 * 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., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23#include <common.h>
24#include <asm/io.h>
Troy Kiskyaf2a35f2012-07-19 08:18:22 +000025#include <asm/arch/clock.h>
Jason Liubc5833c2011-12-29 06:34:19 +000026#include <asm/arch/imx-regs.h>
Troy Kiskyd1c679a2012-08-15 10:27:11 +000027#include <asm/arch/iomux.h>
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +000028#include <asm/arch/mx6q_pins.h>
Jason Liubc5833c2011-12-29 06:34:19 +000029#include <asm/errno.h>
30#include <asm/gpio.h>
Troy Kiskyaf2a35f2012-07-19 08:18:22 +000031#include <asm/imx-common/iomux-v3.h>
Troy Kisky9c067822012-07-19 08:18:26 +000032#include <asm/imx-common/mxc_i2c.h>
Troy Kiskybb05b402012-08-15 10:31:21 +000033#include <asm/imx-common/boot_mode.h>
Jason Liubc5833c2011-12-29 06:34:19 +000034#include <mmc.h>
35#include <fsl_esdhc.h>
Troy Kisky32369212012-10-22 16:40:47 +000036#include <malloc.h>
Troy Kisky2bf33592012-02-07 14:08:50 +000037#include <micrel.h>
Jason Liu2af81e22012-01-12 22:56:16 +000038#include <miiphy.h>
39#include <netdev.h>
Eric Nelsone58010b2012-10-03 07:28:43 +000040#include <linux/fb.h>
41#include <ipu_pixfmt.h>
42#include <asm/arch/crm_regs.h>
43#include <asm/arch/mxc_hdmi.h>
44#include <i2c.h>
45
Jason Liubc5833c2011-12-29 06:34:19 +000046DECLARE_GLOBAL_DATA_PTR;
47
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000048#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
49 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
50 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
Jason Liubc5833c2011-12-29 06:34:19 +000051
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000052#define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \
53 PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \
54 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
Jason Liubc5833c2011-12-29 06:34:19 +000055
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000056#define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
57 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
Jason Liu2af81e22012-01-12 22:56:16 +000058
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000059#define SPI_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_SPEED_MED | \
Eric Nelson373a1d82012-01-31 07:52:05 +000060 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST)
61
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000062#define BUTTON_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
63 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
Eric Nelson28fdbdd2012-04-25 14:14:04 +000064
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000065#define I2C_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
66 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
Troy Kisky31746892012-04-24 17:33:26 +000067 PAD_CTL_ODE | PAD_CTL_SRE_FAST)
68
Jason Liubc5833c2011-12-29 06:34:19 +000069int dram_init(void)
70{
Eric Nelson74cf8092013-02-19 10:07:00 +000071 gd->ram_size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE);
Jason Liubc5833c2011-12-29 06:34:19 +000072
Eric Nelson74cf8092013-02-19 10:07:00 +000073 return 0;
Jason Liubc5833c2011-12-29 06:34:19 +000074}
75
Eric Nelson6e142322012-10-03 07:26:38 +000076iomux_v3_cfg_t const uart1_pads[] = {
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +000077 MX6_PAD_SD3_DAT6__UART1_RXD | MUX_PAD_CTRL(UART_PAD_CTRL),
78 MX6_PAD_SD3_DAT7__UART1_TXD | MUX_PAD_CTRL(UART_PAD_CTRL),
Troy Kisky8e7d7b62012-01-12 23:49:25 +000079};
80
Eric Nelson6e142322012-10-03 07:26:38 +000081iomux_v3_cfg_t const uart2_pads[] = {
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +000082 MX6_PAD_EIM_D26__UART2_TXD | MUX_PAD_CTRL(UART_PAD_CTRL),
83 MX6_PAD_EIM_D27__UART2_RXD | MUX_PAD_CTRL(UART_PAD_CTRL),
Jason Liubc5833c2011-12-29 06:34:19 +000084};
85
Troy Kisky9c067822012-07-19 08:18:26 +000086#define PC MUX_PAD_CTRL(I2C_PAD_CTRL)
87
88/* I2C1, SGTL5000 */
89struct i2c_pads_info i2c_pad_info0 = {
90 .scl = {
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +000091 .i2c_mode = MX6_PAD_EIM_D21__I2C1_SCL | PC,
92 .gpio_mode = MX6_PAD_EIM_D21__GPIO_3_21 | PC,
Stefano Babic5fecb362012-08-19 21:33:50 +000093 .gp = IMX_GPIO_NR(3, 21)
Troy Kisky9c067822012-07-19 08:18:26 +000094 },
95 .sda = {
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +000096 .i2c_mode = MX6_PAD_EIM_D28__I2C1_SDA | PC,
97 .gpio_mode = MX6_PAD_EIM_D28__GPIO_3_28 | PC,
Stefano Babic5fecb362012-08-19 21:33:50 +000098 .gp = IMX_GPIO_NR(3, 28)
Troy Kisky9c067822012-07-19 08:18:26 +000099 }
100};
101
102/* I2C2 Camera, MIPI */
103struct i2c_pads_info i2c_pad_info1 = {
104 .scl = {
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +0000105 .i2c_mode = MX6_PAD_KEY_COL3__I2C2_SCL | PC,
106 .gpio_mode = MX6_PAD_KEY_COL3__GPIO_4_12 | PC,
Stefano Babic5fecb362012-08-19 21:33:50 +0000107 .gp = IMX_GPIO_NR(4, 12)
Troy Kisky9c067822012-07-19 08:18:26 +0000108 },
109 .sda = {
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +0000110 .i2c_mode = MX6_PAD_KEY_ROW3__I2C2_SDA | PC,
111 .gpio_mode = MX6_PAD_KEY_ROW3__GPIO_4_13 | PC,
Stefano Babic5fecb362012-08-19 21:33:50 +0000112 .gp = IMX_GPIO_NR(4, 13)
Troy Kisky9c067822012-07-19 08:18:26 +0000113 }
114};
115
116/* I2C3, J15 - RGB connector */
117struct i2c_pads_info i2c_pad_info2 = {
118 .scl = {
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +0000119 .i2c_mode = MX6_PAD_GPIO_5__I2C3_SCL | PC,
120 .gpio_mode = MX6_PAD_GPIO_5__GPIO_1_5 | PC,
Stefano Babic5fecb362012-08-19 21:33:50 +0000121 .gp = IMX_GPIO_NR(1, 5)
Troy Kisky9c067822012-07-19 08:18:26 +0000122 },
123 .sda = {
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +0000124 .i2c_mode = MX6_PAD_GPIO_16__I2C3_SDA | PC,
125 .gpio_mode = MX6_PAD_GPIO_16__GPIO_7_11 | PC,
Stefano Babic5fecb362012-08-19 21:33:50 +0000126 .gp = IMX_GPIO_NR(7, 11)
Troy Kisky9c067822012-07-19 08:18:26 +0000127 }
Troy Kisky31746892012-04-24 17:33:26 +0000128};
129
Eric Nelson6e142322012-10-03 07:26:38 +0000130iomux_v3_cfg_t const usdhc3_pads[] = {
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +0000131 MX6_PAD_SD3_CLK__USDHC3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
132 MX6_PAD_SD3_CMD__USDHC3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
133 MX6_PAD_SD3_DAT0__USDHC3_DAT0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
134 MX6_PAD_SD3_DAT1__USDHC3_DAT1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
135 MX6_PAD_SD3_DAT2__USDHC3_DAT2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
136 MX6_PAD_SD3_DAT3__USDHC3_DAT3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
137 MX6_PAD_SD3_DAT5__GPIO_7_0 | MUX_PAD_CTRL(NO_PAD_CTRL), /* CD */
Jason Liubc5833c2011-12-29 06:34:19 +0000138};
139
Eric Nelson6e142322012-10-03 07:26:38 +0000140iomux_v3_cfg_t const usdhc4_pads[] = {
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +0000141 MX6_PAD_SD4_CLK__USDHC4_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
142 MX6_PAD_SD4_CMD__USDHC4_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
143 MX6_PAD_SD4_DAT0__USDHC4_DAT0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
144 MX6_PAD_SD4_DAT1__USDHC4_DAT1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
145 MX6_PAD_SD4_DAT2__USDHC4_DAT2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
146 MX6_PAD_SD4_DAT3__USDHC4_DAT3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
147 MX6_PAD_NANDF_D6__GPIO_2_6 | MUX_PAD_CTRL(NO_PAD_CTRL), /* CD */
Jason Liubc5833c2011-12-29 06:34:19 +0000148};
149
Eric Nelson6e142322012-10-03 07:26:38 +0000150iomux_v3_cfg_t const enet_pads1[] = {
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +0000151 MX6_PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL),
152 MX6_PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL),
153 MX6_PAD_RGMII_TXC__ENET_RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL),
154 MX6_PAD_RGMII_TD0__ENET_RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
155 MX6_PAD_RGMII_TD1__ENET_RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
156 MX6_PAD_RGMII_TD2__ENET_RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL),
157 MX6_PAD_RGMII_TD3__ENET_RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL),
158 MX6_PAD_RGMII_TX_CTL__RGMII_TX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL),
159 MX6_PAD_ENET_REF_CLK__ENET_TX_CLK | MUX_PAD_CTRL(ENET_PAD_CTRL),
Jason Liu2af81e22012-01-12 22:56:16 +0000160 /* pin 35 - 1 (PHY_AD2) on reset */
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +0000161 MX6_PAD_RGMII_RXC__GPIO_6_30 | MUX_PAD_CTRL(NO_PAD_CTRL),
Jason Liu2af81e22012-01-12 22:56:16 +0000162 /* pin 32 - 1 - (MODE0) all */
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +0000163 MX6_PAD_RGMII_RD0__GPIO_6_25 | MUX_PAD_CTRL(NO_PAD_CTRL),
Jason Liu2af81e22012-01-12 22:56:16 +0000164 /* pin 31 - 1 - (MODE1) all */
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +0000165 MX6_PAD_RGMII_RD1__GPIO_6_27 | MUX_PAD_CTRL(NO_PAD_CTRL),
Jason Liu2af81e22012-01-12 22:56:16 +0000166 /* pin 28 - 1 - (MODE2) all */
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +0000167 MX6_PAD_RGMII_RD2__GPIO_6_28 | MUX_PAD_CTRL(NO_PAD_CTRL),
Jason Liu2af81e22012-01-12 22:56:16 +0000168 /* pin 27 - 1 - (MODE3) all */
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +0000169 MX6_PAD_RGMII_RD3__GPIO_6_29 | MUX_PAD_CTRL(NO_PAD_CTRL),
Jason Liu2af81e22012-01-12 22:56:16 +0000170 /* pin 33 - 1 - (CLK125_EN) 125Mhz clockout enabled */
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +0000171 MX6_PAD_RGMII_RX_CTL__GPIO_6_24 | MUX_PAD_CTRL(NO_PAD_CTRL),
Jason Liu2af81e22012-01-12 22:56:16 +0000172 /* pin 42 PHY nRST */
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +0000173 MX6_PAD_EIM_D23__GPIO_3_23 | MUX_PAD_CTRL(NO_PAD_CTRL),
Jason Liu2af81e22012-01-12 22:56:16 +0000174};
175
Eric Nelson6e142322012-10-03 07:26:38 +0000176iomux_v3_cfg_t const enet_pads2[] = {
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +0000177 MX6_PAD_RGMII_RXC__ENET_RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL),
178 MX6_PAD_RGMII_RD0__ENET_RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
179 MX6_PAD_RGMII_RD1__ENET_RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
180 MX6_PAD_RGMII_RD2__ENET_RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL),
181 MX6_PAD_RGMII_RD3__ENET_RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL),
182 MX6_PAD_RGMII_RX_CTL__RGMII_RX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL),
Jason Liu2af81e22012-01-12 22:56:16 +0000183};
184
Eric Nelson28fdbdd2012-04-25 14:14:04 +0000185/* Button assignments for J14 */
Eric Nelson6e142322012-10-03 07:26:38 +0000186static iomux_v3_cfg_t const button_pads[] = {
Eric Nelson28fdbdd2012-04-25 14:14:04 +0000187 /* Menu */
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +0000188 MX6_PAD_NANDF_D1__GPIO_2_1 | MUX_PAD_CTRL(BUTTON_PAD_CTRL),
Eric Nelson28fdbdd2012-04-25 14:14:04 +0000189 /* Back */
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +0000190 MX6_PAD_NANDF_D2__GPIO_2_2 | MUX_PAD_CTRL(BUTTON_PAD_CTRL),
Eric Nelson28fdbdd2012-04-25 14:14:04 +0000191 /* Labelled Search (mapped to Power under Android) */
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +0000192 MX6_PAD_NANDF_D3__GPIO_2_3 | MUX_PAD_CTRL(BUTTON_PAD_CTRL),
Eric Nelson28fdbdd2012-04-25 14:14:04 +0000193 /* Home */
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +0000194 MX6_PAD_NANDF_D4__GPIO_2_4 | MUX_PAD_CTRL(BUTTON_PAD_CTRL),
Eric Nelson28fdbdd2012-04-25 14:14:04 +0000195 /* Volume Down */
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +0000196 MX6_PAD_GPIO_19__GPIO_4_5 | MUX_PAD_CTRL(BUTTON_PAD_CTRL),
Eric Nelson28fdbdd2012-04-25 14:14:04 +0000197 /* Volume Up */
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +0000198 MX6_PAD_GPIO_18__GPIO_7_13 | MUX_PAD_CTRL(BUTTON_PAD_CTRL),
Eric Nelson28fdbdd2012-04-25 14:14:04 +0000199};
200
Jason Liu2af81e22012-01-12 22:56:16 +0000201static void setup_iomux_enet(void)
202{
Ashok Kumar Reddy5d208812012-09-08 17:56:51 +0530203 gpio_direction_output(IMX_GPIO_NR(3, 23), 0);
204 gpio_direction_output(IMX_GPIO_NR(6, 30), 1);
205 gpio_direction_output(IMX_GPIO_NR(6, 25), 1);
206 gpio_direction_output(IMX_GPIO_NR(6, 27), 1);
207 gpio_direction_output(IMX_GPIO_NR(6, 28), 1);
208 gpio_direction_output(IMX_GPIO_NR(6, 29), 1);
Jason Liu2af81e22012-01-12 22:56:16 +0000209 imx_iomux_v3_setup_multiple_pads(enet_pads1, ARRAY_SIZE(enet_pads1));
Ashok Kumar Reddy5d208812012-09-08 17:56:51 +0530210 gpio_direction_output(IMX_GPIO_NR(6, 24), 1);
Jason Liu2af81e22012-01-12 22:56:16 +0000211
212 /* Need delay 10ms according to KSZ9021 spec */
213 udelay(1000 * 10);
Ashok Kumar Reddy5d208812012-09-08 17:56:51 +0530214 gpio_set_value(IMX_GPIO_NR(3, 23), 1);
Jason Liu2af81e22012-01-12 22:56:16 +0000215
216 imx_iomux_v3_setup_multiple_pads(enet_pads2, ARRAY_SIZE(enet_pads2));
217}
218
Eric Nelson6e142322012-10-03 07:26:38 +0000219iomux_v3_cfg_t const usb_pads[] = {
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +0000220 MX6_PAD_GPIO_17__GPIO_7_12 | MUX_PAD_CTRL(NO_PAD_CTRL),
Wolfgang Grandegger2ea73e92012-02-08 22:33:26 +0000221};
222
Jason Liubc5833c2011-12-29 06:34:19 +0000223static void setup_iomux_uart(void)
224{
Troy Kisky8e7d7b62012-01-12 23:49:25 +0000225 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
Eric Nelson74cf8092013-02-19 10:07:00 +0000226 imx_iomux_v3_setup_multiple_pads(uart2_pads, ARRAY_SIZE(uart2_pads));
Jason Liubc5833c2011-12-29 06:34:19 +0000227}
228
Wolfgang Grandegger2ea73e92012-02-08 22:33:26 +0000229#ifdef CONFIG_USB_EHCI_MX6
230int board_ehci_hcd_init(int port)
231{
232 imx_iomux_v3_setup_multiple_pads(usb_pads, ARRAY_SIZE(usb_pads));
233
234 /* Reset USB hub */
Stefano Babic5fecb362012-08-19 21:33:50 +0000235 gpio_direction_output(IMX_GPIO_NR(7, 12), 0);
Wolfgang Grandegger2ea73e92012-02-08 22:33:26 +0000236 mdelay(2);
Stefano Babic5fecb362012-08-19 21:33:50 +0000237 gpio_set_value(IMX_GPIO_NR(7, 12), 1);
Wolfgang Grandegger2ea73e92012-02-08 22:33:26 +0000238
239 return 0;
240}
241#endif
242
Jason Liubc5833c2011-12-29 06:34:19 +0000243#ifdef CONFIG_FSL_ESDHC
244struct fsl_esdhc_cfg usdhc_cfg[2] = {
Eric Nelson74cf8092013-02-19 10:07:00 +0000245 {USDHC3_BASE_ADDR},
246 {USDHC4_BASE_ADDR},
Jason Liubc5833c2011-12-29 06:34:19 +0000247};
248
249int board_mmc_getcd(struct mmc *mmc)
250{
Eric Nelson74cf8092013-02-19 10:07:00 +0000251 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
252 int ret;
Jason Liubc5833c2011-12-29 06:34:19 +0000253
Eric Nelson74cf8092013-02-19 10:07:00 +0000254 if (cfg->esdhc_base == USDHC3_BASE_ADDR) {
Ashok Kumar Reddy5d208812012-09-08 17:56:51 +0530255 gpio_direction_input(IMX_GPIO_NR(7, 0));
256 ret = !gpio_get_value(IMX_GPIO_NR(7, 0));
Eric Nelson74cf8092013-02-19 10:07:00 +0000257 } else {
Ashok Kumar Reddy5d208812012-09-08 17:56:51 +0530258 gpio_direction_input(IMX_GPIO_NR(2, 6));
259 ret = !gpio_get_value(IMX_GPIO_NR(2, 6));
Eric Nelson74cf8092013-02-19 10:07:00 +0000260 }
Jason Liubc5833c2011-12-29 06:34:19 +0000261
Eric Nelson74cf8092013-02-19 10:07:00 +0000262 return ret;
Jason Liubc5833c2011-12-29 06:34:19 +0000263}
264
265int board_mmc_init(bd_t *bis)
266{
Eric Nelson74cf8092013-02-19 10:07:00 +0000267 s32 status = 0;
268 u32 index = 0;
Jason Liubc5833c2011-12-29 06:34:19 +0000269
Benoît Thébaudeaua2ac1b32012-10-01 08:36:25 +0000270 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
271 usdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC4_CLK);
272
Abbas Razaaad46592013-03-25 09:13:34 +0000273 usdhc_cfg[0].max_bus_width = 4;
274 usdhc_cfg[1].max_bus_width = 4;
275
Eric Nelson74cf8092013-02-19 10:07:00 +0000276 for (index = 0; index < CONFIG_SYS_FSL_USDHC_NUM; ++index) {
277 switch (index) {
278 case 0:
279 imx_iomux_v3_setup_multiple_pads(
280 usdhc3_pads, ARRAY_SIZE(usdhc3_pads));
281 break;
282 case 1:
283 imx_iomux_v3_setup_multiple_pads(
284 usdhc4_pads, ARRAY_SIZE(usdhc4_pads));
Wolfgang Denkf5cdc112012-04-16 23:13:51 +0200285 break;
286 default:
Eric Nelson74cf8092013-02-19 10:07:00 +0000287 printf("Warning: you configured more USDHC controllers"
Wolfgang Denkf5cdc112012-04-16 23:13:51 +0200288 "(%d) then supported by the board (%d)\n",
289 index + 1, CONFIG_SYS_FSL_USDHC_NUM);
Eric Nelson74cf8092013-02-19 10:07:00 +0000290 return status;
291 }
Jason Liubc5833c2011-12-29 06:34:19 +0000292
Eric Nelson74cf8092013-02-19 10:07:00 +0000293 status |= fsl_esdhc_initialize(bis, &usdhc_cfg[index]);
294 }
Jason Liubc5833c2011-12-29 06:34:19 +0000295
Eric Nelson74cf8092013-02-19 10:07:00 +0000296 return status;
Jason Liubc5833c2011-12-29 06:34:19 +0000297}
298#endif
299
Eric Nelson373a1d82012-01-31 07:52:05 +0000300#ifdef CONFIG_MXC_SPI
Eric Nelson6e142322012-10-03 07:26:38 +0000301iomux_v3_cfg_t const ecspi1_pads[] = {
Eric Nelson373a1d82012-01-31 07:52:05 +0000302 /* SS1 */
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +0000303 MX6_PAD_EIM_D19__GPIO_3_19 | MUX_PAD_CTRL(SPI_PAD_CTRL),
304 MX6_PAD_EIM_D17__ECSPI1_MISO | MUX_PAD_CTRL(SPI_PAD_CTRL),
305 MX6_PAD_EIM_D18__ECSPI1_MOSI | MUX_PAD_CTRL(SPI_PAD_CTRL),
306 MX6_PAD_EIM_D16__ECSPI1_SCLK | MUX_PAD_CTRL(SPI_PAD_CTRL),
Eric Nelson373a1d82012-01-31 07:52:05 +0000307};
308
309void setup_spi(void)
310{
Eric Nelsonba54b922012-01-31 07:52:09 +0000311 gpio_direction_output(CONFIG_SF_DEFAULT_CS, 1);
Eric Nelson373a1d82012-01-31 07:52:05 +0000312 imx_iomux_v3_setup_multiple_pads(ecspi1_pads,
313 ARRAY_SIZE(ecspi1_pads));
314}
315#endif
316
Troy Kisky2bf33592012-02-07 14:08:50 +0000317int board_phy_config(struct phy_device *phydev)
Jason Liu2af81e22012-01-12 22:56:16 +0000318{
Jason Liu2af81e22012-01-12 22:56:16 +0000319 /* min rx data delay */
Troy Kisky2bf33592012-02-07 14:08:50 +0000320 ksz9021_phy_extended_write(phydev,
321 MII_KSZ9021_EXT_RGMII_RX_DATA_SKEW, 0x0);
322 /* min tx data delay */
323 ksz9021_phy_extended_write(phydev,
324 MII_KSZ9021_EXT_RGMII_TX_DATA_SKEW, 0x0);
325 /* max rx/tx clock delay, min rx/tx control */
326 ksz9021_phy_extended_write(phydev,
327 MII_KSZ9021_EXT_RGMII_CLOCK_SKEW, 0xf0f0);
328 if (phydev->drv->config)
329 phydev->drv->config(phydev);
Wolfgang Denkf5cdc112012-04-16 23:13:51 +0200330
Jason Liu2af81e22012-01-12 22:56:16 +0000331 return 0;
332}
333
334int board_eth_init(bd_t *bis)
335{
Troy Kisky32369212012-10-22 16:40:47 +0000336 uint32_t base = IMX_FEC_BASE;
337 struct mii_dev *bus = NULL;
338 struct phy_device *phydev = NULL;
Jason Liu2af81e22012-01-12 22:56:16 +0000339 int ret;
340
341 setup_iomux_enet();
342
Troy Kisky32369212012-10-22 16:40:47 +0000343#ifdef CONFIG_FEC_MXC
344 bus = fec_get_miibus(base, -1);
345 if (!bus)
346 return 0;
347 /* scan phy 4,5,6,7 */
348 phydev = phy_find_by_mask(bus, (0xf << 4), PHY_INTERFACE_MODE_RGMII);
349 if (!phydev) {
350 free(bus);
351 return 0;
352 }
353 printf("using phy at %d\n", phydev->addr);
354 ret = fec_probe(bis, -1, base, bus, phydev);
355 if (ret) {
Jason Liu2af81e22012-01-12 22:56:16 +0000356 printf("FEC MXC: %s:failed\n", __func__);
Troy Kisky32369212012-10-22 16:40:47 +0000357 free(phydev);
358 free(bus);
359 }
360#endif
Jason Liu2af81e22012-01-12 22:56:16 +0000361 return 0;
362}
363
Eric Nelson28fdbdd2012-04-25 14:14:04 +0000364static void setup_buttons(void)
365{
366 imx_iomux_v3_setup_multiple_pads(button_pads,
367 ARRAY_SIZE(button_pads));
368}
369
Eric Nelson3996a962012-05-01 09:55:11 +0000370#ifdef CONFIG_CMD_SATA
371
372int setup_sata(void)
373{
374 struct iomuxc_base_regs *const iomuxc_regs
375 = (struct iomuxc_base_regs *) IOMUXC_BASE_ADDR;
376 int ret = enable_sata_clock();
377 if (ret)
378 return ret;
379
380 clrsetbits_le32(&iomuxc_regs->gpr[13],
381 IOMUXC_GPR13_SATA_MASK,
382 IOMUXC_GPR13_SATA_PHY_8_RXEQ_3P0DB
383 |IOMUXC_GPR13_SATA_PHY_7_SATA2M
384 |IOMUXC_GPR13_SATA_SPEED_3G
385 |(3<<IOMUXC_GPR13_SATA_PHY_6_SHIFT)
386 |IOMUXC_GPR13_SATA_SATA_PHY_5_SS_DISABLED
387 |IOMUXC_GPR13_SATA_SATA_PHY_4_ATTEN_9_16
388 |IOMUXC_GPR13_SATA_PHY_3_TXBOOST_0P00_DB
389 |IOMUXC_GPR13_SATA_PHY_2_TX_1P104V
390 |IOMUXC_GPR13_SATA_PHY_1_SLOW);
391
392 return 0;
393}
394#endif
395
Eric Nelsone58010b2012-10-03 07:28:43 +0000396#if defined(CONFIG_VIDEO_IPUV3)
397
398static iomux_v3_cfg_t const backlight_pads[] = {
399 /* Backlight on RGB connector: J15 */
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +0000400 MX6_PAD_SD1_DAT3__GPIO_1_21 | MUX_PAD_CTRL(NO_PAD_CTRL),
Eric Nelsone58010b2012-10-03 07:28:43 +0000401#define RGB_BACKLIGHT_GP IMX_GPIO_NR(1, 21)
402
403 /* Backlight on LVDS connector: J6 */
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +0000404 MX6_PAD_SD1_CMD__GPIO_1_18 | MUX_PAD_CTRL(NO_PAD_CTRL),
Eric Nelsone58010b2012-10-03 07:28:43 +0000405#define LVDS_BACKLIGHT_GP IMX_GPIO_NR(1, 18)
406};
407
408static iomux_v3_cfg_t const rgb_pads[] = {
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +0000409 MX6_PAD_DI0_DISP_CLK__IPU1_DI0_DISP_CLK,
410 MX6_PAD_DI0_PIN15__IPU1_DI0_PIN15,
411 MX6_PAD_DI0_PIN2__IPU1_DI0_PIN2,
412 MX6_PAD_DI0_PIN3__IPU1_DI0_PIN3,
413 MX6_PAD_DI0_PIN4__GPIO_4_20,
414 MX6_PAD_DISP0_DAT0__IPU1_DISP0_DAT_0,
415 MX6_PAD_DISP0_DAT1__IPU1_DISP0_DAT_1,
416 MX6_PAD_DISP0_DAT2__IPU1_DISP0_DAT_2,
417 MX6_PAD_DISP0_DAT3__IPU1_DISP0_DAT_3,
418 MX6_PAD_DISP0_DAT4__IPU1_DISP0_DAT_4,
419 MX6_PAD_DISP0_DAT5__IPU1_DISP0_DAT_5,
420 MX6_PAD_DISP0_DAT6__IPU1_DISP0_DAT_6,
421 MX6_PAD_DISP0_DAT7__IPU1_DISP0_DAT_7,
422 MX6_PAD_DISP0_DAT8__IPU1_DISP0_DAT_8,
423 MX6_PAD_DISP0_DAT9__IPU1_DISP0_DAT_9,
424 MX6_PAD_DISP0_DAT10__IPU1_DISP0_DAT_10,
425 MX6_PAD_DISP0_DAT11__IPU1_DISP0_DAT_11,
426 MX6_PAD_DISP0_DAT12__IPU1_DISP0_DAT_12,
427 MX6_PAD_DISP0_DAT13__IPU1_DISP0_DAT_13,
428 MX6_PAD_DISP0_DAT14__IPU1_DISP0_DAT_14,
429 MX6_PAD_DISP0_DAT15__IPU1_DISP0_DAT_15,
430 MX6_PAD_DISP0_DAT16__IPU1_DISP0_DAT_16,
431 MX6_PAD_DISP0_DAT17__IPU1_DISP0_DAT_17,
432 MX6_PAD_DISP0_DAT18__IPU1_DISP0_DAT_18,
433 MX6_PAD_DISP0_DAT19__IPU1_DISP0_DAT_19,
434 MX6_PAD_DISP0_DAT20__IPU1_DISP0_DAT_20,
435 MX6_PAD_DISP0_DAT21__IPU1_DISP0_DAT_21,
436 MX6_PAD_DISP0_DAT22__IPU1_DISP0_DAT_22,
437 MX6_PAD_DISP0_DAT23__IPU1_DISP0_DAT_23,
Eric Nelsone58010b2012-10-03 07:28:43 +0000438};
439
440struct display_info_t {
441 int bus;
442 int addr;
443 int pixfmt;
444 int (*detect)(struct display_info_t const *dev);
445 void (*enable)(struct display_info_t const *dev);
446 struct fb_videomode mode;
447};
448
449
450static int detect_hdmi(struct display_info_t const *dev)
451{
Fabio Estevam1b097cf2013-02-28 14:35:02 +0000452 struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
453 return readb(&hdmi->phy_stat0) & HDMI_PHY_HPD;
Eric Nelsone58010b2012-10-03 07:28:43 +0000454}
455
456static void enable_hdmi(struct display_info_t const *dev)
457{
Fabio Estevam1b097cf2013-02-28 14:35:02 +0000458 struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
Eric Nelsone58010b2012-10-03 07:28:43 +0000459 u8 reg;
460 printf("%s: setup HDMI monitor\n", __func__);
Fabio Estevam1b097cf2013-02-28 14:35:02 +0000461 reg = readb(&hdmi->phy_conf0);
Eric Nelsone58010b2012-10-03 07:28:43 +0000462 reg |= HDMI_PHY_CONF0_PDZ_MASK;
Fabio Estevam1b097cf2013-02-28 14:35:02 +0000463 writeb(reg, &hdmi->phy_conf0);
464
Eric Nelsone58010b2012-10-03 07:28:43 +0000465 udelay(3000);
466 reg |= HDMI_PHY_CONF0_ENTMDS_MASK;
Fabio Estevam1b097cf2013-02-28 14:35:02 +0000467 writeb(reg, &hdmi->phy_conf0);
Eric Nelsone58010b2012-10-03 07:28:43 +0000468 udelay(3000);
469 reg |= HDMI_PHY_CONF0_GEN2_TXPWRON_MASK;
Fabio Estevam1b097cf2013-02-28 14:35:02 +0000470 writeb(reg, &hdmi->phy_conf0);
471 writeb(HDMI_MC_PHYRSTZ_ASSERT, &hdmi->mc_phyrstz);
Eric Nelsone58010b2012-10-03 07:28:43 +0000472}
473
474static int detect_i2c(struct display_info_t const *dev)
475{
476 return ((0 == i2c_set_bus_num(dev->bus))
477 &&
478 (0 == i2c_probe(dev->addr)));
479}
480
481static void enable_lvds(struct display_info_t const *dev)
482{
483 struct iomuxc *iomux = (struct iomuxc *)
484 IOMUXC_BASE_ADDR;
485 u32 reg = readl(&iomux->gpr[2]);
486 reg |= IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT;
487 writel(reg, &iomux->gpr[2]);
488 gpio_direction_output(LVDS_BACKLIGHT_GP, 1);
489}
490
491static void enable_rgb(struct display_info_t const *dev)
492{
493 imx_iomux_v3_setup_multiple_pads(
494 rgb_pads,
495 ARRAY_SIZE(rgb_pads));
496 gpio_direction_output(RGB_BACKLIGHT_GP, 1);
497}
498
499static struct display_info_t const displays[] = {{
500 .bus = -1,
501 .addr = 0,
502 .pixfmt = IPU_PIX_FMT_RGB24,
503 .detect = detect_hdmi,
504 .enable = enable_hdmi,
505 .mode = {
506 .name = "HDMI",
507 .refresh = 60,
508 .xres = 1024,
509 .yres = 768,
510 .pixclock = 15385,
511 .left_margin = 220,
512 .right_margin = 40,
513 .upper_margin = 21,
514 .lower_margin = 7,
515 .hsync_len = 60,
516 .vsync_len = 10,
517 .sync = FB_SYNC_EXT,
518 .vmode = FB_VMODE_NONINTERLACED
519} }, {
520 .bus = 2,
521 .addr = 0x4,
522 .pixfmt = IPU_PIX_FMT_LVDS666,
523 .detect = detect_i2c,
524 .enable = enable_lvds,
525 .mode = {
526 .name = "Hannstar-XGA",
527 .refresh = 60,
528 .xres = 1024,
529 .yres = 768,
530 .pixclock = 15385,
531 .left_margin = 220,
532 .right_margin = 40,
533 .upper_margin = 21,
534 .lower_margin = 7,
535 .hsync_len = 60,
536 .vsync_len = 10,
537 .sync = FB_SYNC_EXT,
538 .vmode = FB_VMODE_NONINTERLACED
539} }, {
540 .bus = 2,
541 .addr = 0x38,
542 .pixfmt = IPU_PIX_FMT_LVDS666,
543 .detect = detect_i2c,
544 .enable = enable_lvds,
545 .mode = {
546 .name = "wsvga-lvds",
547 .refresh = 60,
548 .xres = 1024,
549 .yres = 600,
550 .pixclock = 15385,
551 .left_margin = 220,
552 .right_margin = 40,
553 .upper_margin = 21,
554 .lower_margin = 7,
555 .hsync_len = 60,
556 .vsync_len = 10,
557 .sync = FB_SYNC_EXT,
558 .vmode = FB_VMODE_NONINTERLACED
559} }, {
560 .bus = 2,
561 .addr = 0x48,
562 .pixfmt = IPU_PIX_FMT_RGB666,
563 .detect = detect_i2c,
564 .enable = enable_rgb,
565 .mode = {
566 .name = "wvga-rgb",
567 .refresh = 57,
568 .xres = 800,
569 .yres = 480,
570 .pixclock = 37037,
571 .left_margin = 40,
572 .right_margin = 60,
573 .upper_margin = 10,
574 .lower_margin = 10,
575 .hsync_len = 20,
576 .vsync_len = 10,
577 .sync = 0,
578 .vmode = FB_VMODE_NONINTERLACED
579} } };
580
581int board_video_skip(void)
582{
583 int i;
584 int ret;
585 char const *panel = getenv("panel");
586 if (!panel) {
587 for (i = 0; i < ARRAY_SIZE(displays); i++) {
588 struct display_info_t const *dev = displays+i;
589 if (dev->detect(dev)) {
590 panel = dev->mode.name;
591 printf("auto-detected panel %s\n", panel);
592 break;
593 }
594 }
595 if (!panel) {
596 panel = displays[0].mode.name;
597 printf("No panel detected: default to %s\n", panel);
598 }
599 } else {
600 for (i = 0; i < ARRAY_SIZE(displays); i++) {
601 if (!strcmp(panel, displays[i].mode.name))
602 break;
603 }
604 }
605 if (i < ARRAY_SIZE(displays)) {
606 ret = ipuv3_fb_init(&displays[i].mode, 0,
607 displays[i].pixfmt);
608 if (!ret) {
609 displays[i].enable(displays+i);
610 printf("Display: %s (%ux%u)\n",
611 displays[i].mode.name,
612 displays[i].mode.xres,
613 displays[i].mode.yres);
614 } else
615 printf("LCD %s cannot be configured: %d\n",
616 displays[i].mode.name, ret);
617 } else {
618 printf("unsupported panel %s\n", panel);
619 ret = -EINVAL;
620 }
621 return (0 != ret);
622}
623
624static void setup_display(void)
625{
626 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
627 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
628 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
Fabio Estevam1b097cf2013-02-28 14:35:02 +0000629 struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
Eric Nelsone58010b2012-10-03 07:28:43 +0000630
631 int reg;
632
633 /* Turn on LDB0,IPU,IPU DI0 clocks */
634 reg = __raw_readl(&mxc_ccm->CCGR3);
635 reg |= MXC_CCM_CCGR3_IPU1_IPU_DI0_OFFSET
636 |MXC_CCM_CCGR3_LDB_DI0_MASK;
637 writel(reg, &mxc_ccm->CCGR3);
638
639 /* Turn on HDMI PHY clock */
640 reg = __raw_readl(&mxc_ccm->CCGR2);
641 reg |= MXC_CCM_CCGR2_HDMI_TX_IAHBCLK_MASK
642 |MXC_CCM_CCGR2_HDMI_TX_ISFRCLK_MASK;
643 writel(reg, &mxc_ccm->CCGR2);
644
645 /* clear HDMI PHY reset */
Fabio Estevam1b097cf2013-02-28 14:35:02 +0000646 writeb(HDMI_MC_PHYRSTZ_DEASSERT, &hdmi->mc_phyrstz);
Eric Nelsone58010b2012-10-03 07:28:43 +0000647
648 /* set PFD1_FRAC to 0x13 == 455 MHz (480*18)/0x13 */
649 writel(ANATOP_PFD_480_PFD1_FRAC_MASK, &anatop->pfd_480_clr);
650 writel(0x13<<ANATOP_PFD_480_PFD1_FRAC_SHIFT, &anatop->pfd_480_set);
651
652 /* set LDB0, LDB1 clk select to 011/011 */
653 reg = readl(&mxc_ccm->cs2cdr);
654 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
655 |MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
656 reg |= (3<<MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)
657 |(3<<MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
658 writel(reg, &mxc_ccm->cs2cdr);
659
660 reg = readl(&mxc_ccm->cscmr2);
661 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV;
662 writel(reg, &mxc_ccm->cscmr2);
663
664 reg = readl(&mxc_ccm->chsccdr);
665 reg &= ~(MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK
666 |MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK
667 |MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK);
668 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
669 <<MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET)
670 |(CHSCCDR_PODF_DIVIDE_BY_3
671 <<MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET)
672 |(CHSCCDR_IPU_PRE_CLK_540M_PFD
673 <<MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET);
674 writel(reg, &mxc_ccm->chsccdr);
675
676 reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
677 |IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH
678 |IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW
679 |IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG
680 |IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT
681 |IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
682 |IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT
683 |IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED
684 |IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0;
685 writel(reg, &iomux->gpr[2]);
686
687 reg = readl(&iomux->gpr[3]);
688 reg = (reg & ~IOMUXC_GPR3_LVDS0_MUX_CTL_MASK)
689 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0
690 <<IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET);
691 writel(reg, &iomux->gpr[3]);
692
693 /* backlights off until needed */
694 imx_iomux_v3_setup_multiple_pads(backlight_pads,
695 ARRAY_SIZE(backlight_pads));
696 gpio_direction_input(LVDS_BACKLIGHT_GP);
697 gpio_direction_input(RGB_BACKLIGHT_GP);
698}
699#endif
700
Jason Liubc5833c2011-12-29 06:34:19 +0000701int board_early_init_f(void)
702{
Eric Nelson28fdbdd2012-04-25 14:14:04 +0000703 setup_iomux_uart();
704 setup_buttons();
Jason Liubc5833c2011-12-29 06:34:19 +0000705
Eric Nelsone58010b2012-10-03 07:28:43 +0000706#if defined(CONFIG_VIDEO_IPUV3)
707 setup_display();
708#endif
Eric Nelson28fdbdd2012-04-25 14:14:04 +0000709 return 0;
Jason Liubc5833c2011-12-29 06:34:19 +0000710}
711
Eric Nelsone58010b2012-10-03 07:28:43 +0000712/*
713 * Do not overwrite the console
714 * Use always serial for U-Boot console
715 */
716int overwrite_console(void)
717{
718 return 1;
719}
720
Jason Liubc5833c2011-12-29 06:34:19 +0000721int board_init(void)
722{
Eric Nelson74cf8092013-02-19 10:07:00 +0000723 /* address of boot parameters */
724 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
Jason Liubc5833c2011-12-29 06:34:19 +0000725
Eric Nelsond928a8f2012-02-26 12:03:15 +0000726#ifdef CONFIG_MXC_SPI
727 setup_spi();
728#endif
Troy Kisky9c067822012-07-19 08:18:26 +0000729 setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info0);
730 setup_i2c(1, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info1);
731 setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info2);
Eric Nelsond928a8f2012-02-26 12:03:15 +0000732
Eric Nelson3996a962012-05-01 09:55:11 +0000733#ifdef CONFIG_CMD_SATA
734 setup_sata();
735#endif
736
Eric Nelson74cf8092013-02-19 10:07:00 +0000737 return 0;
Jason Liubc5833c2011-12-29 06:34:19 +0000738}
739
740int checkboard(void)
741{
Eric Nelson74cf8092013-02-19 10:07:00 +0000742 puts("Board: MX6Q-Sabre Lite\n");
Jason Liubc5833c2011-12-29 06:34:19 +0000743
Eric Nelson74cf8092013-02-19 10:07:00 +0000744 return 0;
Jason Liubc5833c2011-12-29 06:34:19 +0000745}
Eric Nelson28fdbdd2012-04-25 14:14:04 +0000746
747struct button_key {
748 char const *name;
749 unsigned gpnum;
750 char ident;
751};
752
753static struct button_key const buttons[] = {
Stefano Babic5fecb362012-08-19 21:33:50 +0000754 {"back", IMX_GPIO_NR(2, 2), 'B'},
755 {"home", IMX_GPIO_NR(2, 4), 'H'},
756 {"menu", IMX_GPIO_NR(2, 1), 'M'},
757 {"search", IMX_GPIO_NR(2, 3), 'S'},
758 {"volup", IMX_GPIO_NR(7, 13), 'V'},
759 {"voldown", IMX_GPIO_NR(4, 5), 'v'},
Eric Nelson28fdbdd2012-04-25 14:14:04 +0000760};
761
762/*
763 * generate a null-terminated string containing the buttons pressed
764 * returns number of keys pressed
765 */
766static int read_keys(char *buf)
767{
768 int i, numpressed = 0;
769 for (i = 0; i < ARRAY_SIZE(buttons); i++) {
770 if (!gpio_get_value(buttons[i].gpnum))
771 buf[numpressed++] = buttons[i].ident;
772 }
773 buf[numpressed] = '\0';
774 return numpressed;
775}
776
777static int do_kbd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
778{
779 char envvalue[ARRAY_SIZE(buttons)+1];
780 int numpressed = read_keys(envvalue);
781 setenv("keybd", envvalue);
782 return numpressed == 0;
783}
784
785U_BOOT_CMD(
786 kbd, 1, 1, do_kbd,
787 "Tests for keypresses, sets 'keybd' environment variable",
788 "Returns 0 (true) to shell if key is pressed."
789);
790
791#ifdef CONFIG_PREBOOT
792static char const kbd_magic_prefix[] = "key_magic";
793static char const kbd_command_prefix[] = "key_cmd";
794
795static void preboot_keys(void)
796{
797 int numpressed;
798 char keypress[ARRAY_SIZE(buttons)+1];
799 numpressed = read_keys(keypress);
800 if (numpressed) {
801 char *kbd_magic_keys = getenv("magic_keys");
802 char *suffix;
803 /*
804 * loop over all magic keys
805 */
806 for (suffix = kbd_magic_keys; *suffix; ++suffix) {
807 char *keys;
808 char magic[sizeof(kbd_magic_prefix) + 1];
809 sprintf(magic, "%s%c", kbd_magic_prefix, *suffix);
810 keys = getenv(magic);
811 if (keys) {
812 if (!strcmp(keys, keypress))
813 break;
814 }
815 }
816 if (*suffix) {
817 char cmd_name[sizeof(kbd_command_prefix) + 1];
818 char *cmd;
819 sprintf(cmd_name, "%s%c", kbd_command_prefix, *suffix);
820 cmd = getenv(cmd_name);
821 if (cmd) {
822 setenv("preboot", cmd);
823 return;
824 }
825 }
826 }
827}
828#endif
829
Troy Kiskybb05b402012-08-15 10:31:21 +0000830#ifdef CONFIG_CMD_BMODE
831static const struct boot_mode board_boot_modes[] = {
832 /* 4 bit bus width */
833 {"mmc0", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
834 {"mmc1", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)},
835 {NULL, 0},
836};
837#endif
838
Eric Nelson28fdbdd2012-04-25 14:14:04 +0000839int misc_init_r(void)
840{
841#ifdef CONFIG_PREBOOT
842 preboot_keys();
843#endif
Troy Kiskybb05b402012-08-15 10:31:21 +0000844
845#ifdef CONFIG_CMD_BMODE
846 add_board_boot_modes(board_boot_modes);
847#endif
Eric Nelson28fdbdd2012-04-25 14:14:04 +0000848 return 0;
849}