]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/kosagi/novena/novena.c
e7a6adb6115d986cb9ab97e4dd27d295ffc26011
[karo-tx-uboot.git] / board / kosagi / novena / novena.c
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 | DEV_FLAGS_SYSTEM,
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         button_input.read_keys = novena_gpio_button_read_keys;
92
93         error = input_stdio_register(&dev);
94         if (error)
95                 return error;
96
97         return 0;
98 }
99 #endif
100
101 /*
102  * SDHC
103  */
104 #ifdef CONFIG_FSL_ESDHC
105 static struct fsl_esdhc_cfg usdhc_cfg[] = {
106         { USDHC3_BASE_ADDR, 0, 4 },     /* Micro SD */
107         { USDHC2_BASE_ADDR, 0, 4 },     /* Big SD */
108 };
109
110 int board_mmc_getcd(struct mmc *mmc)
111 {
112         struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
113
114         /* There is no CD for a microSD card, assume always present. */
115         if (cfg->esdhc_base == USDHC3_BASE_ADDR)
116                 return 1;
117         else
118                 return !gpio_get_value(NOVENA_SD_CD);
119 }
120
121 int board_mmc_getwp(struct mmc *mmc)
122 {
123         struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
124
125         /* There is no WP for a microSD card, assume always read-write. */
126         if (cfg->esdhc_base == USDHC3_BASE_ADDR)
127                 return 0;
128         else
129                 return gpio_get_value(NOVENA_SD_WP);
130 }
131
132
133 int board_mmc_init(bd_t *bis)
134 {
135         s32 status = 0;
136         int index;
137
138         usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
139         usdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
140
141         /* Big SD write-protect and card-detect */
142         gpio_direction_input(NOVENA_SD_WP);
143         gpio_direction_input(NOVENA_SD_CD);
144
145         for (index = 0; index < ARRAY_SIZE(usdhc_cfg); index++) {
146                 status = fsl_esdhc_initialize(bis, &usdhc_cfg[index]);
147                 if (status)
148                         return status;
149         }
150
151         return status;
152 }
153 #endif
154
155 int board_early_init_f(void)
156 {
157 #if defined(CONFIG_VIDEO_IPUV3)
158         setup_display_clock();
159 #endif
160
161         return 0;
162 }
163
164 int board_init(void)
165 {
166         /* address of boot parameters */
167         gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
168
169 #ifdef CONFIG_CMD_SATA
170         setup_sata();
171 #endif
172
173         return 0;
174 }
175
176 int checkboard(void)
177 {
178         puts("Board: Novena 4x\n");
179         return 0;
180 }
181
182 int dram_init(void)
183 {
184         gd->ram_size = imx_ddr_size();
185         return 0;
186 }
187
188 /* setup board specific PMIC */
189 int power_init_board(void)
190 {
191         struct pmic *p;
192         u32 reg;
193         int ret;
194
195         power_pfuze100_init(1);
196         p = pmic_get("PFUZE100");
197         if (!p)
198                 return -EINVAL;
199
200         ret = pmic_probe(p);
201         if (ret)
202                 return ret;
203
204         pmic_reg_read(p, PFUZE100_DEVICEID, &reg);
205         printf("PMIC:  PFUZE100 ID=0x%02x\n", reg);
206
207         /* Set SWBST to 5.0V and enable (for USB) */
208         pmic_reg_read(p, PFUZE100_SWBSTCON1, &reg);
209         reg &= ~(SWBST_MODE_MASK | SWBST_VOL_MASK);
210         reg |= (SWBST_5_00V | SWBST_MODE_AUTO);
211         pmic_reg_write(p, PFUZE100_SWBSTCON1, reg);
212
213         return 0;
214 }
215
216 /* EEPROM configuration data */
217 struct novena_eeprom_data {
218         uint8_t         signature[6];
219         uint8_t         version;
220         uint8_t         reserved;
221         uint32_t        serial;
222         uint8_t         mac[6];
223         uint16_t        features;
224 };
225
226 int misc_init_r(void)
227 {
228         struct novena_eeprom_data data;
229         uchar *datap = (uchar *)&data;
230         const char *signature = "Novena";
231         int ret;
232
233         /* If 'ethaddr' is already set, do nothing. */
234         if (getenv("ethaddr"))
235                 return 0;
236
237         /* EEPROM is at bus 2. */
238         ret = i2c_set_bus_num(2);
239         if (ret) {
240                 puts("Cannot select EEPROM I2C bus.\n");
241                 return 0;
242         }
243
244         /* EEPROM is at address 0x56. */
245         ret = eeprom_read(0x56, 0, datap, sizeof(data));
246         if (ret) {
247                 puts("Cannot read I2C EEPROM.\n");
248                 return 0;
249         }
250
251         /* Check EEPROM signature. */
252         if (memcmp(data.signature, signature, 6)) {
253                 puts("Invalid I2C EEPROM signature.\n");
254                 return 0;
255         }
256
257         /* Set ethernet address from EEPROM. */
258         eth_setenv_enetaddr("ethaddr", data.mac);
259
260         return ret;
261 }