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