blob: 37d0b85e0eacb7f6417d8b0b83965bbac8c89e3e [file] [log] [blame]
Mateusz Kulikowski626f0482016-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
Simon Glass76b00ac2017-03-31 08:40:32 -060022int dram_init_banksize(void)
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020023{
24 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
25 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
Simon Glass76b00ac2017-03-31 08:40:32 -060026
27 return 0;
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020028}
29
30
31int 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 Glasse160f7d2017-01-17 16:52:55 -070049 node = fdt_subnode_offset(gd->fdt_blob,
50 dev_of_offset(pmic_gpio),
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020051 "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 Glass150c5af2017-05-30 21:47:09 -060056 ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
57 "gpios", 0, &hub_reset, 0);
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020058 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 Glasse160f7d2017-01-17 16:52:55 -070065 node = fdt_subnode_offset(gd->fdt_blob,
66 dev_of_offset(pmic_gpio),
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020067 "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 Glass150c5af2017-05-30 21:47:09 -060072 ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
73 "gpios", 0, &usb_sel, 0);
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020074 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
99int board_init(void)
100{
101 return 0;
102}
103
104/* Check for vol- button - if pressed - stop autoboot */
105int 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 Glasse160f7d2017-01-17 16:52:55 -0700117 node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon),
118 "key_vol_down");
Mateusz Kulikowski626f0482016-03-31 23:12:33 +0200119 if (node < 0) {
120 printf("Failed to find key_vol_down node. Check device tree\n");
121 return 0;
122 }
123
Simon Glass150c5af2017-05-30 21:47:09 -0600124 if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0,
125 &resin, 0)) {
Mateusz Kulikowski626f0482016-03-31 23:12:33 +0200126 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}