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 | |
| 37 | static int usb_enabled = 0; |
| 38 | |
| 39 | /* Board specific xHCI dis-/enable code */ |
| 40 | |
| 41 | /* |
| 42 | * Set USB VBUS signals (via I2C IO expander/GPIO) as output and set |
| 43 | * output value as disabled |
| 44 | * |
| 45 | * Set USB Current Limit signals (via I2C IO expander/GPIO) as output |
| 46 | * and set output value as enabled |
| 47 | */ |
| 48 | int board_xhci_config(void) |
| 49 | { |
| 50 | struct udevice *dev; |
| 51 | int ret; |
| 52 | u8 buf[8]; |
| 53 | |
Stefan Roese | b961b86 | 2016-10-25 12:41:45 +0200 | [diff] [blame] | 54 | if (of_machine_is_compatible("marvell,armada7040-db")) { |
| 55 | /* Configure IO exander PCA9555: 7bit address 0x21 */ |
| 56 | ret = i2c_get_chip_for_busnum(0, I2C_IO_EXP_ADDR, 1, &dev); |
| 57 | if (ret) { |
| 58 | printf("Cannot find PCA9555: %d\n", ret); |
| 59 | return 0; |
| 60 | } |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 61 | |
Stefan Roese | b961b86 | 2016-10-25 12:41:45 +0200 | [diff] [blame] | 62 | /* |
| 63 | * Read configuration (direction) and set VBUS pin as output |
| 64 | * (reset pin = output) |
| 65 | */ |
| 66 | ret = dm_i2c_read(dev, I2C_IO_CFG_REG_0, buf, 1); |
| 67 | if (ret) { |
| 68 | printf("Failed to read IO expander value via I2C\n"); |
| 69 | return -EIO; |
| 70 | } |
| 71 | buf[0] &= ~I2C_IO_REG_VBUS; |
| 72 | buf[0] &= ~I2C_IO_REG_CL; |
| 73 | ret = dm_i2c_write(dev, I2C_IO_CFG_REG_0, buf, 1); |
| 74 | if (ret) { |
| 75 | printf("Failed to set IO expander via I2C\n"); |
| 76 | return -EIO; |
| 77 | } |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 78 | |
Stefan Roese | b961b86 | 2016-10-25 12:41:45 +0200 | [diff] [blame] | 79 | /* Read output value and configure it */ |
| 80 | ret = dm_i2c_read(dev, I2C_IO_DATA_OUT_REG_0, buf, 1); |
| 81 | if (ret) { |
| 82 | printf("Failed to read IO expander value via I2C\n"); |
| 83 | return -EIO; |
| 84 | } |
| 85 | buf[0] &= ~I2C_IO_REG_VBUS; |
| 86 | buf[0] |= I2C_IO_REG_CL; |
| 87 | ret = dm_i2c_write(dev, I2C_IO_DATA_OUT_REG_0, buf, 1); |
| 88 | if (ret) { |
| 89 | printf("Failed to set IO expander via I2C\n"); |
| 90 | return -EIO; |
| 91 | } |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 92 | |
Stefan Roese | b961b86 | 2016-10-25 12:41:45 +0200 | [diff] [blame] | 93 | mdelay(500); /* required delay to let output value settle */ |
| 94 | } |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
Jon Nettleton | a81f47c | 2017-11-06 10:33:19 +0200 | [diff] [blame] | 99 | int board_xhci_enable(fdt_addr_t base) |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 100 | { |
| 101 | struct udevice *dev; |
| 102 | int ret; |
| 103 | u8 buf[8]; |
| 104 | |
Stefan Roese | b961b86 | 2016-10-25 12:41:45 +0200 | [diff] [blame] | 105 | if (of_machine_is_compatible("marvell,armada7040-db")) { |
| 106 | /* |
| 107 | * This function enables all USB ports simultaniously, |
| 108 | * it only needs to get called once |
| 109 | */ |
| 110 | if (usb_enabled) |
| 111 | return 0; |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 112 | |
Stefan Roese | b961b86 | 2016-10-25 12:41:45 +0200 | [diff] [blame] | 113 | /* Configure IO exander PCA9555: 7bit address 0x21 */ |
| 114 | ret = i2c_get_chip_for_busnum(0, I2C_IO_EXP_ADDR, 1, &dev); |
| 115 | if (ret) { |
| 116 | printf("Cannot find PCA9555: %d\n", ret); |
| 117 | return 0; |
| 118 | } |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 119 | |
Stefan Roese | b961b86 | 2016-10-25 12:41:45 +0200 | [diff] [blame] | 120 | /* Read VBUS output value */ |
| 121 | ret = dm_i2c_read(dev, I2C_IO_DATA_OUT_REG_0, buf, 1); |
| 122 | if (ret) { |
| 123 | printf("Failed to read IO expander value via I2C\n"); |
| 124 | return -EIO; |
| 125 | } |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 126 | |
Stefan Roese | b961b86 | 2016-10-25 12:41:45 +0200 | [diff] [blame] | 127 | /* Enable VBUS power: Set output value of VBUS pin as enabled */ |
| 128 | buf[0] |= I2C_IO_REG_VBUS; |
| 129 | ret = dm_i2c_write(dev, I2C_IO_DATA_OUT_REG_0, buf, 1); |
| 130 | if (ret) { |
| 131 | printf("Failed to set IO expander via I2C\n"); |
| 132 | return -EIO; |
| 133 | } |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 134 | |
Stefan Roese | b961b86 | 2016-10-25 12:41:45 +0200 | [diff] [blame] | 135 | mdelay(500); /* required delay to let output value settle */ |
| 136 | usb_enabled = 1; |
| 137 | } |
Stefan Roese | 7be1b9b | 2016-05-25 08:21:21 +0200 | [diff] [blame] | 138 | |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | int board_early_init_f(void) |
| 143 | { |
| 144 | /* Nothing to do (yet), perhaps later some pin-muxing etc */ |
| 145 | |
| 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | int board_init(void) |
| 150 | { |
| 151 | /* adress of boot parameters */ |
| 152 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
| 153 | |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | int board_late_init(void) |
| 158 | { |
| 159 | /* Pre-configure the USB ports (overcurrent, VBus) */ |
| 160 | board_xhci_config(); |
| 161 | |
| 162 | return 0; |
| 163 | } |