Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 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> |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 13 | #include <fdt_support.h> |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 14 | |
| 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 17 | /* pointer to the device tree ammended by the firmware */ |
Jorge Ramirez-Ortiz | f44f301 | 2018-01-10 11:34:38 +0100 | [diff] [blame] | 18 | extern void *fw_dtb; |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 19 | |
Jorge Ramirez-Ortiz | f44f301 | 2018-01-10 11:34:38 +0100 | [diff] [blame] | 20 | void *board_fdt_blob_setup(void) |
| 21 | { |
| 22 | if (fdt_magic(fw_dtb) != FDT_MAGIC) { |
| 23 | printf("Firmware provided invalid dtb!\n"); |
| 24 | return NULL; |
| 25 | } |
| 26 | |
| 27 | return fw_dtb; |
| 28 | } |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 29 | |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 30 | int dram_init(void) |
| 31 | { |
| 32 | gd->ram_size = PHYS_SDRAM_1_SIZE; |
Jorge Ramirez-Ortiz | f44f301 | 2018-01-10 11:34:38 +0100 | [diff] [blame] | 33 | |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 34 | return 0; |
| 35 | } |
| 36 | |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 37 | int dram_init_banksize(void) |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 38 | { |
| 39 | gd->bd->bi_dram[0].start = PHYS_SDRAM_1; |
| 40 | gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE; |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 41 | |
| 42 | return 0; |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 43 | } |
| 44 | |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 45 | int board_prepare_usb(enum usb_init_type type) |
| 46 | { |
| 47 | static struct udevice *pmic_gpio; |
| 48 | static struct gpio_desc hub_reset, usb_sel; |
| 49 | int ret = 0, node; |
| 50 | |
| 51 | if (!pmic_gpio) { |
| 52 | ret = uclass_get_device_by_name(UCLASS_GPIO, |
| 53 | "pm8916_gpios@c000", |
| 54 | &pmic_gpio); |
| 55 | if (ret < 0) { |
| 56 | printf("Failed to find pm8916_gpios@c000 node.\n"); |
| 57 | return ret; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /* Try to request gpios needed to start usb host on dragonboard */ |
| 62 | if (!dm_gpio_is_valid(&hub_reset)) { |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 63 | node = fdt_subnode_offset(gd->fdt_blob, |
| 64 | dev_of_offset(pmic_gpio), |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 65 | "usb_hub_reset_pm"); |
| 66 | if (node < 0) { |
| 67 | printf("Failed to find usb_hub_reset_pm dt node.\n"); |
| 68 | return node; |
| 69 | } |
Simon Glass | 1d9af1f | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 70 | ret = gpio_request_by_name_nodev(offset_to_ofnode(node), |
| 71 | "gpios", 0, &hub_reset, 0); |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 72 | if (ret < 0) { |
| 73 | printf("Failed to request usb_hub_reset_pm gpio.\n"); |
| 74 | return ret; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | if (!dm_gpio_is_valid(&usb_sel)) { |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 79 | node = fdt_subnode_offset(gd->fdt_blob, |
| 80 | dev_of_offset(pmic_gpio), |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 81 | "usb_sw_sel_pm"); |
| 82 | if (node < 0) { |
| 83 | printf("Failed to find usb_sw_sel_pm dt node.\n"); |
| 84 | return 0; |
| 85 | } |
Simon Glass | 1d9af1f | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 86 | ret = gpio_request_by_name_nodev(offset_to_ofnode(node), |
| 87 | "gpios", 0, &usb_sel, 0); |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 88 | if (ret < 0) { |
| 89 | printf("Failed to request usb_sw_sel_pm gpio.\n"); |
| 90 | return ret; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | if (type == USB_INIT_HOST) { |
| 95 | /* Start USB Hub */ |
| 96 | dm_gpio_set_dir_flags(&hub_reset, |
| 97 | GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); |
| 98 | mdelay(100); |
| 99 | /* Switch usb to host connectors */ |
| 100 | dm_gpio_set_dir_flags(&usb_sel, |
| 101 | GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); |
| 102 | mdelay(100); |
| 103 | } else { /* Device */ |
| 104 | /* Disable hub */ |
| 105 | dm_gpio_set_dir_flags(&hub_reset, GPIOD_IS_OUT); |
| 106 | /* Switch back to device connector */ |
| 107 | dm_gpio_set_dir_flags(&usb_sel, GPIOD_IS_OUT); |
| 108 | } |
| 109 | |
| 110 | return 0; |
| 111 | } |
| 112 | |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 113 | /* Check for vol- button - if pressed - stop autoboot */ |
| 114 | int misc_init_r(void) |
| 115 | { |
| 116 | struct udevice *pon; |
| 117 | struct gpio_desc resin; |
| 118 | int node, ret; |
| 119 | |
| 120 | ret = uclass_get_device_by_name(UCLASS_GPIO, "pm8916_pon@800", &pon); |
| 121 | if (ret < 0) { |
| 122 | printf("Failed to find PMIC pon node. Check device tree\n"); |
| 123 | return 0; |
| 124 | } |
| 125 | |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 126 | node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon), |
| 127 | "key_vol_down"); |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 128 | if (node < 0) { |
| 129 | printf("Failed to find key_vol_down node. Check device tree\n"); |
| 130 | return 0; |
| 131 | } |
| 132 | |
Simon Glass | 1d9af1f | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 133 | if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0, |
| 134 | &resin, 0)) { |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 135 | printf("Failed to request key_vol_down button.\n"); |
| 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | if (dm_gpio_get_value(&resin)) { |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 140 | env_set("bootdelay", "-1"); |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 141 | printf("Power button pressed - dropping to console.\n"); |
| 142 | } |
| 143 | |
| 144 | return 0; |
| 145 | } |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 146 | |
| 147 | int board_init(void) |
| 148 | { |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | int ft_board_setup(void *blob, bd_t *bd) |
| 153 | { |
Jorge Ramirez-Ortiz | f44f301 | 2018-01-10 11:34:38 +0100 | [diff] [blame] | 154 | int offset, len, i; |
| 155 | const char *mac; |
| 156 | struct { |
| 157 | const char *compatible; |
| 158 | const char *property; |
| 159 | } fix[] = { |
| 160 | [0] = { |
| 161 | /* update the kernel's dtb with wlan mac */ |
| 162 | .compatible = "qcom,wcnss-wlan", |
| 163 | .property = "local-mac-address", |
| 164 | }, |
| 165 | [1] = { |
| 166 | /* update the kernel's dtb with bt mac */ |
| 167 | .compatible = "qcom,wcnss-bt", |
| 168 | .property = "local-bd-address", |
| 169 | }, |
| 170 | }; |
| 171 | |
| 172 | for (i = 0; i < sizeof(fix) / sizeof(fix[0]); i++) { |
| 173 | offset = fdt_node_offset_by_compatible(gd->fdt_blob, -1, |
| 174 | fix[i].compatible); |
| 175 | if (offset < 0) |
| 176 | continue; |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 177 | |
Jorge Ramirez-Ortiz | f44f301 | 2018-01-10 11:34:38 +0100 | [diff] [blame] | 178 | mac = fdt_getprop(gd->fdt_blob, offset, fix[i].property, &len); |
| 179 | if (mac) |
| 180 | do_fixup_by_compat(blob, fix[i].compatible, |
| 181 | fix[i].property, mac, ARP_HLEN, 1); |
| 182 | } |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 183 | |
| 184 | return 0; |
| 185 | } |
Jorge Ramirez-Ortiz | 4154c9e | 2018-01-10 11:34:36 +0100 | [diff] [blame] | 186 | |
| 187 | void reset_cpu(ulong addr) |
| 188 | { |
| 189 | psci_system_reset(); |
| 190 | } |