Mateusz Kulikowski | 626f048 | 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> |
| 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 | |
Simon Glass | 76b00ac | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 22 | int dram_init_banksize(void) |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 23 | { |
| 24 | gd->bd->bi_dram[0].start = PHYS_SDRAM_1; |
| 25 | gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE; |
Simon Glass | 76b00ac | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 26 | |
| 27 | return 0; |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | |
| 31 | int board_prepare_usb(enum usb_init_type type) |
| 32 | { |
| 33 | static struct udevice *pmic_gpio; |
| 34 | static struct gpio_desc hub_reset, usb_sel; |
| 35 | int ret = 0, node; |
| 36 | |
| 37 | if (!pmic_gpio) { |
| 38 | ret = uclass_get_device_by_name(UCLASS_GPIO, |
| 39 | "pm8916_gpios@c000", |
| 40 | &pmic_gpio); |
| 41 | if (ret < 0) { |
| 42 | printf("Failed to find pm8916_gpios@c000 node.\n"); |
| 43 | return ret; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | /* Try to request gpios needed to start usb host on dragonboard */ |
| 48 | if (!dm_gpio_is_valid(&hub_reset)) { |
Simon Glass | e160f7d | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 49 | node = fdt_subnode_offset(gd->fdt_blob, |
| 50 | dev_of_offset(pmic_gpio), |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 51 | "usb_hub_reset_pm"); |
| 52 | if (node < 0) { |
| 53 | printf("Failed to find usb_hub_reset_pm dt node.\n"); |
| 54 | return node; |
| 55 | } |
Simon Glass | 150c5af | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 56 | ret = gpio_request_by_name_nodev(offset_to_ofnode(node), |
| 57 | "gpios", 0, &hub_reset, 0); |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 58 | if (ret < 0) { |
| 59 | printf("Failed to request usb_hub_reset_pm gpio.\n"); |
| 60 | return ret; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | if (!dm_gpio_is_valid(&usb_sel)) { |
Simon Glass | e160f7d | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 65 | node = fdt_subnode_offset(gd->fdt_blob, |
| 66 | dev_of_offset(pmic_gpio), |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 67 | "usb_sw_sel_pm"); |
| 68 | if (node < 0) { |
| 69 | printf("Failed to find usb_sw_sel_pm dt node.\n"); |
| 70 | return 0; |
| 71 | } |
Simon Glass | 150c5af | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 72 | ret = gpio_request_by_name_nodev(offset_to_ofnode(node), |
| 73 | "gpios", 0, &usb_sel, 0); |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 74 | if (ret < 0) { |
| 75 | printf("Failed to request usb_sw_sel_pm gpio.\n"); |
| 76 | return ret; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | if (type == USB_INIT_HOST) { |
| 81 | /* Start USB Hub */ |
| 82 | dm_gpio_set_dir_flags(&hub_reset, |
| 83 | GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); |
| 84 | mdelay(100); |
| 85 | /* Switch usb to host connectors */ |
| 86 | dm_gpio_set_dir_flags(&usb_sel, |
| 87 | GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); |
| 88 | mdelay(100); |
| 89 | } else { /* Device */ |
| 90 | /* Disable hub */ |
| 91 | dm_gpio_set_dir_flags(&hub_reset, GPIOD_IS_OUT); |
| 92 | /* Switch back to device connector */ |
| 93 | dm_gpio_set_dir_flags(&usb_sel, GPIOD_IS_OUT); |
| 94 | } |
| 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | int board_init(void) |
| 100 | { |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | /* Check for vol- button - if pressed - stop autoboot */ |
| 105 | int misc_init_r(void) |
| 106 | { |
| 107 | struct udevice *pon; |
| 108 | struct gpio_desc resin; |
| 109 | int node, ret; |
| 110 | |
| 111 | ret = uclass_get_device_by_name(UCLASS_GPIO, "pm8916_pon@800", &pon); |
| 112 | if (ret < 0) { |
| 113 | printf("Failed to find PMIC pon node. Check device tree\n"); |
| 114 | return 0; |
| 115 | } |
| 116 | |
Simon Glass | e160f7d | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 117 | node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon), |
| 118 | "key_vol_down"); |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 119 | if (node < 0) { |
| 120 | printf("Failed to find key_vol_down node. Check device tree\n"); |
| 121 | return 0; |
| 122 | } |
| 123 | |
Simon Glass | 150c5af | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 124 | if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0, |
| 125 | &resin, 0)) { |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 126 | printf("Failed to request key_vol_down button.\n"); |
| 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | if (dm_gpio_get_value(&resin)) { |
| 131 | setenv("bootdelay", "-1"); |
| 132 | printf("Power button pressed - dropping to console.\n"); |
| 133 | } |
| 134 | |
| 135 | return 0; |
| 136 | } |