2 * Board init file for TXSD-410E
4 * (C) Copyright 2017 Lothar Waßmann <LW@KARO-electronics.de>
6 * SPDX-License-Identifier: GPL-2.0+
12 #include <fdt_support.h>
17 #include <usb_ether.h>
20 #include <asm/armv8/mmu.h>
23 #include <spmi/spmi.h>
24 #include <power/pmic.h>
25 #include <power/pmic-qcom-smd-rpm.h>
27 #include "../common/karo.h"
29 DECLARE_GLOBAL_DATA_PTR;
31 #ifdef CONFIG_SHOW_ACTIVITY
39 static int led_state = LED_STATE_INIT;
41 #define FDT_USER_LED_LABEL "txsd-410e:green:user1"
43 void show_activity(int arg)
45 static struct udevice *led_dev;
49 if (led_state == LED_STATE_ACTIVE) {
52 if (get_timer(last) > CONFIG_SYS_HZ) {
55 ret = led_set_on(led_dev, led_on);
59 } else if (led_state == LED_STATE_DISABLED) {
61 } else if (led_state == LED_STATE_INIT) {
62 ret = led_get_by_label(FDT_USER_LED_LABEL, &led_dev);
64 printf("No '%s' LED found in DTB\n",
69 led_state = LED_STATE_ACTIVE;
71 printf("Invalid LED state: %d @ %p\n", led_state, &led_state);
77 led_state = LED_STATE_DISABLED;
82 vidinfo_t panel_info = {
83 /* set to max. size supported by SoC */
87 .vl_bpix = LCD_COLOR32, /* Bits per pixel, 0: 1bpp, 1: 2bpp, 2: 4bpp, 3: 8bpp ... */
90 static int lcd_enabled = 1;
91 static int lcd_bl_polarity;
92 static struct gpio_desc lcd_bl_gpio;
96 if (lcd_bl_gpio.dev) {
97 dm_gpio_set_dir_flags(&lcd_bl_gpio, GPIOD_IS_OUT |
98 (lcd_bl_polarity ? GPIOD_ACTIVE_LOW : 0));
102 void lcd_ctrl_init(void *lcdbase)
104 int color_depth = 24;
105 const char *video_mode = karo_get_vmode(getenv("video_mode"));
109 struct fb_videomode *p;
110 struct fb_videomode fb_mode;
111 int xres_set = 0, yres_set = 0, bpp_set = 0, refresh_set = 0;
113 if (karo_get_fb_mode(NULL, &p) <= 0)
117 debug("LCD disabled\n");
121 if (had_ctrlc() || video_mode == NULL) {
122 debug("Disabling LCD\n");
125 setenv("splashimage", NULL);
130 karo_fdt_get_backlight_gpio(gd->fdt_blob, &lcd_bl_gpio);
131 lcd_bl_polarity = karo_fdt_get_backlight_polarity(gd->fdt_blob);
134 if (karo_fdt_get_fb_mode(gd->fdt_blob, video_mode, &fb_mode) == 0) {
136 debug("Using video mode from FDT\n");
138 if (fb_mode.xres > panel_info.vl_col ||
139 fb_mode.yres > panel_info.vl_row) {
140 printf("video resolution from DT: %dx%d exceeds hardware limits: %dx%d\n",
141 fb_mode.xres, fb_mode.yres,
142 panel_info.vl_col, panel_info.vl_row);
148 debug("Trying compiled-in video modes\n");
149 while (p->name != NULL) {
150 if (strcmp(p->name, vm) == 0) {
151 debug("Using video mode: '%s'\n", p->name);
158 debug("Trying to decode video_mode: '%s'\n", vm);
159 while (*vm != '\0') {
160 if (*vm >= '0' && *vm <= '9') {
163 val = simple_strtoul(vm, &end, 0);
166 if (val > panel_info.vl_col)
167 val = panel_info.vl_col;
169 panel_info.vl_col = val;
171 } else if (!yres_set) {
172 if (val > panel_info.vl_row)
173 val = panel_info.vl_row;
175 panel_info.vl_row = val;
177 } else if (!bpp_set) {
185 printf("Invalid color depth: '%.*s' in video_mode; using default: '%u'\n",
186 (int)(end - vm), vm, color_depth);
189 } else if (!refresh_set) {
216 if (p->xres == 0 || p->yres == 0) {
217 int num_modes = karo_get_fb_mode(NULL, &p);
220 printf("Invalid video mode: %s\n", getenv("video_mode"));
222 printf("Supported video modes are:");
223 for (i = 0; i < num_modes; i++, p++) {
225 printf(" %s", p->name);
230 if (p->xres > panel_info.vl_col || p->yres > panel_info.vl_row) {
231 printf("video resolution: %dx%d exceeds hardware limits: %dx%d\n",
232 p->xres, p->yres, panel_info.vl_col, panel_info.vl_row);
236 panel_info.vl_col = p->xres;
237 panel_info.vl_row = p->yres;
239 switch (color_depth) {
241 panel_info.vl_bpix = LCD_COLOR8;
244 panel_info.vl_bpix = LCD_COLOR16;
247 panel_info.vl_bpix = LCD_COLOR32;
250 p->pixclock = KHZ2PICOS(refresh *
251 (p->xres + p->left_margin + p->right_margin + p->hsync_len) *
252 (p->yres + p->upper_margin + p->lower_margin + p->vsync_len) /
254 debug("Pixel clock set to %lu.%03lu MHz\n",
255 PICOS2KHZ(p->pixclock) / 1000, PICOS2KHZ(p->pixclock) % 1000);
260 debug("Creating new display-timing node from '%s'\n",
262 ret = karo_fdt_create_fb_mode(working_fdt, video_mode, p);
264 printf("Failed to create new display-timing node from '%s': %d\n",
269 gpio_request_array(stk5_lcd_gpios, ARRAY_SIZE(stk5_lcd_gpios));
270 imx_iomux_v3_setup_multiple_pads(stk5_lcd_pads,
271 ARRAY_SIZE(stk5_lcd_pads));
273 if (karo_load_splashimage(0) == 0) {
274 debug("Initializing LCD controller\n");
276 debug("Skipping initialization of LCD controller\n");
282 panel_info.vl_col = 0;
283 panel_info.vl_row = 0;
285 #endif /* CONFIG_LCD */
287 void txsd_mmc_preinit(void)
289 struct udevice *mmcdev;
291 for (uclass_first_device(UCLASS_MMC, &mmcdev); mmcdev;
292 uclass_next_device(&mmcdev)) {
293 struct mmc *m = mmc_get_mmc_dev(mmcdev);
295 mmc_set_preinit(m, 1);
302 const struct mm_region *mm = mem_map;
305 for (i = 0; mm->size; i++, mm++) {
306 printf("MMU region[%d]=%08llx..%08llx -> %08llx..%08llx size: %08llx Attrs: %08llx\n",
307 i, mm->phys, mm->phys + mm->size - 1,
308 mm->virt, mm->virt + mm->size - 1, mm->size, mm->attrs);
311 #if CONFIG_NR_DRAM_BANKS == 1
312 gd->ram_size = PHYS_SDRAM_1_SIZE;
314 gd->ram_size = PHYS_SDRAM_1_SIZE + PHYS_SDRAM_2_SIZE;
319 void dram_init_banksize(void)
321 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
322 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
323 printf("RAM bank 0 size set to %lluMiB\n", gd->bd->bi_dram[0].size / SZ_1M);
324 #if CONFIG_NR_DRAM_BANKS > 1
325 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
326 gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
327 printf("RAM bank 1 size set to %lluMiB\n", gd->bd->bi_dram[1].size / SZ_1M);
329 printf("Total RAM size: %lluMiB\n", gd->ram_size / SZ_1M);
332 /* run with default environment */
336 printf("<CTRL-C> detected; safeboot enabled\n");
343 /* run with env from mass storage device */
344 static inline int fdt_err_to_errno(int fdterr)
347 case FDT_ERR_NOTFOUND:
351 case FDT_ERR_NOSPACE:
353 case FDT_ERR_BADOFFSET:
354 case FDT_ERR_BADPATH:
355 case FDT_ERR_BADPHANDLE:
356 case FDT_ERR_BADSTATE:
358 case FDT_ERR_TRUNCATED:
360 case FDT_ERR_BADMAGIC:
361 case FDT_ERR_BADVERSION:
362 case FDT_ERR_BADSTRUCTURE:
363 case FDT_ERR_BADLAYOUT:
364 case FDT_ERR_INTERNAL:
365 case FDT_ERR_BADNCELLS:
366 case FDT_ERR_TOODEEP:
372 int board_prepare_usb(enum usb_init_type type)
374 static struct gpio_desc vbusen;
378 printf("Setting up USB port as %s\n",
379 type == USB_INIT_HOST ? "host" :
380 USB_INIT_DEVICE ? "device" : "invalid");
381 if (type != USB_INIT_HOST && type != USB_INIT_DEVICE)
382 printf("Invalid USB type: %08x\n", type);
385 int off = fdt_path_offset(gd->fdt_blob, "usbhost");
388 printf("Could not find 'usbost' node: %s\n",
392 ret = gpio_request_by_name_nodev(gd->fdt_blob, off,
393 "switch-gpio", 0, &vbusen, 0);
395 printf("Failed to request VBUSEN GPIO: %d\n", ret);
401 ret = dm_gpio_set_value(&vbusen, type == USB_INIT_HOST);
403 ret = dm_gpio_set_dir_flags(&vbusen, GPIOD_IS_OUT);
405 ret = dm_gpio_set_value(&vbusen, type == USB_INIT_HOST);
410 static int karo_spmi_init(void)
415 ret = uclass_get_device_by_name(UCLASS_SPMI, "spmi", &dev);
419 /* Configure PON_PS_HOLD_RESET_CTL for HARD reset */
420 ret = spmi_reg_write(dev, 0, 8, 0x5a, 7);
424 /* Check for <CTRL-C> - if pressed - stop autoboot */
425 int misc_init_r(void)
427 unsigned long fdt_addr __maybe_unused = getenv_ulong("fdtaddr", 16, 0);
433 setenv_ulong("safeboot", 1);
436 setenv("safeboot", NULL);
438 ret = karo_spmi_init();
440 printf("Failed to initialize SPMI interface: %d\n", ret);
444 if (getenv("usbethaddr") && !had_ctrlc()) {
445 uchar mac_addr[ETH_ALEN];
449 printf("USB init failed: %d\n", ret);
452 if (eth_getenv_enetaddr("usbethaddr", mac_addr))
453 printf("MAC address: %pM\n", mac_addr);
456 printf("'usbethaddr' not set; skipping USB initialization\n");
461 #ifdef CONFIG_QCOM_SMD_RPM
462 #define LDO(n, uV, en) uint32_t ldo##n[] = { \
463 LDOA_RES_TYPE, n, KEY_SOFTWARE_ENABLE, 4, GENERIC_##en, \
464 KEY_MICRO_VOLT, 4, uV, }
466 static LDO(2, 1200000, ENABLE); // LPDDR
467 static LDO(3, 1150000, ENABLE); // VDD_MEM, PLL, USB
468 static LDO(5, 1800000, ENABLE); // LPDDR I/O
469 static LDO(7, 1800000, ENABLE); // WLAN OSC, PLL2, VDDA2, USBPHY
470 static LDO(8, 2900000, ENABLE); // eMMC
471 static LDO(15, 1800000, ENABLE); // Basisboard VDDIO + L16
472 static LDO(16, 1800000, ENABLE); // Basisboard VDDIO + L15 (55mA)
473 static LDO(17, 3300000, ENABLE); // Basisboard VDD33 (450mA)
475 static LDO(1, 1225000, DISABLE); // ext. Conn.
476 static LDO(6, 1800000, DISABLE); // MIPI + Temp Sens.
477 static LDO(9, 3300000, DISABLE); // WLAN
478 static LDO(11, 1900000, ENABLE); // JTAG, ext. Conn. OWIRE
479 static LDO(12, 2900000, ENABLE); // SD-Card
480 static LDO(13, 3075000, ENABLE); // USBPHY
482 static LDO(4, 1800000, DISABLE); // NC
483 static LDO(10, 1000000, DISABLE); // NC
484 static LDO(14, 1000000, DISABLE); // NC
485 static LDO(18, 1000000, DISABLE); // NC
487 #define _debug(fmt...) do {} while (0)
489 static inline void __smd_regulator_control(uint32_t *data, size_t len,
494 _debug("%s@%d: %sabling %s: %u.%03uV\n", __func__, __LINE__,
495 data[4] == GENERIC_ENABLE ? "En" : "Dis", name,
496 data[7] / 1000000, data[7] / 1000 % 1000);
497 ret = rpm_send_data(data, len, RPM_REQUEST_TYPE);
499 printf("Failed to configure regulator %s\n", name);
503 #define smd_regulator_control(n) __smd_regulator_control(n, sizeof(n), #n)
505 static void smd_pmic_setup(void)
509 smd_regulator_control(ldo1);
510 smd_regulator_control(ldo2);
511 smd_regulator_control(ldo3);
512 smd_regulator_control(ldo4);
513 smd_regulator_control(ldo5);
514 smd_regulator_control(ldo6);
515 smd_regulator_control(ldo7);
516 smd_regulator_control(ldo8);
517 smd_regulator_control(ldo9);
518 smd_regulator_control(ldo10);
519 smd_regulator_control(ldo11);
520 smd_regulator_control(ldo12);
521 smd_regulator_control(ldo13);
522 smd_regulator_control(ldo14);
523 smd_regulator_control(ldo15);
524 smd_regulator_control(ldo16);
525 smd_regulator_control(ldo17);
526 smd_regulator_control(ldo18);
528 /* turn off unused regulators */
529 smd_regulator_control(ldo4);
530 smd_regulator_control(ldo10);
531 smd_regulator_control(ldo14);
532 smd_regulator_control(ldo18);
534 /* enable all essential regulators */
535 smd_regulator_control(ldo2);
536 smd_regulator_control(ldo3);
537 smd_regulator_control(ldo5);
538 smd_regulator_control(ldo7);
539 smd_regulator_control(ldo8);
540 smd_regulator_control(ldo15);
541 smd_regulator_control(ldo16);
542 smd_regulator_control(ldo17);
544 /* setup optional regulators */
545 smd_regulator_control(ldo1);
546 smd_regulator_control(ldo6);
547 smd_regulator_control(ldo9);
548 smd_regulator_control(ldo11);
549 smd_regulator_control(ldo12);
550 smd_regulator_control(ldo13);
555 static inline void smd_pmic_setup(void)
560 int board_late_init(void)
562 if (!getenv("safeboot") && !ctrlc())
569 static const char *txsd_touchpanels[] = {
574 int ft_board_setup(void *blob, bd_t *bd)
577 const char *video_mode = karo_get_vmode(getenv("video_mode"));
579 ret = fdt_increase_size(blob, 4096);
581 printf("Failed to increase FDT size: %s\n", fdt_strerror(ret));
584 karo_fdt_fixup_touchpanel(blob, txsd_touchpanels,
585 ARRAY_SIZE(txsd_touchpanels));
586 karo_fdt_update_fb_mode(blob, video_mode);
591 static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
596 ret = uclass_get_device_by_name(UCLASS_SPMI, "spmi", &dev);
598 printf("Failed to get SPMI bus: %d\n", ret);
599 return CMD_RET_FAILURE;
602 ret = spmi_reg_write(dev, 0, 8, 0x8f, 8);
604 return CMD_RET_FAILURE;
606 do_reset(NULL, 0, 0, NULL);
607 return CMD_RET_FAILURE;
611 fastboot, 2, 1, do_fastboot,
612 "reboot into Fastboot protocol\n",
613 " - run as a fastboot usb device"