1 /* 2 * Board init file for Dragonboard 410C 3 * 4 * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com> 5 * 6 * SPDX-License-Identifier: GPL-2.0+ 7 */ 8 9 #include <common.h> 10 #include <dm.h> 11 #include <usb.h> 12 #include <asm/gpio.h> 13 14 DECLARE_GLOBAL_DATA_PTR; 15 16 int dram_init(void) 17 { 18 gd->ram_size = PHYS_SDRAM_1_SIZE; 19 return 0; 20 } 21 22 void dram_init_banksize(void) 23 { 24 gd->bd->bi_dram[0].start = PHYS_SDRAM_1; 25 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE; 26 } 27 28 29 int board_prepare_usb(enum usb_init_type type) 30 { 31 static struct udevice *pmic_gpio; 32 static struct gpio_desc hub_reset, usb_sel; 33 int ret = 0, node; 34 35 if (!pmic_gpio) { 36 ret = uclass_get_device_by_name(UCLASS_GPIO, 37 "pm8916_gpios@c000", 38 &pmic_gpio); 39 if (ret < 0) { 40 printf("Failed to find pm8916_gpios@c000 node.\n"); 41 return ret; 42 } 43 } 44 45 /* Try to request gpios needed to start usb host on dragonboard */ 46 if (!dm_gpio_is_valid(&hub_reset)) { 47 node = fdt_subnode_offset(gd->fdt_blob, pmic_gpio->of_offset, 48 "usb_hub_reset_pm"); 49 if (node < 0) { 50 printf("Failed to find usb_hub_reset_pm dt node.\n"); 51 return node; 52 } 53 ret = gpio_request_by_name_nodev(gd->fdt_blob, node, "gpios", 0, 54 &hub_reset, 0); 55 if (ret < 0) { 56 printf("Failed to request usb_hub_reset_pm gpio.\n"); 57 return ret; 58 } 59 } 60 61 if (!dm_gpio_is_valid(&usb_sel)) { 62 node = fdt_subnode_offset(gd->fdt_blob, pmic_gpio->of_offset, 63 "usb_sw_sel_pm"); 64 if (node < 0) { 65 printf("Failed to find usb_sw_sel_pm dt node.\n"); 66 return 0; 67 } 68 ret = gpio_request_by_name_nodev(gd->fdt_blob, node, "gpios", 0, 69 &usb_sel, 0); 70 if (ret < 0) { 71 printf("Failed to request usb_sw_sel_pm gpio.\n"); 72 return ret; 73 } 74 } 75 76 if (type == USB_INIT_HOST) { 77 /* Start USB Hub */ 78 dm_gpio_set_dir_flags(&hub_reset, 79 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); 80 mdelay(100); 81 /* Switch usb to host connectors */ 82 dm_gpio_set_dir_flags(&usb_sel, 83 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); 84 mdelay(100); 85 } else { /* Device */ 86 /* Disable hub */ 87 dm_gpio_set_dir_flags(&hub_reset, GPIOD_IS_OUT); 88 /* Switch back to device connector */ 89 dm_gpio_set_dir_flags(&usb_sel, GPIOD_IS_OUT); 90 } 91 92 return 0; 93 } 94 95 int board_init(void) 96 { 97 return 0; 98 } 99 100 /* Check for vol- button - if pressed - stop autoboot */ 101 int misc_init_r(void) 102 { 103 struct udevice *pon; 104 struct gpio_desc resin; 105 int node, ret; 106 107 ret = uclass_get_device_by_name(UCLASS_GPIO, "pm8916_pon@800", &pon); 108 if (ret < 0) { 109 printf("Failed to find PMIC pon node. Check device tree\n"); 110 return 0; 111 } 112 113 node = fdt_subnode_offset(gd->fdt_blob, pon->of_offset, "key_vol_down"); 114 if (node < 0) { 115 printf("Failed to find key_vol_down node. Check device tree\n"); 116 return 0; 117 } 118 119 if (gpio_request_by_name_nodev(gd->fdt_blob, node, "gpios", 0, &resin, 120 0)) { 121 printf("Failed to request key_vol_down button.\n"); 122 return 0; 123 } 124 125 if (dm_gpio_get_value(&resin)) { 126 setenv("bootdelay", "-1"); 127 printf("Power button pressed - dropping to console.\n"); 128 } 129 130 return 0; 131 } 132