blob: 818ae04dfd015c2c0d6c1b9ed0e4c1db9bd4a1b5 [file] [log] [blame]
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +02001/*
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
14DECLARE_GLOBAL_DATA_PTR;
15
16int dram_init(void)
17{
18 gd->ram_size = PHYS_SDRAM_1_SIZE;
19 return 0;
20}
21
22void 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
29int 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)) {
Simon Glassdd79d6e2017-01-17 16:52:55 -070047 node = fdt_subnode_offset(gd->fdt_blob,
48 dev_of_offset(pmic_gpio),
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020049 "usb_hub_reset_pm");
50 if (node < 0) {
51 printf("Failed to find usb_hub_reset_pm dt node.\n");
52 return node;
53 }
54 ret = gpio_request_by_name_nodev(gd->fdt_blob, node, "gpios", 0,
55 &hub_reset, 0);
56 if (ret < 0) {
57 printf("Failed to request usb_hub_reset_pm gpio.\n");
58 return ret;
59 }
60 }
61
62 if (!dm_gpio_is_valid(&usb_sel)) {
Simon Glassdd79d6e2017-01-17 16:52:55 -070063 node = fdt_subnode_offset(gd->fdt_blob,
64 dev_of_offset(pmic_gpio),
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020065 "usb_sw_sel_pm");
66 if (node < 0) {
67 printf("Failed to find usb_sw_sel_pm dt node.\n");
68 return 0;
69 }
70 ret = gpio_request_by_name_nodev(gd->fdt_blob, node, "gpios", 0,
71 &usb_sel, 0);
72 if (ret < 0) {
73 printf("Failed to request usb_sw_sel_pm gpio.\n");
74 return ret;
75 }
76 }
77
78 if (type == USB_INIT_HOST) {
79 /* Start USB Hub */
80 dm_gpio_set_dir_flags(&hub_reset,
81 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
82 mdelay(100);
83 /* Switch usb to host connectors */
84 dm_gpio_set_dir_flags(&usb_sel,
85 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
86 mdelay(100);
87 } else { /* Device */
88 /* Disable hub */
89 dm_gpio_set_dir_flags(&hub_reset, GPIOD_IS_OUT);
90 /* Switch back to device connector */
91 dm_gpio_set_dir_flags(&usb_sel, GPIOD_IS_OUT);
92 }
93
94 return 0;
95}
96
97int board_init(void)
98{
99 return 0;
100}
101
102/* Check for vol- button - if pressed - stop autoboot */
103int misc_init_r(void)
104{
105 struct udevice *pon;
106 struct gpio_desc resin;
107 int node, ret;
108
109 ret = uclass_get_device_by_name(UCLASS_GPIO, "pm8916_pon@800", &pon);
110 if (ret < 0) {
111 printf("Failed to find PMIC pon node. Check device tree\n");
112 return 0;
113 }
114
Simon Glassdd79d6e2017-01-17 16:52:55 -0700115 node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon),
116 "key_vol_down");
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200117 if (node < 0) {
118 printf("Failed to find key_vol_down node. Check device tree\n");
119 return 0;
120 }
121
122 if (gpio_request_by_name_nodev(gd->fdt_blob, node, "gpios", 0, &resin,
123 0)) {
124 printf("Failed to request key_vol_down button.\n");
125 return 0;
126 }
127
128 if (dm_gpio_get_value(&resin)) {
129 setenv("bootdelay", "-1");
130 printf("Power button pressed - dropping to console.\n");
131 }
132
133 return 0;
134}