uboot/board/qualcomm/dragonboard410c/dragonboard410c.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0+
   2/*
   3 * Board init file for Dragonboard 410C
   4 *
   5 * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
   6 */
   7
   8#include <common.h>
   9#include <cpu_func.h>
  10#include <dm.h>
  11#include <env.h>
  12#include <init.h>
  13#include <net.h>
  14#include <usb.h>
  15#include <asm/cache.h>
  16#include <asm/gpio.h>
  17#include <fdt_support.h>
  18#include <asm/arch/dram.h>
  19#include <asm/arch/misc.h>
  20#include <linux/delay.h>
  21
  22DECLARE_GLOBAL_DATA_PTR;
  23
  24/* pointer to the device tree ammended by the firmware */
  25extern void *fw_dtb;
  26
  27void *board_fdt_blob_setup(void)
  28{
  29        if (fdt_magic(fw_dtb) != FDT_MAGIC) {
  30                printf("Firmware provided invalid dtb!\n");
  31                return NULL;
  32        }
  33
  34        return fw_dtb;
  35}
  36
  37int dram_init(void)
  38{
  39        gd->ram_size = PHYS_SDRAM_1_SIZE;
  40
  41        return 0;
  42}
  43
  44int dram_init_banksize(void)
  45{
  46        gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  47        gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
  48
  49        return 0;
  50}
  51
  52int board_usb_init(int index, enum usb_init_type init)
  53{
  54        static struct udevice *pmic_gpio;
  55        static struct gpio_desc hub_reset, usb_sel;
  56        int ret = 0, node;
  57
  58        if (!pmic_gpio) {
  59                ret = uclass_get_device_by_name(UCLASS_GPIO,
  60                                                "pm8916_gpios@c000",
  61                                                &pmic_gpio);
  62                if (ret < 0) {
  63                        printf("Failed to find pm8916_gpios@c000 node.\n");
  64                        return ret;
  65                }
  66        }
  67
  68        /* Try to request gpios needed to start usb host on dragonboard */
  69        if (!dm_gpio_is_valid(&hub_reset)) {
  70                node = fdt_subnode_offset(gd->fdt_blob,
  71                                          dev_of_offset(pmic_gpio),
  72                                          "usb_hub_reset_pm");
  73                if (node < 0) {
  74                        printf("Failed to find usb_hub_reset_pm dt node.\n");
  75                        return node;
  76                }
  77                ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
  78                                                 "gpios", 0, &hub_reset, 0);
  79                if (ret < 0) {
  80                        printf("Failed to request usb_hub_reset_pm gpio.\n");
  81                        return ret;
  82                }
  83        }
  84
  85        if (!dm_gpio_is_valid(&usb_sel)) {
  86                node = fdt_subnode_offset(gd->fdt_blob,
  87                                          dev_of_offset(pmic_gpio),
  88                                          "usb_sw_sel_pm");
  89                if (node < 0) {
  90                        printf("Failed to find usb_sw_sel_pm dt node.\n");
  91                        return 0;
  92                }
  93                ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
  94                                                 "gpios", 0, &usb_sel, 0);
  95                if (ret < 0) {
  96                        printf("Failed to request usb_sw_sel_pm gpio.\n");
  97                        return ret;
  98                }
  99        }
 100
 101        if (init == USB_INIT_HOST) {
 102                /* Start USB Hub */
 103                dm_gpio_set_dir_flags(&hub_reset,
 104                                      GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
 105                mdelay(100);
 106                /* Switch usb to host connectors */
 107                dm_gpio_set_dir_flags(&usb_sel,
 108                                      GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
 109                mdelay(100);
 110        } else { /* Device */
 111                /* Disable hub */
 112                dm_gpio_set_dir_flags(&hub_reset, GPIOD_IS_OUT);
 113                /* Switch back to device connector */
 114                dm_gpio_set_dir_flags(&usb_sel, GPIOD_IS_OUT);
 115        }
 116
 117        return 0;
 118}
 119
 120/* Check for vol- button - if pressed - stop autoboot */
 121int misc_init_r(void)
 122{
 123        struct udevice *pon;
 124        struct gpio_desc resin;
 125        int node, ret;
 126
 127        ret = uclass_get_device_by_name(UCLASS_GPIO, "pm8916_pon@800", &pon);
 128        if (ret < 0) {
 129                printf("Failed to find PMIC pon node. Check device tree\n");
 130                return 0;
 131        }
 132
 133        node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon),
 134                                  "key_vol_down");
 135        if (node < 0) {
 136                printf("Failed to find key_vol_down node. Check device tree\n");
 137                return 0;
 138        }
 139
 140        if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0,
 141                                       &resin, 0)) {
 142                printf("Failed to request key_vol_down button.\n");
 143                return 0;
 144        }
 145
 146        if (dm_gpio_get_value(&resin)) {
 147                env_set("bootdelay", "-1");
 148                env_set("bootcmd", "fastboot 0");
 149                printf("key_vol_down pressed - Starting fastboot.\n");
 150        }
 151
 152        return 0;
 153}
 154
 155int board_init(void)
 156{
 157        return 0;
 158}
 159
 160int board_late_init(void)
 161{
 162        char serial[16];
 163
 164        memset(serial, 0, 16);
 165        snprintf(serial, 13, "%x", msm_board_serial());
 166        env_set("serial#", serial);
 167        return 0;
 168}
 169
 170/* Fixup of DTB for Linux Kernel
 171 * 1. Fixup installed DRAM.
 172 * 2. Fixup WLAN/BT Mac address:
 173 *      First, check if MAC addresses for WLAN/BT exists as environemnt
 174 *      variables wlanaddr,btaddr. if not, generate a unique address.
 175 */
 176
 177int ft_board_setup(void *blob, struct bd_info *bd)
 178{
 179        u8 mac[ARP_HLEN];
 180
 181        msm_fixup_memory(blob);
 182
 183        if (!eth_env_get_enetaddr("wlanaddr", mac)) {
 184                msm_generate_mac_addr(mac);
 185        };
 186
 187        do_fixup_by_compat(blob, "qcom,wcnss-wlan",
 188                           "local-mac-address", mac, ARP_HLEN, 1);
 189
 190
 191        if (!eth_env_get_enetaddr("btaddr", mac)) {
 192                msm_generate_mac_addr(mac);
 193
 194/* The BD address is same as WLAN MAC address but with
 195 * least significant bit flipped.
 196 */
 197                mac[0] ^= 0x01;
 198        };
 199
 200        do_fixup_by_compat(blob, "qcom,wcnss-bt",
 201                           "local-bd-address", mac, ARP_HLEN, 1);
 202        return 0;
 203}
 204
 205void reset_cpu(ulong addr)
 206{
 207        psci_system_reset();
 208}
 209