Daisuke Nojiri | 0594914 | 2014-11-21 15:33:26 -0800 | [diff] [blame] | 1 | /* |
Vadim Bendebury | 6fe4e5e | 2014-12-06 10:44:58 -0800 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Daisuke Nojiri | 0594914 | 2014-11-21 15:33:26 -0800 | [diff] [blame] | 3 | * |
Sourabh Banerjee | 8920865 | 2015-02-19 16:43:26 +0530 | [diff] [blame] | 4 | * Copyright (C) 2014 - 2015 The Linux Foundation. All rights reserved. |
Daisuke Nojiri | 0594914 | 2014-11-21 15:33:26 -0800 | [diff] [blame] | 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in the |
| 13 | * documentation and/or other materials provided with the distribution. |
| 14 | * 3. The name of the author may not be used to endorse or promote products |
| 15 | * derived from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 27 | * SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #ifndef __QUP_H__ |
| 31 | #define __QUP_H__ |
Vadim Bendebury | 6fe4e5e | 2014-12-06 10:44:58 -0800 | [diff] [blame] | 32 | |
| 33 | #include <soc/gsbi.h> |
Daisuke Nojiri | 0594914 | 2014-11-21 15:33:26 -0800 | [diff] [blame] | 34 | |
| 35 | /* QUP block registers */ |
| 36 | #define QUP_CONFIG 0x0 |
| 37 | #define QUP_STATE 0x4 |
| 38 | #define QUP_IO_MODES 0x8 |
| 39 | #define QUP_SW_RESET 0xc |
| 40 | #define QUP_TIME_OUT 0x10 |
| 41 | #define QUP_TIME_OUT_CURRENT 0x14 |
| 42 | #define QUP_OPERATIONAL 0x18 |
| 43 | #define QUP_ERROR_FLAGS 0x1c |
| 44 | #define QUP_ERROR_FLAGS_EN 0x20 |
| 45 | #define QUP_TEST_CTRL 0x24 |
| 46 | #define QUP_MX_OUTPUT_COUNT 0x100 |
| 47 | #define QUP_MX_OUTPUT_CNT_CURRENT 0x104 |
| 48 | #define QUP_OUTPUT_DEBUG 0x108 |
| 49 | #define QUP_OUTPUT_FIFO_WORD_CNT 0x10c |
| 50 | #define QUP_OUTPUT_FIFO 0x110 |
| 51 | #define QUP_MX_WRITE_COUNT 0x150 |
| 52 | #define QUP_WRITE_CNT_CURRENT 0x154 |
| 53 | #define QUP_MX_INPUT_COUNT 0x200 |
| 54 | #define QUP_READ_COUNT 0x208 |
| 55 | #define QUP_MX_READ_CNT_CURRENT 0x20c |
| 56 | #define QUP_INPUT_DEBUG 0x210 |
| 57 | #define QUP_INPUT_FIFO_WORD_CNT 0x214 |
| 58 | #define QUP_INPUT_FIFO 0x218 |
| 59 | #define QUP_I2C_MASTER_CLK_CTL 0x400 |
| 60 | #define QUP_I2C_MASTER_STATUS 0x404 |
| 61 | |
| 62 | #define OUTPUT_FIFO_FULL (1<<6) |
| 63 | #define INPUT_FIFO_NOT_EMPTY (1<<5) |
| 64 | #define OUTPUT_FIFO_NOT_EMPTY (1<<4) |
| 65 | #define INPUT_SERVICE_FLAG (1<<9) |
| 66 | #define OUTPUT_SERVICE_FLAG (1<<8) |
| 67 | #define QUP_OUTPUT_BIT_SHIFT_EN (1<<16) |
| 68 | |
| 69 | #define QUP_MODE_MASK (0x03) |
| 70 | #define QUP_OUTPUT_MODE_SHFT (10) |
| 71 | #define QUP_INPUT_MODE_SHFT (12) |
| 72 | |
| 73 | #define QUP_FS_DIVIDER_MASK (0xFF) |
| 74 | |
| 75 | #define QUP_MINI_CORE_PROTO_SHFT (8) |
| 76 | #define QUP_MINI_CORE_PROTO_MASK (0x0F) |
| 77 | |
| 78 | /* Mini-core states */ |
| 79 | #define QUP_STATE_RESET 0x0 |
| 80 | #define QUP_STATE_RUN 0x1 |
| 81 | #define QUP_STATE_PAUSE 0x3 |
| 82 | #define QUP_STATE_VALID (1<<2) |
| 83 | #define QUP_STATE_MASK 0x3 |
| 84 | #define QUP_STATE_VALID_MASK (1<<2) |
| 85 | |
| 86 | /* Tags for output FIFO */ |
| 87 | #define QUP_I2C_1CLK_NOOP_SEQ 0x1 /*MSB 8-bit NOP, LSB 8-bits 1 clk.*/ |
| 88 | #define QUP_I2C_START_SEQ (0x1 << 8) |
| 89 | #define QUP_I2C_DATA_SEQ (0x2 << 8) |
| 90 | #define QUP_I2C_STOP_SEQ (0x3 << 8) |
| 91 | #define QUP_I2C_RECV_SEQ (0x4 << 8) |
| 92 | |
| 93 | /* Tags for input FIFO */ |
| 94 | #define QUP_I2C_MIDATA_SEQ (0x5 << 8) |
| 95 | #define QUP_I2C_MISTOP_SEQ (0x6 << 8) |
| 96 | #define QUP_I2C_MINACK_SEQ (0x7 << 8) |
| 97 | |
| 98 | #define QUP_I2C_ADDR(x) ((x & 0xFF) << 1) |
| 99 | #define QUP_I2C_DATA(x) (x & 0xFF) |
| 100 | #define QUP_I2C_MI_TAG(x) (x & 0xFF00) |
| 101 | #define QUP_I2C_SLAVE_READ (0x1) |
| 102 | |
| 103 | /*Bit vals for I2C_MASTER_CLK_CTL register */ |
| 104 | #define QUP_HS_DIVIDER_SHFT (8) |
| 105 | #define QUP_DIVIDER_MIN_VAL (0x3) |
| 106 | |
| 107 | /* Bit masks for I2C_MASTER_STATUS register */ |
| 108 | #define QUP_I2C_INVALID_READ_SEQ (1 << 25) |
| 109 | #define QUP_I2C_INVALID_READ_ADDR (1 << 24) |
| 110 | #define QUP_I2C_INVALID_TAG (1 << 23) |
| 111 | #define QUP_I2C_FAILED_MASK (0x3 << 6) |
Sourabh Banerjee | f36cffc | 2015-02-27 19:18:11 +0530 | [diff] [blame] | 112 | #define QUP_I2C_INVALID_WRITE (1 << 5) |
Daisuke Nojiri | 0594914 | 2014-11-21 15:33:26 -0800 | [diff] [blame] | 113 | #define QUP_I2C_ARB_LOST (1 << 4) |
Sourabh Banerjee | f36cffc | 2015-02-27 19:18:11 +0530 | [diff] [blame] | 114 | #define QUP_I2C_PACKET_NACK (1 << 3) |
Daisuke Nojiri | 0594914 | 2014-11-21 15:33:26 -0800 | [diff] [blame] | 115 | #define QUP_I2C_BUS_ERROR (1 << 2) |
| 116 | |
| 117 | typedef enum { |
| 118 | QUP_SUCCESS = 0, |
| 119 | QUP_ERR_BAD_PARAM, |
| 120 | QUP_ERR_STATE_SET, |
| 121 | QUP_ERR_TIMEOUT, |
| 122 | QUP_ERR_UNSUPPORTED, |
Vadim Bendebury | 6fe4e5e | 2014-12-06 10:44:58 -0800 | [diff] [blame] | 123 | QUP_ERR_I2C_FAILED, |
| 124 | QUP_ERR_I2C_ARB_LOST, |
| 125 | QUP_ERR_I2C_BUS_ERROR, |
Daisuke Nojiri | 0594914 | 2014-11-21 15:33:26 -0800 | [diff] [blame] | 126 | QUP_ERR_I2C_INVALID_SLAVE_ADDR, |
| 127 | QUP_ERR_XFER_FAIL, |
Sourabh Banerjee | f36cffc | 2015-02-27 19:18:11 +0530 | [diff] [blame] | 128 | QUP_ERR_I2C_NACK, |
| 129 | QUP_ERR_I2C_INVALID_WRITE, |
| 130 | QUP_ERR_I2C_INVALID_TAG, |
Daisuke Nojiri | 0594914 | 2014-11-21 15:33:26 -0800 | [diff] [blame] | 131 | QUP_ERR_UNDEFINED, |
| 132 | } qup_return_t; |
| 133 | |
| 134 | typedef enum { |
| 135 | QUP_MINICORE_SPI = 1, |
| 136 | QUP_MINICORE_I2C_MASTER, |
| 137 | QUP_MINICORE_I2C_SLAVE |
| 138 | } qup_protocol_t; |
| 139 | |
| 140 | typedef enum { |
| 141 | QUP_MODE_FIFO = 0, |
| 142 | QUP_MODE_BLOCK, |
| 143 | QUP_MODE_DATAMOVER, |
| 144 | } qup_mode_t; |
| 145 | |
| 146 | typedef struct { |
| 147 | qup_protocol_t protocol; |
| 148 | unsigned clk_frequency; |
| 149 | unsigned src_frequency; |
| 150 | qup_mode_t mode; |
Sourabh Banerjee | 8920865 | 2015-02-19 16:43:26 +0530 | [diff] [blame] | 151 | unsigned initialized; |
Daisuke Nojiri | 0594914 | 2014-11-21 15:33:26 -0800 | [diff] [blame] | 152 | } qup_config_t; |
| 153 | |
| 154 | typedef struct { |
| 155 | qup_protocol_t protocol; |
| 156 | union { |
| 157 | struct { |
| 158 | uint8_t addr; |
| 159 | uint8_t *data; |
| 160 | unsigned data_len; |
| 161 | } iic; |
| 162 | struct { |
| 163 | void *in; |
| 164 | void *out; |
| 165 | unsigned size; |
| 166 | } spi; |
| 167 | } p; |
| 168 | } qup_data_t; |
| 169 | |
| 170 | /* |
| 171 | * Initialize GSBI QUP block for FIFO I2C transfers. |
| 172 | * gsbi_id[IN]: GSBI for which QUP is to be initialized. |
| 173 | * config_ptr[IN]: configurations parameters for the QUP. |
| 174 | * |
| 175 | * return: QUP_SUCCESS, if initialization succeeds. |
| 176 | */ |
Vadim Bendebury | 6fe4e5e | 2014-12-06 10:44:58 -0800 | [diff] [blame] | 177 | qup_return_t qup_init(gsbi_id_t gsbi_id, const qup_config_t *config_ptr); |
Daisuke Nojiri | 0594914 | 2014-11-21 15:33:26 -0800 | [diff] [blame] | 178 | |
| 179 | /* |
| 180 | * Set QUP state to run, pause, reset. |
| 181 | * gsbi_id[IN]: GSBI block for which QUP state is to be set. |
| 182 | * state[IN]: New state to transition to. |
| 183 | * |
| 184 | * return: QUP_SUCCESS, if state transition succeeds. |
| 185 | */ |
| 186 | qup_return_t qup_set_state(gsbi_id_t gsbi_id, uint32_t state); |
| 187 | |
| 188 | /* |
| 189 | * Reset the status bits set during an i2c transfer. |
| 190 | * gsbi_id[IN]: GSBI block for which i2c status bits are to be cleared. |
| 191 | * |
| 192 | * return: QUP_SUCCESS, if status bits are cleared successfully. |
| 193 | */ |
| 194 | qup_return_t qup_reset_i2c_master_status(gsbi_id_t gsbi_id); |
| 195 | |
| 196 | /* |
| 197 | * Send data to the peripheral on the bus. |
| 198 | * gsbi_id[IN]: GSBI block for which data is to be sent. |
| 199 | * p_tx_obj[IN]: Data to be sent to the slave on the bus. |
| 200 | * stop_seq[IN]: When set to non-zero QUP engine sends i2c stop sequnce. |
| 201 | * |
| 202 | * return: QUP_SUCCESS, when data is sent successfully to the peripheral. |
| 203 | */ |
| 204 | qup_return_t qup_send_data(gsbi_id_t gsbi_id, qup_data_t *p_tx_obj, |
| 205 | uint8_t stop_seq); |
| 206 | |
| 207 | /* |
| 208 | * Receive data from peripheral on the bus. |
| 209 | * gsbi_id[IN]: GSBI block from which data is to be received. |
| 210 | * p_tx_obj[IN]: length of data to be received, slave address. |
| 211 | * [OUT]: buffer filled with data from slave. |
| 212 | * |
| 213 | * return: QUP_SUCCESS, when data is received successfully. |
| 214 | */ |
| 215 | qup_return_t qup_recv_data(gsbi_id_t gsbi_id, qup_data_t *p_tx_obj); |
| 216 | |
| 217 | #endif //__QUP_H__ |