Baochu Xu | 6788fad | 2017-12-05 18:45:28 +0800 | [diff] [blame] | 1 | /* Copyright (c) 2014,2018, The Linux Foundation. All rights reserved. |
Unnati Gandhi | b3820bc | 2014-07-04 16:56:27 +0530 | [diff] [blame] | 2 | * |
| 3 | * Redistribution and use in source and binary forms, with or without |
| 4 | * modification, are permitted provided that the following conditions are |
| 5 | * met: |
| 6 | * * Redistributions of source code must retain the above copyright |
| 7 | * notice, this list of conditions and the following disclaimer. |
| 8 | * * Redistributions in binary form must reproduce the above |
| 9 | * copyright notice, this list of conditions and the following |
| 10 | * disclaimer in the documentation and/or other materials provided |
| 11 | * with the distribution. |
| 12 | * * Neither the name of The Linux Foundation nor the names of its |
| 13 | * contributors may be used to endorse or promote products derived |
| 14 | * from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include <debug.h> |
| 30 | #include <reg.h> |
| 31 | #include <platform/iomap.h> |
| 32 | #include <platform/gpio.h> |
| 33 | #include <blsp_qup.h> |
Baochu Xu | 7a8327b | 2017-12-01 10:40:21 +0800 | [diff] [blame] | 34 | #include <smem.h> |
Unnati Gandhi | b3820bc | 2014-07-04 16:56:27 +0530 | [diff] [blame] | 35 | |
| 36 | void gpio_tlmm_config(uint32_t gpio, uint8_t func, |
| 37 | uint8_t dir, uint8_t pull, |
| 38 | uint8_t drvstr, uint32_t enable) |
| 39 | { |
| 40 | uint32_t val = 0; |
| 41 | val |= pull; |
| 42 | val |= func << 2; |
| 43 | val |= drvstr << 6; |
| 44 | val |= enable << 9; |
| 45 | writel(val, (uint32_t *)GPIO_CONFIG_ADDR(gpio)); |
| 46 | return; |
| 47 | } |
| 48 | |
| 49 | void gpio_set(uint32_t gpio, uint32_t dir) |
| 50 | { |
| 51 | writel(dir, (uint32_t *)GPIO_IN_OUT_ADDR(gpio)); |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | /* Configure gpio for blsp uart 2 */ |
| 56 | void gpio_config_uart_dm(uint8_t id) |
| 57 | { |
Baochu Xu | 7a8327b | 2017-12-01 10:40:21 +0800 | [diff] [blame] | 58 | if (board_hardware_subtype() == HW_PLATFORM_SUBTYPE_8909_PM660_V1) |
| 59 | { |
| 60 | /* configure rx gpio */ |
| 61 | gpio_tlmm_config(21, 3, GPIO_INPUT, GPIO_NO_PULL, |
Unnati Gandhi | b3820bc | 2014-07-04 16:56:27 +0530 | [diff] [blame] | 62 | GPIO_8MA, GPIO_DISABLE); |
| 63 | |
Baochu Xu | 7a8327b | 2017-12-01 10:40:21 +0800 | [diff] [blame] | 64 | /* configure tx gpio */ |
| 65 | gpio_tlmm_config(20, 3, GPIO_OUTPUT, GPIO_NO_PULL, |
Unnati Gandhi | b3820bc | 2014-07-04 16:56:27 +0530 | [diff] [blame] | 66 | GPIO_8MA, GPIO_DISABLE); |
Baochu Xu | 7a8327b | 2017-12-01 10:40:21 +0800 | [diff] [blame] | 67 | } |
| 68 | else |
| 69 | { |
| 70 | /* configure rx gpio */ |
| 71 | gpio_tlmm_config(5, 2, GPIO_INPUT, GPIO_NO_PULL, |
| 72 | GPIO_8MA, GPIO_DISABLE); |
| 73 | |
| 74 | /* configure tx gpio */ |
| 75 | gpio_tlmm_config(4, 2, GPIO_OUTPUT, GPIO_NO_PULL, |
| 76 | GPIO_8MA, GPIO_DISABLE); |
| 77 | } |
Unnati Gandhi | b3820bc | 2014-07-04 16:56:27 +0530 | [diff] [blame] | 78 | } |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 79 | |
| 80 | uint32_t gpio_status(uint32_t gpio) |
| 81 | { |
| 82 | return readl(GPIO_IN_OUT_ADDR(gpio)) & GPIO_IN; |
| 83 | } |
| 84 | |
Unnati Gandhi | 88cf23b | 2014-12-10 15:39:12 +0530 | [diff] [blame] | 85 | void gpio_config_blsp_i2c(uint8_t blsp_id, uint8_t qup_id) |
| 86 | { |
| 87 | if(blsp_id == BLSP_ID_1) { |
| 88 | switch (qup_id) { |
| 89 | case QUP_ID_1: |
| 90 | /* configure I2C SDA gpio */ |
| 91 | gpio_tlmm_config(6, 3, GPIO_OUTPUT, GPIO_NO_PULL, |
| 92 | GPIO_8MA, GPIO_DISABLE); |
| 93 | |
| 94 | /* configure I2C SCL gpio */ |
| 95 | gpio_tlmm_config(7, 3, GPIO_OUTPUT, GPIO_NO_PULL, |
| 96 | GPIO_8MA, GPIO_DISABLE); |
| 97 | break; |
| 98 | case QUP_ID_2: |
| 99 | /* configure I2C SDA gpio */ |
| 100 | gpio_tlmm_config(111, 3, GPIO_OUTPUT, GPIO_NO_PULL, |
| 101 | GPIO_8MA, GPIO_DISABLE); |
| 102 | |
| 103 | /* configure I2C SCL gpio */ |
| 104 | gpio_tlmm_config(112, 3, GPIO_OUTPUT, GPIO_NO_PULL, |
| 105 | GPIO_8MA, GPIO_DISABLE); |
| 106 | break; |
| 107 | case QUP_ID_3: |
| 108 | /* configure I2C SDA gpio */ |
| 109 | gpio_tlmm_config(29, 3, GPIO_OUTPUT, GPIO_NO_PULL, |
| 110 | GPIO_8MA, GPIO_DISABLE); |
| 111 | |
| 112 | /* configure I2C SCL gpio */ |
| 113 | gpio_tlmm_config(30, 3, GPIO_OUTPUT, GPIO_NO_PULL, |
| 114 | GPIO_8MA, GPIO_DISABLE); |
| 115 | break; |
| 116 | case QUP_ID_4: |
| 117 | /* configure I2C SDA gpio */ |
| 118 | gpio_tlmm_config(14, 3, GPIO_OUTPUT, GPIO_NO_PULL, |
| 119 | GPIO_8MA, GPIO_DISABLE); |
| 120 | |
| 121 | /* configure I2C SCL gpio */ |
| 122 | gpio_tlmm_config(15, 3, GPIO_OUTPUT, GPIO_NO_PULL, |
| 123 | GPIO_8MA, GPIO_DISABLE); |
| 124 | break; |
| 125 | case QUP_ID_5: |
| 126 | /* configure I2C SDA gpio */ |
| 127 | gpio_tlmm_config(18, 3, GPIO_OUTPUT, GPIO_NO_PULL, |
| 128 | GPIO_8MA, GPIO_DISABLE); |
| 129 | |
| 130 | /* configure I2C SCL gpio */ |
| 131 | gpio_tlmm_config(19, 3, GPIO_OUTPUT, GPIO_NO_PULL, |
| 132 | GPIO_8MA, GPIO_DISABLE); |
| 133 | break; |
| 134 | |
| 135 | default: |
| 136 | dprintf(CRITICAL, "Incorrect QUP id %d\n",qup_id); |
| 137 | ASSERT(0); |
| 138 | }; |
| 139 | } else { |
| 140 | dprintf(CRITICAL, "Incorrect BLSP id %d\n",blsp_id); |
| 141 | ASSERT(0); |
| 142 | } |
| 143 | } |
Baochu Xu | 6788fad | 2017-12-05 18:45:28 +0800 | [diff] [blame] | 144 | |
| 145 | void gpio_config_blsp_spi(uint8_t blsp_id, uint8_t qup_id) |
| 146 | { |
| 147 | if(blsp_id == BLSP_ID_1) { |
| 148 | switch (qup_id) { |
| 149 | |
| 150 | case QUP_ID_3: |
| 151 | /* configure SPI MOSI gpio */ |
| 152 | gpio_tlmm_config(12, 1, GPIO_OUTPUT, GPIO_NO_PULL, |
| 153 | GPIO_16MA, GPIO_DISABLE); |
| 154 | |
| 155 | /* configure SPI MISO gpio */ |
| 156 | gpio_tlmm_config(13, 1, GPIO_OUTPUT, GPIO_NO_PULL, |
| 157 | GPIO_16MA, GPIO_DISABLE); |
| 158 | |
| 159 | /* configure SPI CS_N gpio */ |
| 160 | gpio_tlmm_config(14, 1, GPIO_OUTPUT, GPIO_NO_PULL, |
| 161 | GPIO_16MA, GPIO_DISABLE); |
| 162 | |
| 163 | /* configure SPI CLK gpio */ |
| 164 | gpio_tlmm_config(15, 1, GPIO_OUTPUT, GPIO_NO_PULL, |
| 165 | GPIO_16MA, GPIO_DISABLE); |
| 166 | break; |
| 167 | |
| 168 | case QUP_ID_4: |
| 169 | /* configure SPI MOSI gpio */ |
| 170 | gpio_tlmm_config(16, 1, GPIO_OUTPUT, GPIO_NO_PULL, |
| 171 | GPIO_16MA, GPIO_DISABLE); |
| 172 | |
| 173 | /* configure SPI MISO gpio */ |
| 174 | gpio_tlmm_config(17, 1, GPIO_OUTPUT, GPIO_NO_PULL, |
| 175 | GPIO_16MA, GPIO_DISABLE); |
| 176 | |
| 177 | /* configure SPI CS_N gpio */ |
| 178 | gpio_tlmm_config(18, 1, GPIO_OUTPUT, GPIO_NO_PULL, |
| 179 | GPIO_16MA, GPIO_DISABLE); |
| 180 | |
| 181 | /* configure SPI CLK gpio */ |
| 182 | gpio_tlmm_config(19, 1, GPIO_OUTPUT, GPIO_NO_PULL, |
| 183 | GPIO_16MA, GPIO_DISABLE); |
| 184 | break; |
| 185 | |
| 186 | case QUP_ID_0: |
| 187 | case QUP_ID_1: |
| 188 | |
| 189 | case QUP_ID_2: |
| 190 | |
| 191 | |
| 192 | |
| 193 | case QUP_ID_5: |
| 194 | default: |
| 195 | dprintf(CRITICAL, "Incorrect QUP id %d\n",qup_id); |
| 196 | ASSERT(0); |
| 197 | }; |
| 198 | } else { |
| 199 | dprintf(CRITICAL, "Incorrect BLSP id %d\n",blsp_id); |
| 200 | ASSERT(0); |
| 201 | } |
| 202 | } |