Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016 Stefan Roese <sr@denx.de> |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Stefan Roese | b961b86 | 2016-10-25 12:41:45 +0200 | [diff] [blame] | 7 | #include <dm.h> |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 8 | #include <i2c.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 9 | #include <init.h> |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 10 | #include <asm/io.h> |
| 11 | #include <asm/arch/cpu.h> |
| 12 | #include <asm/arch/soc.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 13 | #include <linux/delay.h> |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 14 | |
| 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
Stefan Roese | b961b86 | 2016-10-25 12:41:45 +0200 | [diff] [blame] | 17 | /* |
| 18 | * Information specific to the DB-88F7040 eval board. We strive to use |
| 19 | * DT for such platform specfic configurations. At some point, this |
| 20 | * might be removed here and implemented via DT. |
| 21 | */ |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 22 | /* IO expander I2C device */ |
| 23 | #define I2C_IO_EXP_ADDR 0x21 |
| 24 | #define I2C_IO_CFG_REG_0 0x6 |
| 25 | #define I2C_IO_DATA_OUT_REG_0 0x2 |
| 26 | /* VBus enable */ |
| 27 | #define I2C_IO_REG_0_USB_H0_OFF 0 |
| 28 | #define I2C_IO_REG_0_USB_H1_OFF 1 |
| 29 | #define I2C_IO_REG_VBUS ((1 << I2C_IO_REG_0_USB_H0_OFF) | \ |
| 30 | (1 << I2C_IO_REG_0_USB_H1_OFF)) |
| 31 | /* Current limit */ |
| 32 | #define I2C_IO_REG_0_USB_H0_CL 4 |
| 33 | #define I2C_IO_REG_0_USB_H1_CL 5 |
| 34 | #define I2C_IO_REG_CL ((1 << I2C_IO_REG_0_USB_H0_CL) | \ |
| 35 | (1 << I2C_IO_REG_0_USB_H1_CL)) |
| 36 | |
Luka Kovacic | 1f790c6 | 2020-08-29 00:35:51 +0200 | [diff] [blame] | 37 | /* |
| 38 | * Information specific to the iEi Puzzle-M801 board. |
| 39 | */ |
| 40 | |
| 41 | /* Internal configuration registers */ |
| 42 | #define CP1_CONF_REG_BASE 0xf4440000 |
| 43 | #define CONF_REG_MPP0 0x0 |
| 44 | #define CONF_REG_MPP1 0x4 |
| 45 | #define CONF_REG_MPP2 0x8 |
| 46 | #define CONF_REG_MPP3 0xC |
| 47 | |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 48 | static int usb_enabled = 0; |
| 49 | |
| 50 | /* Board specific xHCI dis-/enable code */ |
| 51 | |
| 52 | /* |
| 53 | * Set USB VBUS signals (via I2C IO expander/GPIO) as output and set |
| 54 | * output value as disabled |
| 55 | * |
| 56 | * Set USB Current Limit signals (via I2C IO expander/GPIO) as output |
| 57 | * and set output value as enabled |
| 58 | */ |
| 59 | int board_xhci_config(void) |
| 60 | { |
| 61 | struct udevice *dev; |
| 62 | int ret; |
| 63 | u8 buf[8]; |
| 64 | |
Stefan Roese | b961b86 | 2016-10-25 12:41:45 +0200 | [diff] [blame] | 65 | if (of_machine_is_compatible("marvell,armada7040-db")) { |
| 66 | /* Configure IO exander PCA9555: 7bit address 0x21 */ |
| 67 | ret = i2c_get_chip_for_busnum(0, I2C_IO_EXP_ADDR, 1, &dev); |
| 68 | if (ret) { |
| 69 | printf("Cannot find PCA9555: %d\n", ret); |
| 70 | return 0; |
| 71 | } |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 72 | |
Stefan Roese | b961b86 | 2016-10-25 12:41:45 +0200 | [diff] [blame] | 73 | /* |
| 74 | * Read configuration (direction) and set VBUS pin as output |
| 75 | * (reset pin = output) |
| 76 | */ |
| 77 | ret = dm_i2c_read(dev, I2C_IO_CFG_REG_0, buf, 1); |
| 78 | if (ret) { |
| 79 | printf("Failed to read IO expander value via I2C\n"); |
| 80 | return -EIO; |
| 81 | } |
| 82 | buf[0] &= ~I2C_IO_REG_VBUS; |
| 83 | buf[0] &= ~I2C_IO_REG_CL; |
| 84 | ret = dm_i2c_write(dev, I2C_IO_CFG_REG_0, buf, 1); |
| 85 | if (ret) { |
| 86 | printf("Failed to set IO expander via I2C\n"); |
| 87 | return -EIO; |
| 88 | } |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 89 | |
Stefan Roese | b961b86 | 2016-10-25 12:41:45 +0200 | [diff] [blame] | 90 | /* Read output value and configure it */ |
| 91 | ret = dm_i2c_read(dev, I2C_IO_DATA_OUT_REG_0, buf, 1); |
| 92 | if (ret) { |
| 93 | printf("Failed to read IO expander value via I2C\n"); |
| 94 | return -EIO; |
| 95 | } |
| 96 | buf[0] &= ~I2C_IO_REG_VBUS; |
| 97 | buf[0] |= I2C_IO_REG_CL; |
| 98 | ret = dm_i2c_write(dev, I2C_IO_DATA_OUT_REG_0, buf, 1); |
| 99 | if (ret) { |
| 100 | printf("Failed to set IO expander via I2C\n"); |
| 101 | return -EIO; |
| 102 | } |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 103 | |
Stefan Roese | b961b86 | 2016-10-25 12:41:45 +0200 | [diff] [blame] | 104 | mdelay(500); /* required delay to let output value settle */ |
| 105 | } |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 106 | |
| 107 | return 0; |
| 108 | } |
| 109 | |
Jon Nettleton | a81f47c | 2017-11-06 10:33:19 +0200 | [diff] [blame] | 110 | int board_xhci_enable(fdt_addr_t base) |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 111 | { |
| 112 | struct udevice *dev; |
| 113 | int ret; |
| 114 | u8 buf[8]; |
| 115 | |
Stefan Roese | b961b86 | 2016-10-25 12:41:45 +0200 | [diff] [blame] | 116 | if (of_machine_is_compatible("marvell,armada7040-db")) { |
| 117 | /* |
| 118 | * This function enables all USB ports simultaniously, |
| 119 | * it only needs to get called once |
| 120 | */ |
| 121 | if (usb_enabled) |
| 122 | return 0; |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 123 | |
Stefan Roese | b961b86 | 2016-10-25 12:41:45 +0200 | [diff] [blame] | 124 | /* Configure IO exander PCA9555: 7bit address 0x21 */ |
| 125 | ret = i2c_get_chip_for_busnum(0, I2C_IO_EXP_ADDR, 1, &dev); |
| 126 | if (ret) { |
| 127 | printf("Cannot find PCA9555: %d\n", ret); |
| 128 | return 0; |
| 129 | } |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 130 | |
Stefan Roese | b961b86 | 2016-10-25 12:41:45 +0200 | [diff] [blame] | 131 | /* Read VBUS output value */ |
| 132 | ret = dm_i2c_read(dev, I2C_IO_DATA_OUT_REG_0, buf, 1); |
| 133 | if (ret) { |
| 134 | printf("Failed to read IO expander value via I2C\n"); |
| 135 | return -EIO; |
| 136 | } |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 137 | |
Stefan Roese | b961b86 | 2016-10-25 12:41:45 +0200 | [diff] [blame] | 138 | /* Enable VBUS power: Set output value of VBUS pin as enabled */ |
| 139 | buf[0] |= I2C_IO_REG_VBUS; |
| 140 | ret = dm_i2c_write(dev, I2C_IO_DATA_OUT_REG_0, buf, 1); |
| 141 | if (ret) { |
| 142 | printf("Failed to set IO expander via I2C\n"); |
| 143 | return -EIO; |
| 144 | } |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 145 | |
Stefan Roese | b961b86 | 2016-10-25 12:41:45 +0200 | [diff] [blame] | 146 | mdelay(500); /* required delay to let output value settle */ |
| 147 | usb_enabled = 1; |
| 148 | } |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 149 | |
| 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | int board_early_init_f(void) |
| 154 | { |
Luka Kovacic | 1f790c6 | 2020-08-29 00:35:51 +0200 | [diff] [blame] | 155 | /* Initialize some platform specific memory locations */ |
| 156 | if (of_machine_is_compatible("marvell,armada8040-puzzle-m801")) { |
| 157 | /* MPP setup */ |
| 158 | writel(0x00444444, CP1_CONF_REG_BASE + CONF_REG_MPP0); |
| 159 | writel(0x00000000, CP1_CONF_REG_BASE + CONF_REG_MPP1); |
| 160 | writel(0x00000000, CP1_CONF_REG_BASE + CONF_REG_MPP2); |
| 161 | writel(0x08888000, CP1_CONF_REG_BASE + CONF_REG_MPP3); |
| 162 | } |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 163 | |
| 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | int board_init(void) |
| 168 | { |
| 169 | /* adress of boot parameters */ |
| 170 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
| 171 | |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | int board_late_init(void) |
| 176 | { |
| 177 | /* Pre-configure the USB ports (overcurrent, VBus) */ |
| 178 | board_xhci_config(); |
| 179 | |
| 180 | return 0; |
| 181 | } |